예제 #1
0
  private void initForNewRadioTechnology() {
    if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");

    ringer.updateRingerContextAfterRadioTechnologyChange(this.phone);
    notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
    if (mBtHandsfree != null) {
      mBtHandsfree.updateBtHandsfreeAfterRadioTechnologyChange();
    }
    if (mInCallScreen != null) {
      mInCallScreen.updateAfterRadioTechnologyChange();
    }

    // Update registration for ICC status after radio technology change
    IccCard sim = phone.getIccCard();
    if (sim != null) {
      if (DBG) Log.d(LOG_TAG, "Update registration for ICC status...");

      // Register all events new to the new active phone
      sim.registerForAbsent(mHandler, EVENT_SIM_ABSENT, null);
      sim.registerForLocked(mHandler, EVENT_SIM_LOCKED, null);
      sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null);
    }

    if (phone.getPhoneName().equals("CDMA")) {
      // Create an instance of CdmaPhoneCallState and initialize it to IDLE
      cdmaPhoneCallState = new CdmaPhoneCallState();
      cdmaPhoneCallState.CdmaPhoneCallStateInit();
    }
  }
예제 #2
0
  @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();
    }
  }