Skip to content

插件自定义Provider的Authority被自动添加上宿主PluginContainerContentProvider Authority  #1410

@mikelhm

Description

@mikelhm

2025-12-18 12:03:08.170 28888-28888 AndroidRuntime com.example.shadow E FATAL EXCEPTION: main
Process: com.example.shadow:plugin, PID: 28888
java.lang.IllegalArgumentException: Unknown URI: content://com.example.shadow.contentprovider.authority.dynamic/com.example.shadow.provider.CustomContentProvider/downloads

com.example.shadow.contentprovider.authority.dynamic是宿主定义的坑位Provider authority

<provider
            android:authorities="${applicationId}.contentprovider.authority.dynamic"
            android:name="com.tencent.shadow.core.runtime.container.PluginContainerContentProvider"
            android:grantUriPermissions="true"
            android:process=":plugin" />

com.example.shadow.provider.CustomContentProvider是插件的authority

<provider
            android:name="com.example.shadow.provider.CustomContentProvider"
            android:authorities="${applicationId}.provider.CustomContentProvider"
            android:enabled="true"
            android:exported="false"/>

貌似被拼接一起了

 崩溃发生在下面第一句:
     cursor = DownloadProvider.getInstance(context).query(DownloadConstants.Database.CONTENT_URI,
          null, selection, null, sortOrder);
      if (cursor != null) {
        while (cursor.moveToNext()) {
          try {
       
            InnerDownloadInfo info = readFromDatabase(cursor);
            downloadInfos.add(info);
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }

query的实现,uri 打印出来是:content://com.example.shadow.contentprovider.authority.dynamic/com.example.shadow.provider.CustomContentProvider/downloads
所以match == -1 崩溃

  public Cursor query(Uri uri, String[] projection, String where,
      String[] whereArgs, String sortOrder) {
    SQLiteDatabase db = databaseHelper.getReadableDatabase();
    int match = uriMatcher.match(uri);
    if (match == -1) {
      throw new IllegalArgumentException("Unknown URI: " + uri);
    }

CONTENT_URI的定义:

DownloadConstants.Database.CONTENT_URI=Uri.parse("content://" + AUTHORITY
        + "/" + DOWNLOAD_TABLE);

public static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".provider.CustomContentProvider";

直接看下面的测试:

我在shadow 的demo 打印了下日志进行测试,发现也是会自动添加com.tencent.shadow.sample.host.contentprovider.authority.dynamic,这个是符合预期的吗?

Image

如果符合预期,那么原本插件的逻辑用到Uri.parse的地方就可能发生上述不匹配的问题
插件原来的逻辑

uriMatcher.addURI(BuildConfig.APPLICATION_ID + ".provider.CustomContentProvider",
        "downloads", 1);
uriMather.match(uri)// 带有 com.tencent.shadow.sample.host.contentprovider.authority.dynamic 的uri 不匹配

而且如果插件APP本身依赖的三方SDK 如果也有类似情况的话,也会有问题?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions