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

Commit 14e51c8a authored by Junyu Lai's avatar Junyu Lai Committed by android-build-merger
Browse files

Merge changes from topic "ka05"

am: b3656c7b

Change-Id: I2448348d1501ca50daac87f4c06c120b4de3b2ae
parents 0fd63d54 b3656c7b
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -27112,6 +27112,7 @@ package android.net {
  public class ConnectivityManager {
    method public void addDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener);
    method public boolean bindProcessToNetwork(@Nullable android.net.Network);
    method public android.net.SocketKeepalive createSocketKeepalive(@NonNull android.net.Network, @NonNull android.net.IpSecManager.UdpEncapsulationSocket, @NonNull java.net.InetAddress, @NonNull java.net.InetAddress, @NonNull java.util.concurrent.Executor, @NonNull android.net.SocketKeepalive.Callback);
    method @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) @Nullable public android.net.Network getActiveNetwork();
    method @Deprecated @Nullable @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) public android.net.NetworkInfo getActiveNetworkInfo();
    method @Deprecated @NonNull @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) public android.net.NetworkInfo[] getAllNetworkInfo();
@@ -27616,6 +27617,29 @@ package android.net {
    ctor public SSLSessionCache(android.content.Context);
  }
  public abstract class SocketKeepalive implements java.lang.AutoCloseable {
    method public final void close();
    method public final void start(@IntRange(from=0xa, to=0xe10) int);
    method public final void stop();
    field public static final int ERROR_HARDWARE_ERROR = -31; // 0xffffffe1
    field public static final int ERROR_HARDWARE_UNSUPPORTED = -30; // 0xffffffe2
    field public static final int ERROR_INVALID_INTERVAL = -24; // 0xffffffe8
    field public static final int ERROR_INVALID_IP_ADDRESS = -21; // 0xffffffeb
    field public static final int ERROR_INVALID_LENGTH = -23; // 0xffffffe9
    field public static final int ERROR_INVALID_NETWORK = -20; // 0xffffffec
    field public static final int ERROR_INVALID_PORT = -22; // 0xffffffea
    field public static final int ERROR_INVALID_SOCKET = -25; // 0xffffffe7
    field public static final int ERROR_SOCKET_NOT_IDLE = -26; // 0xffffffe6
  }
  public static class SocketKeepalive.Callback {
    ctor public SocketKeepalive.Callback();
    method public void onDataReceived();
    method public void onError(int);
    method public void onStarted();
    method public void onStopped();
  }
  public class TrafficStats {
    ctor public TrafficStats();
    method public static void clearThreadStatsTag();
+1 −0
Original line number Diff line number Diff line
@@ -3060,6 +3060,7 @@ package android.net {
  }
  public class ConnectivityManager {
    method @RequiresPermission("android.permission.PACKET_KEEPALIVE_OFFLOAD") public android.net.SocketKeepalive createNattKeepalive(@NonNull android.net.Network, @NonNull java.io.FileDescriptor, @NonNull java.net.InetAddress, @NonNull java.net.InetAddress, @NonNull java.util.concurrent.Executor, @NonNull android.net.SocketKeepalive.Callback);
    method public boolean getAvoidBadWifi();
    method @RequiresPermission(android.Manifest.permission.LOCAL_MAC_ADDRESS) public String getCaptivePortalServerUrl();
    method @RequiresPermission(anyOf={android.Manifest.permission.TETHER_PRIVILEGED, android.Manifest.permission.WRITE_SETTINGS}) public boolean isTetheringSupported();
+67 −0
Original line number Diff line number Diff line
@@ -15,6 +15,9 @@
 */
package android.net;

import static android.net.IpSecManager.INVALID_RESOURCE_ID;

import android.annotation.CallbackExecutor;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -28,6 +31,8 @@ import android.annotation.UnsupportedAppUsage;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.IpSecManager.UdpEncapsulationSocket;
import android.net.SocketKeepalive.Callback;
import android.os.Binder;
import android.os.Build;
import android.os.Build.VERSION_CODES;
@@ -58,6 +63,7 @@ import com.android.internal.util.Protocol;

import libcore.net.event.NetworkEventDispatcher;

import java.io.FileDescriptor;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.net.InetAddress;
@@ -66,6 +72,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;

/**
 * Class that answers queries about the state of network connectivity. It also
@@ -1699,6 +1706,8 @@ public class ConnectivityManager {
     * {@link PacketKeepaliveCallback#onStopped} if the operation was successful or
     * {@link PacketKeepaliveCallback#onError} if an error occurred.
     *
     * @deprecated Use {@link SocketKeepalive} instead.
     *
     * @hide
     */
    public class PacketKeepalive {
@@ -1802,6 +1811,8 @@ public class ConnectivityManager {
    /**
     * Starts an IPsec NAT-T keepalive packet with the specified parameters.
     *
     * @deprecated Use {@link #createSocketKeepalive} instead.
     *
     * @hide
     */
    @UnsupportedAppUsage
@@ -1820,6 +1831,62 @@ public class ConnectivityManager {
        return k;
    }

    /**
     * Request that keepalives be started on a IPsec NAT-T socket.
     *
     * @param network The {@link Network} the socket is on.
     * @param socket The socket that needs to be kept alive.
     * @param source The source address of the {@link UdpEncapsulationSocket}.
     * @param destination The destination address of the {@link UdpEncapsulationSocket}.
     * @param executor The executor on which callback will be invoked. The provided {@link Executor}
     *                 must run callback sequentially, otherwise the order of callbacks cannot be
     *                 guaranteed.
     * @param callback A {@link SocketKeepalive.Callback}. Used for notifications about keepalive
     *        changes. Must be extended by applications that use this API.
     *
     * @return A {@link SocketKeepalive} object, which can be used to control this keepalive object.
     **/
    public SocketKeepalive createSocketKeepalive(@NonNull Network network,
            @NonNull UdpEncapsulationSocket socket,
            @NonNull InetAddress source,
            @NonNull InetAddress destination,
            @NonNull @CallbackExecutor Executor executor,
            @NonNull Callback callback) {
        return new NattSocketKeepalive(mService, network, socket.getFileDescriptor(),
            socket.getResourceId(), source, destination, executor, callback);
    }

    /**
     * Request that keepalives be started on a IPsec NAT-T socket file descriptor. Directly called
     * by system apps which don't use IpSecService to create {@link UdpEncapsulationSocket}.
     *
     * @param network The {@link Network} the socket is on.
     * @param fd The {@link FileDescriptor} that needs to be kept alive. The provided
     *        {@link FileDescriptor} must be bound to a port and the keepalives will be sent from
     *        that port.
     * @param source The source address of the {@link UdpEncapsulationSocket}.
     * @param destination The destination address of the {@link UdpEncapsulationSocket}. The
     *        keepalive packets will always be sent to port 4500 of the given {@code destination}.
     * @param executor The executor on which callback will be invoked. The provided {@link Executor}
     *                 must run callback sequentially, otherwise the order of callbacks cannot be
     *                 guaranteed.
     * @param callback A {@link SocketKeepalive.Callback}. Used for notifications about keepalive
     *        changes. Must be extended by applications that use this API.
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.PACKET_KEEPALIVE_OFFLOAD)
    public SocketKeepalive createNattKeepalive(@NonNull Network network,
            @NonNull FileDescriptor fd,
            @NonNull InetAddress source,
            @NonNull InetAddress destination,
            @NonNull @CallbackExecutor Executor executor,
            @NonNull Callback callback) {
        return new NattSocketKeepalive(mService, network, fd, INVALID_RESOURCE_ID /* Unused */,
                source, destination, executor, callback);
    }

    /**
     * Ensure that a network route exists to deliver traffic to the specified
     * host via the specified network interface. An attempt to add a route that
+4 −0
Original line number Diff line number Diff line
@@ -181,6 +181,10 @@ interface IConnectivityManager
    void startNattKeepalive(in Network network, int intervalSeconds, in Messenger messenger,
            in IBinder binder, String srcAddr, int srcPort, String dstAddr);

    void startNattKeepaliveWithFd(in Network network, in FileDescriptor fd, int resourceId,
            int intervalSeconds, in Messenger messenger, in IBinder binder, String srcAddr,
            String dstAddr);

    void stopKeepalive(in Network network, int slot);

    String getCaptivePortalServerUrl();
+75 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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;

import java.io.FileDescriptor;
import java.net.InetAddress;
import java.util.concurrent.Executor;

/** @hide */
public final class NattSocketKeepalive extends SocketKeepalive {
    /** The NAT-T destination port for IPsec */
    public static final int NATT_PORT = 4500;

    @NonNull private final InetAddress mSource;
    @NonNull private final InetAddress mDestination;
    @NonNull private final FileDescriptor mFd;
    private final int mResourceId;

    NattSocketKeepalive(@NonNull IConnectivityManager service,
            @NonNull Network network,
            @NonNull FileDescriptor fd,
            int resourceId,
            @NonNull InetAddress source,
            @NonNull InetAddress destination,
            @NonNull Executor executor,
            @NonNull Callback callback) {
        super(service, network, executor, callback);
        mSource = source;
        mDestination = destination;
        mFd = fd;
        mResourceId = resourceId;
    }

    @Override
    void startImpl(int intervalSec) {
        try {
            mService.startNattKeepaliveWithFd(mNetwork, mFd, mResourceId, intervalSec, mMessenger,
                    new Binder(), mSource.getHostAddress(), mDestination.getHostAddress());
        } catch (RemoteException e) {
            Log.e(TAG, "Error starting packet keepalive: ", e);
            stopLooper();
        }
    }

    @Override
    void stopImpl() {
        try {
            if (mSlot != null) {
                mService.stopKeepalive(mNetwork, mSlot);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Error stopping packet keepalive: ", e);
            stopLooper();
        }
    }
}
Loading