summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-06-13 10:19:09 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-06-13 10:19:09 +0000
commiteabff006be8b113b4c8a6705db64e1b1700afb3b (patch)
treec16ff9023bce0d5bac5391bf34605260333c7d09
parent298c4974bba096c7d1fe0421a377382d99127fb3 (diff)
parent8e25ad6f535977b5ca12329a6e73faaae85050b5 (diff)
Snap for 8714527 from 8e25ad6f535977b5ca12329a6e73faaae85050b5 to s-keystone-qcom-release
Change-Id: Iaba848a2e74ea3bfafe355a9d41212c94c029308
-rw-r--r--src/com/android/settings/development/SmartDdsSwitchPreferenceController.java37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/com/android/settings/development/SmartDdsSwitchPreferenceController.java b/src/com/android/settings/development/SmartDdsSwitchPreferenceController.java
index d216ed40b4..0a3a167dd0 100644
--- a/src/com/android/settings/development/SmartDdsSwitchPreferenceController.java
+++ b/src/com/android/settings/development/SmartDdsSwitchPreferenceController.java
@@ -29,12 +29,16 @@ THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
package com.android.settings.development;
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.provider.Settings;
+import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import androidx.preference.Preference;
@@ -69,6 +73,12 @@ public class SmartDdsSwitchPreferenceController extends DeveloperOptionsPreferen
private boolean mFeatureAvailable = false;
private boolean mServiceConnected = false;
private boolean mSwitchEnabled = false;
+ private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ updateState(mPreference);
+ }
+ };
private SmartDdsSwitchPreferenceController(Context context) {
super(context);
@@ -78,6 +88,9 @@ public class SmartDdsSwitchPreferenceController extends DeveloperOptionsPreferen
mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
mExtTelephonyManager = ExtTelephonyManager.getInstance(mContext);
mExtTelephonyManager.connectService(mExtTelManagerServiceCallback);
+ IntentFilter filter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
+ filter.addAction(TelephonyManager.ACTION_SIM_APPLICATION_STATE_CHANGED);
+ mContext.registerReceiver(mBroadcastReceiver, filter);
}
public static SmartDdsSwitchPreferenceController getInstance(Context context) {
@@ -96,7 +109,7 @@ public class SmartDdsSwitchPreferenceController extends DeveloperOptionsPreferen
private ServiceCallback mExtTelManagerServiceCallback = new ServiceCallback() {
@Override
public void onConnected() {
- Log.d(TAG, "mExtTelManagerServiceCallback: service connected");
+ Log.d(TAG, "ExtTelephonyService connected");
mServiceConnected = true;
mClient = mExtTelephonyManager.registerCallback(mPackageName, mCallback);
Log.d(TAG, "Client = " + mClient);
@@ -104,7 +117,8 @@ public class SmartDdsSwitchPreferenceController extends DeveloperOptionsPreferen
@Override
public void onDisconnected() {
- Log.d(TAG, "mExtTelManagerServiceCallback: service disconnected");
+ Log.d(TAG, "ExtTelephonyService disconnected");
+ mContext.unregisterReceiver(mBroadcastReceiver);
mServiceConnected = false;
mClient = null;
}
@@ -183,7 +197,7 @@ public class SmartDdsSwitchPreferenceController extends DeveloperOptionsPreferen
if (mFeatureAvailable) {
String defaultSummary = mContext.getResources().getString(
R.string.smart_dds_switch_summary);
- updateUi(defaultSummary, true);
+ updateUi(defaultSummary, isAvailable());
} else {
Log.d(TAG, "Feature unavailable");
preference.setVisible(false);
@@ -204,10 +218,17 @@ public class SmartDdsSwitchPreferenceController extends DeveloperOptionsPreferen
@Override
public boolean isAvailable() {
- // Only show the toggle if more than one phone is active
- int numActiveModemCount = mTelephonyManager.getActiveModemCount();
- Log.d(TAG, "numActiveModemCount: " + numActiveModemCount);
- return numActiveModemCount > 1;
+ // Only show the toggle if 1) APM is off and 2) more than one subscription is active
+ SubscriptionManager subscriptionManager = mContext.getSystemService(
+ SubscriptionManager.class);
+ int numActiveSubscriptionInfoCount = subscriptionManager.getActiveSubscriptionInfoCount();
+ Log.d(TAG, "numActiveSubscriptionInfoCount: " + numActiveSubscriptionInfoCount);
+ return !isAirplaneModeOn() && (numActiveSubscriptionInfoCount > 1);
+ }
+
+ private boolean isAirplaneModeOn() {
+ return Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
}
private void putSwitchValue(int state) {
@@ -218,4 +239,4 @@ public class SmartDdsSwitchPreferenceController extends DeveloperOptionsPreferen
return Settings.Global.getInt(mContext.getContentResolver(), getPreferenceKey(),
SETTING_VALUE_OFF);
}
-}
+} \ No newline at end of file