From 1b36fda31615b74b131f0f75f58b1202728a03d3 Mon Sep 17 00:00:00 2001 From: Bonian Chen Date: Mon, 6 Apr 2020 22:00:18 +0800 Subject: [PATCH] [Settings] mSubId should not be overridden in TelephonyBasePreferenceController mSubId is a protected member provided by parent class. Overriding mSubId should be avoided. Bug: 150535296 Test: manual Merged-In: I391b034c9badd43094ab52b8b6488bca07ef3c86 Change-Id: I65fda30d1e699695315eb57d8930a27fdebb5a46 --- .../DisabledSubscriptionController.java | 18 +++++++++++++----- .../cdma/CdmaBasePreferenceController.java | 1 - 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/com/android/settings/network/telephony/DisabledSubscriptionController.java b/src/com/android/settings/network/telephony/DisabledSubscriptionController.java index e6cace48dfa..b5febdd18a7 100644 --- a/src/com/android/settings/network/telephony/DisabledSubscriptionController.java +++ b/src/com/android/settings/network/telephony/DisabledSubscriptionController.java @@ -28,16 +28,21 @@ import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceScreen; -import com.android.settings.core.BasePreferenceController; import com.android.settings.network.SubscriptionsChangeListener; -public class DisabledSubscriptionController extends BasePreferenceController implements +/** + * Preference controller group which can hide UI option from visible when SIM is no longer in + * active. + */ +public class DisabledSubscriptionController extends TelephonyBasePreferenceController implements SubscriptionsChangeListener.SubscriptionsChangeListenerClient, LifecycleObserver { private PreferenceCategory mCategory; - private int mSubId; private SubscriptionsChangeListener mChangeListener; private SubscriptionManager mSubscriptionManager; + /** + * Constructor of preference controller + */ public DisabledSubscriptionController(Context context, String preferenceKey) { super(context, preferenceKey); mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; @@ -45,6 +50,9 @@ public class DisabledSubscriptionController extends BasePreferenceController imp mChangeListener = new SubscriptionsChangeListener(context, this); } + /** + * Re-initialize the configuration based on subscription id provided + */ public void init(Lifecycle lifecycle, int subId) { lifecycle.addObserver(this); mSubId = subId; @@ -69,7 +77,7 @@ public class DisabledSubscriptionController extends BasePreferenceController imp } private void update() { - if (mCategory == null || mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { + if (mCategory == null || !SubscriptionManager.isValidSubscriptionId(mSubId)) { return; } // TODO b/135222940: re-evaluate whether to use mSubscriptionManager#isSubscriptionEnabled @@ -77,7 +85,7 @@ public class DisabledSubscriptionController extends BasePreferenceController imp } @Override - public int getAvailabilityStatus() { + public int getAvailabilityStatus(int subId) { return AVAILABLE_UNSEARCHABLE; } diff --git a/src/com/android/settings/network/telephony/cdma/CdmaBasePreferenceController.java b/src/com/android/settings/network/telephony/cdma/CdmaBasePreferenceController.java index 07805b0c8e0..a100d700257 100644 --- a/src/com/android/settings/network/telephony/cdma/CdmaBasePreferenceController.java +++ b/src/com/android/settings/network/telephony/cdma/CdmaBasePreferenceController.java @@ -44,7 +44,6 @@ public abstract class CdmaBasePreferenceController extends TelephonyBasePreferen protected Preference mPreference; protected TelephonyManager mTelephonyManager; protected PreferenceManager mPreferenceManager; - protected int mSubId; private DataContentObserver mDataContentObserver; public CdmaBasePreferenceController(Context context, String key) {