• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.settingslib.RestrictedSwitchPreference;
28 import com.android.settingslib.development.DeveloperOptionsPreferenceController;
29 
30 public class DefaultUsbConfigurationPreferenceController extends
31         DeveloperOptionsPreferenceController {
32 
33     private static final String PREFERENCE_KEY = "default_usb_configuration";
34 
35     private RestrictedSwitchPreference mPreference;
36 
DefaultUsbConfigurationPreferenceController(Context context)37     public DefaultUsbConfigurationPreferenceController(Context context) {
38         super(context);
39     }
40 
41     @Override
getPreferenceKey()42     public String getPreferenceKey() {
43         return PREFERENCE_KEY;
44     }
45 
46     @Override
displayPreference(PreferenceScreen screen)47     public void displayPreference(PreferenceScreen screen) {
48         super.displayPreference(screen);
49         mPreference = screen.findPreference(getPreferenceKey());
50     }
51 
52     @Override
updateState(Preference preference)53     public void updateState(Preference preference) {
54         mPreference.setDisabledByAdmin(
55                 checkIfUsbDataSignalingIsDisabled(mContext, UserHandle.myUserId()));
56     }
57 
58     @Override
onDeveloperOptionsSwitchEnabled()59     protected void onDeveloperOptionsSwitchEnabled() {
60         super.onDeveloperOptionsSwitchEnabled();
61         mPreference.setDisabledByAdmin(
62                 checkIfUsbDataSignalingIsDisabled(mContext, UserHandle.myUserId()));
63     }
64 }
65