support for led notifications



  • [edit 2019/11/20] {
    Sorry I give up. I have working code but the automated tests fail. Unfortunately the testing framework is even more complicated then unity itself and the things it tests are trivial. I see no use in crafting dbus messages and plugins just to automatically 'test' a led turning white or green.

    Small advice: maintaining this test bed is too big a burden for a project this short of man power. I think you really should get rid of it.
    }

    I want to have the led on my phone show it is being charged or it's battery is full.
    One of the core developers on telegram pointed out that this could be done by extending repowerd. So I tried to do that.

    [edits] {
    2019/11/09 made a PR for unity8
    2019/11/07 I am now changing IndicatorsLight.qml. You can already try it. No need to build anything, just replace the qml file (keep a copy).
    }

    This is my first step in ubports and I have absolutely no clue of the architecture of ubports or the direction it is going into. So any development related reactions are welcome.

    What I did:
    Created a LightControl that does two things. Control the led (on/off/color etc) and manage the led. With managing I mean show a certain event charging, full, etc.
    The battery state is monitored by UPowerPowerSource. I made it pass the BatteryInfo in its changed callback and have DefaultStateMachine pass it along.
    Furthermore DefaultStateMachine also notifies display on/off.
    Led styles are now hardcoded but could be made to use DeviceConfig.
    Currently the led is off when the display is on. It can show charging (white pulsing) and full (solid lime green).

    Choice to make

    • Currently the led shows dark green when a message is 'new'. This is handled by a qml file in Unity.
      There cannot be two captains on this ship so either Unity must take care of managing the led or repowerd. I opt for repowerd.
    • Should the led be controllable through dbus?

    Problems

    • I need information on how to know the state (or keep track of it) of pending new messages and missed calls.
    • I don't have sim card in my phone. How can I test 'pending new message'?

    My work can be found in the add-light branch of repo https://github.com/wdehoog/repowerd
    Development is done using cross-builder. I test it on my oneplus one.

    When interested to test see: https://gist.github.com/wdehoog/c7c09a792799d03e6880e10dbc19ab33

    PS.
    I have very strong feelings about the testing framework of repowerd. The COC probably forbids me to express them.



  • Hello and thanks for your motivation, it feels like you are highly motivated, so we want to get you onboard this train fast 😉

    Some high-level thoughts:

    • For a long time I was pondering the same idea roughly. I wanted to have information about bluetooth being on/discoverable so that you could remember to turn it off when not needed.
    • As you already found out, there is a use for the led as notifications indicator, this must not break! Its one of the core things that really works well 🙂
    • If you install a new authority for LED access, of course unity8 or whoever from that gang drives notifications LED now needs to backoff and we need to instead let him be a client for your component.
    • Your component does not need to track the state of messages, it should react on a request from Postal service to turn on or off this LED message class
    • Your component needs a hierarchy or alteration scheme for various LED message classes that have order of importance like:
    1. (highest) Battery low
    2. Unread notifications
    3. Bluetooth enabled
    4. (Lowest) Charging/Fully charged - those are exclusive and therefore in the same slot

    OR:

    • Have a mechanism of rotation of LED states: Each slot will be visible for x seconds - But it could get irritating for the users, so I am not sure about it

    • You can even without SIM card trigger notifications - just install TELEports App, register a Telegram account on another device and let some messages arrive. OR use FluffyChat with a matrix account. Both will work without SIM card needed.



  • @Flohack said in support for led notifications:

    You can even without SIM card trigger notifications - just install TELEports App, register a Telegram account on another device and let some messages arrive. OR use FluffyChat with a matrix account. Both will work without SIM card needed.

    You can also use Dekko too for your emails... I have activated push imap and the notifications are fast (no need to wait 5-30 minutes for a test 😄



  • @Flohack Thanks for your warm welcome. Not sure if I will come onboard. I am more of a drive-by developer but lets see how it rolls.

    Thanks for pointing me to the Postal service. If I understand you correctly you think that it is best if this Light thinghy can be notified by dbus of certain states/changes (pending messages, bluetooth discoverability, battery low)?

    Wouldn't that cause modification of lots of services/stuff to become aware if this new led controller? I am trying to keep the changes more in one place.

    Above all do you agree with the approach of having this 'led authority' as you call it, located in repowerd?



  • @wdehoog Yeah lets see how this rolls ^^

    • Well no I am not concerned that this will cause many changes: LED is currently only used by notifications, and this is already centralized, so its one place to change. I agree on the DBus architecture as it is the most commonly used thing for IPC in UT.
    • I forgot one thing: All LED message classes should be configureable via system settings, so your addon to repowerd also needs to be able to remember what the user has turned on and what not. Otherwise I can hear already the many voices complaining that they cannot turn off x ^^


  • @Flohack said in support for led notifications:

    I forgot one thing: All LED message classes should be configureable via system settings, so your addon to repowerd also needs to be able to remember what the user has turned on and what not. Otherwise I can hear already the many voices complaining that they cannot turn off x ^^

    This would be outside the scope of repowerd handling of the hardware itself, I think. Instead, for notifications level configuration, this would be handled by the code which handles notifications, and then requests the LED to be set to a color or whatever.

    Anyway, I also think we shouldn't let any configuration possibilities get too out of hand. More configuration means more problems.



  • @dobey Well we can put it into a separate component, but the entry barrier will be higher, it would be a standalone service, or would you put it into Postal or such? Anyways, if we want to have morethan one meaning for the LED we need something that holds this state of alternatives. Putting it into repowerd might be not the most elegant way but its a scope that a single dev can handle probably.



  • @Flohack Well, as a comparison, the Power and Volume keys have multiple meanings, and all those meanings are not handled by repowerd. It only deals with the hardware, and unity8 decides whether the screen should be turned off, the reboot menu should be opened, volume should be changed, or a screenshot taken.

    Likewise, repowerd should only handle the direct interaction with the LED hardware. It shouldn't manage itself what needs the LED is being used for; only handle the requests from above to set the state to on, off, blinking, pulsing, and what color it should be; and maybe deal with conflicts if multiple things want to set the state.

    As for notifications, this is another area of the system that has long needed much refactoring and consolidation. Currently it's all spread across multiple components and is quite a mess. "Better LED handling for things" is as good a reason as any to start getting things cleaned up there as well. For an immediate solution, keeping the same LED usage and simply moving the core hardware interaction into repowerd with unity8 asking it to turn the LED on and off, rather than doing itself, is the way forward. Then a little more refactoring could be done to enable charging status along with the current generic notifications usage. And then more from there later on.



  • @dobey @Flohack
    repowerd seems to do more then handling hardware. It contains a class DefaultStateMachine that also keeps track of state and for example takes care of the display dimming and turing off.
    It also knows about the battery state. For the proposed led states (charging/low/full/bt/notifications) repowerd seems like a good place for now.

    unity currently detects unread notifications by checking if a dbus signal (Changed) contains a "message" part with an "icon" field with a string containing "indicator-messages-new". When the display is off it sets the led. I guess repowerd can also listen to this signal.

    I'll gladly move the led stuff stuff somewhere else but the current unity place (qml\Panel\Indicators\IndicatorsLight.qml) feels like the wrong one. A friend of mine (owned a ut-phone) suggested the lockscreen should manage the led state.

    If it is decided that the led indicator is usefull and should be part of ubports then indeed configurability should not be overdone. Some already existing config file would allow things to be disabled if really needed.



  • @wdehoog said in support for led notifications:

    It contains a class DefaultStateMachine that also keeps track of state and for example takes care of the display dimming and turing off.

    Yes, repowerd is the thing which tells the hardware what to do here. It is the implementation for such pieces of hardware interaction. It is not where policy is decided though. It is simply told when the display should be dimmed or powered off, when an alarm event should be triggered, etc… It is itself not a full stack.

    @wdehoog said in support for led notifications:

    I guess repowerd can also listen to this signal.

    No, repowerd should not implement any part of indicator rendering.

    @wdehoog said in support for led notifications:

    I'll gladly move the led stuff stuff somewhere else but the current unity place (qml\Panel\Indicators\IndicatorsLight.qml) feels like the wrong one

    It may not be the right place, but it is a sufficient one for now. There's no need to move the "should the LED be enabled, and how" to somewhere else. The only part that should be moved to repowerd is the part that actually turns the LED on, off, blinks/pulses it, and such. It should not do more than that.

    @wdehoog said in support for led notifications:

    A friend of mine (owned a ut-phone) suggested the lockscreen should manage the led state.

    Friends and users do not developers make. The lock screen is definitely the wrong place. The current location is fine for the level of refactoring which needs to be done now, to achieve what you want. There's no need to grow things beyond their need yet.

    @wdehoog said in support for led notifications:

    If it is decided that the led indicator is usefull and should be part of ubports then indeed configurability should not be overdone. Some already existing config file would allow things to be disabled if really needed.

    There is no need to worry about this level of configuration yet, to achieve the immediate goal of charging/charged LED status.



  • @dobey
    So repowerd will listen on dbus to set the led on/off state, color and pulse rate.
    Unity will decide if and how the led should shine.

    Now the thing is repowerd already knows about the battery state and the display state.
    So I think part of the policy could best be done in repowerd:

    • only show the led when the display is off
    • indicate battery low (or hot?)
    • if no other state for the led is set then show charging/full
      unity will then set the led state regarding unread messages, bluetooth or whatever comes next

    But I am new here so you I'll follow your advice.

    The order would then be

    • move led hardware control to repowerd.
    • Allow the led state to be controlled through dbus.
    • Let unity use the led using dbus (extend Powerd plugin, remove Lights plugin).
    • Add led indication of battery state low/charging/full.
      Question is where should this be done and how does it get the battery info?

Log in to reply