FM: Updating FM app to target SDK version 34
Made changes to update FM app to target SDK version 34. FM app
will request for POST_NOTIFICATIONS permission required in the
new SDK version.
Updated startForeground API to start FM service as foreground with
type media playback. Updated stopForeground to use new
STOP_FOREGROUND_REMOVE.
Tested FM on/off, tune, recording, volume change, scan, FM stats after
making changes.
CRs-Fixed: 3522378
Change-Id: I28bc06fbbc84381f0b3ef3eaa79f21b9fb2fa93b
diff --git a/fmapp2/AndroidManifest.xml b/fmapp2/AndroidManifest.xml
index bc5b790..fc55149 100644
--- a/fmapp2/AndroidManifest.xml
+++ b/fmapp2/AndroidManifest.xml
@@ -29,7 +29,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.caf.fmradio" >
- <uses-sdk android:minSdkVersion="31" android:targetSdkVersion="31"/>
+ <uses-sdk android:minSdkVersion="34" android:targetSdkVersion="34"/>
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
+ <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
@@ -130,6 +132,7 @@
</activity>
<service android:name=".FMRadioService"
+ android:foregroundServiceType="mediaPlayback"
android:exported="true" />
</application>
diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java
index b1d7216..0b06f3b 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadioService.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java
@@ -42,6 +42,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.ServiceInfo;
import android.app.IntentService;
import android.os.UserHandle;
import android.content.BroadcastReceiver;
@@ -1734,7 +1735,8 @@
.setOngoing(true)
.build();
- startForeground(FMRADIOSERVICE_STATUS, notification);
+ startForeground(FMRADIOSERVICE_STATUS, notification,
+ ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK);
mFMOn = true;
}
}
@@ -1777,7 +1779,7 @@
mDelayedStopHandler.removeCallbacksAndMessages(null);
cancelAlarms();
setAlarmDelayedServiceStop();
- stopForeground(true);
+ stopForeground(Service.STOP_FOREGROUND_REMOVE);
}
/** Read's the internal Antenna available state from the FM