diff options
author | Howard Chen <howardsoc@google.com> | 2019-08-05 16:56:12 +0800 |
---|---|---|
committer | Howard Chen <howardsoc@google.com> | 2019-09-09 18:14:48 +0800 |
commit | ae615b32cddb2b7c259bc552842991ac72f9a062 (patch) | |
tree | c1cafaf7530c0e014460dc4dea80238480288305 /packages/DynamicSystemInstallationService/src | |
parent | c44ee158b9f92b6381c221b7539371b5f73011ba (diff) |
Use Ashmem to reduce buffer copies
Use android.os.MemoryFile to allocate Ashmem and use gsid.setAshmem and
gsid.commitGsiChunkFromAshmem to submit data.
Bug: 138976291
Test: adb shell am start-activity \
-n com.android.dynsystem/com.android.dynsystem.VerificationActivity \
-a android.os.image.action.START_INSTALL \
-d file:///storage/emulated/0/Download/system.raw.gz \
--el KEY_SYSTEM_SIZE $(du -b system.raw|cut -f1) \
--el KEY_USERDATA_SIZE 8589934592
Change-Id: I6df718a8cc3f4e5835c9d20d0bf5bf8bb0daee22
Merged-In: I6df718a8cc3f4e5835c9d20d0bf5bf8bb0daee22
Diffstat (limited to 'packages/DynamicSystemInstallationService/src')
-rw-r--r-- | packages/DynamicSystemInstallationService/src/com/android/dynsystem/InstallationAsyncTask.java | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/packages/DynamicSystemInstallationService/src/com/android/dynsystem/InstallationAsyncTask.java b/packages/DynamicSystemInstallationService/src/com/android/dynsystem/InstallationAsyncTask.java index 077f7ecd3e46..cf286bdbde96 100644 --- a/packages/DynamicSystemInstallationService/src/com/android/dynsystem/InstallationAsyncTask.java +++ b/packages/DynamicSystemInstallationService/src/com/android/dynsystem/InstallationAsyncTask.java @@ -20,6 +20,8 @@ import android.content.Context; import android.gsi.GsiProgress; import android.net.Uri; import android.os.AsyncTask; +import android.os.MemoryFile; +import android.os.ParcelFileDescriptor; import android.os.image.DynamicSystemManager; import android.util.Log; import android.webkit.URLUtil; @@ -28,11 +30,9 @@ import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; -import java.util.Arrays; import java.util.Locale; import java.util.zip.GZIPInputStream; - class InstallationAsyncTask extends AsyncTask<String, Long, Throwable> { private static final String TAG = "InstallationAsyncTask"; @@ -125,28 +125,26 @@ class InstallationAsyncTask extends AsyncTask<String, Long, Throwable> { Thread.sleep(10); } - if (mInstallationSession == null) { - throw new IOException("Failed to start installation with requested size: " - + (mSystemSize + mUserdataSize)); + throw new IOException( + "Failed to start installation with requested size: " + + (mSystemSize + mUserdataSize)); } installedSize = mUserdataSize; + MemoryFile memoryFile = new MemoryFile("dsu", READ_BUFFER_SIZE); byte[] bytes = new byte[READ_BUFFER_SIZE]; - + mInstallationSession.setAshmem( + new ParcelFileDescriptor(memoryFile.getFileDescriptor()), READ_BUFFER_SIZE); int numBytesRead; - Log.d(TAG, "Start installation loop"); while ((numBytesRead = mStream.read(bytes, 0, READ_BUFFER_SIZE)) != -1) { + memoryFile.writeBytes(bytes, 0, 0, numBytesRead); if (isCancelled()) { break; } - - byte[] writeBuffer = numBytesRead == READ_BUFFER_SIZE - ? bytes : Arrays.copyOf(bytes, numBytesRead); - - if (!mInstallationSession.write(writeBuffer)) { + if (!mInstallationSession.submitFromAshmem(numBytesRead)) { throw new IOException("Failed write() to DynamicSystem"); } @@ -157,7 +155,6 @@ class InstallationAsyncTask extends AsyncTask<String, Long, Throwable> { reportedInstalledSize = installedSize; } } - return null; } catch (Exception e) { |