diff options
Diffstat (limited to 'src/com/android/packageinstaller/wear/WearPackageInstallerService.java')
-rw-r--r-- | src/com/android/packageinstaller/wear/WearPackageInstallerService.java | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/src/com/android/packageinstaller/wear/WearPackageInstallerService.java b/src/com/android/packageinstaller/wear/WearPackageInstallerService.java index 2d4744c2..6f4e2bcf 100644 --- a/src/com/android/packageinstaller/wear/WearPackageInstallerService.java +++ b/src/com/android/packageinstaller/wear/WearPackageInstallerService.java @@ -298,16 +298,6 @@ public class WearPackageInstallerService extends Service { } } - // Check permissions on both the new wearable package and also on the already installed - // wearable package. - // If the app is targeting API level 23, we will also start a service in ClockworkHome - // which will ultimately prompt the user to accept/reject permissions. - if (checkPerms && !checkPermissions(pkg, companionSdkVersion, companionDeviceVersion, - permUri, wearablePerms, tempFile)) { - Log.w(TAG, "Wearable does not have enough permissions."); - return; - } - // Check that the wearable has all the features. boolean hasAllFeatures = true; if (pkg.reqFeatures != null) { @@ -325,6 +315,16 @@ public class WearPackageInstallerService extends Service { return; } + // Check permissions on both the new wearable package and also on the already installed + // wearable package. + // If the app is targeting API level 23, we will also start a service in ClockworkHome + // which will ultimately prompt the user to accept/reject permissions. + if (checkPerms && !checkPermissions(pkg, companionSdkVersion, companionDeviceVersion, + permUri, wearablePerms, tempFile)) { + Log.w(TAG, "Wearable does not have enough permissions."); + return; + } + // Finally install the package. ParcelFileDescriptor fd = getContentResolver().openFileDescriptor(assetUri, "r"); PackageInstallerFactory.getPackageInstaller(this).install(packageName, fd, @@ -355,11 +355,27 @@ public class WearPackageInstallerService extends Service { final String packageName = WearPackageArgs.getPackageName(argsBundle); final PackageManager pm = getPackageManager(); - PowerManager.WakeLock lock = getLock(this.getApplicationContext()); - pm.deletePackage(packageName, new PackageDeleteObserver(lock, startId), - PackageManager.DELETE_ALL_USERS); - startPermsServiceForUninstall(packageName); - Log.i(TAG, "Sent delete request for " + packageName); + try { + // Result ignored. + pm.getPackageInfo(packageName, 0); + + // Found package, send uninstall request. + PowerManager.WakeLock lock = getLock(this.getApplicationContext()); + + try { + pm.deletePackage(packageName, new PackageDeleteObserver(lock, startId), + PackageManager.DELETE_ALL_USERS); + } catch (IllegalArgumentException e) { + // Couldn't find the package, no need to call uninstall. + Log.w(TAG, "Could not find package, not deleting " + packageName, e); + } + + startPermsServiceForUninstall(packageName); + Log.i(TAG, "Sent delete request for " + packageName); + } catch (PackageManager.NameNotFoundException e) { + // Couldn't find the package, no need to call uninstall. + Log.w(TAG, "Could not find package, not deleting " + packageName, e); + } } private boolean checkPermissions(PackageParser.Package pkg, int companionSdkVersion, |