DO NOT MERGE - Ask device owner for master clear in demo mode
Bug: 62712426 Test: make RunSettingsRoboTests -j19 Change-Id: I29f92ff1062590f2c5eb7713e5969da7870fc582
This commit is contained in:
@@ -144,10 +144,10 @@ public class MasterClear extends OptionsMenuFragment {
|
|||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
final Context context = view.getContext();
|
final Context context = view.getContext();
|
||||||
if (Utils.isDemoUser(context)) {
|
if (Utils.isDemoUser(context)) {
|
||||||
final String packageName = Utils.getDemoModePackageName(context);
|
final ComponentName componentName = Utils.getDeviceOwnerComponent(context);
|
||||||
if (!TextUtils.isEmpty(packageName)) {
|
if (componentName != null) {
|
||||||
final Intent requestFactoryReset = new Intent()
|
final Intent requestFactoryReset = new Intent()
|
||||||
.setPackage(packageName)
|
.setPackage(componentName.getPackageName())
|
||||||
.setAction(Intent.ACTION_FACTORY_RESET);
|
.setAction(Intent.ACTION_FACTORY_RESET);
|
||||||
context.startActivity(requestFactoryReset);
|
context.startActivity(requestFactoryReset);
|
||||||
}
|
}
|
||||||
|
@@ -1280,8 +1280,10 @@ public final class Utils extends com.android.settingslib.Utils {
|
|||||||
return UserManager.isDeviceInDemoMode(context) && getUserManager(context).isDemoUser();
|
return UserManager.isDeviceInDemoMode(context) && getUserManager(context).isDemoUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDemoModePackageName(Context context) {
|
public static ComponentName getDeviceOwnerComponent(Context context) {
|
||||||
return context.getString(com.android.internal.R.string.config_demoModePackage);
|
final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
|
||||||
|
Context.DEVICE_POLICY_SERVICE);
|
||||||
|
return dpm.getDeviceOwnerComponentOnAnyUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -26,6 +26,7 @@ import static org.robolectric.Shadows.shadowOf;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -37,7 +38,6 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
|
||||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -144,19 +144,19 @@ public class MasterClearTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = { ShadowUtils.class, SettingsShadowResources.class })
|
@Config(shadows = { ShadowUtils.class })
|
||||||
public void testInitiateMasterClear_inDemoMode_sendsIntent() {
|
public void testInitiateMasterClear_inDemoMode_sendsIntent() {
|
||||||
SettingsShadowResources.overrideResource(
|
|
||||||
com.android.internal.R.string.config_demoModePackage, "package");
|
|
||||||
|
|
||||||
ShadowUtils.setIsDemoUser(true);
|
ShadowUtils.setIsDemoUser(true);
|
||||||
|
|
||||||
|
final ComponentName componentName = ComponentName.unflattenFromString(
|
||||||
|
"com.android.retaildemo/.DeviceAdminReceiver");
|
||||||
|
ShadowUtils.setDeviceOwnerComponent(componentName);
|
||||||
|
|
||||||
mMasterClear.mInitiateListener.onClick(
|
mMasterClear.mInitiateListener.onClick(
|
||||||
mContentView.findViewById(R.id.initiate_master_clear));
|
mContentView.findViewById(R.id.initiate_master_clear));
|
||||||
final Intent intent = mShadowActivity.getNextStartedActivity();
|
final Intent intent = mShadowActivity.getNextStartedActivity();
|
||||||
assertThat(Intent.ACTION_FACTORY_RESET).isEqualTo(intent.getAction());
|
assertThat(Intent.ACTION_FACTORY_RESET).isEqualTo(intent.getAction());
|
||||||
final String packageName = Utils.getDemoModePackageName(RuntimeEnvironment.application);
|
assertThat(componentName.getPackageName()).isEqualTo(intent.getPackage());
|
||||||
assertThat(packageName).isEqualTo(intent.getPackage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initScrollView(int height, int scrollY, int childBottom) {
|
private void initScrollView(int height, int scrollY, int childBottom) {
|
||||||
|
@@ -30,6 +30,7 @@ public class ShadowUtils {
|
|||||||
|
|
||||||
private static IFingerprintManager sFingerprintManager = null;
|
private static IFingerprintManager sFingerprintManager = null;
|
||||||
private static boolean sIsDemoUser;
|
private static boolean sIsDemoUser;
|
||||||
|
private static ComponentName sDeviceOwnerComponentName;
|
||||||
|
|
||||||
@Implementation
|
@Implementation
|
||||||
public static int enforceSameOwner(Context context, int userId) {
|
public static int enforceSameOwner(Context context, int userId) {
|
||||||
@@ -63,4 +64,13 @@ public class ShadowUtils {
|
|||||||
public static boolean isDemoUser(Context context) {
|
public static boolean isDemoUser(Context context) {
|
||||||
return sIsDemoUser;
|
return sIsDemoUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setDeviceOwnerComponent(ComponentName componentName) {
|
||||||
|
sDeviceOwnerComponentName = componentName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
public static ComponentName getDeviceOwnerComponent(Context context) {
|
||||||
|
return sDeviceOwnerComponentName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user