Merge "Support reevaluation request from captive portal app"
am: 254c3d830e
Change-Id: I5f376b4a342557b91b70d892308469b1fdda2363
This commit is contained in:
@@ -60,6 +60,18 @@ public class CaptivePortal implements Parcelable {
|
|||||||
@SystemApi
|
@SystemApi
|
||||||
@TestApi
|
@TestApi
|
||||||
public static final int APP_RETURN_WANTED_AS_IS = 2;
|
public static final int APP_RETURN_WANTED_AS_IS = 2;
|
||||||
|
/** Event offset of request codes from captive portal application. */
|
||||||
|
private static final int APP_REQUEST_BASE = 100;
|
||||||
|
/**
|
||||||
|
* Request code from the captive portal application, indicating that the network condition may
|
||||||
|
* have changed and the network should be re-validated.
|
||||||
|
* @see ICaptivePortal#appRequest(int)
|
||||||
|
* @see android.net.INetworkMonitor#forceReevaluation(int)
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@SystemApi
|
||||||
|
@TestApi
|
||||||
|
public static final int APP_REQUEST_REEVALUATION_REQUIRED = APP_REQUEST_BASE + 0;
|
||||||
|
|
||||||
private final IBinder mBinder;
|
private final IBinder mBinder;
|
||||||
|
|
||||||
@@ -135,6 +147,19 @@ public class CaptivePortal implements Parcelable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request that the system reevaluates the captive portal status.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@SystemApi
|
||||||
|
@TestApi
|
||||||
|
public void reevaluateNetwork() {
|
||||||
|
try {
|
||||||
|
ICaptivePortal.Stub.asInterface(mBinder).appRequest(APP_REQUEST_REEVALUATION_REQUIRED);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a captive portal login event.
|
* Log a captive portal login event.
|
||||||
* @param eventId one of the CAPTIVE_PORTAL_LOGIN_* constants in metrics_constants.proto.
|
* @param eventId one of the CAPTIVE_PORTAL_LOGIN_* constants in metrics_constants.proto.
|
||||||
|
|||||||
@@ -3609,16 +3609,31 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
enforceSettingsPermission();
|
enforceSettingsPermission();
|
||||||
}
|
}
|
||||||
|
|
||||||
// getNetworkAgentInfoForNetwork is thread-safe
|
final NetworkMonitorManager nm = getNetworkMonitorManager(mNetwork);
|
||||||
final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(mNetwork);
|
|
||||||
if (nai == null) return;
|
|
||||||
|
|
||||||
// nai.networkMonitor() is thread-safe
|
|
||||||
final NetworkMonitorManager nm = nai.networkMonitor();
|
|
||||||
if (nm == null) return;
|
if (nm == null) return;
|
||||||
nm.notifyCaptivePortalAppFinished(response);
|
nm.notifyCaptivePortalAppFinished(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void appRequest(final int request) {
|
||||||
|
final NetworkMonitorManager nm = getNetworkMonitorManager(mNetwork);
|
||||||
|
if (nm == null) return;
|
||||||
|
|
||||||
|
if (request == CaptivePortal.APP_REQUEST_REEVALUATION_REQUIRED) {
|
||||||
|
nm.forceReevaluation(Binder.getCallingUid());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private NetworkMonitorManager getNetworkMonitorManager(final Network network) {
|
||||||
|
// getNetworkAgentInfoForNetwork is thread-safe
|
||||||
|
final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
|
||||||
|
if (nai == null) return null;
|
||||||
|
|
||||||
|
// nai.networkMonitor() is thread-safe
|
||||||
|
return nai.networkMonitor();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logEvent(int eventId, String packageName) {
|
public void logEvent(int eventId, String packageName) {
|
||||||
enforceSettingsPermission();
|
enforceSettingsPermission();
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ public class CaptivePortalTest {
|
|||||||
mCode = response;
|
mCode = response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void appRequest(final int request) throws RemoteException {
|
||||||
|
mCode = request;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logEvent(int eventId, String packageName) throws RemoteException {
|
public void logEvent(int eventId, String packageName) throws RemoteException {
|
||||||
mCode = eventId;
|
mCode = eventId;
|
||||||
@@ -79,6 +84,12 @@ public class CaptivePortalTest {
|
|||||||
assertEquals(result.mCode, CaptivePortal.APP_RETURN_WANTED_AS_IS);
|
assertEquals(result.mCode, CaptivePortal.APP_RETURN_WANTED_AS_IS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReevaluateNetwork() {
|
||||||
|
final MyCaptivePortalImpl result = runCaptivePortalTest(c -> c.reevaluateNetwork());
|
||||||
|
assertEquals(result.mCode, CaptivePortal.APP_REQUEST_REEVALUATION_REQUIRED);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLogEvent() {
|
public void testLogEvent() {
|
||||||
final MyCaptivePortalImpl result = runCaptivePortalTest(c -> c.logEvent(
|
final MyCaptivePortalImpl result = runCaptivePortalTest(c -> c.logEvent(
|
||||||
|
|||||||
Reference in New Issue
Block a user