Skip to content
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

Master on/off not working #130

Closed
leoauri opened this issue Mar 19, 2017 · 23 comments
Closed

Master on/off not working #130

leoauri opened this issue Mar 19, 2017 · 23 comments
Labels
Milestone

Comments

@leoauri
Copy link

leoauri commented Mar 19, 2017

Hi there,
Maybe related to #128 (also began with 2.10.0 on Fairphone 1 (although Android 4.2.2), but not resolved with 2.10.1 update)

The timer is switching the filter on and off successfully but the master switch does not turn the filter on or deactivate it when the timer has activated it.
Peculiar is that adjustment of the filter settings temporarily adds the overlay until the slider is released, whether the master switch is on or off.

Reinstalling hasn't solved this.

Great app and thank you

@smichel17
Copy link
Member

Quoting myself from #126:

In the current version, if Red Moon is off*, the service is not running**.
The switch does what the floating button used to do.

*means the same thing as "if the filter is off" used to mean. See #121 for more info.

**One exception: if the app is open, the service is running, so that the preview will start up faster, and to fix issues that could occur if the app got killed while it was running.


The switch was originally supposed to be a master switch. If it's off, Red Moon is guaranteed to be completely disabled. Like the switch on a power strip, or on the back of a desktop computer.

But, behind the scenes, it didn't actually do much. If the filter was off, the service was probably stopped too, even when the switch was on. The switch only really did two things:

  • Allow you to easily disable and enable the timer while preserving your settings
    • This was useful.
  • Prevent you from manually turning on the timer
    • This was not useful and confusing to new users

Now that the timer settings are on their own page, there is a way to easily turn it off, so there wasn't much of a reason to keep the "master switch" functionality around, since all it did was hide the floating button and stop widgets from working (and it made the code more complicated than it needed to be).

@smichel17
Copy link
Member

Ah, I think I might have misread you. I thought this was about the switch functionality changing, but you are saying the new functionality is not working (ie, you cannot get the filter to turn on at all), correct?

Can you turn on the filter via a home screen widget?

@leoauri
Copy link
Author

leoauri commented Mar 19, 2017

Right, the master switch does not function as the floating button used to...
It mostly does nothing, and occasionally the expected behaviour as you describe...

@leoauri
Copy link
Author

leoauri commented Mar 19, 2017

Home screen widget works as expected!

@leoauri
Copy link
Author

leoauri commented Mar 19, 2017

logcat while toggling master switch, are these entries interesting?

I/AP_PROF (  567): unable to open /proc/mtprof/status entry
I/PowerManagerService(  567): setBrightness mButtonLight 0.
I/AP_PROF (  567): unable to open /proc/mtprof/status entry
I/PowerManagerService(  567): setBrightness mButtonLight 0.

@smichel17
Copy link
Member

The relevant entries will be marked with one of MainActivity, ScreenFilterService, or ScreenFilterPresenter.

@smichel17
Copy link
Member

While any logs from those 3 are probably helpful, the three most relevant are:

  • two from the service starting with "onStartCommand" and "Received flag"
  • one from the presenter starting with "Handling command"

@leoauri
Copy link
Author

leoauri commented Mar 19, 2017

Update: behaviour works as expected with the icon widget version.
With the play/pause button version, it toggled the filter off on the first press, then didn't work for several keypresses, then started working as expected.

@smichel17
Copy link
Member

The switch in the app does toggle using a slightly different method than all of the widgets, but it should end up triggering the same actions.

Can you check if the timer works? It uses the same method as the switch.

@leoauri
Copy link
Author

leoauri commented Mar 20, 2017

The timer seems to work without fail!

smichel17 added a commit that referenced this issue Mar 20, 2017
@smichel17
Copy link
Member

smichel17 commented Mar 20, 2017

I added a little more logging to help debug this in the next release (2.10.2 should be soon).

@leoauri
Copy link
Author

leoauri commented Mar 20, 2017

Output of adb logcat MainActivity:V ScreenFilterService:V ScreenFilterPresenter:V *:S

Toggling filter with widget (works):

I/ScreenFilterService(17736): onCreate
I/ScreenFilterPresenter(17736): Handling command OFF in state: InitState
I/ScreenFilterPresenter(17736): Transitioning from InitState to OffState
I/ScreenFilterPresenter(17736): super(OffState).onActivation(InitState)
I/ScreenFilterPresenter(17736): Setting brightness to: 0, automatic: false
I/ScreenFilterPresenter(17736): Stopping app monitoring
I/ScreenFilterService(17736): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 1
I/ScreenFilterService(17736): Recieved flag: 6
I/ScreenFilterPresenter(17736): Handling command TOGGLE in state: OffState
I/ScreenFilterPresenter(17736): Transitioning from OffState to OnState
I/ScreenFilterPresenter(17736): super(OnState).onActivation(OffState)
I/ScreenFilterPresenter(17736): Sending update broadcast
I/ScreenFilterPresenter(17736): Filter is turning on again; don't close it.
I/ScreenFilterPresenter(17736): Filter is turning on again; don't close it.
I/ScreenFilterPresenter(17736): Setting brightness to: 0, automatic: false
I/ScreenFilterPresenter(17736): Starting app monitoring
I/ScreenFilterService(17736): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 2
I/ScreenFilterService(17736): Recieved flag: 5
I/ScreenFilterPresenter(17736): Handling command STOP_SUSPEND in state: OnState
I/ScreenFilterService(17736): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 3
I/ScreenFilterService(17736): Recieved flag: 5
I/ScreenFilterPresenter(17736): Handling command STOP_SUSPEND in state: OnState
I/ScreenFilterService(17736): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 4
I/ScreenFilterService(17736): Recieved flag: 5
I/ScreenFilterPresenter(17736): Handling command STOP_SUSPEND in state: OnState
I/ScreenFilterService(17736): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 5
I/ScreenFilterService(17736): Recieved flag: 5
I/ScreenFilterPresenter(17736): Handling command STOP_SUSPEND in state: OnState
I/ScreenFilterService(17736): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 6
I/ScreenFilterService(17736): Recieved flag: 5
I/ScreenFilterPresenter(17736): Handling command STOP_SUSPEND in state: OnState
I/ScreenFilterService(17736): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 7
I/ScreenFilterService(17736): Recieved flag: 6
I/ScreenFilterPresenter(17736): Handling command TOGGLE in state: OnState
I/ScreenFilterPresenter(17736): Transitioning from OnState to OffState
I/ScreenFilterPresenter(17736): super(OffState).onActivation(OnState)
I/ScreenFilterPresenter(17736): Sending update broadcast
I/ScreenFilterPresenter(17736): Setting brightness to: 0, automatic: false
I/ScreenFilterPresenter(17736): Stopping app monitoring
I/ScreenFilterService(17736): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 8
I/ScreenFilterService(17736): Recieved flag: 5
I/ScreenFilterPresenter(17736): Handling command STOP_SUSPEND in state: OffState
I/ScreenFilterService(17736): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 9
I/ScreenFilterService(17736): Recieved flag: 5
I/ScreenFilterPresenter(17736): Handling command STOP_SUSPEND in state: OffState
I/ScreenFilterService(17736): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 10
I/ScreenFilterService(17736): Recieved flag: 5
[...]
I/MainActivity(17736): Got intent
[...]

Toggling the master switch just keeps giving the same kind of

...
I/ScreenFilterService(17736): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 45
I/ScreenFilterService(17736): Recieved flag: 5
I/ScreenFilterPresenter(17736): Handling command STOP_SUSPEND in state: OffState
I/ScreenFilterService(17736): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 46
I/ScreenFilterService(17736): Recieved flag: 5
I/ScreenFilterPresenter(17736): Handling command STOP_SUSPEND in state: OffState
I/ScreenFilterService(17736): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 47
I/ScreenFilterService(17736): Recieved flag: 5
I/ScreenFilterPresenter(17736): Handling command STOP_SUSPEND in state: OffState
I/ScreenFilterService(17736): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 48
I/ScreenFilterService(17736): Recieved flag: 5
I/ScreenFilterPresenter(17736): Handling command STOP_SUSPEND in state: OffState
I/ScreenFilterService(17736): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 49
I/ScreenFilterService(17736): Recieved flag: 5
I/ScreenFilterPresenter(17736): Handling command STOP_SUSPEND in state: OffState
I/ScreenFilterService(17736): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 50
I/ScreenFilterService(17736): Recieved flag: 5
I/ScreenFilterPresenter(17736): Handling command STOP_SUSPEND in state: OffState
...

@smichel17
Copy link
Member

smichel17 commented Mar 20, 2017

It looks like the command to stop/stop is not getting received. I don't know if it's an issue with transmission to the service or if the switch is not registering your touch correctly; we'll need the new debug output for that.

All the

I/ScreenFilterService(17736): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 49
I/ScreenFilterService(17736): Recieved flag: 5
I/ScreenFilterPresenter(17736): Handling command STOP_SUSPEND in state: OffState

comes from the Pause in secure apps feature, so you can get cleaner logs if you disable it.

@smichel17
Copy link
Member

@leoauri I believe v2.10.2 is out now

@leoauri
Copy link
Author

leoauri commented Apr 19, 2017

on 2.10.2
adb logcat MainActivity:V ScreenFilterService:V ScreenFilterPresenter:V *:S
activate and deactivate filter via in-app switch, log output null
widget shows a stop sign, although filter is inactive
tap widget, filter is activated, stop sign remains, log output:

I/ScreenFilterService( 5678): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 2
I/ScreenFilterService( 5678): Recieved flag: 6
I/ScreenFilterPresenter( 5678): Handling command TOGGLE in state: OffState
I/ScreenFilterPresenter( 5678): Transitioning from OffState to OnState
I/ScreenFilterPresenter( 5678): super(OnState).onActivation(OffState)
I/ScreenFilterPresenter( 5678): Sending update broadcast

In-app switch still no effect or log output
Tap widget, filter deactivated, widget shows a play symbol, log output:

I/ScreenFilterService( 5678): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 3
I/ScreenFilterService( 5678): Recieved flag: 6
I/ScreenFilterPresenter( 5678): Handling command TOGGLE in state: OnState
I/ScreenFilterPresenter( 5678): Transitioning from OnState to OffState
I/ScreenFilterPresenter( 5678): super(OffState).onActivation(OnState)
I/ScreenFilterPresenter( 5678): Sending update broadcast

Although filter is now deactivated, dragging the dim level dragbar temporatily activates the filter and outputs:

I/ScreenFilterService( 5678): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 4
I/ScreenFilterService( 5678): Recieved flag: 2
I/ScreenFilterPresenter( 5678): Handling command SHOW_PREVIEW in state: OffState
I/ScreenFilterPresenter( 5678): Transitioning from OffState to PreviewState
I/ScreenFilterPresenter( 5678): super(PreviewState).onActivation(OffState)
I/ScreenFilterService( 5678): onStartCommand(Intent { cmp=com.jmstudios.redmoon/.service.ScreenFilterService (has extras) }, 0, 5
I/ScreenFilterService( 5678): Recieved flag: 3
I/ScreenFilterPresenter( 5678): Handling command HIDE_PREVIEW in state: PreviewState
I/ScreenFilterPresenter( 5678): Transitioning from PreviewState to OffState
I/ScreenFilterPresenter( 5678): super(OffState).onActivation(PreviewState)

...I guess this is design...

@smichel17
Copy link
Member

smichel17 commented Apr 20, 2017

@leoauri I have a suspicion about what is causing this. I added a couple more logs; could you try building from 4e24436 (the switchlogging branch)? If you'd prefer not to build yourself, I put a debug build up here: http://smichel.me/files/red-moon/red-moon-debug-extra_switch_logging.apk

If my hunch is right, that version of the app will crash when you try to use the master switch. It'll produce useful debug logs even if it doesn't crash.

I probably should have added these from the start; sorry for asking you to get logs multiple times.

@leoauri
Copy link
Author

leoauri commented Apr 21, 2017

No problem, this is fun

First I opened the debug version, toggled the switch, no crash.

This was in the log when I opened it:

--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
I/MainActivity(24333): Got intent
I/MainActivity(24333): switch: android.widget.Switch{424cccb8 VFED..C. ......ID 0,0-0,0 #7f0f00a8 app:id/switch_for_action_bar}, listener set? false
I/MainActivity(24333): Setting switch on click listener
I/MainActivity(24333): mSwitch: android.widget.Switch{424cccb8 VFED..C. ......ID 0,0-0,0 #7f0f00a8 app:id/switch_for_action_bar}, listener set? true
I/MainActivity(24333): switch: android.widget.Switch{42332e90 VFED..C. ......ID 0,0-0,0 #7f0f00a8 app:id/switch_for_action_bar}, listener set? false
I/MainActivity(24333): Setting switch on click listener
I/MainActivity(24333): mSwitch: android.widget.Switch{42332e90 VFED..C. ......ID 0,0-0,0 #7f0f00a8 app:id/switch_for_action_bar}, listener set? true

Switched master on again:

I/MainActivity(24333): switch: android.widget.Switch{428a4730 VFED..C. ......ID 0,0-0,0 #7f0f00a8 app:id/switch_for_action_bar}, listener set? false
I/MainActivity(24333): Setting switch on click listener
I/MainActivity(24333): mSwitch: android.widget.Switch{428a4730 VFED..C. ......ID 0,0-0,0 #7f0f00a8 app:id/switch_for_action_bar}, listener set? true

Switching off produced no log.

smichel17 added a commit that referenced this issue Apr 22, 2017
@smichel17
Copy link
Member

smichel17 commented Apr 22, 2017

That's really bizzare. The click listener is being set correctly, but the system is not calling it on click.

Try http://smichel.me/files/red-moon/red-moon-debug-switch_fix_attempt_1.apk (built from 6d6566a), which reverts the only other change I can find since 2.9.2. According to the API reference, I shouldn't need SwitchCompat to set an onClickListener, but maybe something is broken and not documented (or is broken because putting a switch in the top bar is not a standard behavior).

If that doesn't work, I'll just give up on fixing the switch and make it a floating button again.

@smichel17
Copy link
Member

If that doesn't work, I'll just give up on fixing the switch and make it a floating button again.

Actually, I'm considering doing this anyway, since we actually have menu options now.

@leoauri
Copy link
Author

leoauri commented Apr 25, 2017

6d6566a kind of works...!
If I tap the switch area, the switch toggles and the filter activates/deactivates..
If I drag the switch slider though, it is dragged into position but filter state isn't toggled... If I then tap the switch area, the switch remains in place and the filter state is toggled to match the switch.
Well, that's good enough for me :)

@smichel17
Copy link
Member

Right now the switch intentionally only responds to taps, not changes in position, in order to fix a different bug (below). I didn't realize dragging the switch was not considered a tap.

We need to toggle the position of the switch when Red Moon turns on (ie, because of the timer). The service that displays the filter can't currently distinguish the source of a signal telling it to turn on/off (widget vs switch vs timer), so if we made the switch respond to changes in position, it would cause an infinite loop.

There's another way to do it -- temporarily ignore changes in position -- that we used to do; I switched to the current method because it made the code much easier to understand. But there's been a lot of overall cleanup since then and I can do it the old way with much simpler code.

smichel17 added a commit that referenced this issue Apr 25, 2017
Also one where the filter would switch off instantly instead of
animating if stopped while it was turning on.
@smichel17 smichel17 added this to the v3.0.1 milestone Apr 25, 2017
@smichel17
Copy link
Member

@leoauri Should be fixed in master (built at http://smichel.me/files/red-moon/red-moon-debug-2017-04-25.apk).

@smichel17 smichel17 modified the milestones: v3.1.0, v3.0.1 Jun 30, 2017
@smichel17
Copy link
Member

I'm going to close this because I think we're ready for a release, whenever @raatmarien finds a bit of spare time to do one.

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

No branches or pull requests

2 participants