Merge "Make Watchdog request timeout flag configurable" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
62a176c140
@@ -18,6 +18,7 @@ package android.ext.services.watchdog;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.service.watchdog.ExplicitHealthCheckService;
|
||||
import android.service.watchdog.PackageInfo;
|
||||
import android.util.Log;
|
||||
@@ -27,6 +28,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Routes explicit health check requests to the appropriate {@link ExplicitHealthChecker}.
|
||||
@@ -36,6 +38,10 @@ public final class ExplicitHealthCheckServiceImpl extends ExplicitHealthCheckSer
|
||||
// TODO: Add build dependency on NetworkStack stable AIDL so we can stop hard coding class name
|
||||
private static final String NETWORK_STACK_CONNECTOR_CLASS =
|
||||
"android.net.INetworkStackConnector";
|
||||
private static final String PROPERTY_WATCHDOG_REQUEST_TIMEOUT_MILLIS =
|
||||
"watchdog_request_timeout_millis";
|
||||
private static final long DEFAULT_REQUEST_TIMEOUT_MILLIS =
|
||||
TimeUnit.HOURS.toMillis(1);
|
||||
// Modified only #onCreate, using concurrent collection to ensure thread visibility
|
||||
private final Map<String, ExplicitHealthChecker> mSupportedCheckers = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -70,8 +76,17 @@ public final class ExplicitHealthCheckServiceImpl extends ExplicitHealthCheckSer
|
||||
@Override
|
||||
public List<PackageInfo> onGetSupportedPackages() {
|
||||
List<PackageInfo> packages = new ArrayList<>();
|
||||
long requestTimeoutMillis = DeviceConfig.getLong(
|
||||
DeviceConfig.NAMESPACE_ROLLBACK,
|
||||
PROPERTY_WATCHDOG_REQUEST_TIMEOUT_MILLIS,
|
||||
DEFAULT_REQUEST_TIMEOUT_MILLIS);
|
||||
if (requestTimeoutMillis <= 0) {
|
||||
requestTimeoutMillis = DEFAULT_REQUEST_TIMEOUT_MILLIS;
|
||||
}
|
||||
for (ExplicitHealthChecker checker : mSupportedCheckers.values()) {
|
||||
packages.add(checker.getSupportedPackage());
|
||||
PackageInfo pkg = new PackageInfo(checker.getSupportedPackageName(),
|
||||
requestTimeoutMillis);
|
||||
packages.add(pkg);
|
||||
}
|
||||
return packages;
|
||||
}
|
||||
@@ -87,7 +102,7 @@ public final class ExplicitHealthCheckServiceImpl extends ExplicitHealthCheckSer
|
||||
while (it.hasNext()) {
|
||||
ExplicitHealthChecker checker = it.next();
|
||||
if (checker.isPending()) {
|
||||
packages.add(checker.getSupportedPackage().getPackageName());
|
||||
packages.add(checker.getSupportedPackageName());
|
||||
}
|
||||
}
|
||||
return packages;
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package android.ext.services.watchdog;
|
||||
|
||||
import android.service.watchdog.PackageInfo;
|
||||
|
||||
/**
|
||||
* A type of explicit health check that can be performed on a device, e.g network health check
|
||||
*/
|
||||
@@ -40,7 +38,7 @@ interface ExplicitHealthChecker {
|
||||
boolean isPending();
|
||||
|
||||
/**
|
||||
* Returns the {@link PackageInfo} object this checker can make requests for.
|
||||
* Returns the name of the package this checker can make requests for.
|
||||
*/
|
||||
PackageInfo getSupportedPackage();
|
||||
String getSupportedPackageName();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkRequest;
|
||||
import android.service.watchdog.ExplicitHealthCheckService;
|
||||
import android.service.watchdog.PackageInfo;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
|
||||
@@ -35,8 +34,6 @@ final class NetworkChecker extends ConnectivityManager.NetworkCallback
|
||||
private final Object mLock = new Object();
|
||||
private final ExplicitHealthCheckService mService;
|
||||
private final String mPackageName;
|
||||
// TODO: Receive from DeviceConfig flag
|
||||
private final long mRequestDurationMillis = 0;
|
||||
@GuardedBy("mLock")
|
||||
private boolean mIsPending;
|
||||
|
||||
@@ -76,8 +73,8 @@ final class NetworkChecker extends ConnectivityManager.NetworkCallback
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackageInfo getSupportedPackage() {
|
||||
return new PackageInfo(mPackageName, mRequestDurationMillis);
|
||||
public String getSupportedPackageName() {
|
||||
return mPackageName;
|
||||
}
|
||||
|
||||
// TODO(b/120598832): Also monitor NetworkCallback#onAvailable to see if we have any
|
||||
|
||||
Reference in New Issue
Block a user