From 8b26dd27e829f3e2bb6e03833303c5e3839c604d Mon Sep 17 00:00:00 2001 From: Antony Sargent Date: Fri, 8 Mar 2019 11:23:21 -0800 Subject: [PATCH] Fix unit test problems in MobileNetworkSummaryController There were two failing tests due to problems in this class: -PreferenceControllerContractTest -SettingsSearchIndexablesProviderTest In one case it was because we weren't checking for a valid Lifecycle, and in the other it wasn't implementing PreferenceControllerMixin (or inheriting from BasePreferenceController). Bug: 127524919 Test: atest SettingsUnitTests Change-Id: I662e300d68a21c28e1efb3ec9e23c4a882497176 --- .../network/MobileNetworkSummaryController.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/network/MobileNetworkSummaryController.java b/src/com/android/settings/network/MobileNetworkSummaryController.java index dd282c6d485..392a8f5ed25 100644 --- a/src/com/android/settings/network/MobileNetworkSummaryController.java +++ b/src/com/android/settings/network/MobileNetworkSummaryController.java @@ -29,6 +29,7 @@ import android.telephony.TelephonyManager; import android.telephony.euicc.EuiccManager; import com.android.settings.R; +import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.network.telephony.MobileNetworkActivity; import com.android.settings.widget.AddPreference; import com.android.settingslib.Utils; @@ -43,7 +44,8 @@ import androidx.preference.Preference; import androidx.preference.PreferenceScreen; public class MobileNetworkSummaryController extends AbstractPreferenceController implements - SubscriptionsChangeListener.SubscriptionsChangeListenerClient, LifecycleObserver { + SubscriptionsChangeListener.SubscriptionsChangeListenerClient, LifecycleObserver, + PreferenceControllerMixin { private static final String TAG = "MobileNetSummaryCtlr"; private static final String KEY = "mobile_network_list"; @@ -74,8 +76,10 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController mSubscriptionManager = context.getSystemService(SubscriptionManager.class); mTelephonyMgr = mContext.getSystemService(TelephonyManager.class); mEuiccManager = mContext.getSystemService(EuiccManager.class); - mChangeListener = new SubscriptionsChangeListener(context, this); - lifecycle.addObserver(this); + if (lifecycle != null) { + mChangeListener = new SubscriptionsChangeListener(context, this); + lifecycle.addObserver(this); + } } @OnLifecycleEvent(ON_RESUME)