Move developer options related class to development package
Bug: 34203528 Test: none, purely moving classes around Change-Id: I3cd1d257f948729fda5c04632e7ce9114c40bd0c
This commit is contained in:
124
src/com/android/settings/development/ColorModePreference.java
Normal file
124
src/com/android/settings/development/ColorModePreference.java
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.content.res.Resources;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.hardware.display.DisplayManager.DisplayListener;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Display;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ColorModePreference extends SwitchPreference implements DisplayListener {
|
||||
|
||||
private DisplayManager mDisplayManager;
|
||||
private Display mDisplay;
|
||||
|
||||
private int mCurrentIndex;
|
||||
private ArrayList<ColorModeDescription> mDescriptions;
|
||||
|
||||
public ColorModePreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mDisplayManager = getContext().getSystemService(DisplayManager.class);
|
||||
}
|
||||
|
||||
public int getColorModeCount() {
|
||||
return mDescriptions.size();
|
||||
}
|
||||
|
||||
public void startListening() {
|
||||
mDisplayManager.registerDisplayListener(this, new Handler(Looper.getMainLooper()));
|
||||
}
|
||||
|
||||
public void stopListening() {
|
||||
mDisplayManager.unregisterDisplayListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisplayAdded(int displayId) {
|
||||
if (displayId == Display.DEFAULT_DISPLAY) {
|
||||
updateCurrentAndSupported();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisplayChanged(int displayId) {
|
||||
if (displayId == Display.DEFAULT_DISPLAY) {
|
||||
updateCurrentAndSupported();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisplayRemoved(int displayId) {
|
||||
}
|
||||
|
||||
public void updateCurrentAndSupported() {
|
||||
mDisplay = mDisplayManager.getDisplay(Display.DEFAULT_DISPLAY);
|
||||
|
||||
mDescriptions = new ArrayList<>();
|
||||
|
||||
Resources resources = getContext().getResources();
|
||||
int[] colorModes = resources.getIntArray(R.array.color_mode_ids);
|
||||
String[] titles = resources.getStringArray(R.array.color_mode_names);
|
||||
String[] descriptions = resources.getStringArray(R.array.color_mode_descriptions);
|
||||
// Map the resource information describing color modes.
|
||||
for (int i = 0; i < colorModes.length; i++) {
|
||||
if (colorModes[i] != -1 && i != 1 /* Skip Natural for now. */) {
|
||||
ColorModeDescription desc = new ColorModeDescription();
|
||||
desc.colorMode = colorModes[i];
|
||||
desc.title = titles[i];
|
||||
desc.summary = descriptions[i];
|
||||
mDescriptions.add(desc);
|
||||
}
|
||||
}
|
||||
|
||||
int currentColorMode = mDisplay.getColorMode();
|
||||
mCurrentIndex = -1;
|
||||
for (int i = 0; i < mDescriptions.size(); i++) {
|
||||
if (mDescriptions.get(i).colorMode == currentColorMode) {
|
||||
mCurrentIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
setChecked(mCurrentIndex == 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean persistBoolean(boolean value) {
|
||||
// Right now this is a switch, so we only support two modes.
|
||||
if (mDescriptions.size() == 2) {
|
||||
ColorModeDescription desc = mDescriptions.get(value ? 1 : 0);
|
||||
|
||||
mDisplay.requestColorMode(desc.colorMode);
|
||||
mCurrentIndex = mDescriptions.indexOf(desc);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static class ColorModeDescription {
|
||||
private int colorMode;
|
||||
private String title;
|
||||
private String summary;
|
||||
}
|
||||
}
|
2847
src/com/android/settings/development/DevelopmentSettings.java
Normal file
2847
src/com/android/settings/development/DevelopmentSettings.java
Normal file
File diff suppressed because it is too large
Load Diff
61
src/com/android/settings/development/OemUnlockUtils.java
Normal file
61
src/com/android/settings/development/OemUnlockUtils.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.service.persistentdata.PersistentDataBlockManager;
|
||||
import android.util.Log;
|
||||
|
||||
public class OemUnlockUtils {
|
||||
private static final String TAG = "OemUnlockUtils";
|
||||
|
||||
/**
|
||||
* Returns whether or not this device is able to be OEM unlocked.
|
||||
*/
|
||||
static boolean isOemUnlockEnabled(Context context) {
|
||||
PersistentDataBlockManager manager = (PersistentDataBlockManager)
|
||||
context.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
|
||||
return manager.getOemUnlockEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows enabling or disabling OEM unlock on this device. OEM unlocked
|
||||
* devices allow users to flash other OSes to them.
|
||||
*/
|
||||
static void setOemUnlockEnabled(Context context, boolean enabled) {
|
||||
try {
|
||||
PersistentDataBlockManager manager = (PersistentDataBlockManager)
|
||||
context.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
|
||||
manager.setOemUnlockEnabled(enabled);
|
||||
} catch (SecurityException e) {
|
||||
Log.e(TAG, "Fail to set oem unlock.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if OEM unlock is disallowed by user restriction
|
||||
* {@link UserManager#DISALLOW_FACTORY_RESET} or {@link UserManager#DISALLOW_OEM_UNLOCK}.
|
||||
* Otherwise, returns {@code false}.
|
||||
*/
|
||||
static boolean isOemUnlockAllowed(UserManager um) {
|
||||
final UserHandle userHandle = UserHandle.of(UserHandle.myUserId());
|
||||
return !(um.hasBaseUserRestriction(UserManager.DISALLOW_OEM_UNLOCK, userHandle)
|
||||
|| um.hasBaseUserRestriction(UserManager.DISALLOW_FACTORY_RESET, userHandle));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user