Skip to content

Commit feb30df

Browse files
committed
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
1 parent 0bf2991 commit feb30df

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

include/android/performance_hint.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#define ANDROID_NATIVE_PERFORMANCE_HINT_H
5050

5151
#include <sys/cdefs.h>
52+
#include <jni.h>
5253

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

377+
/**
378+
* Return the APerformanceHintSession wrapped by a Java PerformanceHintManager.Session object.
379+
*
380+
* The Java session maintains ownership over the wrapped native session, so it cannot be
381+
* closed using {@link APerformanceHint_closeSession}.
382+
*
383+
* @param env The Java environment where the PerformanceHintManager.Session lives.
384+
* @param sessionObj The Java Session to unwrap.
385+
*
386+
* @return A pointer to the APerformanceHintManager that backs the Java Session.
387+
*/
388+
APerformanceHintSession* _Nonnull APerformanceHint_borrowSessionFromJava(
389+
JNIEnv* _Nonnull env, jobject _Nonnull sessionObj) __INTRODUCED_IN(36);
390+
391+
373392
__END_DECLS
374393

375394
#endif // ANDROID_NATIVE_PERFORMANCE_HINT_H

include/private/performance_hint_private.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ APerformanceHintSession* APerformanceHint_createSessionInternal(APerformanceHint
109109
const int32_t* threadIds, size_t size,
110110
int64_t initialTargetWorkDurationNanos, SessionTag tag);
111111

112+
/**
113+
* Creates a session from the Java SDK implementation
114+
*/
115+
APerformanceHintSession* APerformanceHint_createSessionFromJava(APerformanceHintManager* manager,
116+
const int32_t* threadIds, size_t size,
117+
int64_t initialTargetWorkDurationNanos);
118+
119+
/**
120+
* Special method for Java SDK implementation to kill sessions
121+
*/
122+
void APerformanceHint_closeSessionFromJava(APerformanceHintSession* session);
123+
112124
/**
113125
* Forces FMQ to be enabled or disabled, for testing only.
114126
*/

0 commit comments

Comments
 (0)