Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Tvserver to examples #11780

Merged
merged 6 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
move share lib and tv-common(zzz_generated/tv-app/zap-generated) link…
… to example, so that we cloud have different android tv apps for different clusters
  • Loading branch information
xylophone21 committed Nov 17, 2021
commit 971c995b8d9823a6900f29fde25b3e021ea8c246
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {

if (current_os == "android") {
deps += [
"${chip_root}/examples/tv-app/android:java",
"${chip_root}/src/app/server/java",
"${chip_root}/src/controller/java",
"${chip_root}/src/platform/android:java",
Expand Down
42 changes: 40 additions & 2 deletions examples/tv-app/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

import("${build_root}/config/android_abi.gni")
import("${chip_root}/build/chip/java/rules.gni")
import("${chip_root}/build/chip/tools.gni")

# Todo: copy from examples/tv-app/linux but later will be moved to jni and upto java workd
source_set("android-tv-app") {
# Todo: copy from examples/tv-app/linux but later will be moved to jni and upto java word
shared_library("jni") {

output_name = "libTvApp"

sources = [
"${chip_root}/examples/tv-app/tv-common/include/CHIPProjectAppConfig.h",
"include/account-login/AccountLoginManager.cpp",
Expand Down Expand Up @@ -49,13 +54,46 @@ source_set("android-tv-app") {
"include/tv-channel/TvChannelManager.h",
"include/wake-on-lan/WakeOnLanManager.cpp",
"include/wake-on-lan/WakeOnLanManager.h",
"java/TVApp-JNI.cpp",
]

deps = [
"${chip_root}/examples/tv-app/tv-common",
"${chip_root}/src/lib",
"${chip_root}/third_party/inipp",
"${chip_root}/src/app/server/java:jni",
]

cflags = [ "-Wconversion" ]

output_dir = "${root_out_dir}/lib/jni/${android_abi}"

ldflags = [ "-Wl,--gc-sections" ]
}

android_library("java") {
output_name = "TvApp.jar"

deps = [
":android",
"${chip_root}/third_party/android_deps:annotation",
]

data_deps = [
":jni",
"${chip_root}/build/chip/java:shared_cpplib",
]

sources = [
"java/src/com/tcl/tvapp/TvApp.java",
]

javac_flags = [ "-Xlint:deprecation" ]

# TODO: add classpath support (we likely need to add something like
# ..../platforms/android-21/android.jar to access BLE items)
}

java_prebuilt("android") {
jar_path = "${android_sdk_root}/platforms/android-21/android.jar"
}
35 changes: 35 additions & 0 deletions examples/tv-app/android/java/TVApp-JNI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2021 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

/**
* @file
* Implementation of JNI bridge for Tv App on Android.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this @file comment does not seem to help me understand code more: it is obvious that a file named TVApp-JNI.cpp contains an implementation of JNI for a TV APP

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will remove it in next PR

*
*/
#include <jni.h>
#include <lib/core/CHIPError.h>
#include <lib/support/CHIPJNIError.h>
#include <app/server/java/AndroidAppServerWrapper.h>

jint JNI_OnLoad(JavaVM * jvm, void * reserved) {
return AndroidAppServerJNI_OnLoad(jvm, reserved);
}

void JNI_OnUnload(JavaVM * jvm, void * reserved) {
return AndroidAppServerJNI_OnUnload(jvm, reserved);
}
27 changes: 27 additions & 0 deletions examples/tv-app/android/java/src/com/tcl/tvapp/TvApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2021 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package src.com.tcl.tvapp;

public class TvApp {
public TvApp() {
}

static {
System.loadLibrary("TvApp");
}
}
6 changes: 5 additions & 1 deletion scripts/build/builders/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def _build(self):
#
# If we unify the JNI libraries, libc++_shared.so may not be needed anymore, which could
# be another path of resolving this inconsistency.
for libName in ['libSetupPayloadParser.so', 'libCHIPController.so', 'libc++_shared.so', 'libCHIPAppServer.so']:
for libName in ['libSetupPayloadParser.so', 'libCHIPController.so', 'libc++_shared.so', 'libTvApp.so']:
self._Execute(['cp', os.path.join(self.output_dir, 'lib', 'jni', self.board.AbiName(
), libName), os.path.join(jnilibs_dir, libName)])

Expand All @@ -233,6 +233,7 @@ def _build(self):
'SetupPayloadParser.jar': 'src/setup_payload/java/SetupPayloadParser.jar',
'AndroidPlatform.jar': 'src/platform/android/AndroidPlatform.jar',
'CHIPAppServer.jar': 'src/app/server/java/CHIPAppServer.jar',
'TvApp.jar': 'examples/tv-app/android/TvApp.jar',
}

for jarName in jars.keys():
Expand Down Expand Up @@ -266,6 +267,9 @@ def build_outputs(self):
'SetupPayloadParser.jar':
os.path.join(self.output_dir, 'lib',
'src/setup_payload/java/SetupPayloadParser.jar'),
'CHIPAppServer.jar':
os.path.join(self.output_dir, 'lib',
'src/app/server/java/CHIPAppServer.jar'),

'jni/%s/libSetupPayloadParser.so' % self.board.AbiName():
os.path.join(self.output_dir, 'lib', 'jni',
Expand Down
8 changes: 8 additions & 0 deletions src/android/CHIPTVServer/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ android {
sourceSets {
main {
jniLibs.srcDirs = ['libs/jniLibs']

java.srcDirs = [
'../../../setup_payload/java/src',
'../../../controller/java/zap-generated',
'../../../controller/java/src',
'../../../platform/android/java',
'../../../../examples/tv-app/android/java',
]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/

#include "AppMain.h"
#include "AndroidAppServerWrapper.h"
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <credentials/DeviceAttestationCredsProvider.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
*/

#pragma once
#include <jni.h>
#include <lib/core/CHIPError.h>

CHIP_ERROR ChipAndroidAppInit(void);

jint AndroidAppServerJNI_OnLoad(JavaVM * jvm, void * reserved);

void AndroidAppServerJNI_OnUnload(JavaVM * jvm, void * reserved);
12 changes: 3 additions & 9 deletions src/app/server/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ import("${chip_root}/build/chip/java/rules.gni")
import("${chip_root}/src/app/common_flags.gni")
import("${chip_root}/src/lib/lib.gni")

shared_library("jni") {
static_library("jni") {
output_name = "libCHIPAppServer"

sources = [
"AppMain.cpp",
"AppMain.h",
"AndroidAppServerWrapper.cpp",
"AndroidAppServerWrapper.h",
"CHIPAppServer-JNI.cpp",
]

deps = [
"${chip_root}/examples/tv-app/android:android-tv-app",
"${chip_root}/examples/tv-app/tv-common",
"${chip_root}/src/app/server",
"${chip_root}/src/inet",
"${chip_root}/src/lib",
Expand All @@ -41,10 +39,6 @@ shared_library("jni") {
]

public_configs = [ "${chip_root}/src:includes" ]

output_dir = "${root_out_dir}/lib/jni/${android_abi}"

ldflags = [ "-Wl,--gc-sections" ]
}

android_library("java") {
Expand Down
6 changes: 3 additions & 3 deletions src/app/server/java/CHIPAppServer-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Implementation of JNI bridge for CHIP App Server for Android TV apps
*
*/
#include "AppMain.h"
#include "AndroidAppServerWrapper.h"
#include <jni.h>
#include <lib/core/CHIPError.h>
#include <lib/support/CHIPJNIError.h>
Expand Down Expand Up @@ -53,7 +53,7 @@ pthread_t sIOThread = PTHREAD_NULL;
jclass sChipAppServerExceptionCls = NULL;
} // namespace

jint JNI_OnLoad(JavaVM * jvm, void * reserved)
jint AndroidAppServerJNI_OnLoad(JavaVM * jvm, void * reserved)
{
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env;
Expand Down Expand Up @@ -91,7 +91,7 @@ jint JNI_OnLoad(JavaVM * jvm, void * reserved)
return (err == CHIP_NO_ERROR) ? JNI_VERSION_1_6 : JNI_ERR;
}

void JNI_OnUnload(JavaVM * jvm, void * reserved)
void AndroidAppServerJNI_OnUnload(JavaVM * jvm, void * reserved)
{
chip::DeviceLayer::StackLock lock;
ChipLogProgress(AppServer, "JNI_OnUnload() called");
Expand Down
4 changes: 0 additions & 4 deletions src/app/server/java/src/chip/appserver/ChipAppServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,5 @@
public class ChipAppServer {
private static final String TAG = ChipAppServer.class.getSimpleName();

static {
System.loadLibrary("CHIPAppServer");
}

public native boolean startApp();
}