diff options
| author | 2018-10-17 22:12:02 +0000 | |
|---|---|---|
| committer | 2018-10-17 22:12:02 +0000 | |
| commit | a9d551ca7b59bb2bc43ee85bc8ac886cf8b4a697 (patch) | |
| tree | 3537ba156018248d863ac3946337b3ba87107fc0 | |
| parent | ea008f1429a388aa35638ea4e1de4beeea605380 (diff) | |
| parent | 5660149817134b5f1bce8d46acfcdfc45e4f81ff (diff) | |
Merge "Compare Emergency number display priority"
| -rwxr-xr-x | api/current.txt | 3 | ||||
| -rw-r--r-- | telephony/java/android/telephony/emergency/EmergencyNumber.java | 100 |
2 files changed, 82 insertions, 21 deletions
diff --git a/api/current.txt b/api/current.txt index 1f29fcb0ceb5..b691ef37492e 100755 --- a/api/current.txt +++ b/api/current.txt @@ -43032,7 +43032,8 @@ package android.telephony.data { package android.telephony.emergency { - public final class EmergencyNumber implements android.os.Parcelable { + public final class EmergencyNumber implements java.lang.Comparable android.os.Parcelable { + method public int compareTo(android.telephony.emergency.EmergencyNumber); method public int describeContents(); method public java.lang.String getCountryIso(); method public int getEmergencyNumberSourceBitmask(); diff --git a/telephony/java/android/telephony/emergency/EmergencyNumber.java b/telephony/java/android/telephony/emergency/EmergencyNumber.java index d6a08543b9cd..bdba8c860db0 100644 --- a/telephony/java/android/telephony/emergency/EmergencyNumber.java +++ b/telephony/java/android/telephony/emergency/EmergencyNumber.java @@ -33,7 +33,7 @@ import java.util.Set; * A parcelable class that wraps and retrieves the information of number, service category(s) and * country code for a specific emergency number. */ -public final class EmergencyNumber implements Parcelable { +public final class EmergencyNumber implements Parcelable, Comparable<EmergencyNumber> { private static final String LOG_TAG = "EmergencyNumber"; @@ -235,20 +235,22 @@ public final class EmergencyNumber implements Parcelable { } /** - * Returns the bitmask of emergency service categories {@link EmergencyServiceCategories} of - * the emergency number. + * Returns the bitmask of emergency service categories of the emergency number. * - * @return bitmask of the emergency service categories {@link EmergencyServiceCategories} + * @return bitmask of the emergency service categories */ public @EmergencyServiceCategories int getEmergencyServiceCategoryBitmask() { return mEmergencyServiceCategoryBitmask; } /** - * Returns the emergency service categories {@link EmergencyServiceCategories} of the emergency - * number. + * Returns the emergency service categories of the emergency number. * - * @return a list of the emergency service categories {@link EmergencyServiceCategories} + * Note: if the emergency number is in {@link #EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED}, only + * {@link #EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED} is returned and it means the number is in + * all categories. + * + * @return a list of the emergency service categories */ public List<Integer> getEmergencyServiceCategories() { List<Integer> categories = new ArrayList<>(); @@ -276,34 +278,37 @@ public final class EmergencyNumber implements Parcelable { } /** - * Checks if the emergency number is in the specified emergency service category(s) - * {@link EmergencyServiceCategories}. + * Checks if the emergency number is in the supplied emergency service category(s). * - * @return {@code true} if the emergency number is in the specified emergency service - * category(s) {@link EmergencyServiceCategories}; {@code false} otherwise. + * @param categories - the supplied emergency service categories * - * @param categories - emergency service categories {@link EmergencyServiceCategories} + * @return {@code true} if the emergency number is in the specified emergency service + * category(s) or if its emergency service category is + * {@link #EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED}; {@code false} otherwise. */ public boolean isInEmergencyServiceCategories(@EmergencyServiceCategories int categories) { if (categories == EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED) { return serviceUnspecified(); } + if (serviceUnspecified()) { + return true; + } return (mEmergencyServiceCategoryBitmask & categories) == categories; } /** - * Returns the bitmask of the sources {@link EmergencyNumberSources} of the emergency number. + * Returns the bitmask of the sources of the emergency number. * - * @return bitmask of the emergency number sources {@link EmergencyNumberSources} + * @return bitmask of the emergency number sources */ public @EmergencyNumberSources int getEmergencyNumberSourceBitmask() { return mEmergencyNumberSourceBitmask; } /** - * Returns a list of {@link EmergencyNumberSources} of the emergency number. + * Returns a list of sources of the emergency number. * - * @return a list of {@link EmergencyNumberSources} + * @return a list of emergency number sources */ public List<Integer> getEmergencyNumberSources() { List<Integer> sources = new ArrayList<>(); @@ -316,13 +321,12 @@ public final class EmergencyNumber implements Parcelable { } /** - * Checks if the emergency number is from the specified emergency number source(s) - * {@link EmergencyNumberSources}. + * Checks if the emergency number is from the specified emergency number source(s). * * @return {@code true} if the emergency number is from the specified emergency number - * source(s) {@link EmergencyNumberSources}; {@code false} otherwise. + * source(s); {@code false} otherwise. * - * @param sources - {@link EmergencyNumberSources} + * @param sources - the supplied emergency number sources */ public boolean isFromSources(@EmergencyNumberSources int sources) { return (mEmergencyNumberSourceBitmask & sources) == sources; @@ -359,6 +363,62 @@ public final class EmergencyNumber implements Parcelable { return (o == this || toString().equals(o.toString())); } + /** + * Calculate the score for display priority. + * + * A higher display priority score means the emergency number has a higher display priority. + * The score is higher if the source is defined for a higher display priority. + * + * The priority of sources are defined as follows: + * EMERGENCY_NUMBER_SOURCE_NETWORK_SIGNALING > + * EMERGENCY_NUMBER_SOURCE_SIM > + * EMERGENCY_NUMBER_SOURCE_DEFAULT > + * EMERGENCY_NUMBER_SOURCE_MODEM_CONFIG + * + */ + private int getDisplayPriorityScore() { + int score = 0; + if (this.isFromSources(EMERGENCY_NUMBER_SOURCE_NETWORK_SIGNALING)) { + score += 1 << 4; + } + if (this.isFromSources(EMERGENCY_NUMBER_SOURCE_SIM)) { + score += 1 << 3; + } + // TODO add a score if the number comes from Google's emergency number database + if (this.isFromSources(EMERGENCY_NUMBER_SOURCE_DEFAULT)) { + score += 1 << 1; + } + if (this.isFromSources(EMERGENCY_NUMBER_SOURCE_MODEM_CONFIG)) { + score += 1 << 0; + } + return score; + } + + /** + * Compare the display priority for this emergency number and the supplied emergency number. + * + * @param emergencyNumber the supplied emergency number + * @return a negative value if the supplied emergency number has a lower display priority; + * a positive value if the supplied emergency number has a higher display priority; + * 0 if both have equal display priority. + */ + @Override + public int compareTo(EmergencyNumber emergencyNumber) { + if (this.getDisplayPriorityScore() + > emergencyNumber.getDisplayPriorityScore()) { + return -1; + } else if (this.getDisplayPriorityScore() + < emergencyNumber.getDisplayPriorityScore()) { + return 1; + } else { + /** + * TODO if both numbers have the same display priority score, the number matches the + * Google's emergency number database has a higher display priority. + */ + return 0; + } + } + public static final Parcelable.Creator<EmergencyNumber> CREATOR = new Parcelable.Creator<EmergencyNumber>() { @Override |