diff options
| author | 2022-07-29 07:39:36 -0700 | |
|---|---|---|
| committer | 2022-08-10 16:52:20 +0000 | |
| commit | 0d9ec2f351a257ca06eae2be600b2aaf195631fb (patch) | |
| tree | 7223d62b74a9f3f2e0a3587282007c4e9253d4a3 | |
| parent | cbaad935eecaf2d919f737bf84be9d247c6b223c (diff) | |
Correct cache use in SubscriptionManager
Bug: 234632427
Change the SubscriptionManager caches so that error conditions
(RemoteException, null ISub, TimeoutException) do not generate values
in the cache. Instead, these error conditions are handled above the
cache.
Test: atest
* SubscriptionControllerTest
* android.telephony.cts.SubscriptionManagerTest
Change-Id: I758a4636a49e7889cfd08b613e90cb09411fc8ab
| -rw-r--r-- | telephony/java/android/telephony/SubscriptionManager.java | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 1f97d862fb6b..f28408e1abc9 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -194,13 +194,24 @@ public class SubscriptionManager { } @Override - public T recompute(Void aVoid) { + public T recompute(Void query) { + // This always throws on any error. The exceptions must be handled outside + // the cache. + try { + return mInterfaceMethod.applyOrThrow(TelephonyManager.getSubscriptionService()); + } catch (Exception re) { + throw new RuntimeException(re); + } + } + + @Override + public T query(Void query) { T result = mDefaultValue; try { ISub iSub = TelephonyManager.getSubscriptionService(); if (iSub != null) { - result = mInterfaceMethod.applyOrThrow(iSub); + result = super.query(query); } } catch (Exception ex) { Rlog.w(LOG_TAG, "Failed to recompute cache key for " + mCacheKeyProperty); @@ -229,12 +240,24 @@ public class SubscriptionManager { @Override public T recompute(Integer query) { + // This always throws on any error. The exceptions must be handled outside + // the cache. + try { + return mInterfaceMethod.applyOrThrow( + TelephonyManager.getSubscriptionService(), query); + } catch (Exception re) { + throw new RuntimeException(re); + } + } + + @Override + public T query(Integer query) { T result = mDefaultValue; try { ISub iSub = TelephonyManager.getSubscriptionService(); if (iSub != null) { - result = mInterfaceMethod.applyOrThrow(iSub, query); + result = super.query(query); } } catch (Exception ex) { Rlog.w(LOG_TAG, "Failed to recompute cache key for " + mCacheKeyProperty); @@ -4118,4 +4141,3 @@ public class SubscriptionManager { usageSetting, subscriptionId, mContext.getOpPackageName())); } } - |