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

Commit 8022ba12 authored by Dichen Zhang's avatar Dichen Zhang
Browse files

jWakeLock

replace native binder with java PowerManager in JWakeLock

Test: MediaPlayer2Test
Bug: 122470692
Change-Id: I1e5871a50ecac4b0785f064801107e4b6035889a
parent cf82717c
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1309,11 +1309,11 @@ public class MediaPlayer2 implements AutoCloseable
        return addTask(new Task(CALL_COMPLETED_SET_WAKE_LOCK, false) {
            @Override
            void process() {
                boolean washeld = false;
                boolean wasHeld = false;

                if (mWakeLock != null) {
                    if (mWakeLock.isHeld()) {
                        washeld = true;
                        wasHeld = true;
                        mWakeLock.release();
                    }
                }
@@ -1321,7 +1321,7 @@ public class MediaPlayer2 implements AutoCloseable
                mWakeLock = wakeLock;
                if (mWakeLock != null) {
                    mWakeLock.setReferenceCounted(false);
                    if (washeld) {
                    if (wasHeld) {
                        mWakeLock.acquire();
                    }
                }
+0 −1
Original line number Diff line number Diff line
@@ -102,7 +102,6 @@ cc_library_shared {
        "libhidlbase",
        "libhidlmemory",

        "libpowermanager",  // Used by JWakeLock. Will be replace with public SDK API.
        "libmediametrics",  // Used by MediaMetrics. Will be replaced with stable C API.
        "libbinder",  // Used by JWakeLock and MediaMetrics.

+13 −6
Original line number Diff line number Diff line
@@ -86,7 +86,8 @@ using media::VolumeShaper;
// ----------------------------------------------------------------------------

struct fields_t {
    jfieldID    context;
    jfieldID    context;               // passed from Java to native, used for creating JWakeLock
    jfieldID    nativeContext;         // mNativeContext in MediaPlayer2.java
    jfieldID    surface_texture;

    jmethodID   post_event;
@@ -225,21 +226,21 @@ void JNIMediaPlayer2Listener::notify(int64_t srcId, int msg, int ext1, int ext2,
static sp<MediaPlayer2> getMediaPlayer(JNIEnv* env, jobject thiz)
{
    Mutex::Autolock l(sLock);
    MediaPlayer2* const p = (MediaPlayer2*)env->GetLongField(thiz, fields.context);
    MediaPlayer2* const p = (MediaPlayer2*)env->GetLongField(thiz, fields.nativeContext);
    return sp<MediaPlayer2>(p);
}

static sp<MediaPlayer2> setMediaPlayer(JNIEnv* env, jobject thiz, const sp<MediaPlayer2>& player)
{
    Mutex::Autolock l(sLock);
    sp<MediaPlayer2> old = (MediaPlayer2*)env->GetLongField(thiz, fields.context);
    sp<MediaPlayer2> old = (MediaPlayer2*)env->GetLongField(thiz, fields.nativeContext);
    if (player.get()) {
        player->incStrong((void*)setMediaPlayer);
    }
    if (old != 0) {
        old->decStrong((void*)setMediaPlayer);
    }
    env->SetLongField(thiz, fields.context, (jlong)player.get());
    env->SetLongField(thiz, fields.nativeContext, (jlong)player.get());
    return old;
}

@@ -955,11 +956,16 @@ android_media_MediaPlayer2_native_init(JNIEnv *env)
        return;
    }

    fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
    fields.context = env->GetFieldID(clazz, "mContext", "Landroid/content/Context;");
    if (fields.context == NULL) {
        return;
    }

    fields.nativeContext = env->GetFieldID(clazz, "mNativeContext", "J");
    if (fields.nativeContext == NULL) {
        return;
    }

    fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative",
                                               "(Ljava/lang/Object;JIII[B)V");
    if (fields.post_event == NULL) {
@@ -1013,7 +1019,8 @@ android_media_MediaPlayer2_native_setup(JNIEnv *env, jobject thiz,
        jint sessionId, jobject weak_this)
{
    ALOGV("native_setup");
    sp<MediaPlayer2> mp = MediaPlayer2::Create(sessionId);
    jobject context = env->GetObjectField(thiz, fields.context);
    sp<MediaPlayer2> mp = MediaPlayer2::Create(sessionId, context);
    if (mp == NULL) {
        jniThrowException(env, "java/lang/RuntimeException", "Out of memory");
        return;