aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Blitzstein <sblitz@google.com>2013-12-04 12:59:36 -0800
committerMichael Bestas <mkbestas@lineageos.org>2020-06-24 23:14:05 +0300
commite843e7de04fa151e99399d6f860c7c367a66a8a8 (patch)
tree0ac65c982bf04f8f3c3afe6f6b22b7fc6a072970
parentcf6b5107eaf1462f26b1c4d80ca4dd50f6ecf9d4 (diff)
downloadandroid_packages_apps_Etar-e843e7de04fa151e99399d6f860c7c367a66a8a8.tar.gz
android_packages_apps_Etar-e843e7de04fa151e99399d6f860c7c367a66a8a8.tar.bz2
android_packages_apps_Etar-e843e7de04fa151e99399d6f860c7c367a66a8a8.zip
Force a manual, incremental sync one time, as early as possible.
Either at package replacement (doesn't seem to work), restart, or app load. Only do this one time. This is to ensure the database goes through the proper upgrade path in case its in a bad state. Bug: 11828610 Change-Id: I850bef5d105fcb806f74b3fdffba1dfef03a0a1b
-rw-r--r--AndroidManifest.xml11
-rw-r--r--src/com/android/calendar/AllInOneActivity.java3
-rw-r--r--src/com/android/calendar/UpgradeReceiver.java29
-rw-r--r--src/com/android/calendar/Utils.java23
4 files changed, 66 insertions, 0 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 3cc64562..a4663130 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -231,6 +231,17 @@
<receiver android:name="com.android.calendar.alerts.GlobalDismissManager"
android:exported="false" />
+ <receiver android:name="com.android.calendar.UpgradeReceiver">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
+ <data android:scheme="package"/>
+ </intent-filter>
+ </receiver>
+
<service android:name="com.android.calendar.alerts.AlertService" />
<service android:name="com.android.calendar.alerts.DismissAlarmsService" />
diff --git a/src/com/android/calendar/AllInOneActivity.java b/src/com/android/calendar/AllInOneActivity.java
index 04212ee0..744ff3a7 100644
--- a/src/com/android/calendar/AllInOneActivity.java
+++ b/src/com/android/calendar/AllInOneActivity.java
@@ -555,6 +555,9 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH
super.onResume();
dynamicTheme.onResume(this);
+ // Check if the upgrade code has ever been run. If not, force a sync just this one time.
+ Utils.trySyncAndDisableUpgradeReceiver(this);
+
// Must register as the first activity because this activity can modify
// the list of event handlers in it's handle method. This affects who
// the rest of the handlers the controller dispatches to are.
diff --git a/src/com/android/calendar/UpgradeReceiver.java b/src/com/android/calendar/UpgradeReceiver.java
new file mode 100644
index 00000000..0e89286d
--- /dev/null
+++ b/src/com/android/calendar/UpgradeReceiver.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.calendar;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+public class UpgradeReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(final Context context, final Intent intent) {
+ Utils.trySyncAndDisableUpgradeReceiver(context);
+ }
+
+} \ No newline at end of file
diff --git a/src/com/android/calendar/Utils.java b/src/com/android/calendar/Utils.java
index 0f0152d0..9003f95b 100644
--- a/src/com/android/calendar/Utils.java
+++ b/src/com/android/calendar/Utils.java
@@ -20,6 +20,7 @@ import android.accounts.Account;
import android.app.Activity;
import android.app.SearchManager;
import android.content.BroadcastReceiver;
+import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -845,6 +846,28 @@ public class Utils {
return (0xff000000) | ((r | g | b) >> 8);
}
+ public static void trySyncAndDisableUpgradeReceiver(Context context) {
+ final PackageManager pm = context.getPackageManager();
+ ComponentName upgradeComponent = new ComponentName(context, UpgradeReceiver.class);
+ if (pm.getComponentEnabledSetting(upgradeComponent) ==
+ PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
+ // The upgrade receiver has been disabled, which means this code has been run before,
+ // so no need to sync.
+ return;
+ }
+
+ Bundle extras = new Bundle();
+ extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
+ ContentResolver.requestSync(
+ null /* no account */,
+ Calendars.CONTENT_URI.getAuthority(),
+ extras);
+
+ // Now unregister the receiver so that we won't continue to sync every time.
+ pm.setComponentEnabledSetting(upgradeComponent,
+ PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
+ }
+
/**
* Converts a list of events to a list of segments to draw. Assumes list is
* ordered by start time of the events. The function processes events for a