1 /* 2 * Copyright (C) 2013 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.BroadcastReceiver; 20 import android.content.ComponentName; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.net.Uri; 24 import android.os.Bundle; 25 import androidx.localbroadcastmanager.content.LocalBroadcastManager; 26 import android.telecom.PhoneAccountHandle; 27 import android.telecom.TelecomManager; 28 import android.telecom.VideoProfile; 29 import android.util.Log; 30 31 /** 32 * This class receives the notification callback intents used to update call states for 33 * {@link TestConnectionService}. 34 */ 35 public class CallNotificationReceiver extends BroadcastReceiver { 36 37 static final String TAG = CallNotificationReceiver.class.getSimpleName(); 38 /** 39 * Exit intent action is sent when the user clicks the "exit" action of the 40 * TestConnectionService notification. Used to cancel (remove) the notification. 41 */ 42 static final String ACTION_CALL_SERVICE_EXIT = 43 "com.android.server.telecom.testapps.ACTION_CALL_SERVICE_EXIT"; 44 static final String ACTION_REGISTER_PHONE_ACCOUNT = 45 "com.android.server.telecom.testapps.ACTION_REGISTER_PHONE_ACCOUNT"; 46 static final String ACTION_SHOW_ALL_PHONE_ACCOUNTS = 47 "com.android.server.telecom.testapps.ACTION_SHOW_ALL_PHONE_ACCOUNTS"; 48 static final String ACTION_ONE_WAY_VIDEO_CALL = 49 "com.android.server.telecom.testapps.ACTION_ONE_WAY_VIDEO_CALL"; 50 static final String ACTION_TWO_WAY_VIDEO_CALL = 51 "com.android.server.telecom.testapps.ACTION_TWO_WAY_VIDEO_CALL"; 52 static final String ACTION_AUDIO_CALL = 53 "com.android.server.telecom.testapps.ACTION_AUDIO_CALL"; 54 static final String ACTION_RTT_CALL = 55 "com.android.server.telecom.testapps.ACTION_RTT_CALL"; 56 57 /** {@inheritDoc} */ 58 @Override onReceive(Context context, Intent intent)59 public void onReceive(Context context, Intent intent) { 60 String action = intent.getAction(); 61 if (ACTION_CALL_SERVICE_EXIT.equals(action)) { 62 CallServiceNotifier.getInstance().cancelNotifications(context); 63 } else if (ACTION_REGISTER_PHONE_ACCOUNT.equals(action)) { 64 CallServiceNotifier.getInstance().registerPhoneAccount(context); 65 } else if (ACTION_SHOW_ALL_PHONE_ACCOUNTS.equals(action)) { 66 CallServiceNotifier.getInstance().showAllPhoneAccounts(context); 67 } else if (ACTION_ONE_WAY_VIDEO_CALL.equals(action)) { 68 sendIncomingCallIntent(context, null, VideoProfile.STATE_RX_ENABLED); 69 } else if (ACTION_TWO_WAY_VIDEO_CALL.equals(action)) { 70 sendIncomingCallIntent(context, null, VideoProfile.STATE_BIDIRECTIONAL); 71 } else if (ACTION_RTT_CALL.equals(action)) { 72 sendIncomingRttCallIntent(context, null, VideoProfile.STATE_AUDIO_ONLY); 73 } else if (ACTION_AUDIO_CALL.equals(action)) { 74 sendIncomingCallIntent(context, null, VideoProfile.STATE_AUDIO_ONLY); 75 } 76 } 77 78 /** 79 * Creates and sends the intent to add an incoming call through Telecom. 80 * 81 * @param context The current context. 82 * @param videoState The video state requested for the incoming call. 83 */ sendIncomingCallIntent(Context context, Uri handle, int videoState)84 public static void sendIncomingCallIntent(Context context, Uri handle, int videoState) { 85 TelecomManager telecomManager = context.getSystemService(TelecomManager.class); 86 PhoneAccountHandle phoneAccount = new PhoneAccountHandle( 87 new ComponentName(context, TestConnectionService.class), 88 CallServiceNotifier.SIM_SUBSCRIPTION_ID); 89 90 // For the purposes of testing, indicate whether the incoming call is a video call by 91 // stashing an indicator in the EXTRA_INCOMING_CALL_EXTRAS. 92 Bundle extras = new Bundle(); 93 extras.putInt(TestConnectionService.EXTRA_START_VIDEO_STATE, videoState); 94 if (handle != null) { 95 extras.putParcelable(TestConnectionService.EXTRA_HANDLE, handle); 96 } 97 98 telecomManager.addNewIncomingCall(phoneAccount, extras); 99 } 100 sendIncomingRttCallIntent(Context context, Uri handle, int videoState)101 public static void sendIncomingRttCallIntent(Context context, Uri handle, int videoState) { 102 TelecomManager telecomManager = context.getSystemService(TelecomManager.class); 103 PhoneAccountHandle phoneAccount = new PhoneAccountHandle( 104 new ComponentName(context, TestConnectionService.class), 105 CallServiceNotifier.SIM_SUBSCRIPTION_ID); 106 107 // For the purposes of testing, indicate whether the incoming call is a video call by 108 // stashing an indicator in the EXTRA_INCOMING_CALL_EXTRAS. 109 Bundle extras = new Bundle(); 110 extras.putInt(TestConnectionService.EXTRA_START_VIDEO_STATE, videoState); 111 if (handle != null) { 112 extras.putParcelable(TestConnectionService.EXTRA_HANDLE, handle); 113 } 114 extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_RTT, true); 115 116 telecomManager.addNewIncomingCall(phoneAccount, extras); 117 } 118 addNewUnknownCall(Context context, Uri handle, Bundle extras)119 public static void addNewUnknownCall(Context context, Uri handle, Bundle extras) { 120 Log.i(TAG, "Adding new unknown call with handle " + handle); 121 TelecomManager telecomManager = context.getSystemService(TelecomManager.class); 122 PhoneAccountHandle phoneAccount = new PhoneAccountHandle( 123 new ComponentName(context, TestConnectionService.class), 124 CallServiceNotifier.SIM_SUBSCRIPTION_ID); 125 126 if (extras == null) { 127 extras = new Bundle(); 128 } 129 130 if (handle != null) { 131 extras.putParcelable(TelecomManager.EXTRA_UNKNOWN_CALL_HANDLE, handle); 132 extras.putParcelable(TestConnectionService.EXTRA_HANDLE, handle); 133 } 134 135 telecomManager.addNewUnknownCall(phoneAccount, extras); 136 } 137 hangupCalls(Context context)138 public static void hangupCalls(Context context) { 139 Log.i(TAG, "Hanging up all calls"); 140 LocalBroadcastManager.getInstance(context).sendBroadcast( 141 new Intent(TestCallActivity.ACTION_HANGUP_CALLS)); 142 } 143 sendUpgradeRequest(Context context, Uri data)144 public static void sendUpgradeRequest(Context context, Uri data) { 145 Log.i(TAG, "Sending upgrade request of type: " + data); 146 final Intent intent = new Intent(TestCallActivity.ACTION_SEND_UPGRADE_REQUEST); 147 intent.setData(data); 148 LocalBroadcastManager.getInstance(context).sendBroadcast(intent); 149 } 150 remoteRttUpgrade(Context context)151 public static void remoteRttUpgrade(Context context) { 152 final Intent intent = new Intent(TestCallActivity.ACTION_REMOTE_RTT_UPGRADE); 153 LocalBroadcastManager.getInstance(context).sendBroadcast(intent); 154 } 155 } 156