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

Commit 851660ba authored by James Lemieux's avatar James Lemieux Committed by Android Git Automerger
Browse files

am 24b11ac8: Merge "Add backup/restore support" into ub-deskclock-business

* commit '24b11ac8':
  Add backup/restore support
parents 522e9d98 24b11ac8
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -35,6 +35,10 @@

    <application android:label="@string/app_label"
                 android:name=".DeskClockApplication"
                 android:allowBackup="true"
                 android:backupAgent="DeskClockBackupAgent"
                 android:fullBackupContent="@xml/backup_scheme"
                 android:fullBackupOnly="true"
                 android:icon="@mipmap/ic_launcher_alarmclock"
                 android:requiredForAllUsers="true"
                 android:supportsRtl="true">
@@ -47,8 +51,7 @@
                android:label="@string/app_label"
                android:theme="@style/DeskClock"
                android:icon="@mipmap/ic_launcher_alarmclock"
                android:launchMode="singleTask"
                >
                android:launchMode="singleTask">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
+20 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 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.
-->

<full-backup-content>
    <include domain="database" path="alarms.db" />
    <include domain="sharedpref" path="com.android.deskclock_preferences.xml" />
</full-backup-content>
 No newline at end of file
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 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.deskclock;

import android.app.backup.BackupAgent;
import android.app.backup.BackupDataInput;
import android.app.backup.BackupDataOutput;
import android.os.ParcelFileDescriptor;
import android.support.annotation.NonNull;

import com.android.deskclock.alarms.AlarmStateManager;

import java.io.File;
import java.io.IOException;

public class DeskClockBackupAgent extends BackupAgent {

    @Override
    public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
            ParcelFileDescriptor newState) throws IOException { }

    @Override
    public void onRestore(BackupDataInput data, int appVersionCode,
            ParcelFileDescriptor newState) throws IOException { }

    @Override
    public void onRestoreFile(@NonNull ParcelFileDescriptor data, long size, File destination,
            int type, long mode, long mtime) throws IOException {
        // The preference file on the backup device may not be the same on the restore device.
        // Massage the file name here before writing it.
        if (destination.getName().endsWith("_preferences.xml")) {
            final String prefFileName = getPackageName() + "_preferences.xml";
            destination = new File(destination.getParentFile(), prefFileName);
        }

        super.onRestoreFile(data, size, destination, type, mode, mtime);
    }

    @Override
    public void onRestoreFinished() {
        // Now that alarms have been restored, schedule them in AlarmManager.
        AlarmStateManager.fixAlarmInstances(this);
    }
}
 No newline at end of file