Skip to content

Commit

Permalink
Fix empty channel ( fix build error ) (#17626)
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

* fix build_example.py error

* fix build_example.py error

* fix build_example.py error
  • Loading branch information
xylophone21 authored and pull[bot] committed Jan 3, 2024
1 parent 42f2475 commit 79c156e
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 55 deletions.
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

0 comments on commit 79c156e

Please sign in to comment.