1 /*
2  * Copyright (C) 2022 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.connectivity;
18 
19 import android.content.Context;
20 import android.net.ConnectivityManager;
21 import android.net.RoutingCoordinatorManager;
22 import android.os.Build;
23 import android.os.IBinder;
24 
25 import androidx.annotation.RequiresApi;
26 
27 /**
28  * Utility providing limited access to module-internal APIs which are only available on Android T+,
29  * as this class is only in the bootclasspath on T+ as part of framework-connectivity.
30  *
31  * R+ module components like Tethering cannot depend on all hidden symbols from
32  * framework-connectivity. They only have access to stable API stubs where newer APIs can be
33  * accessed after an API level check (enforced by the linter), or to limited hidden symbols in this
34  * class which is also annotated with @RequiresApi (so API level checks are also enforced by the
35  * linter).
36  * @hide
37  */
38 @RequiresApi(Build.VERSION_CODES.S)
39 public class ConnectivityInternalApiUtil {
40 
41     /**
42      * Get a service binder token for
43      * {@link com.android.server.connectivity.wear.CompanionDeviceManagerProxyService}.
44      */
45     @RequiresApi(Build.VERSION_CODES.TIRAMISU)
getCompanionDeviceManagerProxyService(Context ctx)46     public static IBinder getCompanionDeviceManagerProxyService(Context ctx) {
47         final ConnectivityManager cm = ctx.getSystemService(ConnectivityManager.class);
48         return cm.getCompanionDeviceManagerProxyService();
49     }
50 
51     /**
52      * Obtain a routing coordinator manager from a context, possibly cross-module.
53      * @param ctx the context
54      * @return an instance of the coordinator manager
55      */
56     @RequiresApi(Build.VERSION_CODES.S)
getRoutingCoordinatorManager(Context ctx)57     public static RoutingCoordinatorManager getRoutingCoordinatorManager(Context ctx) {
58         final ConnectivityManager cm = ctx.getSystemService(ConnectivityManager.class);
59         return cm.getRoutingCoordinatorManager();
60     }
61 }
62