Check tvinput AIDL existing before using

Not all TV devices have the tvinput HAL. We should check whether it's existed before using.

Bug: 261699781
Test: Test on TV device w/o tvinput HAL
Change-Id: I6a46fdae3823a0ba2774d94824f8fbfa3c4a1cfd
This commit is contained in:
Hongguang Chen
2022-12-07 14:33:27 +00:00
parent 6a5c7459a4
commit f08dbaf6c1

View File

@@ -42,8 +42,11 @@ JTvInputHal* JTvInputHal::createInstance(JNIEnv* env, jobject thiz, const sp<Loo
std::shared_ptr<ITvInputWrapper>(new ITvInputWrapper(hidlITvInput)),
looper);
}
::ndk::SpAIBinder binder(AServiceManager_waitForService(TV_INPUT_AIDL_SERVICE_NAME));
std::shared_ptr<AidlITvInput> aidlITvInput = AidlITvInput::fromBinder(binder);
std::shared_ptr<AidlITvInput> aidlITvInput = nullptr;
if (AServiceManager_isDeclared(TV_INPUT_AIDL_SERVICE_NAME)) {
::ndk::SpAIBinder binder(AServiceManager_waitForService(TV_INPUT_AIDL_SERVICE_NAME));
aidlITvInput = AidlITvInput::fromBinder(binder);
}
if (aidlITvInput == nullptr) {
ALOGE("Couldn't get tv.input service.");
return nullptr;