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 private boolean mNoRematchAllRequestsOnRegister; 37 38 /** 39 * Whether ConnectivityService should avoid avoid rematching all requests when a network 40 * request is registered, and rematch only the registered requests instead. 41 * 42 * This flag is disabled by default. 43 * 44 * IMPORTANT NOTE: This flag is false by default and will only be loaded in ConnectivityService 45 * systemReady. It is also not volatile for performance reasons, so for most threads it may 46 * only change to true after some time. This is fine for this particular flag because it only 47 * controls whether all requests or a subset of requests should be rematched, which is only 48 * a performance optimization, so its value does not need to be consistent over time; but most 49 * flags will not have these properties and should not use the same model. 50 * 51 * TODO: when adding other flags, consider the appropriate timing to load them, and necessary 52 * threading guarantees according to the semantics of the flags. 53 */ noRematchAllRequestsOnRegister()54 public boolean noRematchAllRequestsOnRegister() { 55 return mNoRematchAllRequestsOnRegister; 56 } 57 58 /** 59 * Load flag values. Should only be called once, and can only be called once PackageManager is 60 * ready. 61 */ loadFlags(ConnectivityService.Dependencies deps, Context ctx)62 public void loadFlags(ConnectivityService.Dependencies deps, Context ctx) { 63 mNoRematchAllRequestsOnRegister = deps.isFeatureEnabled( 64 ctx, NO_REMATCH_ALL_REQUESTS_ON_REGISTER, false /* defaultEnabled */); 65 } 66 } 67