| sunnyshao | 15ec2cf | 2018-03-29 19:50:20 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.settings.backup; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.content.Intent; |
| sunnyshao | 15ec2cf | 2018-03-29 19:50:20 +0800 | [diff] [blame] | 21 | |
| Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 22 | import androidx.preference.Preference; |
| 23 | |
| sunnyshao | 15ec2cf | 2018-03-29 19:50:20 +0800 | [diff] [blame] | 24 | import com.android.settings.R; |
| Fan Zhang | 16de45d | 2018-04-30 13:41:56 -0700 | [diff] [blame] | 25 | import com.android.settings.core.BasePreferenceController; |
| 26 | |
| sunnyshao | 15ec2cf | 2018-03-29 19:50:20 +0800 | [diff] [blame] | 27 | public class ConfigureAccountPreferenceController extends BasePreferenceController { |
| 28 | private PrivacySettingsConfigData mPSCD; |
| 29 | |
| 30 | public ConfigureAccountPreferenceController(Context context, String key) { |
| 31 | super(context, key); |
| Fan Zhang | 16de45d | 2018-04-30 13:41:56 -0700 | [diff] [blame] | 32 | mPSCD = PrivacySettingsConfigData.getInstance(); |
| sunnyshao | 15ec2cf | 2018-03-29 19:50:20 +0800 | [diff] [blame] | 33 | } |
| 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 Fritze | f87a1f3 | 2018-05-03 16:46:51 -0700 | [diff] [blame] | 41 | return UNSUPPORTED_ON_DEVICE; |
| sunnyshao | 15ec2cf | 2018-03-29 19:50:20 +0800 | [diff] [blame] | 42 | } |
| 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 | } |