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
Merged-In: I365e2f8f351671e68f83cceb7c0ca241d7a5a588
(cherry picked from commit 60b2960cbb)
This commit is contained in:
Denis Kuznetsov
2017-04-27 10:44:21 +02:00
parent b21808bd6b
commit 7db69b7a26
22 changed files with 1544 additions and 186 deletions

View File

@@ -0,0 +1,69 @@
/*
* 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.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.os.AsyncTask;
import android.os.UserHandle;
import android.os.UserManager;
import java.util.ArrayList;
import java.util.List;
/**
* Lists apps for current user that fit some criteria specified by includeInCount method
* implementation.
* This class is similar to {@link AppCounter} class, but but builds actual list of apps instead
* of just counting them.
*/
public abstract class AppLister extends AsyncTask<Void, Void, List<UserAppInfo>> {
protected final PackageManagerWrapper mPm;
protected final UserManager mUm;
public AppLister(PackageManagerWrapper packageManager, UserManager userManager) {
mPm = packageManager;
mUm = userManager;
}
@Override
protected List<UserAppInfo> doInBackground(Void... params) {
final List<UserAppInfo> result = new ArrayList<>();
for (UserInfo user : mUm.getProfiles(UserHandle.myUserId())) {
final List<ApplicationInfo> list =
mPm.getInstalledApplicationsAsUser(PackageManager.GET_DISABLED_COMPONENTS
| PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS
| (user.isAdmin() ? PackageManager.MATCH_ANY_USER : 0),
user.id);
for (ApplicationInfo info : list) {
if (includeInCount(info)) {
result.add(new UserAppInfo(user, info));
}
}
}
return result;
}
@Override
protected void onPostExecute(List<UserAppInfo> list) {
onAppListBuilt(list);
}
protected abstract void onAppListBuilt(List<UserAppInfo> list);
protected abstract boolean includeInCount(ApplicationInfo info);
}

View File

@@ -31,7 +31,6 @@ import com.android.settings.enterprise.DevicePolicyManagerWrapper;
public abstract class AppWithAdminGrantedPermissionsCounter extends AppCounter {
private final String[] mPermissions;
private final PackageManagerWrapper mPackageManager;
private final IPackageManagerWrapper mPackageManagerService;
private final DevicePolicyManagerWrapper mDevicePolicyManager;
@@ -40,18 +39,24 @@ public abstract class AppWithAdminGrantedPermissionsCounter extends AppCounter {
DevicePolicyManagerWrapper devicePolicyManager) {
super(context, packageManager);
mPermissions = permissions;
mPackageManager = packageManager;
mPackageManagerService = packageManagerService;
mDevicePolicyManager = devicePolicyManager;
}
@Override
protected boolean includeInCount(ApplicationInfo info) {
return includeInCount(mPermissions, mDevicePolicyManager, mPm, mPackageManagerService,
info);
}
public static boolean includeInCount(String[] permissions,
DevicePolicyManagerWrapper devicePolicyManager, PackageManagerWrapper packageManager,
IPackageManagerWrapper packageManagerService, ApplicationInfo info) {
if (info.targetSdkVersion >= Build.VERSION_CODES.M) {
// The app uses run-time permissions. Check whether one or more of the permissions were
// granted by enterprise policy.
for (final String permission : mPermissions) {
if (mDevicePolicyManager.getPermissionGrantState(null /* admin */, info.packageName,
for (final String permission : permissions) {
if (devicePolicyManager.getPermissionGrantState(null /* admin */, info.packageName,
permission) == DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED) {
return true;
}
@@ -61,14 +66,14 @@ public abstract class AppWithAdminGrantedPermissionsCounter extends AppCounter {
// The app uses install-time permissions. Check whether the app requested one or more of the
// permissions and was installed by enterprise policy, implicitly granting permissions.
if (mPackageManager.getInstallReason(info.packageName,
if (packageManager.getInstallReason(info.packageName,
new UserHandle(UserHandle.getUserId(info.uid)))
!= PackageManager.INSTALL_REASON_POLICY) {
return false;
}
try {
for (final String permission : mPermissions) {
if (mPackageManagerService.checkUidPermission(permission, info.uid)
for (final String permission : permissions) {
if (packageManagerService.checkUidPermission(permission, info.uid)
== PackageManager.PERMISSION_GRANTED) {
return true;
}

View File

@@ -0,0 +1,46 @@
/*
* 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.pm.ApplicationInfo;
import android.os.UserManager;
import com.android.settings.enterprise.DevicePolicyManagerWrapper;
/**
* Lists installed apps across all users that have been granted one or more specific permissions by
* the admin.
*/
public abstract class AppWithAdminGrantedPermissionsLister extends AppLister {
private final String[] mPermissions;
private final IPackageManagerWrapper mPackageManagerService;
private final DevicePolicyManagerWrapper mDevicePolicyManager;
public AppWithAdminGrantedPermissionsLister(String[] permissions,
PackageManagerWrapper packageManager, IPackageManagerWrapper packageManagerService,
DevicePolicyManagerWrapper devicePolicyManager, UserManager userManager) {
super(packageManager, userManager);
mPermissions = permissions;
mPackageManagerService = packageManagerService;
mDevicePolicyManager = devicePolicyManager;
}
@Override
protected boolean includeInCount(ApplicationInfo info) {
return AppWithAdminGrantedPermissionsCounter.includeInCount(mPermissions,
mDevicePolicyManager, mPm, mPackageManagerService, info);
}
}

View File

@@ -22,6 +22,7 @@ import android.app.Fragment;
import android.content.Intent;
import android.view.View;
import java.util.List;
import java.util.Set;
public interface ApplicationFeatureProvider {
@@ -48,6 +49,14 @@ public interface ApplicationFeatureProvider {
*/
void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback);
/**
* Asynchronously builds the list of apps installed on the device via policy in the current user
* and all its managed profiles.
*
* @param callback The callback to invoke with the result
*/
void listPolicyInstalledApps(ListOfAppsCallback callback);
/**
* Asynchronously calculates the total number of apps installed in the current user and all its
* managed profiles that have been granted one or more of the given permissions by the admin.
@@ -60,6 +69,16 @@ public interface ApplicationFeatureProvider {
void calculateNumberOfAppsWithAdminGrantedPermissions(String[] permissions, boolean async,
NumberOfAppsCallback callback);
/**
* Asynchronously builds the list of apps installed in the current user and all its
* managed profiles that have been granted one or more of the given permissions by the admin.
*
* @param permissions Only consider apps that have been granted one or more of these permissions
* by the admin, either at run-time or install-time
* @param callback The callback to invoke with the result
*/
void listAppsWithAdminGrantedPermissions(String[] permissions, ListOfAppsCallback 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
@@ -79,6 +98,13 @@ public interface ApplicationFeatureProvider {
void onNumberOfAppsResult(int num);
}
/**
* Callback that receives the list of packages installed on the device.
*/
interface ListOfAppsCallback {
void onListOfAppsResult(List<UserAppInfo> result);
}
public static class PersistentPreferredActivityInfo {
public final String packageName;
public final int userId;

View File

@@ -73,6 +73,13 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
}
}
@Override
public void listPolicyInstalledApps(ListOfAppsCallback callback) {
final CurrentUserPolicyInstalledAppLister lister =
new CurrentUserPolicyInstalledAppLister(mPm, mUm, callback);
lister.execute();
}
@Override
public void calculateNumberOfAppsWithAdminGrantedPermissions(String[] permissions,
boolean async, NumberOfAppsCallback callback) {
@@ -86,6 +93,15 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
}
}
@Override
public void listAppsWithAdminGrantedPermissions(String[] permissions,
ListOfAppsCallback callback) {
final CurrentUserAppWithAdminGrantedPermissionsLister lister =
new CurrentUserAppWithAdminGrantedPermissionsLister(permissions, mPm, mPms, mDpm,
mUm, callback);
lister.execute();
}
@Override
public Set<PersistentPreferredActivityInfo> findPersistentPreferredActivities(
Intent[] intents) {
@@ -152,4 +168,39 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
mCallback.onNumberOfAppsResult(num);
}
}
private static class CurrentUserPolicyInstalledAppLister extends InstalledAppLister {
private ListOfAppsCallback mCallback;
CurrentUserPolicyInstalledAppLister(PackageManagerWrapper packageManager,
UserManager userManager, ListOfAppsCallback callback) {
super(packageManager, userManager);
mCallback = callback;
}
@Override
protected void onAppListBuilt(List<UserAppInfo> list) {
mCallback.onListOfAppsResult(list);
}
}
private static class CurrentUserAppWithAdminGrantedPermissionsLister extends
AppWithAdminGrantedPermissionsLister {
private ListOfAppsCallback mCallback;
CurrentUserAppWithAdminGrantedPermissionsLister(String[] permissions,
PackageManagerWrapper packageManager, IPackageManagerWrapper packageManagerService,
DevicePolicyManagerWrapper devicePolicyManager, UserManager userManager,
ListOfAppsCallback callback) {
super(permissions, packageManager, packageManagerService, devicePolicyManager,
userManager);
mCallback = callback;
}
@Override
protected void onAppListBuilt(List<UserAppInfo> list) {
mCallback.onListOfAppsResult(list);
}
}
}

View File

@@ -31,21 +31,24 @@ public abstract class InstalledAppCounter extends AppCounter {
public static final int IGNORE_INSTALL_REASON = -1;
private final int mInstallReason;
private final PackageManagerWrapper mPackageManager;
public InstalledAppCounter(Context context, int installReason,
PackageManagerWrapper packageManager) {
super(context, packageManager);
mInstallReason = installReason;
mPackageManager = packageManager;
}
@Override
protected boolean includeInCount(ApplicationInfo info) {
return includeInCount(mInstallReason, mPm, info);
}
public static boolean includeInCount(int installReason, PackageManagerWrapper pm,
ApplicationInfo info) {
final int userId = UserHandle.getUserId(info.uid);
if (mInstallReason != IGNORE_INSTALL_REASON
&& mPackageManager.getInstallReason(info.packageName,
new UserHandle(userId)) != mInstallReason) {
if (installReason != IGNORE_INSTALL_REASON
&& pm.getInstallReason(info.packageName,
new UserHandle(userId)) != installReason) {
return false;
}
if ((info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
@@ -57,7 +60,7 @@ public abstract class InstalledAppCounter extends AppCounter {
Intent launchIntent = new Intent(Intent.ACTION_MAIN, null)
.addCategory(Intent.CATEGORY_LAUNCHER)
.setPackage(info.packageName);
List<ResolveInfo> intents = mPm.queryIntentActivitiesAsUser(
List<ResolveInfo> intents = pm.queryIntentActivitiesAsUser(
launchIntent,
PackageManager.GET_DISABLED_COMPONENTS
| PackageManager.MATCH_DIRECT_BOOT_AWARE

View File

@@ -0,0 +1,34 @@
/*
* 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.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.UserManager;
public abstract class InstalledAppLister extends AppLister {
public InstalledAppLister(PackageManagerWrapper packageManager,
UserManager userManager) {
super(packageManager, userManager);
}
@Override
protected boolean includeInCount(ApplicationInfo info) {
return InstalledAppCounter.includeInCount(PackageManager.INSTALL_REASON_POLICY, mPm, info);
}
}

View File

@@ -0,0 +1,57 @@
/*
* 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.pm.ApplicationInfo;
import android.content.pm.UserInfo;
import android.text.TextUtils;
import java.util.Objects;
/**
* Simple class for bringing together information about application and user for which it was
* installed.
*/
public class UserAppInfo {
public final UserInfo userInfo;
public final ApplicationInfo appInfo;
public UserAppInfo(UserInfo mUserInfo, ApplicationInfo mAppInfo) {
this.userInfo = mUserInfo;
this.appInfo = mAppInfo;
}
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (other == null || getClass() != other.getClass()) {
return false;
}
final UserAppInfo that = (UserAppInfo) other;
return that.userInfo.id == userInfo.id && TextUtils.equals(that.appInfo.packageName,
appInfo.packageName);
}
@Override
public int hashCode() {
return Objects.hash(userInfo.id, appInfo.packageName);
}
}