VirtualAPK icon indicating copy to clipboard operation
VirtualAPK copied to clipboard

0.9.9.1-dev版本,Intent原来的categories会丢失

Open BeQuietLee opened this issue 6 years ago • 0 comments

相关问题:Issues: ClassNotFoundException

ComponentsHandler.java中,对于插件传来的Intent,将其原有categories以KEY_CATEGORY保存在intent中,但是后续处理时并没有恢复,导致categories丢失。请问这里是否有问题? @superqiaopu

// ComponentsHandler.java
    public void markIntentIfNeeded(Intent intent) {
        if (intent.getComponent() == null) {
            return;
        }
        String targetPackageName = intent.getComponent().getPackageName();
        String targetClassName = intent.getComponent().getClassName();
        // search map and return specific launchmode stub activity
        if (!targetPackageName.equals(mContext.getPackageName()) && mPluginManager.getLoadedPlugin(targetPackageName) != null) {
            // mark plugin by categories
            Set<String> categories = intent.getCategories();
            if (categories != null) {
                intent.putStringArrayListExtra(Constants.KEY_CATEGORY, new ArrayList<>(categories)); // 这里保存下来,但是解析时并没有恢复categories
                categories.clear();
            }
            intent.addCategory(Constants.CATEGORY_PREFIX_TARGET_PACKAGE + targetPackageName);
            intent.addCategory(Constants.CATEGORY_PREFIX_TARGET_ACTIVITY + targetClassName);
            dispatchStubActivity(intent);
        }
    }

补充

我尝试在PluginUtil.java中的getComponent(Intent)方法里恢复原来的categories,但是这样会导致ClassNotFoundException再次发生,原因是intent.getStringArrayListExtra(Constants.KEY_CATEGORY)方法会调用unparcel

// BaseBundle.java
    ArrayList<String> getStringArrayList(@Nullable String key) {
        unparcel();
        Object o = mMap.get(key);
        if (o == null) {
            return null;
        }
        try {
            return (ArrayList<String>) o;
        } catch (ClassCastException e) {
            typeWarning(key, o, "ArrayList<String>", e);
            return null;
        }
    }

BeQuietLee avatar Jun 04 '19 03:06 BeQuietLee