Pass bluetoothUseRandomAddress via RoutingCoordinator constructor

This refactoring changes how the bluetoothUseRandomAddress flag is
accessed.

PrivateAddressCoordinator is in a library used by multiple mainline
modules(Tethering, NetworkStack, CaptivePortal, WiFi) and cannot
directly read a Tethering mainline beta flag.

To fix this, the flag's value is now passed down through constructors.

An alternative solution would be to split the Java library for each module,
but with this solution, a single utility class cannot be shared.

This commit is a no-op as the passed value is hardcoded to false.

Test: TH
Flag: EXEMPT refactor
Bug: 287177081
Change-Id: I5f2174ee94b55e7a7298b9742221d6e6c3c5cac5
This commit is contained in:
Motomu Utsumi 2025-07-10 17:11:52 +09:00
commit 323d22a497
2 changed files with 50 additions and 31 deletions

View file

@ -40,7 +40,6 @@ import android.util.ArrayMap;
import androidx.annotation.Nullable;
import com.android.internal.annotations.VisibleForTesting;
import com.android.modules.utils.build.SdkLevel;
import java.io.PrintWriter;
import java.net.Inet4Address;
@ -109,31 +108,23 @@ public class PrivateAddressCoordinator {
public boolean isFeatureNotChickenedOut(String featureName) {
return DeviceConfigUtils.isTetheringFeatureNotChickenedOut(mContext, featureName);
}
/**
* Whether to randomize the tethering prefix for bluetooth as well. Requires T+ because
* in S this code is in the platform.
*/
public boolean shouldBluetoothUseRandomAddress() {
// TODO: add a mainline beta flag to enable the new behaviour.
return SdkLevel.isAtLeastT() && false;
}
}
public PrivateAddressCoordinator(Supplier<Network[]> getAllNetworksSupplier, Context context) {
this(getAllNetworksSupplier, new Dependencies(context));
public PrivateAddressCoordinator(Supplier<Network[]> getAllNetworksSupplier, Context context,
boolean bluetoothTetheringUseRandomAddress) {
this(getAllNetworksSupplier, new Dependencies(context), bluetoothTetheringUseRandomAddress);
}
@VisibleForTesting
public PrivateAddressCoordinator(Supplier<Network[]> getAllNetworksSupplier,
Dependencies deps) {
Dependencies deps, boolean bluetoothTetheringUseRandomAddress) {
mDownstreams = new ArrayMap<>();
mUpstreamPrefixMap = new ArrayMap<>();
mGetAllNetworksSupplier = getAllNetworksSupplier;
mDeps = deps;
mCachedAddresses = new ArrayMap<AddressKey, LinkAddress>();
// Reserved static addresses for BLUETOOTH pre-T and WIFI_P2P.
if (!mDeps.shouldBluetoothUseRandomAddress()) {
if (!bluetoothTetheringUseRandomAddress) {
mCachedAddresses.put(new AddressKey(TETHERING_BLUETOOTH, CONNECTIVITY_SCOPE_GLOBAL),
new LinkAddress(LEGACY_BLUETOOTH_IFACE_ADDRESS));
}

View file

@ -56,18 +56,23 @@ public class RoutingCoordinatorService extends IRoutingCoordinator.Stub {
@GuardedBy("mPrivateAddressCoordinatorLock")
private final PrivateAddressCoordinator mPrivateAddressCoordinator;
// TODO: Remove bluetoothTetheringUseRandomAddress argument once the beta flag is rolled out
public RoutingCoordinatorService(@NonNull INetd netd,
@NonNull Supplier<Network[]> getAllNetworksSupplier,
@NonNull Context context) {
this(netd, getAllNetworksSupplier, new PrivateAddressCoordinator.Dependencies(context));
@NonNull Supplier<Network[]> getAllNetworksSupplier,
@NonNull Context context,
boolean bluetoothTetheringUseRandomAddress) {
this(netd, getAllNetworksSupplier, new PrivateAddressCoordinator.Dependencies(context),
bluetoothTetheringUseRandomAddress);
}
@VisibleForTesting
public RoutingCoordinatorService(@NonNull INetd netd,
@NonNull Supplier<Network[]> getAllNetworksSupplier,
@NonNull PrivateAddressCoordinator.Dependencies pacDeps) {
@NonNull Supplier<Network[]> getAllNetworksSupplier,
@NonNull PrivateAddressCoordinator.Dependencies pacDeps,
boolean bluetoothTetheringUseRandomAddress) {
mNetd = netd;
mPrivateAddressCoordinator = new PrivateAddressCoordinator(getAllNetworksSupplier, pacDeps);
mPrivateAddressCoordinator = new PrivateAddressCoordinator(
getAllNetworksSupplier, pacDeps, bluetoothTetheringUseRandomAddress);
}
/**