blob: 07bdf46987a250e2ace74037f68958c33905f8e3 [file] [log] [blame]
Heemin Seogf401cf22018-12-06 16:34:00 -08001/*
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
17package com.android.car.settings.system;
18
davidln8cd37362018-12-12 10:51:39 -080019import android.car.drivingstate.CarUxRestrictions;
Heemin Seogf401cf22018-12-06 16:34:00 -080020import android.content.Context;
Anthony Hugh492f1842019-07-11 13:50:15 -070021import android.os.UserManager;
Heemin Seogf401cf22018-12-06 16:34:00 -080022
davidln8cd37362018-12-12 10:51:39 -080023import androidx.preference.Preference;
24
Heemin Seogf401cf22018-12-06 16:34:00 -080025import com.android.car.settings.common.FragmentController;
Alex Stetson36441602020-05-06 12:10:49 -070026import com.android.car.settings.common.Logger;
davidln8cd37362018-12-12 10:51:39 -080027import com.android.car.settings.common.PreferenceController;
Heemin Seogf401cf22018-12-06 16:34:00 -080028import com.android.car.settings.development.DevelopmentSettingsUtil;
29
30/** Controls the visibility of the developer options setting. */
davidln8cd37362018-12-12 10:51:39 -080031public class DeveloperOptionsEntryPreferenceController extends PreferenceController<Preference> {
Heemin Seogf401cf22018-12-06 16:34:00 -080032
Alex Stetson36441602020-05-06 12:10:49 -070033 private static final Logger LOG = new Logger(DeveloperOptionsEntryPreferenceController.class);
Anthony Hugh492f1842019-07-11 13:50:15 -070034 private UserManager mUserManager;
Heemin Seogf401cf22018-12-06 16:34:00 -080035
davidln8cd37362018-12-12 10:51:39 -080036 public DeveloperOptionsEntryPreferenceController(Context context, String preferenceKey,
37 FragmentController fragmentController, CarUxRestrictions uxRestrictions) {
38 super(context, preferenceKey, fragmentController, uxRestrictions);
Anthony Hugh492f1842019-07-11 13:50:15 -070039 mUserManager = UserManager.get(context);
Heemin Seogf401cf22018-12-06 16:34:00 -080040 }
41
42 @Override
davidln8cd37362018-12-12 10:51:39 -080043 protected Class<Preference> getPreferenceType() {
44 return Preference.class;
45 }
46
47 @Override
48 protected int getAvailabilityStatus() {
Anthony Hughf9447d62019-07-16 16:23:00 -070049 return DevelopmentSettingsUtil.isDevelopmentSettingsEnabled(getContext(), mUserManager)
50 ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
Heemin Seogf401cf22018-12-06 16:34:00 -080051 }
Heemin Seog32a493e2019-07-18 14:33:55 -070052
53 @Override
54 protected boolean handlePreferenceClicked(Preference preference) {
Alex Stetson36441602020-05-06 12:10:49 -070055 // We need to make sure the developer options module is enabled for the following reasons:
56 // - To enable developer options by default on eng builds
57 // - To enable developer options for all admin users when any admin user enables it
58 // This is because on first launch per user, the developer options module may be disabled
59 // while the setting is enabled, so we need to enable the module
Heemin Seog32a493e2019-07-18 14:33:55 -070060 if (!DevelopmentSettingsUtil.isDeveloperOptionsModuleEnabled(getContext())) {
Alex Stetson36441602020-05-06 12:10:49 -070061 LOG.i("Inconsistent state: developer options enabled, but developer options module "
62 + "disabled. Enabling module...");
63 DevelopmentSettingsUtil.setDevelopmentSettingsEnabled(getContext(), /* enable= */
64 true);
Heemin Seog32a493e2019-07-18 14:33:55 -070065 }
Heemin Seog32a493e2019-07-18 14:33:55 -070066 getContext().startActivity(preference.getIntent());
67 return true;
68 }
Heemin Seogf401cf22018-12-06 16:34:00 -080069}