diff options
author | 2018-03-28 12:19:38 +0100 | |
---|---|---|
committer | 2018-04-05 11:59:31 +0000 | |
commit | 7a32fba76a15d356d929b35db516fcf3f136defb (patch) | |
tree | 701cf5d2b58cee8d9e45bcc7a681b667e8d29be5 | |
parent | c83cf90166120435e09a1dd4a436e095622b071c (diff) |
Added adb commands to set and reset brightness.
adb shell cmd display set-brightness BRIGHTNESS command sets the
screen brightness programatically.
adb shell cmd display reset-brightness resets the brightness
configuration to the default configuration.
Test: run "adb shell cmd display set-brightness <number>" and watch
the magic happen.
Test: run "adb shell cmd jobscheduler run -f
com.google.android.apps.turbo 104" to push a new configuration,
then run "adb shell cmd display reset-brightness-configuration"
to reset it. If it's not noticable enough, you can manually
edit /data/system/display-manager-state.xml: for example, set
nits="0.0" for all the <brightness-point />s in the
<brightness-curve /> to make it as dark as posible.
Fixes: 77574628
Change-Id: I37e19c1e662370e60c9f616a3710780f16418620
-rw-r--r-- | services/core/java/com/android/server/display/DisplayManagerService.java | 28 | ||||
-rw-r--r-- | services/core/java/com/android/server/display/DisplayManagerShellCommand.java | 92 |
2 files changed, 119 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java index c7ae1f4f5e50..93e0bd5b45c5 100644 --- a/services/core/java/com/android/server/display/DisplayManagerService.java +++ b/services/core/java/com/android/server/display/DisplayManagerService.java @@ -61,12 +61,15 @@ import android.os.Message; import android.os.PowerManager; import android.os.Process; import android.os.RemoteException; +import android.os.ResultReceiver; import android.os.ServiceManager; +import android.os.ShellCallback; import android.os.SystemClock; import android.os.SystemProperties; import android.os.Trace; import android.os.UserHandle; import android.os.UserManager; +import android.provider.Settings; import android.text.TextUtils; import android.util.IntArray; import android.util.Slog; @@ -1030,7 +1033,7 @@ public final class DisplayManagerService extends SystemService { } private void setBrightnessConfigurationForUserInternal( - @NonNull BrightnessConfiguration c, @UserIdInt int userId, + @Nullable BrightnessConfiguration c, @UserIdInt int userId, @Nullable String packageName) { final int userSerial = getUserManager().getUserSerialNumber(userId); synchronized (mSyncRoot) { @@ -1983,6 +1986,29 @@ public final class DisplayManagerService extends SystemService { } } + @Override // Binder call + public void onShellCommand(FileDescriptor in, FileDescriptor out, + FileDescriptor err, String[] args, ShellCallback callback, + ResultReceiver resultReceiver) { + final long token = Binder.clearCallingIdentity(); + try { + DisplayManagerShellCommand command = new DisplayManagerShellCommand(this); + command.exec(this, in, out, err, args, callback, resultReceiver); + } finally { + Binder.restoreCallingIdentity(token); + } + } + + void setBrightness(int brightness) { + Settings.System.putIntForUser(mContext.getContentResolver(), + Settings.System.SCREEN_BRIGHTNESS, brightness, UserHandle.USER_CURRENT); + } + + void resetBrightnessConfiguration() { + setBrightnessConfigurationForUserInternal(null, mContext.getUserId(), + mContext.getPackageName()); + } + private boolean validatePackageName(int uid, String packageName) { if (packageName != null) { String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid); diff --git a/services/core/java/com/android/server/display/DisplayManagerShellCommand.java b/services/core/java/com/android/server/display/DisplayManagerShellCommand.java new file mode 100644 index 000000000000..27cad1eece09 --- /dev/null +++ b/services/core/java/com/android/server/display/DisplayManagerShellCommand.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2018 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.server.display; + +import android.content.Intent; +import android.os.RemoteException; +import android.os.ResultReceiver; +import android.os.ShellCallback; +import android.os.ShellCommand; +import android.util.Slog; + +import java.io.PrintWriter; +import java.lang.NumberFormatException; + +class DisplayManagerShellCommand extends ShellCommand { + private static final String TAG = "DisplayManagerShellCommand"; + + private final DisplayManagerService.BinderService mService; + + DisplayManagerShellCommand(DisplayManagerService.BinderService service) { + mService = service; + } + + @Override + public int onCommand(String cmd) { + if (cmd == null) { + return handleDefaultCommands(cmd); + } + final PrintWriter pw = getOutPrintWriter(); + switch(cmd) { + case "set-brightness": + return setBrightness(); + case "reset-brightness-configuration": + return resetBrightnessConfiguration(); + default: + return handleDefaultCommands(cmd); + } + } + + @Override + public void onHelp() { + final PrintWriter pw = getOutPrintWriter(); + pw.println("Display manager commands:"); + pw.println(" help"); + pw.println(" Print this help text."); + pw.println(); + pw.println(" set-brightness BRIGHTNESS"); + pw.println(" Sets the current brightness to BRIGHTNESS (a number between 0 and 1)."); + pw.println(" reset-brightness-configuration"); + pw.println(" Reset the brightness to its default configuration."); + pw.println(); + Intent.printIntentArgsHelp(pw , ""); + } + + private int setBrightness() { + String brightnessText = getNextArg(); + if (brightnessText == null) { + getErrPrintWriter().println("Error: no brightness specified"); + return 1; + } + float brightness = -1; + try { + brightness = Float.parseFloat(brightnessText); + } catch (NumberFormatException e) { + } + if (brightness < 0 || brightness > 1) { + getErrPrintWriter().println("Error: brightness should be a number between 0 and 1"); + return 1; + } + mService.setBrightness((int) brightness * 255); + return 0; + } + + private int resetBrightnessConfiguration() { + mService.resetBrightnessConfiguration(); + return 0; + } +} |