Skip to content

Decorator Plugin Development

oasisfeng edited this page Jun 6, 2019 · 10 revisions

Overview

Decorator plug-in is responsible for tweaking the notification to provider better experience, such as design polishing, additional functionality and even Android Wear/Auto specific support.

Decorators from different developers may work in a pipeline to processing the notification one by one, ordered by "priority" attribute, which provide the hint for final ordering. (User will be allowed to re-order the decorators in settings in a future version)

Workflow

Decorator is implemented by extending NevoDecoratorService class. It has two basic methods:

  • apply() receives notification to be processed and applies modifications via various APIs on the MutableStatusBarNotification class, whose getNotification() will return a MutableNotification instance with convenient APIs to assist notification tweaking.

  • onNotificationRemoved() receives the event of notification removal. Nothing can be applied here except for invoking notification operation APIs on NevoDecoratorService. It's commonly used to keep internal state synchronized with notification visibility state.

Formula Request

Decorator with UI can request itself to be added to formula of specific app, with this activity API:

startActivityForResult(new Intent("com.oasisfeng.nevo.action.ACTIVATE_DECORATOR")
        .putExtra("nevo.decorator", new ComponentName(this, MyDecorator.class))
        .putExtra("nevo.target", "com.example.target.app"), requestCode);

To request removal from formula, use action com.oasisfeng.nevo.action.DEACTIVATE_DECORATOR instead.

Sample Projects

  • WeChat Modernized

    A sample project for app-specific decorator.

  • Call Vibration

    A sample project to take advantage of notification content as input to implement functionality supposedly impossible without root.

  • Misc. Decorators

    A collection of general-purpose decorators, which can be applied to various apps.

Limitations

  • Notification sound and vibration may not be changed if the whole evolving procedure is too slow. So keep your decorator as efficient as possible.

  • Evolved notifications are not automatically removed by the originating app (e.g. when app is opened). This is an mechanism limitation in Android system, we have no proper solution yet for this at present.

  • On Android prior to 8.0, if the original notification has delete intent, it is triggered when the notification is evolved (due to the removal for substitution). This may have side effect on the notification behaviors of the originating app. Please test it carefully in decorator development.

  • Notification can only be altered, but not removed by 3rd-party decorators at present. It's a design choice to prevent notification loss caused by bugs or mis-configured settings in decorators. If you have different opinion on this decision, please feel free to discuss with us in issue tracker.

Write an Effective Decorator

TODO