Add ADB commands to control ambient display
Adds the following ADB commands 'adb shell cmd power suppress-ambient-display <token> true|false' Controls suppressing ambient display through PowerManager#suppressAmbientDisplay() 'adb shell cmd power list-ambient-display-suppression-tokens' Prints the tokens suppressing ambient display through the suppress-ambient-display command Bug: 151138820 Test: Invoking the ADB commands, FrameworksServicesTests:PowerManagerServiceTest Change-Id: I49686ae60d83a40311ceb0c92732ddb298f0374b
This commit is contained in:
@@ -29,7 +29,9 @@ import android.util.Slog;
|
||||
import com.android.internal.statusbar.IStatusBarService;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -72,6 +74,24 @@ public class AmbientDisplaySuppressionController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tokens used to suppress ambient display through
|
||||
* {@link #suppress(String, int, boolean)}.
|
||||
*
|
||||
* @param callingUid The uid of the calling application.
|
||||
*/
|
||||
List<String> getSuppressionTokens(int callingUid) {
|
||||
List<String> result = new ArrayList<>();
|
||||
synchronized (mSuppressionTokens) {
|
||||
for (Pair<String, Integer> token : mSuppressionTokens) {
|
||||
if (token.second == callingUid) {
|
||||
result.add(token.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether ambient display is suppressed for the given token.
|
||||
*
|
||||
|
||||
@@ -5500,6 +5500,22 @@ public final class PowerManagerService extends SystemService
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tokens used to suppress ambient display by the calling app.
|
||||
*
|
||||
* <p>The calling app suppressed ambient display by calling
|
||||
* {@link #suppressAmbientDisplay(String, boolean)}.
|
||||
*/
|
||||
public List<String> getAmbientDisplaySuppressionTokens() {
|
||||
final int uid = Binder.getCallingUid();
|
||||
final long ident = Binder.clearCallingIdentity();
|
||||
try {
|
||||
return mAmbientDisplaySuppressionController.getSuppressionTokens(uid);
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
||||
@@ -17,20 +17,20 @@
|
||||
package com.android.server.power;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.IPowerManager;
|
||||
import android.os.PowerManagerInternal;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ShellCommand;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.List;
|
||||
|
||||
class PowerManagerShellCommand extends ShellCommand {
|
||||
private static final int LOW_POWER_MODE_ON = 1;
|
||||
|
||||
final IPowerManager mInterface;
|
||||
final PowerManagerService.BinderService mService;
|
||||
|
||||
PowerManagerShellCommand(IPowerManager service) {
|
||||
mInterface = service;
|
||||
PowerManagerShellCommand(PowerManagerService.BinderService service) {
|
||||
mService = service;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,6 +48,10 @@ class PowerManagerShellCommand extends ShellCommand {
|
||||
return runSetMode();
|
||||
case "set-fixed-performance-mode-enabled":
|
||||
return runSetFixedPerformanceModeEnabled();
|
||||
case "suppress-ambient-display":
|
||||
return runSuppressAmbientDisplay();
|
||||
case "list-ambient-display-suppression-tokens":
|
||||
return runListAmbientDisplaySuppressionTokens();
|
||||
default:
|
||||
return handleDefaultCommands(cmd);
|
||||
}
|
||||
@@ -58,7 +62,7 @@ class PowerManagerShellCommand extends ShellCommand {
|
||||
}
|
||||
|
||||
private int runSetAdaptiveEnabled() throws RemoteException {
|
||||
mInterface.setAdaptivePowerSaveEnabled(Boolean.parseBoolean(getNextArgRequired()));
|
||||
mService.setAdaptivePowerSaveEnabled(Boolean.parseBoolean(getNextArgRequired()));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -71,12 +75,12 @@ class PowerManagerShellCommand extends ShellCommand {
|
||||
pw.println("Error: " + ex.toString());
|
||||
return -1;
|
||||
}
|
||||
mInterface.setPowerSaveModeEnabled(mode == LOW_POWER_MODE_ON);
|
||||
mService.setPowerSaveModeEnabled(mode == LOW_POWER_MODE_ON);
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int runSetFixedPerformanceModeEnabled() throws RemoteException {
|
||||
boolean success = mInterface.setPowerModeChecked(
|
||||
boolean success = mService.setPowerModeChecked(
|
||||
PowerManagerInternal.MODE_FIXED_PERFORMANCE,
|
||||
Boolean.parseBoolean(getNextArgRequired()));
|
||||
if (!success) {
|
||||
@@ -87,6 +91,32 @@ class PowerManagerShellCommand extends ShellCommand {
|
||||
return success ? 0 : -1;
|
||||
}
|
||||
|
||||
private int runSuppressAmbientDisplay() throws RemoteException {
|
||||
final PrintWriter pw = getOutPrintWriter();
|
||||
|
||||
try {
|
||||
String token = getNextArgRequired();
|
||||
boolean enabled = Boolean.parseBoolean(getNextArgRequired());
|
||||
mService.suppressAmbientDisplay(token, enabled);
|
||||
} catch (RuntimeException ex) {
|
||||
pw.println("Error: " + ex.toString());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int runListAmbientDisplaySuppressionTokens() throws RemoteException {
|
||||
final PrintWriter pw = getOutPrintWriter();
|
||||
List<String> tokens = mService.getAmbientDisplaySuppressionTokens();
|
||||
if (tokens.isEmpty()) {
|
||||
pw.println("none");
|
||||
} else {
|
||||
pw.println(String.format("[%s]", String.join(", ", tokens)));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public void onHelp() {
|
||||
final PrintWriter pw = getOutPrintWriter();
|
||||
@@ -103,6 +133,11 @@ class PowerManagerShellCommand extends ShellCommand {
|
||||
pw.println(" enables or disables fixed performance mode");
|
||||
pw.println(" note: this will affect system performance and should only be used");
|
||||
pw.println(" during development");
|
||||
pw.println(" suppress-ambient-display <token> [true|false]");
|
||||
pw.println(" suppresses the current ambient display configuration and disables");
|
||||
pw.println(" ambient display");
|
||||
pw.println(" list-ambient-display-suppression-tokens");
|
||||
pw.println(" prints the tokens used to suppress ambient display");
|
||||
pw.println();
|
||||
Intent.printIntentArgsHelp(pw , "");
|
||||
}
|
||||
|
||||
@@ -1052,6 +1052,35 @@ public class PowerManagerServiceTest {
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAmbientDisplaySuppressionTokens_default() {
|
||||
createService();
|
||||
BinderService service = mService.getBinderServiceInstance();
|
||||
|
||||
assertThat(service.getAmbientDisplaySuppressionTokens()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAmbientDisplaySuppressionTokens_singleToken() {
|
||||
createService();
|
||||
BinderService service = mService.getBinderServiceInstance();
|
||||
service.suppressAmbientDisplay("test1", true);
|
||||
service.suppressAmbientDisplay("test2", false);
|
||||
|
||||
assertThat(service.getAmbientDisplaySuppressionTokens()).containsExactly("test1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAmbientDisplaySuppressionTokens_multipleTokens() {
|
||||
createService();
|
||||
BinderService service = mService.getBinderServiceInstance();
|
||||
service.suppressAmbientDisplay("test1", true);
|
||||
service.suppressAmbientDisplay("test2", true);
|
||||
|
||||
assertThat(service.getAmbientDisplaySuppressionTokens())
|
||||
.containsExactly("test1", "test2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetPowerBoost_redirectsCallToNativeWrapper() {
|
||||
createService();
|
||||
|
||||
Reference in New Issue
Block a user