Merge "Add proximity wakelock shell command" into tm-qpr-dev am: 504bed432d
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20249003 Change-Id: Ifec8d5f428650ae62edd6c85d4d04f6aa7c1ac7c Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -1033,7 +1033,7 @@ public final class PowerManagerService extends SystemService
|
|||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mBinderService = new BinderService();
|
mBinderService = new BinderService(mContext);
|
||||||
mLocalService = new LocalService();
|
mLocalService = new LocalService();
|
||||||
mNativeWrapper = injector.createNativeWrapper();
|
mNativeWrapper = injector.createNativeWrapper();
|
||||||
mSystemProperties = injector.createSystemPropertiesWrapper();
|
mSystemProperties = injector.createSystemPropertiesWrapper();
|
||||||
@@ -5465,12 +5465,17 @@ public final class PowerManagerService extends SystemService
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
final class BinderService extends IPowerManager.Stub {
|
final class BinderService extends IPowerManager.Stub {
|
||||||
|
private final PowerManagerShellCommand mShellCommand;
|
||||||
|
|
||||||
|
BinderService(Context context) {
|
||||||
|
mShellCommand = new PowerManagerShellCommand(context, this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onShellCommand(FileDescriptor in, FileDescriptor out,
|
public void onShellCommand(FileDescriptor in, FileDescriptor out,
|
||||||
FileDescriptor err, String[] args, ShellCallback callback,
|
FileDescriptor err, String[] args, ShellCallback callback,
|
||||||
ResultReceiver resultReceiver) {
|
ResultReceiver resultReceiver) {
|
||||||
(new PowerManagerShellCommand(this)).exec(
|
mShellCommand.exec(this, in, out, err, args, callback, resultReceiver);
|
||||||
this, in, out, err, args, callback, resultReceiver);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // Binder call
|
@Override // Binder call
|
||||||
|
|||||||
@@ -16,10 +16,15 @@
|
|||||||
|
|
||||||
package com.android.server.power;
|
package com.android.server.power;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.PowerManager;
|
||||||
|
import android.os.PowerManager.WakeLock;
|
||||||
import android.os.PowerManagerInternal;
|
import android.os.PowerManagerInternal;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ShellCommand;
|
import android.os.ShellCommand;
|
||||||
|
import android.util.SparseArray;
|
||||||
|
import android.view.Display;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -27,9 +32,13 @@ import java.util.List;
|
|||||||
class PowerManagerShellCommand extends ShellCommand {
|
class PowerManagerShellCommand extends ShellCommand {
|
||||||
private static final int LOW_POWER_MODE_ON = 1;
|
private static final int LOW_POWER_MODE_ON = 1;
|
||||||
|
|
||||||
final PowerManagerService.BinderService mService;
|
private final Context mContext;
|
||||||
|
private final PowerManagerService.BinderService mService;
|
||||||
|
|
||||||
PowerManagerShellCommand(PowerManagerService.BinderService service) {
|
private SparseArray<WakeLock> mProxWakelocks = new SparseArray<>();
|
||||||
|
|
||||||
|
PowerManagerShellCommand(Context context, PowerManagerService.BinderService service) {
|
||||||
|
mContext = context;
|
||||||
mService = service;
|
mService = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +61,8 @@ class PowerManagerShellCommand extends ShellCommand {
|
|||||||
return runSuppressAmbientDisplay();
|
return runSuppressAmbientDisplay();
|
||||||
case "list-ambient-display-suppression-tokens":
|
case "list-ambient-display-suppression-tokens":
|
||||||
return runListAmbientDisplaySuppressionTokens();
|
return runListAmbientDisplaySuppressionTokens();
|
||||||
|
case "set-prox":
|
||||||
|
return runSetProx();
|
||||||
default:
|
default:
|
||||||
return handleDefaultCommands(cmd);
|
return handleDefaultCommands(cmd);
|
||||||
}
|
}
|
||||||
@@ -117,6 +128,56 @@ class PowerManagerShellCommand extends ShellCommand {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** TODO: Consider updating this code to support all wakelock types. */
|
||||||
|
private int runSetProx() throws RemoteException {
|
||||||
|
PrintWriter pw = getOutPrintWriter();
|
||||||
|
final boolean acquire;
|
||||||
|
switch (getNextArgRequired().toLowerCase()) {
|
||||||
|
case "list":
|
||||||
|
pw.println("Wakelocks:");
|
||||||
|
pw.println(mProxWakelocks);
|
||||||
|
return 0;
|
||||||
|
case "acquire":
|
||||||
|
acquire = true;
|
||||||
|
break;
|
||||||
|
case "release":
|
||||||
|
acquire = false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
pw.println("Error: Allowed options are 'list' 'enable' and 'disable'.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int displayId = Display.INVALID_DISPLAY;
|
||||||
|
String displayOption = getNextArg();
|
||||||
|
if ("-d".equals(displayOption)) {
|
||||||
|
String idStr = getNextArg();
|
||||||
|
displayId = Integer.parseInt(idStr);
|
||||||
|
if (displayId < 0) {
|
||||||
|
pw.println("Error: Specified displayId (" + idStr + ") must a non-negative int.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int wakelockIndex = displayId + 1; // SparseArray doesn't support negative indexes
|
||||||
|
WakeLock wakelock = mProxWakelocks.get(wakelockIndex);
|
||||||
|
if (wakelock == null) {
|
||||||
|
PowerManager pm = mContext.getSystemService(PowerManager.class);
|
||||||
|
wakelock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,
|
||||||
|
"PowerManagerShellCommand[" + displayId + "]", displayId);
|
||||||
|
mProxWakelocks.put(wakelockIndex, wakelock);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (acquire) {
|
||||||
|
wakelock.acquire();
|
||||||
|
} else {
|
||||||
|
wakelock.release();
|
||||||
|
}
|
||||||
|
pw.println(wakelock);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHelp() {
|
public void onHelp() {
|
||||||
final PrintWriter pw = getOutPrintWriter();
|
final PrintWriter pw = getOutPrintWriter();
|
||||||
@@ -138,6 +199,11 @@ class PowerManagerShellCommand extends ShellCommand {
|
|||||||
pw.println(" ambient display");
|
pw.println(" ambient display");
|
||||||
pw.println(" list-ambient-display-suppression-tokens");
|
pw.println(" list-ambient-display-suppression-tokens");
|
||||||
pw.println(" prints the tokens used to suppress ambient display");
|
pw.println(" prints the tokens used to suppress ambient display");
|
||||||
|
pw.println(" set-prox [list|acquire|release] (-d <display_id>)");
|
||||||
|
pw.println(" Acquires the proximity sensor wakelock. Wakelock is associated with");
|
||||||
|
pw.println(" a specific display if specified. 'list' lists wakelocks previously");
|
||||||
|
pw.println(" created by set-prox including their held status.");
|
||||||
|
|
||||||
pw.println();
|
pw.println();
|
||||||
Intent.printIntentArgsHelp(pw , "");
|
Intent.printIntentArgsHelp(pw , "");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user