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

Commit 9554abf9 authored by markchien's avatar markchien
Browse files

Fix TetheringEntitlementValueListener related API

Test: -build, flash, boot
      -atest FrameworksNetTests
bug: 126701557
bug: 126392011

Change-Id: I6dda10fbfe8ffaef71269617750a22563396f5ea
parent 06e2f822
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -304,11 +304,17 @@ package android.media.tv {
package android.net {

  public class ConnectivityManager {
    method @Deprecated public void getLatestTetheringEntitlementValue(int, boolean, @NonNull android.net.ConnectivityManager.TetheringEntitlementValueListener, @Nullable android.os.Handler);
    method @Deprecated public boolean requestRouteToHost(int, int);
    method @Deprecated public int startUsingNetworkFeature(int, String);
    method @Deprecated public int stopUsingNetworkFeature(int, String);
  }

  @Deprecated public abstract static class ConnectivityManager.TetheringEntitlementValueListener {
    ctor public ConnectivityManager.TetheringEntitlementValueListener();
    method public void onEntitlementResult(int);
  }

  @Deprecated public class NetworkBadging {
    method @NonNull public static android.graphics.drawable.Drawable getWifiIcon(@IntRange(from=0, to=4) int, int, @Nullable android.content.res.Resources.Theme);
    field public static final int BADGING_4K = 30; // 0x1e
+2 −3
Original line number Diff line number Diff line
@@ -3098,7 +3098,7 @@ package android.net {
    method @RequiresPermission(android.Manifest.permission.PACKET_KEEPALIVE_OFFLOAD) public android.net.SocketKeepalive createSocketKeepalive(@NonNull android.net.Network, @NonNull java.net.Socket, @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(android.Manifest.permission.TETHER_PRIVILEGED) public void getLatestTetheringEntitlementResult(int, boolean, @NonNull java.util.concurrent.Executor, @NonNull android.net.ConnectivityManager.OnTetheringEntitlementResultListener);
    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.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK) public void startCaptivePortalApp(android.net.Network, android.os.Bundle);
@@ -3121,8 +3121,7 @@ package android.net {
    method public void onTetheringStarted();
  }
  public abstract static class ConnectivityManager.TetheringEntitlementValueListener {
    ctor public ConnectivityManager.TetheringEntitlementValueListener();
  public static interface ConnectivityManager.OnTetheringEntitlementResultListener {
    method public void onEntitlementResult(int);
  }
+62 −6
Original line number Diff line number Diff line
@@ -2681,12 +2681,39 @@ public class ConnectivityManager {
        }
    }

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(value = {
            TETHER_ERROR_NO_ERROR,
            TETHER_ERROR_PROVISION_FAILED,
            TETHER_ERROR_ENTITLEMENT_UNKONWN,
    })
    public @interface EntitlementResultCode {
    }

    /**
     * Callback for use with {@link #getLatestTetheringEntitlementValue} to find out whether
     * Callback for use with {@link #getLatestTetheringEntitlementResult} to find out whether
     * entitlement succeeded.
     * @hide
     */
    @SystemApi
    public interface OnTetheringEntitlementResultListener  {
        /**
         * Called to notify entitlement result.
         *
         * @param resultCode an 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}.
         */
        void onEntitlementResult(@EntitlementResultCode int resultCode);
    }

    /**
     * @removed
     * @deprecated This API would be removed when all of caller has been updated.
     * */
    @Deprecated
    public abstract static class TetheringEntitlementValueListener  {
        /**
         * Called to notify entitlement result.
@@ -2712,14 +2739,43 @@ public class ConnectivityManager {
     *         {@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.
     * @param executor the executor on which callback will be invoked.
     * @param listener an {@link OnTetheringEntitlementResultListener} which will be called to
     *         notify the caller of the result of entitlement check. The listener may be called zero
     *         or one time.
     * {@hide}
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
    public void getLatestTetheringEntitlementResult(int type, boolean showEntitlementUi,
            @NonNull @CallbackExecutor Executor executor,
            @NonNull final OnTetheringEntitlementResultListener listener) {
        Preconditions.checkNotNull(listener, "TetheringEntitlementResultListener cannot be null.");
        ResultReceiver wrappedListener = new ResultReceiver(null) {
            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
                Binder.withCleanCallingIdentity(() ->
                            executor.execute(() -> {
                                listener.onEntitlementResult(resultCode);
                            }));
            }
        };

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

    /**
     * @removed
     * @deprecated This API would be removed when all of caller has been updated.
     * */
    @Deprecated
    public void getLatestTetheringEntitlementValue(int type, boolean showEntitlementUi,
            @NonNull final TetheringEntitlementValueListener listener, @Nullable Handler handler) {
        Preconditions.checkNotNull(listener, "TetheringEntitlementValueListener cannot be null.");
@@ -2733,7 +2789,7 @@ public class ConnectivityManager {
        try {
            String pkgName = mContext.getOpPackageName();
            Log.i(TAG, "getLatestTetheringEntitlementValue:" + pkgName);
            mService.getLatestTetheringEntitlementValue(type, wrappedListener,
            mService.getLatestTetheringEntitlementResult(type, wrappedListener,
                    showEntitlementUi, pkgName);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
+1 −1
Original line number Diff line number Diff line
@@ -201,6 +201,6 @@ interface IConnectivityManager
    boolean isCallerCurrentAlwaysOnVpnApp();
    boolean isCallerCurrentAlwaysOnVpnLockdownApp();

    void getLatestTetheringEntitlementValue(int type, in ResultReceiver receiver,
    void getLatestTetheringEntitlementResult(int type, in ResultReceiver receiver,
            boolean showEntitlementUi, String callerPkg);
}
+2 −2
Original line number Diff line number Diff line
@@ -3758,10 +3758,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
     * if it's really needed.
     */
    @Override
    public void getLatestTetheringEntitlementValue(int type, ResultReceiver receiver,
    public void getLatestTetheringEntitlementResult(int type, ResultReceiver receiver,
            boolean showEntitlementUi, String callerPkg) {
        ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
        mTethering.getLatestTetheringEntitlementValue(type, receiver, showEntitlementUi);
        mTethering.getLatestTetheringEntitlementResult(type, receiver, showEntitlementUi);
    }

    // Called when we lose the default network and have no replacement yet.
Loading