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 android.telecom.cts.api29incallservice; 18 19 import android.app.Service; 20 import android.content.Intent; 21 import android.os.IBinder; 22 import android.os.Process; 23 import android.telecom.Call; 24 import android.util.Log; 25 26 public class CtsApi29InCallServiceControl extends Service { 27 28 private static final String TAG = CtsApi29InCallServiceControl.class.getSimpleName(); 29 public static final String CONTROL_INTERFACE_ACTION = 30 "android.telecom.cts.api29incallservice.ACTION_API29_CONTROL"; 31 32 private final IBinder mCtsCompanionAppControl = new ICtsApi29InCallServiceControl.Stub() { 33 34 @Override 35 public int getCallState(String callId) { 36 return CtsApi29InCallService.sCalls.stream() 37 .filter(c -> c.getDetails().getTelecomCallId().equals(callId)) 38 .findFirst().map(Call::getState).orElse(-1); 39 } 40 41 @Override 42 public int getLocalCallCount() { 43 return CtsApi29InCallService.getLocalCallCount(); 44 } 45 46 @Override 47 public int getHistoricalCallCount() { 48 return CtsApi29InCallService.sHistoricalCallCount; 49 } 50 51 @Override 52 public boolean hasReceivedBindRequest() { 53 return CtsApi29InCallService.sBindRequestFuture.getNow(false); 54 } 55 56 @Override 57 public void setShouldReturnNullBinding(boolean shouldReturnNullBinding) { 58 CtsApi29InCallService.sShouldReturnNullBinding = shouldReturnNullBinding; 59 } 60 61 @Override 62 public boolean waitForBindRequest() { 63 return CtsApi29InCallService.waitForBindRequest(); 64 } 65 66 @Override 67 public void kill() { 68 Process.killProcess(Process.myPid()); 69 } 70 }; 71 72 @Override onBind(Intent intent)73 public IBinder onBind(Intent intent) { 74 if (CONTROL_INTERFACE_ACTION.equals(intent.getAction())) { 75 Log.d(TAG, "onBind: return control interface."); 76 return mCtsCompanionAppControl; 77 } 78 Log.d(TAG, "onBind: invalid intent."); 79 return null; 80 } 81 82 @Override onUnbind(Intent intent)83 public boolean onUnbind(Intent intent) { 84 CtsApi29InCallService.reset(); 85 return false; 86 } 87 88 } 89