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
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);
method public void onTetheringStarted();
}
- public abstract static class ConnectivityManager.TetheringEntitlementValueListener {
- ctor public ConnectivityManager.TetheringEntitlementValueListener();
+ public static interface ConnectivityManager.OnTetheringEntitlementResultListener {
method public void onEntitlementResult(int);
}
}
}
+ /** @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.
* {@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.");
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();
boolean isCallerCurrentAlwaysOnVpnApp();
boolean isCallerCurrentAlwaysOnVpnLockdownApp();
- void getLatestTetheringEntitlementValue(int type, in ResultReceiver receiver,
+ void getLatestTetheringEntitlementResult(int type, in ResultReceiver receiver,
boolean showEntitlementUi, String callerPkg);
}
* 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.
}
/** Get the latest value of the tethering entitlement check. */
- public void getLatestTetheringEntitlementValue(int type, ResultReceiver receiver,
+ public void getLatestTetheringEntitlementResult(int type, ResultReceiver receiver,
boolean showEntitlementUi) {
if (receiver != null) {
- mEntitlementMgr.getLatestTetheringEntitlementValue(type, receiver, showEntitlementUi);
+ mEntitlementMgr.getLatestTetheringEntitlementResult(type, receiver, showEntitlementUi);
}
}
}
/** Get the last value of the tethering entitlement check. */
- public void getLatestTetheringEntitlementValue(int downstream, ResultReceiver receiver,
+ public void getLatestTetheringEntitlementResult(int downstream, ResultReceiver receiver,
boolean showEntitlementUi) {
if (!isTetherProvisioningRequired()) {
receiver.send(TETHER_ERROR_NO_ERROR, null);
mCallbacklatch.countDown();
}
};
- mEnMgr.getLatestTetheringEntitlementValue(TETHERING_WIFI, receiver, true);
+ mEnMgr.getLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true);
callbackTimeoutHelper(mCallbacklatch);
assertFalse(mEnMgr.everRunUiEntitlement);
mCallbacklatch.countDown();
}
};
- mEnMgr.getLatestTetheringEntitlementValue(TETHERING_WIFI, receiver, false);
+ mEnMgr.getLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, false);
callbackTimeoutHelper(mCallbacklatch);
assertFalse(mEnMgr.everRunUiEntitlement);
// 3. No cache value and ui entitlement check is needed.
mCallbacklatch.countDown();
}
};
- mEnMgr.getLatestTetheringEntitlementValue(TETHERING_WIFI, receiver, true);
+ mEnMgr.getLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true);
mLooper.dispatchAll();
callbackTimeoutHelper(mCallbacklatch);
assertTrue(mEnMgr.everRunUiEntitlement);
mCallbacklatch.countDown();
}
};
- mEnMgr.getLatestTetheringEntitlementValue(TETHERING_WIFI, receiver, false);
+ mEnMgr.getLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, false);
callbackTimeoutHelper(mCallbacklatch);
assertFalse(mEnMgr.everRunUiEntitlement);
// 5. Cache value is TETHER_ERROR_PROVISION_FAILED and ui entitlement check is needed.
mCallbacklatch.countDown();
}
};
- mEnMgr.getLatestTetheringEntitlementValue(TETHERING_WIFI, receiver, true);
+ mEnMgr.getLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true);
mLooper.dispatchAll();
callbackTimeoutHelper(mCallbacklatch);
assertTrue(mEnMgr.everRunUiEntitlement);
mCallbacklatch.countDown();
}
};
- mEnMgr.getLatestTetheringEntitlementValue(TETHERING_WIFI, receiver, true);
+ mEnMgr.getLatestTetheringEntitlementResult(TETHERING_WIFI, receiver, true);
callbackTimeoutHelper(mCallbacklatch);
assertFalse(mEnMgr.everRunUiEntitlement);
// 7. Test get value for other downstream type.
mCallbacklatch.countDown();
}
};
- mEnMgr.getLatestTetheringEntitlementValue(TETHERING_USB, receiver, false);
+ mEnMgr.getLatestTetheringEntitlementResult(TETHERING_USB, receiver, false);
callbackTimeoutHelper(mCallbacklatch);
assertFalse(mEnMgr.everRunUiEntitlement);
}