Skip to content

Commit

Permalink
Revert "Fix empty channel (#17489)" (#17607)
Browse files Browse the repository at this point in the history
This reverts commit 18338b9.

Commit broke android compilation using build_examples.py:

```
./scripts/build/build_examples.py --target android-arm-chip-tvserver
```
  • Loading branch information
andy31415 authored and pull[bot] committed Dec 5, 2023
1 parent 8795e3d commit 2407120
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 92 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 = ['../platform-app/libs/jniLibs']
jniLibs.srcDirs = ['../app/libs/jniLibs']

// uncomment this code to debug
// java.srcDirs = [
Expand All @@ -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'
Expand Down
125 changes: 55 additions & 70 deletions examples/tv-app/android/java/ChannelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<jstring>(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<jstring>(env->GetObjectField(channelLineupObject, lineupNameFild));
JniUtfString lineupName(env, jlineupName);
if (jlineupName != nullptr)
{
lineupInfo.lineupName = Optional<CharSpan>(lineupName.charSpan());
}
jclass channelLineupClazz = env->GetObjectClass(channelLineupObject);

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 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();
}

err = aEncoder.Encode(lineupInfo);
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());
}
else

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)
{
err = aEncoder.EncodeNull();
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);

err = aEncoder.Encode(lineupInfo);
}

exit:
Expand All @@ -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<jstring>(env->GetObjectField(channelInfoObject, getCallSignField));
JniUtfString callsign(env, jcallSign);
if (jcallSign != nullptr)
{
channelInfo.callSign = Optional<CharSpan>(callsign.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 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 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 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);
}
else
{
err = aEncoder.EncodeNull();
return err;
}
err = aEncoder.Encode(channelInfo);
}

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

Expand All @@ -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;
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 -ex
set -e

# 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/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/"

0 comments on commit 2407120

Please sign in to comment.