From a6c820b5ddd1df771594dced2bac7f6115390211 Mon Sep 17 00:00:00 2001 From: Isaac Katzenelson Date: Tue, 28 Feb 2023 08:15:10 +0000 Subject: API Review: TetherNetwork, DeviceInfo Renamed TetherNetwork to HotspotNetwork and replaced all usage of Tether with Hotspot. Renamed DeviceInfo to NetworkProviderInfo. Added DEVICE_TYPE_WATCH and DEVICE_TYPE_AUTO for futureproofing in NetworkProviderInfo.java Bug: 268486125 Test: atest (all affected test classes) Change-Id: I889457f02322644f3779bf25c3a125f7f973c69c --- .../wifi/sharedconnectivity/app/DeviceInfo.aidl | 19 - .../wifi/sharedconnectivity/app/DeviceInfo.java | 307 ---------------- .../sharedconnectivity/app/HotspotNetwork.aidl | 19 + .../sharedconnectivity/app/HotspotNetwork.java | 385 +++++++++++++++++++++ .../app/HotspotNetworkConnectionStatus.aidl | 19 + .../app/HotspotNetworkConnectionStatus.java | 261 ++++++++++++++ .../wifi/sharedconnectivity/app/KnownNetwork.java | 36 +- .../app/NetworkProviderInfo.aidl | 19 + .../app/NetworkProviderInfo.java | 320 +++++++++++++++++ .../app/SharedConnectivityClientCallback.java | 15 +- .../app/SharedConnectivityManager.java | 70 ++-- .../wifi/sharedconnectivity/app/TetherNetwork.aidl | 19 - .../wifi/sharedconnectivity/app/TetherNetwork.java | 374 -------------------- .../app/TetherNetworkConnectionStatus.aidl | 19 - .../app/TetherNetworkConnectionStatus.java | 259 -------------- .../service/ISharedConnectivityCallback.aidl | 8 +- .../service/ISharedConnectivityService.aidl | 12 +- .../service/SharedConnectivityService.java | 92 +++-- 18 files changed, 1140 insertions(+), 1113 deletions(-) delete mode 100644 wifi/java/src/android/net/wifi/sharedconnectivity/app/DeviceInfo.aidl delete mode 100644 wifi/java/src/android/net/wifi/sharedconnectivity/app/DeviceInfo.java create mode 100644 wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetwork.aidl create mode 100644 wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetwork.java create mode 100644 wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetworkConnectionStatus.aidl create mode 100644 wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetworkConnectionStatus.java create mode 100644 wifi/java/src/android/net/wifi/sharedconnectivity/app/NetworkProviderInfo.aidl create mode 100644 wifi/java/src/android/net/wifi/sharedconnectivity/app/NetworkProviderInfo.java delete mode 100644 wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetwork.aidl delete mode 100644 wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetwork.java delete mode 100644 wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetworkConnectionStatus.aidl delete mode 100644 wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetworkConnectionStatus.java (limited to 'wifi/java') diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/DeviceInfo.aidl b/wifi/java/src/android/net/wifi/sharedconnectivity/app/DeviceInfo.aidl deleted file mode 100644 index 35d5c15a161b..000000000000 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/DeviceInfo.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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; - -parcelable DeviceInfo; \ No newline at end of file diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/DeviceInfo.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/DeviceInfo.java deleted file mode 100644 index 52abf33bc761..000000000000 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/DeviceInfo.java +++ /dev/null @@ -1,307 +0,0 @@ -/* - * 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 android.annotation.IntDef; -import android.annotation.IntRange; -import android.annotation.NonNull; -import android.annotation.SystemApi; -import android.net.wifi.sharedconnectivity.service.SharedConnectivityService; -import android.os.Parcel; -import android.os.Parcelable; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.util.Objects; - -/** - * A data class representing a device providing connectivity. - * This class is used in IPC calls between the implementer of {@link SharedConnectivityService} and - * the consumers of {@link com.android.wifitrackerlib}. - * - * @hide - */ -@SystemApi -public final class DeviceInfo implements Parcelable { - - /** - * Device type providing connectivity is unknown. - */ - public static final int DEVICE_TYPE_UNKNOWN = 0; - - /** - * Device providing connectivity is a mobile phone. - */ - public static final int DEVICE_TYPE_PHONE = 1; - - /** - * Device providing connectivity is a tablet. - */ - public static final int DEVICE_TYPE_TABLET = 2; - - /** - * Device providing connectivity is a laptop. - */ - public static final int DEVICE_TYPE_LAPTOP = 3; - - /** - * @hide - */ - @Retention(RetentionPolicy.SOURCE) - @IntDef({ - DEVICE_TYPE_UNKNOWN, - DEVICE_TYPE_PHONE, - DEVICE_TYPE_TABLET, - DEVICE_TYPE_LAPTOP - }) - public @interface DeviceType {} - - @DeviceType private final int mDeviceType; - private final String mDeviceName; - private final String mModelName; - private final int mBatteryPercentage; - private final int mConnectionStrength; - - /** - * Builder class for {@link DeviceInfo}. - */ - public static final class Builder { - private int mDeviceType; - private String mDeviceName; - private String mModelName; - private int mBatteryPercentage; - private int mConnectionStrength; - - public Builder() {} - - /** - * Sets the device type that provides connectivity. - * - * @param deviceType Device type as represented by IntDef {@link DeviceType}. - * @return Returns the Builder object. - */ - @NonNull - public Builder setDeviceType(@DeviceType int deviceType) { - mDeviceType = deviceType; - return this; - } - - /** - * Sets the device name of the remote device. - * - * @param deviceName The user configurable device name. - * @return Returns the Builder object. - */ - @NonNull - public Builder setDeviceName(@NonNull String deviceName) { - mDeviceName = deviceName; - return this; - } - - /** - * Sets the model name of the remote device. - * - * @param modelName The OEM configured name for the device model. - * @return Returns the Builder object. - */ - @NonNull - public Builder setModelName(@NonNull String modelName) { - mModelName = modelName; - return this; - } - - /** - * Sets the battery charge percentage of the remote device. - * - * @param batteryPercentage The battery charge percentage in the range 0 to 100. - * @return Returns the Builder object. - */ - @NonNull - public Builder setBatteryPercentage(@IntRange(from = 0, to = 100) int batteryPercentage) { - mBatteryPercentage = batteryPercentage; - return this; - } - - /** - * Sets the displayed connection strength of the remote device to the internet. - * - * @param connectionStrength Connection strength in range 0 to 3. - * @return Returns the Builder object. - */ - @NonNull - public Builder setConnectionStrength(@IntRange(from = 0, to = 3) int connectionStrength) { - mConnectionStrength = connectionStrength; - return this; - } - - /** - * Builds the {@link DeviceInfo} object. - * - * @return Returns the built {@link DeviceInfo} object. - */ - @NonNull - public DeviceInfo build() { - return new DeviceInfo(mDeviceType, mDeviceName, mModelName, mBatteryPercentage, - mConnectionStrength); - } - } - - private static void validate(int deviceType, String deviceName, String modelName, - int batteryPercentage, int connectionStrength) { - if (deviceType != DEVICE_TYPE_UNKNOWN && deviceType != DEVICE_TYPE_PHONE - && deviceType != DEVICE_TYPE_TABLET && deviceType != DEVICE_TYPE_LAPTOP) { - throw new IllegalArgumentException("Illegal device type"); - } - if (Objects.isNull(deviceName)) { - throw new IllegalArgumentException("DeviceName must be set"); - } - if (Objects.isNull(modelName)) { - throw new IllegalArgumentException("ModelName must be set"); - } - if (batteryPercentage < 0 || batteryPercentage > 100) { - throw new IllegalArgumentException("BatteryPercentage must be in range 0-100"); - } - if (connectionStrength < 0 || connectionStrength > 3) { - throw new IllegalArgumentException("ConnectionStrength must be in range 0-3"); - } - } - - private DeviceInfo(@DeviceType int deviceType, @NonNull String deviceName, - @NonNull String modelName, int batteryPercentage, int connectionStrength) { - validate(deviceType, deviceName, modelName, batteryPercentage, connectionStrength); - mDeviceType = deviceType; - mDeviceName = deviceName; - mModelName = modelName; - mBatteryPercentage = batteryPercentage; - mConnectionStrength = connectionStrength; - } - - /** - * Gets the device type that provides connectivity. - * - * @return Returns the device type as represented by IntDef {@link DeviceType}. - */ - @DeviceType - public int getDeviceType() { - return mDeviceType; - } - - /** - * Gets the device name of the remote device. - * - * @return Returns the user configurable device name. - */ - @NonNull - public String getDeviceName() { - return mDeviceName; - } - - /** - * Gets the model name of the remote device. - * - * @return Returns the OEM configured name for the device model. - */ - @NonNull - public String getModelName() { - return mModelName; - } - - /** - * Gets the battery charge percentage of the remote device. - * - * @return Returns the battery charge percentage in the range 0 to 100. - */ - @IntRange(from = 0, to = 100) - public int getBatteryPercentage() { - return mBatteryPercentage; - } - - /** - * Gets the displayed connection strength of the remote device to the internet. - * - * @return Returns the connection strength in range 0 to 3. - */ - @IntRange(from = 0, to = 3) - public int getConnectionStrength() { - return mConnectionStrength; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof DeviceInfo)) return false; - DeviceInfo other = (DeviceInfo) obj; - return mDeviceType == other.getDeviceType() - && Objects.equals(mDeviceName, other.mDeviceName) - && Objects.equals(mModelName, other.mModelName) - && mBatteryPercentage == other.mBatteryPercentage - && mConnectionStrength == other.mConnectionStrength; - } - - @Override - public int hashCode() { - return Objects.hash(mDeviceType, mDeviceName, mModelName, mBatteryPercentage, - mConnectionStrength); - } - @Override - public void writeToParcel(@NonNull Parcel dest, int flags) { - dest.writeInt(mDeviceType); - dest.writeString(mDeviceName); - dest.writeString(mModelName); - dest.writeInt(mBatteryPercentage); - dest.writeInt(mConnectionStrength); - } - - @Override - public int describeContents() { - 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 CREATOR = new Creator() { - @Override - public DeviceInfo createFromParcel(Parcel in) { - return readFromParcel(in); - } - - @Override - public DeviceInfo[] newArray(int size) { - return new DeviceInfo[size]; - } - }; - - @Override - public String toString() { - return new StringBuilder("DeviceInfo[") - .append("deviceType=").append(mDeviceType) - .append(", deviceName=").append(mDeviceName) - .append(", modelName=").append(mModelName) - .append(", batteryPercentage=").append(mBatteryPercentage) - .append(", connectionStrength=").append(mConnectionStrength) - .append("]").toString(); - } -} diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetwork.aidl b/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetwork.aidl new file mode 100644 index 000000000000..f9c4829c8f93 --- /dev/null +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetwork.aidl @@ -0,0 +1,19 @@ +/* + * 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; + +parcelable HotspotNetwork; diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetwork.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetwork.java new file mode 100644 index 000000000000..5cf19fb90195 --- /dev/null +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetwork.java @@ -0,0 +1,385 @@ +/* + * 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.WifiAnnotations.SecurityType; + +import android.annotation.IntDef; +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.annotation.SystemApi; +import android.net.wifi.sharedconnectivity.service.SharedConnectivityService; +import android.os.Parcel; +import android.os.Parcelable; +import android.util.ArraySet; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.util.Objects; +import java.util.Set; + +/** + * A data class representing a hotspot network. + * This class is used in IPC calls between the implementer of {@link SharedConnectivityService} and + * the consumers of {@link com.android.wifitrackerlib}. + * + * @hide + */ +@SystemApi +public final class HotspotNetwork implements Parcelable { + /** + * Remote device is connected to the internet via an unknown connection. + */ + public static final int NETWORK_TYPE_UNKNOWN = 0; + + /** + * Remote device is connected to the internet via a cellular connection. + */ + public static final int NETWORK_TYPE_CELLULAR = 1; + + /** + * Remote device is connected to the internet via a Wi-Fi connection. + */ + public static final int NETWORK_TYPE_WIFI = 2; + + /** + * Remote device is connected to the internet via an ethernet connection. + */ + public static final int NETWORK_TYPE_ETHERNET = 3; + + /** + * @hide + */ + @Retention(RetentionPolicy.SOURCE) + @IntDef({ + NETWORK_TYPE_UNKNOWN, + NETWORK_TYPE_CELLULAR, + NETWORK_TYPE_WIFI, + NETWORK_TYPE_ETHERNET + }) + public @interface NetworkType { + } + + private final long mDeviceId; + private final NetworkProviderInfo mNetworkProviderInfo; + @NetworkType + private final int mNetworkType; + private final String mNetworkName; + @Nullable + private final String mHotspotSsid; + @Nullable + private final String mHotspotBssid; + @Nullable + @SecurityType + private final ArraySet mHotspotSecurityTypes; + + /** + * Builder class for {@link HotspotNetwork}. + */ + public static final class Builder { + private long mDeviceId = -1; + private NetworkProviderInfo mNetworkProviderInfo; + @NetworkType + private int mNetworkType; + private String mNetworkName; + @Nullable + private String mHotspotSsid; + @Nullable + private String mHotspotBssid; + @Nullable + @SecurityType + private final ArraySet mHotspotSecurityTypes = + new ArraySet<>(); + + /** + * Set the remote device ID. + * + * @param deviceId Locally unique ID for this Hotspot network. + * @return Returns the Builder object. + */ + @NonNull + public Builder setDeviceId(long deviceId) { + mDeviceId = deviceId; + return this; + } + + /** + * Sets information about the device providing connectivity. + * + * @param networkProviderInfo The device information object. + * @return Returns the Builder object. + */ + @NonNull + public Builder setNetworkProviderInfo(@NonNull NetworkProviderInfo networkProviderInfo) { + mNetworkProviderInfo = networkProviderInfo; + return this; + } + + /** + * Sets the network type that the remote device is connected to. + * + * @param networkType Network type as represented by IntDef {@link NetworkType}. + * @return Returns the Builder object. + */ + @NonNull + public Builder setHostNetworkType(@NetworkType int networkType) { + mNetworkType = networkType; + return this; + } + + /** + * Sets the display name of the network the remote device is connected to. + * + * @param networkName Network display name. (e.g. "Google Fi", "Hotel WiFi", "Ethernet") + * @return Returns the Builder object. + */ + @NonNull + public Builder setNetworkName(@NonNull String networkName) { + mNetworkName = networkName; + return this; + } + + /** + * Sets the hotspot SSID being broadcast by the remote device, or null if hotspot is off. + * + * @param hotspotSsid The SSID of the hotspot. Surrounded by double quotes if UTF-8. + * @return Returns the Builder object. + */ + @NonNull + public Builder setHotspotSsid(@NonNull String hotspotSsid) { + mHotspotSsid = hotspotSsid; + return this; + } + + /** + * Sets the hotspot BSSID being broadcast by the remote device, or null if hotspot is off. + * + * @param hotspotBssid The BSSID of the hotspot. + * @return Returns the Builder object. + */ + @NonNull + public Builder setHotspotBssid(@NonNull String hotspotBssid) { + mHotspotBssid = hotspotBssid; + return this; + } + + /** + * Adds a security type supported by the hotspot created by the remote device. + * + * @param hotspotSecurityType A security type supported by the hotspot. + * @return Returns the Builder object. + */ + @NonNull + public Builder addHotspotSecurityType(@SecurityType int hotspotSecurityType) { + mHotspotSecurityTypes.add(hotspotSecurityType); + return this; + } + + /** + * Builds the {@link HotspotNetwork} object. + * + * @return Returns the built {@link HotspotNetwork} object. + */ + @NonNull + public HotspotNetwork build() { + return new HotspotNetwork( + mDeviceId, + mNetworkProviderInfo, + mNetworkType, + mNetworkName, + mHotspotSsid, + mHotspotBssid, + mHotspotSecurityTypes); + } + } + + private static void validate(long deviceId, int networkType, String networkName) { + if (deviceId < 0) { + throw new IllegalArgumentException("DeviceId must be set"); + } + if (networkType != NETWORK_TYPE_CELLULAR && networkType != NETWORK_TYPE_WIFI + && networkType != NETWORK_TYPE_ETHERNET && networkType != NETWORK_TYPE_UNKNOWN) { + throw new IllegalArgumentException("Illegal network type"); + } + if (Objects.isNull(networkName)) { + throw new IllegalArgumentException("NetworkName must be set"); + } + } + + private HotspotNetwork( + long deviceId, + NetworkProviderInfo networkProviderInfo, + @NetworkType int networkType, + @NonNull String networkName, + @Nullable String hotspotSsid, + @Nullable String hotspotBssid, + @Nullable @SecurityType ArraySet hotspotSecurityTypes) { + validate(deviceId, + networkType, + networkName); + mDeviceId = deviceId; + mNetworkProviderInfo = networkProviderInfo; + mNetworkType = networkType; + mNetworkName = networkName; + mHotspotSsid = hotspotSsid; + mHotspotBssid = hotspotBssid; + mHotspotSecurityTypes = new ArraySet<>(hotspotSecurityTypes); + } + + /** + * Gets the remote device ID. + * + * @return Returns the locally unique ID for this Hotspot network. + */ + public long getDeviceId() { + return mDeviceId; + } + + /** + * Gets information about the device providing connectivity. + * + * @return Returns the information of the device providing the Hotspot network. + */ + @NonNull + public NetworkProviderInfo getNetworkProviderInfo() { + return mNetworkProviderInfo; + } + + /** + * Gets the network type that the remote device is connected to. + * + * @return Returns the network type as represented by IntDef {@link NetworkType}. + */ + @NetworkType + public int getHostNetworkType() { + return mNetworkType; + } + + /** + * Gets the display name of the network the remote device is connected to. + * + * @return Returns the network display name. (e.g. "Google Fi", "Hotel WiFi", "Ethernet") + */ + @NonNull + public String getNetworkName() { + return mNetworkName; + } + + /** + * Gets the hotspot SSID being broadcast by the remote device, or null if hotspot is off. + * + * @return Returns the SSID of the hotspot. Surrounded by double quotes if UTF-8. + */ + @Nullable + public String getHotspotSsid() { + return mHotspotSsid; + } + + /** + * Gets the hotspot BSSID being broadcast by the remote device, or null if hotspot is off. + * + * @return Returns the BSSID of the hotspot. + */ + @Nullable + public String getHotspotBssid() { + return mHotspotBssid; + } + + /** + * Gets the hotspot security types supported by the remote device. + * + * @return Returns a set of the security types supported by the hotspot. + */ + @NonNull + @SecurityType + public Set getHotspotSecurityTypes() { + return mHotspotSecurityTypes; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof HotspotNetwork)) return false; + HotspotNetwork other = (HotspotNetwork) obj; + return mDeviceId == other.getDeviceId() + && Objects.equals(mNetworkProviderInfo, other.getNetworkProviderInfo()) + && mNetworkType == other.getHostNetworkType() + && Objects.equals(mNetworkName, other.getNetworkName()) + && Objects.equals(mHotspotSsid, other.getHotspotSsid()) + && Objects.equals(mHotspotBssid, other.getHotspotBssid()) + && Objects.equals(mHotspotSecurityTypes, other.getHotspotSecurityTypes()); + } + + @Override + public int hashCode() { + return Objects.hash(mDeviceId, mNetworkProviderInfo, mNetworkName, mHotspotSsid, + mHotspotBssid, mHotspotSecurityTypes); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeLong(mDeviceId); + mNetworkProviderInfo.writeToParcel(dest, flags); + dest.writeInt(mNetworkType); + dest.writeString(mNetworkName); + dest.writeString(mHotspotSsid); + dest.writeString(mHotspotBssid); + dest.writeArraySet(mHotspotSecurityTypes); + } + + /** + * Creates a {@link HotspotNetwork} object from a parcel. + * + * @hide + */ + @NonNull + public static HotspotNetwork readFromParcel(@NonNull Parcel in) { + return new HotspotNetwork(in.readLong(), NetworkProviderInfo.readFromParcel(in), + in.readInt(), in.readString(), in.readString(), in.readString(), + (ArraySet) in.readArraySet(null)); + } + + @NonNull + public static final Creator CREATOR = new Creator<>() { + @Override + public HotspotNetwork createFromParcel(Parcel in) { + return readFromParcel(in); + } + + @Override + public HotspotNetwork[] newArray(int size) { + return new HotspotNetwork[size]; + } + }; + + @Override + public String toString() { + return new StringBuilder("HotspotNetwork[") + .append("deviceId=").append(mDeviceId) + .append(", networkType=").append(mNetworkType) + .append(", networkProviderInfo=").append(mNetworkProviderInfo.toString()) + .append(", networkName=").append(mNetworkName) + .append(", hotspotSsid=").append(mHotspotSsid) + .append(", hotspotBssid=").append(mHotspotBssid) + .append(", hotspotSecurityTypes=").append(mHotspotSecurityTypes.toString()) + .append("]").toString(); + } +} diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetworkConnectionStatus.aidl b/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetworkConnectionStatus.aidl new file mode 100644 index 000000000000..d32d15e7c058 --- /dev/null +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetworkConnectionStatus.aidl @@ -0,0 +1,19 @@ +/* + * 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; + +parcelable HotspotNetworkConnectionStatus; diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetworkConnectionStatus.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetworkConnectionStatus.java new file mode 100644 index 000000000000..7a5022329c98 --- /dev/null +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/HotspotNetworkConnectionStatus.java @@ -0,0 +1,261 @@ +/* + * 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 android.annotation.IntDef; +import android.annotation.NonNull; +import android.annotation.SystemApi; +import android.os.Bundle; +import android.os.Parcel; +import android.os.Parcelable; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.util.Objects; + +/** + * The status of a connection to a hotspot network after the client called + * {@link SharedConnectivityManager#connectHotspotNetwork}. + * + * @hide + */ +@SystemApi +public final class HotspotNetworkConnectionStatus implements Parcelable { + + /** + * Connection status is unknown. + */ + public static final int CONNECTION_STATUS_UNKNOWN = 0; + + /** + * The connection is being initiated. + */ + public static final int CONNECTION_STATUS_ENABLING_HOTSPOT = 1; + + /** + * Device providing the hotspot failed to initiate it. + */ + public static final int CONNECTION_STATUS_UNKNOWN_ERROR = 2; + + /** + * Failed to provision tethering. + */ + public static final int CONNECTION_STATUS_PROVISIONING_FAILED = 3; + + /** + * Timeout while trying to provision tethering. + */ + public static final int CONNECTION_STATUS_TETHERING_TIMEOUT = 4; + + /** + * Device doesn't support tethering. + */ + public static final int CONNECTION_STATUS_TETHERING_UNSUPPORTED = 5; + + /** + * Device has no cell data. + */ + public static final int CONNECTION_STATUS_NO_CELL_DATA = 6; + + /** + * Device failed to enable hotspot + */ + public static final int CONNECTION_STATUS_ENABLING_HOTSPOT_FAILED = 7; + + /** + * Timeout while trying to enable hotspot + */ + public static final int CONNECTION_STATUS_ENABLING_HOTSPOT_TIMEOUT = 8; + + /** + * Failed to connect to hotspot + */ + public static final int CONNECTION_STATUS_CONNECT_TO_HOTSPOT_FAILED = 9; + + /** + * @hide + */ + @Retention(RetentionPolicy.SOURCE) + @IntDef({ + CONNECTION_STATUS_UNKNOWN, + CONNECTION_STATUS_ENABLING_HOTSPOT, + CONNECTION_STATUS_UNKNOWN_ERROR, + CONNECTION_STATUS_PROVISIONING_FAILED, + CONNECTION_STATUS_TETHERING_TIMEOUT, + CONNECTION_STATUS_TETHERING_UNSUPPORTED, + CONNECTION_STATUS_NO_CELL_DATA, + CONNECTION_STATUS_ENABLING_HOTSPOT_FAILED, + CONNECTION_STATUS_ENABLING_HOTSPOT_TIMEOUT, + CONNECTION_STATUS_CONNECT_TO_HOTSPOT_FAILED, + }) + public @interface ConnectionStatus { + } + + @ConnectionStatus + private final int mStatus; + private final HotspotNetwork mHotspotNetwork; + private final Bundle mExtras; + + /** + * Builder class for {@link HotspotNetworkConnectionStatus}. + */ + public static final class Builder { + @ConnectionStatus + private int mStatus; + private HotspotNetwork mHotspotNetwork; + private Bundle mExtras; + + /** + * Sets the status of the connection + * + * @return Returns the Builder object. + */ + @NonNull + public Builder setStatus(@ConnectionStatus int status) { + mStatus = status; + return this; + } + + /** + * Sets the {@link HotspotNetwork} object of the connection. + * + * @return Returns the Builder object. + */ + @NonNull + public Builder setHotspotNetwork(@NonNull HotspotNetwork hotspotNetwork) { + mHotspotNetwork = hotspotNetwork; + 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 HotspotNetworkConnectionStatus} object. + * + * @return Returns the built {@link HotspotNetworkConnectionStatus} object. + */ + @NonNull + public HotspotNetworkConnectionStatus build() { + return new HotspotNetworkConnectionStatus(mStatus, mHotspotNetwork, mExtras); + } + } + + private HotspotNetworkConnectionStatus(@ConnectionStatus int status, + HotspotNetwork hotspotNetwork, + Bundle extras) { + mStatus = status; + mHotspotNetwork = hotspotNetwork; + mExtras = extras; + } + + /** + * Gets the status of the connection + * + * @return Returns true for enabled, false otherwise. + */ + @ConnectionStatus + public int getStatus() { + return mStatus; + } + + /** + * Gets the {@link HotspotNetwork} object of the connection. + * + * @return Returns a HotspotNetwork object. + */ + @NonNull + public HotspotNetwork getHotspotNetwork() { + return mHotspotNetwork; + } + + /** + * Gets the extras Bundle. + * + * @return Returns a Bundle object. + */ + @NonNull + public Bundle getExtras() { + return mExtras; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof HotspotNetworkConnectionStatus)) return false; + HotspotNetworkConnectionStatus other = (HotspotNetworkConnectionStatus) obj; + return mStatus == other.getStatus() + && Objects.equals(mHotspotNetwork, other.getHotspotNetwork()); + } + + @Override + public int hashCode() { + return Objects.hash(mStatus, mHotspotNetwork); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeInt(mStatus); + mHotspotNetwork.writeToParcel(dest, flags); + dest.writeBundle(mExtras); + } + + /** + * Creates a {@link HotspotNetworkConnectionStatus} object from a parcel. + * + * @hide + */ + @NonNull + public static HotspotNetworkConnectionStatus readFromParcel(@NonNull Parcel in) { + return new HotspotNetworkConnectionStatus(in.readInt(), + HotspotNetwork.readFromParcel(in), in.readBundle()); + } + + @NonNull + public static final Creator CREATOR = new Creator<>() { + @Override + public HotspotNetworkConnectionStatus createFromParcel(Parcel in) { + return readFromParcel(in); + } + + @Override + public HotspotNetworkConnectionStatus[] newArray(int size) { + return new HotspotNetworkConnectionStatus[size]; + } + }; + + @Override + public String toString() { + return new StringBuilder("HotspotNetworkConnectionStatus[") + .append("status=").append(mStatus) + .append("hotspot network=").append(mHotspotNetwork.toString()) + .append("extras=").append(mExtras.toString()) + .append("]").toString(); + } +} 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 fe23caae7f03..d33e08feacc5 100644 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetwork.java +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetwork.java @@ -69,7 +69,7 @@ public final class KnownNetwork implements Parcelable { @NetworkSource private final int mNetworkSource; private final String mSsid; @SecurityType private final ArraySet mSecurityTypes; - private final DeviceInfo mDeviceInfo; + private final NetworkProviderInfo mNetworkProviderInfo; /** * Builder class for {@link KnownNetwork}. @@ -78,7 +78,7 @@ public final class KnownNetwork implements Parcelable { @NetworkSource private int mNetworkSource = -1; private String mSsid; @SecurityType private final ArraySet mSecurityTypes = new ArraySet<>(); - private android.net.wifi.sharedconnectivity.app.DeviceInfo mDeviceInfo; + private NetworkProviderInfo mNetworkProviderInfo; /** * Sets the indicated source of the known network. @@ -120,12 +120,12 @@ public final class KnownNetwork implements Parcelable { * Sets the device information of the device providing connectivity. * Must be set if network source is {@link KnownNetwork#NETWORK_SOURCE_NEARBY_SELF}. * - * @param deviceInfo The device information object. + * @param networkProviderInfo The device information object. * @return Returns the Builder object. */ @NonNull - public Builder setDeviceInfo(@Nullable DeviceInfo deviceInfo) { - mDeviceInfo = deviceInfo; + public Builder setNetworkProviderInfo(@Nullable NetworkProviderInfo networkProviderInfo) { + mNetworkProviderInfo = networkProviderInfo; return this; } @@ -140,12 +140,12 @@ public final class KnownNetwork implements Parcelable { mNetworkSource, mSsid, mSecurityTypes, - mDeviceInfo); + mNetworkProviderInfo); } } private static void validate(int networkSource, String ssid, Set securityTypes, - DeviceInfo deviceInfo) { + NetworkProviderInfo networkProviderInfo) { if (networkSource != NETWORK_SOURCE_UNKNOWN && networkSource != NETWORK_SOURCE_CLOUD_SELF && networkSource != NETWORK_SOURCE_NEARBY_SELF) { @@ -157,7 +157,7 @@ public final class KnownNetwork implements Parcelable { if (securityTypes.isEmpty()) { throw new IllegalArgumentException("SecurityTypes must be set"); } - if (networkSource == NETWORK_SOURCE_NEARBY_SELF && deviceInfo == null) { + if (networkSource == NETWORK_SOURCE_NEARBY_SELF && networkProviderInfo == null) { throw new IllegalArgumentException("Device info must be provided when network source" + " is NETWORK_SOURCE_NEARBY_SELF"); } @@ -167,12 +167,12 @@ public final class KnownNetwork implements Parcelable { @NetworkSource int networkSource, @NonNull String ssid, @NonNull @SecurityType ArraySet securityTypes, - @Nullable DeviceInfo deviceInfo) { - validate(networkSource, ssid, securityTypes, deviceInfo); + @Nullable NetworkProviderInfo networkProviderInfo) { + validate(networkSource, ssid, securityTypes, networkProviderInfo); mNetworkSource = networkSource; mSsid = ssid; mSecurityTypes = new ArraySet<>(securityTypes); - mDeviceInfo = deviceInfo; + mNetworkProviderInfo = networkProviderInfo; } /** @@ -213,8 +213,8 @@ public final class KnownNetwork implements Parcelable { * network source is cloud or unknown. */ @Nullable - public DeviceInfo getDeviceInfo() { - return mDeviceInfo; + public NetworkProviderInfo getNetworkProviderInfo() { + return mNetworkProviderInfo; } @Override @@ -224,12 +224,12 @@ public final class KnownNetwork implements Parcelable { return mNetworkSource == other.getNetworkSource() && Objects.equals(mSsid, other.getSsid()) && Objects.equals(mSecurityTypes, other.getSecurityTypes()) - && Objects.equals(mDeviceInfo, other.getDeviceInfo()); + && Objects.equals(mNetworkProviderInfo, other.getNetworkProviderInfo()); } @Override public int hashCode() { - return Objects.hash(mNetworkSource, mSsid, mSecurityTypes, mDeviceInfo); + return Objects.hash(mNetworkSource, mSsid, mSecurityTypes, mNetworkProviderInfo); } @Override @@ -242,7 +242,7 @@ public final class KnownNetwork implements Parcelable { dest.writeInt(mNetworkSource); dest.writeString(mSsid); dest.writeArraySet(mSecurityTypes); - mDeviceInfo.writeToParcel(dest, flags); + mNetworkProviderInfo.writeToParcel(dest, flags); } /** @@ -254,7 +254,7 @@ public final class KnownNetwork implements Parcelable { public static KnownNetwork readFromParcel(@NonNull Parcel in) { return new KnownNetwork(in.readInt(), in.readString(), (ArraySet) in.readArraySet(null), - DeviceInfo.readFromParcel(in)); + NetworkProviderInfo.readFromParcel(in)); } @NonNull @@ -276,7 +276,7 @@ public final class KnownNetwork implements Parcelable { .append("NetworkSource=").append(mNetworkSource) .append(", ssid=").append(mSsid) .append(", securityTypes=").append(mSecurityTypes.toString()) - .append(", deviceInfo=").append(mDeviceInfo.toString()) + .append(", networkProviderInfo=").append(mNetworkProviderInfo.toString()) .append("]").toString(); } } diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/NetworkProviderInfo.aidl b/wifi/java/src/android/net/wifi/sharedconnectivity/app/NetworkProviderInfo.aidl new file mode 100644 index 000000000000..f3cbbc2963a3 --- /dev/null +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/NetworkProviderInfo.aidl @@ -0,0 +1,19 @@ +/* + * 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; + +parcelable NetworkProviderInfo; \ No newline at end of file diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/NetworkProviderInfo.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/NetworkProviderInfo.java new file mode 100644 index 000000000000..a436571cb2a1 --- /dev/null +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/NetworkProviderInfo.java @@ -0,0 +1,320 @@ +/* + * 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 android.annotation.IntDef; +import android.annotation.IntRange; +import android.annotation.NonNull; +import android.annotation.SystemApi; +import android.net.wifi.sharedconnectivity.service.SharedConnectivityService; +import android.os.Parcel; +import android.os.Parcelable; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.util.Objects; + +/** + * A data class representing a device providing connectivity. + * This class is used in IPC calls between the implementer of {@link SharedConnectivityService} and + * the consumers of {@link com.android.wifitrackerlib}. + * + * @hide + */ +@SystemApi +public final class NetworkProviderInfo implements Parcelable { + + /** + * Device type providing connectivity is unknown. + */ + public static final int DEVICE_TYPE_UNKNOWN = 0; + + /** + * Device providing connectivity is a mobile phone. + */ + public static final int DEVICE_TYPE_PHONE = 1; + + /** + * Device providing connectivity is a tablet. + */ + public static final int DEVICE_TYPE_TABLET = 2; + + /** + * Device providing connectivity is a laptop. + */ + public static final int DEVICE_TYPE_LAPTOP = 3; + + /** + * Device providing connectivity is a watch. + */ + public static final int DEVICE_TYPE_WATCH = 4; + + /** + * Device providing connectivity is a watch. + */ + public static final int DEVICE_TYPE_AUTO = 5; + + /** + * @hide + */ + @Retention(RetentionPolicy.SOURCE) + @IntDef({ + DEVICE_TYPE_UNKNOWN, + DEVICE_TYPE_PHONE, + DEVICE_TYPE_TABLET, + DEVICE_TYPE_LAPTOP, + DEVICE_TYPE_WATCH, + DEVICE_TYPE_AUTO + }) + public @interface DeviceType {} + + @DeviceType private final int mDeviceType; + private final String mDeviceName; + private final String mModelName; + private final int mBatteryPercentage; + private final int mConnectionStrength; + + /** + * Builder class for {@link NetworkProviderInfo}. + */ + public static final class Builder { + private int mDeviceType; + private String mDeviceName; + private String mModelName; + private int mBatteryPercentage; + private int mConnectionStrength; + + public Builder() {} + + /** + * Sets the device type that provides connectivity. + * + * @param deviceType Device type as represented by IntDef {@link DeviceType}. + * @return Returns the Builder object. + */ + @NonNull + public Builder setDeviceType(@DeviceType int deviceType) { + mDeviceType = deviceType; + return this; + } + + /** + * Sets the device name of the remote device. + * + * @param deviceName The user configurable device name. + * @return Returns the Builder object. + */ + @NonNull + public Builder setDeviceName(@NonNull String deviceName) { + mDeviceName = deviceName; + return this; + } + + /** + * Sets the model name of the remote device. + * + * @param modelName The OEM configured name for the device model. + * @return Returns the Builder object. + */ + @NonNull + public Builder setModelName(@NonNull String modelName) { + mModelName = modelName; + return this; + } + + /** + * Sets the battery charge percentage of the remote device. + * + * @param batteryPercentage The battery charge percentage in the range 0 to 100. + * @return Returns the Builder object. + */ + @NonNull + public Builder setBatteryPercentage(@IntRange(from = 0, to = 100) int batteryPercentage) { + mBatteryPercentage = batteryPercentage; + return this; + } + + /** + * Sets the displayed connection strength of the remote device to the internet. + * + * @param connectionStrength Connection strength in range 0 to 3. + * @return Returns the Builder object. + */ + @NonNull + public Builder setConnectionStrength(@IntRange(from = 0, to = 3) int connectionStrength) { + mConnectionStrength = connectionStrength; + return this; + } + + /** + * Builds the {@link NetworkProviderInfo} object. + * + * @return Returns the built {@link NetworkProviderInfo} object. + */ + @NonNull + public NetworkProviderInfo build() { + return new NetworkProviderInfo(mDeviceType, mDeviceName, mModelName, mBatteryPercentage, + mConnectionStrength); + } + } + + private static void validate(int deviceType, String deviceName, String modelName, + int batteryPercentage, int connectionStrength) { + if (deviceType != DEVICE_TYPE_UNKNOWN && deviceType != DEVICE_TYPE_PHONE + && deviceType != DEVICE_TYPE_TABLET && deviceType != DEVICE_TYPE_LAPTOP + && deviceType != DEVICE_TYPE_WATCH && deviceType != DEVICE_TYPE_AUTO) { + throw new IllegalArgumentException("Illegal device type"); + } + if (Objects.isNull(deviceName)) { + throw new IllegalArgumentException("DeviceName must be set"); + } + if (Objects.isNull(modelName)) { + throw new IllegalArgumentException("ModelName must be set"); + } + if (batteryPercentage < 0 || batteryPercentage > 100) { + throw new IllegalArgumentException("BatteryPercentage must be in range 0-100"); + } + if (connectionStrength < 0 || connectionStrength > 3) { + throw new IllegalArgumentException("ConnectionStrength must be in range 0-3"); + } + } + + private NetworkProviderInfo(@DeviceType int deviceType, @NonNull String deviceName, + @NonNull String modelName, int batteryPercentage, int connectionStrength) { + validate(deviceType, deviceName, modelName, batteryPercentage, connectionStrength); + mDeviceType = deviceType; + mDeviceName = deviceName; + mModelName = modelName; + mBatteryPercentage = batteryPercentage; + mConnectionStrength = connectionStrength; + } + + /** + * Gets the device type that provides connectivity. + * + * @return Returns the device type as represented by IntDef {@link DeviceType}. + */ + @DeviceType + public int getDeviceType() { + return mDeviceType; + } + + /** + * Gets the device name of the remote device. + * + * @return Returns the user configurable device name. + */ + @NonNull + public String getDeviceName() { + return mDeviceName; + } + + /** + * Gets the model name of the remote device. + * + * @return Returns the OEM configured name for the device model. + */ + @NonNull + public String getModelName() { + return mModelName; + } + + /** + * Gets the battery charge percentage of the remote device. + * + * @return Returns the battery charge percentage in the range 0 to 100. + */ + @IntRange(from = 0, to = 100) + public int getBatteryPercentage() { + return mBatteryPercentage; + } + + /** + * Gets the displayed connection strength of the remote device to the internet. + * + * @return Returns the connection strength in range 0 to 3. + */ + @IntRange(from = 0, to = 3) + public int getConnectionStrength() { + return mConnectionStrength; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof NetworkProviderInfo)) return false; + NetworkProviderInfo other = (NetworkProviderInfo) obj; + return mDeviceType == other.getDeviceType() + && Objects.equals(mDeviceName, other.mDeviceName) + && Objects.equals(mModelName, other.mModelName) + && mBatteryPercentage == other.mBatteryPercentage + && mConnectionStrength == other.mConnectionStrength; + } + + @Override + public int hashCode() { + return Objects.hash(mDeviceType, mDeviceName, mModelName, mBatteryPercentage, + mConnectionStrength); + } + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeInt(mDeviceType); + dest.writeString(mDeviceName); + dest.writeString(mModelName); + dest.writeInt(mBatteryPercentage); + dest.writeInt(mConnectionStrength); + } + + @Override + public int describeContents() { + return 0; + } + + /** + * Creates a {@link NetworkProviderInfo} object from a parcel. + * + * @hide + */ + @NonNull + public static NetworkProviderInfo readFromParcel(@NonNull Parcel in) { + return new NetworkProviderInfo(in.readInt(), in.readString(), in.readString(), in.readInt(), + in.readInt()); + } + + @NonNull + public static final Creator CREATOR = new Creator() { + @Override + public NetworkProviderInfo createFromParcel(Parcel in) { + return readFromParcel(in); + } + + @Override + public NetworkProviderInfo[] newArray(int size) { + return new NetworkProviderInfo[size]; + } + }; + + @Override + public String toString() { + return new StringBuilder("NetworkProviderInfo[") + .append("deviceType=").append(mDeviceType) + .append(", deviceName=").append(mDeviceName) + .append(", modelName=").append(mModelName) + .append(", batteryPercentage=").append(mBatteryPercentage) + .append(", connectionStrength=").append(mConnectionStrength) + .append("]").toString(); + } +} diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityClientCallback.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityClientCallback.java index d2b9be783bca..eb04df64d6d0 100644 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityClientCallback.java +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityClientCallback.java @@ -32,14 +32,16 @@ import java.util.List; public interface SharedConnectivityClientCallback { /** * This method is being called by {@link SharedConnectivityService} to notify of a change in the - * list of available Tether Networks. - * @param networks Updated Tether Network list. + * list of available Hotspot Networks. + * + * @param networks Updated Hotspot Network list. */ - void onTetherNetworksUpdated(@NonNull List networks); + void onHotspotNetworksUpdated(@NonNull List networks); /** * This method is being called by {@link SharedConnectivityService} to notify of a change in the * list of available Known Networks. + * * @param networks Updated Known Network list. */ void onKnownNetworksUpdated(@NonNull List networks); @@ -47,20 +49,23 @@ public interface SharedConnectivityClientCallback { /** * This method is being called by {@link SharedConnectivityService} to notify of a change in the * state of share connectivity settings. + * * @param state The new state. */ void onSharedConnectivitySettingsChanged(@NonNull SharedConnectivitySettingsState state); /** * This method is being called by {@link SharedConnectivityService} to notify of a change in the - * status of the current tether network connection. + * status of the current hotspot network connection. + * * @param status The new status. */ - void onTetherNetworkConnectionStatusChanged(@NonNull TetherNetworkConnectionStatus status); + void onHotspotNetworkConnectionStatusChanged(@NonNull HotspotNetworkConnectionStatus status); /** * This method is being called by {@link SharedConnectivityService} to notify of a change in the * status of the current known network connection. + * * @param status The new status. */ void onKnownNetworkConnectionStatusChanged(@NonNull KnownNetworkConnectionStatus status); diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityManager.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityManager.java index c09f85b39ee4..684b385d60e8 100644 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityManager.java +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityManager.java @@ -49,7 +49,7 @@ import java.util.concurrent.Executor; * This class is the library used by consumers of Shared Connectivity data to bind to the service, * receive callbacks from, and send user actions to the service. * - * The methods {@link #connectTetherNetwork}, {@link #disconnectTetherNetwork}, + * The methods {@link #connectHotspotNetwork}, {@link #disconnectHotspotNetwork}, * {@link #connectKnownNetwork} and {@link #forgetKnownNetwork} are not valid and will return false * if not called between {@link SharedConnectivityClientCallback#onServiceConnected()} * and {@link SharedConnectivityClientCallback#onServiceDisconnected()} or if @@ -74,12 +74,11 @@ public class SharedConnectivityManager { mCallback = callback; } - @Override - public void onTetherNetworksUpdated(@NonNull List networks) { + public void onHotspotNetworksUpdated(@NonNull List networks) { if (mCallback != null) { final long token = Binder.clearCallingIdentity(); try { - mExecutor.execute(() -> mCallback.onTetherNetworksUpdated(networks)); + mExecutor.execute(() -> mCallback.onHotspotNetworksUpdated(networks)); } finally { Binder.restoreCallingIdentity(token); } @@ -111,14 +110,13 @@ public class SharedConnectivityManager { } } - @Override - public void onTetherNetworkConnectionStatusChanged( - @NonNull TetherNetworkConnectionStatus status) { + public void onHotspotNetworkConnectionStatusChanged( + @NonNull HotspotNetworkConnectionStatus status) { if (mCallback != null) { final long token = Binder.clearCallingIdentity(); try { mExecutor.execute(() -> - mCallback.onTetherNetworkConnectionStatusChanged(status)); + mCallback.onHotspotNetworkConnectionStatusChanged(status)); } finally { Binder.restoreCallingIdentity(token); } @@ -259,8 +257,8 @@ public class SharedConnectivityManager { } /** - * Registers a callback for receiving updates to the list of Tether Networks, Known Networks, - * shared connectivity settings state, tether network connection status and known network + * Registers a callback for receiving updates to the list of Hotspot Networks, Known Networks, + * shared connectivity settings state, hotspot network connection status and known network * connection status. * The {@link SharedConnectivityClientCallback#onRegisterCallbackFailed} will be called if the * registration failed. @@ -331,26 +329,26 @@ public class SharedConnectivityManager { /** * Send command to the implementation of {@link SharedConnectivityService} requesting connection - * to the specified Tether Network. + * to the specified Hotspot Network. * - * @param network {@link TetherNetwork} object representing the network the user has requested + * @param network {@link HotspotNetwork} object representing the network the user has requested * a connection to. * @return Returns true if the service received the command. Does not guarantee that the - * connection was successful. + * connection was successful. */ @RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) - public boolean connectTetherNetwork(@NonNull TetherNetwork network) { - Objects.requireNonNull(network, "Tether network cannot be null"); + public boolean connectHotspotNetwork(@NonNull HotspotNetwork network) { + Objects.requireNonNull(network, "Hotspot network cannot be null"); if (mService == null) { return false; } try { - mService.connectTetherNetwork(network); + mService.connectHotspotNetwork(network); } catch (RemoteException e) { - Log.e(TAG, "Exception in connectTetherNetwork", e); + Log.e(TAG, "Exception in connectHotspotNetwork", e); return false; } return true; @@ -358,24 +356,24 @@ public class SharedConnectivityManager { /** * Send command to the implementation of {@link SharedConnectivityService} requesting - * disconnection from the active Tether Network. + * disconnection from the active Hotspot Network. * - * @param network {@link TetherNetwork} object representing the network the user has requested + * @param network {@link HotspotNetwork} object representing the network the user has requested * to disconnect from. * @return Returns true if the service received the command. Does not guarantee that the - * disconnection was successful. + * disconnection was successful. */ @RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) - public boolean disconnectTetherNetwork(@NonNull TetherNetwork network) { + public boolean disconnectHotspotNetwork(@NonNull HotspotNetwork network) { if (mService == null) { return false; } try { - mService.disconnectTetherNetwork(network); + mService.disconnectHotspotNetwork(network); } catch (RemoteException e) { - Log.e(TAG, "Exception in disconnectTetherNetwork", e); + Log.e(TAG, "Exception in disconnectHotspotNetwork", e); return false; } return true; @@ -388,7 +386,7 @@ public class SharedConnectivityManager { * @param network {@link KnownNetwork} object representing the network the user has requested * a connection to. * @return Returns true if the service received the command. Does not guarantee that the - * connection was successful. + * connection was successful. */ @RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) @@ -413,7 +411,7 @@ public class SharedConnectivityManager { * the specified Known Network from the list of Known Networks. * * @return Returns true if the service received the command. Does not guarantee that the - * forget action was successful. + * forget action was successful. */ @RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) @@ -434,22 +432,22 @@ public class SharedConnectivityManager { } /** - * Gets the list of tether networks the user can select to connect to. + * Gets the list of hotspot networks the user can select to connect to. * - * @return Returns a {@link List} of {@link TetherNetwork} objects, empty list on failure. + * @return Returns a {@link List} of {@link HotspotNetwork} objects, empty list on failure. */ @RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) @NonNull - public List getTetherNetworks() { + public List getHotspotNetworks() { if (mService == null) { return List.of(); } try { - return mService.getTetherNetworks(); + return mService.getHotspotNetworks(); } catch (RemoteException e) { - Log.e(TAG, "Exception in getTetherNetworks", e); + Log.e(TAG, "Exception in getHotspotNetworks", e); } return List.of(); } @@ -498,24 +496,24 @@ public class SharedConnectivityManager { } /** - * Gets the connection status of the tether network the user selected to connect to. + * Gets the connection status of the hotspot network the user selected to connect to. * - * @return Returns a {@link TetherNetworkConnectionStatus} object with the connection status, + * @return Returns a {@link HotspotNetworkConnectionStatus} object with the connection status, * null on failure. If no connection is active the status will be - * {@link TetherNetworkConnectionStatus#CONNECTION_STATUS_UNKNOWN}. + * {@link HotspotNetworkConnectionStatus#CONNECTION_STATUS_UNKNOWN}. */ @RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) @Nullable - public TetherNetworkConnectionStatus getTetherNetworkConnectionStatus() { + public HotspotNetworkConnectionStatus getHotspotNetworkConnectionStatus() { if (mService == null) { return null; } try { - return mService.getTetherNetworkConnectionStatus(); + return mService.getHotspotNetworkConnectionStatus(); } catch (RemoteException e) { - Log.e(TAG, "Exception in getTetherNetworkConnectionStatus", e); + Log.e(TAG, "Exception in getHotspotNetworkConnectionStatus", e); } return null; } diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetwork.aidl b/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetwork.aidl deleted file mode 100644 index 6cc4cfe7dce5..000000000000 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetwork.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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; - -parcelable TetherNetwork; diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetwork.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetwork.java deleted file mode 100644 index 7b591d3a45bd..000000000000 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetwork.java +++ /dev/null @@ -1,374 +0,0 @@ -/* - * 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.WifiAnnotations.SecurityType; - -import android.annotation.IntDef; -import android.annotation.NonNull; -import android.annotation.Nullable; -import android.annotation.SystemApi; -import android.net.wifi.sharedconnectivity.service.SharedConnectivityService; -import android.os.Parcel; -import android.os.Parcelable; -import android.util.ArraySet; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.util.Objects; -import java.util.Set; - -/** - * A data class representing an Instant Tether network. - * This class is used in IPC calls between the implementer of {@link SharedConnectivityService} and - * the consumers of {@link com.android.wifitrackerlib}. - * - * @hide - */ -@SystemApi -public final class TetherNetwork implements Parcelable { - /** - * Remote device is connected to the internet via an unknown connection. - */ - public static final int NETWORK_TYPE_UNKNOWN = 0; - - /** - * Remote device is connected to the internet via a cellular connection. - */ - public static final int NETWORK_TYPE_CELLULAR = 1; - - /** - * Remote device is connected to the internet via a Wi-Fi connection. - */ - public static final int NETWORK_TYPE_WIFI = 2; - - /** - * Remote device is connected to the internet via an ethernet connection. - */ - public static final int NETWORK_TYPE_ETHERNET = 3; - - /** - * @hide - */ - @Retention(RetentionPolicy.SOURCE) - @IntDef({ - NETWORK_TYPE_UNKNOWN, - NETWORK_TYPE_CELLULAR, - NETWORK_TYPE_WIFI, - NETWORK_TYPE_ETHERNET - }) - public @interface NetworkType {} - - private final long mDeviceId; - private final DeviceInfo mDeviceInfo; - @NetworkType private final int mNetworkType; - private final String mNetworkName; - @Nullable private final String mHotspotSsid; - @Nullable private final String mHotspotBssid; - @Nullable @SecurityType private final ArraySet mHotspotSecurityTypes; - - /** - * Builder class for {@link TetherNetwork}. - */ - public static final class Builder { - private long mDeviceId = -1; - private DeviceInfo mDeviceInfo; - @NetworkType private int mNetworkType; - private String mNetworkName; - @Nullable private String mHotspotSsid; - @Nullable private String mHotspotBssid; - @Nullable @SecurityType private final ArraySet mHotspotSecurityTypes = - new ArraySet<>(); - - /** - * Set the remote device ID. - * - * @param deviceId Locally unique ID for this Instant Tether network. - * @return Returns the Builder object. - */ - @NonNull - public Builder setDeviceId(long deviceId) { - mDeviceId = deviceId; - return this; - } - - /** - * Sets information about the device providing connectivity. - * - * @param deviceInfo The device information object. - * @return Returns the Builder object. - */ - @NonNull - public Builder setDeviceInfo(@NonNull DeviceInfo deviceInfo) { - mDeviceInfo = deviceInfo; - return this; - } - - /** - * Sets the network type that the remote device is connected to. - * - * @param networkType Network type as represented by IntDef {@link NetworkType}. - * @return Returns the Builder object. - */ - @NonNull - public Builder setNetworkType(@NetworkType int networkType) { - mNetworkType = networkType; - return this; - } - - /** - * Sets the display name of the network the remote device is connected to. - * - * @param networkName Network display name. (e.g. "Google Fi", "Hotel WiFi", "Ethernet") - * @return Returns the Builder object. - */ - @NonNull - public Builder setNetworkName(@NonNull String networkName) { - mNetworkName = networkName; - return this; - } - - /** - * Sets the hotspot SSID being broadcast by the remote device, or null if hotspot is off. - * - * @param hotspotSsid The SSID of the hotspot. Surrounded by double quotes if UTF-8. - * @return Returns the Builder object. - */ - @NonNull - public Builder setHotspotSsid(@NonNull String hotspotSsid) { - mHotspotSsid = hotspotSsid; - return this; - } - - /** - * Sets the hotspot BSSID being broadcast by the remote device, or null if hotspot is off. - * - * @param hotspotBssid The BSSID of the hotspot. - * @return Returns the Builder object. - */ - @NonNull - public Builder setHotspotBssid(@NonNull String hotspotBssid) { - mHotspotBssid = hotspotBssid; - return this; - } - - /** - * Adds a security type supported by the hotspot created by the remote device. - * - * @param hotspotSecurityType A security type supported by the hotspot. - * @return Returns the Builder object. - */ - @NonNull - public Builder addHotspotSecurityType(@SecurityType int hotspotSecurityType) { - mHotspotSecurityTypes.add(hotspotSecurityType); - return this; - } - - /** - * Builds the {@link TetherNetwork} object. - * - * @return Returns the built {@link TetherNetwork} object. - */ - @NonNull - public TetherNetwork build() { - return new TetherNetwork( - mDeviceId, - mDeviceInfo, - mNetworkType, - mNetworkName, - mHotspotSsid, - mHotspotBssid, - mHotspotSecurityTypes); - } - } - - private static void validate(long deviceId, int networkType, String networkName) { - if (deviceId < 0) { - throw new IllegalArgumentException("DeviceId must be set"); - } - if (networkType != NETWORK_TYPE_CELLULAR && networkType != NETWORK_TYPE_WIFI - && networkType != NETWORK_TYPE_ETHERNET && networkType != NETWORK_TYPE_UNKNOWN) { - throw new IllegalArgumentException("Illegal network type"); - } - if (Objects.isNull(networkName)) { - throw new IllegalArgumentException("NetworkName must be set"); - } - } - - private TetherNetwork( - long deviceId, - DeviceInfo deviceInfo, - @NetworkType int networkType, - @NonNull String networkName, - @Nullable String hotspotSsid, - @Nullable String hotspotBssid, - @Nullable @SecurityType ArraySet hotspotSecurityTypes) { - validate(deviceId, - networkType, - networkName); - mDeviceId = deviceId; - mDeviceInfo = deviceInfo; - mNetworkType = networkType; - mNetworkName = networkName; - mHotspotSsid = hotspotSsid; - mHotspotBssid = hotspotBssid; - mHotspotSecurityTypes = new ArraySet<>(hotspotSecurityTypes); - } - - /** - * Gets the remote device ID. - * - * @return Returns the locally unique ID for this Instant Tether network. - */ - public long getDeviceId() { - return mDeviceId; - } - - /** - * Gets information about the device providing connectivity. - * - * @return Returns the information of the device providing the Instant Tether network. - */ - @NonNull - public DeviceInfo getDeviceInfo() { - return mDeviceInfo; - } - - /** - * Gets the network type that the remote device is connected to. - * - * @return Returns the network type as represented by IntDef {@link NetworkType}. - */ - @NetworkType - public int getNetworkType() { - return mNetworkType; - } - - /** - * Gets the display name of the network the remote device is connected to. - * - * @return Returns the network display name. (e.g. "Google Fi", "Hotel WiFi", "Ethernet") - */ - @NonNull - public String getNetworkName() { - return mNetworkName; - } - - /** - * Gets the hotspot SSID being broadcast by the remote device, or null if hotspot is off. - * - * @return Returns the SSID of the hotspot. Surrounded by double quotes if UTF-8. - */ - @Nullable - public String getHotspotSsid() { - return mHotspotSsid; - } - - /** - * Gets the hotspot BSSID being broadcast by the remote device, or null if hotspot is off. - * - * @return Returns the BSSID of the hotspot. - */ - @Nullable - public String getHotspotBssid() { - return mHotspotBssid; - } - - /** - * Gets the hotspot security types supported by the remote device. - * - * @return Returns a set of the security types supported by the hotspot. - */ - @NonNull - @SecurityType - public Set getHotspotSecurityTypes() { - return mHotspotSecurityTypes; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof TetherNetwork)) return false; - TetherNetwork other = (TetherNetwork) obj; - return mDeviceId == other.getDeviceId() - && Objects.equals(mDeviceInfo, other.getDeviceInfo()) - && mNetworkType == other.getNetworkType() - && Objects.equals(mNetworkName, other.getNetworkName()) - && Objects.equals(mHotspotSsid, other.getHotspotSsid()) - && Objects.equals(mHotspotBssid, other.getHotspotBssid()) - && Objects.equals(mHotspotSecurityTypes, other.getHotspotSecurityTypes()); - } - - @Override - public int hashCode() { - return Objects.hash(mDeviceId, mDeviceInfo, mNetworkName, mHotspotSsid, mHotspotBssid, - mHotspotSecurityTypes); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(@NonNull Parcel dest, int flags) { - dest.writeLong(mDeviceId); - mDeviceInfo.writeToParcel(dest, flags); - dest.writeInt(mNetworkType); - dest.writeString(mNetworkName); - dest.writeString(mHotspotSsid); - dest.writeString(mHotspotBssid); - dest.writeArraySet(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(), - (ArraySet) in.readArraySet(null)); - } - - @NonNull - public static final Creator CREATOR = new Creator<>() { - @Override - public TetherNetwork createFromParcel(Parcel in) { - return readFromParcel(in); - } - - @Override - public TetherNetwork[] newArray(int size) { - return new TetherNetwork[size]; - } - }; - - @Override - public String toString() { - return new StringBuilder("TetherNetwork[") - .append("deviceId=").append(mDeviceId) - .append(", networkType=").append(mNetworkType) - .append(", deviceInfo=").append(mDeviceInfo.toString()) - .append(", networkName=").append(mNetworkName) - .append(", hotspotSsid=").append(mHotspotSsid) - .append(", hotspotBssid=").append(mHotspotBssid) - .append(", hotspotSecurityTypes=").append(mHotspotSecurityTypes.toString()) - .append("]").toString(); - } -} diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetworkConnectionStatus.aidl b/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetworkConnectionStatus.aidl deleted file mode 100644 index c677a6c508ad..000000000000 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetworkConnectionStatus.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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; - -parcelable TetherNetworkConnectionStatus; diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetworkConnectionStatus.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetworkConnectionStatus.java deleted file mode 100644 index 3cf44ed3ed32..000000000000 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetworkConnectionStatus.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * 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 android.annotation.IntDef; -import android.annotation.NonNull; -import android.annotation.SystemApi; -import android.os.Bundle; -import android.os.Parcel; -import android.os.Parcelable; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.util.Objects; - -/** - * The status of a connection to an instant tether network after the client called - * {@link SharedConnectivityManager#connectTetherNetwork}. - * - * @hide - */ -@SystemApi -public final class TetherNetworkConnectionStatus implements Parcelable { - - /** - * Connection status is unknown. - */ - public static final int CONNECTION_STATUS_UNKNOWN = 0; - - /** - * The connection is being initiated. - */ - public static final int CONNECTION_STATUS_ENABLING_HOTSPOT = 1; - - /** - * Device providing the hotspot failed to initiate it. - */ - public static final int CONNECTION_STATUS_UNKNOWN_ERROR = 2; - - /** - * Failed to provision tethering. - */ - public static final int CONNECTION_STATUS_PROVISIONING_FAILED = 3; - - /** - * Timeout while trying to provision tethering. - */ - public static final int CONNECTION_STATUS_TETHERING_TIMEOUT = 4; - - /** - * Device doesn't support tethering. - */ - public static final int CONNECTION_STATUS_TETHERING_UNSUPPORTED = 5; - - /** - * Device has no cell data. - */ - public static final int CONNECTION_STATUS_NO_CELL_DATA = 6; - - /** - * Device failed to enable hotspot - */ - public static final int CONNECTION_STATUS_ENABLING_HOTSPOT_FAILED = 7; - - /** - * Timeout while trying to enable hotspot - */ - public static final int CONNECTION_STATUS_ENABLING_HOTSPOT_TIMEOUT = 8; - - /** - * Failed to connect to hotspot - */ - public static final int CONNECTION_STATUS_CONNECT_TO_HOTSPOT_FAILED = 9; - - /** - * @hide - */ - @Retention(RetentionPolicy.SOURCE) - @IntDef({ - CONNECTION_STATUS_UNKNOWN, - CONNECTION_STATUS_ENABLING_HOTSPOT, - CONNECTION_STATUS_UNKNOWN_ERROR, - CONNECTION_STATUS_PROVISIONING_FAILED, - CONNECTION_STATUS_TETHERING_TIMEOUT, - CONNECTION_STATUS_TETHERING_UNSUPPORTED, - CONNECTION_STATUS_NO_CELL_DATA, - CONNECTION_STATUS_ENABLING_HOTSPOT_FAILED, - CONNECTION_STATUS_ENABLING_HOTSPOT_TIMEOUT, - CONNECTION_STATUS_CONNECT_TO_HOTSPOT_FAILED, - }) - public @interface ConnectionStatus {} - - @ConnectionStatus private final int mStatus; - private final TetherNetwork mTetherNetwork; - private final Bundle mExtras; - - /** - * Builder class for {@link TetherNetworkConnectionStatus}. - */ - public static final class Builder { - @ConnectionStatus private int mStatus; - private TetherNetwork mTetherNetwork; - private Bundle mExtras; - - public Builder() {} - - /** - * Sets the status of the connection - * - * @return Returns the Builder object. - */ - @NonNull - public Builder setStatus(@ConnectionStatus int status) { - mStatus = status; - 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 - * - * @return Returns the Builder object. - */ - @NonNull - public Builder setExtras(@NonNull Bundle extras) { - mExtras = extras; - return this; - } - - /** - * Builds the {@link TetherNetworkConnectionStatus} object. - * - * @return Returns the built {@link TetherNetworkConnectionStatus} object. - */ - @NonNull - public TetherNetworkConnectionStatus build() { - return new TetherNetworkConnectionStatus(mStatus, mTetherNetwork, mExtras); - } - } - - private TetherNetworkConnectionStatus(@ConnectionStatus int status, TetherNetwork tetherNetwork, - Bundle extras) { - mStatus = status; - mTetherNetwork = tetherNetwork; - mExtras = extras; - } - - /** - * Gets the status of the connection - * - * @return Returns true for enabled, false otherwise. - */ - @ConnectionStatus - public int getStatus() { - 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. - * - * @return Returns a Bundle object. - */ - @NonNull - public Bundle getExtras() { - return mExtras; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof TetherNetworkConnectionStatus)) return false; - TetherNetworkConnectionStatus other = (TetherNetworkConnectionStatus) obj; - return mStatus == other.getStatus() - && Objects.equals(mTetherNetwork, other.getTetherNetwork()); - } - - @Override - public int hashCode() { - return Objects.hash(mStatus, mTetherNetwork); - } - - @Override - public int describeContents() { - return 0; - } - - @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 CREATOR = new Creator<>() { - @Override - public TetherNetworkConnectionStatus createFromParcel(Parcel in) { - return readFromParcel(in); - } - - @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(); - } -} diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/service/ISharedConnectivityCallback.aidl b/wifi/java/src/android/net/wifi/sharedconnectivity/service/ISharedConnectivityCallback.aidl index 6f6f1627c6a5..737aa6d9964c 100644 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/service/ISharedConnectivityCallback.aidl +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/service/ISharedConnectivityCallback.aidl @@ -19,15 +19,15 @@ package android.net.wifi.sharedconnectivity.service; import android.net.wifi.sharedconnectivity.app.KnownNetwork; import android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus; import android.net.wifi.sharedconnectivity.app.SharedConnectivitySettingsState; -import android.net.wifi.sharedconnectivity.app.TetherNetwork; -import android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus; +import android.net.wifi.sharedconnectivity.app.HotspotNetwork; +import android.net.wifi.sharedconnectivity.app.HotspotNetworkConnectionStatus; /* * @hide */ interface ISharedConnectivityCallback { - oneway void onTetherNetworksUpdated(in List networks); - oneway void onTetherNetworkConnectionStatusChanged(in TetherNetworkConnectionStatus status); + oneway void onHotspotNetworksUpdated(in List networks); + oneway void onHotspotNetworkConnectionStatusChanged(in HotspotNetworkConnectionStatus status); oneway void onKnownNetworksUpdated(in List networks); oneway void onKnownNetworkConnectionStatusChanged(in KnownNetworkConnectionStatus status); oneway void onSharedConnectivitySettingsChanged(in SharedConnectivitySettingsState state); diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/service/ISharedConnectivityService.aidl b/wifi/java/src/android/net/wifi/sharedconnectivity/service/ISharedConnectivityService.aidl index 9f33e99ad3d1..c81380df3c79 100644 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/service/ISharedConnectivityService.aidl +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/service/ISharedConnectivityService.aidl @@ -17,10 +17,10 @@ package android.net.wifi.sharedconnectivity.service; import android.net.wifi.sharedconnectivity.app.KnownNetwork; -import android.net.wifi.sharedconnectivity.app.TetherNetwork; +import android.net.wifi.sharedconnectivity.app.HotspotNetwork; import android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus; import android.net.wifi.sharedconnectivity.app.SharedConnectivitySettingsState; -import android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus; +import android.net.wifi.sharedconnectivity.app.HotspotNetworkConnectionStatus; import android.net.wifi.sharedconnectivity.service.ISharedConnectivityCallback; /* @@ -29,13 +29,13 @@ import android.net.wifi.sharedconnectivity.service.ISharedConnectivityCallback; interface ISharedConnectivityService { void registerCallback(in ISharedConnectivityCallback callback); void unregisterCallback(in ISharedConnectivityCallback callback); - void connectTetherNetwork(in TetherNetwork network); - void disconnectTetherNetwork(in TetherNetwork network); + void connectHotspotNetwork(in HotspotNetwork network); + void disconnectHotspotNetwork(in HotspotNetwork network); void connectKnownNetwork(in KnownNetwork network); void forgetKnownNetwork(in KnownNetwork network); - List getTetherNetworks(); + List getHotspotNetworks(); List getKnownNetworks(); SharedConnectivitySettingsState getSettingsState(); - TetherNetworkConnectionStatus getTetherNetworkConnectionStatus(); + HotspotNetworkConnectionStatus getHotspotNetworkConnectionStatus(); KnownNetworkConnectionStatus getKnownNetworkConnectionStatus(); } diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/service/SharedConnectivityService.java b/wifi/java/src/android/net/wifi/sharedconnectivity/service/SharedConnectivityService.java index 4c88c1b269a9..c53da9c15d4d 100644 --- a/wifi/java/src/android/net/wifi/sharedconnectivity/service/SharedConnectivityService.java +++ b/wifi/java/src/android/net/wifi/sharedconnectivity/service/SharedConnectivityService.java @@ -27,12 +27,12 @@ import android.annotation.TestApi; import android.app.Service; import android.content.Intent; import android.content.pm.PackageManager; +import android.net.wifi.sharedconnectivity.app.HotspotNetwork; +import android.net.wifi.sharedconnectivity.app.HotspotNetworkConnectionStatus; import android.net.wifi.sharedconnectivity.app.KnownNetwork; import android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus; import android.net.wifi.sharedconnectivity.app.SharedConnectivityManager; import android.net.wifi.sharedconnectivity.app.SharedConnectivitySettingsState; -import android.net.wifi.sharedconnectivity.app.TetherNetwork; -import android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; @@ -62,14 +62,14 @@ public abstract class SharedConnectivityService extends Service { private Handler mHandler; private final RemoteCallbackList mRemoteCallbackList = new RemoteCallbackList<>(); - private List mTetherNetworks = Collections.emptyList(); + private List mHotspotNetworks = Collections.emptyList(); private List mKnownNetworks = Collections.emptyList(); private SharedConnectivitySettingsState mSettingsState = new SharedConnectivitySettingsState.Builder().setInstantTetherEnabled(false) .setExtras(Bundle.EMPTY).build(); - private TetherNetworkConnectionStatus mTetherNetworkConnectionStatus = - new TetherNetworkConnectionStatus.Builder() - .setStatus(TetherNetworkConnectionStatus.CONNECTION_STATUS_UNKNOWN) + private HotspotNetworkConnectionStatus mHotspotNetworkConnectionStatus = + new HotspotNetworkConnectionStatus.Builder() + .setStatus(HotspotNetworkConnectionStatus.CONNECTION_STATUS_UNKNOWN) .setExtras(Bundle.EMPTY).build(); private KnownNetworkConnectionStatus mKnownNetworkConnectionStatus = new KnownNetworkConnectionStatus.Builder() @@ -84,8 +84,8 @@ public abstract class SharedConnectivityService extends Service { IBinder serviceStub = new ISharedConnectivityService.Stub() { /** - * Registers a callback for receiving updates to the list of Tether Networks, Known - * Networks, shared connectivity settings state, tether network connection status and + * Registers a callback for receiving updates to the list of Hotspot Networks, Known + * Networks, shared connectivity settings state, hotspot network connection status and * known network connection status. * * @param callback The callback of type {@link ISharedConnectivityCallback} to be called @@ -113,29 +113,28 @@ public abstract class SharedConnectivityService extends Service { } /** - * Connects to a tether network. + * Connects to a hotspot network. * * @param network The network to connect to. */ @RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) @Override - public void connectTetherNetwork(TetherNetwork network) { + public void connectHotspotNetwork(HotspotNetwork network) { checkPermissions(); - mHandler.post(() -> onConnectTetherNetwork(network)); + mHandler.post(() -> onConnectHotspotNetwork(network)); } /** - * Disconnects from a previously connected tether network. + * Disconnects from a previously connected hotspot network. * * @param network The network to disconnect from. */ @RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) - @Override - public void disconnectTetherNetwork(TetherNetwork network) { + public void disconnectHotspotNetwork(HotspotNetwork network) { checkPermissions(); - mHandler.post(() -> onDisconnectTetherNetwork(network)); + mHandler.post(() -> onDisconnectHotspotNetwork(network)); } /** @@ -164,16 +163,16 @@ public abstract class SharedConnectivityService extends Service { } /** - * Gets the list of tether networks the user can select to connect to. + * Gets the list of hotspot networks the user can select to connect to. * - * @return Returns a {@link List} of {@link TetherNetwork} objects + * @return Returns a {@link List} of {@link HotspotNetwork} objects */ @RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) @Override - public List getTetherNetworks() { + public List getHotspotNetworks() { checkPermissions(); - return mTetherNetworks; + return mHotspotNetworks; } /** @@ -203,17 +202,17 @@ public abstract class SharedConnectivityService extends Service { } /** - * Gets the connection status of the tether network the user selected to connect to. + * Gets the connection status of the hotspot network the user selected to connect to. * - * @return Returns a {@link TetherNetworkConnectionStatus} object with the connection + * @return Returns a {@link HotspotNetworkConnectionStatus} object with the connection * status. */ @RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) @Override - public TetherNetworkConnectionStatus getTetherNetworkConnectionStatus() { + public HotspotNetworkConnectionStatus getHotspotNetworkConnectionStatus() { checkPermissions(); - return mTetherNetworkConnectionStatus; + return mHotspotNetworkConnectionStatus; } /** @@ -254,7 +253,8 @@ public abstract class SharedConnectivityService extends Service { /** @hide */ @TestApi - public void onBind() {} + public void onBind() { + } private void onRegisterCallback(ISharedConnectivityCallback callback) { mRemoteCallbackList.register(callback); @@ -265,23 +265,23 @@ public abstract class SharedConnectivityService extends Service { } /** - * Implementing application should call this method to provide an up-to-date list of Tether + * Implementing application should call this method to provide an up-to-date list of Hotspot * Networks to be displayed to the user. * * This method updates the cached list and notifies all registered callbacks. Any callbacks that * are inaccessible will be unregistered. * - * @param networks The updated list of {@link TetherNetwork} objects. + * @param networks The updated list of {@link HotspotNetwork} objects. */ - public final void setTetherNetworks(@NonNull List networks) { - mTetherNetworks = networks; + public final void setHotspotNetworks(@NonNull List networks) { + mHotspotNetworks = networks; int count = mRemoteCallbackList.beginBroadcast(); for (int i = 0; i < count; i++) { try { - mRemoteCallbackList.getBroadcastItem(i).onTetherNetworksUpdated(mTetherNetworks); + mRemoteCallbackList.getBroadcastItem(i).onHotspotNetworksUpdated(mHotspotNetworks); } catch (RemoteException e) { - if (DEBUG) Log.w(TAG, "Exception in setTetherNetworks", e); + if (DEBUG) Log.w(TAG, "Exception in setHotspotNetworks", e); } } mRemoteCallbackList.finishBroadcast(); @@ -318,7 +318,7 @@ public abstract class SharedConnectivityService extends Service { * that are inaccessible will be unregistered. * * @param settingsState The updated state {@link SharedConnectivitySettingsState} - * objects. + * objects. */ public final void setSettingsState(@NonNull SharedConnectivitySettingsState settingsState) { mSettingsState = settingsState; @@ -337,23 +337,22 @@ public abstract class SharedConnectivityService extends Service { /** * Implementing application should call this method to provide an up-to-date status of enabling - * and connecting to the tether network. - * - * @param status The updated status {@link TetherNetworkConnectionStatus} of the connection. + * and connecting to the hotspot network. * + * @param status The updated status {@link HotspotNetworkConnectionStatus} of the connection. */ - public final void updateTetherNetworkConnectionStatus( - @NonNull TetherNetworkConnectionStatus status) { - mTetherNetworkConnectionStatus = status; + public final void updateHotspotNetworkConnectionStatus( + @NonNull HotspotNetworkConnectionStatus status) { + mHotspotNetworkConnectionStatus = status; int count = mRemoteCallbackList.beginBroadcast(); for (int i = 0; i < count; i++) { try { mRemoteCallbackList - .getBroadcastItem(i).onTetherNetworkConnectionStatusChanged( - mTetherNetworkConnectionStatus); + .getBroadcastItem(i).onHotspotNetworkConnectionStatusChanged( + mHotspotNetworkConnectionStatus); } catch (RemoteException e) { - if (DEBUG) Log.w(TAG, "Exception in updateTetherNetworkConnectionStatus", e); + if (DEBUG) Log.w(TAG, "Exception in updateHotspotNetworkConnectionStatus", e); } } mRemoteCallbackList.finishBroadcast(); @@ -364,7 +363,6 @@ public abstract class SharedConnectivityService extends Service { * connecting to a known network. * * @param status The updated status {@link KnownNetworkConnectionStatus} of the connection. - * */ public final void updateKnownNetworkConnectionStatus( @NonNull KnownNetworkConnectionStatus status) { @@ -386,20 +384,20 @@ public abstract class SharedConnectivityService extends Service { /** * Implementing application should implement this method. * - * Implementation should initiate a connection to the Tether Network indicated. + * Implementation should initiate a connection to the Hotspot Network indicated. * - * @param network Object identifying the Tether Network the user has requested a connection to. + * @param network Object identifying the Hotspot Network the user has requested a connection to. */ - public abstract void onConnectTetherNetwork(@NonNull TetherNetwork network); + public abstract void onConnectHotspotNetwork(@NonNull HotspotNetwork network); /** * Implementing application should implement this method. * - * Implementation should initiate a disconnection from the active Tether Network. + * Implementation should initiate a disconnection from the active Hotspot Network. * - * @param network Object identifying the Tether Network the user has requested to disconnect. + * @param network Object identifying the Hotspot Network the user has requested to disconnect. */ - public abstract void onDisconnectTetherNetwork(@NonNull TetherNetwork network); + public abstract void onDisconnectHotspotNetwork(@NonNull HotspotNetwork network); /** * Implementing application should implement this method. -- cgit v1.2.3-59-g8ed1b