blob: 553edc25fa41e192ff2fd73c438d62b9e07a06e1 [file] [log] [blame]
sunnyshao15ec2cf2018-03-29 19:50:20 +08001/*
2 * Copyright (C) 2018 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.content.Context;
20import android.content.Intent;
sunnyshao15ec2cf2018-03-29 19:50:20 +080021
Fan Zhang23f8d592018-08-28 15:11:40 -070022import androidx.preference.Preference;
23
sunnyshao15ec2cf2018-03-29 19:50:20 +080024import com.android.settings.R;
Fan Zhang16de45d2018-04-30 13:41:56 -070025import com.android.settings.core.BasePreferenceController;
26
sunnyshao15ec2cf2018-03-29 19:50:20 +080027public class ConfigureAccountPreferenceController extends BasePreferenceController {
28 private PrivacySettingsConfigData mPSCD;
29
30 public ConfigureAccountPreferenceController(Context context, String key) {
31 super(context, key);
Fan Zhang16de45d2018-04-30 13:41:56 -070032 mPSCD = PrivacySettingsConfigData.getInstance();
sunnyshao15ec2cf2018-03-29 19:50:20 +080033 }
34
35 @Override
36 public int getAvailabilityStatus() {
37 if (!PrivacySettingsUtils.isAdminUser(mContext)) {
38 return DISABLED_FOR_USER;
39 }
40 if (PrivacySettingsUtils.isInvisibleKey(mContext, PrivacySettingsUtils.CONFIGURE_ACCOUNT)) {
Matthew Fritzef87a1f32018-05-03 16:46:51 -070041 return UNSUPPORTED_ON_DEVICE;
sunnyshao15ec2cf2018-03-29 19:50:20 +080042 }
43 return AVAILABLE;
44 }
45
46 @Override
47 public void updateState(Preference preference) {
48 super.updateState(preference);
49 final Intent configIntent = mPSCD.getConfigIntent();
50 final boolean configureEnabled = (configIntent != null) && mPSCD.isBackupEnabled();
51 preference.setEnabled(configureEnabled);
52 preference.setIntent(configIntent);
53 }
54
55 @Override
56 public CharSequence getSummary() {
57 final String configSummary = mPSCD.getConfigSummary();
58 return configSummary != null
59 ? configSummary
60 : mContext.getText(R.string.backup_configure_account_default_summary);
61 }
62}