New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin stop mechanism #2

Merged
merged 11 commits into from Sep 2, 2017

Conversation

Projects
None yet
3 participants
@moonsky219
Member

moonsky219 commented Jul 24, 2017

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
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()))
  1. register this callback for receiving MobileInsight.Main.StopService at initial function
br = BroadcastReceiver(
        on_broadcast, actions=['MobileInsight.Main.StopService'])
br.start()

@zwyuan zwyuan added the enhancement label Jul 24, 2017

@yuanjieli

This comment has been minimized.

Contributor

yuanjieli commented Jul 24, 2017

@moonsky219

This comment has been minimized.

Member

moonsky219 commented Jul 24, 2017

@yuanjieli
But I think the plugin also need to do cleaning work itself inside the registered function (for example on_broadcast here).

@yuanjieli

This comment has been minimized.

Contributor

yuanjieli commented Jul 24, 2017

@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.

@moonsky219

This comment has been minimized.

Member

moonsky219 commented Jul 24, 2017

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.

import mi2app_utils
def on_broadcast(context, intent):

This comment has been minimized.

@yuanjieli

yuanjieli Jul 24, 2017

Contributor

Would be great if we can eliminate plugin developer's efforts to manually add on_broadcast(). One possibility is to overload the mobileinsight-mobile/app/service/main.py and add on_broadcast() here. In this way, any plugin can be stopped.

This comment has been minimized.

@zwyuan

zwyuan Jul 24, 2017

Member

should define basic functionalities in analyzer, and let the plugins to reload/override it.

@moonsky219

This comment has been minimized.

Member

moonsky219 commented Aug 31, 2017

I remove the code about checking orphan log in main.py and support it in LoggingAnalyzer of NetLogger

moonsky219 added some commits Aug 31, 2017

Disable tcpdump
need to specity different interface name for different devices

@zwyuan zwyuan merged commit b813bd7 into dev Sep 2, 2017

@moonsky219 moonsky219 deleted the pluginStopMachinism branch Oct 5, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment