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

Commit b2d15371 authored by Kholoud Mohamed's avatar Kholoud Mohamed Committed by kholoud mohamed
Browse files

Add user settings and intent filters to userTypeDetails

Added the capability to set default user settings and
default cross profile intent filters for different user
types in UserTypeDetails.
Also added default values for managed profiles.
The following is mostly copied from existing code in MP:
* DefaultCrossProfileIntentFilter class
* DefaultCrossProfileIntentFiltersUtils class
* setDefaultCrossProfileIntentFilters and
* resetDefaultCrossProfileIntentFilters in UserManagerService

NOTE REGARDING FILE HISTORY: Several classes moved from ManagedProvisioning
to the framework. There is a comment on this CL that points to an internal
link to the change history of these files in ManagedProvisioning.

Bug: 176973252
Test: atest UserManagerServiceUserTypeTest
Test: atest BundleUtilsTest
Test: atest UserRestrictionsUtilsTest
Test: atest com.android.server.pm.UserManagerTest
Test: atest UserManagerServiceTest
Test: atest com.android.server.devicepolice.DevicePolicyManagerTest

Change-Id: I3d4cbfcbcad6b6419c5306ae025d4cb9dca317ba
parent 11512218
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -389,6 +389,7 @@ package android.app.admin {
    method public boolean isFactoryResetProtectionPolicySupported();
    method @NonNull public static String operationToString(int);
    method @RequiresPermission("android.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS") public void provisionFullyManagedDevice(@NonNull android.app.admin.FullyManagedDeviceProvisioningParams) throws android.app.admin.ProvisioningException;
    method @RequiresPermission("android.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS") public void resetDefaultCrossProfileIntentFilters(int);
    method @RequiresPermission("android.permission.MANAGE_DEVICE_ADMINS") public void setNextOperationSafety(int, int);
    method @NonNull public static String unsafeOperationReasonToString(int);
    field public static final String ACTION_DATA_SHARING_RESTRICTION_APPLIED = "android.app.action.DATA_SHARING_RESTRICTION_APPLIED";
+23 −0
Original line number Diff line number Diff line
@@ -1730,8 +1730,12 @@ public class DevicePolicyManager {
     * Broadcast action to notify ManagedProvisioning that
     * {@link UserManager#DISALLOW_SHARE_INTO_MANAGED_PROFILE} restriction has changed.
     * @hide
     * @deprecated No longer needed as ManagedProvisioning no longer handles
     * {@link UserManager#DISALLOW_SHARE_INTO_MANAGED_PROFILE} restriction changing.
     */
    // TODO(b/177221010): Remove when Managed Provisioning no longer depend on it.
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    @Deprecated
    public static final String ACTION_DATA_SHARING_RESTRICTION_CHANGED =
            "android.app.action.DATA_SHARING_RESTRICTION_CHANGED";
@@ -13268,4 +13272,23 @@ public class DevicePolicyManager {
            }
        }
    }
    /**
     * Resets the default cross profile intent filters that were set during
     * {@link #createAndProvisionManagedProfile} between {@code userId} and all it's managed
     * profiles if any.
     *
     * @hide
     */
    @TestApi
    @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS)
    public void resetDefaultCrossProfileIntentFilters(@UserIdInt int userId) {
        if (mService != null) {
            try {
                mService.resetDefaultCrossProfileIntentFilters(userId);
            } catch (RemoteException re) {
                throw re.rethrowFromSystemServer();
            }
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -498,4 +498,6 @@ interface IDevicePolicyManager {

    UserHandle createAndProvisionManagedProfile(in ManagedProfileProvisioningParams provisioningParams, in String callerPackage);
    void provisionFullyManagedDevice(in FullyManagedDeviceProvisioningParams provisioningParams, in String callerPackage);

    void resetDefaultCrossProfileIntentFilters(int userId);
}
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.server;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Bundle;

/**
 * Utility methods for handling {@link Bundle}.
 *
 */
public final class BundleUtils {
    private BundleUtils() {
    }

    /**
     * Returns true if {@code in} is null or empty.
     */
    public static boolean isEmpty(@Nullable Bundle in) {
        return (in == null) || (in.size() == 0);
    }

    /**
     * Creates a copy of the {@code in} Bundle.  If {@code in} is null, it'll return an empty
     * bundle.
     *
     * <p>The resulting {@link Bundle} is always writable. (i.e. it won't return
     * {@link Bundle#EMPTY})
     */
    public static @NonNull Bundle clone(@Nullable Bundle in) {
        return (in != null) ? new Bundle(in) : new Bundle();
    }

}
+118 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.server.pm;

import static java.util.Objects.requireNonNull;

import android.annotation.IntDef;
import android.content.IntentFilter;

import com.android.internal.annotations.Immutable;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Representation of an immutable default cross-profile intent filter.
 */
@Immutable
final class DefaultCrossProfileIntentFilter {

    @IntDef({
            Direction.TO_PARENT,
            Direction.TO_PROFILE
    })
    @Retention(RetentionPolicy.SOURCE)
    @interface Direction {
        int TO_PARENT = 0;
        int TO_PROFILE = 1;
    }

    /** The intent filter that's used */
    public final IntentFilter filter;

    /**
     * The flags related to the forwarding, e.g.
     * {@link android.content.pm.PackageManager#SKIP_CURRENT_PROFILE} or
     * {@link android.content.pm.PackageManager#ONLY_IF_NO_MATCH_FOUND}.
     */
    public final int flags;

    /**
     * The direction of forwarding, can be either {@link Direction#TO_PARENT} or
     * {@link Direction#TO_PROFILE}.
     */
    public final @Direction int direction;

    /**
     * Whether this cross profile intent filter would allow personal data to be shared into
     * the work profile. If this is {@code true}, this intent filter should be only added to
     * the profile if the admin does not enable
     * {@link android.os.UserManager#DISALLOW_SHARE_INTO_MANAGED_PROFILE}.
     */
    public final boolean letsPersonalDataIntoProfile;

    private DefaultCrossProfileIntentFilter(IntentFilter filter, int flags,
            @Direction int direction, boolean letsPersonalDataIntoProfile) {
        this.filter = requireNonNull(filter);
        this.flags = flags;
        this.direction = direction;
        this.letsPersonalDataIntoProfile = letsPersonalDataIntoProfile;
    }

    static final class Builder {
        private IntentFilter mFilter = new IntentFilter();
        private int mFlags;
        private @Direction int mDirection;
        private boolean mLetsPersonalDataIntoProfile;

        Builder(@Direction int direction, int flags, boolean letsPersonalDataIntoProfile) {
            mDirection = direction;
            mFlags = flags;
            mLetsPersonalDataIntoProfile = letsPersonalDataIntoProfile;
        }

        Builder addAction(String action) {
            mFilter.addAction(action);
            return this;
        }

        Builder addCategory(String category) {
            mFilter.addCategory(category);
            return this;
        }

        Builder addDataType(String type) {
            try {
                mFilter.addDataType(type);
            } catch (IntentFilter.MalformedMimeTypeException e) {
                // ignore
            }
            return this;
        }

        Builder addDataScheme(String scheme) {
            mFilter.addDataScheme(scheme);
            return this;
        }

        DefaultCrossProfileIntentFilter build() {
            return new DefaultCrossProfileIntentFilter(mFilter, mFlags, mDirection,
                    mLetsPersonalDataIntoProfile);
        }
    }
}
Loading