Move trustagent to security package.
Bug: 32953042 Fixes: 34461256 Test: robotests Change-Id: I341076ff320ad60081542a96eb588614230cb13e
This commit is contained in:
@@ -69,7 +69,7 @@
|
||||
<Preference android:key="manage_trust_agents"
|
||||
android:title="@string/manage_trust_agents"
|
||||
android:persistent="false"
|
||||
android:fragment="com.android.settings.TrustAgentSettings"/>
|
||||
android:fragment="com.android.settings.security.trustagent.TrustAgentSettings"/>
|
||||
|
||||
<Preference
|
||||
android:key="screen_pinning_settings"
|
||||
|
@@ -55,7 +55,6 @@ import android.util.Log;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.TrustAgentUtils.TrustAgentComponentInfo;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
@@ -73,7 +72,8 @@ import com.android.settings.search.Indexable;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
import com.android.settings.security.OwnerInfoPreferenceController;
|
||||
import com.android.settings.security.SecurityFeatureProvider;
|
||||
import com.android.settings.trustagent.TrustAgentManager;
|
||||
import com.android.settings.security.trustagent.TrustAgentManager;
|
||||
import com.android.settings.security.trustagent.TrustAgentManager.TrustAgentComponentInfo;
|
||||
import com.android.settings.widget.GearPreference;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
@@ -127,11 +127,6 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
private static final String KEY_SECURITY_STATUS = "security_status";
|
||||
private static final String SECURITY_STATUS_KEY_PREFIX = "security_status_";
|
||||
|
||||
// Package verifier Settings
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
static final String KEY_PACKAGE_VERIFIER_STATUS = "security_status_package_verifier";
|
||||
private static final int PACKAGE_VERIFIER_STATE_ENABLED = 1;
|
||||
|
||||
// Device management settings
|
||||
private static final String KEY_ENTERPRISE_PRIVACY = "enterprise_privacy";
|
||||
private static final String KEY_MANAGE_DEVICE_ADMIN = "manage_device_admin";
|
||||
@@ -541,7 +536,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
TrustAgentManager trustAgentManager, LockPatternUtils utils,
|
||||
DevicePolicyManager dpm) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
ArrayList<TrustAgentComponentInfo> result = new ArrayList<TrustAgentComponentInfo>();
|
||||
ArrayList<TrustAgentComponentInfo> result = new ArrayList<>();
|
||||
List<ResolveInfo> resolveInfos = pm.queryIntentServices(TRUST_AGENT_INTENT,
|
||||
PackageManager.GET_META_DATA);
|
||||
List<ComponentName> enabledTrustAgents = utils.getEnabledTrustAgents(MY_USER_ID);
|
||||
@@ -557,13 +552,13 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
continue;
|
||||
}
|
||||
TrustAgentComponentInfo trustAgentComponentInfo =
|
||||
TrustAgentUtils.getSettingsComponent(pm, resolveInfo);
|
||||
trustAgentManager.getSettingsComponent(pm, resolveInfo);
|
||||
if (trustAgentComponentInfo.componentName == null ||
|
||||
!enabledTrustAgents.contains(
|
||||
TrustAgentUtils.getComponentName(resolveInfo)) ||
|
||||
trustAgentManager.getComponentName(resolveInfo)) ||
|
||||
TextUtils.isEmpty(trustAgentComponentInfo.title)) continue;
|
||||
if (admin != null && dpm.getTrustAgentConfiguration(
|
||||
null, TrustAgentUtils.getComponentName(resolveInfo)) == null) {
|
||||
null, trustAgentManager.getComponentName(resolveInfo)) == null) {
|
||||
trustAgentComponentInfo.admin = admin;
|
||||
}
|
||||
result.add(trustAgentComponentInfo);
|
||||
|
@@ -19,7 +19,7 @@ package com.android.settings.security;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.trustagent.TrustAgentManager;
|
||||
import com.android.settings.security.trustagent.TrustAgentManager;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
|
||||
|
||||
|
@@ -30,8 +30,7 @@ import android.util.ArrayMap;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.trustagent.TrustAgentManager;
|
||||
import com.android.settings.trustagent.TrustAgentManagerImpl;
|
||||
import com.android.settings.security.trustagent.TrustAgentManager;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.drawer.TileUtils;
|
||||
@@ -192,7 +191,7 @@ public class SecurityFeatureProviderImpl implements SecurityFeatureProvider {
|
||||
@Override
|
||||
public TrustAgentManager getTrustAgentManager() {
|
||||
if (mTrustAgentManager == null) {
|
||||
mTrustAgentManager = new TrustAgentManagerImpl();
|
||||
mTrustAgentManager = new TrustAgentManager();
|
||||
}
|
||||
return mTrustAgentManager;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -11,10 +11,12 @@
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings;
|
||||
package com.android.settings.security.trustagent;
|
||||
|
||||
import static android.service.trust.TrustAgentService.TRUST_AGENT_META_DATA;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -22,40 +24,67 @@ import android.content.pm.ResolveInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.service.trust.TrustAgentService;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.Slog;
|
||||
import android.util.Xml;
|
||||
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
// TODO(b/34461256): Refactor TrustAgentUtils into TrustAgentManager.
|
||||
public class TrustAgentUtils {
|
||||
static final String TAG = "TrustAgentUtils";
|
||||
|
||||
private static final String TRUST_AGENT_META_DATA = TrustAgentService.TRUST_AGENT_META_DATA;
|
||||
/** A manager for trust agent state. */
|
||||
public class TrustAgentManager {
|
||||
|
||||
public static class TrustAgentComponentInfo {
|
||||
ComponentName componentName;
|
||||
String title;
|
||||
String summary;
|
||||
EnforcedAdmin admin = null;
|
||||
public ComponentName componentName;
|
||||
public String title;
|
||||
public String summary;
|
||||
public RestrictedLockUtils.EnforcedAdmin admin = null;
|
||||
}
|
||||
|
||||
public static ComponentName getComponentName(ResolveInfo resolveInfo) {
|
||||
private static final String TAG = "TrustAgentManager";
|
||||
|
||||
@VisibleForTesting
|
||||
static final String PERMISSION_PROVIDE_AGENT =
|
||||
android.Manifest.permission.PROVIDE_TRUST_AGENT;
|
||||
|
||||
/**
|
||||
* Determines if the service associated with a resolved trust agent intent is allowed to provide
|
||||
* trust on this device.
|
||||
*
|
||||
* @param resolveInfo The entry corresponding to the matched trust agent intent.
|
||||
* @param pm The package manager to be used to check for permissions.
|
||||
* @return {@code true} if the associated service is allowed to provide a trust agent, and
|
||||
* {@code false} if otherwise.
|
||||
*/
|
||||
public boolean shouldProvideTrust(ResolveInfo resolveInfo, PackageManager pm) {
|
||||
final String packageName = resolveInfo.serviceInfo.packageName;
|
||||
if (pm.checkPermission(PERMISSION_PROVIDE_AGENT, packageName)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
Log.w(TAG, "Skipping agent because package " + packageName
|
||||
+ " does not have permission " + PERMISSION_PROVIDE_AGENT + ".");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ComponentName getComponentName(ResolveInfo resolveInfo) {
|
||||
if (resolveInfo == null || resolveInfo.serviceInfo == null) return null;
|
||||
return new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name);
|
||||
}
|
||||
|
||||
public static TrustAgentComponentInfo getSettingsComponent(
|
||||
public TrustAgentComponentInfo getSettingsComponent(
|
||||
PackageManager pm, ResolveInfo resolveInfo) {
|
||||
if (resolveInfo == null || resolveInfo.serviceInfo == null
|
||||
|| resolveInfo.serviceInfo.metaData == null) return null;
|
||||
|| resolveInfo.serviceInfo.metaData == null) {
|
||||
return null;
|
||||
}
|
||||
String cn = null;
|
||||
TrustAgentComponentInfo trustAgentComponentInfo = new TrustAgentComponentInfo();
|
||||
XmlResourceParser parser = null;
|
||||
@@ -101,7 +130,8 @@ public class TrustAgentUtils {
|
||||
if (cn != null && cn.indexOf('/') < 0) {
|
||||
cn = resolveInfo.serviceInfo.packageName + "/" + cn;
|
||||
}
|
||||
trustAgentComponentInfo.componentName = (cn == null) ? null : ComponentName.unflattenFromString(cn);
|
||||
trustAgentComponentInfo.componentName =
|
||||
(cn == null) ? null : ComponentName.unflattenFromString(cn);
|
||||
return trustAgentComponentInfo;
|
||||
}
|
||||
}
|
@@ -14,7 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings;
|
||||
package com.android.settings.security.trustagent;
|
||||
|
||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
@@ -34,15 +36,14 @@ import android.util.ArraySet;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.trustagent.TrustAgentManager;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
public class TrustAgentSettings extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
private static final String SERVICE_INTERFACE = TrustAgentService.SERVICE_INTERFACE;
|
||||
@@ -152,7 +153,7 @@ public class TrustAgentSettings extends SettingsPreferenceFragment implements
|
||||
UserHandle.myUserId());
|
||||
}
|
||||
|
||||
ArrayMap<ComponentName, AgentInfo> findAvailableTrustAgents() {
|
||||
private ArrayMap<ComponentName, AgentInfo> findAvailableTrustAgents() {
|
||||
PackageManager pm = getActivity().getPackageManager();
|
||||
Intent trustAgentIntent = new Intent(SERVICE_INTERFACE);
|
||||
List<ResolveInfo> resolveInfos = pm.queryIntentServices(trustAgentIntent,
|
||||
@@ -169,7 +170,7 @@ public class TrustAgentSettings extends SettingsPreferenceFragment implements
|
||||
if (!mTrustAgentManager.shouldProvideTrust(resolveInfo, pm)) {
|
||||
continue;
|
||||
}
|
||||
ComponentName name = TrustAgentUtils.getComponentName(resolveInfo);
|
||||
ComponentName name = mTrustAgentManager.getComponentName(resolveInfo);
|
||||
AgentInfo agentInfo = new AgentInfo();
|
||||
agentInfo.label = resolveInfo.loadLabel(pm);
|
||||
agentInfo.icon = resolveInfo.loadIcon(pm);
|
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.trustagent;
|
||||
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
|
||||
|
||||
/** A manager for trust agent state. */
|
||||
public interface TrustAgentManager {
|
||||
|
||||
String PERMISSION_PROVIDE_AGENT = android.Manifest.permission.PROVIDE_TRUST_AGENT;
|
||||
|
||||
/**
|
||||
* Determines if the service associated with a resolved trust agent intent is allowed to provide
|
||||
* trust on this device.
|
||||
*
|
||||
* @param resolveInfo The entry corresponding to the matched trust agent intent.
|
||||
* @param pm The package manager to be used to check for permissions.
|
||||
* @return {@code true} if the associated service is allowed to provide a trust agent, and
|
||||
* {@code false} if otherwise.
|
||||
*/
|
||||
boolean shouldProvideTrust(ResolveInfo resolveInfo, PackageManager pm);
|
||||
}
|
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.trustagent;
|
||||
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.util.Log;
|
||||
|
||||
/** Implementation for {@code SecurityFeatureProvider}. */
|
||||
public class TrustAgentManagerImpl implements TrustAgentManager {
|
||||
|
||||
private static final String TAG = "TrustAgentFeature";
|
||||
|
||||
@Override
|
||||
public boolean shouldProvideTrust(ResolveInfo resolveInfo, PackageManager pm) {
|
||||
final String packageName = resolveInfo.serviceInfo.packageName;
|
||||
if (pm.checkPermission(PERMISSION_PROVIDE_AGENT, packageName)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
Log.w(TAG, "Skipping agent because package " + packageName
|
||||
+ " does not have permission " + PERMISSION_PROVIDE_AGENT + ".");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -77,7 +77,7 @@ com.android.settings.WifiCallingSettings
|
||||
com.android.settings.WifiCallingSettingsForSub
|
||||
com.android.settings.password.SetupChooseLockGeneric$SetupChooseLockGenericFragment
|
||||
com.android.settings.SetupRedactionInterstitial$SetupRedactionInterstitialFragment
|
||||
com.android.settings.TrustAgentSettings
|
||||
com.android.settings.security.trustagent.TrustAgentSettings
|
||||
com.android.settings.password.ChooseLockGeneric$ChooseLockGenericFragment
|
||||
com.android.settings.IccLockSettings
|
||||
com.android.settings.TetherSettings
|
||||
|
@@ -14,14 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.trustagent;
|
||||
package com.android.settings.security.trustagent;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -30,51 +33,48 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class TrustAgentFeatureProviderImplTest {
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
|
||||
public class TrustAgentFeatureProviderTest {
|
||||
|
||||
private static final String CANNED_PACKAGE_NAME = "com.test.package";
|
||||
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
private TrustAgentManagerImpl mImpl;
|
||||
private TrustAgentManager mTrustAgentManager;
|
||||
|
||||
@Before
|
||||
public void setUp() throws PackageManager.NameNotFoundException {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mImpl = new TrustAgentManagerImpl();
|
||||
mTrustAgentManager = new TrustAgentManager();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldProvideTrust_doesProvideTrustWithPermission() {
|
||||
when(mPackageManager.checkPermission(TrustAgentManager.PERMISSION_PROVIDE_AGENT,
|
||||
CANNED_PACKAGE_NAME)).thenReturn(PackageManager.PERMISSION_GRANTED);
|
||||
CANNED_PACKAGE_NAME)).thenReturn(PackageManager.PERMISSION_GRANTED);
|
||||
|
||||
ServiceInfo serviceInfo = new ServiceInfo();
|
||||
serviceInfo.packageName = CANNED_PACKAGE_NAME;
|
||||
ResolveInfo resolveInfo = new ResolveInfo();
|
||||
resolveInfo.serviceInfo = serviceInfo;
|
||||
|
||||
assertTrue(mImpl.shouldProvideTrust(resolveInfo, mPackageManager));
|
||||
assertThat(mTrustAgentManager.shouldProvideTrust(resolveInfo, mPackageManager))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldProvideTrust_doesNotProvideTrustWithoutPermission() {
|
||||
when(mPackageManager.checkPermission(TrustAgentManager.PERMISSION_PROVIDE_AGENT,
|
||||
CANNED_PACKAGE_NAME)).thenReturn(PackageManager.PERMISSION_DENIED);
|
||||
CANNED_PACKAGE_NAME)).thenReturn(PackageManager.PERMISSION_DENIED);
|
||||
|
||||
ServiceInfo serviceInfo = new ServiceInfo();
|
||||
serviceInfo.packageName = CANNED_PACKAGE_NAME;
|
||||
ResolveInfo resolveInfo = new ResolveInfo();
|
||||
resolveInfo.serviceInfo = serviceInfo;
|
||||
|
||||
assertFalse(mImpl.shouldProvideTrust(resolveInfo, mPackageManager));
|
||||
assertThat(mTrustAgentManager.shouldProvideTrust(resolveInfo, mPackageManager))
|
||||
.isFalse();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user