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 | */ |
markchien | 6d06f6d | 2019-12-16 20:15:20 +0800 | [diff] [blame^] | 42 | public abstract class TetheringDependencies { |
markchien | 0df2ebc4 | 2019-09-30 14:40:57 +0800 | [diff] [blame] | 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 | */ |
markchien | 6d06f6d | 2019-12-16 20:15:20 +0800 | [diff] [blame^] | 69 | public abstract IpServer.Dependencies getIpServerDependencies(); |
markchien | 0df2ebc4 | 2019-09-30 14:40:57 +0800 | [diff] [blame] | 70 | |
| 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 | */ |
markchien | 6d06f6d | 2019-12-16 20:15:20 +0800 | [diff] [blame^] | 81 | public abstract NetworkRequest getDefaultNetworkRequest(); |
markchien | 0df2ebc4 | 2019-09-30 14:40:57 +0800 | [diff] [blame] | 82 | |
| 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 | */ |
markchien | 6d06f6d | 2019-12-16 20:15:20 +0800 | [diff] [blame^] | 137 | public abstract Looper getTetheringLooper(); |
markchien | 0df2ebc4 | 2019-09-30 14:40:57 +0800 | [diff] [blame] | 138 | |
| 139 | /** |
| 140 | * Get Context of TetheringSerice. |
| 141 | */ |
markchien | 6d06f6d | 2019-12-16 20:15:20 +0800 | [diff] [blame^] | 142 | public abstract Context getContext(); |
markchien | 0df2ebc4 | 2019-09-30 14:40:57 +0800 | [diff] [blame] | 143 | } |