diff options
Diffstat (limited to 'telephony/java/android')
5 files changed, 105 insertions, 78 deletions
diff --git a/telephony/java/android/telephony/CellIdentityCdma.java b/telephony/java/android/telephony/CellIdentityCdma.java index dbd48d9..b39b4c7 100644 --- a/telephony/java/android/telephony/CellIdentityCdma.java +++ b/telephony/java/android/telephony/CellIdentityCdma.java @@ -20,6 +20,8 @@ import android.os.Parcel; import android.os.Parcelable; import android.telephony.Rlog; +import java.util.Objects; + /** * CellIdentity is to represent a unique CDMA cell */ @@ -137,27 +139,25 @@ public final class CellIdentityCdma implements Parcelable { @Override public int hashCode() { - int primeNum = 31; - return (mNetworkId * primeNum) + (mSystemId * primeNum) + (mBasestationId * primeNum) + - (mLatitude * primeNum) + (mLongitude * primeNum); + return Objects.hash(mNetworkId, mSystemId, mBasestationId, mLatitude, mLongitude); } @Override public boolean equals(Object other) { - if (super.equals(other)) { - try { - CellIdentityCdma o = (CellIdentityCdma)other; - return mNetworkId == o.mNetworkId && - mSystemId == o.mSystemId && - mBasestationId == o.mBasestationId && - mLatitude == o.mLatitude && - mLongitude == o.mLongitude; - } catch (ClassCastException e) { - return false; - } - } else { + if (this == other) { + return true; + } + + if (!(other instanceof CellIdentityCdma)) { return false; } + + CellIdentityCdma o = (CellIdentityCdma) other; + return mNetworkId == o.mNetworkId && + mSystemId == o.mSystemId && + mBasestationId == o.mBasestationId && + mLatitude == o.mLatitude && + mLongitude == o.mLongitude; } @Override diff --git a/telephony/java/android/telephony/CellIdentityGsm.java b/telephony/java/android/telephony/CellIdentityGsm.java index 6f8cc91..90d2aa0 100644 --- a/telephony/java/android/telephony/CellIdentityGsm.java +++ b/telephony/java/android/telephony/CellIdentityGsm.java @@ -20,6 +20,8 @@ import android.os.Parcel; import android.os.Parcelable; import android.telephony.Rlog; +import java.util.Objects; + /** * CellIdentity to represent a unique GSM cell */ @@ -113,25 +115,24 @@ public final class CellIdentityGsm implements Parcelable { @Override public int hashCode() { - int primeNum = 31; - return (mMcc * primeNum) + (mMnc * primeNum) + (mLac * primeNum) + (mCid * primeNum); + return Objects.hash(mMcc, mMnc, mLac, mCid); } @Override public boolean equals(Object other) { - if (super.equals(other)) { - try { - CellIdentityGsm o = (CellIdentityGsm)other; - return mMcc == o.mMcc && - mMnc == o.mMnc && - mLac == o.mLac && - mCid == o.mCid; - } catch (ClassCastException e) { - return false; - } - } else { + if (this == other) { + return true; + } + + if (!(other instanceof CellIdentityGsm)) { return false; } + + CellIdentityGsm o = (CellIdentityGsm) other; + return mMcc == o.mMcc && + mMnc == o.mMnc && + mLac == o.mLac && + mCid == o.mCid; } @Override diff --git a/telephony/java/android/telephony/CellIdentityLte.java b/telephony/java/android/telephony/CellIdentityLte.java index 72578a4..1e7ac08 100644 --- a/telephony/java/android/telephony/CellIdentityLte.java +++ b/telephony/java/android/telephony/CellIdentityLte.java @@ -20,6 +20,8 @@ import android.os.Parcel; import android.os.Parcelable; import android.telephony.Rlog; +import java.util.Objects; + /** * CellIdentity is to represent a unique LTE cell */ @@ -117,27 +119,25 @@ public final class CellIdentityLte implements Parcelable { @Override public int hashCode() { - int primeNum = 31; - return (mMcc * primeNum) + (mMnc * primeNum) + (mCi * primeNum) + (mPci * primeNum) + - (mTac * primeNum); + return Objects.hash(mMcc, mMnc, mCi, mPci, mTac); } @Override public boolean equals(Object other) { - if (super.equals(other)) { - try { - CellIdentityLte o = (CellIdentityLte)other; - return mMcc == o.mMcc && - mMnc == o.mMnc && - mCi == o.mCi && - mPci == o.mPci && - mTac == o.mTac; - } catch (ClassCastException e) { - return false; - } - } else { + if (this == other) { + return true; + } + + if (!(other instanceof CellIdentityLte)) { return false; } + + CellIdentityLte o = (CellIdentityLte) other; + return mMcc == o.mMcc && + mMnc == o.mMnc && + mCi == o.mCi && + mPci == o.mPci && + mTac == o.mTac; } @Override diff --git a/telephony/java/android/telephony/CellIdentityWcdma.java b/telephony/java/android/telephony/CellIdentityWcdma.java index 2f8fa42..56ee8c9 100644 --- a/telephony/java/android/telephony/CellIdentityWcdma.java +++ b/telephony/java/android/telephony/CellIdentityWcdma.java @@ -20,6 +20,8 @@ import android.os.Parcel; import android.os.Parcelable; import android.telephony.Rlog; +import java.util.Objects; + /** * CellIdentity to represent a unique UMTS cell */ @@ -118,27 +120,25 @@ public final class CellIdentityWcdma implements Parcelable { @Override public int hashCode() { - int primeNum = 31; - return (mMcc * primeNum) + (mMnc * primeNum) + (mLac * primeNum) + (mCid * primeNum) + - (mPsc * primeNum); + return Objects.hash(mMcc, mMnc, mLac, mCid, mPsc); } @Override public boolean equals(Object other) { - if (super.equals(other)) { - try { - CellIdentityWcdma o = (CellIdentityWcdma)other; - return mMcc == o.mMcc && - mMnc == o.mMnc && - mLac == o.mLac && - mCid == o.mCid && - mPsc == o.mPsc; - } catch (ClassCastException e) { - return false; - } - } else { + if (this == other) { + return true; + } + + if (!(other instanceof CellIdentityWcdma)) { return false; } + + CellIdentityWcdma o = (CellIdentityWcdma) other; + return mMcc == o.mMcc && + mMnc == o.mMnc && + mLac == o.mLac && + mCid == o.mCid && + mPsc == o.mPsc; } @Override diff --git a/telephony/java/android/telephony/PhoneNumberUtils.java b/telephony/java/android/telephony/PhoneNumberUtils.java index 7ab189c..a59505c 100644 --- a/telephony/java/android/telephony/PhoneNumberUtils.java +++ b/telephony/java/android/telephony/PhoneNumberUtils.java @@ -1145,6 +1145,7 @@ public class PhoneNumberUtils * * @deprecated Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead */ + @Deprecated public static String formatNumber(String source) { SpannableStringBuilder text = new SpannableStringBuilder(source); formatNumber(text, getFormatTypeForLocale(Locale.getDefault())); @@ -1163,6 +1164,7 @@ public class PhoneNumberUtils * @hide * @deprecated Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead */ + @Deprecated public static String formatNumber(String source, int defaultFormattingType) { SpannableStringBuilder text = new SpannableStringBuilder(source); formatNumber(text, defaultFormattingType); @@ -1178,6 +1180,7 @@ public class PhoneNumberUtils * * @deprecated Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead */ + @Deprecated public static int getFormatTypeForLocale(Locale locale) { String country = locale.getCountry(); @@ -1194,6 +1197,7 @@ public class PhoneNumberUtils * * @deprecated Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead */ + @Deprecated public static void formatNumber(Editable text, int defaultFormattingType) { int formatType = defaultFormattingType; @@ -1242,6 +1246,7 @@ public class PhoneNumberUtils * * @deprecated Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead */ + @Deprecated public static void formatNanpNumber(Editable text) { int length = text.length(); if (length > "+1-nnn-nnn-nnnn".length()) { @@ -1357,6 +1362,7 @@ public class PhoneNumberUtils * * @deprecated Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead */ + @Deprecated public static void formatJapaneseNumber(Editable text) { JapanesePhoneNumberFormatter.format(text); } @@ -1378,32 +1384,52 @@ public class PhoneNumberUtils } /** - * Format the given phoneNumber to the E.164 representation. + * Formats the specified {@code phoneNumber} to the E.164 representation. + * + * @param phoneNumber the phone number to format. + * @param defaultCountryIso the ISO 3166-1 two letters country code. + * @return the E.164 representation, or null if the given phone number is not valid. + */ + public static String formatNumberToE164(String phoneNumber, String defaultCountryIso) { + return formatNumberInternal(phoneNumber, defaultCountryIso, PhoneNumberFormat.E164); + } + + /** + * Formats the specified {@code phoneNumber} to the RFC3966 representation. + * + * @param phoneNumber the phone number to format. + * @param defaultCountryIso the ISO 3166-1 two letters country code. + * @return the RFC3966 representation, or null if the given phone number is not valid. + */ + public static String formatNumberToRFC3966(String phoneNumber, String defaultCountryIso) { + return formatNumberInternal(phoneNumber, defaultCountryIso, PhoneNumberFormat.RFC3966); + } + + /** + * Formats the raw phone number (string) using the specified {@code formatIdentifier}. * <p> - * The given phone number must have an area code and could have a country - * code. + * The given phone number must have an area code and could have a country code. * <p> - * The defaultCountryIso is used to validate the given number and generate - * the E.164 phone number if the given number doesn't have a country code. + * The defaultCountryIso is used to validate the given number and generate the formatted number + * if the specified number doesn't have a country code. * - * @param phoneNumber - * the phone number to format - * @param defaultCountryIso - * the ISO 3166-1 two letters country code - * @return the E.164 representation, or null if the given phone number is - * not valid. + * @param rawPhoneNumber The phone number to format. + * @param defaultCountryIso The ISO 3166-1 two letters country code. + * @param formatIdentifier The (enum) identifier of the desired format. + * @return the formatted representation, or null if the specified number is not valid. */ - public static String formatNumberToE164(String phoneNumber, String defaultCountryIso) { + private static String formatNumberInternal( + String rawPhoneNumber, String defaultCountryIso, PhoneNumberFormat formatIdentifier) { + PhoneNumberUtil util = PhoneNumberUtil.getInstance(); - String result = null; try { - PhoneNumber pn = util.parse(phoneNumber, defaultCountryIso); - if (util.isValidNumber(pn)) { - result = util.format(pn, PhoneNumberFormat.E164); + PhoneNumber phoneNumber = util.parse(rawPhoneNumber, defaultCountryIso); + if (util.isValidNumber(phoneNumber)) { + return util.format(phoneNumber, formatIdentifier); } - } catch (NumberParseException e) { - } - return result; + } catch (NumberParseException ignored) { } + + return null; } /** @@ -2458,7 +2484,7 @@ public class PhoneNumberUtils * * @param number SIP address of the form "username@domainname" * (or the URI-escaped equivalent "username%40domainname") - * @see isUriNumber + * @see #isUriNumber * * @hide */ |