summaryrefslogtreecommitdiff
path: root/wifi
diff options
context:
space:
mode:
authorIsaac Katzenelson <isaackatz@google.com>2023-02-28 01:59:21 +0000
committerAndrew Sapperstein <asapperstein@google.com>2023-03-01 15:09:30 +0000
commit44d3fa63ff86b0273eb49f57a2a49a15334df12c (patch)
tree98cfbd017273cea4f21215843dc1e16547e8db57 /wifi
parent8e2d8bdc398b125558457a5e69a6f0e61ca761a2 (diff)
downloadbase-44d3fa63ff86b0273eb49f57a2a49a15334df12c.tar.gz
API Review: SharedConnectivityManager & SharedConnectivityService
Bug: 268486125 Test: atest SharedConnectivityManagerTest SharedConnectivityServiceTest Change-Id: I4d9671379cc426102cabd81e973c70ee2cbb41f4
Diffstat (limited to 'wifi')
-rw-r--r--wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityManager.java30
-rw-r--r--wifi/java/src/android/net/wifi/sharedconnectivity/service/SharedConnectivityService.java82
2 files changed, 108 insertions, 4 deletions
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 a19510b3f9df..c09f85b39ee4 100644
--- a/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityManager.java
+++ b/wifi/java/src/android/net/wifi/sharedconnectivity/app/SharedConnectivityManager.java
@@ -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) {
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 d2cea613d2ec..4c88c1b269a9 100644
--- a/wifi/java/src/android/net/wifi/sharedconnectivity/service/SharedConnectivityService.java
+++ b/wifi/java/src/android/net/wifi/sharedconnectivity/service/SharedConnectivityService.java
@@ -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();