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
This commit is contained in:
Howard Chen
2019-08-05 16:56:12 +08:00
parent f77da413f1
commit 7bb18effb2
4 changed files with 62 additions and 23 deletions

View File

@@ -20,6 +20,7 @@ import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.content.Context;
import android.gsi.GsiProgress;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
/**
@@ -52,21 +53,38 @@ public class DynamicSystemManager {
/** The DynamicSystemManager.Session represents a started session for the installation. */
public class Session {
private Session() {}
/**
* Write a chunk of the DynamicSystem system image
* Set the file descriptor that points to a ashmem which will be used
* to fetch data during the submitFromAshmem.
*
* @return {@code true} if the call succeeds. {@code false} if there is any native runtime
* error.
* @param ashmem fd that points to a ashmem
* @param size size of the ashmem file
*/
@RequiresPermission(android.Manifest.permission.MANAGE_DYNAMIC_SYSTEM)
public boolean write(byte[] buf) {
public boolean setAshmem(ParcelFileDescriptor ashmem, long size) {
try {
return mService.write(buf);
return mService.setAshmem(ashmem, size);
} catch (RemoteException e) {
throw new RuntimeException(e.toString());
}
}
/**
* Submit bytes to the DSU partition from the ashmem previously set with
* setAshmem.
*
* @param size Number of bytes
* @return true on success, false otherwise.
*/
@RequiresPermission(android.Manifest.permission.MANAGE_DYNAMIC_SYSTEM)
public boolean submitFromAshmem(int size) {
try {
return mService.submitFromAshmem(size);
} catch (RemoteException e) {
throw new RuntimeException(e.toString());
}
}
/**
* Finish write and make device to boot into the it after reboot.
*

View File

@@ -79,10 +79,20 @@ interface IDynamicSystemService
boolean setEnable(boolean enable, boolean oneShot);
/**
* Write a chunk of the DynamicSystem system image
* Set the file descriptor that points to a ashmem which will be used
* to fetch data during the submitFromAshmem.
*
* @return true if the call succeeds
* @param fd fd that points to a ashmem
* @param size size of the ashmem file
*/
boolean write(in byte[] buf);
boolean setAshmem(in ParcelFileDescriptor fd, long size);
/**
* Submit bytes to the DSU partition from the ashmem previously set with
* setAshmem.
*
* @param bytes number of bytes that can be read from stream.
* @return true on success, false otherwise.
*/
boolean submitFromAshmem(long bytes);
}