Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ class PluginContentProviderManager() : UriConverter.UriParseDelegate {
providerInfo.packageName = context.packageName
providerInfo.name = it.className
providerInfo.authority = it.authorities
providerInfo.grantUriPermissions = true //插件没有权限管理机制

providerInfo.grantUriPermissions = it.grantUriPermissions
contentProvider?.attachInfo(context, providerInfo)
providerMap[it.authorities] = contentProvider
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ sealed class AndroidManifestKeys {
const val service = "service"
const val provider = "provider"
const val receiver = "receiver"
const val grantUriPermissions = "android:grantUriPermissions"
}
}
typealias ComponentMapKey = String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class AndroidManifestReader {
val providerMap = parseComponent(element).toMutableMap()

providerMap.putAttributeIfNotNull(element, AndroidManifestKeys.authorities)
providerMap.putAttributeIfNotNull(element, AndroidManifestKeys.grantUriPermissions)

return providerMap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ private class PluginManifestBuilder(

private fun toNewProviderInfo(componentMap: ComponentMap): String {
val authoritiesValue = componentMap[AndroidManifestKeys.authorities]
//如果未传值使用android.content.pm.ProviderInfo.grantUriPermissions的默认值false
val grantUriPermissions = componentMap[AndroidManifestKeys.grantUriPermissions] ?: false

val authoritiesLiteral =
if (authoritiesValue != null) {
"\"${authoritiesValue}\""
Expand All @@ -249,7 +252,7 @@ private class PluginManifestBuilder(
}

return "new com.tencent.shadow.core.runtime.PluginManifest" +
".ProviderInfo(\"${componentMap[AndroidManifestKeys.name]}\", $authoritiesLiteral)"
".ProviderInfo(\"${componentMap[AndroidManifestKeys.name]}\", $authoritiesLiteral,$grantUriPermissions)"
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@ public ReceiverInfo(String className, String[] actions) {

final class ProviderInfo extends ComponentInfo {
public final String authorities;
public final boolean grantUriPermissions;

public ProviderInfo(String className, String authorities) {
public ProviderInfo(String className, String authorities, boolean grantUriPermissions) {
super(className);
this.authorities = authorities;
this.grantUriPermissions = grantUriPermissions;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@

<provider
android:name=".lib.usecases.provider.TestProvider"
android:grantUriPermissions="true"
android:authorities="${applicationId}.provider.test" />

<provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.content.pm.ProviderInfo;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
Expand All @@ -41,6 +43,15 @@ public boolean onCreate() {
return true;
}

@Override
public void attachInfo(Context context, ProviderInfo info) {
super.attachInfo(context, info);
//用于测试是否读取了Manifest中的grantUriPermissions值,在实际生产中这里并不需要抛出异常
if (!info.grantUriPermissions) {
throw new IllegalStateException("读取ProviderInfo.grantUriPermissions失败");
}
}


@Nullable
@Override
Expand Down