-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I9a25ad24cc17f31318ebfc7f0826dcfb31aee61f
- Loading branch information
1 parent
ffdbaa1
commit bfa2c0c
Showing
6 changed files
with
55 additions
and
1 deletion.
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
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,15 @@ | ||
cmake_minimum_required(VERSION 3.22.1) | ||
|
||
project("nativelib") | ||
|
||
add_library(${CMAKE_PROJECT_NAME} SHARED | ||
nativelib.cpp | ||
) | ||
|
||
target_link_libraries(${CMAKE_PROJECT_NAME} | ||
android | ||
log | ||
) | ||
|
||
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -O3 -ffunction-sections -fdata-sections -ffile-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=/src) | ||
target_link_libraries(${CMAKE_PROJECT_NAME} -s -flto -Wl,--gc-sections -Wl,--build-id=none -Wl,--hash-style=both) |
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,20 @@ | ||
#include <jni.h> | ||
#include <string> | ||
#include <ftw.h> | ||
|
||
namespace NativeNS { | ||
thread_local size_t total_size{0}; | ||
|
||
int on_walking(const char *path, const struct stat *p_stat, int flag) { | ||
total_size += p_stat->st_size; | ||
return 0; | ||
} | ||
} | ||
|
||
extern "C" JNIEXPORT jlong JNICALL | ||
Java_com_xayah_core_rootservice_util_NativeLib_calculateSize(JNIEnv *env, jobject, jstring path) { | ||
NativeNS::total_size = 0; | ||
const char *p_path = env->GetStringUTFChars(path, JNI_FALSE); | ||
ftw(p_path, &NativeNS::on_walking, 1024); | ||
return NativeNS::total_size; | ||
} |
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
5 changes: 5 additions & 0 deletions
5
source/core/rootservice/src/main/kotlin/com/xayah/core/rootservice/util/NativeLib.kt
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,5 @@ | ||
package com.xayah.core.rootservice.util | ||
|
||
object NativeLib { | ||
external fun calculateSize(path: String): Long | ||
} |