NFC服务一段时间后死机的可能原因是啥?

Posted

技术标签:

【中文标题】NFC服务一段时间后死机的可能原因是啥?【英文标题】:What are the possible reasons for NFC Service to become dead after some time?NFC服务一段时间后死机的可能原因是什么? 【发布时间】:2019-04-10 21:55:05 【问题描述】:

我们使用 NFC 标签作为进出停车票。在每个入口处,标签上都写有一些数据,并且在出口处,数据会验证车辆的出口。

部分车辆进出后,NfcService失效,手机无法检测到NFC标签。设备需要重启才能重启 NfcService,设备又开始正常工作了。

此错误是随机出现的,我们在开发环境中无法重现此错误,但我们在安装在停车场出入口的设备上多次观察到此问题。

当我们调试这个问题时,我们能够以某种方式管理上述日志。

我们尝试了不同的更改,例如使用 enableReaderMode 而不是 enableForegroundDispatch,但问题仍然存在。

public void enableReaderMode() 
    try 
    Log.d("WTF", "Enabling reader mode");
    NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);

    if (nfc != null) 
        int flags = NfcAdapter.FLAG_READER_NFC_A ;

            nfc.enableReaderMode(this, new NfcAdapter.ReaderCallback() 
                @Override
                public void onTagDiscovered(Tag tag) 
                    runOnUiThread(new Runnable() 
                        @Override
                        public void run() 
                            Log.d("WTF", "Tag discovered");
                            String uid = ByteArrayToHexString(tag.getId());
                            Toast.makeText(MainActivity.this, getString(R.string.message_tag_detected), Toast.LENGTH_SHORT).show();
                            Ndef ndef = Ndef.get(tag);

                            if (isNFCDialogDisplayed) 

                                if (isWrite) 

                                    mNfcWriteFragment = (NFCWriteFragment) getFragmentManager().findFragmentByTag(NFCWriteFragment.TAG);
                                    mNfcWriteFragment.onNfcDetected(ndef, uid);

                                 else 

                                    mNfcReadFragment = (NFCReadFragment) getFragmentManager().findFragmentByTag(NFCReadFragment.TAG);
                                    mNfcReadFragment.onNfcDetected(ndef, uid);
                                
                            
                        
                    );

                
            , flags, null);

    

    catch (Exception e)
        Crashlytics.logException(e);
    


public void disableReaderMode() 
    try 
    Log.d("WTF", "Disabling reader mode");
    NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
    if (nfc != null) 
            nfc.disableReaderMode(this);
    
    catch (Exception e)
        Crashlytics.logException(e);
    

NFCWriteFragment 和 NFCReadFragment 在内部读取和写入 NDEF 数据到标签。

*** 上的类似问题:

NFC service dead - attempting to recover - 尝试将代码从 onResume 转移,因此当调用 enableReadeMode()disableReaderMode() 时,活动始终处于活动状态且可见 android NFC Issue with APDU Commands - 这可能是相关的,但不能给出令人满意的结论

更新

将代码从 onResume 移出,因此当调用 enableReadeMode()disableReaderMode() 时,活动始终处于活动状态且可见

这是新的日志

04-15 01:51:50.328 4987-4987/in.parksmart.operator D/WindowClient: 添加到 mViews: com.android.internal.policy.PhoneWindow$DecorView55c53ae V.E...... R.....一世。 0,0-0,0,这 = android.view.WindowManagerGlobal@ff3d558 04-15 01:51:50.329 4987-5037/in.parksmart.operator D/OpenGLRenderer: CanvasContext() 0x9cafb800 04-15 01:51:50.330 4987-4987/in.parksmart.operator D/ViewRootImpl:启用硬件加速,这 = ViewRoot7de1f47 in.parksmart.operator/in.parksmart.operator.MainActivity,ident = 133 04-15 01:51:50.354 4987-4987/in.parksmart.operator D/Surface: Surface::allocateBuffers(this=0x9de38200) 04-15 01:51:50.360 4987-5037/in.parksmart.operator D/OpenGLRenderer: CanvasContext() 0x9cafb800 初始化窗口=0x9de38208,标题=in.parksmart.operator/in.parksmart.operator.MainActivity 04-15 01:51:50.360 4987-5037/in.parksmart.operator D/Surface: Surface::connect(this=0x9de38200,api=1) 04-15 01:51:50.361 4987-5037/in.parksmart.operator W/libEGL:[ANDROID_RECORDABLE] 格式:1 04-15 01:51:50.361 4987-5037/in.parksmart.operator D/Surface: Surface::setBufferCount(this=0x9de38200,bufferCount=4) 04-15 01:51:50.366 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9c9cd8e0)(w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:51.181 4987-4999/in.parksmart.operator D/WTF:禁用阅读器模式 04-15 01:51:51.182 4987-4999/in.parksmart.operator D/WTF:NFC:不兼容标签 04-15 01:51:51.218 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1) 04-15 01:51:51.218 4987-5037/in.parksmart.operator D/GraphicBuffer:注销,句柄(0x9c9cd8e0)(w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:51.220 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1) 04-15 01:51:51.220 4987-5037/in.parksmart.operator D/Surface: Surface::connect(this=0x9de38200,api=1) 04-15 01:51:51.221 4987-5037/in.parksmart.operator W/libEGL:[ANDROID_RECORDABLE] 格式:1 04-15 01:51:51.221 4987-5037/in.parksmart.operator D/Surface: Surface::setBufferCount(this=0x9de38200,bufferCount=4) 04-15 01:51:51.224 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9c9cd8e0)(w:584 h:593 s:592 f:0x1 u:0x000f02) 04-15 01:51:51.432 4987-5077/in.parksmart.operator D/NativeCrypto: ssl=0xaa571900 sslWrite buf=0x9da11aa0 len=7 write_timeout_millis=0 04-15 01:51:51.432 4987-5077/in.parksmart.operator D/NativeCrypto:sslNotify,appData=0xaf928a00 ret=1 04-15 01:51:51.459 4987-5052/in.parksmart.operator D/NativeCrypto: sslSelect, appData=0xaf928a00 被令牌唤醒 04-15 01:51:51.459 4987-5052/in.parksmart.operator D/NativeCrypto:sslSelect,appData=0xaf928a00 读取 ret=1 04-15 01:51:51.459 4987-5052/in.parksmart.operator D/NativeCrypto: sslSelect, appData=0xaf928a00 被令牌唤醒 04-15 01:51:51.459 4987-5052/in.parksmart.operator D/NativeCrypto:sslSelect,appData=0xaf928a00 读取 ret=1 04-15 01:51:54.335 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9d9715a0)(w:584 h:593 s:592 f:0x1 u:0x000f02) 04-15 01:51:54.414 4987-4987/in.parksmart.operator D/SettingsInterface:来自设置缓存,名称 = sound_effects_enabled ,值 = 0 04-15 01:51:54.414 4987-4987/in.parksmart.operator D/WTF:启用阅读器模式 04-15 01:51:54.467 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1) 04-15 01:51:54.467 4987-5037/in.parksmart.operator D/GraphicBuffer: 注销,句柄 (0x9c9cd8e0) (w:584 h:593 s:592 f:0x1 u:0x000f02) 04-15 01:51:54.468 4987-5037/in.parksmart.operator D/GraphicBuffer: 注销,句柄 (0x9d9715a0) (w:584 h:593 s:592 f:0x1 u:0x000f02) 04-15 01:51:54.471 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1) 04-15 01:51:54.471 4987-5037/in.parksmart.operator D/Surface: Surface::connect(this=0x9de38200,api=1) 04-15 01:51:54.472 4987-5037/in.parksmart.operator W/libEGL:[ANDROID_RECORDABLE] 格式:1 04-15 01:51:54.474 4987-5037/in.parksmart.operator D/Surface: Surface::setBufferCount(this=0x9de38200,bufferCount=4) 04-15 01:51:54.478 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9d9715a0)(w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:54.485 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9c9cd8e0)(w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:54.506 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9d971610)(w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:54.542 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9d971680)(w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:54.976 4987-5000/in.parksmart.operator D/WTF:禁用阅读器模式 04-15 01:51:54.977 4987-5000/in.parksmart.operator D/WTF:NFC:不兼容的标签 04-15 01:51:55.003 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1) 04-15 01:51:55.003 4987-5037/in.parksmart.operator D/GraphicBuffer:注销,句柄(0x9d9715a0)(w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:55.004 4987-5037/in.parksmart.operator D/GraphicBuffer:注销,句柄(0x9c9cd8e0)(w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:55.005 4987-5037/in.parksmart.operator D/GraphicBuffer:注销,句柄(0x9d971610)(w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:55.005 4987-5037/in.parksmart.operator D/GraphicBuffer:注销,处理(0x9d971680)(w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:55.007 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1) 04-15 01:51:55.008 4987-5037/in.parksmart.operator D/Surface: Surface::connect(this=0x9de38200,api=1) 04-15 01:51:55.009 4987-5037/in.parksmart.operator W/libEGL:[ANDROID_RECORDABLE] 格式:1 04-15 01:51:55.010 4987-5037/in.parksmart.operator D/Surface: Surface::setBufferCount(this=0x9de38200,bufferCount=4) 04-15 01:51:55.012 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9d971680)(w:584 h:593 s:592 f:0x1 u:0x000f02) 04-15 01:51:56.966 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9d971610)(w:584 h:593 s:592 f:0x1 u:0x000f02) 04-15 01:51:57.023 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9c9cd8e0)(w:584 h:593 s:592 f:0x1 u:0x000f02) 04-15 01:51:57.118 4987-4987/in.parksmart.operator D/SettingsInterface:来自设置缓存,名称 = sound_effects_enabled ,值 = 0 04-15 01:51:57.119 4987-4987/in.parksmart.operator D/WTF:启用阅读器模式 04-15 01:52:05.451 4987-4987/in.parksmart.operator E/NFC: NFC 服务失效 - 试图恢复 android.os.DeadObjectException 在 android.os.BinderProxy.transactNative(本机方法) 在 android.os.BinderProxy.transact(Binder.java:511) 在 android.nfc.INfcAdapter$Stub$Proxy.setReaderMode(INfcAdapter.java:614) 在 android.nfc.NfcActivityManager.setReaderMode(NfcActivityManager.java:241) 在 android.nfc.NfcActivityManager.enableReaderMode(NfcActivityManager.java:217) 在 android.nfc.NfcAdapter.enableReaderMode(NfcAdapter.java:1299) 在 in.parksmart.operator.NFCReadFragment.enableReaderMode(NFCReadFragment.java:131) 在 in.parksmart.operator.NFCReadFragment$1.onClick(NFCReadFragment.java:100) 在 android.view.View.performClick(View.java:5265) 在 android.view.View$PerformClick.run(View.java:21534) 在 android.os.Handler.handleCallback(Handler.java:815) 在 android.os.Handler.dispatchMessage(Handler.java:104) 在 android.os.Looper.loop(Looper.java:207) 在 android.app.ActivityThread.main(ActivityThread.java:5728) 在 java.lang.reflect.Method.invoke(本机方法) 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 04-15 01:52:05.452 4987-4987/in.parksmart.operator E/NFC:在服务恢复期间无法检索 NFC 服务 04-15 01:52:05.454 4987-4987/in.parksmart.operator I/Choreographer:跳过了 432 帧!应用程序可能在其主线程上做了太多工作。 04-15 01:52:05.473 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1) 04-15 01:52:05.473 4987-5037/in.parksmart.operator D/GraphicBuffer:注销,句柄(0x9d971680)(w:584 h:593 s:592 f:0x1 u:0x000f02) 04-15 01:52:05.474 4987-5037/in.parksmart.operator D/GraphicBuffer:注销,句柄(0x9d971610)(w:584 h:593 s:592 f:0x1 u:0x000f02) 04-15 01:52:05.475 4987-5037/in.parksmart.operator D/GraphicBuffer: 注销,句柄 (0x9c9cd8e0) (w:584 h:593 s:592 f:0x1 u:0x000f02) 04-15 01:52:05.477 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1) 04-15 01:52:05.478 4987-5037/in.parksmart.operator D/Surface: Surface::connect(this=0x9de38200,api=1) 04-15 01:52:05.480 4987-5037/in.parksmart.operator W/libEGL:[ANDROID_RECORDABLE] 格式:1 04-15 01:52:05.481 4987-5037/in.parksmart.operator D/Surface: Surface::setBufferCount(this=0x9de38200,bufferCount=4) 04-15 01:52:05.485 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9c9cd8e0)(w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:52:05.509 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1) 04-15 01:52:05.509 4987-5037/in.parksmart.operator D/GraphicBuffer:注销,句柄(0x9c9cd8e0)(w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:52:05.511 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1) 04-15 01:52:05.516 4987-4987/in.parksmart.operator D/WindowClient:从 mViews 中删除:com.android.internal.policy.PhoneWindow$DecorView55c53ae V.E...... R..... .D 0,0-528,369,这 = android.view.WindowManagerGlobal@ff3d558 04-15 01:52:05.516 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。 04-15 01:52:05.517 4987-4987/in.parksmart.operator W/ViewRootImpl:由于根视图被删除而丢弃事件:MotionEvent action=ACTION_MOVE, actionButton=0, id[0]=0, x[0 ]=-33.087376, y[0]=95.55115, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=6, eventTime=1689826, downTime=1689716 , deviceId=2, 源=0x1002 04-15 01:52:05.517 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。 04-15 01:52:05.518 4987-4987/in.parksmart.operator W/ViewRootImpl:由于根视图被删除而丢弃事件:MotionEvent action=ACTION_UP, actionButton=0, id[0]=0, x[0 ]=-33.087376, y[0]=95.55115, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=1689842, downTime=1689716 , deviceId=2, 源=0x1002 04-15 01:52:05.518 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。 04-15 01:52:05.519 4987-4987/in.parksmart.operator W/ViewRootImpl:由于根视图被删除而丢弃事件:MotionEvent action=ACTION_DOWN, actionButton=0, id[0]=0, x[0 ]=353.3759, y[0]=527.21387, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=1692129, downTime=1692129,设备 ID=2,来源=0x1002 04-15 01:52:05.520 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。 04-15 01:52:05.520 4987-4987/in.parksmart.operator W/ViewRootImpl:由于根视图被删除而丢弃事件:MotionEvent action=ACTION_MOVE, actionButton=0, id[0]=0, x[0 ]=353.3759, y[0]=527.21387, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=6, eventTime=1692243, downTime=1692129,设备 ID=2,来源=0x1002 04-15 01:52:05.520 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。 04-15 01:52:05.521 4987-4987/in.parksmart.operator W/ViewRootImpl:由于根视图被删除而丢弃事件:MotionEvent action=ACTION_UP, actionButton=0, id[0]=0, x[0 ]=353.3759, y[0]=527.21387, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=1692258, downTime=1692129,设备 ID=2,来源=0x1002 04-15 01:52:05.521 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。 04-15 01:52:05.521 4987-4987/in.parksmart.operator W/ViewRootImpl:由于根视图被删除而丢弃事件:MotionEvent action=ACTION_DOWN, actionButton=0, id[0]=0, x[0 ]=393.3204, y[0]=526.21466, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=1692338, downTime=1692338,设备 ID=2,来源=0x1002 04-15 01:52:05.521 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。 04-15 01:52:05.522 4987-4987/in.parksmart.operator W/ViewRootImpl:由于根视图被删除而丢弃事件:MotionEvent action=ACTION_MOVE, actionButton=0, id[0]=0, x[0 ]=393.3204, y[0]=526.21466, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=1692416, downTime=1692338,设备 ID=2,来源=0x1002 04-15 01:52:05.522 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。 04-15 01:52:05.522 4987-4987/in.parksmart.operator W/ViewRootImpl:由于根视图被删除而丢弃事件:MotionEvent action=ACTION_UP, actionButton=0, id[0]=0, x[0 ]=393.3204, y[0]=526.21466, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=1692432, downTime=1692338,设备 ID=2,来源=0x1002 04-15 01:52:05.522 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。 04-15 01:52:06.898 4987-4987/in.parksmart.operator D/SettingsInterface:来自设置缓存,名称 = sound_effects_enabled ,值 = 0 04-15 01:52:06.899 4987-4987/in.parksmart.operator E/NFC: NFC 服务失效 - 试图恢复 android.os.DeadObjectException 在 android.os.BinderProxy.transactNative(本机方法) 在 android.os.BinderProxy.transact(Binder.java:511) 在 android.nfc.INfcAdapter$Stub$Proxy.getState(INfcAdapter.java:365) 在 android.nfc.NfcAdapter.isEnabled(NfcAdapter.java:642) 在 in.parksmart.operator.MainActivity$PlaceholderFragment.lambda$onCreateView$4(MainActivity.java:2925) 在 in.parksmart.operator.-$$Lambda$MainActivity$PlaceholderFragment$rsZBvNO0FFN0PjGCm8QiSvrhIqw.onClick(lambda) 在 android.view.View.performClick(View.java:5265) 在 android.view.View$PerformClick.run(View.java:21534) 在 android.os.Handler.handleCallback(Handler.java:815) 在 android.os.Handler.dispatchMessage(Handler.java:104) 在 android.os.Looper.loop(Looper.java:207) 在 android.app.ActivityThread.main(ActivityThread.java:5728) 在 java.lang.reflect.Method.invoke(本机方法) 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 04-15 01:52:06.941 4987-4987/in.parksmart.operator D/WindowClient: 添加到 mViews: com.android.internal.policy.PhoneWindow$DecorViewdcd6d0c V.E...... R.....一世。 0,0-0,0,这 = android.view.WindowManagerGlobal@ff3d558 04-15 01:52:06.942 4987-5037/in.parksmart.operator D/OpenGLRenderer: CanvasContext() 0x9f734800 04-15 01:52:06.943 4987-4987/in.parksmart.operator D/ViewRootImpl:启用硬件加速,这 = ViewRoot5eeb4b3 in.parksmart.operator/in.parksmart.operator.MainActivity,ident = 134 04-15 01:52:06.972 4987-5037/in.parksmart.operator D/OpenGLRenderer: CanvasContext() 0x9f734800 初始化窗口=0x9de38208,标题=in.parksmart.operator/in.parksmart.operator.MainActivity 04-15 01:52:06.972 4987-4987/in.parksmart.operator D/Surface: Surface::allocateBuffers(this=0x9de38200) 04-15 01:52:06.972 4987-5037/in.parksmart.operator D/Surface: Surface::connect(this=0x9de38200,api=1) 04-15 01:52:06.975 4987-5037/in.parksmart.operator W/libEGL:[ANDROID_RECORDABLE] 格式:1 04-15 01:52:06.976 4987-5037/in.parksmart.operator D/Surface: Surface::setBufferCount(this=0x9de38200,bufferCount=4) 04-15 01:52:06.980 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9c9cd8e0)(w:812 h:400 s:816 f:0x1 u:0x000f02) 04-15 01:52:07.008 4987-5037/in.parksmart.operator D/OpenGLRenderer: CacheTexture 4 上传: x, y, width height = 0, 0, 1024, 512 04-15 01:52:07.025 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9d974780)(w:812 h:400 s:816 f:0x1 u:0x000f02) 04-15 01:52:13.710 4987-5052/in.parksmart.operator D/NativeCrypto: ssl=0xaa571900 sslRead buf=0xaf907641 len=1,timeo=0 04-15 01:52:13.710 4987-5052/in.parksmart.operator D/NativeCrypto: ssl=0xaa571900 sslRead buf=0xaf917800 len=91,timeo=0 04-15 01:52:13.711 4987-5052/in.parksmart.operator D/NativeCrypto: ssl=0xaa571900 sslRead buf=0xaf907640 len=1,timeo=0 04-15 01:52:13.722 4987-4987/in.parksmart.operator D/FBDB: 孩子被移除 04-15 01:52:13.729 4987-4987/in.parksmart.operator D/FBDB:儿童被移除 04-15 01:52:13.729 4987-4987/in.parksmart.operator D/FBDB:孩子被移除

现在似乎不是活动娱乐的案例。 每次我们希望 NFC 标签连接时,我们都会调用enableReaderMode,一旦我们使用标签的工作结束,我们就会调用disableReaderMode

客户端使用的设备是天波900B。

【问题讨论】:

你解决这个问题了吗?怎么样? 我们更换了设备。这个问题并没有完全解决,但发生这种情况的频率大大降低了。还没有找到永久的解决方案。 使用执行isEnabled两次的方法? 是的,即使isEnabled 两次接近问题也没有解决 【参考方案1】:

E/NFC: NFC service dead - trying to recovery 错误通常发生在标签和 Android 设备之间的连接不良(即通信中断且 NFC 服务无法恢复时)从错误中恢复)。在那些(罕见的?)情况下,NFC 服务会崩溃并尝试重新启动。

在某些情况下,您可以通过重新注册前台调度/阅读器模式来从应用内的错误中恢复,例如使用

NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
if (nfc != null) 
    try  nfc.isEnabled();  catch (Exception ignore) 
    if (nfc.isEnabled())  // be sure to check isEnabled() twice to recover binder
        nfc.enableReaderMode(this, ... );
    

不幸的是,在某些设备上,从此类错误中恢复的唯一方法是手动强制停止 NFC 系统服务应用程序,甚至重新启动设备。

【讨论】:

【参考方案2】:

我没有崩溃的解决方案,但我有一些提示如何重现它。

崩溃是如何造成的

这个崩溃是由自动化测试环境触发的

android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)

而且很可能在活动重新创建之间某些东西没有持续/正确处理。

通过仪器测试进行复制。

您可以通过文档了解如何编写仪器测试以重现它: https://developer.android.com/reference/android/app/Instrumentation

在这篇文章中,有一些关于如何通过仪器测试处理活动生命周期的额外细节 How to stop and restart an activity in an android instrumentation test?

以用户身份进行复制。

当您将应用程序发送到后台时,这可能会在真实设备上发生,并且系统将其杀死以获取资源,因此当它再次带到前面时,某些内容分配不正确。

这里的难点在于,在测试时让系统杀死您的活动并不容易,因为如果另一个复杂的任务需要资源,可能会发生这种情况,低端设备是此类测试的必要条件。

作为开发人员进行复制。

根据文档,简单的解决方法是使用开发人员选项下提供的“Don't keep activities”,这将在活动发送到后台后立即终止。

【讨论】:

以上是关于NFC服务一段时间后死机的可能原因是啥?的主要内容,如果未能解决你的问题,请参考以下文章

电脑老是卡屏 死机是啥原因啊??

笔记本电脑突然就卡死不动了,可能是啥原因?

电脑常死机为啥啊

通过 Spring Websocket STOMP 打开连接会导致我们的服务器死机

win10白屏怎么办

关机后Arduino死机