public void setComponentEnabledSetting(ComponentName componentName,
int newState, int flags) {
setEnabledSetting(componentName.getPackageName(),
componentName.getClassName(), newState, flags);
}
public void setApplicationEnabledSetting(String appPackageName,
int newState, int flags) {
setEnabledSetting(appPackageName, null, newState, flags);
}
private void setEnabledSetting(
final String packageName, String className, int newState, final int flags) {
if (!(newState == COMPONENT_ENABLED_STATE_DEFAULT
|| newState == COMPONENT_ENABLED_STATE_ENABLED
|| newState == COMPONENT_ENABLED_STATE_DISABLED)) {
throw new IllegalArgumentException("Invalid new component state: "
+ newState);
}
PackageSetting pkgSetting;
final int uid = Binder.getCallingUid();
final int permission = mContext.checkCallingPermission(
android.Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE);
final boolean allowedByPermission = (permission == PackageManager.PERMISSION_GRANTED);
boolean sendNow = false;
boolean isApp = (className == null);
String componentName = isApp ? packageName : className;
int packageUid = -1;
ArrayList<String> components;
synchronized (mPackages) {
pkgSetting = mSettings.mPackages.get(packageName);
if (pkgSetting == null) {
if (className == null) {
throw new IllegalArgumentException(
"Unknown package: " + packageName);
}
throw new IllegalArgumentException(
"Unknown component: " + packageName
+ "/" + className);
}
if (!allowedByPermission && (**uid != pkgSetting.userId**)) {
throw new SecurityException(
"Permission Denial: attempt to change component state from pid="
+ Binder.getCallingPid()
+ ", uid=" + uid + ", package uid=" + pkgSetting.userId);
}
....
}
它會比較UID,所以不能禁用或啓用其他應用程序。 從:/frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java
感謝您的輸入.. –
即從[Android的源(https://開頭代碼。 google.com/p/android-source-browsing/source/browse/services/java/com/android/server/PackageManagerService.java?repo=platform--frameworks--base&r=1ccac75e1f1b97eccb916a8de04fc1012b30f6e5&spec=svn.platform--frameworks-- base.6a67a38f46cafdb9a9cedf3351f7150140cf0bd7#4668) - 應該已經清楚地在答案 –
是啊,這是來自Android的source.But Saurabh酒店似乎不明白.. – Hugo