Extend previously added limits for listeners

original change (ag/10753900) did not cover all apis
-added limit check to onSubscriptionsChangedListener
-added limit check to addOnOpportunisticSubscriptionListener
-minor refactoring to remove duplicate code
-error logging to ensure that logs are printed for sys/phone uids

Bug: 222188265
Test: atest TelephonyRegistryTest
Change-Id: Ie231d7d2bc217bf1d373f8447f5f2f672c8ab908
This commit is contained in:
Chinmay Dhodapkar
2022-03-16 18:18:08 -07:00
parent e133038ef5
commit 1b5369b5fb

View File

@@ -873,6 +873,13 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
mContext.registerReceiver(mBroadcastReceiver, filter);
}
//helper function to determine if limit on num listeners applies to callingUid
private boolean doesLimitApplyForListeners(int callingUid, int exemptUid) {
return (callingUid != Process.SYSTEM_UID
&& callingUid != Process.PHONE_UID
&& callingUid != exemptUid);
}
@Override
public void addOnSubscriptionsChangedListener(String callingPackage, String callingFeatureId,
IOnSubscriptionsChangedListener callback) {
@@ -887,7 +894,9 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
synchronized (mRecords) {
// register
IBinder b = callback.asBinder();
Record r = add(b, Binder.getCallingUid(), Binder.getCallingPid(), false);
boolean doesLimitApply = doesLimitApplyForListeners(Binder.getCallingUid(),
Process.myUid());
Record r = add(b, Binder.getCallingUid(), Binder.getCallingPid(), doesLimitApply); //
if (r == null) {
return;
@@ -941,7 +950,9 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
synchronized (mRecords) {
// register
IBinder b = callback.asBinder();
Record r = add(b, Binder.getCallingUid(), Binder.getCallingPid(), false);
boolean doesLimitApply = doesLimitApplyForListeners(Binder.getCallingUid(),
Process.myUid());
Record r = add(b, Binder.getCallingUid(), Binder.getCallingPid(), doesLimitApply); //
if (r == null) {
return;
@@ -1070,10 +1081,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
synchronized (mRecords) {
// register
IBinder b = callback.asBinder();
boolean doesLimitApply =
Binder.getCallingUid() != Process.SYSTEM_UID
&& Binder.getCallingUid() != Process.PHONE_UID
&& Binder.getCallingUid() != Process.myUid();
boolean doesLimitApply = doesLimitApplyForListeners(Binder.getCallingUid(),
Process.myUid());
Record r = add(b, Binder.getCallingUid(), Binder.getCallingPid(), doesLimitApply);
if (r == null) {
@@ -1417,7 +1426,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
.isRegistrationLimitEnabledInPlatformCompat(callingUid)) {
throw new IllegalStateException(errorMsg);
}
} else if (doesLimitApply && numRecordsForPid
} else if (numRecordsForPid
>= TelephonyCallback.DEFAULT_PER_PID_REGISTRATION_LIMIT / 2) {
// Log the warning independently of the dynamically set limit -- apps shouldn't be
// doing this regardless of whether we're throwing them an exception for it.