前言

简单记录一下,在Android源码中的Intent.java定义自己的源码。记录一下,方便自己查阅。

流水账哈,只是方便自己而已。

\frameworks\base\core\api\current.txt
\frameworks\base\core\java\android\content\Intent.java

正文

Intent.java新增一个快速扫描完成广播,主要提供给Android扫描器(MediaProvider)使用。

新增Action

已知Android提供的如下通知Action

Intent.ACTION_MEDIA_SCANNER_STARTED
Intent.ACTION_MEDIA_SCANNER_FINISHED

不够用,因此,这里新增一个。

Intent.java

参考ACTION_MEDIA_SCANNER_FINISHED的定义,改为如下:

@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_MEDIA_FAST_SCAN_FINISHED = "android.intent.action.MEDIA_FAST_SCAN_FINISHED";
current.txt
field public static final String ACTION_MEDIA_FAST_SCAN_FINISHED = "android.intent.action.MEDIA_FAST_SCAN_FINISHED";
问题1: Inconsistent action value
frameworks/base/core/java/android/content/Intent.java:3545: error: Inconsistent action value; expected `android.intent.action.MEDIA_SCANNER_FAST_FINISHED`, was `android.intent.action.MEDIA_FAST_SCAN_FINISHED` [ActionValue]Error: metalava detected the following problems:
frameworks/base/core/java/android/content/Intent.java:3545: error: Inconsistent action value; expected `android.intent.action.MEDIA_SCANNER_FAST_FINISHED`, was `android.intent.action.MEDIA_FAST_SCAN_FINISHED` [ActionValue]
************************************************************
Your API changes are triggering API Lint warnings or errors.
To make these errors go away, fix the code according to the
error and/or warning messages above.

If it is not possible to do so, there are workarounds:

1. You can suppress the errors with @SuppressLint("<id>")
   where the <id> is given in brackets in the error message above.
2. You can add a baseline file of existing lint failures
   to the build rule of api-stubs-docs-non-updatable.
************************************************************

提示[Inconsistent action value]意思值和action不一致。

# 错误[这部分值MEDIA_FAST_SCAN_FINISHED不一样]
public static final String ACTION_MEDIA_SCANNER_FAST_FINISHED = "android.intent.action.MEDIA_FAST_SCAN_FINISHED";

# 正确[MEDIA_SCANNER_FAST_FINISHED一样]
public static final String ACTION_MEDIA_SCANNER_FAST_FINISHED = "android.intent.action.MEDIA_SCANNER_FAST_FINISHED";

当然,也可能不是这个原因,但可以试试,这个只是第一步。第二步就是删除current.txt中之前新增的。

然后重新执行

make update-api
问题2:FileUriExposedException
 Failed operation Intent { act=com.android.providers.media.action.SCAN_VOLUME (has extras) }
 android.os.FileUriExposedException: file:///storage/5055-B658 exposed beyond app through Intent.getData()
    at android.os.StrictMode.onFileUriExposed(StrictMode.java:2208)
    at android.net.Uri.checkFileUriExposed(Uri.java:2407)
    at android.content.Intent.prepareToLeaveProcess(Intent.java:11860)
    at android.content.Intent.prepareToLeaveProcess(Intent.java:11809)
    at android.app.ContextImpl.sendBroadcastAsUser(ContextImpl.java:1415)
    at android.content.ContextWrapper.sendBroadcastAsUser(ContextWrapper.java:593)
    at com.android.providers.media.MediaService.onScanVolume(MediaService.java:212)
    at com.android.providers.media.MediaService.onHandleWork(MediaService.java:97)
    at androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:396)
    at androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:387)
    at android.os.AsyncTask$3.call(AsyncTask.java:394)
    at java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
    at java.lang.Thread.run(Thread.java:1023)

ACTION_MEDIA_SCANNER_FAST_FINISHED是新增通知app媒体扫描结束的,需要跟其他媒体Action一样,需要进行过滤。

/**
 * Prepare this {@link Intent} to leave an app process.
 *
 * @hide
 */
public void prepareToLeaveProcess(boolean leavingPackage) {
    //略
    if (mAction != null && mData != null && StrictMode.vmFileUriExposureEnabled()
            && leavingPackage) {
        switch (mAction) {
            case ACTION_MEDIA_REMOVED:
            case ACTION_MEDIA_UNMOUNTED:
            case ACTION_MEDIA_CHECKING:
            case ACTION_MEDIA_NOFS:
            case ACTION_MEDIA_MOUNTED:
            case ACTION_MEDIA_SHARED:
            case ACTION_MEDIA_UNSHARED:
            case ACTION_MEDIA_BAD_REMOVAL:
            case ACTION_MEDIA_UNMOUNTABLE:
            case ACTION_MEDIA_EJECT:
            case ACTION_MEDIA_SCANNER_STARTED:
            case ACTION_MEDIA_SCANNER_FINISHED:
            case ACTION_MEDIA_SCANNER_SCAN_FILE:
            case ACTION_PACKAGE_NEEDS_VERIFICATION:
            case ACTION_PACKAGE_NEEDS_INTEGRITY_VERIFICATION:
            case ACTION_PACKAGE_VERIFIED:
            case ACTION_PACKAGE_ENABLE_ROLLBACK:
            //新增的
            case ACTION_MEDIA_SCANNER_FAST_FINISHED:
                // Ignore legacy actions
                break;
            default:
                mData.checkFileUriExposed("Intent.getData()");
        }
    }
    //略
}

make update-api

下面情况下就需要

  • 添加系统API或者修改@hide的API后,需要执行

    make update-api   //然后再make

    这部分暂时没测试过~_~

  • 修改公共api后,需要

    make update-api
例子1

在修改完系统Api或部分公共Api后(常见于修改Intent.java、KeyEvent.java等等),执行源码编译时会有如下提示

******************************
You have tried to change the API from what has been previously approved.
To make these errors go away, you have two choices:
   1) You can add "@hide" javadoc comments to the methods, etc. listed in the
      errors above.
   2) You can update current.txt by executing the following command:
         make update-api
      To submit the revised current.txt to the main Android repository,
      you will need approval.
******************************

一般会有提示,然后执行提示命令即可。

提交代码是也要把make update-api修改的contex.txt文件一起提交!

例子2

除了 make update-api,还有其他命令。

下面是修改MediaProvider中MediaStore.java是提示的

You have tried to change the API from what has been previously approved.
To make these errors go away, you have two choices:
   1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)
      to the new methods, etc. shown in the above diff.
   2. You can update current.txt and/or removed.txt by executing the following command:
         m framework-mediaprovider.stubs.source-update-current-api
      To submit the revised current.txt to the main Android repository,
      you will need approval.

这里提示

m framework-mediaprovider.stubs.source-update-current-api

反正看提示,不同情况需要使用不同的命令。

其他

还有其他的命令,随手记录一下

make api-stubs-docs-non-updatable
make api-stubs-docs-non-updatable-update-current-api
make api-stubs-docs-update-current-api

参考文章

  1. make update-api

相关文章

1 条评论

  • 城堡大人
    城堡大人 管理员

    让我看看

    回复