Files
ucvl-home-vision/test_android_location.py
T

68 lines
3.9 KiB
Python
Raw Normal View History

"""Installer routing and permission contracts; not a physical phone test."""
from pathlib import Path
import unittest
import xml.etree.ElementTree as ET
ROOT = Path(__file__).resolve().parent
ANDROID = ROOT/'android-display'
NS = '{http://schemas.android.com/apk/res/android}'
class AndroidLocationContractTests(unittest.TestCase):
def test_terminal_is_ordinary_app_without_home_or_boot_receiver(self):
manifest=ET.parse(ANDROID/'AndroidManifest-terminal.xml').getroot()
self.assertEqual(manifest.findall('application/receiver'),[])
categories=[c.get(NS+'name') for c in manifest.findall('.//category')]
self.assertNotIn('android.intent.category.HOME',categories)
self.assertEqual(categories.count('android.intent.category.LAUNCHER'),1)
self.assertEqual(manifest.get(NS+'versionName'),(ROOT/'VERSION').read_text().strip())
def test_voice_is_foreground_press_to_record_and_cleans_temp_media(self):
source=(ANDROID/'src/cn/ucvl/zhaodisplay/VoicePanel.java').read_text(encoding='utf-8')
for text in ('ACTION_CANCEL:finish(false)','Manifest.permission.RECORD_AUDIO','AAC_ADTS','file.delete()','stopPlayer("rejected")','getCacheDir()','AudioFocusRequest','current(e,t)'):
self.assertIn(text,source)
self.assertNotIn('setStreamVolume',source)
ui=(ANDROID/'src/cn/ucvl/zhaodisplay/LocationActivity.java').read_text(encoding='utf-8')
self.assertIn('homeContent.setVisibility(paired?View.VISIBLE:View.GONE)',ui)
self.assertIn('voice.active(false)',ui)
main=(ANDROID/'src/cn/ucvl/zhaodisplay/MainActivity.java').read_text(encoding='utf-8')
self.assertIn('client=android&load=',main)
def test_phone_launcher_is_location_only(self):
manifest = ET.parse(ANDROID/'AndroidManifest.xml').getroot()
entries = manifest.findall('application/activity')
launchers = [a.get(NS+'name') for a in entries if any(c.get(NS+'name') ==
'android.intent.category.LAUNCHER' for c in a.findall('intent-filter/category'))]
television = [a.get(NS+'name') for a in entries if any(c.get(NS+'name') ==
'android.intent.category.LEANBACK_LAUNCHER' for c in a.findall('intent-filter/category'))]
self.assertEqual(launchers, ['.LocationActivity'])
self.assertEqual(television, ['.MainActivity'])
self.assertEqual(manifest.get(NS+'versionName'), (ROOT/'VERSION').read_text().strip())
self.assertEqual(manifest.get(NS+'versionCode'), '4')
def test_collection_is_visible_foreground_and_never_boot_started(self):
manifest = ET.parse(ANDROID/'AndroidManifest.xml').getroot()
service = next(s for s in manifest.findall('application/service') if s.get(NS+'name') == '.LocationService')
self.assertEqual(service.get(NS+'exported'), 'false')
self.assertEqual(service.get(NS+'foregroundServiceType'), 'location')
boot = (ANDROID/'src/cn/ucvl/zhaodisplay/BootReceiver.java').read_text()
self.assertNotIn('LocationService', boot)
self.assertIn('phoneMode', boot)
ui = (ANDROID/'src/cn/ucvl/zhaodisplay/LocationActivity.java').read_text(encoding='utf-8')
self.assertNotIn('WebView', ui)
self.assertIn('共享我的位置', ui)
self.assertIn('new int[]{10,60,300}', ui)
self.assertIn('consent.isChecked()', ui)
def test_map_has_local_assets_no_external_coordinate_requests(self):
source = (ANDROID/'src/cn/ucvl/zhaodisplay/LocationMapView.java').read_text(encoding='utf-8')
self.assertIn('getAssets().open("world-land.json")', source)
self.assertNotIn('http', source)
build = (ANDROID/'build.ps1').read_text(encoding='utf-8')
for name in ('world-land.json', 'WORLD-LAND-LICENSE.txt'):
self.assertIn(name, build)
self.assertTrue((ROOT/'frontend/src/data'/name).exists())
if __name__ == '__main__': unittest.main()