From 88930e373e4b81c4ee9523445a7ff8322f9980b6 Mon Sep 17 00:00:00 2001 From: Andrew Sapperstein Date: Thu, 7 Mar 2019 14:18:15 -0800 Subject: [PATCH] Update eSIM deletion strings. Adds some conditional behavior for the confirmation screens. When the erase eSIM option is visible and checked, shows alternate string. Fixes: 126262481 Fixes: 118751918 Test: visual inspection & make -j RunSettingsRoboTests Change-Id: I40f983b03ad470d785bf104e645dbc92e7897d2d --- res/layout/reset_network_confirm.xml | 1 + res/values/strings.xml | 18 ++-- src/com/android/settings/MasterClear.java | 6 +- src/com/android/settings/MasterClearConfirm.java | 15 +++- src/com/android/settings/ResetNetwork.java | 12 ++- src/com/android/settings/ResetNetworkConfirm.java | 12 ++- .../android/settings/MasterClearConfirmTest.java | 67 +++++++++++++++ .../src/com/android/settings/MasterClearTest.java | 47 ++++++++++- .../android/settings/ResetNetworkConfirmTest.java | 28 +++++++ .../src/com/android/settings/ResetNetworkTest.java | 98 ++++++++++++++++++++++ 10 files changed, 287 insertions(+), 17 deletions(-) create mode 100644 tests/robotests/src/com/android/settings/MasterClearConfirmTest.java create mode 100644 tests/robotests/src/com/android/settings/ResetNetworkTest.java diff --git a/res/layout/reset_network_confirm.xml b/res/layout/reset_network_confirm.xml index ffaafb3808..0e5327f5b2 100644 --- a/res/layout/reset_network_confirm.xml +++ b/res/layout/reset_network_confirm.xml @@ -19,6 +19,7 @@ android:orientation="vertical"> Reset Wi-Fi, mobile & Bluetooth This will reset all network settings, including:\n\n
  • Wi\u2011Fi
  • \n
  • Mobile data
  • \n
  • Bluetooth
  • "
    + - Erase eSIMs + Erase downloaded SIMs - You\u2019ll have to contact your carrier to download replacement eSIMs. This won\u2019t cancel any mobile service plans. + To download replacement SIMs, contact your carrier. This won\u2019t cancel any mobile service plans. + Reset settings - Reset all network settings? You can\u2019t undo this action! + Reset all network settings? You can\u2019t undo this action. + + Reset all network settings and erase downloaded SIMs? You can\u2019t undo this action. Reset settings @@ -3609,9 +3613,9 @@ Network settings have been reset - Cant\u2019t reset eSIMs + Can\u2019t erase SIMs - The eSIMs can\u2019tt be reset due to an error. + Downloaded SIMs can\u2019t be erased due to an error.\n\nRestart your device and try again. @@ -3649,7 +3653,9 @@ Erase all data - All of your personal information and downloaded apps will be deleted. You can\u2019t undo this action! + All of your personal information and downloaded apps will be deleted. You can\u2019t undo this action. + + All of your personal information, including downloaded apps & SIMs, will be deleted. You can\u2019t undo this action. Erase everything diff --git a/src/com/android/settings/MasterClear.java b/src/com/android/settings/MasterClear.java index c78115d13c..14a6aed9e7 100644 --- a/src/com/android/settings/MasterClear.java +++ b/src/com/android/settings/MasterClear.java @@ -102,7 +102,8 @@ public class MasterClear extends InstrumentedFragment implements OnGlobalLayoutL private View mExternalStorageContainer; @VisibleForTesting CheckBox mExternalStorage; - private View mEsimStorageContainer; + @VisibleForTesting + View mEsimStorageContainer; @VisibleForTesting CheckBox mEsimStorage; @VisibleForTesting @@ -181,7 +182,8 @@ public class MasterClear extends InstrumentedFragment implements OnGlobalLayoutL void showFinalConfirmation() { final Bundle args = new Bundle(); args.putBoolean(ERASE_EXTERNAL_EXTRA, mExternalStorage.isChecked()); - args.putBoolean(ERASE_ESIMS_EXTRA, mEsimStorage.isChecked()); + args.putBoolean(ERASE_ESIMS_EXTRA, + mEsimStorageContainer.getVisibility() == View.VISIBLE && mEsimStorage.isChecked()); new SubSettingLauncher(getContext()) .setDestination(MasterClearConfirm.class.getName()) .setArguments(args) diff --git a/src/com/android/settings/MasterClearConfirm.java b/src/com/android/settings/MasterClearConfirm.java index 618dd2c263..ac97c11746 100644 --- a/src/com/android/settings/MasterClearConfirm.java +++ b/src/com/android/settings/MasterClearConfirm.java @@ -40,6 +40,8 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; +import androidx.annotation.VisibleForTesting; + import com.android.settings.core.InstrumentedFragment; import com.android.settings.enterprise.ActionDisabledByAdminDialogHelper; import com.android.settingslib.RestrictedLockUtilsInternal; @@ -62,9 +64,9 @@ import com.google.android.setupdesign.GlifLayout; public class MasterClearConfirm extends InstrumentedFragment { private final static String TAG = "MasterClearConfirm"; - private View mContentView; + @VisibleForTesting View mContentView; private boolean mEraseSdCard; - private boolean mEraseEsims; + @VisibleForTesting boolean mEraseEsims; /** * The user has gone through the multiple confirmation, so now we go ahead @@ -199,6 +201,7 @@ public class MasterClearConfirm extends InstrumentedFragment { setUpActionBarAndTitle(); establishFinalConfirmationState(); setAccessibilityTitle(); + setSubtitle(); return mContentView; } @@ -212,6 +215,14 @@ public class MasterClearConfirm extends InstrumentedFragment { } } + @VisibleForTesting + void setSubtitle() { + if (mEraseEsims) { + ((TextView) mContentView.findViewById(R.id.master_clear_confirm)) + .setText(R.string.master_clear_final_desc_esim); + } + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/src/com/android/settings/ResetNetwork.java b/src/com/android/settings/ResetNetwork.java index 5d7dd9994c..424d976e90 100644 --- a/src/com/android/settings/ResetNetwork.java +++ b/src/com/android/settings/ResetNetwork.java @@ -42,6 +42,8 @@ import android.widget.CheckBox; import android.widget.Spinner; import android.widget.TextView; +import androidx.annotation.VisibleForTesting; + import com.android.internal.telephony.PhoneConstants; import com.android.settings.core.InstrumentedFragment; import com.android.settings.core.SubSettingLauncher; @@ -74,8 +76,8 @@ public class ResetNetwork extends InstrumentedFragment { private View mContentView; private Spinner mSubscriptionSpinner; private Button mInitiateButton; - private View mEsimContainer; - private CheckBox mEsimCheckbox; + @VisibleForTesting View mEsimContainer; + @VisibleForTesting CheckBox mEsimCheckbox; @Override public void onCreate(@Nullable Bundle savedInstanceState) { @@ -112,14 +114,16 @@ public class ResetNetwork extends InstrumentedFragment { } } - private void showFinalConfirmation() { + @VisibleForTesting + void showFinalConfirmation() { Bundle args = new Bundle(); if (mSubscriptions != null && mSubscriptions.size() > 0) { int selectedIndex = mSubscriptionSpinner.getSelectedItemPosition(); SubscriptionInfo subscription = mSubscriptions.get(selectedIndex); args.putInt(PhoneConstants.SUBSCRIPTION_KEY, subscription.getSubscriptionId()); } - args.putBoolean(MasterClear.ERASE_ESIMS_EXTRA, mEsimCheckbox.isChecked()); + args.putBoolean(MasterClear.ERASE_ESIMS_EXTRA, + mEsimContainer.getVisibility() == View.VISIBLE && mEsimCheckbox.isChecked()); new SubSettingLauncher(getContext()) .setDestination(ResetNetworkConfirm.class.getName()) .setArguments(args) diff --git a/src/com/android/settings/ResetNetworkConfirm.java b/src/com/android/settings/ResetNetworkConfirm.java index 72e19194e7..376b7262d0 100644 --- a/src/com/android/settings/ResetNetworkConfirm.java +++ b/src/com/android/settings/ResetNetworkConfirm.java @@ -40,6 +40,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.TextView; import android.widget.Toast; import androidx.annotation.VisibleForTesting; @@ -64,7 +65,7 @@ import com.android.settingslib.RestrictedLockUtilsInternal; */ public class ResetNetworkConfirm extends InstrumentedFragment { - private View mContentView; + @VisibleForTesting View mContentView; private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; @VisibleForTesting boolean mEraseEsim; @VisibleForTesting EraseEsimAsyncTask mEraseEsimTask; @@ -207,6 +208,14 @@ public class ResetNetworkConfirm extends InstrumentedFragment { .setOnClickListener(mFinalClickListener); } + @VisibleForTesting + void setSubtitle() { + if (mEraseEsim) { + ((TextView) mContentView.findViewById(R.id.reset_network_confirm)) + .setText(R.string.reset_network_final_desc_esim); + } + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -224,6 +233,7 @@ public class ResetNetworkConfirm extends InstrumentedFragment { } mContentView = inflater.inflate(R.layout.reset_network_confirm, null); establishFinalConfirmationState(); + setSubtitle(); return mContentView; } diff --git a/tests/robotests/src/com/android/settings/MasterClearConfirmTest.java b/tests/robotests/src/com/android/settings/MasterClearConfirmTest.java new file mode 100644 index 0000000000..0c6903a9e9 --- /dev/null +++ b/tests/robotests/src/com/android/settings/MasterClearConfirmTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings; + +import static com.google.common.truth.Truth.assertThat; + +import android.app.Activity; +import android.view.LayoutInflater; +import android.widget.TextView; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; + +@RunWith(RobolectricTestRunner.class) +public class MasterClearConfirmTest { + private Activity mActivity; + + @Before + public void setUp() { + mActivity = Robolectric.setupActivity(Activity.class); + } + + @Test + public void setSubtitle_eraseEsim() { + MasterClearConfirm masterClearConfirm = new MasterClearConfirm(); + masterClearConfirm.mEraseEsims = true; + masterClearConfirm.mContentView = + LayoutInflater.from(mActivity).inflate(R.layout.master_clear_confirm, null); + + masterClearConfirm.setSubtitle(); + + assertThat(((TextView) masterClearConfirm.mContentView + .findViewById(R.id.master_clear_confirm)).getText()) + .isEqualTo(mActivity.getString(R.string.master_clear_final_desc_esim)); + } + + @Test + public void setSubtitle_notEraseEsim() { + MasterClearConfirm masterClearConfirm = new MasterClearConfirm(); + masterClearConfirm.mEraseEsims = false; + masterClearConfirm.mContentView = + LayoutInflater.from(mActivity).inflate(R.layout.master_clear_confirm, null); + + masterClearConfirm.setSubtitle(); + + assertThat(((TextView) masterClearConfirm.mContentView + .findViewById(R.id.master_clear_confirm)).getText()) + .isEqualTo(mActivity.getString(R.string.master_clear_final_desc)); + } +} diff --git a/tests/robotests/src/com/android/settings/MasterClearTest.java b/tests/robotests/src/com/android/settings/MasterClearTest.java index 749373b2c2..813e4aafa6 100644 --- a/tests/robotests/src/com/android/settings/MasterClearTest.java +++ b/tests/robotests/src/com/android/settings/MasterClearTest.java @@ -108,12 +108,14 @@ public class MasterClearTest { } @Test - public void testShowFinalConfirmation_eraseEsimChecked() { + public void testShowFinalConfirmation_eraseEsimVisible_eraseEsimChecked() { final Context context = mock(Context.class); when(mMasterClear.getContext()).thenReturn(context); mMasterClear.mEsimStorage = mContentView.findViewById(R.id.erase_esim); mMasterClear.mExternalStorage = mContentView.findViewById(R.id.erase_external); + mMasterClear.mEsimStorageContainer = mContentView.findViewById(R.id.erase_esim_container); + mMasterClear.mEsimStorageContainer.setVisibility(View.VISIBLE); mMasterClear.mEsimStorage.setChecked(true); mMasterClear.showFinalConfirmation(); @@ -126,12 +128,14 @@ public class MasterClearTest { } @Test - public void testShowFinalConfirmation_eraseEsimUnchecked() { + public void testShowFinalConfirmation_eraseEsimVisible_eraseEsimUnchecked() { final Context context = mock(Context.class); when(mMasterClear.getContext()).thenReturn(context); mMasterClear.mEsimStorage = mContentView.findViewById(R.id.erase_esim); mMasterClear.mExternalStorage = mContentView.findViewById(R.id.erase_external); + mMasterClear.mEsimStorageContainer = mContentView.findViewById(R.id.erase_esim_container); + mMasterClear.mEsimStorageContainer.setVisibility(View.VISIBLE); mMasterClear.mEsimStorage.setChecked(false); mMasterClear.showFinalConfirmation(); final ArgumentCaptor intent = ArgumentCaptor.forClass(Intent.class); @@ -143,6 +147,45 @@ public class MasterClearTest { } @Test + public void testShowFinalConfirmation_eraseEsimGone_eraseEsimChecked() { + final Context context = mock(Context.class); + when(mMasterClear.getContext()).thenReturn(context); + + mMasterClear.mEsimStorage = mContentView.findViewById(R.id.erase_esim); + mMasterClear.mExternalStorage = mContentView.findViewById(R.id.erase_external); + mMasterClear.mEsimStorageContainer = mContentView.findViewById(R.id.erase_esim_container); + mMasterClear.mEsimStorageContainer.setVisibility(View.GONE); + mMasterClear.mEsimStorage.setChecked(true); + mMasterClear.showFinalConfirmation(); + + final ArgumentCaptor intent = ArgumentCaptor.forClass(Intent.class); + + verify(context).startActivity(intent.capture()); + assertThat(intent.getValue().getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS) + .getBoolean(MasterClear.ERASE_ESIMS_EXTRA, false)) + .isFalse(); + } + + @Test + public void testShowFinalConfirmation_eraseEsimGone_eraseEsimUnchecked() { + final Context context = mock(Context.class); + when(mMasterClear.getContext()).thenReturn(context); + + mMasterClear.mEsimStorage = mContentView.findViewById(R.id.erase_esim); + mMasterClear.mExternalStorage = mContentView.findViewById(R.id.erase_external); + mMasterClear.mEsimStorageContainer = mContentView.findViewById(R.id.erase_esim_container); + mMasterClear.mEsimStorageContainer.setVisibility(View.GONE); + mMasterClear.mEsimStorage.setChecked(false); + mMasterClear.showFinalConfirmation(); + final ArgumentCaptor intent = ArgumentCaptor.forClass(Intent.class); + + verify(context).startActivity(intent.capture()); + assertThat(intent.getValue().getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS) + .getBoolean(MasterClear.ERASE_ESIMS_EXTRA, false)) + .isFalse(); + } + + @Test public void testShowWipeEuicc_euiccDisabled() { prepareEuiccState( false /* isEuiccEnabled */, diff --git a/tests/robotests/src/com/android/settings/ResetNetworkConfirmTest.java b/tests/robotests/src/com/android/settings/ResetNetworkConfirmTest.java index 0e4592da1f..1e960bf9d2 100644 --- a/tests/robotests/src/com/android/settings/ResetNetworkConfirmTest.java +++ b/tests/robotests/src/com/android/settings/ResetNetworkConfirmTest.java @@ -21,6 +21,8 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.spy; import android.app.Activity; +import android.view.LayoutInflater; +import android.widget.TextView; import com.android.settings.testutils.shadow.ShadowRecoverySystem; import com.android.settings.testutils.shadow.ShadowWifiP2pManager; @@ -86,4 +88,30 @@ public class ResetNetworkConfirmTest { assertThat(ShadowWifiP2pManager.getFactoryResetCount()).isEqualTo(1); } + + @Test + public void setSubtitle_eraseEsim() { + mResetNetworkConfirm.mEraseEsim = true; + mResetNetworkConfirm.mContentView = + LayoutInflater.from(mActivity).inflate(R.layout.reset_network_confirm, null); + + mResetNetworkConfirm.setSubtitle(); + + assertThat(((TextView) mResetNetworkConfirm.mContentView + .findViewById(R.id.reset_network_confirm)).getText()) + .isEqualTo(mActivity.getString(R.string.reset_network_final_desc_esim)); + } + + @Test + public void setSubtitle_notEraseEsim() { + mResetNetworkConfirm.mEraseEsim = false; + mResetNetworkConfirm.mContentView = + LayoutInflater.from(mActivity).inflate(R.layout.reset_network_confirm, null); + + mResetNetworkConfirm.setSubtitle(); + + assertThat(((TextView) mResetNetworkConfirm.mContentView + .findViewById(R.id.reset_network_confirm)).getText()) + .isEqualTo(mActivity.getString(R.string.reset_network_final_desc)); + } } diff --git a/tests/robotests/src/com/android/settings/ResetNetworkTest.java b/tests/robotests/src/com/android/settings/ResetNetworkTest.java new file mode 100644 index 0000000000..3b1d73be21 --- /dev/null +++ b/tests/robotests/src/com/android/settings/ResetNetworkTest.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings; + +import static com.google.common.truth.Truth.assertThat; + +import static org.robolectric.Shadows.shadowOf; + +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import android.app.Activity; +import android.content.Intent; +import android.view.View; +import android.widget.CheckBox; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; + +@RunWith(RobolectricTestRunner.class) +public class ResetNetworkTest { + private Activity mActivity; + private ResetNetwork mResetNetwork; + + @Before + public void setUp() { + mActivity = Robolectric.setupActivity(Activity.class); + mResetNetwork = spy(new ResetNetwork()); + when(mResetNetwork.getContext()).thenReturn(mActivity); + mResetNetwork.mEsimContainer = new View(mActivity); + mResetNetwork.mEsimCheckbox = new CheckBox(mActivity); + } + + @Test + public void showFinalConfirmation_checkboxVisible_eraseEsimChecked() { + mResetNetwork.mEsimContainer.setVisibility(View.VISIBLE); + mResetNetwork.mEsimCheckbox.setChecked(true); + + mResetNetwork.showFinalConfirmation(); + + Intent intent = shadowOf(mActivity).getNextStartedActivity(); + assertThat(intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS) + .getBoolean(MasterClear.ERASE_ESIMS_EXTRA, false)).isTrue(); + } + + @Test + public void showFinalConfirmation_checkboxVisible_eraseEsimUnchecked() { + mResetNetwork.mEsimContainer.setVisibility(View.VISIBLE); + mResetNetwork.mEsimCheckbox.setChecked(false); + + mResetNetwork.showFinalConfirmation(); + + Intent intent = shadowOf(mActivity).getNextStartedActivity(); + assertThat(intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS) + .getBoolean(MasterClear.ERASE_ESIMS_EXTRA, false)).isFalse(); + } + + @Test + public void showFinalConfirmation_checkboxGone_eraseEsimChecked() { + mResetNetwork.mEsimContainer.setVisibility(View.GONE); + mResetNetwork.mEsimCheckbox.setChecked(true); + + mResetNetwork.showFinalConfirmation(); + + Intent intent = shadowOf(mActivity).getNextStartedActivity(); + assertThat(intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS) + .getBoolean(MasterClear.ERASE_ESIMS_EXTRA, false)).isFalse(); + } + + @Test + public void showFinalConfirmation_checkboxGone_eraseEsimUnchecked() { + mResetNetwork.mEsimContainer.setVisibility(View.GONE); + mResetNetwork.mEsimCheckbox.setChecked(false); + + mResetNetwork.showFinalConfirmation(); + + Intent intent = shadowOf(mActivity).getNextStartedActivity(); + assertThat(intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS) + .getBoolean(MasterClear.ERASE_ESIMS_EXTRA, false)).isFalse(); + } +} -- 2.11.0