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

Commit 43e4401c authored by Ayush Sharma's avatar Ayush Sharma Committed by Android (Google) Code Review
Browse files

Merge "Reset cross profile intent filters for call/sms" into udc-dev

parents b5c0e284 e1ddc0cc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ public final class DefaultCrossProfileIntentFilter {
            Direction.TO_PROFILE
    })
    @Retention(RetentionPolicy.SOURCE)
    @interface Direction {
    public @interface Direction {
        int TO_PARENT = 0;
        int TO_PROFILE = 1;
    }
+86 −15
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.hardware.usb.UsbManager;
import android.provider.AlarmClock;
import android.provider.MediaStore;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@@ -88,6 +89,23 @@ public class DefaultCrossProfileIntentFiltersUtils {
                    .addDataType("vnd.android.cursor.item/calls")
                    .build();

    /** Dial intent with mime type exclusively handled by managed profile. */
    private static final DefaultCrossProfileIntentFilter DIAL_MIME_MANAGED_PROFILE =
            new DefaultCrossProfileIntentFilter.Builder(
                    DefaultCrossProfileIntentFilter.Direction.TO_PROFILE,
                    SKIP_CURRENT_PROFILE,
                    /* letsPersonalDataIntoProfile= */ false)
                    .addAction(Intent.ACTION_DIAL)
                    .addAction(Intent.ACTION_VIEW)
                    .addCategory(Intent.CATEGORY_DEFAULT)
                    .addCategory(Intent.CATEGORY_BROWSABLE)
                    .addDataType("vnd.android.cursor.item/phone")
                    .addDataType("vnd.android.cursor.item/phone_v2")
                    .addDataType("vnd.android.cursor.item/person")
                    .addDataType("vnd.android.cursor.dir/calls")
                    .addDataType("vnd.android.cursor.item/calls")
                    .build();

    /** Dial intent with data scheme can be handled by either managed profile or its parent user. */
    private static final DefaultCrossProfileIntentFilter DIAL_DATA =
            new DefaultCrossProfileIntentFilter.Builder(
@@ -103,6 +121,21 @@ public class DefaultCrossProfileIntentFiltersUtils {
                    .addDataScheme("voicemail")
                    .build();

    /** Dial intent with data scheme exclusively handled by managed profile. */
    private static final DefaultCrossProfileIntentFilter DIAL_DATA_MANAGED_PROFILE =
            new DefaultCrossProfileIntentFilter.Builder(
                    DefaultCrossProfileIntentFilter.Direction.TO_PROFILE,
                    SKIP_CURRENT_PROFILE,
                    /* letsPersonalDataIntoProfile= */ false)
                    .addAction(Intent.ACTION_DIAL)
                    .addAction(Intent.ACTION_VIEW)
                    .addCategory(Intent.CATEGORY_DEFAULT)
                    .addCategory(Intent.CATEGORY_BROWSABLE)
                    .addDataScheme("tel")
                    .addDataScheme("sip")
                    .addDataScheme("voicemail")
                    .build();

    /**
     * Dial intent with no data scheme or type can be handled by either managed profile or its
     * parent user.
@@ -117,6 +150,19 @@ public class DefaultCrossProfileIntentFiltersUtils {
                    .addCategory(Intent.CATEGORY_BROWSABLE)
                    .build();

    /**
     * Dial intent with no data scheme or type exclusively handled by managed profile.
     */
    private static final DefaultCrossProfileIntentFilter DIAL_RAW_MANAGED_PROFILE =
            new DefaultCrossProfileIntentFilter.Builder(
                    DefaultCrossProfileIntentFilter.Direction.TO_PROFILE,
                    SKIP_CURRENT_PROFILE,
                    /* letsPersonalDataIntoProfile= */ false)
                    .addAction(Intent.ACTION_DIAL)
                    .addCategory(Intent.CATEGORY_DEFAULT)
                    .addCategory(Intent.CATEGORY_BROWSABLE)
                    .build();

    /** Pressing the call button can be handled by either managed profile or its parent user. */
    private static final DefaultCrossProfileIntentFilter CALL_BUTTON =
            new DefaultCrossProfileIntentFilter.Builder(
@@ -143,6 +189,22 @@ public class DefaultCrossProfileIntentFiltersUtils {
                    .addDataScheme("mmsto")
                    .build();

    /** SMS and MMS intent exclusively handled by the managed profile. */
    private static final DefaultCrossProfileIntentFilter SMS_MMS_MANAGED_PROFILE =
            new DefaultCrossProfileIntentFilter.Builder(
                    DefaultCrossProfileIntentFilter.Direction.TO_PROFILE,
                    SKIP_CURRENT_PROFILE,
                    /* letsPersonalDataIntoProfile= */ false)
                    .addAction(Intent.ACTION_VIEW)
                    .addAction(Intent.ACTION_SENDTO)
                    .addCategory(Intent.CATEGORY_DEFAULT)
                    .addCategory(Intent.CATEGORY_BROWSABLE)
                    .addDataScheme("sms")
                    .addDataScheme("smsto")
                    .addDataScheme("mms")
                    .addDataScheme("mmsto")
                    .build();

    /** Mobile network settings is always shown in the primary user. */
    private static final DefaultCrossProfileIntentFilter
            MOBILE_NETWORK_SETTINGS =
@@ -297,14 +359,12 @@ public class DefaultCrossProfileIntentFiltersUtils {
                    .build();

    public static List<DefaultCrossProfileIntentFilter> getDefaultManagedProfileFilters() {
        return Arrays.asList(
        List<DefaultCrossProfileIntentFilter> filters =
                new ArrayList<DefaultCrossProfileIntentFilter>();
        filters.addAll(Arrays.asList(
                EMERGENCY_CALL_MIME,
                EMERGENCY_CALL_DATA,
                DIAL_MIME,
                DIAL_DATA,
                DIAL_RAW,
                CALL_BUTTON,
                SMS_MMS,
                SET_ALARM,
                MEDIA_CAPTURE,
                RECOGNIZE_SPEECH,
@@ -317,11 +377,13 @@ public class DefaultCrossProfileIntentFiltersUtils {
                USB_DEVICE_ATTACHED,
                ACTION_SEND,
                HOME,
                MOBILE_NETWORK_SETTINGS);
                MOBILE_NETWORK_SETTINGS));
        filters.addAll(getDefaultCrossProfileTelephonyIntentFilters(false));
        return filters;
    }

    /** Call intent with tel scheme */
    private static final DefaultCrossProfileIntentFilter CALL =
    /** Call intent with tel scheme exclusively handled my managed profile. */
    private static final DefaultCrossProfileIntentFilter CALL_MANAGED_PROFILE =
            new DefaultCrossProfileIntentFilter.Builder(
                    DefaultCrossProfileIntentFilter.Direction.TO_PROFILE,
                    SKIP_CURRENT_PROFILE,
@@ -334,14 +396,23 @@ public class DefaultCrossProfileIntentFiltersUtils {
    /**
     * Returns default telephony related intent filters for managed profile.
     */
    public static List<DefaultCrossProfileIntentFilter> getDefaultManagedProfileTelephonyFilters() {
    public static List<DefaultCrossProfileIntentFilter>
            getDefaultCrossProfileTelephonyIntentFilters(boolean telephonyOnlyInManagedProfile) {
        if (telephonyOnlyInManagedProfile) {
            return Arrays.asList(
                    DIAL_DATA_MANAGED_PROFILE,
                    DIAL_MIME_MANAGED_PROFILE,
                    DIAL_RAW_MANAGED_PROFILE,
                    CALL_MANAGED_PROFILE,
                    SMS_MMS_MANAGED_PROFILE);
        } else {
            return Arrays.asList(
                    DIAL_DATA,
                    DIAL_MIME,
                    DIAL_RAW,
                CALL,
                    SMS_MMS);
        }
    }

    /**
     * Clone profile's DefaultCrossProfileIntentFilter
+66 −22
Original line number Diff line number Diff line
@@ -7711,30 +7711,72 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    private void updateTelephonyCrossProfileIntentFilters(int parentUserId, int profileUserId,
            boolean enableWorkTelephony) {
        try {
            String packageName = mContext.getOpPackageName();
            if (enableWorkTelephony) {
                // Reset call/sms cross profile intent filters to be handled by managed profile.
            // This should only occur when managed profile is being removed.
            if (!enableWorkTelephony && profileUserId == UserHandle.USER_NULL) {
                mIPackageManager.clearCrossProfileIntentFilters(parentUserId,
                        mContext.getPackageName());
                return;
            }
            for (DefaultCrossProfileIntentFilter filter :
                    DefaultCrossProfileIntentFiltersUtils
                                .getDefaultManagedProfileTelephonyFilters()) {
                    IntentFilter intentFilter = filter.filter.getIntentFilter();
                    if (!mIPackageManager.removeCrossProfileIntentFilter(intentFilter, packageName,
                            profileUserId, parentUserId, filter.flags)) {
                            .getDefaultCrossProfileTelephonyIntentFilters(!enableWorkTelephony)) {
                if (removeCrossProfileIntentFilter(filter, parentUserId, profileUserId)) {
                    Slogf.w(LOG_TAG,
                                "Failed to remove cross-profile intent filter: " + intentFilter);
                            "Failed to remove cross-profile intent filter: "
                                    + filter.filter.getIntentFilter() + ", enableWorkTelephony: "
                                    + enableWorkTelephony);
                }
                    mIPackageManager.addCrossProfileIntentFilter(intentFilter, packageName,
                            parentUserId, profileUserId, PackageManager.SKIP_CURRENT_PROFILE);
            }
            } else {
                mIPackageManager.clearCrossProfileIntentFilters(parentUserId, packageName);
            for (DefaultCrossProfileIntentFilter filter :
                    DefaultCrossProfileIntentFiltersUtils
                            .getDefaultCrossProfileTelephonyIntentFilters(enableWorkTelephony)) {
                addCrossProfileIntentFilter(filter, parentUserId, profileUserId);
            }
        } catch (RemoteException re) {
            Slogf.wtf(LOG_TAG, "Error updating telephony cross profile intent filters", re);
        }
    }
    void addCrossProfileIntentFilter(DefaultCrossProfileIntentFilter filter, int parentUserId,
            int profileUserId)
            throws RemoteException {
        if (filter.direction == DefaultCrossProfileIntentFilter.Direction.TO_PROFILE) {
            mIPackageManager.addCrossProfileIntentFilter(
                    filter.filter.getIntentFilter(),
                    mContext.getOpPackageName(),
                    parentUserId,
                    profileUserId,
                    filter.flags);
        } else {
            mIPackageManager.addCrossProfileIntentFilter(
                    filter.filter.getIntentFilter(),
                    mContext.getOpPackageName(),
                    profileUserId,
                    parentUserId,
                    filter.flags);
        }
    }
    boolean removeCrossProfileIntentFilter(DefaultCrossProfileIntentFilter filter, int parentUserId,
            int profileUserId)
            throws RemoteException {
        if (filter.direction == DefaultCrossProfileIntentFilter.Direction.TO_PROFILE) {
            return mIPackageManager.removeCrossProfileIntentFilter(
                    filter.filter.getIntentFilter(),
                    mContext.getOpPackageName(),
                    parentUserId,
                    profileUserId,
                    filter.flags);
        } else {
            return mIPackageManager.removeCrossProfileIntentFilter(
                    filter.filter.getIntentFilter(),
                    mContext.getOpPackageName(),
                    profileUserId,
                    parentUserId,
                    filter.flags);
        }
    }
    /**
     * @param factoryReset null: legacy behaviour, false: attempt to remove user, true: attempt to
     *                     factory reset
@@ -23346,16 +23388,18 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        applyManagedSubscriptionsPolicyIfRequired();
        int policyType = getManagedSubscriptionsPolicy().getPolicyType();
        if (policyType == ManagedSubscriptionsPolicy.TYPE_ALL_MANAGED_SUBSCRIPTIONS) {
        final long id = mInjector.binderClearCallingIdentity();
        try {
            if (policyType == ManagedSubscriptionsPolicy.TYPE_ALL_MANAGED_SUBSCRIPTIONS) {
                installOemDefaultDialerAndSmsApp(caller.getUserId());
                updateTelephonyCrossProfileIntentFilters(parentUserId, caller.getUserId(), true);
            } else if (policyType == ManagedSubscriptionsPolicy.TYPE_ALL_PERSONAL_SUBSCRIPTIONS) {
                updateTelephonyCrossProfileIntentFilters(parentUserId, caller.getUserId(), false);
            }
        } finally {
            mInjector.binderRestoreCallingIdentity(id);
        }
    }
    }
    private void installOemDefaultDialerAndSmsApp(int targetUserId) {
        try {