Support static address configuration

Application can specify static ipv4 server and client address to setup
tethering and this is one shot configuration. Tethering service would
not save the configuration and the configuration would be reset when
tethering stop or start failure.

When startTethering callback fired, it just mean tethering is requested
successful. Therefore, callers may call startTethering again if
startTethering successful but do not receive following tethering active
notification for a while. Tethering service never actually does anything
synchronously when startTethering is called:
  -startProvisioningIfNeeded just posts a message to the handler thread.
  -enableTetheringInternal doesn't do anything synchronously, it just
  asks the downstreams to get their interfaces ready and waits for
  callbacks.
If tethering is already enabled with a different request,
tethering would be disabled and re-enabled.

Bug: 141256482
Test: -build, flash, boot
      -atest TetheringTests
      -atest CtsTetheringTest

Change-Id: I2b2dd965a673e6f1626738d41b5d443f0f9fbd0e
Merged-In: I0399917e7cefa1547d617e688225544c4fc1a231
(cherry picked from commit 5d6723e24e21154bef3967585a8adc069e007f49)
This commit is contained in:
Automerger Merge Worker
2020-03-17 16:59:57 +00:00
committed by markchien
parent 06b45ca764
commit 9462a3c9f0
9 changed files with 316 additions and 40 deletions

View File

@@ -512,19 +512,36 @@ public class TetheringManager {
mBuilderParcel = new TetheringRequestParcel();
mBuilderParcel.tetheringType = type;
mBuilderParcel.localIPv4Address = null;
mBuilderParcel.staticClientAddress = null;
mBuilderParcel.exemptFromEntitlementCheck = false;
mBuilderParcel.showProvisioningUi = true;
}
/**
* Configure tethering with static IPv4 assignment (with DHCP disabled).
* Configure tethering with static IPv4 assignment.
*
* @param localIPv4Address The preferred local IPv4 address to use.
* The clientAddress must be in the localIPv4Address prefix. A DHCP server will be
* started, but will only be able to offer the client address. The two addresses must
* be in the same prefix.
*
* @param localIPv4Address The preferred local IPv4 link address to use.
* @param clientAddress The static client address.
*/
@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
@NonNull
public Builder useStaticIpv4Addresses(@NonNull final LinkAddress localIPv4Address) {
public Builder setStaticIpv4Addresses(@NonNull final LinkAddress localIPv4Address,
@NonNull final LinkAddress clientAddress) {
Objects.requireNonNull(localIPv4Address);
Objects.requireNonNull(clientAddress);
if (localIPv4Address.getPrefixLength() != clientAddress.getPrefixLength()
|| !localIPv4Address.isIpv4() || !clientAddress.isIpv4()
|| !new IpPrefix(localIPv4Address.toString()).equals(
new IpPrefix(clientAddress.toString()))) {
throw new IllegalArgumentException("Invalid server or client addresses");
}
mBuilderParcel.localIPv4Address = localIPv4Address;
mBuilderParcel.staticClientAddress = clientAddress;
return this;
}
@@ -549,6 +566,18 @@ public class TetheringManager {
public TetheringRequest build() {
return new TetheringRequest(mBuilderParcel);
}
/** Get static server address. */
@Nullable
public LinkAddress getLocalIpv4Address() {
return mBuilderParcel.localIPv4Address;
}
/** Get static client address. */
@Nullable
public LinkAddress getClientStaticIpv4Address() {
return mBuilderParcel.staticClientAddress;
}
}
/**
@@ -563,6 +592,7 @@ public class TetheringManager {
public String toString() {
return "TetheringRequest [ type= " + mRequestParcel.tetheringType
+ ", localIPv4Address= " + mRequestParcel.localIPv4Address
+ ", staticClientAddress= " + mRequestParcel.staticClientAddress
+ ", exemptFromEntitlementCheck= "
+ mRequestParcel.exemptFromEntitlementCheck + ", showProvisioningUi= "
+ mRequestParcel.showProvisioningUi + " ]";

View File

@@ -25,6 +25,7 @@ import android.net.LinkAddress;
parcelable TetheringRequestParcel {
int tetheringType;
LinkAddress localIPv4Address;
LinkAddress staticClientAddress;
boolean exemptFromEntitlementCheck;
boolean showProvisioningUi;
}