Home | History | Annotate | Download | only in backup
      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.UserManager;
     22 import android.support.v7.preference.Preference;
     23 
     24 import com.android.settings.R;
     25 import com.android.settings.core.PreferenceControllerMixin;
     26 import com.android.settingslib.core.AbstractPreferenceController;
     27 
     28 public class BackupSettingsActivityPreferenceController extends
     29         AbstractPreferenceController implements PreferenceControllerMixin {
     30     private static final String KEY_BACKUP_SETTINGS = "backup_settings";
     31     private static final String TAG = "BackupSettingActivityPC" ;
     32 
     33     private final UserManager mUm;
     34     private final BackupManager mBackupManager;
     35 
     36     public BackupSettingsActivityPreferenceController(Context context) {
     37         super(context);
     38         mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
     39         mBackupManager = new BackupManager(context);
     40     }
     41 
     42     @Override
     43     public boolean isAvailable() {
     44         return mUm.isAdminUser();
     45     }
     46 
     47     @Override
     48     public String getPreferenceKey() {
     49         return KEY_BACKUP_SETTINGS;
     50     }
     51 
     52     @Override
     53     public void updateState(Preference preference) {
     54         final boolean backupEnabled = mBackupManager.isBackupEnabled();
     55 
     56         preference.setSummary(backupEnabled
     57                 ? R.string.accessibility_feature_state_on
     58                 : R.string.accessibility_feature_state_off);
     59     }
     60 }
     61