Add check for DISALLOW_DEBUGGING_FEATURES restriction

- if the user has restriction for the action
  DISALLOW_DEBUGGING_FEATURES, remove the preference for taking bug
  report and the switch preference to enable bug report shortcut in the
  power key.
- refactor DevelopmentSettings to use preference controller for Take bug
  report and enable bug report in power key.

Fixes: 27145643
Test: make RunSettingsRoboTests

Change-Id: I18784d218d37956130c33f527d514ab703727397
This commit is contained in:
Doris Ling
2016-12-07 13:21:20 -08:00
parent fb8d1bf427
commit cc20600102
5 changed files with 499 additions and 26 deletions

View File

@@ -0,0 +1,62 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.development;
import android.content.Context;
import android.os.UserManager;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.core.PreferenceController;
public class BugReportPreferenceController extends PreferenceController {
private static final String KEY_BUGREPORT = "bugreport";
private UserManager mUserManager;
private Preference mPreference;
public BugReportPreferenceController(Context context) {
super(context);
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
if (isAvailable()) {
mPreference = screen.findPreference(KEY_BUGREPORT);
}
}
@Override
public String getPreferenceKey() {
return KEY_BUGREPORT;
}
@Override
public boolean isAvailable() {
return !mUserManager.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
}
public void enablePreference(boolean enabled) {
if (isAvailable()) {
mPreference.setEnabled(enabled);
}
}
}