From 79c156e3bafdb3eb83ca297b145dbec5fe1960e9 Mon Sep 17 00:00:00 2001 From: "Hui.Li-TCL" Date: Fri, 22 Apr 2022 21:17:05 +0800 Subject: [PATCH] Fix empty channel ( fix build error ) (#17626) * fix build error * fix lineup and channel null error * fix restyled-io and ci errors * fix build_example.py error * fix build_example.py error * fix build_example.py error --- .../App/{platform-app => app}/libs/README.md | 0 .../libs/jniLibs/README.md | 0 .../tv-app/android/java/ChannelManager.cpp | 125 ++++++++++-------- .../tcl/chip/tvapp/ChannelManagerStub.java | 14 ++ 4 files changed, 84 insertions(+), 55 deletions(-) rename examples/tv-app/android/App/{platform-app => app}/libs/README.md (100%) rename examples/tv-app/android/App/{platform-app => app}/libs/jniLibs/README.md (100%) diff --git a/examples/tv-app/android/App/platform-app/libs/README.md b/examples/tv-app/android/App/app/libs/README.md similarity index 100% rename from examples/tv-app/android/App/platform-app/libs/README.md rename to examples/tv-app/android/App/app/libs/README.md diff --git a/examples/tv-app/android/App/platform-app/libs/jniLibs/README.md b/examples/tv-app/android/App/app/libs/jniLibs/README.md similarity index 100% rename from examples/tv-app/android/App/platform-app/libs/jniLibs/README.md rename to examples/tv-app/android/App/app/libs/jniLibs/README.md diff --git a/examples/tv-app/android/java/ChannelManager.cpp b/examples/tv-app/android/java/ChannelManager.cpp index 303c2afbd61e8c..fef1174fbd9a84 100644 --- a/examples/tv-app/android/java/ChannelManager.cpp +++ b/examples/tv-app/android/java/ChannelManager.cpp @@ -141,37 +141,44 @@ CHIP_ERROR ChannelManager::HandleGetLineup(AttributeValueEncoder & aEncoder) { jobject channelLineupObject = env->CallObjectMethod(mChannelManagerObject, mGetLineupMethod); - jclass channelLineupClazz = env->GetObjectClass(channelLineupObject); - - jfieldID operatorNameFild = env->GetFieldID(channelLineupClazz, "operatorName", "Ljava/lang/String;"); - jstring joperatorName = static_cast(env->GetObjectField(channelLineupObject, operatorNameFild)); - JniUtfString operatorName(env, joperatorName); - if (joperatorName != nullptr) + if (channelLineupObject != nullptr) { - lineupInfo.operatorName = operatorName.charSpan(); - } + jclass channelLineupClazz = env->GetObjectClass(channelLineupObject); - jfieldID lineupNameFild = env->GetFieldID(channelLineupClazz, "lineupName", "Ljava/lang/String;"); - jstring jlineupName = static_cast(env->GetObjectField(channelLineupObject, lineupNameFild)); - JniUtfString lineupName(env, jlineupName); - if (jlineupName != nullptr) - { - lineupInfo.lineupName = Optional(lineupName.charSpan()); - } + jfieldID operatorNameFild = env->GetFieldID(channelLineupClazz, "operatorName", "Ljava/lang/String;"); + jstring joperatorName = static_cast(env->GetObjectField(channelLineupObject, operatorNameFild)); + JniUtfString operatorName(env, joperatorName); + if (joperatorName != nullptr) + { + lineupInfo.operatorName = operatorName.charSpan(); + } - jfieldID postalCodeFild = env->GetFieldID(channelLineupClazz, "postalCode", "Ljava/lang/String;"); - jstring jpostalCode = static_cast(env->GetObjectField(channelLineupObject, postalCodeFild)); - JniUtfString postalCode(env, jpostalCode); - if (jpostalCode != nullptr) - { - lineupInfo.postalCode = Optional(postalCode.charSpan()); - } + jfieldID lineupNameFild = env->GetFieldID(channelLineupClazz, "lineupName", "Ljava/lang/String;"); + jstring jlineupName = static_cast(env->GetObjectField(channelLineupObject, lineupNameFild)); + JniUtfString lineupName(env, jlineupName); + if (jlineupName != nullptr) + { + lineupInfo.lineupName = Optional(lineupName.charSpan()); + } + + jfieldID postalCodeFild = env->GetFieldID(channelLineupClazz, "postalCode", "Ljava/lang/String;"); + jstring jpostalCode = static_cast(env->GetObjectField(channelLineupObject, postalCodeFild)); + JniUtfString postalCode(env, jpostalCode); + if (jpostalCode != nullptr) + { + lineupInfo.postalCode = Optional(postalCode.charSpan()); + } - jfieldID lineupInfoTypeFild = env->GetFieldID(channelLineupClazz, "lineupInfoType", "I"); - jint jlineupInfoType = (env->GetIntField(channelLineupObject, lineupInfoTypeFild)); - lineupInfo.lineupInfoType = static_cast(jlineupInfoType); + jfieldID lineupInfoTypeFild = env->GetFieldID(channelLineupClazz, "lineupInfoType", "I"); + jint jlineupInfoType = (env->GetIntField(channelLineupObject, lineupInfoTypeFild)); + lineupInfo.lineupInfoType = static_cast(jlineupInfoType); - err = aEncoder.Encode(lineupInfo); + err = aEncoder.Encode(lineupInfo); + } + else + { + err = aEncoder.EncodeNull(); + } } exit: @@ -195,41 +202,49 @@ CHIP_ERROR ChannelManager::HandleGetCurrentChannel(AttributeValueEncoder & aEnco { jobject channelInfoObject = env->CallObjectMethod(mChannelManagerObject, mGetCurrentChannelMethod); - jclass channelClass = env->GetObjectClass(channelInfoObject); - - jfieldID getCallSignField = env->GetFieldID(channelClass, "callSign", "Ljava/lang/String;"); - jstring jcallSign = static_cast(env->GetObjectField(channelInfoObject, getCallSignField)); - JniUtfString callsign(env, jcallSign); - if (jcallSign != nullptr) + if (channelInfoObject != nullptr) { - channelInfo.callSign = Optional(callsign.charSpan()); - } + jclass channelClass = env->GetObjectClass(channelInfoObject); - jfieldID getNameField = env->GetFieldID(channelClass, "name", "Ljava/lang/String;"); - jstring jname = static_cast(env->GetObjectField(channelInfoObject, getNameField)); - JniUtfString name(env, jname); - if (jname != nullptr) - { - channelInfo.name = Optional(name.charSpan()); - } + jfieldID getCallSignField = env->GetFieldID(channelClass, "callSign", "Ljava/lang/String;"); + jstring jcallSign = static_cast(env->GetObjectField(channelInfoObject, getCallSignField)); + JniUtfString callsign(env, jcallSign); + if (jcallSign != nullptr) + { + channelInfo.callSign = Optional(callsign.charSpan()); + } - jfieldID getJaffiliateCallSignField = env->GetFieldID(channelClass, "affiliateCallSign", "Ljava/lang/String;"); - jstring jaffiliateCallSign = static_cast(env->GetObjectField(channelInfoObject, getJaffiliateCallSignField)); - JniUtfString affiliateCallSign(env, jaffiliateCallSign); - if (jaffiliateCallSign != nullptr) - { - channelInfo.affiliateCallSign = Optional(affiliateCallSign.charSpan()); - } + jfieldID getNameField = env->GetFieldID(channelClass, "name", "Ljava/lang/String;"); + jstring jname = static_cast(env->GetObjectField(channelInfoObject, getNameField)); + JniUtfString name(env, jname); + if (jname != nullptr) + { + channelInfo.name = Optional(name.charSpan()); + } + + jfieldID getJaffiliateCallSignField = env->GetFieldID(channelClass, "affiliateCallSign", "Ljava/lang/String;"); + jstring jaffiliateCallSign = static_cast(env->GetObjectField(channelInfoObject, getJaffiliateCallSignField)); + JniUtfString affiliateCallSign(env, jaffiliateCallSign); + if (jaffiliateCallSign != nullptr) + { + channelInfo.affiliateCallSign = Optional(affiliateCallSign.charSpan()); + } - jfieldID majorNumField = env->GetFieldID(channelClass, "majorNumber", "I"); - jint jmajorNum = env->GetIntField(channelInfoObject, majorNumField); - channelInfo.majorNumber = static_cast(jmajorNum); + jfieldID majorNumField = env->GetFieldID(channelClass, "majorNumber", "I"); + jint jmajorNum = env->GetIntField(channelInfoObject, majorNumField); + channelInfo.majorNumber = static_cast(jmajorNum); - jfieldID minorNumField = env->GetFieldID(channelClass, "minorNumber", "I"); - jint jminorNum = env->GetIntField(channelInfoObject, minorNumField); - channelInfo.minorNumber = static_cast(jminorNum); + jfieldID minorNumField = env->GetFieldID(channelClass, "minorNumber", "I"); + jint jminorNum = env->GetIntField(channelInfoObject, minorNumField); + channelInfo.minorNumber = static_cast(jminorNum); - err = aEncoder.Encode(channelInfo); + err = aEncoder.Encode(channelInfo); + } + else + { + err = aEncoder.EncodeNull(); + return err; + } } exit: diff --git a/examples/tv-app/android/java/src/com/tcl/chip/tvapp/ChannelManagerStub.java b/examples/tv-app/android/java/src/com/tcl/chip/tvapp/ChannelManagerStub.java index 9519d0fb1ee143..9c7556e8bb340b 100644 --- a/examples/tv-app/android/java/src/com/tcl/chip/tvapp/ChannelManagerStub.java +++ b/examples/tv-app/android/java/src/com/tcl/chip/tvapp/ChannelManagerStub.java @@ -23,6 +23,7 @@ public class ChannelManagerStub implements ChannelManager { private static final String TAG = ChannelManagerStub.class.getSimpleName(); private int endpoint; + private int mCurrentChannel = 0; public ChannelManagerStub(int endpoint) { this.endpoint = endpoint; @@ -38,6 +39,12 @@ public ChannelInfo[] getChannelList() { @Override public ChannelLineupInfo getLineup() { + // for null lineup test + if (mCurrentChannel == 100) { + Log.d(TAG, "getChannelLineup: null at " + endpoint); + return null; + } + ChannelLineupInfo lineupInfo = new ChannelLineupInfo("operator", "lineup", "postalCode"); Log.d(TAG, "getChannelLineup: " + lineupInfo + " at " + endpoint); return lineupInfo; @@ -46,6 +53,11 @@ public ChannelLineupInfo getLineup() { @Override public ChannelInfo getCurrentChannel() { Log.d(TAG, "getCurrentChannel: at " + endpoint); + // for null channel test + if (mCurrentChannel == 100) { + return null; + } + return new ChannelInfo(1, 1, "HDMI", "callSign", "affiliateCallSign"); } @@ -72,6 +84,8 @@ public boolean changeChannelByNumber(int majorNumber, int minorNumber) { + " at " + endpoint); + mCurrentChannel = majorNumber; + // for failed test if (majorNumber == 1 && minorNumber == 1) { return false;