Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit feb30df9 authored by Matt Buckley's avatar Matt Buckley
Browse files

Add support for converting java hint sessions to native hint sessions

Add an API called "APerformanceHint_getSessionFromJava" for Java
clients to access the native APerformanceHintSession objects that
Java hint sessions wrap. This should will make the Java and Native APIs
substantially more interoperable.

This patch also makes the native code aware of when it is being used in
Java, to allow it to have slightly different behavior, especially when
it is being directly accessed through JNI. The main place where this
mostly matters is in preventing clients from closing Java-owned sessions
through the JNI, as that could cause weird behavior otherwise.

Bug: 367803904

Test: atest HintManagerServiceTest
Test: atest PerformanceHintNativeTestCases
Flag: EXEMPT trivial refactor
Change-Id: I9bae7f78b61e40037de63839103906c3e536a743
parent 0bf29918
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@
#define ANDROID_NATIVE_PERFORMANCE_HINT_H

#include <sys/cdefs.h>
#include <jni.h>

/******************************************************************
 *
@@ -202,6 +203,9 @@ int APerformanceHint_reportActualWorkDuration(
 * Release the performance hint manager pointer acquired via
 * {@link APerformanceHint_createSession}.
 *
 * This cannot be used to close a Java PerformanceHintManager.Session, as its
 * lifecycle is tied to the object in the SDK.
 *
 * @param session The performance hint session instance to release.
 */
void APerformanceHint_closeSession(
@@ -370,6 +374,21 @@ void AWorkDuration_setActualCpuDurationNanos(AWorkDuration* _Nonnull aWorkDurati
void AWorkDuration_setActualGpuDurationNanos(AWorkDuration* _Nonnull aWorkDuration,
        int64_t actualGpuDurationNanos) __INTRODUCED_IN(__ANDROID_API_V__);

/**
 * Return the APerformanceHintSession wrapped by a Java PerformanceHintManager.Session object.
 *
 * The Java session maintains ownership over the wrapped native session, so it cannot be
 * closed using {@link APerformanceHint_closeSession}.
 *
 * @param env The Java environment where the PerformanceHintManager.Session lives.
 * @param sessionObj The Java Session to unwrap.
 *
 * @return A pointer to the APerformanceHintManager that backs the Java Session.
 */
APerformanceHintSession* _Nonnull APerformanceHint_borrowSessionFromJava(
        JNIEnv* _Nonnull env, jobject _Nonnull sessionObj) __INTRODUCED_IN(36);


__END_DECLS

#endif // ANDROID_NATIVE_PERFORMANCE_HINT_H
+12 −0
Original line number Diff line number Diff line
@@ -109,6 +109,18 @@ APerformanceHintSession* APerformanceHint_createSessionInternal(APerformanceHint
                                        const int32_t* threadIds, size_t size,
                                        int64_t initialTargetWorkDurationNanos, SessionTag tag);

/**
 * Creates a session from the Java SDK implementation
 */
APerformanceHintSession* APerformanceHint_createSessionFromJava(APerformanceHintManager* manager,
                                        const int32_t* threadIds, size_t size,
                                        int64_t initialTargetWorkDurationNanos);

/**
 * Special method for Java SDK implementation to kill sessions
 */
void APerformanceHint_closeSessionFromJava(APerformanceHintSession* session);

/**
 * Forces FMQ to be enabled or disabled, for testing only.
 */