From dcb1e3b9136180bb415f967c120de48ee0b8c94e Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Fri, 17 Dec 2021 01:32:47 +0900 Subject: [PATCH] Explicit cast from android::Base::Errno to status_t Previously, Result.error().code() returned int and this was convertible to status_t which is an alias of int. However, this actually was type unsafe because the return type of error().code() was actually mean to be that of errno. errno and status_t are both int, but their meanings are very different. To handle such problems, Result.error().code() now returns android::base::Errno which is a wrapper to errno, but not to other int-based types like status_t and StatusCode. Eventually, Result used here should be changed into Result where StatusT is a type-safe wrapper class to status_t that implements the contract to be used as the error type in android::base::Result. Unfortunately, since the use of Result is so wide spread, in this change, I aim to only fix the build error in this CL. Bug: 209929099 Test: m Change-Id: Ic10ab8ed52f6827ba3ac6fb7d6e031585827562f --- .../core/jni/com_android_server_input_InputManagerService.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index bb9740b60f782..7066d5680f668 100644 --- a/services/core/jni/com_android_server_input_InputManagerService.cpp +++ b/services/core/jni/com_android_server_input_InputManagerService.cpp @@ -1585,7 +1585,7 @@ static jobject nativeCreateInputChannel(JNIEnv* env, jclass /* clazz */, jlong p if (!inputChannel.ok()) { std::string message = inputChannel.error().message(); - message += StringPrintf(" Status=%d", inputChannel.error().code()); + message += StringPrintf(" Status=%d", static_cast(inputChannel.error().code())); jniThrowRuntimeException(env, message.c_str()); return nullptr; } @@ -1619,7 +1619,7 @@ static jobject nativeCreateInputMonitor(JNIEnv* env, jclass /* clazz */, jlong p if (!inputChannel.ok()) { std::string message = inputChannel.error().message(); - message += StringPrintf(" Status=%d", inputChannel.error().code()); + message += StringPrintf(" Status=%d", static_cast(inputChannel.error().code())); jniThrowRuntimeException(env, message.c_str()); return nullptr; }