diff options
author | Neil Fuller <nfuller@google.com> | 2017-07-17 14:51:40 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-07-17 14:51:40 +0000 |
commit | aea80a0b3b406ec57cfeafe3210116d400137ed0 (patch) | |
tree | 76d8ef3f33b1ce12ca2feb7aae8f7e283fe13c06 | |
parent | 727642db15bbb5e1e3308e74409111f659171c56 (diff) | |
parent | 0a64f4144a25e7fac8d9729ae9854e9a3e692dde (diff) | |
download | TimeZoneUpdater-aea80a0b3b406ec57cfeafe3210116d400137ed0.tar.gz |
Modify RulesCheckReceiver to stage an uninstall am: 12c0bfbdbc am: f738fc1c88 am: 8195d68df1
am: 0a64f4144a
Change-Id: I4a4f6cb19a2a63871b1c06b47f0232c3ca5e1f40
-rw-r--r-- | src/main/com/android/timezone/updater/RulesCheckReceiver.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/main/com/android/timezone/updater/RulesCheckReceiver.java b/src/main/com/android/timezone/updater/RulesCheckReceiver.java index 79abfd4..b2c30c6 100644 --- a/src/main/com/android/timezone/updater/RulesCheckReceiver.java +++ b/src/main/com/android/timezone/updater/RulesCheckReceiver.java @@ -24,6 +24,9 @@ import android.app.timezone.RulesUpdaterContract; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.content.pm.ProviderInfo; import android.database.Cursor; import android.net.Uri; import android.os.ParcelFileDescriptor; @@ -88,6 +91,14 @@ public class RulesCheckReceiver extends BroadcastReceiver { byte[] token = intent.getByteArrayExtra(RulesUpdaterContract.EXTRA_CHECK_TOKEN); + if (shouldUninstallCurrentInstall(context)) { + Log.i(TAG, "Device should be returned to having no time zone distro installed, issuing" + + " uninstall request"); + // Uninstall is a no-op if nothing is installed. + handleUninstall(token); + return; + } + // Note: We rely on the system server to check that the configured data application is the // one that exposes the content provider with the well-known authority, and is a privileged // application as required. It is *not* checked here and it is assumed the updater can trust @@ -124,6 +135,31 @@ public class RulesCheckReceiver extends BroadcastReceiver { } } + private boolean shouldUninstallCurrentInstall(Context context) { + int flags = PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS; + PackageManager packageManager = context.getPackageManager(); + ProviderInfo providerInfo = + packageManager.resolveContentProvider(TimeZoneRulesDataContract.AUTHORITY, flags); + if (providerInfo == null || providerInfo.applicationInfo == null) { + Log.w(TAG, "No package/application info available for content provider " + + TimeZoneRulesDataContract.AUTHORITY); + // Something has gone wrong. Trying to return the device to clean is a reasonable + // response. + return true; + } + + // If the data app is the one from /system, we can treat this as "uninstall": if nothing + // is installed then the system will treat this as a no-op, and if something is installed + // this will stage an uninstall. + // We could install the distro from an app contained in the system image but we assume it's + // going to contain the same time zone data as in /system and would be a no op. + + ApplicationInfo applicationInfo = providerInfo.applicationInfo; + // isPrivilegedApp() => initial install directory for app /system/priv-app (required) + // isUpdatedSystemApp() => app has been replaced by an updated version that resides in /data + return applicationInfo.isPrivilegedApp() && !applicationInfo.isUpdatedSystemApp(); + } + private DistroOperation getOperation(Context context) { Cursor c = context.getContentResolver() .query(TimeZoneRulesDataContract.Operation.CONTENT_URI, |