Skip to content

Commit

Permalink
Fix empty channel (#17489)
Browse files Browse the repository at this point in the history
* fix build error

* fix lineup and channel null error

* fix restyled-io and ci errors
  • Loading branch information
xylophone21 authored and pull[bot] committed Dec 22, 2023
1 parent 3d1c488 commit 1168344
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 63 deletions.
4 changes: 2 additions & 2 deletions examples/tv-app/android/App/platform-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ android {

sourceSets {
main {
jniLibs.srcDirs = ['../app/libs/jniLibs']
jniLibs.srcDirs = ['../platform-app/libs/jniLibs']

// uncomment this code to debug
// java.srcDirs = [
Expand All @@ -54,7 +54,7 @@ android {
}

dependencies {
implementation fileTree(dir: "../app/libs", include: ["*.jar","*.so"])
implementation fileTree(dir: "../platform-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'
Expand Down
125 changes: 70 additions & 55 deletions examples/tv-app/android/java/ChannelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<jstring>(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<jstring>(env->GetObjectField(channelLineupObject, lineupNameFild));
JniUtfString lineupName(env, jlineupName);
if (jlineupName != nullptr)
{
lineupInfo.lineupName = Optional<CharSpan>(lineupName.charSpan());
}
jfieldID operatorNameFild = env->GetFieldID(channelLineupClazz, "operatorName", "Ljava/lang/String;");
jstring joperatorName = static_cast<jstring>(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<jstring>(env->GetObjectField(channelLineupObject, postalCodeFild));
JniUtfString postalCode(env, jpostalCode);
if (jpostalCode != nullptr)
{
lineupInfo.postalCode = Optional<CharSpan>(postalCode.charSpan());
}
jfieldID lineupNameFild = env->GetFieldID(channelLineupClazz, "lineupName", "Ljava/lang/String;");
jstring jlineupName = static_cast<jstring>(env->GetObjectField(channelLineupObject, lineupNameFild));
JniUtfString lineupName(env, jlineupName);
if (jlineupName != nullptr)
{
lineupInfo.lineupName = Optional<CharSpan>(lineupName.charSpan());
}

jfieldID postalCodeFild = env->GetFieldID(channelLineupClazz, "postalCode", "Ljava/lang/String;");
jstring jpostalCode = static_cast<jstring>(env->GetObjectField(channelLineupObject, postalCodeFild));
JniUtfString postalCode(env, jpostalCode);
if (jpostalCode != nullptr)
{
lineupInfo.postalCode = Optional<CharSpan>(postalCode.charSpan());
}

jfieldID lineupInfoTypeFild = env->GetFieldID(channelLineupClazz, "lineupInfoType", "I");
jint jlineupInfoType = (env->GetIntField(channelLineupObject, lineupInfoTypeFild));
lineupInfo.lineupInfoType = static_cast<app::Clusters::Channel::LineupInfoTypeEnum>(jlineupInfoType);
jfieldID lineupInfoTypeFild = env->GetFieldID(channelLineupClazz, "lineupInfoType", "I");
jint jlineupInfoType = (env->GetIntField(channelLineupObject, lineupInfoTypeFild));
lineupInfo.lineupInfoType = static_cast<app::Clusters::Channel::LineupInfoTypeEnum>(jlineupInfoType);

err = aEncoder.Encode(lineupInfo);
err = aEncoder.Encode(lineupInfo);
}
else
{
err = aEncoder.EncodeNull();
}
}

exit:
Expand All @@ -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<jstring>(env->GetObjectField(channelInfoObject, getCallSignField));
JniUtfString callsign(env, jcallSign);
if (jcallSign != nullptr)
if (channelInfoObject != nullptr)
{
channelInfo.callSign = Optional<CharSpan>(callsign.charSpan());
}
jclass channelClass = env->GetObjectClass(channelInfoObject);

jfieldID getNameField = env->GetFieldID(channelClass, "name", "Ljava/lang/String;");
jstring jname = static_cast<jstring>(env->GetObjectField(channelInfoObject, getNameField));
JniUtfString name(env, jname);
if (jname != nullptr)
{
channelInfo.name = Optional<CharSpan>(name.charSpan());
}
jfieldID getCallSignField = env->GetFieldID(channelClass, "callSign", "Ljava/lang/String;");
jstring jcallSign = static_cast<jstring>(env->GetObjectField(channelInfoObject, getCallSignField));
JniUtfString callsign(env, jcallSign);
if (jcallSign != nullptr)
{
channelInfo.callSign = Optional<CharSpan>(callsign.charSpan());
}

jfieldID getJaffiliateCallSignField = env->GetFieldID(channelClass, "affiliateCallSign", "Ljava/lang/String;");
jstring jaffiliateCallSign = static_cast<jstring>(env->GetObjectField(channelInfoObject, getJaffiliateCallSignField));
JniUtfString affiliateCallSign(env, jaffiliateCallSign);
if (jaffiliateCallSign != nullptr)
{
channelInfo.affiliateCallSign = Optional<CharSpan>(affiliateCallSign.charSpan());
}
jfieldID getNameField = env->GetFieldID(channelClass, "name", "Ljava/lang/String;");
jstring jname = static_cast<jstring>(env->GetObjectField(channelInfoObject, getNameField));
JniUtfString name(env, jname);
if (jname != nullptr)
{
channelInfo.name = Optional<CharSpan>(name.charSpan());
}

jfieldID getJaffiliateCallSignField = env->GetFieldID(channelClass, "affiliateCallSign", "Ljava/lang/String;");
jstring jaffiliateCallSign = static_cast<jstring>(env->GetObjectField(channelInfoObject, getJaffiliateCallSignField));
JniUtfString affiliateCallSign(env, jaffiliateCallSign);
if (jaffiliateCallSign != nullptr)
{
channelInfo.affiliateCallSign = Optional<CharSpan>(affiliateCallSign.charSpan());
}

jfieldID majorNumField = env->GetFieldID(channelClass, "majorNumber", "I");
jint jmajorNum = env->GetIntField(channelInfoObject, majorNumField);
channelInfo.majorNumber = static_cast<uint16_t>(jmajorNum);
jfieldID majorNumField = env->GetFieldID(channelClass, "majorNumber", "I");
jint jmajorNum = env->GetIntField(channelInfoObject, majorNumField);
channelInfo.majorNumber = static_cast<uint16_t>(jmajorNum);

jfieldID minorNumField = env->GetFieldID(channelClass, "minorNumber", "I");
jint jminorNum = env->GetIntField(channelInfoObject, minorNumField);
channelInfo.minorNumber = static_cast<uint16_t>(jminorNum);
jfieldID minorNumField = env->GetFieldID(channelClass, "minorNumber", "I");
jint jminorNum = env->GetIntField(channelInfoObject, minorNumField);
channelInfo.minorNumber = static_cast<uint16_t>(jminorNum);

err = aEncoder.Encode(channelInfo);
err = aEncoder.Encode(channelInfo);
}
else
{
err = aEncoder.EncodeNull();
return err;
}
}

exit:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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");
}

Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions scripts/examples/gn_android_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

set -e
set -ex

# Build script for GN examples GitHub workflow.

Expand Down Expand Up @@ -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/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/"
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/"

0 comments on commit 1168344

Please sign in to comment.