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 | /** |
| 256 | * Resets the audio mode and speaker state when a call ends. |
| 257 | */ |
| 258 | private void resetAudioStateAfterDisconnect() { |
| 259 | if (VDBG) log("resetAudioStateAfterDisconnect()..."); |
| 260 | |
| 261 | if (mBluetoothHeadset != null) { |
| 262 | mBluetoothHeadset.disconnectAudio(); |
| 263 | } |
| 264 | |
| 265 | // call turnOnSpeaker() with state=false and store=true even if speaker |
| 266 | // is already off to reset user requested speaker state. |
| 267 | PhoneUtils.turnOnSpeaker(mApplication, false, true); |
| 268 | |
| 269 | PhoneUtils.setAudioMode(mCM); |
| 270 | } |
| 271 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 272 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 273 | * Helper class to play tones through the earpiece (or speaker / BT) |
| 274 | * during a call, using the ToneGenerator. |
| 275 | * |
| 276 | * To use, just instantiate a new InCallTonePlayer |
| 277 | * (passing in the TONE_* constant for the tone you want) |
| 278 | * and start() it. |
| 279 | * |
| 280 | * When we're done playing the tone, if the phone is idle at that |
| 281 | * point, we'll reset the audio routing and speaker state. |
| 282 | * (That means that for tones that get played *after* a call |
| 283 | * disconnects, like "busy" or "congestion" or "call ended", you |
| 284 | * should NOT call resetAudioStateAfterDisconnect() yourself. |
| 285 | * Instead, just start the InCallTonePlayer, which will automatically |
| 286 | * defer the resetAudioStateAfterDisconnect() call until the tone |
| 287 | * finishes playing.) |
| 288 | */ |
| 289 | private class InCallTonePlayer extends Thread { |
| 290 | private int mToneId; |
| 291 | private int mState; |
| 292 | // The possible tones we can play. |
| 293 | public static final int TONE_NONE = 0; |
| 294 | public static final int TONE_CALL_WAITING = 1; |
| 295 | public static final int TONE_BUSY = 2; |
| 296 | public static final int TONE_CONGESTION = 3; |
| 297 | public static final int TONE_CALL_ENDED = 4; |
| 298 | public static final int TONE_VOICE_PRIVACY = 5; |
| 299 | public static final int TONE_REORDER = 6; |
| 300 | public static final int TONE_INTERCEPT = 7; |
| 301 | public static final int TONE_CDMA_DROP = 8; |
| 302 | public static final int TONE_OUT_OF_SERVICE = 9; |
| 303 | public static final int TONE_REDIAL = 10; |
| 304 | public static final int TONE_OTA_CALL_END = 11; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 305 | public static final int TONE_UNOBTAINABLE_NUMBER = 13; |
| 306 | |
| 307 | // The tone volume relative to other sounds in the stream |
| 308 | static final int TONE_RELATIVE_VOLUME_EMERGENCY = 100; |
| 309 | static final int TONE_RELATIVE_VOLUME_HIPRI = 80; |
| 310 | static final int TONE_RELATIVE_VOLUME_LOPRI = 50; |
| 311 | |
| 312 | // Buffer time (in msec) to add on to tone timeout value. |
| 313 | // Needed mainly when the timeout value for a tone is the |
| 314 | // exact duration of the tone itself. |
| 315 | static final int TONE_TIMEOUT_BUFFER = 20; |
| 316 | |
| 317 | // The tone state |
| 318 | static final int TONE_OFF = 0; |
| 319 | static final int TONE_ON = 1; |
| 320 | static final int TONE_STOPPED = 2; |
| 321 | |
| 322 | InCallTonePlayer(int toneId) { |
| 323 | super(); |
| 324 | mToneId = toneId; |
| 325 | mState = TONE_OFF; |
| 326 | } |
| 327 | |
| 328 | @Override |
| 329 | public void run() { |
| 330 | log("InCallTonePlayer.run(toneId = " + mToneId + ")..."); |
| 331 | |
| 332 | int toneType = 0; // passed to ToneGenerator.startTone() |
| 333 | int toneVolume; // passed to the ToneGenerator constructor |
| 334 | int toneLengthMillis; |
| 335 | int phoneType = mCM.getFgPhone().getPhoneType(); |
| 336 | |
| 337 | switch (mToneId) { |
| 338 | case TONE_CALL_WAITING: |
| 339 | toneType = ToneGenerator.TONE_SUP_CALL_WAITING; |
| 340 | toneVolume = TONE_RELATIVE_VOLUME_HIPRI; |
| 341 | // Call waiting tone is stopped by stopTone() method |
| 342 | toneLengthMillis = Integer.MAX_VALUE - TONE_TIMEOUT_BUFFER; |
| 343 | break; |
| 344 | case TONE_BUSY: |
| 345 | if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { |
| 346 | toneType = ToneGenerator.TONE_CDMA_NETWORK_BUSY_ONE_SHOT; |
| 347 | toneVolume = TONE_RELATIVE_VOLUME_LOPRI; |
| 348 | toneLengthMillis = 1000; |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 349 | } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM |
| 350 | || phoneType == PhoneConstants.PHONE_TYPE_SIP |
Etan Cohen | 0ca1c80 | 2014-07-07 15:35:48 -0700 | [diff] [blame] | 351 | || phoneType == PhoneConstants.PHONE_TYPE_IMS |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 352 | || phoneType == PhoneConstants.PHONE_TYPE_THIRD_PARTY) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 353 | toneType = ToneGenerator.TONE_SUP_BUSY; |
| 354 | toneVolume = TONE_RELATIVE_VOLUME_HIPRI; |
| 355 | toneLengthMillis = 4000; |
| 356 | } else { |
| 357 | throw new IllegalStateException("Unexpected phone type: " + phoneType); |
| 358 | } |
| 359 | break; |
| 360 | case TONE_CONGESTION: |
| 361 | toneType = ToneGenerator.TONE_SUP_CONGESTION; |
| 362 | toneVolume = TONE_RELATIVE_VOLUME_HIPRI; |
| 363 | toneLengthMillis = 4000; |
| 364 | break; |
| 365 | |
| 366 | case TONE_CALL_ENDED: |
| 367 | toneType = ToneGenerator.TONE_PROP_PROMPT; |
| 368 | toneVolume = TONE_RELATIVE_VOLUME_HIPRI; |
| 369 | toneLengthMillis = 200; |
| 370 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 371 | case TONE_VOICE_PRIVACY: |
| 372 | toneType = ToneGenerator.TONE_CDMA_ALERT_NETWORK_LITE; |
| 373 | toneVolume = TONE_RELATIVE_VOLUME_HIPRI; |
| 374 | toneLengthMillis = 5000; |
| 375 | break; |
| 376 | case TONE_REORDER: |
| 377 | toneType = ToneGenerator.TONE_CDMA_REORDER; |
| 378 | toneVolume = TONE_RELATIVE_VOLUME_HIPRI; |
| 379 | toneLengthMillis = 4000; |
| 380 | break; |
| 381 | case TONE_INTERCEPT: |
| 382 | toneType = ToneGenerator.TONE_CDMA_ABBR_INTERCEPT; |
| 383 | toneVolume = TONE_RELATIVE_VOLUME_LOPRI; |
| 384 | toneLengthMillis = 500; |
| 385 | break; |
| 386 | case TONE_CDMA_DROP: |
| 387 | case TONE_OUT_OF_SERVICE: |
| 388 | toneType = ToneGenerator.TONE_CDMA_CALLDROP_LITE; |
| 389 | toneVolume = TONE_RELATIVE_VOLUME_LOPRI; |
| 390 | toneLengthMillis = 375; |
| 391 | break; |
| 392 | case TONE_REDIAL: |
| 393 | toneType = ToneGenerator.TONE_CDMA_ALERT_AUTOREDIAL_LITE; |
| 394 | toneVolume = TONE_RELATIVE_VOLUME_LOPRI; |
| 395 | toneLengthMillis = 5000; |
| 396 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 397 | case TONE_UNOBTAINABLE_NUMBER: |
| 398 | toneType = ToneGenerator.TONE_SUP_ERROR; |
| 399 | toneVolume = TONE_RELATIVE_VOLUME_HIPRI; |
| 400 | toneLengthMillis = 4000; |
| 401 | break; |
| 402 | default: |
| 403 | throw new IllegalArgumentException("Bad toneId: " + mToneId); |
| 404 | } |
| 405 | |
| 406 | // If the mToneGenerator creation fails, just continue without it. It is |
| 407 | // a local audio signal, and is not as important. |
| 408 | ToneGenerator toneGenerator; |
| 409 | try { |
| 410 | int stream; |
| 411 | if (mBluetoothHeadset != null) { |
| 412 | stream = mBluetoothHeadset.isAudioOn() ? AudioManager.STREAM_BLUETOOTH_SCO: |
| 413 | AudioManager.STREAM_VOICE_CALL; |
| 414 | } else { |
| 415 | stream = AudioManager.STREAM_VOICE_CALL; |
| 416 | } |
| 417 | toneGenerator = new ToneGenerator(stream, toneVolume); |
| 418 | // if (DBG) log("- created toneGenerator: " + toneGenerator); |
| 419 | } catch (RuntimeException e) { |
| 420 | Log.w(LOG_TAG, |
| 421 | "InCallTonePlayer: Exception caught while creating ToneGenerator: " + e); |
| 422 | toneGenerator = null; |
| 423 | } |
| 424 | |
| 425 | // Using the ToneGenerator (with the CALL_WAITING / BUSY / |
| 426 | // CONGESTION tones at least), the ToneGenerator itself knows |
| 427 | // the right pattern of tones to play; we do NOT need to |
| 428 | // manually start/stop each individual tone, or manually |
| 429 | // insert the correct delay between tones. (We just start it |
| 430 | // and let it run for however long we want the tone pattern to |
| 431 | // continue.) |
| 432 | // |
| 433 | // TODO: When we stop the ToneGenerator in the middle of a |
| 434 | // "tone pattern", it sounds bad if we cut if off while the |
| 435 | // tone is actually playing. Consider adding API to the |
| 436 | // ToneGenerator to say "stop at the next silent part of the |
| 437 | // pattern", or simply "play the pattern N times and then |
| 438 | // stop." |
| 439 | boolean needToStopTone = true; |
| 440 | boolean okToPlayTone = false; |
| 441 | |
| 442 | if (toneGenerator != null) { |
| 443 | int ringerMode = mAudioManager.getRingerMode(); |
| 444 | if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { |
| 445 | if (toneType == ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD) { |
| 446 | if ((ringerMode != AudioManager.RINGER_MODE_SILENT) && |
| 447 | (ringerMode != AudioManager.RINGER_MODE_VIBRATE)) { |
| 448 | if (DBG) log("- InCallTonePlayer: start playing call tone=" + toneType); |
| 449 | okToPlayTone = true; |
| 450 | needToStopTone = false; |
| 451 | } |
| 452 | } else if ((toneType == ToneGenerator.TONE_CDMA_NETWORK_BUSY_ONE_SHOT) || |
| 453 | (toneType == ToneGenerator.TONE_CDMA_REORDER) || |
| 454 | (toneType == ToneGenerator.TONE_CDMA_ABBR_REORDER) || |
| 455 | (toneType == ToneGenerator.TONE_CDMA_ABBR_INTERCEPT) || |
| 456 | (toneType == ToneGenerator.TONE_CDMA_CALLDROP_LITE)) { |
| 457 | if (ringerMode != AudioManager.RINGER_MODE_SILENT) { |
| 458 | if (DBG) log("InCallTonePlayer:playing call fail tone:" + toneType); |
| 459 | okToPlayTone = true; |
| 460 | needToStopTone = false; |
| 461 | } |
| 462 | } else if ((toneType == ToneGenerator.TONE_CDMA_ALERT_AUTOREDIAL_LITE) || |
| 463 | (toneType == ToneGenerator.TONE_CDMA_ALERT_NETWORK_LITE)) { |
| 464 | if ((ringerMode != AudioManager.RINGER_MODE_SILENT) && |
| 465 | (ringerMode != AudioManager.RINGER_MODE_VIBRATE)) { |
| 466 | if (DBG) log("InCallTonePlayer:playing tone for toneType=" + toneType); |
| 467 | okToPlayTone = true; |
| 468 | needToStopTone = false; |
| 469 | } |
| 470 | } else { // For the rest of the tones, always OK to play. |
| 471 | okToPlayTone = true; |
| 472 | } |
| 473 | } else { // Not "CDMA" |
| 474 | okToPlayTone = true; |
| 475 | } |
| 476 | |
| 477 | synchronized (this) { |
| 478 | if (okToPlayTone && mState != TONE_STOPPED) { |
| 479 | mState = TONE_ON; |
| 480 | toneGenerator.startTone(toneType); |
| 481 | try { |
| 482 | wait(toneLengthMillis + TONE_TIMEOUT_BUFFER); |
| 483 | } catch (InterruptedException e) { |
| 484 | Log.w(LOG_TAG, |
| 485 | "InCallTonePlayer stopped: " + e); |
| 486 | } |
| 487 | if (needToStopTone) { |
| 488 | toneGenerator.stopTone(); |
| 489 | } |
| 490 | } |
| 491 | // if (DBG) log("- InCallTonePlayer: done playing."); |
| 492 | toneGenerator.release(); |
| 493 | mState = TONE_OFF; |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | // Finally, do the same cleanup we otherwise would have done |
| 498 | // in onDisconnect(). |
| 499 | // |
| 500 | // (But watch out: do NOT do this if the phone is in use, |
| 501 | // since some of our tones get played *during* a call (like |
| 502 | // CALL_WAITING) and we definitely *don't* |
| 503 | // want to reset the audio mode / speaker / bluetooth after |
| 504 | // playing those! |
| 505 | // This call is really here for use with tones that get played |
| 506 | // *after* a call disconnects, like "busy" or "congestion" or |
| 507 | // "call ended", where the phone has already become idle but |
| 508 | // we need to defer the resetAudioStateAfterDisconnect() call |
| 509 | // till the tone finishes playing.) |
| 510 | if (mCM.getState() == PhoneConstants.State.IDLE) { |
| 511 | resetAudioStateAfterDisconnect(); |
| 512 | } |
| 513 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | /** |
| 517 | * Displays a notification when the phone receives a DisplayInfo record. |
| 518 | */ |
| 519 | private void onDisplayInfo(AsyncResult r) { |
| 520 | // Extract the DisplayInfo String from the message |
| 521 | CdmaDisplayInfoRec displayInfoRec = (CdmaDisplayInfoRec)(r.result); |
| 522 | |
| 523 | if (displayInfoRec != null) { |
| 524 | String displayInfo = displayInfoRec.alpha; |
| 525 | if (DBG) log("onDisplayInfo: displayInfo=" + displayInfo); |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 526 | PhoneDisplayMessage.displayNetworkMessage(mApplication, displayInfo); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 527 | |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 528 | // start a timer that kills the dialog |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 529 | sendEmptyMessageDelayed(INTERNAL_SHOW_MESSAGE_NOTIFICATION_DONE, |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 530 | SHOW_MESSAGE_NOTIFICATION_TIME); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | |
| 534 | /** |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 535 | * Displays a notification when the phone receives a notice that a supplemental |
| 536 | * service has failed. |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 537 | */ |
| 538 | private void onSuppServiceFailed(AsyncResult r) { |
Tyler Gunn | 9dd07d0 | 2014-12-08 10:52:57 -0800 | [diff] [blame] | 539 | String mergeFailedString = ""; |
| 540 | if (r.result == Phone.SuppService.CONFERENCE) { |
| 541 | if (DBG) log("onSuppServiceFailed: displaying merge failure message"); |
| 542 | mergeFailedString = mApplication.getResources().getString( |
| 543 | R.string.incall_error_supp_service_conference); |
| 544 | } else if (r.result == Phone.SuppService.RESUME) { |
Tyler Gunn | 93f9ff5 | 2018-04-11 13:53:04 -0700 | [diff] [blame] | 545 | if (DBG) log("onSuppServiceFailed: displaying resume failure message"); |
Tyler Gunn | 9dd07d0 | 2014-12-08 10:52:57 -0800 | [diff] [blame] | 546 | mergeFailedString = mApplication.getResources().getString( |
Tyler Gunn | 93f9ff5 | 2018-04-11 13:53:04 -0700 | [diff] [blame] | 547 | R.string.incall_error_supp_service_resume); |
Anju Mathapati | 4effeb2 | 2016-01-25 22:25:09 -0800 | [diff] [blame] | 548 | } else if (r.result == Phone.SuppService.HOLD) { |
Tyler Gunn | a7de7d3 | 2017-06-09 16:21:00 -0700 | [diff] [blame] | 549 | if (DBG) log("onSuppServiceFailed: displaying hold failure message"); |
Anju Mathapati | 4effeb2 | 2016-01-25 22:25:09 -0800 | [diff] [blame] | 550 | mergeFailedString = mApplication.getResources().getString( |
| 551 | R.string.incall_error_supp_service_hold); |
Tyler Gunn | a7de7d3 | 2017-06-09 16:21:00 -0700 | [diff] [blame] | 552 | } else if (r.result == Phone.SuppService.TRANSFER) { |
| 553 | if (DBG) log("onSuppServiceFailed: displaying transfer failure message"); |
| 554 | mergeFailedString = mApplication.getResources().getString( |
| 555 | R.string.incall_error_supp_service_transfer); |
| 556 | } else if (r.result == Phone.SuppService.SEPARATE) { |
| 557 | if (DBG) log("onSuppServiceFailed: displaying separate failure message"); |
| 558 | mergeFailedString = mApplication.getResources().getString( |
| 559 | R.string.incall_error_supp_service_separate); |
| 560 | } else if (r.result == Phone.SuppService.SWITCH) { |
| 561 | if (DBG) log("onSuppServiceFailed: displaying switch failure message"); |
Shashidhar Vithalrao Kulkarni | a557d62 | 2018-05-10 13:41:42 +0530 | [diff] [blame] | 562 | mergeFailedString = mApplication.getResources().getString( |
Tyler Gunn | a7de7d3 | 2017-06-09 16:21:00 -0700 | [diff] [blame] | 563 | R.string.incall_error_supp_service_switch); |
| 564 | } else if (r.result == Phone.SuppService.REJECT) { |
| 565 | if (DBG) log("onSuppServiceFailed: displaying reject failure message"); |
Shashidhar Vithalrao Kulkarni | a557d62 | 2018-05-10 13:41:42 +0530 | [diff] [blame] | 566 | mergeFailedString = mApplication.getResources().getString( |
Tyler Gunn | a7de7d3 | 2017-06-09 16:21:00 -0700 | [diff] [blame] | 567 | R.string.incall_error_supp_service_reject); |
Shashidhar Vithalrao Kulkarni | a557d62 | 2018-05-10 13:41:42 +0530 | [diff] [blame] | 568 | } else if (r.result == Phone.SuppService.HANGUP) { |
| 569 | mergeFailedString = mApplication.getResources().getString( |
| 570 | R.string.incall_error_supp_service_hangup); |
| 571 | } else { |
Tyler Gunn | a7de7d3 | 2017-06-09 16:21:00 -0700 | [diff] [blame] | 572 | if (DBG) log("onSuppServiceFailed: unknown failure"); |
| 573 | return; |
Tyler Gunn | 9dd07d0 | 2014-12-08 10:52:57 -0800 | [diff] [blame] | 574 | } |
Tyler Gunn | a7de7d3 | 2017-06-09 16:21:00 -0700 | [diff] [blame] | 575 | |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 576 | PhoneDisplayMessage.displayErrorMessage(mApplication, mergeFailedString); |
| 577 | |
| 578 | // start a timer that kills the dialog |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 579 | sendEmptyMessageDelayed(INTERNAL_SHOW_MESSAGE_NOTIFICATION_DONE, |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 580 | SHOW_MESSAGE_NOTIFICATION_TIME); |
| 581 | } |
| 582 | |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 583 | public void updatePhoneStateListeners(boolean isRefresh) { |
Srikanth Chintala | 4baf0b9 | 2017-11-14 15:52:47 +0530 | [diff] [blame] | 584 | updatePhoneStateListeners(isRefresh, UPDATE_TYPE_MWI_CFI, |
| 585 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
| 586 | } |
| 587 | |
| 588 | public void updatePhoneStateListeners(boolean isRefresh, int updateType, int subIdToUpdate) { |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 589 | List<SubscriptionInfo> subInfos = mSubscriptionManager.getActiveSubscriptionInfoList(); |
| 590 | |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 591 | // Sort sub id list based on slot id, so that CFI/MWI notifications will be updated for |
| 592 | // slot 0 first then slot 1. This is needed to ensure that when CFI or MWI is enabled for |
| 593 | // both slots, user always sees icon related to slot 0 on left side followed by that of |
| 594 | // slot 1. |
| 595 | List<Integer> subIdList = new ArrayList<Integer>(mPhoneStateListeners.keySet()); |
| 596 | Collections.sort(subIdList, new Comparator<Integer>() { |
| 597 | public int compare(Integer sub1, Integer sub2) { |
| 598 | int slotId1 = SubscriptionController.getInstance().getSlotIndex(sub1); |
| 599 | int slotId2 = SubscriptionController.getInstance().getSlotIndex(sub2); |
| 600 | return slotId1 > slotId2 ? 0 : -1; |
| 601 | } |
| 602 | }); |
| 603 | |
| 604 | for (int subIdCounter = (subIdList.size() - 1); subIdCounter >= 0; subIdCounter--) { |
| 605 | int subId = subIdList.get(subIdCounter); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 606 | if (subInfos == null || !containsSubId(subInfos, subId)) { |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 607 | Log.d(LOG_TAG, "updatePhoneStateListeners: Hide the outstanding notifications."); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 608 | // Hide the outstanding notifications. |
| 609 | mApplication.notificationMgr.updateMwi(subId, false); |
| 610 | mApplication.notificationMgr.updateCfi(subId, false); |
| 611 | |
| 612 | // Listening to LISTEN_NONE removes the listener. |
| 613 | mTelephonyManager.listen( |
| 614 | mPhoneStateListeners.get(subId), PhoneStateListener.LISTEN_NONE); |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 615 | mPhoneStateListeners.remove(subId); |
| 616 | } else { |
| 617 | Log.d(LOG_TAG, "updatePhoneStateListeners: update CF notifications."); |
| 618 | |
| 619 | if (mCFIStatus.containsKey(subId)) { |
Srikanth Chintala | 4baf0b9 | 2017-11-14 15:52:47 +0530 | [diff] [blame] | 620 | if ((updateType == UPDATE_TYPE_CFI) && (subId == subIdToUpdate)) { |
| 621 | mApplication.notificationMgr.updateCfi(subId, mCFIStatus.get(subId), |
| 622 | isRefresh); |
| 623 | } else { |
| 624 | mApplication.notificationMgr.updateCfi(subId, mCFIStatus.get(subId), true); |
| 625 | } |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 626 | } |
| 627 | if (mMWIStatus.containsKey(subId)) { |
Srikanth Chintala | 4baf0b9 | 2017-11-14 15:52:47 +0530 | [diff] [blame] | 628 | if ((updateType == UPDATE_TYPE_MWI) && (subId == subIdToUpdate)) { |
| 629 | mApplication.notificationMgr.updateMwi(subId, mMWIStatus.get(subId), |
| 630 | isRefresh); |
| 631 | } else { |
| 632 | mApplication.notificationMgr.updateMwi(subId, mMWIStatus.get(subId), true); |
| 633 | } |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 634 | } |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | |
| 638 | if (subInfos == null) { |
| 639 | return; |
| 640 | } |
| 641 | |
| 642 | // Register new phone listeners for active subscriptions. |
| 643 | for (int i = 0; i < subInfos.size(); i++) { |
| 644 | int subId = subInfos.get(i).getSubscriptionId(); |
| 645 | if (!mPhoneStateListeners.containsKey(subId)) { |
| 646 | CallNotifierPhoneStateListener listener = new CallNotifierPhoneStateListener(subId); |
| 647 | mTelephonyManager.listen(listener, |
| 648 | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
| 649 | | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR); |
| 650 | mPhoneStateListeners.put(subId, listener); |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | /** |
| 656 | * @return {@code true} if the list contains SubscriptionInfo with the given subscription id. |
| 657 | */ |
| 658 | private boolean containsSubId(List<SubscriptionInfo> subInfos, int subId) { |
| 659 | if (subInfos == null) { |
| 660 | return false; |
| 661 | } |
| 662 | |
| 663 | for (int i = 0; i < subInfos.size(); i++) { |
| 664 | if (subInfos.get(i).getSubscriptionId() == subId) { |
| 665 | return true; |
| 666 | } |
| 667 | } |
| 668 | return false; |
| 669 | } |
| 670 | |
Anthony Lee | e946853 | 2014-11-15 15:21:00 -0800 | [diff] [blame] | 671 | /** |
Pavel Zhamaitsiak | 82256c0 | 2014-12-10 17:11:40 -0800 | [diff] [blame] | 672 | * Displays a notification when the phone receives a notice that TTY mode |
| 673 | * has changed on remote end. |
| 674 | */ |
| 675 | private void onTtyModeReceived(AsyncResult r) { |
| 676 | if (DBG) log("TtyModeReceived: displaying notification message"); |
| 677 | |
| 678 | int resId = 0; |
| 679 | switch (((Integer)r.result).intValue()) { |
| 680 | case TelecomManager.TTY_MODE_FULL: |
| 681 | resId = com.android.internal.R.string.peerTtyModeFull; |
| 682 | break; |
| 683 | case TelecomManager.TTY_MODE_HCO: |
| 684 | resId = com.android.internal.R.string.peerTtyModeHco; |
| 685 | break; |
| 686 | case TelecomManager.TTY_MODE_VCO: |
| 687 | resId = com.android.internal.R.string.peerTtyModeVco; |
| 688 | break; |
| 689 | case TelecomManager.TTY_MODE_OFF: |
| 690 | resId = com.android.internal.R.string.peerTtyModeOff; |
| 691 | break; |
| 692 | default: |
| 693 | Log.e(LOG_TAG, "Unsupported TTY mode: " + r.result); |
| 694 | break; |
| 695 | } |
| 696 | if (resId != 0) { |
| 697 | PhoneDisplayMessage.displayNetworkMessage(mApplication, |
| 698 | mApplication.getResources().getString(resId)); |
| 699 | |
| 700 | // start a timer that kills the dialog |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 701 | sendEmptyMessageDelayed(INTERNAL_SHOW_MESSAGE_NOTIFICATION_DONE, |
Pavel Zhamaitsiak | 82256c0 | 2014-12-10 17:11:40 -0800 | [diff] [blame] | 702 | SHOW_MESSAGE_NOTIFICATION_TIME); |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 707 | * Helper class to play SignalInfo tones using the ToneGenerator. |
| 708 | * |
| 709 | * To use, just instantiate a new SignalInfoTonePlayer |
| 710 | * (passing in the ToneID constant for the tone you want) |
| 711 | * and start() it. |
| 712 | */ |
| 713 | private class SignalInfoTonePlayer extends Thread { |
| 714 | private int mToneId; |
| 715 | |
| 716 | SignalInfoTonePlayer(int toneId) { |
| 717 | super(); |
| 718 | mToneId = toneId; |
| 719 | } |
| 720 | |
| 721 | @Override |
| 722 | public void run() { |
| 723 | log("SignalInfoTonePlayer.run(toneId = " + mToneId + ")..."); |
Yorke Lee | 65cbd16 | 2014-10-08 11:26:02 -0700 | [diff] [blame] | 724 | createSignalInfoToneGenerator(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 725 | if (mSignalInfoToneGenerator != null) { |
| 726 | //First stop any ongoing SignalInfo tone |
| 727 | mSignalInfoToneGenerator.stopTone(); |
| 728 | |
| 729 | //Start playing the new tone if its a valid tone |
| 730 | mSignalInfoToneGenerator.startTone(mToneId); |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | /** |
| 736 | * Plays a tone when the phone receives a SignalInfo record. |
| 737 | */ |
| 738 | private void onSignalInfo(AsyncResult r) { |
| 739 | // Signal Info are totally ignored on non-voice-capable devices. |
| 740 | if (!PhoneGlobals.sVoiceCapable) { |
| 741 | Log.w(LOG_TAG, "Got onSignalInfo() on non-voice-capable device! Ignoring..."); |
| 742 | return; |
| 743 | } |
| 744 | |
| 745 | if (PhoneUtils.isRealIncomingCall(mCM.getFirstActiveRingingCall().getState())) { |
| 746 | // Do not start any new SignalInfo tone when Call state is INCOMING |
| 747 | // and stop any previous SignalInfo tone which is being played |
| 748 | stopSignalInfoTone(); |
| 749 | } else { |
| 750 | // Extract the SignalInfo String from the message |
| 751 | CdmaSignalInfoRec signalInfoRec = (CdmaSignalInfoRec)(r.result); |
| 752 | // Only proceed if a Signal info is present. |
| 753 | if (signalInfoRec != null) { |
| 754 | boolean isPresent = signalInfoRec.isPresent; |
| 755 | if (DBG) log("onSignalInfo: isPresent=" + isPresent); |
| 756 | if (isPresent) {// if tone is valid |
| 757 | int uSignalType = signalInfoRec.signalType; |
| 758 | int uAlertPitch = signalInfoRec.alertPitch; |
| 759 | int uSignal = signalInfoRec.signal; |
| 760 | |
| 761 | if (DBG) log("onSignalInfo: uSignalType=" + uSignalType + ", uAlertPitch=" + |
| 762 | uAlertPitch + ", uSignal=" + uSignal); |
| 763 | //Map the Signal to a ToneGenerator ToneID only if Signal info is present |
| 764 | int toneID = SignalToneUtil.getAudioToneFromSignalInfo |
| 765 | (uSignalType, uAlertPitch, uSignal); |
| 766 | |
| 767 | //Create the SignalInfo tone player and pass the ToneID |
| 768 | new SignalInfoTonePlayer(toneID).start(); |
| 769 | } |
| 770 | } |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | /** |
| 775 | * Stops a SignalInfo tone in the following condition |
| 776 | * 1 - On receiving a New Ringing Call |
| 777 | * 2 - On disconnecting a call |
| 778 | * 3 - On answering a Call Waiting Call |
| 779 | */ |
| 780 | /* package */ void stopSignalInfoTone() { |
| 781 | if (DBG) log("stopSignalInfoTone: Stopping SignalInfo tone player"); |
| 782 | new SignalInfoTonePlayer(ToneGenerator.TONE_CDMA_SIGNAL_OFF).start(); |
| 783 | } |
| 784 | |
Santos Cordon | 5c04672 | 2014-09-18 15:41:13 -0700 | [diff] [blame] | 785 | private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener = |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 786 | new BluetoothProfile.ServiceListener() { |
| 787 | public void onServiceConnected(int profile, BluetoothProfile proxy) { |
| 788 | mBluetoothHeadset = (BluetoothHeadset) proxy; |
| 789 | if (VDBG) log("- Got BluetoothHeadset: " + mBluetoothHeadset); |
| 790 | } |
| 791 | |
| 792 | public void onServiceDisconnected(int profile) { |
| 793 | mBluetoothHeadset = null; |
| 794 | } |
| 795 | }; |
| 796 | |
| 797 | private class CallNotifierPhoneStateListener extends PhoneStateListener { |
| 798 | public CallNotifierPhoneStateListener(int subId) { |
| 799 | super(subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 800 | } |
| 801 | |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 802 | @Override |
| 803 | public void onMessageWaitingIndicatorChanged(boolean visible) { |
| 804 | if (VDBG) log("onMessageWaitingIndicatorChanged(): " + this.mSubId + " " + visible); |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 805 | mMWIStatus.put(this.mSubId, visible); |
Srikanth Chintala | 4baf0b9 | 2017-11-14 15:52:47 +0530 | [diff] [blame] | 806 | updatePhoneStateListeners(false, UPDATE_TYPE_MWI, this.mSubId); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | @Override |
| 810 | public void onCallForwardingIndicatorChanged(boolean visible) { |
Tyler Gunn | 17bffd0 | 2017-09-19 11:40:12 -0700 | [diff] [blame] | 811 | Log.i(LOG_TAG, "onCallForwardingIndicatorChanged(): subId=" + this.mSubId |
| 812 | + ", visible=" + (visible ? "Y" : "N")); |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 813 | mCFIStatus.put(this.mSubId, visible); |
Srikanth Chintala | 4baf0b9 | 2017-11-14 15:52:47 +0530 | [diff] [blame] | 814 | updatePhoneStateListeners(false, UPDATE_TYPE_CFI, this.mSubId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 815 | } |
| 816 | }; |
| 817 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 818 | private void log(String msg) { |
| 819 | Log.d(LOG_TAG, msg); |
| 820 | } |
| 821 | } |