diff options
| author | Paul Hu <paulhu@google.com> | 2020-12-29 03:45:34 +0000 |
|---|---|---|
| committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-12-29 03:45:34 +0000 |
| commit | 7b848d34b72f8a4c95f90df3851e240414ab7b26 (patch) | |
| tree | 37cf6aa69d74cd3f1d997968f57add1e268df68b /core/java/android | |
| parent | 6d432142ed8651f372bad262e699723ea2b708d5 (diff) | |
| parent | 206c66213e9a35ad906d1dce37dc670bab0d5a8a (diff) | |
Merge "Add DnsResolverServiceManager" am: 6bc7032b85 am: b3ea5a5a71 am: 206c66213e
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1465502
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: Ia89725249d9d6fca7a56b426a4bcb024ac8b1bb8
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/net/DnsResolverServiceManager.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/core/java/android/net/DnsResolverServiceManager.java b/core/java/android/net/DnsResolverServiceManager.java new file mode 100644 index 000000000000..15973224f10b --- /dev/null +++ b/core/java/android/net/DnsResolverServiceManager.java @@ -0,0 +1,63 @@ +/* + * 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."); + } + } +} |
