summaryrefslogtreecommitdiff
path: root/wifi/java
diff options
context:
space:
mode:
author Isaac Katzenelson <isaackatz@google.com> 2023-02-09 22:06:15 +0000
committer Isaac Katzenelson <isaackatz@google.com> 2023-02-10 21:46:41 +0000
commit4827bf495653c65f6ded18b3764bdd6423d2a08a (patch)
tree6bcf42379ca972ee8ba5340df85aa083df518f8a /wifi/java
parent4f7fa715e2d1d4155d385ff83deabc189c1b9666 (diff)
Add callbacks for connection status.
Including some fixes to documentation and annotations. Bug: 267765640, 268486125 API-Coverage-Bug: 265968015 Test: atest SharedConnectivityManagerTest Change-Id: I0e7113aa621f3086573a01dc4bd70c7e9dfe3227
Diffstat (limited to 'wifi/java')
-rw-r--r--wifi/java/src/android/net/wifi/sharedconnectivity/app/DeviceInfo.java2
-rw-r--r--wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetwork.java9
-rw-r--r--wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetworkConnectionStatus.aidl19
-rw-r--r--wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetworkConnectionStatus.java179
-rw-r--r--wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityClientCallback.java14
-rw-r--r--wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityManager.java28
-rw-r--r--wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivitySettingsState.java4
-rw-r--r--wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetwork.java6
-rw-r--r--wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetworkConnectionStatus.aidl19
-rw-r--r--wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetworkConnectionStatus.java221
-rw-r--r--wifi/java/src/android/net/wifi/sharedconnectivity/service/ISharedConnectivityCallback.aidl4
-rw-r--r--wifi/java/src/android/net/wifi/sharedconnectivity/service/SharedConnectivityService.java61
12 files changed, 551 insertions, 15 deletions
diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/DeviceInfo.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/DeviceInfo.java
index 7874b2a22e02..9aad9aafbd7e 100644
--- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/DeviceInfo.java
+++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/DeviceInfo.java
@@ -225,7 +225,6 @@ public final class DeviceInfo implements Parcelable {
*
* @return Returns the battery charge percentage in the range 0 to 100.
*/
- @NonNull
@IntRange(from = 0, to = 100)
public int getBatteryPercentage() {
return mBatteryPercentage;
@@ -236,7 +235,6 @@ public final class DeviceInfo implements Parcelable {
*
* @return Returns the connection strength in range 0 to 3.
*/
- @NonNull
@IntRange(from = 0, to = 3)
public int getConnectionStrength() {
return mConnectionStrength;
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 34b7e94e0fda..b219e86ec407 100644
--- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetwork.java
+++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetwork.java
@@ -31,7 +31,7 @@ import java.util.Arrays;
import java.util.Objects;
/**
- * A data class representing a known Wifi network.
+ * A data class representing a known Wi-Fi network.
*
* @hide
*/
@@ -112,7 +112,7 @@ public final class KnownNetwork implements Parcelable {
/**
* Sets the device information of the device providing connectivity.
*
- * @param deviceInfo The array of security types supported by the known network.
+ * @param deviceInfo The device information object.
* @return Returns the Builder object.
*/
@NonNull
@@ -153,7 +153,7 @@ public final class KnownNetwork implements Parcelable {
@NetworkSource int networkSource,
@NonNull String ssid,
@NonNull @SecurityType int[] securityTypes,
- @NonNull android.net.wifi.sharedconnectivity.app.DeviceInfo deviceInfo) {
+ @NonNull DeviceInfo deviceInfo) {
validate(networkSource, ssid, securityTypes);
mNetworkSource = networkSource;
mSsid = ssid;
@@ -166,7 +166,6 @@ public final class KnownNetwork implements Parcelable {
*
* @return Returns the network source as defined by IntDef {@link NetworkSource}.
*/
- @NonNull
@NetworkSource
public int getNetworkSource() {
return mNetworkSource;
@@ -196,7 +195,7 @@ public final class KnownNetwork implements Parcelable {
/**
* Gets the device information of the device providing connectivity.
*
- * @return Returns the array of security types supported by the known network.
+ * @return Returns the information of the device providing the known network.
*/
@NonNull
public DeviceInfo getDeviceInfo() {
diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetworkConnectionStatus.aidl b/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetworkConnectionStatus.aidl
new file mode 100644
index 000000000000..df43508ab0cc
--- /dev/null
+++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetworkConnectionStatus.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 KnownNetworkConnectionStatus;
diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetworkConnectionStatus.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetworkConnectionStatus.java
new file mode 100644
index 000000000000..2cefb8e9f5ae
--- /dev/null
+++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/KnownNetworkConnectionStatus.java
@@ -0,0 +1,179 @@
+/*
+ * 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 known network after the client called
+ * {@link SharedConnectivityManager#connectKnownNetwork}.
+ *
+ * @hide
+ */
+@SystemApi
+public final class KnownNetworkConnectionStatus implements Parcelable {
+
+ /**
+ * Connection status is unknown.
+ */
+ public static final int CONNECTION_STATUS_UNKNOWN = 0;
+
+ /**
+ * The connection's data was saved successfully in the Wi-Fi configuration.
+ */
+ public static final int CONNECTION_STATUS_SAVED = 1;
+
+ /**
+ * Failed to save the connection's data in the Wi-Fi configuration.
+ */
+ public static final int CONNECTION_STATUS_SAVE_FAILED = 2;
+
+ /**
+ * @hide
+ */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({
+ CONNECTION_STATUS_UNKNOWN,
+ CONNECTION_STATUS_SAVED,
+ CONNECTION_STATUS_SAVE_FAILED,
+ })
+ public @interface ConnectionStatus {}
+
+ @ConnectionStatus private final int mStatus;
+ private final Bundle mExtras;
+
+ /**
+ * Builder class for {@link KnownNetworkConnectionStatus}.
+ */
+ public static final class Builder {
+ @ConnectionStatus private int mStatus;
+ 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 extras bundle
+ *
+ * @return Returns the Builder object.
+ */
+ @NonNull
+ public Builder setExtras(@NonNull Bundle extras) {
+ mExtras = extras;
+ return this;
+ }
+
+ /**
+ * Builds the {@link KnownNetworkConnectionStatus} object.
+ *
+ * @return Returns the built {@link KnownNetworkConnectionStatus} object.
+ */
+ @NonNull
+ public KnownNetworkConnectionStatus build() {
+ return new KnownNetworkConnectionStatus(mStatus, mExtras);
+ }
+ }
+
+ private KnownNetworkConnectionStatus(@ConnectionStatus int status, Bundle extras) {
+ mStatus = status;
+ mExtras = extras;
+ }
+
+ /**
+ * Gets the status of the connection
+ *
+ * @return Returns true for enabled, false otherwise.
+ */
+ @ConnectionStatus
+ public int getStatus() {
+ return mStatus;
+ }
+
+ /**
+ * Gets the extras Bundle.
+ *
+ * @return Returns a Bundle object.
+ */
+ @NonNull
+ public Bundle getExtras() {
+ return mExtras;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof KnownNetworkConnectionStatus)) return false;
+ KnownNetworkConnectionStatus other = (KnownNetworkConnectionStatus) obj;
+ return mStatus == other.getStatus();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mStatus);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(@NonNull Parcel dest, int flags) {
+ dest.writeInt(mStatus);
+ dest.writeBundle(mExtras);
+ }
+
+ @NonNull
+ public static final Creator<KnownNetworkConnectionStatus> CREATOR = new Creator<>() {
+ @Override
+ public KnownNetworkConnectionStatus createFromParcel(Parcel in) {
+ return new KnownNetworkConnectionStatus(in.readInt(),
+ in.readBundle(getClass().getClassLoader()));
+ }
+
+ @Override
+ public KnownNetworkConnectionStatus[] newArray(int size) {
+ return new KnownNetworkConnectionStatus[size];
+ }
+ };
+
+ @Override
+ public String toString() {
+ return new StringBuilder("KnownNetworkConnectionStatus[")
+ .append("status=").append(mStatus)
+ .append("extras=").append(mExtras.toString())
+ .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 dcb5201b4594..f62bfd451d5e 100644
--- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityClientCallback.java
+++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityClientCallback.java
@@ -50,5 +50,19 @@ public interface SharedConnectivityClientCallback {
* @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.
+ * @param status The new status.
+ */
+ void onTetherNetworkConnectionStatusChanged(@NonNull TetherNetworkConnectionStatus 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 b43e4f7f57b5..a8d0e894a5e2 100644
--- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityManager.java
+++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityManager.java
@@ -103,6 +103,34 @@ public class SharedConnectivityManager {
}
}
};
+
+ @Override
+ public void onTetherNetworkConnectionStatusChanged(
+ @NonNull TetherNetworkConnectionStatus status) {
+ if (mCallback != null) {
+ final long token = Binder.clearCallingIdentity();
+ try {
+ mExecutor.execute(() ->
+ mCallback.onTetherNetworkConnectionStatusChanged(status));
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+ };
+
+ @Override
+ public void onKnownNetworkConnectionStatusChanged(
+ @NonNull KnownNetworkConnectionStatus status) {
+ if (mCallback != null) {
+ final long token = Binder.clearCallingIdentity();
+ try {
+ mExecutor.execute(() ->
+ mCallback.onKnownNetworkConnectionStatusChanged(status));
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+ };
}
private ISharedConnectivityService mService;
diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivitySettingsState.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivitySettingsState.java
index dd2fa94ccf2d..87f5efd5e0c8 100644
--- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivitySettingsState.java
+++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivitySettingsState.java
@@ -91,7 +91,6 @@ public final class SharedConnectivitySettingsState implements Parcelable {
*
* @return Returns true for enabled, false otherwise.
*/
- @NonNull
public boolean isInstantTetherEnabled() {
return mInstantTetherEnabled;
}
@@ -130,8 +129,7 @@ public final class SharedConnectivitySettingsState implements Parcelable {
}
@NonNull
- public static final Creator<SharedConnectivitySettingsState> CREATOR =
- new Creator<SharedConnectivitySettingsState>() {
+ public static final Creator<SharedConnectivitySettingsState> CREATOR = new Creator<>() {
@Override
public SharedConnectivitySettingsState createFromParcel(Parcel in) {
return new SharedConnectivitySettingsState(in.readBoolean(),
diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetwork.java b/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetwork.java
index bbdad5344646..3eff72416b12 100644
--- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetwork.java
+++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetwork.java
@@ -110,7 +110,7 @@ public final class TetherNetwork implements Parcelable {
/**
* Sets information about the device providing connectivity.
*
- * @param deviceInfo The user configurable device name.
+ * @param deviceInfo The device information object.
* @return Returns the Builder object.
*/
@NonNull
@@ -236,7 +236,6 @@ public final class TetherNetwork implements Parcelable {
*
* @return Returns the locally unique ID for this Instant Tether network.
*/
- @NonNull
public long getDeviceId() {
return mDeviceId;
}
@@ -244,7 +243,7 @@ public final class TetherNetwork implements Parcelable {
/**
* Gets information about the device providing connectivity.
*
- * @return Returns the locally unique ID for this Instant Tether network.
+ * @return Returns the information of the device providing the Instant Tether network.
*/
@NonNull
public DeviceInfo getDeviceInfo() {
@@ -256,7 +255,6 @@ public final class TetherNetwork implements Parcelable {
*
* @return Returns the network type as represented by IntDef {@link NetworkType}.
*/
- @NonNull
@NetworkType
public int getNetworkType() {
return mNetworkType;
diff --git a/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetworkConnectionStatus.aidl b/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetworkConnectionStatus.aidl
new file mode 100644
index 000000000000..c677a6c508ad
--- /dev/null
+++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetworkConnectionStatus.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 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
new file mode 100644
index 000000000000..86202bb6674d
--- /dev/null
+++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/TetherNetworkConnectionStatus.java
@@ -0,0 +1,221 @@
+/*
+ * 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 Bundle mExtras;
+
+ /**
+ * Builder class for {@link TetherNetworkConnectionStatus}.
+ */
+ public static final class Builder {
+ @ConnectionStatus private int mStatus;
+ 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 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, mExtras);
+ }
+ }
+
+ private TetherNetworkConnectionStatus(@ConnectionStatus int status, Bundle extras) {
+ mStatus = status;
+ mExtras = extras;
+ }
+
+ /**
+ * Gets the status of the connection
+ *
+ * @return Returns true for enabled, false otherwise.
+ */
+ @ConnectionStatus
+ public int getStatus() {
+ return mStatus;
+ }
+
+ /**
+ * 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();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mStatus);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(@NonNull Parcel dest, int flags) {
+ dest.writeInt(mStatus);
+ dest.writeBundle(mExtras);
+ }
+
+ @NonNull
+ public static final Creator<TetherNetworkConnectionStatus> CREATOR = new Creator<>() {
+ @Override
+ public TetherNetworkConnectionStatus createFromParcel(Parcel in) {
+ return new TetherNetworkConnectionStatus(in.readInt(),
+ in.readBundle(getClass().getClassLoader()));
+ }
+
+ @Override
+ public TetherNetworkConnectionStatus[] newArray(int size) {
+ return new TetherNetworkConnectionStatus[size];
+ }
+ };
+
+ @Override
+ public String toString() {
+ return new StringBuilder("TetherNetworkConnectionStatus[")
+ .append("status=").append(mStatus)
+ .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 6e5613886cdc..6f6f1627c6a5 100644
--- a/wifi/java/src/android/net/wifi/sharedconnectivity/service/ISharedConnectivityCallback.aidl
+++ b/wifi/java/src/android/net/wifi/sharedconnectivity/service/ISharedConnectivityCallback.aidl
@@ -17,14 +17,18 @@
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;
/*
* @hide
*/
interface ISharedConnectivityCallback {
oneway void onTetherNetworksUpdated(in List<TetherNetwork> networks);
+ oneway void onTetherNetworkConnectionStatusChanged(in TetherNetworkConnectionStatus status);
oneway void onKnownNetworksUpdated(in List<KnownNetwork> networks);
+ oneway void onKnownNetworkConnectionStatusChanged(in KnownNetworkConnectionStatus status);
oneway void onSharedConnectivitySettingsChanged(in SharedConnectivitySettingsState state);
}
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 234319ad5318..a40049b2515a 100644
--- a/wifi/java/src/android/net/wifi/sharedconnectivity/service/SharedConnectivityService.java
+++ b/wifi/java/src/android/net/wifi/sharedconnectivity/service/SharedConnectivityService.java
@@ -27,9 +27,11 @@ import android.app.Service;
import android.content.Intent;
import android.content.pm.PackageManager;
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.Handler;
import android.os.IBinder;
import android.os.RemoteException;
@@ -66,6 +68,8 @@ public abstract class SharedConnectivityService extends Service {
private List<TetherNetwork> mTetherNetworks = Collections.emptyList();
private List<KnownNetwork> mKnownNetworks = Collections.emptyList();
private SharedConnectivitySettingsState mSettingsState;
+ private TetherNetworkConnectionStatus mTetherNetworkConnectionStatus;
+ private KnownNetworkConnectionStatus mKnownNetworkConnectionStatus;
public SharedConnectivityService() {
mHandler = new Handler(getMainLooper());
@@ -145,7 +149,10 @@ public abstract class SharedConnectivityService extends Service {
private void registerCallback(ISharedConnectivityCallback callback) {
// Listener gets triggered on first register using cashed data
- if (!notifyTetherNetworkUpdate(callback) || !notifyKnownNetworkUpdate(callback)) {
+ if (!notifyTetherNetworkUpdate(callback) || !notifyKnownNetworkUpdate(callback)
+ || !notifySettingsStateUpdate(callback)
+ || !notifyTetherNetworkConnectionStatusChanged(callback)
+ || !notifyKnownNetworkConnectionStatusChanged(callback)) {
if (DEBUG) Log.w(TAG, "Failed to notify client");
return;
}
@@ -199,6 +206,27 @@ public abstract class SharedConnectivityService extends Service {
return true;
}
+ private boolean notifyTetherNetworkConnectionStatusChanged(
+ ISharedConnectivityCallback callback) {
+ try {
+ callback.onTetherNetworkConnectionStatusChanged(mTetherNetworkConnectionStatus);
+ } catch (RemoteException e) {
+ if (DEBUG) Log.w(TAG, "Exception in notifyTetherNetworkConnectionStatusChanged", e);
+ return false;
+ }
+ return true;
+ }
+
+ private boolean notifyKnownNetworkConnectionStatusChanged(
+ ISharedConnectivityCallback callback) {
+ try {
+ callback.onKnownNetworkConnectionStatusChanged(mKnownNetworkConnectionStatus);
+ } catch (RemoteException e) {
+ if (DEBUG) Log.w(TAG, "Exception in notifyKnownNetworkConnectionStatusChanged", e);
+ return false;
+ }
+ return true;
+ }
/**
* Implementing application should call this method to provide an up-to-date list of Tether
* Networks to be displayed to the user.
@@ -252,6 +280,37 @@ 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.
+ *
+ */
+ public final void updateTetherNetworkConnectionStatus(
+ @NonNull TetherNetworkConnectionStatus status) {
+ mTetherNetworkConnectionStatus = status;
+ for (ISharedConnectivityCallback callback:mCallbacks) {
+ notifyTetherNetworkConnectionStatusChanged(callback);
+ }
+ }
+
+ /**
+ * Implementing application should call this method to provide an up-to-date status of
+ * connecting to a known network.
+ *
+ * @param status The updated status {@link KnownNetworkConnectionStatus} of the connection.
+ *
+ */
+ public final void updateKnownNetworkConnectionStatus(
+ @NonNull KnownNetworkConnectionStatus status) {
+ mKnownNetworkConnectionStatus = status;
+
+ for (ISharedConnectivityCallback callback:mCallbacks) {
+ notifyKnownNetworkConnectionStatusChanged(callback);
+ }
+ }
+
+ /**
* Implementing application should implement this method.
*
* Implementation should initiate a connection to the Tether Network indicated.