1 /* 2 * Copyright 2019 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.security; 18 19 import static android.os.UserManager.DISALLOW_CONFIG_CREDENTIALS; 20 21 import static com.android.car.settings.enterprise.ActionDisabledByAdminDialogFragment.DISABLED_BY_ADMIN_CONFIRM_DIALOG_TAG; 22 23 import android.car.drivingstate.CarUxRestrictions; 24 import android.content.Context; 25 import android.os.UserManager; 26 27 import androidx.preference.Preference; 28 29 import com.android.car.settings.common.FragmentController; 30 import com.android.car.settings.common.PreferenceController; 31 import com.android.car.settings.enterprise.EnterpriseUtils; 32 33 /** Controls whether the option to reset credentials is shown to the user. */ 34 public class CredentialsResetPreferenceController extends PreferenceController<Preference> { 35 36 private final UserManager mUserManager; 37 CredentialsResetPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)38 public CredentialsResetPreferenceController(Context context, String preferenceKey, 39 FragmentController fragmentController, CarUxRestrictions uxRestrictions) { 40 super(context, preferenceKey, fragmentController, uxRestrictions); 41 mUserManager = UserManager.get(context); 42 } 43 44 @Override getPreferenceType()45 protected Class<Preference> getPreferenceType() { 46 return Preference.class; 47 } 48 49 @Override onCreateInternal()50 protected void onCreateInternal() { 51 super.onCreateInternal(); 52 setClickableWhileDisabled(getPreference(), /* clickable= */ true, p -> { 53 if (EnterpriseUtils 54 .hasUserRestrictionByDpm(getContext(), DISALLOW_CONFIG_CREDENTIALS)) { 55 showActionDisabledByAdminDialog(); 56 } 57 }); 58 } 59 60 @Override getDefaultAvailabilityStatus()61 public int getDefaultAvailabilityStatus() { 62 if (EnterpriseUtils.hasUserRestrictionByUm(getContext(), DISALLOW_CONFIG_CREDENTIALS)) { 63 return DISABLED_FOR_PROFILE; 64 } 65 if (EnterpriseUtils.hasUserRestrictionByDpm(getContext(), DISALLOW_CONFIG_CREDENTIALS)) { 66 return AVAILABLE_FOR_VIEWING; 67 } 68 return AVAILABLE; 69 } 70 showActionDisabledByAdminDialog()71 private void showActionDisabledByAdminDialog() { 72 getFragmentController().showDialog( 73 EnterpriseUtils.getActionDisabledByAdminDialog(getContext(), 74 DISALLOW_CONFIG_CREDENTIALS), 75 DISABLED_BY_ADMIN_CONFIRM_DIALOG_TAG); 76 } 77 } 78