Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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.phone; |
| 18 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 19 | import android.bluetooth.BluetoothAdapter; |
| 20 | import android.bluetooth.BluetoothHeadset; |
| 21 | import android.bluetooth.BluetoothProfile; |
| 22 | import android.content.Context; |
| 23 | import android.media.AudioManager; |
| 24 | import android.media.ToneGenerator; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 25 | import android.os.AsyncResult; |
| 26 | import android.os.Handler; |
| 27 | import android.os.Message; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 28 | import android.os.SystemProperties; |
Pavel Zhamaitsiak | 82256c0 | 2014-12-10 17:11:40 -0800 | [diff] [blame] | 29 | import android.telecom.TelecomManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | import android.telephony.PhoneStateListener; |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 31 | import android.telephony.SubscriptionInfo; |
| 32 | import android.telephony.SubscriptionManager; |
| 33 | import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 34 | import android.telephony.TelephonyManager; |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 35 | import android.util.ArrayMap; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 36 | import android.util.Log; |
| 37 | |
Aravind Sreekumar | afc08c5 | 2018-04-10 15:34:32 -0700 | [diff] [blame] | 38 | import com.android.internal.telephony.CallManager; |
| 39 | import com.android.internal.telephony.Phone; |
| 40 | import com.android.internal.telephony.PhoneConstants; |
| 41 | import com.android.internal.telephony.SubscriptionController; |
| 42 | import com.android.internal.telephony.cdma.CdmaInformationRecords.CdmaDisplayInfoRec; |
| 43 | import com.android.internal.telephony.cdma.CdmaInformationRecords.CdmaSignalInfoRec; |
| 44 | import com.android.internal.telephony.cdma.SignalToneUtil; |
| 45 | |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 46 | import java.util.ArrayList; |
| 47 | import java.util.Collections; |
| 48 | import java.util.Comparator; |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 49 | import java.util.List; |
| 50 | import java.util.Map; |
| 51 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | /** |
| 53 | * Phone app module that listens for phone state changes and various other |
| 54 | * events from the telephony layer, and triggers any resulting UI behavior |
Santos Cordon | 5422a8d | 2014-09-12 04:20:56 -0700 | [diff] [blame] | 55 | * (like starting the Incoming Call UI, playing in-call tones, |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | * updating notifications, writing call log entries, etc.) |
| 57 | */ |
Santos Cordon | 5422a8d | 2014-09-12 04:20:56 -0700 | [diff] [blame] | 58 | public class CallNotifier extends Handler { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 59 | private static final String LOG_TAG = "CallNotifier"; |
| 60 | private static final boolean DBG = |
| 61 | (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1); |
| 62 | private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 63 | |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 64 | // Time to display the message from the underlying phone layers. |
| 65 | private static final int SHOW_MESSAGE_NOTIFICATION_TIME = 3000; // msec |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 66 | |
| 67 | /** The singleton instance. */ |
| 68 | private static CallNotifier sInstance; |
| 69 | |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 70 | private Map<Integer, CallNotifierPhoneStateListener> mPhoneStateListeners = |
| 71 | new ArrayMap<Integer, CallNotifierPhoneStateListener>(); |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 72 | private Map<Integer, Boolean> mCFIStatus = new ArrayMap<Integer, Boolean>(); |
| 73 | private Map<Integer, Boolean> mMWIStatus = new ArrayMap<Integer, Boolean>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | private PhoneGlobals mApplication; |
| 75 | private CallManager mCM; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 76 | private BluetoothHeadset mBluetoothHeadset; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 77 | |
| 78 | // ToneGenerator instance for playing SignalInfo tones |
| 79 | private ToneGenerator mSignalInfoToneGenerator; |
| 80 | |
| 81 | // The tone volume relative to other sounds in the stream SignalInfo |
| 82 | private static final int TONE_RELATIVE_VOLUME_SIGNALINFO = 80; |
| 83 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 84 | private boolean mVoicePrivacyState = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 85 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 86 | // Cached AudioManager |
| 87 | private AudioManager mAudioManager; |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 88 | private SubscriptionManager mSubscriptionManager; |
| 89 | private TelephonyManager mTelephonyManager; |
Santos Cordon | 27a3c1f | 2013-08-06 07:49:27 -0700 | [diff] [blame] | 90 | |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 91 | // Events from the Phone object: |
| 92 | public static final int PHONE_DISCONNECT = 3; |
| 93 | public static final int PHONE_STATE_DISPLAYINFO = 6; |
| 94 | public static final int PHONE_STATE_SIGNALINFO = 7; |
| 95 | public static final int PHONE_ENHANCED_VP_ON = 9; |
| 96 | public static final int PHONE_ENHANCED_VP_OFF = 10; |
| 97 | public static final int PHONE_SUPP_SERVICE_FAILED = 14; |
| 98 | public static final int PHONE_TTY_MODE_RECEIVED = 15; |
| 99 | // Events generated internally. |
| 100 | // We should store all the possible event type values in one place to make sure that |
| 101 | // they don't step on each others' toes. |
| 102 | public static final int INTERNAL_SHOW_MESSAGE_NOTIFICATION_DONE = 22; |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 103 | |
Srikanth Chintala | 4baf0b9 | 2017-11-14 15:52:47 +0530 | [diff] [blame] | 104 | public static final int UPDATE_TYPE_MWI = 0; |
| 105 | public static final int UPDATE_TYPE_CFI = 1; |
| 106 | public static final int UPDATE_TYPE_MWI_CFI = 2; |
| 107 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 108 | /** |
| 109 | * Initialize the singleton CallNotifier instance. |
| 110 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 111 | */ |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 112 | /* package */ static CallNotifier init( |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 113 | PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 114 | synchronized (CallNotifier.class) { |
| 115 | if (sInstance == null) { |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 116 | sInstance = new CallNotifier(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 117 | } else { |
| 118 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 119 | } |
| 120 | return sInstance; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /** Private constructor; @see init() */ |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 125 | private CallNotifier( |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 126 | PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 127 | mApplication = app; |
| 128 | mCM = app.mCM; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | |
| 130 | mAudioManager = (AudioManager) mApplication.getSystemService(Context.AUDIO_SERVICE); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 131 | mTelephonyManager = |
| 132 | (TelephonyManager) mApplication.getSystemService(Context.TELEPHONY_SERVICE); |
| 133 | mSubscriptionManager = (SubscriptionManager) mApplication.getSystemService( |
| 134 | Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 135 | |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 136 | registerForNotifications(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 137 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 138 | BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); |
| 139 | if (adapter != null) { |
| 140 | adapter.getProfileProxy(mApplication.getApplicationContext(), |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 141 | mBluetoothProfileServiceListener, |
| 142 | BluetoothProfile.HEADSET); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Wink Saville | f67832f | 2015-01-12 16:51:50 -0800 | [diff] [blame] | 145 | mSubscriptionManager.addOnSubscriptionsChangedListener( |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 146 | new OnSubscriptionsChangedListener() { |
| 147 | @Override |
| 148 | public void onSubscriptionsChanged() { |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 149 | updatePhoneStateListeners(true); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 150 | } |
| 151 | }); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | private void createSignalInfoToneGenerator() { |
| 155 | // Instantiate the ToneGenerator for SignalInfo and CallWaiting |
| 156 | // TODO: We probably don't need the mSignalInfoToneGenerator instance |
| 157 | // around forever. Need to change it so as to create a ToneGenerator instance only |
| 158 | // when a tone is being played and releases it after its done playing. |
| 159 | if (mSignalInfoToneGenerator == null) { |
| 160 | try { |
| 161 | mSignalInfoToneGenerator = new ToneGenerator(AudioManager.STREAM_VOICE_CALL, |
| 162 | TONE_RELATIVE_VOLUME_SIGNALINFO); |
| 163 | Log.d(LOG_TAG, "CallNotifier: mSignalInfoToneGenerator created when toneplay"); |
| 164 | } catch (RuntimeException e) { |
| 165 | Log.w(LOG_TAG, "CallNotifier: Exception caught while creating " + |
| 166 | "mSignalInfoToneGenerator: " + e); |
| 167 | mSignalInfoToneGenerator = null; |
| 168 | } |
| 169 | } else { |
| 170 | Log.d(LOG_TAG, "mSignalInfoToneGenerator created already, hence skipping"); |
| 171 | } |
| 172 | } |
| 173 | |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 174 | /** |
| 175 | * Register for call state notifications with the CallManager. |
| 176 | */ |
| 177 | private void registerForNotifications() { |
| 178 | mCM.registerForDisconnect(this, PHONE_DISCONNECT, null); |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 179 | mCM.registerForDisplayInfo(this, PHONE_STATE_DISPLAYINFO, null); |
| 180 | mCM.registerForSignalInfo(this, PHONE_STATE_SIGNALINFO, null); |
| 181 | mCM.registerForInCallVoicePrivacyOn(this, PHONE_ENHANCED_VP_ON, null); |
| 182 | mCM.registerForInCallVoicePrivacyOff(this, PHONE_ENHANCED_VP_OFF, null); |
| 183 | mCM.registerForSuppServiceFailed(this, PHONE_SUPP_SERVICE_FAILED, null); |
| 184 | mCM.registerForTtyModeReceived(this, PHONE_TTY_MODE_RECEIVED, null); |
| 185 | } |
| 186 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 187 | @Override |
| 188 | public void handleMessage(Message msg) { |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 189 | if (DBG) { |
| 190 | Log.d(LOG_TAG, "handleMessage(" + msg.what + ")"); |
| 191 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 192 | switch (msg.what) { |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 193 | case PHONE_DISCONNECT: |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 194 | if (DBG) log("DISCONNECT"); |
Roshan Pius | 19f39cf | 2015-08-12 10:44:38 -0700 | [diff] [blame] | 195 | // Stop any signalInfo tone being played when a call gets ended, the rest of the |
| 196 | // disconnect functionality in onDisconnect() is handled in ConnectionService. |
| 197 | stopSignalInfoTone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 198 | break; |
| 199 | |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 200 | case PHONE_STATE_DISPLAYINFO: |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 201 | if (DBG) log("Received PHONE_STATE_DISPLAYINFO event"); |
| 202 | onDisplayInfo((AsyncResult) msg.obj); |
| 203 | break; |
| 204 | |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 205 | case PHONE_STATE_SIGNALINFO: |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 206 | if (DBG) log("Received PHONE_STATE_SIGNALINFO event"); |
| 207 | onSignalInfo((AsyncResult) msg.obj); |
| 208 | break; |
| 209 | |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 210 | case INTERNAL_SHOW_MESSAGE_NOTIFICATION_DONE: |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 211 | if (DBG) log("Received Display Info notification done event ..."); |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 212 | PhoneDisplayMessage.dismissMessage(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 213 | break; |
| 214 | |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 215 | case PHONE_ENHANCED_VP_ON: |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 216 | if (DBG) log("PHONE_ENHANCED_VP_ON..."); |
| 217 | if (!mVoicePrivacyState) { |
| 218 | int toneToPlay = InCallTonePlayer.TONE_VOICE_PRIVACY; |
| 219 | new InCallTonePlayer(toneToPlay).start(); |
| 220 | mVoicePrivacyState = true; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 221 | } |
| 222 | break; |
| 223 | |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 224 | case PHONE_ENHANCED_VP_OFF: |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 225 | if (DBG) log("PHONE_ENHANCED_VP_OFF..."); |
| 226 | if (mVoicePrivacyState) { |
| 227 | int toneToPlay = InCallTonePlayer.TONE_VOICE_PRIVACY; |
| 228 | new InCallTonePlayer(toneToPlay).start(); |
| 229 | mVoicePrivacyState = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 230 | } |
| 231 | break; |
| 232 | |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 233 | case PHONE_SUPP_SERVICE_FAILED: |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 234 | if (DBG) log("PHONE_SUPP_SERVICE_FAILED..."); |
| 235 | onSuppServiceFailed((AsyncResult) msg.obj); |
| 236 | break; |
| 237 | |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 238 | case PHONE_TTY_MODE_RECEIVED: |
Pavel Zhamaitsiak | 82256c0 | 2014-12-10 17:11:40 -0800 | [diff] [blame] | 239 | if (DBG) log("Received PHONE_TTY_MODE_RECEIVED event"); |
| 240 | onTtyModeReceived((AsyncResult) msg.obj); |
| 241 | break; |
| 242 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 243 | default: |
| 244 | // super.handleMessage(msg); |
| 245 | } |
| 246 | } |
| 247 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 248 | void updateCallNotifierRegistrationsAfterRadioTechnologyChange() { |
| 249 | if (DBG) Log.d(LOG_TAG, "updateCallNotifierRegistrationsAfterRadioTechnologyChange..."); |
| 250 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 251 | // Instantiate mSignalInfoToneGenerator |
| 252 | createSignalInfoToneGenerator(); |
| 253 | } |
| 254 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 255 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 256 | * Helper class to play tones through the earpiece (or speaker / BT) |
| 257 | * during a call, using the ToneGenerator. |
| 258 | * |
| 259 | * To use, just instantiate a new InCallTonePlayer |
| 260 | * (passing in the TONE_* constant for the tone you want) |
| 261 | * and start() it. |
| 262 | * |
| 263 | * When we're done playing the tone, if the phone is idle at that |
| 264 | * point, we'll reset the audio routing and speaker state. |
| 265 | * (That means that for tones that get played *after* a call |
| 266 | * disconnects, like "busy" or "congestion" or "call ended", you |
| 267 | * should NOT call resetAudioStateAfterDisconnect() yourself. |
| 268 | * Instead, just start the InCallTonePlayer, which will automatically |
| 269 | * defer the resetAudioStateAfterDisconnect() call until the tone |
| 270 | * finishes playing.) |
| 271 | */ |
| 272 | private class InCallTonePlayer extends Thread { |
| 273 | private int mToneId; |
| 274 | private int mState; |
| 275 | // The possible tones we can play. |
| 276 | public static final int TONE_NONE = 0; |
| 277 | public static final int TONE_CALL_WAITING = 1; |
| 278 | public static final int TONE_BUSY = 2; |
| 279 | public static final int TONE_CONGESTION = 3; |
| 280 | public static final int TONE_CALL_ENDED = 4; |
| 281 | public static final int TONE_VOICE_PRIVACY = 5; |
| 282 | public static final int TONE_REORDER = 6; |
| 283 | public static final int TONE_INTERCEPT = 7; |
| 284 | public static final int TONE_CDMA_DROP = 8; |
| 285 | public static final int TONE_OUT_OF_SERVICE = 9; |
| 286 | public static final int TONE_REDIAL = 10; |
| 287 | public static final int TONE_OTA_CALL_END = 11; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 288 | public static final int TONE_UNOBTAINABLE_NUMBER = 13; |
| 289 | |
| 290 | // The tone volume relative to other sounds in the stream |
| 291 | static final int TONE_RELATIVE_VOLUME_EMERGENCY = 100; |
| 292 | static final int TONE_RELATIVE_VOLUME_HIPRI = 80; |
| 293 | static final int TONE_RELATIVE_VOLUME_LOPRI = 50; |
| 294 | |
| 295 | // Buffer time (in msec) to add on to tone timeout value. |
| 296 | // Needed mainly when the timeout value for a tone is the |
| 297 | // exact duration of the tone itself. |
| 298 | static final int TONE_TIMEOUT_BUFFER = 20; |
| 299 | |
| 300 | // The tone state |
| 301 | static final int TONE_OFF = 0; |
| 302 | static final int TONE_ON = 1; |
| 303 | static final int TONE_STOPPED = 2; |
| 304 | |
| 305 | InCallTonePlayer(int toneId) { |
| 306 | super(); |
| 307 | mToneId = toneId; |
| 308 | mState = TONE_OFF; |
| 309 | } |
| 310 | |
| 311 | @Override |
| 312 | public void run() { |
| 313 | log("InCallTonePlayer.run(toneId = " + mToneId + ")..."); |
| 314 | |
| 315 | int toneType = 0; // passed to ToneGenerator.startTone() |
| 316 | int toneVolume; // passed to the ToneGenerator constructor |
| 317 | int toneLengthMillis; |
| 318 | int phoneType = mCM.getFgPhone().getPhoneType(); |
| 319 | |
| 320 | switch (mToneId) { |
| 321 | case TONE_CALL_WAITING: |
| 322 | toneType = ToneGenerator.TONE_SUP_CALL_WAITING; |
| 323 | toneVolume = TONE_RELATIVE_VOLUME_HIPRI; |
| 324 | // Call waiting tone is stopped by stopTone() method |
| 325 | toneLengthMillis = Integer.MAX_VALUE - TONE_TIMEOUT_BUFFER; |
| 326 | break; |
| 327 | case TONE_BUSY: |
| 328 | if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { |
| 329 | toneType = ToneGenerator.TONE_CDMA_NETWORK_BUSY_ONE_SHOT; |
| 330 | toneVolume = TONE_RELATIVE_VOLUME_LOPRI; |
| 331 | toneLengthMillis = 1000; |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 332 | } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM |
| 333 | || phoneType == PhoneConstants.PHONE_TYPE_SIP |
Etan Cohen | 0ca1c80 | 2014-07-07 15:35:48 -0700 | [diff] [blame] | 334 | || phoneType == PhoneConstants.PHONE_TYPE_IMS |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 335 | || phoneType == PhoneConstants.PHONE_TYPE_THIRD_PARTY) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 336 | toneType = ToneGenerator.TONE_SUP_BUSY; |
| 337 | toneVolume = TONE_RELATIVE_VOLUME_HIPRI; |
| 338 | toneLengthMillis = 4000; |
| 339 | } else { |
| 340 | throw new IllegalStateException("Unexpected phone type: " + phoneType); |
| 341 | } |
| 342 | break; |
| 343 | case TONE_CONGESTION: |
| 344 | toneType = ToneGenerator.TONE_SUP_CONGESTION; |
| 345 | toneVolume = TONE_RELATIVE_VOLUME_HIPRI; |
| 346 | toneLengthMillis = 4000; |
| 347 | break; |
| 348 | |
| 349 | case TONE_CALL_ENDED: |
| 350 | toneType = ToneGenerator.TONE_PROP_PROMPT; |
| 351 | toneVolume = TONE_RELATIVE_VOLUME_HIPRI; |
| 352 | toneLengthMillis = 200; |
| 353 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 354 | case TONE_VOICE_PRIVACY: |
| 355 | toneType = ToneGenerator.TONE_CDMA_ALERT_NETWORK_LITE; |
| 356 | toneVolume = TONE_RELATIVE_VOLUME_HIPRI; |
| 357 | toneLengthMillis = 5000; |
| 358 | break; |
| 359 | case TONE_REORDER: |
| 360 | toneType = ToneGenerator.TONE_CDMA_REORDER; |
| 361 | toneVolume = TONE_RELATIVE_VOLUME_HIPRI; |
| 362 | toneLengthMillis = 4000; |
| 363 | break; |
| 364 | case TONE_INTERCEPT: |
| 365 | toneType = ToneGenerator.TONE_CDMA_ABBR_INTERCEPT; |
| 366 | toneVolume = TONE_RELATIVE_VOLUME_LOPRI; |
| 367 | toneLengthMillis = 500; |
| 368 | break; |
| 369 | case TONE_CDMA_DROP: |
| 370 | case TONE_OUT_OF_SERVICE: |
| 371 | toneType = ToneGenerator.TONE_CDMA_CALLDROP_LITE; |
| 372 | toneVolume = TONE_RELATIVE_VOLUME_LOPRI; |
| 373 | toneLengthMillis = 375; |
| 374 | break; |
| 375 | case TONE_REDIAL: |
| 376 | toneType = ToneGenerator.TONE_CDMA_ALERT_AUTOREDIAL_LITE; |
| 377 | toneVolume = TONE_RELATIVE_VOLUME_LOPRI; |
| 378 | toneLengthMillis = 5000; |
| 379 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 380 | case TONE_UNOBTAINABLE_NUMBER: |
| 381 | toneType = ToneGenerator.TONE_SUP_ERROR; |
| 382 | toneVolume = TONE_RELATIVE_VOLUME_HIPRI; |
| 383 | toneLengthMillis = 4000; |
| 384 | break; |
| 385 | default: |
| 386 | throw new IllegalArgumentException("Bad toneId: " + mToneId); |
| 387 | } |
| 388 | |
| 389 | // If the mToneGenerator creation fails, just continue without it. It is |
| 390 | // a local audio signal, and is not as important. |
| 391 | ToneGenerator toneGenerator; |
| 392 | try { |
| 393 | int stream; |
| 394 | if (mBluetoothHeadset != null) { |
Jordan Liu | 1c85e77 | 2019-08-06 16:06:19 -0700 | [diff] [blame] | 395 | stream = isBluetoothAudioOn() ? AudioManager.STREAM_BLUETOOTH_SCO : |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 396 | AudioManager.STREAM_VOICE_CALL; |
| 397 | } else { |
| 398 | stream = AudioManager.STREAM_VOICE_CALL; |
| 399 | } |
| 400 | toneGenerator = new ToneGenerator(stream, toneVolume); |
| 401 | // if (DBG) log("- created toneGenerator: " + toneGenerator); |
| 402 | } catch (RuntimeException e) { |
| 403 | Log.w(LOG_TAG, |
| 404 | "InCallTonePlayer: Exception caught while creating ToneGenerator: " + e); |
| 405 | toneGenerator = null; |
| 406 | } |
| 407 | |
| 408 | // Using the ToneGenerator (with the CALL_WAITING / BUSY / |
| 409 | // CONGESTION tones at least), the ToneGenerator itself knows |
| 410 | // the right pattern of tones to play; we do NOT need to |
| 411 | // manually start/stop each individual tone, or manually |
| 412 | // insert the correct delay between tones. (We just start it |
| 413 | // and let it run for however long we want the tone pattern to |
| 414 | // continue.) |
| 415 | // |
| 416 | // TODO: When we stop the ToneGenerator in the middle of a |
| 417 | // "tone pattern", it sounds bad if we cut if off while the |
| 418 | // tone is actually playing. Consider adding API to the |
| 419 | // ToneGenerator to say "stop at the next silent part of the |
| 420 | // pattern", or simply "play the pattern N times and then |
| 421 | // stop." |
| 422 | boolean needToStopTone = true; |
| 423 | boolean okToPlayTone = false; |
| 424 | |
| 425 | if (toneGenerator != null) { |
| 426 | int ringerMode = mAudioManager.getRingerMode(); |
| 427 | if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { |
| 428 | if (toneType == ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD) { |
| 429 | if ((ringerMode != AudioManager.RINGER_MODE_SILENT) && |
| 430 | (ringerMode != AudioManager.RINGER_MODE_VIBRATE)) { |
| 431 | if (DBG) log("- InCallTonePlayer: start playing call tone=" + toneType); |
| 432 | okToPlayTone = true; |
| 433 | needToStopTone = false; |
| 434 | } |
| 435 | } else if ((toneType == ToneGenerator.TONE_CDMA_NETWORK_BUSY_ONE_SHOT) || |
| 436 | (toneType == ToneGenerator.TONE_CDMA_REORDER) || |
| 437 | (toneType == ToneGenerator.TONE_CDMA_ABBR_REORDER) || |
| 438 | (toneType == ToneGenerator.TONE_CDMA_ABBR_INTERCEPT) || |
| 439 | (toneType == ToneGenerator.TONE_CDMA_CALLDROP_LITE)) { |
| 440 | if (ringerMode != AudioManager.RINGER_MODE_SILENT) { |
| 441 | if (DBG) log("InCallTonePlayer:playing call fail tone:" + toneType); |
| 442 | okToPlayTone = true; |
| 443 | needToStopTone = false; |
| 444 | } |
| 445 | } else if ((toneType == ToneGenerator.TONE_CDMA_ALERT_AUTOREDIAL_LITE) || |
| 446 | (toneType == ToneGenerator.TONE_CDMA_ALERT_NETWORK_LITE)) { |
| 447 | if ((ringerMode != AudioManager.RINGER_MODE_SILENT) && |
| 448 | (ringerMode != AudioManager.RINGER_MODE_VIBRATE)) { |
| 449 | if (DBG) log("InCallTonePlayer:playing tone for toneType=" + toneType); |
| 450 | okToPlayTone = true; |
| 451 | needToStopTone = false; |
| 452 | } |
| 453 | } else { // For the rest of the tones, always OK to play. |
| 454 | okToPlayTone = true; |
| 455 | } |
| 456 | } else { // Not "CDMA" |
| 457 | okToPlayTone = true; |
| 458 | } |
| 459 | |
| 460 | synchronized (this) { |
| 461 | if (okToPlayTone && mState != TONE_STOPPED) { |
| 462 | mState = TONE_ON; |
| 463 | toneGenerator.startTone(toneType); |
| 464 | try { |
| 465 | wait(toneLengthMillis + TONE_TIMEOUT_BUFFER); |
| 466 | } catch (InterruptedException e) { |
| 467 | Log.w(LOG_TAG, |
| 468 | "InCallTonePlayer stopped: " + e); |
| 469 | } |
| 470 | if (needToStopTone) { |
| 471 | toneGenerator.stopTone(); |
| 472 | } |
| 473 | } |
| 474 | // if (DBG) log("- InCallTonePlayer: done playing."); |
| 475 | toneGenerator.release(); |
| 476 | mState = TONE_OFF; |
| 477 | } |
| 478 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 479 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Jordan Liu | 1c85e77 | 2019-08-06 16:06:19 -0700 | [diff] [blame] | 482 | // Returns whether there are any connected Bluetooth audio devices |
| 483 | private boolean isBluetoothAudioOn() { |
| 484 | return mBluetoothHeadset.getConnectedDevices().size() > 0; |
| 485 | } |
| 486 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 487 | /** |
| 488 | * Displays a notification when the phone receives a DisplayInfo record. |
| 489 | */ |
| 490 | private void onDisplayInfo(AsyncResult r) { |
| 491 | // Extract the DisplayInfo String from the message |
| 492 | CdmaDisplayInfoRec displayInfoRec = (CdmaDisplayInfoRec)(r.result); |
| 493 | |
| 494 | if (displayInfoRec != null) { |
| 495 | String displayInfo = displayInfoRec.alpha; |
| 496 | if (DBG) log("onDisplayInfo: displayInfo=" + displayInfo); |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 497 | PhoneDisplayMessage.displayNetworkMessage(mApplication, displayInfo); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 498 | |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 499 | // start a timer that kills the dialog |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 500 | sendEmptyMessageDelayed(INTERNAL_SHOW_MESSAGE_NOTIFICATION_DONE, |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 501 | SHOW_MESSAGE_NOTIFICATION_TIME); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | |
| 505 | /** |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 506 | * Displays a notification when the phone receives a notice that a supplemental |
| 507 | * service has failed. |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 508 | */ |
| 509 | private void onSuppServiceFailed(AsyncResult r) { |
Tyler Gunn | 9dd07d0 | 2014-12-08 10:52:57 -0800 | [diff] [blame] | 510 | String mergeFailedString = ""; |
| 511 | if (r.result == Phone.SuppService.CONFERENCE) { |
| 512 | if (DBG) log("onSuppServiceFailed: displaying merge failure message"); |
| 513 | mergeFailedString = mApplication.getResources().getString( |
| 514 | R.string.incall_error_supp_service_conference); |
| 515 | } else if (r.result == Phone.SuppService.RESUME) { |
Tyler Gunn | 93f9ff5 | 2018-04-11 13:53:04 -0700 | [diff] [blame] | 516 | if (DBG) log("onSuppServiceFailed: displaying resume failure message"); |
Tyler Gunn | 9dd07d0 | 2014-12-08 10:52:57 -0800 | [diff] [blame] | 517 | mergeFailedString = mApplication.getResources().getString( |
Tyler Gunn | 93f9ff5 | 2018-04-11 13:53:04 -0700 | [diff] [blame] | 518 | R.string.incall_error_supp_service_resume); |
Anju Mathapati | 4effeb2 | 2016-01-25 22:25:09 -0800 | [diff] [blame] | 519 | } else if (r.result == Phone.SuppService.HOLD) { |
Tyler Gunn | a7de7d3 | 2017-06-09 16:21:00 -0700 | [diff] [blame] | 520 | if (DBG) log("onSuppServiceFailed: displaying hold failure message"); |
Anju Mathapati | 4effeb2 | 2016-01-25 22:25:09 -0800 | [diff] [blame] | 521 | mergeFailedString = mApplication.getResources().getString( |
| 522 | R.string.incall_error_supp_service_hold); |
Tyler Gunn | a7de7d3 | 2017-06-09 16:21:00 -0700 | [diff] [blame] | 523 | } else if (r.result == Phone.SuppService.TRANSFER) { |
| 524 | if (DBG) log("onSuppServiceFailed: displaying transfer failure message"); |
| 525 | mergeFailedString = mApplication.getResources().getString( |
| 526 | R.string.incall_error_supp_service_transfer); |
| 527 | } else if (r.result == Phone.SuppService.SEPARATE) { |
| 528 | if (DBG) log("onSuppServiceFailed: displaying separate failure message"); |
| 529 | mergeFailedString = mApplication.getResources().getString( |
| 530 | R.string.incall_error_supp_service_separate); |
| 531 | } else if (r.result == Phone.SuppService.SWITCH) { |
| 532 | if (DBG) log("onSuppServiceFailed: displaying switch failure message"); |
Shashidhar Vithalrao Kulkarni | a557d62 | 2018-05-10 13:41:42 +0530 | [diff] [blame] | 533 | mergeFailedString = mApplication.getResources().getString( |
Tyler Gunn | a7de7d3 | 2017-06-09 16:21:00 -0700 | [diff] [blame] | 534 | R.string.incall_error_supp_service_switch); |
| 535 | } else if (r.result == Phone.SuppService.REJECT) { |
| 536 | if (DBG) log("onSuppServiceFailed: displaying reject failure message"); |
Shashidhar Vithalrao Kulkarni | a557d62 | 2018-05-10 13:41:42 +0530 | [diff] [blame] | 537 | mergeFailedString = mApplication.getResources().getString( |
Tyler Gunn | a7de7d3 | 2017-06-09 16:21:00 -0700 | [diff] [blame] | 538 | R.string.incall_error_supp_service_reject); |
Shashidhar Vithalrao Kulkarni | a557d62 | 2018-05-10 13:41:42 +0530 | [diff] [blame] | 539 | } else if (r.result == Phone.SuppService.HANGUP) { |
| 540 | mergeFailedString = mApplication.getResources().getString( |
| 541 | R.string.incall_error_supp_service_hangup); |
| 542 | } else { |
Tyler Gunn | a7de7d3 | 2017-06-09 16:21:00 -0700 | [diff] [blame] | 543 | if (DBG) log("onSuppServiceFailed: unknown failure"); |
| 544 | return; |
Tyler Gunn | 9dd07d0 | 2014-12-08 10:52:57 -0800 | [diff] [blame] | 545 | } |
Tyler Gunn | a7de7d3 | 2017-06-09 16:21:00 -0700 | [diff] [blame] | 546 | |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 547 | PhoneDisplayMessage.displayErrorMessage(mApplication, mergeFailedString); |
| 548 | |
| 549 | // start a timer that kills the dialog |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 550 | sendEmptyMessageDelayed(INTERNAL_SHOW_MESSAGE_NOTIFICATION_DONE, |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 551 | SHOW_MESSAGE_NOTIFICATION_TIME); |
| 552 | } |
| 553 | |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 554 | public void updatePhoneStateListeners(boolean isRefresh) { |
Srikanth Chintala | 4baf0b9 | 2017-11-14 15:52:47 +0530 | [diff] [blame] | 555 | updatePhoneStateListeners(isRefresh, UPDATE_TYPE_MWI_CFI, |
| 556 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
| 557 | } |
| 558 | |
| 559 | public void updatePhoneStateListeners(boolean isRefresh, int updateType, int subIdToUpdate) { |
Malcolm Chen | a336e2a | 2019-02-12 18:51:37 -0800 | [diff] [blame] | 560 | List<SubscriptionInfo> subInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame^] | 561 | .getActiveSubscriptionInfoList(mApplication.getOpPackageName(), |
| 562 | null); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 563 | |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 564 | // Sort sub id list based on slot id, so that CFI/MWI notifications will be updated for |
| 565 | // slot 0 first then slot 1. This is needed to ensure that when CFI or MWI is enabled for |
| 566 | // both slots, user always sees icon related to slot 0 on left side followed by that of |
| 567 | // slot 1. |
| 568 | List<Integer> subIdList = new ArrayList<Integer>(mPhoneStateListeners.keySet()); |
| 569 | Collections.sort(subIdList, new Comparator<Integer>() { |
| 570 | public int compare(Integer sub1, Integer sub2) { |
| 571 | int slotId1 = SubscriptionController.getInstance().getSlotIndex(sub1); |
| 572 | int slotId2 = SubscriptionController.getInstance().getSlotIndex(sub2); |
| 573 | return slotId1 > slotId2 ? 0 : -1; |
| 574 | } |
| 575 | }); |
| 576 | |
| 577 | for (int subIdCounter = (subIdList.size() - 1); subIdCounter >= 0; subIdCounter--) { |
| 578 | int subId = subIdList.get(subIdCounter); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 579 | if (subInfos == null || !containsSubId(subInfos, subId)) { |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 580 | Log.d(LOG_TAG, "updatePhoneStateListeners: Hide the outstanding notifications."); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 581 | // Hide the outstanding notifications. |
| 582 | mApplication.notificationMgr.updateMwi(subId, false); |
| 583 | mApplication.notificationMgr.updateCfi(subId, false); |
| 584 | |
| 585 | // Listening to LISTEN_NONE removes the listener. |
| 586 | mTelephonyManager.listen( |
| 587 | mPhoneStateListeners.get(subId), PhoneStateListener.LISTEN_NONE); |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 588 | mPhoneStateListeners.remove(subId); |
| 589 | } else { |
| 590 | Log.d(LOG_TAG, "updatePhoneStateListeners: update CF notifications."); |
| 591 | |
| 592 | if (mCFIStatus.containsKey(subId)) { |
Srikanth Chintala | 4baf0b9 | 2017-11-14 15:52:47 +0530 | [diff] [blame] | 593 | if ((updateType == UPDATE_TYPE_CFI) && (subId == subIdToUpdate)) { |
| 594 | mApplication.notificationMgr.updateCfi(subId, mCFIStatus.get(subId), |
| 595 | isRefresh); |
| 596 | } else { |
| 597 | mApplication.notificationMgr.updateCfi(subId, mCFIStatus.get(subId), true); |
| 598 | } |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 599 | } |
| 600 | if (mMWIStatus.containsKey(subId)) { |
Srikanth Chintala | 4baf0b9 | 2017-11-14 15:52:47 +0530 | [diff] [blame] | 601 | if ((updateType == UPDATE_TYPE_MWI) && (subId == subIdToUpdate)) { |
| 602 | mApplication.notificationMgr.updateMwi(subId, mMWIStatus.get(subId), |
| 603 | isRefresh); |
| 604 | } else { |
| 605 | mApplication.notificationMgr.updateMwi(subId, mMWIStatus.get(subId), true); |
| 606 | } |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 607 | } |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
| 611 | if (subInfos == null) { |
| 612 | return; |
| 613 | } |
| 614 | |
| 615 | // Register new phone listeners for active subscriptions. |
| 616 | for (int i = 0; i < subInfos.size(); i++) { |
| 617 | int subId = subInfos.get(i).getSubscriptionId(); |
| 618 | if (!mPhoneStateListeners.containsKey(subId)) { |
chen xu | 0694647 | 2019-03-20 14:55:59 -0700 | [diff] [blame] | 619 | CallNotifierPhoneStateListener listener = new CallNotifierPhoneStateListener(); |
| 620 | mTelephonyManager.createForSubscriptionId(subId).listen(listener, |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 621 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
| 622 | | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR); |
| 623 | mPhoneStateListeners.put(subId, listener); |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | /** |
| 629 | * @return {@code true} if the list contains SubscriptionInfo with the given subscription id. |
| 630 | */ |
| 631 | private boolean containsSubId(List<SubscriptionInfo> subInfos, int subId) { |
| 632 | if (subInfos == null) { |
| 633 | return false; |
| 634 | } |
| 635 | |
| 636 | for (int i = 0; i < subInfos.size(); i++) { |
| 637 | if (subInfos.get(i).getSubscriptionId() == subId) { |
| 638 | return true; |
| 639 | } |
| 640 | } |
| 641 | return false; |
| 642 | } |
| 643 | |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 644 | /** |
Pavel Zhamaitsiak | 82256c0 | 2014-12-10 17:11:40 -0800 | [diff] [blame] | 645 | * Displays a notification when the phone receives a notice that TTY mode |
| 646 | * has changed on remote end. |
| 647 | */ |
| 648 | private void onTtyModeReceived(AsyncResult r) { |
| 649 | if (DBG) log("TtyModeReceived: displaying notification message"); |
| 650 | |
| 651 | int resId = 0; |
| 652 | switch (((Integer)r.result).intValue()) { |
| 653 | case TelecomManager.TTY_MODE_FULL: |
| 654 | resId = com.android.internal.R.string.peerTtyModeFull; |
| 655 | break; |
| 656 | case TelecomManager.TTY_MODE_HCO: |
| 657 | resId = com.android.internal.R.string.peerTtyModeHco; |
| 658 | break; |
| 659 | case TelecomManager.TTY_MODE_VCO: |
| 660 | resId = com.android.internal.R.string.peerTtyModeVco; |
| 661 | break; |
| 662 | case TelecomManager.TTY_MODE_OFF: |
| 663 | resId = com.android.internal.R.string.peerTtyModeOff; |
| 664 | break; |
| 665 | default: |
| 666 | Log.e(LOG_TAG, "Unsupported TTY mode: " + r.result); |
| 667 | break; |
| 668 | } |
| 669 | if (resId != 0) { |
| 670 | PhoneDisplayMessage.displayNetworkMessage(mApplication, |
| 671 | mApplication.getResources().getString(resId)); |
| 672 | |
| 673 | // start a timer that kills the dialog |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 674 | sendEmptyMessageDelayed(INTERNAL_SHOW_MESSAGE_NOTIFICATION_DONE, |
Pavel Zhamaitsiak | 82256c0 | 2014-12-10 17:11:40 -0800 | [diff] [blame] | 675 | SHOW_MESSAGE_NOTIFICATION_TIME); |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 680 | * Helper class to play SignalInfo tones using the ToneGenerator. |
| 681 | * |
| 682 | * To use, just instantiate a new SignalInfoTonePlayer |
| 683 | * (passing in the ToneID constant for the tone you want) |
| 684 | * and start() it. |
| 685 | */ |
| 686 | private class SignalInfoTonePlayer extends Thread { |
| 687 | private int mToneId; |
| 688 | |
| 689 | SignalInfoTonePlayer(int toneId) { |
| 690 | super(); |
| 691 | mToneId = toneId; |
| 692 | } |
| 693 | |
| 694 | @Override |
| 695 | public void run() { |
| 696 | log("SignalInfoTonePlayer.run(toneId = " + mToneId + ")..."); |
Yorke Lee | 65cbd16 | 2014-10-08 11:26:02 -0700 | [diff] [blame] | 697 | createSignalInfoToneGenerator(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 698 | if (mSignalInfoToneGenerator != null) { |
| 699 | //First stop any ongoing SignalInfo tone |
| 700 | mSignalInfoToneGenerator.stopTone(); |
| 701 | |
| 702 | //Start playing the new tone if its a valid tone |
| 703 | mSignalInfoToneGenerator.startTone(mToneId); |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | /** |
| 709 | * Plays a tone when the phone receives a SignalInfo record. |
| 710 | */ |
| 711 | private void onSignalInfo(AsyncResult r) { |
| 712 | // Signal Info are totally ignored on non-voice-capable devices. |
| 713 | if (!PhoneGlobals.sVoiceCapable) { |
| 714 | Log.w(LOG_TAG, "Got onSignalInfo() on non-voice-capable device! Ignoring..."); |
| 715 | return; |
| 716 | } |
| 717 | |
| 718 | if (PhoneUtils.isRealIncomingCall(mCM.getFirstActiveRingingCall().getState())) { |
| 719 | // Do not start any new SignalInfo tone when Call state is INCOMING |
| 720 | // and stop any previous SignalInfo tone which is being played |
| 721 | stopSignalInfoTone(); |
| 722 | } else { |
| 723 | // Extract the SignalInfo String from the message |
| 724 | CdmaSignalInfoRec signalInfoRec = (CdmaSignalInfoRec)(r.result); |
| 725 | // Only proceed if a Signal info is present. |
| 726 | if (signalInfoRec != null) { |
| 727 | boolean isPresent = signalInfoRec.isPresent; |
| 728 | if (DBG) log("onSignalInfo: isPresent=" + isPresent); |
| 729 | if (isPresent) {// if tone is valid |
| 730 | int uSignalType = signalInfoRec.signalType; |
| 731 | int uAlertPitch = signalInfoRec.alertPitch; |
| 732 | int uSignal = signalInfoRec.signal; |
| 733 | |
| 734 | if (DBG) log("onSignalInfo: uSignalType=" + uSignalType + ", uAlertPitch=" + |
| 735 | uAlertPitch + ", uSignal=" + uSignal); |
| 736 | //Map the Signal to a ToneGenerator ToneID only if Signal info is present |
| 737 | int toneID = SignalToneUtil.getAudioToneFromSignalInfo |
| 738 | (uSignalType, uAlertPitch, uSignal); |
| 739 | |
| 740 | //Create the SignalInfo tone player and pass the ToneID |
| 741 | new SignalInfoTonePlayer(toneID).start(); |
| 742 | } |
| 743 | } |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | /** |
| 748 | * Stops a SignalInfo tone in the following condition |
| 749 | * 1 - On receiving a New Ringing Call |
| 750 | * 2 - On disconnecting a call |
| 751 | * 3 - On answering a Call Waiting Call |
| 752 | */ |
| 753 | /* package */ void stopSignalInfoTone() { |
| 754 | if (DBG) log("stopSignalInfoTone: Stopping SignalInfo tone player"); |
| 755 | new SignalInfoTonePlayer(ToneGenerator.TONE_CDMA_SIGNAL_OFF).start(); |
| 756 | } |
| 757 | |
Santos Cordon | 5c04672 | 2014-09-18 15:41:13 -0700 | [diff] [blame] | 758 | private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener = |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 759 | new BluetoothProfile.ServiceListener() { |
| 760 | public void onServiceConnected(int profile, BluetoothProfile proxy) { |
| 761 | mBluetoothHeadset = (BluetoothHeadset) proxy; |
| 762 | if (VDBG) log("- Got BluetoothHeadset: " + mBluetoothHeadset); |
| 763 | } |
| 764 | |
| 765 | public void onServiceDisconnected(int profile) { |
| 766 | mBluetoothHeadset = null; |
| 767 | } |
| 768 | }; |
| 769 | |
| 770 | private class CallNotifierPhoneStateListener extends PhoneStateListener { |
chen xu | 0694647 | 2019-03-20 14:55:59 -0700 | [diff] [blame] | 771 | public CallNotifierPhoneStateListener() { |
| 772 | super(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 773 | } |
| 774 | |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 775 | @Override |
| 776 | public void onMessageWaitingIndicatorChanged(boolean visible) { |
| 777 | if (VDBG) log("onMessageWaitingIndicatorChanged(): " + this.mSubId + " " + visible); |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 778 | mMWIStatus.put(this.mSubId, visible); |
Srikanth Chintala | 4baf0b9 | 2017-11-14 15:52:47 +0530 | [diff] [blame] | 779 | updatePhoneStateListeners(false, UPDATE_TYPE_MWI, this.mSubId); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | @Override |
| 783 | public void onCallForwardingIndicatorChanged(boolean visible) { |
Tyler Gunn | 17bffd0 | 2017-09-19 11:40:12 -0700 | [diff] [blame] | 784 | Log.i(LOG_TAG, "onCallForwardingIndicatorChanged(): subId=" + this.mSubId |
| 785 | + ", visible=" + (visible ? "Y" : "N")); |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 786 | mCFIStatus.put(this.mSubId, visible); |
Srikanth Chintala | 4baf0b9 | 2017-11-14 15:52:47 +0530 | [diff] [blame] | 787 | updatePhoneStateListeners(false, UPDATE_TYPE_CFI, this.mSubId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 788 | } |
| 789 | }; |
| 790 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 791 | private void log(String msg) { |
| 792 | Log.d(LOG_TAG, msg); |
| 793 | } |
| 794 | } |