Files
LihonT/tests/test_streak_patch.py
cheb0chik eb4ae1cf25 LihonT 2 Luna pre-release 2
Streak widget from 1x1 to 4x4 with an animated flame (orange while lit, grey when not), a streak keeper that writes
the chosen message once a day to the chosen chats (off until switched on), avatar shapes, widgets and the keeper kept
per account, Material 3 tonal surfaces instead of black (AMOLED keeps pure black), launcher previews of our own, and
the mod runtime in a dex of its own.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 15:09:30 +03:00

65 lines
2.8 KiB
Python

import unittest
import zipfile
from pathlib import Path
from lihont import streak_patch, widget_patch
from lihont.axml import Axml, RES_XML_END_ELEMENT
ROOT = Path(__file__).resolve().parents[1]
APKS = sorted((ROOT / "OriginalAPKtiktok").glob("*.apk")) if (ROOT / "OriginalAPKtiktok").is_dir() else []
class FakeApk:
"""Just enough of lihont.apkzip.Apk: reads from the original apk, remembers what is replaced."""
def __init__(self, path):
self.zip = zipfile.ZipFile(path)
self.replaced = {}
def read(self, name):
return self.replaced.get(name) or self.zip.read(name)
def replace(self, name, data):
self.replaced[name] = data
@unittest.skipUnless(APKS, "the original TikTok apk is not in OriginalAPKtiktok/")
class StreakPatchTest(unittest.TestCase):
def setUp(self):
self.apk = FakeApk(APKS[0])
self.xml = Axml.parse(self.apk.read("AndroidManifest.xml"))
def test_the_alarm_receiver_is_declared_and_private(self):
report = streak_patch.apply(self.apk, self.xml)
rebuilt = Axml.parse(self.apk.replaced["AndroidManifest.xml"])
nodes = [n for n in rebuilt.elements("receiver") if rebuilt.attr_string(n, "name") == streak_patch.RECEIVER]
self.assertEqual(1, len(nodes))
self.assertEqual(0, rebuilt.attr(nodes[0], "exported").data, "no other app can reach it")
self.assertEqual({"receiver": streak_patch.RECEIVER, "exported": False}, report)
ids = [rebuilt.resource_map[a.name] for a in nodes[0].attributes]
self.assertEqual(sorted(ids), ids, "the attributes stay in ascending id order")
def test_it_has_no_intent_filter(self):
streak_patch.apply(self.apk, self.xml)
rebuilt = Axml.parse(self.apk.replaced["AndroidManifest.xml"])
node = next(n for n in rebuilt.elements("receiver") if rebuilt.attr_string(n, "name") == streak_patch.RECEIVER)
following = rebuilt.nodes[rebuilt.nodes.index(node) + 1]
self.assertEqual(RES_XML_END_ELEMENT, following.kind, "the receiver closes right away: no intent filter")
def test_a_second_pass_is_refused(self):
streak_patch.apply(self.apk, self.xml)
with self.assertRaises(streak_patch.StreakError):
streak_patch.apply(self.apk, self.xml)
def test_it_sits_next_to_the_widget_changes(self):
widget_patch.apply(self.apk, self.xml, 0x7F120364)
streak_patch.apply(self.apk, self.xml)
rebuilt = Axml.parse(self.apk.replaced["AndroidManifest.xml"])
names = {rebuilt.attr_string(n, "name") for n in rebuilt.elements("receiver")}
self.assertIn(streak_patch.RECEIVER, names)
self.assertIn("lihont.two.widget.StreakWidget1", names)
if __name__ == "__main__":
unittest.main()