示例#1
0
  /**
   * getCallerInfo given a phone number and subscription, look up in the call-log database for the
   * matching caller id info.
   *
   * @param context the context used to get the ContentResolver
   * @param number the phone number used to lookup caller id
   * @param subId the subscription for checking for if voice mail number or not
   * @return the CallerInfo which contains the caller id for the given number. The returned
   *     CallerInfo is null if no number is supplied. If a matching number is not found, then a
   *     generic caller info is returned, with all relevant fields empty or null.
   */
  public static CallerInfo getCallerInfo(Context context, String number, int subId) {

    if (TextUtils.isEmpty(number)) {
      return null;
    }

    // Change the callerInfo number ONLY if it is an emergency number
    // or if it is the voicemail number.  If it is either, take a
    // shortcut and skip the query.
    if (PhoneNumberUtils.isLocalEmergencyNumber(context, number)) {
      return new CallerInfo().markAsEmergency(context);
    } else if (PhoneNumberUtils.isVoiceMailNumber(subId, number)) {
      return new CallerInfo().markAsVoiceMail();
    }

    Uri contactUri =
        Uri.withAppendedPath(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, Uri.encode(number));

    CallerInfo info = getCallerInfo(context, contactUri);
    info = doSecondaryLookupIfNecessary(context, number, info);

    // if no query results were returned with a viable number,
    // fill in the original number value we used to query with.
    if (TextUtils.isEmpty(info.phoneNumber)) {
      info.phoneNumber = number;
    }

    return info;
  }
  public Connection dial(String dialString, UUSInfo uusInfo) throws CallStateException {
    // Need to make sure dialString gets parsed properly
    String newDialString = PhoneNumberUtils.stripSeparators(dialString);

    // handle in-call MMI first if applicable
    if (handleInCallMmiCommands(newDialString)) {
      return null;
    }

    // Only look at the Network portion for mmi
    String networkPortion = PhoneNumberUtils.extractNetworkPortionAlt(newDialString);
    GsmMmiCode mmi = GsmMmiCode.newFromDialString(networkPortion, this);
    if (LOCAL_DEBUG) Log.d(LOG_TAG, "dialing w/ mmi '" + mmi + "'...");

    if (mmi == null) {
      return mCT.dial(newDialString, uusInfo);
    } else if (mmi.isTemporaryModeCLIR()) {
      return mCT.dial(mmi.dialingNumber, mmi.getCLIRMode(), uusInfo);
    } else {
      mPendingMMIs.add(mmi);
      mMmiRegistrants.notifyRegistrants(new AsyncResult(null, mmi, null));
      mmi.processCode();

      // FIXME should this return null or something else?
      return null;
    }
  }
  /*package*/
  public ConnectionBase(
      Context context, String dialString, CallTracker ct, Call parent, CallDetails moCallDetails) {
    createWakeLock(context);
    acquireWakeLock();

    owner = ct;
    h = new MyHandler(owner.getLooper());

    this.dialString = dialString;
    if ((moCallDetails != null) && (moCallDetails.call_domain == CallDetails.RIL_CALL_DOMAIN_PS))
      this.address = dialString;
    else this.address = PhoneNumberUtils.extractNetworkPortionAlt(dialString);
    this.postDialString = PhoneNumberUtils.extractPostDialPortion(dialString);

    index = -1;

    isIncoming = false;
    cnapName = null;
    createTime = System.currentTimeMillis();
    callDetails = moCallDetails;

    if (parent != null) {
      this.parent = parent;

      // for the cdma three way call case, do not change parent state
      // pass remote caller id in cdma 3 way call only
      if (parent.state == Call.State.ACTIVE) {
        cnapNamePresentation = Connection.PRESENTATION_ALLOWED;
        numberPresentation = Connection.PRESENTATION_ALLOWED;
        parent.attachFake(this, Call.State.ACTIVE);
      } else { // MO call for Gsm & Cdma, set state to dialing
        parent.attachFake(this, Call.State.DIALING);
      }
    }
  }
  /** Factory method to start query with a number */
  public static CallerInfoAsyncQuery startQuery(
      int token, Context context, String number, OnQueryCompleteListener listener, Object cookie) {
    // contruct the URI object and start Query.
    Uri contactRef = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));

    CallerInfoAsyncQuery c = new CallerInfoAsyncQuery();
    c.allocate(context, contactRef);

    if (DBG) log("starting query for number: " + number + " handler: " + c.toString());

    // create cookieWrapper, start query
    CookieWrapper cw = new CookieWrapper();
    cw.listener = listener;
    cw.cookie = cookie;
    cw.number = number;

    // check to see if these are recognized numbers, and use shortcuts if we can.
    if (PhoneNumberUtils.isEmergencyNumber(number)) {
      cw.event = EVENT_EMERGENCY_NUMBER;
    } else if (PhoneNumberUtils.isVoiceMailNumber(number)) {
      cw.event = EVENT_VOICEMAIL_NUMBER;
    } else {
      cw.event = EVENT_NEW_QUERY;
    }

    c.mHandler.startQuery(token, cw, contactRef, null, null, null, null);

    return c;
  }
  @VisibleForTesting
  static boolean isNumberAddress(String number) {
    if (number.contains("@")) return false;
    if (GroupUtil.isEncodedGroup(number)) return false;

    final String networkNumber = PhoneNumberUtils.extractNetworkPortion(number);
    if (TextUtils.isEmpty(networkNumber)) return false;
    if (networkNumber.length() < 3) return false;

    return PhoneNumberUtils.isWellFormedSmsAddress(number);
  }
示例#6
0
  private void deliverPlaintextMessage(SmsMessageRecord message)
      throws UndeliverableMessageException {
    String recipient = message.getIndividualRecipient().getNumber();

    // See issue #1516 for bug report, and discussion on commits related to #4833 for problems
    // related to the original fix to #1516. This still may not be a correct fix if networks allow
    // SMS/MMS sending to alphanumeric recipients other than email addresses, but should also
    // help to fix issue #3099.
    if (!NumberUtil.isValidEmail(recipient)) {
      recipient =
          PhoneNumberUtils.stripSeparators(
              PhoneNumberUtils.convertKeypadLettersToDigits(recipient));
    }

    if (!NumberUtil.isValidSmsOrEmail(recipient)) {
      throw new UndeliverableMessageException("Not a valid SMS destination! " + recipient);
    }

    ArrayList<String> messages = SmsManager.getDefault().divideMessage(message.getBody().getBody());
    ArrayList<PendingIntent> sentIntents =
        constructSentIntents(message.getId(), message.getType(), messages, false);
    ArrayList<PendingIntent> deliveredIntents =
        constructDeliveredIntents(message.getId(), message.getType(), messages);

    // NOTE 11/04/14 -- There's apparently a bug where for some unknown recipients
    // and messages, this will throw an NPE.  We have no idea why, so we're just
    // catching it and marking the message as a failure.  That way at least it doesn't
    // repeatedly crash every time you start the app.
    try {
      getSmsManagerFor(message.getSubscriptionId())
          .sendMultipartTextMessage(recipient, null, messages, sentIntents, deliveredIntents);
    } catch (NullPointerException npe) {
      Log.w(TAG, npe);
      Log.w(TAG, "Recipient: " + recipient);
      Log.w(TAG, "Message Parts: " + messages.size());

      try {
        for (int i = 0; i < messages.size(); i++) {
          getSmsManagerFor(message.getSubscriptionId())
              .sendTextMessage(
                  recipient,
                  null,
                  messages.get(i),
                  sentIntents.get(i),
                  deliveredIntents == null ? null : deliveredIntents.get(i));
        }
      } catch (NullPointerException npe2) {
        Log.w(TAG, npe);
        throw new UndeliverableMessageException(npe2);
      }
    }
  }
 private String formatNumber(String number, String type) {
   if (type != null && type.equals("sip")) {
     return "sip:" + number;
   } else {
     if (!number.startsWith("sip:")) {
       // Code from android source : com/android/phone/OutgoingCallBroadcaster.java
       // so that we match exactly the same case that an outgoing call from android
       number = PhoneNumberUtils.convertKeypadLettersToDigits(number);
       number = PhoneNumberUtils.stripSeparators(number);
     }
     return number;
   }
 }
示例#8
0
 /**
  * Performs another lookup if previous lookup fails and it's a SIP call and the peer's username is
  * all numeric. Look up the username as it could be a PSTN number in the contact database.
  *
  * @param context the query context
  * @param number the original phone number, could be a SIP URI
  * @param previousResult the result of previous lookup
  * @return previousResult if it's not the case
  */
 static CallerInfo doSecondaryLookupIfNecessary(
     Context context, String number, CallerInfo previousResult) {
   if (!previousResult.contactExists && PhoneNumberUtils.isUriNumber(number)) {
     String username = PhoneNumberUtils.getUsernameFromUriNumber(number);
     if (PhoneNumberUtils.isGlobalPhoneNumber(username)) {
       previousResult =
           getCallerInfo(
               context,
               Uri.withAppendedPath(
                   PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, Uri.encode(username)));
     }
   }
   return previousResult;
 }
  private void insertPhone(
      Cursor c,
      SQLiteStatement phoneInsert,
      SQLiteStatement phoneLookupInsert,
      SQLiteStatement hasPhoneUpdate) {
    long lastUpdatedContact = -1;
    long id = c.getLong(PhonesQuery.PERSON);
    String number = c.getString(PhonesQuery.NUMBER);
    String normalizedNumber = null;
    if (number != null) {
      normalizedNumber = PhoneNumberUtils.getStrippedReversed(number);
    }
    phoneInsert.bindLong(PhoneInsert.RAW_CONTACT_ID, id);
    phoneInsert.bindLong(PhoneInsert.MIMETYPE_ID, mPhoneMimetypeId);
    bindString(phoneInsert, PhoneInsert.IS_PRIMARY, c.getString(PhonesQuery.ISPRIMARY));
    bindString(phoneInsert, PhoneInsert.NUMBER, number);
    bindString(phoneInsert, PhoneInsert.TYPE, c.getString(PhonesQuery.TYPE));
    bindString(phoneInsert, PhoneInsert.LABEL, c.getString(PhonesQuery.LABEL));
    bindString(phoneInsert, PhoneInsert.NORMALIZED_NUMBER, normalizedNumber);

    long dataId = insert(phoneInsert);
    if (normalizedNumber != null) {
      phoneLookupInsert.bindLong(PhoneLookupInsert.RAW_CONTACT_ID, id);
      phoneLookupInsert.bindLong(PhoneLookupInsert.DATA_ID, dataId);
      phoneLookupInsert.bindString(PhoneLookupInsert.NORMALIZED_NUMBER, normalizedNumber);
      insert(phoneLookupInsert);

      if (lastUpdatedContact != id) {
        lastUpdatedContact = id;
        hasPhoneUpdate.bindLong(HasPhoneNumberUpdate.CONTACT_ID, id);
        hasPhoneUpdate.execute();
      }
    }
  }
示例#10
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#006666")));
    setContentView(R.layout.contacts_picker_activity);
    mNames = Helpers.getAllContactNames();
    List<String> numbers = Helpers.getAllContactNumbers();
    ArrayList<String> output = getFormattedListEntries(mNames, numbers);
    listAdapter =
        new ArrayAdapter<>(this, android.R.layout.simple_list_item_multiple_choice, output);
    mListView = (ListView) findViewById(R.id.list);
    mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    mListView.setAdapter(listAdapter);

    String noteTitle;
    if (getIntent().getExtras() != null) {
      String checkedContacts = getIntent().getExtras().getString("pre_checked");
      noteTitle = getIntent().getExtras().getString("note");
      boolean revisitingTemporary = getIntent().getExtras().getBoolean("temporary_select");
      if (checkedContacts != null) {
        String[] pre_checked = checkedContacts.split(",");
        for (int i = 0; i < mListView.getCount(); i++) {
          for (String contact : pre_checked) {
            if (PhoneNumberUtils.compare(numbers.get(i), contact)) {
              mListView.setItemChecked(i, true);
            }
          }
        }
      } else if (revisitingTemporary) {
        // Just don't do anything
      } else {
        // checkContacts here
      }
    }
  }
 public boolean shouldCollapseWith(PhoneItem phoneItem) {
   if (PhoneNumberUtils.compare(
       PhoneDisambigDialog.this.mContext, phoneNumber, phoneItem.phoneNumber)) {
     return true;
   }
   return false;
 }
 private byte[] buildAnrData(int length, int adnRecIndex, String anr) {
   byte[] data = new byte[length];
   for (int i = 0; i < length; i++) {
     data[i] = (byte) 0xff;
   }
   if (TextUtils.isEmpty(anr)) {
     Log.w(LOG_TAG, "[buildAnrData] Empty anr record");
     return data; // return the empty record (for delete)
   }
   data[ANR_DESCRIPTION_ID] = (byte) (0x0);
   byte[] byteAnr = PhoneNumberUtils.numberToCalledPartyBCD(anr);
   int maxlength = ANR_ADDITIONAL_NUMBER_END_ID - ANR_ADDITIONAL_NUMBER_START_ID + 1;
   if (byteAnr.length > maxlength) {
     System.arraycopy(byteAnr, 0, data, ANR_TON_NPI_ID, maxlength);
     data[ANR_BCD_NUMBER_LENGTH] = (byte) (maxlength);
   } else {
     System.arraycopy(byteAnr, 0, data, ANR_TON_NPI_ID, byteAnr.length);
     data[ANR_BCD_NUMBER_LENGTH] = (byte) (byteAnr.length);
   }
   data[ANR_CAPABILITY_ID] = (byte) 0xFF;
   data[ANR_EXTENSION_ID] = (byte) 0xFF;
   if (length == 17) {
     // TODO: should update the SFI at the same time???
     int pbrIndex = getPbrIndexBy(adnRecIndex);
     int recordIndex = adnRecIndex - getInitIndexBy(pbrIndex);
     data[ANR_ADN_RECORD_IDENTIFIER_ID] = (byte) (recordIndex + 1);
   }
   Log.w(LOG_TAG, " buildAnrData: data is" + IccUtils.bytesToHexString(data));
   return data;
 }
  /**
   * Performs the appropriate action for a post-dial char, but does not notify application. returns
   * false if the character is invalid and should be ignored
   */
  private boolean processPostDialChar(char c) {
    if (PhoneNumberUtils.is12Key(c)) {
      owner.cm.sendDtmf(c, h.obtainMessage(EVENT_DTMF_DONE));
    } else if (c == PhoneNumberUtils.PAUSE) {
      setPostDialState(PostDialState.PAUSE); // TBD check why it is not in Gsm
      /*
       * From TS 22.101: It continues... Upon the called party answering
       * the UE shall send the DTMF digits automatically to the network
       * after a delay of 3 seconds(plus/minus 20 %). The digits shall be
       * sent according to the procedures and timing specified in 3GPP TS
       * 24.008 [13]. The first occurrence of the
       * "DTMF Control Digits Separator" shall be used by the ME to
       * distinguish between the addressing digits (i.e. the phone number)
       * and the DTMF digits. Upon subsequent occurrences of the
       * separator, the UE shall pause again for 3 seconds before sending
       * any further DTMF digits.
       */

      // TBD 3s for gsm n 2s for cdma check specs
      h.sendMessageDelayed(h.obtainMessage(EVENT_PAUSE_DONE), PAUSE_DELAY_MILLIS);
    } else if (c == PhoneNumberUtils.WAIT) {
      setPostDialState(PostDialState.WAIT);
    } else if (c == PhoneNumberUtils.WILD) {
      setPostDialState(PostDialState.WILD);
    } else {
      return false;
    }

    return true;
  }
示例#14
0
  protected long insertMessageOutbox(
      long threadId, OutgoingTextMessage message, long type, boolean forceSms, long date) {
    if (message.isKeyExchange()) type |= Types.KEY_EXCHANGE_BIT;
    else if (message.isSecureMessage()) type |= Types.SECURE_MESSAGE_BIT;
    else if (message.isEndSession()) type |= Types.END_SESSION_BIT;
    if (forceSms) type |= Types.MESSAGE_FORCE_SMS_BIT;

    ContentValues contentValues = new ContentValues(6);
    contentValues.put(
        ADDRESS,
        PhoneNumberUtils.formatNumber(message.getRecipients().getPrimaryRecipient().getNumber()));
    contentValues.put(THREAD_ID, threadId);
    contentValues.put(BODY, message.getMessageBody());
    contentValues.put(DATE_RECEIVED, System.currentTimeMillis());
    contentValues.put(DATE_SENT, date);
    contentValues.put(READ, 1);
    contentValues.put(TYPE, type);

    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    long messageId = db.insert(TABLE_NAME, ADDRESS, contentValues);

    DatabaseFactory.getThreadDatabase(context).update(threadId, true);
    notifyConversationListeners(threadId);
    jobManager.add(new TrimThreadJob(context, threadId));

    return messageId;
  }
示例#15
0
 /**
  * Add call number info to call history database for international dialing feature !!!! need to
  * check okToLogThisCall is suitable for international dialing feature
  *
  * @param number The number for the call being logged.
  * @param start The start time of the call being logged.
  * @param duration The duration of the call being logged.
  * @param isSipCall whether sip call
  * @param slotId The slot id for the call being logged.
  */
 private void addCallHistoryAsync(
     String number, long start, long duration, boolean isSipCall, int slotId) {
   final boolean isEmergencyNumber = PhoneNumberUtils.isLocalEmergencyNumber(number, mApplication);
   if (!isEmergencyNumber
       && !mIsComing
       && mVtCall != CALL_TYPE_VIDEO
       && !isSipCall
       && duration >= CallNotifier.CALL_DURATION_THRESHOLD_FOR_CALL_HISTORY
       && slotId > -1) {
     String countryISO = CallOptionUtils.getCurrentCountryISO(PhoneGlobals.getInstance());
     try {
       new CallHistoryAsync()
           .addCall(
               new CallHistoryAsync.AddCallArgs(
                   PhoneGlobals.getInstance(),
                   number,
                   countryISO,
                   start,
                   slotId,
                   GeminiUtils.isGeminiSupport()));
     } catch (SQLiteDiskIOException e) {
       // TODO Auto-generated catch block
       Log.e(LOG_TAG, "Error!! - onDisconnect() Disk Full!");
       e.printStackTrace();
     }
   }
 }
  public static String piiHandle(Object pii) {
    if (pii == null || VERBOSE) {
      return String.valueOf(pii);
    }

    StringBuilder sb = new StringBuilder();
    if (pii instanceof Uri) {
      Uri uri = (Uri) pii;
      String scheme = uri.getScheme();

      if (!TextUtils.isEmpty(scheme)) {
        sb.append(scheme).append(":");
      }

      String textToObfuscate = uri.getSchemeSpecificPart();
      if (PhoneAccount.SCHEME_TEL.equals(scheme)) {
        for (int i = 0; i < textToObfuscate.length(); i++) {
          char c = textToObfuscate.charAt(i);
          sb.append(PhoneNumberUtils.isDialable(c) ? "*" : c);
        }
      } else if (PhoneAccount.SCHEME_SIP.equals(scheme)) {
        for (int i = 0; i < textToObfuscate.length(); i++) {
          char c = textToObfuscate.charAt(i);
          if (c != '@' && c != '.') {
            c = '*';
          }
          sb.append(c);
        }
      } else {
        sb.append(pii(pii));
      }
    }

    return sb.toString();
  }
  @Override
  public void dial(String address, int clirMode, UUSInfo uusInfo, Message result) {
    RILRequest rr;
    if (PhoneNumberUtils.isEmergencyNumber(address)) {
      Log.v(LOG_TAG, "Emergency dial: " + address);
      rr = RILRequest.obtain(RIL_REQUEST_DIAL_EMERGENCY, result);
      rr.mp.writeString(address + "/");
    } else {
      rr = RILRequest.obtain(RIL_REQUEST_DIAL, result);
      rr.mp.writeString(address);
    }

    rr.mp.writeInt(clirMode);
    rr.mp.writeInt(0); // UUS information is absent

    if (uusInfo == null) {
      rr.mp.writeInt(0); // UUS information is absent
    } else {
      rr.mp.writeInt(1); // UUS information is present
      rr.mp.writeInt(uusInfo.getType());
      rr.mp.writeInt(uusInfo.getDcs());
      rr.mp.writeByteArray(uusInfo.getUserData());
    }

    if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));

    send(rr);
  }
示例#18
0
 public static void doSendSMSTo(Context context, String phoneNumber, String message) {
   if (PhoneNumberUtils.isGlobalPhoneNumber(phoneNumber)) {
     Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + phoneNumber));
     intent.putExtra("sms_body", message);
     context.startActivity(intent);
   }
 }
示例#19
0
 // Remove a contact from the ContactsCache based on the number or email address
 private void remove(Contact contact) {
   synchronized (ContactsCache.this) {
     String number = contact.getNumber();
     final boolean isNotRegularPhoneNumber =
         contact.isMe() || MessageUtils.isEmailAddress(number) || MessageUtils.isAlias(number);
     final String key = isNotRegularPhoneNumber ? number : key(number, sStaticKeyBuffer);
     ArrayList<Contact> candidates = mContactsHash.get(key);
     if (candidates != null) {
       int length = candidates.size();
       for (int i = 0; i < length; i++) {
         Contact c = candidates.get(i);
         if (isNotRegularPhoneNumber) {
           if (number.equals(c.mNumber)) {
             candidates.remove(i);
             break;
           }
         } else {
           if (PhoneNumberUtils.compare(number, c.mNumber)) {
             candidates.remove(i);
             break;
           }
         }
       }
       if (candidates.size() == 0) {
         mContactsHash.remove(key);
       }
     }
   }
 }
示例#20
0
  /** See TS 51.011 10.5.10 */
  @DSGenerator(
      tool_name = "Doppelganger",
      tool_version = "2.0",
      generated_on = "2013-12-30 12:59:17.042 -0500",
      hash_original_method = "D43EB4B47E694B53E14D637B6CBB15DA",
      hash_generated_method = "7FE5675D2A5F80229B9CC32689C8E510")
  public void appendExtRecord(byte[] extRecord) {
    try {
      if (extRecord.length != EXT_RECORD_LENGTH_BYTES) {
        return;
      }

      if ((extRecord[0] & EXT_RECORD_TYPE_MASK) != EXT_RECORD_TYPE_ADDITIONAL_DATA) {
        return;
      }

      if ((0xff & extRecord[1]) > MAX_EXT_CALLED_PARTY_LENGTH) {
        // invalid or empty record
        return;
      }

      number += PhoneNumberUtils.calledPartyBCDFragmentToString(extRecord, 2, 0xff & extRecord[1]);

      // We don't support ext record chaining.

    } catch (RuntimeException ex) {
      Log.w(LOG_TAG, "Error parsing AdnRecord ext record", ex);
    }
  }
示例#21
0
  /**
   * Send generic SMS
   *
   * @param phoneNumber
   * @param message
   */
  public void sendSms(Context context, String phoneNumber, String message) {
    if (PhoneNumberUtils.isWellFormedSmsAddress(phoneNumber)) {
      String SENT = "SMS_SENT";
      String DELIVERED = "SMS_DELIVERED";

      PendingIntent sentPI =
          PendingIntent.getBroadcast(context.getApplicationContext(), 0, new Intent(SENT), 0);

      PendingIntent deliveredPI =
          PendingIntent.getBroadcast(context.getApplicationContext(), 0, new Intent(DELIVERED), 0);

      /* receive when the SMS has been sent */
      context.getApplicationContext().registerReceiver(SmsSendReceiver, new IntentFilter(SENT));

      /* receive when the SMS has been delivered */
      context
          .getApplicationContext()
          .registerReceiver(SmsDeliveredReceiver, new IntentFilter(DELIVERED));

      Log.d(Constants.TAG, "Sending SMS to " + phoneNumber + " with message: " + message);

      // TODO: make it a preference to switch between data sms and normal sms

      SmsManager smsManager = SmsManager.getDefault();
      smsManager.sendDataMessage(
          phoneNumber, null, Constants.DATA_SMS_PORT, message.getBytes(), sentPI, deliveredPI);
      // smsManager.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
    } else {
      mCryptoCallService.sendUpdateUiToHandler(R.string.status_destination_invalid);
    }
  }
示例#22
0
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    addPreferencesFromResource(R.xml.my_phone_number);
    mPhoneNumberStatus = findPreference(KEY_PHONE_NUMBER_STATUS_PREFERENCE);

    mTelephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);

    mPhone = PhoneFactory.getDefaultPhone();

    String rawNumber = mTelephonyManager.getLine1Number();
    String formattedNumber = null;

    if (!TextUtils.isEmpty(rawNumber)) {
      formattedNumber = PhoneNumberUtils.formatNumber(rawNumber);
    } else {
      formattedNumber = getResources().getString(R.string.unknown);
    }

    mPhoneNumberStatus.setSummary(formattedNumber);

    Log.d(LOG_TAG, " sim state: " + mTelephonyManager.getSimState());

    // Check SIM status
    if (mTelephonyManager.getSimState() != TelephonyManager.SIM_STATE_READY) {
      showNoSimAlertDialog();
    }
  }
 static boolean handleChars(Context context, String s, Activity activity) {
   String s1 = PhoneNumberUtils.stripSeparators(s);
   return handleIMEIDisplay(context, s1)
       || handlePinEntry(context, s1, activity)
       || handleAdnEntry(context, s1)
       || handleSecretCode(context, s1);
 }
 public void startDtmf(char c) {
   if (!PhoneNumberUtils.is12Key(c)) {
     Log.e(LOG_TAG, "startDtmf called with invalid character '" + c + "'");
   } else {
     mCM.startDtmf(c, null);
   }
 }
    protected boolean equalPhoneNumbers(CharArrayBuffer buffer1, CharArrayBuffer buffer2) {

      // TODO add PhoneNumberUtils.compare(CharSequence, CharSequence) to avoid
      // string allocation
      return PhoneNumberUtils.compare(
          new String(buffer1.data, 0, buffer1.sizeCopied),
          new String(buffer2.data, 0, buffer2.sizeCopied));
    }
示例#26
0
 @Override
 public void startDtmf(char c) {
   if (!PhoneNumberUtils.is12Key(c)) {
     loge("startDtmf called with invalid character '" + c + "'");
   } else {
     sendDtmf(c);
   }
 }
示例#27
0
  /** Logs a call to the call from the parameters passed in. */
  public void logCall(
      CallerInfo ci,
      String number,
      int presentation,
      int callType,
      long start,
      long duration,
      int slotId) {
    final boolean isEmergencyNumber = PhoneNumberUtils.isLocalEmergencyNumber(number, mApplication);

    // On some devices, to avoid accidental redialing of
    // emergency numbers, we *never* log emergency calls to
    // the Call Log.  (This behavior is set on a per-product
    // basis, based on carrier requirements.)
    final boolean okToLogEmergencyNumber =
        mApplication.getResources().getBoolean(R.bool.allow_emergency_numbers_in_call_log);

    // Don't log emergency numbers if the device doesn't allow it,
    boolean isOkToLogThisCall = !isEmergencyNumber || okToLogEmergencyNumber;

    if (isOkToLogThisCall) {
      if (DBG) {
        log(
            "sending Calllog entry: "
                + ci
                + ", "
                + PhoneUtils.toLogSafePhoneNumber(number)
                + ","
                + presentation
                + ", "
                + callType
                + ", "
                + start
                + ", "
                + duration);
      }

      /// M: For GEMINI or Other type call(Ex: sip call/video call) @{
      CallLogAsync.AddCallArgs args;
      if (mPhoneType == PhoneConstants.PHONE_TYPE_CDMA && mIsCdmaCallWaitingReject) {
        args =
            getCallArgsForCdmaCallWaitingReject(
                ci, number, presentation, callType, start, duration, slotId);
      } else {
        args = getCallArgs(ci, number, presentation, callType, start, duration, slotId);
      }
      /// @}

      try {
        mCallLog.addCall(args);
      } catch (SQLiteDiskIOException e) {
        // TODO Auto-generated catch block
        Log.e(LOG_TAG, "Error!! - logCall() Disk Full!");
        e.printStackTrace();
      }
    }
    reset();
  }
示例#28
0
  /**
   * Build adn hex byte array based on record size The format of byte array is defined in 51.011
   * 10.5.1
   *
   * @param recordSize is the size X of EF record
   * @return hex byte[recordSize] to be written to EF record return null for wrong format of dialing
   *     number or tag
   */
  public byte[] buildAdnString(int recordSize) {
    byte[] bcdNumber;
    byte[] byteTag;
    byte[] adnString;
    int footerOffset = recordSize - FOOTER_SIZE_BYTES;

    // create an empty record
    adnString = new byte[recordSize];
    for (int i = 0; i < recordSize; i++) {
      adnString[i] = (byte) 0xFF;
    }

    if (TextUtils.isEmpty(number)) {
      Log.w(LOG_TAG, "[buildAdnString] Empty dialing number");
      return adnString; // return the empty record (for delete)
    } else if (number.length() > (ADN_DIALING_NUMBER_END - ADN_DIALING_NUMBER_START + 1) * 2) {
      Log.w(LOG_TAG, "[buildAdnString] Max length of dialing number is 20");
      return null;
    } else if (alphaTag != null && alphaTag.length() > footerOffset) {
      Log.w(LOG_TAG, "[buildAdnString] Max length of tag is " + footerOffset);
      return null;
    } else {
      bcdNumber = PhoneNumberUtils.numberToCalledPartyBCD(number);

      System.arraycopy(bcdNumber, 0, adnString, footerOffset + ADN_TON_AND_NPI, bcdNumber.length);

      adnString[footerOffset + ADN_BCD_NUMBER_LENGTH] = (byte) (bcdNumber.length);
      adnString[footerOffset + ADN_CAPABILITY_ID] = (byte) 0xFF; // Capability Id
      adnString[footerOffset + ADN_EXTENSION_ID] = (byte) 0xFF; // Extension Record Id

      if (TextUtils.isEmpty(alphaTag)) {
        Log.d(LOG_TAG, " alphaTag is " + alphaTag);
      } else if (GsmAlphabet.isStringToGsm8Bit(alphaTag)) {
        byteTag = GsmAlphabet.stringToGsm8BitPacked(alphaTag);
        if (byteTag.length > footerOffset) {
          System.arraycopy(byteTag, 0, adnString, 0, footerOffset);
        } else {
          System.arraycopy(byteTag, 0, adnString, 0, byteTag.length);
        }
        Log.w(LOG_TAG, "use stringToGsm8BitPacked to encode");
      } else {
        adnString[0] = (byte) 0x80;
        try {
          byteTag = alphaTag.getBytes("UTF-16BE");
          if ((byteTag.length + 1) > footerOffset) {
            System.arraycopy(byteTag, 0, adnString, 1, footerOffset - 1);
          } else {
            System.arraycopy(byteTag, 0, adnString, 1, byteTag.length);
          }
          Log.w(LOG_TAG, "use UTF-16BE to encode");
        } catch (UnsupportedEncodingException e) {
          Log.w(LOG_TAG, "encoding alphaTag failed : UnsupportedEncodingException");
        }
      }

      return adnString;
    }
  }
 public void sendDtmf(char c) {
   if (!PhoneNumberUtils.is12Key(c)) {
     Log.e(LOG_TAG, "sendDtmf called with invalid character '" + c + "'");
   } else {
     if (mCT.state == Phone.State.OFFHOOK) {
       mCM.sendDtmf(c, null);
     }
   }
 }
示例#30
0
 /**
  * 跳转至发送短信界面(自动设置接收方的号码)
  *
  * @param mContext
  * @param strPhone 手机号码
  * @param strMsgContext 短信内容
  */
 public static void toSendMessageActivity(
     Context mContext, String strPhone, String strMsgContext) {
   if (PhoneNumberUtils.isGlobalPhoneNumber(strPhone)) {
     Uri uri = Uri.parse("smsto:" + strPhone);
     Intent sendIntent = new Intent(Intent.ACTION_VIEW, uri);
     sendIntent.putExtra("sms_body", strMsgContext);
     mContext.startActivity(sendIntent);
   }
 }