Ensure trust agents are only provided by platform packages
Ensures that Settings only shows TrustAgentServices from platform packages. Bug: 15287044 Change-Id: I62c131d99c7266f8617ec32a50a4f5549a07b4b7
This commit is contained in:
@@ -109,6 +109,7 @@ public class AdvancedSecuritySettings extends ListFragment implements View.OnCli
|
|||||||
|
|
||||||
for (ResolveInfo resolveInfo : resolveInfos) {
|
for (ResolveInfo resolveInfo : resolveInfos) {
|
||||||
if (resolveInfo.serviceInfo == null) continue;
|
if (resolveInfo.serviceInfo == null) continue;
|
||||||
|
if (!TrustAgentUtils.checkProvidePermission(resolveInfo, pm)) continue;
|
||||||
ComponentName name = TrustAgentUtils.getComponentName(resolveInfo);
|
ComponentName name = TrustAgentUtils.getComponentName(resolveInfo);
|
||||||
if (!mAvailableAgents.containsKey(name)) {
|
if (!mAvailableAgents.containsKey(name)) {
|
||||||
AgentInfo agentInfo = new AgentInfo();
|
AgentInfo agentInfo = new AgentInfo();
|
||||||
|
@@ -317,6 +317,7 @@ public class SecuritySettings extends RestrictedSettingsFragment
|
|||||||
PackageManager.GET_META_DATA);
|
PackageManager.GET_META_DATA);
|
||||||
for (ResolveInfo resolveInfo : resolveInfos) {
|
for (ResolveInfo resolveInfo : resolveInfos) {
|
||||||
if (resolveInfo.serviceInfo == null) continue;
|
if (resolveInfo.serviceInfo == null) continue;
|
||||||
|
if (!TrustAgentUtils.checkProvidePermission(resolveInfo, pm)) continue;
|
||||||
TrustAgentUtils.TrustAgentComponentInfo trustAgentComponentInfo =
|
TrustAgentUtils.TrustAgentComponentInfo trustAgentComponentInfo =
|
||||||
TrustAgentUtils.getSettingsComponent(pm, resolveInfo);
|
TrustAgentUtils.getSettingsComponent(pm, resolveInfo);
|
||||||
if (trustAgentComponentInfo.componentName == null ||
|
if (trustAgentComponentInfo.componentName == null ||
|
||||||
|
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
|
import com.android.internal.Manifest;
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
@@ -24,6 +26,7 @@ import android.content.res.TypedArray;
|
|||||||
import android.content.res.XmlResourceParser;
|
import android.content.res.XmlResourceParser;
|
||||||
import android.service.trust.TrustAgentService;
|
import android.service.trust.TrustAgentService;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
|
|
||||||
@@ -36,6 +39,21 @@ public class TrustAgentUtils {
|
|||||||
static final String TAG = "TrustAgentUtils";
|
static final String TAG = "TrustAgentUtils";
|
||||||
|
|
||||||
private static final String TRUST_AGENT_META_DATA = TrustAgentService.TRUST_AGENT_META_DATA;
|
private static final String TRUST_AGENT_META_DATA = TrustAgentService.TRUST_AGENT_META_DATA;
|
||||||
|
private static final String PERMISSION_PROVIDE_AGENT = Manifest.permission.PROVIDE_TRUST_AGENT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true, if the service in resolveInfo has the permission to provide a trust agent.
|
||||||
|
*/
|
||||||
|
public static boolean checkProvidePermission(ResolveInfo resolveInfo, PackageManager pm) {
|
||||||
|
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 static class TrustAgentComponentInfo {
|
public static class TrustAgentComponentInfo {
|
||||||
ComponentName componentName;
|
ComponentName componentName;
|
||||||
|
Reference in New Issue
Block a user