1# CarTelemetry Demo Vendor Application 2 3This directory contains source code for a test application that CarService binds to at boot. 4 5The application uses CarTelemetryManager APIs to add metrics configurations and collect telemetry. 6 7## Usage 8 9The `Car Telemetry Collector` app is the UI component of this test application. It allows the adding/removing of configs and viewing retrieved data and errors on screen. 10 11CarService should bind to the vendor service, the list of early start up applications that 12CarService binds to are listed in `vendor/auto/embedded/products/rro_overlay/CarServiceOverlay/res/values/config.xml`. 13 14Add 15 16``` 17<item>com.android.car.cartelemetryapp/.CarMetricsCollectorService#bind=bind,user=system,trigger=userUnlocked</item> 18``` 19 20to `config_earlyStartupServices` in `vendor/auto/embedded/products/rro_overlay/CarServiceOverlay/res/values/config.xml` 21 22 23```shell 24m CarTelemetryApp 25adb root && adb remount && adb sync system && adb shell stop && adb shell start 26``` 27 28Verify that `adb logcat -b all -T 10000 -v color | egrep -i 'CAR.TELEMETRY|CarMetricsCollector'` 29contains the messages related to addMetricsConfig 30 31Note that stats reports are created after 10 minutes. Keep the process running and verify logcat. 32 33## Privileged Permission 34 35CarTelemetryManager APIs are protected with a 36permission `android.car.permission.USE_CAR_TELEMETRY_SERVICE`. 37 38The application declares the permission in `AndroidManifest.xml` and has a permission allowlist file 39at `frameworks/base/data/etc/car/com.android.car.cartelemetryapp.xml` 40 41## MetricsConfigs in assets/ Folder 42 43The assets/ folder contains the MetricsConfigs proto binaries. Examples: 44 45### activity_foreground_state_changed_config 46 47``` 48name: activity_foreground_state_changed_config 49version: 1 50script: 51 """ 52 function onActivityForegroundStateChanged(published_data, state) 53 result = {} 54 n = 0 55 for k, v in pairs(published_data) do 56 result[k] = v[1] 57 n = n + 1 58 end 59 result.n = n 60 on_script_finished(result) 61 end 62 """ 63subscribers: 64 - handler: onActivityForegroundStateChanged 65 publisher: 66 stats: 67 system_metric: ACTIVITY_FOREGROUND_STATE_CHANGED 68 priority: 0 69``` 70 71### process_memory_metrics_config 72 73``` 74name: process_memory_metrics_config 75version: 1 76script: 77 """ 78 function calculateAverage(tbl) 79 sum = 0 80 size = 0 81 for _, value in ipairs(tbl) do 82 sum = sum + value 83 size = size + 1 84 end 85 return sum/size 86 end 87 function onProcessMemory(published_data, state) 88 result = {} 89 result.page_fault_avg = calculateAverage(published_data.page_fault) 90 result.major_page_fault_avg = calculateAverage(" 91 + "published_data.page_major_fault) 92 result.oom_adj_score_avg = calculateAverage(" 93 + "published_data.oom_adj_score) 94 result.rss_in_bytes_avg = calculateAverage(" 95 + "published_data.rss_in_bytes) 96 result.swap_in_bytes_avg = calculateAverage(" 97 + "published_data.swap_in_bytes) 98 result.cache_in_bytes_avg = calculateAverage(" 99 + "published_data.cache_in_bytes) 100 on_script_finished(result) 101 end 102 """ 103subscribers: 104 - handler: onProcessMemory 105 publisher: 106 stats: 107 system_metric: PROCESS_MEMORY_STATE 108 priority: 0 109``` 110