Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 99ffc02d authored by Sam Blitzstein's avatar Sam Blitzstein Committed by Michael Bestas
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 93fd0e96
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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" />
+3 −0
Original line number Diff line number Diff line
@@ -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.
+29 −0
Original line number Diff line number Diff line
/*
 * 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
+23 −0
Original line number Diff line number Diff line
@@ -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