List of usage examples for android.os ParcelFileDescriptor MODE_WRITE_ONLY
int MODE_WRITE_ONLY
To view the source code for android.os ParcelFileDescriptor MODE_WRITE_ONLY.
Click Source Link
From source file:net.sf.fakenames.fddemo.PermissionActivity.java
private String accessPattern(String access) { final int accessMode = ParcelFileDescriptor.parseMode(access); if ((accessMode & ParcelFileDescriptor.MODE_READ_ONLY) == accessMode) { return "read"; }//from w w w. j a va 2s . com if ((accessMode & ParcelFileDescriptor.MODE_WRITE_ONLY) == accessMode) { return "write"; } return "full"; }
From source file:net.sf.xfd.provider.PublicProvider.java
@Override public Uri canonicalize(@NonNull Uri uri) { try {/* ww w . ja v a2s . com*/ base.assertAbsolute(uri); String grantMode = uri.getQueryParameter(URI_ARG_MODE); if (TextUtils.isEmpty(grantMode)) { grantMode = "r"; } verifyMac(uri, grantMode, grantMode); final int flags = ParcelFileDescriptor.parseMode(grantMode); final Context context = getContext(); assert context != null; final String packageName = context.getPackageName(); final Uri canon = DocumentsContract.buildDocumentUri(packageName + FileProvider.AUTHORITY_SUFFIX, canonString(uri.getPath())); final int callerUid = Binder.getCallingUid(); if (callerUid != Process.myUid()) { int grantFlags = Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION; if ((flags & ParcelFileDescriptor.MODE_READ_ONLY) == flags) { grantFlags |= Intent.FLAG_GRANT_READ_URI_PERMISSION; } else if ((flags & ParcelFileDescriptor.MODE_WRITE_ONLY) == flags) grantFlags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION; else { grantFlags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION; grantFlags |= Intent.FLAG_GRANT_READ_URI_PERMISSION; } final String[] packages; final String caller = getCallingPackage(); if (caller != null) { packages = new String[] { caller }; } else { final PackageManager pm = context.getPackageManager(); packages = pm.getPackagesForUid(callerUid); } if (packages != null) { for (String pkg : packages) { context.grantUriPermission(pkg, canon, grantFlags); } } } return canon; } catch (FileNotFoundException e) { return null; } }
From source file:com.hippo.content.FileProvider.java
/** * Copied from ContentResolver.java/*w ww .j a va2 s . com*/ */ private static int modeToMode(String mode) { int modeBits; if ("r".equals(mode)) { modeBits = ParcelFileDescriptor.MODE_READ_ONLY; } else if ("w".equals(mode) || "wt".equals(mode)) { modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY | ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_TRUNCATE; } else if ("wa".equals(mode)) { modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY | ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_APPEND; } else if ("rw".equals(mode)) { modeBits = ParcelFileDescriptor.MODE_READ_WRITE | ParcelFileDescriptor.MODE_CREATE; } else if ("rwt".equals(mode)) { modeBits = ParcelFileDescriptor.MODE_READ_WRITE | ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_TRUNCATE; } else { throw new IllegalArgumentException("Invalid mode: " + mode); } return modeBits; }