1/*
2 * Copyright (C) 2017 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.settings.backup;
18
19import android.app.backup.BackupManager;
20import android.content.Context;
21import android.os.UserManager;
22
23import com.android.settings.R;
24import com.android.settings.core.BasePreferenceController;
25
26public class BackupSettingsActivityPreferenceController extends BasePreferenceController {
27    private static final String TAG = "BackupSettingActivityPC";
28
29    private static final String KEY_BACKUP_SETTINGS = "backup_settings";
30
31    private final UserManager mUm;
32    private final BackupManager mBackupManager;
33
34    public BackupSettingsActivityPreferenceController(Context context) {
35        super(context, KEY_BACKUP_SETTINGS);
36        mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
37        mBackupManager = new BackupManager(context);
38    }
39
40    @Override
41    public int getAvailabilityStatus() {
42        return mUm.isAdminUser()
43                ? AVAILABLE
44                : UNSUPPORTED_ON_DEVICE;
45    }
46
47    @Override
48    public CharSequence getSummary() {
49        final boolean backupEnabled = mBackupManager.isBackupEnabled();
50
51        return backupEnabled
52                ? mContext.getText(R.string.accessibility_feature_state_on)
53                : mContext.getText(R.string.accessibility_feature_state_off);
54    }
55}