Merge "[Settings] Mobile network not updated based on SIM change" into rvc-dev am: 3a132d7c9a
Change-Id: I3aff01da1dc0e29b0da818784ee44f3b7a58c7bc
This commit is contained in:
@@ -62,6 +62,7 @@ public abstract class ActiveSubsciptionsListener
|
||||
private BroadcastReceiver mSubscriptionChangeReceiver;
|
||||
|
||||
private static final int MAX_SUBSCRIPTION_UNKNOWN = -1;
|
||||
private final int mTargetSubscriptionId;
|
||||
|
||||
private AtomicInteger mMaxActiveSubscriptionInfos;
|
||||
private List<SubscriptionInfo> mCachedActiveSubscriptionInfo;
|
||||
@@ -73,9 +74,21 @@ public abstract class ActiveSubsciptionsListener
|
||||
* @param context {@code Context} of this listener
|
||||
*/
|
||||
public ActiveSubsciptionsListener(Looper looper, Context context) {
|
||||
this(looper, context, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param looper {@code Looper} of this listener
|
||||
* @param context {@code Context} of this listener
|
||||
* @param subscriptionId for subscription on this listener
|
||||
*/
|
||||
public ActiveSubsciptionsListener(Looper looper, Context context, int subscriptionId) {
|
||||
super(looper);
|
||||
mLooper = looper;
|
||||
mContext = context;
|
||||
mTargetSubscriptionId = subscriptionId;
|
||||
|
||||
mCacheState = new AtomicInteger(STATE_NOT_LISTENING);
|
||||
mMaxActiveSubscriptionInfos = new AtomicInteger(MAX_SUBSCRIPTION_UNKNOWN);
|
||||
@@ -108,6 +121,12 @@ public abstract class ActiveSubsciptionsListener
|
||||
if (!clearCachedSubId(subId)) {
|
||||
return;
|
||||
}
|
||||
if (SubscriptionManager.isValidSubscriptionId(mTargetSubscriptionId)) {
|
||||
if (SubscriptionManager.isValidSubscriptionId(subId)
|
||||
&& (mTargetSubscriptionId != subId)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
onSubscriptionsChanged();
|
||||
}
|
||||
|
@@ -16,7 +16,9 @@
|
||||
|
||||
package com.android.settings.network.telephony;
|
||||
|
||||
import android.os.SystemClock;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -34,6 +36,7 @@ abstract class AbstractMobileNetworkSettings extends RestrictedDashboardFragment
|
||||
|
||||
private List<AbstractPreferenceController> mHiddenControllerList =
|
||||
new ArrayList<AbstractPreferenceController>();
|
||||
private boolean mIsRedrawRequired;
|
||||
|
||||
/**
|
||||
* @param restrictionKey The restriction key to check before pin protecting
|
||||
@@ -52,6 +55,15 @@ abstract class AbstractMobileNetworkSettings extends RestrictedDashboardFragment
|
||||
return result;
|
||||
}
|
||||
|
||||
Preference searchForPreference(PreferenceScreen screen,
|
||||
AbstractPreferenceController controller) {
|
||||
final String key = controller.getPreferenceKey();
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
return null;
|
||||
}
|
||||
return screen.findPreference(key);
|
||||
}
|
||||
|
||||
TelephonyStatusControlSession setTelephonyAvailabilityStatus(
|
||||
Collection<AbstractPreferenceController> listOfPrefControllers) {
|
||||
return (new TelephonyStatusControlSession.Builder(listOfPrefControllers))
|
||||
@@ -78,13 +90,19 @@ abstract class AbstractMobileNetworkSettings extends RestrictedDashboardFragment
|
||||
protected void updatePreferenceStates() {
|
||||
mHiddenControllerList.clear();
|
||||
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
getPreferenceControllersAsList().forEach(controller -> {
|
||||
final String key = controller.getPreferenceKey();
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
if (mIsRedrawRequired) {
|
||||
redrawPreferenceControllers();
|
||||
return;
|
||||
}
|
||||
final Preference preference = screen.findPreference(key);
|
||||
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
getPreferenceControllersAsList().forEach(controller ->
|
||||
updateVisiblePreferenceControllers(screen, controller));
|
||||
}
|
||||
|
||||
private void updateVisiblePreferenceControllers(PreferenceScreen screen,
|
||||
AbstractPreferenceController controller) {
|
||||
final Preference preference = searchForPreference(screen, controller);
|
||||
if (preference == null) {
|
||||
return;
|
||||
}
|
||||
@@ -96,8 +114,36 @@ abstract class AbstractMobileNetworkSettings extends RestrictedDashboardFragment
|
||||
return;
|
||||
}
|
||||
controller.updateState(preference);
|
||||
}
|
||||
|
||||
void redrawPreferenceControllers() {
|
||||
mHiddenControllerList.clear();
|
||||
|
||||
if (!isResumed()) {
|
||||
mIsRedrawRequired = true;
|
||||
return;
|
||||
}
|
||||
mIsRedrawRequired = false;
|
||||
|
||||
final long startTime = SystemClock.elapsedRealtime();
|
||||
|
||||
final List<AbstractPreferenceController> controllers =
|
||||
getPreferenceControllersAsList();
|
||||
final TelephonyStatusControlSession session =
|
||||
setTelephonyAvailabilityStatus(controllers);
|
||||
|
||||
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
controllers.forEach(controller -> {
|
||||
controller.displayPreference(screen);
|
||||
updateVisiblePreferenceControllers(screen, controller);
|
||||
});
|
||||
|
||||
final long endTime = SystemClock.elapsedRealtime();
|
||||
|
||||
Log.d(LOG_TAG, "redraw fragment: +" + (endTime - startTime) + "ms");
|
||||
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -126,12 +126,13 @@ public class MobileNetworkActivity extends SettingsBaseActivity
|
||||
: SUB_ID_NULL);
|
||||
|
||||
final SubscriptionInfo subscription = getSubscription();
|
||||
updateTitleAndNavigation(subscription);
|
||||
maybeShowContactDiscoveryDialog(subscription);
|
||||
|
||||
// Since onChanged() will take place immediately when addActiveSubscriptionsListener(),
|
||||
// perform registration after mCurSubscriptionId been configured.
|
||||
registerActiveSubscriptionsListener();
|
||||
|
||||
updateSubscriptions(subscription);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
@@ -37,6 +37,7 @@ import androidx.preference.Preference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.datausage.BillingCyclePreferenceController;
|
||||
import com.android.settings.datausage.DataUsageSummaryPreferenceController;
|
||||
import com.android.settings.network.ActiveSubsciptionsListener;
|
||||
import com.android.settings.network.telephony.cdma.CdmaSubscriptionPreferenceController;
|
||||
import com.android.settings.network.telephony.cdma.CdmaSystemSelectPreferenceController;
|
||||
import com.android.settings.network.telephony.gsm.AutoSelectPreferenceController;
|
||||
@@ -44,6 +45,7 @@ import com.android.settings.network.telephony.gsm.OpenNetworkSelectPagePreferenc
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -70,6 +72,10 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings {
|
||||
private UserManager mUserManager;
|
||||
private String mClickedPrefKey;
|
||||
|
||||
private ActiveSubsciptionsListener mActiveSubsciptionsListener;
|
||||
private boolean mActiveSubsciptionsListenerStarting;
|
||||
private int mActiveSubsciptionsListenerCount;
|
||||
|
||||
public MobileNetworkSettings() {
|
||||
super(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);
|
||||
}
|
||||
@@ -197,6 +203,38 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings {
|
||||
onRestoreInstance(icicle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (mActiveSubsciptionsListener == null) {
|
||||
mActiveSubsciptionsListenerStarting = true;
|
||||
mActiveSubsciptionsListener = new ActiveSubsciptionsListener(
|
||||
getContext().getMainLooper(), getContext(), mSubId) {
|
||||
public void onChanged() {
|
||||
onSubscriptionDetailChanged();
|
||||
}
|
||||
};
|
||||
mActiveSubsciptionsListenerStarting = false;
|
||||
}
|
||||
mActiveSubsciptionsListener.start();
|
||||
}
|
||||
|
||||
private void onSubscriptionDetailChanged() {
|
||||
if (mActiveSubsciptionsListenerStarting) {
|
||||
Log.d(LOG_TAG, "Callback during onResume()");
|
||||
return;
|
||||
}
|
||||
mActiveSubsciptionsListenerCount++;
|
||||
if (mActiveSubsciptionsListenerCount != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
ThreadUtils.postOnMainThread(() -> {
|
||||
mActiveSubsciptionsListenerCount = 0;
|
||||
redrawPreferenceControllers();
|
||||
});
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void onRestoreInstance(Bundle icicle) {
|
||||
if (icicle != null) {
|
||||
|
Reference in New Issue
Block a user