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

Commit 40ee6ffa authored by Ytai Ben-tsvi's avatar Ytai Ben-tsvi Committed by Android (Google) Code Review
Browse files

Merge changes from topic "invert-capture-rvc" into rvc-dev

* changes:
  Register for capture state notifications via JNI
  Remove obsolete permission
  Change external capture state notification mechanism
parents f2f056ef d1afa087
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -4712,12 +4712,6 @@
    <permission android:name="android.permission.MANAGE_SOUND_TRIGGER"
        android:protectionLevel="signature|privileged" />

    <!-- Allows preempting sound trigger recognitions for the sake of capturing audio on
         implementations which do not support running both concurrently.
         @hide -->
    <permission android:name="android.permission.PREEMPT_SOUND_TRIGGER"
                android:protectionLevel="signature|privileged" />

    <!-- Must be required by system/priv apps implementing sound trigger detection services
         @hide
         @SystemApi -->
+0 −1
Original line number Diff line number Diff line
@@ -162,7 +162,6 @@
    <assign-permission name="android.permission.UPDATE_DEVICE_STATS" uid="audioserver" />
    <assign-permission name="android.permission.UPDATE_APP_OPS_STATS" uid="audioserver" />
    <assign-permission name="android.permission.PACKAGE_USAGE_STATS" uid="audioserver" />
    <assign-permission name="android.permission.PREEMPT_SOUND_TRIGGER" uid="audioserver" />

    <assign-permission name="android.permission.MODIFY_AUDIO_SETTINGS" uid="cameraserver" />
    <assign-permission name="android.permission.ACCESS_SURFACE_FLINGER" uid="cameraserver" />
+0 −6
Original line number Diff line number Diff line
@@ -39,10 +39,4 @@ interface ISoundTriggerMiddlewareService {
     * one of the handles from the returned list.
     */
    ISoundTriggerModule attach(int handle, ISoundTriggerCallback callback);

    /**
     * Notify the service that external input capture is taking place. This may cause some of the
     * active recognitions to be aborted.
     */
    void setExternalCaptureState(boolean active);
}
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -126,6 +126,7 @@ java_library_static {
        "android.hardware.rebootescrow-java",
        "android.hardware.soundtrigger-V2.3-java",
        "android.hidl.manager-V1.2-java",
        "capture_state_listener-aidl-java",
        "dnsresolver_aidl_interface-V2-java",
        "netd_event_listener_interface-java",
        "overlayable_policy_aidl-java",
+91 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source 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 com.android.server.soundtrigger_middleware;

import android.media.ICaptureStateListener;
import android.os.IBinder;
import android.os.Parcel;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;

import java.util.concurrent.Semaphore;
import java.util.function.Consumer;

/**
 * This is a never-give-up listener for sound trigger external capture state notifications, as
 * published by the audio policy service.
 *
 * This class will constantly try to connect to the service over a background thread and tolerate
 * its death. The client will be notified by a single provided function that is called in a
 * synchronized manner.
 * For simplicity, there is currently no way to stop the tracker. This is possible to add if the
 * need ever arises.
 */
class ExternalCaptureStateTracker {
    private static final String TAG = "CaptureStateTracker";
    /** Our client's listener. */
    private final Consumer<Boolean> mListener;
    /** This semaphore will get a permit every time we need to reconnect. */
    private final Semaphore mNeedToConnect = new Semaphore(1);

    /**
     * Constructor. Will start a background thread to do the work.
     *
     * @param listener A client provided listener that will be called on state
     *                 changes. May be
     *                 called multiple consecutive times with the same value. Never
     *                 called
     *                 concurrently.
     */
    ExternalCaptureStateTracker(Consumer<Boolean> listener) {
        mListener = listener;
        new Thread(this::run).start();
    }

    /**
     * Routine for the background thread. Keeps trying to reconnect.
     */
    private void run() {
        while (true) {
            mNeedToConnect.acquireUninterruptibly();
            connect();
        }
    }

    /**
     * Connect to the service, install listener and death notifier.
     */
    private native void connect();

    /**
     * Called by native code to invoke the client listener.
     *
     * @param active true when external capture is active.
     */
    private void setCaptureState(boolean active) {
        mListener.accept(active);
    }

    /**
     * Called by native code when the remote service died.
     */
    private void binderDied() {
        Log.w(TAG, "Audio policy service died");
        mNeedToConnect.release();
    }
}
Loading