Ask device owner for master clear in demo mode

Bug: 62712426
Test: make RunSettingsRoboTests -j19
Change-Id: I29f92ff1062590f2c5eb7713e5969da7870fc582
This commit is contained in:
Justin Klaassen
2017-08-08 21:58:05 -07:00
parent 882d35715e
commit 3025727e16
4 changed files with 27 additions and 17 deletions

View File

@@ -144,10 +144,10 @@ public class MasterClear extends OptionsMenuFragment {
public void onClick(View view) {
final Context context = view.getContext();
if (Utils.isDemoUser(context)) {
final String packageName = Utils.getDemoModePackageName(context);
if (!TextUtils.isEmpty(packageName)) {
final ComponentName componentName = Utils.getDeviceOwnerComponent(context);
if (componentName != null) {
final Intent requestFactoryReset = new Intent()
.setPackage(packageName)
.setPackage(componentName.getPackageName())
.setAction(Intent.ACTION_FACTORY_RESET);
context.startActivity(requestFactoryReset);
}

View File

@@ -1249,8 +1249,10 @@ public final class Utils extends com.android.settingslib.Utils {
return UserManager.isDeviceInDemoMode(context) && getUserManager(context).isDemoUser();
}
public static String getDemoModePackageName(Context context) {
return context.getString(com.android.internal.R.string.config_demoModePackage);
public static ComponentName getDeviceOwnerComponent(Context context) {
final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
Context.DEVICE_POLICY_SERVICE);
return dpm.getDeviceOwnerComponentOnAnyUser();
}
/**