VoiceInteractionService.java revision 91097de49b0f683b00e26a75dbc0ac6082344137
1/** 2 * Copyright (C) 2014 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 17package android.service.voice; 18 19import android.annotation.SdkConstant; 20import android.app.Instrumentation; 21import android.app.Service; 22import android.content.Context; 23import android.content.Intent; 24import android.os.IBinder; 25import android.os.RemoteException; 26import android.os.ServiceManager; 27import com.android.internal.app.IVoiceInteractionManagerService; 28 29public class VoiceInteractionService extends Service { 30 /** 31 * The {@link Intent} that must be declared as handled by the service. 32 * To be supported, the service must also require the 33 * {@link android.Manifest.permission#BIND_VOICE_INTERACTION} permission so 34 * that other applications can not abuse it. 35 */ 36 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION) 37 public static final String SERVICE_INTERFACE = 38 "android.service.voice.VoiceInteractionService"; 39 40 /** 41 * Name under which a VoiceInteractionService component publishes information about itself. 42 * This meta-data should reference an XML resource containing a 43 * <code><{@link 44 * android.R.styleable#VoiceInteractionService voice-interaction-service}></code> tag. 45 */ 46 public static final String SERVICE_META_DATA = "android.voice_interaction"; 47 48 IVoiceInteractionService mInterface = new IVoiceInteractionService.Stub() { 49 }; 50 51 IVoiceInteractionManagerService mSystemService; 52 53 public void startVoiceActivity(Intent intent, VoiceInteractionSession session) { 54 try { 55 int res = mSystemService.startVoiceActivity(intent, 56 intent.resolveType(getContentResolver()), 57 mInterface, session.mSession, session.mInteractor); 58 Instrumentation.checkStartActivityResult(res, intent); 59 } catch (RemoteException e) { 60 } 61 } 62 63 @Override 64 public void onCreate() { 65 super.onCreate(); 66 mSystemService = IVoiceInteractionManagerService.Stub.asInterface( 67 ServiceManager.getService(Context.VOICE_INTERACTION_MANAGER_SERVICE)); 68 } 69 70 @Override 71 public IBinder onBind(Intent intent) { 72 if (SERVICE_INTERFACE.equals(intent.getAction())) { 73 return mInterface.asBinder(); 74 } 75 return null; 76 } 77} 78