summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Hugh <ahugh@google.com>2015-11-16 21:12:37 (GMT)
committerandroid-build-merger <android-build-merger@google.com>2015-11-16 21:12:37 (GMT)
commit786cf97b83a4e502b8683198cdea8872c8507b93 (patch)
tree75eea7e2eeb67d00b53dac8f32551d9887aaad65
parent6f8e0b2bdc64cf625baa234fd8bd4fb423601be4 (diff)
parent9c78316fe6baa4f7fd7d5108349ecf8a2532b047 (diff)
downloadandroid_packages_apps_PackageInstaller-786cf97b83a4e502b8683198cdea8872c8507b93.zip
android_packages_apps_PackageInstaller-786cf97b83a4e502b8683198cdea8872c8507b93.tar.gz
android_packages_apps_PackageInstaller-786cf97b83a4e502b8683198cdea8872c8507b93.tar.bz2
Remove app from "needs permission" state if installation failed
am: 9c78316fe6 * commit '9c78316fe6baa4f7fd7d5108349ecf8a2532b047': Remove app from "needs permission" state if installation failed
-rw-r--r--src/com/android/packageinstaller/wear/WearPackageInstallerService.java19
-rw-r--r--src/com/android/packageinstaller/wear/WearPackageUtil.java19
2 files changed, 31 insertions, 7 deletions
diff --git a/src/com/android/packageinstaller/wear/WearPackageInstallerService.java b/src/com/android/packageinstaller/wear/WearPackageInstallerService.java
index d57236e..6dc5aa7 100644
--- a/src/com/android/packageinstaller/wear/WearPackageInstallerService.java
+++ b/src/com/android/packageinstaller/wear/WearPackageInstallerService.java
@@ -337,7 +337,8 @@ public class WearPackageInstallerService extends Service {
// Finally install the package.
pm.installPackage(Uri.fromFile(tempFile),
- new PackageInstallObserver(this, lock, startId), installFlags, packageName);
+ new PackageInstallObserver(this, lock, startId, packageName),
+ installFlags, packageName);
messageSent = true;
Log.i(TAG, "Sent installation request for " + packageName);
} catch (FileNotFoundException e) {
@@ -575,20 +576,26 @@ public class WearPackageInstallerService extends Service {
private Context mContext;
private PowerManager.WakeLock mWakeLock;
private int mStartId;
+ private String mApplicationPackageName;
private PackageInstallObserver(Context context, PowerManager.WakeLock wakeLock,
- int startId) {
+ int startId, String applicationPackageName) {
mContext = context;
mWakeLock = wakeLock;
mStartId = startId;
+ mApplicationPackageName = applicationPackageName;
}
public void packageInstalled(String packageName, int returnCode) {
- if (returnCode >= 0) {
- Log.i(TAG, "Package " + packageName + " was installed.");
- } else {
- Log.e(TAG, "Package install failed " + packageName + ", returnCode " + returnCode);
+ // If installation failed, bail out and remove the ShowPermsStore entry
+ if (returnCode < 0) {
+ Log.e(TAG, "Package install failed " + mApplicationPackageName
+ + ", returnCode " + returnCode);
+ WearPackageUtil.removeFromPermStore(mContext, mApplicationPackageName);
+ return;
}
+ Log.i(TAG, "Package " + packageName + " was installed.");
+
// Delete tempFile from the file system.
File tempFile = WearPackageUtil.getTemporaryFile(mContext, packageName);
if (tempFile != null) {
diff --git a/src/com/android/packageinstaller/wear/WearPackageUtil.java b/src/com/android/packageinstaller/wear/WearPackageUtil.java
index dc42075..688d616 100644
--- a/src/com/android/packageinstaller/wear/WearPackageUtil.java
+++ b/src/com/android/packageinstaller/wear/WearPackageUtil.java
@@ -17,9 +17,9 @@
package com.android.packageinstaller.wear;
import android.annotation.Nullable;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.PackageManager;
import android.content.pm.PackageParser;
import android.os.ParcelFileDescriptor;
import android.system.ErrnoException;
@@ -42,6 +42,12 @@ public class WearPackageUtil {
private static final String COMPRESSION_LZMA = "lzma";
private static final String COMPRESSION_XZ = "xz";
+ private static final String SHOW_PERMS_SERVICE_PKG_NAME = "com.google.android.wearable.app";
+ private static final String SHOW_PERMS_SERVICE_CLASS_NAME =
+ "com.google.android.clockwork.packagemanager.ShowPermsService";
+ private static final String EXTRA_PACKAGE_NAME
+ = "com.google.android.clockwork.EXTRA_PACKAGE_NAME";
+
public static File getTemporaryFile(Context context, String packageName) {
try {
File newFileDir = new File(context.getFilesDir(), "tmp");
@@ -147,4 +153,15 @@ public class WearPackageUtil {
}
return false;
}
+
+ public static void removeFromPermStore(Context context, String wearablePackageName) {
+ Intent newIntent = new Intent()
+ .setComponent(new ComponentName(
+ SHOW_PERMS_SERVICE_PKG_NAME, SHOW_PERMS_SERVICE_CLASS_NAME))
+ .setAction(Intent.ACTION_UNINSTALL_PACKAGE);
+ newIntent.putExtra(EXTRA_PACKAGE_NAME, wearablePackageName);
+ Log.i(TAG, "Sending removeFromPermStore to ShowPermsService " + newIntent
+ + " for " + wearablePackageName);
+ context.startService(newIntent);
+ }
}