summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorJames Mattis <jmattis@google.com>2020-11-06 19:19:46 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-11-06 19:19:46 +0000
commit15c0e3c9d503bd2a1ae48e840eb5ae6bb9b237ca (patch)
tree27b17ade331d89c38f3af29186e62a2991336927 /core/java
parent6af2ef3ce67f2914692afba7c2e58ead8a56dc61 (diff)
parentab220aa956c16dad7284bb19fa4214f1585aa1cc (diff)
Merge "Adding API stubs for application network routing" am: 20a9e59e25 am: e92d8a7865 am: ab220aa956
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1478963 Change-Id: I22f8b7b15a0bc7643474f5119dd34cdddf5a8376
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/net/ConnectivityManager.java5
-rw-r--r--core/java/android/net/OemNetworkPreferences.aidl19
-rw-r--r--core/java/android/net/OemNetworkPreferences.java189
3 files changed, 213 insertions, 0 deletions
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index 9b68d3f4f841..c28a901fba75 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -4816,4 +4816,9 @@ public class ConnectivityManager {
e.rethrowFromSystemServer();
}
}
+
+ private void setOemNetworkPreference(@NonNull OemNetworkPreferences preference) {
+ Log.d(TAG, "setOemNetworkPreference called with preference: "
+ + preference.toString());
+ }
}
diff --git a/core/java/android/net/OemNetworkPreferences.aidl b/core/java/android/net/OemNetworkPreferences.aidl
new file mode 100644
index 000000000000..2b6a4ceef592
--- /dev/null
+++ b/core/java/android/net/OemNetworkPreferences.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2020 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;
+
+parcelable OemNetworkPreferences;
diff --git a/core/java/android/net/OemNetworkPreferences.java b/core/java/android/net/OemNetworkPreferences.java
new file mode 100644
index 000000000000..07789433fbe7
--- /dev/null
+++ b/core/java/android/net/OemNetworkPreferences.java
@@ -0,0 +1,189 @@
+/*
+ * Copyright (C) 2020 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;
+
+import android.annotation.IntDef;
+import android.annotation.NonNull;
+import android.os.Parcelable;
+import android.util.SparseArray;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+/** @hide */
+public final class OemNetworkPreferences implements Parcelable {
+ /**
+ * Use default behavior requesting networks. Equivalent to not setting any preference at all.
+ */
+ public static final int OEM_NETWORK_PREFERENCE_DEFAULT = 0;
+
+ /**
+ * Prefer networks in order: NET_CAPABILITY_NOT_METERED, NET_CAPABILITY_OEM_PAID, default.
+ */
+ public static final int OEM_NETWORK_PREFERENCE_OEM_PAID = 1;
+
+ /**
+ * Prefer networks in order: NET_CAPABILITY_NOT_METERED, NET_CAPABILITY_OEM_PAID.
+ */
+ public static final int OEM_NETWORK_PREFERENCE_OEM_PAID_NO_FALLBACK = 2;
+
+ /**
+ * Prefer only NET_CAPABILITY_OEM_PAID networks.
+ */
+ public static final int OEM_NETWORK_PREFERENCE_OEM_PAID_ONLY = 3;
+
+ /**
+ * Prefer only NET_CAPABILITY_OEM_PRIVATE networks.
+ */
+ public static final int OEM_NETWORK_PREFERENCE_OEM_PRIVATE_ONLY = 4;
+
+ @NonNull
+ private final SparseArray<List<String>> mNetworkMappings;
+
+ @NonNull
+ public SparseArray<List<String>> getNetworkPreferences() {
+ return mNetworkMappings.clone();
+ }
+
+ private OemNetworkPreferences(@NonNull SparseArray<List<String>> networkMappings) {
+ Objects.requireNonNull(networkMappings);
+ mNetworkMappings = networkMappings.clone();
+ }
+
+ @Override
+ public String toString() {
+ return "OemNetworkPreferences{" + "mNetworkMappings=" + mNetworkMappings + '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ OemNetworkPreferences that = (OemNetworkPreferences) o;
+
+ return mNetworkMappings.size() == that.mNetworkMappings.size()
+ && mNetworkMappings.toString().equals(that.mNetworkMappings.toString());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mNetworkMappings);
+ }
+
+ /**
+ * Builder used to create {@link OemNetworkPreferences} objects. Specify the preferred Network
+ * to package name mappings.
+ *
+ * @hide
+ */
+ public static final class Builder {
+ private final SparseArray<List<String>> mNetworkMappings;
+
+ public Builder() {
+ mNetworkMappings = new SparseArray<>();
+ }
+
+ /**
+ * Add a network preference for a list of packages.
+ *
+ * @param preference the desired network preference to use
+ * @param packages full package names (e.g.: "com.google.apps.contacts") for apps to use
+ * the given preference
+ * @return The builder to facilitate chaining.
+ */
+ @NonNull
+ public Builder addNetworkPreference(@OemNetworkPreference final int preference,
+ @NonNull List<String> packages) {
+ Objects.requireNonNull(packages);
+ mNetworkMappings.put(preference,
+ Collections.unmodifiableList(new ArrayList<>(packages)));
+ return this;
+ }
+
+ /**
+ * Build {@link OemNetworkPreferences} return the current OEM network preferences.
+ */
+ @NonNull
+ public OemNetworkPreferences build() {
+ return new OemNetworkPreferences(mNetworkMappings);
+ }
+ }
+
+ /** @hide */
+ @IntDef(prefix = "OEM_NETWORK_PREFERENCE_", value = {
+ OEM_NETWORK_PREFERENCE_DEFAULT,
+ OEM_NETWORK_PREFERENCE_OEM_PAID,
+ OEM_NETWORK_PREFERENCE_OEM_PAID_NO_FALLBACK,
+ OEM_NETWORK_PREFERENCE_OEM_PAID_ONLY,
+ OEM_NETWORK_PREFERENCE_OEM_PRIVATE_ONLY
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface OemNetworkPreference {}
+
+ /**
+ * Return the string value for OemNetworkPreference
+ *
+ * @param value int value of OemNetworkPreference
+ * @return string version of OemNetworkPreference
+ */
+ @NonNull
+ public static String oemNetworkPreferenceToString(@OemNetworkPreference int value) {
+ switch (value) {
+ case OEM_NETWORK_PREFERENCE_DEFAULT:
+ return "OEM_NETWORK_PREFERENCE_DEFAULT";
+ case OEM_NETWORK_PREFERENCE_OEM_PAID:
+ return "OEM_NETWORK_PREFERENCE_OEM_PAID";
+ case OEM_NETWORK_PREFERENCE_OEM_PAID_NO_FALLBACK:
+ return "OEM_NETWORK_PREFERENCE_OEM_PAID_NO_FALLBACK";
+ case OEM_NETWORK_PREFERENCE_OEM_PAID_ONLY:
+ return "OEM_NETWORK_PREFERENCE_OEM_PAID_ONLY";
+ case OEM_NETWORK_PREFERENCE_OEM_PRIVATE_ONLY:
+ return "OEM_NETWORK_PREFERENCE_OEM_PRIVATE_ONLY";
+ default:
+ return Integer.toHexString(value);
+ }
+ }
+
+ @Override
+ public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
+ dest.writeSparseArray(mNetworkMappings);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @NonNull
+ public static final Parcelable.Creator<OemNetworkPreferences> CREATOR =
+ new Parcelable.Creator<OemNetworkPreferences>() {
+ @Override
+ public OemNetworkPreferences[] newArray(int size) {
+ return new OemNetworkPreferences[size];
+ }
+
+ @Override
+ public OemNetworkPreferences createFromParcel(@NonNull android.os.Parcel in) {
+ return new OemNetworkPreferences(
+ in.readSparseArray(getClass().getClassLoader()));
+ }
+ };
+}