/*
     * Use PIN or PUK to unlock SIM card
     *
     * If PUK is null, unlock SIM card with PIN
     *
     * If PUK is not null, unlock SIM card with PUK and set PIN code
     */
    synchronized boolean unlockSim(String puk, String pin) {

      while (mHandler == null) {
        try {
          wait();
        } catch (InterruptedException e) {
          Thread.currentThread().interrupt();
        }
      }
      Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);

      if (puk == null) {
        mSimCard.supplyPin(pin, callback);
      } else {
        mSimCard.supplyPuk(puk, pin, callback);
      }

      while (!mDone) {
        try {
          Log.d(LOG_TAG, "wait for done");
          wait();
        } catch (InterruptedException e) {
          // Restore the interrupted status
          Thread.currentThread().interrupt();
        }
      }
      Log.d(LOG_TAG, "done");
      return mResult;
    }
예제 #2
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();
    }
  }
        public void onClick(View v) {
          if (v == mOldPin) {
            mNewPin1.requestFocus();
          } else if (v == mNewPin1) {
            mNewPin2.requestFocus();
          } else if (v == mNewPin2) {
            mButton.requestFocus();
          } else if (v == mButton) {
            IccCard iccCardInterface = mPhone.getIccCard();
            if (iccCardInterface != null) {
              String oldPin = mOldPin.getText().toString();
              String newPin1 = mNewPin1.getText().toString();
              String newPin2 = mNewPin2.getText().toString();

              int error = validateNewPin(newPin1, newPin2);

              switch (error) {
                case PIN_INVALID_LENGTH:
                case PIN_MISMATCH:
                  mNewPin1.getText().clear();
                  mNewPin2.getText().clear();
                  mMismatchError.setVisibility(View.VISIBLE);

                  Resources r = getResources();
                  CharSequence text;

                  if (error == PIN_MISMATCH) {
                    text = r.getString(R.string.mismatchPin);
                  } else {
                    text = r.getString(R.string.invalidPin);
                  }

                  mMismatchError.setText(text);
                  break;

                default:
                  Message callBack = Message.obtain(mHandler, EVENT_PIN_CHANGED);

                  if (DBG) log("change pin attempt: old=" + oldPin + ", newPin=" + newPin1);

                  reset();

                  if (mChangePin2) {
                    iccCardInterface.changeIccFdnPassword(oldPin, newPin1, callBack);
                  } else {
                    iccCardInterface.changeIccLockPassword(oldPin, newPin1, callBack);
                  }

                  // TODO: show progress panel
              }
            }
          } else if (v == mPUKCode) {
            mPUKSubmit.requestFocus();
          } else if (v == mPUKSubmit) {
            mPhone
                .getIccCard()
                .supplyPuk2(
                    mPUKCode.getText().toString(),
                    mNewPin1.getText().toString(),
                    Message.obtain(mHandler, EVENT_PIN_CHANGED));
          }
        }
예제 #4
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();
    }
  }