summaryrefslogtreecommitdiffstats
path: root/src/com/android/packageinstaller/wear/WearPackageInstallerService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/packageinstaller/wear/WearPackageInstallerService.java')
-rw-r--r--src/com/android/packageinstaller/wear/WearPackageInstallerService.java82
1 files changed, 46 insertions, 36 deletions
diff --git a/src/com/android/packageinstaller/wear/WearPackageInstallerService.java b/src/com/android/packageinstaller/wear/WearPackageInstallerService.java
index 7387ed2a..2d4744c2 100644
--- a/src/com/android/packageinstaller/wear/WearPackageInstallerService.java
+++ b/src/com/android/packageinstaller/wear/WearPackageInstallerService.java
@@ -22,7 +22,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.FeatureInfo;
import android.content.pm.IPackageDeleteObserver;
-import android.content.pm.IPackageInstallObserver;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageParser;
@@ -98,13 +97,6 @@ public class WearPackageInstallerService extends Service {
private static final String SHOW_PERMS_SERVICE_CLASS =
"com.google.android.clockwork.packagemanager.ShowPermsService";
- /**
- * Normally sent by the Play store (See http://go/playstore-gms_updated), we instead
- * broadcast, ourselves. http://b/17387718
- */
- private static final String GMS_UPDATED_BROADCAST = "com.google.android.gms.GMS_UPDATED";
- public static final String GMS_PACKAGE_NAME = "com.google.android.gms";
-
private final int START_INSTALL = 1;
private final int START_UNINSTALL = 2;
@@ -203,13 +195,15 @@ public class WearPackageInstallerService extends Service {
int companionSdkVersion = WearPackageArgs.getCompanionSdkVersion(argsBundle);
int companionDeviceVersion = WearPackageArgs.getCompanionDeviceVersion(argsBundle);
String compressionAlg = WearPackageArgs.getCompressionAlg(argsBundle);
+ boolean skipIfLowerVersion = WearPackageArgs.skipIfLowerVersion(argsBundle);
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Installing package: " + packageName + ", assetUri: " + assetUri +
",permUri: " + permUri + ", startId: " + startId + ", checkPerms: " +
checkPerms + ", skipIfSameVersion: " + skipIfSameVersion +
", compressionAlg: " + compressionAlg + ", companionSdkVersion: " +
- companionSdkVersion + ", companionDeviceVersion: " + companionDeviceVersion);
+ companionSdkVersion + ", companionDeviceVersion: " + companionDeviceVersion +
+ ", skipIfLowerVersion: " + skipIfLowerVersion);
}
final PackageManager pm = getPackageManager();
File tempFile = null;
@@ -233,6 +227,12 @@ public class WearPackageInstallerService extends Service {
Log.d(TAG, "Replacing package:" + packageName);
}
}
+ // TODO(28021618): This was left as a temp file due to the fact that this code is being
+ // deprecated and that we need the bare minimum to continue working moving forward
+ // If this code is used as reference, this permission logic might want to be
+ // reworked to use a stream instead of a file so that we don't need to write a
+ // file at all. Note that there might be some trickiness with opening a stream
+ // for multiple users.
ParcelFileDescriptor parcelFd = getContentResolver()
.openFileDescriptor(assetUri, "r");
tempFile = WearPackageUtil.getFileFromFd(WearPackageInstallerService.this,
@@ -268,9 +268,17 @@ public class WearPackageInstallerService extends Service {
") is equal to existing app for " + packageName);
}
} else if (existingPkgInfo.versionCode > pkg.mVersionCode) {
- Log.w(TAG, "Version number of new app (" + pkg.mVersionCode +
- ") is lower than existing app ( " + existingPkgInfo.versionCode +
- ") for " + packageName);
+ if (skipIfLowerVersion) {
+ // Starting in Feldspar, we are not going to allow downgrades of any app.
+ Log.w(TAG, "Version number of new app (" + pkg.mVersionCode +
+ ") is lower than existing app ( " + existingPkgInfo.versionCode +
+ ") for " + packageName + "; not installing due to versionCheck");
+ return;
+ } else {
+ Log.w(TAG, "Version number of new app (" + pkg.mVersionCode +
+ ") is lower than existing app ( " + existingPkgInfo.versionCode +
+ ") for " + packageName);
+ }
}
// Following the Android Phone model, we should only check for permissions for any
@@ -318,9 +326,9 @@ public class WearPackageInstallerService extends Service {
}
// Finally install the package.
- pm.installPackage(Uri.fromFile(tempFile),
- new PackageInstallObserver(this, lock, startId, packageName),
- installFlags, packageName);
+ ParcelFileDescriptor fd = getContentResolver().openFileDescriptor(assetUri, "r");
+ PackageInstallerFactory.getPackageInstaller(this).install(packageName, fd,
+ new PackageInstallListener(this, lock, startId, packageName));
messageSent = true;
Log.i(TAG, "Sent installation request for " + packageName);
@@ -338,6 +346,10 @@ public class WearPackageInstallerService extends Service {
}
}
+ // TODO: This was left using the old PackageManager API due to the fact that this code is being
+ // deprecated and that we need the bare minimum to continue working moving forward
+ // If this code is used as reference, this logic should be reworked to use the new
+ // PackageInstaller APIs similar to how installPackage was reworked
private void uninstallPackage(Bundle argsBundle) {
int startId = WearPackageArgs.getStartId(argsBundle);
final String packageName = WearPackageArgs.getPackageName(argsBundle);
@@ -558,12 +570,12 @@ public class WearPackageInstallerService extends Service {
}
}
- private class PackageInstallObserver extends IPackageInstallObserver.Stub {
+ private class PackageInstallListener implements PackageInstallerImpl.InstallListener {
private Context mContext;
private PowerManager.WakeLock mWakeLock;
private int mStartId;
private String mApplicationPackageName;
- private PackageInstallObserver(Context context, PowerManager.WakeLock wakeLock,
+ private PackageInstallListener(Context context, PowerManager.WakeLock wakeLock,
int startId, String applicationPackageName) {
mContext = context;
mWakeLock = wakeLock;
@@ -571,35 +583,33 @@ public class WearPackageInstallerService extends Service {
mApplicationPackageName = applicationPackageName;
}
- public void packageInstalled(String packageName, int returnCode) {
- try {
- // 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;
- }
+ @Override
+ public void installBeginning() {
+ Log.i(TAG, "Package " + mApplicationPackageName + " is being installed.");
+ }
- Log.i(TAG, "Package " + packageName + " was installed.");
+ @Override
+ public void installSucceeded() {
+ try {
+ Log.i(TAG, "Package " + mApplicationPackageName + " was installed.");
// Delete tempFile from the file system.
- File tempFile = WearPackageUtil.getTemporaryFile(mContext, packageName);
+ File tempFile = WearPackageUtil.getTemporaryFile(mContext, mApplicationPackageName);
if (tempFile != null) {
tempFile.delete();
}
-
- // Broadcast the "UPDATED" gmscore intent, normally sent by play store.
- // TODO: Remove this broadcast if/when we get the play store to do this for us.
- if (GMS_PACKAGE_NAME.equals(packageName)) {
- Intent gmsInstalledIntent = new Intent(GMS_UPDATED_BROADCAST);
- gmsInstalledIntent.setPackage(GMS_PACKAGE_NAME);
- mContext.sendBroadcast(gmsInstalledIntent);
- }
} finally {
finishService(mWakeLock, mStartId);
}
}
+
+ @Override
+ public void installFailed(int errorCode, String errorDesc) {
+ Log.e(TAG, "Package install failed " + mApplicationPackageName
+ + ", errorCode " + errorCode);
+ WearPackageUtil.removeFromPermStore(mContext, mApplicationPackageName);
+ finishService(mWakeLock, mStartId);
+ }
}
private class PackageDeleteObserver extends IPackageDeleteObserver.Stub {