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

Commit 37391eb8 authored by Matthew Eastman's avatar Matthew Eastman
Browse files

Invoke provideDataStream callback on WearableSensingService death.

Keeps track of the statusCallback provided by the client to the
WearableSensingManager in provideDataStream and invokes it with
STATUS_SERVICE_UNAVAILABLE when the remote WearableSensingService dies.

We do not need to call the provideConnection or
provideConcurrentConnection callbacks on binder death because they are
invoked with STATUS_CHANNEL_ERROR when the WearableSensingService dies.

Tested with CTS tests in ag/35512608 and locally by killing the
WearableSensingService process with ADB and verifying that the callback
was invoked with STATUS_SERVICE_UNAVAILABLE.

Change-Id: I8a7677714c0371f0cd754e4c589c11b14397b2c7
Bug: 441336476
Flag: EXEMPT BUGFIX
parent 4240e525
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -465,6 +465,9 @@ public class WearableSensingManager {
     * WearableSensingService. If the data stream was provided successfully {@link
     * WearableSensingManager#STATUS_SUCCESS} will be provided.
     *
     * <p>If the WearableSensingService process dies, the system will send a status code of {@link
     * WearableSensingManager#STATUS_SERVICE_UNAVAILABLE} to the {@code statusConsumer}.
     *
     * <p>Starting from target SDK level 35, if the WearableSensingService implementation belongs to
     * the same APK as the caller, calling this method will allow WearableSensingService to read
     * from the caller's file directory via {@link Context#openFileInput(String)}. The read will be
+28 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.os.SharedMemory;
import android.service.voice.HotwordAudioStream;
import android.service.voice.VoiceInteractionManagerInternal;
import android.service.voice.VoiceInteractionManagerInternal.WearableHotwordDetectionCallback;
import android.service.wearable.IWearableSensingService;
import android.system.ErrnoException;
import android.system.Os;
import android.system.OsConstants;
@@ -52,6 +53,7 @@ import android.util.IndentingPrintWriter;
import android.util.Slog;

import com.android.internal.R;
import com.android.internal.infra.ServiceConnector;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.infra.AndroidFuture;
@@ -95,6 +97,15 @@ final class WearableSensingManagerPerUserService
    @GuardedBy("mSecureChannelMap")
    private final Map<Integer, WearableSensingSecureChannel> mSecureChannelMap = new HashMap<>();

    // Keep track of the status callback for the deprecated WearableSensingManager#provideDataStream
    // API so that we can notify the client when the remote service dies. This is not needed for the
    // WearableSensingManager#provideConnection, WearableSensingManager#provideConcurrentConnection
    // callbacks because they will receive STATUS_CHANNEL_ERROR when the secure channel is closed
    // when the WearableSensingService process dies.
    @GuardedBy("mLock")
    @Nullable
    private RemoteCallback mProvideDataStreamStatusCallback;

    private final AtomicInteger mNextConnectionId = new AtomicInteger(1);

    private final int mMaxNumberOfConcurrentConnections;
@@ -136,6 +147,22 @@ final class WearableSensingManagerPerUserService
        if (mRemoteService == null) {
            mRemoteService =
                    new RemoteWearableSensingService(getContext(), mComponentName, getUserId());
            mRemoteService.setServiceLifecycleCallbacks(
                    new ServiceConnector.ServiceLifecycleCallbacks<IWearableSensingService>() {
                        @Override
                        public void onBinderDied() {
                            RemoteCallback statusCallback;
                            synchronized (mLock) {
                                statusCallback = mProvideDataStreamStatusCallback;
                                mProvideDataStreamStatusCallback = null;
                            }
                            if (statusCallback != null) {
                                notifyStatusCallback(
                                        statusCallback,
                                        WearableSensingManager.STATUS_SERVICE_UNAVAILABLE);
                            }
                        }
                    });
        }
    }

@@ -487,6 +514,7 @@ final class WearableSensingManagerPerUserService
            }
            Slog.i(TAG, "calling over to remote servvice.");
            ensureRemoteServiceInitiated();
            mProvideDataStreamStatusCallback = statusCallback;
            mRemoteService.provideDataStream(
                    parcelFileDescriptor,
                    wrapWearableSensingCallback(wearableSensingCallback),