1 /*
2  * Copyright (C) 2015 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 
17 package com.android.cellbroadcastreceiver;
18 
19 import android.app.backup.BackupAgentHelper;
20 import android.app.backup.SharedPreferencesBackupHelper;
21 import android.content.Intent;
22 import android.os.UserHandle;
23 import android.preference.PreferenceManager;
24 import android.util.Log;
25 
26 import com.android.internal.annotations.VisibleForTesting;
27 
28 /**
29  * The CellBroadcast backup agent backs up the shared
30  * preferences settings of the CellBroadcastReceiver App. Right
31  * now it backs up the whole shared preference file. This can be
32  * modified in the future to accommodate partial backup.
33  */
34 public class CellBroadcastBackupAgent extends BackupAgentHelper {
35     @VisibleForTesting
36     public static final String SHARED_KEY = "shared_pref";
37     private static final String TAG = "CBBackupAgent";
38 
39     @Override
onCreate()40     public void onCreate() {
41         Log.d(TAG, "onCreate");
42         addHelper(SHARED_KEY, new SharedPreferencesBackupHelper(this,
43                 PreferenceManager.getDefaultSharedPreferencesName(this)));
44     }
45 
46     @Override
onRestoreFinished()47     public void onRestoreFinished() {
48         Log.d(TAG, "Restore finished.");
49         Intent intent = new Intent(getApplicationContext(), CellBroadcastInternalReceiver.class);
50         intent.setAction(CellBroadcastReceiver.CELLBROADCAST_START_CONFIG_ACTION);
51 
52         // Cell broadcast was configured during boot up before the shared preference is restored,
53         // we need to re-configure it.
54         sendBroadcastAsUser(intent, UserHandle.SYSTEM);
55     }
56 }
57 
58