Merge "Support sound models with no data" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
6f1e0dddd6
@@ -34,10 +34,7 @@ import android.media.soundtrigger_middleware.SoundTriggerModuleDescriptor;
|
||||
import android.media.soundtrigger_middleware.SoundTriggerModuleProperties;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.SharedMemory;
|
||||
import android.system.ErrnoException;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
@@ -111,13 +108,9 @@ class ConversionUtil {
|
||||
aidlModel.type = apiModel.getType();
|
||||
aidlModel.uuid = api2aidlUuid(apiModel.getUuid());
|
||||
aidlModel.vendorUuid = api2aidlUuid(apiModel.getVendorUuid());
|
||||
try {
|
||||
aidlModel.data = ParcelFileDescriptor.dup(
|
||||
byteArrayToSharedMemory(apiModel.getData(), "SoundTrigger SoundModel"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
aidlModel.dataSize = apiModel.getData().length;
|
||||
byte[] data = apiModel.getData();
|
||||
aidlModel.data = byteArrayToSharedMemory(data, "SoundTrigger SoundModel");
|
||||
aidlModel.dataSize = data.length;
|
||||
return aidlModel;
|
||||
}
|
||||
|
||||
@@ -379,7 +372,7 @@ class ConversionUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static @Nullable FileDescriptor byteArrayToSharedMemory(byte[] data, String name) {
|
||||
private static @Nullable ParcelFileDescriptor byteArrayToSharedMemory(byte[] data, String name) {
|
||||
if (data.length == 0) {
|
||||
return null;
|
||||
}
|
||||
@@ -389,8 +382,10 @@ class ConversionUtil {
|
||||
ByteBuffer buffer = shmem.mapReadWrite();
|
||||
buffer.put(data);
|
||||
shmem.unmap(buffer);
|
||||
return shmem.getFileDescriptor();
|
||||
} catch (ErrnoException e) {
|
||||
ParcelFileDescriptor fd = shmem.getFdDup();
|
||||
shmem.close();
|
||||
return fd;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user