DO Disclosures: detailed application lists
Add UI that lists enterprise set default apps for handling important intents (opening browser, using camera, phone, etc). Bug: 32692748 Test: m RunSettingsRoboTests Change-Id: I75bb97d1b3728b1dcb90981b24d12edf510c4b04
This commit is contained in:
@@ -38,11 +38,6 @@ public abstract class ApplicationListFragment extends DashboardFragment
|
||||
|
||||
static final String TAG = "EnterprisePrivacySettings";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.ENTERPRISE_PRIVACY_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
@@ -75,6 +70,11 @@ public abstract class ApplicationListFragment extends DashboardFragment
|
||||
FeatureFactory.getFactory(context).getApplicationFeatureProvider(context)
|
||||
.listAppsWithAdminGrantedPermissions(mPermissions, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.ENTERPRISE_PRIVACY_PERMISSIONS;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AdminGrantedPermissionCamera extends AdminGrantedPermission {
|
||||
@@ -100,6 +100,11 @@ public abstract class ApplicationListFragment extends DashboardFragment
|
||||
public EnterpriseInstalledPackages() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.ENTERPRISE_PRIVACY_INSTALLED_APPS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildApplicationList(Context context,
|
||||
ApplicationFeatureProvider.ListOfAppsCallback callback) {
|
||||
|
@@ -17,10 +17,8 @@
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.content.res.Resources;
|
||||
|
@@ -14,7 +14,6 @@
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Fragment for displaying a list of default applications set by profile or device admin.
|
||||
*/
|
||||
public class EnterpriseSetDefaultAppsListFragment extends DashboardFragment {
|
||||
static final String TAG = "EnterprisePrivacySettings";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.ENTERPRISE_PRIVACY_DEFAULT_APPS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.enterprise_set_default_apps_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
final List controllers = new ArrayList<PreferenceController>();
|
||||
final EnterpriseSetDefaultAppsListPreferenceController controller =
|
||||
new EnterpriseSetDefaultAppsListPreferenceController(
|
||||
context, this, context.getPackageManager());
|
||||
controllers.add(controller);
|
||||
return controllers;
|
||||
}
|
||||
}
|
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* 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.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
import com.android.settings.applications.EnterpriseDefaultApps;
|
||||
import com.android.settings.applications.UserAppInfo;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.users.UserFeatureProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* PreferenceController that builds a dynamic list of default apps set by device or profile owner.
|
||||
*/
|
||||
public class EnterpriseSetDefaultAppsListPreferenceController extends PreferenceController {
|
||||
private final PackageManager mPm;
|
||||
private final SettingsPreferenceFragment mParent;
|
||||
private final ApplicationFeatureProvider mApplicationFeatureProvider;
|
||||
private final EnterprisePrivacyFeatureProvider mEnterprisePrivacyFeatureProvider;
|
||||
private final UserFeatureProvider mUserFeatureProvider;
|
||||
|
||||
private List<UserInfo> mUsers = Collections.emptyList();
|
||||
private List<EnumMap<EnterpriseDefaultApps, List<ApplicationInfo>>> mApps =
|
||||
Collections.emptyList();
|
||||
|
||||
public EnterpriseSetDefaultAppsListPreferenceController(Context context,
|
||||
SettingsPreferenceFragment parent, PackageManager packageManager) {
|
||||
super(context);
|
||||
mPm = packageManager;
|
||||
mParent = parent;
|
||||
final FeatureFactory factory = FeatureFactory.getFactory(context);
|
||||
mApplicationFeatureProvider = factory.getApplicationFeatureProvider(context);
|
||||
mEnterprisePrivacyFeatureProvider = factory.getEnterprisePrivacyFeatureProvider(context);
|
||||
mUserFeatureProvider = factory.getUserFeatureProvider(context);
|
||||
buildAppList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds data for UI. Updates mUsers and mApps so that they contain non-empty list.
|
||||
*/
|
||||
private void buildAppList() {
|
||||
mUsers = new ArrayList<>();
|
||||
mApps = new ArrayList<>();
|
||||
for (UserHandle user : mUserFeatureProvider.getUserProfiles()) {
|
||||
boolean hasDefaultsForUser = false;
|
||||
EnumMap<EnterpriseDefaultApps, List<ApplicationInfo>> userMap = null;
|
||||
|
||||
for (EnterpriseDefaultApps typeOfDefault : EnterpriseDefaultApps.values()) {
|
||||
List<UserAppInfo> apps = mApplicationFeatureProvider.
|
||||
findPersistentPreferredActivities(user.getIdentifier(),
|
||||
typeOfDefault.getIntents());
|
||||
if (apps.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (!hasDefaultsForUser) {
|
||||
hasDefaultsForUser = true;
|
||||
mUsers.add(apps.get(0).userInfo);
|
||||
userMap = new EnumMap<>(EnterpriseDefaultApps.class);
|
||||
mApps.add(userMap);
|
||||
}
|
||||
ArrayList<ApplicationInfo> applicationInfos = new ArrayList<>();
|
||||
for (UserAppInfo userAppInfo : apps) {
|
||||
applicationInfos.add(userAppInfo.appInfo);
|
||||
}
|
||||
userMap.put(typeOfDefault, applicationInfos);
|
||||
}
|
||||
}
|
||||
new Handler(mContext.getMainLooper()).post(() -> { updateUi(); });
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateUi() {
|
||||
final Context prefContext = mParent.getPreferenceManager().getContext();
|
||||
final PreferenceScreen screen = mParent.getPreferenceScreen();
|
||||
if (screen == null) {
|
||||
return;
|
||||
}
|
||||
if (!mEnterprisePrivacyFeatureProvider.isInCompMode() && mUsers.size() == 1) {
|
||||
createPreferences(prefContext, screen, mApps.get(0));
|
||||
} else {
|
||||
for (int i = 0; i < mUsers.size(); i++) {
|
||||
final UserInfo userInfo = mUsers.get(i);
|
||||
final PreferenceCategory category = new PreferenceCategory(prefContext);
|
||||
screen.addPreference(category);
|
||||
if (userInfo.isManagedProfile()) {
|
||||
category.setTitle(R.string.managed_device_admin_title);
|
||||
} else {
|
||||
category.setTitle(R.string.personal_device_admin_title);
|
||||
}
|
||||
category.setOrder(i);
|
||||
createPreferences(prefContext, category, mApps.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createPreferences(Context prefContext, PreferenceGroup group,
|
||||
EnumMap<EnterpriseDefaultApps, List<ApplicationInfo>> apps) {
|
||||
if (group == null) {
|
||||
return;
|
||||
}
|
||||
for (EnterpriseDefaultApps typeOfDefault : EnterpriseDefaultApps.values()) {
|
||||
final List<ApplicationInfo> appsForCategory = apps.get(typeOfDefault);
|
||||
if (appsForCategory == null || appsForCategory.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
final Preference preference = new Preference(prefContext);
|
||||
preference.setTitle(getTitle(prefContext, typeOfDefault, appsForCategory.size()));
|
||||
preference.setSummary(buildSummaryString(prefContext, appsForCategory));
|
||||
preference.setOrder(typeOfDefault.ordinal());
|
||||
preference.setSelectable(false);
|
||||
group.addPreference(preference);
|
||||
}
|
||||
}
|
||||
|
||||
private CharSequence buildSummaryString(Context context, List<ApplicationInfo> apps) {
|
||||
final CharSequence[] appNames = new String[apps.size()];
|
||||
for (int i = 0; i < apps.size(); i++) {
|
||||
appNames[i] = apps.get(i).loadLabel(mPm);
|
||||
}
|
||||
if (apps.size() == 1) {
|
||||
return appNames[0];
|
||||
} else if (apps.size() == 2) {
|
||||
return context.getString(R.string.app_names_concatenation_template_2, appNames[0],
|
||||
appNames[1]);
|
||||
} else {
|
||||
return context.getString(R.string.app_names_concatenation_template_3, appNames[0],
|
||||
appNames[1], appNames[2]);
|
||||
}
|
||||
}
|
||||
|
||||
private String getTitle(Context context, EnterpriseDefaultApps typeOfDefault, int appCount) {
|
||||
switch (typeOfDefault) {
|
||||
case BROWSER:
|
||||
return context.getString(R.string.default_browser_title);
|
||||
case CALENDAR:
|
||||
return context.getString(R.string.default_calendar_app_title);
|
||||
case CONTACTS:
|
||||
return context.getString(R.string.default_contacts_app_title);
|
||||
case PHONE:
|
||||
return context.getResources()
|
||||
.getQuantityString(R.plurals.default_phone_app_title, appCount);
|
||||
case MAP:
|
||||
return context.getString(R.string.default_map_app_title);
|
||||
case EMAIL:
|
||||
return context.getResources()
|
||||
.getQuantityString(R.plurals.default_email_app_title, appCount);
|
||||
case CAMERA:
|
||||
return context.getResources()
|
||||
.getQuantityString(R.plurals.default_camera_app_title, appCount);
|
||||
default:
|
||||
throw new IllegalStateException("Unknown type of default " + typeOfDefault);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -14,28 +14,29 @@
|
||||
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.os.UserHandle;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
import com.android.settings.applications.EnterpriseDefaultApps;
|
||||
import com.android.settings.core.DynamicAvailabilityPreferenceController;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.users.UserFeatureProvider;
|
||||
|
||||
public class EnterpriseSetDefaultAppsPreferenceController
|
||||
extends DynamicAvailabilityPreferenceController {
|
||||
|
||||
private static final String KEY_DEFAULT_APPS = "number_enterprise_set_default_apps";
|
||||
private final ApplicationFeatureProvider mFeatureProvider;
|
||||
private final ApplicationFeatureProvider mApplicationFeatureProvider;
|
||||
private final UserFeatureProvider mUserFeatureProvider;
|
||||
|
||||
public EnterpriseSetDefaultAppsPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context, lifecycle);
|
||||
mFeatureProvider = FeatureFactory.getFactory(context)
|
||||
.getApplicationFeatureProvider(context);
|
||||
final FeatureFactory factory = FeatureFactory.getFactory(context);
|
||||
mApplicationFeatureProvider = factory.getApplicationFeatureProvider(context);
|
||||
mUserFeatureProvider = factory.getUserFeatureProvider(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,47 +57,14 @@ public class EnterpriseSetDefaultAppsPreferenceController
|
||||
}
|
||||
|
||||
private int getNumberOfEnterpriseSetDefaultApps() {
|
||||
// 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();
|
||||
|
||||
int num = 0;
|
||||
for (UserHandle user : mUserFeatureProvider.getUserProfiles()) {
|
||||
for (EnterpriseDefaultApps app : EnterpriseDefaultApps.values()) {
|
||||
num += mApplicationFeatureProvider
|
||||
.findPersistentPreferredActivities(user.getIdentifier(),
|
||||
app.getIntents()).size();
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user