summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author maheshkkv <maheshkkv@google.com> 2024-11-17 23:02:13 -0800
committer maheshkkv <maheshkkv@google.com> 2024-11-22 08:56:26 -0800
commitd6071bc9992e1cb3ea5cc8025849ffc32bce4d57 (patch)
tree0cbf37f6af23f5ac74c06d856dd454a4e768d5ed
parent15a453545c11f8bed056227f5e9bb40e8e495120 (diff)
Add USD characterstics
Flag: android.net.wifi.flags.usd Bug: 340878198 Test: atest FrameworksWifiApiTests Change-Id: Ia4395af58ae5042279b6316fc4c437a96a4c3d6a
-rw-r--r--framework/aidl-export/android/net/wifi/usd/Characteristics.aidl19
-rw-r--r--framework/api/system-current.txt12
-rw-r--r--framework/java/android/net/wifi/usd/Characteristics.java149
-rw-r--r--framework/java/android/net/wifi/usd/IUsdManager.aidl2
-rw-r--r--framework/java/android/net/wifi/usd/UsdManager.java20
-rw-r--r--service/java/com/android/server/wifi/usd/UsdServiceImpl.java21
6 files changed, 223 insertions, 0 deletions
diff --git a/framework/aidl-export/android/net/wifi/usd/Characteristics.aidl b/framework/aidl-export/android/net/wifi/usd/Characteristics.aidl
new file mode 100644
index 0000000000..818426bda2
--- /dev/null
+++ b/framework/aidl-export/android/net/wifi/usd/Characteristics.aidl
@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2024, 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.usd;
+
+parcelable Characteristics;
diff --git a/framework/api/system-current.txt b/framework/api/system-current.txt
index 7ea49964ff..e37b7f8404 100644
--- a/framework/api/system-current.txt
+++ b/framework/api/system-current.txt
@@ -1847,6 +1847,17 @@ package android.net.wifi.twt {
package android.net.wifi.usd {
+ @FlaggedApi("android.net.wifi.flags.usd") public final class Characteristics implements android.os.Parcelable {
+ method public int describeContents();
+ method public int getMaxMatchFilterLength();
+ method public int getMaxNumberOfPublishSessions();
+ method public int getMaxNumberOfSubscribeSessions();
+ method public int getMaxServiceNameLength();
+ method public int getMaxServiceSpecificInfoLength();
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.usd.Characteristics> CREATOR;
+ }
+
@FlaggedApi("android.net.wifi.flags.usd") public abstract class Config {
method @NonNull public java.util.List<byte[]> getRxMatchFilter();
method @NonNull public byte[] getServiceName();
@@ -1907,6 +1918,7 @@ package android.net.wifi.usd {
}
@FlaggedApi("android.net.wifi.flags.usd") public class UsdManager {
+ method @Nullable @RequiresPermission(android.Manifest.permission.MANAGE_WIFI_NETWORK_SELECTION) public android.net.wifi.usd.Characteristics getCharacteristics();
method @RequiresPermission(android.Manifest.permission.MANAGE_WIFI_NETWORK_SELECTION) public boolean isPublisherAvailable();
method @RequiresPermission(android.Manifest.permission.MANAGE_WIFI_NETWORK_SELECTION) public boolean isPublisherSupported();
method @RequiresPermission(android.Manifest.permission.MANAGE_WIFI_NETWORK_SELECTION) public boolean isSubscriberAvailable();
diff --git a/framework/java/android/net/wifi/usd/Characteristics.java b/framework/java/android/net/wifi/usd/Characteristics.java
new file mode 100644
index 0000000000..3467eeeaab
--- /dev/null
+++ b/framework/java/android/net/wifi/usd/Characteristics.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2024 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.usd;
+
+import android.annotation.FlaggedApi;
+import android.annotation.SystemApi;
+import android.net.wifi.flags.Flags;
+import android.os.Bundle;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import androidx.annotation.NonNull;
+
+import java.util.List;
+import java.util.concurrent.Executor;
+import java.util.function.Consumer;
+
+/**
+ * The characteristics of the USD implementation.
+ *
+ * @hide
+ */
+@SystemApi
+@FlaggedApi(Flags.FLAG_USD)
+public final class Characteristics implements Parcelable {
+ private final Bundle mCharacteristics;
+ /** @hide */
+ public static final String KEY_MAX_SERVICE_NAME_LENGTH = "key_max_service_name_length";
+ /** @hide */
+ public static final String KEY_MAX_SERVICE_SPECIFIC_INFO_LENGTH =
+ "key_max_service_specific_info_length";
+ /** @hide */
+ public static final String KEY_MAX_MATCH_FILTER_LENGTH = "key_max_match_filter_length";
+ /** @hide */
+ public static final String KEY_MAX_NUM_PUBLISH_SESSIONS = "key_max_num_publish_session";
+ /** @hide */
+ public static final String KEY_MAX_NUM_SUBSCRIBE_SESSIONS = "key_max_num_subscribe_session";
+
+
+ /** @hide : should not be created by apps */
+ public Characteristics(Bundle characteristics) {
+ mCharacteristics = characteristics;
+ }
+
+ private Characteristics(@NonNull Parcel in) {
+ mCharacteristics = in.readBundle(getClass().getClassLoader());
+ }
+
+ @NonNull
+ public static final Creator<Characteristics> CREATOR = new Creator<Characteristics>() {
+ @Override
+ public Characteristics createFromParcel(Parcel in) {
+ return new Characteristics(in);
+ }
+
+ @Override
+ public Characteristics[] newArray(int size) {
+ return new Characteristics[size];
+ }
+ };
+
+ /**
+ * Returns the maximum string length that can be used to specify a USD service name.
+ *
+ * @return A positive integer, maximum string length of USD service name.
+ */
+ public int getMaxServiceNameLength() {
+ return mCharacteristics.getInt(KEY_MAX_SERVICE_NAME_LENGTH);
+ }
+
+ /**
+ * Returns the maximum length of byte array that can be used to specify a service specific
+ * information field: the arbitrary load used in discovery or the message length of USD
+ * message exchange. Restricts the parameters of the
+ * {@link PublishConfig.Builder#setServiceSpecificInfo(byte[])},
+ * {@link SubscribeConfig.Builder#setServiceSpecificInfo(byte[])},
+ * {@link PublishSession#sendMessage(int, byte[], Executor, Consumer)} and
+ * {@link SubscribeSession#sendMessage(int, byte[], Executor, Consumer)}
+ * variants.
+ *
+ * @return A positive integer, maximum length of byte array for USD messaging.
+ */
+ public int getMaxServiceSpecificInfoLength() {
+ return mCharacteristics.getInt(KEY_MAX_SERVICE_SPECIFIC_INFO_LENGTH);
+ }
+
+ /**
+ * Returns the maximum length of byte array that can be used to specify a USD match filter.
+ * Restricts the parameters of the
+ * {@link PublishConfig.Builder#setTxMatchFilter(List)},
+ * {@link PublishConfig.Builder#setRxMatchFilter(List)},
+ * {@link SubscribeConfig.Builder#setTxMatchFilter(List)} and
+ * {@link SubscribeConfig.Builder#setRxMatchFilter(List)}
+ *
+ * @return A positive integer, maximum length of byte array for USD discovery match filter.
+ */
+ public int getMaxMatchFilterLength() {
+ return mCharacteristics.getInt(KEY_MAX_MATCH_FILTER_LENGTH);
+ }
+
+ /**
+ * Returns the maximum number of publish sessions supported by USD
+ *
+ * @return A positive integer
+ */
+ public int getMaxNumberOfPublishSessions() {
+ return mCharacteristics.getInt(KEY_MAX_NUM_PUBLISH_SESSIONS);
+ }
+
+ /**
+ * Returns the maximum number of subscribe sessions supported by USD
+ *
+ * @return A positive integer
+ */
+ public int getMaxNumberOfSubscribeSessions() {
+ return mCharacteristics.getInt(KEY_MAX_NUM_SUBSCRIBE_SESSIONS);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ /**
+ * Flatten this object in to a Parcel.
+ *
+ * @param dest The Parcel in which the object should be written.
+ * @param flags Additional flags about how the object should be written.
+ * May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}.
+ */
+ @Override
+ public void writeToParcel(@NonNull Parcel dest, int flags) {
+ dest.writeBundle(mCharacteristics);
+ }
+}
diff --git a/framework/java/android/net/wifi/usd/IUsdManager.aidl b/framework/java/android/net/wifi/usd/IUsdManager.aidl
index 4d0ed3da3e..625f9b805d 100644
--- a/framework/java/android/net/wifi/usd/IUsdManager.aidl
+++ b/framework/java/android/net/wifi/usd/IUsdManager.aidl
@@ -16,6 +16,7 @@
package android.net.wifi.usd;
+import android.net.wifi.usd.Characteristics;
import android.net.wifi.usd.IAvailabilityCallback;
/**
@@ -30,4 +31,5 @@ interface IUsdManager {
boolean isPublisherAvailable();
void registerAvailabilityCallback(IAvailabilityCallback callback);
void unregisterAvailabilityCallback(IAvailabilityCallback callback);
+ Characteristics getCharacteristics();
}
diff --git a/framework/java/android/net/wifi/usd/UsdManager.java b/framework/java/android/net/wifi/usd/UsdManager.java
index bcb23a2d28..a2e4217376 100644
--- a/framework/java/android/net/wifi/usd/UsdManager.java
+++ b/framework/java/android/net/wifi/usd/UsdManager.java
@@ -21,6 +21,7 @@ import static android.Manifest.permission.MANAGE_WIFI_NETWORK_SELECTION;
import android.annotation.CallbackExecutor;
import android.annotation.FlaggedApi;
import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.annotation.RequiresApi;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
@@ -255,4 +256,23 @@ public class UsdManager {
}
}
}
+
+ /**
+ * Gets the characteristics of USD: a set of parameters which specify limitations on
+ * configurations, e.g. maximum service name length.
+ *
+ * @return An object specifying the configuration limitation of USD. Return {@code null} if
+ * USD feature is not supported.
+ */
+ @RequiresPermission(MANAGE_WIFI_NETWORK_SELECTION)
+ public @Nullable Characteristics getCharacteristics() {
+ if (!Environment.isSdkAtLeastB()) {
+ throw new UnsupportedOperationException();
+ }
+ try {
+ return mService.getCharacteristics();
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
}
diff --git a/service/java/com/android/server/wifi/usd/UsdServiceImpl.java b/service/java/com/android/server/wifi/usd/UsdServiceImpl.java
index 2bbaa5a536..e0d340045f 100644
--- a/service/java/com/android/server/wifi/usd/UsdServiceImpl.java
+++ b/service/java/com/android/server/wifi/usd/UsdServiceImpl.java
@@ -18,10 +18,12 @@ package com.android.server.wifi.usd;
import android.annotation.NonNull;
import android.content.Context;
+import android.net.wifi.usd.Characteristics;
import android.net.wifi.usd.IAvailabilityCallback;
import android.net.wifi.usd.IUsdManager;
import android.net.wifi.usd.UsdManager;
import android.os.Binder;
+import android.os.Bundle;
import android.util.Log;
import com.android.server.wifi.RunnerHandler;
@@ -146,4 +148,23 @@ public class UsdServiceImpl extends IUsdManager.Stub {
throw new SecurityException("App not allowed to use USD (uid = " + uid + ")");
}
}
+
+ /**
+ * See {@link UsdManager#getCharacteristics()}
+ */
+ @Override
+ public Characteristics getCharacteristics() {
+ int uid = getMockableCallingUid();
+ if (!mWifiPermissionsUtil.checkManageWifiNetworkSelectionPermission(uid)) {
+ throw new SecurityException("App not allowed to use USD (uid = " + uid + ")");
+ }
+
+ Bundle bundle = new Bundle();
+ bundle.putInt(Characteristics.KEY_MAX_NUM_SUBSCRIBE_SESSIONS, 0);
+ bundle.putInt(Characteristics.KEY_MAX_NUM_SUBSCRIBE_SESSIONS, 0);
+ bundle.putInt(Characteristics.KEY_MAX_SERVICE_SPECIFIC_INFO_LENGTH, 0);
+ bundle.putInt(Characteristics.KEY_MAX_MATCH_FILTER_LENGTH, 0);
+ bundle.putInt(Characteristics.KEY_MAX_SERVICE_NAME_LENGTH, 0);
+ return new Characteristics(bundle);
+ }
}