Fix TetheringEntitlementValueListener related API

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

Change-Id: I6dda10fbfe8ffaef71269617750a22563396f5ea
This commit is contained in:
markchien
2019-03-06 16:25:00 +08:00
parent 8cf699851a
commit bf5ab01869
3 changed files with 65 additions and 9 deletions

View File

@@ -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. * entitlement succeeded.
* @hide * @hide
*/ */
@SystemApi @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 { public abstract static class TetheringEntitlementValueListener {
/** /**
* Called to notify entitlement result. * Called to notify entitlement result.
@@ -2712,14 +2739,43 @@ public class ConnectivityManager {
* {@link #TETHERING_USB}, or * {@link #TETHERING_USB}, or
* {@link #TETHERING_BLUETOOTH}. * {@link #TETHERING_BLUETOOTH}.
* @param showEntitlementUi a boolean indicating whether to run UI-based entitlement check. * @param showEntitlementUi a boolean indicating whether to run UI-based entitlement check.
* @param listener an {@link TetheringEntitlementValueListener} which will be called to notify * @param executor the executor on which callback will be invoked.
* the caller of the result of entitlement check. The listener may be called zero or * @param listener an {@link OnTetheringEntitlementResultListener} which will be called to
* one time. * notify the caller of the result of entitlement check. The listener may be called zero
* @param handler {@link Handler} to specify the thread upon which the listener will be invoked. * or one time.
* {@hide} * {@hide}
*/ */
@SystemApi @SystemApi
@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) @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, public void getLatestTetheringEntitlementValue(int type, boolean showEntitlementUi,
@NonNull final TetheringEntitlementValueListener listener, @Nullable Handler handler) { @NonNull final TetheringEntitlementValueListener listener, @Nullable Handler handler) {
Preconditions.checkNotNull(listener, "TetheringEntitlementValueListener cannot be null."); Preconditions.checkNotNull(listener, "TetheringEntitlementValueListener cannot be null.");
@@ -2733,7 +2789,7 @@ public class ConnectivityManager {
try { try {
String pkgName = mContext.getOpPackageName(); String pkgName = mContext.getOpPackageName();
Log.i(TAG, "getLatestTetheringEntitlementValue:" + pkgName); Log.i(TAG, "getLatestTetheringEntitlementValue:" + pkgName);
mService.getLatestTetheringEntitlementValue(type, wrappedListener, mService.getLatestTetheringEntitlementResult(type, wrappedListener,
showEntitlementUi, pkgName); showEntitlementUi, pkgName);
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();

View File

@@ -201,6 +201,6 @@ interface IConnectivityManager
boolean isCallerCurrentAlwaysOnVpnApp(); boolean isCallerCurrentAlwaysOnVpnApp();
boolean isCallerCurrentAlwaysOnVpnLockdownApp(); boolean isCallerCurrentAlwaysOnVpnLockdownApp();
void getLatestTetheringEntitlementValue(int type, in ResultReceiver receiver, void getLatestTetheringEntitlementResult(int type, in ResultReceiver receiver,
boolean showEntitlementUi, String callerPkg); boolean showEntitlementUi, String callerPkg);
} }

View File

@@ -3758,10 +3758,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
* if it's really needed. * if it's really needed.
*/ */
@Override @Override
public void getLatestTetheringEntitlementValue(int type, ResultReceiver receiver, public void getLatestTetheringEntitlementResult(int type, ResultReceiver receiver,
boolean showEntitlementUi, String callerPkg) { boolean showEntitlementUi, String callerPkg) {
ConnectivityManager.enforceTetherChangePermission(mContext, 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. // Called when we lose the default network and have no replacement yet.