Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5fa8cb38 authored by Lucas Lin's avatar Lucas Lin Committed by android-build-merger
Browse files

Merge "Popup a notification after logging in the captive portal network" am:...

Merge "Popup a notification after logging in the captive portal network" am: 6fa3d391 am: ff4106fc
am: 5b8b54cd

Change-Id: I62b9ef24f3a7f9fe75450a05d19dffda3b84d4b5
parents c97d0c5f 5b8b54cd
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -3387,6 +3387,9 @@
    <!-- A notification is shown when the user connects to a Wi-Fi network and the system detects that that network has no Internet access. This is the notification's message. -->
    <string name="wifi_no_internet_detailed">Tap for options</string>

    <!-- A notification is shown after the user logs in to a captive portal network, to indicate that the network should now have internet connectivity. This is the message of notification. [CHAR LIMIT=50] -->
    <string name="captive_portal_logged_in_detailed">Connected</string>

    <!-- A notification is shown when the user's softap config has been changed due to underlying
         hardware restrictions. This is the notifications's title.
         [CHAR_LIMIT=NONE] -->
+1 −0
Original line number Diff line number Diff line
@@ -695,6 +695,7 @@
  <java-symbol type="string" name="capability_title_canControlMagnification" />
  <java-symbol type="string" name="capability_desc_canPerformGestures" />
  <java-symbol type="string" name="capability_title_canPerformGestures" />
  <java-symbol type="string" name="captive_portal_logged_in_detailed" />
  <java-symbol type="string" name="cfTemplateForwarded" />
  <java-symbol type="string" name="cfTemplateForwardedTime" />
  <java-symbol type="string" name="cfTemplateNotForwarded" />
+2 −0
Original line number Diff line number Diff line
@@ -241,6 +241,8 @@ message SystemMessage {
    NOTE_NETWORK_LOST_INTERNET = 742;
    // The system default network switched to a different network
    NOTE_NETWORK_SWITCH = 743;
    // Device logged-in captive portal network successfully
    NOTE_NETWORK_LOGGED_IN = 744;

    // Notify the user that their work profile has been deleted
    // Package: android
+48 −10
Original line number Diff line number Diff line
@@ -98,10 +98,10 @@ import android.net.VpnService;
import android.net.metrics.IpConnectivityLog;
import android.net.metrics.NetworkEvent;
import android.net.netlink.InetDiagMessage;
import android.net.shared.NetdService;
import android.net.shared.NetworkMonitorUtils;
import android.net.shared.PrivateDnsConfig;
import android.net.util.MultinetworkPolicyTracker;
import android.net.shared.NetdService;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
@@ -238,6 +238,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
    // connect anyway?" dialog after the user selects a network that doesn't validate.
    private static final int PROMPT_UNVALIDATED_DELAY_MS = 8 * 1000;

    // How long to dismiss network notification.
    private static final int TIMEOUT_NOTIFICATION_DELAY_MS = 20 * 1000;

    // Default to 30s linger time-out. Modifiable only for testing.
    private static final String LINGER_DELAY_PROPERTY = "persist.netmon.linger";
    private static final int DEFAULT_LINGER_DELAY_MS = 30_000;
@@ -473,6 +476,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
     */
    public static final int EVENT_PROVISIONING_NOTIFICATION = 43;

    /**
     * This event can handle dismissing notification by given network id.
     */
    public static final int EVENT_TIMEOUT_NOTIFICATION = 44;

    /**
     * Argument for {@link #EVENT_PROVISIONING_NOTIFICATION} to indicate that the notification
     * should be shown.
@@ -2477,6 +2485,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
                    final boolean valid = (msg.arg1 == NETWORK_TEST_RESULT_VALID);
                    final boolean wasValidated = nai.lastValidated;
                    final boolean wasDefault = isDefaultNetwork(nai);
                    if (nai.everCaptivePortalDetected && !nai.captivePortalLoginNotified
                            && valid) {
                        nai.captivePortalLoginNotified = true;
                        showNetworkNotification(nai, NotificationType.LOGGED_IN);
                    }

                    final String redirectUrl = (msg.obj instanceof String) ? (String) msg.obj : "";

@@ -2497,7 +2510,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
                        updateCapabilities(oldScore, nai, nai.networkCapabilities);
                        // If score has changed, rebroadcast to NetworkFactories. b/17726566
                        if (oldScore != nai.getCurrentScore()) sendUpdatedScoreToFactories(nai);
                        if (valid) handleFreshlyValidatedNetwork(nai);
                        if (valid) {
                            handleFreshlyValidatedNetwork(nai);
                            // Clear NO_INTERNET and LOST_INTERNET notifications if network becomes
                            // valid.
                            mNotifier.clearNotification(nai.network.netId,
                                    NotificationType.NO_INTERNET);
                            mNotifier.clearNotification(nai.network.netId,
                                    NotificationType.LOST_INTERNET);
                        }
                    }
                    updateInetCondition(nai);
                    // Let the NetworkAgent know the state of its network
@@ -2521,6 +2542,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
                        final int oldScore = nai.getCurrentScore();
                        nai.lastCaptivePortalDetected = visible;
                        nai.everCaptivePortalDetected |= visible;
                        if (visible) {
                            nai.captivePortalLoginNotified = false;
                        }
                        if (nai.lastCaptivePortalDetected &&
                            Settings.Global.CAPTIVE_PORTAL_MODE_AVOID == getCaptivePortalMode()) {
                            if (DBG) log("Avoiding captive portal network: " + nai.name());
@@ -2532,7 +2556,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
                        updateCapabilities(oldScore, nai, nai.networkCapabilities);
                    }
                    if (!visible) {
                        mNotifier.clearNotification(netId);
                        // Only clear SIGN_IN and NETWORK_SWITCH notifications here, or else other
                        // notifications belong to the same network may be cleared unexpected.
                        mNotifier.clearNotification(netId, NotificationType.SIGN_IN);
                        mNotifier.clearNotification(netId, NotificationType.NETWORK_SWITCH);
                    } else {
                        if (nai == null) {
                            loge("EVENT_PROVISIONING_NOTIFICATION from unknown NetworkMonitor");
@@ -3238,9 +3265,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
        pw.decreaseIndent();
    }

    private void showValidationNotification(NetworkAgentInfo nai, NotificationType type) {
    private void showNetworkNotification(NetworkAgentInfo nai, NotificationType type) {
        final String action;
        switch (type) {
            case LOGGED_IN:
                action = Settings.ACTION_WIFI_SETTINGS;
                mHandler.removeMessages(EVENT_TIMEOUT_NOTIFICATION);
                mHandler.sendMessageDelayed(mHandler.obtainMessage(EVENT_TIMEOUT_NOTIFICATION,
                        nai.network.netId, 0), TIMEOUT_NOTIFICATION_DELAY_MS);
                break;
            case NO_INTERNET:
                action = ConnectivityManager.ACTION_PROMPT_UNVALIDATED;
                break;
@@ -3253,10 +3286,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
        }

        Intent intent = new Intent(action);
        if (type != NotificationType.LOGGED_IN) {
            intent.setData(Uri.fromParts("netId", Integer.toString(nai.network.netId), null));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setClassName("com.android.settings",
                    "com.android.settings.wifi.WifiNoInternetDialog");
        }

        PendingIntent pendingIntent = PendingIntent.getActivityAsUser(
                mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT);
@@ -3274,7 +3309,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
                !nai.networkMisc.explicitlySelected || nai.networkMisc.acceptUnvalidated) {
            return;
        }
        showValidationNotification(nai, NotificationType.NO_INTERNET);
        showNetworkNotification(nai, NotificationType.NO_INTERNET);
    }

    private void handleNetworkUnvalidated(NetworkAgentInfo nai) {
@@ -3283,7 +3318,7 @@ public class ConnectivityService extends IConnectivityManager.Stub

        if (nc.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) &&
            mMultinetworkPolicyTracker.shouldNotifyWifiUnvalidated()) {
            showValidationNotification(nai, NotificationType.LOST_INTERNET);
            showNetworkNotification(nai, NotificationType.LOST_INTERNET);
        }
    }

@@ -3429,6 +3464,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
                case EVENT_DATA_SAVER_CHANGED:
                    handleRestrictBackgroundChanged(toBool(msg.arg1));
                    break;
                case EVENT_TIMEOUT_NOTIFICATION:
                    mNotifier.clearNotification(msg.arg1, NotificationType.LOGGED_IN);
                    break;
            }
        }
    }
+17 −12
Original line number Diff line number Diff line
@@ -152,6 +152,10 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
    // Whether a captive portal was found during the last network validation attempt.
    public boolean lastCaptivePortalDetected;

    // Indicates the user was notified of a successful captive portal login since a portal was
    // last detected.
    public boolean captivePortalLoginNotified;

    // Networks are lingered when they become unneeded as a result of their NetworkRequests being
    // satisfied by a higher-scoring network. so as to allow communication to wrap up before the
    // network is taken down.  This usually only happens to the default network. Lingering ends with
@@ -618,18 +622,19 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
    }

    public String toString() {
        return "NetworkAgentInfo{ ni{" + networkInfo + "}  " +
                "network{" + network + "}  nethandle{" + network.getNetworkHandle() + "}  " +
                "lp{" + linkProperties + "}  " +
                "nc{" + networkCapabilities + "}  Score{" + getCurrentScore() + "}  " +
                "everValidated{" + everValidated + "}  lastValidated{" + lastValidated + "}  " +
                "created{" + created + "} lingering{" + isLingering() + "} " +
                "explicitlySelected{" + networkMisc.explicitlySelected + "} " +
                "acceptUnvalidated{" + networkMisc.acceptUnvalidated + "} " +
                "everCaptivePortalDetected{" + everCaptivePortalDetected + "} " +
                "lastCaptivePortalDetected{" + lastCaptivePortalDetected + "} " +
                "clat{" + clatd + "} " +
                "}";
        return "NetworkAgentInfo{ ni{" + networkInfo + "}  "
                + "network{" + network + "}  nethandle{" + network.getNetworkHandle() + "}  "
                + "lp{" + linkProperties + "}  "
                + "nc{" + networkCapabilities + "}  Score{" + getCurrentScore() + "}  "
                + "everValidated{" + everValidated + "}  lastValidated{" + lastValidated + "}  "
                + "created{" + created + "} lingering{" + isLingering() + "} "
                + "explicitlySelected{" + networkMisc.explicitlySelected + "} "
                + "acceptUnvalidated{" + networkMisc.acceptUnvalidated + "} "
                + "everCaptivePortalDetected{" + everCaptivePortalDetected + "} "
                + "lastCaptivePortalDetected{" + lastCaptivePortalDetected + "} "
                + "captivePortalLoginNotified{" + captivePortalLoginNotified + "} "
                + "clat{" + clatd + "} "
                + "}";
    }

    public String name() {
Loading