• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.settingslib.development;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.os.Build;
22 import android.os.UserManager;
23 import android.provider.Settings;
24 
25 import androidx.localbroadcastmanager.content.LocalBroadcastManager;
26 
27 public class DevelopmentSettingsEnabler {
28 
29     public static final String DEVELOPMENT_SETTINGS_CHANGED_ACTION =
30             "com.android.settingslib.development.DevelopmentSettingsEnabler.SETTINGS_CHANGED";
31 
DevelopmentSettingsEnabler()32     private DevelopmentSettingsEnabler() {
33     }
34 
setDevelopmentSettingsEnabled(Context context, boolean enable)35     public static void setDevelopmentSettingsEnabled(Context context, boolean enable) {
36         Settings.Global.putInt(context.getContentResolver(),
37                 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, enable ? 1 : 0);
38         LocalBroadcastManager.getInstance(context)
39                 .sendBroadcast(new Intent(DEVELOPMENT_SETTINGS_CHANGED_ACTION));
40     }
41 
isDevelopmentSettingsEnabled(Context context)42     public static boolean isDevelopmentSettingsEnabled(Context context) {
43         final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
44         final boolean settingEnabled = Settings.Global.getInt(context.getContentResolver(),
45                 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED,
46                 Build.TYPE.equals("eng") ? 1 : 0) != 0;
47         final boolean hasRestriction = um.hasUserRestriction(
48                 UserManager.DISALLOW_DEBUGGING_FEATURES);
49         final boolean isAdmin = um.isAdminUser();
50         return isAdmin && !hasRestriction && settingEnabled;
51     }
52 }
53