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