1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.service.voice;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.UserIdInt;
22 import android.content.ComponentName;
23 import android.media.AudioFormat;
24 import android.os.Bundle;
25 import android.os.IBinder;
26 import android.os.ParcelFileDescriptor;
27 import android.os.PersistableBundle;
28 
29 import com.android.internal.annotations.Immutable;
30 
31 /**
32  * @hide Private interface to the VoiceInteractionManagerService for use within system_server.
33  */
34 public abstract class VoiceInteractionManagerInternal {
35 
36     /**
37      * Start a new voice interaction session when requested from within an activity
38      * by Activity.startLocalVoiceInteraction()
39      * @param callingActivity The binder token representing the calling activity.
40      * @param attributionTag The attribution tag of the calling context or {@code null} for default
41      *                       attribution
42      * @param options A Bundle of private arguments to the current voice interaction service
43      */
startLocalVoiceInteraction(@onNull IBinder callingActivity, @Nullable String attributionTag, @Nullable Bundle options)44     public abstract void startLocalVoiceInteraction(@NonNull IBinder callingActivity,
45             @Nullable String attributionTag, @Nullable Bundle options);
46 
47     /**
48      * Returns whether the currently selected voice interaction service supports local voice
49      * interaction for launching from an Activity.
50      */
supportsLocalVoiceInteraction()51     public abstract boolean supportsLocalVoiceInteraction();
52 
stopLocalVoiceInteraction(IBinder callingActivity)53     public abstract void stopLocalVoiceInteraction(IBinder callingActivity);
54 
55     /**
56      * Returns whether the given package is currently in an active session
57      */
hasActiveSession(String packageName)58     public abstract boolean hasActiveSession(String packageName);
59 
60     /**
61      * Returns the package name of the active session.
62      *
63      * @param callingVoiceInteractor the voice interactor binder from the calling VoiceInteractor.
64      */
getVoiceInteractorPackageName(IBinder callingVoiceInteractor)65     public abstract String getVoiceInteractorPackageName(IBinder callingVoiceInteractor);
66 
67     /**
68      * Gets the identity of the currently active HotwordDetectionService.
69      *
70      * @see HotwordDetectionServiceIdentity
71      */
72     @Nullable
getHotwordDetectionServiceIdentity()73     public abstract HotwordDetectionServiceIdentity getHotwordDetectionServiceIdentity();
74 
75     /**
76      * Called by {@code UMS.convertPreCreatedUserIfPossible()} when a new user is not created from
77      * scratched, but converted from the pool of existing pre-created users.
78      */
79     // TODO(b/226201975): remove method once RoleService supports pre-created users
onPreCreatedUserConversion(@serIdInt int userId)80     public abstract void onPreCreatedUserConversion(@UserIdInt int userId);
81 
82     /**
83      * Called by {@link com.android.server.wearable.WearableSensingManagerPerUserService} when a
84      * wearable starts sending audio data for hotword detection.
85      *
86      * @param audioStream The audio data.
87      * @param audioFormat The format of the audio data.
88      * @param options Options supporting hotword detection.
89      * @param targetVisComponentName The target VoiceInteractionService ComponentName
90      * @param userId The user ID of the calling wearable service
91      * @param callback The callback to notify the caller of the hotword detection result.
92      */
startListeningFromWearable( ParcelFileDescriptor audioStream, AudioFormat audioFormat, PersistableBundle options, ComponentName targetVisComponentName, int userId, WearableHotwordDetectionCallback callback)93     public abstract void startListeningFromWearable(
94             ParcelFileDescriptor audioStream,
95             AudioFormat audioFormat,
96             PersistableBundle options,
97             ComponentName targetVisComponentName,
98             int userId,
99             WearableHotwordDetectionCallback callback);
100 
101     /**
102      * Provides the uids of the currently active
103      * {@link android.service.voice.HotwordDetectionService} and its owning package. The
104      * HotwordDetectionService is an isolated service, so it has a separate uid.
105      */
106     @Immutable
107     public static class HotwordDetectionServiceIdentity {
108         private final int mIsolatedUid;
109         private final int mOwnerUid;
110 
HotwordDetectionServiceIdentity(int isolatedUid, int ownerUid)111         public HotwordDetectionServiceIdentity(int isolatedUid, int ownerUid) {
112             mIsolatedUid = isolatedUid;
113             mOwnerUid = ownerUid;
114         }
115 
116         /** Gets the uid of the currently active isolated process hosting the service. */
getIsolatedUid()117         public int getIsolatedUid() {
118             return mIsolatedUid;
119         }
120 
121         /** Gets the uid of the package that provides the HotwordDetectionService. */
getOwnerUid()122         public int getOwnerUid() {
123             return mOwnerUid;
124         }
125     }
126 
127     /**
128      * Callback for returning the detected hotword result to the wearable.
129      *
130      * @hide
131      */
132     public interface WearableHotwordDetectionCallback {
133         /** Called when hotword is detected. */
onDetected()134         void onDetected();
135 
136         /** Called when hotword is not detected. */
onRejected()137         void onRejected();
138 
139         /** Called when an unexpected error occurs. */
onError(String errorMessage)140         void onError(String errorMessage);
141     }
142 }
143