diff options
author | Amith Yamasani <yamasani@google.com> | 2014-08-13 11:11:44 -0700 |
---|---|---|
committer | Amith Yamasani <yamasani@google.com> | 2014-08-13 16:18:33 -0700 |
commit | 080f8db85c62672344375ca70c53086b891bce52 (patch) | |
tree | 40ae462db8e76fec9fdde31d720704aa6bcb6c5f /src | |
parent | 561d6bc9bb3f1473ac67f4bef5edac7b3046a901 (diff) | |
download | packages_apps_Settings-080f8db85c62672344375ca70c53086b891bce52.zip packages_apps_Settings-080f8db85c62672344375ca70c53086b891bce52.tar.gz packages_apps_Settings-080f8db85c62672344375ca70c53086b891bce52.tar.bz2 |
Make sure profile owner is system app
For cases where an app wants to become the profile owner after
setup has completed, make sure that it is a system app.
Bug: 17004847
Change-Id: I88249f1ce3bf841ca4d87f33acfd07a7db906332
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/settings/DeviceAdminAdd.java | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/com/android/settings/DeviceAdminAdd.java b/src/com/android/settings/DeviceAdminAdd.java index 0bd548f..ed95500 100644 --- a/src/com/android/settings/DeviceAdminAdd.java +++ b/src/com/android/settings/DeviceAdminAdd.java @@ -32,7 +32,10 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.ActivityInfo; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.os.Bundle; @@ -103,6 +106,7 @@ public class DeviceAdminAdd extends Activity { mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE); mAppOps = (AppOpsManager)getSystemService(Context.APP_OPS_SERVICE); + PackageManager packageManager = getPackageManager(); if ((getIntent().getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) { Log.w(TAG, "Cannot start ADD_DEVICE_ADMIN as a new task"); @@ -120,6 +124,8 @@ public class DeviceAdminAdd extends Activity { } if (action != null && action.equals(DevicePolicyManager.ACTION_SET_PROFILE_OWNER)) { + setResult(RESULT_CANCELED); + setFinishOnTouchOutside(true); mAddingProfileOwner = true; mProfileOwnerName = getIntent().getStringExtra(DevicePolicyManager.EXTRA_PROFILE_OWNER_NAME); @@ -129,11 +135,23 @@ public class DeviceAdminAdd extends Activity { finish(); return; } + try { + PackageInfo packageInfo = packageManager.getPackageInfo(callingPackage, 0); + if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { + Log.e(TAG, "Cannot set a non-system app as a profile owner"); + finish(); + return; + } + } catch (NameNotFoundException nnfe) { + Log.e(TAG, "Cannot find the package " + callingPackage); + finish(); + return; + } } ActivityInfo ai; try { - ai = getPackageManager().getReceiverInfo(who, PackageManager.GET_META_DATA); + ai = packageManager.getReceiverInfo(who, PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, "Unable to retrieve device policy " + who, e); finish(); @@ -144,7 +162,7 @@ public class DeviceAdminAdd extends Activity { // No need to check this when deactivating, because it is safe to deactivate an active // invalid device admin. if (!mDPM.isAdminActive(who)) { - List<ResolveInfo> avail = getPackageManager().queryBroadcastReceivers( + List<ResolveInfo> avail = packageManager.queryBroadcastReceivers( new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED), PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS); int count = avail == null ? 0 : avail.size(); |