diff options
author | Isaac Katzenelson <isaackatz@google.com> | 2023-03-15 01:01:06 +0000 |
---|---|---|
committer | Isaac Katzenelson <isaack@android.com> | 2023-03-16 05:38:04 +0000 |
commit | c2a698bf8dc4cdcba80a61e6574f7b6fc9be9c21 (patch) | |
tree | 3e06c9e111b9c9c8d69ec01f3ab5cdf2c0e18005 /wifi | |
parent | 6c34756275e261a18034b29734b2c4850185bac8 (diff) | |
download | base-c2a698bf8dc4cdcba80a61e6574f7b6fc9be9c21.tar.gz |
Add extras parameter to rest of data classes
Made sure all extras are non-null on all data classes.
Bug: 273606522
Test: atest HotspotNetworkTest KnownNetworkTest NetworkProviderInfoTest
Change-Id: Ieb393bfd8868fbde38a4699b0c78e98df4bb42a8
Diffstat (limited to 'wifi')
9 files changed, 139 insertions, 21 deletions
diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetwork.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetwork.java index 9bfeb6308d13..fe397d9c2662 100644 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetwork.java +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetwork.java @@ -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. @@ -190,6 +192,17 @@ public final class HotspotNetwork implements Parcelable { } /** + * 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. * * @return Returns the built {@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(); } } diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetworkConnectionStatus.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetworkConnectionStatus.java index 69767f302bd8..72acf2ccab0c 100644 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetworkConnectionStatus.java +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetworkConnectionStatus.java @@ -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; diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetwork.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetwork.java index 64412bc55fb2..c390e42f348e 100644 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetwork.java +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetwork.java @@ -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. @@ -135,6 +138,17 @@ public final class KnownNetwork implements Parcelable { } /** + * 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. * * @return Returns the built {@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(); } } diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetworkConnectionStatus.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetworkConnectionStatus.java index 6bd0a5ecd4c8..b30dc3f6b530 100644 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetworkConnectionStatus.java +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetworkConnectionStatus.java @@ -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; diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/NetworkProviderInfo.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/NetworkProviderInfo.java index ed4d699ad4de..25fbabce71ae 100644 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/NetworkProviderInfo.java +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/NetworkProviderInfo.java @@ -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); @@ -170,6 +173,17 @@ public final class NetworkProviderInfo implements Parcelable { } /** + * 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. * * @return Returns the built {@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(); } } diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivitySettingsState.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivitySettingsState.java index 63e471b25ffb..30bb98962b3c 100644 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivitySettingsState.java +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivitySettingsState.java @@ -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; diff --git a/wifi/tests/src/android/net/wifi/sharedconnectivity/app/HotspotNetworkTest.java b/wifi/tests/src/android/net/wifi/sharedconnectivity/app/HotspotNetworkTest.java index 8302094b1c34..0827ffaea482 100644 --- a/wifi/tests/src/android/net/wifi/sharedconnectivity/app/HotspotNetworkTest.java +++ b/wifi/tests/src/android/net/wifi/sharedconnectivity/app/HotspotNetworkTest.java @@ -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; + } } diff --git a/wifi/tests/src/android/net/wifi/sharedconnectivity/app/KnownNetworkTest.java b/wifi/tests/src/android/net/wifi/sharedconnectivity/app/KnownNetworkTest.java index 1ecba7644cf9..81d7b44382e0 100644 --- a/wifi/tests/src/android/net/wifi/sharedconnectivity/app/KnownNetworkTest.java +++ b/wifi/tests/src/android/net/wifi/sharedconnectivity/app/KnownNetworkTest.java @@ -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; + } } diff --git a/wifi/tests/src/android/net/wifi/sharedconnectivity/app/NetworkProviderInfoTest.java b/wifi/tests/src/android/net/wifi/sharedconnectivity/app/NetworkProviderInfoTest.java index 8f35d8d94a8b..4aa9ca684ad0 100644 --- a/wifi/tests/src/android/net/wifi/sharedconnectivity/app/NetworkProviderInfoTest.java +++ b/wifi/tests/src/android/net/wifi/sharedconnectivity/app/NetworkProviderInfoTest.java @@ -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; } } |