diff options
author | Vala Zadeh <quic_vzadeh@quicinc.com> | 2022-04-04 11:56:56 -0700 |
---|---|---|
committer | Vala Zadeh <quic_vzadeh@quicinc.com> | 2022-05-11 16:36:00 -0700 |
commit | eee8c55c40c901da5541fa4e80dccf9af8d00d28 (patch) | |
tree | 99ad4e2ba73a73eaa324c7af3351eba73b2bc974 /src/com/android/settings/development/SmartDdsSwitchPreferenceController.java | |
parent | c70219df75eaf68ef1d9091682cd861cdc66aab7 (diff) |
Dynamically gray out the smart DDS switch option
If fewer than two subscriptions are active, gray out the smart DDS
switch option.
CRs-Fixed: 3107817
Change-Id: Idf1b662723a702a020b48796b9b57886dc519525
Diffstat (limited to 'src/com/android/settings/development/SmartDdsSwitchPreferenceController.java')
-rw-r--r-- | src/com/android/settings/development/SmartDdsSwitchPreferenceController.java | 37 |
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 |