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

Unverified Commit 67c0daf5 authored by Luca Stefani's avatar Luca Stefani Committed by Michael Bestas
Browse files

Remove LineageAudioService

Change-Id: I4aea4c62154a0f7d9d6d96e68ddf2bd401458fab
parent 7242fc83
Loading
Loading
Loading
Loading

lineage/jni/Android.bp

deleted100644 → 0
+0 −50
Original line number Diff line number Diff line
//
// Copyright (C) 2018-2020 The LineageOS Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

cc_library_shared {
    name: "liblineage-sdk_platform_jni",
    system_ext_specific: true,
    srcs: [
        "src/org_lineageos_platform_internal_LineageAudioService.cpp",
        "src/onload.cpp",
    ],

    include_dirs: [
        "frameworks/base/core/jni",
        "frameworks/av/include",
        "hardware/libhardware/include",
    ],

    shared_libs: [
        "libandroid_runtime",
        "libaudioclient",
        "libcutils",
        "libhardware",
        "liblog",
        "libmedia",
        "libutils",
    ],

    header_libs: [
        "jni_headers",
    ],

    cflags: [
        "-Wall",
        "-Werror",
        "-Wno-unused-parameter",
    ],
}

lineage/jni/src/onload.cpp

deleted100644 → 0
+0 −47
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The CyanogenMod Project
 *               2017,2020 The LineageOS Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <nativehelper/JNIHelp.h>

#include "jni.h"
#include "utils/Log.h"
#include "utils/misc.h"

namespace android {

int register_org_lineageos_platform_internal_LineageAudioService(JNIEnv* env);

};

using namespace android;

extern "C" jint JNI_OnLoad(JavaVM* vm, void* /* reserved */)
{
    JNIEnv* env = NULL;
    jint result = -1;

    if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
        ALOGE("GetEnv failed!");
        return result;
    }
    ALOG_ASSERT(env, "Could not retrieve the env!");

    register_org_lineageos_platform_internal_LineageAudioService(env);

    return JNI_VERSION_1_4;
}
+0 −179
Original line number Diff line number Diff line
/*
**
** Copyright 2016, The CyanogenMod Project
**           2017,2020 The LineageOS Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

//#define LOG_NDEBUG 0

#define LOG_TAG "LineageAudioService-JNI"

#include <utils/Log.h>

#include <jni.h>
#include "core_jni_helpers.h"
#include "android_media_AudioErrors.h"

#include <media/AudioSystem.h>
/*
#include <media/AudioSession.h>
*/

#include <system/audio.h>
#include <utils/misc.h>
#include <utils/threads.h>

// ----------------------------------------------------------------------------

namespace android {

/*
static const char* const kClassPathName = "org/lineageos/platform/internal/LineageAudioService";

static jclass gArrayListClass;
static struct {
    jmethodID    add;
    jmethodID    toArray;
} gArrayListMethods;

static struct {
    jmethodID postAudioSessionEventFromNative;
} gAudioSessionEventHandlerMethods;

static jclass gAudioSessionInfoClass;
static jmethodID gAudioSessionInfoCstor;

static jobject gThiz;

static Mutex gCallbackLock;

// ----------------------------------------------------------------------------

static void
org_lineageos_platform_internal_LineageAudioService_session_info_callback(int event,
        sp<AudioSessionInfo>& info, bool added)
{
    AutoMutex _l(gCallbackLock);

    JNIEnv *env = AndroidRuntime::getJNIEnv();
    if (env == NULL) {
        return;
    }

    jobject jSession = env->NewObject(gAudioSessionInfoClass, gAudioSessionInfoCstor,
            info->mSessionId, info->mStream, info->mFlags, info->mChannelMask, info->mUid);

    env->CallVoidMethod(gThiz,
            gAudioSessionEventHandlerMethods.postAudioSessionEventFromNative,
            event, jSession, added);

    env->DeleteLocalRef(jSession);
}

static void
org_lineageos_platform_internal_LineageAudioService_registerAudioSessionCallback(
        JNIEnv *env, jobject thiz, jboolean enabled)
{
    if (gThiz == NULL) {
        gThiz = env->NewGlobalRef(thiz);
    }

    AudioSystem::setAudioSessionCallback( enabled ?
            org_lineageos_platform_internal_LineageAudioService_session_info_callback : NULL);
}

static jint
org_lineageos_platform_internal_LineageAudioService_listAudioSessions(JNIEnv *env, jobject thiz,
        jint streams, jobject jSessions)
{
    ALOGV("listAudioSessions");

    if (jSessions == NULL) {
        ALOGE("listAudioSessions NULL arraylist");
        return (jint)AUDIO_JAVA_BAD_VALUE;
    }
    if (!env->IsInstanceOf(jSessions, gArrayListClass)) {
        ALOGE("listAudioSessions not an arraylist");
        return (jint)AUDIO_JAVA_BAD_VALUE;
    }

    status_t status;
    Vector< sp<AudioSessionInfo>> sessions;

    status = AudioSystem::listAudioSessions((audio_stream_type_t)streams, sessions);
    if (status != NO_ERROR) {
        ALOGE("AudioSystem::listAudioSessions error %d", status);
    } else {
        ALOGV("AudioSystem::listAudioSessions count=%zu", sessions.size());
    }

    jint jStatus = nativeToJavaStatus(status);
    if (jStatus != AUDIO_JAVA_SUCCESS) {
        goto exit;
    }

    for (size_t i = 0; i < sessions.size(); i++) {
        const sp<AudioSessionInfo>& s = sessions.itemAt(i);

        jobject jSession = env->NewObject(gAudioSessionInfoClass, gAudioSessionInfoCstor,
                s->mSessionId, s->mStream, s->mFlags, s->mChannelMask, s->mUid);

        if (jSession == NULL) {
            jStatus = (jint)AUDIO_JAVA_ERROR;
            goto exit;
        }

        env->CallBooleanMethod(jSessions, gArrayListMethods.add, jSession);
        env->DeleteLocalRef(jSession);
    }

exit:
    return jStatus;
}


// ----------------------------------------------------------------------------

static JNINativeMethod gMethods[] = {
     {"native_listAudioSessions", "(ILjava/util/ArrayList;)I",
            (void *)org_lineageos_platform_internal_LineageAudioService_listAudioSessions},
     {"native_registerAudioSessionCallback", "(Z)V",
            (void *)org_lineageos_platform_internal_LineageAudioService_registerAudioSessionCallback},
};

*/

int register_org_lineageos_platform_internal_LineageAudioService(JNIEnv *env)
{
    return 0;
/*
    jclass arrayListClass = FindClassOrDie(env, "java/util/ArrayList");
    gArrayListClass = MakeGlobalRefOrDie(env, arrayListClass);
    gArrayListMethods.add = GetMethodIDOrDie(env, arrayListClass, "add", "(Ljava/lang/Object;)Z");
    gArrayListMethods.toArray = GetMethodIDOrDie(env, arrayListClass, "toArray", "()[Ljava/lang/Object;");

    jclass audioSessionInfoClass = FindClassOrDie(env, "lineageos/media/AudioSessionInfo");
    gAudioSessionInfoClass = MakeGlobalRefOrDie(env, audioSessionInfoClass);
    gAudioSessionInfoCstor = GetMethodIDOrDie(env, audioSessionInfoClass, "<init>", "(IIIII)V");

    gAudioSessionEventHandlerMethods.postAudioSessionEventFromNative =
            GetMethodIDOrDie(env, env->FindClass(kClassPathName),
            "audioSessionCallbackFromNative", "(ILlineageos/media/AudioSessionInfo;Z)V");

    return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
*/
}

} /* namespace android */
+0 −160
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.lineageos.platform.internal;

import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import lineageos.app.LineageContextConstants;
import lineageos.media.AudioSessionInfo;
import lineageos.media.LineageAudioManager;
import lineageos.media.ILineageAudioService;
import lineageos.platform.Manifest;

public class LineageAudioService extends LineageSystemService {

    private static final String TAG = "LineageAudioService";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

    private final Context mContext;

    private static final int AUDIO_STATUS_OK = 0;

    //keep in sync with include/media/AudioPolicy.h
    private final static int AUDIO_OUTPUT_SESSION_EFFECTS_UPDATE = 10;

    public LineageAudioService(Context context) {
        super(context);

        mContext = context;
    }

    @Override
    public String getFeatureDeclaration() {
        return LineageContextConstants.Features.AUDIO;
    }

    @Override
    public void onStart() {
        if (!NativeHelper.isNativeLibraryAvailable()) {
            Log.wtf(TAG, "Lineage Audio service started by system server by native library is" +
                    "unavailable. Service will be unavailable.");
            return;
        }
        publishBinderService(LineageContextConstants.LINEAGE_AUDIO_SERVICE, mBinder);
    }

    @Override
    public void onBootPhase(int phase) {
        if (phase == PHASE_BOOT_COMPLETED) {
            if (NativeHelper.isNativeLibraryAvailable()) {
                native_registerAudioSessionCallback(true);
            }
        }
    }

    private final IBinder mBinder = new ILineageAudioService.Stub() {

        @Override
        public List<AudioSessionInfo> listAudioSessions(int streamType) throws RemoteException {
            final ArrayList<AudioSessionInfo> sessions = new ArrayList<AudioSessionInfo>();
            if (!NativeHelper.isNativeLibraryAvailable()) {
                // no sessions for u
                return sessions;
            }

            int status = native_listAudioSessions(streamType, sessions);
            if (status != AUDIO_STATUS_OK) {
                Log.e(TAG, "Error retrieving audio sessions! status=" + status);
            }

            return sessions;
        }

        @Override
        public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);

            pw.println();
            pw.println("Lineage Audio Service State:");
            try {
                List<AudioSessionInfo> sessions = listAudioSessions(-1);
                if (sessions.size() > 0) {
                    pw.println("  Audio sessions:");
                    for (AudioSessionInfo info : sessions) {
                        pw.println("   " + info.toString());
                    }
                } else {
                    pw.println("  No active audio sessions");
                }
            } catch (RemoteException e) {
                // nothing
            }
        }
    };

    private void broadcastSessionChanged(boolean added, AudioSessionInfo sessionInfo) {
        Intent i = new Intent(LineageAudioManager.ACTION_AUDIO_SESSIONS_CHANGED);
        i.putExtra(LineageAudioManager.EXTRA_SESSION_INFO, sessionInfo);
        i.putExtra(LineageAudioManager.EXTRA_SESSION_ADDED, added);

        sendBroadcastToAll(i, Manifest.permission.OBSERVE_AUDIO_SESSIONS);
    }

    private void sendBroadcastToAll(Intent intent, String receiverPermission) {
        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);

        final long ident = Binder.clearCallingIdentity();
        try {
            if (DEBUG) Log.d(TAG, "Sending broadcast: " + intent.toString());

            mContext.sendBroadcastAsUser(intent, UserHandle.ALL, receiverPermission);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    /*
     * Handles events from JNI
     */
    private synchronized void audioSessionCallbackFromNative(int event,
            AudioSessionInfo sessionInfo, boolean added) {

        switch (event) {
            case AUDIO_OUTPUT_SESSION_EFFECTS_UPDATE:
                broadcastSessionChanged(added, sessionInfo);
                break;
            default:
                Log.e(TAG, "Unknown event " + event);
        }
    }

    private native final void native_registerAudioSessionCallback(boolean enabled);

    private native final int native_listAudioSessions(
            int stream, ArrayList<AudioSessionInfo> sessions);
}
+0 −8
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@
    <protected-broadcast android:name="lineageos.intent.action.SCREEN_CAMERA_GESTURE" />
    <protected-broadcast android:name="lineageos.intent.action.INITIALIZE_LINEAGE_HARDWARE" />
    <protected-broadcast android:name="lineageos.intent.action.INITIALIZE_LIVEDISPLAY" />
    <protected-broadcast android:name="lineageos.intent.action.ACTION_AUDIO_SESSIONS_CHANGED" />
    <protected-broadcast android:name="lineageos.platform.intent.action.PROFILE_SELECTED" />

    <protected-broadcast android:name="lineageos.intent.action.UPDATE_PREFERENCE" />
@@ -64,13 +63,6 @@
                android:description="@string/permdesc_writeSecureSettings"
                android:protectionLevel="signature|privileged|development" />

    <!-- Allows an application to observe system-wide changes to audio sessions
         @hide -->
    <permission android:name="lineageos.permission.OBSERVE_AUDIO_SESSIONS"
                android:label="@string/permlab_observe_audio_sessions"
                android:description="@string/permdesc_observe_audio_sessions"
                android:protectionLevel="normal"/>

    <!-- Allows an application to manage LiveDisplay -->
    <permission android:name="lineageos.permission.MANAGE_LIVEDISPLAY"
                android:label="@string/permlab_manageLiveDisplay"
Loading