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

Grpc method #39

Open
wants to merge 5 commits into
base: celadon/r/mr0/stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 18 additions & 0 deletions penguinpeak/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (C) 2018 The Android Open Source Project
# Copyright (C) 2021 Intel Corporation
#
# 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.
#
LOCAL_PATH := $(my-dir)
include $(call all-subdir-makefiles, $(LOCAL_PATH))
36 changes: 36 additions & 0 deletions penguinpeak/ClipboardAgent/Android.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Copyright (C) 2018 The Android Open Source Project
// Copyright (C) 2021 Intel Corporation.
//
// 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.
//

// This makefile shows how to build a shared library and an activity that
// bundles the shared library and calls it using JNI.

android_app {
name: "ClipboardAgent",
srcs: ["**/*.java"],
// JNI library built from C++ source code
jni_libs: ["libVsockMsgDispatch", "libVsocketClientImpl"],
optimize: {
enabled: false,
},
sdk_version: "system_current",
dex_preopt: {
enabled: false,
},
privileged: true,
// To match the signature
certificate: "platform",
}
45 changes: 45 additions & 0 deletions penguinpeak/ClipboardAgent/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.intel.clipboardagent"
android:sharedUserId="android.uid.system">

<!--uses-sdk android:minSdkVersion="17" android:targetSdkVersion="30"/-->
<!-- Need clipboard access, so get the SYSTEM_WINDOW permissioin -->
<uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW"/>
<!-- Need internet permission to create socket -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.MANAGE_NOTIFICATION_LISTENERS" />
<!-- TODO: update persistent and allowBackup to be true. -->
<application
android:name=".ClipboardAgent"
android:persistent="true"
android:allowBackup="false">
<activity
android:name=".MainActivity"
android:theme="@android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<service android:name=".NotificationListener"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
android:exported="true">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
<service
android:exported="false"
android:name=".GuestVsockCommService">
</service>
<service
android:exported="false"
android:name=".ClipboardService">
</service>
</application>

</manifest>
139 changes: 139 additions & 0 deletions penguinpeak/ClipboardAgent/jni/Android.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
//
// Copyright (C) 2008 The Android Open Source Project
//
// 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.
//

// This makefile supplies the rules for building a library of JNI code for
// use by our example of how to bundle a shared library with an APK.

cc_library_shared {
name: "libVsocketClientImpl",
// All of the source files that we will compile.
srcs: ["VsockClientImpl.cpp"],
// All of the shared libraries we link against.
// liblog is used to print trace log in C plus plus source code.
shared_libs: ["liblog"],
// No static libraries.
static_libs: [],
cflags: [
"-Wall",
"-Werror",
],
// We cannot use stl:"none" here to link libc++ dynamically because
// it caused "'iostream' file not found" build issue.
stl: "c++_static",
sdk_version: "current",
}

genrule {
name: "pgp-proto",
tool_files: [ ":TAF-proto-gen", ":TAF-templates", ":TAF-proto-gen-deps",],
srcs: [
"proto/appstatus-protogen.inp",
"proto/notification-protogen.inp",
],
out: [
"proto/appstatus-gen.proto",
"proto/notification-gen.proto",
],
cmd: "$(location) -I vendor/intel/external/apps/penguinpeak/ClipboardAgent/jni/ -o $(genDir) -i $(in) --proto",
}

genrule {
name: "pgp-headers",
tool_files: [ ":TAF-proto-gen", ":TAF-templates", ":TAF-proto-gen-deps",],
srcs: [
"proto/appstatus-protogen.inp",
"proto/notification-protogen.inp",
],
out: [
"proto/appstatus.h",
"proto/notification.h",
],
cmd: "$(location) -I vendor/intel/external/apps/penguinpeak/ClipboardAgent/jni/ -o $(genDir) -i $(in) --header",
}


genrule {
name: "pgp-gRPCGenStub_h",
tools: [
"aprotoc",
"protoc-gen-grpc-cpp-plugin",
],
cmd: "$(location aprotoc) -Iout/soong/.intermediates/vendor/intel/external/apps/penguinpeak/ClipboardAgent/jni/pgp-proto/gen -Ivendor/intel/external/apps/penguinpeak/ClipboardAgent/jni -Iexternal/protobuf/src --plugin=protoc-gen-grpc=$(location protoc-gen-grpc-cpp-plugin) $(in) --grpc_out=$(genDir) --cpp_out=$(genDir)",
srcs: [ ":pgp-proto",
"proto/appstatus.proto",
"proto/notification.proto",
],
out: [
"proto/appstatus.pb.h",
"proto/appstatus-gen.pb.h",
"proto/appstatus-gen.grpc.pb.h",
"proto/notification.pb.h",
"proto/notification-gen.pb.h",
"proto/notification-gen.grpc.pb.h",
],
}

genrule {
name: "pgp-gRPCGenStub_cc",
tools: [
"aprotoc",
"protoc-gen-grpc-cpp-plugin",
],
cmd: "$(location aprotoc) -Iout/soong/.intermediates/vendor/intel/external/apps/penguinpeak/ClipboardAgent/jni/pgp-proto/gen -Ivendor/intel/external/apps/penguinpeak/ClipboardAgent/jni -Iexternal/protobuf/src --plugin=protoc-gen-grpc=$(location protoc-gen-grpc-cpp-plugin) $(in) --grpc_out=$(genDir) --cpp_out=$(genDir)",
srcs: [
":pgp-proto",
"proto/appstatus.proto",
"proto/notification.proto",
],
out: [
"proto/appstatus.pb.cc",
"proto/appstatus-gen.pb.cc",
"proto/appstatus-gen.grpc.pb.cc",
"proto/notification.pb.cc",
"proto/notification-gen.pb.cc",
"proto/notification-gen.grpc.pb.cc",
],
}

cc_library_shared {
name: "libVsockMsgDispatch",
defaults: ["TAF-defaults",],
srcs: [
"DispatchHelper.cpp",
"adapter.cpp",
],
cflags: [
"-Wall",
"-Werror",
"-Wno-unused-parameter",
"-Wno-unused-label",
],
generated_headers: [ "pgp-headers", "pgp-gRPCGenStub_h", ],
generated_sources: [ "pgp-gRPCGenStub_cc", ],
sdk_version: "current",
}

cc_binary {
name: "cfc_host_agent",
host_supported: true,
defaults: ["TAF-defaults",],
srcs: [
"appstatus.cpp",
"notification.cpp",
],
generated_headers: [ "pgp-headers", "pgp-gRPCGenStub_h", ],
generated_sources: [ "pgp-gRPCGenStub_cc", ],
}
44 changes: 44 additions & 0 deletions penguinpeak/ClipboardAgent/jni/DispatchHelper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "DispatchHelper.h"
#include <string.h>
#include <jni.h>
#include "adapter.h"

#undef LOG_TAG
#define LOG_TAG "DispatchHelper"

JNIEXPORT void JNICALL Java_com_intel_clipboardagent_DispatchHelper_registerComponent(JNIEnv *env, jobject thisObject, jstring className) {
env->GetJavaVM(&gVm);
std::string name = env->GetStringUTFChars(className, 0);
LOG_INFO("Attempting to register Service %s\n", name.c_str());
ServiceAdapter* adapter = AdapterFactory::GetAdapter(name);
if (adapter != nullptr) {
adapter->Register();
} else {
LOG_ERROR("Service adapter not found for %s\n", name.c_str());
}
}

JNIEXPORT void JNICALL Java_com_intel_clipboardagent_DispatchHelper_sendMsg(JNIEnv *env, jobject thisObject, jstring className, jobject msg, jlong handle) {
JavaObjectHelper jobjHelper(msg);
std::string name = env->GetStringUTFChars(className, 0);
ServiceAdapter* adapter = AdapterFactory::GetAdapter(name);
if (adapter == nullptr) {
LOG_ERROR("Service adapter not found for %s\n", name.c_str());
return;
}
adapter->SendResponse(&jobjHelper);
}

JNIEXPORT void JNICALL Java_com_intel_clipboardagent_DispatchHelper_start(JNIEnv *env, jobject thisObject) {
if (!g_server_->Start()) {
LOG_ERROR("FATAL! Failed to start server");
}
}

JNIEXPORT void JNICALL Java_com_intel_clipboardagent_DispatchHelper_stop(JNIEnv *env, jobject thisObject) {
g_server_->Stop();
delete g_server_;
g_server_ = nullptr;
AdapterFactory::RemoveAll();
}

45 changes: 45 additions & 0 deletions penguinpeak/ClipboardAgent/jni/DispatchHelper.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading