1 /* 2 * Copyright (C) 2019 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 com.android.car.settings.testutils; 18 19 import android.content.pm.PackageManager; 20 import android.content.pm.ServiceInfo; 21 import android.service.voice.VoiceInteractionServiceInfo; 22 23 import org.robolectric.annotation.Implementation; 24 import org.robolectric.annotation.Implements; 25 import org.robolectric.annotation.Resetter; 26 27 import java.util.HashMap; 28 import java.util.Map; 29 30 @Implements(VoiceInteractionServiceInfo.class) 31 public class ShadowVoiceInteractionServiceInfo { 32 private static Map<ServiceInfo, Boolean> sSupportsAssistMap = new HashMap<>(); 33 private static Map<ServiceInfo, String> sRecognitionServiceMap = new HashMap<>(); 34 private static Map<ServiceInfo, String> sSettingsActivityMap = new HashMap<>(); 35 36 private ServiceInfo mServiceInfo; 37 __constructor__(PackageManager pm, ServiceInfo si)38 public void __constructor__(PackageManager pm, ServiceInfo si) { 39 mServiceInfo = si; 40 } 41 setSupportsAssist(ServiceInfo si, boolean supports)42 public static void setSupportsAssist(ServiceInfo si, boolean supports) { 43 sSupportsAssistMap.put(si, supports); 44 } 45 setRecognitionService(ServiceInfo si, String recognitionService)46 public static void setRecognitionService(ServiceInfo si, String recognitionService) { 47 sRecognitionServiceMap.put(si, recognitionService); 48 } 49 setSettingsActivity(ServiceInfo si, String settingsActivity)50 public static void setSettingsActivity(ServiceInfo si, String settingsActivity) { 51 sSettingsActivityMap.put(si, settingsActivity); 52 } 53 54 @Implementation getSupportsAssist()55 protected boolean getSupportsAssist() { 56 return sSupportsAssistMap.get(mServiceInfo); 57 } 58 59 @Implementation getRecognitionService()60 protected String getRecognitionService() { 61 return sRecognitionServiceMap.get(mServiceInfo); 62 } 63 64 @Implementation getSettingsActivity()65 protected String getSettingsActivity() { 66 return sSettingsActivityMap.get(mServiceInfo); 67 } 68 69 @Implementation getServiceInfo()70 protected ServiceInfo getServiceInfo() { 71 return mServiceInfo; 72 } 73 74 @Resetter reset()75 public static void reset() { 76 sSupportsAssistMap.clear(); 77 sRecognitionServiceMap.clear(); 78 sSettingsActivityMap.clear(); 79 } 80 } 81