80 lines
5.1 KiB
Python
80 lines
5.1 KiB
Python
"""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)
|
|
self.assertIn('共享我的位置', ui)
|
|
self.assertIn('new int[]{10,60,300}', 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_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_background_permission_only_in_phone_and_separately_requested(self):
|
|
for name,expected in [('AndroidManifest.xml',True),('AndroidManifest-terminal.xml',False)]:
|
|
manifest=ET.parse(ANDROID/name).getroot()
|
|
permissions=[x.get(NS+'name') for x in manifest.findall('uses-permission')]
|
|
self.assertEqual('android.permission.ACCESS_BACKGROUND_LOCATION' in permissions,expected)
|
|
source=(ANDROID/'src/cn/ucvl/zhaodisplay/LocationActivity.java').read_text(encoding='utf-8')
|
|
self.assertIn('ACTION_APPLICATION_DETAILS_SETTINGS',source)
|
|
self.assertIn('new String[]{Manifest.permission.ACCESS_BACKGROUND_LOCATION},48',source)
|
|
self.assertIn('if(request==47||request==48){render();return;}',source)
|
|
|
|
|
|
if __name__ == '__main__': unittest.main()
|