From 77f9cbe3152b0727fe4f4ac86e45320807912a8f Mon Sep 17 00:00:00 2001 From: Weng Su Date: Tue, 24 May 2022 03:13:03 +0800 Subject: [PATCH 1/5] Refine carrier Wi-Fi functions - Sync the same design to query and set carrier Wi-Fi enabled status from MergedCarrierEntry - Add more logs for issue tracking Bug: 227236604 Test: manual test atest -c CarrierWifiTogglePreferenceControllerTest \ WifiPickerTrackerHelperTest Change-Id: I869fa97bd24ed31a3224b4a395ffc97a17aa1471 --- .../CarrierWifiTogglePreferenceController.java | 3 +-- .../settings/wifi/WifiPickerTrackerHelper.java | 13 +++++++++++-- .../CarrierWifiTogglePreferenceControllerTest.java | 4 ++-- .../settings/wifi/WifiPickerTrackerHelperTest.java | 10 ++++------ 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/com/android/settings/network/CarrierWifiTogglePreferenceController.java b/src/com/android/settings/network/CarrierWifiTogglePreferenceController.java index af2c0a52531..ce225b4b529 100644 --- a/src/com/android/settings/network/CarrierWifiTogglePreferenceController.java +++ b/src/com/android/settings/network/CarrierWifiTogglePreferenceController.java @@ -23,7 +23,6 @@ import androidx.preference.Preference; import androidx.preference.PreferenceScreen; import com.android.settings.R; -import com.android.settings.Utils; import com.android.settings.core.TogglePreferenceController; import com.android.settings.wifi.WifiPickerTrackerHelper; import com.android.wifitrackerlib.WifiPickerTracker; @@ -65,7 +64,7 @@ public class CarrierWifiTogglePreferenceController extends TogglePreferenceContr @Override public boolean isChecked() { - return mWifiPickerTrackerHelper.isCarrierNetworkEnabled(mSubId); + return mWifiPickerTrackerHelper.isCarrierNetworkEnabled(); } @Override diff --git a/src/com/android/settings/wifi/WifiPickerTrackerHelper.java b/src/com/android/settings/wifi/WifiPickerTrackerHelper.java index 1be71c8cc65..3aa7b834638 100644 --- a/src/com/android/settings/wifi/WifiPickerTrackerHelper.java +++ b/src/com/android/settings/wifi/WifiPickerTrackerHelper.java @@ -117,16 +117,25 @@ public class WifiPickerTrackerHelper implements LifecycleObserver { } /** Return the enabled/disabled state of the carrier network */ - public boolean isCarrierNetworkEnabled(int subId) { - return mWifiManager.isCarrierNetworkOffloadEnabled(subId, true /* merged */); + public boolean isCarrierNetworkEnabled() { + final MergedCarrierEntry mergedCarrierEntry = mWifiPickerTracker.getMergedCarrierEntry(); + if (mergedCarrierEntry == null) { + Log.e(TAG, "Failed to get MergedCarrierEntry to query enabled status"); + return false; + } + final boolean isCarrierNetworkEnabled = mergedCarrierEntry.isEnabled(); + Log.i(TAG, "isCarrierNetworkEnabled:" + isCarrierNetworkEnabled); + return isCarrierNetworkEnabled; } /** Enables/disables the carrier network */ public void setCarrierNetworkEnabled(boolean enabled) { final MergedCarrierEntry mergedCarrierEntry = mWifiPickerTracker.getMergedCarrierEntry(); if (mergedCarrierEntry == null) { + Log.e(TAG, "Unable to get MergedCarrierEntry to set enabled status"); return; } + Log.i(TAG, "setCarrierNetworkEnabled:" + enabled); mergedCarrierEntry.setEnabled(enabled); } diff --git a/tests/unit/src/com/android/settings/network/CarrierWifiTogglePreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/CarrierWifiTogglePreferenceControllerTest.java index 21a8444b687..480d74480d8 100644 --- a/tests/unit/src/com/android/settings/network/CarrierWifiTogglePreferenceControllerTest.java +++ b/tests/unit/src/com/android/settings/network/CarrierWifiTogglePreferenceControllerTest.java @@ -107,14 +107,14 @@ public class CarrierWifiTogglePreferenceControllerTest { @Test public void isChecked_carrierNetworkEnabled_returnTrue() { - doReturn(true).when(mWifiPickerTrackerHelper).isCarrierNetworkEnabled(SUB_ID); + doReturn(true).when(mWifiPickerTrackerHelper).isCarrierNetworkEnabled(); assertThat(mController.isChecked()).isEqualTo(true); } @Test public void isChecked_carrierNetworkDisabled_returnFalse() { - doReturn(false).when(mWifiPickerTrackerHelper).isCarrierNetworkEnabled(SUB_ID); + doReturn(false).when(mWifiPickerTrackerHelper).isCarrierNetworkEnabled(); assertThat(mController.isChecked()).isEqualTo(false); } diff --git a/tests/unit/src/com/android/settings/wifi/WifiPickerTrackerHelperTest.java b/tests/unit/src/com/android/settings/wifi/WifiPickerTrackerHelperTest.java index 1c0cf0429cb..b79dd459d5b 100644 --- a/tests/unit/src/com/android/settings/wifi/WifiPickerTrackerHelperTest.java +++ b/tests/unit/src/com/android/settings/wifi/WifiPickerTrackerHelperTest.java @@ -24,7 +24,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -135,14 +134,13 @@ public class WifiPickerTrackerHelperTest { @Test public void isCarrierNetworkEnabled_returnCorrect() { - doReturn(true).when(mWifiManager).isCarrierNetworkOffloadEnabled(SUB_ID, true /* merged */); + when(mMergedCarrierEntry.isEnabled()).thenReturn(true); - assertThat(mWifiPickerTrackerHelper.isCarrierNetworkEnabled(SUB_ID)).isTrue(); + assertThat(mWifiPickerTrackerHelper.isCarrierNetworkEnabled()).isTrue(); - doReturn(false).when(mWifiManager) - .isCarrierNetworkOffloadEnabled(SUB_ID, true /* merged */); + when(mMergedCarrierEntry.isEnabled()).thenReturn(false); - assertThat(mWifiPickerTrackerHelper.isCarrierNetworkEnabled(SUB_ID)).isFalse(); + assertThat(mWifiPickerTrackerHelper.isCarrierNetworkEnabled()).isFalse(); } @Test From 2e34038233a99cefbf432d2b68851048246dfecb Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Tue, 24 May 2022 18:00:34 +0800 Subject: [PATCH 2/5] Fix crash for DefaultSubscriptionController setSummaryProvider() is used instead of setSummary() in Ia24d88817c99db7ed3fc264dbc9c10e0a09d8a39, but there is still a place using the setSummary(), mixing these two will lead to crash. Change it to setSummaryProvider() to prevent crash. Fix: 233295254 Fix: 233712251 Test: manual Change-Id: I4627545711b848009c3bd7179f0368ff82e62697 --- .../network/telephony/DefaultSubscriptionController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java index 5511829a61a..a3a281c4198 100644 --- a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java +++ b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java @@ -168,8 +168,8 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere if (subs.size() == 1) { mPreference.setEnabled(false); - mPreference.setSummary(SubscriptionUtil.getUniqueSubscriptionDisplayName( - subs.get(0), mContext)); + mPreference.setSummaryProvider(pref -> + SubscriptionUtil.getUniqueSubscriptionDisplayName(subs.get(0), mContext)); return; } From bd369cfee5bdb4d175d92037d3a3cb538d63910d Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Thu, 19 May 2022 16:27:18 +0800 Subject: [PATCH 3/5] Fix Conversation page flickers In this page, 3 conversation lists are implemented by the ConversationListPreferenceController, these lists updates its contents in updateState(), which is after the preference screen view created. So when the first time this page is showed, animations of added contents will be shown. The improvement is when the first time, update the list in the onCreate(), which is called before view creation, instead of the updateState(). And also do the same thing for RecentConversationsPreferenceController. Also, to reduce latency, 1. Because currently there are duplicated calls in NoConversationsPreferenceController to check whether conversations are exists or not, by removing the duplicated calls and reuse the result from other controllers, the latency could be reduced. 2. Currently, there are seperated api calls, the mBackend.getConversations(false) in AllConversationsPreferenceController and the mBackend.getConversations(true) in PriorityConversationsPreferenceController, use one mBackend.getConversations(false) in ConversationListSettings to improve, this does not change the behavior because the result is filtered in matchesFilter() both before and after. 3. Currently, we sort conversations first then filter them, change to filter first then sort to reduce latency. Fix: 215073227 Test: visual check & robo tests Change-Id: I028a7fabbbf64cf5627e6615372282a36eb784e5 --- res/layout/conversation_onboarding.xml | 2 - .../AllConversationsPreferenceController.java | 26 +--- .../ConversationListPreferenceController.java | 63 ++++++---- .../app/ConversationListSettings.java | 50 +++++++- .../NoConversationsPreferenceController.java | 64 ++-------- ...rityConversationsPreferenceController.java | 24 +--- ...centConversationsPreferenceController.java | 114 ++++++++++-------- ...versationListPreferenceControllerTest.java | 65 +++++----- ...ConversationsPreferenceControllerTest.java | 103 ++++++---------- 9 files changed, 220 insertions(+), 291 deletions(-) diff --git a/res/layout/conversation_onboarding.xml b/res/layout/conversation_onboarding.xml index 5d727f6b8f9..5cf36cdfffa 100644 --- a/res/layout/conversation_onboarding.xml +++ b/res/layout/conversation_onboarding.xml @@ -15,12 +15,10 @@ --> mConversations; - - public AllConversationsPreferenceController(Context context, - NotificationBackend backend) { + public AllConversationsPreferenceController(Context context, NotificationBackend backend) { super(context, backend); } @@ -45,11 +37,6 @@ public class AllConversationsPreferenceController extends ConversationListPrefer return KEY; } - @Override - public boolean isAvailable() { - return true; - } - @Override Preference getSummaryPreference() { Preference pref = new Preference(mContext); @@ -63,15 +50,4 @@ public class AllConversationsPreferenceController extends ConversationListPrefer boolean matchesFilter(ConversationChannelWrapper conversation) { return !conversation.getNotificationChannel().isImportantConversation(); } - - @Override - public void updateState(Preference preference) { - PreferenceCategory pref = (PreferenceCategory) preference; - // Load conversations - - mConversations = mBackend.getConversations(false).getList(); - Collections.sort(mConversations, mConversationComparator); - - populateList(mConversations, pref); - } } diff --git a/src/com/android/settings/notification/app/ConversationListPreferenceController.java b/src/com/android/settings/notification/app/ConversationListPreferenceController.java index 29f0dea6991..f893df305e8 100644 --- a/src/com/android/settings/notification/app/ConversationListPreferenceController.java +++ b/src/com/android/settings/notification/app/ConversationListPreferenceController.java @@ -25,8 +25,10 @@ import android.provider.Settings; import android.service.notification.ConversationChannelWrapper; import android.text.TextUtils; +import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import androidx.preference.PreferenceGroup; +import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.applications.AppInfoBase; @@ -38,14 +40,15 @@ import com.android.settingslib.widget.AppPreference; import java.text.Collator; import java.util.Comparator; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; public abstract class ConversationListPreferenceController extends AbstractPreferenceController { private static final String SUMMARY_KEY_SUFFIX = "_summary"; protected final NotificationBackend mBackend; + private PreferenceGroup mPreferenceGroup; - public ConversationListPreferenceController(Context context, - NotificationBackend backend) { + public ConversationListPreferenceController(Context context, NotificationBackend backend) { super(context); mBackend = backend; } @@ -55,44 +58,55 @@ public abstract class ConversationListPreferenceController extends AbstractPrefe return true; } - protected void populateList(List conversations, - PreferenceGroup containerGroup) { - containerGroup.setVisible(false); - containerGroup.removeAll(); + @Override + public void displayPreference(PreferenceScreen screen) { + super.displayPreference(screen); + mPreferenceGroup = screen.findPreference(getPreferenceKey()); + } + + /** + * Updates the conversation list. + * @return true if this controller has content to display. + */ + boolean updateList(List conversations) { + mPreferenceGroup.setVisible(false); + mPreferenceGroup.removeAll(); if (conversations != null) { - populateConversations(conversations, containerGroup); + populateConversations(conversations); } - if (containerGroup.getPreferenceCount() != 0) { + boolean hasContent = mPreferenceGroup.getPreferenceCount() != 0; + if (hasContent) { Preference summaryPref = getSummaryPreference(); if (summaryPref != null) { summaryPref.setKey(getPreferenceKey() + SUMMARY_KEY_SUFFIX); - containerGroup.addPreference(summaryPref); + mPreferenceGroup.addPreference(summaryPref); } - containerGroup.setVisible(true); + mPreferenceGroup.setVisible(true); } + return hasContent; } abstract Preference getSummaryPreference(); abstract boolean matchesFilter(ConversationChannelWrapper conversation); - protected void populateConversations(List conversations, - PreferenceGroup containerGroup) { - int order = 100; - for (ConversationChannelWrapper conversation : conversations) { - if (conversation.getNotificationChannel().isDemoted() - || !matchesFilter(conversation)) { - continue; - } - containerGroup.addPreference(createConversationPref(conversation, order++)); - } + @VisibleForTesting + void populateConversations(List conversations) { + AtomicInteger order = new AtomicInteger(100); + conversations.stream() + .filter(conversation -> !conversation.getNotificationChannel().isDemoted() + && matchesFilter(conversation)) + .sorted(mConversationComparator) + .map(this::createConversationPref) + .forEachOrdered(preference -> { + preference.setOrder(order.getAndIncrement()); + mPreferenceGroup.addPreference(preference); + }); } - protected Preference createConversationPref(final ConversationChannelWrapper conversation, - int order) { + private Preference createConversationPref(final ConversationChannelWrapper conversation) { AppPreference pref = new AppPreference(mContext); - pref.setOrder(order); pref.setTitle(getTitle(conversation)); pref.setSummary(getSummary(conversation)); @@ -141,7 +155,8 @@ public abstract class ConversationListPreferenceController extends AbstractPrefe .setSourceMetricsCategory(SettingsEnums.NOTIFICATION_CONVERSATION_LIST_SETTINGS); } - protected Comparator mConversationComparator = + @VisibleForTesting + Comparator mConversationComparator = new Comparator() { private final Collator sCollator = Collator.getInstance(); @Override diff --git a/src/com/android/settings/notification/app/ConversationListSettings.java b/src/com/android/settings/notification/app/ConversationListSettings.java index 83fc072adbb..f2db47daffe 100644 --- a/src/com/android/settings/notification/app/ConversationListSettings.java +++ b/src/com/android/settings/notification/app/ConversationListSettings.java @@ -19,8 +19,9 @@ package com.android.settings.notification.app; import android.app.people.IPeopleManager; import android.app.settings.SettingsEnums; import android.content.Context; +import android.os.Bundle; import android.os.ServiceManager; -import android.util.Log; +import android.service.notification.ConversationChannelWrapper; import com.android.settings.R; import com.android.settings.dashboard.DashboardFragment; @@ -32,12 +33,16 @@ import java.util.List; public class ConversationListSettings extends DashboardFragment { private static final String TAG = "ConvoListSettings"; - private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); NotificationBackend mBackend = new NotificationBackend(); IPeopleManager mPs; protected List mControllers = new ArrayList<>(); + private NoConversationsPreferenceController mNoConversationsController; + private PriorityConversationsPreferenceController mPriorityConversationsController; + private AllConversationsPreferenceController mAllConversationsController; + private RecentConversationsPreferenceController mRecentConversationsController; + private boolean mUpdatedInOnCreate = false; public ConversationListSettings() { mPs = IPeopleManager.Stub.asInterface( @@ -62,10 +67,43 @@ public class ConversationListSettings extends DashboardFragment { @Override protected List createPreferenceControllers(Context context) { mControllers = new ArrayList<>(); - mControllers.add(new NoConversationsPreferenceController(context, mBackend, mPs)); - mControllers.add(new PriorityConversationsPreferenceController(context, mBackend)); - mControllers.add(new AllConversationsPreferenceController(context, mBackend)); - mControllers.add(new RecentConversationsPreferenceController(context, mBackend, mPs)); + mNoConversationsController = new NoConversationsPreferenceController(context); + mControllers.add(mNoConversationsController); + mPriorityConversationsController = + new PriorityConversationsPreferenceController(context, mBackend); + mControllers.add(mPriorityConversationsController); + mAllConversationsController = new AllConversationsPreferenceController(context, mBackend); + mControllers.add(mAllConversationsController); + mRecentConversationsController = + new RecentConversationsPreferenceController(context, mBackend, mPs); + mControllers.add(mRecentConversationsController); return new ArrayList<>(mControllers); } + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + update(); + mUpdatedInOnCreate = true; + } + + @Override + public void onStart() { + super.onStart(); + if (mUpdatedInOnCreate) { + mUpdatedInOnCreate = false; + } else { + update(); + } + } + + private void update() { + List conversationList = + mBackend.getConversations(false).getList(); + boolean hasContent = mPriorityConversationsController.updateList(conversationList) + | mAllConversationsController.updateList(conversationList) + | mRecentConversationsController.updateList(); + mNoConversationsController.setAvailable(!hasContent); + mNoConversationsController.displayPreference(getPreferenceScreen()); + } } diff --git a/src/com/android/settings/notification/app/NoConversationsPreferenceController.java b/src/com/android/settings/notification/app/NoConversationsPreferenceController.java index 475d90d50f3..21b87188eb6 100644 --- a/src/com/android/settings/notification/app/NoConversationsPreferenceController.java +++ b/src/com/android/settings/notification/app/NoConversationsPreferenceController.java @@ -16,32 +16,18 @@ package com.android.settings.notification.app; -import android.app.people.IPeopleManager; import android.content.Context; -import android.os.AsyncTask; -import android.os.RemoteException; -import android.service.notification.ConversationChannelWrapper; -import android.util.Log; -import android.view.View; -import androidx.preference.Preference; +import com.android.settingslib.core.AbstractPreferenceController; -import com.android.settings.R; -import com.android.settings.notification.NotificationBackend; -import com.android.settingslib.widget.LayoutPreference; +class NoConversationsPreferenceController extends AbstractPreferenceController { -public class NoConversationsPreferenceController extends ConversationListPreferenceController { - - private static String TAG = "NoConversationsPC"; private static final String KEY = "no_conversations"; - private IPeopleManager mPs; - private int mConversationCount = 0; + private boolean mIsAvailable = false; - public NoConversationsPreferenceController(Context context, - NotificationBackend backend, IPeopleManager ps) { - super(context, backend); - mPs = ps; + NoConversationsPreferenceController(Context context) { + super(context); } @Override @@ -51,44 +37,10 @@ public class NoConversationsPreferenceController extends ConversationListPrefere @Override public boolean isAvailable() { - return true; + return mIsAvailable; } - @Override - Preference getSummaryPreference() { - return null; - } - - @Override - boolean matchesFilter(ConversationChannelWrapper conversation) { - return false; - } - - @Override - public void updateState(Preference preference) { - LayoutPreference pref = (LayoutPreference) preference; - // Load conversations - new AsyncTask() { - @Override - protected Void doInBackground(Void... unused) { - mConversationCount = mBackend.getConversations(false).getList().size(); - try { - mConversationCount += mPs.getRecentConversations().getList().size(); - } catch (RemoteException e) { - Log.w(TAG, "Error calling PS", e); - } - return null; - } - - @Override - protected void onPostExecute(Void unused) { - if (mContext == null) { - return; - } - pref.findViewById(R.id.onboarding).setVisibility(mConversationCount == 0 - ? View.VISIBLE : View.GONE); - preference.setVisible(mConversationCount == 0); - } - }.execute(); + void setAvailable(boolean available) { + mIsAvailable = available; } } diff --git a/src/com/android/settings/notification/app/PriorityConversationsPreferenceController.java b/src/com/android/settings/notification/app/PriorityConversationsPreferenceController.java index 3fb605bd2fe..18fc9178510 100644 --- a/src/com/android/settings/notification/app/PriorityConversationsPreferenceController.java +++ b/src/com/android/settings/notification/app/PriorityConversationsPreferenceController.java @@ -17,26 +17,19 @@ package com.android.settings.notification.app; import android.content.Context; -import android.os.AsyncTask; import android.service.notification.ConversationChannelWrapper; import androidx.preference.Preference; -import androidx.preference.PreferenceCategory; import com.android.settings.R; import com.android.settings.notification.NotificationBackend; -import java.util.Collections; -import java.util.List; - public class PriorityConversationsPreferenceController extends ConversationListPreferenceController { private static final String KEY = "important_conversations"; - private List mConversations; - public PriorityConversationsPreferenceController(Context context, - NotificationBackend backend) { + public PriorityConversationsPreferenceController(Context context, NotificationBackend backend) { super(context, backend); } @@ -45,11 +38,6 @@ public class PriorityConversationsPreferenceController extends return KEY; } - @Override - public boolean isAvailable() { - return true; - } - @Override Preference getSummaryPreference() { Preference pref = new Preference(mContext); @@ -63,14 +51,4 @@ public class PriorityConversationsPreferenceController extends boolean matchesFilter(ConversationChannelWrapper conversation) { return conversation.getNotificationChannel().isImportantConversation(); } - - @Override - public void updateState(Preference preference) { - PreferenceCategory pref = (PreferenceCategory) preference; - // Load conversations - mConversations = mBackend.getConversations(true).getList(); - Collections.sort(mConversations, mConversationComparator); - - populateList(mConversations, pref); - } } diff --git a/src/com/android/settings/notification/app/RecentConversationsPreferenceController.java b/src/com/android/settings/notification/app/RecentConversationsPreferenceController.java index 4d8cefef5e8..f5f2e97090b 100644 --- a/src/com/android/settings/notification/app/RecentConversationsPreferenceController.java +++ b/src/com/android/settings/notification/app/RecentConversationsPreferenceController.java @@ -30,9 +30,10 @@ import android.provider.Settings; import android.util.Slog; import android.widget.Button; +import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; -import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceGroup; +import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.applications.AppInfoBase; @@ -45,18 +46,20 @@ import java.text.Collator; import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; public class RecentConversationsPreferenceController extends AbstractPreferenceController { private static final String TAG = "RecentConversationsPC"; private static final String KEY = "recent_conversations"; private static final String CLEAR_ALL_KEY_SUFFIX = "_clear_all"; - private List mConversations; private final IPeopleManager mPs; private final NotificationBackend mBackend; + private PreferenceGroup mPreferenceGroup; - public RecentConversationsPreferenceController(Context context, NotificationBackend backend, - IPeopleManager ps) { + public RecentConversationsPreferenceController( + Context context, NotificationBackend backend, IPeopleManager ps) { super(context); mBackend = backend; mPs = ps; @@ -103,63 +106,69 @@ public class RecentConversationsPreferenceController extends AbstractPreferenceC } @Override - public void updateState(Preference preference) { - PreferenceCategory pref = (PreferenceCategory) preference; - // Load conversations - try { - mConversations = mPs.getRecentConversations().getList(); - } catch (RemoteException e) { - Slog.w(TAG, "Could get recents", e); - } - Collections.sort(mConversations, mConversationComparator); - - populateList(mConversations, pref); - + public void displayPreference(PreferenceScreen screen) { + super.displayPreference(screen); + mPreferenceGroup = screen.findPreference(getPreferenceKey()); } - protected void populateList(List conversations, - PreferenceGroup containerGroup) { - containerGroup.removeAll(); + /** + * Updates the conversation list. + * + * @return true if this controller has content to display. + */ + boolean updateList() { + // Load conversations + List conversations = Collections.emptyList(); + try { + conversations = mPs.getRecentConversations().getList(); + } catch (RemoteException e) { + Slog.w(TAG, "Could not get recent conversations", e); + } + + return populateList(conversations); + } + + @VisibleForTesting + boolean populateList(List conversations) { + mPreferenceGroup.removeAll(); boolean hasClearable = false; if (conversations != null) { - hasClearable = populateConversations(conversations, containerGroup); + hasClearable = populateConversations(conversations); } - if (containerGroup.getPreferenceCount() == 0) { - containerGroup.setVisible(false); - } else { - containerGroup.setVisible(true); - if (hasClearable) { - Preference clearAll = getClearAll(containerGroup); - if (clearAll != null) { - containerGroup.addPreference(clearAll); - } + boolean hashContent = mPreferenceGroup.getPreferenceCount() != 0; + mPreferenceGroup.setVisible(hashContent); + if (hashContent && hasClearable) { + Preference clearAll = getClearAll(mPreferenceGroup); + if (clearAll != null) { + mPreferenceGroup.addPreference(clearAll); } } + return hashContent; } - protected boolean populateConversations(List conversations, - PreferenceGroup containerGroup) { - int order = 100; - boolean hasClearable = false; - for (ConversationChannel conversation : conversations) { - if (conversation.getNotificationChannel().getImportance() == IMPORTANCE_NONE - || (conversation.getNotificationChannelGroup() != null - && conversation.getNotificationChannelGroup().isBlocked())) { - continue; - } - RecentConversationPreference pref = - createConversationPref(containerGroup, conversation, order++); - containerGroup.addPreference(pref); - if (pref.hasClearListener()) { - hasClearable = true; - } - } - return hasClearable; + protected boolean populateConversations(List conversations) { + AtomicInteger order = new AtomicInteger(100); + AtomicBoolean hasClearable = new AtomicBoolean(false); + conversations.stream() + .filter(conversation -> + conversation.getNotificationChannel().getImportance() != IMPORTANCE_NONE + && (conversation.getNotificationChannelGroup() == null + || !conversation.getNotificationChannelGroup().isBlocked())) + .sorted(mConversationComparator) + .map(this::createConversationPref) + .forEachOrdered(pref -> { + pref.setOrder(order.getAndIncrement()); + mPreferenceGroup.addPreference(pref); + if (pref.hasClearListener()) { + hasClearable.set(true); + } + }); + return hasClearable.get(); } - protected RecentConversationPreference createConversationPref(PreferenceGroup parent, - final ConversationChannel conversation, int order) { + protected RecentConversationPreference createConversationPref( + final ConversationChannel conversation) { final String pkg = conversation.getShortcutInfo().getPackage(); final int uid = conversation.getUid(); final String conversationId = conversation.getShortcutInfo().getId(); @@ -171,13 +180,12 @@ public class RecentConversationsPreferenceController extends AbstractPreferenceC mPs.removeRecentConversation(pkg, UserHandle.getUserId(uid), conversationId); pref.getClearView().announceForAccessibility( mContext.getString(R.string.recent_convo_removed)); - parent.removePreference(pref); + mPreferenceGroup.removePreference(pref); } catch (RemoteException e) { Slog.w(TAG, "Could not clear recent", e); } }); } - pref.setOrder(order); pref.setTitle(getTitle(conversation)); pref.setSummary(getSummary(conversation)); @@ -230,9 +238,11 @@ public class RecentConversationsPreferenceController extends AbstractPreferenceC .setSourceMetricsCategory(SettingsEnums.NOTIFICATION_CONVERSATION_LIST_SETTINGS); } - protected Comparator mConversationComparator = + @VisibleForTesting + Comparator mConversationComparator = new Comparator() { private final Collator sCollator = Collator.getInstance(); + @Override public int compare(ConversationChannel o1, ConversationChannel o2) { int labelComparison = 0; diff --git a/tests/robotests/src/com/android/settings/notification/app/ConversationListPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/ConversationListPreferenceControllerTest.java index 8113f22826e..aaa2f24f091 100644 --- a/tests/robotests/src/com/android/settings/notification/app/ConversationListPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/ConversationListPreferenceControllerTest.java @@ -21,7 +21,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -35,47 +34,49 @@ import android.provider.Settings; import android.service.notification.ConversationChannelWrapper; import android.text.SpannableStringBuilder; import android.text.Spanned; -import android.text.style.BulletSpan; -import android.text.style.QuoteSpan; import android.text.style.SubscriptSpan; -import android.text.style.UnderlineSpan; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; +import androidx.preference.PreferenceGroup; import androidx.preference.PreferenceManager; import androidx.preference.PreferenceScreen; +import androidx.test.core.app.ApplicationProvider; import com.android.settings.applications.AppInfoBase; import com.android.settings.notification.NotificationBackend; +import com.google.common.collect.ImmutableList; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Answers; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.mockito.Spy; import org.robolectric.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; -import org.robolectric.shadows.ShadowApplication; - -import java.util.ArrayList; @RunWith(RobolectricTestRunner.class) public class ConversationListPreferenceControllerTest { - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private Context mContext; + private final Context mContext = ApplicationProvider.getApplicationContext(); @Mock private NotificationBackend mBackend; + @Spy + private PreferenceGroup mPreferenceGroup = new PreferenceCategory(mContext); private TestPreferenceController mController; @Before public void setUp() { MockitoAnnotations.initMocks(this); - ShadowApplication shadowApplication = ShadowApplication.getInstance(); - mContext = RuntimeEnvironment.application; mController = new TestPreferenceController(mContext, mBackend); + + PreferenceManager preferenceManager = new PreferenceManager(mContext); + PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext); + mPreferenceGroup.setKey(mController.getPreferenceKey()); + preferenceScreen.addPreference(mPreferenceGroup); + mController.displayPreference(preferenceScreen); } @Test @@ -84,39 +85,30 @@ public class ConversationListPreferenceControllerTest { } @Test - public void testPopulateList_hideIfNoConversations() { - PreferenceCategory outerContainer = mock(PreferenceCategory.class); + public void testUpdateList_hideIfNoConversations() { + boolean hasContent = mController.updateList(ImmutableList.of()); - mController.populateList(new ArrayList<>(), outerContainer); - - verify(outerContainer).setVisible(false); - verify(outerContainer, never()).addPreference(any()); + assertThat(hasContent).isFalse(); + verify(mPreferenceGroup).setVisible(false); + verify(mPreferenceGroup, never()).addPreference(any()); } @Test - public void testPopulateList_validConversations() { - final PreferenceManager preferenceManager = new PreferenceManager(mContext); - PreferenceScreen ps = preferenceManager.createPreferenceScreen(mContext); - PreferenceCategory outerContainer = spy(new PreferenceCategory(mContext)); - ps.addPreference(outerContainer); - + public void testUpdateList_validConversations() { ConversationChannelWrapper ccw = new ConversationChannelWrapper(); ccw.setNotificationChannel(mock(NotificationChannel.class)); ccw.setPkg("pkg"); ccw.setUid(1); ccw.setShortcutInfo(mock(ShortcutInfo.class)); - ArrayList list = new ArrayList<>(); - list.add(ccw); + boolean hasContent = mController.updateList(ImmutableList.of(ccw)); - mController.populateList(list, outerContainer); - verify(outerContainer, times(1)).addPreference(any()); + assertThat(hasContent).isTrue(); + verify(mPreferenceGroup, times(1)).addPreference(any()); } @Test public void populateConversations() { - PreferenceCategory container = mock(PreferenceCategory.class); - ConversationChannelWrapper ccw = new ConversationChannelWrapper(); ccw.setNotificationChannel(mock(NotificationChannel.class)); ccw.setPkg("pkg"); @@ -131,13 +123,9 @@ public class ConversationListPreferenceControllerTest { ccwDemoted.setUid(1); ccwDemoted.setShortcutInfo(mock(ShortcutInfo.class)); - ArrayList list = new ArrayList<>(); - list.add(ccw); - list.add(ccwDemoted); + mController.populateConversations(ImmutableList.of(ccw, ccwDemoted)); - mController.populateConversations(list, container); - - verify(container, times(1)).addPreference(any()); + verify(mPreferenceGroup, times(1)).addPreference(any()); } @Test @@ -240,7 +228,8 @@ public class ConversationListPreferenceControllerTest { assertThat(mController.mConversationComparator.compare(one, two)).isLessThan(0); } - private final class TestPreferenceController extends ConversationListPreferenceController { + private static final class TestPreferenceController extends + ConversationListPreferenceController { private TestPreferenceController(Context context, NotificationBackend backend) { super(context, backend); diff --git a/tests/robotests/src/com/android/settings/notification/app/RecentConversationsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/RecentConversationsPreferenceControllerTest.java index 1688d63ec52..3c0a0f33349 100644 --- a/tests/robotests/src/com/android/settings/notification/app/RecentConversationsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/RecentConversationsPreferenceControllerTest.java @@ -37,9 +37,7 @@ import android.os.Bundle; import android.os.UserHandle; import android.provider.Settings; import android.text.SpannedString; -import android.view.LayoutInflater; import android.view.View; -import android.widget.LinearLayout; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; @@ -47,42 +45,46 @@ import androidx.preference.PreferenceGroup; import androidx.preference.PreferenceManager; import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceViewHolder; +import androidx.test.core.app.ApplicationProvider; import com.android.settings.R; import com.android.settings.applications.AppInfoBase; import com.android.settings.notification.NotificationBackend; import com.android.settingslib.widget.LayoutPreference; +import com.google.common.collect.ImmutableList; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Answers; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.mockito.Spy; import org.robolectric.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; -import org.robolectric.shadows.ShadowApplication; - -import java.util.ArrayList; @RunWith(RobolectricTestRunner.class) public class RecentConversationsPreferenceControllerTest { - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private Context mContext; + private final Context mContext = ApplicationProvider.getApplicationContext(); @Mock private NotificationBackend mBackend; @Mock private IPeopleManager mPs; + @Spy + private PreferenceGroup mPreferenceGroup = new PreferenceCategory(mContext); private RecentConversationsPreferenceController mController; @Before public void setUp() { MockitoAnnotations.initMocks(this); - ShadowApplication shadowApplication = ShadowApplication.getInstance(); - mContext = RuntimeEnvironment.application; mController = new RecentConversationsPreferenceController(mContext, mBackend, mPs); + + PreferenceManager preferenceManager = new PreferenceManager(mContext); + PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext); + mPreferenceGroup.setKey(mController.getPreferenceKey()); + preferenceScreen.addPreference(mPreferenceGroup); + mController.displayPreference(preferenceScreen); } @Test @@ -92,38 +94,29 @@ public class RecentConversationsPreferenceControllerTest { @Test public void testPopulateList_hideIfNoConversations() { - PreferenceCategory outerContainer = mock(PreferenceCategory.class); + boolean hasContent = mController.populateList(ImmutableList.of()); - mController.populateList(new ArrayList<>(), outerContainer); - - verify(outerContainer).setVisible(false); - verify(outerContainer, never()).addPreference(any()); + assertThat(hasContent).isFalse(); + verify(mPreferenceGroup).setVisible(false); + verify(mPreferenceGroup, never()).addPreference(any()); } @Test public void testPopulateList_validConversations() { - final PreferenceManager preferenceManager = new PreferenceManager(mContext); - PreferenceScreen ps = preferenceManager.createPreferenceScreen(mContext); - PreferenceCategory outerContainer = spy(new PreferenceCategory(mContext)); - ps.addPreference(outerContainer); - ConversationChannel ccw = new ConversationChannel(mock(ShortcutInfo.class), 6, new NotificationChannel("hi", "hi", 4), new NotificationChannelGroup("hi", "hi"), 7, false); - ArrayList list = new ArrayList<>(); - list.add(ccw); + boolean hasContent = mController.populateList(ImmutableList.of(ccw)); - mController.populateList(list, outerContainer); + assertThat(hasContent).isTrue(); // one for the preference, one for the button ro clear all - verify(outerContainer, times(2)).addPreference(any()); + verify(mPreferenceGroup, times(2)).addPreference(any()); } @Test public void populateConversations_blocked() { - PreferenceCategory container = mock(PreferenceCategory.class); - ConversationChannel ccw = new ConversationChannel(mock(ShortcutInfo.class), 6, new NotificationChannel("hi", "hi", 4), new NotificationChannelGroup("hi", "hi"), 7, @@ -141,14 +134,10 @@ public class RecentConversationsPreferenceControllerTest { blockedGroup, 7, false); - ArrayList list = new ArrayList<>(); - list.add(ccw); - list.add(ccw2); - list.add(ccw3); + boolean hasContent = mController.populateConversations(ImmutableList.of(ccw, ccw2, ccw3)); - mController.populateConversations(list, container); - - verify(container, times(1)).addPreference(any()); + assertThat(hasContent).isTrue(); + verify(mPreferenceGroup, times(1)).addPreference(any()); } @Test @@ -223,8 +212,7 @@ public class RecentConversationsPreferenceControllerTest { new NotificationChannelGroup("hi", "group"), 7, true); - Preference pref = mController.createConversationPref(new PreferenceCategory(mContext), - ccw, 100); + Preference pref = mController.createConversationPref(ccw); try { pref.performClick(); } catch (RuntimeException e) { @@ -244,9 +232,7 @@ public class RecentConversationsPreferenceControllerTest { new NotificationChannelGroup("hi", "group"), 7, false); - RecentConversationPreference pref = - (RecentConversationPreference) mController.createConversationPref( - new PreferenceCategory(mContext), ccw, 100); + RecentConversationPreference pref = mController.createConversationPref(ccw); final View view = View.inflate(mContext, pref.getLayoutResource(), null); PreferenceViewHolder holder = spy(PreferenceViewHolder.createInstanceForTests(view)); View delete = View.inflate(mContext, pref.getSecondTargetResId(), null); @@ -274,34 +260,28 @@ public class RecentConversationsPreferenceControllerTest { new NotificationChannelGroup("hi", "group"), 7, true); - PreferenceCategory group = new PreferenceCategory(mContext); - PreferenceScreen screen = new PreferenceManager(mContext).createPreferenceScreen(mContext); - screen.addPreference(group); - - RecentConversationPreference pref = mController.createConversationPref( - new PreferenceCategory(mContext), ccw, 100); + RecentConversationPreference pref = mController.createConversationPref(ccw); final View view = View.inflate(mContext, pref.getLayoutResource(), null); PreferenceViewHolder holder = spy(PreferenceViewHolder.createInstanceForTests(view)); View delete = View.inflate(mContext, pref.getSecondTargetResId(), null); when(holder.findViewById(pref.getClearId())).thenReturn(delete); - group.addPreference(pref); + mPreferenceGroup.addPreference(pref); - RecentConversationPreference pref2 = mController.createConversationPref( - new PreferenceCategory(mContext), ccw2, 100); + RecentConversationPreference pref2 = mController.createConversationPref(ccw2); final View view2 = View.inflate(mContext, pref2.getLayoutResource(), null); PreferenceViewHolder holder2 = spy(PreferenceViewHolder.createInstanceForTests(view2)); View delete2 = View.inflate(mContext, pref2.getSecondTargetResId(), null); when(holder2.findViewById(pref.getClearId())).thenReturn(delete2); - group.addPreference(pref2); + mPreferenceGroup.addPreference(pref2); - LayoutPreference clearAll = mController.getClearAll(group); - group.addPreference(clearAll); + LayoutPreference clearAll = mController.getClearAll(mPreferenceGroup); + mPreferenceGroup.addPreference(clearAll); clearAll.findViewById(R.id.conversation_settings_clear_recents).performClick(); verify(mPs).removeAllRecentConversations(); - assertThat((Preference) group.findPreference("hi:person")).isNull(); - assertThat((Preference) group.findPreference("bye:person")).isNotNull(); + assertThat((Preference) mPreferenceGroup.findPreference("hi:person")).isNull(); + assertThat((Preference) mPreferenceGroup.findPreference("bye:person")).isNotNull(); } @Test @@ -314,30 +294,23 @@ public class RecentConversationsPreferenceControllerTest { new NotificationChannelGroup("hi", "group"), 7, true); - RecentConversationPreference pref = - (RecentConversationPreference) mController.createConversationPref( - new PreferenceCategory(mContext), ccw, 100); + RecentConversationPreference pref = mController.createConversationPref(ccw); + assertThat(pref.hasClearListener()).isFalse(); } @Test public void testPopulateList_onlyNonremoveableConversations() { - final PreferenceManager preferenceManager = new PreferenceManager(mContext); - PreferenceScreen ps = preferenceManager.createPreferenceScreen(mContext); - PreferenceCategory outerContainer = spy(new PreferenceCategory(mContext)); - ps.addPreference(outerContainer); - ConversationChannel ccw = new ConversationChannel(mock(ShortcutInfo.class), 6, new NotificationChannel("hi", "hi", 4), new NotificationChannelGroup("hi", "hi"), 7, true /* hasactivenotifs */); - ArrayList list = new ArrayList<>(); - list.add(ccw); + boolean hasContent = mController.populateList(ImmutableList.of(ccw)); - mController.populateList(list, outerContainer); + assertThat(hasContent).isTrue(); // one for the preference, none for 'clear all' - verify(outerContainer, times(1)).addPreference(any()); + verify(mPreferenceGroup, times(1)).addPreference(any()); } @Test From 866b79c245d6c19eca0cd6ea4bb172adb3052448 Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Wed, 25 May 2022 12:25:43 +0800 Subject: [PATCH 4/5] 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 --- .../ContactDiscoveryPreferenceController.java | 5 +---- .../DataDuringCallsPreferenceController.java | 4 +--- .../DefaultSubscriptionController.java | 5 ----- .../DisabledSubscriptionController.java | 4 +--- ...nabledNetworkModePreferenceController.java | 4 +--- .../telephony/MobileNetworkSettings.java | 19 ++++++++----------- .../MobileNetworkSwitchController.java | 4 +--- .../NetworkPreferenceCategoryController.java | 4 +--- .../gsm/AutoSelectPreferenceController.java | 7 ++++--- ...NetworkSelectPagePreferenceController.java | 7 ++++--- ...tactDiscoveryPreferenceControllerTest.java | 3 ++- ...taDuringCallsPreferenceControllerTest.java | 7 +------ ...edNetworkModePreferenceControllerTest.java | 16 ++++++++-------- .../DisabledSubscriptionControllerTest.java | 6 +----- .../MobileNetworkSwitchControllerTest.java | 5 +---- .../AutoSelectPreferenceControllerTest.java | 7 ++----- ...orkSelectPagePreferenceControllerTest.java | 5 +---- 17 files changed, 38 insertions(+), 74 deletions(-) diff --git a/src/com/android/settings/network/telephony/ContactDiscoveryPreferenceController.java b/src/com/android/settings/network/telephony/ContactDiscoveryPreferenceController.java index a4ae51bf93d..f4ad478d383 100644 --- a/src/com/android/settings/network/telephony/ContactDiscoveryPreferenceController.java +++ b/src/com/android/settings/network/telephony/ContactDiscoveryPreferenceController.java @@ -61,12 +61,9 @@ public class ContactDiscoveryPreferenceController extends TelephonyTogglePrefere mCarrierConfigCache = CarrierConfigCache.getInstance(context); } - public ContactDiscoveryPreferenceController init(FragmentManager fragmentManager, int subId, - Lifecycle lifecycle) { + void init(FragmentManager fragmentManager, int subId) { mFragmentManager = fragmentManager; mSubId = subId; - lifecycle.addObserver(this); - return this; } @Override diff --git a/src/com/android/settings/network/telephony/DataDuringCallsPreferenceController.java b/src/com/android/settings/network/telephony/DataDuringCallsPreferenceController.java index 2bbb1cab049..099e01f9057 100644 --- a/src/com/android/settings/network/telephony/DataDuringCallsPreferenceController.java +++ b/src/com/android/settings/network/telephony/DataDuringCallsPreferenceController.java @@ -25,7 +25,6 @@ import android.os.Looper; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; -import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.Preference; @@ -52,10 +51,9 @@ public class DataDuringCallsPreferenceController extends TelephonyTogglePreferen super(context, preferenceKey); } - public void init(Lifecycle lifecycle, int subId) { + void init(int subId) { this.mSubId = subId; mManager = mContext.getSystemService(TelephonyManager.class).createForSubscriptionId(subId); - lifecycle.addObserver(this); } @OnLifecycleEvent(ON_RESUME) diff --git a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java index a3a281c4198..342b5793853 100644 --- a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java +++ b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java @@ -28,7 +28,6 @@ import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.view.View; -import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.ListPreference; @@ -72,10 +71,6 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere == View.LAYOUT_DIRECTION_RTL; } - public void init(Lifecycle lifecycle) { - lifecycle.addObserver(this); - } - /** @return SubscriptionInfo for the default subscription for the service, or null if there * isn't one. */ protected abstract SubscriptionInfo getDefaultSubscriptionInfo(); diff --git a/src/com/android/settings/network/telephony/DisabledSubscriptionController.java b/src/com/android/settings/network/telephony/DisabledSubscriptionController.java index b5febdd18a7..6c6228686a7 100644 --- a/src/com/android/settings/network/telephony/DisabledSubscriptionController.java +++ b/src/com/android/settings/network/telephony/DisabledSubscriptionController.java @@ -22,7 +22,6 @@ import static androidx.lifecycle.Lifecycle.Event.ON_RESUME; import android.content.Context; import android.telephony.SubscriptionManager; -import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.PreferenceCategory; @@ -53,8 +52,7 @@ public class DisabledSubscriptionController extends TelephonyBasePreferenceContr /** * Re-initialize the configuration based on subscription id provided */ - public void init(Lifecycle lifecycle, int subId) { - lifecycle.addObserver(this); + public void init(int subId) { mSubId = subId; } diff --git a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java index 658c6c6ba22..43b3cc0e4c4 100644 --- a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java +++ b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java @@ -28,7 +28,6 @@ import android.telephony.TelephonyManager; import android.util.Log; import androidx.annotation.VisibleForTesting; -import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.ListPreference; @@ -163,7 +162,7 @@ public class EnabledNetworkModePreferenceController extends return false; } - public void init(Lifecycle lifecycle, int subId) { + void init(int subId) { mSubId = subId; mTelephonyManager = mContext.getSystemService(TelephonyManager.class) .createForSubscriptionId(mSubId); @@ -178,7 +177,6 @@ public class EnabledNetworkModePreferenceController extends updatePreference(); }); } - lifecycle.addObserver(this); } private void updatePreference() { diff --git a/src/com/android/settings/network/telephony/MobileNetworkSettings.java b/src/com/android/settings/network/telephony/MobileNetworkSettings.java index 4eb8a857232..94b6aaf1bcc 100644 --- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java +++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java @@ -176,14 +176,12 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings { if (dataUsageSummaryPreferenceController != null) { dataUsageSummaryPreferenceController.init(mSubId); } - use(CallsDefaultSubscriptionController.class).init(getLifecycle()); - use(SmsDefaultSubscriptionController.class).init(getLifecycle()); - use(MobileNetworkSwitchController.class).init(getLifecycle(), mSubId); + use(MobileNetworkSwitchController.class).init(mSubId); use(CarrierSettingsVersionPreferenceController.class).init(mSubId); use(BillingCyclePreferenceController.class).init(mSubId); use(MmsMessagePreferenceController.class).init(mSubId); - use(DataDuringCallsPreferenceController.class).init(getLifecycle(), mSubId); - use(DisabledSubscriptionController.class).init(getLifecycle(), mSubId); + use(DataDuringCallsPreferenceController.class).init(mSubId); + use(DisabledSubscriptionController.class).init(mSubId); use(DeleteSimProfilePreferenceController.class).init(mSubId, this, REQUEST_CODE_DELETE_SUBSCRIPTION); use(DisableSimFooterPreferenceController.class).init(mSubId); @@ -197,7 +195,7 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings { use(CarrierPreferenceController.class).init(mSubId); use(DataUsagePreferenceController.class).init(mSubId); use(PreferredNetworkModePreferenceController.class).init(mSubId); - use(EnabledNetworkModePreferenceController.class).init(getLifecycle(), mSubId); + use(EnabledNetworkModePreferenceController.class).init(mSubId); use(DataServiceSetupPreferenceController.class).init(mSubId); use(Enable2gPreferenceController.class).init(mSubId); use(CarrierWifiTogglePreferenceController.class).init(getLifecycle(), mSubId); @@ -206,12 +204,12 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings { use(WifiCallingPreferenceController.class).init(mSubId); final OpenNetworkSelectPagePreferenceController openNetworkSelectPagePreferenceController = - use(OpenNetworkSelectPagePreferenceController.class).init(getLifecycle(), mSubId); + use(OpenNetworkSelectPagePreferenceController.class).init(mSubId); final AutoSelectPreferenceController autoSelectPreferenceController = use(AutoSelectPreferenceController.class) - .init(getLifecycle(), mSubId) + .init(mSubId) .addListener(openNetworkSelectPagePreferenceController); - use(NetworkPreferenceCategoryController.class).init(getLifecycle(), mSubId) + use(NetworkPreferenceCategoryController.class).init(mSubId) .setChildren(Arrays.asList(autoSelectPreferenceController)); mCdmaSystemSelectPreferenceController = use(CdmaSystemSelectPreferenceController.class); mCdmaSystemSelectPreferenceController.init(getPreferenceManager(), mSubId); @@ -231,8 +229,7 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings { .addListener(videoCallingPreferenceController); use(Enhanced4gAdvancedCallingPreferenceController.class).init(mSubId) .addListener(videoCallingPreferenceController); - use(ContactDiscoveryPreferenceController.class).init(getParentFragmentManager(), mSubId, - getLifecycle()); + use(ContactDiscoveryPreferenceController.class).init(getParentFragmentManager(), mSubId); use(NrAdvancedCallingPreferenceController.class).init(mSubId); } diff --git a/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java b/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java index 42fa95ecd99..50146343299 100644 --- a/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java +++ b/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java @@ -23,7 +23,6 @@ import android.content.Context; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; -import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.PreferenceScreen; @@ -49,8 +48,7 @@ public class MobileNetworkSwitchController extends BasePreferenceController impl mChangeListener = new SubscriptionsChangeListener(context, this); } - public void init(Lifecycle lifecycle, int subId) { - lifecycle.addObserver(this); + void init(int subId) { mSubId = subId; } diff --git a/src/com/android/settings/network/telephony/NetworkPreferenceCategoryController.java b/src/com/android/settings/network/telephony/NetworkPreferenceCategoryController.java index 4ebcb7a59d6..ed14616940c 100644 --- a/src/com/android/settings/network/telephony/NetworkPreferenceCategoryController.java +++ b/src/com/android/settings/network/telephony/NetworkPreferenceCategoryController.java @@ -22,7 +22,6 @@ import static androidx.lifecycle.Lifecycle.Event.ON_STOP; import android.content.Context; import android.telephony.SubscriptionManager; -import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.PreferenceScreen; @@ -69,10 +68,9 @@ public class NetworkPreferenceCategoryController extends PreferenceCategoryContr mPreferenceScreen = screen; } - public NetworkPreferenceCategoryController init(Lifecycle lifecycle, int subId) { + NetworkPreferenceCategoryController init(int subId) { mSubId = subId; - lifecycle.addObserver(this); return this; } } diff --git a/src/com/android/settings/network/telephony/gsm/AutoSelectPreferenceController.java b/src/com/android/settings/network/telephony/gsm/AutoSelectPreferenceController.java index ed8dc24063e..a19702fcb06 100644 --- a/src/com/android/settings/network/telephony/gsm/AutoSelectPreferenceController.java +++ b/src/com/android/settings/network/telephony/gsm/AutoSelectPreferenceController.java @@ -34,7 +34,6 @@ import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import androidx.annotation.VisibleForTesting; -import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.Preference; @@ -206,7 +205,10 @@ public class AutoSelectPreferenceController extends TelephonyTogglePreferenceCon }); } - public AutoSelectPreferenceController init(Lifecycle lifecycle, int subId) { + /** + * Initialization based on given subscription id. + **/ + public AutoSelectPreferenceController init(int subId) { mSubId = subId; mTelephonyManager = mContext.getSystemService(TelephonyManager.class) .createForSubscriptionId(mSubId); @@ -217,7 +219,6 @@ public class AutoSelectPreferenceController extends TelephonyTogglePreferenceCon CarrierConfigManager.KEY_ONLY_AUTO_SELECT_IN_HOME_NETWORK_BOOL) : false; - lifecycle.addObserver(this); return this; } diff --git a/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceController.java b/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceController.java index 4c5dd953453..8462228febd 100644 --- a/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceController.java +++ b/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceController.java @@ -26,7 +26,6 @@ import android.telephony.ServiceState; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; -import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.Preference; @@ -118,11 +117,13 @@ public class OpenNetworkSelectPagePreferenceController extends } } - public OpenNetworkSelectPagePreferenceController init(Lifecycle lifecycle, int subId) { + /** + * Initialization based on given subscription id. + **/ + public OpenNetworkSelectPagePreferenceController init(int subId) { mSubId = subId; mTelephonyManager = mContext.getSystemService(TelephonyManager.class) .createForSubscriptionId(mSubId); - lifecycle.addObserver(this); return this; } diff --git a/tests/robotests/src/com/android/settings/network/telephony/ContactDiscoveryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/ContactDiscoveryPreferenceControllerTest.java index b3725fa6c18..de3d2b27425 100644 --- a/tests/robotests/src/com/android/settings/network/telephony/ContactDiscoveryPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/network/telephony/ContactDiscoveryPreferenceControllerTest.java @@ -105,7 +105,8 @@ public class ContactDiscoveryPreferenceControllerTest { "ContactDiscovery"); // Ensure subscriptionInfo check doesn't fail. SubscriptionUtil.setAvailableSubscriptionsForTesting(Collections.emptyList()); - mPreferenceControllerUT.init(mFragmentManager, TEST_SUB_ID, mLifecycle); + mPreferenceControllerUT.init(mFragmentManager, TEST_SUB_ID); + mLifecycle.addObserver(mPreferenceControllerUT); mSwitchPreferenceUT = spy(new SwitchPreference(mContext)); mSwitchPreferenceUT.setKey(mPreferenceControllerUT.getPreferenceKey()); mPreferenceControllerUT.preference = mSwitchPreferenceUT; diff --git a/tests/robotests/src/com/android/settings/network/telephony/DataDuringCallsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/DataDuringCallsPreferenceControllerTest.java index 62d9974c59e..4a53aa25349 100644 --- a/tests/robotests/src/com/android/settings/network/telephony/DataDuringCallsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/network/telephony/DataDuringCallsPreferenceControllerTest.java @@ -32,12 +32,9 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.telephony.TelephonyManager; -import androidx.lifecycle.Lifecycle; import androidx.preference.PreferenceScreen; import androidx.preference.SwitchPreference; -import com.android.settings.network.telephony.DataDuringCallsPreferenceController; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -58,8 +55,6 @@ public class DataDuringCallsPreferenceControllerTest { @Mock private TelephonyManager mTelephonyManager; @Mock - private Lifecycle mLifecycle; - @Mock private PreferenceScreen mPreferenceScreen; private Context mContext; @@ -78,7 +73,7 @@ public class DataDuringCallsPreferenceControllerTest { @Override protected boolean hasMobileData() { return true; } }; - mController.init(mLifecycle, SUB_ID_1); + mController.init(SUB_ID_1); } @Test diff --git a/tests/unit/src/com/android/settings/network/EnabledNetworkModePreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/EnabledNetworkModePreferenceControllerTest.java index c9452063a95..4b996465dfb 100644 --- a/tests/unit/src/com/android/settings/network/EnabledNetworkModePreferenceControllerTest.java +++ b/tests/unit/src/com/android/settings/network/EnabledNetworkModePreferenceControllerTest.java @@ -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 diff --git a/tests/unit/src/com/android/settings/network/telephony/DisabledSubscriptionControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/DisabledSubscriptionControllerTest.java index b2696600bad..9f52c4cf9b0 100644 --- a/tests/unit/src/com/android/settings/network/telephony/DisabledSubscriptionControllerTest.java +++ b/tests/unit/src/com/android/settings/network/telephony/DisabledSubscriptionControllerTest.java @@ -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 diff --git a/tests/unit/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java index 23c9531fcc4..e460d675de9 100644 --- a/tests/unit/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java +++ b/tests/unit/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java @@ -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(); diff --git a/tests/unit/src/com/android/settings/network/telephony/gsm/AutoSelectPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/gsm/AutoSelectPreferenceControllerTest.java index 1e165d7a5a4..292b4a9ae5c 100644 --- a/tests/unit/src/com/android/settings/network/telephony/gsm/AutoSelectPreferenceControllerTest.java +++ b/tests/unit/src/com/android/settings/network/telephony/gsm/AutoSelectPreferenceControllerTest.java @@ -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); } } diff --git a/tests/unit/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceControllerTest.java index 53ae1b9eb53..b4d49b2a838 100644 --- a/tests/unit/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceControllerTest.java +++ b/tests/unit/src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceControllerTest.java @@ -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 From 968f30a470f99b3fdad08444d82ee7918b316b8d Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Wed, 25 May 2022 16:58:08 +0800 Subject: [PATCH 5/5] Fix SeekBarPreference selectable test SeekBarPreference is set to unselectable in change Ie5d819088dc3c435005ddd00e232b2f6992b234a Update the test accordingly. Bug: 230553896 Test: robotest Change-Id: Ia024b81e3f8e3808b0bb1e48c41a84d0ececaa85 --- .../com/android/settings/widget/SeekBarPreferenceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/robotests/src/com/android/settings/widget/SeekBarPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/SeekBarPreferenceTest.java index 770559d90c8..8b527fd5cff 100644 --- a/tests/robotests/src/com/android/settings/widget/SeekBarPreferenceTest.java +++ b/tests/robotests/src/com/android/settings/widget/SeekBarPreferenceTest.java @@ -112,7 +112,7 @@ public class SeekBarPreferenceTest { @Test @Config(qualifiers = "mcc999") - public void isSelectable_selectableInXml_returnTrue() { + public void isSelectable_selectableInXml_returnFalse() { final PreferenceFragmentCompat fragment = FragmentController.of(new TestFragment(), new Bundle()) .create() @@ -122,7 +122,7 @@ public class SeekBarPreferenceTest { final SeekBarPreference seekBarPreference = fragment.findPreference("seek_bar"); - assertThat(seekBarPreference.isSelectable()).isTrue(); + assertThat(seekBarPreference.isSelectable()).isFalse(); } @Test