From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Thomas Stuart Date: Thu, 23 Jun 2022 14:20:30 -0700 Subject: [PATCH] switch TelecomManager List getters to ParceledListSlice It was shown that given a large phoneAccountHandles that are over 1 mb, a TransactionTooLarge exception can be silently thrown causing an empty list to be returned. In order to prevent this behavior, all Lists that return a PhoneAccountHandle or PhoneAccount have been switched to ParceledListSlice. bug: 236263294 Test: atest android.telecom.cts.PhoneAccountRegistrarTest #testRegisterPhoneAccountHandleWithFieldOverLimit Change-Id: Ibc3814dabd59cf9f0f9505b88f2146a4c3c5e015 Merged-In: Ibc3814dabd59cf9f0f9505b88f2146a4c3c5e015 (cherry picked from commit 960147d4bba558c87a26df6f0328df637a30479b) Merged-In: Ibc3814dabd59cf9f0f9505b88f2146a4c3c5e015 --- .../server/telecom/TelecomServiceImpl.java | 44 +++++++++++-------- .../telecom/tests/TelecomServiceImplTest.java | 21 +++++---- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/com/android/server/telecom/TelecomServiceImpl.java b/src/com/android/server/telecom/TelecomServiceImpl.java index f2e85c64c..6bb1a1226 100644 --- a/src/com/android/server/telecom/TelecomServiceImpl.java +++ b/src/com/android/server/telecom/TelecomServiceImpl.java @@ -32,6 +32,8 @@ import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.Resources; +import android.content.pm.ParceledListSlice; +import android.content.pm.ResolveInfo; import android.net.Uri; import android.os.Binder; import android.os.Bundle; @@ -176,19 +178,20 @@ public class TelecomServiceImpl { } @Override - public List getCallCapablePhoneAccounts( + public ParceledListSlice getCallCapablePhoneAccounts( boolean includeDisabledAccounts, String callingPackage) { try { Log.startSession("TSI.gCCPA"); if (!canReadPhoneState(callingPackage, "getDefaultOutgoingPhoneAccount")) { - return Collections.emptyList(); + return ParceledListSlice.emptyList(); } synchronized (mLock) { final UserHandle callingUserHandle = Binder.getCallingUserHandle(); long token = Binder.clearCallingIdentity(); try { - return mPhoneAccountRegistrar.getCallCapablePhoneAccounts(null, - includeDisabledAccounts, callingUserHandle); + return new ParceledListSlice<>( + mPhoneAccountRegistrar.getCallCapablePhoneAccounts(null, + includeDisabledAccounts, callingUserHandle)); } catch (Exception e) { Log.e(this, e, "getCallCapablePhoneAccounts"); throw e; @@ -201,20 +204,22 @@ public class TelecomServiceImpl { } } + @Override - public List getPhoneAccountsSupportingScheme(String uriScheme, - String callingPackage) { - try { + public ParceledListSlice getPhoneAccountsSupportingScheme( + String uriScheme, String callingPackage) { + try { Log.startSession("TSI.gPASS"); synchronized (mLock) { if (!canReadPhoneState(callingPackage, "getPhoneAccountsSupportingScheme")) { - return Collections.emptyList(); + return ParceledListSlice.emptyList(); } final UserHandle callingUserHandle = Binder.getCallingUserHandle(); long token = Binder.clearCallingIdentity(); try { - return mPhoneAccountRegistrar.getCallCapablePhoneAccounts(uriScheme, false, - callingUserHandle); + return new ParceledListSlice<>(mPhoneAccountRegistrar + .getCallCapablePhoneAccounts(uriScheme, false, + callingUserHandle)); } catch (Exception e) { Log.e(this, e, "getPhoneAccountsSupportingScheme %s", uriScheme); throw e; @@ -228,7 +233,8 @@ public class TelecomServiceImpl { } @Override - public List getPhoneAccountsForPackage(String packageName) { + public ParceledListSlice getPhoneAccountsForPackage( + String packageName) { //TODO: Deprecate this in S try { enforceCallingPackage(packageName); @@ -251,8 +257,8 @@ public class TelecomServiceImpl { long token = Binder.clearCallingIdentity(); try { Log.startSession("TSI.gPAFP"); - return mPhoneAccountRegistrar.getPhoneAccountsForPackage(packageName, - callingUserHandle); + return new ParceledListSlice<>(mPhoneAccountRegistrar + .getPhoneAccountsForPackage(packageName, callingUserHandle)); } catch (Exception e) { Log.e(this, e, "getPhoneAccountsForPackage %s", packageName); throw e; @@ -293,7 +299,7 @@ public class TelecomServiceImpl { try { Log.startSession("TSI.gAPAC"); // This list is pre-filtered for the calling user. - return getAllPhoneAccounts().size(); + return getAllPhoneAccounts().getList().size(); } catch (Exception e) { Log.e(this, e, "getAllPhoneAccountsCount"); throw e; @@ -304,13 +310,14 @@ public class TelecomServiceImpl { } @Override - public List getAllPhoneAccounts() { + public ParceledListSlice getAllPhoneAccounts() { synchronized (mLock) { final UserHandle callingUserHandle = Binder.getCallingUserHandle(); long token = Binder.clearCallingIdentity(); try { Log.startSession("TSI.gAPA"); - return mPhoneAccountRegistrar.getAllPhoneAccounts(callingUserHandle); + return new ParceledListSlice<>(mPhoneAccountRegistrar + .getAllPhoneAccounts(callingUserHandle)); } catch (Exception e) { Log.e(this, e, "getAllPhoneAccounts"); throw e; @@ -322,13 +329,14 @@ public class TelecomServiceImpl { } @Override - public List getAllPhoneAccountHandles() { + public ParceledListSlice getAllPhoneAccountHandles() { synchronized (mLock) { final UserHandle callingUserHandle = Binder.getCallingUserHandle(); long token = Binder.clearCallingIdentity(); try { Log.startSession("TSI.gAPAH"); - return mPhoneAccountRegistrar.getAllPhoneAccountHandles(callingUserHandle); + return new ParceledListSlice<>(mPhoneAccountRegistrar + .getAllPhoneAccountHandles(callingUserHandle)); } catch (Exception e) { Log.e(this, e, "getAllPhoneAccounts"); throw e; diff --git a/tests/src/com/android/server/telecom/tests/TelecomServiceImplTest.java b/tests/src/com/android/server/telecom/tests/TelecomServiceImplTest.java index 8de54bfbf..8b194b220 100644 --- a/tests/src/com/android/server/telecom/tests/TelecomServiceImplTest.java +++ b/tests/src/com/android/server/telecom/tests/TelecomServiceImplTest.java @@ -311,9 +311,12 @@ public class TelecomServiceImplTest extends TelecomTestCase { makeAccountsVisibleToAllUsers(TEL_PA_HANDLE_16, SIP_PA_HANDLE_17); assertEquals(fullPHList, - mTSIBinder.getCallCapablePhoneAccounts(true, DEFAULT_DIALER_PACKAGE)); - assertEquals(smallPHList, - mTSIBinder.getCallCapablePhoneAccounts(false, DEFAULT_DIALER_PACKAGE)); + mTSIBinder.getCallCapablePhoneAccounts( + true, DEFAULT_DIALER_PACKAGE).getList()); + + assertEquals(smallPHList, + mTSIBinder.getCallCapablePhoneAccounts( + false, DEFAULT_DIALER_PACKAGE).getList()); } @SmallTest @@ -327,7 +330,7 @@ public class TelecomServiceImplTest extends TelecomTestCase { List result = null; try { - result = mTSIBinder.getCallCapablePhoneAccounts(true, ""); + result = mTSIBinder.getCallCapablePhoneAccounts(true, "").getList(); } catch (SecurityException e) { // intended behavior } @@ -354,9 +357,11 @@ public class TelecomServiceImplTest extends TelecomTestCase { makeAccountsVisibleToAllUsers(TEL_PA_HANDLE_16, SIP_PA_HANDLE_17); assertEquals(telPHList, - mTSIBinder.getPhoneAccountsSupportingScheme("tel", DEFAULT_DIALER_PACKAGE)); + mTSIBinder.getPhoneAccountsSupportingScheme( + "tel", DEFAULT_DIALER_PACKAGE).getList()); assertEquals(sipPHList, - mTSIBinder.getPhoneAccountsSupportingScheme("sip", DEFAULT_DIALER_PACKAGE)); + mTSIBinder.getPhoneAccountsSupportingScheme( + "sip", DEFAULT_DIALER_PACKAGE).getList()); } @SmallTest @@ -371,7 +376,7 @@ public class TelecomServiceImplTest extends TelecomTestCase { makeAccountsVisibleToAllUsers(TEL_PA_HANDLE_16, SIP_PA_HANDLE_17); assertEquals(phoneAccountHandleList, mTSIBinder.getPhoneAccountsForPackage( - TEL_PA_HANDLE_16.getComponentName().getPackageName())); + TEL_PA_HANDLE_16.getComponentName().getPackageName()).getList()); } @SmallTest @@ -392,7 +397,7 @@ public class TelecomServiceImplTest extends TelecomTestCase { when(mFakePhoneAccountRegistrar.getAllPhoneAccounts(any(UserHandle.class))) .thenReturn(phoneAccountList); - assertEquals(2, mTSIBinder.getAllPhoneAccounts().size()); + assertEquals(2, mTSIBinder.getAllPhoneAccounts().getList().size()); } @SmallTest