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

Commit f34a8e1b authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "[FUI22] Support getAllNetworkStateSnapshot" am: 4c73e05c am: 1e1379b2 am: ee3fc014

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1614779

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I52f8339bd1cda35a3f26f28fd3c0165f6f6ff91e
parents 072e6e15 ee3fc014
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;

import com.android.net.module.util.NetworkIdentityUtils;

import java.util.Objects;

/**
@@ -124,4 +126,15 @@ public final class NetworkStateSnapshot implements Parcelable {
    public int hashCode() {
        return Objects.hash(network, networkCapabilities, linkProperties, subscriberId, legacyType);
    }

    @Override
    public String toString() {
        return "NetworkStateSnapshot{"
                + "network=" + network
                + ", networkCapabilities=" + networkCapabilities
                + ", linkProperties=" + linkProperties
                + ", subscriberId='" + NetworkIdentityUtils.scrubSubscriberId(subscriberId) + '\''
                + ", legacyType=" + legacyType
                + '}';
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ package android.net {
  }

  public class ConnectivityManager {
    method @NonNull @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public java.util.List<android.net.NetworkStateSnapshot> getAllNetworkStateSnapshot();
    method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public void registerSystemDefaultNetworkCallback(@NonNull android.net.ConnectivityManager.NetworkCallback, @NonNull android.os.Handler);
    method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_STACK, android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}) public void requestBackgroundNetwork(@NonNull android.net.NetworkRequest, @Nullable android.os.Handler, @NonNull android.net.ConnectivityManager.NetworkCallback);
    method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_TEST_NETWORKS, android.Manifest.permission.NETWORK_STACK}) public void simulateDataStall(int, long, @NonNull android.net.Network, @NonNull android.os.PersistableBundle);
+19 −0
Original line number Diff line number Diff line
@@ -1258,6 +1258,25 @@ public class ConnectivityManager {
        }
    }

    /**
     * Return a list of {@link NetworkStateSnapshot}s, one for each network that is currently
     * connected.
     * @hide
     */
    @SystemApi(client = MODULE_LIBRARIES)
    @RequiresPermission(anyOf = {
            NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK,
            android.Manifest.permission.NETWORK_STACK,
            android.Manifest.permission.NETWORK_SETTINGS})
    @NonNull
    public List<NetworkStateSnapshot> getAllNetworkStateSnapshot() {
        try {
            return mService.getAllNetworkStateSnapshot();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Returns the {@link Network} object currently serving a given type, or
     * null if the given type is not connected.
+3 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkRequest;
import android.net.NetworkState;
import android.net.NetworkStateSnapshot;
import android.net.OemNetworkPreferences;
import android.net.ProxyInfo;
import android.net.UidRange;
@@ -79,6 +80,8 @@ interface IConnectivityManager
    @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
    NetworkState[] getAllNetworkState();

    List<NetworkStateSnapshot> getAllNetworkStateSnapshot();

    boolean isActiveNetworkMetered();

    boolean requestRouteToHostAddress(int networkType, in byte[] hostAddress,
+26 −4
Original line number Diff line number Diff line
@@ -1886,24 +1886,46 @@ public class ConnectivityService extends IConnectivityManager.Stub
        }
    }

    // TODO: Consider delete this function or turn it into a no-op method.
    @Override
    public NetworkState[] getAllNetworkState() {
        // This contains IMSI details, so make sure the caller is privileged.
        PermissionUtils.enforceNetworkStackPermission(mContext);

        final ArrayList<NetworkState> result = new ArrayList<>();
        for (NetworkStateSnapshot snapshot : getAllNetworkStateSnapshot()) {
            // NetworkStateSnapshot doesn't contain NetworkInfo, so need to fetch it from the
            // NetworkAgentInfo.
            final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(snapshot.network);
            if (nai != null && nai.networkInfo.isConnected()) {
                result.add(new NetworkState(new NetworkInfo(nai.networkInfo),
                        snapshot.linkProperties, snapshot.networkCapabilities, snapshot.network,
                        snapshot.subscriberId));
            }
        }
        return result.toArray(new NetworkState[result.size()]);
    }

    @Override
    @NonNull
    public List<NetworkStateSnapshot> getAllNetworkStateSnapshot() {
        // This contains IMSI details, so make sure the caller is privileged.
        PermissionUtils.enforceNetworkStackPermission(mContext);

        final ArrayList<NetworkStateSnapshot> result = new ArrayList<>();
        for (Network network : getAllNetworks()) {
            final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
            // TODO: Consider include SUSPENDED networks.
            // TODO: Consider include SUSPENDED networks, which should be considered as
            //  temporary shortage of connectivity of a connected network.
            if (nai != null && nai.networkInfo.isConnected()) {
                // TODO (b/73321673) : NetworkState contains a copy of the
                // TODO (b/73321673) : NetworkStateSnapshot contains a copy of the
                // NetworkCapabilities, which may contain UIDs of apps to which the
                // network applies. Should the UIDs be cleared so as not to leak or
                // interfere ?
                result.add(nai.getNetworkState());
                result.add(nai.getNetworkStateSnapshot());
            }
        }
        return result.toArray(new NetworkState[result.size()]);
        return result;
    }

    @Override
Loading