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

Commit 00e3dabd authored by Sooraj Sasindran's avatar Sooraj Sasindran
Browse files

Allow a list of configs to be sent for enterprise slice

Allow a list of configs to be sent for enterprise slice
Allow device owner to set enterprise slice config
Allow enterprise apn to be configured by profile owner

Bug: 217365439
Bug: 222723840
Test: ran CTS tests
Change-Id: I82c159843d0806cbfc5eea602fbd0304e7ff04ac
parent 719b6d79
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -7437,7 +7437,7 @@ package android.app.admin {
    method @Nullable public java.util.List<java.lang.String> getPermittedCrossProfileNotificationListeners(@NonNull android.content.ComponentName);
    method @Nullable public java.util.List<java.lang.String> getPermittedInputMethods(@NonNull android.content.ComponentName);
    method public int getPersonalAppsSuspendedReasons(@NonNull android.content.ComponentName);
    method @NonNull public android.app.admin.PreferentialNetworkServiceConfig getPreferentialNetworkServiceConfig();
    method @NonNull public java.util.List<android.app.admin.PreferentialNetworkServiceConfig> getPreferentialNetworkServiceConfigs();
    method public int getRequiredPasswordComplexity();
    method public long getRequiredStrongAuthTimeout(@Nullable android.content.ComponentName);
    method public boolean getScreenCaptureDisabled(@Nullable android.content.ComponentName);
@@ -7582,7 +7582,7 @@ package android.app.admin {
    method public boolean setPermittedCrossProfileNotificationListeners(@NonNull android.content.ComponentName, @Nullable java.util.List<java.lang.String>);
    method public boolean setPermittedInputMethods(@NonNull android.content.ComponentName, java.util.List<java.lang.String>);
    method public void setPersonalAppsSuspended(@NonNull android.content.ComponentName, boolean);
    method public void setPreferentialNetworkServiceConfig(@NonNull android.app.admin.PreferentialNetworkServiceConfig);
    method public void setPreferentialNetworkServiceConfigs(@NonNull java.util.List<android.app.admin.PreferentialNetworkServiceConfig>);
    method public void setPreferentialNetworkServiceEnabled(boolean);
    method public void setProfileEnabled(@NonNull android.content.ComponentName);
    method public void setProfileName(@NonNull android.content.ComponentName, String);
+66 −51
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@
package android.app.admin;
import static android.net.NetworkCapabilities.NET_ENTERPRISE_ID_1;
import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;
import android.Manifest.permission;
@@ -11031,7 +11033,7 @@ public class DevicePolicyManager {
    }
    /**
     * Sets whether preferential network service is enabled on the work profile.
     * Sets whether preferential network service is enabled.
     * For example, an organization can have a deal/agreement with a carrier that all of
     * the work data from its employees’ devices will be sent via a network service dedicated
     * for enterprise use.
@@ -11039,75 +11041,72 @@ public class DevicePolicyManager {
     * An example of a supported preferential network service is the Enterprise
     * slice on 5G networks.
     *
     * By default, preferential network service is disabled on the work profile on supported
     * carriers and devices. Admins can explicitly enable it with this API.
     * On fully-managed devices this method is unsupported because all traffic is considered
     * work traffic.
     * By default, preferential network service is disabled on the work profile and
     * fully managed devices, on supported carriers and devices.
     * Admins can explicitly enable it with this API.
     *
     * <p> This method enables preferential network service with a default configuration.
     * To fine-tune the configuration, use {@link #setPreferentialNetworkServiceConfig) instead.
     * To fine-tune the configuration, use {@link #setPreferentialNetworkServiceConfigs) instead.
     * <p> Before Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
     * this method can be called by the profile owner of a managed profile.
     * <p> Starting from Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
     * This method can be called by the profile owner of a managed profile
     * or device owner.
     *
     * <p>This method can only be called by the profile owner of a managed profile.
     * @param enabled whether preferential network service should be enabled.
     * @throws SecurityException if the caller is not the profile owner.
     * @throws SecurityException if the caller is not the profile owner or device owner.
     **/
    public void setPreferentialNetworkServiceEnabled(boolean enabled) {
        throwIfParentInstance("setPreferentialNetworkServiceEnabled");
        if (mService == null) {
            return;
        }
        try {
            mService.setPreferentialNetworkServiceEnabled(enabled);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        PreferentialNetworkServiceConfig.Builder configBuilder =
                new PreferentialNetworkServiceConfig.Builder();
        configBuilder.setEnabled(enabled);
        if (enabled) {
            configBuilder.setNetworkId(NET_ENTERPRISE_ID_1);
        }
        setPreferentialNetworkServiceConfigs(List.of(configBuilder.build()));
    }
    /**
     * Indicates whether preferential network service is enabled.
     *
     * <p>This method can be called by the profile owner of a managed profile.
     * <p> Before Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
     * This method can be called by the profile owner of a managed profile.
     * <p> Starting from Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
     * This method can be called by the profile owner of a managed profile
     * or device owner.
     *
     * @return whether preferential network service is enabled.
     * @throws SecurityException if the caller is not the profile owner.
     * @throws SecurityException if the caller is not the profile owner or device owner.
     */
    public boolean isPreferentialNetworkServiceEnabled() {
        throwIfParentInstance("isPreferentialNetworkServiceEnabled");
        if (mService == null) {
            return false;
        }
        try {
            return mService.isPreferentialNetworkServiceEnabled(myUserId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        return getPreferentialNetworkServiceConfigs().stream().anyMatch(c -> c.isEnabled());
    }
    /**
     * Sets preferential network configuration on the work profile.
     * Sets preferential network configurations.
     * {@see PreferentialNetworkServiceConfig}
     *
     * An example of a supported preferential network service is the Enterprise
     * slice on 5G networks.
     *
     * By default, preferential network service is disabled on the work profile on supported
     * carriers and devices. Admins can explicitly enable it with this API.
     * On fully-managed devices this method is unsupported because all traffic is considered
     * work traffic.
     * By default, preferential network service is disabled on the work profile and fully managed
     * devices, on supported carriers and devices. Admins can explicitly enable it with this API.
     * If admin wants to have multiple enterprise slices,
     * it can be configured by passing list of {@link PreferentialNetworkServiceConfig} objects.
     *
     * <p>This method can only be called by the profile owner of a managed profile.
     * @param preferentialNetworkServiceConfig preferential network configuration.
     * @throws SecurityException if the caller is not the profile owner.
     * @param preferentialNetworkServiceConfigs list of preferential network configurations.
     * @throws SecurityException if the caller is not the profile owner or device owner.
     **/
    public void setPreferentialNetworkServiceConfig(
            @NonNull PreferentialNetworkServiceConfig preferentialNetworkServiceConfig) {
        throwIfParentInstance("setPreferentialNetworkServiceConfig");
    public void setPreferentialNetworkServiceConfigs(
            @NonNull List<PreferentialNetworkServiceConfig> preferentialNetworkServiceConfigs) {
        throwIfParentInstance("setPreferentialNetworkServiceConfigs");
        if (mService == null) {
            return;
        }
        try {
            mService.setPreferentialNetworkServiceConfig(preferentialNetworkServiceConfig);
            mService.setPreferentialNetworkServiceConfigs(preferentialNetworkServiceConfigs);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -11117,18 +11116,16 @@ public class DevicePolicyManager {
     * Get preferential network configuration
     * {@see PreferentialNetworkServiceConfig}
     *
     * <p>This method can be called by the profile owner of a managed profile.
     *
     * @return preferential network configuration.
     * @throws SecurityException if the caller is not the profile owner.
     * @throws SecurityException if the caller is not the profile owner or device owner.
     */
    public @NonNull PreferentialNetworkServiceConfig getPreferentialNetworkServiceConfig() {
        throwIfParentInstance("getPreferentialNetworkServiceConfig");
    public @NonNull List<PreferentialNetworkServiceConfig> getPreferentialNetworkServiceConfigs() {
        throwIfParentInstance("getPreferentialNetworkServiceConfigs");
        if (mService == null) {
            return PreferentialNetworkServiceConfig.DEFAULT;
            return List.of(PreferentialNetworkServiceConfig.DEFAULT);
        }
        try {
            return mService.getPreferentialNetworkServiceConfig();
            return mService.getPreferentialNetworkServiceConfigs();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -13612,13 +13609,18 @@ public class DevicePolicyManager {
    }
    /**
     * Called by device owner to add an override APN.
     * Called by device owner or profile owner to add an override APN.
     *
     * <p>This method may returns {@code -1} if {@code apnSetting} conflicts with an existing
     * override APN. Update the existing conflicted APN with
     * {@link #updateOverrideApn(ComponentName, int, ApnSetting)} instead of adding a new entry.
     * <p>Two override APNs are considered to conflict when all the following APIs return
     * the same values on both override APNs:
     * <p> Before Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
     * Only device owners can add APNs.
     * <p> Starting from Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
     * Device and profile owners can add enterprise APNs
     * ({@link ApnSetting#TYPE_ENTERPRISE}), while only device owners can add other type of APNs.
     * <ul>
     *   <li>{@link ApnSetting#getOperatorNumeric()}</li>
     *   <li>{@link ApnSetting#getApnName()}</li>
@@ -13637,7 +13639,8 @@ public class DevicePolicyManager {
     * @param apnSetting the override APN to insert
     * @return The {@code id} of inserted override APN. Or {@code -1} when failed to insert into
     *         the database.
     * @throws SecurityException if {@code admin} is not a device owner.
     * @throws SecurityException If request is for enterprise APN {@code admin} is either device
     * owner or profile owner and in all other types of APN if {@code admin} is not a device owner.
     *
     * @see #setOverrideApnsEnabled(ComponentName, boolean)
     */
@@ -13654,20 +13657,26 @@ public class DevicePolicyManager {
    }
    /**
     * Called by device owner to update an override APN.
     * Called by device owner or profile owner to update an override APN.
     *
     * <p>This method may returns {@code false} if there is no override APN with the given
     * {@code apnId}.
     * <p>This method may also returns {@code false} if {@code apnSetting} conflicts with an
     * existing override APN. Update the existing conflicted APN instead.
     * <p>See {@link #addOverrideApn} for the definition of conflict.
     * <p> Before Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
     * Only device owners can update APNs.
     * <p> Starting from Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
     * Device and profile owners can update enterprise APNs
     * ({@link ApnSetting#TYPE_ENTERPRISE}), while only device owners can update other type of APNs.
     *
     * @param admin which {@link DeviceAdminReceiver} this request is associated with
     * @param apnId the {@code id} of the override APN to update
     * @param apnSetting the override APN to update
     * @return {@code true} if the required override APN is successfully updated,
     *         {@code false} otherwise.
     * @throws SecurityException if {@code admin} is not a device owner.
     * @throws SecurityException If request is for enterprise APN {@code admin} is either device
     * owner or profile owner and in all other types of APN if {@code admin} is not a device owner.
     *
     * @see #setOverrideApnsEnabled(ComponentName, boolean)
     */
@@ -13685,16 +13694,22 @@ public class DevicePolicyManager {
    }
    /**
     * Called by device owner to remove an override APN.
     * Called by device owner or profile owner to remove an override APN.
     *
     * <p>This method may returns {@code false} if there is no override APN with the given
     * {@code apnId}.
     * <p> Before Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
     * Only device owners can remove APNs.
     * <p> Starting from Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
     * Device and profile owners can remove enterprise APNs
     * ({@link ApnSetting#TYPE_ENTERPRISE}), while only device owners can remove other type of APNs.
     *
     * @param admin which {@link DeviceAdminReceiver} this request is associated with
     * @param apnId the {@code id} of the override APN to remove
     * @return {@code true} if the required override APN is successfully removed, {@code false}
     *         otherwise.
     * @throws SecurityException if {@code admin} is not a device owner.
     * @throws SecurityException If request is for enterprise APN {@code admin} is either device
     * owner or profile owner and in all other types of APN if {@code admin} is not a device owner.
     *
     * @see #setOverrideApnsEnabled(ComponentName, boolean)
     */
+3 −6
Original line number Diff line number Diff line
@@ -285,12 +285,9 @@ interface IDevicePolicyManager {
    void setSecondaryLockscreenEnabled(in ComponentName who, boolean enabled);
    boolean isSecondaryLockscreenEnabled(in UserHandle userHandle);

    void setPreferentialNetworkServiceEnabled(in boolean enabled);
    boolean isPreferentialNetworkServiceEnabled(int userHandle);

    void setPreferentialNetworkServiceConfig(
            in PreferentialNetworkServiceConfig preferentialNetworkServiceConfig);
    PreferentialNetworkServiceConfig getPreferentialNetworkServiceConfig();
    void setPreferentialNetworkServiceConfigs(
            in List<PreferentialNetworkServiceConfig> preferentialNetworkServiceConfigs);
    List<PreferentialNetworkServiceConfig> getPreferentialNetworkServiceConfigs();

    void setLockTaskPackages(in ComponentName who, in String[] packages);
    String[] getLockTaskPackages(in ComponentName who);
+1 −5
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ import java.util.Objects;

/**
 * Network configuration to be set for the user profile
 * {@see DevicePolicyManager#setPreferentialNetworkServiceConfig}.
 * {@see DevicePolicyManager#setPreferentialNetworkServiceConfigs}.
 */
public final class PreferentialNetworkServiceConfig implements Parcelable {
    final boolean mIsEnabled;
@@ -147,8 +147,6 @@ public final class PreferentialNetworkServiceConfig implements Parcelable {

    /**
     * @return preference enterprise identifier.
     * valid values starts from
     * {@link #PREFERENTIAL_NETWORK_ID_1} to {@link #PREFERENTIAL_NETWORK_ID_5}.
     * preference identifier is applicable only if preference network service is enabled
     *
     */
@@ -286,8 +284,6 @@ public final class PreferentialNetworkServiceConfig implements Parcelable {

        /**
         * Set the preferential network identifier.
         * Valid values starts from {@link #PREFERENTIAL_NETWORK_ID_1} to
         * {@link #PREFERENTIAL_NETWORK_ID_5}.
         * preference identifier is applicable only if preferential network service is enabled.
         * @param preferenceId  preference Id
         * @return The builder to facilitate chaining.
+2 −2
Original line number Diff line number Diff line
@@ -307,8 +307,8 @@ class ActiveAdmin {
    public boolean mAdminCanGrantSensorsPermissions;
    public boolean mPreferentialNetworkServiceEnabled =
            DevicePolicyManager.PREFERENTIAL_NETWORK_SERVICE_ENABLED_DEFAULT;
    public PreferentialNetworkServiceConfig mPreferentialNetworkServiceConfig =
            PreferentialNetworkServiceConfig.DEFAULT;
    public List<PreferentialNetworkServiceConfig> mPreferentialNetworkServiceConfigs =
            List.of(PreferentialNetworkServiceConfig.DEFAULT);

    private static final boolean USB_DATA_SIGNALING_ENABLED_DEFAULT = true;
    boolean mUsbDataSignalingEnabled = USB_DATA_SIGNALING_ENABLED_DEFAULT;
Loading