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