In Settings, don't allow to disable an app which is profile/device owner.
In the App Info section of Settings: If the app is device owner or profile owner of at least one user, disable the disable button. BUG: 20831525 Change-Id: Iff00314108caf8c0b209f66060e6655ef06f2aa0
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.applications;
|
package com.android.settings.applications;
|
||||||
|
|
||||||
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@@ -32,6 +33,7 @@ import android.content.pm.PackageInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
|
import android.content.pm.UserInfo;
|
||||||
import android.net.INetworkStatsService;
|
import android.net.INetworkStatsService;
|
||||||
import android.net.INetworkStatsSession;
|
import android.net.INetworkStatsSession;
|
||||||
import android.net.NetworkTemplate;
|
import android.net.NetworkTemplate;
|
||||||
@@ -188,6 +190,10 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isProfileOrDeviceOwner(mPackageInfo.packageName)) {
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Home apps need special handling. Bundled ones we don't risk downgrading
|
// Home apps need special handling. Bundled ones we don't risk downgrading
|
||||||
// because that can interfere with home-key resolution. Furthermore, we
|
// because that can interfere with home-key resolution. Furthermore, we
|
||||||
// can't allow uninstallation of the only home app, and we don't want to
|
// can't allow uninstallation of the only home app, and we don't want to
|
||||||
@@ -223,6 +229,23 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns if the supplied package is device owner or profile owner of at least one user */
|
||||||
|
private boolean isProfileOrDeviceOwner(String packageName) {
|
||||||
|
List<UserInfo> userInfos = mUserManager.getUsers();
|
||||||
|
DevicePolicyManager dpm = (DevicePolicyManager)
|
||||||
|
getContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
|
if (packageName.equals(dpm.getDeviceOwner())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (UserInfo userInfo : userInfos) {
|
||||||
|
ComponentName cn = dpm.getProfileOwnerAsUser(userInfo.id);
|
||||||
|
if (cn != null && cn.getPackageName().equals(packageName)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
|
Reference in New Issue
Block a user