Loading services/core/java/com/android/server/display/DisplayManagerService.java +27 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading Loading @@ -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); Loading services/core/java/com/android/server/display/DisplayManagerShellCommand.java 0 → 100644 +92 −0 Original line number Diff line number Diff line /* * 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; } } Loading
services/core/java/com/android/server/display/DisplayManagerService.java +27 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading Loading @@ -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); Loading
services/core/java/com/android/server/display/DisplayManagerShellCommand.java 0 → 100644 +92 −0 Original line number Diff line number Diff line /* * 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; } }