summaryrefslogtreecommitdiff
path: root/core/jni
diff options
context:
space:
mode:
authorBrian Orr <brianorr@google.com>2021-06-15 12:47:53 -0700
committerDaniel Norman <danielnorman@google.com>2021-06-17 13:37:54 -0700
commit71c831703ae59baf47e0afe611fecd714c481cdf (patch)
tree06731a987032723085b9e1a65951cf96abbc19cf /core/jni
parent065c9e9a6e9d61d4383a91721eb56a3de253bdbe (diff)
parent81833820d54b9a6b27894f9f8dfd72222d416992 (diff)
Merge SP1A.210604.001
Change-Id: I5200ee05285ae422d5e9c1c00f45709a5d6188be
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/Android.bp4
-rw-r--r--core/jni/AndroidRuntime.cpp4
-rw-r--r--core/jni/android_content_res_ApkAssets.cpp37
-rw-r--r--core/jni/android_hardware_camera2_DngCreator.cpp140
-rw-r--r--core/jni/android_media_AudioRecord.cpp20
-rw-r--r--core/jni/android_media_AudioTrack.cpp12
-rw-r--r--core/jni/android_os_Parcel.cpp10
-rw-r--r--core/jni/android_util_Binder.cpp21
-rw-r--r--core/jni/android_util_StringBlock.cpp8
-rw-r--r--core/jni/android_view_InputEventReceiver.cpp24
-rw-r--r--core/jni/android_view_TunnelModeEnabledListener.cpp130
-rw-r--r--core/jni/com_android_internal_os_ZygoteCommandBuffer.cpp4
-rw-r--r--core/jni/permission_utils.cpp71
-rw-r--r--core/jni/permission_utils.h27
14 files changed, 319 insertions, 193 deletions
diff --git a/core/jni/Android.bp b/core/jni/Android.bp
index 662948e9fbc9..2359e96c1ab6 100644
--- a/core/jni/Android.bp
+++ b/core/jni/Android.bp
@@ -130,6 +130,7 @@ cc_library_shared {
"android_graphics_BLASTBufferQueue.cpp",
"android_view_SurfaceSession.cpp",
"android_view_TextureView.cpp",
+ "android_view_TunnelModeEnabledListener.cpp",
"android_view_VelocityTracker.cpp",
"android_view_VerifiedKeyEvent.cpp",
"android_view_VerifiedMotionEvent.cpp",
@@ -223,7 +224,6 @@ cc_library_shared {
"fd_utils.cpp",
"android_hardware_input_InputWindowHandle.cpp",
"android_hardware_input_InputApplicationHandle.cpp",
- "permission_utils.cpp",
],
static_libs: [
@@ -242,7 +242,6 @@ cc_library_shared {
"audioflinger-aidl-cpp",
"av-types-aidl-cpp",
"android.hardware.camera.device@3.2",
- "media_permission-aidl-cpp",
"libandroidicu",
"libbpf_android",
"libnetdbpf",
@@ -259,6 +258,7 @@ cc_library_shared {
"libgraphicsenv",
"libgui",
"libmediandk",
+ "libpermission",
"libsensor",
"libinput",
"libcamera_client",
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index 1983207c8496..7da1d3e6ece7 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -98,7 +98,6 @@ extern int register_android_media_AudioVolumeGroupChangeHandler(JNIEnv *env);
extern int register_android_media_MicrophoneInfo(JNIEnv *env);
extern int register_android_media_ToneGenerator(JNIEnv *env);
extern int register_android_media_midi(JNIEnv *env);
-extern int register_android_media_permission_Identity(JNIEnv* env);
namespace android {
extern int register_android_util_SeempLog(JNIEnv* env);
@@ -128,6 +127,7 @@ extern int register_android_view_SurfaceControlHdrLayerInfoListener(JNIEnv* env)
extern int register_android_view_SurfaceSession(JNIEnv* env);
extern int register_android_view_CompositionSamplingListener(JNIEnv* env);
extern int register_android_view_TextureView(JNIEnv* env);
+extern int register_android_view_TunnelModeEnabledListener(JNIEnv* env);
extern int register_android_database_CursorWindow(JNIEnv* env);
extern int register_android_database_SQLiteConnection(JNIEnv* env);
extern int register_android_database_SQLiteGlobal(JNIEnv* env);
@@ -1524,6 +1524,7 @@ static const RegJNIRec gRegJNI[] = {
REG_JNI(register_android_view_SurfaceSession),
REG_JNI(register_android_view_CompositionSamplingListener),
REG_JNI(register_android_view_TextureView),
+ REG_JNI(register_android_view_TunnelModeEnabledListener),
REG_JNI(register_com_google_android_gles_jni_EGLImpl),
REG_JNI(register_com_google_android_gles_jni_GLImpl),
REG_JNI(register_android_opengl_jni_EGL14),
@@ -1592,7 +1593,6 @@ static const RegJNIRec gRegJNI[] = {
REG_JNI(register_android_media_RemoteDisplay),
REG_JNI(register_android_media_ToneGenerator),
REG_JNI(register_android_media_midi),
- REG_JNI(register_android_media_permission_Identity),
REG_JNI(register_android_opengl_classes),
REG_JNI(register_android_server_NetworkManagementSocketTagger),
diff --git a/core/jni/android_content_res_ApkAssets.cpp b/core/jni/android_content_res_ApkAssets.cpp
index 9c8daec7919a..1be84282f6db 100644
--- a/core/jni/android_content_res_ApkAssets.cpp
+++ b/core/jni/android_content_res_ApkAssets.cpp
@@ -212,10 +212,11 @@ static jlong NativeLoad(JNIEnv* env, jclass /*clazz*/, const format_type_t forma
std::unique_ptr<ApkAssets> apk_assets;
switch (format) {
case FORMAT_APK: {
- auto assets = MultiAssetsProvider::Create(std::move(loader_assets),
- ZipAssetsProvider::Create(path.c_str()));
- apk_assets = ApkAssets::Load(std::move(assets), property_flags);
- break;
+ auto assets = MultiAssetsProvider::Create(std::move(loader_assets),
+ ZipAssetsProvider::Create(path.c_str(),
+ property_flags));
+ apk_assets = ApkAssets::Load(std::move(assets), property_flags);
+ break;
}
case FORMAT_IDMAP:
apk_assets = ApkAssets::LoadOverlay(path.c_str(), property_flags);
@@ -271,11 +272,13 @@ static jlong NativeLoadFromFd(JNIEnv* env, jclass /*clazz*/, const format_type_t
std::unique_ptr<const ApkAssets> apk_assets;
switch (format) {
case FORMAT_APK: {
- auto assets = MultiAssetsProvider::Create(
- std::move(loader_assets),
- ZipAssetsProvider::Create(std::move(dup_fd), friendly_name_utf8.c_str()));
- apk_assets = ApkAssets::Load(std::move(assets), property_flags);
- break;
+ auto assets =
+ MultiAssetsProvider::Create(std::move(loader_assets),
+ ZipAssetsProvider::Create(std::move(dup_fd),
+ friendly_name_utf8.c_str(),
+ property_flags));
+ apk_assets = ApkAssets::Load(std::move(assets), property_flags);
+ break;
}
case FORMAT_ARSC:
apk_assets = ApkAssets::LoadTable(
@@ -336,12 +339,16 @@ static jlong NativeLoadFromFdOffset(JNIEnv* env, jclass /*clazz*/, const format_
std::unique_ptr<const ApkAssets> apk_assets;
switch (format) {
case FORMAT_APK: {
- auto assets = MultiAssetsProvider::Create(
- std::move(loader_assets),
- ZipAssetsProvider::Create(std::move(dup_fd), friendly_name_utf8.c_str(),
- static_cast<off64_t>(offset), static_cast<off64_t>(length)));
- apk_assets = ApkAssets::Load(std::move(assets), property_flags);
- break;
+ auto assets =
+ MultiAssetsProvider::Create(std::move(loader_assets),
+ ZipAssetsProvider::Create(std::move(dup_fd),
+ friendly_name_utf8.c_str(),
+ property_flags,
+ static_cast<off64_t>(offset),
+ static_cast<off64_t>(
+ length)));
+ apk_assets = ApkAssets::Load(std::move(assets), property_flags);
+ break;
}
case FORMAT_ARSC:
apk_assets = ApkAssets::LoadTable(
diff --git a/core/jni/android_hardware_camera2_DngCreator.cpp b/core/jni/android_hardware_camera2_DngCreator.cpp
index 4fad239b5743..b4b727bcdcf2 100644
--- a/core/jni/android_hardware_camera2_DngCreator.cpp
+++ b/core/jni/android_hardware_camera2_DngCreator.cpp
@@ -83,6 +83,22 @@ using android::base::GetProperty;
return nullptr; \
}
+#define BAIL_IF_EMPTY_RET_BOOL(entry, jnienv, tagId, writer) \
+ if ((entry).count == 0) { \
+ jniThrowExceptionFmt(jnienv, "java/lang/IllegalArgumentException", \
+ "Missing metadata fields for tag %s (%x)", \
+ (writer)->getTagName(tagId), (tagId)); \
+ return false; \
+ }
+
+#define BAIL_IF_EMPTY_RET_STATUS(entry, jnienv, tagId, writer) \
+ if ((entry).count == 0) { \
+ jniThrowExceptionFmt(jnienv, "java/lang/IllegalArgumentException", \
+ "Missing metadata fields for tag %s (%x)", \
+ (writer)->getTagName(tagId), (tagId)); \
+ return BAD_VALUE; \
+ }
+
#define BAIL_IF_EXPR_RET_NULL_SP(expr, jnienv, tagId, writer) \
if (expr) { \
jniThrowExceptionFmt(jnienv, "java/lang/IllegalArgumentException", \
@@ -764,15 +780,76 @@ uint32_t DirectStripSource::getIfd() const {
// End of DirectStripSource
// ----------------------------------------------------------------------------
+// Get the appropriate tag corresponding to default / maximum resolution mode.
+static int32_t getAppropriateModeTag(int32_t tag, bool maximumResolution) {
+ if (!maximumResolution) {
+ return tag;
+ }
+ switch (tag) {
+ case ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE:
+ return ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE_MAXIMUM_RESOLUTION;
+ case ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE:
+ return ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION;
+ case ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE:
+ return ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION;
+ default:
+ ALOGE("%s: Tag %d doesn't have sensor info related maximum resolution counterpart",
+ __FUNCTION__, tag);
+ return -1;
+ }
+}
+
+static bool isMaximumResolutionModeImage(const CameraMetadata& characteristics, uint32_t imageWidth,
+ uint32_t imageHeight, const sp<TiffWriter> writer,
+ JNIEnv* env) {
+ // If this isn't an ultra-high resolution sensor, return false;
+ camera_metadata_ro_entry capabilitiesEntry =
+ characteristics.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
+ size_t capsCount = capabilitiesEntry.count;
+ const uint8_t* caps = capabilitiesEntry.data.u8;
+ if (std::find(caps, caps + capsCount,
+ ANDROID_REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR) ==
+ caps + capsCount) {
+ // not an ultra-high resolution sensor, cannot have a maximum resolution
+ // mode image.
+ return false;
+ }
+
+ // If the image width and height are either the maximum resolution
+ // pre-correction active array size or the maximum resolution pixel array
+ // size, this image is a maximum resolution RAW_SENSOR image.
+
+ // Check dimensions
+ camera_metadata_ro_entry entry = characteristics.find(
+ ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION);
+
+ BAIL_IF_EMPTY_RET_BOOL(entry, env, TAG_IMAGEWIDTH, writer);
+
+ uint32_t preWidth = static_cast<uint32_t>(entry.data.i32[2]);
+ uint32_t preHeight = static_cast<uint32_t>(entry.data.i32[3]);
+
+ camera_metadata_ro_entry pixelArrayEntry =
+ characteristics.find(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE_MAXIMUM_RESOLUTION);
+
+ BAIL_IF_EMPTY_RET_BOOL(pixelArrayEntry, env, TAG_IMAGEWIDTH, writer);
+
+ uint32_t pixWidth = static_cast<uint32_t>(pixelArrayEntry.data.i32[0]);
+ uint32_t pixHeight = static_cast<uint32_t>(pixelArrayEntry.data.i32[1]);
+
+ return (imageWidth == preWidth && imageHeight == preHeight) ||
+ (imageWidth == pixWidth && imageHeight == pixHeight);
+}
+
/**
* Calculate the default crop relative to the "active area" of the image sensor (this active area
* will always be the pre-correction active area rectangle), and set this.
*/
static status_t calculateAndSetCrop(JNIEnv* env, const CameraMetadata& characteristics,
- sp<TiffWriter> writer) {
-
- camera_metadata_ro_entry entry =
- characteristics.find(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
+ sp<TiffWriter> writer, bool maximumResolutionMode) {
+ camera_metadata_ro_entry entry = characteristics.find(
+ getAppropriateModeTag(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE,
+ maximumResolutionMode));
+ BAIL_IF_EMPTY_RET_STATUS(entry, env, TAG_IMAGEWIDTH, writer);
uint32_t width = static_cast<uint32_t>(entry.data.i32[2]);
uint32_t height = static_cast<uint32_t>(entry.data.i32[3]);
@@ -811,11 +888,18 @@ static bool validateDngHeader(JNIEnv* env, sp<TiffWriter> writer,
"Image height %d is invalid", height);
return false;
}
+ bool isMaximumResolutionMode =
+ isMaximumResolutionModeImage(characteristics, static_cast<uint32_t>(width),
+ static_cast<uint32_t>(height), writer, env);
- camera_metadata_ro_entry preCorrectionEntry =
- characteristics.find(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
- camera_metadata_ro_entry pixelArrayEntry =
- characteristics.find(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE);
+ camera_metadata_ro_entry preCorrectionEntry = characteristics.find(
+ getAppropriateModeTag(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE,
+ isMaximumResolutionMode));
+ BAIL_IF_EMPTY_RET_BOOL(preCorrectionEntry, env, TAG_IMAGEWIDTH, writer);
+
+ camera_metadata_ro_entry pixelArrayEntry = characteristics.find(
+ getAppropriateModeTag(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, isMaximumResolutionMode));
+ BAIL_IF_EMPTY_RET_BOOL(pixelArrayEntry, env, TAG_IMAGEWIDTH, writer);
int pWidth = static_cast<int>(pixelArrayEntry.data.i32[0]);
int pHeight = static_cast<int>(pixelArrayEntry.data.i32[1]);
@@ -1236,10 +1320,13 @@ static sp<TiffWriter> DngCreator_setup(JNIEnv* env, jobject thiz, uint32_t image
uint32_t preHeight = 0;
uint8_t colorFilter = 0;
bool isBayer = true;
+ bool isMaximumResolutionMode =
+ isMaximumResolutionModeImage(characteristics, imageWidth, imageHeight, writer, env);
{
// Check dimensions
- camera_metadata_entry entry =
- characteristics.find(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
+ camera_metadata_entry entry = characteristics.find(
+ getAppropriateModeTag(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE,
+ isMaximumResolutionMode));
BAIL_IF_EMPTY_RET_NULL_SP(entry, env, TAG_IMAGEWIDTH, writer);
preXMin = static_cast<uint32_t>(entry.data.i32[0]);
preYMin = static_cast<uint32_t>(entry.data.i32[1]);
@@ -1247,15 +1334,18 @@ static sp<TiffWriter> DngCreator_setup(JNIEnv* env, jobject thiz, uint32_t image
preHeight = static_cast<uint32_t>(entry.data.i32[3]);
camera_metadata_entry pixelArrayEntry =
- characteristics.find(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE);
+ characteristics.find(getAppropriateModeTag(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE,
+ isMaximumResolutionMode));
+
+ BAIL_IF_EMPTY_RET_NULL_SP(pixelArrayEntry, env, TAG_IMAGEWIDTH, writer);
uint32_t pixWidth = static_cast<uint32_t>(pixelArrayEntry.data.i32[0]);
uint32_t pixHeight = static_cast<uint32_t>(pixelArrayEntry.data.i32[1]);
if (!((imageWidth == preWidth && imageHeight == preHeight) ||
(imageWidth == pixWidth && imageHeight == pixHeight))) {
jniThrowException(env, "java/lang/AssertionError",
- "Height and width of image buffer did not match height and width of"
- "either the preCorrectionActiveArraySize or the pixelArraySize.");
+ "Height and width of image buffer did not match height and width of"
+ " either the preCorrectionActiveArraySize or the pixelArraySize.");
return nullptr;
}
@@ -1773,11 +1863,12 @@ static sp<TiffWriter> DngCreator_setup(JNIEnv* env, jobject thiz, uint32_t image
{
// Set dimensions
- if (calculateAndSetCrop(env, characteristics, writer) != OK) {
+ if (calculateAndSetCrop(env, characteristics, writer, isMaximumResolutionMode) != OK) {
return nullptr;
}
- camera_metadata_entry entry =
- characteristics.find(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
+ camera_metadata_entry entry = characteristics.find(
+ getAppropriateModeTag(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE,
+ isMaximumResolutionMode));
BAIL_IF_EMPTY_RET_NULL_SP(entry, env, TAG_ACTIVEAREA, writer);
uint32_t xmin = static_cast<uint32_t>(entry.data.i32[0]);
uint32_t ymin = static_cast<uint32_t>(entry.data.i32[1]);
@@ -1872,8 +1963,9 @@ static sp<TiffWriter> DngCreator_setup(JNIEnv* env, jobject thiz, uint32_t image
camera_metadata_entry entry2 = results.find(ANDROID_STATISTICS_LENS_SHADING_MAP);
- camera_metadata_entry entry =
- characteristics.find(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
+ camera_metadata_entry entry = characteristics.find(
+ getAppropriateModeTag(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE,
+ isMaximumResolutionMode));
BAIL_IF_EMPTY_RET_NULL_SP(entry, env, TAG_IMAGEWIDTH, writer);
uint32_t xmin = static_cast<uint32_t>(entry.data.i32[0]);
uint32_t ymin = static_cast<uint32_t>(entry.data.i32[1]);
@@ -1899,7 +1991,12 @@ static sp<TiffWriter> DngCreator_setup(JNIEnv* env, jobject thiz, uint32_t image
// Hot pixel map is specific to bayer camera per DNG spec.
if (isBayer) {
// Set up bad pixel correction list
- camera_metadata_entry entry3 = characteristics.find(ANDROID_STATISTICS_HOT_PIXEL_MAP);
+ // We first check the capture result. If the hot pixel map is not
+ // available, as a fallback, try the static characteristics.
+ camera_metadata_entry entry3 = results.find(ANDROID_STATISTICS_HOT_PIXEL_MAP);
+ if (entry3.count == 0) {
+ entry3 = characteristics.find(ANDROID_STATISTICS_HOT_PIXEL_MAP);
+ }
if ((entry3.count % 2) != 0) {
ALOGE("%s: Hot pixel map contains odd number of values, cannot map to pairs!",
@@ -1908,7 +2005,8 @@ static sp<TiffWriter> DngCreator_setup(JNIEnv* env, jobject thiz, uint32_t image
return nullptr;
}
- // Adjust the bad pixel coordinates to be relative to the origin of the active area DNG tag
+ // Adjust the bad pixel coordinates to be relative to the origin of the active area
+ // DNG tag
std::vector<uint32_t> v;
for (size_t i = 0; i < entry3.count; i += 2) {
int32_t x = entry3.data.i32[i];
@@ -1962,6 +2060,8 @@ static sp<TiffWriter> DngCreator_setup(JNIEnv* env, jobject thiz, uint32_t image
std::array<float, 6> distortion = {1.f, 0.f, 0.f, 0.f, 0.f, 0.f};
bool gotDistortion = false;
+ // The capture result would have the correct intrinsic calibration
+ // regardless of the sensor pixel mode.
camera_metadata_entry entry4 =
results.find(ANDROID_LENS_INTRINSIC_CALIBRATION);
diff --git a/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cpp
index 83dc1e0bb0d9..bce4ed78eda1 100644
--- a/core/jni/android_media_AudioRecord.cpp
+++ b/core/jni/android_media_AudioRecord.cpp
@@ -22,13 +22,15 @@
#include <jni.h>
#include <nativehelper/JNIHelp.h>
#include "core_jni_helpers.h"
-#include "permission_utils.h"
#include <utils/Log.h>
#include <media/AudioRecord.h>
#include <media/MicrophoneInfo.h>
#include <vector>
+#include <android/content/AttributionSourceState.h>
+#include <android_os_Parcel.h>
+
#include <nativehelper/ScopedUtfChars.h>
#include "android_media_AudioFormat.h"
@@ -38,10 +40,8 @@
#include "android_media_MicrophoneInfo.h"
#include "android_media_AudioAttributes.h"
-// ----------------------------------------------------------------------------
-using android::media::permission::convertIdentity;
-using android::media::permission::Identity;
+// ----------------------------------------------------------------------------
using namespace android;
@@ -189,7 +189,7 @@ static jint android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject w
jobject jaa, jintArray jSampleRate, jint channelMask,
jint channelIndexMask, jint audioFormat,
jint buffSizeInBytes, jintArray jSession,
- jobject jIdentity, jlong nativeRecordInJavaObj,
+ jobject jAttributionSource, jlong nativeRecordInJavaObj,
jint sharedAudioHistoryMs) {
//ALOGV(">> Entering android_media_AudioRecord_setup");
//ALOGV("sampleRate=%d, audioFormat=%d, channel mask=%x, buffSizeInBytes=%d "
@@ -260,14 +260,18 @@ static jint android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject w
size_t bytesPerSample = audio_bytes_per_sample(format);
if (buffSizeInBytes == 0) {
- ALOGE("Error creating AudioRecord: frameCount is 0.");
+ ALOGE("Error creating AudioRecord: frameCount is 0.");
return (jint) AUDIORECORD_ERROR_SETUP_ZEROFRAMECOUNT;
}
size_t frameSize = channelCount * bytesPerSample;
size_t frameCount = buffSizeInBytes / frameSize;
// create an uninitialized AudioRecord object
- lpRecorder = new AudioRecord(convertIdentity(env, jIdentity));
+ Parcel* parcel = parcelForJavaObject(env, jAttributionSource);
+ android::content::AttributionSourceState attributionSource;
+ attributionSource.readFromParcel(parcel);
+
+ lpRecorder = new AudioRecord(attributionSource);
// read the AudioAttributes values
auto paa = JNIAudioAttributeHelper::makeUnique();
@@ -912,7 +916,7 @@ static const JNINativeMethod gMethods[] = {
{"native_start", "(II)I", (void *)android_media_AudioRecord_start},
{"native_stop", "()V", (void *)android_media_AudioRecord_stop},
{"native_setup",
- "(Ljava/lang/Object;Ljava/lang/Object;[IIIII[ILandroid/media/permission/Identity;JI)I",
+ "(Ljava/lang/Object;Ljava/lang/Object;[IIIII[ILandroid/os/Parcel;JI)I",
(void *)android_media_AudioRecord_setup},
{"native_finalize", "()V", (void *)android_media_AudioRecord_finalize},
{"native_release", "()V", (void *)android_media_AudioRecord_release},
diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp
index de5df202ba4e..73d2d8d949cd 100644
--- a/core/jni/android_media_AudioTrack.cpp
+++ b/core/jni/android_media_AudioTrack.cpp
@@ -48,7 +48,6 @@
using namespace android;
using ::android::media::VolumeShaper;
-using ::android::media::permission::Identity;
// ----------------------------------------------------------------------------
static const char* const kClassPathName = "android/media/AudioTrack";
@@ -330,9 +329,10 @@ static jint android_media_AudioTrack_setup(JNIEnv *env, jobject thiz, jobject we
// create the native AudioTrack object
ScopedUtfChars opPackageNameStr(env, opPackageName);
// TODO b/182469354: make consistent with AudioRecord
- Identity identity = Identity();
- identity.packageName = std::string(opPackageNameStr.c_str());
- lpTrack = new AudioTrack(identity);
+ AttributionSourceState attributionSource;
+ attributionSource.packageName = std::string(opPackageNameStr.c_str());
+ attributionSource.token = sp<BBinder>::make();
+ lpTrack = new AudioTrack(attributionSource);
// read the AudioAttributes values
auto paa = JNIAudioAttributeHelper::makeUnique();
@@ -395,7 +395,7 @@ static jint android_media_AudioTrack_setup(JNIEnv *env, jobject thiz, jobject we
offload ? AudioTrack::TRANSFER_SYNC_NOTIF_CALLBACK
: AudioTrack::TRANSFER_SYNC,
(offload || encapsulationMode) ? &offloadInfo : NULL,
- Identity(), // default uid, pid values
+ AttributionSourceState(), // default uid, pid values
paa.get());
break;
@@ -421,7 +421,7 @@ static jint android_media_AudioTrack_setup(JNIEnv *env, jobject thiz, jobject we
sessionId, // audio session ID
AudioTrack::TRANSFER_SHARED,
NULL, // default offloadInfo
- Identity(), // default uid, pid values
+ AttributionSourceState(), // default uid, pid values
paa.get());
break;
diff --git a/core/jni/android_os_Parcel.cpp b/core/jni/android_os_Parcel.cpp
index 3acbd1ecd16e..787d34822ef7 100644
--- a/core/jni/android_os_Parcel.cpp
+++ b/core/jni/android_os_Parcel.cpp
@@ -36,7 +36,6 @@
#include <utils/List.h>
#include <utils/KeyedVector.h>
#include <binder/Parcel.h>
-#include <binder/ParcelRef.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
#include <utils/threads.h>
@@ -516,9 +515,8 @@ static jobject android_os_Parcel_readFileDescriptor(JNIEnv* env, jclass clazz, j
static jlong android_os_Parcel_create(JNIEnv* env, jclass clazz)
{
- sp<ParcelRef> parcelRef = ParcelRef::create();
- parcelRef->incStrong(reinterpret_cast<const void*>(android_os_Parcel_create));
- return reinterpret_cast<jlong>(static_cast<Parcel *>(parcelRef.get()));
+ Parcel* parcel = new Parcel();
+ return reinterpret_cast<jlong>(parcel);
}
static void android_os_Parcel_freeBuffer(JNIEnv* env, jclass clazz, jlong nativePtr)
@@ -531,8 +529,8 @@ static void android_os_Parcel_freeBuffer(JNIEnv* env, jclass clazz, jlong native
static void android_os_Parcel_destroy(JNIEnv* env, jclass clazz, jlong nativePtr)
{
- ParcelRef* derivative = static_cast<ParcelRef*>(reinterpret_cast<Parcel*>(nativePtr));
- derivative->decStrong(reinterpret_cast<const void*>(android_os_Parcel_create));
+ Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
+ delete parcel;
}
static jbyteArray android_os_Parcel_marshall(JNIEnv* env, jclass clazz, jlong nativePtr)
diff --git a/core/jni/android_util_Binder.cpp b/core/jni/android_util_Binder.cpp
index 29f8ccf37654..793b4eba788c 100644
--- a/core/jni/android_util_Binder.cpp
+++ b/core/jni/android_util_Binder.cpp
@@ -35,7 +35,6 @@
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/Parcel.h>
-#include <binder/ParcelRef.h>
#include <binder/ProcessState.h>
#include <binder/Stability.h>
#include <binderthreadstate/CallerUtils.h>
@@ -1381,8 +1380,7 @@ static bool should_time_binder_calls() {
}
static jboolean android_os_BinderProxy_transact(JNIEnv* env, jobject obj,
- jint code, jobject dataObj, jobject replyObj, jboolean replyObjOwnsNativeParcel,
- jint flags) // throws RemoteException
+ jint code, jobject dataObj, jobject replyObj, jint flags) // throws RemoteException
{
if (dataObj == NULL) {
jniThrowNullPointerException(env, NULL);
@@ -1424,21 +1422,6 @@ static jboolean android_os_BinderProxy_transact(JNIEnv* env, jobject obj,
status_t err = target->transact(code, *data, reply, flags);
//if (reply) printf("Transact from Java code to %p received: ", target); reply->print();
- if (reply) {
- if (replyObjOwnsNativeParcel) {
- // as per Parcel java class constructor, here, "reply" MUST be a "ParcelRef"
- // only for Parcel that contained Binder objects
- if (reply->objectsCount() > 0) {
- IPCThreadState::self()->createTransactionReference(static_cast<ParcelRef*>(reply));
- }
- } else {
- // as per Parcel.java, if Parcel java object NOT owning native Parcel object, it will
- // NOT destroy the native Parcel object upon GC(finalize()), so, there will be no race
- // condtion in this case. Please refer to the java class methods: Parcel.finalize(),
- // Parcel.destroy().
- }
- }
-
if (kEnableBinderSample) {
if (time_binder_calls) {
conditionally_log_binder_call(start_millis, target, code);
@@ -1567,7 +1550,7 @@ static const JNINativeMethod gBinderProxyMethods[] = {
{"pingBinder", "()Z", (void*)android_os_BinderProxy_pingBinder},
{"isBinderAlive", "()Z", (void*)android_os_BinderProxy_isBinderAlive},
{"getInterfaceDescriptor", "()Ljava/lang/String;", (void*)android_os_BinderProxy_getInterfaceDescriptor},
- {"transactNative", "(ILandroid/os/Parcel;Landroid/os/Parcel;ZI)Z", (void*)android_os_BinderProxy_transact},
+ {"transactNative", "(ILandroid/os/Parcel;Landroid/os/Parcel;I)Z", (void*)android_os_BinderProxy_transact},
{"linkToDeath", "(Landroid/os/IBinder$DeathRecipient;I)V", (void*)android_os_BinderProxy_linkToDeath},
{"unlinkToDeath", "(Landroid/os/IBinder$DeathRecipient;I)Z", (void*)android_os_BinderProxy_unlinkToDeath},
{"getNativeFinalizer", "()J", (void*)android_os_BinderProxy_getNativeFinalizer},
diff --git a/core/jni/android_util_StringBlock.cpp b/core/jni/android_util_StringBlock.cpp
index d94e0841003f..dd7df26ee881 100644
--- a/core/jni/android_util_StringBlock.cpp
+++ b/core/jni/android_util_StringBlock.cpp
@@ -72,7 +72,7 @@ static jstring android_content_StringBlock_nativeGetString(JNIEnv* env, jobject
ResStringPool* osb = reinterpret_cast<ResStringPool*>(token);
if (osb == NULL) {
jniThrowNullPointerException(env, NULL);
- return 0;
+ return NULL;
}
if (auto str8 = osb->string8At(idx); str8.has_value()) {
@@ -80,9 +80,11 @@ static jstring android_content_StringBlock_nativeGetString(JNIEnv* env, jobject
}
auto str = osb->stringAt(idx);
- if (UNLIKELY(!str.has_value())) {
+ if (IsIOError(str)) {
+ return NULL;
+ } else if (UNLIKELY(!str.has_value())) {
jniThrowException(env, "java/lang/IndexOutOfBoundsException", NULL);
- return 0;
+ return NULL;
}
return env->NewString((const jchar*)str->data(), str->size());
diff --git a/core/jni/android_view_InputEventReceiver.cpp b/core/jni/android_view_InputEventReceiver.cpp
index a80f9c0f9a7e..ce419b104c57 100644
--- a/core/jni/android_view_InputEventReceiver.cpp
+++ b/core/jni/android_view_InputEventReceiver.cpp
@@ -244,13 +244,13 @@ status_t NativeInputEventReceiver::processOutboundEvents() {
}
// Some other error. Give up
- ALOGW("Failed to send outbound event on channel '%s'. status=%d",
- getInputChannelName().c_str(), status);
+ ALOGW("Failed to send outbound event on channel '%s'. status=%s(%d)",
+ getInputChannelName().c_str(), statusToString(status).c_str(), status);
if (status != DEAD_OBJECT) {
JNIEnv* env = AndroidRuntime::getJNIEnv();
std::string message =
- android::base::StringPrintf("Failed to send outbound event. status=%d",
- status);
+ android::base::StringPrintf("Failed to send outbound event. status=%s(%d)",
+ statusToString(status).c_str(), status);
jniThrowRuntimeException(env, message.c_str());
mMessageQueue->raiseAndClearException(env, "finishInputEvent");
}
@@ -346,8 +346,8 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env,
}
if (status != OK && status != WOULD_BLOCK) {
- ALOGE("channel '%s' ~ Failed to consume input event. status=%d",
- getInputChannelName().c_str(), status);
+ ALOGE("channel '%s' ~ Failed to consume input event. status=%s(%d)",
+ getInputChannelName().c_str(), statusToString(status).c_str(), status);
return status;
}
@@ -529,9 +529,9 @@ static jlong nativeInit(JNIEnv* env, jclass clazz, jobject receiverWeak,
receiverWeak, inputChannel, messageQueue);
status_t status = receiver->initialize();
if (status) {
- std::string message =
- android::base::StringPrintf("Failed to initialize input event receiver. status=%d",
- status);
+ std::string message = android::base::
+ StringPrintf("Failed to initialize input event receiver. status=%s(%d)",
+ statusToString(status).c_str(), status);
jniThrowRuntimeException(env, message.c_str());
return 0;
}
@@ -558,7 +558,7 @@ static void nativeFinishInputEvent(JNIEnv* env, jclass clazz, jlong receiverPtr,
if (status != DEAD_OBJECT) {
std::string message =
android::base::StringPrintf("Failed to finish input event. status=%s(%d)",
- strerror(-status), status);
+ statusToString(status).c_str(), status);
jniThrowRuntimeException(env, message.c_str());
}
}
@@ -591,8 +591,8 @@ static jboolean nativeConsumeBatchedInputEvents(JNIEnv* env, jclass clazz, jlong
&consumedBatch);
if (status && status != DEAD_OBJECT && !env->ExceptionCheck()) {
std::string message =
- android::base::StringPrintf("Failed to consume batched input event. status=%d",
- status);
+ android::base::StringPrintf("Failed to consume batched input event. status=%s(%d)",
+ statusToString(status).c_str(), status);
jniThrowRuntimeException(env, message.c_str());
return JNI_FALSE;
}
diff --git a/core/jni/android_view_TunnelModeEnabledListener.cpp b/core/jni/android_view_TunnelModeEnabledListener.cpp
new file mode 100644
index 000000000000..af7bae8c89dd
--- /dev/null
+++ b/core/jni/android_view_TunnelModeEnabledListener.cpp
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "TunnelModeEnabledListener"
+
+#include "android_util_Binder.h"
+#include "core_jni_helpers.h"
+
+#include <nativehelper/JNIHelp.h>
+
+#include <android/gui/BnTunnelModeEnabledListener.h>
+#include <android_runtime/AndroidRuntime.h>
+#include <android_runtime/Log.h>
+#include <utils/Log.h>
+
+#include <gui/SurfaceComposerClient.h>
+#include <ui/Rect.h>
+
+namespace android {
+
+namespace {
+
+struct {
+ jclass mClass;
+ jmethodID mDispatchOnTunnelModeEnabledChanged;
+} gListenerClassInfo;
+
+struct TunnelModeEnabledListener : public gui::BnTunnelModeEnabledListener {
+ TunnelModeEnabledListener(JNIEnv* env, jobject listener)
+ : mListener(env->NewWeakGlobalRef(listener)) {}
+
+ binder::Status onTunnelModeEnabledChanged(bool tunnelModeEnabled) override {
+ JNIEnv* env = AndroidRuntime::getJNIEnv();
+ LOG_ALWAYS_FATAL_IF(env == nullptr,
+ "Unable to retrieve JNIEnv in onTunnelModeEnabledChanged.");
+
+ jobject listener = env->NewGlobalRef(mListener);
+ if (listener == NULL) {
+ // Weak reference went out of scope
+ return binder::Status::ok();
+ }
+ env->CallStaticVoidMethod(gListenerClassInfo.mClass,
+ gListenerClassInfo.mDispatchOnTunnelModeEnabledChanged, listener,
+ static_cast<jboolean>(tunnelModeEnabled));
+ env->DeleteGlobalRef(listener);
+
+ if (env->ExceptionCheck()) {
+ ALOGE("TunnelModeEnabledListener.onTunnelModeEnabledChanged() failed.");
+ LOGE_EX(env);
+ env->ExceptionClear();
+ }
+ return binder::Status::ok();
+ }
+
+protected:
+ virtual ~TunnelModeEnabledListener() {
+ JNIEnv* env = AndroidRuntime::getJNIEnv();
+ env->DeleteWeakGlobalRef(mListener);
+ }
+
+private:
+ jweak mListener;
+};
+
+jlong nativeCreate(JNIEnv* env, jclass clazz, jobject obj) {
+ TunnelModeEnabledListener* listener = new TunnelModeEnabledListener(env, obj);
+ listener->incStrong((void*)nativeCreate);
+ return reinterpret_cast<jlong>(listener);
+}
+
+void nativeDestroy(JNIEnv* env, jclass clazz, jlong ptr) {
+ TunnelModeEnabledListener* listener = reinterpret_cast<TunnelModeEnabledListener*>(ptr);
+ listener->decStrong((void*)nativeCreate);
+}
+
+void nativeRegister(JNIEnv* env, jclass clazz, jlong ptr) {
+ sp<TunnelModeEnabledListener> listener = reinterpret_cast<TunnelModeEnabledListener*>(ptr);
+ if (SurfaceComposerClient::addTunnelModeEnabledListener(listener) != OK) {
+ constexpr auto error_msg = "Couldn't addTunnelModeEnabledListener";
+ ALOGE(error_msg);
+ jniThrowRuntimeException(env, error_msg);
+ }
+}
+
+void nativeUnregister(JNIEnv* env, jclass clazz, jlong ptr) {
+ sp<TunnelModeEnabledListener> listener = reinterpret_cast<TunnelModeEnabledListener*>(ptr);
+
+ if (SurfaceComposerClient::removeTunnelModeEnabledListener(listener) != OK) {
+ constexpr auto error_msg = "Couldn't removeTunnelModeEnabledListener";
+ ALOGE(error_msg);
+ jniThrowRuntimeException(env, error_msg);
+ }
+}
+
+const JNINativeMethod gMethods[] = {
+ /* name, signature, funcPtr */
+ {"nativeCreate", "(Landroid/view/TunnelModeEnabledListener;)J", (void*)nativeCreate},
+ {"nativeDestroy", "(J)V", (void*)nativeDestroy},
+ {"nativeRegister", "(J)V", (void*)nativeRegister},
+ {"nativeUnregister", "(J)V", (void*)nativeUnregister}};
+
+} // namespace
+
+int register_android_view_TunnelModeEnabledListener(JNIEnv* env) {
+ int res = jniRegisterNativeMethods(env, "android/view/TunnelModeEnabledListener", gMethods,
+ NELEM(gMethods));
+ LOG_ALWAYS_FATAL_IF(res < 0, "Unable to register native methods.");
+
+ jclass clazz = env->FindClass("android/view/TunnelModeEnabledListener");
+ gListenerClassInfo.mClass = MakeGlobalRefOrDie(env, clazz);
+ gListenerClassInfo.mDispatchOnTunnelModeEnabledChanged =
+ env->GetStaticMethodID(clazz, "dispatchOnTunnelModeEnabledChanged",
+ "(Landroid/view/TunnelModeEnabledListener;Z)V");
+ return 0;
+}
+
+} // namespace android
diff --git a/core/jni/com_android_internal_os_ZygoteCommandBuffer.cpp b/core/jni/com_android_internal_os_ZygoteCommandBuffer.cpp
index 24fef4881e4c..5fe96ede202e 100644
--- a/core/jni/com_android_internal_os_ZygoteCommandBuffer.cpp
+++ b/core/jni/com_android_internal_os_ZygoteCommandBuffer.cpp
@@ -402,7 +402,7 @@ jboolean com_android_internal_os_ZygoteCommandBuffer_nativeForkRepeatedly(
socklen_t cred_size = sizeof credentials;
if (getsockopt(n_buffer->getFd(), SOL_SOCKET, SO_PEERCRED, &credentials, &cred_size) == -1
|| cred_size != sizeof credentials) {
- fail_fn_1("ForkMany failed to get initial credentials, %s", strerror(errno));
+ fail_fn_1(CREATE_ERROR("ForkMany failed to get initial credentials, %s", strerror(errno)));
}
bool first_time = true;
@@ -453,7 +453,7 @@ jboolean com_android_internal_os_ZygoteCommandBuffer_nativeForkRepeatedly(
close(session_socket);
int new_fd = accept(zygote_socket_fd, nullptr, nullptr);
if (new_fd == -1) {
- fail_fn_z("Accept(%d) failed: %s", zygote_socket_fd, strerror(errno));
+ fail_fn_z(CREATE_ERROR("Accept(%d) failed: %s", zygote_socket_fd, strerror(errno)));
}
if (new_fd != session_socket) {
// Move new_fd back to the old value, so that we don't have to change Java-level data
diff --git a/core/jni/permission_utils.cpp b/core/jni/permission_utils.cpp
deleted file mode 100644
index 2b7ef9999491..000000000000
--- a/core/jni/permission_utils.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "permission_utils.h"
-#include "core_jni_helpers.h"
-
-static struct {
- jfieldID fieldUid; // Identity.uid
- jfieldID fieldPid; // Identity.pid
- jfieldID fieldPackageName; // Identity.packageName
- jfieldID fieldAttributionTag; // Identity.attributionTag
-} javaIdentityFields;
-
-static const JNINativeMethod method_table[] = {
- // no static methods, currently
-};
-
-int register_android_media_permission_Identity(JNIEnv* env) {
- jclass identityClass = android::FindClassOrDie(env, "android/media/permission/Identity");
- javaIdentityFields.fieldUid = android::GetFieldIDOrDie(env, identityClass, "uid", "I");
- javaIdentityFields.fieldPid = android::GetFieldIDOrDie(env, identityClass, "pid", "I");
- javaIdentityFields.fieldPackageName =
- android::GetFieldIDOrDie(env, identityClass, "packageName", "Ljava/lang/String;");
- javaIdentityFields.fieldAttributionTag =
- android::GetFieldIDOrDie(env, identityClass, "attributionTag", "Ljava/lang/String;");
-
- return android::RegisterMethodsOrDie(env, "android/media/permission/Identity", method_table,
- NELEM(method_table));
-}
-
-namespace android::media::permission {
-
-Identity convertIdentity(JNIEnv* env, const jobject& jIdentity) {
- Identity identity;
-
- identity.uid = env->GetIntField(jIdentity, javaIdentityFields.fieldUid);
- identity.pid = env->GetIntField(jIdentity, javaIdentityFields.fieldPid);
-
- jstring packageNameStr = static_cast<jstring>(
- env->GetObjectField(jIdentity, javaIdentityFields.fieldPackageName));
- if (packageNameStr == nullptr) {
- identity.packageName = std::nullopt;
- } else {
- identity.packageName = std::string(ScopedUtfChars(env, packageNameStr).c_str());
- }
-
- jstring attributionTagStr = static_cast<jstring>(
- env->GetObjectField(jIdentity, javaIdentityFields.fieldAttributionTag));
- if (attributionTagStr == nullptr) {
- identity.attributionTag = std::nullopt;
- } else {
- identity.attributionTag = std::string(ScopedUtfChars(env, attributionTagStr).c_str());
- }
-
- return identity;
-}
-
-} // namespace android::media::permission
diff --git a/core/jni/permission_utils.h b/core/jni/permission_utils.h
deleted file mode 100644
index d625bb6ba30a..000000000000
--- a/core/jni/permission_utils.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <android/media/permission/Identity.h>
-#include <jni.h>
-
-namespace android::media::permission {
-
-Identity convertIdentity(JNIEnv* env, const jobject& jIdentity);
-}
-
-int register_android_media_permission_Identity(JNIEnv* env);