Merge "Add callbacks for connection status. Including some fixes to documentation and annotations."
This commit is contained in:
committed by
Android (Google) Code Review
commit
1e81bf96b2
@@ -9937,8 +9937,8 @@ package android.net.wifi.sharedconnectivity.app {
|
||||
|
||||
public final class DeviceInfo implements android.os.Parcelable {
|
||||
method public int describeContents();
|
||||
method @IntRange(from=0, to=100) @NonNull public int getBatteryPercentage();
|
||||
method @IntRange(from=0, to=3) @NonNull public int getConnectionStrength();
|
||||
method @IntRange(from=0, to=100) public int getBatteryPercentage();
|
||||
method @IntRange(from=0, to=3) public int getConnectionStrength();
|
||||
method @NonNull public String getDeviceName();
|
||||
method public int getDeviceType();
|
||||
method @NonNull public String getModelName();
|
||||
@@ -9963,7 +9963,7 @@ package android.net.wifi.sharedconnectivity.app {
|
||||
public final class KnownNetwork implements android.os.Parcelable {
|
||||
method public int describeContents();
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.DeviceInfo getDeviceInfo();
|
||||
method @NonNull public int getNetworkSource();
|
||||
method public int getNetworkSource();
|
||||
method @NonNull public int[] getSecurityTypes();
|
||||
method @NonNull public String getSsid();
|
||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||
@@ -9981,9 +9981,29 @@ package android.net.wifi.sharedconnectivity.app {
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetwork.Builder setSsid(@NonNull String);
|
||||
}
|
||||
|
||||
public final class KnownNetworkConnectionStatus implements android.os.Parcelable {
|
||||
method public int describeContents();
|
||||
method @NonNull public android.os.Bundle getExtras();
|
||||
method public int getStatus();
|
||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||
field public static final int CONNECTION_STATUS_SAVED = 1; // 0x1
|
||||
field public static final int CONNECTION_STATUS_SAVE_FAILED = 2; // 0x2
|
||||
field public static final int CONNECTION_STATUS_UNKNOWN = 0; // 0x0
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus> CREATOR;
|
||||
}
|
||||
|
||||
public static final class KnownNetworkConnectionStatus.Builder {
|
||||
ctor public KnownNetworkConnectionStatus.Builder();
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus build();
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus.Builder setExtras(@NonNull android.os.Bundle);
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus.Builder setStatus(int);
|
||||
}
|
||||
|
||||
public interface SharedConnectivityClientCallback {
|
||||
method public void onKnownNetworkConnectionStatusChanged(@NonNull android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus);
|
||||
method public void onKnownNetworksUpdated(@NonNull java.util.List<android.net.wifi.sharedconnectivity.app.KnownNetwork>);
|
||||
method public void onSharedConnectivitySettingsChanged(@NonNull android.net.wifi.sharedconnectivity.app.SharedConnectivitySettingsState);
|
||||
method public void onTetherNetworkConnectionStatusChanged(@NonNull android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus);
|
||||
method public void onTetherNetworksUpdated(@NonNull java.util.List<android.net.wifi.sharedconnectivity.app.TetherNetwork>);
|
||||
}
|
||||
|
||||
@@ -9999,7 +10019,7 @@ package android.net.wifi.sharedconnectivity.app {
|
||||
public final class SharedConnectivitySettingsState implements android.os.Parcelable {
|
||||
method public int describeContents();
|
||||
method @NonNull public android.os.Bundle getExtras();
|
||||
method @NonNull public boolean isInstantTetherEnabled();
|
||||
method public boolean isInstantTetherEnabled();
|
||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.sharedconnectivity.app.SharedConnectivitySettingsState> CREATOR;
|
||||
}
|
||||
@@ -10013,13 +10033,13 @@ package android.net.wifi.sharedconnectivity.app {
|
||||
|
||||
public final class TetherNetwork implements android.os.Parcelable {
|
||||
method public int describeContents();
|
||||
method @NonNull public long getDeviceId();
|
||||
method public long getDeviceId();
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.DeviceInfo getDeviceInfo();
|
||||
method @Nullable public String getHotspotBssid();
|
||||
method @Nullable public int[] getHotspotSecurityTypes();
|
||||
method @Nullable public String getHotspotSsid();
|
||||
method @NonNull public String getNetworkName();
|
||||
method @NonNull public int getNetworkType();
|
||||
method public int getNetworkType();
|
||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.sharedconnectivity.app.TetherNetwork> CREATOR;
|
||||
field public static final int NETWORK_TYPE_CELLULAR = 1; // 0x1
|
||||
@@ -10040,6 +10060,31 @@ package android.net.wifi.sharedconnectivity.app {
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.TetherNetwork.Builder setNetworkType(int);
|
||||
}
|
||||
|
||||
public final class TetherNetworkConnectionStatus implements android.os.Parcelable {
|
||||
method public int describeContents();
|
||||
method @NonNull public android.os.Bundle getExtras();
|
||||
method public int getStatus();
|
||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||
field public static final int CONNECTION_STATUS_CONNECT_TO_HOTSPOT_FAILED = 9; // 0x9
|
||||
field public static final int CONNECTION_STATUS_ENABLING_HOTSPOT = 1; // 0x1
|
||||
field public static final int CONNECTION_STATUS_ENABLING_HOTSPOT_FAILED = 7; // 0x7
|
||||
field public static final int CONNECTION_STATUS_ENABLING_HOTSPOT_TIMEOUT = 8; // 0x8
|
||||
field public static final int CONNECTION_STATUS_NO_CELL_DATA = 6; // 0x6
|
||||
field public static final int CONNECTION_STATUS_PROVISIONING_FAILED = 3; // 0x3
|
||||
field public static final int CONNECTION_STATUS_TETHERING_TIMEOUT = 4; // 0x4
|
||||
field public static final int CONNECTION_STATUS_TETHERING_UNSUPPORTED = 5; // 0x5
|
||||
field public static final int CONNECTION_STATUS_UNKNOWN = 0; // 0x0
|
||||
field public static final int CONNECTION_STATUS_UNKNOWN_ERROR = 2; // 0x2
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus> CREATOR;
|
||||
}
|
||||
|
||||
public static final class TetherNetworkConnectionStatus.Builder {
|
||||
ctor public TetherNetworkConnectionStatus.Builder();
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus build();
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus.Builder setExtras(@NonNull android.os.Bundle);
|
||||
method @NonNull public android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus.Builder setStatus(int);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package android.net.wifi.sharedconnectivity.service {
|
||||
@@ -10055,6 +10100,8 @@ package android.net.wifi.sharedconnectivity.service {
|
||||
method public final void setKnownNetworks(@NonNull java.util.List<android.net.wifi.sharedconnectivity.app.KnownNetwork>);
|
||||
method public final void setSettingsState(@NonNull android.net.wifi.sharedconnectivity.app.SharedConnectivitySettingsState);
|
||||
method public final void setTetherNetworks(@NonNull java.util.List<android.net.wifi.sharedconnectivity.app.TetherNetwork>);
|
||||
method public final void updateKnownNetworkConnectionStatus(@NonNull android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus);
|
||||
method public final void updateTetherNetworkConnectionStatus(@NonNull android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -102,6 +102,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;
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -251,6 +279,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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user