— a/frameworks/base/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
+++ b/frameworks/base/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
@@ -1636,84 +1636,88 @@ class PackageManagerShellCommand extends ShellCommand {
}
private int runUninstall() throws RemoteException {
-
final PrintWriter pw = getOutPrintWriter();
-
int flags = 0;
-
int userId = UserHandle.USER_ALL;
-
long versionCode = PackageManager.VERSION_CODE_HIGHEST;
-
String opt;
-
while ((opt = getNextOption()) != null) {
-
switch (opt) {
-
case "-k":
-
flags |= PackageManager.DELETE_KEEP_DATA;
-
break;
-
case "--user":
-
userId = UserHandle.parseUserArg(getNextArgRequired());
-
break;
-
case "--versionCode":
-
versionCode = Long.parseLong(getNextArgRequired());
-
break;
-
default:
-
pw.println("Error: Unknown option: " + opt);
-
return 1;
-
}
-
}
-
final String packageName = getNextArg();
-
if (packageName == null) {
-
pw.println("Error: package name not specified");
-
return 1;
-
}
-
// if a split is specified, just remove it and not the whole package
-
final String splitName = getNextArg();
-
if (splitName != null) {
-
return runRemoveSplit(packageName, splitName);
-
}
-
userId = translateUserId(userId, true /*allowAll*/, "runUninstall");
-
final LocalIntentReceiver receiver = new LocalIntentReceiver();
-
PackageManagerInternal internal = LocalServices.getService(PackageManagerInternal.class);
-
if (internal.isApexPackage(packageName)) {
-
internal.uninstallApex(packageName, versionCode, userId, receiver.getIntentSender());
-
} else {
-
if (userId == UserHandle.USER_ALL) {
-
userId = UserHandle.USER_SYSTEM;
-
flags |= PackageManager.DELETE_ALL_USERS;
-
} else {
-
final PackageInfo info = mInterface.getPackageInfo(packageName,
-
PackageManager.MATCH_STATIC_SHARED_LIBRARIES, userId);
-
if (info == null) {
-
pw.println("Failure [not installed for " + userId + "]");
-
return 1;
-
}
-
final boolean isSystem =
-
(info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
-
// If we are being asked to delete a system app for just one
-
// user set flag so it disables rather than reverting to system
-
// version of the app.
-
if (isSystem) {
-
flags |= PackageManager.DELETE_SYSTEM_APP;
-
}
-
}
-
mInterface.getPackageInstaller().uninstall(new VersionedPackage(packageName,
-
versionCode), null /*callerPackageName*/, flags,
-
receiver.getIntentSender(), userId);
-
}
-
final Intent result = receiver.getResult();
-
final int status = result.getIntExtra(PackageInstaller.EXTRA_STATUS,
-
PackageInstaller.STATUS_FAILURE);
-
if (status == PackageInstaller.STATUS_SUCCESS) {
-
pw.println("Success");
-
return 0;
-
} else {
-
pw.println("Failure ["
-
+ result.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE) + "]");
-
//add ycj return 1;
-
}
-
//end ycj
+/* final PrintWriter pw = getOutPrintWriter();
-
int flags = 0;
-
int userId = UserHandle.USER_ALL;
-
long versionCode = PackageManager.VERSION_CODE_HIGHEST;
-
String opt;
-
while ((opt = getNextOption()) != null) {
-
switch (opt) {
-
case "-k":
-
flags |= PackageManager.DELETE_KEEP_DATA;
-
break;
-
case "--user":
-
userId = UserHandle.parseUserArg(getNextArgRequired());
-
break;
-
return 1;
-
}
-
// if a split is specified, just remove it and not the whole package
-
final String splitName = getNextArg();
-
if (splitName != null) {
-
return runRemoveSplit(packageName, splitName);
-
}
-
userId = translateUserId(userId, true /*allowAll*/, "runUninstall");
-
final LocalIntentReceiver receiver = new LocalIntentReceiver();
-
PackageManagerInternal internal = LocalServices.getService(PackageManagerInternal.class);
-
if (internal.isApexPackage(packageName)) {
-
internal.uninstallApex(packageName, versionCode, userId, receiver.getIntentSender());
-
} else {
-
if (userId == UserHandle.USER_ALL) {
-
userId = UserHandle.USER_SYSTEM;
-
flags |= PackageManager.DELETE_ALL_USERS;
-
} else {
-
final PackageInfo info = mInterface.getPackageInfo(packageName,
-
PackageManager.MATCH_STATIC_SHARED_LIBRARIES, userId);
-
if (info == null) {
-
pw.println("Failure [not installed for " + userId + "]");
-
return 1;
-
}
-
final boolean isSystem =
-
(info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
-
// If we are being asked to delete a system app for just one
-
// user set flag so it disables rather than reverting to system
-
// version of the app.
-
if (isSystem) {
-
flags |= PackageManager.DELETE_SYSTEM_APP;
-
}
-
}
-
mInterface.getPackageInstaller().uninstall(new VersionedPackage(packageName,
-
versionCode), null /*callerPackageName*/, flags,
-
receiver.getIntentSender(), userId);
-
}
-
final Intent result = receiver.getResult();
-
final int status = result.getIntExtra(PackageInstaller.EXTRA_STATUS,
-
PackageInstaller.STATUS_FAILURE);
-
if (status == PackageInstaller.STATUS_SUCCESS) {
-
pw.println("Success");
-
return 0;
-
} else {
-
pw.println("Failure ["
-
+ result.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE) + "]");
-
//add ycj return 1;
-
}
-
//end ycj
+/* final PrintWriter pw = getOutPrintWriter();
-
int flags = 0;
-
int userId = UserHandle.USER_ALL;
-
long versionCode = PackageManager.VERSION_CODE_HIGHEST;
-
String opt;
-
while ((opt = getNextOption()) != null) {
-
switch (opt) {
-
case "-k":
-
flags |= PackageManager.DELETE_KEEP_DATA;
-
break;
-
case "--user":
-
userId = UserHandle.parseUserArg(getNextArgRequired());
-
break;
-
case "--versionCode":
-
versionCode = Long.parseLong(getNextArgRequired());
-
break;
-
default:
-
pw.println("Error: Unknown option: " + opt);
-
return 1;
-
}
-
}
-
final String packageName = getNextArg();
-
if (packageName == null) {
-
pw.println("Error: package name not specified");
-
return 1;
-
}
-
// if a split is specified, just remove it and not the whole package
-
final String splitName = getNextArg();
-
if (splitName != null) {
-
return runRemoveSplit(packageName, splitName);
-
}
-
userId = translateUserId(userId, true , "runUninstall");
-
final LocalIntentReceiver receiver = new LocalIntentReceiver();
-
PackageManagerInternal internal = LocalServices.getService(PackageManagerInternal.class);
-
if (internal.isApexPackage(packageName)) {
-
internal.uninstallApex(packageName, versionCode, userId, receiver.getIntentSender());
-
} else {
-
if (userId == UserHandle.USER_ALL) {
-
userId = UserHandle.USER_SYSTEM;
-
flags |= PackageManager.DELETE_ALL_USERS;
-
} else {
-
final PackageInfo info = mInterface.getPackageInfo(packageName,
-
PackageManager.MATCH_STATIC_SHARED_LIBRARIES, userId);
-
if (info == null) {
-
pw.println("Failure [not installed for " + userId + "]");
-
return 1;
-
}
-
final boolean isSystem =
-
(info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
-
// If we are being asked to delete a system app for just one
-
// user set flag so it disables rather than reverting to system
-
// version of the app.
-
if (isSystem) {
-
flags |= PackageManager.DELETE_SYSTEM_APP;
-
}
-
}
-
mInterface.getPackageInstaller().uninstall(new VersionedPackage(packageName,
-
versionCode), null , flags,
-
receiver.getIntentSender(), userId);
-
}
-
final Intent result = receiver.getResult();
-
final int status = result.getIntExtra(PackageInstaller.EXTRA_STATUS,
-
PackageInstaller.STATUS_FAILURE);
-
if (status == PackageInstaller.STATUS_SUCCESS) {
-
pw.println("Success");
-
return 0;
-
} else {
-
pw.println("Failure ["
-
+ result.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE) + "]");
-
return 1;
-
}
-
} */
}
private int runRemoveSplit(String packageName, String splitName) throws RemoteException {