Loading src/com/android/server/NetworkStackService.java +6 −0 Original line number Diff line number Diff line Loading @@ -246,6 +246,12 @@ public class NetworkStackService extends Service { mNm.launchCaptivePortalApp(); } @Override public void notifyCaptivePortalAppFinished(int response) { checkNetworkStackCallingPermission(); mNm.notifyCaptivePortalAppFinished(response); } @Override public void forceReevaluation(int uid) { checkNetworkStackCallingPermission(); Loading src/com/android/server/connectivity/NetworkMonitor.java +10 −26 Original line number Diff line number Diff line Loading @@ -39,9 +39,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.CaptivePortal; import android.net.ConnectivityManager; import android.net.ICaptivePortal; import android.net.INetworkMonitor; import android.net.INetworkMonitorCallbacks; import android.net.LinkProperties; Loading Loading @@ -460,6 +458,13 @@ public class NetworkMonitor extends StateMachine { sendMessage(CMD_LAUNCH_CAPTIVE_PORTAL_APP); } /** * Notify that the captive portal app was closed with the provided response code. */ public void notifyCaptivePortalAppFinished(int response) { sendMessage(CMD_CAPTIVE_PORTAL_APP_FINISHED, response); } @Override protected void log(String s) { if (DBG) Log.d(TAG + "/" + mNetwork.toString(), s); Loading Loading @@ -671,29 +676,8 @@ public class NetworkMonitor extends StateMachine { case CMD_LAUNCH_CAPTIVE_PORTAL_APP: final Bundle appExtras = new Bundle(); // OneAddressPerFamilyNetwork is not parcelable across processes. appExtras.putParcelable( ConnectivityManager.EXTRA_NETWORK, new Network(mNetwork)); appExtras.putParcelable(ConnectivityManager.EXTRA_CAPTIVE_PORTAL, new CaptivePortal(new ICaptivePortal.Stub() { @Override public void appResponse(int response) { if (response == APP_RETURN_WANTED_AS_IS) { mContext.enforceCallingPermission( PERMISSION_NETWORK_SETTINGS, "CaptivePortal"); } sendMessage(CMD_CAPTIVE_PORTAL_APP_FINISHED, response); } @Override public void logEvent(int eventId, String packageName) throws RemoteException { mContext.enforceCallingPermission( PERMISSION_NETWORK_SETTINGS, "CaptivePortal"); mCallback.logCaptivePortalLoginEvent(eventId, packageName); } })); final Network network = new Network(mNetwork); appExtras.putParcelable(ConnectivityManager.EXTRA_NETWORK, network); final CaptivePortalProbeResult probeRes = mLastPortalProbeResult; appExtras.putString(EXTRA_CAPTIVE_PORTAL_URL, probeRes.detectUrl); if (probeRes.probeSpec != null) { Loading @@ -702,7 +686,7 @@ public class NetworkMonitor extends StateMachine { } appExtras.putString(ConnectivityManager.EXTRA_CAPTIVE_PORTAL_USER_AGENT, mCaptivePortalUserAgent); mCm.startCaptivePortalApp(appExtras); mCm.startCaptivePortalApp(network, appExtras); return HANDLED; default: return NOT_HANDLED; Loading tests/src/com/android/server/connectivity/NetworkMonitorTest.java +15 −14 Original line number Diff line number Diff line Loading @@ -16,8 +16,7 @@ package com.android.server.connectivity; import static android.net.ConnectivityManager.ACTION_CAPTIVE_PORTAL_SIGN_IN; import static android.net.ConnectivityManager.EXTRA_CAPTIVE_PORTAL; import static android.net.CaptivePortal.APP_RETURN_DISMISSED; import static android.net.INetworkMonitor.NETWORK_TEST_RESULT_INVALID; import static android.net.INetworkMonitor.NETWORK_TEST_RESULT_VALID; import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET; Loading @@ -41,8 +40,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.content.Intent; import android.net.CaptivePortal; import android.net.ConnectivityManager; import android.net.INetworkMonitorCallbacks; import android.net.InetAddresses; Loading @@ -54,10 +51,10 @@ import android.net.captiveportal.CaptivePortalProbeResult; import android.net.metrics.IpConnectivityLog; import android.net.util.SharedLog; import android.net.wifi.WifiManager; import android.os.Bundle; import android.os.ConditionVariable; import android.os.Handler; import android.os.SystemClock; import android.os.UserHandle; import android.provider.Settings; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; Loading Loading @@ -487,19 +484,23 @@ public class NetworkMonitorTest { // Check that startCaptivePortalApp sends the expected intent. nm.launchCaptivePortalApp(); final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mContext, timeout(HANDLER_TIMEOUT_MS).times(1)) .startActivityAsUser(intentCaptor.capture(), eq(UserHandle.CURRENT)); final Intent intent = intentCaptor.getValue(); assertEquals(ACTION_CAPTIVE_PORTAL_SIGN_IN, intent.getAction()); final Network network = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK); assertEquals(TEST_NETID, network.netId); final ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class); final ArgumentCaptor<Network> networkCaptor = ArgumentCaptor.forClass(Network.class); verify(mCm, timeout(HANDLER_TIMEOUT_MS).times(1)) .startCaptivePortalApp(networkCaptor.capture(), bundleCaptor.capture()); final Bundle bundle = bundleCaptor.getValue(); final Network bundleNetwork = bundle.getParcelable(ConnectivityManager.EXTRA_NETWORK); assertEquals(TEST_NETID, bundleNetwork.netId); // network is passed both in bundle and as parameter, as the bundle is opaque to the // framework and only intended for the captive portal app, but the framework needs // the network to identify the right NetworkMonitor. assertEquals(TEST_NETID, networkCaptor.getValue().netId); // Have the app report that the captive portal is dismissed, and check that we revalidate. setStatus(mHttpsConnection, 204); setStatus(mHttpConnection, 204); final CaptivePortal captivePortal = intent.getParcelableExtra(EXTRA_CAPTIVE_PORTAL); captivePortal.reportCaptivePortalDismissed(); nm.notifyCaptivePortalAppFinished(APP_RETURN_DISMISSED); verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1)) .notifyNetworkTested(NETWORK_TEST_RESULT_VALID, null); } Loading Loading
src/com/android/server/NetworkStackService.java +6 −0 Original line number Diff line number Diff line Loading @@ -246,6 +246,12 @@ public class NetworkStackService extends Service { mNm.launchCaptivePortalApp(); } @Override public void notifyCaptivePortalAppFinished(int response) { checkNetworkStackCallingPermission(); mNm.notifyCaptivePortalAppFinished(response); } @Override public void forceReevaluation(int uid) { checkNetworkStackCallingPermission(); Loading
src/com/android/server/connectivity/NetworkMonitor.java +10 −26 Original line number Diff line number Diff line Loading @@ -39,9 +39,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.CaptivePortal; import android.net.ConnectivityManager; import android.net.ICaptivePortal; import android.net.INetworkMonitor; import android.net.INetworkMonitorCallbacks; import android.net.LinkProperties; Loading Loading @@ -460,6 +458,13 @@ public class NetworkMonitor extends StateMachine { sendMessage(CMD_LAUNCH_CAPTIVE_PORTAL_APP); } /** * Notify that the captive portal app was closed with the provided response code. */ public void notifyCaptivePortalAppFinished(int response) { sendMessage(CMD_CAPTIVE_PORTAL_APP_FINISHED, response); } @Override protected void log(String s) { if (DBG) Log.d(TAG + "/" + mNetwork.toString(), s); Loading Loading @@ -671,29 +676,8 @@ public class NetworkMonitor extends StateMachine { case CMD_LAUNCH_CAPTIVE_PORTAL_APP: final Bundle appExtras = new Bundle(); // OneAddressPerFamilyNetwork is not parcelable across processes. appExtras.putParcelable( ConnectivityManager.EXTRA_NETWORK, new Network(mNetwork)); appExtras.putParcelable(ConnectivityManager.EXTRA_CAPTIVE_PORTAL, new CaptivePortal(new ICaptivePortal.Stub() { @Override public void appResponse(int response) { if (response == APP_RETURN_WANTED_AS_IS) { mContext.enforceCallingPermission( PERMISSION_NETWORK_SETTINGS, "CaptivePortal"); } sendMessage(CMD_CAPTIVE_PORTAL_APP_FINISHED, response); } @Override public void logEvent(int eventId, String packageName) throws RemoteException { mContext.enforceCallingPermission( PERMISSION_NETWORK_SETTINGS, "CaptivePortal"); mCallback.logCaptivePortalLoginEvent(eventId, packageName); } })); final Network network = new Network(mNetwork); appExtras.putParcelable(ConnectivityManager.EXTRA_NETWORK, network); final CaptivePortalProbeResult probeRes = mLastPortalProbeResult; appExtras.putString(EXTRA_CAPTIVE_PORTAL_URL, probeRes.detectUrl); if (probeRes.probeSpec != null) { Loading @@ -702,7 +686,7 @@ public class NetworkMonitor extends StateMachine { } appExtras.putString(ConnectivityManager.EXTRA_CAPTIVE_PORTAL_USER_AGENT, mCaptivePortalUserAgent); mCm.startCaptivePortalApp(appExtras); mCm.startCaptivePortalApp(network, appExtras); return HANDLED; default: return NOT_HANDLED; Loading
tests/src/com/android/server/connectivity/NetworkMonitorTest.java +15 −14 Original line number Diff line number Diff line Loading @@ -16,8 +16,7 @@ package com.android.server.connectivity; import static android.net.ConnectivityManager.ACTION_CAPTIVE_PORTAL_SIGN_IN; import static android.net.ConnectivityManager.EXTRA_CAPTIVE_PORTAL; import static android.net.CaptivePortal.APP_RETURN_DISMISSED; import static android.net.INetworkMonitor.NETWORK_TEST_RESULT_INVALID; import static android.net.INetworkMonitor.NETWORK_TEST_RESULT_VALID; import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET; Loading @@ -41,8 +40,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.content.Intent; import android.net.CaptivePortal; import android.net.ConnectivityManager; import android.net.INetworkMonitorCallbacks; import android.net.InetAddresses; Loading @@ -54,10 +51,10 @@ import android.net.captiveportal.CaptivePortalProbeResult; import android.net.metrics.IpConnectivityLog; import android.net.util.SharedLog; import android.net.wifi.WifiManager; import android.os.Bundle; import android.os.ConditionVariable; import android.os.Handler; import android.os.SystemClock; import android.os.UserHandle; import android.provider.Settings; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; Loading Loading @@ -487,19 +484,23 @@ public class NetworkMonitorTest { // Check that startCaptivePortalApp sends the expected intent. nm.launchCaptivePortalApp(); final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mContext, timeout(HANDLER_TIMEOUT_MS).times(1)) .startActivityAsUser(intentCaptor.capture(), eq(UserHandle.CURRENT)); final Intent intent = intentCaptor.getValue(); assertEquals(ACTION_CAPTIVE_PORTAL_SIGN_IN, intent.getAction()); final Network network = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK); assertEquals(TEST_NETID, network.netId); final ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class); final ArgumentCaptor<Network> networkCaptor = ArgumentCaptor.forClass(Network.class); verify(mCm, timeout(HANDLER_TIMEOUT_MS).times(1)) .startCaptivePortalApp(networkCaptor.capture(), bundleCaptor.capture()); final Bundle bundle = bundleCaptor.getValue(); final Network bundleNetwork = bundle.getParcelable(ConnectivityManager.EXTRA_NETWORK); assertEquals(TEST_NETID, bundleNetwork.netId); // network is passed both in bundle and as parameter, as the bundle is opaque to the // framework and only intended for the captive portal app, but the framework needs // the network to identify the right NetworkMonitor. assertEquals(TEST_NETID, networkCaptor.getValue().netId); // Have the app report that the captive portal is dismissed, and check that we revalidate. setStatus(mHttpsConnection, 204); setStatus(mHttpConnection, 204); final CaptivePortal captivePortal = intent.getParcelableExtra(EXTRA_CAPTIVE_PORTAL); captivePortal.reportCaptivePortalDismissed(); nm.notifyCaptivePortalAppFinished(APP_RETURN_DISMISSED); verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1)) .notifyNetworkTested(NETWORK_TEST_RESULT_VALID, null); } Loading