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; 21 22 import androidx.preference.Preference; 23 24 import com.android.settings.R; 25 import com.android.settings.core.BasePreferenceController; 26 27 public class ConfigureAccountPreferenceController extends BasePreferenceController { 28 private PrivacySettingsConfigData mPSCD; 29 ConfigureAccountPreferenceController(Context context, String key)30 public ConfigureAccountPreferenceController(Context context, String key) { 31 super(context, key); 32 mPSCD = PrivacySettingsConfigData.getInstance(); 33 } 34 35 @Override getAvailabilityStatus()36 public int getAvailabilityStatus() { 37 if (!PrivacySettingsUtils.isAdminUser(mContext)) { 38 return DISABLED_FOR_USER; 39 } 40 if (PrivacySettingsUtils.isInvisibleKey(mContext, PrivacySettingsUtils.CONFIGURE_ACCOUNT)) { 41 return UNSUPPORTED_ON_DEVICE; 42 } 43 return AVAILABLE; 44 } 45 46 @Override updateState(Preference preference)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 getSummary()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 }