Merge "Remove NetworkMonitor dependency on ICaptivePortal"
This commit is contained in:
@@ -3920,15 +3920,16 @@ public class ConnectivityManager {
|
|||||||
*
|
*
|
||||||
* <p>This endpoint is exclusively for use by the NetworkStack and is protected by the
|
* <p>This endpoint is exclusively for use by the NetworkStack and is protected by the
|
||||||
* corresponding permission.
|
* corresponding permission.
|
||||||
|
* @param network Network on which the captive portal was detected.
|
||||||
* @param appExtras Extras to include in the app start intent.
|
* @param appExtras Extras to include in the app start intent.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@SystemApi
|
@SystemApi
|
||||||
@TestApi
|
@TestApi
|
||||||
@RequiresPermission(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK)
|
@RequiresPermission(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK)
|
||||||
public void startCaptivePortalApp(Bundle appExtras) {
|
public void startCaptivePortalApp(Network network, Bundle appExtras) {
|
||||||
try {
|
try {
|
||||||
mService.startCaptivePortalAppInternal(appExtras);
|
mService.startCaptivePortalAppInternal(network, appExtras);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ interface IConnectivityManager
|
|||||||
void setAcceptUnvalidated(in Network network, boolean accept, boolean always);
|
void setAcceptUnvalidated(in Network network, boolean accept, boolean always);
|
||||||
void setAvoidUnvalidated(in Network network);
|
void setAvoidUnvalidated(in Network network);
|
||||||
void startCaptivePortalApp(in Network network);
|
void startCaptivePortalApp(in Network network);
|
||||||
void startCaptivePortalAppInternal(in Bundle appExtras);
|
void startCaptivePortalAppInternal(in Network network, in Bundle appExtras);
|
||||||
|
|
||||||
boolean getAvoidBadWifi();
|
boolean getAvoidBadWifi();
|
||||||
int getMultipathPreference(in Network Network);
|
int getMultipathPreference(in Network Network);
|
||||||
|
|||||||
@@ -57,8 +57,10 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
|
import android.net.CaptivePortal;
|
||||||
import android.net.ConnectionInfo;
|
import android.net.ConnectionInfo;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.ICaptivePortal;
|
||||||
import android.net.IConnectivityManager;
|
import android.net.IConnectivityManager;
|
||||||
import android.net.IIpConnectivityMetrics;
|
import android.net.IIpConnectivityMetrics;
|
||||||
import android.net.INetd;
|
import android.net.INetd;
|
||||||
@@ -2689,11 +2691,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
EVENT_PROVISIONING_NOTIFICATION, PROVISIONING_NOTIFICATION_HIDE,
|
EVENT_PROVISIONING_NOTIFICATION, PROVISIONING_NOTIFICATION_HIDE,
|
||||||
mNai.network.netId));
|
mNai.network.netId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void logCaptivePortalLoginEvent(int eventId, String packageName) {
|
|
||||||
new MetricsLogger().action(eventId, packageName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean networkRequiresValidation(NetworkAgentInfo nai) {
|
private boolean networkRequiresValidation(NetworkAgentInfo nai) {
|
||||||
@@ -3239,22 +3236,63 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
/**
|
/**
|
||||||
* NetworkStack endpoint to start the captive portal app. The NetworkStack needs to use this
|
* NetworkStack endpoint to start the captive portal app. The NetworkStack needs to use this
|
||||||
* endpoint as it does not have INTERACT_ACROSS_USERS_FULL itself.
|
* endpoint as it does not have INTERACT_ACROSS_USERS_FULL itself.
|
||||||
|
* @param network Network on which the captive portal was detected.
|
||||||
* @param appExtras Bundle to use as intent extras for the captive portal application.
|
* @param appExtras Bundle to use as intent extras for the captive portal application.
|
||||||
* Must be treated as opaque to avoid preventing the captive portal app to
|
* Must be treated as opaque to avoid preventing the captive portal app to
|
||||||
* update its arguments.
|
* update its arguments.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void startCaptivePortalAppInternal(Bundle appExtras) {
|
public void startCaptivePortalAppInternal(Network network, Bundle appExtras) {
|
||||||
mContext.checkCallingOrSelfPermission(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK);
|
mContext.checkCallingOrSelfPermission(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK);
|
||||||
|
|
||||||
final Intent appIntent = new Intent(ConnectivityManager.ACTION_CAPTIVE_PORTAL_SIGN_IN);
|
final Intent appIntent = new Intent(ConnectivityManager.ACTION_CAPTIVE_PORTAL_SIGN_IN);
|
||||||
appIntent.putExtras(appExtras);
|
appIntent.putExtras(appExtras);
|
||||||
|
appIntent.putExtra(ConnectivityManager.EXTRA_CAPTIVE_PORTAL,
|
||||||
|
new CaptivePortal(new CaptivePortalImpl(network).asBinder()));
|
||||||
appIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
|
appIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
|
||||||
Binder.withCleanCallingIdentity(() ->
|
Binder.withCleanCallingIdentity(() ->
|
||||||
mContext.startActivityAsUser(appIntent, UserHandle.CURRENT));
|
mContext.startActivityAsUser(appIntent, UserHandle.CURRENT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class CaptivePortalImpl extends ICaptivePortal.Stub {
|
||||||
|
private final Network mNetwork;
|
||||||
|
|
||||||
|
private CaptivePortalImpl(Network network) {
|
||||||
|
mNetwork = network;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void appResponse(final int response) throws RemoteException {
|
||||||
|
if (response == CaptivePortal.APP_RETURN_WANTED_AS_IS) {
|
||||||
|
enforceSettingsPermission();
|
||||||
|
}
|
||||||
|
|
||||||
|
// getNetworkAgentInfoForNetwork is thread-safe
|
||||||
|
final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(mNetwork);
|
||||||
|
if (nai == null) return;
|
||||||
|
|
||||||
|
// nai.networkMonitor() is thread-safe
|
||||||
|
final INetworkMonitor nm = nai.networkMonitor();
|
||||||
|
if (nm == null) return;
|
||||||
|
|
||||||
|
final long token = Binder.clearCallingIdentity();
|
||||||
|
try {
|
||||||
|
nm.notifyCaptivePortalAppFinished(response);
|
||||||
|
} finally {
|
||||||
|
// Not using Binder.withCleanCallingIdentity() to keep the checked RemoteException
|
||||||
|
Binder.restoreCallingIdentity(token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logEvent(int eventId, String packageName) {
|
||||||
|
enforceSettingsPermission();
|
||||||
|
|
||||||
|
new MetricsLogger().action(eventId, packageName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean avoidBadWifi() {
|
public boolean avoidBadWifi() {
|
||||||
return mMultinetworkPolicyTracker.getAvoidBadWifi();
|
return mMultinetworkPolicyTracker.getAvoidBadWifi();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user