Merge "Refactor InstallationAsyncTask.Progress" am: 93e3644f88

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1537221

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Id0bde5d3c07fbf1c8dde5aada73e1d84b359a855
This commit is contained in:
Yo Chiang
2020-12-31 03:48:47 +00:00
committed by Automerger Merge Worker
2 changed files with 29 additions and 43 deletions

View File

@@ -211,10 +211,10 @@ public class DynamicSystemInstallationService extends Service
@Override @Override
public void onProgressUpdate(InstallationAsyncTask.Progress progress) { public void onProgressUpdate(InstallationAsyncTask.Progress progress) {
mCurrentPartitionName = progress.mPartitionName; mCurrentPartitionName = progress.partitionName;
mCurrentPartitionSize = progress.mPartitionSize; mCurrentPartitionSize = progress.partitionSize;
mCurrentPartitionInstalledSize = progress.mInstalledSize; mCurrentPartitionInstalledSize = progress.installedSize;
mNumInstalledPartitions = progress.mNumInstalledPartitions; mNumInstalledPartitions = progress.numInstalledPartitions;
postStatus(STATUS_IN_PROGRESS, CAUSE_NOT_SPECIFIED, null); postStatus(STATUS_IN_PROGRESS, CAUSE_NOT_SPECIFIED, null);
} }

View File

@@ -102,20 +102,16 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog
static final int RESULT_ERROR_UNSUPPORTED_FORMAT = 5; static final int RESULT_ERROR_UNSUPPORTED_FORMAT = 5;
static final int RESULT_ERROR_EXCEPTION = 6; static final int RESULT_ERROR_EXCEPTION = 6;
class Progress { static class Progress {
String mPartitionName; public final String partitionName;
long mPartitionSize; public final long partitionSize;
long mInstalledSize; public final int numInstalledPartitions;
public long installedSize;
int mNumInstalledPartitions; Progress(String partitionName, long partitionSize, int numInstalledPartitions) {
this.partitionName = partitionName;
Progress(String partitionName, long partitionSize, long installedSize, this.partitionSize = partitionSize;
int numInstalled) { this.numInstalledPartitions = numInstalledPartitions;
mPartitionName = partitionName;
mPartitionSize = partitionSize;
mInstalledSize = installedSize;
mNumInstalledPartitions = numInstalled;
} }
} }
@@ -141,6 +137,8 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog
private boolean mIsZip; private boolean mIsZip;
private boolean mIsCompleted; private boolean mIsCompleted;
private int mNumInstalledPartitions;
private InputStream mStream; private InputStream mStream;
private ZipFile mZipFile; private ZipFile mZipFile;
@@ -312,18 +310,17 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog
Log.d(TAG, "Creating partition: userdata"); Log.d(TAG, "Creating partition: userdata");
thread.start(); thread.start();
long installedSize = 0; Progress progress = new Progress("userdata", mUserdataSize, mNumInstalledPartitions++);
Progress progress = new Progress("userdata", mUserdataSize, installedSize, 0);
while (thread.isAlive()) { while (thread.isAlive()) {
if (isCancelled()) { if (isCancelled()) {
return; return;
} }
installedSize = mDynSystem.getInstallationProgress().bytes_processed; final long installedSize = mDynSystem.getInstallationProgress().bytes_processed;
if (installedSize > progress.mInstalledSize + MIN_PROGRESS_TO_PUBLISH) { if (installedSize > progress.installedSize + MIN_PROGRESS_TO_PUBLISH) {
progress.mInstalledSize = installedSize; progress.installedSize = installedSize;
publishProgress(progress); publishProgress(progress);
} }
@@ -357,7 +354,7 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog
private void installStreamingGzUpdate() private void installStreamingGzUpdate()
throws IOException, InterruptedException, ImageValidationException { throws IOException, InterruptedException, ImageValidationException {
Log.d(TAG, "To install a streaming GZ update"); Log.d(TAG, "To install a streaming GZ update");
installImage("system", mSystemSize, new GZIPInputStream(mStream), 1); installImage("system", mSystemSize, new GZIPInputStream(mStream));
} }
private void installStreamingZipUpdate() private void installStreamingZipUpdate()
@@ -367,12 +364,8 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog
ZipInputStream zis = new ZipInputStream(mStream); ZipInputStream zis = new ZipInputStream(mStream);
ZipEntry zipEntry = null; ZipEntry zipEntry = null;
int numInstalledPartitions = 1;
while ((zipEntry = zis.getNextEntry()) != null) { while ((zipEntry = zis.getNextEntry()) != null) {
if (installImageFromAnEntry(zipEntry, zis, numInstalledPartitions)) { installImageFromAnEntry(zipEntry, zis);
numInstalledPartitions++;
}
if (isCancelled()) { if (isCancelled()) {
break; break;
@@ -385,14 +378,10 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog
Log.d(TAG, "To install a local ZIP update"); Log.d(TAG, "To install a local ZIP update");
Enumeration<? extends ZipEntry> entries = mZipFile.entries(); Enumeration<? extends ZipEntry> entries = mZipFile.entries();
int numInstalledPartitions = 1;
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement(); ZipEntry entry = entries.nextElement();
if (installImageFromAnEntry( installImageFromAnEntry(entry, mZipFile.getInputStream(entry));
entry, mZipFile.getInputStream(entry), numInstalledPartitions)) {
numInstalledPartitions++;
}
if (isCancelled()) { if (isCancelled()) {
break; break;
@@ -400,8 +389,7 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog
} }
} }
private boolean installImageFromAnEntry( private boolean installImageFromAnEntry(ZipEntry entry, InputStream is)
ZipEntry entry, InputStream is, int numInstalledPartitions)
throws IOException, InterruptedException, ImageValidationException { throws IOException, InterruptedException, ImageValidationException {
String name = entry.getName(); String name = entry.getName();
@@ -420,13 +408,12 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog
long uncompressedSize = entry.getSize(); long uncompressedSize = entry.getSize();
installImage(partitionName, uncompressedSize, is, numInstalledPartitions); installImage(partitionName, uncompressedSize, is);
return true; return true;
} }
private void installImage( private void installImage(String partitionName, long uncompressedSize, InputStream is)
String partitionName, long uncompressedSize, InputStream is, int numInstalledPartitions)
throws IOException, InterruptedException, ImageValidationException { throws IOException, InterruptedException, ImageValidationException {
SparseInputStream sis = new SparseInputStream(new BufferedInputStream(is)); SparseInputStream sis = new SparseInputStream(new BufferedInputStream(is));
@@ -473,10 +460,9 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog
mInstallationSession.setAshmem(pfd, READ_BUFFER_SIZE); mInstallationSession.setAshmem(pfd, READ_BUFFER_SIZE);
long installedSize = 0; Progress progress = new Progress(partitionName, partitionSize, mNumInstalledPartitions++);
Progress progress = new Progress(
partitionName, partitionSize, installedSize, numInstalledPartitions);
long installedSize = 0;
byte[] bytes = new byte[READ_BUFFER_SIZE]; byte[] bytes = new byte[READ_BUFFER_SIZE];
int numBytesRead; int numBytesRead;
@@ -493,8 +479,8 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog
installedSize += numBytesRead; installedSize += numBytesRead;
if (installedSize > progress.mInstalledSize + MIN_PROGRESS_TO_PUBLISH) { if (installedSize > progress.installedSize + MIN_PROGRESS_TO_PUBLISH) {
progress.mInstalledSize = installedSize; progress.installedSize = installedSize;
publishProgress(progress); publishProgress(progress);
} }
} }