summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSam Blitzstein <sblitz@google.com>2013-12-04 12:59:36 -0800
committerSam Blitzstein <sblitz@google.com>2013-12-04 13:02:35 -0800
commitf52c64145b6219aeceeb93f4bdb5e2c069bf48a4 (patch)
tree9740c9390710c179fbea75306814d2661ae19d7c /src
parentfb0097adc5656ccd052abb9e6e807355768d200a (diff)
downloadandroid_packages_apps_Calendar-f52c64145b6219aeceeb93f4bdb5e2c069bf48a4.tar.gz
android_packages_apps_Calendar-f52c64145b6219aeceeb93f4bdb5e2c069bf48a4.tar.bz2
android_packages_apps_Calendar-f52c64145b6219aeceeb93f4bdb5e2c069bf48a4.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
Diffstat (limited to 'src')
-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
3 files changed, 55 insertions, 0 deletions
diff --git a/src/com/android/calendar/AllInOneActivity.java b/src/com/android/calendar/AllInOneActivity.java
index e61d69c8..0e1feb49 100644
--- a/src/com/android/calendar/AllInOneActivity.java
+++ b/src/com/android/calendar/AllInOneActivity.java
@@ -507,6 +507,9 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH
protected void onResume() {
super.onResume();
+ // 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 4018f22b..41961852 100644
--- a/src/com/android/calendar/Utils.java
+++ b/src/com/android/calendar/Utils.java
@@ -22,6 +22,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;
@@ -848,6 +849,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);
+ }
+
// A single strand represents one color of events. Events are divided up by
// color to make them convenient to draw. The black strand is special in
// that it holds conflicting events as well as color settings for allday on