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.development;
18 
19 import static com.android.settingslib.RestrictedLockUtilsInternal.checkIfUsbDataSignalingIsDisabled;
20 
21 import android.content.Context;
22 import android.os.UserHandle;
23 
24 import androidx.preference.Preference;
25 import androidx.preference.PreferenceScreen;
26 
27 import com.android.settings.core.PreferenceControllerMixin;
28 import com.android.settingslib.RestrictedPreference;
29 import com.android.settingslib.development.DeveloperOptionsPreferenceController;
30 
31 public class DefaultUsbConfigurationPreferenceController extends
32         DeveloperOptionsPreferenceController implements PreferenceControllerMixin {
33 
34     private static final String PREFERENCE_KEY = "default_usb_configuration";
35 
36     private RestrictedPreference mPreference;
37 
DefaultUsbConfigurationPreferenceController(Context context)38     public DefaultUsbConfigurationPreferenceController(Context context) {
39         super(context);
40     }
41 
42     @Override
getPreferenceKey()43     public String getPreferenceKey() {
44         return PREFERENCE_KEY;
45     }
46 
47     @Override
displayPreference(PreferenceScreen screen)48     public void displayPreference(PreferenceScreen screen) {
49         super.displayPreference(screen);
50         mPreference = screen.findPreference(getPreferenceKey());
51     }
52 
53     @Override
updateState(Preference preference)54     public void updateState(Preference preference) {
55         mPreference.setDisabledByAdmin(
56                 checkIfUsbDataSignalingIsDisabled(mContext, UserHandle.myUserId()));
57     }
58 
59     @Override
onDeveloperOptionsSwitchEnabled()60     protected void onDeveloperOptionsSwitchEnabled() {
61         super.onDeveloperOptionsSwitchEnabled();
62         mPreference.setDisabledByAdmin(
63                 checkIfUsbDataSignalingIsDisabled(mContext, UserHandle.myUserId()));
64     }
65 }
66