Merge "Keep track of who has disabled applications." into jb-mr2-dev

This commit is contained in:
Dianne Hackborn
2013-03-27 23:32:35 +00:00
committed by Android (Google) Code Review
9 changed files with 57 additions and 23 deletions

View File

@ -1218,7 +1218,8 @@ public final class Pm {
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)));

View File

@ -1279,7 +1279,8 @@ final class ApplicationPackageManager extends PackageManager {
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!
}

View File

@ -239,7 +239,8 @@ interface IPackageManager {
/**
* 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}.

View File

@ -30,6 +30,8 @@ public class PackageUserState {
public boolean installed;
public int enabled;
public String lastDisableAppCaller;
public HashSet<String> disabledComponents;
public HashSet<String> enabledComponents;
@ -43,6 +45,7 @@ public class PackageUserState {
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

View File

@ -2443,7 +2443,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
== 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) {
}

View File

@ -1598,7 +1598,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
== 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) {
}

View File

@ -8733,7 +8733,7 @@ public class PackageManagerService extends IPackageManager.Stub {
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
@ -9306,9 +9306,12 @@ public class PackageManagerService extends IPackageManager.Stub {
@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
@ -9316,11 +9319,11 @@ public class PackageManagerService extends IPackageManager.Stub {
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
@ -9366,7 +9369,12 @@ public class PackageManagerService extends IPackageManager.Stub {
// 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

View File

@ -189,14 +189,20 @@ class PackageSettingBase extends GrantedPermissions {
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;
}
@ -249,13 +255,14 @@ class PackageSettingBase extends GrantedPermissions {
}
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;
}

View File

@ -104,6 +104,7 @@ final class Settings {
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";
@ -453,7 +454,7 @@ final class Settings {
installed,
true, // stopped,
true, // notLaunched
null, null);
null, null, null);
writePackageRestrictionsLPr(user.id);
}
}
@ -850,7 +851,7 @@ final class Settings {
true, // installed
false, // stopped
false, // notLaunched
null, null);
null, null, null);
}
return;
}
@ -895,6 +896,8 @@ final class Settings {
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);
@ -925,7 +928,7 @@ final class Settings {
}
ps.setUserState(userId, enabled, installed, stopped, notLaunched,
enabledComponents, disabledComponents);
enabledCaller, enabledComponents, disabledComponents);
} else if (tagName.equals("preferred-activities")) {
readPreferredActivitiesLPw(parser, userId);
} else {
@ -1052,6 +1055,10 @@ final class Settings {
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) {
@ -2239,14 +2246,14 @@ final class Settings {
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
@ -2255,7 +2262,7 @@ final class Settings {
}
}
} else {
packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0);
packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0, null);
}
final String installStatusStr = parser.getAttributeValue(null, "installStatus");
@ -2789,6 +2796,11 @@ final class Settings {
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:");