PowerManager: add powerHint method

Add powerHint method to IPowerManager for passing power hints from other
processes.

Change-Id: Ic596ace2ed1796a6da4cddb2163dcc4536115e55
diff --git a/core/java/android/os/IPowerManager.aidl b/core/java/android/os/IPowerManager.aidl
index d03b0c5..be3c0cc 100644
--- a/core/java/android/os/IPowerManager.aidl
+++ b/core/java/android/os/IPowerManager.aidl
@@ -23,7 +23,7 @@
 
 interface IPowerManager
 {
-    // WARNING: The first four methods must remain the first three methods because their
+    // WARNING: The first five methods must remain the first five methods because their
     // transaction numbers must not change unless IPowerManager.cpp is also updated.
     void acquireWakeLock(IBinder lock, int flags, String tag, String packageName, in WorkSource ws,
             String historyTag);
@@ -31,6 +31,7 @@
             int uidtoblame);
     void releaseWakeLock(IBinder lock, int flags);
     void updateWakeLockUids(IBinder lock, in int[] uids);
+    oneway void powerHint(int hintId, int data);
 
     void updateWakeLockWorkSource(IBinder lock, in WorkSource ws, String historyTag);
     boolean isWakeLockLevelSupported(int level);
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index 80c3c8e..b85a506 100644
--- a/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -406,6 +406,7 @@
     private static native void nativeReleaseSuspendBlocker(String name);
     private static native void nativeSetInteractive(boolean enable);
     private static native void nativeSetAutoSuspend(boolean enable);
+    private static native void nativeSendPowerHint(int hintId, int data);
 
     public PowerManagerService(Context context) {
         super(context);
@@ -2548,6 +2549,12 @@
         }
 
         @Override // Binder call
+        public void powerHint(int hintId, int data) {
+            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
+            nativeSendPowerHint(hintId, data);
+        }
+
+        @Override // Binder call
         public void acquireWakeLock(IBinder lock, int flags, String tag, String packageName,
                 WorkSource ws, String historyTag) {
             if (lock == null) {
diff --git a/services/core/jni/com_android_server_power_PowerManagerService.cpp b/services/core/jni/com_android_server_power_PowerManagerService.cpp
index 151e134..3ee2b16 100644
--- a/services/core/jni/com_android_server_power_PowerManagerService.cpp
+++ b/services/core/jni/com_android_server_power_PowerManagerService.cpp
@@ -189,6 +189,12 @@
     }
 }
 
+static void nativeSendPowerHint(JNIEnv *env, jclass clazz, jint hintId, jint data) {
+    if (gPowerModule && gPowerModule->powerHint) {
+        gPowerModule->powerHint(gPowerModule, (power_hint_t)hintId, (void *)data);
+    }
+}
+
 // ----------------------------------------------------------------------------
 
 static JNINativeMethod gPowerManagerServiceMethods[] = {
@@ -205,6 +211,8 @@
             (void*) nativeSetInteractive },
     { "nativeSetAutoSuspend", "(Z)V",
             (void*) nativeSetAutoSuspend },
+    { "nativeSendPowerHint", "(II)V",
+            (void*) nativeSendPowerHint },
 };
 
 #define FIND_CLASS(var, className) \