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

Commit e477e92b authored by Junyu Lai's avatar Junyu Lai Committed by Automerger Merge Worker
Browse files

Merge "Implement registerSystemDefaultNetworkCallback replacement in api30"...

Merge "Implement registerSystemDefaultNetworkCallback replacement in api30" am: 7c2f81d7 am: 2d02bdb7 am: c5e03f3d

Original change: https://android-review.googlesource.com/c/platform/packages/modules/NetworkStack/+/1699885

Change-Id: I7d78f142b0375ad8a46b5236adbd03c51b945527
parents 9ca375f2 c5e03f3d
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -17,12 +17,15 @@
package com.android.networkstack.apishim.api30;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.ConnectivityManager.NetworkCallback;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.os.Build;
import android.os.Handler;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

import com.android.networkstack.apishim.common.ConnectivityManagerShim;
import com.android.networkstack.apishim.common.ShimUtils;
@@ -33,8 +36,10 @@ import com.android.networkstack.apishim.common.UnsupportedApiLevelException;
 */
public class ConnectivityManagerShimImpl
        extends com.android.networkstack.apishim.api29.ConnectivityManagerShimImpl {
    protected final ConnectivityManager mCm;
    protected ConnectivityManagerShimImpl(Context context) {
        super(context);
        mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    }

    /**
@@ -65,9 +70,22 @@ public class ConnectivityManagerShimImpl
     * @throws UnsupportedApiLevelException if API is not available in this API level.
     */
    @Override
    @RequiresApi(Build.VERSION_CODES.R)
    public void registerSystemDefaultNetworkCallback(@NonNull NetworkCallback networkCallback,
            @NonNull Handler handler) throws UnsupportedApiLevelException {
        // Not supported for API 30.
        throw new UnsupportedApiLevelException("Not supported in API 30.");
            @NonNull Handler handler) {
        // defaultNetworkRequest is not really a "request", just a way of tracking the system
        // default network. It's guaranteed not to actually bring up any networks because it
        // should be the same request as the ConnectivityService default request, and thus
        // shares fate with it.  In API <= R, registerSystemDefaultNetworkCallback is not
        // available, and registerDefaultNetworkCallback will not track the system default when
        // a VPN applies to the UID of this process.
        final NetworkRequest defaultNetworkRequest = new NetworkRequest.Builder()
                .clearCapabilities()
                .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
                .addCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED)
                .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)
                .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                .build();
        mCm.requestNetwork(defaultNetworkRequest, networkCallback, handler);
    }
}
+0 −3
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.networkstack.apishim;
import static com.android.modules.utils.build.SdkLevel.isAtLeastS;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.ConnectivityManager.NetworkCallback;
import android.net.NetworkRequest;
import android.os.Build;
@@ -39,11 +38,9 @@ import java.util.Collection;
@RequiresApi(Build.VERSION_CODES.S)
public class ConnectivityManagerShimImpl
        extends com.android.networkstack.apishim.api30.ConnectivityManagerShimImpl  {
    private final ConnectivityManager mCm;

    protected ConnectivityManagerShimImpl(Context context) {
        super(context);
        mCm = context.getSystemService(ConnectivityManager.class);
    }

    /**