Commit f52c6414 authored by Sam Blitzstein's avatar Sam Blitzstein
Browse files

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
parent fb0097ad
......@@ -189,6 +189,17 @@
<receiver android:name=".alerts.GlobalDismissManager"
android:exported="false" />
<receiver android:name=".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=".alerts.AlertService" />
<service android:name=".alerts.DismissAlarmsService" />
......
......@@ -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.
......
/*
* 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
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment