DO Disclosure: add UI that lists apps that were managed by owner:
- had permissions granted by admin - were installed by owner via policy Bug: 32692748 Test: m RunSettingsRoboTests Change-Id: I365e2f8f351671e68f83cceb7c0ca241d7a5a588
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -32,6 +31,7 @@ public abstract class AdminGrantedPermissionsPreferenceControllerBase
|
||||
private final String mPermissionGroup;
|
||||
private final ApplicationFeatureProvider mFeatureProvider;
|
||||
private final boolean mAsync;
|
||||
private boolean mHasApps;
|
||||
|
||||
public AdminGrantedPermissionsPreferenceControllerBase(Context context, Lifecycle lifecycle,
|
||||
boolean async, String[] permissions, String permissionGroup) {
|
||||
@@ -41,6 +41,7 @@ public abstract class AdminGrantedPermissionsPreferenceControllerBase
|
||||
mFeatureProvider = FeatureFactory.getFactory(context)
|
||||
.getApplicationFeatureProvider(context);
|
||||
mAsync = async;
|
||||
mHasApps = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,11 +51,13 @@ public abstract class AdminGrantedPermissionsPreferenceControllerBase
|
||||
(num) -> {
|
||||
if (num == 0) {
|
||||
preference.setVisible(false);
|
||||
mHasApps = false;
|
||||
} else {
|
||||
preference.setVisible(true);
|
||||
preference.setSummary(mContext.getResources().getQuantityString(
|
||||
R.plurals.enterprise_privacy_number_packages_lower_bound,
|
||||
num, num));
|
||||
mHasApps = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -76,7 +79,8 @@ public abstract class AdminGrantedPermissionsPreferenceControllerBase
|
||||
final Boolean[] haveAppsWithAdminGrantedPermissions = { null };
|
||||
mFeatureProvider.calculateNumberOfAppsWithAdminGrantedPermissions(mPermissions,
|
||||
false /* async */, (num) -> haveAppsWithAdminGrantedPermissions[0] = num > 0);
|
||||
return haveAppsWithAdminGrantedPermissions[0];
|
||||
mHasApps = haveAppsWithAdminGrantedPermissions[0];
|
||||
return mHasApps;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,9 +88,9 @@ public abstract class AdminGrantedPermissionsPreferenceControllerBase
|
||||
if (!getPreferenceKey().equals(preference.getKey())) {
|
||||
return false;
|
||||
}
|
||||
final Intent intent = new Intent(Intent.ACTION_MANAGE_PERMISSION_APPS)
|
||||
.putExtra(Intent.EXTRA_PERMISSION_NAME, mPermissionGroup);
|
||||
mContext.startActivity(intent);
|
||||
return true;
|
||||
if (!mHasApps) {
|
||||
return false;
|
||||
}
|
||||
return super.handlePreferenceTreeClick(preference);
|
||||
}
|
||||
}
|
||||
|
110
src/com/android/settings/enterprise/ApplicationListFragment.java
Normal file
110
src/com/android/settings/enterprise/ApplicationListFragment.java
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.Manifest;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Base fragment for displaying a list of applications on a device.
|
||||
* Inner static classes are concrete implementations.
|
||||
*/
|
||||
public abstract class ApplicationListFragment extends DashboardFragment
|
||||
implements ApplicationListPreferenceController.ApplicationListBuilder {
|
||||
|
||||
static final String TAG = "EnterprisePrivacySettings";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.ENTERPRISE_PRIVACY_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.app_list_disclosure_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
final List controllers = new ArrayList<>();
|
||||
ApplicationListPreferenceController controller = new ApplicationListPreferenceController(
|
||||
context, this, context.getPackageManager(), this);
|
||||
controllers.add(controller);
|
||||
return controllers;
|
||||
}
|
||||
|
||||
private abstract static class AdminGrantedPermission extends ApplicationListFragment {
|
||||
private final String[] mPermissions;
|
||||
|
||||
public AdminGrantedPermission(String[] permissions) {
|
||||
mPermissions = permissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildApplicationList(Context context,
|
||||
ApplicationFeatureProvider.ListOfAppsCallback callback) {
|
||||
FeatureFactory.getFactory(context).getApplicationFeatureProvider(context)
|
||||
.listAppsWithAdminGrantedPermissions(mPermissions, callback);
|
||||
}
|
||||
}
|
||||
|
||||
public static class AdminGrantedPermissionCamera extends AdminGrantedPermission {
|
||||
public AdminGrantedPermissionCamera() {
|
||||
super(new String[] {Manifest.permission.CAMERA});
|
||||
}
|
||||
}
|
||||
|
||||
public static class AdminGrantedPermissionLocation extends AdminGrantedPermission {
|
||||
public AdminGrantedPermissionLocation() {
|
||||
super(new String[] {Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION});
|
||||
}
|
||||
}
|
||||
|
||||
public static class AdminGrantedPermissionMicrophone extends AdminGrantedPermission {
|
||||
public AdminGrantedPermissionMicrophone() {
|
||||
super(new String[] {Manifest.permission.RECORD_AUDIO});
|
||||
}
|
||||
}
|
||||
|
||||
public static class EnterpriseInstalledPackages extends ApplicationListFragment {
|
||||
public EnterpriseInstalledPackages() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildApplicationList(Context context,
|
||||
ApplicationFeatureProvider.ListOfAppsCallback callback) {
|
||||
FeatureFactory.getFactory(context).getApplicationFeatureProvider(context).
|
||||
listPolicyInstalledApps(callback);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.PackageManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
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.UserAppInfo;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* PreferenceController that builds a dynamic list of applications provided by
|
||||
* {@link ApplicationListBuilder} instance.
|
||||
*/
|
||||
public class ApplicationListPreferenceController extends PreferenceController
|
||||
implements ApplicationFeatureProvider.ListOfAppsCallback {
|
||||
private final PackageManager mPm;
|
||||
private SettingsPreferenceFragment mParent;
|
||||
|
||||
public ApplicationListPreferenceController(Context context, ApplicationListBuilder builder,
|
||||
PackageManager packageManager, SettingsPreferenceFragment parent) {
|
||||
super(context);
|
||||
mPm = packageManager;
|
||||
mParent = parent;
|
||||
builder.buildApplicationList(context, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListOfAppsResult(List<UserAppInfo> result) {
|
||||
final PreferenceScreen screen = mParent.getPreferenceScreen();
|
||||
if (screen == null) {
|
||||
return;
|
||||
}
|
||||
final Context prefContext = mParent.getPreferenceManager().getContext();
|
||||
for (int position = 0; position < result.size(); position++) {
|
||||
final UserAppInfo item = result.get(position);
|
||||
final Preference preference = new Preference(prefContext);
|
||||
preference.setLayoutResource(R.layout.preference_app);
|
||||
preference.setTitle(item.appInfo.loadLabel(mPm));
|
||||
preference.setIcon(item.appInfo.loadIcon(mPm));
|
||||
preference.setOrder(position);
|
||||
preference.setSelectable(false);
|
||||
screen.addPreference(preference);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple interface for building application list within {
|
||||
* @link ApplicationListPreferenceController}
|
||||
*/
|
||||
public interface ApplicationListBuilder {
|
||||
void buildApplicationList(Context context,
|
||||
ApplicationFeatureProvider.ListOfAppsCallback callback);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user