When I call fsetxattr on InternalStorage file, it works
but on AdoptableStorage file (my be externalStorage? connect by usb), get errno 95
Here art my code
java side
// File testFile = new File("/data/data/Android/data/com.xxx.xxx/files/test_attr.txt");
File testFile = new File("/storage/80E9-8A2E/Android/data/com.xxx.xxx/files/test_attr.txt");
testFile.createNewFile();
FileInputStream fis = new FileInputStream(testFile);
FileDescriptor fd = fis.getFD();
Field descriptor = ReflectionUtils.getDeclaredField(FileDescriptor.class, "descriptor");
descriptor.setAccessible(true);
int descriptorInt = (int) descriptor.get(fd);
Logger.info("testattr fd " + descriptorInt);
String setAttrRet = testSetAttr(descriptorInt);
Logger.info("testattr setAttrRet " + setAttrRet);
String getAttrRet = testGetAttr(descriptorInt);
Logger.info("testattr getAttrRet " + getAttrRet);
cpp side
jstring testSetAttr(JNIEnv *env, jclass clazz, jint fd) {
int ret = fsetxattr(fd, "user.test", "testjni", 8, XATTR_CREATE);
std::string str = std::to_string(ret);
LOGI("testSetAttr ret=%d", errno);
return env->NewStringUTF(str.c_str());
}
jstring testGetAttr(JNIEnv *env, jclass clazz, jint fd) {
char buf[1024];
int ret = fgetxattr(fd, "user.test", buf, 1024);
std::string str = std::string(buf, ret);
return env->NewStringUTF(str.c_str());
}