Closed moonsky219 closed 7 years ago
I would suggest to move on_broadcast() to mobileinsight-mobile/app/service/main.py. In this way, the plugin developers do not need to manually add this function. We can also prevent any unexpected deadlocks due to imperfect plugins.
On Sun, Jul 23, 2017 at 11:10 PM, Haotian Deng notifications@github.com wrote:
The whole procedure works like this:
main.py
- main.py will broadcast MobileInsight.Main.StopService when user click stop xxx plugin.
- main.py waits for MobileInsight.Plugin.StopServiceAck (or a 5 seconds timer expired)
- main.py stops plugin forcefully
plugin
- waiting for MobileInsight.Main.StopService intent
- finish any closure work
- broadcasting MobileInsight.Plugin.StopServiceAck
To utilize this mechanism, plugin need to add following extra code:
- define a callback function for doing closure work and sending StopServiceAck back to main.py
def on_broadcast(context, intent): ''' This plugin is going to be stopped, finish closure work ''' IntentClass = autoclass("android.content.Intent") intent = IntentClass() action = 'MobileInsight.Plugin.StopServiceAck' intent.setAction(action) try: mi2app_utils.pyService.sendBroadcast(intent) except Exception as e: import traceback analyzer.log_error(str(traceback.format_exc()))
- register this callback for receiving MobileInsight.Main.StopService at initial function
br = BroadcastReceiver( on_broadcast, actions=['MobileInsight.Main.StopService']) br.start()
You can view, comment on, or merge this pull request online at:
https://github.com/mobile-insight/mobileinsight-mobile/pull/2 Commit Summary
- Add stop mechanism for plugins
- Merge branch 'dev' of github.com:mobile-insight/mobileinsight-mobile into dev
- Plugins will be forced to stop if waiting time since user click stop button is longer than 5 seconds
File Changes
- M app/main.py https://github.com/mobile-insight/mobileinsight-mobile/pull/2/files#diff-0 (79)
- M app/plugins/NasAnalysis/main.mi2app https://github.com/mobile-insight/mobileinsight-mobile/pull/2/files#diff-1 (22)
- M app/plugins/NetLogger/logging_analyzer.py https://github.com/mobile-insight/mobileinsight-mobile/pull/2/files#diff-2 (41)
- M app/plugins/NetLogger/main.mi2app https://github.com/mobile-insight/mobileinsight-mobile/pull/2/files#diff-3 (0)
- M app/plugins/RrcAnalysis/main.mi2app https://github.com/mobile-insight/mobileinsight-mobile/pull/2/files#diff-4 (22)
Patch Links:
- https://github.com/mobile-insight/mobileinsight-mobile/pull/2.patch
- https://github.com/mobile-insight/mobileinsight-mobile/pull/2.diff
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mobile-insight/mobileinsight-mobile/pull/2, or mute the thread https://github.com/notifications/unsubscribe-auth/AENZ91NEXdx-i2RpvdbnPMHszicU7Htzks5sRDVAgaJpZM4OgwsU .
@yuanjieli But I think the plugin also need to do cleaning work itself inside the registered function (for example on_broadcast here).
@moonsky219 I see. But what would happen if the plugin developer forgets to do so? My main concern is that on_broadcast
is currently not mandatory. We should (1) make it mandatory programmatically since it is critical; (2) simplify the developer's efforts to overload this function.
Yes, I totally agree with you. My current work around is letting main.py to wait for maximum 5 seconds before stopping the plugin compulsively. A better implementation is still needed.
I remove the code about checking orphan log in main.py and support it in LoggingAnalyzer of NetLogger
The whole procedure works like this:
main.py 1) main.py will broadcast MobileInsight.Main.StopService when user click stop xxx plugin. 2) main.py waits for MobileInsight.Plugin.StopServiceAck (or a 5 seconds timer expired) 3) main.py stops plugin forcefully
plugin 1) waiting for MobileInsight.Main.StopService intent 2) finish any closure work 3) broadcasting MobileInsight.Plugin.StopServiceAck
To utilize this mechanism, plugin need to add following extra code: 1) define a callback function for doing closure work and sending StopServiceAck back to main.py
2) register this callback for receiving MobileInsight.Main.StopService at initial function