PhoneApp.java revision 87145810d08c0c89e3197c063a5a90d085e1a308
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; 23b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.bluetooth.BluetoothHeadset; 24b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.content.BroadcastReceiver; 25b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.content.ContentResolver; 26b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.content.Context; 27b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.content.Intent; 28b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.content.IntentFilter; 29d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillaiimport android.content.res.Configuration; 30b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.media.AudioManager; 31b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.net.Uri; 32b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.AsyncResult; 33b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.Binder; 34b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.Handler; 35b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.IBinder; 36b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.IPowerManager; 37b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.LocalPowerManager; 38b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.Message; 39b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.PowerManager; 40b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.RemoteException; 41b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.ServiceManager; 42b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.SystemClock; 43b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.os.SystemProperties; 44b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.preference.PreferenceManager; 45b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.provider.Settings.System; 46404edc94de563aef5fd5ba48be9114a970cb93bbWink Savilleimport android.telephony.ServiceState; 47b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.util.Config; 48b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.util.Log; 49b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.view.KeyEvent; 50b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectimport android.widget.Toast; 51b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 52ee77dd0ec7fcbe315a34ef6625854a8affe31885David Brownimport com.android.internal.telephony.Call; 53a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Savilleimport com.android.internal.telephony.IccCard; 54a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Savilleimport com.android.internal.telephony.MmiCode; 55a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Savilleimport com.android.internal.telephony.Phone; 56a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Savilleimport com.android.internal.telephony.PhoneFactory; 57a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Savilleimport com.android.internal.telephony.TelephonyIntents; 58ee77dd0ec7fcbe315a34ef6625854a8affe31885David Brownimport com.android.internal.telephony.cdma.EriInfo; 596bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillaiimport com.android.phone.OtaUtils.CdmaOtaScreenState; 60a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville 61b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project/** 62b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Top-level Application class for the Phone app. 63b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 64b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Projectpublic class PhoneApp extends Application { 65b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ static final String LOG_TAG = "PhoneApp"; 66796c70c99bc39295bf685061056f06ab8949c742David Brown 67796c70c99bc39295bf685061056f06ab8949c742David Brown /** 68796c70c99bc39295bf685061056f06ab8949c742David Brown * Phone app-wide debug level: 69796c70c99bc39295bf685061056f06ab8949c742David Brown * 0 - no debug logging 70796c70c99bc39295bf685061056f06ab8949c742David Brown * 1 - normal debug logging if ro.debuggable is set (which is true in 71796c70c99bc39295bf685061056f06ab8949c742David Brown * "eng" and "userdebug" builds but not "user" builds) 72796c70c99bc39295bf685061056f06ab8949c742David Brown * 2 - ultra-verbose debug logging 73796c70c99bc39295bf685061056f06ab8949c742David Brown * 74796c70c99bc39295bf685061056f06ab8949c742David Brown * Most individual classes in the phone app have a local DBG constant, 75796c70c99bc39295bf685061056f06ab8949c742David Brown * typically set to 76796c70c99bc39295bf685061056f06ab8949c742David Brown * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1) 77796c70c99bc39295bf685061056f06ab8949c742David Brown * or else 78796c70c99bc39295bf685061056f06ab8949c742David Brown * (PhoneApp.DBG_LEVEL >= 2) 79796c70c99bc39295bf685061056f06ab8949c742David Brown * depending on the desired verbosity. 80796c70c99bc39295bf685061056f06ab8949c742David Brown */ 81796c70c99bc39295bf685061056f06ab8949c742David Brown /* package */ static final int DBG_LEVEL = 1; 82796c70c99bc39295bf685061056f06ab8949c742David Brown 83796c70c99bc39295bf685061056f06ab8949c742David Brown private static final boolean DBG = 84796c70c99bc39295bf685061056f06ab8949c742David Brown (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1); 85796c70c99bc39295bf685061056f06ab8949c742David Brown private static final boolean VDBG = (PhoneApp.DBG_LEVEL >= 2); 86b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 87b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Message codes; see mHandler below. 88b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private static final int EVENT_SIM_ABSENT = 1; 89b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private static final int EVENT_SIM_LOCKED = 2; 90b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private static final int EVENT_SIM_NETWORK_LOCKED = 3; 91b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private static final int EVENT_WIRED_HEADSET_PLUG = 7; 92b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private static final int EVENT_SIM_STATE_CHANGED = 8; 938bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project private static final int EVENT_UPDATE_INCALL_NOTIFICATION = 9; 944079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10; 954079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project private static final int EVENT_DATA_ROAMING_OK = 11; 96404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12; 97b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 98b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // The MMI codes are also used by the InCallScreen. 994079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project public static final int MMI_INITIATE = 51; 1004079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project public static final int MMI_COMPLETE = 52; 1014079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project public static final int MMI_CANCEL = 53; 102b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Don't use message codes larger than 99 here; those are reserved for 103b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // the individual Activities of the Phone UI. 104b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 105b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 106b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Allowable values for the poke lock code (timeout between a user activity and the 107b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * going to sleep), please refer to {@link com.android.server.PowerManagerService} 108b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * for additional reference. 109b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * SHORT uses the short delay for the timeout (SHORT_KEYLIGHT_DELAY, 6 sec) 110b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * MEDIUM uses the medium delay for the timeout (MEDIUM_KEYLIGHT_DELAY, 15 sec) 111b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * DEFAULT is the system-wide default delay for the timeout (1 min) 112b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 113b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project public enum ScreenTimeoutDuration { 114b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project SHORT, 115b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project MEDIUM, 116b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project DEFAULT 117b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 118b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 119b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 120b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Allowable values for the wake lock code. 121b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * SLEEP means the device can be put to sleep. 122b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * PARTIAL means wake the processor, but we display can be kept off. 123b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * FULL means wake both the processor and the display. 124b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 125b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project public enum WakeState { 126b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project SLEEP, 127b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PARTIAL, 128b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project FULL 129b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 130b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 131b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private static PhoneApp sMe; 132b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 133b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // A few important fields we expose to the rest of the package 134b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // directly (rather than thru set/get methods) for efficiency. 135b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Phone phone; 136b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project CallNotifier notifier; 137b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Ringer ringer; 138b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project BluetoothHandsfree mBtHandsfree; 139b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneInterfaceManager phoneMgr; 1408bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project int mBluetoothHeadsetState = BluetoothHeadset.STATE_ERROR; 1414b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project int mBluetoothHeadsetAudioState = BluetoothHeadset.STATE_ERROR; 1428bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project boolean mShowBluetoothIndication = false; 143b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 1440fb2b4b8eff811fd3243aefdf536e7ba2b10f4e9Wink Saville // Internal PhoneApp Call state tracker 1450fb2b4b8eff811fd3243aefdf536e7ba2b10f4e9Wink Saville CdmaPhoneCallState cdmaPhoneCallState; 1460fb2b4b8eff811fd3243aefdf536e7ba2b10f4e9Wink Saville 147b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // The InCallScreen instance (or null if the InCallScreen hasn't been 148b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // created yet.) 149b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private InCallScreen mInCallScreen; 150b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 151b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // The currently-active PUK entry activity and progress dialog. 152b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Normally, these are the Emergency Dialer and the subsequent 153b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // progress dialog. null if there is are no such objects in 154b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // the foreground. 155b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private Activity mPUKEntryActivity; 156b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private ProgressDialog mPUKEntryProgressDialog; 157b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 158b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private boolean mIsSimPinEnabled; 159b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private String mCachedSimPin; 160b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 161b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // True if a wired headset is currently plugged in, based on the state 162b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // from the latest Intent.ACTION_HEADSET_PLUG broadcast we received in 163b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // mReceiver.onReceive(). 164b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private boolean mIsHeadsetPlugged; 165b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 166d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai // True if the keyboard is currently *not* hidden 167d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai // Gets updated whenever there is a Configuration change 168d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai private boolean mIsHardKeyboardOpen; 169d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai 170445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood // True if we are beginning a call, but the phone state has not changed yet 171445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood private boolean mBeginningCall; 172445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood 173445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood // Last phone state seen by updatePhoneState() 174445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood Phone.State mLastPhoneState = Phone.State.IDLE; 175445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood 176b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private WakeState mWakeState = WakeState.SLEEP; 1774472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown private ScreenTimeoutDuration mScreenTimeoutDuration = ScreenTimeoutDuration.DEFAULT; 1784472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown private boolean mIgnoreTouchUserActivity = false; 179b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private IBinder mPokeLockToken = new Binder(); 180b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private IPowerManager mPowerManagerService; 181b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private PowerManager.WakeLock mWakeLock; 182b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private PowerManager.WakeLock mPartialWakeLock; 18358de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown private PowerManager.WakeLock mProximityWakeLock; 184b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private KeyguardManager mKeyguardManager; 185b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private KeyguardManager.KeyguardLock mKeyguardLock; 18687145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood private int mKeyguardDisableCount; 187b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 188b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Broadcast receiver for various intent broadcasts (see onCreate()) 189b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver(); 190b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 191b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Broadcast receiver purely for ACTION_MEDIA_BUTTON broadcasts 192b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private final BroadcastReceiver mMediaButtonReceiver = new MediaButtonBroadcastReceiver(); 193b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 194b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** boolean indicating restoring mute state on InCallScreen.onResume() */ 195b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private boolean mShouldRestoreMuteOnInCallResume; 196b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 197af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // Following are the CDMA OTA information Objects used during OTA Call. 198af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // cdmaOtaProvisionData object store static OTA information that needs 199af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // to be maintained even during Slider open/close scenarios. 200af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // cdmaOtaConfigData object stores configuration info to control visiblity 201af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // of each OTA Screens. 202af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // cdmaOtaScreenState object store OTA Screen State information. 203af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville public OtaUtils.CdmaOtaProvisionData cdmaOtaProvisionData; 204af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville public OtaUtils.CdmaOtaConfigData cdmaOtaConfigData; 205af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville public OtaUtils.CdmaOtaScreenState cdmaOtaScreenState; 206af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville 207b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 208b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Set the restore mute state flag. Used when we are setting the mute state 209b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * OUTSIDE of user interaction {@link PhoneUtils#startNewCall(Phone)} 210b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 211b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /*package*/void setRestoreMuteOnInCallResume (boolean mode) { 212b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mShouldRestoreMuteOnInCallResume = mode; 213b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 214b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 215b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 216b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Get the restore mute state flag. 217b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * This is used by the InCallScreen {@link InCallScreen#onResume()} to figure 218b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * out if we need to restore the mute state for the current active call. 219b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 220b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /*package*/boolean getRestoreMuteOnInCallResume () { 221b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return mShouldRestoreMuteOnInCallResume; 222b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 223b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 224b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Handler mHandler = new Handler() { 225b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project @Override 226b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project public void handleMessage(Message msg) { 227b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project switch (msg.what) { 228b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case EVENT_SIM_LOCKED: 229b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// mIsSimPinEnabled = true; 230b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// 231b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// if (Config.LOGV) Log.v(LOG_TAG, "show sim unlock panel"); 232b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// SimPinUnlockPanel pinUnlockPanel = new SimPinUnlockPanel( 233b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// PhoneApp.getInstance()); 234b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// pinUnlockPanel.show(); 235b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 236b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 237b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case EVENT_SIM_ABSENT: 238b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// Don't need this now that the lock screen handles this case 239b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// if (Config.LOGV) Log.v(LOG_TAG, "show sim missing panel"); 240b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// SimMissingPanel missingPanel = new SimMissingPanel( 241b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// PhoneApp.getInstance()); 242b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project// missingPanel.show(); 243b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 244b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 245b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case EVENT_SIM_NETWORK_LOCKED: 24609328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown if (getResources().getBoolean(R.bool.ignore_sim_network_locked_events)) { 24709328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown // Some products don't have the concept of a "SIM network lock" 24809328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; " 24909328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown + "not showing 'SIM network unlock' PIN entry screen"); 25009328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown } else { 25109328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown // Normal case: show the "SIM network unlock" PIN entry screen. 25209328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown // The user won't be able to do anything else until 25309328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown // they enter a valid SIM network PIN. 25409328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown Log.i(LOG_TAG, "show sim depersonal panel"); 25509328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown IccNetworkDepersonalizationPanel ndpPanel = 25609328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown new IccNetworkDepersonalizationPanel(PhoneApp.getInstance()); 25709328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown ndpPanel.show(); 25809328f1bd9acf6b16a9cb79d7d9fa59d322ac6c2David Brown } 259b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 260b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 2618bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project case EVENT_UPDATE_INCALL_NOTIFICATION: 2628bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // Tell the NotificationMgr to update the "ongoing 2638bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // call" icon in the status bar, if necessary. 2648bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // Currently, this is triggered by a bluetooth headset 2658bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // state change (since the status bar icon needs to 2668bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // turn blue when bluetooth is active.) 2678bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project NotificationMgr.getDefault().updateInCallNotification(); 2688bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project break; 2698bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project 2704079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project case EVENT_DATA_ROAMING_DISCONNECTED: 2714079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project NotificationMgr.getDefault().showDataDisconnectedRoaming(); 272b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 2734079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project 2744079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project case EVENT_DATA_ROAMING_OK: 2754079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project NotificationMgr.getDefault().hideDataDisconnectedRoaming(); 2764079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project break; 2774079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project 278b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case MMI_COMPLETE: 279b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project onMMIComplete((AsyncResult) msg.obj); 280b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 281b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 282b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case MMI_CANCEL: 283b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.cancelMmiCode(phone); 284b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 285b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 286b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case EVENT_WIRED_HEADSET_PLUG: 287b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Since the presence of a wired headset or bluetooth affects the 288b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // speakerphone, update the "speaker" state. We ONLY want to do 289b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // this on the wired headset connect / disconnect events for now 290b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // though, so we're only triggering on EVENT_WIRED_HEADSET_PLUG. 291425b8e3c9846d5e0e76466604b35cad8856d79deEric Laurent // If in call screen is showing, let InCallScreen handle the speaker. 2924a8cbde060e7876a5560346215c11078a9efc90eEric Laurent 2934a8cbde060e7876a5560346215c11078a9efc90eEric Laurent Phone.State phoneState = phone.getState(); 2944a8cbde060e7876a5560346215c11078a9efc90eEric Laurent // Do not change speaker state if phone is not off hook 2954a8cbde060e7876a5560346215c11078a9efc90eEric Laurent if (phoneState == Phone.State.OFFHOOK) { 2964a8cbde060e7876a5560346215c11078a9efc90eEric Laurent if (!isShowingCallScreen() && 2974a8cbde060e7876a5560346215c11078a9efc90eEric Laurent (mBtHandsfree == null || !mBtHandsfree.isAudioOn())) { 2984a8cbde060e7876a5560346215c11078a9efc90eEric Laurent if (!isHeadsetPlugged()) { 2994a8cbde060e7876a5560346215c11078a9efc90eEric Laurent // if the state is "not connected", restore the speaker state. 3004a8cbde060e7876a5560346215c11078a9efc90eEric Laurent PhoneUtils.restoreSpeakerMode(getApplicationContext()); 3014a8cbde060e7876a5560346215c11078a9efc90eEric Laurent } else { 3024a8cbde060e7876a5560346215c11078a9efc90eEric Laurent // if the state is "connected", force the speaker off without 3034a8cbde060e7876a5560346215c11078a9efc90eEric Laurent // storing the state. 3044a8cbde060e7876a5560346215c11078a9efc90eEric Laurent PhoneUtils.turnOnSpeaker(getApplicationContext(), false, false); 3054a8cbde060e7876a5560346215c11078a9efc90eEric Laurent } 306425b8e3c9846d5e0e76466604b35cad8856d79deEric Laurent } 307b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 308d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai // Update the Proximity sensor based on headset state 3094a8cbde060e7876a5560346215c11078a9efc90eEric Laurent updateProximitySensorMode(phoneState); 310b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 311b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 312b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case EVENT_SIM_STATE_CHANGED: 313b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Marks the event where the SIM goes into ready state. 314b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Right now, this is only used for the PUK-unlocking 315b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // process. 316a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville if (msg.obj.equals(IccCard.INTENT_VALUE_ICC_READY)) { 317b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // when the right event is triggered and there 318b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // are UI objects in the foreground, we close 319b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // them to display the lock panel. 320b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mPUKEntryActivity != null) { 321b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPUKEntryActivity.finish(); 322b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPUKEntryActivity = null; 323b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 324b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mPUKEntryProgressDialog != null) { 325b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPUKEntryProgressDialog.dismiss(); 326b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPUKEntryProgressDialog = null; 327b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 328b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 329b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 330404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville 331404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville case EVENT_UNSOL_CDMA_INFO_RECORD: 332404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville //TODO: handle message here; 333404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville break; 334b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 335b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 336b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project }; 337b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 338b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project public PhoneApp() { 339b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project sMe = this; 340b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 341b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 342b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project @Override 343b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project public void onCreate() { 344b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (Config.LOGV) Log.v(LOG_TAG, "onCreate()..."); 345b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 346b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project ContentResolver resolver = getContentResolver(); 347b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 348b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (phone == null) { 349b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Initialize the telephony framework 350b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneFactory.makeDefaultPhones(this); 351b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 352b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Get the default phone 353b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project phone = PhoneFactory.getDefaultPhone(); 354b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 355b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project NotificationMgr.init(this); 356b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 357b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project phoneMgr = new PhoneInterfaceManager(this, phone); 358c9d9ed30aa547b79b81adc13a4d148a003b6ee62w 359c9d9ed30aa547b79b81adc13a4d148a003b6ee62w if (phone.getPhoneName().equals("CDMA")) { 360c9d9ed30aa547b79b81adc13a4d148a003b6ee62w // Create an instance of CdmaPhoneCallState and initialize it to IDLE 361c9d9ed30aa547b79b81adc13a4d148a003b6ee62w cdmaPhoneCallState = new CdmaPhoneCallState(); 362c9d9ed30aa547b79b81adc13a4d148a003b6ee62w cdmaPhoneCallState.CdmaPhoneCallStateInit(); 363c9d9ed30aa547b79b81adc13a4d148a003b6ee62w } 364c9d9ed30aa547b79b81adc13a4d148a003b6ee62w 365b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (getSystemService(Context.BLUETOOTH_SERVICE) != null) { 366b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mBtHandsfree = new BluetoothHandsfree(this, phone); 367b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project startService(new Intent(this, BluetoothHeadsetService.class)); 368b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } else { 369b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Device is not bluetooth capable 370b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mBtHandsfree = null; 371b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 372b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 373b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project ringer = new Ringer(phone); 374b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 375b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // before registering for phone state changes 376b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); 377b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK 378b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project | PowerManager.ACQUIRE_CAUSES_WAKEUP 379b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project | PowerManager.ON_AFTER_RELEASE, LOG_TAG); 380b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // lock used to keep the processor awake, when we don't care for the display. 381b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPartialWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK 382b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project | PowerManager.ON_AFTER_RELEASE, LOG_TAG); 38358de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown // Wake lock used to control proximity sensor behavior. 38458de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown if ((pm.getSupportedWakeLockFlags() 38558de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown & PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK) != 0x0) { 38658de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown mProximityWakeLock = 38758de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, LOG_TAG); 38858de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown } 38958de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown if (DBG) Log.d(LOG_TAG, "mProximityWakeLock: " + mProximityWakeLock); 39058de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown 391b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); 392b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mKeyguardLock = mKeyguardManager.newKeyguardLock(LOG_TAG); 393b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 394b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // get a handle to the service so that we can use it later when we 395b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // want to set the poke lock. 396b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPowerManagerService = IPowerManager.Stub.asInterface( 397b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project ServiceManager.getService("power")); 398b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 399b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project notifier = new CallNotifier(this, phone, ringer, mBtHandsfree); 400b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 401a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville // register for ICC status 402a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville IccCard sim = phone.getIccCard(); 403b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (sim != null) { 404a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville if (Config.LOGV) Log.v(LOG_TAG, "register for ICC status"); 405b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project sim.registerForAbsent(mHandler, EVENT_SIM_ABSENT, null); 406b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project sim.registerForLocked(mHandler, EVENT_SIM_LOCKED, null); 407b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null); 408b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 409b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 410b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // register for MMI/USSD 411fa3fbeedf018e40f8d6696a382bbf316219cf4aeReli Tal if (phone.getPhoneName().equals("GSM")) { 412fa3fbeedf018e40f8d6696a382bbf316219cf4aeReli Tal phone.registerForMmiComplete(mHandler, MMI_COMPLETE, null); 413fa3fbeedf018e40f8d6696a382bbf316219cf4aeReli Tal } 414b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 415b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // register connection tracking to PhoneUtils 416b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.initializeConnectionHandler(phone); 417b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 418b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Register for misc other intent broadcasts. 419b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project IntentFilter intentFilter = 420b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED); 42118e0a07cc700234f5a02fe10eee9b3ea10db58b3Nick Pelly intentFilter.addAction(BluetoothHeadset.ACTION_STATE_CHANGED); 42218e0a07cc700234f5a02fe10eee9b3ea10db58b3Nick Pelly intentFilter.addAction(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED); 423b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED); 424b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project intentFilter.addAction(Intent.ACTION_HEADSET_PLUG); 425b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project intentFilter.addAction(Intent.ACTION_BATTERY_LOW); 426b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); 427a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED); 428404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); 429abeff00b5242e795baa8f5271525c5911f649993Wink Saville intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); 430b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project registerReceiver(mReceiver, intentFilter); 431b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 432b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Use a separate receiver for ACTION_MEDIA_BUTTON broadcasts, 433b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // since we need to manually adjust its priority (to make sure 434b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // we get these intents *before* the media player.) 435b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project IntentFilter mediaButtonIntentFilter = 436b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project new IntentFilter(Intent.ACTION_MEDIA_BUTTON); 437b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 438b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Make sure we're higher priority than the media player's 439b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // MediaButtonIntentReceiver (which currently has the default 440b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // priority of zero; see apps/Music/AndroidManifest.xml.) 441b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mediaButtonIntentFilter.setPriority(1); 442b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 443b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project registerReceiver(mMediaButtonReceiver, mediaButtonIntentFilter); 444b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 445b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project //set the default values for the preferences in the phone. 446b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PreferenceManager.setDefaultValues(this, R.xml.network_setting, false); 447cd0189299f484dcbd51400b994daf585923e9e8dDavid Krause 448cd0189299f484dcbd51400b994daf585923e9e8dDavid Krause PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false); 449b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 450b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Make sure the audio mode (along with some 451b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // audio-mode-related state of our own) is initialized 452b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // correctly, given the current state of the phone. 453b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project switch (phone.getState()) { 454b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case IDLE: 455b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (DBG) Log.d(LOG_TAG, "Resetting audio state/mode: IDLE"); 456b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.setAudioControlState(PhoneUtils.AUDIO_IDLE); 457b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.setAudioMode(this, AudioManager.MODE_NORMAL); 458b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 459b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case RINGING: 460b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (DBG) Log.d(LOG_TAG, "Resetting audio state/mode: RINGING"); 461b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.setAudioControlState(PhoneUtils.AUDIO_RINGING); 462b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.setAudioMode(this, AudioManager.MODE_RINGTONE); 463b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 464b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case OFFHOOK: 465b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (DBG) Log.d(LOG_TAG, "Resetting audio state/mode: OFFHOOK"); 466b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.setAudioControlState(PhoneUtils.AUDIO_OFFHOOK); 467b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.setAudioMode(this, AudioManager.MODE_IN_CALL); 468b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 469b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 470b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 471b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 472af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville if (phone.getPhoneName().equals("CDMA")) { 473af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData(); 474af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData(); 475af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState(); 476af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 477af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville 478b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // XXX pre-load the SimProvider so that it's ready 479a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville resolver.getType(Uri.parse("content://icc/adn")); 480b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 481b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // start with the default value to set the mute state. 482b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mShouldRestoreMuteOnInCallResume = false; 483404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville 4840fb2b4b8eff811fd3243aefdf536e7ba2b10f4e9Wink Saville // Register for Cdma Information Records 4850fb2b4b8eff811fd3243aefdf536e7ba2b10f4e9Wink Saville // TODO(Moto): Merge 4860fb2b4b8eff811fd3243aefdf536e7ba2b10f4e9Wink Saville // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null); 4870fb2b4b8eff811fd3243aefdf536e7ba2b10f4e9Wink Saville 4887fe7f7e57aaa38290c37ab48867d34a279d198f3w // Read TTY settings and store it into BP NV. 4897fe7f7e57aaa38290c37ab48867d34a279d198f3w // AP owns (i.e. stores) the TTY setting in AP settings database and pushes the setting 4907fe7f7e57aaa38290c37ab48867d34a279d198f3w // to BP at power up (BP does not need to make the TTY setting persistent storage). 4917fe7f7e57aaa38290c37ab48867d34a279d198f3w // This way, there is a single owner (i.e AP) for the TTY setting in the phone. 4927fe7f7e57aaa38290c37ab48867d34a279d198f3w if (phone.getPhoneName().equals("CDMA")) { 4937fe7f7e57aaa38290c37ab48867d34a279d198f3w int settingsTtyMode = android.provider.Settings.Secure.getInt( 4947fe7f7e57aaa38290c37ab48867d34a279d198f3w phone.getContext().getContentResolver(), 4957fe7f7e57aaa38290c37ab48867d34a279d198f3w android.provider.Settings.Secure.PREFERRED_TTY_MODE, 4967fe7f7e57aaa38290c37ab48867d34a279d198f3w Phone.TTY_MODE_OFF); 4977fe7f7e57aaa38290c37ab48867d34a279d198f3w phone.setTTYMode(settingsTtyMode, null); 4987fe7f7e57aaa38290c37ab48867d34a279d198f3w } 499b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 500b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 501d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai @Override 502d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai public void onConfigurationChanged(Configuration newConfig) { 503d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) { 504d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai mIsHardKeyboardOpen = true; 505d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai } else { 506d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai mIsHardKeyboardOpen = false; 507d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai } 508d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai 509d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai // Update the Proximity sensor based on keyboard state 510d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai updateProximitySensorMode(phone.getState()); 511d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai super.onConfigurationChanged(newConfig); 512d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai } 513d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai 514b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 515b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Returns the singleton instance of the PhoneApp. 516b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 517b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project static PhoneApp getInstance() { 518b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return sMe; 519b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 520b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 521b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Ringer getRinger() { 522b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return ringer; 523b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 524b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 525b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project BluetoothHandsfree getBluetoothHandsfree() { 526b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return mBtHandsfree; 527b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 528b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 529b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project static Intent createCallLogIntent() { 530b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Intent intent = new Intent(Intent.ACTION_VIEW, null); 531b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project intent.setType("vnd.android.cursor.dir/calls"); 532b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return intent; 533b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 534b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 535b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 536b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Return an Intent that can be used to bring up the in-call screen. 537b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 538b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * This intent can only be used from within the Phone app, since the 539b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * InCallScreen is not exported from our AndroidManifest. 540b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 541b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ static Intent createInCallIntent() { 542b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Intent intent = new Intent(Intent.ACTION_MAIN, null); 543b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 544b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS 545b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project | Intent.FLAG_ACTIVITY_NO_USER_ACTION); 546b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project intent.setClassName("com.android.phone", getCallScreenClassName()); 547b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return intent; 548b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 549b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 550b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 551b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Variation of createInCallIntent() that also specifies whether the 552b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * DTMF dialpad should be initially visible when the InCallScreen 553b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * comes up. 554b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 555b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ static Intent createInCallIntent(boolean showDialpad) { 556b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Intent intent = createInCallIntent(); 557b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project intent.putExtra(InCallScreen.SHOW_DIALPAD_EXTRA, showDialpad); 558b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return intent; 559b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 560b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 561b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project static String getCallScreenClassName() { 562b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return InCallScreen.class.getName(); 563b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 564b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 565b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 566b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Starts the InCallScreen Activity. 567b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 568b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project void displayCallScreen() { 569796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "displayCallScreen()..."); 570b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project startActivity(createInCallIntent()); 571b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Profiler.callScreenRequested(); 572b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 573b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 574b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 575b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Helper function to check for one special feature of the CALL key: 576b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Normally, when the phone is idle, CALL takes you to the call log 577b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * (see the handler for KEYCODE_CALL in PhoneWindow.onKeyUp().) 578b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * But if the phone is in use (either off-hook or ringing) we instead 579b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * handle the CALL button by taking you to the in-call UI. 580b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 581b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @return true if we intercepted the CALL keypress (i.e. the phone 582b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * was in use) 583b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 584b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @see DialerActivity#onCreate 585b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 586b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean handleInCallOrRinging() { 587b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (phone.getState() != Phone.State.IDLE) { 588b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Phone is OFFHOOK or RINGING. 589b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (DBG) Log.v(LOG_TAG, 590b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project "handleInCallOrRinging: show call screen"); 591b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project displayCallScreen(); 592b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return true; 593b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 594b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return false; 595b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 596b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 597b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean isSimPinEnabled() { 598b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return mIsSimPinEnabled; 599b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 600b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 601b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean authenticateAgainstCachedSimPin(String pin) { 602b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return (mCachedSimPin != null && mCachedSimPin.equals(pin)); 603b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 604b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 605b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project void setCachedSimPin(String pin) { 606b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mCachedSimPin = pin; 607b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 608b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 609b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project void setInCallScreenInstance(InCallScreen inCallScreen) { 610b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mInCallScreen = inCallScreen; 611b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 612b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 613b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 614b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @return true if the in-call UI is running as the foreground 615b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * activity. (In other words, from the perspective of the 616b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * InCallScreen activity, return true between onResume() and 617b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * onPause().) 618b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 619b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Note this method will return false if the screen is currently off, 620b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * even if the InCallScreen *was* in the foreground just before the 621b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * screen turned off. (This is because the foreground activity is 622b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * always "paused" while the screen is off.) 623b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 624b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean isShowingCallScreen() { 625b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mInCallScreen == null) return false; 626b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return mInCallScreen.isForegroundActivity(); 627b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 628b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 629b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 630b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Dismisses the in-call UI. 631b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 632b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * This also ensures that you won't be able to get back to the in-call 633b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * UI via the BACK button (since this call removes the InCallScreen 634b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * from the activity history.) 635af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * For OTA Call, it call InCallScreen api to handle OTA Call End scenario 636af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * to display OTA Call End screen. 637b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 638b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project void dismissCallScreen() { 639b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mInCallScreen != null) { 6406bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai if (mInCallScreen.isOtaCallInActiveState() 6416bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai || mInCallScreen.isOtaCallInEndState() 6426bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai || ((cdmaOtaScreenState != null) 6436bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai && (cdmaOtaScreenState.otaScreenState 6446bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai != CdmaOtaScreenState.OtaScreenState.OTA_STATUS_UNDEFINED))) { 645af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // TODO(Moto): During OTA Call, display should not become dark to 646af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // allow user to see OTA UI update. Phone app needs to hold a SCREEN_DIM_WAKE_LOCK 647af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville // wake lock during the entire OTA call. 648af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville wakeUpScreen(); 6496bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai // If InCallScreen is not in foreground we resume it to show the OTA call end screen 6506bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai // Fire off the InCallScreen intent 6516bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai displayCallScreen(); 6526bdc4d568f008ca476c744d52056dde3e8db27f8Abhishek Pillai 653af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville mInCallScreen.handleOtaCallEnd(); 654af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville return; 655af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } else { 656af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville mInCallScreen.finish(); 657af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 658b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 659b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 660b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 661b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 662af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * Handle OTA events 663af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * 664af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * When OTA call is active and display becomes dark, then CallNotifier will 665af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * handle OTA Events by calling this api which then calls OtaUtil function. 666af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville */ 667af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville void handleOtaEvents(Message msg) { 668af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville 669af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville if (DBG) Log.d(LOG_TAG, "Enter handleOtaEvents"); 670af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville if ((mInCallScreen != null) && (!isShowingCallScreen())) { 671af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville if (mInCallScreen.otaUtils != null) { 672af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville mInCallScreen.otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj); 673af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 674af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 675af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 676af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville 677af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville 678af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville /** 679b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Sets the activity responsible for un-PUK-blocking the device 680b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * so that we may close it when we receive a positive result. 681b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * mPUKEntryActivity is also used to indicate to the device that 682b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * we are trying to un-PUK-lock the phone. In other words, iff 683b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * it is NOT null, then we are trying to unlock and waiting for 684b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * the SIM to move to READY state. 685b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 686b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @param activity is the activity to close when PUK has 687b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * finished unlocking. Can be set to null to indicate the unlock 688b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * or SIM READYing process is over. 689b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 690b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project void setPukEntryActivity(Activity activity) { 691b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPUKEntryActivity = activity; 692b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 693b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 694b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Activity getPUKEntryActivity() { 695b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return mPUKEntryActivity; 696b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 697b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 698b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 699b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Sets the dialog responsible for notifying the user of un-PUK- 700b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * blocking - SIM READYing progress, so that we may dismiss it 701b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * when we receive a positive result. 702b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 703b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @param dialog indicates the progress dialog informing the user 704b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * of the state of the device. Dismissed upon completion of 705b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * READYing process 706b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 707b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project void setPukEntryProgressDialog(ProgressDialog dialog) { 708b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPUKEntryProgressDialog = dialog; 709b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 710b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 711b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project ProgressDialog getPUKEntryProgressDialog() { 712b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return mPUKEntryProgressDialog; 713b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 714b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 715b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 716b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Disables the keyguard. This is used by the phone app to allow 717b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * interaction with the Phone UI when the keyguard would otherwise be 718b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * active (like receiving an incoming call while the device is 719b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * locked.) 720b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 721b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Any call to this method MUST be followed (eventually) 722b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * by a corresponding reenableKeyguard() call. 723b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 724b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ void disableKeyguard() { 725b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (DBG) Log.d(LOG_TAG, "disable keyguard"); 726b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // if (DBG) Log.d(LOG_TAG, "disableKeyguard()...", new Throwable("stack dump")); 72787145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood synchronized (mKeyguardLock) { 72887145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood if (mKeyguardDisableCount++ == 0) { 72987145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood mKeyguardLock.disableKeyguard(); 73087145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood } 73187145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood } 732b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 733b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 734b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 735b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Re-enables the keyguard after a previous disableKeyguard() call. 736b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 737b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Any call to this method MUST correspond to (i.e. be balanced with) 738b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * a previous disableKeyguard() call. 739b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 740b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ void reenableKeyguard() { 741b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (DBG) Log.d(LOG_TAG, "re-enable keyguard"); 742b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // if (DBG) Log.d(LOG_TAG, "reenableKeyguard()...", new Throwable("stack dump")); 74387145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood synchronized (mKeyguardLock) { 74487145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood if (mKeyguardDisableCount > 0) { 74587145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood if (--mKeyguardDisableCount == 0) { 74687145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood mKeyguardLock.reenableKeyguard(); 74787145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood } 74887145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood } else { 74987145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood Log.e(LOG_TAG, "mKeyguardDisableCount is already zero"); 75087145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood } 75187145810d08c0c89e3197c063a5a90d085e1a308Mike Lockwood } 752b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 753b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 754b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 755b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Controls how quickly the screen times out. 756b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 757b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * The poke lock controls how long it takes before the screen powers 758b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * down, and therefore has no immediate effect when the current 759b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * WakeState (see {@link PhoneApp#requestWakeState}) is FULL. 760b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * If we're in a state where the screen *is* allowed to turn off, 761b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * though, the poke lock will determine the timeout interval (long or 762b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * short). 763b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 764b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @param shortPokeLock tells the device the timeout duration to use 765b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * before going to sleep 766b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * {@link com.android.server.PowerManagerService#SHORT_KEYLIGHT_DELAY}. 767b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 768b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ void setScreenTimeout(ScreenTimeoutDuration duration) { 769796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "setScreenTimeout(" + duration + ")..."); 770b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 771b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // make sure we don't set the poke lock repeatedly so that we 772b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // avoid triggering the userActivity calls in 773b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // PowerManagerService.setPokeLock(). 7744472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown if (duration == mScreenTimeoutDuration) { 775b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return; 776b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 777039a8e51aa4a3ed27ad788dd5f1e043446517d92Mike Lockwood // stick with default timeout if we are using the proximity sensor 778039a8e51aa4a3ed27ad788dd5f1e043446517d92Mike Lockwood if (proximitySensorModeEnabled()) { 779039a8e51aa4a3ed27ad788dd5f1e043446517d92Mike Lockwood return; 780039a8e51aa4a3ed27ad788dd5f1e043446517d92Mike Lockwood } 7814472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown mScreenTimeoutDuration = duration; 7824472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown updatePokeLock(); 7834472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown } 784b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 7854472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown /** 7864472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * Update the state of the poke lock held by the phone app, 7874472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * based on the current desired screen timeout and the 7884472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * current "ignore user activity on touch" flag. 7894472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown */ 7904472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown private void updatePokeLock() { 791b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // This is kind of convoluted, but the basic thing to remember is 792b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // that the poke lock just sends a message to the screen to tell 793b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // it to stay on for a while. 794b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // The default is 0, for a long timeout and should be set that way 795b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // when we are heading back into a the keyguard / screen off 796b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // state, and also when we're trying to keep the screen alive 797b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // while ringing. We'll also want to ignore the cheek events 798b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // regardless of the timeout duration. 799b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // The short timeout is really used whenever we want to give up 800b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // the screen lock, such as when we're in call. 801b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project int pokeLockSetting = LocalPowerManager.POKE_LOCK_IGNORE_CHEEK_EVENTS; 8024472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown switch (mScreenTimeoutDuration) { 803b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case SHORT: 804b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Set the poke lock to timeout the display after a short 805b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // timeout (5s). This ensures that the screen goes to sleep 806b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // as soon as acceptably possible after we the wake lock 807b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // has been released. 808b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project pokeLockSetting |= LocalPowerManager.POKE_LOCK_SHORT_TIMEOUT; 809b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 810b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 811b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case MEDIUM: 812b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Set the poke lock to timeout the display after a medium 813b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // timeout (15s). This ensures that the screen goes to sleep 814b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // as soon as acceptably possible after we the wake lock 815b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // has been released. 816b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project pokeLockSetting |= LocalPowerManager.POKE_LOCK_MEDIUM_TIMEOUT; 817b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 818b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 819b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case DEFAULT: 820b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project default: 821b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // set the poke lock to timeout the display after a long 822b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // delay by default. 823b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // TODO: it may be nice to be able to disable cheek presses 824b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // for long poke locks (emergency dialer, for instance). 825b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 826b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 827b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 8284472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown if (mIgnoreTouchUserActivity) { 8294472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown pokeLockSetting |= LocalPowerManager.POKE_LOCK_IGNORE_TOUCH_AND_CHEEK_EVENTS; 8304472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown } 8314472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown 832b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Send the request 833b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project try { 834b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPowerManagerService.setPokeLock(pokeLockSetting, mPokeLockToken, LOG_TAG); 835b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } catch (RemoteException e) { 8364472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown Log.w(LOG_TAG, "mPowerManagerService.setPokeLock() failed: " + e); 837b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 838b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 839b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 840b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 841b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Controls whether or not the screen is allowed to sleep. 842b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 843b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Once sleep is allowed (WakeState is SLEEP), it will rely on the 844b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * settings for the poke lock to determine when to timeout and let 845b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * the device sleep {@link PhoneApp#setScreenTimeout}. 846b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 847b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @param ws tells the device to how to wake. 848b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 849b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ void requestWakeState(WakeState ws) { 850796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")..."); 851b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mWakeState != ws) { 852b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project switch (ws) { 853b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case PARTIAL: 854b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // acquire the processor wake lock, and release the FULL 855b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // lock if it is being held. 856b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPartialWakeLock.acquire(); 857b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mWakeLock.isHeld()) { 858b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mWakeLock.release(); 859b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 860b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 861b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case FULL: 862b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // acquire the full wake lock, and release the PARTIAL 863b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // lock if it is being held. 864b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mWakeLock.acquire(); 865b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mPartialWakeLock.isHeld()) { 866b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPartialWakeLock.release(); 867b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 868b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 869b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project case SLEEP: 870b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project default: 871b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // release both the PARTIAL and FULL locks. 872b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mWakeLock.isHeld()) { 873b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mWakeLock.release(); 874b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 875b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mPartialWakeLock.isHeld()) { 876b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPartialWakeLock.release(); 877b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 878b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project break; 879b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 880b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mWakeState = ws; 881b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 882b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 883b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 884b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 885b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * If we are not currently keeping the screen on, then poke the power 886b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * manager to wake up the screen for the user activity timeout duration. 887b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 888b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ void wakeUpScreen() { 889b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (mWakeState == WakeState.SLEEP) { 890b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (DBG) Log.d(LOG_TAG, "pulse screen lock"); 891b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project try { 892b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPowerManagerService.userActivityWithForce(SystemClock.uptimeMillis(), false, true); 893b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } catch (RemoteException ex) { 894b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Ignore -- the system process is dead. 895b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 896b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 897b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 898b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 899b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 900b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Sets the wake state and screen timeout based on the current state 901b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * of the phone, and the current state of the in-call UI. 902b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 903b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * This method is a "UI Policy" wrapper around 904b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * {@link PhoneApp#requestWakeState} and {@link PhoneApp#setScreenTimeout}. 905b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 906b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * It's safe to call this method regardless of the state of the Phone 907b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * (e.g. whether or not it's idle), and regardless of the state of the 908b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Phone UI (e.g. whether or not the InCallScreen is active.) 909b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 910b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ void updateWakeState() { 911b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Phone.State state = phone.getState(); 912b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 913b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // True if the in-call UI is the foreground activity. 914b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // (Note this will be false if the screen is currently off, 915b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // since in that case *no* activity is in the foreground.) 916b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean isShowingCallScreen = isShowingCallScreen(); 917b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 918b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // True if the InCallScreen's DTMF dialer is currently opened. 919b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // (Note this does NOT imply whether or not the InCallScreen 920b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // itself is visible.) 921b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean isDialerOpened = (mInCallScreen != null) && mInCallScreen.isDialerOpened(); 922b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 923b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // True if the speakerphone is in use. (If so, we *always* use 924b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // the default timeout. Since the user is obviously not holding 925b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // the phone up to his/her face, we don't need to worry about 926b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // false touches, and thus don't need to turn the screen off so 927b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // aggressively.) 928b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Note that we need to make a fresh call to this method any 929b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // time the speaker state changes. (That happens in 930b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // PhoneUtils.turnOnSpeaker().) 931b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean isSpeakerInUse = (state == Phone.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this); 932b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 933b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // TODO (bug 1440854): The screen timeout *might* also need to 934b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // depend on the bluetooth state, but this isn't as clear-cut as 935b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // the speaker state (since while using BT it's common for the 936b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // user to put the phone straight into a pocket, in which case the 937b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // timeout should probably still be short.) 938b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 939796c70c99bc39295bf685061056f06ab8949c742David Brown if (DBG) Log.d(LOG_TAG, "updateWakeState: callscreen " + isShowingCallScreen 940796c70c99bc39295bf685061056f06ab8949c742David Brown + ", dialer " + isDialerOpened 941796c70c99bc39295bf685061056f06ab8949c742David Brown + ", speaker " + isSpeakerInUse + "..."); 942b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 943b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 944b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // (1) Set the screen timeout. 945b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 946b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Note that the "screen timeout" value we determine here is 947b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // meaningless if the screen is forced on (see (2) below.) 948b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 949b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (!isShowingCallScreen || isSpeakerInUse) { 950b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Use the system-wide default timeout. 951b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project setScreenTimeout(ScreenTimeoutDuration.DEFAULT); 952b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } else { 953b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // We're on the in-call screen, and *not* using the speakerphone. 954b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (isDialerOpened) { 955b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // The DTMF dialpad is up. This case is special because 956b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // the in-call UI has its own "touch lock" mechanism to 957b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // disable the dialpad after a very short amount of idle 958b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // time (to avoid false touches from the user's face while 959b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // in-call.) 960b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 961b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // In this case the *physical* screen just uses the 962b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // system-wide default timeout. 963b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project setScreenTimeout(ScreenTimeoutDuration.DEFAULT); 964b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } else { 965b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // We're on the in-call screen, and not using the DTMF dialpad. 966b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // There's actually no touchable UI onscreen at all in 967b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // this state. Also, the user is (most likely) not 968b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // looking at the screen at all, since they're probably 969b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // holding the phone up to their face. Here we use a 970b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // special screen timeout value specific to the in-call 971b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // screen, purely to save battery life. 972b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project setScreenTimeout(ScreenTimeoutDuration.MEDIUM); 973b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 974b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 975b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 976b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 977b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // (2) Decide whether to force the screen on or not. 978b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 979ee77dd0ec7fcbe315a34ef6625854a8affe31885David Brown // Force the screen to be on if the phone is ringing or dialing, 980ee77dd0ec7fcbe315a34ef6625854a8affe31885David Brown // or if we're displaying the "Call ended" UI for a connection in 981ee77dd0ec7fcbe315a34ef6625854a8affe31885David Brown // the "disconnected" state. 982b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // 983b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean isRinging = (state == Phone.State.RINGING); 984ee77dd0ec7fcbe315a34ef6625854a8affe31885David Brown boolean isDialing = (phone.getForegroundCall().getState() == Call.State.DIALING); 985b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean showingDisconnectedConnection = 986b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.hasDisconnectedConnections(phone) && isShowingCallScreen; 987ee77dd0ec7fcbe315a34ef6625854a8affe31885David Brown boolean keepScreenOn = isRinging || isDialing || showingDisconnectedConnection; 988b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (DBG) Log.d(LOG_TAG, "updateWakeState: keepScreenOn = " + keepScreenOn 989b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project + " (isRinging " + isRinging 990ee77dd0ec7fcbe315a34ef6625854a8affe31885David Brown + ", isDialing " + isDialing 991796c70c99bc39295bf685061056f06ab8949c742David Brown + ", showingDisc " + showingDisconnectedConnection + ")"); 992b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // keepScreenOn == true means we'll hold a full wake lock: 993b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP); 994b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 995b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 996b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 997b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Wrapper around the PowerManagerService.preventScreenOn() API. 998b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * This allows the in-call UI to prevent the screen from turning on 999b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * even if a subsequent call to updateWakeState() causes us to acquire 1000b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * a full wake lock. 1001b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 1002b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /* package */ void preventScreenOn(boolean prevent) { 1003796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "- preventScreenOn(" + prevent + ")..."); 1004b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project try { 1005b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mPowerManagerService.preventScreenOn(prevent); 1006b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } catch (RemoteException e) { 1007b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project Log.w(LOG_TAG, "mPowerManagerService.preventScreenOn() failed: " + e); 1008b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1009b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1010b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 10114472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown /** 10124472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * Sets or clears the flag that tells the PowerManager that touch 10134472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * (and cheek) events should NOT be considered "user activity". 10144472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * 10154472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * Since the in-call UI is totally insensitive to touch in most 10164472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * states, we set this flag whenever the InCallScreen is in the 10174472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * foreground. (Otherwise, repeated unintentional touches could 10184472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * prevent the device from going to sleep.) 10194472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * 10204472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * There *are* some some touch events that really do count as user 10214472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * activity, though. For those, we need to manually poke the 10224472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * PowerManager's userActivity method; see pokeUserActivity(). 10234472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown */ 10244472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown /* package */ void setIgnoreTouchUserActivity(boolean ignore) { 10254472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown if (VDBG) Log.d(LOG_TAG, "setIgnoreTouchUserActivity(" + ignore + ")..."); 10264472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown mIgnoreTouchUserActivity = ignore; 10274472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown updatePokeLock(); 10284472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown } 10294472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown 10304472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown /** 10314472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * Manually pokes the PowerManager's userActivity method. Since we 10324472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * hold the POKE_LOCK_IGNORE_TOUCH_AND_CHEEK_EVENTS poke lock while 10334472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * the InCallScreen is active, we need to do this for touch events 10344472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * that really do count as user activity (like DTMF key presses, or 10354472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown * unlocking the "touch lock" overlay.) 10364472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown */ 10374472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown /* package */ void pokeUserActivity() { 10384472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown if (VDBG) Log.d(LOG_TAG, "pokeUserActivity()..."); 10394472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown try { 10404472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown mPowerManagerService.userActivity(SystemClock.uptimeMillis(), false); 10414472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown } catch (RemoteException e) { 10424472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown Log.w(LOG_TAG, "mPowerManagerService.userActivity() failed: " + e); 10434472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown } 10444472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown } 10454472ce7a7e8568b4bb66098c4e4a2e71099167acDavid Brown 104658de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown /** 1047445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood * Set when a new outgoing call is beginning, so we can update 1048445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood * the proximity sensor state. 1049445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood * Cleared when the InCallScreen is no longer in the foreground, 1050445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood * in case the call fails without changing the telephony state. 1051445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood */ 1052445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood /* package */ void setBeginningCall(boolean beginning) { 1053445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood // Note that we are beginning a new call, for proximity sensor support 1054445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood mBeginningCall = beginning; 1055445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood // Update the Proximity sensor based on mBeginningCall state 1056445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood updateProximitySensorMode(phone.getState()); 1057445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood } 1058445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood 1059445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood /** 106058de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * Updates the wake lock used to control proximity sensor behavior, 106158de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * based on the current state of the phone. This method is called 106258de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * from the CallNotifier on any phone state change. 106358de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * 106458de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * On devices that have a proximity sensor, to avoid false touches 106558de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * during a call, we hold a PROXIMITY_SCREEN_OFF_WAKE_LOCK wake lock 106658de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * whenever the phone is off hook. (When held, that wake lock causes 106758de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * the screen to turn off automatically when the sensor detects an 106858de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * object close to the screen.) 106958de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * 107058de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * This method is a no-op for devices that don't have a proximity 107158de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * sensor. 107258de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * 107358de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * Note this method doesn't care if the InCallScreen is the foreground 107458de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * activity or not. That's because we want the proximity sensor to be 107558de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * enabled any time the phone is in use, to avoid false cheek events 107658de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * for whatever app you happen to be running. 107758de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * 1078d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai * Proximity wake lock will *not* be held if any one of the 1079d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai * conditions is true while on a call: 1080d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai * 1) If the audio is routed via Bluetooth 1081d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai * 2) If a wired headset is connected 1082d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai * 3) if the speaker is ON 1083d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai * 4) If the slider is open(i.e. the hardkeyboard is *not* hidden) 108458de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * 108558de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown * @param state current state of the phone (see {@link Phone#State}) 108658de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown */ 108758de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown /* package */ void updateProximitySensorMode(Phone.State state) { 1088445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood if (VDBG) Log.d(LOG_TAG, "updateProximitySensorMode: state = " + state); 1089d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai 1090039a8e51aa4a3ed27ad788dd5f1e043446517d92Mike Lockwood if (proximitySensorModeEnabled()) { 1091445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood if (((state == Phone.State.OFFHOOK) || mBeginningCall) 1092d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai && !(isHeadsetPlugged() 1093d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai || PhoneUtils.isSpeakerOn(this) 1094d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai || ((mBtHandsfree != null) && mBtHandsfree.isAudioOn()) 1095d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai || mIsHardKeyboardOpen)) { 109658de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown // Phone is in use! Arrange for the screen to turn off 109758de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown // automatically when the sensor detects a close object. 109858de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown if (!mProximityWakeLock.isHeld()) { 109958de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown if (DBG) Log.d(LOG_TAG, "updateProximitySensorMode: acquiring..."); 110058de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown mProximityWakeLock.acquire(); 11015601d455864ffb08ff995ba3fc162580dc7b8998Mike Lockwood // disable keyguard while we are using the proximity sensor 11025601d455864ffb08ff995ba3fc162580dc7b8998Mike Lockwood disableKeyguard(); 1103f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown } else { 1104445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood if (VDBG) Log.d(LOG_TAG, "updateProximitySensorMode: lock already held."); 110558de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown } 110658de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown } else { 110758de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown // Phone is either idle, or ringing. We don't want any 110858de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown // special proximity sensor behavior in either case. 110958de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown if (mProximityWakeLock.isHeld()) { 111058de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown if (DBG) Log.d(LOG_TAG, "updateProximitySensorMode: releasing..."); 111158de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown mProximityWakeLock.release(); 11125601d455864ffb08ff995ba3fc162580dc7b8998Mike Lockwood reenableKeyguard(); 1113f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown } else { 1114445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood if (VDBG) Log.d(LOG_TAG, "updateProximitySensorMode: lock already released."); 111558de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown } 111658de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown } 111758de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown } 111858de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown } 111958de0c5d10bbf48f6316a12495cd1c176a11a6feDavid Brown 1120f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown /** 1121445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood * Notifies the phone app when the phone state changes. 1122445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood * Currently used only for proximity sensor support. 1123445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood */ 1124445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood /* package */ void updatePhoneState(Phone.State state) { 1125445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood if (state != mLastPhoneState) { 1126445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood mLastPhoneState = state; 1127445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood updateProximitySensorMode(state); 1128445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood // clear our beginning call flag 1129445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood mBeginningCall = false; 1130445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood } 1131445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood } 1132445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood 1133445c9030dc93750a8209ace086ea3820ee33f0b1Mike Lockwood /** 1134f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown * @return true if this device supports the "proximity sensor 1135f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown * auto-lock" feature while in-call (see updateProximitySensorMode()). 1136f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown */ 1137f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown /* package */ boolean proximitySensorModeEnabled() { 1138f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown return (mProximityWakeLock != null); 1139f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown } 1140f0f6d973992a988c0fc801ba80f826c8edf02c03David Brown 1141b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project KeyguardManager getKeyguardManager() { 1142b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return mKeyguardManager; 1143b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1144b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 1145b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private void onMMIComplete(AsyncResult r) { 1146796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "onMMIComplete()..."); 1147b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project MmiCode mmiCode = (MmiCode) r.result; 1148b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project PhoneUtils.displayMMIComplete(phone, getInstance(), mmiCode, null, null); 1149b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1150b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 1151a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville private void initForNewRadioTechnology() { 115287258b2b589c3afea4b89b840251012378e0d3b4David Brown if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology..."); 1153a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville 115460877272381161201c6969dea501e683705d6e32w if (phone.getPhoneName().equals("CDMA")) { 115560877272381161201c6969dea501e683705d6e32w // Create an instance of CdmaPhoneCallState and initialize it to IDLE 115660877272381161201c6969dea501e683705d6e32w cdmaPhoneCallState = new CdmaPhoneCallState(); 115760877272381161201c6969dea501e683705d6e32w cdmaPhoneCallState.CdmaPhoneCallStateInit(); 115860877272381161201c6969dea501e683705d6e32w 115960877272381161201c6969dea501e683705d6e32w //create instances of CDMA OTA data classes 116060877272381161201c6969dea501e683705d6e32w if (cdmaOtaProvisionData == null) { 116160877272381161201c6969dea501e683705d6e32w cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData(); 116260877272381161201c6969dea501e683705d6e32w } 116360877272381161201c6969dea501e683705d6e32w if (cdmaOtaConfigData == null) { 116460877272381161201c6969dea501e683705d6e32w cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData(); 116560877272381161201c6969dea501e683705d6e32w } 116660877272381161201c6969dea501e683705d6e32w if (cdmaOtaScreenState == null) { 116760877272381161201c6969dea501e683705d6e32w cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState(); 116860877272381161201c6969dea501e683705d6e32w } 116960877272381161201c6969dea501e683705d6e32w } 117060877272381161201c6969dea501e683705d6e32w 1171a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville ringer.updateRingerContextAfterRadioTechnologyChange(this.phone); 1172a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange(); 117387258b2b589c3afea4b89b840251012378e0d3b4David Brown if (mBtHandsfree != null) { 1174a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville mBtHandsfree.updateBtHandsfreeAfterRadioTechnologyChange(); 1175a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville } 117687258b2b589c3afea4b89b840251012378e0d3b4David Brown if (mInCallScreen != null) { 117787258b2b589c3afea4b89b840251012378e0d3b4David Brown mInCallScreen.updateAfterRadioTechnologyChange(); 117887258b2b589c3afea4b89b840251012378e0d3b4David Brown } 1179a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville 118087258b2b589c3afea4b89b840251012378e0d3b4David Brown // Update registration for ICC status after radio technology change 1181a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville IccCard sim = phone.getIccCard(); 1182a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville if (sim != null) { 118387258b2b589c3afea4b89b840251012378e0d3b4David Brown if (DBG) Log.d(LOG_TAG, "Update registration for ICC status..."); 1184a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville 1185a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville //Register all events new to the new active phone 1186a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville sim.registerForAbsent(mHandler, EVENT_SIM_ABSENT, null); 1187a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville sim.registerForLocked(mHandler, EVENT_SIM_LOCKED, null); 1188a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null); 1189a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville } 1190a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville } 1191a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville 1192404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville 1193404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville /** 1194b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @return true if a wired headset is currently plugged in. 1195b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 1196b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * @see Intent.ACTION_HEADSET_PLUG (which we listen for in mReceiver.onReceive()) 1197b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 1198b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean isHeadsetPlugged() { 1199b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project return mIsHeadsetPlugged; 1200b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1201b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 12028bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project /** 12038bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * @return true if the onscreen UI should currently be showing the 12048bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * special "bluetooth is active" indication in a couple of places (in 12058bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * which UI elements turn blue and/or show the bluetooth logo.) 12068bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * 12078bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * This depends on the BluetoothHeadset state *and* the current 12088bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * telephony state; see shouldShowBluetoothIndication(). 12098bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * 12108bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * @see CallCard 12118bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * @see NotificationMgr.updateInCallNotification 12128bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project */ 12138bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project /* package */ boolean showBluetoothIndication() { 12148bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project return mShowBluetoothIndication; 12158bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project } 12168bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project 12178bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project /** 12188bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * Recomputes the mShowBluetoothIndication flag based on the current 12198bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * bluetooth state and current telephony state. 12208bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * 12218bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * This needs to be called any time the bluetooth headset state or the 12228bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * telephony state changes. 12234b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project * 12244b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project * @param forceUiUpdate if true, force the UI elements that care 12254b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project * about this flag to update themselves. 12268bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project */ 12274b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project /* package */ void updateBluetoothIndication(boolean forceUiUpdate) { 12288bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project mShowBluetoothIndication = shouldShowBluetoothIndication(mBluetoothHeadsetState, 12294b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project mBluetoothHeadsetAudioState, 12308bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project phone); 12314b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project if (forceUiUpdate) { 12324b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project // Post Handler messages to the various components that might 12334b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project // need to be refreshed based on the new state. 12344b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project if (isShowingCallScreen()) mInCallScreen.updateBluetoothIndication(); 12354b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project mHandler.sendEmptyMessage(EVENT_UPDATE_INCALL_NOTIFICATION); 12364b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project } 1237d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai 1238d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai // Update the Proximity sensor based on Bluetooth audio state 1239d3744ff481f7d96669740b015a39d7441208152bAbhishek Pillai updateProximitySensorMode(phone.getState()); 12408bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project } 12418bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project 12428bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project /** 12438bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * UI policy helper function for the couple of places in the UI that 12448bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * have some way of indicating that "bluetooth is in use." 12458bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * 12468bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * @return true if the onscreen UI should indicate that "bluetooth is in use", 12478bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * based on the specified bluetooth headset state, and the 12488bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * current state of the phone. 12498bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project * @see showBluetoothIndication() 12508bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project */ 12518bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project private static boolean shouldShowBluetoothIndication(int bluetoothState, 12524b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project int bluetoothAudioState, 12538bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project Phone phone) { 12548bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // We want the UI to indicate that "bluetooth is in use" in two 12558bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // slightly different cases: 12568bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // 12578bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // (a) The obvious case: if a bluetooth headset is currently in 12588bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // use for an ongoing call. 12598bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // 12608bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // (b) The not-so-obvious case: if an incoming call is ringing, 12618bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // and we expect that audio *will* be routed to a bluetooth 12628bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // headset once the call is answered. 12638bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project 12648bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project switch (phone.getState()) { 12658bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project case OFFHOOK: 12668bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // This covers normal active calls, and also the case if 12674b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project // the foreground call is DIALING or ALERTING. In this 12684b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project // case, bluetooth is considered "active" if a headset 12694b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project // is connected *and* audio is being routed to it. 12704b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project return ((bluetoothState == BluetoothHeadset.STATE_CONNECTED) 12714b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project && (bluetoothAudioState == BluetoothHeadset.AUDIO_STATE_CONNECTED)); 12728bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project 12738bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project case RINGING: 12748bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // If an incoming call is ringing, we're *not* yet routing 12758bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // audio to the headset (since there's no in-call audio 12768bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // yet!) In this case, if a bluetooth headset is 12778bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // connected at all, we assume that it'll become active 12788bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project // once the user answers the phone. 12798bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project return (bluetoothState == BluetoothHeadset.STATE_CONNECTED); 12808bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project 12818bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project default: // Presumably IDLE 12828bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project return false; 12838bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project } 12848bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project } 12858bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project 1286b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 1287b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 1288b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Receiver for misc intent broadcasts the Phone app cares about. 1289b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 1290b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private class PhoneAppBroadcastReceiver extends BroadcastReceiver { 1291b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project @Override 1292b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project public void onReceive(Context context, Intent intent) { 1293b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project String action = intent.getAction(); 1294b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) { 1295b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean enabled = System.getInt(getContentResolver(), 1296b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project System.AIRPLANE_MODE_ON, 0) == 0; 1297b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project phone.setRadioPower(enabled); 129818e0a07cc700234f5a02fe10eee9b3ea10db58b3Nick Pelly } else if (action.equals(BluetoothHeadset.ACTION_STATE_CHANGED)) { 129918e0a07cc700234f5a02fe10eee9b3ea10db58b3Nick Pelly mBluetoothHeadsetState = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE, 13008bb467d9a1106dedd79e42166c7b6e9fc9a897a7The Android Open Source Project BluetoothHeadset.STATE_ERROR); 1301796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "mReceiver: HEADSET_STATE_CHANGED_ACTION"); 1302796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "==> new state: " + mBluetoothHeadsetState); 13034b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project updateBluetoothIndication(true); // Also update any visible UI if necessary 130418e0a07cc700234f5a02fe10eee9b3ea10db58b3Nick Pelly } else if (action.equals(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED)) { 13054b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project mBluetoothHeadsetAudioState = 130618e0a07cc700234f5a02fe10eee9b3ea10db58b3Nick Pelly intent.getIntExtra(BluetoothHeadset.EXTRA_AUDIO_STATE, 13074b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project BluetoothHeadset.STATE_ERROR); 1308796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "mReceiver: HEADSET_AUDIO_STATE_CHANGED_ACTION"); 1309796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "==> new state: " + mBluetoothHeadsetAudioState); 13104b8337277ec2e375c3536b97c40e6617a7b12990The Android Open Source Project updateBluetoothIndication(true); // Also update any visible UI if necessary 1311b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) { 131287258b2b589c3afea4b89b840251012378e0d3b4David Brown if (VDBG) Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED"); 131387258b2b589c3afea4b89b840251012378e0d3b4David Brown if (VDBG) Log.d(LOG_TAG, "- state: " + intent.getStringExtra(Phone.STATE_KEY)); 131487258b2b589c3afea4b89b840251012378e0d3b4David Brown if (VDBG) Log.d(LOG_TAG, "- reason: " 131587258b2b589c3afea4b89b840251012378e0d3b4David Brown + intent.getStringExtra(Phone.STATE_CHANGE_REASON_KEY)); 13164079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project 13174079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // The "data disconnected due to roaming" notification is 13184079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // visible if you've lost data connectivity because you're 13194079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // roaming and you have the "data roaming" feature turned off. 13204079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project boolean disconnectedDueToRoaming = false; 1321b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if ("DISCONNECTED".equals(intent.getStringExtra(Phone.STATE_KEY))) { 1322b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project String reason = intent.getStringExtra(Phone.STATE_CHANGE_REASON_KEY); 1323b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (Phone.REASON_ROAMING_ON.equals(reason)) { 13244079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // We just lost our data connection, and the reason 13254079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // is that we started roaming. This implies that 13264079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // the user has data roaming turned off. 13274079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project disconnectedDueToRoaming = true; 1328b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1329b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 13304079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project mHandler.sendEmptyMessage(disconnectedDueToRoaming 13314079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project ? EVENT_DATA_ROAMING_DISCONNECTED 13324079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project : EVENT_DATA_ROAMING_OK); 1333b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } else if (action.equals(Intent.ACTION_HEADSET_PLUG)) { 1334796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "mReceiver: ACTION_HEADSET_PLUG"); 1335796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, " state: " + intent.getIntExtra("state", 0)); 1336796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, " name: " + intent.getStringExtra("name")); 1337b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mIsHeadsetPlugged = (intent.getIntExtra("state", 0) == 1); 1338b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mHandler.sendMessage(mHandler.obtainMessage(EVENT_WIRED_HEADSET_PLUG, 0)); 1339b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } else if (action.equals(Intent.ACTION_BATTERY_LOW)) { 1340796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "mReceiver: ACTION_BATTERY_LOW"); 1341b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project notifier.sendBatteryLow(); // Play a warning tone if in-call 1342b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) && 1343b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project (mPUKEntryActivity != null)) { 1344b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // if an attempt to un-PUK-lock the device was made, while we're 1345b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // receiving this state change notification, notify the handler. 1346b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has 1347b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // been attempted. 1348b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED, 1349a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville intent.getStringExtra(IccCard.INTENT_KEY_ICC_STATE))); 1350a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) { 1351a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville String newPhone = intent.getStringExtra(Phone.PHONE_NAME_KEY); 1352a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active."); 1353a69de9f9a2e99fe08f0009bb218b95ed7985c575Wink Saville initForNewRadioTechnology(); 1354404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) { 1355404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville handleServiceStateChanged(intent); 1356abeff00b5242e795baa8f5271525c5911f649993Wink Saville } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) { 13574e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski if(phone.getPhoneName().equals("CDMA")) { 13584e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp."); 13594e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski // Start Emergency Callback Mode service 13604e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski if (intent.getBooleanExtra("phoneinECMState", false)) { 13614e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski context.startService(new Intent(context, 13624e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski EmergencyCallbackModeService.class)); 13634e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski } 13644e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski } else { 13654e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski Log.e(LOG_TAG, "Error! Emergency Callback Mode not supported for " + 13664e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski phone.getPhoneName() + " phones"); 13674e879989bb6e23763802ceb128e8785f8f063ac0Robert Kowalski } 1368b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1369b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1370b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1371b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 1372b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project /** 1373b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * Broadcast receiver for the ACTION_MEDIA_BUTTON broadcast intent. 1374b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * 1375b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * This functionality isn't lumped in with the other intents in 1376b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * PhoneAppBroadcastReceiver because we instantiate this as a totally 1377b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * separate BroadcastReceiver instance, since we need to manually 1378b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * adjust its IntentFilter's priority (to make sure we get these 1379b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project * intents *before* the media player.) 1380b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project */ 1381b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project private class MediaButtonBroadcastReceiver extends BroadcastReceiver { 1382b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project @Override 1383b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project public void onReceive(Context context, Intent intent) { 1384b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); 1385796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, 1386b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project "MediaButtonBroadcastReceiver.onReceive()... event = " + event); 1387b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if ((event != null) 1388b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project && (event.getKeyCode() == KeyEvent.KEYCODE_HEADSETHOOK) 1389b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project && (event.getAction() == KeyEvent.ACTION_DOWN)) { 1390b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project 1391b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (event.getRepeatCount() == 0) { 1392b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project // Mute ONLY on the initial keypress. 1393796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "MediaButtonBroadcastReceiver: HEADSETHOOK down!"); 1394b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project boolean consumed = PhoneUtils.handleHeadsetHook(phone); 1395796c70c99bc39295bf685061056f06ab8949c742David Brown if (VDBG) Log.d(LOG_TAG, "==> handleHeadsetHook(): consumed = " + consumed); 1396b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project if (consumed) { 1397b8df8173e1a0ea8ba89cea984176216201c4d5e7Paul Berman // If a headset is attached and the press is consumed, also update 1398b8df8173e1a0ea8ba89cea984176216201c4d5e7Paul Berman // any UI items (such as an InCallScreen mute button) that may need to 1399b8df8173e1a0ea8ba89cea984176216201c4d5e7Paul Berman // be updated if their state changed. 1400b8df8173e1a0ea8ba89cea984176216201c4d5e7Paul Berman if (isShowingCallScreen()) { 1401b8df8173e1a0ea8ba89cea984176216201c4d5e7Paul Berman mInCallScreen.requestUpdateTouchUi(); 1402b8df8173e1a0ea8ba89cea984176216201c4d5e7Paul Berman } 1403b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project abortBroadcast(); 1404b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 14054079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project } else if (phone.getState() != Phone.State.IDLE) { 14064079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // As for any DOWN events other than the initial press, we consume 14074079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // (and ignore) those too if the phone is in use. (Otherwise the 14084079f559beb3e414036056b4b33ad40de5e89c4aThe Android Open Source Project // music player will handle them, which would be confusing.) 1409b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project abortBroadcast(); 1410b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1411b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1412b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1413b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project } 1414404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville 1415404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville private void handleServiceStateChanged(Intent intent) { 14164e41cdf8b65434a324f3e83be1095689ddabd153Wink Saville /** 14174e41cdf8b65434a324f3e83be1095689ddabd153Wink Saville * This used to handle updating EriTextWidgetProvider this routine 14184e41cdf8b65434a324f3e83be1095689ddabd153Wink Saville * and and listening for ACTION_SERVICE_STATE_CHANGED intents could 14194e41cdf8b65434a324f3e83be1095689ddabd153Wink Saville * be removed. But leaving just in case it might be needed in the near 14204e41cdf8b65434a324f3e83be1095689ddabd153Wink Saville * future. 14214e41cdf8b65434a324f3e83be1095689ddabd153Wink Saville */ 14224e41cdf8b65434a324f3e83be1095689ddabd153Wink Saville 1423404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville // If service just returned, start sending out the queued messages 1424404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville ServiceState ss = ServiceState.newFromBundle(intent.getExtras()); 1425404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville 1426404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville boolean hasService = true; 1427404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville boolean isCdma = false; 1428404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville String eriText = ""; 1429404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville 1430404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville if (ss != null) { 1431404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville int state = ss.getState(); 143299d10538d840f0103c36dafa44db9f649ca884c8johnwang NotificationMgr.getDefault().updateNetworkSelection(state); 1433404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville switch (state) { 1434404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville case ServiceState.STATE_OUT_OF_SERVICE: 1435404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville case ServiceState.STATE_POWER_OFF: 1436404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville hasService = false; 1437404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville break; 1438404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville } 1439404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville } else { 1440404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville hasService = false; 1441404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville } 1442404edc94de563aef5fd5ba48be9114a970cb93bbWink Saville } 1443af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville 1444af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville public boolean isOtaCallInActiveState() { 1445af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville boolean otaCallActive = false; 1446af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville if (mInCallScreen != null) { 1447af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville otaCallActive = mInCallScreen.isOtaCallInActiveState(); 1448af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 1449af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville if (DBG) Log.d(LOG_TAG, "PhoneApp - isOtaCallInActiveState " + otaCallActive); 1450af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville return otaCallActive; 1451af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 1452af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville 1453af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville public boolean isOtaCallInEndState() { 1454af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville boolean otaCallEnded = false; 1455af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville if (mInCallScreen != null) { 1456af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville otaCallEnded = mInCallScreen.isOtaCallInEndState(); 1457af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 1458af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville if (DBG) Log.d(LOG_TAG, "PhoneApp - isOtaCallInEndState " + otaCallEnded); 1459af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville return otaCallEnded; 1460af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville } 146173caead845b30580010a7502e4b7551d21dfa265Matthew Sun 146273caead845b30580010a7502e4b7551d21dfa265Matthew Sun // it is safe to call clearOtaState() even if the InCallScreen isn't active 146373caead845b30580010a7502e4b7551d21dfa265Matthew Sun public void clearOtaState() { 146473caead845b30580010a7502e4b7551d21dfa265Matthew Sun if (DBG) Log.d(LOG_TAG, "PhoneApp - clearOtaState ..."); 146573caead845b30580010a7502e4b7551d21dfa265Matthew Sun if ((mInCallScreen != null) 146673caead845b30580010a7502e4b7551d21dfa265Matthew Sun && (mInCallScreen.otaUtils != null)) { 146773caead845b30580010a7502e4b7551d21dfa265Matthew Sun mInCallScreen.otaUtils.cleanOtaScreen(); 146873caead845b30580010a7502e4b7551d21dfa265Matthew Sun if (DBG) Log.d(LOG_TAG, "PhoneApp - clearOtaState clears OTA screen"); 146973caead845b30580010a7502e4b7551d21dfa265Matthew Sun } 147073caead845b30580010a7502e4b7551d21dfa265Matthew Sun } 147173caead845b30580010a7502e4b7551d21dfa265Matthew Sun 147273caead845b30580010a7502e4b7551d21dfa265Matthew Sun // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active 147373caead845b30580010a7502e4b7551d21dfa265Matthew Sun public void dismissOtaDialogs() { 147473caead845b30580010a7502e4b7551d21dfa265Matthew Sun if (DBG) Log.d(LOG_TAG, "PhoneApp - dismissOtaDialogs ..."); 147573caead845b30580010a7502e4b7551d21dfa265Matthew Sun if ((mInCallScreen != null) 147673caead845b30580010a7502e4b7551d21dfa265Matthew Sun && (mInCallScreen.otaUtils != null)) { 147773caead845b30580010a7502e4b7551d21dfa265Matthew Sun mInCallScreen.otaUtils.dismissAllOtaDialogs(); 147873caead845b30580010a7502e4b7551d21dfa265Matthew Sun if (DBG) Log.d(LOG_TAG, "PhoneApp - dismissOtaDialogs clears OTA dialogs"); 147973caead845b30580010a7502e4b7551d21dfa265Matthew Sun } 148073caead845b30580010a7502e4b7551d21dfa265Matthew Sun } 148173caead845b30580010a7502e4b7551d21dfa265Matthew Sun 148273caead845b30580010a7502e4b7551d21dfa265Matthew Sun // it is safe to call clearInCallScreenMode() even if the InCallScreen isn't active 148373caead845b30580010a7502e4b7551d21dfa265Matthew Sun public void clearInCallScreenMode() { 148473caead845b30580010a7502e4b7551d21dfa265Matthew Sun if (DBG) Log.d(LOG_TAG, "PhoneApp - clearInCallScreenMode ..."); 148573caead845b30580010a7502e4b7551d21dfa265Matthew Sun if (mInCallScreen != null) { 148673caead845b30580010a7502e4b7551d21dfa265Matthew Sun mInCallScreen.resetInCallScreenMode(); 148773caead845b30580010a7502e4b7551d21dfa265Matthew Sun } 148873caead845b30580010a7502e4b7551d21dfa265Matthew Sun } 1489b16363f5fc191b769e88c364243e34b92eb22688The Android Open Source Project} 1490