问题描述
Android14 EDLA项目部分apk需要内置到系统中,不显示桌面图标,只提供部分应用触发使用。由于有的应用注册了图片、视频、文档触发启动,在使用文件极客(Google套件应用)打开上述类型文件时,会触发文件打开选择器,选择器会显示要隐藏的apk应用。不符合项目需求,文件选择器也要隐藏对应的apk。
原因分析:
因应用本身设计需求,注册了不同类型的文件监听器,当打开此类型的文件时,若有存在多个可打开的应用就会弹窗应用选择器。
<activity
android:name=".ui.activity.xxxActivity"
....
<intent-filter>
....
<data android:scheme="content" />
<data android:scheme="file" />
<data android:mimeType="audio/*" />
<data android:mimeType="application/ogg" />
...
</intent-filter>
</activity>
解决方案:
1. 应用中修改,去掉对应的文件类型注册,打开对应文件时就不会触发需隐藏应用
此方式在AndroidManifest.xml中去掉对应的注册即可;不过此方式需要修改应用内部的代码,如果遇到需要修改的应用过多、应用无源码或者是因应用需求问题不能去掉对应的注册。此方式修改并不适用,可以使用第二种方式处理。
2. 修改选择器的逻辑代码,通过包名过滤,不显示指定的应用
framework中ResolverListAdapter 修改
路径:frameworks/base/core/java/com/android/internal/app/ResolverListAdapter.java
...
// We assume that at this point we've already filtered out the only intent for a different
// targetUserId which we're going to use.
private void addResolveInfo(DisplayResolveInfo dri) {
if (dri != null && dri.getResolveInfo() != null
&& dri.getResolveInfo().targetUserId == UserHandle.USER_CURRENT) {
if (shouldAddResolveInfo(dri) && shouldAddSkgResolveInfo(dri)/*添加包名过滤*/) {
mDisplayList.add(dri);
Log.i(TAG, "Add DisplayResolveInfo component: " + dri.getResolvedComponentName()
+ ", intent component: " + dri.getResolvedIntent().getComponent());
}
}
}
/*添加包名过滤,按不同需求添加逻辑*/
private boolean shouldAddSkgResolveInfo(DisplayResolveInfo dri) {
if (dri.getResolveInfo().activityInfo.packageName.contains("xxx.xxx.xxx")){
return false;
}
return true;
}
...
IntentResolver应用中添加过滤
路径:packages/modules/IntentResolver/java/src/com/android/intentresolver/ResolverListAdapter.java
...
// We assume that at this point we've already filtered out the only intent for a different
// targetUserId which we're going to use.
private void addResolveInfo(DisplayResolveInfo dri) {
if (dri != null && dri.getResolveInfo() != null
&& dri.getResolveInfo().targetUserId == UserHandle.USER_CURRENT) {
if (shouldAddResolveInfo(dri) && shouldAddSkgResolveInfo(dri)/*添加包名过滤*/) {
mDisplayList.add(dri);
Log.i(TAG, "Add DisplayResolveInfo component: " + dri.getResolvedComponentName()
+ ", intent component: " + dri.getResolvedIntent().getComponent());
}
}
}
/*添加包名过滤,按不同需求添加逻辑*/
private boolean shouldAddSkgResolveInfo(DisplayResolveInfo dri) {
if (dri.getResolveInfo().activityInfo.packageName.contains("xxx.xxx.xxx")){
return false;
}
return true;
}
...