Merge "Added network objects to ConnectionStatus classes."
This commit is contained in:
committed by
Android (Google) Code Review
commit
57ed8e3f4d
@@ -10019,6 +10019,7 @@ package android.net.wifi.sharedconnectivity.app {
|
||||
public final class KnownNetworkConnectionStatus implements android.os.Parcelable {
|
||||
method public int describeContents();
|
||||
method @NonNull public android.os.Bundle getExtras();
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetwork getKnownNetwork();
|
||||
method public int getStatus();
|
||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||
field public static final int CONNECTION_STATUS_SAVED = 1; // 0x1
|
||||
@@ -10031,6 +10032,7 @@ package android.net.wifi.sharedconnectivity.app {
|
||||
ctor public KnownNetworkConnectionStatus.Builder();
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus build();
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus.Builder setExtras(@NonNull android.os.Bundle);
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus.Builder setKnownNetwork(@NonNull android.net.wifi.sharedconnectivity.app.KnownNetwork);
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus.Builder setStatus(int);
|
||||
}
|
||||
|
||||
@@ -10099,6 +10101,7 @@ package android.net.wifi.sharedconnectivity.app {
|
||||
method public int describeContents();
|
||||
method @NonNull public android.os.Bundle getExtras();
|
||||
method public int getStatus();
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.TetherNetwork getTetherNetwork();
|
||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||
field public static final int CONNECTION_STATUS_CONNECT_TO_HOTSPOT_FAILED = 9; // 0x9
|
||||
field public static final int CONNECTION_STATUS_ENABLING_HOTSPOT = 1; // 0x1
|
||||
@@ -10118,6 +10121,7 @@ package android.net.wifi.sharedconnectivity.app {
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus build();
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus.Builder setExtras(@NonNull android.os.Bundle);
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus.Builder setStatus(int);
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus.Builder setTetherNetwork(@NonNull android.net.wifi.sharedconnectivity.app.TetherNetwork);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -270,12 +270,22 @@ public final class DeviceInfo implements Parcelable {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link DeviceInfo} object from a parcel.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@NonNull
|
||||
public static DeviceInfo readFromParcel(@NonNull Parcel in) {
|
||||
return new DeviceInfo(in.readInt(), in.readString(), in.readString(), in.readInt(),
|
||||
in.readInt());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static final Creator<DeviceInfo> CREATOR = new Creator<DeviceInfo>() {
|
||||
@Override
|
||||
public DeviceInfo createFromParcel(Parcel in) {
|
||||
return new DeviceInfo(in.readInt(), in.readString(), in.readString(), in.readInt(),
|
||||
in.readInt());
|
||||
return readFromParcel(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -228,15 +228,25 @@ public final class KnownNetwork implements Parcelable {
|
||||
dest.writeInt(mNetworkSource);
|
||||
dest.writeString(mSsid);
|
||||
dest.writeIntArray(mSecurityTypes);
|
||||
dest.writeTypedObject(mDeviceInfo, 0);
|
||||
mDeviceInfo.writeToParcel(dest, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link KnownNetwork} object from a parcel.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@NonNull
|
||||
public static KnownNetwork readFromParcel(@NonNull Parcel in) {
|
||||
return new KnownNetwork(in.readInt(), in.readString(), in.createIntArray(),
|
||||
DeviceInfo.readFromParcel(in));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static final Creator<KnownNetwork> CREATOR = new Creator<>() {
|
||||
@Override
|
||||
public KnownNetwork createFromParcel(Parcel in) {
|
||||
return new KnownNetwork(in.readInt(), in.readString(), in.createIntArray(),
|
||||
in.readTypedObject(DeviceInfo.CREATOR));
|
||||
return readFromParcel(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -63,6 +63,7 @@ public final class KnownNetworkConnectionStatus implements Parcelable {
|
||||
public @interface ConnectionStatus {}
|
||||
|
||||
@ConnectionStatus private final int mStatus;
|
||||
private final KnownNetwork mKnownNetwork;
|
||||
private final Bundle mExtras;
|
||||
|
||||
/**
|
||||
@@ -70,6 +71,7 @@ public final class KnownNetworkConnectionStatus implements Parcelable {
|
||||
*/
|
||||
public static final class Builder {
|
||||
@ConnectionStatus private int mStatus;
|
||||
private KnownNetwork mKnownNetwork;
|
||||
private Bundle mExtras;
|
||||
|
||||
public Builder() {}
|
||||
@@ -85,6 +87,17 @@ public final class KnownNetworkConnectionStatus implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link KnownNetwork} object of the connection.
|
||||
*
|
||||
* @return Returns the Builder object.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder setKnownNetwork(@NonNull KnownNetwork knownNetwork) {
|
||||
mKnownNetwork = knownNetwork;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the extras bundle
|
||||
*
|
||||
@@ -103,12 +116,14 @@ public final class KnownNetworkConnectionStatus implements Parcelable {
|
||||
*/
|
||||
@NonNull
|
||||
public KnownNetworkConnectionStatus build() {
|
||||
return new KnownNetworkConnectionStatus(mStatus, mExtras);
|
||||
return new KnownNetworkConnectionStatus(mStatus, mKnownNetwork, mExtras);
|
||||
}
|
||||
}
|
||||
|
||||
private KnownNetworkConnectionStatus(@ConnectionStatus int status, Bundle extras) {
|
||||
private KnownNetworkConnectionStatus(@ConnectionStatus int status, KnownNetwork knownNetwork,
|
||||
Bundle extras) {
|
||||
mStatus = status;
|
||||
mKnownNetwork = knownNetwork;
|
||||
mExtras = extras;
|
||||
}
|
||||
|
||||
@@ -122,6 +137,16 @@ public final class KnownNetworkConnectionStatus implements Parcelable {
|
||||
return mStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link KnownNetwork} object of the connection.
|
||||
*
|
||||
* @return Returns a KnownNetwork object.
|
||||
*/
|
||||
@NonNull
|
||||
public KnownNetwork getKnownNetwork() {
|
||||
return mKnownNetwork;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extras Bundle.
|
||||
*
|
||||
@@ -136,12 +161,13 @@ public final class KnownNetworkConnectionStatus implements Parcelable {
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof KnownNetworkConnectionStatus)) return false;
|
||||
KnownNetworkConnectionStatus other = (KnownNetworkConnectionStatus) obj;
|
||||
return mStatus == other.getStatus();
|
||||
return mStatus == other.getStatus()
|
||||
&& Objects.equals(mKnownNetwork, other.getKnownNetwork());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(mStatus);
|
||||
return Objects.hash(mStatus, mKnownNetwork);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -152,15 +178,27 @@ public final class KnownNetworkConnectionStatus implements Parcelable {
|
||||
@Override
|
||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||
dest.writeInt(mStatus);
|
||||
mKnownNetwork.writeToParcel(dest, flags);
|
||||
dest.writeBundle(mExtras);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link KnownNetworkConnectionStatus} object from a parcel.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@NonNull
|
||||
public static KnownNetworkConnectionStatus readFromParcel(@NonNull Parcel in) {
|
||||
return new KnownNetworkConnectionStatus(in.readInt(),
|
||||
KnownNetwork.readFromParcel(in),
|
||||
in.readBundle());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static final Creator<KnownNetworkConnectionStatus> CREATOR = new Creator<>() {
|
||||
@Override
|
||||
public KnownNetworkConnectionStatus createFromParcel(Parcel in) {
|
||||
return new KnownNetworkConnectionStatus(in.readInt(),
|
||||
in.readBundle(getClass().getClassLoader()));
|
||||
return readFromParcel(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -173,6 +211,7 @@ public final class KnownNetworkConnectionStatus implements Parcelable {
|
||||
public String toString() {
|
||||
return new StringBuilder("KnownNetworkConnectionStatus[")
|
||||
.append("status=").append(mStatus)
|
||||
.append("known network=").append(mKnownNetwork.toString())
|
||||
.append("extras=").append(mExtras.toString())
|
||||
.append("]").toString();
|
||||
}
|
||||
|
||||
@@ -128,12 +128,22 @@ public final class SharedConnectivitySettingsState implements Parcelable {
|
||||
dest.writeBundle(mExtras);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link SharedConnectivitySettingsState} object from a parcel.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@NonNull
|
||||
public static SharedConnectivitySettingsState readFromParcel(@NonNull Parcel in) {
|
||||
return new SharedConnectivitySettingsState(in.readBoolean(),
|
||||
in.readBundle());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static final Creator<SharedConnectivitySettingsState> CREATOR = new Creator<>() {
|
||||
@Override
|
||||
public SharedConnectivitySettingsState createFromParcel(Parcel in) {
|
||||
return new SharedConnectivitySettingsState(in.readBoolean(),
|
||||
in.readBundle(getClass().getClassLoader()));
|
||||
return readFromParcel(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -328,7 +328,7 @@ public final class TetherNetwork implements Parcelable {
|
||||
@Override
|
||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||
dest.writeLong(mDeviceId);
|
||||
dest.writeTypedObject(mDeviceInfo, 0);
|
||||
mDeviceInfo.writeToParcel(dest, flags);
|
||||
dest.writeInt(mNetworkType);
|
||||
dest.writeString(mNetworkName);
|
||||
dest.writeString(mHotspotSsid);
|
||||
@@ -336,14 +336,23 @@ public final class TetherNetwork implements Parcelable {
|
||||
dest.writeIntArray(mHotspotSecurityTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link TetherNetwork} object from a parcel.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@NonNull
|
||||
public static TetherNetwork readFromParcel(@NonNull Parcel in) {
|
||||
return new TetherNetwork(in.readLong(), DeviceInfo.readFromParcel(in),
|
||||
in.readInt(), in.readString(), in.readString(), in.readString(),
|
||||
in.createIntArray());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static final Creator<TetherNetwork> CREATOR = new Creator<>() {
|
||||
@Override
|
||||
public TetherNetwork createFromParcel(Parcel in) {
|
||||
return new TetherNetwork(in.readLong(), in.readTypedObject(
|
||||
android.net.wifi.sharedconnectivity.app.DeviceInfo.CREATOR),
|
||||
in.readInt(), in.readString(), in.readString(), in.readString(),
|
||||
in.createIntArray());
|
||||
return readFromParcel(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -105,6 +105,7 @@ public final class TetherNetworkConnectionStatus implements Parcelable {
|
||||
public @interface ConnectionStatus {}
|
||||
|
||||
@ConnectionStatus private final int mStatus;
|
||||
private final TetherNetwork mTetherNetwork;
|
||||
private final Bundle mExtras;
|
||||
|
||||
/**
|
||||
@@ -112,6 +113,7 @@ public final class TetherNetworkConnectionStatus implements Parcelable {
|
||||
*/
|
||||
public static final class Builder {
|
||||
@ConnectionStatus private int mStatus;
|
||||
private TetherNetwork mTetherNetwork;
|
||||
private Bundle mExtras;
|
||||
|
||||
public Builder() {}
|
||||
@@ -127,6 +129,17 @@ public final class TetherNetworkConnectionStatus implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link TetherNetwork} object of the connection.
|
||||
*
|
||||
* @return Returns the Builder object.
|
||||
*/
|
||||
@NonNull
|
||||
public Builder setTetherNetwork(@NonNull TetherNetwork tetherNetwork) {
|
||||
mTetherNetwork = tetherNetwork;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the extras bundle
|
||||
*
|
||||
@@ -145,12 +158,14 @@ public final class TetherNetworkConnectionStatus implements Parcelable {
|
||||
*/
|
||||
@NonNull
|
||||
public TetherNetworkConnectionStatus build() {
|
||||
return new TetherNetworkConnectionStatus(mStatus, mExtras);
|
||||
return new TetherNetworkConnectionStatus(mStatus, mTetherNetwork, mExtras);
|
||||
}
|
||||
}
|
||||
|
||||
private TetherNetworkConnectionStatus(@ConnectionStatus int status, Bundle extras) {
|
||||
private TetherNetworkConnectionStatus(@ConnectionStatus int status, TetherNetwork tetherNetwork,
|
||||
Bundle extras) {
|
||||
mStatus = status;
|
||||
mTetherNetwork = tetherNetwork;
|
||||
mExtras = extras;
|
||||
}
|
||||
|
||||
@@ -164,6 +179,16 @@ public final class TetherNetworkConnectionStatus implements Parcelable {
|
||||
return mStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link TetherNetwork} object of the connection.
|
||||
*
|
||||
* @return Returns a TetherNetwork object.
|
||||
*/
|
||||
@NonNull
|
||||
public TetherNetwork getTetherNetwork() {
|
||||
return mTetherNetwork;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extras Bundle.
|
||||
*
|
||||
@@ -178,12 +203,13 @@ public final class TetherNetworkConnectionStatus implements Parcelable {
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof TetherNetworkConnectionStatus)) return false;
|
||||
TetherNetworkConnectionStatus other = (TetherNetworkConnectionStatus) obj;
|
||||
return mStatus == other.getStatus();
|
||||
return mStatus == other.getStatus()
|
||||
&& Objects.equals(mTetherNetwork, other.getTetherNetwork());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(mStatus);
|
||||
return Objects.hash(mStatus, mTetherNetwork);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -194,27 +220,39 @@ public final class TetherNetworkConnectionStatus implements Parcelable {
|
||||
@Override
|
||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||
dest.writeInt(mStatus);
|
||||
mTetherNetwork.writeToParcel(dest, flags);
|
||||
dest.writeBundle(mExtras);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link TetherNetworkConnectionStatus} object from a parcel.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@NonNull
|
||||
public static TetherNetworkConnectionStatus readFromParcel(@NonNull Parcel in) {
|
||||
return new TetherNetworkConnectionStatus(in.readInt(),
|
||||
TetherNetwork.readFromParcel(in), in.readBundle());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static final Creator<TetherNetworkConnectionStatus> CREATOR = new Creator<>() {
|
||||
@Override
|
||||
public TetherNetworkConnectionStatus createFromParcel(Parcel in) {
|
||||
return new TetherNetworkConnectionStatus(in.readInt(),
|
||||
in.readBundle(getClass().getClassLoader()));
|
||||
}
|
||||
@Override
|
||||
public TetherNetworkConnectionStatus createFromParcel(Parcel in) {
|
||||
return readFromParcel(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TetherNetworkConnectionStatus[] newArray(int size) {
|
||||
return new TetherNetworkConnectionStatus[size];
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public TetherNetworkConnectionStatus[] newArray(int size) {
|
||||
return new TetherNetworkConnectionStatus[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("TetherNetworkConnectionStatus[")
|
||||
.append("status=").append(mStatus)
|
||||
.append("tether network=").append(mTetherNetwork.toString())
|
||||
.append("extras=").append(mExtras.toString())
|
||||
.append("]").toString();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net.wifi.sharedconnectivity.app;
|
||||
|
||||
import static android.net.wifi.WifiInfo.SECURITY_TYPE_WEP;
|
||||
import static android.net.wifi.sharedconnectivity.app.DeviceInfo.DEVICE_TYPE_TABLET;
|
||||
import static android.net.wifi.sharedconnectivity.app.KnownNetwork.NETWORK_SOURCE_NEARBY_SELF;
|
||||
import static android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus.CONNECTION_STATUS_SAVED;
|
||||
import static android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus.CONNECTION_STATUS_SAVE_FAILED;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus}.
|
||||
*/
|
||||
@SmallTest
|
||||
public class KnownNetworkConnectionStatusTest {
|
||||
private static final int NETWORK_SOURCE = NETWORK_SOURCE_NEARBY_SELF;
|
||||
private static final String SSID = "TEST_SSID";
|
||||
private static final int[] SECURITY_TYPES = {SECURITY_TYPE_WEP};
|
||||
private static final DeviceInfo DEVICE_INFO = new DeviceInfo.Builder()
|
||||
.setDeviceType(DEVICE_TYPE_TABLET).setDeviceName("TEST_NAME").setModelName("TEST_MODEL")
|
||||
.setConnectionStrength(2).setBatteryPercentage(50).build();
|
||||
private static final String SSID_1 = "TEST_SSID1";
|
||||
private static final String BUNDLE_KEY = "INT-KEY";
|
||||
|
||||
/**
|
||||
* Verifies parcel serialization/deserialization.
|
||||
*/
|
||||
@Test
|
||||
public void testParcelOperation() {
|
||||
KnownNetworkConnectionStatus status = buildConnectionStatusBuilder().build();
|
||||
|
||||
Parcel parcelW = Parcel.obtain();
|
||||
status.writeToParcel(parcelW, 0);
|
||||
byte[] bytes = parcelW.marshall();
|
||||
parcelW.recycle();
|
||||
|
||||
Parcel parcelR = Parcel.obtain();
|
||||
parcelR.unmarshall(bytes, 0, bytes.length);
|
||||
parcelR.setDataPosition(0);
|
||||
KnownNetworkConnectionStatus fromParcel =
|
||||
KnownNetworkConnectionStatus.CREATOR.createFromParcel(parcelR);
|
||||
|
||||
assertEquals(status, fromParcel);
|
||||
assertEquals(status.hashCode(), fromParcel.hashCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the Equals operation
|
||||
*/
|
||||
@Test
|
||||
public void testEqualsOperation() {
|
||||
KnownNetworkConnectionStatus status1 = buildConnectionStatusBuilder().build();
|
||||
KnownNetworkConnectionStatus status2 = buildConnectionStatusBuilder().build();
|
||||
assertEquals(status2, status2);
|
||||
|
||||
KnownNetworkConnectionStatus.Builder builder = buildConnectionStatusBuilder()
|
||||
.setStatus(CONNECTION_STATUS_SAVE_FAILED);
|
||||
assertNotEquals(status1, builder.build());
|
||||
|
||||
builder = buildConnectionStatusBuilder()
|
||||
.setKnownNetwork(buildKnownNetworkBuilder().setSsid(SSID_1).build());
|
||||
assertNotEquals(status1, builder.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the get methods return the expected data.
|
||||
*/
|
||||
@Test
|
||||
public void testGetMethods() {
|
||||
KnownNetworkConnectionStatus status = buildConnectionStatusBuilder().build();
|
||||
assertEquals(status.getStatus(), CONNECTION_STATUS_SAVED);
|
||||
assertEquals(status.getKnownNetwork(), buildKnownNetworkBuilder().build());
|
||||
assertEquals(status.getExtras().getInt(BUNDLE_KEY), buildBundle().getInt(BUNDLE_KEY));
|
||||
}
|
||||
|
||||
private KnownNetworkConnectionStatus.Builder buildConnectionStatusBuilder() {
|
||||
return new KnownNetworkConnectionStatus.Builder()
|
||||
.setStatus(CONNECTION_STATUS_SAVED)
|
||||
.setKnownNetwork(buildKnownNetworkBuilder().build())
|
||||
.setExtras(buildBundle());
|
||||
}
|
||||
|
||||
private Bundle buildBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(BUNDLE_KEY, 1);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
private KnownNetwork.Builder buildKnownNetworkBuilder() {
|
||||
return new KnownNetwork.Builder().setNetworkSource(NETWORK_SOURCE).setSsid(SSID)
|
||||
.setSecurityTypes(SECURITY_TYPES).setDeviceInfo(DEVICE_INFO);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net.wifi.sharedconnectivity.app;
|
||||
|
||||
import static android.net.wifi.WifiInfo.SECURITY_TYPE_EAP;
|
||||
import static android.net.wifi.WifiInfo.SECURITY_TYPE_WEP;
|
||||
import static android.net.wifi.sharedconnectivity.app.DeviceInfo.DEVICE_TYPE_TABLET;
|
||||
import static android.net.wifi.sharedconnectivity.app.TetherNetwork.NETWORK_TYPE_CELLULAR;
|
||||
import static android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus.CONNECTION_STATUS_ENABLING_HOTSPOT;
|
||||
import static android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus.CONNECTION_STATUS_TETHERING_TIMEOUT;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus}.
|
||||
*/
|
||||
@SmallTest
|
||||
public class TetherNetworkConnectionStatusTest {
|
||||
private static final long DEVICE_ID = 11L;
|
||||
private static final DeviceInfo DEVICE_INFO = new DeviceInfo.Builder()
|
||||
.setDeviceType(DEVICE_TYPE_TABLET).setDeviceName("TEST_NAME").setModelName("TEST_MODEL")
|
||||
.setConnectionStrength(2).setBatteryPercentage(50).build();
|
||||
private static final int NETWORK_TYPE = NETWORK_TYPE_CELLULAR;
|
||||
private static final String NETWORK_NAME = "TEST_NETWORK";
|
||||
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 long DEVICE_ID_1 = 111L;
|
||||
private static final String BUNDLE_KEY = "INT-KEY";
|
||||
|
||||
/**
|
||||
* Verifies parcel serialization/deserialization.
|
||||
*/
|
||||
@Test
|
||||
public void testParcelOperation() {
|
||||
TetherNetworkConnectionStatus status = buildConnectionStatusBuilder().build();
|
||||
|
||||
Parcel parcelW = Parcel.obtain();
|
||||
status.writeToParcel(parcelW, 0);
|
||||
byte[] bytes = parcelW.marshall();
|
||||
parcelW.recycle();
|
||||
|
||||
Parcel parcelR = Parcel.obtain();
|
||||
parcelR.unmarshall(bytes, 0, bytes.length);
|
||||
parcelR.setDataPosition(0);
|
||||
TetherNetworkConnectionStatus fromParcel =
|
||||
TetherNetworkConnectionStatus.CREATOR.createFromParcel(parcelR);
|
||||
|
||||
assertEquals(status, fromParcel);
|
||||
assertEquals(status.hashCode(), fromParcel.hashCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the Equals operation
|
||||
*/
|
||||
@Test
|
||||
public void testEqualsOperation() {
|
||||
TetherNetworkConnectionStatus status1 = buildConnectionStatusBuilder().build();
|
||||
TetherNetworkConnectionStatus status2 = buildConnectionStatusBuilder().build();
|
||||
assertEquals(status2, status2);
|
||||
|
||||
TetherNetworkConnectionStatus.Builder builder = buildConnectionStatusBuilder()
|
||||
.setStatus(CONNECTION_STATUS_TETHERING_TIMEOUT);
|
||||
assertNotEquals(status1, builder.build());
|
||||
|
||||
builder = buildConnectionStatusBuilder()
|
||||
.setTetherNetwork(buildTetherNetworkBuilder().setDeviceId(DEVICE_ID_1).build());
|
||||
assertNotEquals(status1, builder.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the get methods return the expected data.
|
||||
*/
|
||||
@Test
|
||||
public void testGetMethods() {
|
||||
TetherNetworkConnectionStatus status = buildConnectionStatusBuilder().build();
|
||||
assertEquals(status.getStatus(), CONNECTION_STATUS_ENABLING_HOTSPOT);
|
||||
assertEquals(status.getTetherNetwork(), buildTetherNetworkBuilder().build());
|
||||
assertEquals(status.getExtras().getInt(BUNDLE_KEY), buildBundle().getInt(BUNDLE_KEY));
|
||||
}
|
||||
|
||||
private TetherNetworkConnectionStatus.Builder buildConnectionStatusBuilder() {
|
||||
|
||||
return new TetherNetworkConnectionStatus.Builder()
|
||||
.setStatus(CONNECTION_STATUS_ENABLING_HOTSPOT)
|
||||
.setTetherNetwork(buildTetherNetworkBuilder().build())
|
||||
.setExtras(buildBundle());
|
||||
}
|
||||
|
||||
private Bundle buildBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(BUNDLE_KEY, 1);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
private TetherNetwork.Builder buildTetherNetworkBuilder() {
|
||||
return new TetherNetwork.Builder()
|
||||
.setDeviceId(DEVICE_ID)
|
||||
.setDeviceInfo(DEVICE_INFO)
|
||||
.setNetworkType(NETWORK_TYPE)
|
||||
.setNetworkName(NETWORK_NAME)
|
||||
.setHotspotSsid(HOTSPOT_SSID)
|
||||
.setHotspotBssid(HOTSPOT_BSSID)
|
||||
.setHotspotSecurityTypes(HOTSPOT_SECURITY_TYPES);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user