Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
253 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ build | |
build-cache | ||
build-cache.lock | ||
/dump.txt | ||
dump.txt | ||
dump.txt | ||
.cxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
Samples/PluginHelloWorld/src/main/java/com/example/pluginhelloworld/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# For more information about using CMake with Android Studio, read the | ||
# documentation: https://d.android.com/studio/projects/add-native-code.html | ||
|
||
# Sets the minimum version of CMake required to build the native library. | ||
|
||
cmake_minimum_required(VERSION 3.4.1) | ||
|
||
# Creates and names a library, sets it as either STATIC | ||
# or SHARED, and provides the relative paths to its source code. | ||
# You can define multiple libraries, and CMake builds them for you. | ||
# Gradle automatically packages shared libraries with your APK. | ||
|
||
add_library( # Sets the name of the library. | ||
cxxTest | ||
|
||
# Sets the library as a shared library. | ||
SHARED | ||
|
||
# Provides a relative path to your source file(s). | ||
id.h | ||
id.c | ||
CxxTest.cpp ) | ||
|
||
# Searches for a specified prebuilt library and stores the path as a | ||
# variable. Because CMake includes system libraries in the search path by | ||
# default, you only need to specify the name of the public NDK library | ||
# you want to add. CMake verifies that the library exists before | ||
# completing its build. | ||
|
||
find_library( # Sets the name of the path variable. | ||
log-lib | ||
|
||
# Specifies the name of the NDK library that | ||
# you want CMake to locate. | ||
log | ||
libcrypto | ||
libcutils | ||
libselinux) | ||
|
||
# Specifies libraries CMake should link to your target library. You | ||
# can link multiple libraries, such as libraries you define in this | ||
# build script, prebuilt third-party libraries, or system libraries. | ||
|
||
target_link_libraries( # Specifies the target library. | ||
cxxTest | ||
|
||
# Links the target library to the log library | ||
# included in the NDK. | ||
${log-lib} ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <jni.h> | ||
#include <string> | ||
|
||
//在C++代码中调用C的库文件,需加上extern "C",用来告诉编译器:这是一个用C写的库文件,请用C的方式链接它们 | ||
extern "C" { | ||
#include "id.h" | ||
} | ||
|
||
extern "C" JNIEXPORT jstring JNICALL | ||
Java_com_example_pluginmain_CxxTest_stringFromJNI( | ||
JNIEnv* env, | ||
jobject /* this */) { | ||
|
||
whoami(); | ||
|
||
std::string hello = "Hello from C++"; | ||
return env->NewStringUTF(hello.c_str()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <sys/types.h> | ||
#include <pwd.h> | ||
#include <grp.h> | ||
#include <android/log.h> | ||
//#include <selinux/selinux.h> | ||
|
||
#include "id.h" | ||
|
||
#define LOG_TAG "whoami" | ||
|
||
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE,LOG_TAG,__VA_ARGS__) | ||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) | ||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) | ||
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__) | ||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) | ||
|
||
static void print_uid(uid_t uid) | ||
{ | ||
struct passwd *pw = getpwuid(uid); | ||
|
||
if(pw) { | ||
LOGV("%d(%s)", uid, pw->pw_name); | ||
} else { | ||
LOGV("%d", uid); | ||
} | ||
} | ||
|
||
static void print_gid(gid_t gid) | ||
{ | ||
struct group *gr = getgrgid(gid); | ||
|
||
if(gr) { | ||
LOGV("%d(%s)", gid, gr->gr_name); | ||
} else { | ||
LOGV("%d", gid); | ||
} | ||
} | ||
|
||
int whoami() | ||
{ | ||
gid_t list[64]; | ||
int n, max; | ||
|
||
max = getgroups(64, list); | ||
if (max < 0) max = 0; | ||
|
||
LOGV("uid="); | ||
print_uid(getuid()); | ||
LOGV(" gid="); | ||
print_gid(getgid()); | ||
if (max) { | ||
LOGV(" groups="); | ||
print_gid(list[0]); | ||
for(n = 1; n < max; n++) { | ||
print_gid(list[n]); | ||
} | ||
} | ||
LOGV("\n"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef APF_ID_H | ||
#define APF_ID_H | ||
|
||
|
||
int whoami(); | ||
|
||
|
||
#endif //APF_ID_H |
11 changes: 11 additions & 0 deletions
11
Samples/PluginMain/src/main/java/com/example/pluginmain/CxxTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.pluginmain; | ||
|
||
public class CxxTest { | ||
|
||
public static native String stringFromJNI(); | ||
|
||
static { | ||
System.loadLibrary("cxxTest"); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
Samples/PluginMain/src/main/java/com/example/pluginmain/Debug.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 4 additions & 5 deletions
9
Samples/PluginMain/src/main/java/com/example/pluginmain/TestFragmentActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Samples/PluginMain/src/main/java/com/example/pluginmain/TestViewActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
Samples/PluginMain/src/main/java/com/example/pluginmain/WebActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Samples/PluginShareLib/src/main/java/com/example/pluginsharelib/BaseActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.