Separate AIDL packages
This moves the android.media.audio.common, android.media.permission and android.media.soundtrigger_middleware AIDL files to a their own separate aidl_interface module for Java. Previously, because of how the framework JAR is configured, those files were automatically compiled into it and we had to disable Java for this target, creating a discrepancy between C++ and Java, which would require us to similarly diverge any dependent targets if we want cross-language support. As part of this change, we also had to switch from using the FileDescriptor type to ParcelFileDescriptor, as this is the only type supported outside of the framework JAR and is also the recommended practice. Test: Manual verification of basic soundtrigger functionality. Change-Id: Ib65c19dd7c7f5433cfa527fa74bb61ac677f5cf5
This commit is contained in:
parent
189d6050da
commit
da7c21ec51
@ -547,6 +547,7 @@ java_library {
|
||||
exclude_srcs: ["core/java/android/content/pm/AndroidTestBaseUpdater.java"],
|
||||
aidl: {
|
||||
generate_get_transaction_name: true,
|
||||
local_include_dirs: ["media/aidl"],
|
||||
},
|
||||
dxflags: [
|
||||
"--core-library",
|
||||
@ -583,6 +584,7 @@ java_library {
|
||||
// in favor of an API stubs dependency in java_library "framework" below.
|
||||
"mimemap",
|
||||
"mediatranscoding_aidl_interface-java",
|
||||
"soundtrigger_middleware-aidl-java",
|
||||
],
|
||||
// For backwards compatibility.
|
||||
stem: "framework",
|
||||
|
@ -83,6 +83,10 @@ stubs_defaults {
|
||||
merge_annotations_dirs: [
|
||||
"metalava-manual",
|
||||
],
|
||||
// TODO(b/169090544): remove below aidl includes.
|
||||
aidl: {
|
||||
local_include_dirs: ["media/aidl"],
|
||||
},
|
||||
}
|
||||
|
||||
droidstubs {
|
||||
@ -150,6 +154,10 @@ doc_defaults {
|
||||
":current-support-api",
|
||||
":current-androidx-api",
|
||||
],
|
||||
// TODO(b/169090544): remove below aidl includes.
|
||||
aidl: {
|
||||
local_include_dirs: ["media/aidl"],
|
||||
},
|
||||
}
|
||||
|
||||
doc_defaults {
|
||||
|
@ -51,9 +51,12 @@ stubs_defaults {
|
||||
":android_icu4j_public_api_files",
|
||||
"**/package.html",
|
||||
],
|
||||
// TODO(b/147699819): remove below aidl includes.
|
||||
// TODO(b/147699819, b/169090544): remove below aidl includes.
|
||||
aidl: {
|
||||
local_include_dirs: ["telephony/java"],
|
||||
local_include_dirs: [
|
||||
"telephony/java",
|
||||
"media/aidl",
|
||||
],
|
||||
},
|
||||
libs: ["framework-internal-utils"],
|
||||
installable: false,
|
||||
|
@ -32,10 +32,12 @@ import android.media.soundtrigger_middleware.RecognitionMode;
|
||||
import android.media.soundtrigger_middleware.SoundModel;
|
||||
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;
|
||||
@ -109,7 +111,12 @@ class ConversionUtil {
|
||||
aidlModel.type = apiModel.getType();
|
||||
aidlModel.uuid = api2aidlUuid(apiModel.getUuid());
|
||||
aidlModel.vendorUuid = api2aidlUuid(apiModel.getVendorUuid());
|
||||
aidlModel.data = byteArrayToSharedMemory(apiModel.getData(), "SoundTrigger SoundModel");
|
||||
try {
|
||||
aidlModel.data = ParcelFileDescriptor.dup(
|
||||
byteArrayToSharedMemory(apiModel.getData(), "SoundTrigger SoundModel"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
aidlModel.dataSize = apiModel.getData().length;
|
||||
return aidlModel;
|
||||
}
|
||||
|
@ -1,85 +1,52 @@
|
||||
aidl_interface {
|
||||
name: "audio_common-aidl",
|
||||
unstable: true,
|
||||
local_include_dir: "java",
|
||||
local_include_dir: "aidl",
|
||||
srcs: [
|
||||
"java/android/media/audio/common/AudioChannelMask.aidl",
|
||||
"java/android/media/audio/common/AudioConfig.aidl",
|
||||
"java/android/media/audio/common/AudioFormat.aidl",
|
||||
"java/android/media/audio/common/AudioOffloadInfo.aidl",
|
||||
"java/android/media/audio/common/AudioStreamType.aidl",
|
||||
"java/android/media/audio/common/AudioUsage.aidl",
|
||||
"aidl/android/media/audio/common/AudioChannelMask.aidl",
|
||||
"aidl/android/media/audio/common/AudioConfig.aidl",
|
||||
"aidl/android/media/audio/common/AudioFormat.aidl",
|
||||
"aidl/android/media/audio/common/AudioOffloadInfo.aidl",
|
||||
"aidl/android/media/audio/common/AudioStreamType.aidl",
|
||||
"aidl/android/media/audio/common/AudioUsage.aidl",
|
||||
],
|
||||
backend:
|
||||
{
|
||||
cpp: {
|
||||
enabled: true,
|
||||
},
|
||||
java: {
|
||||
// Already generated as part of the entire media java library.
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
aidl_interface {
|
||||
name: "media_permission-aidl",
|
||||
unstable: true,
|
||||
local_include_dir: "java",
|
||||
local_include_dir: "aidl",
|
||||
srcs: [
|
||||
"java/android/media/permission/Identity.aidl",
|
||||
"aidl/android/media/permission/Identity.aidl",
|
||||
],
|
||||
backend:
|
||||
{
|
||||
cpp: {
|
||||
enabled: true,
|
||||
},
|
||||
java: {
|
||||
// Already generated as part of the entire media java library.
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
aidl_interface {
|
||||
name: "soundtrigger_middleware-aidl",
|
||||
unstable: true,
|
||||
local_include_dir: "java",
|
||||
local_include_dir: "aidl",
|
||||
srcs: [
|
||||
"java/android/media/soundtrigger_middleware/ConfidenceLevel.aidl",
|
||||
"java/android/media/soundtrigger_middleware/ISoundTriggerCallback.aidl",
|
||||
"java/android/media/soundtrigger_middleware/ISoundTriggerMiddlewareService.aidl",
|
||||
"java/android/media/soundtrigger_middleware/ISoundTriggerModule.aidl",
|
||||
"java/android/media/soundtrigger_middleware/ModelParameter.aidl",
|
||||
"java/android/media/soundtrigger_middleware/ModelParameterRange.aidl",
|
||||
"java/android/media/soundtrigger_middleware/Phrase.aidl",
|
||||
"java/android/media/soundtrigger_middleware/PhraseRecognitionEvent.aidl",
|
||||
"java/android/media/soundtrigger_middleware/PhraseRecognitionExtra.aidl",
|
||||
"java/android/media/soundtrigger_middleware/PhraseSoundModel.aidl",
|
||||
"java/android/media/soundtrigger_middleware/RecognitionConfig.aidl",
|
||||
"java/android/media/soundtrigger_middleware/RecognitionEvent.aidl",
|
||||
"java/android/media/soundtrigger_middleware/RecognitionMode.aidl",
|
||||
"java/android/media/soundtrigger_middleware/RecognitionStatus.aidl",
|
||||
"java/android/media/soundtrigger_middleware/SoundModel.aidl",
|
||||
"java/android/media/soundtrigger_middleware/SoundModelType.aidl",
|
||||
"java/android/media/soundtrigger_middleware/SoundTriggerModuleDescriptor.aidl",
|
||||
"java/android/media/soundtrigger_middleware/SoundTriggerModuleProperties.aidl",
|
||||
"java/android/media/soundtrigger_middleware/Status.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/AudioCapabilities.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/ConfidenceLevel.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/ISoundTriggerCallback.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/ISoundTriggerMiddlewareService.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/ISoundTriggerModule.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/ModelParameter.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/ModelParameterRange.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/Phrase.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/PhraseRecognitionEvent.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/PhraseRecognitionExtra.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/PhraseSoundModel.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/RecognitionConfig.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/RecognitionEvent.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/RecognitionMode.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/RecognitionStatus.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/SoundModel.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/SoundModelType.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/SoundTriggerModuleDescriptor.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/SoundTriggerModuleProperties.aidl",
|
||||
"aidl/android/media/soundtrigger_middleware/Status.aidl",
|
||||
],
|
||||
backend:
|
||||
{
|
||||
cpp: {
|
||||
enabled: true,
|
||||
},
|
||||
java: {
|
||||
// Already generated as part of the entire media java library.
|
||||
enabled: false,
|
||||
},
|
||||
ndk: {
|
||||
// Not currently needed, and disabled because of b/146172425
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
imports: [
|
||||
"audio_common-aidl",
|
||||
"media_permission-aidl",
|
||||
|
@ -16,6 +16,7 @@
|
||||
package android.media.soundtrigger_middleware;
|
||||
|
||||
import android.media.soundtrigger_middleware.SoundModelType;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
||||
/**
|
||||
* Base sound model descriptor. This struct can be extended for various specific types by way of
|
||||
@ -32,7 +33,7 @@ parcelable SoundModel {
|
||||
* was build for */
|
||||
String vendorUuid;
|
||||
/** Opaque data transparent to Android framework */
|
||||
FileDescriptor data;
|
||||
ParcelFileDescriptor data;
|
||||
/** Size of the above data, in bytes. */
|
||||
int dataSize;
|
||||
}
|
@ -40,7 +40,10 @@ import android.media.soundtrigger_middleware.SoundModel;
|
||||
import android.media.soundtrigger_middleware.SoundModelType;
|
||||
import android.media.soundtrigger_middleware.SoundTriggerModuleProperties;
|
||||
import android.os.HidlMemoryUtil;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
/**
|
||||
@ -196,8 +199,18 @@ class ConversionUtil {
|
||||
hidlModel.header.type = aidl2hidlSoundModelType(aidlModel.type);
|
||||
hidlModel.header.uuid = aidl2hidlUuid(aidlModel.uuid);
|
||||
hidlModel.header.vendorUuid = aidl2hidlUuid(aidlModel.vendorUuid);
|
||||
hidlModel.data = HidlMemoryUtil.fileDescriptorToHidlMemory(aidlModel.data,
|
||||
aidlModel.dataSize);
|
||||
|
||||
// Extract a dup of the underlying FileDescriptor out of aidlModel.data without changing
|
||||
// the original.
|
||||
FileDescriptor fd = new FileDescriptor();
|
||||
try {
|
||||
ParcelFileDescriptor dup = aidlModel.data.dup();
|
||||
fd.setInt$(dup.detachFd());
|
||||
hidlModel.data = HidlMemoryUtil.fileDescriptorToHidlMemory(fd, aidlModel.dataSize);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return hidlModel;
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,7 @@ import android.os.HidlMemoryUtil;
|
||||
import android.os.HwParcel;
|
||||
import android.os.IHwBinder;
|
||||
import android.os.IHwInterface;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.RemoteException;
|
||||
import android.os.SharedMemory;
|
||||
import android.system.ErrnoException;
|
||||
@ -126,7 +127,7 @@ public class SoundTriggerMiddlewareImplTest {
|
||||
model.uuid = "12345678-2345-3456-4567-abcdef987654";
|
||||
model.vendorUuid = "87654321-5432-6543-7654-456789fedcba";
|
||||
byte[] data = new byte[]{91, 92, 93, 94, 95};
|
||||
model.data = byteArrayToFileDescriptor(data);
|
||||
model.data = new ParcelFileDescriptor(byteArrayToFileDescriptor(data));
|
||||
model.dataSize = data.length;
|
||||
return model;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user