| Heemin Seog | f401cf2 | 2018-12-06 16:34:00 -0800 | [diff] [blame] | 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 |  | 
| davidln | 8cd3736 | 2018-12-12 10:51:39 -0800 | [diff] [blame] | 19 | import android.car.drivingstate.CarUxRestrictions; | 
| Heemin Seog | f401cf2 | 2018-12-06 16:34:00 -0800 | [diff] [blame] | 20 | import android.content.Context; | 
| Anthony Hugh | 492f184 | 2019-07-11 13:50:15 -0700 | [diff] [blame] | 21 | import android.os.UserManager; | 
| Heemin Seog | f401cf2 | 2018-12-06 16:34:00 -0800 | [diff] [blame] | 22 |  | 
| davidln | 8cd3736 | 2018-12-12 10:51:39 -0800 | [diff] [blame] | 23 | import androidx.preference.Preference; | 
|  | 24 |  | 
| Heemin Seog | f401cf2 | 2018-12-06 16:34:00 -0800 | [diff] [blame] | 25 | import com.android.car.settings.common.FragmentController; | 
| Heemin Seog | 32a493e | 2019-07-18 14:33:55 -0700 | [diff] [blame^] | 26 | import com.android.car.settings.common.Logger; | 
| davidln | 8cd3736 | 2018-12-12 10:51:39 -0800 | [diff] [blame] | 27 | import com.android.car.settings.common.PreferenceController; | 
| Heemin Seog | f401cf2 | 2018-12-06 16:34:00 -0800 | [diff] [blame] | 28 | import com.android.car.settings.development.DevelopmentSettingsUtil; | 
|  | 29 |  | 
|  | 30 | /** Controls the visibility of the developer options setting. */ | 
| davidln | 8cd3736 | 2018-12-12 10:51:39 -0800 | [diff] [blame] | 31 | public class DeveloperOptionsEntryPreferenceController extends PreferenceController<Preference> { | 
| Heemin Seog | f401cf2 | 2018-12-06 16:34:00 -0800 | [diff] [blame] | 32 |  | 
| Heemin Seog | 32a493e | 2019-07-18 14:33:55 -0700 | [diff] [blame^] | 33 | private static final Logger LOG = new Logger(DeveloperOptionsEntryPreferenceController.class); | 
| Anthony Hugh | 492f184 | 2019-07-11 13:50:15 -0700 | [diff] [blame] | 34 | private UserManager mUserManager; | 
| Heemin Seog | f401cf2 | 2018-12-06 16:34:00 -0800 | [diff] [blame] | 35 |  | 
| davidln | 8cd3736 | 2018-12-12 10:51:39 -0800 | [diff] [blame] | 36 | public DeveloperOptionsEntryPreferenceController(Context context, String preferenceKey, | 
|  | 37 | FragmentController fragmentController, CarUxRestrictions uxRestrictions) { | 
|  | 38 | super(context, preferenceKey, fragmentController, uxRestrictions); | 
| Anthony Hugh | 492f184 | 2019-07-11 13:50:15 -0700 | [diff] [blame] | 39 | mUserManager = UserManager.get(context); | 
| Heemin Seog | f401cf2 | 2018-12-06 16:34:00 -0800 | [diff] [blame] | 40 | } | 
|  | 41 |  | 
|  | 42 | @Override | 
| davidln | 8cd3736 | 2018-12-12 10:51:39 -0800 | [diff] [blame] | 43 | protected Class<Preference> getPreferenceType() { | 
|  | 44 | return Preference.class; | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | @Override | 
|  | 48 | protected int getAvailabilityStatus() { | 
| Anthony Hugh | f9447d6 | 2019-07-16 16:23:00 -0700 | [diff] [blame] | 49 | return DevelopmentSettingsUtil.isDevelopmentSettingsEnabled(getContext(), mUserManager) | 
|  | 50 | ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; | 
| Heemin Seog | f401cf2 | 2018-12-06 16:34:00 -0800 | [diff] [blame] | 51 | } | 
| Heemin Seog | 32a493e | 2019-07-18 14:33:55 -0700 | [diff] [blame^] | 52 |  | 
|  | 53 | @Override | 
|  | 54 | protected boolean handlePreferenceClicked(Preference preference) { | 
|  | 55 | // TODO(b/137797266): This should be removed when the root cause of the inconsistency is | 
|  | 56 | //  discovered and fixed. | 
|  | 57 | if (!DevelopmentSettingsUtil.isDeveloperOptionsModuleEnabled(getContext())) { | 
|  | 58 | LOG.e("Inconsistent state: developer options enabled, but developer options module " | 
|  | 59 | + "disabled. Retry enabling..."); | 
|  | 60 | DevelopmentSettingsUtil.setDevelopmentSettingsEnabled(getContext(), /* enable= */ true); | 
|  | 61 | } | 
|  | 62 |  | 
|  | 63 | getContext().startActivity(preference.getIntent()); | 
|  | 64 | return true; | 
|  | 65 | } | 
| Heemin Seog | f401cf2 | 2018-12-06 16:34:00 -0800 | [diff] [blame] | 66 | } |