diff options
| author | 2021-04-16 08:13:03 +0000 | |
|---|---|---|
| committer | 2021-04-16 08:13:03 +0000 | |
| commit | 4911a46b2cb529cfbb113d33409a8b1ca27d167f (patch) | |
| tree | 90962e2c4ba63c8c554809aed615a943543b8ec8 | |
| parent | dddb56c96aa9b13ab7e18e8729b8fb3f0f5cf8d5 (diff) | |
| parent | 3aba6fdd68d4426290c84ad8c0240259c25ee681 (diff) | |
Merge "Don't expose raw IBinder APIs." am: 4b4cc572c0 am: 3aba6fdd68
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1676436
Change-Id: I42ef2c83eefc6dc4967e71be82f48cca38d74f43
5 files changed, 54 insertions, 68 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 4244244e14a1..9e82cfb3257c 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -6101,10 +6101,6 @@ package android.metrics { package android.net { - public class DnsResolverServiceManager { - method @NonNull @RequiresPermission(android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK) public static android.os.IBinder getService(@NonNull android.content.Context); - } - public class EthernetManager { method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_STACK, android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}) public android.net.EthernetManager.TetheredInterfaceRequest requestTetheredInterface(@NonNull java.util.concurrent.Executor, @NonNull android.net.EthernetManager.TetheredInterfaceCallback); } diff --git a/core/java/android/net/DnsResolverServiceManager.java b/core/java/android/net/DnsResolverServiceManager.java deleted file mode 100644 index 15973224f10b..000000000000 --- a/core/java/android/net/DnsResolverServiceManager.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.NonNull; -import android.annotation.RequiresPermission; -import android.annotation.SystemApi; -import android.content.Context; -import android.os.IBinder; -import android.os.ServiceManager; - -import java.util.Objects; - -/** - * Provides a way to obtain the DnsResolver binder objects. - * - * @hide - */ -@SystemApi -public class DnsResolverServiceManager { - /** - * Name to retrieve a {@link android.net.IDnsResolver} IBinder. - */ - private static final String DNS_RESOLVER_SERVICE = "dnsresolver"; - - private DnsResolverServiceManager() {} - - /** - * Get an {@link IBinder} representing the DnsResolver stable AIDL interface - * - * @param context the context for permission check. - * @return {@link android.net.IDnsResolver} IBinder. - */ - @NonNull - @RequiresPermission(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK) - public static IBinder getService(@NonNull final Context context) { - Objects.requireNonNull(context); - context.enforceCallingOrSelfPermission(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, - "DnsResolverServiceManager"); - try { - return ServiceManager.getServiceOrThrow(DNS_RESOLVER_SERVICE); - } catch (ServiceManager.ServiceNotFoundException e) { - // Catch ServiceManager#ServiceNotFoundException and rethrow IllegalStateException - // because ServiceManager#ServiceNotFoundException is @hide so that it can't be listed - // on the system api. Thus, rethrow IllegalStateException if dns resolver service cannot - // be found. - throw new IllegalStateException("Cannot find dns resolver service."); - } - } -} diff --git a/packages/Connectivity/framework/src/android/net/ConnectivityFrameworkInitializer.java b/packages/Connectivity/framework/src/android/net/ConnectivityFrameworkInitializer.java index 92a792b78410..a2e218dcbb4b 100644 --- a/packages/Connectivity/framework/src/android/net/ConnectivityFrameworkInitializer.java +++ b/packages/Connectivity/framework/src/android/net/ConnectivityFrameworkInitializer.java @@ -68,5 +68,11 @@ public final class ConnectivityFrameworkInitializer { return cm.startOrGetTestNetworkManager(); } ); + + SystemServiceRegistry.registerContextAwareService( + DnsResolverServiceManager.DNS_RESOLVER_SERVICE, + DnsResolverServiceManager.class, + (context, serviceBinder) -> new DnsResolverServiceManager(serviceBinder) + ); } } diff --git a/packages/Connectivity/framework/src/android/net/DnsResolverServiceManager.java b/packages/Connectivity/framework/src/android/net/DnsResolverServiceManager.java new file mode 100644 index 000000000000..79009e8d629e --- /dev/null +++ b/packages/Connectivity/framework/src/android/net/DnsResolverServiceManager.java @@ -0,0 +1,45 @@ +/* + * 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.NonNull; +import android.os.IBinder; + +/** + * Provides a way to obtain the DnsResolver binder objects. + * + * @hide + */ +public class DnsResolverServiceManager { + /** Service name for the DNS resolver. Keep in sync with DnsResolverService.h */ + public static final String DNS_RESOLVER_SERVICE = "dnsresolver"; + + private final IBinder mResolver; + + DnsResolverServiceManager(IBinder resolver) { + mResolver = resolver; + } + + /** + * Get an {@link IBinder} representing the DnsResolver stable AIDL interface + * + * @return {@link android.net.IDnsResolver} IBinder. + */ + @NonNull + public IBinder getService() { + return mResolver; + } +} diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index b5aebb111218..a39f8f639163 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -616,7 +616,9 @@ public class ConnectivityService extends IConnectivityManager.Stub } private static IDnsResolver getDnsResolver(Context context) { - return IDnsResolver.Stub.asInterface(DnsResolverServiceManager.getService(context)); + final DnsResolverServiceManager dsm = context.getSystemService( + DnsResolverServiceManager.class); + return IDnsResolver.Stub.asInterface(dsm.getService()); } /** Handler thread used for all of the handlers below. */ |