Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core.runtime): 修复Receiver的actions为空的NPE #758

Merged
merged 1 commit into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
import android.content.res.Configuration;
import android.os.Build;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
Expand All @@ -41,7 +39,7 @@ public class ShadowApplication extends ShadowContext {

private Application mHostApplication;

private Map<String, List<String>> mBroadcasts;
private Map<String, String[]> mBroadcasts;

private ShadowAppComponentFactory mAppComponentFactory;

Expand All @@ -68,16 +66,19 @@ public void onCreate() {

isCallOnCreate = true;

for (Map.Entry<String, List<String>> entry : mBroadcasts.entrySet()) {
for (Map.Entry<String, String[]> entry : mBroadcasts.entrySet()) {
try {
Class<?> clazz = mPluginClassLoader.loadClass(entry.getKey());
String receiverClassname = entry.getKey();
Class<?> clazz = mPluginClassLoader.loadClass(receiverClassname);
BroadcastReceiver receiver = ((BroadcastReceiver) clazz.newInstance());
mAppComponentFactory.instantiateReceiver(mPluginClassLoader, entry.getKey(), null);
mAppComponentFactory.instantiateReceiver(mPluginClassLoader, receiverClassname, null);

IntentFilter intentFilter = new IntentFilter();
for (String action:entry.getValue()
) {
intentFilter.addAction(action);
String[] receiverActions = entry.getValue();
if (receiverActions != null) {
for (String action : receiverActions) {
intentFilter.addAction(action);
}
}
registerReceiver(receiver, intentFilter);
} catch (Exception e) {
Expand Down Expand Up @@ -151,10 +152,10 @@ public void setHostApplicationContextAsBase(Context hostAppContext) {
}

public void setBroadcasts(PluginManifest.ReceiverInfo[] receiverInfos) {
Map<String, List<String>> classNameToActions = new HashMap<>();
Map<String, String[]> classNameToActions = new HashMap<>();
if (receiverInfos != null) {
for (PluginManifest.ReceiverInfo receiverInfo : receiverInfos) {
classNameToActions.put(receiverInfo.className, Arrays.asList(receiverInfo.actions));
classNameToActions.put(receiverInfo.className, receiverInfo.actions);
}
}
mBroadcasts = classNameToActions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<action android:name="com.tencent.test.normal.action" />
</intent-filter>
</receiver>
<receiver android:name=".lib.usecases.receiver.ReceiverWithoutAction" />

<activity android:name=".lib.usecases.provider.TestFileProviderActivity" />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Tencent is pleased to support the open source community by making Tencent Shadow available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of
* the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.tencent.shadow.test.plugin.general_cases.lib.usecases.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

/**
* 测试插件中包含无Action的Receiver能否正常启动
*/
public class ReceiverWithoutAction extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
}
}