相关log:
08-17 18:34:33.907 11673 11673 E AndroidRuntime: FATAL EXCEPTION: main
08-17 18:34:33.907 11673 11673 E AndroidRuntime: Process: com.android.launcher, PID: 11673
08-17 18:34:33.907 11673 11673 E AndroidRuntime: java.lang.SecurityException: Attempt to launch activity without category Intent.CATEGORY_LAUNCHER ComponentInfo{com.google.android.googlequicksearchbox/com.google.android.googlequicksearchbox.MainInfoGatewayInternal}
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at android.os.Parcel.createExceptionOrNull(Parcel.java:2455)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at android.os.Parcel.createException(Parcel.java:2439)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:2422)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:2364)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at android.content.pm.ILauncherApps$Stub$Proxy.getActivityLaunchIntent(ILauncherApps.java:1285)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at android.content.pm.LauncherApps.getMainActivityLaunchIntent(LauncherApps.java:761)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at com.android.systemui.shared.system.LauncherAppsCompat.getMainActivityLaunchIntent(LauncherAppsCompat.java:32)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at com.android.launcher3.taskbar.TaskbarDragController.startSystemDrag(TaskbarDragController.java:302)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at com.android.launcher3.taskbar.TaskbarDragController.callOnDragStart(TaskbarDragController.java:254)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at com.android.launcher3.dragndrop.DragController.handleMoveEvent(DragController.java:895)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at com.android.launcher3.dragndrop.DragController.onDriverDragMove(DragController.java:458)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at com.android.launcher3.dragndrop.DragDriver$InternalDragDriver.onTouchEvent(DragDriver.java:182)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at com.android.launcher3.dragndrop.DragController.onControllerTouchEvent(DragController.java:573)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at com.android.launcher3.views.BaseDragLayer.onTouchEvent(BaseDragLayer.java:283)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at android.view.View.dispatchTouchEvent(View.java:14633)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3167)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2809)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at com.android.launcher3.views.BaseDragLayer.dispatchTouchEvent(BaseDragLayer.java:318)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at com.android.launcher3.taskbar.TaskbarDragLayer.dispatchTouchEvent(TaskbarDragLayer.java:251)
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at
1、通过log来看报错信息应该是在启动 com.google.android.googlequicksearchbox/com.google.android.googlequicksearchbox.MainInfoGatewayInternal 时候缺少category Intent.CATEGORY_LAUNCHER
通过对Google Search进行反编译查看AndroidManifest进行查看
<activity-alias android:excludeFromRecents="true" android:exported="true" android:label="@string/search_activity_name" android:name="com.google.android.googlequicksearchbox.MainInfoGatewayInternal" android:noHistory="true" android:process=":search" android:targetActivity="com.google.android.googlequicksearchbox.SearchActivity" android:taskAffinity="" android:theme="@android:style/Theme.NoDisplay" android:visibleToInstantApps="true">
<meta-data android:name="alias_name" android:value="MainInfoGatewayInternal"/>
<meta-data android:name="instantapps.clients.allowed" android:value="true"/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.INFO"/>
</intent-filter>
</activity-alias>
在启动com.google.android.googlequicksearchbox/com.google.android.googlequicksearchbox.MainInfoGatewayInternal 时候缺少category Intent.CATEGORY_LAUNCHER
2.通过抓取START u0 log发现在界面点击以及hotseat点击google应用时均启动的是SearchActivity。
adb logcat -b all | grep “START u0”
界面点击或者hotseat点击:
08-23 23:36:56.290 919 6748 I ActivityTaskManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.google.android.googlequicksearchbox/.SearchActivity bnds=[60,425][373,650]} from uid 10059
只有在crash问题发生点:recent最近应用,这里启动的Activity是com.google.android.googlequicksearchbox.MainInfoGatewayInternal。由于这里Google应用没有配置 Intent.CATEGORY_LAUNCHER,导致在启动这个Activity的时候找不到因此报错。
3.由于时Google应用我们无法直接进行修改。通过查看代码调用栈,启动应用的位置在launcher里面:
08-17 18:34:33.907 11673 11673 E AndroidRuntime: at com.android.launcher3.taskbar.TaskbarDragController.startSystemDrag(TaskbarDragController.java:302)
我们在这里直接硬编码进行规避,由于正常都是走的com.google.android.googlequicksearchbox/.SearchActivity,只有这种情况走com.google.android.googlequicksearchbox.MainInfoGatewayInternal。我们先让他走进MainInfoGatewayInternal然后在重新设置启动的应用包名和类名为SearchActivity。即可规避crash
startSystemDrag()
if(item!=null && item.getTargetComponent()!=null && item.getTargetComponent().getPackageName()!=null && item.getTargetComponent().getPackageName().equals("com.google.android.googlequicksearchbox")
&& item.getTargetComponent().getClassName().equals("com.google.android.googlequicksearchbox.MainInfoGatewayInternal")){
ComponentName cn = new ComponentName(item.getTargetComponent().getPackageName(), "com.google.android.googlequicksearchbox.SearchActivity");
item.getIntent().setComponent(cn);
}