最近,我遇到了来自 Firebase Crashlytics 的一些奇怪的崩溃报告。
Caused by android.os.BadParcelableException: ClassNotFoundException when unmarshalling: id.dana.model.CurrencyAmountModel
at android.os.Parcel.readParcelableCreator(Parcel.java:2305)
at android.os.Parcel.readParcelable(Parcel.java:2255)
at android.os.Parcel.readValue(Parcel.java:2162)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2495)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.BaseBundle.getIntArray(BaseBundle.java:1164)
at android.appwidget.AppWidgetProvider.onReceive(AppWidgetProvider.java:64)
at com.yocto.wenote.widget.CalendarAppWidgetProvider.onReceive(CalendarAppWidgetProvider.java:234)
我觉得很奇怪,因为我的应用程序从来没有使用/访问类 id.dana.model.CurrencyAmountModel
.我完全不知道类(class)在哪里id.dana.model.CurrencyAmountModel
来自?似乎第 3 方应用程序能够将数据“注入(inject)”我的
AppWidgetProvider
?我的
AppWidgetProvider
定义如下。<receiver android:name="com.yocto.wenote.widget.CalendarAppWidgetProvider"
android:label="@string/widget_calendar_name"
android:exported="true" >
<intent-filter >
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/calendar_widget_info" />
</receiver>
public class CalendarAppWidgetProvider extends AppWidgetProvider {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
...
super.onReceive(context, intent);
}
}
你知道为什么我的AppWidgetProvider
正在接收未知数据 id.dana.model.CurrencyAmountModel
,以及如何避免这种情况?谢谢。
最佳答案
It seems like a 3rd party app is able to "inject" data into my AppWidgetProvider?
当然。您的
AppWidgetProvider
任何其他应用程序都可以公开访问。任何应用程序都可以向它发送广播,它将接收。Do you have any idea why does my AppWidgetProvider is receiving an unknown data id.dana.model.CurrencyAmountModel
某些应用程序正在发送带有
CurrencyAmountModel
的广播作为额外的。基于堆栈跟踪和 AppWidgetProvider
的实现,我的猜测是这个无效值在 AppWidgetManager.EXTRA_APPWIDGET_IDS
下 key 。希望这是另一个应用程序中的错误,而不是恶意的。how I can avoid such?
AFAIK,一个
AppWidgetProvider
必须导出它才能工作。你可以做个实验看看android:exported="false"
仍然给你一个工作的应用程序小部件,但它会让我感到惊讶。如果失败,您可以包装
super.onReceive()
在 try
/catch
阻止以防止崩溃。鉴于 AppWidgetProvider
实现,如果您的 catch
block 被调用,可能你的提供者没有被任何标准回调调用(例如,onUpdate()
)。您可以添加一些日志来尝试了解受影响的用户是否得到任何好处 super.onReceive()
调用:onUpdate()
自己时不时关于java - 我的 AppWidgetProvider 会在 onReceive 中从 3rd 方应用程序接收数据的可能原因是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69529640/