Merge "Lifecycle: detecting blocked and unhealthy." into rvc-dev

This commit is contained in:
Alex Buynytskyy
2020-05-27 04:15:54 +00:00
committed by Android (Google) Code Review
14 changed files with 301 additions and 112 deletions

View File

@@ -19,6 +19,8 @@ package android.os.incremental;
import android.content.pm.DataLoaderParamsParcel;
import android.content.pm.IDataLoaderStatusListener;
import android.os.incremental.IncrementalNewFileParams;
import android.os.incremental.IStorageHealthListener;
import android.os.incremental.StorageHealthCheckParams;
/** @hide */
interface IIncrementalService {
@@ -34,7 +36,10 @@ interface IIncrementalService {
* Opens or creates a storage given a target path and data loader params. Returns the storage ID.
*/
int openStorage(in @utf8InCpp String path);
int createStorage(in @utf8InCpp String path, in DataLoaderParamsParcel params, in IDataLoaderStatusListener listener, int createMode);
int createStorage(in @utf8InCpp String path, in DataLoaderParamsParcel params, int createMode,
in IDataLoaderStatusListener statusListener,
in StorageHealthCheckParams healthCheckParams,
in IStorageHealthListener healthListener);
int createLinkedStorage(in @utf8InCpp String path, int otherStorageId, int createMode);
/**

View File

@@ -0,0 +1,35 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.os.incremental;
/** @hide */
oneway interface IStorageHealthListener {
/** OK status, no pending reads. */
const int HEALTH_STATUS_OK = 0;
/* Statuses depend on timeouts defined in StorageHealthCheckParams. */
/** Pending reads detected, waiting for params.blockedTimeoutMs to confirm blocked state. */
const int HEALTH_STATUS_READS_PENDING = 1;
/** There are reads pending for params.blockedTimeoutMs, waiting till
* params.unhealthyTimeoutMs to confirm unhealthy state. */
const int HEALTH_STATUS_BLOCKED = 2;
/** There are reads pending for params.unhealthyTimeoutMs>,
* marking storage as unhealthy. */
const int HEALTH_STATUS_UNHEALTHY = 3;
/** Health status callback. */
void onHealthStatus(in int storageId, in int status);
}

View File

@@ -65,7 +65,9 @@ public final class IncrementalFileStorages {
public static IncrementalFileStorages initialize(Context context,
@NonNull File stageDir,
@NonNull DataLoaderParams dataLoaderParams,
@Nullable IDataLoaderStatusListener dataLoaderStatusListener,
@Nullable IDataLoaderStatusListener statusListener,
@Nullable StorageHealthCheckParams healthCheckParams,
@Nullable IStorageHealthListener healthListener,
List<InstallationFileParcel> addedFiles) throws IOException {
// TODO(b/136132412): sanity check if session should not be incremental
IncrementalManager incrementalManager = (IncrementalManager) context.getSystemService(
@@ -75,9 +77,9 @@ public final class IncrementalFileStorages {
throw new IOException("Failed to obtain incrementalManager.");
}
final IncrementalFileStorages result =
new IncrementalFileStorages(stageDir, incrementalManager, dataLoaderParams,
dataLoaderStatusListener);
final IncrementalFileStorages result = new IncrementalFileStorages(stageDir,
incrementalManager, dataLoaderParams, statusListener, healthCheckParams,
healthListener);
for (InstallationFileParcel file : addedFiles) {
if (file.location == LOCATION_DATA_APP) {
try {
@@ -100,7 +102,9 @@ public final class IncrementalFileStorages {
private IncrementalFileStorages(@NonNull File stageDir,
@NonNull IncrementalManager incrementalManager,
@NonNull DataLoaderParams dataLoaderParams,
@Nullable IDataLoaderStatusListener dataLoaderStatusListener) throws IOException {
@Nullable IDataLoaderStatusListener statusListener,
@Nullable StorageHealthCheckParams healthCheckParams,
@Nullable IStorageHealthListener healthListener) throws IOException {
try {
mStageDir = stageDir;
mIncrementalManager = incrementalManager;
@@ -117,10 +121,9 @@ public final class IncrementalFileStorages {
mDefaultStorage.bind(stageDir.getAbsolutePath());
} else {
mDefaultStorage = mIncrementalManager.createStorage(stageDir.getAbsolutePath(),
dataLoaderParams,
dataLoaderStatusListener,
IncrementalManager.CREATE_MODE_CREATE
| IncrementalManager.CREATE_MODE_TEMPORARY_BIND, false);
dataLoaderParams, IncrementalManager.CREATE_MODE_CREATE
| IncrementalManager.CREATE_MODE_TEMPORARY_BIND, false,
statusListener, healthCheckParams, healthListener);
if (mDefaultStorage == null) {
throw new IOException(
"Couldn't create incremental storage at " + stageDir);

View File

@@ -110,11 +110,15 @@ public final class IncrementalManager {
*/
@Nullable
public IncrementalStorage createStorage(@NonNull String path,
@NonNull DataLoaderParams params, @Nullable IDataLoaderStatusListener listener,
@NonNull DataLoaderParams params,
@CreateMode int createMode,
boolean autoStartDataLoader) {
boolean autoStartDataLoader,
@Nullable IDataLoaderStatusListener statusListener,
@Nullable StorageHealthCheckParams healthCheckParams,
@Nullable IStorageHealthListener healthListener) {
try {
final int id = mService.createStorage(path, params.getData(), listener, createMode);
final int id = mService.createStorage(path, params.getData(), createMode,
statusListener, healthCheckParams, healthListener);
if (id < 0) {
return null;
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.os.incremental;
/**
* @hide
*/
parcelable StorageHealthCheckParams {
/** Timeouts of the oldest pending read.
* Valid values 0ms < blockedTimeoutMs < unhealthyTimeoutMs < storage page read timeout.
* Invalid values will disable health checking. */
/** To consider storage "blocked". */
int blockedTimeoutMs;
/** To consider storage "unhealthy". */
int unhealthyTimeoutMs;
/** After storage is marked "unhealthy", how often to check if it recovered.
* Valid value 1000ms < unhealthyMonitoringMs. */
int unhealthyMonitoringMs;
}