• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         DeviceConfigFacade deviceConfigFacade = NfcInjector.getInstance().getDeviceConfigFacade();
42 
43         if (nfcAdapter != null) {
44             SharedPreferences prefs = getSharedPreferences(NfcService.PREF,
45                 Context.MODE_MULTI_PROCESS);
46             if (prefs.getBoolean(NfcService.PREF_NFC_ON,
47                     deviceConfigFacade.getNfcDefaultState())) {
48                 nfcAdapter.enable();
49             } else {
50                 nfcAdapter.disable();
51             }
52 
53             if (prefs.getBoolean(NfcService.PREF_NFC_READER_OPTION_ON,
54                     deviceConfigFacade.getDefaultReaderOption())) {
55                 nfcAdapter.enableReaderOption(true);
56             } else {
57                 nfcAdapter.enableReaderOption(false);
58             }
59 
60             if (prefs.getBoolean(NfcService.PREF_SECURE_NFC_ON, deviceConfigFacade.getDefaultSecureNfcState())
61                     && nfcAdapter.isSecureNfcSupported()) {
62                 nfcAdapter.enableSecureNfc(true);
63             } else {
64                 nfcAdapter.enableSecureNfc(false);
65             }
66         }
67     }
68 }
69 
70