Reputation: 11
I want to call another binary executable file when I start my app. This app is on Magic Leap (Am Android Device with x86_64 CPU).
This bin file will generate a txt file with content "hello, world!". I can use ADB to run this binary file under /data/local/tmp
, which may prove that this file can run on Magic Leap.
But I can not cd to app private path, while the app cannot call file under /data/local/tmp
. And I cannot call the file in my app. I tried system()
and execvp()
and they both doesn't work. Kindly note that I want use pure C++ and NDK to realize this.
void checkFilePermissions(const char* filePath) {
if (access(filePath, X_OK) != -1) {
ALOGI( "File has execute permission: %s" , filePath);
} else {
ALOGI( "File does not have execute permission: %s" , filePath);
}
}
int executeBinary(const char *filePath) {
char *args[] = {strdup(filePath), nullptr};
if (execvp(args[0], args) == -1) {
ALOGI( "execvp failed: %s" , strerror(errno));
return -1;
}
return 0;
}
void OnStart() override {
const char *filePath = "/data/data/com.magicleap.capi.sample.eye_tracking/files/bin/hello";
checkFilePermissions(filePath);
int result = executeBinary(filePath);
if (result == -1) {
ALOGI("Failed to execute binary.");
} else {
ALOGI("Binary executed successfully with exit code: %d", result);
}
... // other code
}
File has execute permission: /data/data/com.magicleap.capi.sample.eye_tracking/files/bin/hello
execvp failed: Permission denied
Failed to execute binary.
Upvotes: 0
Views: 28