public String getExportedContentProvider() { StringBuilder sb = new StringBuilder(); if (mPInfo.providers != null) { for (ProviderInfo pi : mPInfo.providers) { String piName = pi.name; if (pi.exported) { //Grant Uri Permissions piName = piName + " GRANT: " + String.valueOf(pi.grantUriPermissions) + "|"; if (pi.authority != null) { piName = piName + " AUTHORITY: " + pi.authority + "|"; } if (pi.readPermission != null) { piName = piName + " READ: " + pi.readPermission + "|"; } if (pi.writePermission != null) { piName = piName + " WRITE: " + pi.writePermission + "|"; } PathPermission[] pp = pi.pathPermissions; if (pp != null) { for (PathPermission pathPermission : pp) { piName = piName + " PATH: " + pathPermission.getPath() + "|"; piName = piName + " - READ: " + pathPermission.getReadPermission() + "|"; piName = piName + " - WRITE: " + pathPermission.getWritePermission() + "|"; } } sb.append(piName + "\n"); } } } else { sb.append(" -- null"); } return sb.toString(); }
public String getNonExportedContentProvider() { StringBuilder sb = new StringBuilder(); if (mPInfo.providers != null) { for (ProviderInfo pi : mPInfo.providers) { String piName = pi.name; if (!pi.exported) { //Grant Uri Permissions piName = piName + " GRANT: " + String.valueOf(pi.grantUriPermissions) + "|"; if (pi.authority != null) { piName = piName + " AUTHORITY: " + pi.authority + "|"; } if (pi.readPermission != null) { piName = piName + " READ: " + pi.readPermission + "|"; } if (pi.writePermission != null) { piName = piName + " WRITE: " + pi.writePermission + "|"; } PathPermission[] pp = pi.pathPermissions; if (pp != null) { for (PathPermission pathPermission : pp) { piName = piName + " PATH: " + pathPermission.getPath() + "|"; piName = piName + " - READ: " + pathPermission.getReadPermission() + "|"; piName = piName + " - WRITE: " + pathPermission.getWritePermission() + "|"; } } sb.append(piName + "\n"); } } } else { sb.append(" -- null"); } return sb.toString(); }
private Uri unwrapUriAndCheckPermissions(Uri wrappedUri, PermissionEnforcement enforcement) { // Unwrap final Matcher matcher = PATH_PATTERN.matcher(wrappedUri.getPath()); if (!matcher.find()) { throw new IllegalArgumentException("Unable to match uri"); } final String authority = matcher.group(1); final String path = matcher.group(2); Uri unwrappedUri = Uri.parse("content://" + authority + path); // Check permissions final boolean isUnprotected = shouldSkipPermissionChecks() || enforcement == PermissionEnforcement.UNPROTECTED; if (!isUnprotected) { final boolean enforceWrite = enforcement == PermissionEnforcement.ENFORCE_WRITE; // Get provider info final ProviderInfo providerInfo = getContext().getPackageManager().resolveContentProvider(unwrappedUri.getAuthority(), PackageManager.GET_META_DATA); if (providerInfo == null) { throw new SecurityException("Unknown wrapped provider"); } // Check "intentslab.disallowproxy" meta-data if (providerInfo.metaData != null && providerInfo.metaData.getBoolean("intentslab.disallowproxy")) { throw new SecurityException("Not allowed to proxy to " + authority + " (disallowed by <meta-data>)"); } // Check also normal permissions boolean hasNormalPermissionGranted; if (!providerInfo.exported) { // Provider not exported, never grant normal permission hasNormalPermissionGranted = false; } else { // Get default provider-global permission String permission = enforceWrite ? providerInfo.writePermission : providerInfo.readPermission; // Find path permission if there are such permissions defined // and there's no provider-global permission set for that, which takes precedence if (providerInfo.pathPermissions != null && permission == null) { for (PathPermission pathPermission : providerInfo.pathPermissions) { if (pathPermission.match(unwrappedUri.getPath())) { permission = enforceWrite ? pathPermission.getWritePermission() : pathPermission.getReadPermission(); break; } } } // Check that permission if (permission == null) { hasNormalPermissionGranted = true; } else { hasNormalPermissionGranted = getContext().checkCallingPermission(permission) == PackageManager.PERMISSION_GRANTED; } } // Check if caller has granted runtime permission final int modeFlags = enforceWrite ? Intent.FLAG_GRANT_WRITE_URI_PERMISSION : Intent.FLAG_GRANT_READ_URI_PERMISSION; final boolean hasRuntimePermissionGranted = getContext().checkCallingUriPermission(unwrappedUri, modeFlags) != PackageManager.PERMISSION_GRANTED; // Throw if permission isn't granted if (!hasNormalPermissionGranted && !hasRuntimePermissionGranted) { throw new SecurityException("Wrapped permission check"); } } return unwrappedUri; }