blob: 78b8bcc74acb7d212f3552e889282586e5da7f33 [file] [log] [blame]
Tyler Gunn61b92102014-08-19 07:42:20 -07001/*
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
Tyler Gunn7cc70b42014-09-12 22:17:27 -070017package com.android.server.telecom.testapps;
Tyler Gunn61b92102014-08-19 07:42:20 -070018
Santos Cordonf78a72f2016-01-21 22:10:32 +000019import android.content.Context;
20import android.content.Intent;
Tyler Gunn633963e2015-04-15 14:32:00 -070021import android.telecom.Call;
Hall Liu67eb3b02018-04-27 17:54:46 -070022import android.telecom.CallAudioState;
Tyler Gunn7cc70b42014-09-12 22:17:27 -070023import android.telecom.InCallService;
24import android.telecom.Phone;
Tyler Gunn61b92102014-08-19 07:42:20 -070025import android.util.Log;
26
27import java.lang.Override;
28import java.lang.String;
29
30/**
31 * Test In-Call service implementation. Logs incoming events. Mainly used to test binding to
32 * multiple {@link InCallService} implementations.
33 */
34public class TestInCallServiceImpl extends InCallService {
35 private static final String TAG = "TestInCallServiceImpl";
Hall Liu67eb3b02018-04-27 17:54:46 -070036 public static TestInCallServiceImpl sInstance;
Tyler Gunn61b92102014-08-19 07:42:20 -070037
38 private Phone mPhone;
39
40 private Phone.Listener mPhoneListener = new Phone.Listener() {
41 @Override
Tyler Gunn633963e2015-04-15 14:32:00 -070042 public void onCallAdded(Phone phone, Call call) {
43 Log.i(TAG, "onCallAdded: " + call.toString());
Santos Cordonf78a72f2016-01-21 22:10:32 +000044 TestCallList callList = TestCallList.getInstance();
45 callList.addCall(call);
46
47 if (callList.size() == 1) {
48 startInCallUI();
49 }
Tyler Gunn61b92102014-08-19 07:42:20 -070050 }
Tyler Gunn633963e2015-04-15 14:32:00 -070051
Tyler Gunn61b92102014-08-19 07:42:20 -070052 @Override
Tyler Gunn633963e2015-04-15 14:32:00 -070053 public void onCallRemoved(Phone phone, Call call) {
Tyler Gunn61b92102014-08-19 07:42:20 -070054 Log.i(TAG, "onCallRemoved: "+call.toString());
Tyler Gunn633963e2015-04-15 14:32:00 -070055 TestCallList.getInstance().removeCall(call);
Tyler Gunn61b92102014-08-19 07:42:20 -070056 }
57 };
58
59 @Override
60 public void onPhoneCreated(Phone phone) {
61 Log.i(TAG, "onPhoneCreated");
62 mPhone = phone;
63 mPhone.addListener(mPhoneListener);
Tyler Gunn633963e2015-04-15 14:32:00 -070064 TestCallList.getInstance().clearCalls();
Tyler Gunn61b92102014-08-19 07:42:20 -070065 }
66
67 @Override
Hall Liu67eb3b02018-04-27 17:54:46 -070068 public boolean onUnbind(Intent intent) {
Tyler Gunn61b92102014-08-19 07:42:20 -070069 Log.i(TAG, "onPhoneDestroyed");
70 mPhone.removeListener(mPhoneListener);
71 mPhone = null;
Tyler Gunn633963e2015-04-15 14:32:00 -070072 TestCallList.getInstance().clearCalls();
Hall Liu67eb3b02018-04-27 17:54:46 -070073 sInstance = null;
74 return super.onUnbind(intent);
75 }
76
77 @Override
78 public void onCallAudioStateChanged(CallAudioState cas) {
79 if (TestInCallUI.sInstance != null) {
80 TestInCallUI.sInstance.updateCallAudioState(cas);
81 }
Tyler Gunn61b92102014-08-19 07:42:20 -070082 }
Santos Cordonf78a72f2016-01-21 22:10:32 +000083
84 private void startInCallUI() {
Hall Liu67eb3b02018-04-27 17:54:46 -070085 sInstance = this;
Santos Cordonf78a72f2016-01-21 22:10:32 +000086 Intent intent = new Intent(Intent.ACTION_MAIN);
87 intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
88 intent.setClass(this, TestInCallUI.class);
89 startActivity(intent);
90 }
Tyler Gunn61b92102014-08-19 07:42:20 -070091}