public void testIsPossibleShortNumber() {
    PhoneNumber possibleNumber = new PhoneNumber();
    possibleNumber.setCountryCode(33).setNationalNumber(123456L);
    assertTrue(shortInfo.isPossibleShortNumber(possibleNumber));
    assertTrue(
        shortInfo.isPossibleShortNumberForRegion(parse("123456", RegionCode.FR), RegionCode.FR));

    PhoneNumber impossibleNumber = new PhoneNumber();
    impossibleNumber.setCountryCode(33).setNationalNumber(9L);
    assertFalse(shortInfo.isPossibleShortNumber(impossibleNumber));

    // Note that GB and GG share the country calling code 44, and that this number is possible but
    // not valid.
    assertTrue(
        shortInfo.isPossibleShortNumber(
            new PhoneNumber().setCountryCode(44).setNationalNumber(11001L)));
  }
  public void testGetExpectedCost() {
    String premiumRateExample =
        shortInfo.getExampleShortNumberForCost(
            RegionCode.FR, ShortNumberInfo.ShortNumberCost.PREMIUM_RATE);
    assertEquals(
        ShortNumberInfo.ShortNumberCost.PREMIUM_RATE,
        shortInfo.getExpectedCostForRegion(
            parse(premiumRateExample, RegionCode.FR), RegionCode.FR));
    PhoneNumber premiumRateNumber = new PhoneNumber();
    premiumRateNumber.setCountryCode(33).setNationalNumber(Integer.parseInt(premiumRateExample));
    assertEquals(
        ShortNumberInfo.ShortNumberCost.PREMIUM_RATE, shortInfo.getExpectedCost(premiumRateNumber));

    String standardRateExample =
        shortInfo.getExampleShortNumberForCost(
            RegionCode.FR, ShortNumberInfo.ShortNumberCost.STANDARD_RATE);
    assertEquals(
        ShortNumberInfo.ShortNumberCost.STANDARD_RATE,
        shortInfo.getExpectedCostForRegion(
            parse(standardRateExample, RegionCode.FR), RegionCode.FR));
    PhoneNumber standardRateNumber = new PhoneNumber();
    standardRateNumber.setCountryCode(33).setNationalNumber(Integer.parseInt(standardRateExample));
    assertEquals(
        ShortNumberInfo.ShortNumberCost.STANDARD_RATE,
        shortInfo.getExpectedCost(standardRateNumber));

    String tollFreeExample =
        shortInfo.getExampleShortNumberForCost(
            RegionCode.FR, ShortNumberInfo.ShortNumberCost.TOLL_FREE);
    assertEquals(
        ShortNumberInfo.ShortNumberCost.TOLL_FREE,
        shortInfo.getExpectedCostForRegion(parse(tollFreeExample, RegionCode.FR), RegionCode.FR));
    PhoneNumber tollFreeNumber = new PhoneNumber();
    tollFreeNumber.setCountryCode(33).setNationalNumber(Integer.parseInt(tollFreeExample));
    assertEquals(
        ShortNumberInfo.ShortNumberCost.TOLL_FREE, shortInfo.getExpectedCost(tollFreeNumber));

    assertEquals(
        ShortNumberInfo.ShortNumberCost.UNKNOWN_COST,
        shortInfo.getExpectedCostForRegion(parse("12345", RegionCode.FR), RegionCode.FR));
    PhoneNumber unknownCostNumber = new PhoneNumber();
    unknownCostNumber.setCountryCode(33).setNationalNumber(12345L);
    assertEquals(
        ShortNumberInfo.ShortNumberCost.UNKNOWN_COST, shortInfo.getExpectedCost(unknownCostNumber));

    // Test that an invalid number may nevertheless have a cost other than UNKNOWN_COST.
    assertFalse(
        shortInfo.isValidShortNumberForRegion(parse("116123", RegionCode.FR), RegionCode.FR));
    assertEquals(
        ShortNumberInfo.ShortNumberCost.TOLL_FREE,
        shortInfo.getExpectedCostForRegion(parse("116123", RegionCode.FR), RegionCode.FR));
    PhoneNumber invalidNumber = new PhoneNumber();
    invalidNumber.setCountryCode(33).setNationalNumber(116123L);
    assertFalse(shortInfo.isValidShortNumber(invalidNumber));
    assertEquals(
        ShortNumberInfo.ShortNumberCost.TOLL_FREE, shortInfo.getExpectedCost(invalidNumber));

    // Test a nonexistent country code.
    assertEquals(
        ShortNumberInfo.ShortNumberCost.UNKNOWN_COST,
        shortInfo.getExpectedCostForRegion(parse("911", RegionCode.US), RegionCode.ZZ));
    unknownCostNumber.clear();
    unknownCostNumber.setCountryCode(123).setNationalNumber(911L);
    assertEquals(
        ShortNumberInfo.ShortNumberCost.UNKNOWN_COST, shortInfo.getExpectedCost(unknownCostNumber));
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.number_validation);

    mAccountManager = AccountManager.get(this);
    mHandler = new Handler();

    lbm = LocalBroadcastManager.getInstance(getApplicationContext());

    final Intent intent = getIntent();
    mFromInternal = intent.getBooleanExtra(PARAM_FROM_INTERNAL, false);

    mNameText = (EditText) findViewById(R.id.name);
    mCountryCode = (Spinner) findViewById(R.id.phone_cc);
    mPhone = (EditText) findViewById(R.id.phone_number);
    mValidateButton = (Button) findViewById(R.id.button_validate);
    mInsertCode = (Button) findViewById(R.id.button_validation_code);

    // populate country codes
    final CountryCodesAdapter ccList =
        new CountryCodesAdapter(this, R.layout.country_item, R.layout.country_dropdown_item);
    PhoneNumberUtil util = PhoneNumberUtil.getInstance();
    Set<String> ccSet = getSupportedRegions(util);
    for (String cc : ccSet) ccList.add(cc);

    ccList.sort(
        new Comparator<CountryCodesAdapter.CountryCode>() {
          public int compare(
              CountryCodesAdapter.CountryCode lhs, CountryCodesAdapter.CountryCode rhs) {
            return lhs.regionName.compareTo(rhs.regionName);
          }
        });
    mCountryCode.setAdapter(ccList);
    mCountryCode.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ccList.setSelected(position);
          }

          public void onNothingSelected(AdapterView<?> parent) {
            // TODO Auto-generated method stub
          }
        });

    // FIXME this doesn't consider creation because of configuration change
    PhoneNumber myNum = NumberValidator.getMyNumber(this);
    if (myNum != null) {
      mPhone.setText(String.valueOf(myNum.getNationalNumber()));
      Log.d(TAG, "selecting country " + util.getRegionCodeForNumber(myNum));
      CountryCode cc = new CountryCode();
      cc.regionCode = util.getRegionCodeForNumber(myNum);
      cc.countryCode = myNum.getCountryCode();
      mCountryCode.setSelection(ccList.getPositionForId(cc));
    } else {
      final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
      final String regionCode = tm.getSimCountryIso().toUpperCase(Locale.US);
      CountryCode cc = new CountryCode();
      cc.regionCode = regionCode;
      cc.countryCode = util.getCountryCodeForRegion(regionCode);
      mCountryCode.setSelection(ccList.getPositionForId(cc));
    }

    // configuration change??
    RetainData data = (RetainData) getLastCustomNonConfigurationInstance();
    if (data != null) {
      synchronized (this) {
        // sync starter was queued, we can exit
        if (data.syncing) {
          delayedSync();
        }

        mValidator = data.validator;
        if (mValidator != null) mValidator.setListener(this);
      }
      if (data.progressMessage != null) {
        setProgressMessage(data.progressMessage, true);
      }
    }
  }
 /**
  * As per {@link #lookup(long)}, but receives the number as a PhoneNumber instead of a long.
  *
  * @param number the phone number to look up
  * @return the description corresponding to the prefix that best matches this phone number
  */
 public String lookup(PhoneNumber number) {
   long phonePrefix =
       Long.parseLong(number.getCountryCode() + phoneUtil.getNationalSignificantNumber(number));
   return lookup(phonePrefix);
 }