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 17 package com.android.server.telecom.testapps; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.telecom.Call; 22 import android.telecom.InCallService; 23 import android.telecom.Phone; 24 import android.util.Log; 25 26 import java.lang.Override; 27 import java.lang.String; 28 29 /** 30 * Test In-Call service implementation. Logs incoming events. Mainly used to test binding to 31 * multiple {@link InCallService} implementations. 32 */ 33 public class TestInCallServiceImpl extends InCallService { 34 private static final String TAG = "TestInCallServiceImpl"; 35 36 private Phone mPhone; 37 38 private Phone.Listener mPhoneListener = new Phone.Listener() { 39 @Override 40 public void onCallAdded(Phone phone, Call call) { 41 Log.i(TAG, "onCallAdded: " + call.toString()); 42 TestCallList callList = TestCallList.getInstance(); 43 callList.addCall(call); 44 45 if (callList.size() == 1) { 46 startInCallUI(); 47 } 48 } 49 50 @Override 51 public void onCallRemoved(Phone phone, Call call) { 52 Log.i(TAG, "onCallRemoved: "+call.toString()); 53 TestCallList.getInstance().removeCall(call); 54 } 55 }; 56 57 @Override onPhoneCreated(Phone phone)58 public void onPhoneCreated(Phone phone) { 59 Log.i(TAG, "onPhoneCreated"); 60 mPhone = phone; 61 mPhone.addListener(mPhoneListener); 62 TestCallList.getInstance().clearCalls(); 63 } 64 65 @Override onPhoneDestroyed(Phone phone)66 public void onPhoneDestroyed(Phone phone) { 67 Log.i(TAG, "onPhoneDestroyed"); 68 mPhone.removeListener(mPhoneListener); 69 mPhone = null; 70 TestCallList.getInstance().clearCalls(); 71 } 72 startInCallUI()73 private void startInCallUI() { 74 Intent intent = new Intent(Intent.ACTION_MAIN); 75 intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK); 76 intent.setClass(this, TestInCallUI.class); 77 startActivity(intent); 78 } 79 } 80