1*d57664e9SAndroid Build Coastguard Worker# TrustTests framework tests 2*d57664e9SAndroid Build Coastguard Worker 3*d57664e9SAndroid Build Coastguard WorkerThese tests test the "trust" part of the platform primarily implemented via TrustManagerService in 4*d57664e9SAndroid Build Coastguard Workerthe system server and TrustAgentService in system apps. 5*d57664e9SAndroid Build Coastguard Worker 6*d57664e9SAndroid Build Coastguard WorkerTests are separated into separate files based on major groupings. When creating new tests, find a 7*d57664e9SAndroid Build Coastguard Worker_closely_ matching existing test file or create a new test file. Prefer many test files over large 8*d57664e9SAndroid Build Coastguard Workertest files. 9*d57664e9SAndroid Build Coastguard Worker 10*d57664e9SAndroid Build Coastguard WorkerEach test file has its own trust agent. To create a new trust agent: 11*d57664e9SAndroid Build Coastguard Worker 12*d57664e9SAndroid Build Coastguard Worker1. Create a new class extending from `BaseTrustAgentService` class in your test file 13*d57664e9SAndroid Build Coastguard Worker2. Add a new `<service>` stanza to `AndroidManifest.xml` in this directory for the new agent 14*d57664e9SAndroid Build Coastguard Worker following the pattern fo the existing agents. 15*d57664e9SAndroid Build Coastguard Worker 16*d57664e9SAndroid Build Coastguard WorkerTo run: 17*d57664e9SAndroid Build Coastguard Worker 18*d57664e9SAndroid Build Coastguard Worker```atest TrustTests``` 19*d57664e9SAndroid Build Coastguard Worker 20*d57664e9SAndroid Build Coastguard Worker## Testing approach: 21*d57664e9SAndroid Build Coastguard Worker 22*d57664e9SAndroid Build Coastguard Worker1. Test the agent service as a black box; avoid inspecting internal state of the service or 23*d57664e9SAndroid Build Coastguard Worker modifying the system code outside of this directory. 24*d57664e9SAndroid Build Coastguard Worker2. The primary interface to the system is through these three points: 25*d57664e9SAndroid Build Coastguard Worker 1. `TrustAgentService`, your agent created by the `TrustAgentRule` and accessible via 26*d57664e9SAndroid Build Coastguard Worker the `agent` property of the rule. 27*d57664e9SAndroid Build Coastguard Worker 1. Call command methods (e.g. `grantTrust`) directly on the agent 28*d57664e9SAndroid Build Coastguard Worker 2. Listen to events (e.g. `onUserRequestedUnlock`) by implementing the method in 29*d57664e9SAndroid Build Coastguard Worker your test's agent class and tracking invocations. See `UserUnlockRequestTest` for an 30*d57664e9SAndroid Build Coastguard Worker example. 31*d57664e9SAndroid Build Coastguard Worker 2. `TrustManager` which is the interface the rest of the system (e.g. SystemUI) has to the 32*d57664e9SAndroid Build Coastguard Worker service. 33*d57664e9SAndroid Build Coastguard Worker 1. Through this API, simulate system events that the service cares about 34*d57664e9SAndroid Build Coastguard Worker (e.g. `reportUnlockAttempt`). 35*d57664e9SAndroid Build Coastguard Worker 3. `TrustListener` which is the interface the rest of the system (e.g. SystemUI) uses to receive 36*d57664e9SAndroid Build Coastguard Worker events from the service. 37*d57664e9SAndroid Build Coastguard Worker 1. Through this, verify behavior that affects the rest of the system. For example, 38*d57664e9SAndroid Build Coastguard Worker see `LockStateTrackingRule`. 39*d57664e9SAndroid Build Coastguard Worker3. To re-use code between tests, prefer creating new rules alongside the existing rules or adding 40*d57664e9SAndroid Build Coastguard Worker functionality to a _closely_ matching existing rule. 41