1 /* 2 * Copyright (C) 2021 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.car.settings.enterprise; 18 19 import android.car.drivingstate.CarUxRestrictions; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.provider.Settings; 23 24 import com.android.car.admin.ui.ManagedDeviceTextView; 25 import com.android.car.settings.R; 26 import com.android.car.settings.common.FragmentController; 27 import com.android.settingslib.widget.FooterPreference; 28 29 /** 30 * A preference controller for the disclosure to be shown when the car is managed by an enterprise. 31 * Inspired from {@link com.android.settings.accounts.EnterpriseDisclosurePreferenceController}. 32 */ 33 public final class EnterpriseDisclosurePreferenceController extends 34 BaseEnterprisePreferenceController<FooterPreference> { 35 EnterpriseDisclosurePreferenceController(Context context, String key, FragmentController fragmentController, CarUxRestrictions uxRestrictions)36 public EnterpriseDisclosurePreferenceController(Context context, String key, 37 FragmentController fragmentController, CarUxRestrictions uxRestrictions) { 38 super(context, key, fragmentController, uxRestrictions); 39 } 40 41 @Override getAvailabilityStatus()42 protected int getAvailabilityStatus() { 43 int superStatus = super.getAvailabilityStatus(); 44 if (superStatus != AVAILABLE) { 45 return superStatus; 46 } 47 return EnterpriseUtils.hasDeviceOwner(getContext()) ? AVAILABLE : DISABLED_FOR_PROFILE; 48 } 49 50 @Override updateState(FooterPreference footerPreference)51 protected void updateState(FooterPreference footerPreference) { 52 super.updateState(footerPreference); 53 CharSequence disclosure = ManagedDeviceTextView.getManagedDeviceText(getContext()); 54 if (disclosure == null) { 55 footerPreference.setVisible(false); 56 return; 57 } 58 footerPreference.setVisible(true); 59 footerPreference.setTitle(disclosure); 60 footerPreference.setLearnMoreAction(view -> 61 getContext().startActivity(new Intent(Settings.ACTION_PRIVACY_SETTINGS)) 62 ); 63 String learnMoreContentDescription = getContext().getString( 64 R.string.footer_learn_more_content_description, getLabelName()); 65 footerPreference.setLearnMoreContentDescription(learnMoreContentDescription); 66 } 67 getLabelName()68 private String getLabelName() { 69 return getContext().getString(R.string.user_add_account_menu); 70 } 71 } 72