Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PermissionUtils: import java.nio.file unknown to Android Java #21

Open
syslogic opened this issue Nov 2, 2015 · 6 comments
Open

PermissionUtils: import java.nio.file unknown to Android Java #21

syslogic opened this issue Nov 2, 2015 · 6 comments

Comments

@syslogic
Copy link

syslogic commented Nov 2, 2015

Can only tell that this is the reason why it can't work; for reference: http://developer.android.com/reference/java/nio/package-summary.html
On Android 6.0 the permissions are meanwhile obtained at runtime / per application, while the effective permissions depend on the mode in which the output stream was opened. that /storage/emulated/0/ is an abstraction layer which may cause octal permissions to be irrelevant - it's probably it's rather about the SE Linux context, which applications can obtain in order to read/write. https://developer.android.com/reference/android/support/v4/content/PermissionChecker.html

@rodrigoGA
Copy link

+1

@ointeractive-depot
Copy link

ointeractive-depot commented Sep 21, 2017

Have this problem too, which is started from KitKat (!). Author is inactive since May 2017. Seems I should fork it and add this libraries :/ So sorry Kamran, there's no choise(

@syslogic
Copy link
Author

syslogic commented Sep 23, 2017

for example:

@Before
public void setup() throws IOException {
    dir = Files.createTempDirectory("tartest").toFile();
    dir.mkdirs();
}

should be something alike:

@Before
public void setup() throws IOException {
	
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            dir = java.nio.file.Files.createTempDirectory("tartest").toFile();
        } else {
            /* obtain a temporary directory for API < 26 */
            this.mContext = InstrumentationRegistry.getTargetContext();
            dir = this.mContext.getCacheDir();
        }
}

One just would needs the permission to read/write and needs to handle temporary files differently and file system permissions - on Android < API level 26. have imported the library to Android Studio and this is what it basically tells me. Building it for nothing but >= API level 26 should be no problem at all.

@ointeractive-depot
Copy link

ointeractive-depot commented Sep 23, 2017

No-no-no, that's wrong. PermissionUtils.java file regulates a POSIX permissions, not Android read/write permissions, because this jTar library was written for native Java, so there's no ANY Android compatible code, please don't confuse it. Android supported POSIX since API 26 (not before), but not fully, there's such a stubs in many its methods, so there's no need to narrow supported Android versions for API 26 and higher, so I've cut the POSIX support from the code, now it's working like a sharm at all API versions, but I won't make the pull request in this project, because now it's separated project specially for Android. Have you interesting in it?

@syslogic
Copy link
Author

well, I can write to /data/user/0/org.kamranzafar.jtar.test/cache ... by Context.getCacheDir().

@ointeractive-depot
Copy link

It's because you've using Android API, not because jTar supports Android. It's simple native Java code which is using some native Java wrappers, not Android, you can simply use it with your Android code, and as it's a native Java code, you can work with it via Android in your project, but can't work with Android directly from its code. But there's no need for you because you have an Android project where you can simply include this library and use it in your project without touching its code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants