"""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.assertGreaterEqual(int(manifest.get(NS+'versionCode')), 5) 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(set(service.get(NS+'foregroundServiceType').split('|')), {'location','dataSync'}) 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) layout=(ANDROID/'src/cn/ucvl/zhaodisplay/PhoneLayout.java').read_text(encoding='utf-8') self.assertIn('共享我的位置', layout) self.assertIn('自定义采集间隔', ui) self.assertIn('LocationCadence.customSample', ui) self.assertIn('setSamplePeriod(result.optInt', ui) self.assertIn('自定义小时 / 天',ui) self.assertIn('LocationCadence.custom',ui) queue=(ANDROID/'src/cn/ucvl/zhaodisplay/LocationQueue.java').read_text(encoding='utf-8') for contract in ('AndroidKeyStore','AES/GCM/NoPadding','MAX_POINTS=50000','MAX_DATABASE_BYTES','batch.digest.equals','"verified".equals(state)','db.beginTransaction()'): self.assertIn(contract,queue) self.assertIn('consent.isChecked()', ui) def test_voice_has_full_screen_large_controls_and_real_amplitude(self): panel=(ANDROID/'src/cn/ucvl/zhaodisplay/VoicePanel.java').read_text(encoding='utf-8') surface=(ANDROID/'src/cn/ucvl/zhaodisplay/VoiceSurface.java').read_text(encoding='utf-8') for text in ('setLayout(-1,-1)','getMaxAmplitude()','VoiceGesture.sendAtLimit(cancelled)','ACTION_CANCEL:finish(false)','view.full','stopPlayer("rejected")'): self.assertIn(text,panel) for text in ('上滑取消','已打开 App','setContentDescription'): self.assertIn(text,surface) def test_map_uses_first_party_tiles_and_never_exposes_pairing_token(self): source = (ANDROID/'src/cn/ucvl/zhaodisplay/LocationMapView.java').read_text(encoding='utf-8') for text in ('https://zhao.ucvl.cn/maps/phone','shouldInterceptRequest','setGeolocationEnabled(false)','setAllowFileAccess(false)','JSONObject.quote','setItems(new JSONArray())'): self.assertIn(text,source) self.assertNotIn('addJavascriptInterface',source) self.assertNotIn('getSharedPreferences',source) def test_phone_three_tabs_use_native_cards_and_keep_sharing_explicit(self): source=(ANDROID/'src/cn/ucvl/zhaodisplay/LocationActivity.java').read_text(encoding='utf-8') layout=(ANDROID/'src/cn/ucvl/zhaodisplay/PhoneLayout.java').read_text(encoding='utf-8') for value in ('"位置","沟通","我的"','scrolls[i].setVisibility(i==next?VISIBLE:GONE)','setContentDescription','共享我的位置'): self.assertIn(value,layout) for value in ('voice.finish(false);phone.select(tab)','if(content.getParent()==scroll)','开启共享后生效','consent.setChecked(false)','showDetail("允许谁查看"','setLayout(-1,-1)'): self.assertIn(value,source) self.assertNotIn('startService',layout) self.assertNotIn('https://',layout) self.assertNotIn('dockSlot',layout) self.assertIn('sortPositions(response.optJSONArray',source) self.assertIn('voice.dock.receiverCard',source) self.assertIn('voice.communication(tab==1)',source) def test_voice_page_uses_explicit_receiver_consent_and_cancels_on_navigation(self): source=(ANDROID/'src/cn/ucvl/zhaodisplay/VoicePanel.java').read_text(encoding='utf-8') surface=(ANDROID/'src/cn/ucvl/zhaodisplay/VoiceSurface.java').read_text(encoding='utf-8') for value in ('view.receiver.setChecked(enabled)','else configure()','VoiceSurface page()','new VoiceCircle(color,night)','setContentDescription'): self.assertIn(value,source+surface) self.assertIn('!visible||!networkReady||recorder!=null',source) self.assertIn('view.destination(selected,networkReady)',source) def test_native_ui_fixture_cannot_access_real_data(self): build=(ANDROID/'tests/build-phone-check.ps1').read_text(encoding='utf-8') self.assertIn('cn.ucvl.zhaodisplay.phonecheck',build) self.assertNotIn('