Add config flag for useDeclaredMethodsForCallbacks
Add a DeviceConfig flag that will be used to control whether callbacks should be sent selectively based on whether the receiving method has been overridden (will be implemented in a future change). This adds utilities to allow ConnectivityManager to check whether a ConnectivityService flag is enabled, as that feature will work across ConnectivityManager and ConnectivityService. ConnectivityManager runs in app process and does not necessarily have permissions to use DeviceConfig. Also if it checked DeviceConfig separately from ConnectivityService, values may be out-of-sync. Test: atest, and see change using this Change-Id: I204fa719cc627e84edc5c1e043d947f5ef3f8dee
This commit is contained in:
parent
08137f6e40
commit
aa355ac875
1 changed files with 56 additions and 2 deletions
|
|
@ -28,6 +28,7 @@ import static android.net.QosCallback.QosCallbackRegistrationException;
|
|||
import android.annotation.CallbackExecutor;
|
||||
import android.annotation.FlaggedApi;
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.LongDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.RequiresApi;
|
||||
|
|
@ -1207,6 +1208,16 @@ public class ConnectivityManager {
|
|||
})
|
||||
public @interface FirewallRule {}
|
||||
|
||||
/** @hide */
|
||||
public static final long FEATURE_USE_DECLARED_METHODS_FOR_CALLBACKS = 1L;
|
||||
|
||||
/** @hide */
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@LongDef(flag = true, prefix = "FEATURE_", value = {
|
||||
FEATURE_USE_DECLARED_METHODS_FOR_CALLBACKS
|
||||
})
|
||||
public @interface ConnectivityManagerFeature {}
|
||||
|
||||
/**
|
||||
* A kludge to facilitate static access where a Context pointer isn't available, like in the
|
||||
* case of the static set/getProcessDefaultNetwork methods and from the Network class.
|
||||
|
|
@ -1220,6 +1231,14 @@ public class ConnectivityManager {
|
|||
@GuardedBy("mTetheringEventCallbacks")
|
||||
private TetheringManager mTetheringManager;
|
||||
|
||||
private final Object mEnabledConnectivityManagerFeaturesLock = new Object();
|
||||
// mEnabledConnectivityManagerFeatures is lazy-loaded in this ConnectivityManager instance, but
|
||||
// fetched from ConnectivityService, where it is loaded in ConnectivityService startup, so it
|
||||
// should have consistent values.
|
||||
@GuardedBy("sEnabledConnectivityManagerFeaturesLock")
|
||||
@ConnectivityManagerFeature
|
||||
private Long mEnabledConnectivityManagerFeatures = null;
|
||||
|
||||
private TetheringManager getTetheringManager() {
|
||||
synchronized (mTetheringEventCallbacks) {
|
||||
if (mTetheringManager == null) {
|
||||
|
|
@ -4529,6 +4548,20 @@ public class ConnectivityManager {
|
|||
return request;
|
||||
}
|
||||
|
||||
private boolean isFeatureEnabled(@ConnectivityManagerFeature long connectivityManagerFeature) {
|
||||
synchronized (mEnabledConnectivityManagerFeaturesLock) {
|
||||
if (mEnabledConnectivityManagerFeatures == null) {
|
||||
try {
|
||||
mEnabledConnectivityManagerFeatures =
|
||||
mService.getEnabledConnectivityManagerFeatures();
|
||||
} catch (RemoteException e) {
|
||||
e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
return (mEnabledConnectivityManagerFeatures & connectivityManagerFeature) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
private NetworkRequest sendRequestForNetwork(NetworkCapabilities need, NetworkCallback callback,
|
||||
int timeoutMs, NetworkRequest.Type reqType, int legacyType, CallbackHandler handler) {
|
||||
return sendRequestForNetwork(Process.INVALID_UID, need, callback, timeoutMs, reqType,
|
||||
|
|
|
|||
Loading…
Reference in a new issue