Use isTetheringFeatureNotChickenedOut for kill switch
Following CLs remove the default value from isFeatureEnabled since the
default value was difficult to use correctly.
For example, there was a code that use isAtLeastT() as default value and
expect feature is always enabled on T+ devices.
However, default value is used only when the device does not have the
flag value or flag value is 0.
So the expectation that the feature is always enabled on T+ devices is
not correct if flag is pushed to the device by mistake or the device is
upgraded from S to T but the flag value is not cleared.
If the feature should be always enabled on T+ devices, `isAtleastT() ||
isFeatureEnabled()` should be used instead of `isFeatureEnabled(
isAtleastT() /* defaultValue*/ )`
After the default value argument is removed from isFeatureEnabled,
isFeatureEnabled is used for default false flag and
isTetheringFeatureNotChickenedOut is used for default true kill switch flag.
automatic_on_off_keepalive_version flag is not configured and devices
don't have this flag value.
So updating to use isTetheringFeatureNotChickenedOut should not have any
behavior change.
Test: m
Bug: 279108992
Change-Id: I43ceab6cc5234bd5a43af3acbd7bd7344844c5a6
diff --git a/service/src/com/android/server/connectivity/AutomaticOnOffKeepaliveTracker.java b/service/src/com/android/server/connectivity/AutomaticOnOffKeepaliveTracker.java
index 4f2909c..3befcfa 100644
--- a/service/src/com/android/server/connectivity/AutomaticOnOffKeepaliveTracker.java
+++ b/service/src/com/android/server/connectivity/AutomaticOnOffKeepaliveTracker.java
@@ -20,7 +20,6 @@
import static android.net.SocketKeepalive.MIN_INTERVAL_SEC;
import static android.net.SocketKeepalive.SUCCESS;
import static android.net.SocketKeepalive.SUCCESS_PAUSED;
-import static android.provider.DeviceConfig.NAMESPACE_TETHERING;
import static android.system.OsConstants.AF_INET;
import static android.system.OsConstants.AF_INET6;
import static android.system.OsConstants.SOL_SOCKET;
@@ -92,8 +91,8 @@
private static final int[] ADDRESS_FAMILIES = new int[] {AF_INET6, AF_INET};
private static final long LOW_TCP_POLLING_INTERVAL_MS = 1_000L;
private static final int ADJUST_TCP_POLLING_DELAY_MS = 2000;
- private static final String AUTOMATIC_ON_OFF_KEEPALIVE_VERSION =
- "automatic_on_off_keepalive_version";
+ private static final String AUTOMATIC_ON_OFF_KEEPALIVE_DISABLE_FLAG =
+ "automatic_on_off_keepalive_disable_flag";
public static final long METRICS_COLLECTION_DURATION_MS = 24 * 60 * 60 * 1_000L;
// ConnectivityService parses message constants from itself and AutomaticOnOffKeepaliveTracker
@@ -219,8 +218,8 @@
// Reading DeviceConfig will check if the calling uid and calling package name are the
// same. Clear calling identity to align the calling uid and package
final boolean enabled = BinderUtils.withCleanCallingIdentity(
- () -> mDependencies.isFeatureEnabled(AUTOMATIC_ON_OFF_KEEPALIVE_VERSION,
- true /* defaultEnabled */));
+ () -> mDependencies.isTetheringFeatureNotChickenedOut(
+ AUTOMATIC_ON_OFF_KEEPALIVE_DISABLE_FLAG));
if (autoOnOff && enabled) {
mAutomaticOnOffState = STATE_ENABLED;
if (null == ki.mFd) {
@@ -700,8 +699,8 @@
// Clear calling identity to align the calling uid and package so that it won't fail if cts
// would like to call dump()
final boolean featureEnabled = BinderUtils.withCleanCallingIdentity(
- () -> mDependencies.isFeatureEnabled(AUTOMATIC_ON_OFF_KEEPALIVE_VERSION,
- true /* defaultEnabled */));
+ () -> mDependencies.isTetheringFeatureNotChickenedOut(
+ AUTOMATIC_ON_OFF_KEEPALIVE_DISABLE_FLAG));
pw.println("AutomaticOnOff enabled: " + featureEnabled);
pw.increaseIndent();
for (AutomaticOnOffKeepalive autoKi : mAutomaticOnOffKeepalives) {
@@ -969,16 +968,13 @@
}
/**
- * Find out if a feature is enabled from DeviceConfig.
+ * Find out if a feature is not disabled from DeviceConfig.
*
* @param name The name of the property to look up.
- * @param defaultEnabled whether to consider the feature enabled in the absence of
- * the flag. This MUST be a statically-known constant.
* @return whether the feature is enabled
*/
- public boolean isFeatureEnabled(@NonNull final String name, final boolean defaultEnabled) {
- return DeviceConfigUtils.isFeatureEnabled(mContext, NAMESPACE_TETHERING, name,
- DeviceConfigUtils.TETHERING_MODULE_NAME, defaultEnabled);
+ public boolean isTetheringFeatureNotChickenedOut(@NonNull final String name) {
+ return DeviceConfigUtils.isTetheringFeatureNotChickenedOut(name);
}
/**
diff --git a/tests/unit/java/com/android/server/ConnectivityServiceTest.java b/tests/unit/java/com/android/server/ConnectivityServiceTest.java
index 3688d83..708697c 100755
--- a/tests/unit/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/unit/java/com/android/server/ConnectivityServiceTest.java
@@ -2301,7 +2301,7 @@
}
@Override
- public boolean isFeatureEnabled(@NonNull final String name, final boolean defaultEnabled) {
+ public boolean isTetheringFeatureNotChickenedOut(@NonNull final String name) {
// Tests for enabling the feature are verified in AutomaticOnOffKeepaliveTrackerTest.
// Assuming enabled here to focus on ConnectivityService tests.
return true;
diff --git a/tests/unit/java/com/android/server/connectivity/AutomaticOnOffKeepaliveTrackerTest.java b/tests/unit/java/com/android/server/connectivity/AutomaticOnOffKeepaliveTrackerTest.java
index b69b042..1b71fb9 100644
--- a/tests/unit/java/com/android/server/connectivity/AutomaticOnOffKeepaliveTrackerTest.java
+++ b/tests/unit/java/com/android/server/connectivity/AutomaticOnOffKeepaliveTrackerTest.java
@@ -32,7 +32,6 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.longThat;
@@ -359,7 +358,7 @@
.when(mDependencies)
.newKeepaliveStatsTracker(mCtx, mTestHandler);
- doReturn(true).when(mDependencies).isFeatureEnabled(any(), anyBoolean());
+ doReturn(true).when(mDependencies).isTetheringFeatureNotChickenedOut(any());
doReturn(0L).when(mDependencies).getElapsedRealtime();
mAOOKeepaliveTracker =
new AutomaticOnOffKeepaliveTracker(mCtx, mTestHandler, mDependencies);