From 24071205b2bf1c458e14703548b2e6eefb1a27f6 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 21 Apr 2022 11:21:08 -0400 Subject: [PATCH] Revert "Fix empty channel (#17489)" (#17607) This reverts commit 18338b9cd07895014a496dd41f8951e9480aee9e. Commit broke android compilation using build_examples.py: ``` ./scripts/build/build_examples.py --target android-arm-chip-tvserver ``` --- .../android/App/platform-app/build.gradle | 4 +- .../tv-app/android/java/ChannelManager.cpp | 125 ++++++++---------- .../tcl/chip/tvapp/ChannelManagerStub.java | 14 -- scripts/examples/gn_android_example.sh | 12 +- 4 files changed, 63 insertions(+), 92 deletions(-) diff --git a/examples/tv-app/android/App/platform-app/build.gradle b/examples/tv-app/android/App/platform-app/build.gradle index f586fbe06f2ae0..8c9d066650ed5f 100644 --- a/examples/tv-app/android/App/platform-app/build.gradle +++ b/examples/tv-app/android/App/platform-app/build.gradle @@ -39,7 +39,7 @@ android { sourceSets { main { - jniLibs.srcDirs = ['../platform-app/libs/jniLibs'] + jniLibs.srcDirs = ['../app/libs/jniLibs'] // uncomment this code to debug // java.srcDirs = [ @@ -54,7 +54,7 @@ android { } dependencies { - implementation fileTree(dir: "../platform-app/libs", include: ["*.jar","*.so"]) + implementation fileTree(dir: "../app/libs", include: ["*.jar","*.so"]) implementation 'androidx.appcompat:appcompat:1.3.1' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.1' diff --git a/examples/tv-app/android/java/ChannelManager.cpp b/examples/tv-app/android/java/ChannelManager.cpp index fef1174fbd9a84..303c2afbd61e8c 100644 --- a/examples/tv-app/android/java/ChannelManager.cpp +++ b/examples/tv-app/android/java/ChannelManager.cpp @@ -141,44 +141,37 @@ CHIP_ERROR ChannelManager::HandleGetLineup(AttributeValueEncoder & aEncoder) { jobject channelLineupObject = env->CallObjectMethod(mChannelManagerObject, mGetLineupMethod); - if (channelLineupObject != nullptr) - { - 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) - { - lineupInfo.operatorName = operatorName.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()); - } + jclass channelLineupClazz = env->GetObjectClass(channelLineupObject); - 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 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(); + } - err = aEncoder.Encode(lineupInfo); + 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()); } - else + + jfieldID postalCodeFild = env->GetFieldID(channelLineupClazz, "postalCode", "Ljava/lang/String;"); + jstring jpostalCode = static_cast(env->GetObjectField(channelLineupObject, postalCodeFild)); + JniUtfString postalCode(env, jpostalCode); + if (jpostalCode != nullptr) { - err = aEncoder.EncodeNull(); + lineupInfo.postalCode = Optional(postalCode.charSpan()); } + + jfieldID lineupInfoTypeFild = env->GetFieldID(channelLineupClazz, "lineupInfoType", "I"); + jint jlineupInfoType = (env->GetIntField(channelLineupObject, lineupInfoTypeFild)); + lineupInfo.lineupInfoType = static_cast(jlineupInfoType); + + err = aEncoder.Encode(lineupInfo); } exit: @@ -202,49 +195,41 @@ CHIP_ERROR ChannelManager::HandleGetCurrentChannel(AttributeValueEncoder & aEnco { jobject channelInfoObject = env->CallObjectMethod(mChannelManagerObject, mGetCurrentChannelMethod); - if (channelInfoObject != nullptr) - { - jclass channelClass = env->GetObjectClass(channelInfoObject); + 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) - { - channelInfo.callSign = Optional(callsign.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 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 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 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); - } - else - { - err = aEncoder.EncodeNull(); - return err; - } + err = aEncoder.Encode(channelInfo); } 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 9c7556e8bb340b..9519d0fb1ee143 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,7 +23,6 @@ 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; @@ -39,12 +38,6 @@ 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; @@ -53,11 +46,6 @@ 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"); } @@ -84,8 +72,6 @@ public boolean changeChannelByNumber(int majorNumber, int minorNumber) { + " at " + endpoint); - mCurrentChannel = majorNumber; - // for failed test if (majorNumber == 1 && minorNumber == 1) { return false; diff --git a/scripts/examples/gn_android_example.sh b/scripts/examples/gn_android_example.sh index 0b089a8f197455..5952eff0f0e8a8 100755 --- a/scripts/examples/gn_android_example.sh +++ b/scripts/examples/gn_android_example.sh @@ -16,7 +16,7 @@ # limitations under the License. # -set -ex +set -e # Build script for GN examples GitHub workflow. @@ -74,8 +74,8 @@ gn gen --check --fail-on-unused-args --root="$EXAMPLE_DIR" "$OUTPUT_DIR" --args= ninja -C "$OUTPUT_DIR" "${NINJA_ARGS[@]}" -cp -rf "$OUTPUT_DIR/lib/jni/." "$EXAMPLE_DIR/App/platform-app/libs/jniLibs/" -cp -f "$OUTPUT_DIR/lib/third_party/connectedhomeip/src/platform/android/AndroidPlatform.jar" "$EXAMPLE_DIR/App/platform-app/libs/" -cp -f "$OUTPUT_DIR/lib/third_party/connectedhomeip/src/app/server/java/CHIPAppServer.jar" "$EXAMPLE_DIR/App/platform-app/libs/" -cp -f "$OUTPUT_DIR/lib/third_party/connectedhomeip/src/setup_payload/java/SetupPayloadParser.jar" "$EXAMPLE_DIR/App/platform-app/libs/" -cp -f "$OUTPUT_DIR/lib/TvApp.jar" "$EXAMPLE_DIR/App/platform-app/libs/" +cp -rf "$OUTPUT_DIR/lib/jni/." "$EXAMPLE_DIR/App/app/libs/jniLibs/" +cp -f "$OUTPUT_DIR/lib/third_party/connectedhomeip/src/platform/android/AndroidPlatform.jar" "$EXAMPLE_DIR/App/app/libs/" +cp -f "$OUTPUT_DIR/lib/third_party/connectedhomeip/src/app/server/java/CHIPAppServer.jar" "$EXAMPLE_DIR/App/app/libs/" +cp -f "$OUTPUT_DIR/lib/third_party/connectedhomeip/src/setup_payload/java/SetupPayloadParser.jar" "$EXAMPLE_DIR/App/app/libs/" +cp -f "$OUTPUT_DIR/lib/TvApp.jar" "$EXAMPLE_DIR/App/app/libs/"