diff options
author | Yo Chiang <yochiang@google.com> | 2020-12-31 03:48:47 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-12-31 03:48:47 +0000 |
commit | 33ad4e1225ecf39ceb7bab09c6767e36b09b33e7 (patch) | |
tree | 28fe07532c3c72c0303ee20fed750a2722226507 /packages/DynamicSystemInstallationService | |
parent | 1b42f73abd831896fb643dc4b207a22d6dc6d5ba (diff) | |
parent | 93e3644f88f28677b73d12fe10ba4c6f73f07523 (diff) |
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
Diffstat (limited to 'packages/DynamicSystemInstallationService')
2 files changed, 29 insertions, 43 deletions
diff --git a/packages/DynamicSystemInstallationService/src/com/android/dynsystem/DynamicSystemInstallationService.java b/packages/DynamicSystemInstallationService/src/com/android/dynsystem/DynamicSystemInstallationService.java index ac2758011816..a4896cb2d8dc 100644 --- a/packages/DynamicSystemInstallationService/src/com/android/dynsystem/DynamicSystemInstallationService.java +++ b/packages/DynamicSystemInstallationService/src/com/android/dynsystem/DynamicSystemInstallationService.java @@ -211,10 +211,10 @@ public class DynamicSystemInstallationService extends Service @Override public void onProgressUpdate(InstallationAsyncTask.Progress progress) { - mCurrentPartitionName = progress.mPartitionName; - mCurrentPartitionSize = progress.mPartitionSize; - mCurrentPartitionInstalledSize = progress.mInstalledSize; - mNumInstalledPartitions = progress.mNumInstalledPartitions; + mCurrentPartitionName = progress.partitionName; + mCurrentPartitionSize = progress.partitionSize; + mCurrentPartitionInstalledSize = progress.installedSize; + mNumInstalledPartitions = progress.numInstalledPartitions; postStatus(STATUS_IN_PROGRESS, CAUSE_NOT_SPECIFIED, null); } diff --git a/packages/DynamicSystemInstallationService/src/com/android/dynsystem/InstallationAsyncTask.java b/packages/DynamicSystemInstallationService/src/com/android/dynsystem/InstallationAsyncTask.java index 4d31ce97e8b7..ac73f35517d6 100644 --- a/packages/DynamicSystemInstallationService/src/com/android/dynsystem/InstallationAsyncTask.java +++ b/packages/DynamicSystemInstallationService/src/com/android/dynsystem/InstallationAsyncTask.java @@ -102,20 +102,16 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog static final int RESULT_ERROR_UNSUPPORTED_FORMAT = 5; static final int RESULT_ERROR_EXCEPTION = 6; - class Progress { - String mPartitionName; - long mPartitionSize; - long mInstalledSize; + static class Progress { + public final String partitionName; + public final long partitionSize; + public final int numInstalledPartitions; + public long installedSize; - int mNumInstalledPartitions; - - Progress(String partitionName, long partitionSize, long installedSize, - int numInstalled) { - mPartitionName = partitionName; - mPartitionSize = partitionSize; - mInstalledSize = installedSize; - - mNumInstalledPartitions = numInstalled; + Progress(String partitionName, long partitionSize, int numInstalledPartitions) { + this.partitionName = partitionName; + this.partitionSize = partitionSize; + this.numInstalledPartitions = numInstalledPartitions; } } @@ -141,6 +137,8 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog private boolean mIsZip; private boolean mIsCompleted; + private int mNumInstalledPartitions; + private InputStream mStream; private ZipFile mZipFile; @@ -312,18 +310,17 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog Log.d(TAG, "Creating partition: userdata"); thread.start(); - long installedSize = 0; - Progress progress = new Progress("userdata", mUserdataSize, installedSize, 0); + Progress progress = new Progress("userdata", mUserdataSize, mNumInstalledPartitions++); while (thread.isAlive()) { if (isCancelled()) { return; } - installedSize = mDynSystem.getInstallationProgress().bytes_processed; + final long installedSize = mDynSystem.getInstallationProgress().bytes_processed; - if (installedSize > progress.mInstalledSize + MIN_PROGRESS_TO_PUBLISH) { - progress.mInstalledSize = installedSize; + if (installedSize > progress.installedSize + MIN_PROGRESS_TO_PUBLISH) { + progress.installedSize = installedSize; publishProgress(progress); } @@ -357,7 +354,7 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog private void installStreamingGzUpdate() throws IOException, InterruptedException, ImageValidationException { 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() @@ -367,12 +364,8 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog ZipInputStream zis = new ZipInputStream(mStream); ZipEntry zipEntry = null; - int numInstalledPartitions = 1; - while ((zipEntry = zis.getNextEntry()) != null) { - if (installImageFromAnEntry(zipEntry, zis, numInstalledPartitions)) { - numInstalledPartitions++; - } + installImageFromAnEntry(zipEntry, zis); if (isCancelled()) { break; @@ -385,14 +378,10 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog Log.d(TAG, "To install a local ZIP update"); Enumeration<? extends ZipEntry> entries = mZipFile.entries(); - int numInstalledPartitions = 1; while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); - if (installImageFromAnEntry( - entry, mZipFile.getInputStream(entry), numInstalledPartitions)) { - numInstalledPartitions++; - } + installImageFromAnEntry(entry, mZipFile.getInputStream(entry)); if (isCancelled()) { break; @@ -400,8 +389,7 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog } } - private boolean installImageFromAnEntry( - ZipEntry entry, InputStream is, int numInstalledPartitions) + private boolean installImageFromAnEntry(ZipEntry entry, InputStream is) throws IOException, InterruptedException, ImageValidationException { String name = entry.getName(); @@ -420,13 +408,12 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog long uncompressedSize = entry.getSize(); - installImage(partitionName, uncompressedSize, is, numInstalledPartitions); + installImage(partitionName, uncompressedSize, is); return true; } - private void installImage( - String partitionName, long uncompressedSize, InputStream is, int numInstalledPartitions) + private void installImage(String partitionName, long uncompressedSize, InputStream is) throws IOException, InterruptedException, ImageValidationException { SparseInputStream sis = new SparseInputStream(new BufferedInputStream(is)); @@ -473,10 +460,9 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog mInstallationSession.setAshmem(pfd, READ_BUFFER_SIZE); - long installedSize = 0; - Progress progress = new Progress( - partitionName, partitionSize, installedSize, numInstalledPartitions); + Progress progress = new Progress(partitionName, partitionSize, mNumInstalledPartitions++); + long installedSize = 0; byte[] bytes = new byte[READ_BUFFER_SIZE]; int numBytesRead; @@ -493,8 +479,8 @@ class InstallationAsyncTask extends AsyncTask<String, InstallationAsyncTask.Prog installedSize += numBytesRead; - if (installedSize > progress.mInstalledSize + MIN_PROGRESS_TO_PUBLISH) { - progress.mInstalledSize = installedSize; + if (installedSize > progress.installedSize + MIN_PROGRESS_TO_PUBLISH) { + progress.installedSize = installedSize; publishProgress(progress); } } |