diff options
Diffstat (limited to 'src/com/android/server')
-rw-r--r-- | src/com/android/server/NetworkStackService.java | 27 | ||||
-rw-r--r-- | src/com/android/server/connectivity/NetworkMonitor.java | 16 |
2 files changed, 38 insertions, 5 deletions
diff --git a/src/com/android/server/NetworkStackService.java b/src/com/android/server/NetworkStackService.java index 1f6631b..5ab2744 100644 --- a/src/com/android/server/NetworkStackService.java +++ b/src/com/android/server/NetworkStackService.java @@ -43,6 +43,8 @@ import android.net.ip.IIpClientCallbacks; import android.net.ip.IpClient; import android.net.shared.PrivateDnsConfig; import android.net.util.SharedLog; +import android.os.Build; +import android.os.HandlerThread; import android.os.IBinder; import android.os.RemoteException; import android.util.ArraySet; @@ -53,6 +55,8 @@ import androidx.annotation.VisibleForTesting; import com.android.internal.annotations.GuardedBy; import com.android.internal.util.IndentingPrintWriter; +import com.android.networkstack.NetworkStackNotifier; +import com.android.networkstack.apishim.ShimUtils; import com.android.server.connectivity.NetworkMonitor; import com.android.server.connectivity.ipmemorystore.IpMemoryStoreService; import com.android.server.util.PermissionUtil; @@ -103,6 +107,11 @@ public class NetworkStackService extends Service { * Get an instance of the IpMemoryStoreService. */ IIpMemoryStore getIpMemoryStoreService(); + + /** + * Get an instance of the NetworkNotifier. + */ + NetworkStackNotifier getNotifier(); } /** @@ -119,6 +128,8 @@ public class NetworkStackService extends Service { @GuardedBy("mIpClients") private final ArrayList<WeakReference<IpClient>> mIpClients = new ArrayList<>(); private final IpMemoryStoreService mIpMemoryStoreService; + @Nullable + private final NetworkStackNotifier mNotifier; private static final int MAX_VALIDATION_LOGS = 10; @GuardedBy("mValidationLogs") @@ -164,6 +175,15 @@ public class NetworkStackService extends Service { (IBinder) context.getSystemService(Context.NETD_SERVICE)); mObserverRegistry = new NetworkObserverRegistry(); mIpMemoryStoreService = new IpMemoryStoreService(context); + // NetworkStackNotifier only shows notifications relevant for API level > Q + if (ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)) { + final HandlerThread notifierThread = new HandlerThread( + NetworkStackNotifier.class.getSimpleName()); + notifierThread.start(); + mNotifier = new NetworkStackNotifier(context, notifierThread.getLooper()); + } else { + mNotifier = null; + } int netdVersion; try { @@ -220,7 +240,7 @@ public class NetworkStackService extends Service { mPermChecker.enforceNetworkStackCallingPermission(); updateSystemAidlVersion(cb.getInterfaceVersion()); final SharedLog log = addValidationLogs(network, name); - final NetworkMonitor nm = new NetworkMonitor(mContext, cb, network, log); + final NetworkMonitor nm = new NetworkMonitor(mContext, cb, network, log, this); cb.onNetworkMonitorCreated(new NetworkMonitorConnector(nm, mPermChecker)); } @@ -250,6 +270,11 @@ public class NetworkStackService extends Service { } @Override + public NetworkStackNotifier getNotifier() { + return mNotifier; + } + + @Override public void fetchIpMemoryStore(@NonNull final IIpMemoryStoreCallbacks cb) throws RemoteException { mPermChecker.enforceNetworkStackCallingPermission(); diff --git a/src/com/android/server/connectivity/NetworkMonitor.java b/src/com/android/server/connectivity/NetworkMonitor.java index 18b8c77..e914a55 100644 --- a/src/com/android/server/connectivity/NetworkMonitor.java +++ b/src/com/android/server/connectivity/NetworkMonitor.java @@ -145,6 +145,7 @@ import com.android.internal.util.RingBufferIndices; import com.android.internal.util.State; import com.android.internal.util.StateMachine; import com.android.internal.util.TrafficStatsConstants; +import com.android.networkstack.NetworkStackNotifier; import com.android.networkstack.R; import com.android.networkstack.apishim.CaptivePortalDataShim; import com.android.networkstack.apishim.CaptivePortalDataShimImpl; @@ -155,6 +156,7 @@ import com.android.networkstack.metrics.DataStallDetectionStats; import com.android.networkstack.metrics.DataStallStatsUtils; import com.android.networkstack.netlink.TcpSocketTracker; import com.android.networkstack.util.DnsUtils; +import com.android.server.NetworkStackService.NetworkStackServiceManager; import org.json.JSONException; import org.json.JSONObject; @@ -348,6 +350,8 @@ public class NetworkMonitor extends StateMachine { private final TelephonyManager mTelephonyManager; private final WifiManager mWifiManager; private final ConnectivityManager mCm; + @Nullable + private final NetworkStackNotifier mNotifier; private final IpConnectivityLog mMetricsLog; private final Dependencies mDependencies; private final DataStallStatsUtils mDetectionStatsUtils; @@ -431,8 +435,8 @@ public class NetworkMonitor extends StateMachine { } public NetworkMonitor(Context context, INetworkMonitorCallbacks cb, Network network, - SharedLog validationLog) { - this(context, cb, network, new IpConnectivityLog(), validationLog, + SharedLog validationLog, @NonNull NetworkStackServiceManager serviceManager) { + this(context, cb, network, new IpConnectivityLog(), validationLog, serviceManager, Dependencies.DEFAULT, new DataStallStatsUtils(), getTcpSocketTrackerOrNull(context, network)); } @@ -440,8 +444,8 @@ public class NetworkMonitor extends StateMachine { @VisibleForTesting public NetworkMonitor(Context context, INetworkMonitorCallbacks cb, Network network, IpConnectivityLog logger, SharedLog validationLogs, - Dependencies deps, DataStallStatsUtils detectionStatsUtils, - @Nullable TcpSocketTracker tst) { + @NonNull NetworkStackServiceManager serviceManager, Dependencies deps, + DataStallStatsUtils detectionStatsUtils, @Nullable TcpSocketTracker tst) { // Add suffix indicating which NetworkMonitor we're talking about. super(TAG + "/" + network.toString()); @@ -461,6 +465,7 @@ public class NetworkMonitor extends StateMachine { mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + mNotifier = serviceManager.getNotifier(); // CHECKSTYLE:OFF IndentationCheck addState(mDefaultState); @@ -962,6 +967,9 @@ public class NetworkMonitor extends StateMachine { } appExtras.putString(ConnectivityManager.EXTRA_CAPTIVE_PORTAL_USER_AGENT, mCaptivePortalUserAgent); + if (mNotifier != null) { + mNotifier.notifyCaptivePortalValidationPending(network); + } mCm.startCaptivePortalApp(network, appExtras); return HANDLED; default: |