Revert "Add UID and package name to TetheringRequest"
This reverts commit 462703c850.
Reason for revert: b/375535923
Change-Id: I7f77959490e8243bb95985bd28b67efcf0f3eb00
This commit is contained in:
parent
462703c850
commit
c8df03ffd7
8 changed files with 8 additions and 171 deletions
|
|
@ -46,10 +46,5 @@ package android.net {
|
|||
method @Deprecated @NonNull public java.util.List<java.lang.String> getTetherableWifiRegexs();
|
||||
}
|
||||
|
||||
public static final class TetheringManager.TetheringRequest implements android.os.Parcelable {
|
||||
method @FlaggedApi("com.android.net.flags.tethering_request_with_soft_ap_config") @Nullable public String getPackageName();
|
||||
method @FlaggedApi("com.android.net.flags.tethering_request_with_soft_ap_config") public int getUid();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ import android.os.ConditionVariable;
|
|||
import android.os.IBinder;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ResultReceiver;
|
||||
import android.util.ArrayMap;
|
||||
|
|
@ -747,7 +746,6 @@ public class TetheringManager {
|
|||
mBuilderParcel.exemptFromEntitlementCheck = false;
|
||||
mBuilderParcel.showProvisioningUi = true;
|
||||
mBuilderParcel.connectivityScope = getDefaultConnectivityScope(type);
|
||||
mBuilderParcel.uid = Process.INVALID_UID;
|
||||
mBuilderParcel.softApConfig = null;
|
||||
}
|
||||
|
||||
|
|
@ -921,47 +919,6 @@ public class TetheringManager {
|
|||
return mRequestParcel.softApConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the UID of the app that sent this request. This should always be overridden when
|
||||
* receiving TetheringRequest from an external source.
|
||||
* @hide
|
||||
*/
|
||||
public void setUid(int uid) {
|
||||
mRequestParcel.uid = uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the package name of the app that sent this request. This should always be overridden
|
||||
* when receiving a TetheringRequest from an external source.
|
||||
* @hide
|
||||
*/
|
||||
public void setPackageName(String packageName) {
|
||||
mRequestParcel.packageName = packageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the UID of the app that sent this request. This defaults to
|
||||
* {@link Process#INVALID_UID} if unset.
|
||||
* @hide
|
||||
*/
|
||||
@FlaggedApi(Flags.FLAG_TETHERING_REQUEST_WITH_SOFT_AP_CONFIG)
|
||||
@SystemApi(client = MODULE_LIBRARIES)
|
||||
public int getUid() {
|
||||
return mRequestParcel.uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the package name of the app that sent this request. This defaults to {@code null} if
|
||||
* unset.
|
||||
* @hide
|
||||
*/
|
||||
@FlaggedApi(Flags.FLAG_TETHERING_REQUEST_WITH_SOFT_AP_CONFIG)
|
||||
@SystemApi(client = MODULE_LIBRARIES)
|
||||
@Nullable
|
||||
public String getPackageName() {
|
||||
return mRequestParcel.packageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a TetheringRequestParcel from the configuration
|
||||
* @hide
|
||||
|
|
@ -978,8 +935,6 @@ public class TetheringManager {
|
|||
+ ", exemptFromEntitlementCheck= " + mRequestParcel.exemptFromEntitlementCheck
|
||||
+ ", showProvisioningUi= " + mRequestParcel.showProvisioningUi
|
||||
+ ", softApConfig= " + mRequestParcel.softApConfig
|
||||
+ ", uid= " + mRequestParcel.uid
|
||||
+ ", packageName= " + mRequestParcel.packageName
|
||||
+ " ]";
|
||||
}
|
||||
|
||||
|
|
@ -995,9 +950,7 @@ public class TetheringManager {
|
|||
&& parcel.exemptFromEntitlementCheck == otherParcel.exemptFromEntitlementCheck
|
||||
&& parcel.showProvisioningUi == otherParcel.showProvisioningUi
|
||||
&& parcel.connectivityScope == otherParcel.connectivityScope
|
||||
&& Objects.equals(parcel.softApConfig, otherParcel.softApConfig)
|
||||
&& parcel.uid == otherParcel.uid
|
||||
&& Objects.equals(parcel.packageName, otherParcel.packageName);
|
||||
&& Objects.equals(parcel.softApConfig, otherParcel.softApConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -1005,8 +958,7 @@ public class TetheringManager {
|
|||
TetheringRequestParcel parcel = getParcel();
|
||||
return Objects.hash(parcel.tetheringType, parcel.localIPv4Address,
|
||||
parcel.staticClientAddress, parcel.exemptFromEntitlementCheck,
|
||||
parcel.showProvisioningUi, parcel.connectivityScope, parcel.softApConfig,
|
||||
parcel.uid, parcel.packageName);
|
||||
parcel.showProvisioningUi, parcel.connectivityScope, parcel.softApConfig);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,4 @@ parcelable TetheringRequestParcel {
|
|||
boolean showProvisioningUi;
|
||||
int connectivityScope;
|
||||
SoftApConfiguration softApConfig;
|
||||
int uid;
|
||||
String packageName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,6 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.net.module.util.PermissionUtils;
|
||||
import com.android.networkstack.apishim.SettingsShimImpl;
|
||||
import com.android.networkstack.apishim.common.SettingsShim;
|
||||
|
||||
|
|
@ -139,10 +138,8 @@ public class TetheringService extends Service {
|
|||
listener)) {
|
||||
return;
|
||||
}
|
||||
TetheringRequest external = new TetheringRequest(request);
|
||||
external.setUid(getBinderCallingUid());
|
||||
external.setPackageName(callerPkg);
|
||||
mTethering.startTethering(external, callerPkg, listener);
|
||||
// TODO(b/216524590): Add UID/packageName of caller to TetheringRequest here
|
||||
mTethering.startTethering(new TetheringRequest(request), callerPkg, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -241,12 +238,6 @@ public class TetheringService extends Service {
|
|||
final String callingAttributionTag, final boolean onlyAllowPrivileged,
|
||||
final IIntResultListener listener) {
|
||||
try {
|
||||
if (!checkPackageNameMatchesUid(getBinderCallingUid(), callerPkg)) {
|
||||
Log.e(TAG, "Package name " + callerPkg + " does not match UID "
|
||||
+ getBinderCallingUid());
|
||||
listener.onResult(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION);
|
||||
return true;
|
||||
}
|
||||
if (!hasTetherChangePermission(callerPkg, callingAttributionTag,
|
||||
onlyAllowPrivileged)) {
|
||||
listener.onResult(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION);
|
||||
|
|
@ -265,12 +256,6 @@ public class TetheringService extends Service {
|
|||
|
||||
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);
|
||||
|
|
@ -305,9 +290,9 @@ public class TetheringService extends Service {
|
|||
|
||||
if (mTethering.isTetherProvisioningRequired()) return false;
|
||||
|
||||
int uid = getBinderCallingUid();
|
||||
int uid = Binder.getCallingUid();
|
||||
|
||||
// If callerPkg's uid is not same as getBinderCallingUid(),
|
||||
// If callerPkg's uid is not same as Binder.getCallingUid(),
|
||||
// checkAndNoteWriteSettingsOperation will return false and the operation will be
|
||||
// denied.
|
||||
return mService.checkAndNoteWriteSettingsOperation(mService, uid, callerPkg,
|
||||
|
|
@ -320,14 +305,6 @@ public class TetheringService extends Service {
|
|||
return mService.checkCallingOrSelfPermission(
|
||||
ACCESS_NETWORK_STATE) == PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
private int getBinderCallingUid() {
|
||||
return mService.getBinderCallingUid();
|
||||
}
|
||||
|
||||
private boolean checkPackageNameMatchesUid(final int uid, final String callerPkg) {
|
||||
return mService.checkPackageNameMatchesUid(mService, uid, callerPkg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -344,28 +321,6 @@ public class TetheringService extends Service {
|
|||
callingAttributionTag, throwException);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the package name matches the uid.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
boolean checkPackageNameMatchesUid(@NonNull Context context, int uid,
|
||||
@NonNull String callingPackage) {
|
||||
try {
|
||||
PermissionUtils.enforcePackageNameMatchesUid(context, uid, callingPackage);
|
||||
} catch (SecurityException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the Binder calling UID, used for mocks.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
int getBinderCallingUid() {
|
||||
return Binder.getCallingUid();
|
||||
}
|
||||
|
||||
/**
|
||||
* An injection method for testing.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -32,8 +32,6 @@ import androidx.annotation.Nullable;
|
|||
public class MockTetheringService extends TetheringService {
|
||||
private final Tethering mTethering = mock(Tethering.class);
|
||||
private final ArrayMap<String, Integer> mMockedPermissions = new ArrayMap<>();
|
||||
private final ArrayMap<String, Integer> mMockedPackageUids = new ArrayMap<>();
|
||||
private int mMockCallingUid;
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
|
|
@ -63,17 +61,6 @@ public class MockTetheringService extends TetheringService {
|
|||
return super.checkCallingOrSelfPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean checkPackageNameMatchesUid(@NonNull Context context, int uid,
|
||||
@NonNull String callingPackage) {
|
||||
return mMockedPackageUids.getOrDefault(callingPackage, 0) == uid;
|
||||
}
|
||||
|
||||
@Override
|
||||
int getBinderCallingUid() {
|
||||
return mMockCallingUid;
|
||||
}
|
||||
|
||||
public Tethering getTethering() {
|
||||
return mTethering;
|
||||
}
|
||||
|
|
@ -104,19 +91,5 @@ public class MockTetheringService extends TetheringService {
|
|||
mMockedPermissions.put(permission, granted);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock a package name matching a uid.
|
||||
*/
|
||||
public void setPackageNameUid(String packageName, int uid) {
|
||||
mMockedPackageUids.put(packageName, uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock a package name matching a uid.
|
||||
*/
|
||||
public void setCallingUid(int uid) {
|
||||
mMockCallingUid = uid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ import static org.mockito.ArgumentMatchers.any;
|
|||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
|
@ -80,7 +79,6 @@ import java.util.function.Supplier;
|
|||
public final class TetheringServiceTest {
|
||||
private static final String TEST_IFACE_NAME = "test_wlan0";
|
||||
private static final String TEST_CALLER_PKG = "com.android.shell";
|
||||
private static final int TEST_CALLER_UID = 1234;
|
||||
private static final String TEST_ATTRIBUTION_TAG = null;
|
||||
@Mock private ITetheringEventCallback mITetheringEventCallback;
|
||||
@Rule public ServiceTestRule mServiceTestRule;
|
||||
|
|
@ -130,8 +128,6 @@ public final class TetheringServiceTest {
|
|||
mTetheringConnector = ITetheringConnector.Stub.asInterface(mMockConnector.getIBinder());
|
||||
final MockTetheringService service = mMockConnector.getService();
|
||||
mTethering = service.getTethering();
|
||||
mMockConnector.setCallingUid(TEST_CALLER_UID);
|
||||
mMockConnector.setPackageNameUid(TEST_CALLER_PKG, TEST_CALLER_UID);
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
@ -333,16 +329,6 @@ public final class TetheringServiceTest {
|
|||
verifyNoMoreInteractionsForTethering();
|
||||
});
|
||||
|
||||
runAsTetherPrivileged((result) -> {
|
||||
String wrongPackage = "wrong.package";
|
||||
mTetheringConnector.startTethering(request, wrongPackage,
|
||||
TEST_ATTRIBUTION_TAG, result);
|
||||
verify(mTethering, never()).startTethering(
|
||||
eq(new TetheringRequest(request)), eq(wrongPackage), eq(result));
|
||||
result.assertResult(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION);
|
||||
verifyNoMoreInteractionsForTethering();
|
||||
});
|
||||
|
||||
runAsTetherPrivileged((result) -> {
|
||||
runStartTethering(result, request);
|
||||
verifyNoMoreInteractionsForTethering();
|
||||
|
|
@ -459,13 +445,6 @@ public final class TetheringServiceTest {
|
|||
verifyNoMoreInteractionsForTethering();
|
||||
});
|
||||
|
||||
runAsTetherPrivileged((none) -> {
|
||||
mTetheringConnector.requestLatestTetheringEntitlementResult(TETHERING_WIFI, result,
|
||||
true /* showEntitlementUi */, "wrong.package", TEST_ATTRIBUTION_TAG);
|
||||
result.assertResult(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION);
|
||||
verifyNoMoreInteractions(mTethering);
|
||||
});
|
||||
|
||||
runAsWriteSettings((none) -> {
|
||||
runRequestLatestTetheringEntitlementResult();
|
||||
verify(mTethering).isTetherProvisioningRequired();
|
||||
|
|
|
|||
|
|
@ -19,10 +19,7 @@ package {
|
|||
|
||||
java_defaults {
|
||||
name: "CtsTetheringTestDefaults",
|
||||
defaults: [
|
||||
"cts_defaults",
|
||||
"framework-connectivity-test-defaults",
|
||||
],
|
||||
defaults: ["cts_defaults"],
|
||||
|
||||
libs: [
|
||||
"android.test.base.stubs.system",
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ import static android.net.TetheringManager.TETHER_ERROR_ENTITLEMENT_UNKNOWN;
|
|||
import static android.net.TetheringManager.TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION;
|
||||
import static android.net.TetheringManager.TETHER_ERROR_NO_ERROR;
|
||||
import static android.net.cts.util.CtsTetheringUtils.isAnyIfaceMatch;
|
||||
import static android.os.Process.INVALID_UID;
|
||||
|
||||
import static com.android.testutils.TestPermissionUtil.runAsShell;
|
||||
|
||||
|
|
@ -245,35 +244,24 @@ public class TetheringManagerTest {
|
|||
assertFalse(tr.isExemptFromEntitlementCheck());
|
||||
assertTrue(tr.getShouldShowEntitlementUi());
|
||||
assertEquals(softApConfiguration, tr.getSoftApConfiguration());
|
||||
assertEquals(INVALID_UID, tr.getUid());
|
||||
assertNull(tr.getPackageName());
|
||||
|
||||
final LinkAddress localAddr = new LinkAddress("192.168.24.5/24");
|
||||
final LinkAddress clientAddr = new LinkAddress("192.168.24.100/24");
|
||||
final TetheringRequest tr2 = new TetheringRequest.Builder(TETHERING_USB)
|
||||
.setStaticIpv4Addresses(localAddr, clientAddr)
|
||||
.setExemptFromEntitlementCheck(true)
|
||||
.setShouldShowEntitlementUi(false)
|
||||
.build();
|
||||
int uid = 1000;
|
||||
String packageName = "package";
|
||||
tr2.setUid(uid);
|
||||
tr2.setPackageName(packageName);
|
||||
.setShouldShowEntitlementUi(false).build();
|
||||
|
||||
assertEquals(localAddr, tr2.getLocalIpv4Address());
|
||||
assertEquals(clientAddr, tr2.getClientStaticIpv4Address());
|
||||
assertEquals(TETHERING_USB, tr2.getTetheringType());
|
||||
assertTrue(tr2.isExemptFromEntitlementCheck());
|
||||
assertFalse(tr2.getShouldShowEntitlementUi());
|
||||
assertEquals(uid, tr2.getUid());
|
||||
assertEquals(packageName, tr2.getPackageName());
|
||||
|
||||
final TetheringRequest tr3 = new TetheringRequest.Builder(TETHERING_USB)
|
||||
.setStaticIpv4Addresses(localAddr, clientAddr)
|
||||
.setExemptFromEntitlementCheck(true)
|
||||
.setShouldShowEntitlementUi(false).build();
|
||||
tr3.setUid(uid);
|
||||
tr3.setPackageName(packageName);
|
||||
assertEquals(tr2, tr3);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue