Fix sorting issue during emergency call attempt.

Fix the integer overflow/underflow caused by sorting of duplicate phoneaccounts during emergency call attempt. 

Bug: 208267659
Original change:
Merged-In: I3529e4f86ba5690a8c2e72d6103a84c00bf3f358
Change-Id: I3529e4f86ba5690a8c2e72d6103a84c00bf3f358
Test: Added unit test (see
Test: Manual testing performed to confirm that this corrects repro.
(cherry picked from commit e20b83ec9b3dc2bc5a49a666bd057cf45ce99f15)
(cherry picked from commit 4f64285184fbad85a0a554f3cefa821846be8002)
diff --git a/src/com/android/server/telecom/ b/src/com/android/server/telecom/
index 2e67b08..e3b8dee 100644
--- a/src/com/android/server/telecom/
+++ b/src/com/android/server/telecom/
@@ -661,7 +661,7 @@
             // then by hashcode
-            return account1.hashCode() - account2.hashCode();
+            return, account2.hashCode());