1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.net; 18 19 import android.annotation.SystemApi; 20 import android.app.SystemServiceRegistry; 21 import android.app.usage.NetworkStatsManager; 22 import android.content.Context; 23 import android.net.mdns.aidl.IMDns; 24 import android.net.nsd.INsdManager; 25 import android.net.nsd.MDnsManager; 26 import android.net.nsd.NsdManager; 27 28 /** 29 * Class for performing registration for Connectivity services which are exposed via updatable APIs 30 * since Android T. 31 * 32 * @hide 33 */ 34 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) 35 public final class ConnectivityFrameworkInitializerTiramisu { ConnectivityFrameworkInitializerTiramisu()36 private ConnectivityFrameworkInitializerTiramisu() {} 37 38 /** 39 * Called by {@link SystemServiceRegistry}'s static initializer and registers NetworkStats, nsd, 40 * ipsec and ethernet services to {@link Context}, so that {@link Context#getSystemService} can 41 * return them. 42 * 43 * @throws IllegalStateException if this is called anywhere besides 44 * {@link SystemServiceRegistry}. 45 */ registerServiceWrappers()46 public static void registerServiceWrappers() { 47 SystemServiceRegistry.registerContextAwareService( 48 Context.NSD_SERVICE, 49 NsdManager.class, 50 (context, serviceBinder) -> { 51 INsdManager service = INsdManager.Stub.asInterface(serviceBinder); 52 return new NsdManager(context, service); 53 } 54 ); 55 56 SystemServiceRegistry.registerContextAwareService( 57 Context.IPSEC_SERVICE, 58 IpSecManager.class, 59 (context, serviceBinder) -> { 60 IIpSecService service = IIpSecService.Stub.asInterface(serviceBinder); 61 return new IpSecManager(context, service); 62 } 63 ); 64 65 SystemServiceRegistry.registerContextAwareService( 66 Context.NETWORK_STATS_SERVICE, 67 NetworkStatsManager.class, 68 (context, serviceBinder) -> { 69 INetworkStatsService service = 70 INetworkStatsService.Stub.asInterface(serviceBinder); 71 return new NetworkStatsManager(context, service); 72 } 73 ); 74 75 SystemServiceRegistry.registerContextAwareService( 76 Context.ETHERNET_SERVICE, 77 EthernetManager.class, 78 (context, serviceBinder) -> { 79 IEthernetManager service = IEthernetManager.Stub.asInterface(serviceBinder); 80 return new EthernetManager(context, service); 81 } 82 ); 83 84 SystemServiceRegistry.registerStaticService( 85 MDnsManager.MDNS_SERVICE, 86 MDnsManager.class, 87 (serviceBinder) -> { 88 IMDns service = IMDns.Stub.asInterface(serviceBinder); 89 return new MDnsManager(service); 90 } 91 ); 92 } 93 } 94