Add admin-set default apps to Enterprise Privacy Settings page

This CL adds information about the number of default handlers for
common intents (e.g. browser, e-mail, calendar) set by the admin.

Bug: 32692748
Test: make RunSettingsRoboTests

Change-Id: I569d9ddabeee2b2aa9a892b28066abb8bf920fcf
This commit is contained in:
Bartosz Fabianowski
2017-01-19 17:20:03 +01:00
parent b62f4f75c9
commit 482908f226
15 changed files with 520 additions and 20 deletions

View File

@@ -17,7 +17,6 @@ package com.android.settings.applications;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.RemoteException;
@@ -33,11 +32,11 @@ public abstract class AppWithAdminGrantedPermissionsCounter extends AppCounter {
private final String[] mPermissions;
private final PackageManagerWrapper mPackageManager;
private final IPackageManager mPackageManagerService;
private final IPackageManagerWrapper mPackageManagerService;
private final DevicePolicyManagerWrapper mDevicePolicyManager;
public AppWithAdminGrantedPermissionsCounter(Context context, String[] permissions,
PackageManagerWrapper packageManager, IPackageManager packageManagerService,
PackageManagerWrapper packageManager, IPackageManagerWrapper packageManagerService,
DevicePolicyManagerWrapper devicePolicyManager) {
super(context, packageManager);
mPermissions = permissions;

View File

@@ -17,8 +17,11 @@
package com.android.settings.applications;
import android.app.Fragment;
import android.content.Intent;
import android.view.View;
import java.util.Set;
public interface ApplicationFeatureProvider {
/**
@@ -54,10 +57,48 @@ public interface ApplicationFeatureProvider {
void calculateNumberOfAppsWithAdminGrantedPermissions(String[] permissions,
NumberOfAppsCallback callback);
/**
* Return the persistent preferred activities configured by the admin for the current user and
* all its managed profiles. A persistent preferred activity is an activity that the admin
* configured to always handle a given intent (e.g. open browser), even if the user has other
* apps installed that would also be able to handle the intent.
*
* @param intent The intents for which to find persistent preferred activities
*
* @return the persistent preferred activites for the given intent
*/
Set<PersistentPreferredActivityInfo> findPersistentPreferredActivities(Intent[] intents);
/**
* Callback that receives the number of packages installed on the device.
*/
interface NumberOfAppsCallback {
void onNumberOfAppsResult(int num);
}
public static class PersistentPreferredActivityInfo {
public final String packageName;
public final int userId;
public PersistentPreferredActivityInfo(String packageName, int userId) {
this.packageName = packageName;
this.userId = userId;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof PersistentPreferredActivityInfo)) {
return false;
}
final PersistentPreferredActivityInfo otherActivityInfo
= (PersistentPreferredActivityInfo) other;
return otherActivityInfo.packageName.equals(packageName)
&& otherActivityInfo.userId == userId;
}
@Override
public int hashCode() {
return packageName.hashCode() ^ userId;
}
}
}

View File

@@ -18,25 +18,34 @@ package com.android.settings.applications;
import android.app.Fragment;
import android.content.Context;
import android.content.pm.IPackageManager;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ComponentInfo;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.UserInfo;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.ArraySet;
import android.view.View;
import com.android.settings.enterprise.DevicePolicyManagerWrapper;
import java.util.List;
import java.util.Set;
public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvider {
private final Context mContext;
private final PackageManagerWrapper mPm;
private final IPackageManager mPms;
private final IPackageManagerWrapper mPms;
private final DevicePolicyManagerWrapper mDpm;
private final UserManager mUm;
public ApplicationFeatureProviderImpl(Context context, PackageManagerWrapper pm,
IPackageManager pms, DevicePolicyManagerWrapper dpm) {
IPackageManagerWrapper pms, DevicePolicyManagerWrapper dpm) {
mContext = context.getApplicationContext();
mPm = pm;
mPms = pms;
@@ -61,6 +70,39 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
callback).execute();
}
@Override
public Set<PersistentPreferredActivityInfo> findPersistentPreferredActivities(
Intent[] intents) {
final Set<PersistentPreferredActivityInfo> activities = new ArraySet<>();
final List<UserHandle> users = mUm.getUserProfiles();
for (final Intent intent : intents) {
for (final UserHandle user : users) {
final int userId = user.getIdentifier();
try {
final ResolveInfo resolveInfo = mPms.findPersistentPreferredActivity(intent,
userId);
if (resolveInfo != null) {
ComponentInfo componentInfo = null;
if (resolveInfo.activityInfo != null) {
componentInfo = resolveInfo.activityInfo;
} else if (resolveInfo.serviceInfo != null) {
componentInfo = resolveInfo.serviceInfo;
} else if (resolveInfo.providerInfo != null) {
componentInfo = resolveInfo.providerInfo;
}
if (componentInfo != null) {
activities.add(new PersistentPreferredActivityInfo(
componentInfo.packageName, userId));
}
}
} catch (RemoteException exception) {
}
}
}
return activities;
}
private static class AllUserInstalledAppCounter extends InstalledAppCounter {
private NumberOfAppsCallback mCallback;
@@ -86,7 +128,7 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
private NumberOfAppsCallback mCallback;
AllUserAppWithAdminGrantedPermissionsCounter(Context context, String[] permissions,
PackageManagerWrapper packageManager, IPackageManager packageManagerService,
PackageManagerWrapper packageManager, IPackageManagerWrapper packageManagerService,
DevicePolicyManagerWrapper devicePolicyManager, NumberOfAppsCallback callback) {
super(context, permissions, packageManager, packageManagerService, devicePolicyManager);
mCallback = callback;

View File

@@ -0,0 +1,44 @@
/*
* Copyright (C) 2017 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.applications;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.RemoteException;
/**
* This interface replicates a subset of the android.content.pm.IPackageManager (PMS). The interface
* exists so that we can use a thin wrapper around the PMS in production code and a mock in tests.
* We cannot directly mock or shadow the PMS, because some of the methods we rely on are newer than
* the API version supported by Robolectric.
*/
public interface IPackageManagerWrapper {
/**
* Calls {@code IPackageManager.checkUidPermission()}.
*
* @see android.content.pm.IPackageManager#checkUidPermission
*/
int checkUidPermission(String permName, int uid) throws RemoteException;
/**
* Calls {@code IPackageManager.findPersistentPreferredActivity()}.
*
* @see android.content.pm.IPackageManager#findPersistentPreferredActivity
*/
ResolveInfo findPersistentPreferredActivity(Intent intent, int userId) throws RemoteException;
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright (C) 2017 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.applications;
import android.content.Intent;
import android.content.pm.IPackageManager;
import android.content.pm.ResolveInfo;
import android.os.RemoteException;
public class IPackageManagerWrapperImpl implements IPackageManagerWrapper {
private final IPackageManager mPms;
public IPackageManagerWrapperImpl(IPackageManager pms) {
mPms = pms;
}
@Override
public int checkUidPermission(String permName, int uid) throws RemoteException {
return mPms.checkUidPermission(permName, uid);
}
@Override
public ResolveInfo findPersistentPreferredActivity(Intent intent, int userId)
throws RemoteException {
return mPms.findPersistentPreferredActivity(intent, userId);
}
}