am 6b8e7b35: am bf20aa76: Merge "Keep track of who has disabled applications." into jb-mr2-dev
* commit '6b8e7b35ef763d29a30c87a5a95ef941d39a8ee9':
Keep track of who has disabled applications.
diff --git a/cmds/pm/src/com/android/commands/pm/Pm.java b/cmds/pm/src/com/android/commands/pm/Pm.java
index 98c82b5..224945a 100644
--- a/cmds/pm/src/com/android/commands/pm/Pm.java
+++ b/cmds/pm/src/com/android/commands/pm/Pm.java
@@ -1218,7 +1218,8 @@
ComponentName cn = ComponentName.unflattenFromString(pkg);
if (cn == null) {
try {
- mPm.setApplicationEnabledSetting(pkg, state, 0, userId);
+ mPm.setApplicationEnabledSetting(pkg, state, 0, userId,
+ "shell:" + android.os.Process.myUid());
System.err.println("Package " + pkg + " new state: "
+ enabledSettingToString(
mPm.getApplicationEnabledSetting(pkg, userId)));
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java
index 6d55dd5..271494f 100644
--- a/core/java/android/app/ApplicationPackageManager.java
+++ b/core/java/android/app/ApplicationPackageManager.java
@@ -1279,7 +1279,8 @@
public void setApplicationEnabledSetting(String packageName,
int newState, int flags) {
try {
- mPM.setApplicationEnabledSetting(packageName, newState, flags, mContext.getUserId());
+ mPM.setApplicationEnabledSetting(packageName, newState, flags,
+ mContext.getUserId(), mContext.getBasePackageName());
} catch (RemoteException e) {
// Should never happen!
}
diff --git a/core/java/android/content/pm/IPackageManager.aidl b/core/java/android/content/pm/IPackageManager.aidl
index a32a201..a0e1555 100644
--- a/core/java/android/content/pm/IPackageManager.aidl
+++ b/core/java/android/content/pm/IPackageManager.aidl
@@ -239,7 +239,8 @@
/**
* As per {@link android.content.pm.PackageManager#setApplicationEnabledSetting}.
*/
- void setApplicationEnabledSetting(in String packageName, in int newState, int flags, int userId);
+ void setApplicationEnabledSetting(in String packageName, in int newState, int flags,
+ int userId, String callingPackage);
/**
* As per {@link android.content.pm.PackageManager#getApplicationEnabledSetting}.
diff --git a/core/java/android/content/pm/PackageUserState.java b/core/java/android/content/pm/PackageUserState.java
index 3579977..dcd54fc 100644
--- a/core/java/android/content/pm/PackageUserState.java
+++ b/core/java/android/content/pm/PackageUserState.java
@@ -30,6 +30,8 @@
public boolean installed;
public int enabled;
+ public String lastDisableAppCaller;
+
public HashSet<String> disabledComponents;
public HashSet<String> enabledComponents;
@@ -43,6 +45,7 @@
stopped = o.stopped;
notLaunched = o.notLaunched;
enabled = o.enabled;
+ lastDisableAppCaller = o.lastDisableAppCaller;
disabledComponents = o.disabledComponents != null
? new HashSet<String>(o.disabledComponents) : null;
enabledComponents = o.enabledComponents != null
diff --git a/services/java/com/android/server/DevicePolicyManagerService.java b/services/java/com/android/server/DevicePolicyManagerService.java
index d3e7c24..ab70e6f 100644
--- a/services/java/com/android/server/DevicePolicyManagerService.java
+++ b/services/java/com/android/server/DevicePolicyManagerService.java
@@ -2443,7 +2443,7 @@
== PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
ipm.setApplicationEnabledSetting(packageName,
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
- PackageManager.DONT_KILL_APP, userId);
+ PackageManager.DONT_KILL_APP, userId, "DevicePolicyManager");
}
} catch (RemoteException e) {
}
diff --git a/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java
index 658bb5c..d2dba58 100644
--- a/services/java/com/android/server/InputMethodManagerService.java
+++ b/services/java/com/android/server/InputMethodManagerService.java
@@ -1603,7 +1603,8 @@
== PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
mIPackageManager.setApplicationEnabledSetting(imm.getPackageName(),
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
- PackageManager.DONT_KILL_APP, mSettings.getCurrentUserId());
+ PackageManager.DONT_KILL_APP, mSettings.getCurrentUserId(),
+ mContext.getBasePackageName());
}
} catch (RemoteException e) {
}
diff --git a/services/java/com/android/server/pm/PackageManagerService.java b/services/java/com/android/server/pm/PackageManagerService.java
index 30c830d..7a015d2 100644
--- a/services/java/com/android/server/pm/PackageManagerService.java
+++ b/services/java/com/android/server/pm/PackageManagerService.java
@@ -8757,7 +8757,7 @@
false, //installed
true, //stopped
true, //notLaunched
- null, null);
+ null, null, null);
if (!isSystemApp(ps)) {
if (ps.isAnyInstalled(sUserManager.getUserIds())) {
// Other user still have this package installed, so all
@@ -9333,9 +9333,12 @@
@Override
public void setApplicationEnabledSetting(String appPackageName,
- int newState, int flags, int userId) {
+ int newState, int flags, int userId, String callingPackage) {
if (!sUserManager.exists(userId)) return;
- setEnabledSetting(appPackageName, null, newState, flags, userId);
+ if (callingPackage == null) {
+ callingPackage = Integer.toString(Binder.getCallingUid());
+ }
+ setEnabledSetting(appPackageName, null, newState, flags, userId, callingPackage);
}
@Override
@@ -9343,11 +9346,11 @@
int newState, int flags, int userId) {
if (!sUserManager.exists(userId)) return;
setEnabledSetting(componentName.getPackageName(),
- componentName.getClassName(), newState, flags, userId);
+ componentName.getClassName(), newState, flags, userId, null);
}
- private void setEnabledSetting(
- final String packageName, String className, int newState, final int flags, int userId) {
+ private void setEnabledSetting(final String packageName, String className, int newState,
+ final int flags, int userId, String callingPackage) {
if (!(newState == COMPONENT_ENABLED_STATE_DEFAULT
|| newState == COMPONENT_ENABLED_STATE_ENABLED
|| newState == COMPONENT_ENABLED_STATE_DISABLED
@@ -9393,7 +9396,12 @@
// Nothing to do
return;
}
- pkgSetting.setEnabled(newState, userId);
+ if (newState == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
+ || newState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
+ // Don't care about who enables an app.
+ callingPackage = null;
+ }
+ pkgSetting.setEnabled(newState, userId, callingPackage);
// pkgSetting.pkg.mSetEnabled = newState;
} else {
// We're dealing with a component level state change
diff --git a/services/java/com/android/server/pm/PackageSettingBase.java b/services/java/com/android/server/pm/PackageSettingBase.java
index 2a723b4..b3fd60c 100644
--- a/services/java/com/android/server/pm/PackageSettingBase.java
+++ b/services/java/com/android/server/pm/PackageSettingBase.java
@@ -195,14 +195,20 @@
return DEFAULT_USER_STATE;
}
- void setEnabled(int state, int userId) {
- modifyUserState(userId).enabled = state;
+ void setEnabled(int state, int userId, String callingPackage) {
+ PackageUserState st = modifyUserState(userId);
+ st.enabled = state;
+ st.lastDisableAppCaller = callingPackage;
}
int getEnabled(int userId) {
return readUserState(userId).enabled;
}
+ String getLastDisabledAppCaller(int userId) {
+ return readUserState(userId).lastDisableAppCaller;
+ }
+
void setInstalled(boolean inst, int userId) {
modifyUserState(userId).installed = inst;
}
@@ -255,13 +261,14 @@
}
void setUserState(int userId, int enabled, boolean installed, boolean stopped,
- boolean notLaunched, HashSet<String> enabledComponents,
+ boolean notLaunched, String lastDisableAppCaller, HashSet<String> enabledComponents,
HashSet<String> disabledComponents) {
PackageUserState state = modifyUserState(userId);
state.enabled = enabled;
state.installed = installed;
state.stopped = stopped;
state.notLaunched = notLaunched;
+ state.lastDisableAppCaller = lastDisableAppCaller;
state.enabledComponents = enabledComponents;
state.disabledComponents = disabledComponents;
}
diff --git a/services/java/com/android/server/pm/Settings.java b/services/java/com/android/server/pm/Settings.java
index f1c5c07..095b698 100644
--- a/services/java/com/android/server/pm/Settings.java
+++ b/services/java/com/android/server/pm/Settings.java
@@ -107,6 +107,7 @@
private static final String ATTR_CODE = "code";
private static final String ATTR_NOT_LAUNCHED = "nl";
private static final String ATTR_ENABLED = "enabled";
+ private static final String ATTR_ENABLED_CALLER = "enabledCaller";
private static final String ATTR_STOPPED = "stopped";
private static final String ATTR_INSTALLED = "inst";
@@ -461,7 +462,7 @@
installed,
true, // stopped,
true, // notLaunched
- null, null);
+ null, null, null);
writePackageRestrictionsLPr(user.id);
}
}
@@ -859,7 +860,7 @@
true, // installed
false, // stopped
false, // notLaunched
- null, null);
+ null, null, null);
}
return;
}
@@ -904,6 +905,8 @@
final String enabledStr = parser.getAttributeValue(null, ATTR_ENABLED);
final int enabled = enabledStr == null
? COMPONENT_ENABLED_STATE_DEFAULT : Integer.parseInt(enabledStr);
+ final String enabledCaller = parser.getAttributeValue(null,
+ ATTR_ENABLED_CALLER);
final String installedStr = parser.getAttributeValue(null, ATTR_INSTALLED);
final boolean installed = installedStr == null
? true : Boolean.parseBoolean(installedStr);
@@ -934,7 +937,7 @@
}
ps.setUserState(userId, enabled, installed, stopped, notLaunched,
- enabledComponents, disabledComponents);
+ enabledCaller, enabledComponents, disabledComponents);
} else if (tagName.equals("preferred-activities")) {
readPreferredActivitiesLPw(parser, userId);
} else {
@@ -1061,6 +1064,10 @@
if (ustate.enabled != COMPONENT_ENABLED_STATE_DEFAULT) {
serializer.attribute(null, ATTR_ENABLED,
Integer.toString(ustate.enabled));
+ if (ustate.lastDisableAppCaller != null) {
+ serializer.attribute(null, ATTR_ENABLED_CALLER,
+ ustate.lastDisableAppCaller);
+ }
}
if (ustate.enabledComponents != null
&& ustate.enabledComponents.size() > 0) {
@@ -2274,14 +2281,14 @@
final String enabledStr = parser.getAttributeValue(null, ATTR_ENABLED);
if (enabledStr != null) {
try {
- packageSetting.setEnabled(Integer.parseInt(enabledStr), 0 /* userId */);
+ packageSetting.setEnabled(Integer.parseInt(enabledStr), 0 /* userId */, null);
} catch (NumberFormatException e) {
if (enabledStr.equalsIgnoreCase("true")) {
- packageSetting.setEnabled(COMPONENT_ENABLED_STATE_ENABLED, 0);
+ packageSetting.setEnabled(COMPONENT_ENABLED_STATE_ENABLED, 0, null);
} else if (enabledStr.equalsIgnoreCase("false")) {
- packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DISABLED, 0);
+ packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DISABLED, 0, null);
} else if (enabledStr.equalsIgnoreCase("default")) {
- packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0);
+ packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0, null);
} else {
PackageManagerService.reportSettingsProblem(Log.WARN,
"Error in package manager settings: package " + name
@@ -2290,7 +2297,7 @@
}
}
} else {
- packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0);
+ packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0, null);
}
final String installStatusStr = parser.getAttributeValue(null, "installStatus");
@@ -2841,6 +2848,11 @@
pw.print(ps.getNotLaunched(user.id));
pw.print(" enabled=");
pw.println(ps.getEnabled(user.id));
+ String lastDisabledAppCaller = ps.getLastDisabledAppCaller(user.id);
+ if (lastDisabledAppCaller != null) {
+ pw.print(prefix); pw.print(" lastDisabledCaller: ");
+ pw.println(lastDisabledAppCaller);
+ }
HashSet<String> cmp = ps.getDisabledComponents(user.id);
if (cmp != null && cmp.size() > 0) {
pw.print(prefix); pw.println(" disabledComponents:");