Merge "Fix legacy tether behavior for duplicate requests" into main
This commit is contained in:
commit
7f911faf5e
3 changed files with 29 additions and 5 deletions
|
|
@ -1188,6 +1188,17 @@ public class TetheringManager {
|
|||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof TetheringRequest otherRequest)) return false;
|
||||
if (!equalsIgnoreUidPackage(otherRequest)) return false;
|
||||
TetheringRequestParcel parcel = getParcel();
|
||||
TetheringRequestParcel otherParcel = otherRequest.getParcel();
|
||||
return parcel.uid == otherParcel.uid
|
||||
&& Objects.equals(parcel.packageName, otherParcel.packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public boolean equalsIgnoreUidPackage(TetheringRequest otherRequest) {
|
||||
TetheringRequestParcel parcel = getParcel();
|
||||
TetheringRequestParcel otherParcel = otherRequest.getParcel();
|
||||
return parcel.tetheringType == otherParcel.tetheringType
|
||||
|
|
@ -1197,8 +1208,6 @@ public class TetheringManager {
|
|||
&& 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.interfaceName, otherParcel.interfaceName);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -664,7 +664,7 @@ public class Tethering {
|
|||
final TetheringRequest unfinishedRequest = mActiveTetheringRequests.get(type);
|
||||
// If tethering is already enabled with a different request,
|
||||
// disable before re-enabling.
|
||||
if (unfinishedRequest != null && !unfinishedRequest.equals(request)) {
|
||||
if (unfinishedRequest != null && !unfinishedRequest.equalsIgnoreUidPackage(request)) {
|
||||
enableTetheringInternal(type, false /* disabled */,
|
||||
unfinishedRequest.getInterfaceName(), null);
|
||||
mEntitlementMgr.stopProvisioningIfNeeded(type);
|
||||
|
|
|
|||
|
|
@ -267,8 +267,9 @@ public class TetheringTest {
|
|||
private static final String TEST_P2P_REGEX = "test_p2p-p2p\\d-.*";
|
||||
private static final String TEST_BT_REGEX = "test_pan\\d";
|
||||
private static final int TEST_CALLER_UID = 1000;
|
||||
private static final int TEST_CALLER_UID_2 = 2000;
|
||||
private static final String TEST_CALLER_PKG = "com.test.tethering";
|
||||
|
||||
private static final String TEST_CALLER_PKG_2 = "com.test.tethering2";
|
||||
private static final int CELLULAR_NETID = 100;
|
||||
private static final int WIFI_NETID = 101;
|
||||
private static final int DUN_NETID = 102;
|
||||
|
|
@ -785,7 +786,10 @@ public class TetheringTest {
|
|||
if (interfaceName != null) {
|
||||
builder.setInterfaceName(interfaceName);
|
||||
}
|
||||
return builder.build();
|
||||
TetheringRequest request = builder.build();
|
||||
request.setUid(TEST_CALLER_UID);
|
||||
request.setPackageName(TEST_CALLER_PKG);
|
||||
return request;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
@ -2786,6 +2790,17 @@ public class TetheringTest {
|
|||
verify(mUsbManager, never()).setCurrentFunctions(UsbManager.FUNCTION_NONE);
|
||||
reset(mUsbManager);
|
||||
|
||||
// Enable USB tethering again with the same request but different uid/package and expect no
|
||||
// change to USB.
|
||||
TetheringRequest differentUidPackage = createTetheringRequest(TETHERING_USB);
|
||||
differentUidPackage.setUid(TEST_CALLER_UID_2);
|
||||
differentUidPackage.setPackageName(TEST_CALLER_PKG_2);
|
||||
mTethering.startTethering(differentUidPackage, TEST_CALLER_PKG_2, secondResult);
|
||||
mLooper.dispatchAll();
|
||||
secondResult.assertHasResult();
|
||||
verify(mUsbManager, never()).setCurrentFunctions(UsbManager.FUNCTION_NONE);
|
||||
reset(mUsbManager);
|
||||
|
||||
// Enable USB tethering with a different request and expect that USB is stopped and
|
||||
// started.
|
||||
mTethering.startTethering(createTetheringRequest(TETHERING_USB,
|
||||
|
|
|
|||
Loading…
Reference in a new issue