public boolean handleMessage(Message msg) { if (msg.what == MSG_REPLY) { mNotificationMgr.sendNotification(getBaseContext(), NotifyType.REPLY); } else if (msg.what == MSG_AT) { mNotificationMgr.sendNotification(getBaseContext(), NotifyType.AT); } else if (msg.what == MSG_MAIL) { mNotificationMgr.sendNotification(getBaseContext(), NotifyType.MAIL); } else if (msg.what == MSG_NO_REPLY) { mNotificationMgr.cancel(NotifyType.REPLY); } else if (msg.what == MSG_NO_AT) { mNotificationMgr.cancel(NotifyType.AT); } else if (msg.what == MSG_NO_MAIL) { mNotificationMgr.cancel(NotifyType.MAIL); } else if (msg.what == MSG_ERROR) { Logcat.e(TAG, "handleMessage MSG_ERROR"); } return true; }
@Override public void onCreate() { if (Config.LOGV) Log.v(LOG_TAG, "onCreate()..."); ContentResolver resolver = getContentResolver(); if (phone == null) { // Initialize the telephony framework PhoneFactory.makeDefaultPhones(this); // Get the default phone phone = PhoneFactory.getDefaultPhone(); NotificationMgr.init(this); phoneMgr = new PhoneInterfaceManager(this, phone); if (getSystemService(Context.BLUETOOTH_SERVICE) != null) { mBtHandsfree = new BluetoothHandsfree(this, phone); startService(new Intent(this, BluetoothHeadsetService.class)); } else { // Device is not bluetooth capable mBtHandsfree = null; } ringer = new Ringer(phone); // before registering for phone state changes PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock( PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, LOG_TAG); // lock used to keep the processor awake, when we don't care for the display. mPartialWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, LOG_TAG); mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); mKeyguardLock = mKeyguardManager.newKeyguardLock(LOG_TAG); // get a handle to the service so that we can use it later when we // want to set the poke lock. mPowerManagerService = IPowerManager.Stub.asInterface(ServiceManager.getService("power")); notifier = new CallNotifier(this, phone, ringer, mBtHandsfree); // register for ICC status IccCard sim = phone.getIccCard(); if (sim != null) { if (Config.LOGV) Log.v(LOG_TAG, "register for ICC status"); sim.registerForAbsent(mHandler, EVENT_SIM_ABSENT, null); sim.registerForLocked(mHandler, EVENT_SIM_LOCKED, null); sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null); } // register for MMI/USSD phone.registerForMmiComplete(mHandler, MMI_COMPLETE, null); // register connection tracking to PhoneUtils PhoneUtils.initializeConnectionHandler(phone); // Register for misc other intent broadcasts. IntentFilter intentFilter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED); intentFilter.addAction(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION); intentFilter.addAction(BluetoothIntent.HEADSET_AUDIO_STATE_CHANGED_ACTION); intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED); intentFilter.addAction(Intent.ACTION_HEADSET_PLUG); intentFilter.addAction(Intent.ACTION_BATTERY_LOW); intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED); intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); intentFilter.addAction(ACTION_VIBRATE_45); registerReceiver(mReceiver, intentFilter); // Use a separate receiver for ACTION_MEDIA_BUTTON broadcasts, // since we need to manually adjust its priority (to make sure // we get these intents *before* the media player.) IntentFilter mediaButtonIntentFilter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON); // // Make sure we're higher priority than the media player's // MediaButtonIntentReceiver (which currently has the default // priority of zero; see apps/Music/AndroidManifest.xml.) mediaButtonIntentFilter.setPriority(1); // registerReceiver(mMediaButtonReceiver, mediaButtonIntentFilter); // set the default values for the preferences in the phone. PreferenceManager.setDefaultValues(this, R.xml.network_setting, false); PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false); // Make sure the audio mode (along with some // audio-mode-related state of our own) is initialized // correctly, given the current state of the phone. switch (phone.getState()) { case IDLE: if (DBG) Log.d(LOG_TAG, "Resetting audio state/mode: IDLE"); PhoneUtils.setAudioControlState(PhoneUtils.AUDIO_IDLE); PhoneUtils.setAudioMode(this, AudioManager.MODE_NORMAL); break; case RINGING: if (DBG) Log.d(LOG_TAG, "Resetting audio state/mode: RINGING"); PhoneUtils.setAudioControlState(PhoneUtils.AUDIO_RINGING); PhoneUtils.setAudioMode(this, AudioManager.MODE_RINGTONE); break; case OFFHOOK: if (DBG) Log.d(LOG_TAG, "Resetting audio state/mode: OFFHOOK"); PhoneUtils.setAudioControlState(PhoneUtils.AUDIO_OFFHOOK); PhoneUtils.setAudioMode(this, AudioManager.MODE_IN_CALL); break; } } // XXX pre-load the SimProvider so that it's ready resolver.getType(Uri.parse("content://icc/adn")); // start with the default value to set the mute state. mShouldRestoreMuteOnInCallResume = false; // add by cytown mSettings = CallFeaturesSetting.getInstance(PreferenceManager.getDefaultSharedPreferences(this)); if (mVibrator == null) { mVibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE); mAM = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); mVibrateIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_VIBRATE_45), 0); } // Register for Cdma Information Records // TODO(Moto): Merge // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null); if (phone.getPhoneName().equals("CDMA")) { // Create an instance of CdmaPhoneCallState and initialize it to IDLE cdmaPhoneCallState = new CdmaPhoneCallState(); cdmaPhoneCallState.CdmaPhoneCallStateInit(); } }
@Override public void handleMessage(Message msg) { switch (msg.what) { case EVENT_SIM_LOCKED: // mIsSimPinEnabled = true; // // if (Config.LOGV) Log.v(LOG_TAG, "show sim unlock panel"); // SimPinUnlockPanel pinUnlockPanel = new SimPinUnlockPanel( // PhoneApp.getInstance()); // pinUnlockPanel.show(); break; case EVENT_SIM_ABSENT: // Don't need this now that the lock screen handles this case // if (Config.LOGV) Log.v(LOG_TAG, "show sim missing panel"); // SimMissingPanel missingPanel = new SimMissingPanel( // PhoneApp.getInstance()); // missingPanel.show(); break; case EVENT_SIM_NETWORK_LOCKED: if (getResources().getBoolean(R.bool.ignore_sim_network_locked_events)) { // Some products don't have the concept of a "SIM network lock" Log.i( LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; " + "not showing 'SIM network unlock' PIN entry screen"); } else { // Normal case: show the "SIM network unlock" PIN entry screen. // The user won't be able to do anything else until // they enter a valid SIM network PIN. Log.i(LOG_TAG, "show sim depersonal panel"); IccNetworkDepersonalizationPanel ndpPanel = new IccNetworkDepersonalizationPanel(PhoneApp.getInstance()); ndpPanel.show(); } break; case EVENT_UPDATE_INCALL_NOTIFICATION: // Tell the NotificationMgr to update the "ongoing // call" icon in the status bar, if necessary. // Currently, this is triggered by a bluetooth headset // state change (since the status bar icon needs to // turn blue when bluetooth is active.) NotificationMgr.getDefault().updateInCallNotification(); break; case EVENT_DATA_ROAMING_DISCONNECTED: NotificationMgr.getDefault().showDataDisconnectedRoaming(); break; case EVENT_DATA_ROAMING_OK: NotificationMgr.getDefault().hideDataDisconnectedRoaming(); break; case MMI_COMPLETE: onMMIComplete((AsyncResult) msg.obj); break; case MMI_CANCEL: PhoneUtils.cancelMmiCode(phone); break; case EVENT_WIRED_HEADSET_PLUG: // Since the presence of a wired headset or bluetooth affects the // speakerphone, update the "speaker" state. We ONLY want to do // this on the wired headset connect / disconnect events for now // though, so we're only triggering on EVENT_WIRED_HEADSET_PLUG. if (!isHeadsetPlugged() && (mBtHandsfree == null || !mBtHandsfree.isAudioOn())) { // is the state is "not connected", restore the speaker state. PhoneUtils.restoreSpeakerMode(getApplicationContext()); } NotificationMgr.getDefault().updateSpeakerNotification(); break; case EVENT_SIM_STATE_CHANGED: // Marks the event where the SIM goes into ready state. // Right now, this is only used for the PUK-unlocking // process. if (msg.obj.equals(IccCard.INTENT_VALUE_ICC_READY)) { // when the right event is triggered and there // are UI objects in the foreground, we close // them to display the lock panel. if (mPUKEntryActivity != null) { mPUKEntryActivity.finish(); mPUKEntryActivity = null; } if (mPUKEntryProgressDialog != null) { mPUKEntryProgressDialog.dismiss(); mPUKEntryProgressDialog = null; } } break; case EVENT_UNSOL_CDMA_INFO_RECORD: // TODO: handle message here; break; } }
@Override public int onStartCommand(Intent intent, int flags, int startId) { mNotificationMgr = NotificationMgr.getInstance(); checkNewMessage(); return super.onStartCommand(intent, flags, startId); }