towards android 12 fixing

This commit is contained in:
Hemanth S 2021-11-08 21:43:49 +05:30 committed by Prathamesh More
parent c7d158f860
commit 19c1bafeb8
5 changed files with 99 additions and 97 deletions

View file

@ -9,14 +9,14 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 29 targetSdkVersion 31
renderscriptTargetApi 29//must match target sdk and build tools renderscriptTargetApi 29//must match target sdk and build tools
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true
applicationId "code.name.monkey.retromusic" applicationId "code.name.monkey.retromusic"
versionCode 10519 versionCode 10537
versionName '5.0.0' + "_" + getDate() versionName '5.2.1 ' + "_" + getDate()
buildConfigField("String", "GOOGLE_PLAY_LICENSING_KEY", "\"${getProperty(getProperties('../public.properties'), 'GOOGLE_PLAY_LICENSE_KEY')}\"") buildConfigField("String", "GOOGLE_PLAY_LICENSING_KEY", "\"${getProperty(getProperties('../public.properties'), 'GOOGLE_PLAY_LICENSE_KEY')}\"")
} }

View file

@ -35,6 +35,7 @@
tools:targetApi="m"> tools:targetApi="m">
<activity <activity
android:name=".activities.MainActivity" android:name=".activities.MainActivity"
android:exported="true"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/SplashTheme"> android:theme="@style/SplashTheme">
<intent-filter> <intent-filter>
@ -147,7 +148,8 @@
android:label="@string/app_name" android:label="@string/app_name"
android:launchMode="singleTask" android:launchMode="singleTask"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar"> android:theme="@style/Theme.AppCompat.NoActionBar"
android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
</intent-filter> </intent-filter>
@ -176,13 +178,17 @@
android:resource="@xml/provider_paths" /> android:resource="@xml/provider_paths" />
</provider> </provider>
<receiver android:name=".service.MediaButtonIntentReceiver"> <receiver
android:name=".service.MediaButtonIntentReceiver"
android:exported="false">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" /> <action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver android:name=".appwidgets.BootReceiver"> <receiver
android:name=".appwidgets.BootReceiver"
android:exported="false">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" /> <action android:name="android.intent.action.QUICKBOOT_POWERON" />
@ -274,17 +280,6 @@
android:name="com.android.vending.splits.required" android:name="com.android.vending.splits.required"
android:value="true" /> android:value="true" />
<!-- Android Auto -->
<meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc" />
<meta-data
android:name="com.google.android.gms.car.application.theme"
android:resource="@style/CarTheme" />
<meta-data
android:name="com.google.android.gms.car.notification.SmallIcon"
android:resource="@drawable/ic_notification" />
<!-- ChromeCast --> <!-- ChromeCast -->
<meta-data <meta-data
android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME" android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"

View file

@ -189,13 +189,13 @@ public class MusicService extends MediaBrowserServiceCompat
private final AppWidgetBig appWidgetBig = AppWidgetBig.Companion.getInstance(); private final AppWidgetBig appWidgetBig = AppWidgetBig.Companion.getInstance();
private final AppWidgetCard appWidgetCard = AppWidgetCard.Companion.getInstance(); private final AppWidgetCard appWidgetCard = AppWidgetCard.Companion.getInstance();
private final AppWidgetClassic appWidgetClassic = AppWidgetClassic.Companion.getInstance(); private final AppWidgetClassic appWidgetClassic = AppWidgetClassic.Companion.getInstance();
private final AppWidgetSmall appWidgetSmall = AppWidgetSmall.Companion.getInstance(); private final AppWidgetSmall appWidgetSmall = AppWidgetSmall.Companion.getInstance();
private final AppWidgetText appWidgetText = AppWidgetText.Companion.getInstance(); private final AppWidgetText appWidgetText = AppWidgetText.Companion.getInstance();
private final BroadcastReceiver widgetIntentReceiver = private final BroadcastReceiver widgetIntentReceiver =
new BroadcastReceiver() { new BroadcastReceiver() {
@ -229,15 +229,15 @@ public class MusicService extends MediaBrowserServiceCompat
} }
} }
}; };
private AudioManager audioManager; private AudioManager audioManager;
private final IntentFilter becomingNoisyReceiverIntentFilter = private final IntentFilter becomingNoisyReceiverIntentFilter =
new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY); new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
private boolean becomingNoisyReceiverRegistered; private boolean becomingNoisyReceiverRegistered;
private final IntentFilter bluetoothConnectedIntentFilter = private final IntentFilter bluetoothConnectedIntentFilter =
new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED); new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED);
private boolean bluetoothConnectedRegistered = false; private boolean bluetoothConnectedRegistered = false;
private final IntentFilter headsetReceiverIntentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); private final IntentFilter headsetReceiverIntentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
private boolean headsetReceiverRegistered = false; private boolean headsetReceiverRegistered = false;
private MediaSessionCompat mediaSession; private MediaSessionCompat mediaSession;
private ContentObserver mediaStoreObserver; private ContentObserver mediaStoreObserver;
private HandlerThread musicPlayerHandlerThread; private HandlerThread musicPlayerHandlerThread;
@ -291,59 +291,59 @@ public class MusicService extends MediaBrowserServiceCompat
private HandlerThread queueSaveHandlerThread; private HandlerThread queueSaveHandlerThread;
private boolean queuesRestored; private boolean queuesRestored;
private int repeatMode; private int repeatMode;
private int shuffleMode; private int shuffleMode;
private final SongPlayCountHelper songPlayCountHelper = new SongPlayCountHelper(); private final SongPlayCountHelper songPlayCountHelper = new SongPlayCountHelper();
private final BroadcastReceiver bluetoothReceiver = private final BroadcastReceiver bluetoothReceiver =
new BroadcastReceiver() { new BroadcastReceiver() {
@Override @Override
public void onReceive(final Context context, final Intent intent) { public void onReceive(final Context context, final Intent intent) {
String action = intent.getAction(); String action = intent.getAction();
if (action != null) { if (action != null) {
if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action) if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)
&& PreferenceUtil.INSTANCE.isBluetoothSpeaker()) { && PreferenceUtil.INSTANCE.isBluetoothSpeaker()) {
if (VERSION.SDK_INT >= VERSION_CODES.M) { if (VERSION.SDK_INT >= VERSION_CODES.M) {
if (getAudioManager().getDevices(AudioManager.GET_DEVICES_OUTPUTS).length > 0) { if (getAudioManager().getDevices(AudioManager.GET_DEVICES_OUTPUTS).length > 0) {
play(); play();
}
} else {
if (getAudioManager().isBluetoothA2dpOn()) {
play();
}
}
}
} }
} else {
if (getAudioManager().isBluetoothA2dpOn()) {
play();
}
}
} }
} };
} private final PhoneStateListener phoneStateListener =
}; new PhoneStateListener() {
private final PhoneStateListener phoneStateListener = @Override
new PhoneStateListener() { public void onCallStateChanged(int state, String incomingNumber) {
@Override switch (state) {
public void onCallStateChanged(int state, String incomingNumber) { case TelephonyManager.CALL_STATE_IDLE:
switch (state) { // Not in call: Play music
case TelephonyManager.CALL_STATE_IDLE: play();
// Not in call: Play music break;
play(); case TelephonyManager.CALL_STATE_RINGING:
break; case TelephonyManager.CALL_STATE_OFFHOOK:
case TelephonyManager.CALL_STATE_RINGING: // A call is dialing, active or on hold
case TelephonyManager.CALL_STATE_OFFHOOK: pause();
// A call is dialing, active or on hold break;
pause(); default:
break; }
default: super.onCallStateChanged(state, incomingNumber);
} }
super.onCallStateChanged(state, incomingNumber); };
} private final BroadcastReceiver headsetReceiver =
}; new BroadcastReceiver() {
private final BroadcastReceiver headsetReceiver = @Override
new BroadcastReceiver() { public void onReceive(Context context, Intent intent) {
@Override String action = intent.getAction();
public void onReceive(Context context, Intent intent) { if (action != null) {
String action = intent.getAction(); if (Intent.ACTION_HEADSET_PLUG.equals(action)) {
if (action != null) { int state = intent.getIntExtra("state", -1);
if (Intent.ACTION_HEADSET_PLUG.equals(action)) { switch (state) {
int state = intent.getIntExtra("state", -1); case 0:
switch (state) { pause();
case 0:
pause();
break; break;
case 1: case 1:
play(); play();
@ -1123,7 +1123,7 @@ public class MusicService extends MediaBrowserServiceCompat
if (playback instanceof CrossFadePlayer) { if (playback instanceof CrossFadePlayer) {
((CrossFadePlayer) playback).sourceChangedByUser(); ((CrossFadePlayer) playback).sourceChangedByUser();
} }
} else { } else {
trackEndedByCrossfade = false; trackEndedByCrossfade = false;
} }
if (openTrackAndPrepareNextAt(position)) { if (openTrackAndPrepareNextAt(position)) {
@ -1594,15 +1594,18 @@ public class MusicService extends MediaBrowserServiceCompat
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaButtonIntent.setComponent(mediaButtonReceiverComponentName); mediaButtonIntent.setComponent(mediaButtonReceiverComponentName);
PendingIntent mediaButtonReceiverPendingIntent = PendingIntent mediaButtonReceiverPendingIntent;
PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, 0); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
mediaButtonReceiverPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, PendingIntent.FLAG_MUTABLE);
} else {
mediaButtonReceiverPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, 0);
}
mediaSession = mediaSession = new MediaSessionCompat(
new MediaSessionCompat( this,
this, "RetroMusicPlayer",
"RetroMusicPlayer", mediaButtonReceiverComponentName,
mediaButtonReceiverComponentName, mediaButtonReceiverPendingIntent);
mediaButtonReceiverPendingIntent);
MediaSessionCallback mediasessionCallback = MediaSessionCallback mediasessionCallback =
new MediaSessionCallback(getApplicationContext(), this); new MediaSessionCallback(getApplicationContext(), this);
mediaSession.setFlags( mediaSession.setFlags(

View file

@ -69,13 +69,21 @@ class PlayingNotificationImpl : PlayingNotification(), KoinComponent {
action.putExtra(MainActivity.EXPAND_PANEL, PreferenceUtil.isExpandPanel) action.putExtra(MainActivity.EXPAND_PANEL, PreferenceUtil.isExpandPanel)
action.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP action.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
val clickIntent = val clickIntent =
PendingIntent.getActivity(service, 0, action, PendingIntent.FLAG_UPDATE_CURRENT) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.getActivity(service, 0, action, PendingIntent.FLAG_IMMUTABLE)
} else {
PendingIntent.getActivity(service, 0, action, PendingIntent.FLAG_UPDATE_CURRENT)
}
val serviceName = ComponentName(service, MusicService::class.java) val serviceName = ComponentName(service, MusicService::class.java)
val intent = Intent(ACTION_QUIT) val intent = Intent(ACTION_QUIT)
intent.component = serviceName intent.component = serviceName
val deleteIntent = PendingIntent.getService(service, 0, intent, 0) val deleteIntent = PendingIntent.getService(
service,
0,
intent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
val bigNotificationImageSize = service.resources val bigNotificationImageSize = service.resources
.getDimensionPixelSize(R.dimen.notification_big_image_size) .getDimensionPixelSize(R.dimen.notification_big_image_size)
service.runOnUiThread { service.runOnUiThread {
@ -191,6 +199,6 @@ class PlayingNotificationImpl : PlayingNotification(), KoinComponent {
val serviceName = ComponentName(service, MusicService::class.java) val serviceName = ComponentName(service, MusicService::class.java)
val intent = Intent(action) val intent = Intent(action)
intent.component = serviceName intent.component = serviceName
return PendingIntent.getService(service, 0, intent, 0) return PendingIntent.getService(service, 0, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
} }
} }

View file

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<automotiveApp>
<uses name="media" />
</automotiveApp>