FM: New target SDK requirement for Android S
The target api value for fm app is updated
to 31 as it uses foreground permission
and accordingly added telephonycallback instead of
phonestate listener as it is deprecated.
Change-Id: I6fa7cff117019f18b5fc6d110f6fc3f9778e0f34
diff --git a/fmapp2/AndroidManifest.xml b/fmapp2/AndroidManifest.xml
index 786fcf8..5dd03a4 100644
--- a/fmapp2/AndroidManifest.xml
+++ b/fmapp2/AndroidManifest.xml
@@ -29,7 +29,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.caf.fmradio" >
- <uses-sdk android:minSdkVersion="29" android:targetSdkVersion="29"/>
+ <uses-sdk android:minSdkVersion="31" android:targetSdkVersion="31"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
@@ -38,8 +38,10 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
+ <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
@@ -65,7 +67,8 @@
android:allowTaskReparenting="true"
android:launchMode="singleTask"
android:configChanges="keyboardHidden|orientation|screenSize"
- android:excludeFromRecents="false" >
+ android:excludeFromRecents="false"
+ android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@@ -79,14 +82,16 @@
</activity>
- <receiver android:name="com.caf.fmradio.FMMediaButtonIntentReceiver">
+ <receiver android:name="com.caf.fmradio.FMMediaButtonIntentReceiver"
+ android:exported="true" >
<intent-filter>
<action android:name="android.media.AUDIO_BECOMING_NOISY" />
</intent-filter>
</receiver>
<activity android:name=".Settings"
- android:label="@string/settings_menu">
+ android:exported="true"
+ android:label="@string/settings_menu">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@@ -95,6 +100,7 @@
</activity>
<activity android:name=".FMStats"
+ android:exported="true"
android:label="@string/test_menu">
<intent-filter>
@@ -104,6 +110,7 @@
</activity>
<activity android:name=".FmTags"
+ android:exported="true"
android:label="@string/rt_plus_tags">
<intent-filter>
@@ -113,6 +120,7 @@
</activity>
<activity android:name=".StationListActivity"
+ android:exported="true"
android:label="@string/app_label_all_channels"
android:configChanges="orientation|keyboardHidden|screenSize|fontScale">
diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java
index b86b0cd..5f375dd 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadioService.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java
@@ -70,7 +70,7 @@
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.RemoteException;
-import android.telephony.PhoneStateListener;
+import android.telephony.TelephonyCallback;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.RemoteViews;
@@ -234,6 +234,7 @@
private boolean mEventReceived = false;
private boolean isfmOffFromApplication = false;
private AudioFocusRequest mGainFocusReq;
+ private PhoneStateCallback mPhoneStateCallback;
public FMRadioService() {
}
@@ -247,8 +248,10 @@
mPrefs = new FmSharedPreferences(this);
mCallbacks = null;
TelephonyManager tmgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
- tmgr.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE |
- PhoneStateListener.LISTEN_DATA_ACTIVITY);
+ if (mPhoneStateCallback == null) {
+ mPhoneStateCallback = new PhoneStateCallback();
+ }
+ tmgr.registerTelephonyCallback(getApplicationContext().getMainExecutor(), mPhoneStateCallback);
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
mWakeLock.setReferenceCounted(false);
@@ -362,7 +365,7 @@
}
TelephonyManager tmgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
- tmgr.listen(mPhoneStateListener, 0);
+ tmgr.unregisterTelephonyCallback(mPhoneStateCallback);
Log.d(LOGTAG, "onDestroy: unbindFromService completed");
@@ -1352,7 +1355,7 @@
cv.put(MediaStore.Audio.Media.DATA, file.getAbsolutePath());
cv.put(MediaStore.Audio.Media.DATE_ADDED, (int) (current / 1000));
cv.put(MediaStore.Audio.Media.DATE_MODIFIED, (int) (modDate / 1000));
- cv.put(MediaStore.Audio.Media.MIME_TYPE, "audio/aac_mp4");
+ cv.put(MediaStore.Audio.Media.MIME_TYPE, "audio/mpeg");
cv.put(MediaStore.Audio.Media.ARTIST,
res.getString(R.string.audio_db_artist_name));
cv.put(MediaStore.Audio.Media.ALBUM,
@@ -1511,11 +1514,12 @@
}
/* Handle Phone Call + FM Concurrency */
- private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
+ private class PhoneStateCallback extends TelephonyCallback implements
+ TelephonyCallback.CallStateListener,
+ TelephonyCallback.DataActivityListener {
@Override
- public void onCallStateChanged(int state, String incomingNumber) {
+ public void onCallStateChanged(int state){
Log.d(LOGTAG, "onCallStateChanged: State - " + state );
- Log.d(LOGTAG, "onCallStateChanged: incomingNumber - " + incomingNumber );
fmActionOnCallState(state );
}