API Review: SharedConnectivityManager & SharedConnectivityService
Bug: 268486125 Test: atest SharedConnectivityManagerTest SharedConnectivityServiceTest Change-Id: I4d9671379cc426102cabd81e973c70ee2cbb41f4
This commit is contained in:
committed by
Andrew Sapperstein
parent
8e2d8bdc39
commit
44d3fa63ff
@@ -10080,17 +10080,17 @@ package android.net.wifi.sharedconnectivity.app {
|
||||
}
|
||||
|
||||
public class SharedConnectivityManager {
|
||||
method public boolean connectKnownNetwork(@NonNull android.net.wifi.sharedconnectivity.app.KnownNetwork);
|
||||
method public boolean connectTetherNetwork(@NonNull android.net.wifi.sharedconnectivity.app.TetherNetwork);
|
||||
method public boolean disconnectTetherNetwork(@NonNull android.net.wifi.sharedconnectivity.app.TetherNetwork);
|
||||
method public boolean forgetKnownNetwork(@NonNull android.net.wifi.sharedconnectivity.app.KnownNetwork);
|
||||
method @Nullable public android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus getKnownNetworkConnectionStatus();
|
||||
method @NonNull public java.util.List<android.net.wifi.sharedconnectivity.app.KnownNetwork> getKnownNetworks();
|
||||
method @Nullable public android.net.wifi.sharedconnectivity.app.SharedConnectivitySettingsState getSettingsState();
|
||||
method @Nullable public android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus getTetherNetworkConnectionStatus();
|
||||
method @NonNull public java.util.List<android.net.wifi.sharedconnectivity.app.TetherNetwork> getTetherNetworks();
|
||||
method public void registerCallback(@NonNull java.util.concurrent.Executor, @NonNull android.net.wifi.sharedconnectivity.app.SharedConnectivityClientCallback);
|
||||
method public boolean unregisterCallback(@NonNull android.net.wifi.sharedconnectivity.app.SharedConnectivityClientCallback);
|
||||
method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) public boolean connectKnownNetwork(@NonNull android.net.wifi.sharedconnectivity.app.KnownNetwork);
|
||||
method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) public boolean connectTetherNetwork(@NonNull android.net.wifi.sharedconnectivity.app.TetherNetwork);
|
||||
method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) public boolean disconnectTetherNetwork(@NonNull android.net.wifi.sharedconnectivity.app.TetherNetwork);
|
||||
method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) public boolean forgetKnownNetwork(@NonNull android.net.wifi.sharedconnectivity.app.KnownNetwork);
|
||||
method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) public android.net.wifi.sharedconnectivity.app.KnownNetworkConnectionStatus getKnownNetworkConnectionStatus();
|
||||
method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) public java.util.List<android.net.wifi.sharedconnectivity.app.KnownNetwork> getKnownNetworks();
|
||||
method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) public android.net.wifi.sharedconnectivity.app.SharedConnectivitySettingsState getSettingsState();
|
||||
method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) public android.net.wifi.sharedconnectivity.app.TetherNetworkConnectionStatus getTetherNetworkConnectionStatus();
|
||||
method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) public java.util.List<android.net.wifi.sharedconnectivity.app.TetherNetwork> getTetherNetworks();
|
||||
method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) public void registerCallback(@NonNull java.util.concurrent.Executor, @NonNull android.net.wifi.sharedconnectivity.app.SharedConnectivityClientCallback);
|
||||
method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) public boolean unregisterCallback(@NonNull android.net.wifi.sharedconnectivity.app.SharedConnectivityClientCallback);
|
||||
}
|
||||
|
||||
public final class SharedConnectivitySettingsState implements android.os.Parcelable {
|
||||
|
||||
@@ -19,6 +19,7 @@ package android.net.wifi.sharedconnectivity.app;
|
||||
import android.annotation.CallbackExecutor;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.SystemApi;
|
||||
import android.annotation.TestApi;
|
||||
@@ -151,7 +152,7 @@ public class SharedConnectivityManager {
|
||||
* Creates a new instance of {@link SharedConnectivityManager}.
|
||||
*
|
||||
* Automatically binds to implementation of {@link SharedConnectivityService} specified in
|
||||
* device overlay.
|
||||
* the device overlay.
|
||||
*
|
||||
* @return An instance of {@link SharedConnectivityManager} or null if the shared connectivity
|
||||
* service is not found.
|
||||
@@ -266,9 +267,10 @@ public class SharedConnectivityManager {
|
||||
*
|
||||
* @param executor The Executor used to invoke the callback.
|
||||
* @param callback The callback of type {@link SharedConnectivityClientCallback} that is invoked
|
||||
* when the service updates either the list of Tether Networks or Known
|
||||
* Networks.
|
||||
* when the service updates its data.
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
public void registerCallback(@NonNull @CallbackExecutor Executor executor,
|
||||
@NonNull SharedConnectivityClientCallback callback) {
|
||||
Objects.requireNonNull(executor, "executor cannot be null");
|
||||
@@ -297,6 +299,8 @@ public class SharedConnectivityManager {
|
||||
*
|
||||
* @return Returns true if the callback was successfully unregistered, false otherwise.
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
public boolean unregisterCallback(
|
||||
@NonNull SharedConnectivityClientCallback callback) {
|
||||
Objects.requireNonNull(callback, "callback cannot be null");
|
||||
@@ -325,7 +329,7 @@ public class SharedConnectivityManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Send command to the implementation of {@link SharedConnectivityService} requesting connection
|
||||
* to the specified Tether Network.
|
||||
*
|
||||
@@ -334,6 +338,8 @@ public class SharedConnectivityManager {
|
||||
* @return Returns true if the service received the command. Does not guarantee that the
|
||||
* 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");
|
||||
|
||||
@@ -359,6 +365,8 @@ public class SharedConnectivityManager {
|
||||
* @return Returns true if the service received the command. Does not guarantee that the
|
||||
* disconnection was successful.
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
public boolean disconnectTetherNetwork(@NonNull TetherNetwork network) {
|
||||
if (mService == null) {
|
||||
return false;
|
||||
@@ -382,6 +390,8 @@ public class SharedConnectivityManager {
|
||||
* @return Returns true if the service received the command. Does not guarantee that the
|
||||
* connection was successful.
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
public boolean connectKnownNetwork(@NonNull KnownNetwork network) {
|
||||
Objects.requireNonNull(network, "Known network cannot be null");
|
||||
|
||||
@@ -405,6 +415,8 @@ public class SharedConnectivityManager {
|
||||
* @return Returns true if the service received the command. Does not guarantee that the
|
||||
* forget action was successful.
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
public boolean forgetKnownNetwork(@NonNull KnownNetwork network) {
|
||||
Objects.requireNonNull(network, "Known network cannot be null");
|
||||
|
||||
@@ -426,6 +438,8 @@ public class SharedConnectivityManager {
|
||||
*
|
||||
* @return Returns a {@link List} of {@link TetherNetwork} objects, empty list on failure.
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
@NonNull
|
||||
public List<TetherNetwork> getTetherNetworks() {
|
||||
if (mService == null) {
|
||||
@@ -445,6 +459,8 @@ public class SharedConnectivityManager {
|
||||
*
|
||||
* @return Returns a {@link List} of {@link KnownNetwork} objects, empty list on failure.
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
@NonNull
|
||||
public List<KnownNetwork> getKnownNetworks() {
|
||||
if (mService == null) {
|
||||
@@ -465,6 +481,8 @@ public class SharedConnectivityManager {
|
||||
* @return Returns a {@link SharedConnectivitySettingsState} object with the state, null on
|
||||
* failure.
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
@Nullable
|
||||
public SharedConnectivitySettingsState getSettingsState() {
|
||||
if (mService == null) {
|
||||
@@ -486,6 +504,8 @@ public class SharedConnectivityManager {
|
||||
* null on failure. If no connection is active the status will be
|
||||
* {@link TetherNetworkConnectionStatus#CONNECTION_STATUS_UNKNOWN}.
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
@Nullable
|
||||
public TetherNetworkConnectionStatus getTetherNetworkConnectionStatus() {
|
||||
if (mService == null) {
|
||||
@@ -507,6 +527,8 @@ public class SharedConnectivityManager {
|
||||
* null on failure. If no connection is active the status will be
|
||||
* {@link KnownNetworkConnectionStatus#CONNECTION_STATUS_UNKNOWN}.
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
@Nullable
|
||||
public KnownNetworkConnectionStatus getKnownNetworkConnectionStatus() {
|
||||
if (mService == null) {
|
||||
|
||||
@@ -82,66 +82,148 @@ public abstract class SharedConnectivityService extends Service {
|
||||
if (DEBUG) Log.i(TAG, "onBind intent=" + intent);
|
||||
mHandler = new Handler(getMainLooper());
|
||||
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
|
||||
* known network connection status.
|
||||
*
|
||||
* @param callback The callback of type {@link ISharedConnectivityCallback} to be called
|
||||
* when there is update to the data.
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
@Override
|
||||
public void registerCallback(ISharedConnectivityCallback callback) {
|
||||
checkPermissions();
|
||||
mHandler.post(() -> onRegisterCallback(callback));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a previously registered callback.
|
||||
*
|
||||
* @param callback The callback to unregister.
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
@Override
|
||||
public void unregisterCallback(ISharedConnectivityCallback callback) {
|
||||
checkPermissions();
|
||||
mHandler.post(() -> onUnregisterCallback(callback));
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to a tether 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) {
|
||||
checkPermissions();
|
||||
mHandler.post(() -> onConnectTetherNetwork(network));
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects from a previously connected tether 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) {
|
||||
checkPermissions();
|
||||
mHandler.post(() -> onDisconnectTetherNetwork(network));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a known network to the available networks on the device and connects to it.
|
||||
*
|
||||
* @param network The network to connect to.
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
@Override
|
||||
public void connectKnownNetwork(KnownNetwork network) {
|
||||
checkPermissions();
|
||||
mHandler.post(() -> onConnectKnownNetwork(network));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a known network from the available networks on the device which will also
|
||||
* disconnect the device from the network if it is connected to it.
|
||||
*
|
||||
* @param network The network to forget.
|
||||
*/
|
||||
@Override
|
||||
public void forgetKnownNetwork(KnownNetwork network) {
|
||||
checkPermissions();
|
||||
mHandler.post(() -> onForgetKnownNetwork(network));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of tether networks the user can select to connect to.
|
||||
*
|
||||
* @return Returns a {@link List} of {@link TetherNetwork} objects
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
@Override
|
||||
public List<TetherNetwork> getTetherNetworks() {
|
||||
checkPermissions();
|
||||
return mTetherNetworks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of known networks the user can select to connect to.
|
||||
*
|
||||
* @return Returns a {@link List} of {@link KnownNetwork} objects.
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
@Override
|
||||
public List<KnownNetwork> getKnownNetworks() {
|
||||
checkPermissions();
|
||||
return mKnownNetworks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the shared connectivity settings state.
|
||||
*
|
||||
* @return Returns a {@link SharedConnectivitySettingsState} object with the state.
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
@Override
|
||||
public SharedConnectivitySettingsState getSettingsState() {
|
||||
checkPermissions();
|
||||
return mSettingsState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the connection status of the tether network the user selected to connect to.
|
||||
*
|
||||
* @return Returns a {@link TetherNetworkConnectionStatus} object with the connection
|
||||
* status.
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
@Override
|
||||
public TetherNetworkConnectionStatus getTetherNetworkConnectionStatus() {
|
||||
checkPermissions();
|
||||
return mTetherNetworkConnectionStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the connection status of the known network the user selected to connect to.
|
||||
*
|
||||
* @return Returns a {@link KnownNetworkConnectionStatus} object with the connection
|
||||
* status.
|
||||
*/
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_SETUP_WIZARD})
|
||||
@Override
|
||||
public KnownNetworkConnectionStatus getKnownNetworkConnectionStatus() {
|
||||
checkPermissions();
|
||||
|
||||
Reference in New Issue
Block a user