收到USB_DEVICE_ATTACHED意向

时间:2018-10-09 08:17:50

标签: java android android-broadcastreceiver android-anr-dialog google-play-console

Google Play控制台向我显示了与接收USB状态意图的静态注册的BroadcastReceiver相关的随机ANR。

集群:

意向广播{act = android.hardware.usb.action.USB_DEVICE_ATTACHED flg = 0x10000010 cmp = eu.sisik.hackendebug / .UsbReceiver(有额外收费)}

在我的广播接收器中,我只是将意图转发到应用程序的其他部分以进行进一步处理。这是BroadcastReceiver的代码

public class UsbReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent != null)
        {
            final String action = intent.getAction();
            if (action != null && action.equals(ACTION_USB_DEVICE_ATTACHED))
            {
                Parcelable usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);    

                Intent broadcastIntent = new Intent(Constants.ACTION_USB_DEVICE_CONNECTED);
                broadcastIntent.putExtra(UsbManager.EXTRA_DEVICE, usbDevice);

                context.sendBroadcast(broadcastIntent);
            }
        }
    }
}

AndroidManifest.xml中的接收者

<receiver android:name=".UsbReceiver">
    <intent-filter>
        <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
    </intent-filter>
    <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
               android:resource="@xml/device_filter" />

    <intent-filter>
        <action android:name="android.hardware.usb.action.USB_STATE" />
    </intent-filter>
    <meta-data android:name="android.hardware.usb.action.USB_STATE"
               android:resource="@xml/device_filter" />
</receiver>

google控制台中“ main”的堆栈跟踪之一仅显示了此

"main" prio=5 tid=1 Native
  | group="main" sCount=1 dsCount=0 obj=0x7525f598 self=0xb4824500
  | sysTid=3945 nice=0 cgrp=apps/bg_non_interactive sched=0/0 handle=0xb6fb2b4c
  | state=S schedstat=( 128672069 176294544 277 ) utm=8 stm=4 core=2 HZ=100
  | stack=0xbe2ea000-0xbe2ec000 stackSize=8MB
  | held mutexes=
  #00  pc 0000000000040944  /system/lib/libc.so (__epoll_pwait+20)
  #01  pc 0000000000019fc3  /system/lib/libc.so (epoll_pwait+26)
  #02  pc 0000000000019fd1  /system/lib/libc.so (epoll_wait+6)
  #03  pc 0000000000012dff  /system/lib/libutils.so (_ZN7android6Looper9pollInnerEi+102)
  #04  pc 000000000001307b  /system/lib/libutils.so (_ZN7android6Looper8pollOnceEiPiS1_PPv+130)
  #05  pc 00000000000873bd  /system/lib/libandroid_runtime.so (_ZN7android18NativeMessageQueue8pollOnceEP7_JNIEnvP8_jobjecti+22)
  #06  pc 0000000000000575  /system/framework/arm/boot.oat (Java_android_os_MessageQueue_nativePollOnce__JI+96)
  at android.os.MessageQueue.nativePollOnce (Native method)
  at android.os.MessageQueue.next (MessageQueue.java:323)
  at android.os.Looper.loop (Looper.java:143)
  at android.app.ActivityThread.main (ActivityThread.java:7225)
  at java.lang.reflect.Method.invoke! (Native method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120) 

我无法在设备上重现此错误,最小的BroadcastReceiver也看不到任何问题。

ANR随机出现在各个制造商的设备上,因此,这不仅是特定于设备的问题,而且我必须尝试在代码中修复此问题。

报告的Android版本主要是6,而Android 9是一个报告。

我该如何解决这个问题,或者至少如何重现此问题?

谢谢

0 个答案:

没有答案