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

オープン
#1,410 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
android, java
領域
mobile

調査の方向性

Start by tracing how Shadow routes plugin ContentProvider URIs through PluginContainerContentProvider and how the plugin’s declared authority is incorporated. Compare that flow with the issue’s UriMatcher example and the demo behavior described in the report. Done means establishing whether the authority prefix is intended and fixing the mismatch so plugin providers and their URI matching behave consistently.

索引モデルが issue の本文から書いたものです。

説明

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 如果也有类似情况的话,也会有问题?

主要言語
Java
スター
7.8k
フォーク
1.3k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Tencent/Shadow のほかの issue

Tencent/Shadow の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。