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

Commit c2327e78 authored by Ytai Ben-Tsvi's avatar Ytai Ben-Tsvi
Browse files

Recover from HAL death in sound trigger

Added some recovery code for the case of a dead driver.
Due to the sound trigger HAL process being tied to the audio server
via init.rc, this would also offer recovery from audio server death
as a by-product.

Bug: 146852437
Change-Id: I8cfea8ab108d482592c8094e8093066973f43288
parent 6df1f3d9
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -369,6 +369,12 @@ public class SoundTriggerModule {
            mHandler.sendMessage(m);
        }

        @Override
        public synchronized void onModuleDied() {
            Message m = mHandler.obtainMessage(EVENT_SERVICE_DIED);
            mHandler.sendMessage(m);
        }

        @Override
        public synchronized void binderDied() {
            Message m = mHandler.obtainMessage(EVENT_SERVICE_DIED);
+7 −0
Original line number Diff line number Diff line
@@ -44,4 +44,11 @@ oneway interface ISoundTriggerCallback {
     * and this event will be sent in addition to the abort event.
     */
    void onRecognitionAvailabilityChange(boolean available);
    /**
     * Notifies the client that the associated module has crashed and restarted. The module instance
     * is no longer usable and will throw a ServiceSpecificException with a Status.DEAD_OBJECT code
     * for every call. The client should detach, then re-attach to the module in order to get a new,
     * usable instance. All state for this module has been lost.
     */
     void onModuleDied();
}
+2 −0
Original line number Diff line number Diff line
@@ -28,4 +28,6 @@ enum Status {
    OPERATION_NOT_SUPPORTED = 2,
    /** Temporary lack of permission. */
    TEMPORARY_PERMISSION_DENIED = 3,
    /** The object on which this method is called is dead and all of its state is lost. */
    DEAD_OBJECT = 4,
}
+31 −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.hardware.soundtrigger.V2_0.ISoundTriggerHw;

/**
 * A factory for creating instances of {@link ISoundTriggerHw}.
 *
 * @hide
 */
public interface HalFactory {
    /**
     * @return An instance of {@link ISoundTriggerHw}.
     */
    ISoundTriggerHw create();
}
+8 −9
Original line number Diff line number Diff line
@@ -78,16 +78,15 @@ public class SoundTriggerMiddlewareImpl implements ISoundTriggerMiddlewareServic
    }

    /**
     * Most generic constructor - gets an array of HAL driver instances.
     * Constructor - gets an array of HAL driver factories.
     */
    public SoundTriggerMiddlewareImpl(@NonNull ISoundTriggerHw[] halServices,
    public SoundTriggerMiddlewareImpl(@NonNull HalFactory[] halFactories,
            @NonNull AudioSessionProvider audioSessionProvider) {
        List<SoundTriggerModule> modules = new ArrayList<>(halServices.length);
        List<SoundTriggerModule> modules = new ArrayList<>(halFactories.length);

        for (int i = 0; i < halServices.length; ++i) {
            ISoundTriggerHw service = halServices[i];
        for (int i = 0; i < halFactories.length; ++i) {
            try {
                modules.add(new SoundTriggerModule(service, audioSessionProvider));
                modules.add(new SoundTriggerModule(halFactories[i], audioSessionProvider));
            } catch (Exception e) {
                Log.e(TAG, "Failed to add a SoundTriggerModule instance", e);
            }
@@ -97,11 +96,11 @@ public class SoundTriggerMiddlewareImpl implements ISoundTriggerMiddlewareServic
    }

    /**
     * Convenience constructor - gets a single HAL driver instance.
     * Convenience constructor - gets a single HAL factory.
     */
    public SoundTriggerMiddlewareImpl(@NonNull ISoundTriggerHw halService,
    public SoundTriggerMiddlewareImpl(@NonNull HalFactory factory,
            @NonNull AudioSessionProvider audioSessionProvider) {
        this(new ISoundTriggerHw[]{halService}, audioSessionProvider);
        this(new HalFactory[]{factory}, audioSessionProvider);
    }

    @Override
Loading