PreferentialNetworkServiceConfig.Builder


public static final class PreferentialNetworkServiceConfig.Builder
extends Object

java.lang.Object
   ↳ android.app.admin.PreferentialNetworkServiceConfig.Builder


Builder used to create PreferentialNetworkServiceConfig objects. Specify the preferred Network preference

Summary

Public constructors

Builder()

Constructs an empty Builder with preferential network disabled by default.

Public methods

PreferentialNetworkServiceConfig build()

Returns an instance of PreferentialNetworkServiceConfig created from the fields set on this builder.

PreferentialNetworkServiceConfig.Builder setEnabled(boolean isEnabled)

Set the preferential network service enabled state.

PreferentialNetworkServiceConfig.Builder setExcludedUids(int[] uids)

Set the array of uids who are not allowed through this preferential network service.

PreferentialNetworkServiceConfig.Builder setFallbackToDefaultConnectionAllowed(boolean allowFallbackToDefaultConnection)

Set whether fallback to the device-wide default network is allowed.

PreferentialNetworkServiceConfig.Builder setIncludedUids(int[] uids)

Set the array of uids whose network access will go through this preferential network service.

PreferentialNetworkServiceConfig.Builder setNetworkId(int preferenceId)

Set the preferential network identifier.

PreferentialNetworkServiceConfig.Builder setShouldBlockNonMatchingNetworks(boolean blockNonMatchingNetworks)

Set whether to block UIDs from using other networks than the preferential service.

Inherited methods

Public constructors

Builder

Added in API level 33
public Builder ()

Constructs an empty Builder with preferential network disabled by default.

Public methods

build

Added in API level 33
public PreferentialNetworkServiceConfig build ()

Returns an instance of PreferentialNetworkServiceConfig created from the fields set on this builder.

Returns
PreferentialNetworkServiceConfig This value cannot be null.

setEnabled

Added in API level 33
public PreferentialNetworkServiceConfig.Builder setEnabled (boolean isEnabled)

Set the preferential network service enabled state. Default value is false.

Parameters
isEnabled boolean: the desired network preference to use, true to enable else false

Returns
PreferentialNetworkServiceConfig.Builder The builder to facilitate chaining. This value cannot be null.

setExcludedUids

Added in API level 33
public PreferentialNetworkServiceConfig.Builder setExcludedUids (int[] uids)

Set the array of uids who are not allowed through this preferential network service. Included UIDs and Excluded UIDs can't both be non-empty. if both are empty, it means this request applies to all uids in the user profile. if included is not empty, then only included UIDs are applied. if excluded is not empty, then it is all uids in the user profile except these UIDs.

Parameters
uids int: array of excluded uids This value cannot be null.

Returns
PreferentialNetworkServiceConfig.Builder The builder to facilitate chaining. This value cannot be null.

setFallbackToDefaultConnectionAllowed

Added in API level 33
public PreferentialNetworkServiceConfig.Builder setFallbackToDefaultConnectionAllowed (boolean allowFallbackToDefaultConnection)

Set whether fallback to the device-wide default network is allowed. This boolean configures whether the default connection (e.g. general cell network or wifi) should be used if no preferential network service connection is available. If true, the default connection will be used when no preferential service is available. If false, the UIDs subject to this configuration will have no default network. Note that while this boolean determines whether the UIDs subject to this configuration have a default network in the absence of a preferential service, apps can still explicitly decide to use another network than their default network by requesting them from the system. This boolean does not determine whether the UIDs are blocked from using such other networks. Use setShouldBlockNonMatchingNetworks(boolean) to specify this. The default value is true.

Parameters
allowFallbackToDefaultConnection boolean: true if fallback is allowed else false

Returns
PreferentialNetworkServiceConfig.Builder The builder to facilitate chaining. This value cannot be null.

setIncludedUids

Added in API level 33
public PreferentialNetworkServiceConfig.Builder setIncludedUids (int[] uids)

Set the array of uids whose network access will go through this preferential network service. Included UIDs and Excluded UIDs can't both be non-empty. if both are empty, it means this request applies to all uids in the user profile. if included is not empty, then only included UIDs are applied. if excluded is not empty, then it is all uids in the user profile except these UIDs.

Parameters
uids int: array of included uids This value cannot be null.

Returns
PreferentialNetworkServiceConfig.Builder The builder to facilitate chaining. This value cannot be null.

setNetworkId

Added in API level 33
public PreferentialNetworkServiceConfig.Builder setNetworkId (int preferenceId)

Set the preferential network identifier. preference identifier is applicable only if preferential network service is enabled.

Parameters
preferenceId int: preference Id Value is PreferentialNetworkServiceConfig.PREFERENTIAL_NETWORK_ID_1, PreferentialNetworkServiceConfig.PREFERENTIAL_NETWORK_ID_2, PreferentialNetworkServiceConfig.PREFERENTIAL_NETWORK_ID_3, PreferentialNetworkServiceConfig.PREFERENTIAL_NETWORK_ID_4, or PreferentialNetworkServiceConfig.PREFERENTIAL_NETWORK_ID_5

Returns
PreferentialNetworkServiceConfig.Builder The builder to facilitate chaining. This value cannot be null.

setShouldBlockNonMatchingNetworks

Added in API level 34
public PreferentialNetworkServiceConfig.Builder setShouldBlockNonMatchingNetworks (boolean blockNonMatchingNetworks)

Set whether to block UIDs from using other networks than the preferential service. Apps can inspect the list of available networks on the device and choose to use multiple of them concurrently for performance, privacy or other reasons. This boolean configures whether the concerned UIDs should be blocked from using networks that do not match the configured preferential network service even if these networks are otherwise open to all apps. The default value is false. This value can only be set to true if setFallbackToDefaultConnectionAllowed(boolean) is set to false, because allowing fallback but blocking it does not make sense. Failure to comply with this constraint will throw when building the object.

Parameters
blockNonMatchingNetworks boolean: true if UIDs should be blocked from using non-matching networks.

Returns
PreferentialNetworkServiceConfig.Builder The builder to facilitate chaining. This value cannot be null.