DO NOT MERGE - Ask device owner for master clear in demo mode

am: a22c8345fa

Change-Id: Idf0f52476201a55c6d3a8051158e0ea3a7f555b0
This commit is contained in:
Justin Klaassen
2017-08-10 00:23:52 +00:00
committed by android-build-merger
4 changed files with 24 additions and 12 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

@@ -1280,8 +1280,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();
}
/**