diff options
Diffstat (limited to 'native')
| -rw-r--r-- | native/android/Android.bp | 6 | ||||
| -rw-r--r-- | native/android/TEST_MAPPING | 9 | ||||
| -rw-r--r-- | native/android/configuration.cpp | 2 | ||||
| -rw-r--r-- | native/android/libandroid.map.txt | 1 | ||||
| -rw-r--r-- | native/android/performance_hint.cpp | 24 | ||||
| -rw-r--r-- | native/android/system_fonts.cpp | 9 | ||||
| -rw-r--r-- | native/android/tests/performance_hint/PerformanceHintNativeTest.cpp | 62 |
7 files changed, 103 insertions, 10 deletions
diff --git a/native/android/Android.bp b/native/android/Android.bp index 254eb4494ed8..7f3792d06795 100644 --- a/native/android/Android.bp +++ b/native/android/Android.bp @@ -46,7 +46,10 @@ cc_defaults { cc_library_shared { name: "libandroid", - defaults: ["libandroid_defaults"], + defaults: [ + "libandroid_defaults", + "android.hardware.power-ndk_shared", + ], srcs: [ "activity_manager.cpp", @@ -95,7 +98,6 @@ cc_library_shared { "libpowermanager", "android.hardware.configstore@1.0", "android.hardware.configstore-utils", - "android.hardware.power-V4-ndk", "libnativedisplay", ], diff --git a/native/android/TEST_MAPPING b/native/android/TEST_MAPPING index 6a5d2c008b1d..fd394fc43477 100644 --- a/native/android/TEST_MAPPING +++ b/native/android/TEST_MAPPING @@ -12,6 +12,15 @@ } ], "file_patterns": ["permission_manager.cpp"] + }, + { + "name": "CtsOsTestCases", + "options": [ + { + "include-filter": "android.os.cts.PerformanceHintManagerTest" + } + ], + "file_patterns": ["performance_hint.cpp"] } ] } diff --git a/native/android/configuration.cpp b/native/android/configuration.cpp index b50514d27bac..283445fc8a9a 100644 --- a/native/android/configuration.cpp +++ b/native/android/configuration.cpp @@ -36,7 +36,7 @@ void AConfiguration_delete(AConfiguration* config) { void AConfiguration_fromAssetManager(AConfiguration* out, AAssetManager* am) { ScopedLock<AssetManager2> locked_mgr(*AssetManagerForNdkAssetManager(am)); - ResTable_config config = locked_mgr->GetConfiguration(); + ResTable_config config = locked_mgr->GetConfigurations()[0]; // AConfiguration is not a virtual subclass, so we can memcpy. memcpy(out, &config, sizeof(config)); diff --git a/native/android/libandroid.map.txt b/native/android/libandroid.map.txt index d74f9b7bb659..b0af09c19b7e 100644 --- a/native/android/libandroid.map.txt +++ b/native/android/libandroid.map.txt @@ -334,6 +334,7 @@ LIBANDROID { APerformanceHint_reportActualWorkDuration; # introduced=Tiramisu APerformanceHint_closeSession; # introduced=Tiramisu APerformanceHint_setThreads; # introduced=UpsideDownCake + APerformanceHint_setPreferPowerEfficiency; # introduced=VanillaIceCream local: *; }; diff --git a/native/android/performance_hint.cpp b/native/android/performance_hint.cpp index b3628fa3e5ce..c25df6e08fd0 100644 --- a/native/android/performance_hint.cpp +++ b/native/android/performance_hint.cpp @@ -17,6 +17,7 @@ #define LOG_TAG "perf_hint" #include <aidl/android/hardware/power/SessionHint.h> +#include <aidl/android/hardware/power/SessionMode.h> #include <android/os/IHintManager.h> #include <android/os/IHintSession.h> #include <android/performance_hint.h> @@ -36,6 +37,7 @@ using namespace android::os; using namespace std::chrono_literals; using AidlSessionHint = aidl::android::hardware::power::SessionHint; +using AidlSessionMode = aidl::android::hardware::power::SessionMode; struct APerformanceHintSession; @@ -72,6 +74,7 @@ public: int sendHint(SessionHint hint); int setThreads(const int32_t* threadIds, size_t size); int getThreadIds(int32_t* const threadIds, size_t* size); + int setPreferPowerEfficiency(bool enabled); private: friend struct APerformanceHintManager; @@ -274,9 +277,10 @@ int APerformanceHintSession::setThreads(const int32_t* threadIds, size_t size) { 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; } @@ -306,6 +310,18 @@ int APerformanceHintSession::getThreadIds(int32_t* const threadIds, size_t* size return 0; } +int APerformanceHintSession::setPreferPowerEfficiency(bool enabled) { + binder::Status ret = + mHintSession->setMode(static_cast<int32_t>(AidlSessionMode::POWER_EFFICIENCY), enabled); + + if (!ret.isOk()) { + ALOGE("%s: HintSession setPreferPowerEfficiency failed: %s", __FUNCTION__, + ret.exceptionMessage().c_str()); + return EPIPE; + } + return OK; +} + // ===================================== C API APerformanceHintManager* APerformanceHint_getManager() { return APerformanceHintManager::getInstance(); @@ -356,6 +372,10 @@ int APerformanceHint_getThreadIds(void* aPerformanceHintSession, int32_t* const ->getThreadIds(threadIds, size); } +int APerformanceHint_setPreferPowerEfficiency(APerformanceHintSession* session, bool enabled) { + return session->setPreferPowerEfficiency(enabled); +} + void APerformanceHint_setIHintManagerForTesting(void* iManager) { delete gHintManagerForTesting; gHintManagerForTesting = nullptr; diff --git a/native/android/system_fonts.cpp b/native/android/system_fonts.cpp index fe3132e3d2a3..de7ea701b26d 100644 --- a/native/android/system_fonts.cpp +++ b/native/android/system_fonts.cpp @@ -251,14 +251,15 @@ ASystemFontIterator* ASystemFontIterator_open() { locale.emplace(minikin::getLocaleString(localeId)); } std::vector<std::pair<uint32_t, float>> axes; - for (const auto& [tag, value] : font->typeface()->GetAxes()) { + for (const auto& [tag, value] : font->baseTypeface()->GetAxes()) { axes.push_back(std::make_pair(tag, value)); } - fonts.insert({font->typeface()->GetFontPath(), std::move(locale), + fonts.insert({font->baseTypeface()->GetFontPath(), std::move(locale), font->style().weight(), font->style().slant() == minikin::FontStyle::Slant::ITALIC, - static_cast<uint32_t>(font->typeface()->GetFontIndex()), axes}); + static_cast<uint32_t>(font->baseTypeface()->GetFontIndex()), + axes}); } }); @@ -323,7 +324,7 @@ AFont* _Nonnull AFontMatcher_match( .font; std::unique_ptr<AFont> result = std::make_unique<AFont>(); const android::MinikinFontSkia* minikinFontSkia = - reinterpret_cast<android::MinikinFontSkia*>(font->typeface().get()); + reinterpret_cast<android::MinikinFontSkia*>(font->baseTypeface().get()); result->mFilePath = minikinFontSkia->getFilePath(); result->mWeight = font->style().weight(); result->mItalic = font->style().slant() == minikin::FontStyle::Slant::ITALIC; diff --git a/native/android/tests/performance_hint/PerformanceHintNativeTest.cpp b/native/android/tests/performance_hint/PerformanceHintNativeTest.cpp index 791adfd33fcd..22d33b139ccf 100644 --- a/native/android/tests/performance_hint/PerformanceHintNativeTest.cpp +++ b/native/android/tests/performance_hint/PerformanceHintNativeTest.cpp @@ -56,7 +56,8 @@ public: (const ::std::vector<int64_t>& actualDurationNanos, const ::std::vector<int64_t>& timeStampNanos), (override)); - MOCK_METHOD(Status, sendHint, (int32_t hints), (override)); + MOCK_METHOD(Status, sendHint, (int32_t hint), (override)); + MOCK_METHOD(Status, setMode, (int32_t mode, bool enabled), (override)); MOCK_METHOD(Status, close, (), (override)); MOCK_METHOD(IBinder*, onAsBinder, (), (override)); }; @@ -178,4 +179,63 @@ TEST_F(PerformanceHintTest, SetThreads) { .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); +} + +TEST_F(PerformanceHintTest, SetPowerEfficient) { + APerformanceHintManager* manager = createManager(); + + std::vector<int32_t> tids; + tids.push_back(1); + tids.push_back(2); + int64_t targetDuration = 56789L; + + StrictMock<MockIHintSession>* iSession = new StrictMock<MockIHintSession>(); + sp<IHintSession> session_sp(iSession); + + EXPECT_CALL(*mMockIHintManager, createHintSession(_, Eq(tids), Eq(targetDuration), _)) + .Times(Exactly(1)) + .WillRepeatedly(DoAll(SetArgPointee<3>(std::move(session_sp)), Return(Status()))); + + APerformanceHintSession* session = + APerformanceHint_createSession(manager, tids.data(), tids.size(), targetDuration); + ASSERT_TRUE(session); + + EXPECT_CALL(*iSession, setMode(_, Eq(true))).Times(Exactly(1)); + int result = APerformanceHint_setPreferPowerEfficiency(session, true); + EXPECT_EQ(0, result); + + EXPECT_CALL(*iSession, setMode(_, Eq(false))).Times(Exactly(1)); + result = APerformanceHint_setPreferPowerEfficiency(session, false); + EXPECT_EQ(0, result); } + +TEST_F(PerformanceHintTest, CreateZeroTargetDurationSession) { + APerformanceHintManager* manager = createManager(); + + std::vector<int32_t> tids; + tids.push_back(1); + tids.push_back(2); + int64_t targetDuration = 0; + + StrictMock<MockIHintSession>* iSession = new StrictMock<MockIHintSession>(); + sp<IHintSession> session_sp(iSession); + + EXPECT_CALL(*mMockIHintManager, createHintSession(_, Eq(tids), Eq(targetDuration), _)) + .Times(Exactly(1)) + .WillRepeatedly(DoAll(SetArgPointee<3>(std::move(session_sp)), Return(Status()))); + + APerformanceHintSession* session = + APerformanceHint_createSession(manager, tids.data(), tids.size(), targetDuration); + ASSERT_TRUE(session); +}
\ No newline at end of file |