1 /* 2 * Copyright (C) 2021 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.car.builtin.app; 18 19 import android.annotation.SystemApi; 20 import android.car.builtin.annotation.AddedIn; 21 import android.car.builtin.annotation.PlatformVersion; 22 import android.car.builtin.os.ServiceManagerHelper; 23 import android.content.Context; 24 import android.os.RemoteException; 25 26 import com.android.internal.app.IVoiceInteractionManagerService; 27 28 /** 29 * Helper for VoiceInteractionManagerService related operations. 30 * 31 * @hide 32 */ 33 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) 34 public final class VoiceInteractionHelper { 35 36 /** Checks if ${link VoiceInteractionManagerService} is available. */ 37 @AddedIn(PlatformVersion.TIRAMISU_0) isAvailable()38 public static boolean isAvailable() { 39 return getService() != null; 40 } 41 42 /** 43 * Enables/disables voice interaction. 44 * 45 * @param enabled Whether to enable or disable voice interaction. 46 */ 47 @AddedIn(PlatformVersion.TIRAMISU_0) setEnabled(boolean enabled)48 public static void setEnabled(boolean enabled) throws RemoteException { 49 IVoiceInteractionManagerService service = getService(); 50 if (service == null) { 51 return; 52 } 53 service.setDisabled(!enabled); 54 } 55 getService()56 private static IVoiceInteractionManagerService getService() { 57 return IVoiceInteractionManagerService.Stub.asInterface(ServiceManagerHelper 58 .getService(Context.VOICE_INTERACTION_MANAGER_SERVICE)); 59 } 60 61 /** Constructs {@link VoiceInteractionHelper}. */ VoiceInteractionHelper()62 private VoiceInteractionHelper() { 63 throw new UnsupportedOperationException("contains only static members"); 64 } 65 } 66