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 17 package com.android.settings.backup; 18 19 import android.app.backup.BackupManager; 20 import android.content.Context; 21 import android.os.Build; 22 import android.os.RemoteException; 23 import android.os.ServiceManager; 24 import android.os.UserManager; 25 import android.support.v7.preference.Preference; 26 import android.support.v7.preference.PreferenceScreen; 27 import android.util.Log; 28 29 import com.android.settings.R; 30 import com.android.settings.Utils; 31 import com.android.settings.core.PreferenceController; 32 33 public class BackupSettingsActivityPreferenceController extends PreferenceController { 34 private static final String KEY_BACKUP_SETTINGS = "backup_settings"; 35 private static final String TAG = "BackupSettingActivityPC" ; 36 37 private final UserManager mUm; 38 private final BackupManager mBackupManager; 39 BackupSettingsActivityPreferenceController(Context context)40 public BackupSettingsActivityPreferenceController(Context context) { 41 super(context); 42 mUm = (UserManager) context.getSystemService(Context.USER_SERVICE); 43 mBackupManager = new BackupManager(context); 44 } 45 46 @Override isAvailable()47 public boolean isAvailable() { 48 return mUm.isAdminUser(); 49 } 50 51 @Override getPreferenceKey()52 public String getPreferenceKey() { 53 return KEY_BACKUP_SETTINGS; 54 } 55 56 @Override updateState(Preference preference)57 public void updateState(Preference preference) { 58 final boolean backupEnabled = mBackupManager.isBackupEnabled(); 59 60 preference.setSummary(backupEnabled 61 ? R.string.accessibility_feature_state_on 62 : R.string.accessibility_feature_state_off); 63 } 64 } 65