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
17package com.android.nfc;
18
19import android.app.backup.BackupAgentHelper;
20import android.app.backup.SharedPreferencesBackupHelper;
21import android.content.SharedPreferences;
22import android.nfc.NfcAdapter;
23import android.content.Context;
24
25public class NfcBackupAgent extends BackupAgentHelper {
26    // Backup identifier
27    static final String SHARED_PREFS_BACKUP_KEY = "shared_prefs";
28
29    @Override
30    public void onCreate() {
31        SharedPreferencesBackupHelper helper =
32                new SharedPreferencesBackupHelper(this, NfcService.PREF);
33        addHelper(SHARED_PREFS_BACKUP_KEY, helper);
34    }
35
36    @Override
37    public void onRestoreFinished() {
38        NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
39
40        if (nfcAdapter != null) {
41            SharedPreferences prefs = getSharedPreferences(NfcService.PREF,
42                Context.MODE_MULTI_PROCESS);
43            if (prefs.getBoolean(NfcService.PREF_NDEF_PUSH_ON,
44                    NfcService.NDEF_PUSH_ON_DEFAULT)) {
45                nfcAdapter.enableNdefPush();
46            } else {
47                nfcAdapter.disableNdefPush();
48            }
49
50            if (prefs.getBoolean(NfcService.PREF_NFC_ON,
51                    NfcService.NFC_ON_DEFAULT)) {
52                nfcAdapter.enable();
53            } else {
54                nfcAdapter.disable();
55            }
56        }
57    }
58}
59
60