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.settings.security; 18 19 import static android.app.admin.DevicePolicyResources.Strings.Settings.MORE_SECURITY_SETTINGS_WORK_PROFILE_SUMMARY; 20 21 import android.app.admin.DevicePolicyManager; 22 import android.content.Context; 23 import android.content.pm.CrossProfileApps; 24 25 import com.android.settings.R; 26 import com.android.settings.core.BasePreferenceController; 27 28 /** 29 * Controller to decide the summary of "Advanced settings" option in the 30 * Security settings screen. 31 */ 32 public class SecurityAdvancedSettingsController extends BasePreferenceController { 33 34 private final CrossProfileApps mCrossProfileApps; 35 private final DevicePolicyManager mDevicePolicyManager; 36 SecurityAdvancedSettingsController(Context context, String preferenceKey)37 public SecurityAdvancedSettingsController(Context context, String preferenceKey) { 38 super(context, preferenceKey); 39 40 mCrossProfileApps = context.getSystemService(CrossProfileApps.class); 41 mDevicePolicyManager = context.getSystemService(DevicePolicyManager.class); 42 } 43 44 @Override getAvailabilityStatus()45 public int getAvailabilityStatus() { 46 return AVAILABLE; 47 } 48 49 @Override getSummary()50 public CharSequence getSummary() { 51 return isWorkProfilePresent() 52 ? mDevicePolicyManager.getResources().getString( 53 MORE_SECURITY_SETTINGS_WORK_PROFILE_SUMMARY, 54 () -> mContext.getResources().getString( 55 R.string.security_advanced_settings_work_profile_settings_summary)) 56 : mContext.getResources().getString( 57 R.string.security_advanced_settings_no_work_profile_settings_summary); 58 } 59 isWorkProfilePresent()60 private boolean isWorkProfilePresent() { 61 return !mCrossProfileApps.getTargetUserProfiles().isEmpty(); 62 } 63 } 64