From d7d4a7ce6d8da891552abbc78db1100e698341f8 Mon Sep 17 00:00:00 2001 From: Sunny Shao Date: Thu, 30 May 2019 11:22:39 +0800 Subject: [PATCH 1/2] Fixed the IllegalStateException on removing account We display a dialog in AccountManager.removeAccountAsUser() callback, but at that time fragment is onstop() which causes the IllegalStateException. Fixes: 133253227 Fixes: 135004255 Test: make RunSettingsRoboTests -j56 ROBOTEST_FILTER=com.android.settings.accounts make RunSettingsRoboTests -j56 ROBOTEST_FILTER=com.android.settings.core make RunSettingsRoboTests -j56 ROBOTEST_FILTER=com.android.settings.dashboard Change-Id: I8534e8f7118234f6346607415698f9f91c3e5ffb (cherry picked from commit d843ee85de0e07a186fbba758d1069d2ca598a76) --- .../accounts/RemoveAccountPreferenceController.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/accounts/RemoveAccountPreferenceController.java b/src/com/android/settings/accounts/RemoveAccountPreferenceController.java index 1bc30d03130..5c6e6bb4e72 100644 --- a/src/com/android/settings/accounts/RemoveAccountPreferenceController.java +++ b/src/com/android/settings/accounts/RemoveAccountPreferenceController.java @@ -191,7 +191,11 @@ public class RemoveAccountPreferenceController extends AbstractPreferenceControl } final RemoveAccountFailureDialog dialog = new RemoveAccountFailureDialog(); dialog.setTargetFragment(parent, 0); - dialog.show(parent.getFragmentManager(), FAILED_REMOVAL_DIALOG); + try { + dialog.show(parent.getFragmentManager(), FAILED_REMOVAL_DIALOG); + } catch (IllegalStateException e) { + Log.w(TAG, "Can't show RemoveAccountFailureDialog. " + e.getMessage()); + } } @Override From 46d819272ae8527387e0848fff1e5468ec095082 Mon Sep 17 00:00:00 2001 From: Antony Sargent Date: Tue, 25 Jun 2019 14:01:36 -0700 Subject: [PATCH 2/2] Check isWfcProvisionedOnDevice in WifiCallingSettings On the SIM details page, the preference leading to a page for configuring wifi calling will appear based on the results of the MobileNetworkUtils#isWifiCallingEnabled helper function. That helper uses the ImsManager to check several conditions, among them both isWfcEnabledByPlatform and isWfcProvisionedOnDevice. The page for configuring wifi calling has a tabbed UX, with one tab for each active subscription that supports it. The WifiCallingSettings class gets a list of the active subscriptions to determine which tabs to show, and removes any that don't support wifi calling, but was only using the isWfcEnabledByPlatform test to do so. This is a problem because the code for showing the contents inside the tab, in WifiCallingSettingsForSub, includes a sanity check of isWfcProvisionedOnDevice and calls finish() if that returns false. What this meant in practice is that if you happened to have 2 subscriptions where one returns true for both isWfcEnabledByPlatform and isWfcProvisionedOnDevice, but the other only returned true for isWfcEnabledByPlatform, then you'd never be able to succesfully use the wifi calling page at all because the tab for the subscription you *aren't* trying to configure would always call finish() early. The right long term solution to this problem is probably to remove the tabbed UX entirely from this page, since we probably don't need it given the overall new multi-SIM UX. But there may still be legacy uses and that is likely a bigger change than we want to make right now. As a stopgap, this CL just adds a check of isWfcProvisionedOnDevice to the code for filtering out ineligible subscriptions from the tabbed interface, which we should have always had anyway. Fixes: 135591718 Test: make RunSettingsRoboTests Change-Id: I656c3d3fb30cb6fabcb86685eae38c5f0cd0c6f2 --- .../wifi/calling/WifiCallingSettings.java | 9 ++++++- .../wifi/calling/WifiCallingSettingsTest.java | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/wifi/calling/WifiCallingSettings.java b/src/com/android/settings/wifi/calling/WifiCallingSettings.java index 1644b39825c..8a342c8a68d 100644 --- a/src/com/android/settings/wifi/calling/WifiCallingSettings.java +++ b/src/com/android/settings/wifi/calling/WifiCallingSettings.java @@ -199,6 +199,12 @@ public class WifiCallingSettings extends InstrumentedFragment implements HelpRes return imsManager.isWfcEnabledByPlatform(); } + @VisibleForTesting + boolean isWfcProvisionedOnDevice(SubscriptionInfo info) { + ImsManager imsManager = ImsManager.getInstance(getActivity(), info.getSimSlotIndex()); + return imsManager.isWfcProvisionedOnDevice(); + } + private void updateSubList() { mSil = SubscriptionUtil.getActiveSubscriptions( getContext().getSystemService(SubscriptionManager.class)); @@ -208,7 +214,8 @@ public class WifiCallingSettings extends InstrumentedFragment implements HelpRes return; } for (int i = 0; i < mSil.size(); ) { - if (!isWfcEnabledByPlatform(mSil.get(i))) { + final SubscriptionInfo info = mSil.get(i); + if (!isWfcEnabledByPlatform(info) || !isWfcProvisionedOnDevice(info)) { mSil.remove(i); } else { i++; diff --git a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsTest.java index a87ac322952..cc9ebb31646 100644 --- a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsTest.java +++ b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsTest.java @@ -19,6 +19,7 @@ package com.android.settings.wifi.calling; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -106,4 +107,30 @@ public class WifiCallingSettingsTest { (WifiCallingSettings.WifiCallingViewPagerAdapter) pager.getAdapter(); assertThat(adapter.getCount()).isEqualTo(2); } + + @Test + public void setupFragment_twoSubscriptionsOneNotProvisionedOnDevice_oneResult() { + SubscriptionInfo info1 = mock(SubscriptionInfo.class); + SubscriptionInfo info2 = mock(SubscriptionInfo.class); + when(info1.getSubscriptionId()).thenReturn(111); + when(info2.getSubscriptionId()).thenReturn(222); + + SubscriptionUtil.setActiveSubscriptionsForTesting(new ArrayList<>( + Arrays.asList(info1, info2))); + doReturn(true).when(mFragment).isWfcEnabledByPlatform(any(SubscriptionInfo.class)); + doReturn(false).when(mFragment).isWfcProvisionedOnDevice(eq(info2)); + + Intent intent = new Intent(); + intent.putExtra(Settings.EXTRA_SUB_ID, info1.getSubscriptionId()); + FragmentController.of(mFragment, intent).create(0 /* containerViewId*/, + null /* bundle */).start().resume().visible().get(); + + View view = mFragment.getView(); + RtlCompatibleViewPager pager = view.findViewById(R.id.view_pager); + assertThat(pager.getCurrentItem()).isEqualTo(0); + + WifiCallingSettings.WifiCallingViewPagerAdapter adapter = + (WifiCallingSettings.WifiCallingViewPagerAdapter) pager.getAdapter(); + assertThat(adapter.getCount()).isEqualTo(1); + } }