Merge "Add extras parameter to rest of data classes" into udc-dev

This commit is contained in:
Andrew Sapperstein
2023-03-16 16:43:47 +00:00
committed by Android (Google) Code Review
10 changed files with 145 additions and 21 deletions

View File

@@ -9984,6 +9984,7 @@ package android.net.wifi.sharedconnectivity.app {
public final class HotspotNetwork implements android.os.Parcelable {
method public int describeContents();
method public long getDeviceId();
method @NonNull public android.os.Bundle getExtras();
method public int getHostNetworkType();
method @Nullable public String getHotspotBssid();
method @NonNull public java.util.Set<java.lang.Integer> getHotspotSecurityTypes();
@@ -10003,6 +10004,7 @@ package android.net.wifi.sharedconnectivity.app {
method @NonNull public android.net.wifi.sharedconnectivity.app.HotspotNetwork.Builder addHotspotSecurityType(int);
method @NonNull public android.net.wifi.sharedconnectivity.app.HotspotNetwork build();
method @NonNull public android.net.wifi.sharedconnectivity.app.HotspotNetwork.Builder setDeviceId(long);
method @NonNull public android.net.wifi.sharedconnectivity.app.HotspotNetwork.Builder setExtras(@NonNull android.os.Bundle);
method @NonNull public android.net.wifi.sharedconnectivity.app.HotspotNetwork.Builder setHostNetworkType(int);
method @NonNull public android.net.wifi.sharedconnectivity.app.HotspotNetwork.Builder setHotspotBssid(@NonNull String);
method @NonNull public android.net.wifi.sharedconnectivity.app.HotspotNetwork.Builder setHotspotSsid(@NonNull String);
@@ -10039,6 +10041,7 @@ package android.net.wifi.sharedconnectivity.app {
public final class KnownNetwork implements android.os.Parcelable {
method public int describeContents();
method @NonNull public android.os.Bundle getExtras();
method @Nullable public android.net.wifi.sharedconnectivity.app.NetworkProviderInfo getNetworkProviderInfo();
method public int getNetworkSource();
method @NonNull public java.util.Set<java.lang.Integer> getSecurityTypes();
@@ -10054,6 +10057,7 @@ package android.net.wifi.sharedconnectivity.app {
ctor public KnownNetwork.Builder();
method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetwork.Builder addSecurityType(int);
method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetwork build();
method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetwork.Builder setExtras(@NonNull android.os.Bundle);
method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetwork.Builder setNetworkProviderInfo(@Nullable android.net.wifi.sharedconnectivity.app.NetworkProviderInfo);
method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetwork.Builder setNetworkSource(int);
method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetwork.Builder setSsid(@NonNull String);
@@ -10085,6 +10089,7 @@ package android.net.wifi.sharedconnectivity.app {
method @IntRange(from=0, to=3) public int getConnectionStrength();
method @NonNull public String getDeviceName();
method public int getDeviceType();
method @NonNull public android.os.Bundle getExtras();
method @NonNull public String getModelName();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.sharedconnectivity.app.NetworkProviderInfo> CREATOR;
@@ -10103,6 +10108,7 @@ package android.net.wifi.sharedconnectivity.app {
method @NonNull public android.net.wifi.sharedconnectivity.app.NetworkProviderInfo.Builder setConnectionStrength(@IntRange(from=0, to=3) int);
method @NonNull public android.net.wifi.sharedconnectivity.app.NetworkProviderInfo.Builder setDeviceName(@NonNull String);
method @NonNull public android.net.wifi.sharedconnectivity.app.NetworkProviderInfo.Builder setDeviceType(int);
method @NonNull public android.net.wifi.sharedconnectivity.app.NetworkProviderInfo.Builder setExtras(@NonNull android.os.Bundle);
method @NonNull public android.net.wifi.sharedconnectivity.app.NetworkProviderInfo.Builder setModelName(@NonNull String);
}

View File

@@ -23,6 +23,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.net.wifi.sharedconnectivity.service.SharedConnectivityService;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.ArraySet;
@@ -86,6 +87,7 @@ public final class HotspotNetwork implements Parcelable {
@Nullable
@SecurityType
private final ArraySet<Integer> mHotspotSecurityTypes;
private final Bundle mExtras;
/**
* Builder class for {@link HotspotNetwork}.
@@ -102,8 +104,8 @@ public final class HotspotNetwork implements Parcelable {
private String mHotspotBssid;
@Nullable
@SecurityType
private final ArraySet<Integer> mHotspotSecurityTypes =
new ArraySet<>();
private final ArraySet<Integer> mHotspotSecurityTypes = new ArraySet<>();
private Bundle mExtras = Bundle.EMPTY;
/**
* Set the remote device ID.
@@ -189,6 +191,17 @@ public final class HotspotNetwork implements Parcelable {
return this;
}
/**
* Sets the extras bundle
*
* @return Returns the Builder object.
*/
@NonNull
public Builder setExtras(@NonNull Bundle extras) {
mExtras = extras;
return this;
}
/**
* Builds the {@link HotspotNetwork} object.
*
@@ -203,7 +216,8 @@ public final class HotspotNetwork implements Parcelable {
mNetworkName,
mHotspotSsid,
mHotspotBssid,
mHotspotSecurityTypes);
mHotspotSecurityTypes,
mExtras);
}
}
@@ -231,7 +245,8 @@ public final class HotspotNetwork implements Parcelable {
@NonNull String networkName,
@Nullable String hotspotSsid,
@Nullable String hotspotBssid,
@Nullable @SecurityType ArraySet<Integer> hotspotSecurityTypes) {
@Nullable @SecurityType ArraySet<Integer> hotspotSecurityTypes,
@NonNull Bundle extras) {
validate(deviceId,
networkType,
networkName,
@@ -243,6 +258,7 @@ public final class HotspotNetwork implements Parcelable {
mHotspotSsid = hotspotSsid;
mHotspotBssid = hotspotBssid;
mHotspotSecurityTypes = new ArraySet<>(hotspotSecurityTypes);
mExtras = extras;
}
/**
@@ -315,6 +331,16 @@ public final class HotspotNetwork implements Parcelable {
return mHotspotSecurityTypes;
}
/**
* Gets the extras Bundle.
*
* @return Returns a Bundle object.
*/
@NonNull
public Bundle getExtras() {
return mExtras;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof HotspotNetwork)) return false;
@@ -348,6 +374,7 @@ public final class HotspotNetwork implements Parcelable {
dest.writeString(mHotspotSsid);
dest.writeString(mHotspotBssid);
dest.writeArraySet(mHotspotSecurityTypes);
dest.writeBundle(mExtras);
}
/**
@@ -359,7 +386,7 @@ public final class HotspotNetwork implements Parcelable {
public static HotspotNetwork readFromParcel(@NonNull Parcel in) {
return new HotspotNetwork(in.readLong(), NetworkProviderInfo.readFromParcel(in),
in.readInt(), in.readString(), in.readString(), in.readString(),
(ArraySet<Integer>) in.readArraySet(null));
(ArraySet<Integer>) in.readArraySet(null), in.readBundle());
}
@NonNull
@@ -385,6 +412,7 @@ public final class HotspotNetwork implements Parcelable {
.append(", hotspotSsid=").append(mHotspotSsid)
.append(", hotspotBssid=").append(mHotspotBssid)
.append(", hotspotSecurityTypes=").append(mHotspotSecurityTypes.toString())
.append(", extras=").append(mExtras.toString())
.append("]").toString();
}
}

View File

@@ -117,7 +117,7 @@ public final class HotspotNetworkConnectionStatus implements Parcelable {
@ConnectionStatus
private int mStatus;
private HotspotNetwork mHotspotNetwork;
private Bundle mExtras;
private Bundle mExtras = Bundle.EMPTY;
/**
* Sets the status of the connection
@@ -179,7 +179,7 @@ public final class HotspotNetworkConnectionStatus implements Parcelable {
}
private HotspotNetworkConnectionStatus(@ConnectionStatus int status,
HotspotNetwork hotspotNetwork, Bundle extras) {
HotspotNetwork hotspotNetwork, @NonNull Bundle extras) {
validate(status);
mStatus = status;
mHotspotNetwork = hotspotNetwork;

View File

@@ -22,6 +22,7 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
@@ -73,6 +74,7 @@ public final class KnownNetwork implements Parcelable {
@SecurityType
private final ArraySet<Integer> mSecurityTypes;
private final NetworkProviderInfo mNetworkProviderInfo;
private final Bundle mExtras;
/**
* Builder class for {@link KnownNetwork}.
@@ -84,6 +86,7 @@ public final class KnownNetwork implements Parcelable {
@SecurityType
private final ArraySet<Integer> mSecurityTypes = new ArraySet<>();
private NetworkProviderInfo mNetworkProviderInfo;
private Bundle mExtras = Bundle.EMPTY;
/**
* Sets the indicated source of the known network.
@@ -134,6 +137,17 @@ public final class KnownNetwork implements Parcelable {
return this;
}
/**
* Sets the extras bundle
*
* @return Returns the Builder object.
*/
@NonNull
public Builder setExtras(@NonNull Bundle extras) {
mExtras = extras;
return this;
}
/**
* Builds the {@link KnownNetwork} object.
*
@@ -145,7 +159,8 @@ public final class KnownNetwork implements Parcelable {
mNetworkSource,
mSsid,
mSecurityTypes,
mNetworkProviderInfo);
mNetworkProviderInfo,
mExtras);
}
}
@@ -173,12 +188,14 @@ public final class KnownNetwork implements Parcelable {
@NetworkSource int networkSource,
@NonNull String ssid,
@NonNull @SecurityType ArraySet<Integer> securityTypes,
@Nullable NetworkProviderInfo networkProviderInfo) {
@Nullable NetworkProviderInfo networkProviderInfo,
@NonNull Bundle extras) {
validate(networkSource, ssid, securityTypes, networkProviderInfo);
mNetworkSource = networkSource;
mSsid = ssid;
mSecurityTypes = new ArraySet<>(securityTypes);
mNetworkProviderInfo = networkProviderInfo;
mExtras = extras;
}
/**
@@ -223,6 +240,16 @@ public final class KnownNetwork implements Parcelable {
return mNetworkProviderInfo;
}
/**
* Gets the extras Bundle.
*
* @return Returns a Bundle object.
*/
@NonNull
public Bundle getExtras() {
return mExtras;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof KnownNetwork)) return false;
@@ -249,6 +276,7 @@ public final class KnownNetwork implements Parcelable {
dest.writeString(mSsid);
dest.writeArraySet(mSecurityTypes);
mNetworkProviderInfo.writeToParcel(dest, flags);
dest.writeBundle(mExtras);
}
/**
@@ -260,7 +288,7 @@ public final class KnownNetwork implements Parcelable {
public static KnownNetwork readFromParcel(@NonNull Parcel in) {
return new KnownNetwork(in.readInt(), in.readString(),
(ArraySet<Integer>) in.readArraySet(null),
NetworkProviderInfo.readFromParcel(in));
NetworkProviderInfo.readFromParcel(in), in.readBundle());
}
@NonNull
@@ -283,6 +311,7 @@ public final class KnownNetwork implements Parcelable {
.append(", ssid=").append(mSsid)
.append(", securityTypes=").append(mSecurityTypes.toString())
.append(", networkProviderInfo=").append(mNetworkProviderInfo.toString())
.append(", extras=").append(mExtras.toString())
.append("]").toString();
}
}

View File

@@ -72,7 +72,7 @@ public final class KnownNetworkConnectionStatus implements Parcelable {
public static final class Builder {
@ConnectionStatus private int mStatus;
private KnownNetwork mKnownNetwork;
private Bundle mExtras;
private Bundle mExtras = Bundle.EMPTY;
public Builder() {}
@@ -128,7 +128,7 @@ public final class KnownNetworkConnectionStatus implements Parcelable {
}
private KnownNetworkConnectionStatus(@ConnectionStatus int status, KnownNetwork knownNetwork,
Bundle extras) {
@NonNull Bundle extras) {
validate(status);
mStatus = status;
mKnownNetwork = knownNetwork;

View File

@@ -21,6 +21,7 @@ import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.net.wifi.sharedconnectivity.service.SharedConnectivityService;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
@@ -89,6 +90,7 @@ public final class NetworkProviderInfo implements Parcelable {
private final String mModelName;
private final int mBatteryPercentage;
private final int mConnectionStrength;
private final Bundle mExtras;
/**
* Builder class for {@link NetworkProviderInfo}.
@@ -99,6 +101,7 @@ public final class NetworkProviderInfo implements Parcelable {
private String mModelName;
private int mBatteryPercentage;
private int mConnectionStrength;
private Bundle mExtras = Bundle.EMPTY;
public Builder(@NonNull String deviceName, @NonNull String modelName) {
Objects.requireNonNull(deviceName);
@@ -169,6 +172,17 @@ public final class NetworkProviderInfo implements Parcelable {
return this;
}
/**
* Sets the extras bundle
*
* @return Returns the Builder object.
*/
@NonNull
public Builder setExtras(@NonNull Bundle extras) {
mExtras = extras;
return this;
}
/**
* Builds the {@link NetworkProviderInfo} object.
*
@@ -177,7 +191,7 @@ public final class NetworkProviderInfo implements Parcelable {
@NonNull
public NetworkProviderInfo build() {
return new NetworkProviderInfo(mDeviceType, mDeviceName, mModelName, mBatteryPercentage,
mConnectionStrength);
mConnectionStrength, mExtras);
}
}
@@ -197,13 +211,15 @@ public final class NetworkProviderInfo implements Parcelable {
}
private NetworkProviderInfo(@DeviceType int deviceType, @NonNull String deviceName,
@NonNull String modelName, int batteryPercentage, int connectionStrength) {
@NonNull String modelName, int batteryPercentage, int connectionStrength,
@NonNull Bundle extras) {
validate(deviceType, deviceName, modelName, batteryPercentage, connectionStrength);
mDeviceType = deviceType;
mDeviceName = deviceName;
mModelName = modelName;
mBatteryPercentage = batteryPercentage;
mConnectionStrength = connectionStrength;
mExtras = extras;
}
/**
@@ -256,6 +272,16 @@ public final class NetworkProviderInfo implements Parcelable {
return mConnectionStrength;
}
/**
* Gets the extras Bundle.
*
* @return Returns a Bundle object.
*/
@NonNull
public Bundle getExtras() {
return mExtras;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof NetworkProviderInfo)) return false;
@@ -280,6 +306,7 @@ public final class NetworkProviderInfo implements Parcelable {
dest.writeString(mModelName);
dest.writeInt(mBatteryPercentage);
dest.writeInt(mConnectionStrength);
dest.writeBundle(mExtras);
}
@Override
@@ -295,7 +322,7 @@ public final class NetworkProviderInfo implements Parcelable {
@NonNull
public static NetworkProviderInfo readFromParcel(@NonNull Parcel in) {
return new NetworkProviderInfo(in.readInt(), in.readString(), in.readString(), in.readInt(),
in.readInt());
in.readInt(), in.readBundle());
}
@NonNull
@@ -319,6 +346,7 @@ public final class NetworkProviderInfo implements Parcelable {
.append(", modelName=").append(mModelName)
.append(", batteryPercentage=").append(mBatteryPercentage)
.append(", connectionStrength=").append(mConnectionStrength)
.append(", extras=").append(mExtras.toString())
.append("]").toString();
}
}

View File

@@ -51,7 +51,7 @@ public final class SharedConnectivitySettingsState implements Parcelable {
private boolean mInstantTetherEnabled;
private Intent mInstantTetherSettingsIntent;
private final Context mContext;
private Bundle mExtras;
private Bundle mExtras = Bundle.EMPTY;
public Builder(@NonNull Context context) {
mContext = context;
@@ -112,8 +112,7 @@ public final class SharedConnectivitySettingsState implements Parcelable {
}
private SharedConnectivitySettingsState(boolean instantTetherEnabled,
PendingIntent pendingIntent, Bundle extras) {
PendingIntent pendingIntent, @NonNull Bundle extras) {
mInstantTetherEnabled = instantTetherEnabled;
mInstantTetherSettingsPendingIntent = pendingIntent;
mExtras = extras;

View File

@@ -28,6 +28,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import android.os.Bundle;
import android.os.Parcel;
import android.util.ArraySet;
@@ -55,6 +56,8 @@ public class HotspotNetworkTest {
private static final String HOTSPOT_SSID = "TEST_SSID";
private static final String HOTSPOT_BSSID = "TEST _BSSID";
private static final int[] HOTSPOT_SECURITY_TYPES = {SECURITY_TYPE_WEP, SECURITY_TYPE_EAP};
private static final String BUNDLE_KEY = "INT-KEY";
private static final int BUNDLE_VALUE = 1;
private static final long DEVICE_ID_1 = 111L;
private static final NetworkProviderInfo NETWORK_PROVIDER_INFO1 =
@@ -138,6 +141,7 @@ public class HotspotNetworkTest {
assertThat(network.getHotspotSsid()).isEqualTo(HOTSPOT_SSID);
assertThat(network.getHotspotBssid()).isEqualTo(HOTSPOT_BSSID);
assertThat(network.getHotspotSecurityTypes()).containsExactlyElementsIn(securityTypes);
assertThat(network.getExtras().getInt(BUNDLE_KEY)).isEqualTo(BUNDLE_VALUE);
}
@Test
@@ -161,11 +165,18 @@ public class HotspotNetworkTest {
.setHostNetworkType(NETWORK_TYPE)
.setNetworkName(NETWORK_NAME)
.setHotspotSsid(HOTSPOT_SSID)
.setHotspotBssid(HOTSPOT_BSSID);
.setHotspotBssid(HOTSPOT_BSSID)
.setExtras(buildBundle());
Arrays.stream(HOTSPOT_SECURITY_TYPES).forEach(builder::addHotspotSecurityType);
if (withNetworkProviderInfo) {
builder.setNetworkProviderInfo(NETWORK_PROVIDER_INFO);
}
return builder;
}
private Bundle buildBundle() {
Bundle bundle = new Bundle();
bundle.putInt(BUNDLE_KEY, BUNDLE_VALUE);
return bundle;
}
}

View File

@@ -25,6 +25,7 @@ import static android.net.wifi.sharedconnectivity.app.NetworkProviderInfo.DEVICE
import static com.google.common.truth.Truth.assertThat;
import android.os.Bundle;
import android.os.Parcel;
import android.util.ArraySet;
@@ -47,6 +48,9 @@ public class KnownNetworkTest {
new NetworkProviderInfo.Builder("TEST_NAME", "TEST_MODEL")
.setDeviceType(DEVICE_TYPE_TABLET).setConnectionStrength(2)
.setBatteryPercentage(50).build();
private static final String BUNDLE_KEY = "INT-KEY";
private static final int BUNDLE_VALUE = 1;
private static final int NETWORK_SOURCE_1 = NETWORK_SOURCE_CLOUD_SELF;
private static final String SSID_1 = "TEST_SSID1";
private static final int[] SECURITY_TYPES_1 = {SECURITY_TYPE_PSK};
@@ -113,6 +117,7 @@ public class KnownNetworkTest {
assertThat(network.getSsid()).isEqualTo(SSID);
assertThat(network.getSecurityTypes()).containsExactlyElementsIn(securityTypes);
assertThat(network.getNetworkProviderInfo()).isEqualTo(NETWORK_PROVIDER_INFO);
assertThat(network.getExtras().getInt(BUNDLE_KEY)).isEqualTo(BUNDLE_VALUE);
}
@Test
@@ -125,8 +130,15 @@ public class KnownNetworkTest {
private KnownNetwork.Builder buildKnownNetworkBuilder() {
KnownNetwork.Builder builder = new KnownNetwork.Builder().setNetworkSource(NETWORK_SOURCE)
.setSsid(SSID).setNetworkProviderInfo(NETWORK_PROVIDER_INFO);
.setSsid(SSID).setNetworkProviderInfo(NETWORK_PROVIDER_INFO)
.setExtras(buildBundle());
Arrays.stream(SECURITY_TYPES).forEach(builder::addSecurityType);
return builder;
}
private Bundle buildBundle() {
Bundle bundle = new Bundle();
bundle.putInt(BUNDLE_KEY, BUNDLE_VALUE);
return bundle;
}
}

View File

@@ -21,6 +21,7 @@ import static android.net.wifi.sharedconnectivity.app.NetworkProviderInfo.DEVICE
import static com.google.common.truth.Truth.assertThat;
import android.os.Bundle;
import android.os.Parcel;
import androidx.test.filters.SmallTest;
@@ -38,6 +39,8 @@ public class NetworkProviderInfoTest {
private static final String DEVICE_MODEL = "TEST_MODEL";
private static final int BATTERY_PERCENTAGE = 50;
private static final int CONNECTION_STRENGTH = 2;
private static final String BUNDLE_KEY = "INT-KEY";
private static final int BUNDLE_VALUE = 1;
private static final int DEVICE_TYPE_1 = DEVICE_TYPE_LAPTOP;
private static final String DEVICE_NAME_1 = "TEST_NAME1";
@@ -105,6 +108,7 @@ public class NetworkProviderInfoTest {
assertThat(info.getModelName()).isEqualTo(DEVICE_MODEL);
assertThat(info.getBatteryPercentage()).isEqualTo(BATTERY_PERCENTAGE);
assertThat(info.getConnectionStrength()).isEqualTo(CONNECTION_STRENGTH);
assertThat(info.getExtras().getInt(BUNDLE_KEY)).isEqualTo(BUNDLE_VALUE);
}
@Test
@@ -118,6 +122,13 @@ public class NetworkProviderInfoTest {
private NetworkProviderInfo.Builder buildNetworkProviderInfoBuilder() {
return new NetworkProviderInfo.Builder(DEVICE_NAME, DEVICE_MODEL).setDeviceType(DEVICE_TYPE)
.setBatteryPercentage(BATTERY_PERCENTAGE)
.setConnectionStrength(CONNECTION_STRENGTH);
.setConnectionStrength(CONNECTION_STRENGTH)
.setExtras(buildBundle());
}
private Bundle buildBundle() {
Bundle bundle = new Bundle();
bundle.putInt(BUNDLE_KEY, BUNDLE_VALUE);
return bundle;
}
}