Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7db69b7a authored by Denis Kuznetsov's avatar Denis Kuznetsov
Browse files

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 60b2960c)
parent b21808bd
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ 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
  -->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
                  android:key="app_list_disclosure_settings">
    <PreferenceCategory
            android:key="dashboard_tile_placeholder"/>

    <com.android.settings.widget.FooterPreference
            android:title="@string/enterprise_privacy_apps_count_estimation_info"
            android:selectable="false"/>
</PreferenceScreen>
+6 −2
Original line number Diff line number Diff line
@@ -46,15 +46,19 @@

    <PreferenceCategory android:title="@string/enterprise_privacy_exposure_changes_category">
        <com.android.settings.DividerPreference
                android:fragment="com.android.settings.enterprise.ApplicationListFragment$EnterpriseInstalledPackages"
                android:key="number_enterprise_installed_packages"
                android:title="@string/enterprise_privacy_enterprise_installed_packages"/>
        <com.android.settings.DividerPreference
                android:fragment="com.android.settings.enterprise.ApplicationListFragment$AdminGrantedPermissionLocation"
                android:key="enterprise_privacy_number_location_access_packages"
                android:title="@string/enterprise_privacy_location_access"/>
        <com.android.settings.DividerPreference
                android:fragment="com.android.settings.enterprise.ApplicationListFragment$AdminGrantedPermissionMicrophone"
                android:key="enterprise_privacy_number_microphone_access_packages"
                android:title="@string/enterprise_privacy_microphone_access"/>
        <com.android.settings.DividerPreference
                android:fragment="com.android.settings.enterprise.ApplicationListFragment$AdminGrantedPermissionCamera"
                android:key="enterprise_privacy_number_camera_access_packages"
                android:title="@string/enterprise_privacy_camera_access"/>
        <com.android.settings.DividerPreference
+69 −0
Original line number Diff line number Diff line
/*
 * 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);
}
+12 −7
Original line number Diff line number Diff line
@@ -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;
                }
+46 −0
Original line number Diff line number Diff line
/*
 * 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);
    }
}
Loading