taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

repro_config_change_db_ownership.py (4372B)


      1 # This file is part of GNU Taler
      2 # (C) 2026 Taler Systems S.A.
      3 #
      4 # GNU Taler is free software; you can redistribute it and/or modify it under the
      5 # terms of the GNU General Public License as published by the Free Software
      6 # Foundation; either version 3, or (at your option) any later version.
      7 #
      8 # GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
      9 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     10 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     11 #
     12 # You should have received a copy of the GNU General Public License along with
     13 # GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     14 """Reproducer: a configuration change locks the wallet out of its database.
     15 
     16 Changing the app's language restarts it, and the new instance cannot take the
     17 SQLite database while the one it replaced still holds it:
     18 
     19     code 7001, "could not acquire exclusive ownership of the wallet database;
     20                 another wallet process may still be using it"
     21 
     22 which lands the user on the Initialization error screen -- the whole app
     23 replaced by two export buttons and an invitation to retry that nothing on the
     24 screen can act on.
     25 
     26 It is a race between the dying and the starting process, so this tries a few
     27 times and reports how often it lost, rather than pretending it is certain.
     28 
     29     cd /opt/taler-sim/driver
     30     python3 ../findings/repro_config_change_db_ownership.py [emulator-5554] [attempts]
     31 
     32 Exits 0 when at least one attempt reaches the error screen.
     33 """
     34 
     35 from __future__ import annotations
     36 
     37 import sys
     38 import time
     39 from pathlib import Path
     40 
     41 sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver"))
     42 
     43 from device import Device  # noqa: E402
     44 from wallet import Wallet  # noqa: E402
     45 
     46 ERROR_SCREEN = (r"(?i)Initialization error|Initialisierungsfehler"
     47                 r"|error occurred while starting|Fehler aufgetreten")
     48 OWNERSHIP = r"(?i)exclusive ownership of the wallet database"
     49 
     50 
     51 def main() -> int:
     52     serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554"
     53     attempts = int(sys.argv[2]) if len(sys.argv) > 2 else 3
     54     dev = Device(serial)
     55     app = Wallet(dev)
     56 
     57     if dev.sdk_int < 33:
     58         print(f"this device is API {dev.sdk_int}; this reproducer changes the "
     59               "per-app language, which needs 33+.  The same defect should be "
     60               "reachable by changing the font size or the display size, which "
     61               "every version supports -- see the finding's table.")
     62         return 2
     63     broke = 0
     64     try:
     65         for n in range(1, attempts + 1):
     66             dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales", check=False)
     67             app.fresh_start(dev_mode=True)
     68             # Any screen will do; a settings sub-screen is where it was first
     69             # seen, and it keeps the wallet busy while the change lands.
     70             app.open_settings()
     71             app.scroll_to_text(r"(?i)^Contacts$", max_scrolls=12)
     72             dev.tap_text(r"(?i)^Contacts$", timeout=20)
     73             time.sleep(3)
     74 
     75             dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales de-DE",
     76                       check=False)
     77             time.sleep(9)
     78             screen = dev.dump()
     79             hit = screen.find(ERROR_SCREEN) is not None
     80             print(f"attempt {n}: "
     81                   + ("INITIALIZATION ERROR" if hit else "survived")
     82                   + f" -- {' | '.join(screen.texts()[:4])[:150]}")
     83             if hit:
     84                 broke += 1
     85                 if screen.find(OWNERSHIP) is not None:
     86                     print("  the error is the database ownership one")
     87                 # Nothing on the screen can retry; the app has to be killed.
     88                 buttons = [n_.label for n_ in screen.tappable() if n_.label]
     89                 print(f"  what the screen offers: {buttons}")
     90                 dev.stop()
     91                 time.sleep(2)
     92                 dev.launch()
     93                 time.sleep(10)
     94                 again = dev.dump().find(ERROR_SCREEN) is not None
     95                 print(f"  still broken after a relaunch: {again}")
     96                 break
     97 
     98         print(f"\nreproduced: {broke > 0} ({broke} of {n} attempts)")
     99         return 0 if broke else 1
    100     finally:
    101         dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales", check=False)
    102 
    103 
    104 if __name__ == "__main__":
    105     sys.exit(main())