Merge "Use isTetheringFeatureNotChickenedOut for kill switch" into main

This commit is contained in:
Motomu Utsumi
2023-08-17 06:13:21 +00:00
committed by Gerrit Code Review
3 changed files with 11 additions and 16 deletions

View File

@@ -20,7 +20,6 @@ import static android.net.SocketKeepalive.ERROR_INVALID_SOCKET;
import static android.net.SocketKeepalive.MIN_INTERVAL_SEC; import static android.net.SocketKeepalive.MIN_INTERVAL_SEC;
import static android.net.SocketKeepalive.SUCCESS; import static android.net.SocketKeepalive.SUCCESS;
import static android.net.SocketKeepalive.SUCCESS_PAUSED; 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_INET;
import static android.system.OsConstants.AF_INET6; import static android.system.OsConstants.AF_INET6;
import static android.system.OsConstants.SOL_SOCKET; import static android.system.OsConstants.SOL_SOCKET;
@@ -92,8 +91,8 @@ public class AutomaticOnOffKeepaliveTracker {
private static final int[] ADDRESS_FAMILIES = new int[] {AF_INET6, AF_INET}; 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 long LOW_TCP_POLLING_INTERVAL_MS = 1_000L;
private static final int ADJUST_TCP_POLLING_DELAY_MS = 2000; private static final int ADJUST_TCP_POLLING_DELAY_MS = 2000;
private static final String AUTOMATIC_ON_OFF_KEEPALIVE_VERSION = private static final String AUTOMATIC_ON_OFF_KEEPALIVE_DISABLE_FLAG =
"automatic_on_off_keepalive_version"; "automatic_on_off_keepalive_disable_flag";
public static final long METRICS_COLLECTION_DURATION_MS = 24 * 60 * 60 * 1_000L; public static final long METRICS_COLLECTION_DURATION_MS = 24 * 60 * 60 * 1_000L;
// ConnectivityService parses message constants from itself and AutomaticOnOffKeepaliveTracker // ConnectivityService parses message constants from itself and AutomaticOnOffKeepaliveTracker
@@ -219,8 +218,8 @@ public class AutomaticOnOffKeepaliveTracker {
// Reading DeviceConfig will check if the calling uid and calling package name are the // 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 // same. Clear calling identity to align the calling uid and package
final boolean enabled = BinderUtils.withCleanCallingIdentity( final boolean enabled = BinderUtils.withCleanCallingIdentity(
() -> mDependencies.isFeatureEnabled(AUTOMATIC_ON_OFF_KEEPALIVE_VERSION, () -> mDependencies.isTetheringFeatureNotChickenedOut(
true /* defaultEnabled */)); AUTOMATIC_ON_OFF_KEEPALIVE_DISABLE_FLAG));
if (autoOnOff && enabled) { if (autoOnOff && enabled) {
mAutomaticOnOffState = STATE_ENABLED; mAutomaticOnOffState = STATE_ENABLED;
if (null == ki.mFd) { if (null == ki.mFd) {
@@ -700,8 +699,8 @@ public class AutomaticOnOffKeepaliveTracker {
// Clear calling identity to align the calling uid and package so that it won't fail if cts // Clear calling identity to align the calling uid and package so that it won't fail if cts
// would like to call dump() // would like to call dump()
final boolean featureEnabled = BinderUtils.withCleanCallingIdentity( final boolean featureEnabled = BinderUtils.withCleanCallingIdentity(
() -> mDependencies.isFeatureEnabled(AUTOMATIC_ON_OFF_KEEPALIVE_VERSION, () -> mDependencies.isTetheringFeatureNotChickenedOut(
true /* defaultEnabled */)); AUTOMATIC_ON_OFF_KEEPALIVE_DISABLE_FLAG));
pw.println("AutomaticOnOff enabled: " + featureEnabled); pw.println("AutomaticOnOff enabled: " + featureEnabled);
pw.increaseIndent(); pw.increaseIndent();
for (AutomaticOnOffKeepalive autoKi : mAutomaticOnOffKeepalives) { for (AutomaticOnOffKeepalive autoKi : mAutomaticOnOffKeepalives) {
@@ -969,16 +968,13 @@ public class AutomaticOnOffKeepaliveTracker {
} }
/** /**
* 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 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 * @return whether the feature is enabled
*/ */
public boolean isFeatureEnabled(@NonNull final String name, final boolean defaultEnabled) { public boolean isTetheringFeatureNotChickenedOut(@NonNull final String name) {
return DeviceConfigUtils.isFeatureEnabled(mContext, NAMESPACE_TETHERING, name, return DeviceConfigUtils.isTetheringFeatureNotChickenedOut(name);
DeviceConfigUtils.TETHERING_MODULE_NAME, defaultEnabled);
} }
/** /**

View File

@@ -2301,7 +2301,7 @@ public class ConnectivityServiceTest {
} }
@Override @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. // Tests for enabling the feature are verified in AutomaticOnOffKeepaliveTrackerTest.
// Assuming enabled here to focus on ConnectivityService tests. // Assuming enabled here to focus on ConnectivityService tests.
return true; return true;

View File

@@ -32,7 +32,6 @@ import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.longThat; import static org.mockito.ArgumentMatchers.longThat;
@@ -359,7 +358,7 @@ public class AutomaticOnOffKeepaliveTrackerTest {
.when(mDependencies) .when(mDependencies)
.newKeepaliveStatsTracker(mCtx, mTestHandler); .newKeepaliveStatsTracker(mCtx, mTestHandler);
doReturn(true).when(mDependencies).isFeatureEnabled(any(), anyBoolean()); doReturn(true).when(mDependencies).isTetheringFeatureNotChickenedOut(any());
doReturn(0L).when(mDependencies).getElapsedRealtime(); doReturn(0L).when(mDependencies).getElapsedRealtime();
mAOOKeepaliveTracker = mAOOKeepaliveTracker =
new AutomaticOnOffKeepaliveTracker(mCtx, mTestHandler, mDependencies); new AutomaticOnOffKeepaliveTracker(mCtx, mTestHandler, mDependencies);