Tyler Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 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 | |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 17 | package com.android.server.telecom.testapps; |
Tyler Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 18 | |
Santos Cordon | f78a72f | 2016-01-21 22:10:32 +0000 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.content.Intent; |
Tyler Gunn | 633963e | 2015-04-15 14:32:00 -0700 | [diff] [blame] | 21 | import android.telecom.Call; |
Hall Liu | 67eb3b0 | 2018-04-27 17:54:46 -0700 | [diff] [blame] | 22 | import android.telecom.CallAudioState; |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 23 | import android.telecom.InCallService; |
| 24 | import android.telecom.Phone; |
Tyler Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 25 | import android.util.Log; |
| 26 | |
| 27 | import java.lang.Override; |
| 28 | import 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 | */ |
| 34 | public class TestInCallServiceImpl extends InCallService { |
| 35 | private static final String TAG = "TestInCallServiceImpl"; |
Hall Liu | 67eb3b0 | 2018-04-27 17:54:46 -0700 | [diff] [blame] | 36 | public static TestInCallServiceImpl sInstance; |
Tyler Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 37 | |
| 38 | private Phone mPhone; |
| 39 | |
| 40 | private Phone.Listener mPhoneListener = new Phone.Listener() { |
| 41 | @Override |
Tyler Gunn | 633963e | 2015-04-15 14:32:00 -0700 | [diff] [blame] | 42 | public void onCallAdded(Phone phone, Call call) { |
| 43 | Log.i(TAG, "onCallAdded: " + call.toString()); |
Santos Cordon | f78a72f | 2016-01-21 22:10:32 +0000 | [diff] [blame] | 44 | TestCallList callList = TestCallList.getInstance(); |
| 45 | callList.addCall(call); |
| 46 | |
| 47 | if (callList.size() == 1) { |
| 48 | startInCallUI(); |
| 49 | } |
Tyler Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 50 | } |
Tyler Gunn | 633963e | 2015-04-15 14:32:00 -0700 | [diff] [blame] | 51 | |
Tyler Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 52 | @Override |
Tyler Gunn | 633963e | 2015-04-15 14:32:00 -0700 | [diff] [blame] | 53 | public void onCallRemoved(Phone phone, Call call) { |
Tyler Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 54 | Log.i(TAG, "onCallRemoved: "+call.toString()); |
Tyler Gunn | 633963e | 2015-04-15 14:32:00 -0700 | [diff] [blame] | 55 | TestCallList.getInstance().removeCall(call); |
Tyler Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 56 | } |
| 57 | }; |
| 58 | |
| 59 | @Override |
| 60 | public void onPhoneCreated(Phone phone) { |
| 61 | Log.i(TAG, "onPhoneCreated"); |
| 62 | mPhone = phone; |
| 63 | mPhone.addListener(mPhoneListener); |
Tyler Gunn | 633963e | 2015-04-15 14:32:00 -0700 | [diff] [blame] | 64 | TestCallList.getInstance().clearCalls(); |
Tyler Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Override |
Hall Liu | 67eb3b0 | 2018-04-27 17:54:46 -0700 | [diff] [blame] | 68 | public boolean onUnbind(Intent intent) { |
Tyler Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 69 | Log.i(TAG, "onPhoneDestroyed"); |
| 70 | mPhone.removeListener(mPhoneListener); |
| 71 | mPhone = null; |
Tyler Gunn | 633963e | 2015-04-15 14:32:00 -0700 | [diff] [blame] | 72 | TestCallList.getInstance().clearCalls(); |
Hall Liu | 67eb3b0 | 2018-04-27 17:54:46 -0700 | [diff] [blame] | 73 | 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 Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 82 | } |
Santos Cordon | f78a72f | 2016-01-21 22:10:32 +0000 | [diff] [blame] | 83 | |
| 84 | private void startInCallUI() { |
Hall Liu | 67eb3b0 | 2018-04-27 17:54:46 -0700 | [diff] [blame] | 85 | sInstance = this; |
Santos Cordon | f78a72f | 2016-01-21 22:10:32 +0000 | [diff] [blame] | 86 | 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 Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 91 | } |