Skip to content

Commit

Permalink
WIP: modules/android-integration: termux-wake-lock and termux-wake-un…
Browse files Browse the repository at this point in the history
…lock
  • Loading branch information
t184256 committed Jul 6, 2024
1 parent 2a3385f commit 874c805
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 5 deletions.
23 changes: 23 additions & 0 deletions modules/environment/android-integration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ in
'';
};

termux-wake-lock.enable = lib.mkOption {
type = lib.types.bool;
default = false;
example = "true";
description = lib.mdDoc ''
Provide a `termux-wake-lock` command
that tones down Android power saving measures.
This is the same action that's available from the notification.
'';
};

termux-wake-unlock.enable = lib.mkOption {
type = lib.types.bool;
default = false;
example = "true";
description = lib.mdDoc ''
Provide a `termux-wake-unlock` command
that undoes the effect of the `termux-wake-lock` one.
'';
};

xdg-open.enable = lib.mkOption {
type = lib.types.bool;
default = false;
Expand Down Expand Up @@ -91,6 +112,8 @@ in
(ifD cfg.termux-setup-storage.enable termux-tools.setup_storage) ++
(ifD cfg.termux-open.enable termux-tools.open) ++
(ifD cfg.termux-open-url.enable termux-tools.open_url) ++
(ifD cfg.termux-wake-lock.enable termux-tools.wake_lock) ++
(ifD cfg.termux-wake-unlock.enable termux-tools.wake_unlock) ++
(ifD cfg.xdg-open.enable termux-tools.xdg_open) ++
(ifD cfg.unsupported.enable termux-tools.out);
};
Expand Down
18 changes: 14 additions & 4 deletions pkgs/android-integration/termux-tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ stdenvNoCC.mkDerivation rec {
--replace @TERMUX_HOME@ /data/data/com.termux.nix/files/home/ \
--replace @TERMUX_APP_PACKAGE@ com.termux.nix
substituteInPlace scripts/termux-open.in \
--replace @[email protected] com.termux.app \
--replace @TERMUX_APP_PACKAGE@ com.termux.nix \
--replace 'getopt ' '${getopt}/bin/getopt '
substituteInPlace \
scripts/termux-open.in \
scripts/termux-wake-lock.in \
scripts/termux-wake-unlock.in \
--replace @[email protected] com.termux.app \
--replace @TERMUX_APP_PACKAGE@ com.termux.nix
${gnused}/bin/sed -i 's|^am |${termux-am}/bin/am |' scripts/*
rm -r doc # manpage is half misleading, pulling pandoc is not worth it
Expand All @@ -49,6 +53,8 @@ stdenvNoCC.mkDerivation rec {
"setup_storage" # termux-setup-storage
"open" # termux-open
"open_url" # termux-open-url
"wake_lock" # termux-wake-lock
"wake_unlock" # termux-wake-unlock
"xdg_open" # xdg-open
];
postInstall = ''
Expand Down Expand Up @@ -88,6 +94,12 @@ stdenvNoCC.mkDerivation rec {
mkdir -p $open_url/bin
mv $out/bin/termux-open-url $open_url/bin/
mkdir -p $wake_lock/bin
mv $out/bin/termux-wake-lock $wake_lock/bin/
mkdir -p $wake_unlock/bin
mv $out/bin/termux-wake-unlock $wake_unlock/bin/
mkdir -p $xdg_open/bin
rm $out/bin/xdg-open
ln -s $open/bin/termux-open $xdg_open/bin/xdg-open
Expand All @@ -98,8 +110,6 @@ stdenvNoCC.mkDerivation rec {
echo ./bin >> expected
echo ./bin/termux-backup >> expected # entirely untested
echo ./bin/termux-reload-settings >> expected # good candidate for fixing
echo ./bin/termux-wake-lock >> expected # good candidate for fixing
echo ./bin/termux-wake-unlock >> expected # good candidate for fixing
echo ./share >> expected
echo ./share/examples >> expected
echo ./share/examples/termux >> expected
Expand Down
35 changes: 34 additions & 1 deletion tests/emulator/android_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

def run(d):
OPENERS = ['termux-open', 'termux-open-url', 'xdg-open']
TOOLS = ['am', 'termux-setup-storage'] + OPENERS
TOOLS = ['am', 'termux-setup-storage',
'termux-wake-lock', 'termux-wake-unlock'] + OPENERS

nod = bootstrap_channels.run(d)

Expand Down Expand Up @@ -96,3 +97,35 @@ def run(d):
d.ui.press('back')
screenshot(d, f'{opener}-back')
wait_for(d, f'{opener} https://example.org')

# test termux-wake-lock/termux-wake-unlock
d.ui.open_notification()
screenshot(d, 'notification-opened')
d.ui(text='Nix').right(resourceId='android:id/expand_button').click()
screenshot(d, 'notification-expanded')
wait_for(d, 'Acquire wakelock')
screenshot(d, 'wakelock-initially-not-acquired')
d.ui.press('back')

d('input text "termux-wake-lock"')
d.ui.press('enter')
screenshot(d, 'wake-lock-command')
d.ui.open_notification()
screenshot(d, 'notification-opened')
wait_for(d, '(wake lock held)')
d.ui(text='Nix').right(resourceId='android:id/expand_button').click()
screenshot(d, 'notification-expanded')
wait_for(d, 'Release wakelock')
screenshot(d, 'notification-with-wakelock')
d.ui.press('back')

d('input text "termux-wake-unlock"')
d.ui.press('enter')
screenshot(d, 'wake-unlock-command')
d.ui.open_notification()
screenshot(d, 'notification-opened')
d.ui(text='Nix').right(resourceId='android:id/expand_button').click()
screenshot(d, 'notification-expanded')
wait_for(d, 'Acquire wakelock')
screenshot(d, 'notification-without-wakelock')
d.ui.press('back')
6 changes: 6 additions & 0 deletions tests/on-device/config-android-integration.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ load lib
run ! command -v termux-setup-storage
run ! command -v termux-open
run ! command -v termux-open-url
run ! command -v termux-wake-lock
run ! command -v termux-wake-unlock
run ! command -v xdg-open
run ! command -v termux-backup

Expand All @@ -20,6 +22,8 @@ load lib
command -v termux-setup-storage
command -v termux-open
command -v termux-open-url
command -v termux-wake-lock
command -v termux-wake-unlock
command -v xdg-open
run ! command -v termux-backup

Expand All @@ -32,6 +36,8 @@ load lib
command -v termux-setup-storage
command -v termux-open
command -v termux-open-url
command -v termux-wake-lock
command -v termux-wake-unlock
command -v xdg-open
command -v termux-backup

Expand Down
2 changes: 2 additions & 0 deletions tests/on-device/config-android-integration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ _:
termux-open.enable = true;
termux-open-url.enable = true;
termux-setup-storage.enable = true;
termux-wake-lock.enable = true;
termux-wake-unlock.enable = true;
xdg-open.enable = true;
# unsupported.enable = false;
};
Expand Down

0 comments on commit 874c805

Please sign in to comment.