ignore IllegalArgumentException during uninstall

It's expected and normal to throw an IllegalArgumentException when
trying to uninstall a package that doesn't exist. Ignore it if it
gets thrown.

Bug: 38197362
Test: bit FrameworksCoreTests:android.content.pm.PackageManagerTests#testFlagFManifestI
Change-Id: Ie0d90010678b09c91747f6e5c4655691951ad3a9
This commit is contained in:
Todd Kennedy
2017-05-16 09:10:07 -07:00
parent 34bc4af810
commit cf901d7839

View File

@@ -1317,24 +1317,8 @@ public class PackageManagerTests extends AndroidTestCase {
return;
}
Runtime.getRuntime().gc();
final String packageName = ip.pkg.packageName;
Log.i(TAG, "Deleting package : " + packageName);
ApplicationInfo info = null;
try {
info = getPm().getApplicationInfo(packageName, PackageManager.MATCH_UNINSTALLED_PACKAGES);
} catch (NameNotFoundException ignored) {
}
DeleteObserver observer = new DeleteObserver(packageName);
getPm().deletePackage(packageName, observer, PackageManager.DELETE_ALL_USERS);
observer.waitForCompletion(MAX_WAIT_TIME);
try {
if (info != null) {
assertUninstalled(info);
}
cleanUpInstall(ip.pkg.packageName);
} finally {
File outFile = new File(ip.pkg.codePath);
if (outFile != null && outFile.exists()) {
@@ -1349,16 +1333,15 @@ public class PackageManagerTests extends AndroidTestCase {
}
Log.i(TAG, "Deleting package : " + pkgName);
try {
ApplicationInfo info = getPm().getApplicationInfo(pkgName,
final ApplicationInfo info = getPm().getApplicationInfo(pkgName,
PackageManager.MATCH_UNINSTALLED_PACKAGES);
if (info != null) {
DeleteObserver observer = new DeleteObserver(pkgName);
getPm().deletePackage(pkgName, observer, PackageManager.DELETE_ALL_USERS);
observer.waitForCompletion(MAX_WAIT_TIME);
assertUninstalled(info);
}
} catch (NameNotFoundException e) {
} catch (IllegalArgumentException | NameNotFoundException e) {
}
}