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