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

Commit cc0e890f authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by android-build-merger
Browse files

Merge changes Ib9a15fec,I9f3f2588 into qt-dev am: f4a435ac

am: 3d7da92f

Change-Id: I11a73f9ad6399f27c1bcf3604b4b2875a4042986
parents 15ec9e0d 3d7da92f
Loading
Loading
Loading
Loading
+15 −50
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ import android.net.NetworkFactory;
import android.net.NetworkInfo;
import android.net.NetworkInfo.DetailedState;
import android.net.NetworkMisc;
import android.net.NetworkMonitorManager;
import android.net.NetworkPolicyManager;
import android.net.NetworkQuotaInfo;
import android.net.NetworkRequest;
@@ -1786,8 +1787,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
            // caller type. Need to re-factor NetdEventListenerService to allow multiple
            // NetworkMonitor registrants.
            if (nai != null && nai.satisfies(mDefaultRequest)) {
                Binder.withCleanCallingIdentity(() ->
                        nai.networkMonitor().notifyDnsResponse(returnCode));
                nai.networkMonitor().notifyDnsResponse(returnCode);
            }
        }

@@ -2854,11 +2854,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
        // Notify the NetworkAgentInfo/NetworkMonitor in case NetworkMonitor needs to cancel or
        // schedule DNS resolutions. If a DNS resolution is required the
        // result will be sent back to us.
        try {
        nai.networkMonitor().notifyPrivateDnsChanged(cfg.toParcel());
        } catch (RemoteException e) {
            e.rethrowAsRuntimeException();
        }

        // With Private DNS bypass support, we can proceed to update the
        // Private DNS config immediately, even if we're in strict mode
@@ -3024,11 +3020,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
            // Disable wakeup packet monitoring for each interface.
            wakeupModifyInterface(iface, nai.networkCapabilities, false);
        }
        try {
        nai.networkMonitor().notifyNetworkDisconnected();
        } catch (RemoteException e) {
            e.rethrowAsRuntimeException();
        }
        mNetworkAgentInfos.remove(nai.messenger);
        nai.clatd.update();
        synchronized (mNetworkForNetId) {
@@ -3441,11 +3433,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
            //
            // TODO: NetworkMonitor does not refer to the "never ask again" bit. The bit is stored
            // per network. Therefore, NetworkMonitor may still do https probe.
            try {
            nai.networkMonitor().setAcceptPartialConnectivity();
            } catch (RemoteException e) {
                e.rethrowAsRuntimeException();
            }
        }
    }

@@ -3477,11 +3465,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
            NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
            if (nai == null) return;
            if (!nai.networkCapabilities.hasCapability(NET_CAPABILITY_CAPTIVE_PORTAL)) return;
            try {
            nai.networkMonitor().launchCaptivePortalApp();
            } catch (RemoteException e) {
                e.rethrowAsRuntimeException();
            }
        });
    }

@@ -3516,7 +3500,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
        }

        @Override
        public void appResponse(final int response) throws RemoteException {
        public void appResponse(final int response) {
            if (response == CaptivePortal.APP_RETURN_WANTED_AS_IS) {
                enforceSettingsPermission();
            }
@@ -3526,16 +3510,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
            if (nai == null) return;

            // nai.networkMonitor() is thread-safe
            final INetworkMonitor nm = nai.networkMonitor();
            final NetworkMonitorManager 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
@@ -4106,11 +4083,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
        if (isNetworkWithLinkPropertiesBlocked(lp, uid, false)) {
            return;
        }
        try {
        nai.networkMonitor().forceReevaluation(uid);
        } catch (RemoteException e) {
            e.rethrowAsRuntimeException();
        }
    }

    /**
@@ -5543,11 +5516,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
            // Start or stop DNS64 detection and 464xlat according to network state.
            networkAgent.clatd.update();
            notifyIfacesChangedForNetworkStats();
            try {
            networkAgent.networkMonitor().notifyLinkPropertiesChanged(newLp);
            } catch (RemoteException e) {
                e.rethrowAsRuntimeException();
            }
            if (networkAgent.everConnected) {
                notifyNetworkCallbacks(networkAgent, ConnectivityManager.CALLBACK_IP_CHANGED);
            }
@@ -6531,15 +6500,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
            // command must be sent after updating LinkProperties to maximize chances of
            // NetworkMonitor seeing the correct LinkProperties when starting.
            // TODO: pass LinkProperties to the NetworkMonitor in the notifyNetworkConnected call.
            try {
            if (networkAgent.networkMisc.acceptPartialConnectivity) {
                networkAgent.networkMonitor().setAcceptPartialConnectivity();
            }
            networkAgent.networkMonitor().notifyNetworkConnected(
                    networkAgent.linkProperties, networkAgent.networkCapabilities);
            } catch (RemoteException e) {
                e.rethrowAsRuntimeException();
            }
            scheduleUnvalidatedPrompt(networkAgent);

            // Whether a particular NetworkRequest listen should cause signal strength thresholds to
+7 −11
Original line number Diff line number Diff line
@@ -25,12 +25,12 @@ import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkMisc;
import android.net.NetworkMonitorManager;
import android.net.NetworkRequest;
import android.net.NetworkState;
import android.os.Handler;
import android.os.INetworkManagementService;
import android.os.Messenger;
import android.os.RemoteException;
import android.os.SystemClock;
import android.util.Log;
import android.util.SparseArray;
@@ -247,7 +247,7 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
    public final Nat464Xlat clatd;

    // Set after asynchronous creation of the NetworkMonitor.
    private volatile INetworkMonitor mNetworkMonitor;
    private volatile NetworkMonitorManager mNetworkMonitor;

    private static final String TAG = ConnectivityService.class.getSimpleName();
    private static final boolean VDBG = false;
@@ -278,7 +278,7 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
     * Inform NetworkAgentInfo that a new NetworkMonitor was created.
     */
    public void onNetworkMonitorCreated(INetworkMonitor networkMonitor) {
        mNetworkMonitor = networkMonitor;
        mNetworkMonitor = new NetworkMonitorManager(networkMonitor);
    }

    /**
@@ -290,13 +290,9 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
     */
    public void setNetworkCapabilities(NetworkCapabilities nc) {
        networkCapabilities = nc;
        final INetworkMonitor nm = mNetworkMonitor;
        final NetworkMonitorManager nm = mNetworkMonitor;
        if (nm != null) {
            try {
            nm.notifyNetworkCapabilitiesChanged(nc);
            } catch (RemoteException e) {
                Log.e(TAG, "Error notifying NetworkMonitor of updated NetworkCapabilities", e);
            }
        }
    }

@@ -317,11 +313,11 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
    }

    /**
     * Get the INetworkMonitor in this NetworkAgentInfo.
     * Get the NetworkMonitorManager in this NetworkAgentInfo.
     *
     * <p>This will be null before {@link #onNetworkMonitorCreated(INetworkMonitor)} is called.
     */
    public INetworkMonitor networkMonitor() {
    public NetworkMonitorManager networkMonitor() {
        return mNetworkMonitor;
    }

+201 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.net;

import android.annotation.NonNull;
import android.os.Binder;
import android.os.RemoteException;
import android.util.Log;

/**
 * A convenience wrapper for INetworkMonitor.
 *
 * Wraps INetworkMonitor calls, making them a bit more friendly to use. Currently handles:
 * - Clearing calling identity
 * - Ignoring RemoteExceptions
 * - Converting to stable parcelables
 *
 * By design, all methods on INetworkMonitor are asynchronous oneway IPCs and are thus void. All the
 * wrapper methods in this class return a boolean that callers can use to determine whether
 * RemoteException was thrown.
 */
public class NetworkMonitorManager {

    @NonNull private final INetworkMonitor mNetworkMonitor;
    @NonNull private final String mTag;

    public NetworkMonitorManager(@NonNull INetworkMonitor networkMonitorManager,
            @NonNull String tag) {
        mNetworkMonitor = networkMonitorManager;
        mTag = tag;
    }

    public NetworkMonitorManager(@NonNull INetworkMonitor networkMonitorManager) {
        this(networkMonitorManager, NetworkMonitorManager.class.getSimpleName());
    }

    private void log(String s, Throwable e) {
        Log.e(mTag, s, e);
    }

    // CHECKSTYLE:OFF Generated code

    public boolean start() {
        final long token = Binder.clearCallingIdentity();
        try {
            mNetworkMonitor.start();
            return true;
        } catch (RemoteException e) {
            log("Error in start", e);
            return false;
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }

    public boolean launchCaptivePortalApp() {
        final long token = Binder.clearCallingIdentity();
        try {
            mNetworkMonitor.launchCaptivePortalApp();
            return true;
        } catch (RemoteException e) {
            log("Error in launchCaptivePortalApp", e);
            return false;
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }

    public boolean notifyCaptivePortalAppFinished(int response) {
        final long token = Binder.clearCallingIdentity();
        try {
            mNetworkMonitor.notifyCaptivePortalAppFinished(response);
            return true;
        } catch (RemoteException e) {
            log("Error in notifyCaptivePortalAppFinished", e);
            return false;
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }

    public boolean setAcceptPartialConnectivity() {
        final long token = Binder.clearCallingIdentity();
        try {
            mNetworkMonitor.setAcceptPartialConnectivity();
            return true;
        } catch (RemoteException e) {
            log("Error in setAcceptPartialConnectivity", e);
            return false;
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }

    public boolean forceReevaluation(int uid) {
        final long token = Binder.clearCallingIdentity();
        try {
            mNetworkMonitor.forceReevaluation(uid);
            return true;
        } catch (RemoteException e) {
            log("Error in forceReevaluation", e);
            return false;
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }

    public boolean notifyPrivateDnsChanged(PrivateDnsConfigParcel config) {
        final long token = Binder.clearCallingIdentity();
        try {
            mNetworkMonitor.notifyPrivateDnsChanged(config);
            return true;
        } catch (RemoteException e) {
            log("Error in notifyPrivateDnsChanged", e);
            return false;
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }

    public boolean notifyDnsResponse(int returnCode) {
        final long token = Binder.clearCallingIdentity();
        try {
            mNetworkMonitor.notifyDnsResponse(returnCode);
            return true;
        } catch (RemoteException e) {
            log("Error in notifyDnsResponse", e);
            return false;
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }

    public boolean notifyNetworkConnected(LinkProperties lp, NetworkCapabilities nc) {
        final long token = Binder.clearCallingIdentity();
        try {
            mNetworkMonitor.notifyNetworkConnected(lp, nc);
            return true;
        } catch (RemoteException e) {
            log("Error in notifyNetworkConnected", e);
            return false;
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }

    public boolean notifyNetworkDisconnected() {
        final long token = Binder.clearCallingIdentity();
        try {
            mNetworkMonitor.notifyNetworkDisconnected();
            return true;
        } catch (RemoteException e) {
            log("Error in notifyNetworkDisconnected", e);
            return false;
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }

    public boolean notifyLinkPropertiesChanged(LinkProperties lp) {
        final long token = Binder.clearCallingIdentity();
        try {
            mNetworkMonitor.notifyLinkPropertiesChanged(lp);
            return true;
        } catch (RemoteException e) {
            log("Error in notifyLinkPropertiesChanged", e);
            return false;
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }

    public boolean notifyNetworkCapabilitiesChanged(NetworkCapabilities nc) {
        final long token = Binder.clearCallingIdentity();
        try {
            mNetworkMonitor.notifyNetworkCapabilitiesChanged(nc);
            return true;
        } catch (RemoteException e) {
            log("Error in notifyNetworkCapabilitiesChanged", e);
            return false;
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }

    // CHECKSTYLE:ON Generated code
}