Merge "Add admin-set default apps to Enterprise Privacy Settings page"
This commit is contained in:
committed by
Android (Google) Code Review
commit
15c1c53068
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -59,6 +59,7 @@ public class EnterprisePrivacySettings extends DashboardFragment {
|
||||
controllers.add(new AdminGrantedLocationPermissionsPreferenceController(context));
|
||||
controllers.add(new AdminGrantedMicrophonePermissionPreferenceController(context));
|
||||
controllers.add(new AdminGrantedCameraPermissionPreferenceController(context));
|
||||
controllers.add(new EnterpriseSetDefaultAppsPreferenceController(context));
|
||||
controllers.add(new AlwaysOnVpnPrimaryUserPreferenceController(context));
|
||||
controllers.add(new AlwaysOnVpnManagedProfilePreferenceController(context));
|
||||
controllers.add(new GlobalHttpProxyPreferenceController(context));
|
||||
|
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.provider.ContactsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
public class EnterpriseSetDefaultAppsPreferenceController extends PreferenceController {
|
||||
|
||||
private static final String KEY_DEFAULT_APPS = "number_enterprise_set_default_apps";
|
||||
private final ApplicationFeatureProvider mFeatureProvider;
|
||||
|
||||
public EnterpriseSetDefaultAppsPreferenceController(Context context) {
|
||||
super(context);
|
||||
mFeatureProvider = FeatureFactory.getFactory(context)
|
||||
.getApplicationFeatureProvider(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
// Browser
|
||||
int num = mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
|
||||
buildIntent(Intent.ACTION_VIEW, Intent.CATEGORY_BROWSABLE, "http:", null)}).size();
|
||||
// Camera
|
||||
num += mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
|
||||
new Intent(MediaStore.ACTION_IMAGE_CAPTURE),
|
||||
new Intent(MediaStore.ACTION_VIDEO_CAPTURE)}).size();
|
||||
// Map
|
||||
num += mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
|
||||
buildIntent(Intent.ACTION_VIEW, null, "geo:", null)}).size();
|
||||
// E-mail
|
||||
num += mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
|
||||
new Intent(Intent.ACTION_SENDTO), new Intent(Intent.ACTION_SEND),
|
||||
new Intent(Intent.ACTION_SEND_MULTIPLE)}).size();
|
||||
// Calendar
|
||||
num += mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
|
||||
buildIntent(Intent.ACTION_INSERT, null, null, "vnd.android.cursor.dir/event")})
|
||||
.size();
|
||||
// Contacts
|
||||
num += mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
|
||||
buildIntent(Intent.ACTION_PICK, null, null,
|
||||
ContactsContract.Contacts.CONTENT_TYPE)}).size();
|
||||
// Dialer
|
||||
num += mFeatureProvider.findPersistentPreferredActivities(new Intent[] {
|
||||
new Intent(Intent.ACTION_DIAL), new Intent(Intent.ACTION_CALL)}).size();
|
||||
|
||||
if (num == 0) {
|
||||
preference.setVisible(false);
|
||||
} else {
|
||||
preference.setVisible(true);
|
||||
preference.setTitle(mContext.getResources().getQuantityString(
|
||||
R.plurals.enterprise_privacy_number_enterprise_set_default_apps,
|
||||
num, num));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_DEFAULT_APPS;
|
||||
}
|
||||
|
||||
private static Intent buildIntent(String action, String category, String protocol,
|
||||
String type) {
|
||||
final Intent intent = new Intent(action);
|
||||
if (category != null) {
|
||||
intent.addCategory(category);
|
||||
}
|
||||
if (protocol != null) {
|
||||
intent.setData(Uri.parse(protocol));
|
||||
}
|
||||
if (type != null) {
|
||||
intent.setType(type);
|
||||
}
|
||||
return intent;
|
||||
}
|
||||
}
|
@@ -25,6 +25,7 @@ import android.support.annotation.Keep;
|
||||
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
import com.android.settings.applications.ApplicationFeatureProviderImpl;
|
||||
import com.android.settings.applications.IPackageManagerWrapperImpl;
|
||||
import com.android.settings.applications.PackageManagerWrapperImpl;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProviderImpl;
|
||||
@@ -90,7 +91,7 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
if (mApplicationFeatureProvider == null) {
|
||||
mApplicationFeatureProvider = new ApplicationFeatureProviderImpl(context,
|
||||
new PackageManagerWrapperImpl(context.getPackageManager()),
|
||||
AppGlobals.getPackageManager(),
|
||||
new IPackageManagerWrapperImpl(AppGlobals.getPackageManager()),
|
||||
new DevicePolicyManagerWrapperImpl((DevicePolicyManager) context
|
||||
.getSystemService(Context.DEVICE_POLICY_SERVICE)));
|
||||
}
|
||||
|
Reference in New Issue
Block a user