markchien | 0df2ebc4 | 2019-09-30 14:40:57 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.connectivity.tethering; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.net.INetd; |
| 21 | import android.net.INetworkPolicyManager; |
| 22 | import android.net.INetworkStatsService; |
| 23 | import android.net.NetworkRequest; |
| 24 | import android.net.ip.IpServer; |
| 25 | import android.net.util.SharedLog; |
| 26 | import android.os.Handler; |
| 27 | import android.os.IBinder; |
| 28 | import android.os.INetworkManagementService; |
| 29 | import android.os.Looper; |
| 30 | import android.os.ServiceManager; |
| 31 | |
| 32 | import com.android.internal.util.StateMachine; |
| 33 | |
| 34 | import java.util.ArrayList; |
| 35 | |
| 36 | |
| 37 | /** |
| 38 | * Capture tethering dependencies, for injection. |
| 39 | * |
| 40 | * @hide |
| 41 | */ |
| 42 | public class TetheringDependencies { |
| 43 | /** |
| 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 | */ |
| 69 | public IpServer.Dependencies getIpServerDependencies() { |
| 70 | return new IpServer.Dependencies(); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Indicates whether tethering is supported on the device. |
| 75 | */ |
| 76 | public boolean isTetheringSupported() { |
| 77 | return true; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Get the NetworkRequest that should be fulfilled by the default network. |
| 82 | */ |
| 83 | public NetworkRequest getDefaultNetworkRequest() { |
| 84 | return null; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Get a reference to the EntitlementManager to be used by tethering. |
| 89 | */ |
| 90 | public EntitlementManager getEntitlementManager(Context ctx, StateMachine target, |
| 91 | SharedLog log, int what) { |
| 92 | return new EntitlementManager(ctx, target, log, what); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Generate a new TetheringConfiguration according to input sub Id. |
| 97 | */ |
| 98 | public TetheringConfiguration generateTetheringConfiguration(Context ctx, SharedLog log, |
| 99 | int subId) { |
| 100 | return new TetheringConfiguration(ctx, log, subId); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Get a reference to INetworkManagementService to registerTetheringStatsProvider from |
| 105 | * OffloadController. Note: This should be removed soon by Usage refactor work in R |
| 106 | * development cycle. |
| 107 | */ |
| 108 | public INetworkManagementService getINetworkManagementService() { |
| 109 | return INetworkManagementService.Stub.asInterface( |
| 110 | ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE)); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Get a reference to INetworkStatsService to force update tethering usage. |
| 115 | * Note: This should be removed in R development cycle. |
| 116 | */ |
| 117 | public INetworkStatsService getINetworkStatsService() { |
| 118 | return INetworkStatsService.Stub.asInterface( |
| 119 | ServiceManager.getService(Context.NETWORK_STATS_SERVICE)); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Get a reference to INetworkPolicyManager to be used by tethering. |
| 124 | */ |
| 125 | public INetworkPolicyManager getINetworkPolicyManager() { |
| 126 | return INetworkPolicyManager.Stub.asInterface( |
| 127 | ServiceManager.getService(Context.NETWORK_POLICY_SERVICE)); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Get a reference to INetd to be used by tethering. |
| 132 | */ |
| 133 | public INetd getINetd(Context context) { |
| 134 | return INetd.Stub.asInterface( |
| 135 | (IBinder) context.getSystemService(Context.NETD_SERVICE)); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Get tethering thread looper. |
| 140 | */ |
| 141 | public Looper getTetheringLooper() { |
| 142 | return null; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Get Context of TetheringSerice. |
| 147 | */ |
| 148 | public Context getContext() { |
| 149 | return null; |
| 150 | } |
| 151 | } |