Merge "Updating TrustManagerService to react to keyguard visible changes." into tm-dev

This commit is contained in:
TreeHugger Robot
2022-05-06 03:28:43 +00:00
committed by Android (Google) Code Review
3 changed files with 38 additions and 17 deletions

View File

@@ -122,16 +122,9 @@ public class TrustAgentWrapper {
if (!TrustManagerService.ENABLE_ACTIVE_UNLOCK_FLAG) { if (!TrustManagerService.ENABLE_ACTIVE_UNLOCK_FLAG) {
return; return;
} }
if (!mWaitingForTrustableDowngrade) {
return;
}
// are these the broadcasts we want to listen to // are these the broadcasts we want to listen to
if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction()) if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
|| Intent.ACTION_USER_PRESENT.equals(intent.getAction())) { downgradeToTrustable();
mTrusted = false;
mTrustable = true;
mWaitingForTrustableDowngrade = false;
mTrustManagerService.updateTrust(mUserId, 0);
} }
} }
}; };
@@ -480,8 +473,7 @@ public class TrustAgentWrapper {
final String pathUri = mAlarmIntent.toUri(Intent.URI_INTENT_SCHEME); final String pathUri = mAlarmIntent.toUri(Intent.URI_INTENT_SCHEME);
alarmFilter.addDataPath(pathUri, PatternMatcher.PATTERN_LITERAL); alarmFilter.addDataPath(pathUri, PatternMatcher.PATTERN_LITERAL);
IntentFilter trustableFilter = new IntentFilter(Intent.ACTION_USER_PRESENT); IntentFilter trustableFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
trustableFilter.addAction(Intent.ACTION_SCREEN_OFF);
// Schedules a restart for when connecting times out. If the connection succeeds, // Schedules a restart for when connecting times out. If the connection succeeds,
// the restart is canceled in mCallback's onConnected. // the restart is canceled in mCallback's onConnected.
@@ -668,6 +660,19 @@ public class TrustAgentWrapper {
mTrustable = false; mTrustable = false;
} }
/**
* Downgrades the trustagent to trustable as a result of a keyguard or screen related event, and
* then updates the trust state of the phone to reflect the change.
*/
public void downgradeToTrustable() {
if (mWaitingForTrustableDowngrade) {
mWaitingForTrustableDowngrade = false;
mTrusted = false;
mTrustable = true;
mTrustManagerService.updateTrust(mUserId, 0);
}
}
public boolean isManagingTrust() { public boolean isManagingTrust() {
return mManagingTrust && !mTrustDisabledByDpm; return mManagingTrust && !mTrustDisabledByDpm;
} }

View File

@@ -1184,6 +1184,22 @@ public class TrustManagerService extends SystemService {
return false; return false;
} }
/**
* We downgrade to trustable whenever keyguard changes its showing value.
* - becomes showing: something has caused the device to show keyguard which happens due to
* user intent to lock the device either through direct action or a timeout
* - becomes not showing: keyguard was dismissed and we no longer need to keep the device
* unlocked
* */
private void dispatchTrustableDowngrade() {
for (int i = 0; i < mActiveAgents.size(); i++) {
AgentInfo info = mActiveAgents.valueAt(i);
if (info.userId == mCurrentUser) {
info.agent.downgradeToTrustable();
}
}
}
private List<String> getTrustGrantedMessages(int userId) { private List<String> getTrustGrantedMessages(int userId) {
if (!mStrongAuthTracker.isTrustAllowedForUser(userId)) { if (!mStrongAuthTracker.isTrustAllowedForUser(userId)) {
return new ArrayList<>(); return new ArrayList<>();
@@ -1752,6 +1768,7 @@ public class TrustManagerService extends SystemService {
refreshDeviceLockedForUser(UserHandle.USER_ALL); refreshDeviceLockedForUser(UserHandle.USER_ALL);
break; break;
case MSG_KEYGUARD_SHOWING_CHANGED: case MSG_KEYGUARD_SHOWING_CHANGED:
dispatchTrustableDowngrade();
refreshDeviceLockedForUser(mCurrentUser); refreshDeviceLockedForUser(mCurrentUser);
break; break;
case MSG_START_USER: case MSG_START_USER:

View File

@@ -29,7 +29,7 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.UiDevice
import com.google.common.truth.Truth.assertThat import android.trust.test.lib.wait
import org.junit.Before import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
@@ -74,9 +74,9 @@ class TemporaryAndRenewableTrustTest {
uiDevice.sleep() uiDevice.sleep()
lockStateTrackingRule.assertLocked() lockStateTrackingRule.assertLocked()
uiDevice.wakeUp()
trustAgentRule.agent.grantTrust( trustAgentRule.agent.grantTrust(
GRANT_MESSAGE, 0, FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE) {} GRANT_MESSAGE, 0, FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE) {}
uiDevice.wakeUp()
lockStateTrackingRule.assertLocked() lockStateTrackingRule.assertLocked()
} }
@@ -98,9 +98,9 @@ class TemporaryAndRenewableTrustTest {
lockStateTrackingRule.assertLocked() lockStateTrackingRule.assertLocked()
uiDevice.wakeUp()
trustAgentRule.agent.grantTrust( trustAgentRule.agent.grantTrust(
GRANT_MESSAGE, 0, FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE) {} GRANT_MESSAGE, 0, FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE) {}
uiDevice.wakeUp()
lockStateTrackingRule.assertUnlocked() lockStateTrackingRule.assertUnlocked()
} }
@@ -116,6 +116,7 @@ class TemporaryAndRenewableTrustTest {
uiDevice.sleep() uiDevice.sleep()
lockStateTrackingRule.assertLocked() lockStateTrackingRule.assertLocked()
uiDevice.wakeUp()
Log.i(TAG, "Renewing trust and unlocking") Log.i(TAG, "Renewing trust and unlocking")
var result: GrantTrustResult? = null var result: GrantTrustResult? = null
@@ -124,10 +125,9 @@ class TemporaryAndRenewableTrustTest {
Log.i(TAG, "Callback received; status=${it.status}") Log.i(TAG, "Callback received; status=${it.status}")
result = it result = it
} }
uiDevice.wakeUp()
lockStateTrackingRule.assertUnlocked() lockStateTrackingRule.assertUnlocked()
assertThat(result?.status).isEqualTo(STATUS_UNLOCKED_BY_GRANT) wait("callback triggered") { result?.status == STATUS_UNLOCKED_BY_GRANT }
} }
@Test @Test
@@ -141,7 +141,6 @@ class TemporaryAndRenewableTrustTest {
trustAgentRule.agent.revokeTrust() trustAgentRule.agent.revokeTrust()
await(500) await(500)
uiDevice.wakeUp() uiDevice.wakeUp()
await(500)
trustAgentRule.agent.grantTrust( trustAgentRule.agent.grantTrust(
GRANT_MESSAGE, 0, FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE) {} GRANT_MESSAGE, 0, FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE) {}