Merge "Add a preference in reset options to delete private space" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
4230ad4b07
@@ -3462,6 +3462,12 @@
|
|||||||
<!-- Message of the error message shown when error happens during erase eSIM data [CHAR LIMIT=NONE] -->
|
<!-- Message of the error message shown when error happens during erase eSIM data [CHAR LIMIT=NONE] -->
|
||||||
<string name="reset_esim_error_msg">Something went wrong and your eSIMs weren\u2019t erased.\n\nRestart your device and try again.</string>
|
<string name="reset_esim_error_msg">Something went wrong and your eSIMs weren\u2019t erased.\n\nRestart your device and try again.</string>
|
||||||
|
|
||||||
|
<!-- Delete private space -->
|
||||||
|
<!-- Title for the Delete private space settings controller [CHAR LIMIT=40] -->
|
||||||
|
<string name="reset_private_space_delete_title">Delete private space</string>
|
||||||
|
<!-- Delete private space dialog mentioning that private space and the apps in it along with its data will be permanently deleted [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="reset_private_space_delete_dialog">If you have a private space on your device, it will be permanently deleted. All apps in your space and their data will be deleted.</string>
|
||||||
|
|
||||||
<!-- Main Clear -->
|
<!-- Main Clear -->
|
||||||
<!-- Button title to factory data reset the entire device [CHAR LIMIT=NONE] -->
|
<!-- Button title to factory data reset the entire device [CHAR LIMIT=NONE] -->
|
||||||
<string name="main_clear_title">Erase all data (factory reset)</string>
|
<string name="main_clear_title">Erase all data (factory reset)</string>
|
||||||
|
@@ -48,6 +48,12 @@
|
|||||||
settings:isPreferenceVisible="@bool/config_show_sim_info"
|
settings:isPreferenceVisible="@bool/config_show_sim_info"
|
||||||
settings:controller="com.android.settings.network.EraseEuiccDataController" />
|
settings:controller="com.android.settings.network.EraseEuiccDataController" />
|
||||||
|
|
||||||
|
<!-- Delete private space -->
|
||||||
|
<Preference
|
||||||
|
android:key="reset_delete_private_space"
|
||||||
|
android:title="@string/reset_private_space_delete_title"
|
||||||
|
settings:controller="com.android.settings.privatespace.delete.ResetOptionsDeletePrivateSpaceController" />
|
||||||
|
|
||||||
<!-- Factory reset -->
|
<!-- Factory reset -->
|
||||||
<com.android.settingslib.RestrictedPreference
|
<com.android.settingslib.RestrictedPreference
|
||||||
android:key="factory_reset"
|
android:key="factory_reset"
|
||||||
|
@@ -0,0 +1,146 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 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.privatespace.delete;
|
||||||
|
|
||||||
|
import static com.android.settings.system.ResetDashboardFragment.PRIVATE_SPACE_DELETE_CREDENTIAL_REQUEST;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.Initializer;
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||||
|
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||||
|
import com.android.settings.privatespace.PrivateSpaceMaintainer;
|
||||||
|
import com.android.settings.system.ResetDashboardFragment;
|
||||||
|
|
||||||
|
/** Controller to delete private space from Settings Reset options after authentication. */
|
||||||
|
public class ResetOptionsDeletePrivateSpaceController extends BasePreferenceController {
|
||||||
|
private static final String TAG = "PrivateSpaceResetCtrl";
|
||||||
|
private ResetDashboardFragment mHostFragment;
|
||||||
|
|
||||||
|
public ResetOptionsDeletePrivateSpaceController(
|
||||||
|
@NonNull Context context, @NonNull String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Initializer
|
||||||
|
public void setFragment(@NonNull ResetDashboardFragment hostFragment) {
|
||||||
|
mHostFragment = hostFragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
// TODO(b/330396315) : use canAddPrivateProfile() to check if private space is supported
|
||||||
|
// on the device
|
||||||
|
return android.multiuser.Flags.enablePrivateSpaceFeatures()
|
||||||
|
&& android.multiuser.Flags.deletePrivateSpaceFromReset()
|
||||||
|
? AVAILABLE
|
||||||
|
: UNSUPPORTED_ON_DEVICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handlePreferenceTreeClick(@NonNull Preference preference) {
|
||||||
|
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
startAuthenticationForDelete();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean startAuthenticationForDelete() {
|
||||||
|
final ChooseLockSettingsHelper.Builder builder =
|
||||||
|
new ChooseLockSettingsHelper.Builder(mHostFragment.getActivity(), mHostFragment);
|
||||||
|
builder.setRequestCode(PRIVATE_SPACE_DELETE_CREDENTIAL_REQUEST).show();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Method to handle onActivityResult */
|
||||||
|
public boolean handleActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||||
|
if (requestCode == PRIVATE_SPACE_DELETE_CREDENTIAL_REQUEST
|
||||||
|
&& resultCode == Activity.RESULT_OK
|
||||||
|
&& data != null) {
|
||||||
|
DeletePrivateSpaceDialogFragment dialogFragment = getDeleteDialogFragment();
|
||||||
|
dialogFragment.show(
|
||||||
|
getFragmentManager(), DeletePrivateSpaceDialogFragment.class.getName());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
DeletePrivateSpaceDialogFragment getDeleteDialogFragment() {
|
||||||
|
return new DeletePrivateSpaceDialogFragment();
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
FragmentManager getFragmentManager() {
|
||||||
|
return mHostFragment.getFragmentManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Dialog shown when deleting private space from Reset Options. */
|
||||||
|
public static class DeletePrivateSpaceDialogFragment extends InstrumentedDialogFragment {
|
||||||
|
private static final String TAG = "PrivateSpaceResetFrag";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return SettingsEnums.RESET_DELETE_PRIVATE_SPACE_DIALOG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||||
|
Context context = getContext();
|
||||||
|
return new AlertDialog.Builder(context)
|
||||||
|
.setTitle(R.string.reset_private_space_delete_title)
|
||||||
|
.setMessage(R.string.reset_private_space_delete_dialog)
|
||||||
|
.setPositiveButton(
|
||||||
|
R.string.private_space_delete_button_label,
|
||||||
|
(DialogInterface dialog, int which) -> {
|
||||||
|
mMetricsFeatureProvider.action(
|
||||||
|
context, SettingsEnums.RESET_DELETE_PRIVATE_SPACE_CONFIRM);
|
||||||
|
PrivateSpaceMaintainer privateSpaceMaintainer =
|
||||||
|
PrivateSpaceMaintainer.getInstance(context);
|
||||||
|
privateSpaceMaintainer.deletePrivateSpace();
|
||||||
|
dialog.dismiss();
|
||||||
|
})
|
||||||
|
.setNegativeButton(
|
||||||
|
R.string.private_space_cancel_label,
|
||||||
|
(DialogInterface dialog, int which) -> {
|
||||||
|
mMetricsFeatureProvider.action(
|
||||||
|
context, SettingsEnums.RESET_DELETE_PRIVATE_SPACE_CANCEL);
|
||||||
|
dialog.cancel();
|
||||||
|
})
|
||||||
|
.create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -18,6 +18,9 @@ package com.android.settings.system;
|
|||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.applications.manageapplications.ResetAppPrefPreferenceController;
|
import com.android.settings.applications.manageapplications.ResetAppPrefPreferenceController;
|
||||||
@@ -25,6 +28,7 @@ import com.android.settings.dashboard.DashboardFragment;
|
|||||||
import com.android.settings.network.EraseEuiccDataController;
|
import com.android.settings.network.EraseEuiccDataController;
|
||||||
import com.android.settings.network.NetworkResetPreferenceController;
|
import com.android.settings.network.NetworkResetPreferenceController;
|
||||||
import com.android.settings.network.SubscriptionUtil;
|
import com.android.settings.network.SubscriptionUtil;
|
||||||
|
import com.android.settings.privatespace.delete.ResetOptionsDeletePrivateSpaceController;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
@@ -38,6 +42,7 @@ import java.util.List;
|
|||||||
public class ResetDashboardFragment extends DashboardFragment {
|
public class ResetDashboardFragment extends DashboardFragment {
|
||||||
|
|
||||||
private static final String TAG = "ResetDashboardFragment";
|
private static final String TAG = "ResetDashboardFragment";
|
||||||
|
public static final int PRIVATE_SPACE_DELETE_CREDENTIAL_REQUEST = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
@@ -65,6 +70,14 @@ public class ResetDashboardFragment extends DashboardFragment {
|
|||||||
if (SubscriptionUtil.isSimHardwareVisible(context)) {
|
if (SubscriptionUtil.isSimHardwareVisible(context)) {
|
||||||
use(EraseEuiccDataController.class).setFragment(this);
|
use(EraseEuiccDataController.class).setFragment(this);
|
||||||
}
|
}
|
||||||
|
if (android.multiuser.Flags.enablePrivateSpaceFeatures()
|
||||||
|
&& android.multiuser.Flags.deletePrivateSpaceFromReset()) {
|
||||||
|
ResetOptionsDeletePrivateSpaceController resetOptionsDeletePrivateSpaceController =
|
||||||
|
use(ResetOptionsDeletePrivateSpaceController.class);
|
||||||
|
if (resetOptionsDeletePrivateSpaceController != null) {
|
||||||
|
resetOptionsDeletePrivateSpaceController.setFragment(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
FactoryResetPreferenceController factoryResetPreferenceController =
|
FactoryResetPreferenceController factoryResetPreferenceController =
|
||||||
use(FactoryResetPreferenceController.class);
|
use(FactoryResetPreferenceController.class);
|
||||||
if (factoryResetPreferenceController != null) {
|
if (factoryResetPreferenceController != null) {
|
||||||
@@ -96,4 +109,13 @@ public class ResetDashboardFragment extends DashboardFragment {
|
|||||||
return buildPreferenceControllers(context, null /* lifecycle */);
|
return buildPreferenceControllers(context, null /* lifecycle */);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||||
|
if (use(ResetOptionsDeletePrivateSpaceController.class)
|
||||||
|
.handleActivityResult(requestCode, resultCode, data)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,176 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 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.privatespace.delete;
|
||||||
|
|
||||||
|
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||||
|
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||||
|
import static com.android.settings.system.ResetDashboardFragment.PRIVATE_SPACE_DELETE_CREDENTIAL_REQUEST;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
|
|
||||||
|
import com.android.settings.system.ResetDashboardFragment;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.mockito.junit.MockitoJUnit;
|
||||||
|
import org.mockito.junit.MockitoRule;
|
||||||
|
import org.robolectric.Robolectric;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.annotation.LooperMode;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@LooperMode(LooperMode.Mode.LEGACY)
|
||||||
|
@Config(shadows = ShadowAlertDialogCompat.class)
|
||||||
|
public class ResetOptionsDeletePrivateSpaceControllerTest {
|
||||||
|
@Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||||
|
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
|
private static final String KEY = "reset_delete_private_space";
|
||||||
|
private Context mContext;
|
||||||
|
private ResetOptionsDeletePrivateSpaceController mController;
|
||||||
|
private ResetOptionsDeletePrivateSpaceController.DeletePrivateSpaceDialogFragment
|
||||||
|
mDialogFragment;
|
||||||
|
@Mock FragmentTransaction mFragmentTransaction;
|
||||||
|
@Mock ResetDashboardFragment mResetDashboardFragment;
|
||||||
|
@Mock FragmentManager mFragmentManager;
|
||||||
|
@Mock ResetOptionsDeletePrivateSpaceController.DeletePrivateSpaceDialogFragment
|
||||||
|
mMockAlertDialog;
|
||||||
|
@Mock Intent mIntent;
|
||||||
|
private FragmentActivity mActivity;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
mController = new ResetOptionsDeletePrivateSpaceController(mContext, KEY);
|
||||||
|
mActivity = Robolectric.setupActivity(FragmentActivity.class);
|
||||||
|
mDialogFragment =
|
||||||
|
new ResetOptionsDeletePrivateSpaceController.DeletePrivateSpaceDialogFragment();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_flagsDisabled_returnsUnsupported() {
|
||||||
|
mSetFlagsRule.disableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
|
||||||
|
mSetFlagsRule.disableFlags(android.multiuser.Flags.FLAG_DELETE_PRIVATE_SPACE_FROM_RESET);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_deleteFromResetFlagDisabled_returnsUnsupported() {
|
||||||
|
mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
|
||||||
|
mSetFlagsRule.disableFlags(android.multiuser.Flags.FLAG_DELETE_PRIVATE_SPACE_FROM_RESET);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_flagsEnabled_returnsAvailable() {
|
||||||
|
mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
|
||||||
|
mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_DELETE_PRIVATE_SPACE_FROM_RESET);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void handleActivityResult_success_showsAlertDialog() {
|
||||||
|
mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
|
||||||
|
mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_DELETE_PRIVATE_SPACE_FROM_RESET);
|
||||||
|
ResetOptionsDeletePrivateSpaceController controller = spy(mController);
|
||||||
|
doReturn(mFragmentManager).when(controller).getFragmentManager();
|
||||||
|
doReturn(mFragmentTransaction).when(mFragmentManager).beginTransaction();
|
||||||
|
doReturn(mMockAlertDialog).when(controller).getDeleteDialogFragment();
|
||||||
|
|
||||||
|
controller.setFragment(mResetDashboardFragment);
|
||||||
|
boolean result =
|
||||||
|
controller.handleActivityResult(
|
||||||
|
PRIVATE_SPACE_DELETE_CREDENTIAL_REQUEST, Activity.RESULT_OK, mIntent);
|
||||||
|
|
||||||
|
assertThat(result).isTrue();
|
||||||
|
verify(mMockAlertDialog).show((FragmentManager) any(), anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void handleActivityResult_notSuccess_noDialogShown() {
|
||||||
|
mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
|
||||||
|
mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_DELETE_PRIVATE_SPACE_FROM_RESET);
|
||||||
|
|
||||||
|
mController.setFragment(mResetDashboardFragment);
|
||||||
|
boolean result =
|
||||||
|
mController.handleActivityResult(
|
||||||
|
PRIVATE_SPACE_DELETE_CREDENTIAL_REQUEST, Activity.RESULT_CANCELED, mIntent);
|
||||||
|
|
||||||
|
assertThat(result).isFalse();
|
||||||
|
AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
|
assertThat(alertDialog).isNotNull();
|
||||||
|
assertThat(alertDialog.isShowing()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setAlertDialog_showsDialog_onPositiveButtonClickDialogRemoved() {
|
||||||
|
mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
|
||||||
|
mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_DELETE_PRIVATE_SPACE_FROM_RESET);
|
||||||
|
|
||||||
|
mDialogFragment.show(mActivity.getSupportFragmentManager(), "className");
|
||||||
|
AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
|
assertThat(alertDialog).isNotNull();
|
||||||
|
assertThat(alertDialog.isShowing()).isTrue();
|
||||||
|
Button positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
||||||
|
|
||||||
|
positiveButton.performClick();
|
||||||
|
assertThat(alertDialog.isShowing()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setAlertDialog_showsDialog_onNegativeButtonClickDialogRemoved() {
|
||||||
|
mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
|
||||||
|
mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_DELETE_PRIVATE_SPACE_FROM_RESET);
|
||||||
|
|
||||||
|
mDialogFragment.show(mActivity.getSupportFragmentManager(), "fragmentName");
|
||||||
|
AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
|
assertThat(alertDialog).isNotNull();
|
||||||
|
assertThat(alertDialog.isShowing()).isTrue();
|
||||||
|
Button negativeButton = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
|
||||||
|
|
||||||
|
negativeButton.performClick();
|
||||||
|
assertThat(alertDialog.isShowing()).isFalse();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user