Fix the bug of not showing lock screen before entering Smart Lock page.
Controller can't find the target preference to handle the click event. Store the preference keys to match the clicked item. Fixes: 158716163 Test: run robotest and manually test the click behavior Change-Id: Ie243206ceffef013c56c4ea29c14fe56da510fb6
This commit is contained in:
@@ -23,7 +23,6 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
@@ -46,6 +45,7 @@ import com.android.settingslib.core.lifecycle.events.OnResume;
|
|||||||
import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
|
import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
|
||||||
import com.android.settingslib.search.SearchIndexableRaw;
|
import com.android.settingslib.search.SearchIndexableRaw;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TrustAgentListPreferenceController extends AbstractPreferenceController
|
public class TrustAgentListPreferenceController extends AbstractPreferenceController
|
||||||
@@ -66,6 +66,9 @@ public class TrustAgentListPreferenceController extends AbstractPreferenceContro
|
|||||||
private Intent mTrustAgentClickIntent;
|
private Intent mTrustAgentClickIntent;
|
||||||
private PreferenceCategory mSecurityCategory;
|
private PreferenceCategory mSecurityCategory;
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
final List<String> mTrustAgentsKeyList;
|
||||||
|
|
||||||
public TrustAgentListPreferenceController(Context context, SecuritySettings host,
|
public TrustAgentListPreferenceController(Context context, SecuritySettings host,
|
||||||
Lifecycle lifecycle) {
|
Lifecycle lifecycle) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -74,6 +77,7 @@ public class TrustAgentListPreferenceController extends AbstractPreferenceContro
|
|||||||
mHost = host;
|
mHost = host;
|
||||||
mLockPatternUtils = provider.getLockPatternUtils(context);
|
mLockPatternUtils = provider.getLockPatternUtils(context);
|
||||||
mTrustAgentManager = provider.getTrustAgentManager();
|
mTrustAgentManager = provider.getTrustAgentManager();
|
||||||
|
mTrustAgentsKeyList = new ArrayList();
|
||||||
if (lifecycle != null) {
|
if (lifecycle != null) {
|
||||||
lifecycle.addObserver(this);
|
lifecycle.addObserver(this);
|
||||||
}
|
}
|
||||||
@@ -113,7 +117,7 @@ public class TrustAgentListPreferenceController extends AbstractPreferenceContro
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
if (!mTrustAgentsKeyList.contains(preference.getKey())) {
|
||||||
return super.handlePreferenceTreeClick(preference);
|
return super.handlePreferenceTreeClick(preference);
|
||||||
}
|
}
|
||||||
final ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(
|
final ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(
|
||||||
@@ -189,6 +193,7 @@ public class TrustAgentListPreferenceController extends AbstractPreferenceContro
|
|||||||
mSecurityCategory.removePreference(oldAgent);
|
mSecurityCategory.removePreference(oldAgent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mTrustAgentsKeyList.clear();
|
||||||
|
|
||||||
// Then add new ones.
|
// Then add new ones.
|
||||||
final boolean hasSecurity = mLockPatternUtils.isSecure(MY_USER_ID);
|
final boolean hasSecurity = mLockPatternUtils.isSecure(MY_USER_ID);
|
||||||
@@ -196,6 +201,7 @@ public class TrustAgentListPreferenceController extends AbstractPreferenceContro
|
|||||||
final RestrictedPreference trustAgentPreference =
|
final RestrictedPreference trustAgentPreference =
|
||||||
new RestrictedPreference(mSecurityCategory.getContext());
|
new RestrictedPreference(mSecurityCategory.getContext());
|
||||||
TrustAgentManager.TrustAgentComponentInfo agent = agents.get(i);
|
TrustAgentManager.TrustAgentComponentInfo agent = agents.get(i);
|
||||||
|
mTrustAgentsKeyList.add(PREF_KEY_TRUST_AGENT + i);
|
||||||
trustAgentPreference.setKey(PREF_KEY_TRUST_AGENT + i);
|
trustAgentPreference.setKey(PREF_KEY_TRUST_AGENT + i);
|
||||||
trustAgentPreference.setTitle(agent.title);
|
trustAgentPreference.setTitle(agent.title);
|
||||||
trustAgentPreference.setSummary(agent.summary);
|
trustAgentPreference.setSummary(agent.summary);
|
||||||
|
@@ -16,10 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.security.trustagent;
|
package com.android.settings.security.trustagent;
|
||||||
|
|
||||||
import static com.android.settings.security.trustagent.TrustAgentListPreferenceController
|
import static com.android.settings.security.trustagent.TrustAgentListPreferenceController.PREF_KEY_SECURITY_CATEGORY;
|
||||||
.PREF_KEY_SECURITY_CATEGORY;
|
import static com.android.settings.security.trustagent.TrustAgentListPreferenceController.PREF_KEY_TRUST_AGENT;
|
||||||
import static com.android.settings.security.trustagent.TrustAgentListPreferenceController
|
|
||||||
.PREF_KEY_TRUST_AGENT;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
@@ -172,6 +170,26 @@ public class TrustAgentListPreferenceControllerTest {
|
|||||||
verify(mCategory, never()).addPreference(any(Preference.class));
|
verify(mCategory, never()).addPreference(any(Preference.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onResume_controllerShouldHasKey() {
|
||||||
|
final List<TrustAgentManager.TrustAgentComponentInfo> agents = new ArrayList<>();
|
||||||
|
final TrustAgentManager.TrustAgentComponentInfo agent =
|
||||||
|
mock(TrustAgentManager.TrustAgentComponentInfo.class);
|
||||||
|
agent.title = "Test_title";
|
||||||
|
agent.summary = "test summary";
|
||||||
|
agent.componentName = new ComponentName("pkg", "agent");
|
||||||
|
agent.admin = null;
|
||||||
|
agents.add(agent);
|
||||||
|
when(mTrustAgentManager.getActiveTrustAgents(mActivity, mLockPatternUtils))
|
||||||
|
.thenReturn(agents);
|
||||||
|
final String key = PREF_KEY_TRUST_AGENT + 0;
|
||||||
|
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
mController.onResume();
|
||||||
|
|
||||||
|
assertThat(mController.mTrustAgentsKeyList).containsExactly(key);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateDynamicRawDataToIndex_shouldIndexAgents() {
|
public void updateDynamicRawDataToIndex_shouldIndexAgents() {
|
||||||
final List<TrustAgentManager.TrustAgentComponentInfo> agents = new ArrayList<>();
|
final List<TrustAgentManager.TrustAgentComponentInfo> agents = new ArrayList<>();
|
||||||
@@ -190,5 +208,4 @@ public class TrustAgentListPreferenceControllerTest {
|
|||||||
|
|
||||||
assertThat(indexRaws).hasSize(1);
|
assertThat(indexRaws).hasSize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user