summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2017-07-17 14:38:09 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-07-17 14:38:09 +0000
commit8195d68df1225c000243970cfd7aeacec6883e19 (patch)
tree76d8ef3f33b1ce12ca2feb7aae8f7e283fe13c06
parent6f5c5f07382484a52c880eb48e402896dd688da1 (diff)
parentf738fc1c8868cb08770f79ba14539a564b7014f8 (diff)
downloadTimeZoneUpdater-8195d68df1225c000243970cfd7aeacec6883e19.tar.gz
Modify RulesCheckReceiver to stage an uninstall am: 12c0bfbdbc
am: f738fc1c88 Change-Id: Ia317e308fb505986e9290c38ff245cc0063db9c3
-rw-r--r--src/main/com/android/timezone/updater/RulesCheckReceiver.java36
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,