Clean up lifecycle in MobileNetworkSettings
To avoid double registering, which prevent potential issues and could
improve latency.
Since DashboardFragment already supported register lifecycle
automatically for the controllers bound by XML which implements
androidx.lifecycle.Lifecycle, so doing a cleanup to prevent register
lifecycle event manually (doubling).
Bug: 149338098
Test: temporarily add logging to make sure the lifecycle method is
called and only called once
Change-Id: I4dbc36414991ef6b599be61aa77ff0dc8c52468c
This commit is contained in:
@@ -111,7 +111,7 @@ public class EnabledNetworkModePreferenceControllerTest {
|
||||
mController = new EnabledNetworkModePreferenceController(mContext, KEY);
|
||||
mockAllowedNetworkTypes(ALLOWED_ALL_NETWORK_TYPE);
|
||||
mockAccessFamily(TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
|
||||
mController.init(mLifecycle, SUB_ID);
|
||||
mController.init(SUB_ID);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ public class EnabledNetworkModePreferenceControllerTest {
|
||||
public void updateState_5gWorldPhone_GlobalHasNr() {
|
||||
mockAllowedNetworkTypes(ALLOWED_ALL_NETWORK_TYPE);
|
||||
mockAccessFamily(TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA);
|
||||
mController.init(mLifecycle, SUB_ID);
|
||||
mController.init(SUB_ID);
|
||||
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
@@ -221,7 +221,7 @@ public class EnabledNetworkModePreferenceControllerTest {
|
||||
mockAllowedNetworkTypes(ALLOWED_ALL_NETWORK_TYPE);
|
||||
mockEnabledNetworkMode(TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);
|
||||
mockAccessFamily(TelephonyManager.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);
|
||||
mController.init(mLifecycle, SUB_ID);
|
||||
mController.init(SUB_ID);
|
||||
|
||||
// NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA = NR | LTE | RAF_TD_SCDMA | GSM | WCDMA
|
||||
when(mTelephonyManager.getAllowedNetworkTypesForReason(
|
||||
@@ -241,7 +241,7 @@ public class EnabledNetworkModePreferenceControllerTest {
|
||||
mockEnabledNetworkMode(TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);
|
||||
mockAccessFamily(TelephonyManager.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);
|
||||
mockAllowedNetworkTypes(DISABLED_5G_NETWORK_TYPE);
|
||||
mController.init(mLifecycle, SUB_ID);
|
||||
mController.init(SUB_ID);
|
||||
|
||||
// NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA = NR | LTE | RAF_TD_SCDMA | GSM | WCDMA
|
||||
when(mTelephonyManager.getAllowedNetworkTypesForReason(
|
||||
@@ -261,7 +261,7 @@ public class EnabledNetworkModePreferenceControllerTest {
|
||||
mockEnabledNetworkMode(TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);
|
||||
mockAccessFamily(TelephonyManager.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA);
|
||||
mockAllowedNetworkTypes(DISABLED_5G_NETWORK_TYPE);
|
||||
mController.init(mLifecycle, SUB_ID);
|
||||
mController.init(SUB_ID);
|
||||
|
||||
// NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA = NR | LTE | RAF_TD_SCDMA | GSM | WCDMA
|
||||
when(mTelephonyManager.getAllowedNetworkTypesForReason(
|
||||
@@ -281,7 +281,7 @@ public class EnabledNetworkModePreferenceControllerTest {
|
||||
mockAccessFamily(TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA);
|
||||
mockAllowedNetworkTypes(DISABLED_5G_NETWORK_TYPE);
|
||||
|
||||
mController.init(mLifecycle, SUB_ID);
|
||||
mController.init(SUB_ID);
|
||||
|
||||
// NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA = LTE | CDMA | EVDO | GSM | WCDMA
|
||||
when(mTelephonyManager.getAllowedNetworkTypesForReason(
|
||||
@@ -304,7 +304,7 @@ public class EnabledNetworkModePreferenceControllerTest {
|
||||
public void updateState_GlobalDisAllowed5g_GlobalWithoutNR() {
|
||||
mockAccessFamily(TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA);
|
||||
mockAllowedNetworkTypes(DISABLED_5G_NETWORK_TYPE);
|
||||
mController.init(mLifecycle, SUB_ID);
|
||||
mController.init(SUB_ID);
|
||||
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);
|
||||
|
||||
// NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA = NR | LTE | CDMA | EVDO | GSM | WCDMA
|
||||
@@ -324,7 +324,7 @@ public class EnabledNetworkModePreferenceControllerTest {
|
||||
public void updateState_GlobalDisAllowed5g_SelectOnGlobal() {
|
||||
mockAccessFamily(TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA);
|
||||
mockAllowedNetworkTypes(DISABLED_5G_NETWORK_TYPE);
|
||||
mController.init(mLifecycle, SUB_ID);
|
||||
mController.init(SUB_ID);
|
||||
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);
|
||||
|
||||
// NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA = NR | LTE | CDMA | EVDO | GSM | WCDMA
|
||||
|
||||
@@ -32,8 +32,6 @@ import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -48,8 +46,6 @@ public class DisabledSubscriptionControllerTest {
|
||||
|
||||
@Mock
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
@Mock
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
private PreferenceScreen mScreen;
|
||||
private PreferenceManager mPreferenceManager;
|
||||
@@ -72,7 +68,7 @@ public class DisabledSubscriptionControllerTest {
|
||||
mScreen.addPreference(mCategory);
|
||||
|
||||
mController = new DisabledSubscriptionController(mContext, KEY);
|
||||
mController.init(mLifecycle, SUB_ID);
|
||||
mController.init(SUB_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -48,7 +48,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.network.SubscriptionUtil;
|
||||
import com.android.settings.widget.SettingsMainSwitchPreference;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -67,8 +66,6 @@ public class MobileNetworkSwitchControllerTest {
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
@Mock
|
||||
private SubscriptionInfo mSubscription;
|
||||
@Mock
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
private PreferenceScreen mScreen;
|
||||
private PreferenceManager mPreferenceManager;
|
||||
@@ -94,7 +91,7 @@ public class MobileNetworkSwitchControllerTest {
|
||||
|
||||
final String key = "prefKey";
|
||||
mController = new MobileNetworkSwitchController(mContext, key);
|
||||
mController.init(mLifecycle, mSubscription.getSubscriptionId());
|
||||
mController.init(mSubscription.getSubscriptionId());
|
||||
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
|
||||
@@ -31,7 +31,6 @@ import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
@@ -62,8 +61,6 @@ public class AutoSelectPreferenceControllerTest {
|
||||
private CarrierConfigCache mCarrierConfigCache;
|
||||
@Mock
|
||||
private ProgressDialog mProgressDialog;
|
||||
@Mock
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
private PersistableBundle mCarrierConfig;
|
||||
private AutoSelectPreferenceController mController;
|
||||
@@ -91,7 +88,7 @@ public class AutoSelectPreferenceControllerTest {
|
||||
mController = new AutoSelectPreferenceController(mContext, "auto_select");
|
||||
mController.mProgressDialog = mProgressDialog;
|
||||
mController.mSwitchPreference = mSwitchPreference;
|
||||
mController.init(mLifecycle, SUB_ID);
|
||||
mController.init(SUB_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,6 +136,6 @@ public class AutoSelectPreferenceControllerTest {
|
||||
when(mCarrierConfigCache.getConfigForSubId(SUB_ID)).thenReturn(null);
|
||||
|
||||
// Should not crash
|
||||
mController.init(mLifecycle, SUB_ID);
|
||||
mController.init(SUB_ID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
@@ -59,8 +58,6 @@ public class OpenNetworkSelectPagePreferenceControllerTest {
|
||||
private ServiceState mServiceState;
|
||||
@Mock
|
||||
private SubscriptionInfo mSubscriptionInfo;
|
||||
@Mock
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
private PersistableBundle mCarrierConfig;
|
||||
private OpenNetworkSelectPagePreferenceController mController;
|
||||
@@ -99,7 +96,7 @@ public class OpenNetworkSelectPagePreferenceControllerTest {
|
||||
super.updateState(mPreference);
|
||||
}
|
||||
};
|
||||
mController.init(mLifecycle, SUB_ID);
|
||||
mController.init(SUB_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user