1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.connectivity; 18 19 import android.content.Context; 20 21 import com.android.internal.annotations.VisibleForTesting; 22 import com.android.server.ConnectivityService; 23 24 /** 25 * Collection of constants for the connectivity module. 26 */ 27 public final class ConnectivityFlags { 28 /** 29 * Minimum module version at which to avoid rematching all requests when a network request is 30 * registered, and rematch only the registered requests instead. 31 */ 32 @VisibleForTesting 33 public static final String NO_REMATCH_ALL_REQUESTS_ON_REGISTER = 34 "no_rematch_all_requests_on_register"; 35 36 public static final String CARRIER_SERVICE_CHANGED_USE_CALLBACK = 37 "carrier_service_changed_use_callback_version"; 38 39 public static final String REQUEST_RESTRICTED_WIFI = 40 "request_restricted_wifi"; 41 42 public static final String INGRESS_TO_VPN_ADDRESS_FILTERING = 43 "ingress_to_vpn_address_filtering"; 44 45 public static final String BACKGROUND_FIREWALL_CHAIN = "background_firewall_chain"; 46 47 public static final String DELAY_DESTROY_SOCKETS = "delay_destroy_sockets"; 48 49 public static final String USE_DECLARED_METHODS_FOR_CALLBACKS = 50 "use_declared_methods_for_callbacks"; 51 52 private boolean mNoRematchAllRequestsOnRegister; 53 54 /** 55 * Whether ConnectivityService should avoid avoid rematching all requests when a network 56 * request is registered, and rematch only the registered requests instead. 57 * 58 * This flag is disabled by default. 59 * 60 * IMPORTANT NOTE: This flag is false by default and will only be loaded in ConnectivityService 61 * systemReady. It is also not volatile for performance reasons, so for most threads it may 62 * only change to true after some time. This is fine for this particular flag because it only 63 * controls whether all requests or a subset of requests should be rematched, which is only 64 * a performance optimization, so its value does not need to be consistent over time; but most 65 * flags will not have these properties and should not use the same model. 66 * 67 * TODO: when adding other flags, consider the appropriate timing to load them, and necessary 68 * threading guarantees according to the semantics of the flags. 69 */ noRematchAllRequestsOnRegister()70 public boolean noRematchAllRequestsOnRegister() { 71 return mNoRematchAllRequestsOnRegister; 72 } 73 74 /** 75 * Load flag values. Should only be called once, and can only be called once PackageManager is 76 * ready. 77 */ loadFlags(ConnectivityService.Dependencies deps, Context ctx)78 public void loadFlags(ConnectivityService.Dependencies deps, Context ctx) { 79 mNoRematchAllRequestsOnRegister = deps.isFeatureEnabled( 80 ctx, NO_REMATCH_ALL_REQUESTS_ON_REGISTER); 81 } 82 } 83