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

Commit 524fbd61 authored by Mark Chien's avatar Mark Chien Committed by android-build-merger
Browse files

Merge "Add get last entitlement value callback API"

am: 4163ff79

Change-Id: I1961297c3fa31f5575ae3a11a3fc90d695cb7de5
parents dac257d2 4163ff79
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -3070,6 +3070,7 @@ package android.net {
    method @RequiresPermission(android.Manifest.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(android.Manifest.permission.TETHER_PRIVILEGED) public void getLatestTetheringEntitlementValue(int, boolean, @NonNull android.net.ConnectivityManager.TetheringEntitlementValueListener, @Nullable android.os.Handler);
    method @RequiresPermission(anyOf={android.Manifest.permission.TETHER_PRIVILEGED, android.Manifest.permission.WRITE_SETTINGS}) public boolean isTetheringSupported();
    method @RequiresPermission(anyOf={"android.permission.NETWORK_SETTINGS", android.Manifest.permission.NETWORK_SETUP_WIZARD, "android.permission.NETWORK_STACK"}) public void setAirplaneMode(boolean);
    method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void startTethering(int, boolean, android.net.ConnectivityManager.OnStartTetheringCallback);
@@ -3080,6 +3081,9 @@ package android.net {
    field public static final int TETHERING_BLUETOOTH = 2; // 0x2
    field public static final int TETHERING_USB = 1; // 0x1
    field public static final int TETHERING_WIFI = 0; // 0x0
    field public static final int TETHER_ERROR_ENTITLEMENT_UNKONWN = 13; // 0xd
    field public static final int TETHER_ERROR_NO_ERROR = 0; // 0x0
    field public static final int TETHER_ERROR_PROVISION_FAILED = 11; // 0xb
  }
  public abstract static class ConnectivityManager.OnStartTetheringCallback {
@@ -3088,6 +3092,11 @@ package android.net {
    method public void onTetheringStarted();
  }
  public abstract static class ConnectivityManager.TetheringEntitlementValueListener {
    ctor public ConnectivityManager.TetheringEntitlementValueListener();
    method public void onEntitlementResult(int);
  }
  public final class IpPrefix implements android.os.Parcelable {
    ctor public IpPrefix(java.net.InetAddress, int);
    ctor public IpPrefix(String);
+64 −0
Original line number Diff line number Diff line
@@ -2581,6 +2581,7 @@ public class ConnectivityManager {
    }

    /** {@hide} */
    @SystemApi
    public static final int TETHER_ERROR_NO_ERROR           = 0;
    /** {@hide} */
    public static final int TETHER_ERROR_UNKNOWN_IFACE      = 1;
@@ -2603,9 +2604,13 @@ public class ConnectivityManager {
    /** {@hide} */
    public static final int TETHER_ERROR_IFACE_CFG_ERROR      = 10;
    /** {@hide} */
    @SystemApi
    public static final int TETHER_ERROR_PROVISION_FAILED     = 11;
    /** {@hide} */
    public static final int TETHER_ERROR_DHCPSERVER_ERROR     = 12;
    /** {@hide} */
    @SystemApi
    public static final int TETHER_ERROR_ENTITLEMENT_UNKONWN  = 13;

    /**
     * Get a more detailed error code after a Tethering or Untethering
@@ -2627,6 +2632,65 @@ public class ConnectivityManager {
        }
    }

    /**
     * Callback for use with {@link #getLatestTetheringEntitlementValue} to find out whether
     * entitlement succeeded.
     * @hide
     */
    @SystemApi
    public abstract static class TetheringEntitlementValueListener  {
        /**
         * Called to notify entitlement result.
         *
         * @param resultCode a int value of entitlement result. It may be one of
         *         {@link #TETHER_ERROR_NO_ERROR},
         *         {@link #TETHER_ERROR_PROVISION_FAILED}, or
         *         {@link #TETHER_ERROR_ENTITLEMENT_UNKONWN}.
         */
        public void onEntitlementResult(int resultCode) {}
    }

    /**
     * Get the last value of the entitlement check on this downstream. If the cached value is
     * {@link #TETHER_ERROR_NO_ERROR} or showEntitlementUi argument is false, it just return the
     * cached value. Otherwise, a UI-based entitlement check would be performed. It is not
     * guaranteed that the UI-based entitlement check will complete in any specific time period
     * and may in fact never complete. Any successful entitlement check the platform performs for
     * any reason will update the cached value.
     *
     * @param type the downstream type of tethering. Must be one of
     *         {@link #TETHERING_WIFI},
     *         {@link #TETHERING_USB}, or
     *         {@link #TETHERING_BLUETOOTH}.
     * @param showEntitlementUi a boolean indicating whether to run UI-based entitlement check.
     * @param listener an {@link TetheringEntitlementValueListener} which will be called to notify
     *         the caller of the result of entitlement check. The listener may be called zero or
     *         one time.
     * @param handler {@link Handler} to specify the thread upon which the listener will be invoked.
     * {@hide}
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
    public void getLatestTetheringEntitlementValue(int type, boolean showEntitlementUi,
            @NonNull final TetheringEntitlementValueListener listener, @Nullable Handler handler) {
        Preconditions.checkNotNull(listener, "TetheringEntitlementValueListener cannot be null.");
        ResultReceiver wrappedListener = new ResultReceiver(handler) {
            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
                listener.onEntitlementResult(resultCode);
            }
        };

        try {
            String pkgName = mContext.getOpPackageName();
            Log.i(TAG, "getLatestTetheringEntitlementValue:" + pkgName);
            mService.getLatestTetheringEntitlementValue(type, wrappedListener,
                    showEntitlementUi, pkgName);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Report network connectivity status.  This is currently used only
     * to alter status bar UI.
+3 −0
Original line number Diff line number Diff line
@@ -197,4 +197,7 @@ interface IConnectivityManager
    int getConnectionOwnerUid(in ConnectionInfo connectionInfo);
    boolean isCallerCurrentAlwaysOnVpnApp();
    boolean isCallerCurrentAlwaysOnVpnLockdownApp();

    void getLatestTetheringEntitlementValue(int type, in ResultReceiver receiver,
            boolean showEntitlementUi, String callerPkg);
}
+14 −0
Original line number Diff line number Diff line
@@ -3643,6 +3643,20 @@ public class ConnectivityService extends IConnectivityManager.Stub
        mTethering.stopTethering(type);
    }

    /**
     * Get the latest value of the tethering entitlement check.
     *
     * Note: Allow privileged apps who have TETHER_PRIVILEGED permission to access. If it turns
     * out some such apps are observed to abuse this API, change to per-UID limits on this API
     * if it's really needed.
     */
    @Override
    public void getLatestTetheringEntitlementValue(int type, ResultReceiver receiver,
            boolean showEntitlementUi, String callerPkg) {
        ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
        mTethering.getLatestTetheringEntitlementValue(type, receiver, showEntitlementUi);
    }

    // Called when we lose the default network and have no replacement yet.
    // This will automatically be cleared after X seconds or a new default network
    // becomes CONNECTED, whichever happens first.  The timer is started by the
+11 −2
Original line number Diff line number Diff line
@@ -121,7 +121,6 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Set;


/**
 * @hide
 *
@@ -223,7 +222,8 @@ public class Tethering extends BaseNetworkObserver {

        IntentFilter filter = new IntentFilter();
        filter.addAction(ACTION_CARRIER_CONFIG_CHANGED);
        mEntitlementMgr = mDeps.getEntitlementManager(mContext, mLog, systemProperties);
        mEntitlementMgr = mDeps.getEntitlementManager(mContext, mTetherMasterSM,
                mLog, systemProperties);
        mCarrierConfigChange = new VersionedBroadcastListener(
                "CarrierConfigChangeListener", mContext, smHandler, filter,
                (Intent ignored) -> {
@@ -470,6 +470,7 @@ public class Tethering extends BaseNetworkObserver {
                } else {
                    sendTetherResult(receiver, resultCode);
                }
                mEntitlementMgr.updateEntitlementCacheValue(type, resultCode);
            }
        };

@@ -1662,6 +1663,14 @@ public class Tethering extends BaseNetworkObserver {
        mUpstreamNetworkMonitor.startTrackDefaultNetwork(mDeps.getDefaultNetworkRequest());
    }

    /** Get the latest value of the tethering entitlement check. */
    public void getLatestTetheringEntitlementValue(int type, ResultReceiver receiver,
            boolean showEntitlementUi) {
        if (receiver != null) {
            mEntitlementMgr.getLatestTetheringEntitlementValue(type, receiver, showEntitlementUi);
        }
    }

    @Override
    public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
        // Binder.java closes the resource for us.
Loading