Loading core/api/current.txt +5 −0 Original line number Diff line number Diff line Loading @@ -32169,7 +32169,12 @@ package android.os { public static class PerformanceHintManager.Session implements java.io.Closeable { method public void close(); method public void reportActualWorkDuration(long); method public void sendHint(int); method public void updateTargetWorkDuration(long); field public static final int CPU_LOAD_DOWN = 1; // 0x1 field public static final int CPU_LOAD_RESET = 2; // 0x2 field public static final int CPU_LOAD_RESUME = 3; // 0x3 field public static final int CPU_LOAD_UP = 0; // 0x0 } public final class PersistableBundle extends android.os.BaseBundle implements java.lang.Cloneable android.os.Parcelable { core/java/android/os/IHintSession.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -22,4 +22,5 @@ oneway interface IHintSession { void updateTargetWorkDuration(long targetDurationNanos); void reportActualWorkDuration(in long[] actualDurationNanos, in long[] timeStampNanos); void close(); void sendHint(int hint); } core/java/android/os/PerformanceHintManager.java +55 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.os; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemService; Loading @@ -24,6 +25,10 @@ import android.content.Context; import com.android.internal.util.Preconditions; import java.io.Closeable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.ref.Reference; /** The PerformanceHintManager allows apps to send performance hint to system. */ @SystemService(Context.PERFORMANCE_HINT_SERVICE) Loading Loading @@ -104,6 +109,40 @@ public final class PerformanceHintManager { mNativeSessionPtr = nativeSessionPtr; } /** * This hint indicates a sudden increase in CPU workload intensity. It means * that this hint session needs extra CPU resources immediately to meet the * target duration for the current work cycle. */ public static final int CPU_LOAD_UP = 0; /** * This hint indicates a decrease in CPU workload intensity. It means that * this hint session can reduce CPU resources and still meet the target duration. */ public static final int CPU_LOAD_DOWN = 1; /* * This hint indicates an upcoming CPU workload that is completely changed and * unknown. It means that the hint session should reset CPU resources to a known * baseline to prepare for an arbitrary load, and must wake up if inactive. */ public static final int CPU_LOAD_RESET = 2; /* * This hint indicates that the most recent CPU workload is resuming after a * period of inactivity. It means that the hint session should allocate similar * CPU resources to what was used previously, and must wake up if inactive. */ public static final int CPU_LOAD_RESUME = 3; /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = {"CPU_LOAD_"}, value = { CPU_LOAD_UP, CPU_LOAD_DOWN, CPU_LOAD_RESET, CPU_LOAD_RESUME }) public @interface Hint {} /** @hide */ @Override protected void finalize() throws Throwable { Loading Loading @@ -152,6 +191,21 @@ public final class PerformanceHintManager { mNativeSessionPtr = 0; } } /** * Sends performance hints to inform the hint session of changes in the workload. * * @param hint The hint to send to the session. */ public void sendHint(@Hint int hint) { Preconditions.checkArgumentNonNegative(hint, "the hint ID should be at least" + " zero."); try { nativeSendHint(mNativeSessionPtr, hint); } finally { Reference.reachabilityFence(this); } } } private static native long nativeAcquireManager(); Loading @@ -163,4 +217,5 @@ public final class PerformanceHintManager { private static native void nativeReportActualWorkDuration(long nativeSessionPtr, long actualDurationNanos); private static native void nativeCloseSession(long nativeSessionPtr); private static native void nativeSendHint(long nativeSessionPtr, int hint); } core/jni/android_os_PerformanceHintManager.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ typedef int64_t (*APH_getPreferredUpdateRateNanos)(APerformanceHintManager* mana typedef void (*APH_updateTargetWorkDuration)(APerformanceHintSession*, int64_t); typedef void (*APH_reportActualWorkDuration)(APerformanceHintSession*, int64_t); typedef void (*APH_closeSession)(APerformanceHintSession* session); typedef void (*APH_sendHint)(APerformanceHintSession*, int32_t); bool gAPerformanceHintBindingInitialized = false; APH_getManager gAPH_getManagerFn = nullptr; Loading @@ -48,6 +49,7 @@ APH_getPreferredUpdateRateNanos gAPH_getPreferredUpdateRateNanosFn = nullptr; APH_updateTargetWorkDuration gAPH_updateTargetWorkDurationFn = nullptr; APH_reportActualWorkDuration gAPH_reportActualWorkDurationFn = nullptr; APH_closeSession gAPH_closeSessionFn = nullptr; APH_sendHint gAPH_sendHintFn = nullptr; void ensureAPerformanceHintBindingInitialized() { if (gAPerformanceHintBindingInitialized) return; Loading Loading @@ -88,6 +90,11 @@ void ensureAPerformanceHintBindingInitialized() { LOG_ALWAYS_FATAL_IF(gAPH_closeSessionFn == nullptr, "Failed to find required symbol APerformanceHint_closeSession!"); gAPH_sendHintFn = (APH_sendHint)dlsym(handle_, "APerformanceHint_sendHint"); LOG_ALWAYS_FATAL_IF(gAPH_sendHintFn == nullptr, "Failed to find required symbol " "APerformanceHint_sendHint!"); gAPerformanceHintBindingInitialized = true; } Loading Loading @@ -138,6 +145,11 @@ static void nativeCloseSession(JNIEnv* env, jclass clazz, jlong nativeSessionPtr gAPH_closeSessionFn(reinterpret_cast<APerformanceHintSession*>(nativeSessionPtr)); } static void nativeSendHint(JNIEnv* env, jclass clazz, jlong nativeSessionPtr, jint hint) { ensureAPerformanceHintBindingInitialized(); gAPH_sendHintFn(reinterpret_cast<APerformanceHintSession*>(nativeSessionPtr), hint); } static const JNINativeMethod gPerformanceHintMethods[] = { {"nativeAcquireManager", "()J", (void*)nativeAcquireManager}, {"nativeGetPreferredUpdateRateNanos", "(J)J", (void*)nativeGetPreferredUpdateRateNanos}, Loading @@ -145,6 +157,7 @@ static const JNINativeMethod gPerformanceHintMethods[] = { {"nativeUpdateTargetWorkDuration", "(JJ)V", (void*)nativeUpdateTargetWorkDuration}, {"nativeReportActualWorkDuration", "(JJ)V", (void*)nativeReportActualWorkDuration}, {"nativeCloseSession", "(J)V", (void*)nativeCloseSession}, {"nativeSendHint", "(JI)V", (void*)nativeSendHint}, }; int register_android_os_PerformanceHintManager(JNIEnv* env) { Loading core/tests/coretests/src/android/os/PerformanceHintManagerTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -113,6 +113,23 @@ public class PerformanceHintManagerTest { }); } @Test public void testSendHint() { Session s = createSession(); assumeNotNull(s); s.sendHint(Session.CPU_LOAD_UP); s.sendHint(Session.CPU_LOAD_RESET); } @Test public void testSendHintWithNegativeHint() { Session s = createSession(); assumeNotNull(s); assertThrows(IllegalArgumentException.class, () -> { s.sendHint(-1); }); } @Test public void testCloseHintSession() { Session s = createSession(); Loading Loading
core/api/current.txt +5 −0 Original line number Diff line number Diff line Loading @@ -32169,7 +32169,12 @@ package android.os { public static class PerformanceHintManager.Session implements java.io.Closeable { method public void close(); method public void reportActualWorkDuration(long); method public void sendHint(int); method public void updateTargetWorkDuration(long); field public static final int CPU_LOAD_DOWN = 1; // 0x1 field public static final int CPU_LOAD_RESET = 2; // 0x2 field public static final int CPU_LOAD_RESUME = 3; // 0x3 field public static final int CPU_LOAD_UP = 0; // 0x0 } public final class PersistableBundle extends android.os.BaseBundle implements java.lang.Cloneable android.os.Parcelable {
core/java/android/os/IHintSession.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -22,4 +22,5 @@ oneway interface IHintSession { void updateTargetWorkDuration(long targetDurationNanos); void reportActualWorkDuration(in long[] actualDurationNanos, in long[] timeStampNanos); void close(); void sendHint(int hint); }
core/java/android/os/PerformanceHintManager.java +55 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.os; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemService; Loading @@ -24,6 +25,10 @@ import android.content.Context; import com.android.internal.util.Preconditions; import java.io.Closeable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.ref.Reference; /** The PerformanceHintManager allows apps to send performance hint to system. */ @SystemService(Context.PERFORMANCE_HINT_SERVICE) Loading Loading @@ -104,6 +109,40 @@ public final class PerformanceHintManager { mNativeSessionPtr = nativeSessionPtr; } /** * This hint indicates a sudden increase in CPU workload intensity. It means * that this hint session needs extra CPU resources immediately to meet the * target duration for the current work cycle. */ public static final int CPU_LOAD_UP = 0; /** * This hint indicates a decrease in CPU workload intensity. It means that * this hint session can reduce CPU resources and still meet the target duration. */ public static final int CPU_LOAD_DOWN = 1; /* * This hint indicates an upcoming CPU workload that is completely changed and * unknown. It means that the hint session should reset CPU resources to a known * baseline to prepare for an arbitrary load, and must wake up if inactive. */ public static final int CPU_LOAD_RESET = 2; /* * This hint indicates that the most recent CPU workload is resuming after a * period of inactivity. It means that the hint session should allocate similar * CPU resources to what was used previously, and must wake up if inactive. */ public static final int CPU_LOAD_RESUME = 3; /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = {"CPU_LOAD_"}, value = { CPU_LOAD_UP, CPU_LOAD_DOWN, CPU_LOAD_RESET, CPU_LOAD_RESUME }) public @interface Hint {} /** @hide */ @Override protected void finalize() throws Throwable { Loading Loading @@ -152,6 +191,21 @@ public final class PerformanceHintManager { mNativeSessionPtr = 0; } } /** * Sends performance hints to inform the hint session of changes in the workload. * * @param hint The hint to send to the session. */ public void sendHint(@Hint int hint) { Preconditions.checkArgumentNonNegative(hint, "the hint ID should be at least" + " zero."); try { nativeSendHint(mNativeSessionPtr, hint); } finally { Reference.reachabilityFence(this); } } } private static native long nativeAcquireManager(); Loading @@ -163,4 +217,5 @@ public final class PerformanceHintManager { private static native void nativeReportActualWorkDuration(long nativeSessionPtr, long actualDurationNanos); private static native void nativeCloseSession(long nativeSessionPtr); private static native void nativeSendHint(long nativeSessionPtr, int hint); }
core/jni/android_os_PerformanceHintManager.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ typedef int64_t (*APH_getPreferredUpdateRateNanos)(APerformanceHintManager* mana typedef void (*APH_updateTargetWorkDuration)(APerformanceHintSession*, int64_t); typedef void (*APH_reportActualWorkDuration)(APerformanceHintSession*, int64_t); typedef void (*APH_closeSession)(APerformanceHintSession* session); typedef void (*APH_sendHint)(APerformanceHintSession*, int32_t); bool gAPerformanceHintBindingInitialized = false; APH_getManager gAPH_getManagerFn = nullptr; Loading @@ -48,6 +49,7 @@ APH_getPreferredUpdateRateNanos gAPH_getPreferredUpdateRateNanosFn = nullptr; APH_updateTargetWorkDuration gAPH_updateTargetWorkDurationFn = nullptr; APH_reportActualWorkDuration gAPH_reportActualWorkDurationFn = nullptr; APH_closeSession gAPH_closeSessionFn = nullptr; APH_sendHint gAPH_sendHintFn = nullptr; void ensureAPerformanceHintBindingInitialized() { if (gAPerformanceHintBindingInitialized) return; Loading Loading @@ -88,6 +90,11 @@ void ensureAPerformanceHintBindingInitialized() { LOG_ALWAYS_FATAL_IF(gAPH_closeSessionFn == nullptr, "Failed to find required symbol APerformanceHint_closeSession!"); gAPH_sendHintFn = (APH_sendHint)dlsym(handle_, "APerformanceHint_sendHint"); LOG_ALWAYS_FATAL_IF(gAPH_sendHintFn == nullptr, "Failed to find required symbol " "APerformanceHint_sendHint!"); gAPerformanceHintBindingInitialized = true; } Loading Loading @@ -138,6 +145,11 @@ static void nativeCloseSession(JNIEnv* env, jclass clazz, jlong nativeSessionPtr gAPH_closeSessionFn(reinterpret_cast<APerformanceHintSession*>(nativeSessionPtr)); } static void nativeSendHint(JNIEnv* env, jclass clazz, jlong nativeSessionPtr, jint hint) { ensureAPerformanceHintBindingInitialized(); gAPH_sendHintFn(reinterpret_cast<APerformanceHintSession*>(nativeSessionPtr), hint); } static const JNINativeMethod gPerformanceHintMethods[] = { {"nativeAcquireManager", "()J", (void*)nativeAcquireManager}, {"nativeGetPreferredUpdateRateNanos", "(J)J", (void*)nativeGetPreferredUpdateRateNanos}, Loading @@ -145,6 +157,7 @@ static const JNINativeMethod gPerformanceHintMethods[] = { {"nativeUpdateTargetWorkDuration", "(JJ)V", (void*)nativeUpdateTargetWorkDuration}, {"nativeReportActualWorkDuration", "(JJ)V", (void*)nativeReportActualWorkDuration}, {"nativeCloseSession", "(J)V", (void*)nativeCloseSession}, {"nativeSendHint", "(JI)V", (void*)nativeSendHint}, }; int register_android_os_PerformanceHintManager(JNIEnv* env) { Loading
core/tests/coretests/src/android/os/PerformanceHintManagerTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -113,6 +113,23 @@ public class PerformanceHintManagerTest { }); } @Test public void testSendHint() { Session s = createSession(); assumeNotNull(s); s.sendHint(Session.CPU_LOAD_UP); s.sendHint(Session.CPU_LOAD_RESET); } @Test public void testSendHintWithNegativeHint() { Session s = createSession(); assumeNotNull(s); assertThrows(IllegalArgumentException.class, () -> { s.sendHint(-1); }); } @Test public void testCloseHintSession() { Session s = createSession(); Loading