当前位置:   article > 正文

binder客户端readException分析_should be specified when a receiver isn't being re

should be specified when a receiver isn't being registered exclusively for s

https://issuetracker.google.com/issues/277822279

里面描述了一种情况,客户端进行了binder方法调用,却因为返回的Exception,发生了crash

  1. Caused by: java.lang.SecurityException: com.adobe.creativesdk.sample: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
  2. at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
  3. at android.os.Parcel.createException(Parcel.java:3041)
  4. at android.os.Parcel.readException(Parcel.java:3024)
  5. at android.os.Parcel.readException(Parcel.java:2966)
  6. at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5393)
  7. at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1851)
  8. at android.app.ContextImpl.registerReceiver(ContextImpl.java:1791)

说明了

1,客户端调用需要添加异常捕获处理,保证程序安全

2,服务端也需要对异常状况进行处理,如果客户端也没有处理,就会出问题

为什么服务端的异常没有在服务端爆发,反而传给了客户端呢,因为服务端的binder方法调用有binder.java里的异常捕获在兜底,

frameworks/base/core/java/android/os/Binder.java

  1. // Entry point from android_util_Binder.cpp's onTransact
  2. 714 private boolean execTransact(int code, long dataObj, long replyObj,
  3. 715 int flags) {
  4. 716 BinderCallsStats binderCallsStats = BinderCallsStats.getInstance();
  5. 717 BinderCallsStats.CallSession callSession = binderCallsStats.callStarted(this, code);
  6. 718 Parcel data = Parcel.obtain(dataObj);
  7. 719 Parcel reply = Parcel.obtain(replyObj);
  8. 720 // theoretically, we should call transact, which will call onTransact,
  9. 721 // but all that does is rewind it, and we just got these from an IPC,
  10. 722 // so we'll just call it directly.
  11. 723 boolean res;
  12. 724 // Log any exceptions as warnings, don't silently suppress them.
  13. 725 // If the call was FLAG_ONEWAY then these exceptions disappear into the ether.
  14. 726 final boolean tracingEnabled = Binder.isTracingEnabled();
  15. 727 try {
  16. 728 if (tracingEnabled) {
  17. 729 Trace.traceBegin(Trace.TRACE_TAG_ALWAYS, getClass().getName() + ":" + code);
  18. 730 }
  19. 731 res = onTransact(code, data, reply, flags);
  20. 732 } catch (RemoteException|RuntimeException e) {
  21. 733 if (LOG_RUNTIME_EXCEPTION) {
  22. 734 Log.w(TAG, "Caught a RuntimeException from the binder stub implementation.", e);
  23. 735 }
  24. 736 if ((flags & FLAG_ONEWAY) != 0) {
  25. 737 if (e instanceof RemoteException) {
  26. 738 Log.w(TAG, "Binder call failed.", e);
  27. 739 } else {
  28. 740 Log.w(TAG, "Caught a RuntimeException from the binder stub implementation.", e);
  29. 741 }
  30. 742 } else {
  31. 743 reply.setDataPosition(0);
  32. 744 reply.writeException(e);
  33. 745 }
  34. 746 res = true;
  35. 747 } finally {
  36. 748 if (tracingEnabled) {
  37. 749 Trace.traceEnd(Trace.TRACE_TAG_ALWAYS);
  38. 750 }
  39. 751 }
  40. 752 checkParcel(this, code, reply, "Unreasonably large binder reply buffer");
  41. 753 reply.recycle();
  42. 754 data.recycle();
  43. 755
  44. 756 // Just in case -- we are done with the IPC, so there should be no more strict
  45. 757 // mode violations that have gathered for this thread. Either they have been
  46. 758 // parceled and are now in transport off to the caller, or we are returning back
  47. 759 // to the main transaction loop to wait for another incoming transaction. Either
  48. 760 // way, strict mode begone!
  49. 761 StrictMode.clearGatheredViolations();
  50. 762 binderCallsStats.callEnded(callSession);
  51. 763
  52. 764 return res;
  53. 765 }
  54. 766}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/630766
推荐阅读
相关标签
  

闽ICP备14008679号