Fix the setThreads JNI to throw SecurityException
Bug: 291830812
Test: atest FrameworksCoreTests:PerformanceHintManagerTest PerformanceHintTest
Change-Id: I35b28772c1ad2cf26e9f9f7f019406ef7c15303e
diff --git a/native/android/performance_hint.cpp b/native/android/performance_hint.cpp
index b3628fa..6198f40 100644
--- a/native/android/performance_hint.cpp
+++ b/native/android/performance_hint.cpp
@@ -274,9 +274,10 @@
binder::Status ret = mHintManager->setHintSessionThreads(mHintSession, tids);
if (!ret.isOk()) {
ALOGE("%s: failed: %s", __FUNCTION__, ret.exceptionMessage().c_str());
- if (ret.exceptionCode() == binder::Status::Exception::EX_SECURITY ||
- ret.exceptionCode() == binder::Status::Exception::EX_ILLEGAL_ARGUMENT) {
+ if (ret.exceptionCode() == binder::Status::Exception::EX_ILLEGAL_ARGUMENT) {
return EINVAL;
+ } else if (ret.exceptionCode() == binder::Status::Exception::EX_SECURITY) {
+ return EPERM;
}
return EPIPE;
}
diff --git a/native/android/tests/performance_hint/PerformanceHintNativeTest.cpp b/native/android/tests/performance_hint/PerformanceHintNativeTest.cpp
index 791adfd..6f7562b 100644
--- a/native/android/tests/performance_hint/PerformanceHintNativeTest.cpp
+++ b/native/android/tests/performance_hint/PerformanceHintNativeTest.cpp
@@ -178,4 +178,15 @@
.WillOnce(Return(Status()));
result = APerformanceHint_setThreads(session, newTids.data(), newTids.size());
EXPECT_EQ(0, result);
+
+ testing::Mock::VerifyAndClearExpectations(mMockIHintManager);
+ std::vector<int32_t> invalidTids;
+ auto status = Status::fromExceptionCode(binder::Status::Exception::EX_SECURITY);
+ invalidTids.push_back(4);
+ invalidTids.push_back(6);
+ EXPECT_CALL(*mMockIHintManager, setHintSessionThreads(_, Eq(invalidTids)))
+ .Times(Exactly(1))
+ .WillOnce(Return(status));
+ result = APerformanceHint_setThreads(session, invalidTids.data(), invalidTids.size());
+ EXPECT_EQ(EPERM, result);
}