Skip to content

Commit

Permalink
Cherry pick PR #1808: Properly set foreground service permissions (#1809
Browse files Browse the repository at this point in the history
)

Refer to the original PR: #1808

Per
https://developer.android.com/about/versions/14/changes/fgs-types-required#media
we should be setting that we are using the
FOREGROUND_SERVICE_MEDIA_PLAYBACK permission and also passing the
corresponding type constants when we start the foreground service.

b/305802411

Co-authored-by: Garo Bournoutian <[email protected]>
  • Loading branch information
cobalt-github-releaser-bot and gbournou authored Oct 17, 2023
1 parent 7cc3940 commit f9c83cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions starboard/android/apk/app/src/app/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<!-- This is needed when targeting API 28+ to use foreground services -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />

<!-- https://iabtechlab.com/OTT-IFA, AdvertisingIdClient.Info.getId() -->
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ServiceInfo;
import android.os.Build.VERSION;
import android.os.IBinder;
import android.os.RemoteException;
Expand Down Expand Up @@ -82,7 +83,12 @@ public void onDestroy() {
public void startService() {
if (this.channelCreated) {
try {
startForeground(NOTIFICATION_ID, buildNotification());
if (VERSION.SDK_INT >= 29) {
startForeground(
NOTIFICATION_ID, buildNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST);
} else {
startForeground(NOTIFICATION_ID, buildNotification());
}
} catch (IllegalStateException e) {
Log.e(TAG, "Failed to start Foreground Service", e);
}
Expand Down

0 comments on commit f9c83cf

Please sign in to comment.