Merge "Add the "Smart Lock" item to dynamic index." into rvc-dev am: 37d5ed5073
am: b9b28441ee
am: f71d5e8427
am: 320c19d355
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/11544230 Change-Id: I2201c8cd46464cd1be832478cd91f1f5e1b26ae8
This commit is contained in:
@@ -44,6 +44,7 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
|||||||
import com.android.settingslib.core.lifecycle.events.OnCreate;
|
import com.android.settingslib.core.lifecycle.events.OnCreate;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
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 java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -134,34 +135,68 @@ public class TrustAgentListPreferenceController extends AbstractPreferenceContro
|
|||||||
updateTrustAgents();
|
updateTrustAgents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDynamicRawDataToIndex(List<SearchIndexableRaw> rawData) {
|
||||||
|
if (!isAvailable()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<TrustAgentManager.TrustAgentComponentInfo> agents = getActiveTrustAgents(
|
||||||
|
mContext);
|
||||||
|
if (agents == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0, size = agents.size(); i < size; i++) {
|
||||||
|
final SearchIndexableRaw raw = new SearchIndexableRaw(mContext);
|
||||||
|
final TrustAgentManager.TrustAgentComponentInfo agent = agents.get(i);
|
||||||
|
|
||||||
|
raw.key = PREF_KEY_TRUST_AGENT + i;
|
||||||
|
raw.title = agent.title;
|
||||||
|
rawData.add(raw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The active trust agents from TrustAgentManager.
|
||||||
|
*/
|
||||||
|
private List<TrustAgentManager.TrustAgentComponentInfo> getActiveTrustAgents(Context context) {
|
||||||
|
return mTrustAgentManager.getActiveTrustAgents(context, mLockPatternUtils);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateTrustAgents() {
|
private void updateTrustAgents() {
|
||||||
if (mSecurityCategory == null) {
|
if (mSecurityCategory == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// If for some reason the preference is no longer available, don't proceed to add.
|
||||||
|
if (!isAvailable()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final List<TrustAgentManager.TrustAgentComponentInfo> agents = getActiveTrustAgents(
|
||||||
|
mContext);
|
||||||
|
if (agents == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// First remove all old trust agents.
|
// First remove all old trust agents.
|
||||||
while (true) {
|
for (int i = 0, size = agents.size(); i < size; i++) {
|
||||||
final Preference oldAgent = mSecurityCategory.findPreference(PREF_KEY_TRUST_AGENT);
|
String key = PREF_KEY_TRUST_AGENT + i;
|
||||||
|
final Preference oldAgent = mSecurityCategory.findPreference(key);
|
||||||
if (oldAgent == null) {
|
if (oldAgent == null) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
mSecurityCategory.removePreference(oldAgent);
|
mSecurityCategory.removePreference(oldAgent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If for some reason the preference is no longer available, don't proceed to add.
|
|
||||||
if (!isAvailable()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Then add new ones.
|
// Then add new ones.
|
||||||
final boolean hasSecurity = mLockPatternUtils.isSecure(MY_USER_ID);
|
final boolean hasSecurity = mLockPatternUtils.isSecure(MY_USER_ID);
|
||||||
final List<TrustAgentManager.TrustAgentComponentInfo> agents =
|
for (int i = 0, size = agents.size(); i < size; i++) {
|
||||||
mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils);
|
|
||||||
if (agents == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (TrustAgentManager.TrustAgentComponentInfo agent : agents) {
|
|
||||||
final RestrictedPreference trustAgentPreference =
|
final RestrictedPreference trustAgentPreference =
|
||||||
new RestrictedPreference(mSecurityCategory.getContext());
|
new RestrictedPreference(mSecurityCategory.getContext());
|
||||||
trustAgentPreference.setKey(PREF_KEY_TRUST_AGENT);
|
TrustAgentManager.TrustAgentComponentInfo agent = agents.get(i);
|
||||||
|
trustAgentPreference.setKey(PREF_KEY_TRUST_AGENT + i);
|
||||||
trustAgentPreference.setTitle(agent.title);
|
trustAgentPreference.setTitle(agent.title);
|
||||||
trustAgentPreference.setSummary(agent.summary);
|
trustAgentPreference.setSummary(agent.summary);
|
||||||
// Create intent for this preference.
|
// Create intent for this preference.
|
||||||
|
@@ -44,6 +44,7 @@ import com.android.settings.core.PreferenceControllerMixin;
|
|||||||
import com.android.settings.security.SecuritySettings;
|
import com.android.settings.security.SecuritySettings;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
import com.android.settingslib.search.SearchIndexableRaw;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -111,10 +112,20 @@ public class TrustAgentListPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onResume_shouldClearOldAgents() {
|
public void onResume_shouldClearOldAgents() {
|
||||||
final Preference oldAgent = new Preference(mActivity);
|
final Preference oldAgent = new Preference(mActivity);
|
||||||
oldAgent.setKey(PREF_KEY_TRUST_AGENT);
|
oldAgent.setKey(PREF_KEY_TRUST_AGENT + 0);
|
||||||
when(mCategory.findPreference(PREF_KEY_TRUST_AGENT))
|
when(mCategory.findPreference(PREF_KEY_TRUST_AGENT + 0))
|
||||||
.thenReturn(oldAgent)
|
.thenReturn(oldAgent)
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
|
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);
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
mController.onResume();
|
mController.onResume();
|
||||||
@@ -160,4 +171,24 @@ public class TrustAgentListPreferenceControllerTest {
|
|||||||
|
|
||||||
verify(mCategory, never()).addPreference(any(Preference.class));
|
verify(mCategory, never()).addPreference(any(Preference.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateDynamicRawDataToIndex_shouldIndexAgents() {
|
||||||
|
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 List<SearchIndexableRaw> indexRaws = new ArrayList<>();
|
||||||
|
|
||||||
|
mController.updateDynamicRawDataToIndex(indexRaws);
|
||||||
|
|
||||||
|
assertThat(indexRaws).hasSize(1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user