diff options
| author | Remi NGUYEN VAN <reminv@google.com> | 2019-01-10 21:15:28 -0800 |
|---|---|---|
| committer | android-build-merger <android-build-merger@google.com> | 2019-01-10 21:15:28 -0800 |
| commit | 8ecc6c9e32e2fee5331ed0744447f12e498fe652 (patch) | |
| tree | cc419d3b2acce956c1c3967064cc129c76109bd4 /core/java/android | |
| parent | fc9a19cb135a2ace7510704ca741a23b6c72ef4b (diff) | |
| parent | 81552d610a297edc8ebe93f997d587a1fa4c44de (diff) | |
Merge "Move NetworkMonitor to NetworkStack"
am: 81552d610a
Change-Id: If5c2c104bc53a565e89e625b1edce0b976a295f3
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/net/ConnectivityManager.java | 10 | ||||
| -rw-r--r-- | core/java/android/net/IConnectivityManager.aidl | 2 | ||||
| -rw-r--r-- | core/java/android/net/INetworkMonitor.aidl | 45 | ||||
| -rw-r--r-- | core/java/android/net/INetworkMonitorCallbacks.aidl | 29 | ||||
| -rw-r--r-- | core/java/android/net/INetworkStackConnector.aidl | 2 | ||||
| -rw-r--r-- | core/java/android/net/NetworkStack.java | 30 | ||||
| -rw-r--r-- | core/java/android/net/PrivateDnsConfigParcel.aidl | 22 |
7 files changed, 134 insertions, 6 deletions
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index 436b4a15e7c1..abc00feeb212 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -2051,6 +2051,16 @@ public class ConnectivityManager { return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); } + /** @hide */ + public NetworkRequest getDefaultRequest() { + try { + // This is not racy as the default request is final in ConnectivityService. + return mService.getDefaultRequest(); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + /* TODO: These permissions checks don't belong in client-side code. Move them to * services.jar, possibly in com.android.server.net. */ diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl index e7d441df82a6..da5d96e49d02 100644 --- a/core/java/android/net/IConnectivityManager.aidl +++ b/core/java/android/net/IConnectivityManager.aidl @@ -167,6 +167,8 @@ interface IConnectivityManager int getMultipathPreference(in Network Network); + NetworkRequest getDefaultRequest(); + int getRestoreDefaultNetworkDelay(int networkType); boolean addVpnAddress(String address, int prefixLength); diff --git a/core/java/android/net/INetworkMonitor.aidl b/core/java/android/net/INetworkMonitor.aidl new file mode 100644 index 000000000000..41f969acad6f --- /dev/null +++ b/core/java/android/net/INetworkMonitor.aidl @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2018, 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 perNmissions and + * limitations under the License. + */ +package android.net; + +import android.net.PrivateDnsConfigParcel; + +/** @hide */ +oneway interface INetworkMonitor { + // After a network has been tested this result can be sent with EVENT_NETWORK_TESTED. + // The network should be used as a default internet connection. It was found to be: + // 1. a functioning network providing internet access, or + // 2. a captive portal and the user decided to use it as is. + const int NETWORK_TEST_RESULT_VALID = 0; + + // After a network has been tested this result can be sent with EVENT_NETWORK_TESTED. + // The network should not be used as a default internet connection. It was found to be: + // 1. a captive portal and the user is prompted to sign-in, or + // 2. a captive portal and the user did not want to use it, or + // 3. a broken network (e.g. DNS failed, connect failed, HTTP request failed). + const int NETWORK_TEST_RESULT_INVALID = 1; + + void start(); + void launchCaptivePortalApp(); + void forceReevaluation(int uid); + void notifyPrivateDnsChanged(in PrivateDnsConfigParcel config); + void notifyDnsResponse(int returnCode); + void notifySystemReady(); + void notifyNetworkConnected(); + void notifyNetworkDisconnected(); + void notifyLinkPropertiesChanged(); + void notifyNetworkCapabilitiesChanged(); +}
\ No newline at end of file diff --git a/core/java/android/net/INetworkMonitorCallbacks.aidl b/core/java/android/net/INetworkMonitorCallbacks.aidl new file mode 100644 index 000000000000..0bc25750129b --- /dev/null +++ b/core/java/android/net/INetworkMonitorCallbacks.aidl @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2018 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.net.INetworkMonitor; +import android.net.PrivateDnsConfigParcel; + +/** @hide */ +oneway interface INetworkMonitorCallbacks { + void onNetworkMonitorCreated(in INetworkMonitor networkMonitor); + void notifyNetworkTested(int testResult, @nullable String redirectUrl); + void notifyPrivateDnsConfigResolved(in PrivateDnsConfigParcel config); + void showProvisioningNotification(String action); + void hideProvisioningNotification(); +}
\ No newline at end of file diff --git a/core/java/android/net/INetworkStackConnector.aidl b/core/java/android/net/INetworkStackConnector.aidl index be0dc07f4b23..2df8ab7ec198 100644 --- a/core/java/android/net/INetworkStackConnector.aidl +++ b/core/java/android/net/INetworkStackConnector.aidl @@ -15,6 +15,7 @@ */ package android.net; +import android.net.INetworkMonitorCallbacks; import android.net.dhcp.DhcpServingParamsParcel; import android.net.dhcp.IDhcpServerCallbacks; @@ -22,4 +23,5 @@ import android.net.dhcp.IDhcpServerCallbacks; oneway interface INetworkStackConnector { void makeDhcpServer(in String ifName, in DhcpServingParamsParcel params, in IDhcpServerCallbacks cb); + void makeNetworkMonitor(int netId, String name, in INetworkMonitorCallbacks cb); }
\ No newline at end of file diff --git a/core/java/android/net/NetworkStack.java b/core/java/android/net/NetworkStack.java index d4a0ec632383..2eac6de56346 100644 --- a/core/java/android/net/NetworkStack.java +++ b/core/java/android/net/NetworkStack.java @@ -48,14 +48,16 @@ import java.util.ArrayList; public class NetworkStack { private static final String TAG = NetworkStack.class.getSimpleName(); + public static final String NETWORKSTACK_PACKAGE_NAME = "com.android.mainline.networkstack"; + @NonNull @GuardedBy("mPendingNetStackRequests") - private final ArrayList<NetworkStackRequest> mPendingNetStackRequests = new ArrayList<>(); + private final ArrayList<NetworkStackCallback> mPendingNetStackRequests = new ArrayList<>(); @Nullable @GuardedBy("mPendingNetStackRequests") private INetworkStackConnector mConnector; - private interface NetworkStackRequest { + private interface NetworkStackCallback { void onNetworkStackConnected(INetworkStackConnector connector); } @@ -77,6 +79,21 @@ public class NetworkStack { }); } + /** + * Create a NetworkMonitor. + * + * <p>The INetworkMonitor will be returned asynchronously through the provided callbacks. + */ + public void makeNetworkMonitor(Network network, String name, INetworkMonitorCallbacks cb) { + requestConnector(connector -> { + try { + connector.makeNetworkMonitor(network.netId, name, cb); + } catch (RemoteException e) { + e.rethrowFromSystemServer(); + } + }); + } + private class NetworkStackConnection implements ServiceConnection { @Override public void onServiceConnected(ComponentName name, IBinder service) { @@ -96,14 +113,14 @@ public class NetworkStack { ServiceManager.addService(Context.NETWORK_STACK_SERVICE, service, false /* allowIsolated */, DUMP_FLAG_PRIORITY_HIGH | DUMP_FLAG_PRIORITY_NORMAL); - final ArrayList<NetworkStackRequest> requests; + final ArrayList<NetworkStackCallback> requests; synchronized (mPendingNetStackRequests) { requests = new ArrayList<>(mPendingNetStackRequests); mPendingNetStackRequests.clear(); mConnector = connector; } - for (NetworkStackRequest r : requests) { + for (NetworkStackCallback r : requests) { r.onNetworkStackConnected(connector); } } @@ -124,7 +141,8 @@ public class NetworkStack { "com.android.server.NetworkStackService", true /* initialize */, context.getClassLoader()); - connector = (IBinder) service.getMethod("makeConnector").invoke(null); + connector = (IBinder) service.getMethod("makeConnector", Context.class) + .invoke(null, context); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { Slog.wtf(TAG, "Could not create network stack connector from NetworkStackService"); // TODO: crash/reboot system here ? @@ -153,7 +171,7 @@ public class NetworkStack { } // TODO: use this method to obtain the connector when implementing network stack operations - private void requestConnector(@NonNull NetworkStackRequest request) { + private void requestConnector(@NonNull NetworkStackCallback request) { // TODO: PID check. if (Binder.getCallingUid() != Process.SYSTEM_UID) { // Don't even attempt to obtain the connector and give a nice error message diff --git a/core/java/android/net/PrivateDnsConfigParcel.aidl b/core/java/android/net/PrivateDnsConfigParcel.aidl new file mode 100644 index 000000000000..b52fce643302 --- /dev/null +++ b/core/java/android/net/PrivateDnsConfigParcel.aidl @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2018 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 PrivateDnsConfigParcel { + String hostname; + String[] ips; +} |
