1 /*
2  * Copyright (C) 2011 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.nfc;
18 
19 import android.app.backup.BackupAgentHelper;
20 import android.app.backup.SharedPreferencesBackupHelper;
21 import android.content.Context;
22 import android.content.SharedPreferences;
23 import android.nfc.NfcAdapter;
24 
25 public class NfcBackupAgent extends BackupAgentHelper {
26     // Backup identifier
27     static final String SHARED_PREFS_BACKUP_KEY = "shared_prefs";
28 
29     @Override
onCreate()30     public void onCreate() {
31         SharedPreferencesBackupHelper helper =
32                 new SharedPreferencesBackupHelper(
33                         this, NfcService.PREF, NfcService.PREF_TAG_APP_LIST);
34         addHelper(SHARED_PREFS_BACKUP_KEY, helper);
35     }
36 
37     @Override
onRestoreFinished()38     public void onRestoreFinished() {
39         NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
40         NfcService.sIsNfcRestore = true;
41 
42         if (nfcAdapter != null) {
43             SharedPreferences prefs = getSharedPreferences(NfcService.PREF,
44                 Context.MODE_MULTI_PROCESS);
45             if (prefs.getBoolean(NfcService.PREF_NFC_ON,
46                     NfcService.NFC_ON_DEFAULT)) {
47                 nfcAdapter.enable();
48             } else {
49                 nfcAdapter.disable();
50             }
51 
52             if (prefs.getBoolean(NfcService.PREF_NFC_READER_OPTION_ON,
53                     NfcService.NFC_READER_OPTION_DEFAULT)) {
54                 nfcAdapter.enableReaderOption(true);
55             } else {
56                 nfcAdapter.enableReaderOption(false);
57             }
58 
59             if (prefs.getBoolean(NfcService.PREF_SECURE_NFC_ON, NfcService.SECURE_NFC_ON_DEFAULT)
60                     && nfcAdapter.isSecureNfcSupported()) {
61                 nfcAdapter.enableSecureNfc(true);
62             } else {
63                 nfcAdapter.enableSecureNfc(false);
64             }
65         }
66     }
67 }
68 
69