blob: b16b3294a1125c82b7443faf64e80bd91133dcf0 [file] [log] [blame]
markchien0df2ebc42019-09-30 14:40:57 +08001/*
2 * Copyright (C) 2017 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
17package com.android.server.connectivity.tethering;
18
19import android.content.Context;
20import android.net.INetd;
21import android.net.INetworkPolicyManager;
22import android.net.INetworkStatsService;
23import android.net.NetworkRequest;
24import android.net.ip.IpServer;
25import android.net.util.SharedLog;
26import android.os.Handler;
27import android.os.IBinder;
28import android.os.INetworkManagementService;
29import android.os.Looper;
30import android.os.ServiceManager;
31
32import com.android.internal.util.StateMachine;
33
34import java.util.ArrayList;
35
36
37/**
38 * Capture tethering dependencies, for injection.
39 *
40 * @hide
41 */
markchien6d06f6d2019-12-16 20:15:20 +080042public abstract class TetheringDependencies {
markchien0df2ebc42019-09-30 14:40:57 +080043 /**
44 * Get a reference to the offload hardware interface to be used by tethering.
45 */
46 public OffloadHardwareInterface getOffloadHardwareInterface(Handler h, SharedLog log) {
47 return new OffloadHardwareInterface(h, log);
48 }
49
50 /**
51 * Get a reference to the UpstreamNetworkMonitor to be used by tethering.
52 */
53 public UpstreamNetworkMonitor getUpstreamNetworkMonitor(Context ctx, StateMachine target,
54 SharedLog log, int what) {
55 return new UpstreamNetworkMonitor(ctx, target, log, what);
56 }
57
58 /**
59 * Get a reference to the IPv6TetheringCoordinator to be used by tethering.
60 */
61 public IPv6TetheringCoordinator getIPv6TetheringCoordinator(
62 ArrayList<IpServer> notifyList, SharedLog log) {
63 return new IPv6TetheringCoordinator(notifyList, log);
64 }
65
66 /**
67 * Get dependencies to be used by IpServer.
68 */
markchien6d06f6d2019-12-16 20:15:20 +080069 public abstract IpServer.Dependencies getIpServerDependencies();
markchien0df2ebc42019-09-30 14:40:57 +080070
71 /**
72 * Indicates whether tethering is supported on the device.
73 */
74 public boolean isTetheringSupported() {
75 return true;
76 }
77
78 /**
79 * Get the NetworkRequest that should be fulfilled by the default network.
80 */
markchien6d06f6d2019-12-16 20:15:20 +080081 public abstract NetworkRequest getDefaultNetworkRequest();
markchien0df2ebc42019-09-30 14:40:57 +080082
83 /**
84 * Get a reference to the EntitlementManager to be used by tethering.
85 */
86 public EntitlementManager getEntitlementManager(Context ctx, StateMachine target,
87 SharedLog log, int what) {
88 return new EntitlementManager(ctx, target, log, what);
89 }
90
91 /**
92 * Generate a new TetheringConfiguration according to input sub Id.
93 */
94 public TetheringConfiguration generateTetheringConfiguration(Context ctx, SharedLog log,
95 int subId) {
96 return new TetheringConfiguration(ctx, log, subId);
97 }
98
99 /**
100 * Get a reference to INetworkManagementService to registerTetheringStatsProvider from
101 * OffloadController. Note: This should be removed soon by Usage refactor work in R
102 * development cycle.
103 */
104 public INetworkManagementService getINetworkManagementService() {
105 return INetworkManagementService.Stub.asInterface(
106 ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
107 }
108
109 /**
110 * Get a reference to INetworkStatsService to force update tethering usage.
111 * Note: This should be removed in R development cycle.
112 */
113 public INetworkStatsService getINetworkStatsService() {
114 return INetworkStatsService.Stub.asInterface(
115 ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
116 }
117
118 /**
119 * Get a reference to INetworkPolicyManager to be used by tethering.
120 */
121 public INetworkPolicyManager getINetworkPolicyManager() {
122 return INetworkPolicyManager.Stub.asInterface(
123 ServiceManager.getService(Context.NETWORK_POLICY_SERVICE));
124 }
125
126 /**
127 * Get a reference to INetd to be used by tethering.
128 */
129 public INetd getINetd(Context context) {
130 return INetd.Stub.asInterface(
131 (IBinder) context.getSystemService(Context.NETD_SERVICE));
132 }
133
134 /**
135 * Get tethering thread looper.
136 */
markchien6d06f6d2019-12-16 20:15:20 +0800137 public abstract Looper getTetheringLooper();
markchien0df2ebc42019-09-30 14:40:57 +0800138
139 /**
140 * Get Context of TetheringSerice.
141 */
markchien6d06f6d2019-12-16 20:15:20 +0800142 public abstract Context getContext();
markchien0df2ebc42019-09-30 14:40:57 +0800143}