Don't use SDK 31 APIs on APEX
For now, the check is don statically using __ANDROID_APEX__ macro. Soon,
it will be changed to a runtime check using __builtin_available.
Bug: 177365934
Test: m
Change-Id: Id0c23d90b69de3cd5ddfd73de6ebcf7154cb2b1d
diff --git a/media/libmediatranscoding/transcoder/VideoTrackTranscoder.cpp b/media/libmediatranscoding/transcoder/VideoTrackTranscoder.cpp
index 0695bdb..21d60ea 100644
--- a/media/libmediatranscoding/transcoder/VideoTrackTranscoder.cpp
+++ b/media/libmediatranscoding/transcoder/VideoTrackTranscoder.cpp
@@ -260,7 +260,12 @@
return AMEDIA_ERROR_INVALID_PARAMETER;
}
+#if !defined(__ANDROID_APEX__)
+ // TODO(jiyong): replace this #ifdef with a __builtin_available check.
AMediaCodec* encoder = AMediaCodec_createEncoderByTypeForClient(destinationMime, mPid, mUid);
+#else
+ AMediaCodec* encoder = AMediaCodec_createEncoderByType(destinationMime);
+#endif
if (encoder == nullptr) {
LOG(ERROR) << "Unable to create encoder for type " << destinationMime;
return AMEDIA_ERROR_UNSUPPORTED;
@@ -290,7 +295,12 @@
return AMEDIA_ERROR_INVALID_PARAMETER;
}
+#if !defined(__ANDROID_APEX__)
+ // TODO(jiyong): replace this #ifdef with a __builtin_available check.
mDecoder = AMediaCodec_createDecoderByTypeForClient(sourceMime, mPid, mUid);
+#else
+ mDecoder = AMediaCodec_createDecoderByType(sourceMime);
+#endif
if (mDecoder == nullptr) {
LOG(ERROR) << "Unable to create decoder for type " << sourceMime;
return AMEDIA_ERROR_UNSUPPORTED;
diff --git a/media/libmediatranscoding/transcoder/include/media/VideoTrackTranscoder.h b/media/libmediatranscoding/transcoder/include/media/VideoTrackTranscoder.h
index d2ffb01..e3f3f4f 100644
--- a/media/libmediatranscoding/transcoder/include/media/VideoTrackTranscoder.h
+++ b/media/libmediatranscoding/transcoder/include/media/VideoTrackTranscoder.h
@@ -97,8 +97,12 @@
BlockingQueue<std::function<void()>> mCodecMessageQueue;
std::shared_ptr<AMediaFormat> mDestinationFormat;
std::shared_ptr<AMediaFormat> mActualOutputFormat;
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-private-field"
+ // These could be unused on older platforms
pid_t mPid;
uid_t mUid;
+#pragma clang diagnostic pop
};
} // namespace android