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

Commit f0a61dd1 authored by Denis Kuznetsov's avatar Denis Kuznetsov
Browse files

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
parent 60b2960c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@
                android:key="enterprise_privacy_number_camera_access_packages"
                android:title="@string/enterprise_privacy_camera_access"/>
        <com.android.settings.DividerPreference
                android:fragment="com.android.settings.enterprise.EnterpriseSetDefaultAppsListFragment"
                android:key="number_enterprise_set_default_apps"
                android:title="@string/enterprise_privacy_enterprise_set_default_apps"/>
        <com.android.settings.DividerPreference
+23 −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="enterprise_set_default_apps_settings">
    <PreferenceCategory
            android:key="dashboard_tile_placeholder"/>
</PreferenceScreen>
+11 −35
Original line number Diff line number Diff line
@@ -16,14 +16,14 @@

package com.android.settings.applications;

import com.android.settings.applications.instantapps.InstantAppButtonsController;

import android.annotation.UserIdInt;
import android.app.Fragment;
import android.content.Intent;
import android.view.View;

import com.android.settings.applications.instantapps.InstantAppButtonsController;

import java.util.List;
import java.util.Set;

public interface ApplicationFeatureProvider {

@@ -80,16 +80,18 @@ public interface ApplicationFeatureProvider {
    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
     * 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.
     * Return the persistent preferred activities configured by the admin for the given user.
     * 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 userId ID of the user for which to find persistent preferred activities
     * @param intent The intents for which to find persistent preferred activities
     *
     * @return the persistent preferred activites for the given intent
     * @return the persistent preferred activites for the given intents, ordered first by user id,
     * then by package name
     */
    Set<PersistentPreferredActivityInfo> findPersistentPreferredActivities(Intent[] intents);
    List<UserAppInfo> findPersistentPreferredActivities(@UserIdInt int userId, Intent[] intents);

    /**
     * Callback that receives the number of packages installed on the device.
@@ -104,30 +106,4 @@ public interface ApplicationFeatureProvider {
    interface ListOfAppsCallback {
        void onListOfAppsResult(List<UserAppInfo> result);
    }

    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;
        }
    }
}
+24 −24
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.Intent;
import android.content.pm.ComponentInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
@@ -31,6 +32,7 @@ import android.view.View;
import com.android.settings.applications.instantapps.InstantAppButtonsController;
import com.android.settings.enterprise.DevicePolicyManagerWrapper;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@@ -103,16 +105,14 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
    }

    @Override
    public Set<PersistentPreferredActivityInfo> findPersistentPreferredActivities(
            Intent[] intents) {
        final Set<PersistentPreferredActivityInfo> activities = new ArraySet<>();
        final List<UserHandle> users = mUm.getUserProfiles();
    public List<UserAppInfo> findPersistentPreferredActivities(int userId, Intent[] intents) {
        final List<UserAppInfo> preferredActivities = new ArrayList<>();
        final Set<UserAppInfo> uniqueApps = new ArraySet<>();
        final UserInfo userInfo = mUm.getUserInfo(userId);
        for (final Intent intent : intents) {
            for (final UserHandle user : users) {
                final int userId = user.getIdentifier();
            try {
                    final ResolveInfo resolveInfo = mPms.findPersistentPreferredActivity(intent,
                            userId);
                final ResolveInfo resolveInfo =
                        mPms.findPersistentPreferredActivity(intent, userId);
                if (resolveInfo != null) {
                    ComponentInfo componentInfo = null;
                    if (resolveInfo.activityInfo != null) {
@@ -123,16 +123,16 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
                        componentInfo = resolveInfo.providerInfo;
                    }
                    if (componentInfo != null) {
                            activities.add(new PersistentPreferredActivityInfo(
                                    componentInfo.packageName, userId));
                        UserAppInfo info = new UserAppInfo(userInfo, componentInfo.applicationInfo);
                        if (uniqueApps.add(info)) {
                            preferredActivities.add(info);
                        }
                    }
                } catch (RemoteException exception) {
                }
            } catch (RemoteException exception) {
            }

        }
        return activities;
        return preferredActivities;
    }

    private static class CurrentUserAndManagedProfilePolicyInstalledAppCounter
+67 −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.Intent;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.MediaStore;

/**
 * UI grouping of important intents that can be configured by device and profile owners.
 */
public enum EnterpriseDefaultApps {
    BROWSER(new Intent[] {
            buildIntent(Intent.ACTION_VIEW, Intent.CATEGORY_BROWSABLE, "http:", null)}),
    CALENDAR(new Intent[] {
            buildIntent(Intent.ACTION_INSERT, null, null, "vnd.android.cursor.dir/event")}),
    CAMERA(new Intent[] {
            new Intent(MediaStore.ACTION_IMAGE_CAPTURE),
            new Intent(MediaStore.ACTION_VIDEO_CAPTURE)}),
    CONTACTS(new Intent[] {
            buildIntent(Intent.ACTION_PICK, null, null, ContactsContract.Contacts.CONTENT_TYPE)}),
    EMAIL(new Intent[] {
            new Intent(Intent.ACTION_SENDTO), new Intent(Intent.ACTION_SEND),
            new Intent(Intent.ACTION_SEND_MULTIPLE)}),
    MAP(new Intent[] {buildIntent(Intent.ACTION_VIEW, null, "geo:", null)}),
    PHONE(new Intent[] {new Intent(Intent.ACTION_DIAL), new Intent(Intent.ACTION_CALL)});
    private final Intent[] mIntents;

    EnterpriseDefaultApps(Intent[] intents) {
        mIntents = intents;
    }

    public Intent[] getIntents() {
        return mIntents;
    }

    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;
    }

}
Loading