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.car.settings.system; 18 19 import static android.os.UserManager.DISALLOW_DEBUGGING_FEATURES; 20 21 import static com.android.car.settings.enterprise.ActionDisabledByAdminDialogFragment.DISABLED_BY_ADMIN_CONFIRM_DIALOG_TAG; 22 import static com.android.car.settings.enterprise.EnterpriseUtils.hasUserRestrictionByDpm; 23 24 import android.car.drivingstate.CarUxRestrictions; 25 import android.content.Context; 26 27 import com.android.car.settings.common.FragmentController; 28 import com.android.car.settings.common.Logger; 29 import com.android.car.settings.common.PreferenceController; 30 import com.android.car.settings.development.DevelopmentSettingsUtil; 31 import com.android.car.settings.enterprise.EnterpriseUtils; 32 import com.android.car.ui.preference.CarUiPreference; 33 34 35 /** Controls the visibility of the developer options setting. */ 36 public class DeveloperOptionsEntryPreferenceController 37 extends PreferenceController<CarUiPreference> { 38 39 private static final Logger LOG = new Logger(DeveloperOptionsEntryPreferenceController.class); 40 DeveloperOptionsEntryPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)41 public DeveloperOptionsEntryPreferenceController(Context context, String preferenceKey, 42 FragmentController fragmentController, CarUxRestrictions uxRestrictions) { 43 super(context, preferenceKey, fragmentController, uxRestrictions); 44 } 45 46 @Override getPreferenceType()47 protected Class<CarUiPreference> getPreferenceType() { 48 return CarUiPreference.class; 49 } 50 51 @Override getDefaultAvailabilityStatus()52 protected int getDefaultAvailabilityStatus() { 53 if (DevelopmentSettingsUtil.isDevelopmentSettingsEnabled(getContext())) { 54 return AVAILABLE; 55 } 56 57 if (hasUserRestrictionByDpm(getContext(), DISALLOW_DEBUGGING_FEATURES)) { 58 return AVAILABLE_FOR_VIEWING; 59 } 60 61 return CONDITIONALLY_UNAVAILABLE; 62 } 63 64 @Override onCreateInternal()65 protected void onCreateInternal() { 66 super.onCreateInternal(); 67 setClickableWhileDisabled(getPreference(), /* clickable= */ true, p -> { 68 if (hasUserRestrictionByDpm(getContext(), DISALLOW_DEBUGGING_FEATURES)) { 69 showActionDisabledByAdminDialog(); 70 } 71 }); 72 } 73 74 @Override handlePreferenceClicked(CarUiPreference preference)75 protected boolean handlePreferenceClicked(CarUiPreference preference) { 76 LOG.d("handlePreferenceClicked"); 77 getContext().startActivity(preference.getIntent()); 78 return true; 79 } 80 showActionDisabledByAdminDialog()81 private void showActionDisabledByAdminDialog() { 82 getFragmentController().showDialog( 83 EnterpriseUtils.getActionDisabledByAdminDialog(getContext(), 84 DISALLOW_DEBUGGING_FEATURES), 85 DISABLED_BY_ADMIN_CONFIRM_DIALOG_TAG); 86 } 87 } 88