Merge changes I44dc66f9,I72ee7af9

* changes:
  Avoid UnsupportedOperationException from getDefaultSmsSubscriptionId()
  Fix the default sub id returned by SmsManager.
This commit is contained in:
Amit Mahajan
2019-06-13 22:47:13 +00:00
committed by Gerrit Code Review

View File

@@ -1958,16 +1958,24 @@ public final class SmsManager {
}
/**
* Get default sms subscription id
* Get default sms subscription id.
*
* @return the user-defined default SMS subscription id or
* {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} if no default is set.
* <p class="note"><strong>Note:</strong>This returns a value different from
* {@link SubscriptionManager#getDefaultSmsSubscriptionId} if the user has not chosen a default.
* In this case it returns the active subscription id if there's only one active subscription
* available.
*
* @return the user-defined default SMS subscription id, or the active subscription id if
* there's only one active subscription available, otherwise
* {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID}.
*/
public static int getDefaultSmsSubscriptionId() {
try {
return SubscriptionManager.getDefaultSmsSubscriptionId();
} catch (NullPointerException ex) {
return -1;
return getISmsService().getPreferredSmsSubscription();
} catch (RemoteException e) {
return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
} catch (NullPointerException e) {
return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
}
}