Merge "DSUService: Deduplicate InstallUserdata() and InstallScratch()"

This commit is contained in:
Yo Chiang
2021-05-12 09:39:04 +00:00
committed by Gerrit Code Review

View File

@@ -320,20 +320,21 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog
} }
} }
private void installScratch() throws IOException { private void installWritablePartition(final String partitionName, final long partitionSize)
final long scratchSize = mDynSystem.suggestScratchSize(); throws IOException {
Log.d(TAG, "Creating writable partition: " + partitionName + ", size: " + partitionSize);
Thread thread = new Thread() { Thread thread = new Thread() {
@Override @Override
public void run() { public void run() {
mInstallationSession = mInstallationSession =
mDynSystem.createPartition("scratch", scratchSize, /* readOnly= */ false); mDynSystem.createPartition(
partitionName, partitionSize, /* readOnly= */ false);
} }
}; };
Log.d(TAG, "Creating partition: scratch, size = " + scratchSize);
thread.start(); thread.start();
Progress progress = new Progress(partitionName, partitionSize, mNumInstalledPartitions++);
Progress progress = new Progress("scratch", scratchSize, mNumInstalledPartitions++);
while (thread.isAlive()) { while (thread.isAlive()) {
if (isCancelled()) { if (isCancelled()) {
@@ -356,53 +357,22 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog
if (mInstallationSession == null) { if (mInstallationSession == null) {
throw new IOException( throw new IOException(
"Failed to start installation with requested size: " + scratchSize); "Failed to start installation with requested size: " + partitionSize);
} }
// Reset installation session and verify that installation completes successfully. // Reset installation session and verify that installation completes successfully.
mInstallationSession = null; mInstallationSession = null;
if (!mDynSystem.closePartition()) { if (!mDynSystem.closePartition()) {
throw new IOException("Failed to complete partition installation: scratch"); throw new IOException("Failed to complete partition installation: " + partitionName);
} }
} }
private void installScratch() throws IOException {
installWritablePartition("scratch", mDynSystem.suggestScratchSize());
}
private void installUserdata() throws IOException { private void installUserdata() throws IOException {
Thread thread = new Thread(() -> { installWritablePartition("userdata", mUserdataSize);
mInstallationSession = mDynSystem.createPartition("userdata", mUserdataSize, false);
});
Log.d(TAG, "Creating partition: userdata, size = " + mUserdataSize);
thread.start();
Progress progress = new Progress("userdata", mUserdataSize, mNumInstalledPartitions++);
while (thread.isAlive()) {
if (isCancelled()) {
return;
}
final long installedSize = mDynSystem.getInstallationProgress().bytes_processed;
if (installedSize > progress.installedSize + MIN_PROGRESS_TO_PUBLISH) {
progress.installedSize = installedSize;
publishProgress(progress);
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// Ignore the error.
}
}
if (mInstallationSession == null) {
throw new IOException(
"Failed to start installation with requested size: " + mUserdataSize);
}
// Reset installation session and verify that installation completes successfully.
mInstallationSession = null;
if (!mDynSystem.closePartition()) {
throw new IOException("Failed to complete partition installation: userdata");
}
} }
private void installImages() throws IOException, ImageValidationException { private void installImages() throws IOException, ImageValidationException {