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

[Android] add Keep screen awake toggle #4428

Merged
merged 1 commit into from Jan 10, 2019

Conversation

Projects
None yet
5 participants
@pazos
Copy link
Contributor

pazos commented Dec 29, 2018

continuation of #4409 , which I managed to close somehow, sorry :p

Fixes #2748
Fixes #4364
Related to #4430 #3567 #3517

In some phones some runtime configuration changes will force a surfaceDestroyed (followed by surfaceCreate) without losing/regain focus, so we need to refresh the screen on APP_CMD_INIT_WINDOW too. This will help on further "black screen issues"

More info: https://developer.nvidia.com/fixing-common-android-lifecycle-issues-games

@pazos pazos requested a review from Frenzie Dec 29, 2018

@pazos

This comment has been minimized.

Copy link
Contributor Author

pazos commented Dec 29, 2018

Tested on MotoG5S with android 7.1 (the device which showed the black screen issue) and on a couple of other unaffected devices. Works nice on all of them.

@Frenzie

This comment has been minimized.

Copy link
Member

Frenzie commented Dec 29, 2018

You know you can reopen it, right? :-P

this.device.screen:refreshFull()
elseif ev.code == C.APP_CMD_WINDOW_REDRAW_NEEDED then
elseif ev.code == C.APP_CMD_GAINED_FOCUS
or ev.code == C.APP_CMD_INIT_WINDOW

This comment has been minimized.

@Frenzie

Frenzie Dec 29, 2018

Member

I wonder if this might also fix the other issue with the brightness level.

This comment has been minimized.

@pazos

pazos Dec 29, 2018

Author Contributor

Hopefully 👍

@pazos

This comment has been minimized.

Copy link
Contributor Author

pazos commented Dec 29, 2018

Uh oh, I guess that we need to restore the flag on init if G_reader_settings:isTrue("keep_screen_on") to allow starting w/ last saved state.

@pazos

This comment has been minimized.

Copy link
Contributor Author

pazos commented Jan 9, 2019

Updated to use android.setWakelock. Requires koreader/android-luajit-launcher#90

Can be logcated with adb logcat KOReader:V luajit-launcher:V *:S | grep wakelock

Result:

01-09 18:19:18.996 26640 26640 V luajit-launcher: Acquiring wakelock
01-09 18:19:32.400 26640 26653 V KOReader: Switching wakelock to false
01-09 18:19:32.400 26640 26653 V luajit-launcher: Releasing wakelock
01-09 18:19:37.600 26640 26640 V luajit-launcher: Releasing wakelock
01-09 18:19:47.609 26640 26653 V KOReader: Switching wakelock to false
01-09 18:19:47.610 26640 26653 V luajit-launcher: Releasing wakelock
01-09 18:19:47.610 26640 26640 V luajit-launcher: Acquiring wakelock
01-09 18:20:09.769 26640 26640 V luajit-launcher: Releasing wakelock
01-09 18:20:13.082 26640 26640 V luajit-launcher: Acquiring wakelock
01-09 18:20:13.083 26640 26653 V KOReader: Switching wakelock to false
01-09 18:20:13.083 26640 26653 V luajit-launcher: Releasing wakelock
01-09 18:20:28.494 26640 26640 V luajit-launcher: Releasing wakelock

@pazos pazos force-pushed the pazos:keep_awake branch 2 times, most recently from 3b71f98 to ef891b9 Jan 10, 2019

@pazos

This comment has been minimized.

Copy link
Contributor Author

pazos commented Jan 10, 2019

@Frenzie ready for review, again.

It would be nice to release this asap and see what happens with those crashy e-ink readers.

Do we need a wiki/doc entry for this change?

@@ -60,6 +60,11 @@ function Device:init()
self.isTouchDevice = yes
end

-- check if we disabled support for wakelocks
if G_reader_settings:isTrue("disable_wakelock") then

This comment has been minimized.

@Frenzie

Frenzie Jan 10, 2019

Member

Since the setting is Android-specific, should we make that clear in the setting name? Pinging @poire-z

This comment has been minimized.

@poire-z

poire-z Jan 10, 2019

Contributor

I wouldn't mind, as only Android would get that setting. But disable_android_wakelock sounds explicite. Or use_android_wakelocks=false

This comment has been minimized.

@Frenzie

Frenzie Jan 10, 2019

Member

Yeah, let's go for disable_android_wakelock. 👍

@rola25

This comment has been minimized.

Copy link

rola25 commented Jan 10, 2019

I own a Tolino Epos and could test the release when it is ready. I already tried it with "Wake Lock PowerManager", but this didn't work (still no refreshes in koreader) :-(

@Frenzie

This comment has been minimized.

Copy link
Member

Frenzie commented Jan 10, 2019

@pazos Please rebase & merge after the final change. :-)

@pazos pazos force-pushed the pazos:keep_awake branch from ef891b9 to 2adce49 Jan 10, 2019

@pazos pazos merged commit 2009ffa into koreader:master Jan 10, 2019

1 check passed

ci/circleci Your tests passed on CircleCI!
Details

@pazos pazos deleted the pazos:keep_awake branch Jan 10, 2019

@pazos

This comment has been minimized.

Copy link
Contributor Author

pazos commented Jan 10, 2019

@rola25:

You can help even when the device doesn't refresh at all (once this PR hits nightlies).

You will need adb installed and following the instructions

  1. check if you can see your device with adb devices
  2. clear old adb logs with adb logcat -c
  3. uninstall KOReader app and install it again.
  4. Launch KOReader, wait at least 15 seconds without touching the screen.
  5. Do a few touches here and there. Wait another few seconds
  6. Do a final touch.
  7. generate a logfile with adb logcat KOReader:V luajit-launcher:V *:S -d > log.txt
  8. Share the log.txt file here.

Also I'm interested in getting a list of vendor/sytem libraries. Which can be done with

adb shell 'find /system' and adb shell 'ls /vendor/lib'

@rola25

This comment has been minimized.

Copy link

rola25 commented Jan 11, 2019

OK no prob. As soon as the .apk is available I will test it

@rola25

This comment has been minimized.

Copy link

rola25 commented Jan 11, 2019

In the meanwhile - here are the system files (no /vendor)

system.txt

@rola25

This comment has been minimized.

Copy link

rola25 commented Jan 11, 2019

And here the logcat from the old version ...

There was no refresh when using the file manager but there was one refresh when I swiped down to view the menu.

log.txt

And this one when book was already open, I tried to change pages - there was no refresh at all

log2.txt

@pazos

This comment has been minimized.

Copy link
Contributor Author

pazos commented Jan 12, 2019

@rola25: aweeeeesome, thanks!

Would you mind to share /system/lib/libepd.so? This is the electronic paper display library, used by some obscure frameworks to refresh the screen. I want to take a look.

BTW, the nightly with wakelocks support is online. You can test it if you want 👍

@rola25

This comment has been minimized.

Copy link

rola25 commented Jan 13, 2019

Hi
Here ist libepd.so.
I tried the new nightly, but it still doesn't refresh. I also set the ["disable_android_wakelock"] = true option in settings.reader.lua.

Tomorrow I will do some more debugging and log-uploading.

libepd.zip

@pazos

This comment has been minimized.

Copy link
Contributor Author

pazos commented Jan 13, 2019

@rola25: thanks again.

The good news are that your device is using an "standard" way of updating the screen: via Java_de_telekom_epub_utils_ScreenHelper

cf: https://www.mobileread.com/forums/showpost.php?p=2700529&postcount=185

The bad news are that you need to wait a few weeks/months/years until somebody implements those methods in KOReader.

Tomorrow I will do some more debugging and log-uploading.

If you wait a couple of days the log will be more valuable (it will provide your device model) and we can use that model to test further android e-ink aware implementations, since your device is currently unusable with ko.

00001f9d T Java_com_android_internal_policy_impl_PhoneWindowManager_FullRefresh
00002145 T Java_com_android_internal_policy_impl_PhoneWindowManager_getFBDoneRender
0000210d T Java_com_android_internal_policy_impl_PhoneWindowManager_setWantToCheckFBState
0000240d T Java_com_android_server_PowerManagerService_BlankFullRefresh
00001f9d T Java_com_android_server_PowerManagerService_FullRefresh
00002145 T Java_com_android_server_PowerManagerService_getFBDoneRender
00001f45 T Java_com_android_server_PowerManagerService_GetSleeping
00001eed T Java_com_android_server_PowerManagerService_SetSleeping
0000210d T Java_com_android_server_PowerManagerService_setWantToCheckFBState
00002b71 T Java_com_android_server_PowerManagerService_ShowScreen
00001f9d T Java_com_ntx_msg_MsgPowerOffActivity_FullRefresh
00001f45 T Java_com_ntx_msg_MsgSuspendActivity_GetSleeping
00001eed T Java_com_ntx_msg_MsgSuspendActivity_SetSleeping
00002f55 T Java_de_telekom_epub_utils_ScreenHelper_DrawBitmapToFB
00001ff5 T Java_de_telekom_epub_utils_ScreenHelper_FullRefresh
00001bc9 T Java_de_telekom_epub_utils_ScreenHelper_GetScreen
00001f45 T Java_de_telekom_epub_utils_ScreenHelper_GetSleeping
000020b3 T Java_de_telekom_epub_utils_ScreenHelper_PartialRefresh
00003081 T Java_de_telekom_epub_utils_ScreenHelper_PostFB
000020bf T Java_de_telekom_epub_utils_ScreenHelper_RegionalRefresh
00002411 T Java_de_telekom_epub_utils_ScreenHelper_SetFBColor
00002433 T Java_de_telekom_epub_utils_ScreenHelper_SetFBColorArray
00002481 T Java_de_telekom_epub_utils_ScreenHelper_SetUpdateMode
00001f45 T Java_de_telekom_test1_MainActivity_GetSleeping
00001eed T Java_de_telekom_test1_MainActivity_SetSleeping
00002f55 T Java_de_telekom_testeink_ImageActivity_DrawBitmapToFB
0000305d T Java_de_telekom_testeink_ImageActivity_PostFB
000020bf T Java_de_telekom_testeink_ImageActivity_RegionalRefresh
000020bf T Java_de_telekom_test_TestActivity_RegionalRefresh
00002411 T Java_de_telekom_test_TestActivity_SetFBColor
00002433 T Java_de_telekom_test_TestActivity_SetFBColorArray
0000240d T Java_ntx_epd_EPDRefreshActivity_BlankFullRefresh
00001f9d T Java_ntx_epd_EPDRefreshActivity_FullRefresh
00002145 T Java_ntx_epd_EPDRefreshActivity_getFBDoneRender
00001f45 T Java_ntx_epd_EPDRefreshActivity_GetSleeping
000020b3 T Java_ntx_epd_EPDRefreshActivity_PartialRefresh
000020bf T Java_ntx_epd_EPDRefreshActivity_RegionalRefresh
00001eed T Java_ntx_epd_EPDRefreshActivity_SetSleeping
0000210d T Java_ntx_epd_EPDRefreshActivity_setWantToCheckFBState
00001f9d T Java_ntx_power_AlarmReceiver_FullRefresh
00002f55 T Java_ntx_PowerEnhance_DemoPreload_DrawBitmapToFB
0000305d T Java_ntx_PowerEnhance_DemoPreload_PostFB
00002fbd T Java_ntx_power_PowerManagerEx_QuickPostFB
00001f9d T Java_ntx_power_PowerMechanismService_FullRefresh
00002145 T Java_ntx_power_PowerMechanismService_getFBDoneRender
0000210d T Java_ntx_power_PowerMechanismService_setWantToCheckFBStat
@rola25

This comment has been minimized.

Copy link

rola25 commented Jan 14, 2019

OK thanks for info and debugging :-)
Just leave a comment here if/when you need new logs.

@NiLuJe

This comment has been minimized.

Copy link
Member

NiLuJe commented Jan 14, 2019

Barring that, that looks like an NTX board, so the Kobo framebuffer code could be repurposed, but it's potentially a bit messy because I have no idea how we handle the framebuffer on Android ^^.

@Frenzie

This comment has been minimized.

Copy link
Member

Frenzie commented Jan 14, 2019

It's similar to SDL in principle, but I never added regional updates to Android like I did on SDL (see koreader/koreader-base#626).

@pazos

This comment has been minimized.

Copy link
Contributor Author

pazos commented Jan 14, 2019

We cannot run code outside the VM on non rooted devices and even on rooted devices we will break SurfaceFlinger if we try to write directly to the framebuffer a la Linux.

BTW a friend lent me her Energy Pro 4 ereader for a few days. Device is based on RK chipset but hopefully the same logic can be applied to both freescale and rockchip devices. I will see what happens when I have a few spare hours :-)

@Frenzie

This comment has been minimized.

Copy link
Member

Frenzie commented Jan 14, 2019

@pazos Btw, you probably already saw, but just in case see this comment #3517 (comment) and the one right after #3517 (comment).

@NiLuJe

This comment has been minimized.

Copy link
Member

NiLuJe commented Jan 14, 2019

@pazos : Eh, I was afraid of that ;).

So, yeah, that leaves the potentially-device-specific-and-vendor-provided JNI "APIs"...

@pazos

This comment has been minimized.

Copy link
Contributor Author

pazos commented Jan 14, 2019

@Frenzie: thanks for the reminder, AFAICT every open implementation is based on http://forum.xda-developers.com/showthread.php?t=1183173.

I will look at relaunchx first since seems easier to understand: https://github.com/rychly/relaunchx/blob/rychly/master/app/src/main/java/com/gacode/relaunchx/N2EpdController.java

@Frenzie

This comment has been minimized.

Copy link
Member

Frenzie commented Jan 15, 2019

@pazos Thanks for the links. I was not aware of that.

@pazos

This comment has been minimized.

Copy link
Contributor Author

pazos commented Jan 16, 2019

It seems that I've got the worst device to test. Tolino has an ScreenHelper class to handle libepd.so, Nook has the great N2EpdController and onyx devices have a full sdk w/ imx6 & rk3026 targets.

The reader I have just does getWindow().getDecorView().invalidate(64526, 64526, 64526, 64526) to force a full e-ink refresh. Oh, and boyue devices are a real crap, software wise, with a bunch of loggers and misterious activities. I doubt if they're using a floppy disk as the internal storage since my write/reads are 2MB/s & 10MB/s.

So, in short: in order to add full screen eink updates we need to add various epd controllers, a la Coolreader. It is not possible to probe current device epd controller without testing one by one (has a Nook epd?, has a Tolino epd?, has an Onyx epd? is a boyue crap?). This is bad because the ideal solution would be probing epd in the frontend. But instead of this we need to keep lists of "compatible" devices w/ each method and call that method directly.

I'm sad...

@Frenzie

This comment has been minimized.

Copy link
Member

Frenzie commented Jan 16, 2019

Sad, but not entirely unexpected based on coolreader. :-)

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