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.car.ui.preference.CarUiFooterPreference; 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<CarUiFooterPreference> { 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 getDefaultAvailabilityStatus()42 protected int getDefaultAvailabilityStatus() { 43 return EnterpriseUtils.hasDeviceOwner(getContext()) ? AVAILABLE : DISABLED_FOR_PROFILE; 44 } 45 46 @Override updateState(CarUiFooterPreference footerPreference)47 protected void updateState(CarUiFooterPreference footerPreference) { 48 super.updateState(footerPreference); 49 CharSequence disclosure = ManagedDeviceTextView.getManagedDeviceText(getContext()); 50 if (disclosure == null) { 51 footerPreference.setVisible(false); 52 return; 53 } 54 footerPreference.setVisible(true); 55 footerPreference.setSummary(disclosure); 56 String learnMoreText = getContext().getString( 57 R.string.footer_learn_more_content_description, getLabelName()); 58 footerPreference.setLink(learnMoreText, () -> 59 getContext().startActivity(new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS)) 60 ); 61 } 62 getLabelName()63 private String getLabelName() { 64 return getContext().getString(R.string.user_add_account_menu); 65 } 66 } 67