1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_JAUDIOATTRIBUTES_H 18 #define ANDROID_JAUDIOATTRIBUTES_H 19 20 #include <jni.h> 21 #include <system/audio.h> 22 23 namespace android { 24 25 class JAudioAttributes { 26 public: 27 /* Creates a Java AudioAttributes object. */ createAudioAttributesObj(JNIEnv * env,const audio_attributes_t * pAttributes)28 static jobject createAudioAttributesObj(JNIEnv *env, 29 const audio_attributes_t* pAttributes) { 30 31 jclass jBuilderCls = env->FindClass("android/media/AudioAttributes$Builder"); 32 jmethodID jBuilderCtor = env->GetMethodID(jBuilderCls, "<init>", "()V"); 33 jobject jBuilderObj = env->NewObject(jBuilderCls, jBuilderCtor); 34 35 if (pAttributes != NULL) { 36 // If pAttributes is not null, streamType is ignored. 37 jmethodID jSetUsage = env->GetMethodID( 38 jBuilderCls, "setUsage", "(I)Landroid/media/AudioAttributes$Builder;"); 39 jBuilderObj = env->CallObjectMethod(jBuilderObj, jSetUsage, pAttributes->usage); 40 41 jmethodID jSetContentType = env->GetMethodID(jBuilderCls, "setContentType", 42 "(I)Landroid/media/AudioAttributes$Builder;"); 43 jBuilderObj = env->CallObjectMethod(jBuilderObj, jSetContentType, 44 pAttributes->content_type); 45 46 // TODO: Java AudioAttributes.Builder.setCapturePreset() is systemApi and hidden. 47 // Can we use this method? 48 // jmethodID jSetCapturePreset = env->GetMethodID(jBuilderCls, "setCapturePreset", 49 // "(I)Landroid/media/AudioAttributes$Builder;"); 50 // jBuilderObj = env->CallObjectMethod(jBuilderObj, jSetCapturePreset, 51 // pAttributes->source); 52 53 jmethodID jSetFlags = env->GetMethodID(jBuilderCls, "setFlags", 54 "(I)Landroid/media/AudioAttributes$Builder;"); 55 jBuilderObj = env->CallObjectMethod(jBuilderObj, jSetFlags, pAttributes->flags); 56 57 // TODO: Handle the 'tags' (char[] to HashSet<String>). 58 // How to parse the char[]? Is there any example of it? 59 // Also, the addTags() method is hidden. 60 } 61 62 jmethodID jBuild = env->GetMethodID(jBuilderCls, "build", 63 "()Landroid/media/AudioAttributes;"); 64 return env->CallObjectMethod(jBuilderObj, jBuild); 65 } 66 67 }; 68 69 } // namespace android 70 71 #endif // ANDROID_JAUDIOATTRIBUTES_H 72