ac8c52db31
Trustagents should know to downgrade to trustable when the keyguard visiblity changes. This will fix a bug on tablet where hitting the power button doesn't sleep the device, and consequently doesn't broadcast the SCREEN_OFF broadcast which causes the unit tests to fail. This also fixes a larger issue where if the phone gets unlatched, or if a trustagent is set up while the phone is unlocked, the phone will be able to downgrade the trustagent to trustable at the correct time. As part of this chance, we can remove the USER_PRESENT broadcast which ends up duplicating the reportKeyguardShowingChanged. Also, in TemporaryAndRenewableTrustTest.kt, we now grantTrust after waking the phone which is more realistic and was causing the tests to fail before. Test: atest TrustTests:TemporaryAndRenewableTrustTests --iterations Bug: 213631682 Fixes: 231326751 Change-Id: I10a3270ff0b9f12d62acd448ad754f829d843b0e
TrustTests framework tests
These tests test the "trust" part of the platform primarily implemented via TrustManagerService in the system server and TrustAgentService in system apps.
Tests are separated into separate files based on major groupings. When creating new tests, find a closely matching existing test file or create a new test file. Prefer many test files over large test files.
Each test file has its own trust agent. To create a new trust agent:
- Create a new class extending from
BaseTrustAgentService
class in your test file - Add a new
<service>
stanza toAndroidManifest.xml
in this directory for the new agent following the pattern fo the existing agents.
To run:
atest TrustTests
Testing approach:
- Test the agent service as a black box; avoid inspecting internal state of the service or modifying the system code outside of this directory.
- The primary interface to the system is through these three points:
TrustAgentService
, your agent created by theTrustAgentRule
and accessible via theagent
property of the rule.- Call command methods (e.g.
grantTrust
) directly on the agent - Listen to events (e.g.
onUserRequestedUnlock
) by implementing the method in your test's agent class and tracking invocations. SeeUserUnlockRequestTest
for an example.
- Call command methods (e.g.
TrustManager
which is the interface the rest of the system (e.g. SystemUI) has to the service.- Through this API, simulate system events that the service cares about
(e.g.
reportUnlockAttempt
).
- Through this API, simulate system events that the service cares about
(e.g.
TrustListener
which is the interface the rest of the system (e.g. SystemUI) uses to receive events from the service.- Through this, verify behavior that affects the rest of the system. For example,
see
LockStateTrackingRule
.
- Through this, verify behavior that affects the rest of the system. For example,
see
- To re-use code between tests, prefer creating new rules alongside the existing rules or adding functionality to a closely matching existing rule.