no-op: Remove checkAndNotifyCommonError with ResultReceiver
There are currently two variants of checkAndNotifyCommonError that do
the exactly the same thing, except one uses IIntResultListener and
another uses ResultReceiver. Remove the lesser-used ResultReceiver
variant and just use the IIntResultListener instead (with a
IIntResultListener wrapper for the ResultReceiver).
Bug: 216524590
Test: covered by existing tests
Change-Id: I292a96b32cd975852a52c7953b03bcb35728db24
diff --git a/Tethering/src/com/android/networkstack/tethering/TetheringService.java b/Tethering/src/com/android/networkstack/tethering/TetheringService.java
index b553f46..f501a50 100644
--- a/Tethering/src/com/android/networkstack/tethering/TetheringService.java
+++ b/Tethering/src/com/android/networkstack/tethering/TetheringService.java
@@ -173,7 +173,21 @@
@Override
public void requestLatestTetheringEntitlementResult(int type, ResultReceiver receiver,
boolean showEntitlementUi, String callerPkg, String callingAttributionTag) {
- if (checkAndNotifyCommonError(callerPkg, callingAttributionTag, receiver)) return;
+ // Wrap the app-provided ResultReceiver in an IIntResultListener in order to call
+ // checkAndNotifyCommonError with it.
+ IIntResultListener listener = new IIntResultListener() {
+ @Override
+ public void onResult(int i) {
+ receiver.send(i, null);
+ }
+
+ @Override
+ public IBinder asBinder() {
+ throw new UnsupportedOperationException("asBinder unexpectedly called on"
+ + " internal-only listener");
+ }
+ };
+ if (checkAndNotifyCommonError(callerPkg, callingAttributionTag, listener)) return;
mTethering.requestLatestTetheringEntitlementResult(type, receiver, showEntitlementUi);
}
@@ -277,27 +291,6 @@
return false;
}
- private boolean checkAndNotifyCommonError(final String callerPkg,
- final String callingAttributionTag, final ResultReceiver receiver) {
- if (!checkPackageNameMatchesUid(getBinderCallingUid(), callerPkg)) {
- Log.e(TAG, "Package name " + callerPkg + " does not match UID "
- + getBinderCallingUid());
- receiver.send(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION, null);
- return true;
- }
- if (!hasTetherChangePermission(callerPkg, callingAttributionTag,
- false /* onlyAllowPrivileged */)) {
- receiver.send(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION, null);
- return true;
- }
- if (!mTethering.isTetheringSupported() || !mTethering.isTetheringAllowed()) {
- receiver.send(TETHER_ERROR_UNSUPPORTED, null);
- return true;
- }
-
- return false;
- }
-
private boolean hasNetworkSettingsPermission() {
return checkCallingOrSelfPermission(NETWORK_SETTINGS);
}