Add hidden flags parameter to addInterfaceStateListener
And pass it through to EthernetListener. This will be used to optionally include callbacks for NCM interfaces which are not tracked by the regex in tests. Test: TH Flag: EXEMPT mainline Change-Id: If388a37911d3b8ceb2be79f8d303f37560b2678b
This commit is contained in:
parent
d0869b0b08
commit
3454b0bdee
4 changed files with 45 additions and 10 deletions
|
|
@ -281,6 +281,36 @@ public class EthernetManager {
|
|||
@SystemApi(client = MODULE_LIBRARIES)
|
||||
public void addInterfaceStateListener(@NonNull Executor executor,
|
||||
@NonNull InterfaceStateListener listener) {
|
||||
addInterfaceStateListener(executor, listener, LISTENER_FLAG_DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
/** @hide */
|
||||
public static final int LISTENER_FLAG_DEFAULT = 0;
|
||||
|
||||
/**
|
||||
* Include callbacks for NCM interfaces which are not tracked by the regex.
|
||||
* @hide
|
||||
*/
|
||||
public static final int LISTENER_FLAG_INCLUDE_NCM = 1 << 0;
|
||||
|
||||
/** @hide */
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef(prefix = { "LISTENER_FLAG_" }, value = {
|
||||
LISTENER_FLAG_DEFAULT,
|
||||
LISTENER_FLAG_INCLUDE_NCM
|
||||
})
|
||||
public @interface ListenerFlag {}
|
||||
|
||||
/**
|
||||
* Listen to ethernet interface state changes
|
||||
*
|
||||
* Version of {@link #addInterfaceStateListener} that accepts flags for testing.
|
||||
* @hide
|
||||
*/
|
||||
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
||||
public void addInterfaceStateListener(@NonNull Executor executor,
|
||||
@NonNull InterfaceStateListener listener, @ListenerFlag int flags) {
|
||||
if (listener == null || executor == null) {
|
||||
throw new NullPointerException("listener and executor must not be null");
|
||||
}
|
||||
|
|
@ -297,15 +327,16 @@ public class EthernetManager {
|
|||
}
|
||||
};
|
||||
synchronized (mListenerLock) {
|
||||
addServiceListener(serviceListener);
|
||||
addServiceListener(serviceListener, flags);
|
||||
mIfaceServiceListeners.put(listener, serviceListener);
|
||||
}
|
||||
}
|
||||
|
||||
@GuardedBy("mListenerLock")
|
||||
private void addServiceListener(@NonNull final IEthernetServiceListener listener) {
|
||||
private void addServiceListener(@NonNull final IEthernetServiceListener listener,
|
||||
@ListenerFlag int flags) {
|
||||
try {
|
||||
mService.addListener(listener);
|
||||
mService.addListener(listener, flags);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
|
|
@ -673,7 +704,7 @@ public class EthernetManager {
|
|||
IpConfiguration configuration) {}
|
||||
};
|
||||
synchronized (mListenerLock) {
|
||||
addServiceListener(serviceListener);
|
||||
addServiceListener(serviceListener, LISTENER_FLAG_DEFAULT);
|
||||
mStateServiceListeners.put(listener, serviceListener);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ interface IEthernetManager
|
|||
IpConfiguration getConfiguration(String iface);
|
||||
void setConfiguration(String iface, in IpConfiguration config);
|
||||
boolean isAvailable(String iface);
|
||||
void addListener(in IEthernetServiceListener listener);
|
||||
void addListener(in IEthernetServiceListener listener, int flags);
|
||||
void removeListener(in IEthernetServiceListener listener);
|
||||
void setIncludeTestInterfaces(boolean include);
|
||||
void requestTetheredInterface(in ITetheredInterfaceCallback callback);
|
||||
|
|
|
|||
|
|
@ -26,10 +26,13 @@ import android.os.RemoteException;
|
|||
public class EthernetListener implements IInterface {
|
||||
private final IEthernetServiceListener mListener;
|
||||
private final boolean mHasUseRestrictedNetworksPermission;
|
||||
private final int mFlags;
|
||||
|
||||
public EthernetListener(IEthernetServiceListener listener, boolean canUseRestrictedNetworks) {
|
||||
public EthernetListener(IEthernetServiceListener listener, boolean canUseRestrictedNetworks,
|
||||
int flags) {
|
||||
mListener = listener;
|
||||
mHasUseRestrictedNetworksPermission = canUseRestrictedNetworks;
|
||||
mFlags = flags;
|
||||
}
|
||||
|
||||
/** Indicates whether the remote uid has USE_RESTRICTED_NETWORKS permission */
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import android.annotation.NonNull;
|
|||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.EthernetManager;
|
||||
import android.net.EthernetNetworkSpecifier;
|
||||
import android.net.EthernetNetworkUpdateRequest;
|
||||
import android.net.IEthernetManager;
|
||||
|
|
@ -166,7 +167,7 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
|
|||
* @param listener A {@link IEthernetServiceListener} to add.
|
||||
*/
|
||||
@Override
|
||||
public void addListener(IEthernetServiceListener listener) throws RemoteException {
|
||||
public void addListener(IEthernetServiceListener listener, int flags) throws RemoteException {
|
||||
Objects.requireNonNull(listener, "listener must not be null");
|
||||
PermissionUtils.enforceAccessNetworkStatePermission(mContext, TAG);
|
||||
final boolean hasUseRestrictedNetworksPermission = hasUseRestrictedNetworksPermission();
|
||||
|
|
@ -174,7 +175,7 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
|
|||
final long ident = Binder.clearCallingIdentity();
|
||||
try {
|
||||
final EthernetListener wrappedListener =
|
||||
new EthernetListener(listener, hasUseRestrictedNetworksPermission);
|
||||
new EthernetListener(listener, hasUseRestrictedNetworksPermission, flags);
|
||||
mTracker.addListener(wrappedListener);
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
|
|
@ -198,8 +199,8 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
|
|||
// extends IInterface> instead of just IInterface.
|
||||
// Note that hasUseRestrictedNetworksPermission is irrelevant in
|
||||
// this context and is only populated for the sake of completeness.
|
||||
final EthernetListener wrappedListener =
|
||||
new EthernetListener(listener, hasUseRestrictedNetworksPermission);
|
||||
final EthernetListener wrappedListener = new EthernetListener(listener,
|
||||
hasUseRestrictedNetworksPermission, EthernetManager.LISTENER_FLAG_DEFAULT);
|
||||
mTracker.removeListener(wrappedListener);
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
|
|
|
|||
Loading…
Reference in a new issue