Android贯穿java层与c++层的值传递(JNI函数返回值)
返回值类型的写法和位置不太一样,模仿文件中其他位置的写法即可,如:
frameworks/base/services/core/java/com/android/server/pm/Installer.java
/**@hide*/
public boolean createDirectory(String path) {
try {
return mInstalld.createDirectory(path); //IBinder binder = ServiceManager.getService("installd");mInstalld = IInstalld.Stub.asInterface(binder);
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
------------------------------------------------------------------------------------------
frameworks/native/cmds/installd/InstalldNativeService.h
binder::Status createDirectory(const std::string& path, bool* _aidl_return);
...
}
--------------------------------------------------------------------------------------------
frameworks/native/cmds/installd/InstalldNativeService.cp
binder::Status InstalldNativeService::createDirectory(const std::string& dirPath, bool* _aidl_return) {
LOG(DEBUG) << "installd handling createDirectory, path: " << dirPath.c_str();
...
*_aidl_return = false;
return ok();
}
甚至可以通过在函数参数中生命参数的“in”、“out”类型来控制参数的址or值传递,更灵活的实现业务逻辑
本文来自博客园,作者:小汀,转载请注明原文链接:https://www.cnblogs.com/1118zjg/p/16953155.html