From 76ab5fb247b7ab6e5e12c3cdb898ecd2a610930b Mon Sep 17 00:00:00 2001 From: Tyler Gunn Date: Wed, 25 Mar 2020 17:49:35 -0700 Subject: [PATCH] Fix potential issue where sub info change listener is not registered. SubscriptionManager#addOnSubscriptionsChangedListener can fail to register a listener if the TELEPHONY_REGISTRY system service is not up. Currently this is just silently ignored. Adding a callback method on the listener to notify the registrant that the listener failed to be registered, and adding exponential backoff code in TelecomAccountRegistry to retry registration. Test: Manual; edited code in Subscriptionmanager to fail the first attempts to add a listener for TelecomAccountRegistry. Verified the backoff took place and registration still occurred for the listener. Test: Tried to write a mockito test but gave up because this code has far too many intertwined dependencies and is not inherently testable Bug: 152217039 Fixes: 153376310 Change-Id: Icf3133cdeca526979cb621f29659b880127b680a Merged-In: Ib032072dcfd2d3d5e700e380af08b7b3142ebb8e --- .../android/telephony/SubscriptionManager.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index d4a76b7c11545..7f2c6c17d5086 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -948,6 +948,18 @@ public class SubscriptionManager { if (DBG) log("onSubscriptionsChanged: NOT OVERRIDDEN"); } + /** + * Callback invoked when {@link SubscriptionManager#addOnSubscriptionsChangedListener( + * Executor, OnSubscriptionsChangedListener)} or + * {@link SubscriptionManager#addOnSubscriptionsChangedListener( + * OnSubscriptionsChangedListener)} fails to complete due to the + * {@link Context#TELEPHONY_REGISTRY_SERVICE} being unavailable. + * @hide + */ + public void onAddListenerFailed() { + Rlog.w(LOG_TAG, "onAddListenerFailed not overridden"); + } + private void log(String s) { Rlog.d(LOG_TAG, s); } @@ -1028,6 +1040,12 @@ public class SubscriptionManager { if (telephonyRegistryManager != null) { telephonyRegistryManager.addOnSubscriptionsChangedListener(listener, executor); + } else { + // If the telephony registry isn't available, we will inform the caller on their + // listener that it failed so they can try to re-register. + loge("addOnSubscriptionsChangedListener: pkgname=" + pkgName + " failed to be added " + + " due to TELEPHONY_REGISTRY_SERVICE being unavailable."); + executor.execute(() -> listener.onAddListenerFailed()); } }