blob: 83e4a60d450e8cf17da3da37e70b2690f9502e99 [file] [log] [blame]
Chris Wren92aa4232013-10-04 11:29:36 -04001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher3;
18
19import android.app.backup.BackupAgentHelper;
20import android.app.backup.BackupManager;
Chris Wren45297f82013-10-17 15:16:48 -040021import android.app.backup.SharedPreferencesBackupHelper;
Chris Wren92aa4232013-10-04 11:29:36 -040022import android.content.Context;
Chris Wren45297f82013-10-17 15:16:48 -040023import android.content.SharedPreferences;
Chris Wren92aa4232013-10-04 11:29:36 -040024
25public class LauncherBackupAgentHelper extends BackupAgentHelper {
26
Chris Wren45297f82013-10-17 15:16:48 -040027 private static final String TAG = "LauncherBackupAgentHelper";
28
Chris Wren92aa4232013-10-04 11:29:36 -040029 private static BackupManager sBackupManager;
30
31 /**
32 * Notify the backup manager that out database is dirty.
33 *
34 * <P>This does not force an immediate backup.
35 *
36 * @param context application context
37 */
38 public static void dataChanged(Context context) {
39 if (sBackupManager == null) {
40 sBackupManager = new BackupManager(context);
41 }
42 sBackupManager.dataChanged();
43 }
44
Chris Wren45297f82013-10-17 15:16:48 -040045 @Override
46 public void onDestroy() {
47 // There is only one process accessing this preference file, but the restore
48 // modifies the file outside the normal codepaths, so it looks like another
49 // process. This forces a reload of the file, in case this process persists.
50 String spKey = LauncherAppState.getSharedPreferencesKey();
51 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS);
52 super.onDestroy();
53 }
Chris Wren92aa4232013-10-04 11:29:36 -040054
55 @Override
56 public void onCreate() {
Chris Wren45297f82013-10-17 15:16:48 -040057 addHelper(LauncherBackupHelper.LAUNCHER_PREFS_PREFIX,
58 new SharedPreferencesBackupHelper(this,
59 LauncherAppState.getSharedPreferencesKey()));
Chris Wren92aa4232013-10-04 11:29:36 -040060 addHelper(LauncherBackupHelper.LAUNCHER_PREFIX, new LauncherBackupHelper(this));
61 }
62}