PhoneApp.java revision e22715b7e908074c33140eded331b01946026d4e
1b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project/* 2b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Copyright (C) 2006 The Android Open Source Project 3b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 4b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 5b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * you may not use this file except in compliance with the License. 6b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * You may obtain a copy of the License at 7b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 8b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 9b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 10b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 11b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 12b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * See the License for the specific language governing permissions and 14b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * limitations under the License. 15b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 16b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 17b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectpackage com.android.phone; 18b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 19b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.app.Activity; 20b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.app.Application; 21b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.app.KeyguardManager; 22b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.app.ProgressDialog; 23e22715b7e908074c33140eded331b01946026d4eMike Lockwoodimport android.app.StatusBarManager; 24b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.bluetooth.BluetoothHeadset; 25b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.content.BroadcastReceiver; 26b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.content.ContentResolver; 27b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.content.Context; 28b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.content.Intent; 29b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.content.IntentFilter; 30d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillaiimport android.content.res.Configuration; 31b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.media.AudioManager; 32b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.net.Uri; 33b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.AsyncResult; 34b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.Binder; 35b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.Handler; 36b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.IBinder; 37b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.IPowerManager; 38b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.LocalPowerManager; 39b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.Message; 40b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.PowerManager; 41b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.RemoteException; 42b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.ServiceManager; 43b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.SystemClock; 44b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.SystemProperties; 45b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.preference.PreferenceManager; 46b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.provider.Settings.System; 47404edc94de563aef5fd5ba48be9114a970cb93bbWink Savilleimport android.telephony.ServiceState; 48b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.util.Config; 49b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.util.Log; 50b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.view.KeyEvent; 51b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.widget.Toast; 52b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 53ee77dd0ec7fcbe315a34ef6625854a8affe31885David Brownimport com.android.internal.telephony.Call; 54a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Savilleimport com.android.internal.telephony.IccCard; 55a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Savilleimport com.android.internal.telephony.MmiCode; 56a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Savilleimport com.android.internal.telephony.Phone; 57a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Savilleimport com.android.internal.telephony.PhoneFactory; 58a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Savilleimport com.android.internal.telephony.TelephonyIntents; 59ee77dd0ec7fcbe315a34ef6625854a8affe31885David Brownimport com.android.internal.telephony.cdma.EriInfo; 606bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillaiimport com.android.phone.OtaUtils.CdmaOtaScreenState; 61a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville 62b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project/** 63b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Top-level Application class for the Phone app. 64b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 65b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectpublic class PhoneApp extends Application { 66b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ static final String LOG_TAG = "PhoneApp"; 67796c70c99bc39295bf685061056f06ab8949c742David Brown 68796c70c99bc39295bf685061056f06ab8949c742David Brown /** 69796c70c99bc39295bf685061056f06ab8949c742David Brown * Phone app-wide debug level: 70796c70c99bc39295bf685061056f06ab8949c742David Brown * 0 - no debug logging 71796c70c99bc39295bf685061056f06ab8949c742David Brown * 1 - normal debug logging if ro.debuggable is set (which is true in 72796c70c99bc39295bf685061056f06ab8949c742David Brown * "eng" and "userdebug" builds but not "user" builds) 73796c70c99bc39295bf685061056f06ab8949c742David Brown * 2 - ultra-verbose debug logging 74796c70c99bc39295bf685061056f06ab8949c742David Brown * 75796c70c99bc39295bf685061056f06ab8949c742David Brown * Most individual classes in the phone app have a local DBG constant, 76796c70c99bc39295bf685061056f06ab8949c742David Brown * typically set to 77796c70c99bc39295bf685061056f06ab8949c742David Brown * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1) 78796c70c99bc39295bf685061056f06ab8949c742David Brown * or else 79796c70c99bc39295bf685061056f06ab8949c742David Brown * (PhoneApp.DBG_LEVEL >= 2) 80796c70c99bc39295bf685061056f06ab8949c742David Brown * depending on the desired verbosity. 81796c70c99bc39295bf685061056f06ab8949c742David Brown */ 82796c70c99bc39295bf685061056f06ab8949c742David Brown /* package */ static final int DBG_LEVEL = 1; 83796c70c99bc39295bf685061056f06ab8949c742David Brown 84796c70c99bc39295bf685061056f06ab8949c742David Brown private static final boolean DBG = 85796c70c99bc39295bf685061056f06ab8949c742David Brown (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1); 86796c70c99bc39295bf685061056f06ab8949c742David Brown private static final boolean VDBG = (PhoneApp.DBG_LEVEL >= 2); 87b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 88b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Message codes; see mHandler below. 89b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private static final int EVENT_SIM_ABSENT = 1; 90b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private static final int EVENT_SIM_LOCKED = 2; 91b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private static final int EVENT_SIM_NETWORK_LOCKED = 3; 92b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private static final int EVENT_WIRED_HEADSET_PLUG = 7; 93b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private static final int EVENT_SIM_STATE_CHANGED = 8; 948bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project private static final int EVENT_UPDATE_INCALL_NOTIFICATION = 9; 954079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10; 964079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project private static final int EVENT_DATA_ROAMING_OK = 11; 97404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12; 98b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 99b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // The MMI codes are also used by the InCallScreen. 1004079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project public static final int MMI_INITIATE = 51; 1014079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project public static final int MMI_COMPLETE = 52; 1024079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project public static final int MMI_CANCEL = 53; 103b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Don't use message codes larger than 99 here; those are reserved for 104b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // the individual Activities of the Phone UI. 105b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 106b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 107b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Allowable values for the poke lock code (timeout between a user activity and the 108b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * going to sleep), please refer to {@link com.android.server.PowerManagerService} 109b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * for additional reference. 110b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * SHORT uses the short delay for the timeout (SHORT_KEYLIGHT_DELAY, 6 sec) 111b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * MEDIUM uses the medium delay for the timeout (MEDIUM_KEYLIGHT_DELAY, 15 sec) 112b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * DEFAULT is the system-wide default delay for the timeout (1 min) 113b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 114b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project public enum ScreenTimeoutDuration { 115b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project SHORT, 116b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project MEDIUM, 117b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project DEFAULT 118b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 119b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 120b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 121b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Allowable values for the wake lock code. 122b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * SLEEP means the device can be put to sleep. 123b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * PARTIAL means wake the processor, but we display can be kept off. 124b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * FULL means wake both the processor and the display. 125b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 126b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project public enum WakeState { 127b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project SLEEP, 128b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PARTIAL, 129b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project FULL 130b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 131b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 132b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private static PhoneApp sMe; 133b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 134b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // A few important fields we expose to the rest of the package 135b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // directly (rather than thru set/get methods) for efficiency. 136b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Phone phone; 137b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project CallNotifier notifier; 138b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Ringer ringer; 139b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project BluetoothHandsfree mBtHandsfree; 140b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneInterfaceManager phoneMgr; 1418bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project int mBluetoothHeadsetState = BluetoothHeadset.STATE_ERROR; 1424b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project int mBluetoothHeadsetAudioState = BluetoothHeadset.STATE_ERROR; 1438bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project boolean mShowBluetoothIndication = false; 144b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 1450fb2b4b8eff811fd3243aefdf536e7ba2b10f4e9Wink Saville // Internal PhoneApp Call state tracker 1460fb2b4b8eff811fd3243aefdf536e7ba2b10f4e9Wink Saville CdmaPhoneCallState cdmaPhoneCallState; 1470fb2b4b8eff811fd3243aefdf536e7ba2b10f4e9Wink Saville 148b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // The InCallScreen instance (or null if the InCallScreen hasn't been 149b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // created yet.) 150b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private InCallScreen mInCallScreen; 151b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 152b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // The currently-active PUK entry activity and progress dialog. 153b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Normally, these are the Emergency Dialer and the subsequent 154b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // progress dialog. null if there is are no such objects in 155b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // the foreground. 156b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private Activity mPUKEntryActivity; 157b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private ProgressDialog mPUKEntryProgressDialog; 158b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 159b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private boolean mIsSimPinEnabled; 160b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private String mCachedSimPin; 161b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 162b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // True if a wired headset is currently plugged in, based on the state 163b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // from the latest Intent.ACTION_HEADSET_PLUG broadcast we received in 164b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // mReceiver.onReceive(). 165b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private boolean mIsHeadsetPlugged; 166b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 167d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai // True if the keyboard is currently *not* hidden 168d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai // Gets updated whenever there is a Configuration change 169d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai private boolean mIsHardKeyboardOpen; 170d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai 171445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood // True if we are beginning a call, but the phone state has not changed yet 172445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood private boolean mBeginningCall; 173445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood 174445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood // Last phone state seen by updatePhoneState() 175445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood Phone.State mLastPhoneState = Phone.State.IDLE; 176445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood 177b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private WakeState mWakeState = WakeState.SLEEP; 1784472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown private ScreenTimeoutDuration mScreenTimeoutDuration = ScreenTimeoutDuration.DEFAULT; 1794472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown private boolean mIgnoreTouchUserActivity = false; 180b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private IBinder mPokeLockToken = new Binder(); 181b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private IPowerManager mPowerManagerService; 182b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private PowerManager.WakeLock mWakeLock; 183b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private PowerManager.WakeLock mPartialWakeLock; 18458de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown private PowerManager.WakeLock mProximityWakeLock; 185b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private KeyguardManager mKeyguardManager; 186b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private KeyguardManager.KeyguardLock mKeyguardLock; 18787145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood private int mKeyguardDisableCount; 188e22715b7e908074c33140eded331b01946026d4eMike Lockwood private StatusBarManager mStatusBarManager; 189b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 190b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Broadcast receiver for various intent broadcasts (see onCreate()) 191b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver(); 192b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 193b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Broadcast receiver purely for ACTION_MEDIA_BUTTON broadcasts 194b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private final BroadcastReceiver mMediaButtonReceiver = new MediaButtonBroadcastReceiver(); 195b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 196b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** boolean indicating restoring mute state on InCallScreen.onResume() */ 197b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private boolean mShouldRestoreMuteOnInCallResume; 198b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 199af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // Following are the CDMA OTA information Objects used during OTA Call. 200af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // cdmaOtaProvisionData object store static OTA information that needs 201af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // to be maintained even during Slider open/close scenarios. 202af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // cdmaOtaConfigData object stores configuration info to control visiblity 203af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // of each OTA Screens. 204af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // cdmaOtaScreenState object store OTA Screen State information. 205af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville public OtaUtils.CdmaOtaProvisionData cdmaOtaProvisionData; 206af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville public OtaUtils.CdmaOtaConfigData cdmaOtaConfigData; 207af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville public OtaUtils.CdmaOtaScreenState cdmaOtaScreenState; 208f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville public OtaUtils.CdmaOtaInCallScreenUiState cdmaOtaInCallScreenUiState; 209af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville 210b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 211b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Set the restore mute state flag. Used when we are setting the mute state 212b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * OUTSIDE of user interaction {@link PhoneUtils#startNewCall(Phone)} 213b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 214b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /*package*/void setRestoreMuteOnInCallResume (boolean mode) { 215b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mShouldRestoreMuteOnInCallResume = mode; 216b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 217b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 218b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 219b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Get the restore mute state flag. 220b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * This is used by the InCallScreen {@link InCallScreen#onResume()} to figure 221b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * out if we need to restore the mute state for the current active call. 222b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 223b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /*package*/boolean getRestoreMuteOnInCallResume () { 224b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return mShouldRestoreMuteOnInCallResume; 225b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 226b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 227b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Handler mHandler = new Handler() { 228b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project @Override 229b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project public void handleMessage(Message msg) { 230b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project switch (msg.what) { 231b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case EVENT_SIM_LOCKED: 232b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// mIsSimPinEnabled = true; 233b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// 234b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// if (Config.LOGV) Log.v(LOG_TAG, "show sim unlock panel"); 235b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// SimPinUnlockPanel pinUnlockPanel = new SimPinUnlockPanel( 236b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// PhoneApp.getInstance()); 237b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// pinUnlockPanel.show(); 238b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 239b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 240b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case EVENT_SIM_ABSENT: 241b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// Don't need this now that the lock screen handles this case 242b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// if (Config.LOGV) Log.v(LOG_TAG, "show sim missing panel"); 243b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// SimMissingPanel missingPanel = new SimMissingPanel( 244b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// PhoneApp.getInstance()); 245b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// missingPanel.show(); 246b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 247b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 248b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case EVENT_SIM_NETWORK_LOCKED: 24909328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown if (getResources().getBoolean(R.bool.ignore_sim_network_locked_events)) { 25009328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown // Some products don't have the concept of a "SIM network lock" 25109328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; " 25209328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown + "not showing 'SIM network unlock' PIN entry screen"); 25309328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown } else { 25409328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown // Normal case: show the "SIM network unlock" PIN entry screen. 25509328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown // The user won't be able to do anything else until 25609328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown // they enter a valid SIM network PIN. 25709328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown Log.i(LOG_TAG, "show sim depersonal panel"); 25809328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown IccNetworkDepersonalizationPanel ndpPanel = 25909328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown new IccNetworkDepersonalizationPanel(PhoneApp.getInstance()); 26009328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown ndpPanel.show(); 26109328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown } 262b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 263b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 2648bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project case EVENT_UPDATE_INCALL_NOTIFICATION: 2658bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // Tell the NotificationMgr to update the "ongoing 2668bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // call" icon in the status bar, if necessary. 2678bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // Currently, this is triggered by a bluetooth headset 2688bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // state change (since the status bar icon needs to 2698bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // turn blue when bluetooth is active.) 2708bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project NotificationMgr.getDefault().updateInCallNotification(); 2718bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project break; 2728bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project 2734079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project case EVENT_DATA_ROAMING_DISCONNECTED: 2744079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project NotificationMgr.getDefault().showDataDisconnectedRoaming(); 275b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 2764079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project 2774079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project case EVENT_DATA_ROAMING_OK: 2784079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project NotificationMgr.getDefault().hideDataDisconnectedRoaming(); 2794079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project break; 2804079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project 281b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case MMI_COMPLETE: 282b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project onMMIComplete((AsyncResult) msg.obj); 283b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 284b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 285b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case MMI_CANCEL: 286b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.cancelMmiCode(phone); 287b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 288b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 289b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case EVENT_WIRED_HEADSET_PLUG: 290b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Since the presence of a wired headset or bluetooth affects the 291b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // speakerphone, update the "speaker" state. We ONLY want to do 292b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // this on the wired headset connect / disconnect events for now 293b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // though, so we're only triggering on EVENT_WIRED_HEADSET_PLUG. 294425b8e3c9846d5e0e76466604b35cad8856d79deEric Laurent // If in call screen is showing, let InCallScreen handle the speaker. 2954a8cbde060e7876a5560346215c11078a9efc90eEric Laurent 2964a8cbde060e7876a5560346215c11078a9efc90eEric Laurent Phone.State phoneState = phone.getState(); 2974a8cbde060e7876a5560346215c11078a9efc90eEric Laurent // Do not change speaker state if phone is not off hook 2984a8cbde060e7876a5560346215c11078a9efc90eEric Laurent if (phoneState == Phone.State.OFFHOOK) { 2994a8cbde060e7876a5560346215c11078a9efc90eEric Laurent if (!isShowingCallScreen() && 3004a8cbde060e7876a5560346215c11078a9efc90eEric Laurent (mBtHandsfree == null || !mBtHandsfree.isAudioOn())) { 3014a8cbde060e7876a5560346215c11078a9efc90eEric Laurent if (!isHeadsetPlugged()) { 3024a8cbde060e7876a5560346215c11078a9efc90eEric Laurent // if the state is "not connected", restore the speaker state. 3034a8cbde060e7876a5560346215c11078a9efc90eEric Laurent PhoneUtils.restoreSpeakerMode(getApplicationContext()); 3044a8cbde060e7876a5560346215c11078a9efc90eEric Laurent } else { 3054a8cbde060e7876a5560346215c11078a9efc90eEric Laurent // if the state is "connected", force the speaker off without 3064a8cbde060e7876a5560346215c11078a9efc90eEric Laurent // storing the state. 3074a8cbde060e7876a5560346215c11078a9efc90eEric Laurent PhoneUtils.turnOnSpeaker(getApplicationContext(), false, false); 3084a8cbde060e7876a5560346215c11078a9efc90eEric Laurent } 309425b8e3c9846d5e0e76466604b35cad8856d79deEric Laurent } 310b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 311d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai // Update the Proximity sensor based on headset state 3124a8cbde060e7876a5560346215c11078a9efc90eEric Laurent updateProximitySensorMode(phoneState); 313b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 314b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 315b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case EVENT_SIM_STATE_CHANGED: 316b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Marks the event where the SIM goes into ready state. 317b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Right now, this is only used for the PUK-unlocking 318b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // process. 319a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville if (msg.obj.equals(IccCard.INTENT_VALUE_ICC_READY)) { 320b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // when the right event is triggered and there 321b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // are UI objects in the foreground, we close 322b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // them to display the lock panel. 323b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mPUKEntryActivity != null) { 324b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPUKEntryActivity.finish(); 325b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPUKEntryActivity = null; 326b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 327b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mPUKEntryProgressDialog != null) { 328b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPUKEntryProgressDialog.dismiss(); 329b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPUKEntryProgressDialog = null; 330b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 331b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 332b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 333404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville 334404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville case EVENT_UNSOL_CDMA_INFO_RECORD: 335404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville //TODO: handle message here; 336404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville break; 337b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 338b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 339b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project }; 340b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 341b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project public PhoneApp() { 342b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project sMe = this; 343b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 344b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 345b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project @Override 346b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project public void onCreate() { 347b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (Config.LOGV) Log.v(LOG_TAG, "onCreate()..."); 348b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 349b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project ContentResolver resolver = getContentResolver(); 350b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 351b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (phone == null) { 352b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Initialize the telephony framework 353b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneFactory.makeDefaultPhones(this); 354b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 355b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Get the default phone 356b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project phone = PhoneFactory.getDefaultPhone(); 357b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 358b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project NotificationMgr.init(this); 359b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 360b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project phoneMgr = new PhoneInterfaceManager(this, phone); 361c9d9ed30aa547b79b81adc13a4d148a003b6ee62w 36279b9f6e30e8402b103f1ec3ed9dda1fcad2b1cd5Tammo Spalink int phoneType = phone.getPhoneType(); 36379b9f6e30e8402b103f1ec3ed9dda1fcad2b1cd5Tammo Spalink 36479b9f6e30e8402b103f1ec3ed9dda1fcad2b1cd5Tammo Spalink if (phoneType == Phone.PHONE_TYPE_CDMA) { 365c9d9ed30aa547b79b81adc13a4d148a003b6ee62w // Create an instance of CdmaPhoneCallState and initialize it to IDLE 366c9d9ed30aa547b79b81adc13a4d148a003b6ee62w cdmaPhoneCallState = new CdmaPhoneCallState(); 367c9d9ed30aa547b79b81adc13a4d148a003b6ee62w cdmaPhoneCallState.CdmaPhoneCallStateInit(); 368c9d9ed30aa547b79b81adc13a4d148a003b6ee62w } 369c9d9ed30aa547b79b81adc13a4d148a003b6ee62w 370b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (getSystemService(Context.BLUETOOTH_SERVICE) != null) { 371b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mBtHandsfree = new BluetoothHandsfree(this, phone); 372b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project startService(new Intent(this, BluetoothHeadsetService.class)); 373b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } else { 374b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Device is not bluetooth capable 375b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mBtHandsfree = null; 376b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 377b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 378b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project ringer = new Ringer(phone); 379b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 380b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // before registering for phone state changes 381b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); 382b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK 383b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project | PowerManager.ACQUIRE_CAUSES_WAKEUP 384b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project | PowerManager.ON_AFTER_RELEASE, LOG_TAG); 385b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // lock used to keep the processor awake, when we don't care for the display. 386b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPartialWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK 387b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project | PowerManager.ON_AFTER_RELEASE, LOG_TAG); 38858de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown // Wake lock used to control proximity sensor behavior. 38958de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown if ((pm.getSupportedWakeLockFlags() 39058de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown & PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK) != 0x0) { 39158de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown mProximityWakeLock = 39258de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, LOG_TAG); 39358de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown } 39458de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown if (DBG) Log.d(LOG_TAG, "mProximityWakeLock: " + mProximityWakeLock); 39558de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown 396b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); 397b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mKeyguardLock = mKeyguardManager.newKeyguardLock(LOG_TAG); 398e22715b7e908074c33140eded331b01946026d4eMike Lockwood mStatusBarManager = (StatusBarManager) getSystemService(Context.STATUS_BAR_SERVICE); 399b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 400b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // get a handle to the service so that we can use it later when we 401b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // want to set the poke lock. 402b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPowerManagerService = IPowerManager.Stub.asInterface( 403b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project ServiceManager.getService("power")); 404b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 405b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project notifier = new CallNotifier(this, phone, ringer, mBtHandsfree); 406b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 407a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville // register for ICC status 408a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville IccCard sim = phone.getIccCard(); 409b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (sim != null) { 410a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville if (Config.LOGV) Log.v(LOG_TAG, "register for ICC status"); 411b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project sim.registerForAbsent(mHandler, EVENT_SIM_ABSENT, null); 412b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project sim.registerForLocked(mHandler, EVENT_SIM_LOCKED, null); 413b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null); 414b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 415b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 416b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // register for MMI/USSD 41779b9f6e30e8402b103f1ec3ed9dda1fcad2b1cd5Tammo Spalink if (phoneType == Phone.PHONE_TYPE_GSM) { 418fa3fbeedf018e40f8d6696a382bbf316219cf4aeReli Tal phone.registerForMmiComplete(mHandler, MMI_COMPLETE, null); 419fa3fbeedf018e40f8d6696a382bbf316219cf4aeReli Tal } 420b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 421b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // register connection tracking to PhoneUtils 422b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.initializeConnectionHandler(phone); 423b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 424b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Register for misc other intent broadcasts. 425b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project IntentFilter intentFilter = 426b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED); 42718e0a07cc700234f5a02fe10eee9b3ea10db58b3Nick Pelly intentFilter.addAction(BluetoothHeadset.ACTION_STATE_CHANGED); 42818e0a07cc700234f5a02fe10eee9b3ea10db58b3Nick Pelly intentFilter.addAction(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED); 429b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED); 430b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project intentFilter.addAction(Intent.ACTION_HEADSET_PLUG); 431b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project intentFilter.addAction(Intent.ACTION_BATTERY_LOW); 432b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); 433a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED); 434404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); 435abeff00b5242e795baa8f5271525c5911f649993Wink Saville intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); 436b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project registerReceiver(mReceiver, intentFilter); 437b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 438b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Use a separate receiver for ACTION_MEDIA_BUTTON broadcasts, 439b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // since we need to manually adjust its priority (to make sure 440b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // we get these intents *before* the media player.) 441b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project IntentFilter mediaButtonIntentFilter = 442b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project new IntentFilter(Intent.ACTION_MEDIA_BUTTON); 443b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 444b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Make sure we're higher priority than the media player's 445b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // MediaButtonIntentReceiver (which currently has the default 446b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // priority of zero; see apps/Music/AndroidManifest.xml.) 447b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mediaButtonIntentFilter.setPriority(1); 448b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 449b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project registerReceiver(mMediaButtonReceiver, mediaButtonIntentFilter); 450b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 451b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project //set the default values for the preferences in the phone. 452b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PreferenceManager.setDefaultValues(this, R.xml.network_setting, false); 453cd0189299f484dcbd51400b994daf585923e9e8dDavid Krause 454cd0189299f484dcbd51400b994daf585923e9e8dDavid Krause PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false); 455b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 456b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Make sure the audio mode (along with some 457b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // audio-mode-related state of our own) is initialized 458b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // correctly, given the current state of the phone. 459b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project switch (phone.getState()) { 460b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case IDLE: 461b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (DBG) Log.d(LOG_TAG, "Resetting audio state/mode: IDLE"); 462b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.setAudioControlState(PhoneUtils.AUDIO_IDLE); 463b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.setAudioMode(this, AudioManager.MODE_NORMAL); 464b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 465b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case RINGING: 466b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (DBG) Log.d(LOG_TAG, "Resetting audio state/mode: RINGING"); 467b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.setAudioControlState(PhoneUtils.AUDIO_RINGING); 468b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.setAudioMode(this, AudioManager.MODE_RINGTONE); 469b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 470b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case OFFHOOK: 471b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (DBG) Log.d(LOG_TAG, "Resetting audio state/mode: OFFHOOK"); 472b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.setAudioControlState(PhoneUtils.AUDIO_OFFHOOK); 473b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.setAudioMode(this, AudioManager.MODE_IN_CALL); 474b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 475b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 476b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 477b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 47879b9f6e30e8402b103f1ec3ed9dda1fcad2b1cd5Tammo Spalink boolean phoneIsCdma = (phone.getPhoneType() == Phone.PHONE_TYPE_CDMA); 47979b9f6e30e8402b103f1ec3ed9dda1fcad2b1cd5Tammo Spalink 48079b9f6e30e8402b103f1ec3ed9dda1fcad2b1cd5Tammo Spalink if (phoneIsCdma) { 481af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData(); 482af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData(); 483af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState(); 484f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState(); 485af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 486af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville 487b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // XXX pre-load the SimProvider so that it's ready 488a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville resolver.getType(Uri.parse("content://icc/adn")); 489b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 490b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // start with the default value to set the mute state. 491b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mShouldRestoreMuteOnInCallResume = false; 492404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville 4930fb2b4b8eff811fd3243aefdf536e7ba2b10f4e9Wink Saville // Register for Cdma Information Records 4940fb2b4b8eff811fd3243aefdf536e7ba2b10f4e9Wink Saville // TODO(Moto): Merge 4950fb2b4b8eff811fd3243aefdf536e7ba2b10f4e9Wink Saville // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null); 4960fb2b4b8eff811fd3243aefdf536e7ba2b10f4e9Wink Saville 4977fe7f7e57aaa38290c37ab48867d34a279d198f3w // Read TTY settings and store it into BP NV. 4987fe7f7e57aaa38290c37ab48867d34a279d198f3w // AP owns (i.e. stores) the TTY setting in AP settings database and pushes the setting 4997fe7f7e57aaa38290c37ab48867d34a279d198f3w // to BP at power up (BP does not need to make the TTY setting persistent storage). 5007fe7f7e57aaa38290c37ab48867d34a279d198f3w // This way, there is a single owner (i.e AP) for the TTY setting in the phone. 50179b9f6e30e8402b103f1ec3ed9dda1fcad2b1cd5Tammo Spalink if (phoneIsCdma) { 5027fe7f7e57aaa38290c37ab48867d34a279d198f3w int settingsTtyMode = android.provider.Settings.Secure.getInt( 5037fe7f7e57aaa38290c37ab48867d34a279d198f3w phone.getContext().getContentResolver(), 5047fe7f7e57aaa38290c37ab48867d34a279d198f3w android.provider.Settings.Secure.PREFERRED_TTY_MODE, 5057fe7f7e57aaa38290c37ab48867d34a279d198f3w Phone.TTY_MODE_OFF); 5067fe7f7e57aaa38290c37ab48867d34a279d198f3w phone.setTTYMode(settingsTtyMode, null); 5077fe7f7e57aaa38290c37ab48867d34a279d198f3w } 508b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 509b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 510d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai @Override 511d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai public void onConfigurationChanged(Configuration newConfig) { 512d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) { 513d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai mIsHardKeyboardOpen = true; 514d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai } else { 515d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai mIsHardKeyboardOpen = false; 516d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai } 517d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai 518d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai // Update the Proximity sensor based on keyboard state 519d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai updateProximitySensorMode(phone.getState()); 520d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai super.onConfigurationChanged(newConfig); 521d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai } 522d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai 523b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 524b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Returns the singleton instance of the PhoneApp. 525b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 526b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project static PhoneApp getInstance() { 527b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return sMe; 528b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 529b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 530b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Ringer getRinger() { 531b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return ringer; 532b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 533b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 534b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project BluetoothHandsfree getBluetoothHandsfree() { 535b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return mBtHandsfree; 536b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 537b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 538b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project static Intent createCallLogIntent() { 539b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Intent intent = new Intent(Intent.ACTION_VIEW, null); 540b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project intent.setType("vnd.android.cursor.dir/calls"); 541b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return intent; 542b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 543b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 544b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 545b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Return an Intent that can be used to bring up the in-call screen. 546b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 547b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * This intent can only be used from within the Phone app, since the 548b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * InCallScreen is not exported from our AndroidManifest. 549b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 550b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ static Intent createInCallIntent() { 551b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Intent intent = new Intent(Intent.ACTION_MAIN, null); 552b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 553b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS 554b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project | Intent.FLAG_ACTIVITY_NO_USER_ACTION); 555b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project intent.setClassName("com.android.phone", getCallScreenClassName()); 556b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return intent; 557b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 558b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 559b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 560b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Variation of createInCallIntent() that also specifies whether the 561b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * DTMF dialpad should be initially visible when the InCallScreen 562b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * comes up. 563b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 564b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ static Intent createInCallIntent(boolean showDialpad) { 565b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Intent intent = createInCallIntent(); 566b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project intent.putExtra(InCallScreen.SHOW_DIALPAD_EXTRA, showDialpad); 567b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return intent; 568b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 569b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 570b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project static String getCallScreenClassName() { 571b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return InCallScreen.class.getName(); 572b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 573b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 574b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 575b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Starts the InCallScreen Activity. 576b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 577b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project void displayCallScreen() { 578796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "displayCallScreen()..."); 579b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project startActivity(createInCallIntent()); 580b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Profiler.callScreenRequested(); 581b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 582b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 583b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 584b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Helper function to check for one special feature of the CALL key: 585b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Normally, when the phone is idle, CALL takes you to the call log 586b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * (see the handler for KEYCODE_CALL in PhoneWindow.onKeyUp().) 587b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * But if the phone is in use (either off-hook or ringing) we instead 588b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * handle the CALL button by taking you to the in-call UI. 589b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 590b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @return true if we intercepted the CALL keypress (i.e. the phone 591b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * was in use) 592b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 593b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @see DialerActivity#onCreate 594b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 595b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean handleInCallOrRinging() { 596b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (phone.getState() != Phone.State.IDLE) { 597b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Phone is OFFHOOK or RINGING. 598b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (DBG) Log.v(LOG_TAG, 599b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project "handleInCallOrRinging: show call screen"); 600b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project displayCallScreen(); 601b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return true; 602b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 603b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return false; 604b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 605b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 606b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean isSimPinEnabled() { 607b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return mIsSimPinEnabled; 608b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 609b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 610b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean authenticateAgainstCachedSimPin(String pin) { 611b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return (mCachedSimPin != null && mCachedSimPin.equals(pin)); 612b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 613b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 614b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project void setCachedSimPin(String pin) { 615b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mCachedSimPin = pin; 616b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 617b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 618b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project void setInCallScreenInstance(InCallScreen inCallScreen) { 619b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mInCallScreen = inCallScreen; 620b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 621b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 622b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 623b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @return true if the in-call UI is running as the foreground 624b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * activity. (In other words, from the perspective of the 625b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * InCallScreen activity, return true between onResume() and 626b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * onPause().) 627b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 628b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Note this method will return false if the screen is currently off, 629b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * even if the InCallScreen *was* in the foreground just before the 630b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * screen turned off. (This is because the foreground activity is 631b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * always "paused" while the screen is off.) 632b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 633b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean isShowingCallScreen() { 634b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mInCallScreen == null) return false; 635b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return mInCallScreen.isForegroundActivity(); 636b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 637b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 638b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 639b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Dismisses the in-call UI. 640b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 641b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * This also ensures that you won't be able to get back to the in-call 642b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * UI via the BACK button (since this call removes the InCallScreen 643b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * from the activity history.) 644af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * For OTA Call, it call InCallScreen api to handle OTA Call End scenario 645af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * to display OTA Call End screen. 646b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 647b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project void dismissCallScreen() { 648b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mInCallScreen != null) { 6496bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai if (mInCallScreen.isOtaCallInActiveState() 6506bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai || mInCallScreen.isOtaCallInEndState() 6516bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai || ((cdmaOtaScreenState != null) 6526bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai && (cdmaOtaScreenState.otaScreenState 6536bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai != CdmaOtaScreenState.OtaScreenState.OTA_STATUS_UNDEFINED))) { 654af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // TODO(Moto): During OTA Call, display should not become dark to 655af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // allow user to see OTA UI update. Phone app needs to hold a SCREEN_DIM_WAKE_LOCK 656af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // wake lock during the entire OTA call. 657af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville wakeUpScreen(); 6586bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai // If InCallScreen is not in foreground we resume it to show the OTA call end screen 6596bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai // Fire off the InCallScreen intent 6606bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai displayCallScreen(); 6616bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai 662af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville mInCallScreen.handleOtaCallEnd(); 663af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville return; 664af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } else { 665af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville mInCallScreen.finish(); 666af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 667b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 668b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 669b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 670b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 671af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * Handle OTA events 672af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * 673af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * When OTA call is active and display becomes dark, then CallNotifier will 674af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * handle OTA Events by calling this api which then calls OtaUtil function. 675af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville */ 676af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville void handleOtaEvents(Message msg) { 677af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville 678af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville if (DBG) Log.d(LOG_TAG, "Enter handleOtaEvents"); 679af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville if ((mInCallScreen != null) && (!isShowingCallScreen())) { 680af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville if (mInCallScreen.otaUtils != null) { 681af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville mInCallScreen.otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj); 682af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 683af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 684af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 685af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville 686af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville 687af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville /** 688b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Sets the activity responsible for un-PUK-blocking the device 689b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * so that we may close it when we receive a positive result. 690b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * mPUKEntryActivity is also used to indicate to the device that 691b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * we are trying to un-PUK-lock the phone. In other words, iff 692b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * it is NOT null, then we are trying to unlock and waiting for 693b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * the SIM to move to READY state. 694b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 695b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @param activity is the activity to close when PUK has 696b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * finished unlocking. Can be set to null to indicate the unlock 697b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * or SIM READYing process is over. 698b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 699b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project void setPukEntryActivity(Activity activity) { 700b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPUKEntryActivity = activity; 701b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 702b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 703b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Activity getPUKEntryActivity() { 704b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return mPUKEntryActivity; 705b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 706b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 707b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 708b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Sets the dialog responsible for notifying the user of un-PUK- 709b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * blocking - SIM READYing progress, so that we may dismiss it 710b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * when we receive a positive result. 711b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 712b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @param dialog indicates the progress dialog informing the user 713b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * of the state of the device. Dismissed upon completion of 714b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * READYing process 715b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 716b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project void setPukEntryProgressDialog(ProgressDialog dialog) { 717b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPUKEntryProgressDialog = dialog; 718b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 719b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 720b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project ProgressDialog getPUKEntryProgressDialog() { 721b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return mPUKEntryProgressDialog; 722b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 723b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 724b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 725b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Disables the keyguard. This is used by the phone app to allow 726b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * interaction with the Phone UI when the keyguard would otherwise be 727b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * active (like receiving an incoming call while the device is 728b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * locked.) 729b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 730b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Any call to this method MUST be followed (eventually) 731b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * by a corresponding reenableKeyguard() call. 732b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 733b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ void disableKeyguard() { 734b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (DBG) Log.d(LOG_TAG, "disable keyguard"); 735b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // if (DBG) Log.d(LOG_TAG, "disableKeyguard()...", new Throwable("stack dump")); 73687145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood synchronized (mKeyguardLock) { 73787145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood if (mKeyguardDisableCount++ == 0) { 73887145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood mKeyguardLock.disableKeyguard(); 739e22715b7e908074c33140eded331b01946026d4eMike Lockwood mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND); 74087145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood } 74187145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood } 742b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 743b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 744b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 745b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Re-enables the keyguard after a previous disableKeyguard() call. 746b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 747b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Any call to this method MUST correspond to (i.e. be balanced with) 748b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * a previous disableKeyguard() call. 749b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 750b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ void reenableKeyguard() { 751b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (DBG) Log.d(LOG_TAG, "re-enable keyguard"); 752b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // if (DBG) Log.d(LOG_TAG, "reenableKeyguard()...", new Throwable("stack dump")); 75387145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood synchronized (mKeyguardLock) { 75487145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood if (mKeyguardDisableCount > 0) { 75587145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood if (--mKeyguardDisableCount == 0) { 75687145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood mKeyguardLock.reenableKeyguard(); 757e22715b7e908074c33140eded331b01946026d4eMike Lockwood mStatusBarManager.disable(StatusBarManager.DISABLE_NONE); 75887145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood } 75987145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood } else { 76087145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood Log.e(LOG_TAG, "mKeyguardDisableCount is already zero"); 76187145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood } 76287145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood } 763b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 764b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 765b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 766b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Controls how quickly the screen times out. 767b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 768b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * The poke lock controls how long it takes before the screen powers 769b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * down, and therefore has no immediate effect when the current 770b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * WakeState (see {@link PhoneApp#requestWakeState}) is FULL. 771b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * If we're in a state where the screen *is* allowed to turn off, 772b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * though, the poke lock will determine the timeout interval (long or 773b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * short). 774b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 775b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @param shortPokeLock tells the device the timeout duration to use 776b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * before going to sleep 777b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * {@link com.android.server.PowerManagerService#SHORT_KEYLIGHT_DELAY}. 778b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 779b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ void setScreenTimeout(ScreenTimeoutDuration duration) { 780796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "setScreenTimeout(" + duration + ")..."); 781b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 782b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // make sure we don't set the poke lock repeatedly so that we 783b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // avoid triggering the userActivity calls in 784b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // PowerManagerService.setPokeLock(). 7854472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown if (duration == mScreenTimeoutDuration) { 786b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return; 787b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 788039a8e51aa4a3ed27ad788dd5f1e043446517d92Mike Lockwood // stick with default timeout if we are using the proximity sensor 789039a8e51aa4a3ed27ad788dd5f1e043446517d92Mike Lockwood if (proximitySensorModeEnabled()) { 790039a8e51aa4a3ed27ad788dd5f1e043446517d92Mike Lockwood return; 791039a8e51aa4a3ed27ad788dd5f1e043446517d92Mike Lockwood } 7924472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown mScreenTimeoutDuration = duration; 7934472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown updatePokeLock(); 7944472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown } 795b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 7964472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown /** 7974472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * Update the state of the poke lock held by the phone app, 7984472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * based on the current desired screen timeout and the 7994472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * current "ignore user activity on touch" flag. 8004472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown */ 8014472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown private void updatePokeLock() { 802b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // This is kind of convoluted, but the basic thing to remember is 803b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // that the poke lock just sends a message to the screen to tell 804b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // it to stay on for a while. 805b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // The default is 0, for a long timeout and should be set that way 806b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // when we are heading back into a the keyguard / screen off 807b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // state, and also when we're trying to keep the screen alive 808b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // while ringing. We'll also want to ignore the cheek events 809b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // regardless of the timeout duration. 810b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // The short timeout is really used whenever we want to give up 811b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // the screen lock, such as when we're in call. 812b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project int pokeLockSetting = LocalPowerManager.POKE_LOCK_IGNORE_CHEEK_EVENTS; 8134472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown switch (mScreenTimeoutDuration) { 814b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case SHORT: 815b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Set the poke lock to timeout the display after a short 816b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // timeout (5s). This ensures that the screen goes to sleep 817b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // as soon as acceptably possible after we the wake lock 818b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // has been released. 819b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project pokeLockSetting |= LocalPowerManager.POKE_LOCK_SHORT_TIMEOUT; 820b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 821b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 822b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case MEDIUM: 823b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Set the poke lock to timeout the display after a medium 824b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // timeout (15s). This ensures that the screen goes to sleep 825b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // as soon as acceptably possible after we the wake lock 826b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // has been released. 827b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project pokeLockSetting |= LocalPowerManager.POKE_LOCK_MEDIUM_TIMEOUT; 828b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 829b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 830b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case DEFAULT: 831b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project default: 832b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // set the poke lock to timeout the display after a long 833b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // delay by default. 834b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // TODO: it may be nice to be able to disable cheek presses 835b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // for long poke locks (emergency dialer, for instance). 836b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 837b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 838b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 8394472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown if (mIgnoreTouchUserActivity) { 8404472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown pokeLockSetting |= LocalPowerManager.POKE_LOCK_IGNORE_TOUCH_AND_CHEEK_EVENTS; 8414472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown } 8424472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown 843b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Send the request 844b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project try { 845b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPowerManagerService.setPokeLock(pokeLockSetting, mPokeLockToken, LOG_TAG); 846b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } catch (RemoteException e) { 8474472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown Log.w(LOG_TAG, "mPowerManagerService.setPokeLock() failed: " + e); 848b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 849b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 850b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 851b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 852b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Controls whether or not the screen is allowed to sleep. 853b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 854b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Once sleep is allowed (WakeState is SLEEP), it will rely on the 855b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * settings for the poke lock to determine when to timeout and let 856b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * the device sleep {@link PhoneApp#setScreenTimeout}. 857b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 858b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @param ws tells the device to how to wake. 859b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 860b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ void requestWakeState(WakeState ws) { 861796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")..."); 862b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mWakeState != ws) { 863b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project switch (ws) { 864b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case PARTIAL: 865b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // acquire the processor wake lock, and release the FULL 866b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // lock if it is being held. 867b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPartialWakeLock.acquire(); 868b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mWakeLock.isHeld()) { 869b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mWakeLock.release(); 870b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 871b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 872b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case FULL: 873b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // acquire the full wake lock, and release the PARTIAL 874b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // lock if it is being held. 875b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mWakeLock.acquire(); 876b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mPartialWakeLock.isHeld()) { 877b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPartialWakeLock.release(); 878b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 879b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 880b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case SLEEP: 881b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project default: 882b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // release both the PARTIAL and FULL locks. 883b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mWakeLock.isHeld()) { 884b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mWakeLock.release(); 885b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 886b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mPartialWakeLock.isHeld()) { 887b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPartialWakeLock.release(); 888b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 889b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 890b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 891b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mWakeState = ws; 892b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 893b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 894b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 895b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 896b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * If we are not currently keeping the screen on, then poke the power 897b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * manager to wake up the screen for the user activity timeout duration. 898b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 899b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ void wakeUpScreen() { 900b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mWakeState == WakeState.SLEEP) { 901b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (DBG) Log.d(LOG_TAG, "pulse screen lock"); 902b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project try { 903b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPowerManagerService.userActivityWithForce(SystemClock.uptimeMillis(), false, true); 904b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } catch (RemoteException ex) { 905b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Ignore -- the system process is dead. 906b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 907b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 908b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 909b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 910b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 911b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Sets the wake state and screen timeout based on the current state 912b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * of the phone, and the current state of the in-call UI. 913b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 914b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * This method is a "UI Policy" wrapper around 915b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * {@link PhoneApp#requestWakeState} and {@link PhoneApp#setScreenTimeout}. 916b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 917b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * It's safe to call this method regardless of the state of the Phone 918b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * (e.g. whether or not it's idle), and regardless of the state of the 919b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Phone UI (e.g. whether or not the InCallScreen is active.) 920b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 921b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ void updateWakeState() { 922b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Phone.State state = phone.getState(); 923b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 924b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // True if the in-call UI is the foreground activity. 925b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // (Note this will be false if the screen is currently off, 926b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // since in that case *no* activity is in the foreground.) 927b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean isShowingCallScreen = isShowingCallScreen(); 928b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 929b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // True if the InCallScreen's DTMF dialer is currently opened. 930b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // (Note this does NOT imply whether or not the InCallScreen 931b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // itself is visible.) 932b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean isDialerOpened = (mInCallScreen != null) && mInCallScreen.isDialerOpened(); 933b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 934b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // True if the speakerphone is in use. (If so, we *always* use 935b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // the default timeout. Since the user is obviously not holding 936b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // the phone up to his/her face, we don't need to worry about 937b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // false touches, and thus don't need to turn the screen off so 938b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // aggressively.) 939b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Note that we need to make a fresh call to this method any 940b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // time the speaker state changes. (That happens in 941b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // PhoneUtils.turnOnSpeaker().) 942b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean isSpeakerInUse = (state == Phone.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this); 943b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 944b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // TODO (bug 1440854): The screen timeout *might* also need to 945b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // depend on the bluetooth state, but this isn't as clear-cut as 946b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // the speaker state (since while using BT it's common for the 947b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // user to put the phone straight into a pocket, in which case the 948b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // timeout should probably still be short.) 949b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 950796c70c99bc39295bf685061056f06ab8949c742David Brown if (DBG) Log.d(LOG_TAG, "updateWakeState: callscreen " + isShowingCallScreen 951796c70c99bc39295bf685061056f06ab8949c742David Brown + ", dialer " + isDialerOpened 952796c70c99bc39295bf685061056f06ab8949c742David Brown + ", speaker " + isSpeakerInUse + "..."); 953b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 954b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 955b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // (1) Set the screen timeout. 956b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 957b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Note that the "screen timeout" value we determine here is 958b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // meaningless if the screen is forced on (see (2) below.) 959b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 960b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (!isShowingCallScreen || isSpeakerInUse) { 961b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Use the system-wide default timeout. 962b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project setScreenTimeout(ScreenTimeoutDuration.DEFAULT); 963b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } else { 964b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // We're on the in-call screen, and *not* using the speakerphone. 965b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (isDialerOpened) { 966b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // The DTMF dialpad is up. This case is special because 967b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // the in-call UI has its own "touch lock" mechanism to 968b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // disable the dialpad after a very short amount of idle 969b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // time (to avoid false touches from the user's face while 970b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // in-call.) 971b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 972b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // In this case the *physical* screen just uses the 973b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // system-wide default timeout. 974b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project setScreenTimeout(ScreenTimeoutDuration.DEFAULT); 975b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } else { 976b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // We're on the in-call screen, and not using the DTMF dialpad. 977b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // There's actually no touchable UI onscreen at all in 978b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // this state. Also, the user is (most likely) not 979b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // looking at the screen at all, since they're probably 980b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // holding the phone up to their face. Here we use a 981b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // special screen timeout value specific to the in-call 982b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // screen, purely to save battery life. 983b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project setScreenTimeout(ScreenTimeoutDuration.MEDIUM); 984b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 985b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 986b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 987b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 988b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // (2) Decide whether to force the screen on or not. 989b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 990ee77dd0ec7fcbe315a34ef6625854a8affe31885David Brown // Force the screen to be on if the phone is ringing or dialing, 991ee77dd0ec7fcbe315a34ef6625854a8affe31885David Brown // or if we're displaying the "Call ended" UI for a connection in 992ee77dd0ec7fcbe315a34ef6625854a8affe31885David Brown // the "disconnected" state. 993b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 994b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean isRinging = (state == Phone.State.RINGING); 995ee77dd0ec7fcbe315a34ef6625854a8affe31885David Brown boolean isDialing = (phone.getForegroundCall().getState() == Call.State.DIALING); 996b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean showingDisconnectedConnection = 997b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.hasDisconnectedConnections(phone) && isShowingCallScreen; 998ee77dd0ec7fcbe315a34ef6625854a8affe31885David Brown boolean keepScreenOn = isRinging || isDialing || showingDisconnectedConnection; 999b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (DBG) Log.d(LOG_TAG, "updateWakeState: keepScreenOn = " + keepScreenOn 1000b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project + " (isRinging " + isRinging 1001ee77dd0ec7fcbe315a34ef6625854a8affe31885David Brown + ", isDialing " + isDialing 1002796c70c99bc39295bf685061056f06ab8949c742David Brown + ", showingDisc " + showingDisconnectedConnection + ")"); 1003b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // keepScreenOn == true means we'll hold a full wake lock: 1004b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP); 1005b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1006b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 1007b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 1008b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Wrapper around the PowerManagerService.preventScreenOn() API. 1009b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * This allows the in-call UI to prevent the screen from turning on 1010b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * even if a subsequent call to updateWakeState() causes us to acquire 1011b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * a full wake lock. 1012b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 1013b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ void preventScreenOn(boolean prevent) { 1014796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "- preventScreenOn(" + prevent + ")..."); 1015b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project try { 1016b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPowerManagerService.preventScreenOn(prevent); 1017b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } catch (RemoteException e) { 1018b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Log.w(LOG_TAG, "mPowerManagerService.preventScreenOn() failed: " + e); 1019b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1020b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1021b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 10224472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown /** 10234472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * Sets or clears the flag that tells the PowerManager that touch 10244472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * (and cheek) events should NOT be considered "user activity". 10254472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * 10264472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * Since the in-call UI is totally insensitive to touch in most 10274472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * states, we set this flag whenever the InCallScreen is in the 10284472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * foreground. (Otherwise, repeated unintentional touches could 10294472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * prevent the device from going to sleep.) 10304472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * 10314472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * There *are* some some touch events that really do count as user 10324472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * activity, though. For those, we need to manually poke the 10334472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * PowerManager's userActivity method; see pokeUserActivity(). 10344472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown */ 10354472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown /* package */ void setIgnoreTouchUserActivity(boolean ignore) { 10364472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown if (VDBG) Log.d(LOG_TAG, "setIgnoreTouchUserActivity(" + ignore + ")..."); 10374472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown mIgnoreTouchUserActivity = ignore; 10384472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown updatePokeLock(); 10394472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown } 10404472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown 10414472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown /** 10424472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * Manually pokes the PowerManager's userActivity method. Since we 10434472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * hold the POKE_LOCK_IGNORE_TOUCH_AND_CHEEK_EVENTS poke lock while 10444472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * the InCallScreen is active, we need to do this for touch events 10454472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * that really do count as user activity (like DTMF key presses, or 10464472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * unlocking the "touch lock" overlay.) 10474472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown */ 10484472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown /* package */ void pokeUserActivity() { 10494472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown if (VDBG) Log.d(LOG_TAG, "pokeUserActivity()..."); 10504472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown try { 10514472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown mPowerManagerService.userActivity(SystemClock.uptimeMillis(), false); 10524472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown } catch (RemoteException e) { 10534472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown Log.w(LOG_TAG, "mPowerManagerService.userActivity() failed: " + e); 10544472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown } 10554472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown } 10564472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown 105758de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown /** 1058445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood * Set when a new outgoing call is beginning, so we can update 1059445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood * the proximity sensor state. 1060445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood * Cleared when the InCallScreen is no longer in the foreground, 1061445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood * in case the call fails without changing the telephony state. 1062445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood */ 1063445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood /* package */ void setBeginningCall(boolean beginning) { 1064445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood // Note that we are beginning a new call, for proximity sensor support 1065445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood mBeginningCall = beginning; 1066445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood // Update the Proximity sensor based on mBeginningCall state 1067445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood updateProximitySensorMode(phone.getState()); 1068445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood } 1069445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood 1070445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood /** 107158de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * Updates the wake lock used to control proximity sensor behavior, 107258de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * based on the current state of the phone. This method is called 107358de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * from the CallNotifier on any phone state change. 107458de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * 107558de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * On devices that have a proximity sensor, to avoid false touches 107658de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * during a call, we hold a PROXIMITY_SCREEN_OFF_WAKE_LOCK wake lock 107758de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * whenever the phone is off hook. (When held, that wake lock causes 107858de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * the screen to turn off automatically when the sensor detects an 107958de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * object close to the screen.) 108058de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * 108158de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * This method is a no-op for devices that don't have a proximity 108258de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * sensor. 108358de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * 108458de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * Note this method doesn't care if the InCallScreen is the foreground 108558de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * activity or not. That's because we want the proximity sensor to be 108658de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * enabled any time the phone is in use, to avoid false cheek events 108758de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * for whatever app you happen to be running. 108858de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * 1089d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai * Proximity wake lock will *not* be held if any one of the 1090d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai * conditions is true while on a call: 1091d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai * 1) If the audio is routed via Bluetooth 1092d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai * 2) If a wired headset is connected 1093d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai * 3) if the speaker is ON 1094d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai * 4) If the slider is open(i.e. the hardkeyboard is *not* hidden) 109558de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * 109658de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * @param state current state of the phone (see {@link Phone#State}) 109758de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown */ 109858de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown /* package */ void updateProximitySensorMode(Phone.State state) { 1099445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood if (VDBG) Log.d(LOG_TAG, "updateProximitySensorMode: state = " + state); 1100d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai 1101039a8e51aa4a3ed27ad788dd5f1e043446517d92Mike Lockwood if (proximitySensorModeEnabled()) { 1102445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood if (((state == Phone.State.OFFHOOK) || mBeginningCall) 1103d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai && !(isHeadsetPlugged() 1104d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai || PhoneUtils.isSpeakerOn(this) 1105d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai || ((mBtHandsfree != null) && mBtHandsfree.isAudioOn()) 1106d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai || mIsHardKeyboardOpen)) { 110758de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown // Phone is in use! Arrange for the screen to turn off 110858de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown // automatically when the sensor detects a close object. 110958de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown if (!mProximityWakeLock.isHeld()) { 111058de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown if (DBG) Log.d(LOG_TAG, "updateProximitySensorMode: acquiring..."); 111158de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown mProximityWakeLock.acquire(); 11125601d455864ffb08ff995ba3fc162580dc7b8998Mike Lockwood // disable keyguard while we are using the proximity sensor 11135601d455864ffb08ff995ba3fc162580dc7b8998Mike Lockwood disableKeyguard(); 1114f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown } else { 1115445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood if (VDBG) Log.d(LOG_TAG, "updateProximitySensorMode: lock already held."); 111658de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown } 111758de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown } else { 111858de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown // Phone is either idle, or ringing. We don't want any 111958de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown // special proximity sensor behavior in either case. 112058de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown if (mProximityWakeLock.isHeld()) { 112158de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown if (DBG) Log.d(LOG_TAG, "updateProximitySensorMode: releasing..."); 112258de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown mProximityWakeLock.release(); 11235601d455864ffb08ff995ba3fc162580dc7b8998Mike Lockwood reenableKeyguard(); 1124f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown } else { 1125445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood if (VDBG) Log.d(LOG_TAG, "updateProximitySensorMode: lock already released."); 112658de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown } 112758de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown } 112858de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown } 112958de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown } 113058de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown 1131f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown /** 1132445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood * Notifies the phone app when the phone state changes. 1133445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood * Currently used only for proximity sensor support. 1134445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood */ 1135445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood /* package */ void updatePhoneState(Phone.State state) { 1136445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood if (state != mLastPhoneState) { 1137445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood mLastPhoneState = state; 1138445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood updateProximitySensorMode(state); 1139445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood // clear our beginning call flag 1140445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood mBeginningCall = false; 1141445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood } 1142445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood } 1143445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood 1144445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood /** 1145f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown * @return true if this device supports the "proximity sensor 1146f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown * auto-lock" feature while in-call (see updateProximitySensorMode()). 1147f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown */ 1148f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown /* package */ boolean proximitySensorModeEnabled() { 1149f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown return (mProximityWakeLock != null); 1150f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown } 1151f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown 1152b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project KeyguardManager getKeyguardManager() { 1153b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return mKeyguardManager; 1154b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1155b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 1156b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private void onMMIComplete(AsyncResult r) { 1157796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "onMMIComplete()..."); 1158b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project MmiCode mmiCode = (MmiCode) r.result; 1159b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.displayMMIComplete(phone, getInstance(), mmiCode, null, null); 1160b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1161b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 1162a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville private void initForNewRadioTechnology() { 116387258b2b589c3afea4b89b840251012378e0d3b4David Brown if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology..."); 1164a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville 116579b9f6e30e8402b103f1ec3ed9dda1fcad2b1cd5Tammo Spalink if (phone.getPhoneType() == Phone.PHONE_TYPE_CDMA) { 116660877272381161201c6969dea501e683705d6e32w // Create an instance of CdmaPhoneCallState and initialize it to IDLE 116760877272381161201c6969dea501e683705d6e32w cdmaPhoneCallState = new CdmaPhoneCallState(); 116860877272381161201c6969dea501e683705d6e32w cdmaPhoneCallState.CdmaPhoneCallStateInit(); 116960877272381161201c6969dea501e683705d6e32w 117060877272381161201c6969dea501e683705d6e32w //create instances of CDMA OTA data classes 117160877272381161201c6969dea501e683705d6e32w if (cdmaOtaProvisionData == null) { 117260877272381161201c6969dea501e683705d6e32w cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData(); 117360877272381161201c6969dea501e683705d6e32w } 117460877272381161201c6969dea501e683705d6e32w if (cdmaOtaConfigData == null) { 117560877272381161201c6969dea501e683705d6e32w cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData(); 117660877272381161201c6969dea501e683705d6e32w } 117760877272381161201c6969dea501e683705d6e32w if (cdmaOtaScreenState == null) { 117860877272381161201c6969dea501e683705d6e32w cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState(); 117960877272381161201c6969dea501e683705d6e32w } 118060877272381161201c6969dea501e683705d6e32w } 118160877272381161201c6969dea501e683705d6e32w 1182a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville ringer.updateRingerContextAfterRadioTechnologyChange(this.phone); 1183a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange(); 118487258b2b589c3afea4b89b840251012378e0d3b4David Brown if (mBtHandsfree != null) { 1185a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville mBtHandsfree.updateBtHandsfreeAfterRadioTechnologyChange(); 1186a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville } 118787258b2b589c3afea4b89b840251012378e0d3b4David Brown if (mInCallScreen != null) { 118887258b2b589c3afea4b89b840251012378e0d3b4David Brown mInCallScreen.updateAfterRadioTechnologyChange(); 118987258b2b589c3afea4b89b840251012378e0d3b4David Brown } 1190a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville 119187258b2b589c3afea4b89b840251012378e0d3b4David Brown // Update registration for ICC status after radio technology change 1192a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville IccCard sim = phone.getIccCard(); 1193a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville if (sim != null) { 119487258b2b589c3afea4b89b840251012378e0d3b4David Brown if (DBG) Log.d(LOG_TAG, "Update registration for ICC status..."); 1195a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville 1196a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville //Register all events new to the new active phone 1197a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville sim.registerForAbsent(mHandler, EVENT_SIM_ABSENT, null); 1198a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville sim.registerForLocked(mHandler, EVENT_SIM_LOCKED, null); 1199a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null); 1200a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville } 1201a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville } 1202a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville 1203404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville 1204404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville /** 1205b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @return true if a wired headset is currently plugged in. 1206b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 1207b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @see Intent.ACTION_HEADSET_PLUG (which we listen for in mReceiver.onReceive()) 1208b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 1209b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean isHeadsetPlugged() { 1210b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return mIsHeadsetPlugged; 1211b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1212b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 12138bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project /** 12148bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * @return true if the onscreen UI should currently be showing the 12158bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * special "bluetooth is active" indication in a couple of places (in 12168bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * which UI elements turn blue and/or show the bluetooth logo.) 12178bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * 12188bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * This depends on the BluetoothHeadset state *and* the current 12198bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * telephony state; see shouldShowBluetoothIndication(). 12208bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * 12218bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * @see CallCard 12228bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * @see NotificationMgr.updateInCallNotification 12238bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project */ 12248bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project /* package */ boolean showBluetoothIndication() { 12258bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project return mShowBluetoothIndication; 12268bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project } 12278bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project 12288bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project /** 12298bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * Recomputes the mShowBluetoothIndication flag based on the current 12308bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * bluetooth state and current telephony state. 12318bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * 12328bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * This needs to be called any time the bluetooth headset state or the 12338bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * telephony state changes. 12344b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project * 12354b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project * @param forceUiUpdate if true, force the UI elements that care 12364b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project * about this flag to update themselves. 12378bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project */ 12384b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project /* package */ void updateBluetoothIndication(boolean forceUiUpdate) { 12398bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project mShowBluetoothIndication = shouldShowBluetoothIndication(mBluetoothHeadsetState, 12404b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project mBluetoothHeadsetAudioState, 12418bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project phone); 12424b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project if (forceUiUpdate) { 12434b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project // Post Handler messages to the various components that might 12444b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project // need to be refreshed based on the new state. 1245325cc2ced6f1ff5fb1708abfcc5e9c73ac0cd962David Brown if (isShowingCallScreen()) mInCallScreen.requestUpdateBluetoothIndication(); 12464b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project mHandler.sendEmptyMessage(EVENT_UPDATE_INCALL_NOTIFICATION); 12474b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project } 1248d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai 1249d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai // Update the Proximity sensor based on Bluetooth audio state 1250d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai updateProximitySensorMode(phone.getState()); 12518bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project } 12528bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project 12538bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project /** 12548bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * UI policy helper function for the couple of places in the UI that 12558bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * have some way of indicating that "bluetooth is in use." 12568bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * 12578bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * @return true if the onscreen UI should indicate that "bluetooth is in use", 12588bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * based on the specified bluetooth headset state, and the 12598bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * current state of the phone. 12608bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * @see showBluetoothIndication() 12618bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project */ 12628bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project private static boolean shouldShowBluetoothIndication(int bluetoothState, 12634b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project int bluetoothAudioState, 12648bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project Phone phone) { 12658bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // We want the UI to indicate that "bluetooth is in use" in two 12668bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // slightly different cases: 12678bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // 12688bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // (a) The obvious case: if a bluetooth headset is currently in 12698bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // use for an ongoing call. 12708bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // 12718bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // (b) The not-so-obvious case: if an incoming call is ringing, 12728bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // and we expect that audio *will* be routed to a bluetooth 12738bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // headset once the call is answered. 12748bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project 12758bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project switch (phone.getState()) { 12768bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project case OFFHOOK: 12778bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // This covers normal active calls, and also the case if 12784b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project // the foreground call is DIALING or ALERTING. In this 12794b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project // case, bluetooth is considered "active" if a headset 12804b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project // is connected *and* audio is being routed to it. 12814b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project return ((bluetoothState == BluetoothHeadset.STATE_CONNECTED) 12824b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project && (bluetoothAudioState == BluetoothHeadset.AUDIO_STATE_CONNECTED)); 12838bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project 12848bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project case RINGING: 12858bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // If an incoming call is ringing, we're *not* yet routing 12868bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // audio to the headset (since there's no in-call audio 12878bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // yet!) In this case, if a bluetooth headset is 12888bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // connected at all, we assume that it'll become active 12898bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // once the user answers the phone. 12908bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project return (bluetoothState == BluetoothHeadset.STATE_CONNECTED); 12918bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project 12928bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project default: // Presumably IDLE 12938bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project return false; 12948bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project } 12958bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project } 12968bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project 1297b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 1298b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 1299b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Receiver for misc intent broadcasts the Phone app cares about. 1300b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 1301b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private class PhoneAppBroadcastReceiver extends BroadcastReceiver { 1302b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project @Override 1303b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project public void onReceive(Context context, Intent intent) { 1304b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project String action = intent.getAction(); 1305b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) { 1306b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean enabled = System.getInt(getContentResolver(), 1307b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project System.AIRPLANE_MODE_ON, 0) == 0; 1308b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project phone.setRadioPower(enabled); 130918e0a07cc700234f5a02fe10eee9b3ea10db58b3Nick Pelly } else if (action.equals(BluetoothHeadset.ACTION_STATE_CHANGED)) { 131018e0a07cc700234f5a02fe10eee9b3ea10db58b3Nick Pelly mBluetoothHeadsetState = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE, 13118bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project BluetoothHeadset.STATE_ERROR); 1312796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "mReceiver: HEADSET_STATE_CHANGED_ACTION"); 1313796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "==> new state: " + mBluetoothHeadsetState); 13144b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project updateBluetoothIndication(true); // Also update any visible UI if necessary 131518e0a07cc700234f5a02fe10eee9b3ea10db58b3Nick Pelly } else if (action.equals(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED)) { 13164b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project mBluetoothHeadsetAudioState = 131718e0a07cc700234f5a02fe10eee9b3ea10db58b3Nick Pelly intent.getIntExtra(BluetoothHeadset.EXTRA_AUDIO_STATE, 13184b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project BluetoothHeadset.STATE_ERROR); 1319796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "mReceiver: HEADSET_AUDIO_STATE_CHANGED_ACTION"); 1320796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "==> new state: " + mBluetoothHeadsetAudioState); 13214b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project updateBluetoothIndication(true); // Also update any visible UI if necessary 1322b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) { 132387258b2b589c3afea4b89b840251012378e0d3b4David Brown if (VDBG) Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED"); 132487258b2b589c3afea4b89b840251012378e0d3b4David Brown if (VDBG) Log.d(LOG_TAG, "- state: " + intent.getStringExtra(Phone.STATE_KEY)); 132587258b2b589c3afea4b89b840251012378e0d3b4David Brown if (VDBG) Log.d(LOG_TAG, "- reason: " 132687258b2b589c3afea4b89b840251012378e0d3b4David Brown + intent.getStringExtra(Phone.STATE_CHANGE_REASON_KEY)); 13274079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project 13284079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // The "data disconnected due to roaming" notification is 13294079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // visible if you've lost data connectivity because you're 13304079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // roaming and you have the "data roaming" feature turned off. 13314079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project boolean disconnectedDueToRoaming = false; 1332b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if ("DISCONNECTED".equals(intent.getStringExtra(Phone.STATE_KEY))) { 1333b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project String reason = intent.getStringExtra(Phone.STATE_CHANGE_REASON_KEY); 1334b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (Phone.REASON_ROAMING_ON.equals(reason)) { 13354079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // We just lost our data connection, and the reason 13364079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // is that we started roaming. This implies that 13374079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // the user has data roaming turned off. 13384079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project disconnectedDueToRoaming = true; 1339b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1340b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 13414079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project mHandler.sendEmptyMessage(disconnectedDueToRoaming 13424079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project ? EVENT_DATA_ROAMING_DISCONNECTED 13434079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project : EVENT_DATA_ROAMING_OK); 1344b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } else if (action.equals(Intent.ACTION_HEADSET_PLUG)) { 1345796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "mReceiver: ACTION_HEADSET_PLUG"); 1346796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, " state: " + intent.getIntExtra("state", 0)); 1347796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, " name: " + intent.getStringExtra("name")); 1348b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mIsHeadsetPlugged = (intent.getIntExtra("state", 0) == 1); 1349b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mHandler.sendMessage(mHandler.obtainMessage(EVENT_WIRED_HEADSET_PLUG, 0)); 1350b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } else if (action.equals(Intent.ACTION_BATTERY_LOW)) { 1351796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "mReceiver: ACTION_BATTERY_LOW"); 1352b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project notifier.sendBatteryLow(); // Play a warning tone if in-call 1353b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) && 1354b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project (mPUKEntryActivity != null)) { 1355b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // if an attempt to un-PUK-lock the device was made, while we're 1356b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // receiving this state change notification, notify the handler. 1357b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has 1358b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // been attempted. 1359b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED, 1360a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville intent.getStringExtra(IccCard.INTENT_KEY_ICC_STATE))); 1361a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) { 1362a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville String newPhone = intent.getStringExtra(Phone.PHONE_NAME_KEY); 1363a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active."); 1364a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville initForNewRadioTechnology(); 1365404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) { 1366404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville handleServiceStateChanged(intent); 1367abeff00b5242e795baa8f5271525c5911f649993Wink Saville } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) { 136879b9f6e30e8402b103f1ec3ed9dda1fcad2b1cd5Tammo Spalink if (phone.getPhoneType() == Phone.PHONE_TYPE_CDMA) { 13694e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp."); 13704e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski // Start Emergency Callback Mode service 13714e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski if (intent.getBooleanExtra("phoneinECMState", false)) { 13724e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski context.startService(new Intent(context, 13734e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski EmergencyCallbackModeService.class)); 13744e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski } 13754e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski } else { 13764e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski Log.e(LOG_TAG, "Error! Emergency Callback Mode not supported for " + 13774e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski phone.getPhoneName() + " phones"); 13784e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski } 1379b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1380b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1381b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1382b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 1383b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 1384b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Broadcast receiver for the ACTION_MEDIA_BUTTON broadcast intent. 1385b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 1386b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * This functionality isn't lumped in with the other intents in 1387b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * PhoneAppBroadcastReceiver because we instantiate this as a totally 1388b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * separate BroadcastReceiver instance, since we need to manually 1389b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * adjust its IntentFilter's priority (to make sure we get these 1390b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * intents *before* the media player.) 1391b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 1392b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private class MediaButtonBroadcastReceiver extends BroadcastReceiver { 1393b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project @Override 1394b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project public void onReceive(Context context, Intent intent) { 1395b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); 1396796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, 1397b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project "MediaButtonBroadcastReceiver.onReceive()... event = " + event); 1398b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if ((event != null) 1399b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project && (event.getKeyCode() == KeyEvent.KEYCODE_HEADSETHOOK) 1400b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project && (event.getAction() == KeyEvent.ACTION_DOWN)) { 1401b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 1402b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (event.getRepeatCount() == 0) { 1403b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Mute ONLY on the initial keypress. 1404796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "MediaButtonBroadcastReceiver: HEADSETHOOK down!"); 1405b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean consumed = PhoneUtils.handleHeadsetHook(phone); 1406796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "==> handleHeadsetHook(): consumed = " + consumed); 1407b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (consumed) { 1408b8df8173e1a0ea8ba89cea984176216201c4d5e7Paul Berman // If a headset is attached and the press is consumed, also update 1409b8df8173e1a0ea8ba89cea984176216201c4d5e7Paul Berman // any UI items (such as an InCallScreen mute button) that may need to 1410b8df8173e1a0ea8ba89cea984176216201c4d5e7Paul Berman // be updated if their state changed. 1411b8df8173e1a0ea8ba89cea984176216201c4d5e7Paul Berman if (isShowingCallScreen()) { 1412b8df8173e1a0ea8ba89cea984176216201c4d5e7Paul Berman mInCallScreen.requestUpdateTouchUi(); 1413b8df8173e1a0ea8ba89cea984176216201c4d5e7Paul Berman } 1414b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project abortBroadcast(); 1415b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 14164079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project } else if (phone.getState() != Phone.State.IDLE) { 14174079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // As for any DOWN events other than the initial press, we consume 14184079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // (and ignore) those too if the phone is in use. (Otherwise the 14194079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // music player will handle them, which would be confusing.) 1420b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project abortBroadcast(); 1421b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1422b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1423b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1424b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1425404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville 1426404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville private void handleServiceStateChanged(Intent intent) { 14274e41cdf8b65434a324f3e83be1095689ddabd153Wink Saville /** 14284e41cdf8b65434a324f3e83be1095689ddabd153Wink Saville * This used to handle updating EriTextWidgetProvider this routine 14294e41cdf8b65434a324f3e83be1095689ddabd153Wink Saville * and and listening for ACTION_SERVICE_STATE_CHANGED intents could 14304e41cdf8b65434a324f3e83be1095689ddabd153Wink Saville * be removed. But leaving just in case it might be needed in the near 14314e41cdf8b65434a324f3e83be1095689ddabd153Wink Saville * future. 14324e41cdf8b65434a324f3e83be1095689ddabd153Wink Saville */ 14334e41cdf8b65434a324f3e83be1095689ddabd153Wink Saville 1434404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville // If service just returned, start sending out the queued messages 1435404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville ServiceState ss = ServiceState.newFromBundle(intent.getExtras()); 1436404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville 1437404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville boolean hasService = true; 1438404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville boolean isCdma = false; 1439404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville String eriText = ""; 1440404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville 1441404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville if (ss != null) { 1442404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville int state = ss.getState(); 144399d10538d840f0103c36dafa44db9f649ca884c8johnwang NotificationMgr.getDefault().updateNetworkSelection(state); 1444404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville switch (state) { 1445404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville case ServiceState.STATE_OUT_OF_SERVICE: 1446404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville case ServiceState.STATE_POWER_OFF: 1447404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville hasService = false; 1448404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville break; 1449404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville } 1450404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville } else { 1451404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville hasService = false; 1452404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville } 1453404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville } 1454af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville 1455af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville public boolean isOtaCallInActiveState() { 1456af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville boolean otaCallActive = false; 1457af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville if (mInCallScreen != null) { 1458af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville otaCallActive = mInCallScreen.isOtaCallInActiveState(); 1459af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 1460af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville if (DBG) Log.d(LOG_TAG, "PhoneApp - isOtaCallInActiveState " + otaCallActive); 1461af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville return otaCallActive; 1462af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 1463af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville 1464af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville public boolean isOtaCallInEndState() { 1465af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville boolean otaCallEnded = false; 1466af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville if (mInCallScreen != null) { 1467af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville otaCallEnded = mInCallScreen.isOtaCallInEndState(); 1468af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 1469af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville if (DBG) Log.d(LOG_TAG, "PhoneApp - isOtaCallInEndState " + otaCallEnded); 1470af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville return otaCallEnded; 1471af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 147273caead845b30580010a7502e4b7551d21dfa265Matthew Sun 147373caead845b30580010a7502e4b7551d21dfa265Matthew Sun // it is safe to call clearOtaState() even if the InCallScreen isn't active 147473caead845b30580010a7502e4b7551d21dfa265Matthew Sun public void clearOtaState() { 147573caead845b30580010a7502e4b7551d21dfa265Matthew Sun if (DBG) Log.d(LOG_TAG, "PhoneApp - clearOtaState ..."); 147673caead845b30580010a7502e4b7551d21dfa265Matthew Sun if ((mInCallScreen != null) 147773caead845b30580010a7502e4b7551d21dfa265Matthew Sun && (mInCallScreen.otaUtils != null)) { 147873caead845b30580010a7502e4b7551d21dfa265Matthew Sun mInCallScreen.otaUtils.cleanOtaScreen(); 147973caead845b30580010a7502e4b7551d21dfa265Matthew Sun if (DBG) Log.d(LOG_TAG, "PhoneApp - clearOtaState clears OTA screen"); 148073caead845b30580010a7502e4b7551d21dfa265Matthew Sun } 148173caead845b30580010a7502e4b7551d21dfa265Matthew Sun } 148273caead845b30580010a7502e4b7551d21dfa265Matthew Sun 148373caead845b30580010a7502e4b7551d21dfa265Matthew Sun // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active 148473caead845b30580010a7502e4b7551d21dfa265Matthew Sun public void dismissOtaDialogs() { 148573caead845b30580010a7502e4b7551d21dfa265Matthew Sun if (DBG) Log.d(LOG_TAG, "PhoneApp - dismissOtaDialogs ..."); 148673caead845b30580010a7502e4b7551d21dfa265Matthew Sun if ((mInCallScreen != null) 148773caead845b30580010a7502e4b7551d21dfa265Matthew Sun && (mInCallScreen.otaUtils != null)) { 148873caead845b30580010a7502e4b7551d21dfa265Matthew Sun mInCallScreen.otaUtils.dismissAllOtaDialogs(); 148973caead845b30580010a7502e4b7551d21dfa265Matthew Sun if (DBG) Log.d(LOG_TAG, "PhoneApp - dismissOtaDialogs clears OTA dialogs"); 149073caead845b30580010a7502e4b7551d21dfa265Matthew Sun } 149173caead845b30580010a7502e4b7551d21dfa265Matthew Sun } 149273caead845b30580010a7502e4b7551d21dfa265Matthew Sun 149373caead845b30580010a7502e4b7551d21dfa265Matthew Sun // it is safe to call clearInCallScreenMode() even if the InCallScreen isn't active 149473caead845b30580010a7502e4b7551d21dfa265Matthew Sun public void clearInCallScreenMode() { 149573caead845b30580010a7502e4b7551d21dfa265Matthew Sun if (DBG) Log.d(LOG_TAG, "PhoneApp - clearInCallScreenMode ..."); 149673caead845b30580010a7502e4b7551d21dfa265Matthew Sun if (mInCallScreen != null) { 149773caead845b30580010a7502e4b7551d21dfa265Matthew Sun mInCallScreen.resetInCallScreenMode(); 149873caead845b30580010a7502e4b7551d21dfa265Matthew Sun } 149973caead845b30580010a7502e4b7551d21dfa265Matthew Sun } 1500b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project} 1501