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