Ability for DPM to specify fallback mechanism
Bug: 194332512 Test: unit test Change-Id: Id4d85da8f64e7559326c4657b8833dac3ce5ce3d
This commit is contained in:
@@ -41,6 +41,7 @@ package android.net {
|
|||||||
field public static final int BLOCKED_REASON_RESTRICTED_MODE = 8; // 0x8
|
field public static final int BLOCKED_REASON_RESTRICTED_MODE = 8; // 0x8
|
||||||
field public static final int PROFILE_NETWORK_PREFERENCE_DEFAULT = 0; // 0x0
|
field public static final int PROFILE_NETWORK_PREFERENCE_DEFAULT = 0; // 0x0
|
||||||
field public static final int PROFILE_NETWORK_PREFERENCE_ENTERPRISE = 1; // 0x1
|
field public static final int PROFILE_NETWORK_PREFERENCE_ENTERPRISE = 1; // 0x1
|
||||||
|
field public static final int PROFILE_NETWORK_PREFERENCE_ENTERPRISE_NO_FALLBACK = 2; // 0x2
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ConnectivityManager.NetworkCallback {
|
public static class ConnectivityManager.NetworkCallback {
|
||||||
|
|||||||
@@ -1078,7 +1078,8 @@ public class ConnectivityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preference for {@link #setNetworkPreferenceForUser(UserHandle, int, Executor, Runnable)}.
|
* Preference for {@link ProfileNetworkPreference#setPreference(int)}.
|
||||||
|
* {@see #setProfileNetworkPreferences(UserHandle, List, Executor, Runnable)}
|
||||||
* Specify that the traffic for this user should by follow the default rules.
|
* Specify that the traffic for this user should by follow the default rules.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@@ -1086,7 +1087,8 @@ public class ConnectivityManager {
|
|||||||
public static final int PROFILE_NETWORK_PREFERENCE_DEFAULT = 0;
|
public static final int PROFILE_NETWORK_PREFERENCE_DEFAULT = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preference for {@link #setNetworkPreferenceForUser(UserHandle, int, Executor, Runnable)}.
|
* Preference for {@link ProfileNetworkPreference#setPreference(int)}.
|
||||||
|
* {@see #setProfileNetworkPreferences(UserHandle, List, Executor, Runnable)}
|
||||||
* Specify that the traffic for this user should by default go on a network with
|
* Specify that the traffic for this user should by default go on a network with
|
||||||
* {@link NetworkCapabilities#NET_CAPABILITY_ENTERPRISE}, and on the system default network
|
* {@link NetworkCapabilities#NET_CAPABILITY_ENTERPRISE}, and on the system default network
|
||||||
* if no such network is available.
|
* if no such network is available.
|
||||||
@@ -1095,11 +1097,23 @@ public class ConnectivityManager {
|
|||||||
@SystemApi(client = MODULE_LIBRARIES)
|
@SystemApi(client = MODULE_LIBRARIES)
|
||||||
public static final int PROFILE_NETWORK_PREFERENCE_ENTERPRISE = 1;
|
public static final int PROFILE_NETWORK_PREFERENCE_ENTERPRISE = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preference for {@link ProfileNetworkPreference#setPreference(int)}.
|
||||||
|
* {@see #setProfileNetworkPreferences(UserHandle, List, Executor, Runnable)}
|
||||||
|
* Specify that the traffic for this user should by default go on a network with
|
||||||
|
* {@link NetworkCapabilities#NET_CAPABILITY_ENTERPRISE} and if no such network is available
|
||||||
|
* should not go on the system default network
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@SystemApi(client = MODULE_LIBRARIES)
|
||||||
|
public static final int PROFILE_NETWORK_PREFERENCE_ENTERPRISE_NO_FALLBACK = 2;
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
@IntDef(value = {
|
@IntDef(value = {
|
||||||
PROFILE_NETWORK_PREFERENCE_DEFAULT,
|
PROFILE_NETWORK_PREFERENCE_DEFAULT,
|
||||||
PROFILE_NETWORK_PREFERENCE_ENTERPRISE
|
PROFILE_NETWORK_PREFERENCE_ENTERPRISE,
|
||||||
|
PROFILE_NETWORK_PREFERENCE_ENTERPRISE_NO_FALLBACK
|
||||||
})
|
})
|
||||||
public @interface ProfileNetworkPreferencePolicy {
|
public @interface ProfileNetworkPreferencePolicy {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public final class ProfileNetworkPreference implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (mPreference);
|
return mPreference;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,6 +91,7 @@ public final class ProfileNetworkPreference implements Parcelable {
|
|||||||
mPreference = preference;
|
mPreference = preference;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an instance of {@link ProfileNetworkPreference} created from the
|
* Returns an instance of {@link ProfileNetworkPreference} created from the
|
||||||
* fields set on this builder.
|
* fields set on this builder.
|
||||||
|
|||||||
@@ -5674,7 +5674,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
mPermissionMonitor.onUserRemoved(user);
|
mPermissionMonitor.onUserRemoved(user);
|
||||||
// If there was a network preference for this user, remove it.
|
// If there was a network preference for this user, remove it.
|
||||||
handleSetProfileNetworkPreference(
|
handleSetProfileNetworkPreference(
|
||||||
List.of(new ProfileNetworkPreferenceList.Preference(user, null)),
|
List.of(new ProfileNetworkPreferenceList.Preference(user, null, true)),
|
||||||
null /* listener */);
|
null /* listener */);
|
||||||
if (mOemNetworkPreferences.getNetworkPreferences().size() > 0) {
|
if (mOemNetworkPreferences.getNetworkPreferences().size() > 0) {
|
||||||
handleSetOemNetworkPreference(mOemNetworkPreferences, null);
|
handleSetOemNetworkPreference(mOemNetworkPreferences, null);
|
||||||
@@ -10139,12 +10139,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
final List<ProfileNetworkPreferenceList.Preference> preferenceList =
|
final List<ProfileNetworkPreferenceList.Preference> preferenceList =
|
||||||
new ArrayList<ProfileNetworkPreferenceList.Preference>();
|
new ArrayList<ProfileNetworkPreferenceList.Preference>();
|
||||||
|
boolean allowFallback = true;
|
||||||
for (final ProfileNetworkPreference preference : preferences) {
|
for (final ProfileNetworkPreference preference : preferences) {
|
||||||
final NetworkCapabilities nc;
|
final NetworkCapabilities nc;
|
||||||
switch (preference.getPreference()) {
|
switch (preference.getPreference()) {
|
||||||
case ConnectivityManager.PROFILE_NETWORK_PREFERENCE_DEFAULT:
|
case ConnectivityManager.PROFILE_NETWORK_PREFERENCE_DEFAULT:
|
||||||
nc = null;
|
nc = null;
|
||||||
break;
|
break;
|
||||||
|
case ConnectivityManager.PROFILE_NETWORK_PREFERENCE_ENTERPRISE_NO_FALLBACK:
|
||||||
|
allowFallback = false;
|
||||||
|
// continue to process the enterprise preference.
|
||||||
case ConnectivityManager.PROFILE_NETWORK_PREFERENCE_ENTERPRISE:
|
case ConnectivityManager.PROFILE_NETWORK_PREFERENCE_ENTERPRISE:
|
||||||
final UidRange uids = UidRange.createForUser(profile);
|
final UidRange uids = UidRange.createForUser(profile);
|
||||||
nc = createDefaultNetworkCapabilitiesForUidRange(uids);
|
nc = createDefaultNetworkCapabilitiesForUidRange(uids);
|
||||||
@@ -10155,8 +10159,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Invalid preference in setProfileNetworkPreferences");
|
"Invalid preference in setProfileNetworkPreferences");
|
||||||
}
|
}
|
||||||
preferenceList.add(
|
preferenceList.add(new ProfileNetworkPreferenceList.Preference(
|
||||||
new ProfileNetworkPreferenceList.Preference(profile, nc));
|
profile, nc, allowFallback));
|
||||||
}
|
}
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(EVENT_SET_PROFILE_NETWORK_PREFERENCE,
|
mHandler.sendMessage(mHandler.obtainMessage(EVENT_SET_PROFILE_NETWORK_PREFERENCE,
|
||||||
new Pair<>(preferenceList, listener)));
|
new Pair<>(preferenceList, listener)));
|
||||||
@@ -10172,17 +10176,17 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
@NonNull final ProfileNetworkPreferenceList prefs) {
|
@NonNull final ProfileNetworkPreferenceList prefs) {
|
||||||
final ArraySet<NetworkRequestInfo> result = new ArraySet<>();
|
final ArraySet<NetworkRequestInfo> result = new ArraySet<>();
|
||||||
for (final ProfileNetworkPreferenceList.Preference pref : prefs.preferences) {
|
for (final ProfileNetworkPreferenceList.Preference pref : prefs.preferences) {
|
||||||
// The NRI for a user should be comprised of two layers:
|
// The NRI for a user should contain the request for capabilities.
|
||||||
// - The request for the capabilities
|
// If fallback to default network is needed then NRI should include
|
||||||
// - The request for the default network, for fallback. Create an image of it to
|
// the request for the default network. Create an image of it to
|
||||||
// have the correct UIDs in it (also a request can only be part of one NRI, because
|
// have the correct UIDs in it (also a request can only be part of one NRI, because
|
||||||
// of lookups in 1:1 associations like mNetworkRequests).
|
// of lookups in 1:1 associations like mNetworkRequests).
|
||||||
// Note that denying a fallback can be implemented simply by not adding the second
|
|
||||||
// request.
|
|
||||||
final ArrayList<NetworkRequest> nrs = new ArrayList<>();
|
final ArrayList<NetworkRequest> nrs = new ArrayList<>();
|
||||||
nrs.add(createNetworkRequest(NetworkRequest.Type.REQUEST, pref.capabilities));
|
nrs.add(createNetworkRequest(NetworkRequest.Type.REQUEST, pref.capabilities));
|
||||||
nrs.add(createDefaultInternetRequestForTransport(
|
if (pref.allowFallback) {
|
||||||
TYPE_NONE, NetworkRequest.Type.TRACK_DEFAULT));
|
nrs.add(createDefaultInternetRequestForTransport(
|
||||||
|
TYPE_NONE, NetworkRequest.Type.TRACK_DEFAULT));
|
||||||
|
}
|
||||||
setNetworkRequestUids(nrs, UidRange.fromIntRanges(pref.capabilities.getUids()));
|
setNetworkRequestUids(nrs, UidRange.fromIntRanges(pref.capabilities.getUids()));
|
||||||
final NetworkRequestInfo nri = new NetworkRequestInfo(Process.myUid(), nrs,
|
final NetworkRequestInfo nri = new NetworkRequestInfo(Process.myUid(), nrs,
|
||||||
PREFERENCE_ORDER_PROFILE);
|
PREFERENCE_ORDER_PROFILE);
|
||||||
|
|||||||
@@ -38,16 +38,22 @@ public class ProfileNetworkPreferenceList {
|
|||||||
@NonNull public final UserHandle user;
|
@NonNull public final UserHandle user;
|
||||||
// Capabilities are only null when sending an object to remove the setting for a user
|
// Capabilities are only null when sending an object to remove the setting for a user
|
||||||
@Nullable public final NetworkCapabilities capabilities;
|
@Nullable public final NetworkCapabilities capabilities;
|
||||||
|
public final boolean allowFallback;
|
||||||
|
|
||||||
public Preference(@NonNull final UserHandle user,
|
public Preference(@NonNull final UserHandle user,
|
||||||
@Nullable final NetworkCapabilities capabilities) {
|
@Nullable final NetworkCapabilities capabilities,
|
||||||
|
final boolean allowFallback) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.capabilities = null == capabilities ? null : new NetworkCapabilities(capabilities);
|
this.capabilities = null == capabilities ? null : new NetworkCapabilities(capabilities);
|
||||||
|
this.allowFallback = allowFallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** toString */
|
/** toString */
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[ProfileNetworkPreference user=" + user + " caps=" + capabilities + "]";
|
return "[ProfileNetworkPreference user=" + user
|
||||||
|
+ " caps=" + capabilities
|
||||||
|
+ " allowFallback=" + allowFallback
|
||||||
|
+ "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import static android.net.ConnectivityManager.EXTRA_NETWORK_INFO;
|
|||||||
import static android.net.ConnectivityManager.EXTRA_NETWORK_TYPE;
|
import static android.net.ConnectivityManager.EXTRA_NETWORK_TYPE;
|
||||||
import static android.net.ConnectivityManager.PROFILE_NETWORK_PREFERENCE_DEFAULT;
|
import static android.net.ConnectivityManager.PROFILE_NETWORK_PREFERENCE_DEFAULT;
|
||||||
import static android.net.ConnectivityManager.PROFILE_NETWORK_PREFERENCE_ENTERPRISE;
|
import static android.net.ConnectivityManager.PROFILE_NETWORK_PREFERENCE_ENTERPRISE;
|
||||||
|
import static android.net.ConnectivityManager.PROFILE_NETWORK_PREFERENCE_ENTERPRISE_NO_FALLBACK;
|
||||||
import static android.net.ConnectivityManager.TYPE_ETHERNET;
|
import static android.net.ConnectivityManager.TYPE_ETHERNET;
|
||||||
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||||
import static android.net.ConnectivityManager.TYPE_MOBILE_FOTA;
|
import static android.net.ConnectivityManager.TYPE_MOBILE_FOTA;
|
||||||
@@ -250,6 +251,7 @@ import android.net.NetworkStateSnapshot;
|
|||||||
import android.net.NetworkTestResultParcelable;
|
import android.net.NetworkTestResultParcelable;
|
||||||
import android.net.OemNetworkPreferences;
|
import android.net.OemNetworkPreferences;
|
||||||
import android.net.PacProxyManager;
|
import android.net.PacProxyManager;
|
||||||
|
import android.net.ProfileNetworkPreference;
|
||||||
import android.net.Proxy;
|
import android.net.Proxy;
|
||||||
import android.net.ProxyInfo;
|
import android.net.ProxyInfo;
|
||||||
import android.net.QosCallbackException;
|
import android.net.QosCallbackException;
|
||||||
@@ -13755,12 +13757,12 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure per-profile networking preference behaves as expected when the enterprise network
|
* Make sure per profile network preferences behave as expected for a given
|
||||||
* goes up and down while the preference is active. Make sure they behave as expected whether
|
* profile network preference.
|
||||||
* there is a general default network or not.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
public void testPreferenceForUserNetworkUpDownForGivenPreference(
|
||||||
public void testPreferenceForUserNetworkUpDown() throws Exception {
|
ProfileNetworkPreference profileNetworkPreference,
|
||||||
|
boolean connectWorkProfileAgentAhead) throws Exception {
|
||||||
final InOrder inOrder = inOrder(mMockNetd);
|
final InOrder inOrder = inOrder(mMockNetd);
|
||||||
final UserHandle testHandle = setupEnterpriseNetwork();
|
final UserHandle testHandle = setupEnterpriseNetwork();
|
||||||
registerDefaultNetworkCallbacks();
|
registerDefaultNetworkCallbacks();
|
||||||
@@ -13774,29 +13776,45 @@ public class ConnectivityServiceTest {
|
|||||||
inOrder.verify(mMockNetd).networkCreate(nativeNetworkConfigPhysical(
|
inOrder.verify(mMockNetd).networkCreate(nativeNetworkConfigPhysical(
|
||||||
mCellNetworkAgent.getNetwork().netId, INetd.PERMISSION_NONE));
|
mCellNetworkAgent.getNetwork().netId, INetd.PERMISSION_NONE));
|
||||||
|
|
||||||
|
final TestNetworkAgentWrapper workAgent = makeEnterpriseNetworkAgent();
|
||||||
|
if (connectWorkProfileAgentAhead) {
|
||||||
|
workAgent.connect(false);
|
||||||
|
}
|
||||||
|
|
||||||
final TestOnCompleteListener listener = new TestOnCompleteListener();
|
final TestOnCompleteListener listener = new TestOnCompleteListener();
|
||||||
mCm.setProfileNetworkPreference(testHandle, PROFILE_NETWORK_PREFERENCE_ENTERPRISE,
|
mCm.setProfileNetworkPreferences(testHandle, List.of(profileNetworkPreference),
|
||||||
r -> r.run(), listener);
|
r -> r.run(), listener);
|
||||||
listener.expectOnComplete();
|
listener.expectOnComplete();
|
||||||
|
boolean allowFallback = true;
|
||||||
// Setting a network preference for this user will create a new set of routing rules for
|
if (profileNetworkPreference.getPreference()
|
||||||
// the UID range that corresponds to this user, so as to define the default network
|
== PROFILE_NETWORK_PREFERENCE_ENTERPRISE_NO_FALLBACK) {
|
||||||
// for these apps separately. This is true because the multi-layer request relevant to
|
allowFallback = false;
|
||||||
// this UID range contains a TRACK_DEFAULT, so the range will be moved through UID-specific
|
}
|
||||||
// rules to the correct network – in this case the system default network. The case where
|
if (allowFallback) {
|
||||||
// the default network for the profile happens to be the same as the system default
|
// Setting a network preference for this user will create a new set of routing rules for
|
||||||
// is not handled specially, the rules are always active as long as a preference is set.
|
// the UID range that corresponds to this user, inorder to define the default network
|
||||||
inOrder.verify(mMockNetd).networkAddUidRangesParcel(new NativeUidRangeConfig(
|
// for these apps separately. This is true because the multi-layer request relevant to
|
||||||
mCellNetworkAgent.getNetwork().netId, uidRangeFor(testHandle),
|
// this UID range contains a TRACK_DEFAULT, so the range will be moved through
|
||||||
PREFERENCE_ORDER_PROFILE));
|
// UID-specific rules to the correct network – in this case the system default network.
|
||||||
|
// The case where the default network for the profile happens to be the same as the
|
||||||
|
// system default is not handled specially, the rules are always active as long as
|
||||||
|
// a preference is set.
|
||||||
|
inOrder.verify(mMockNetd).networkAddUidRangesParcel(new NativeUidRangeConfig(
|
||||||
|
mCellNetworkAgent.getNetwork().netId, uidRangeFor(testHandle),
|
||||||
|
PREFERENCE_ORDER_PROFILE));
|
||||||
|
}
|
||||||
|
|
||||||
// The enterprise network is not ready yet.
|
// The enterprise network is not ready yet.
|
||||||
assertNoCallbacks(mSystemDefaultNetworkCallback, mDefaultNetworkCallback,
|
assertNoCallbacks(mSystemDefaultNetworkCallback, mDefaultNetworkCallback);
|
||||||
mProfileDefaultNetworkCallback);
|
if (allowFallback) {
|
||||||
|
assertNoCallbacks(mProfileDefaultNetworkCallback);
|
||||||
|
} else if (!connectWorkProfileAgentAhead) {
|
||||||
|
mProfileDefaultNetworkCallback.expectCallback(CallbackEntry.LOST, mCellNetworkAgent);
|
||||||
|
}
|
||||||
|
|
||||||
final TestNetworkAgentWrapper workAgent = makeEnterpriseNetworkAgent();
|
if (!connectWorkProfileAgentAhead) {
|
||||||
workAgent.connect(false);
|
workAgent.connect(false);
|
||||||
|
}
|
||||||
|
|
||||||
mProfileDefaultNetworkCallback.expectAvailableCallbacksUnvalidated(workAgent);
|
mProfileDefaultNetworkCallback.expectAvailableCallbacksUnvalidated(workAgent);
|
||||||
mSystemDefaultNetworkCallback.assertNoCallback();
|
mSystemDefaultNetworkCallback.assertNoCallback();
|
||||||
@@ -13805,9 +13823,12 @@ public class ConnectivityServiceTest {
|
|||||||
nativeNetworkConfigPhysical(workAgent.getNetwork().netId, INetd.PERMISSION_SYSTEM));
|
nativeNetworkConfigPhysical(workAgent.getNetwork().netId, INetd.PERMISSION_SYSTEM));
|
||||||
inOrder.verify(mMockNetd).networkAddUidRangesParcel(new NativeUidRangeConfig(
|
inOrder.verify(mMockNetd).networkAddUidRangesParcel(new NativeUidRangeConfig(
|
||||||
workAgent.getNetwork().netId, uidRangeFor(testHandle), PREFERENCE_ORDER_PROFILE));
|
workAgent.getNetwork().netId, uidRangeFor(testHandle), PREFERENCE_ORDER_PROFILE));
|
||||||
inOrder.verify(mMockNetd).networkRemoveUidRangesParcel(new NativeUidRangeConfig(
|
|
||||||
mCellNetworkAgent.getNetwork().netId, uidRangeFor(testHandle),
|
if (allowFallback) {
|
||||||
PREFERENCE_ORDER_PROFILE));
|
inOrder.verify(mMockNetd).networkRemoveUidRangesParcel(new NativeUidRangeConfig(
|
||||||
|
mCellNetworkAgent.getNetwork().netId, uidRangeFor(testHandle),
|
||||||
|
PREFERENCE_ORDER_PROFILE));
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure changes to the work agent send callbacks to the app in the work profile, but
|
// Make sure changes to the work agent send callbacks to the app in the work profile, but
|
||||||
// not to the other apps.
|
// not to the other apps.
|
||||||
@@ -13853,17 +13874,23 @@ public class ConnectivityServiceTest {
|
|||||||
// default network.
|
// default network.
|
||||||
workAgent.disconnect();
|
workAgent.disconnect();
|
||||||
mProfileDefaultNetworkCallback.expectCallback(CallbackEntry.LOST, workAgent);
|
mProfileDefaultNetworkCallback.expectCallback(CallbackEntry.LOST, workAgent);
|
||||||
mProfileDefaultNetworkCallback.expectAvailableCallbacksValidated(mCellNetworkAgent);
|
if (allowFallback) {
|
||||||
|
mProfileDefaultNetworkCallback.expectAvailableCallbacksValidated(mCellNetworkAgent);
|
||||||
|
}
|
||||||
assertNoCallbacks(mSystemDefaultNetworkCallback, mDefaultNetworkCallback);
|
assertNoCallbacks(mSystemDefaultNetworkCallback, mDefaultNetworkCallback);
|
||||||
inOrder.verify(mMockNetd).networkAddUidRangesParcel(new NativeUidRangeConfig(
|
if (allowFallback) {
|
||||||
mCellNetworkAgent.getNetwork().netId, uidRangeFor(testHandle),
|
inOrder.verify(mMockNetd).networkAddUidRangesParcel(new NativeUidRangeConfig(
|
||||||
PREFERENCE_ORDER_PROFILE));
|
mCellNetworkAgent.getNetwork().netId, uidRangeFor(testHandle),
|
||||||
|
PREFERENCE_ORDER_PROFILE));
|
||||||
|
}
|
||||||
inOrder.verify(mMockNetd).networkDestroy(workAgent.getNetwork().netId);
|
inOrder.verify(mMockNetd).networkDestroy(workAgent.getNetwork().netId);
|
||||||
|
|
||||||
mCellNetworkAgent.disconnect();
|
mCellNetworkAgent.disconnect();
|
||||||
mSystemDefaultNetworkCallback.expectCallback(CallbackEntry.LOST, mCellNetworkAgent);
|
mSystemDefaultNetworkCallback.expectCallback(CallbackEntry.LOST, mCellNetworkAgent);
|
||||||
mDefaultNetworkCallback.expectCallback(CallbackEntry.LOST, mCellNetworkAgent);
|
mDefaultNetworkCallback.expectCallback(CallbackEntry.LOST, mCellNetworkAgent);
|
||||||
mProfileDefaultNetworkCallback.expectCallback(CallbackEntry.LOST, mCellNetworkAgent);
|
if (allowFallback) {
|
||||||
|
mProfileDefaultNetworkCallback.expectCallback(CallbackEntry.LOST, mCellNetworkAgent);
|
||||||
|
}
|
||||||
|
|
||||||
// Waiting for the handler to be idle before checking for networkDestroy is necessary
|
// Waiting for the handler to be idle before checking for networkDestroy is necessary
|
||||||
// here because ConnectivityService calls onLost before the network is fully torn down.
|
// here because ConnectivityService calls onLost before the network is fully torn down.
|
||||||
@@ -13891,7 +13918,7 @@ public class ConnectivityServiceTest {
|
|||||||
assertNoCallbacks(mSystemDefaultNetworkCallback, mDefaultNetworkCallback);
|
assertNoCallbacks(mSystemDefaultNetworkCallback, mDefaultNetworkCallback);
|
||||||
inOrder.verify(mMockNetd, never()).networkAddUidRangesParcel(any());
|
inOrder.verify(mMockNetd, never()).networkAddUidRangesParcel(any());
|
||||||
|
|
||||||
// When the agent disconnects, test that the app on the work profile falls back to the
|
// When the agent disconnects, test that the app on the work profile fall back to the
|
||||||
// default network.
|
// default network.
|
||||||
workAgent2.disconnect();
|
workAgent2.disconnect();
|
||||||
mProfileDefaultNetworkCallback.expectCallback(CallbackEntry.LOST, workAgent2);
|
mProfileDefaultNetworkCallback.expectCallback(CallbackEntry.LOST, workAgent2);
|
||||||
@@ -13904,6 +13931,52 @@ public class ConnectivityServiceTest {
|
|||||||
// Callbacks will be unregistered by tearDown()
|
// Callbacks will be unregistered by tearDown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure per-profile networking preference behaves as expected when the enterprise network
|
||||||
|
* goes up and down while the preference is active. Make sure they behave as expected whether
|
||||||
|
* there is a general default network or not.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testPreferenceForUserNetworkUpDown() throws Exception {
|
||||||
|
ProfileNetworkPreference.Builder profileNetworkPreferenceBuilder =
|
||||||
|
new ProfileNetworkPreference.Builder();
|
||||||
|
profileNetworkPreferenceBuilder.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE);
|
||||||
|
testPreferenceForUserNetworkUpDownForGivenPreference(
|
||||||
|
profileNetworkPreferenceBuilder.build(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure per-profile networking preference behaves as expected when the enterprise network
|
||||||
|
* goes up and down while the preference is active. Make sure they behave as expected whether
|
||||||
|
* there is a general default network or not when configured to not fallback to default network.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testPreferenceForUserNetworkUpDownWithNoFallback() throws Exception {
|
||||||
|
ProfileNetworkPreference.Builder profileNetworkPreferenceBuilder =
|
||||||
|
new ProfileNetworkPreference.Builder();
|
||||||
|
profileNetworkPreferenceBuilder.setPreference(
|
||||||
|
PROFILE_NETWORK_PREFERENCE_ENTERPRISE_NO_FALLBACK);
|
||||||
|
testPreferenceForUserNetworkUpDownForGivenPreference(
|
||||||
|
profileNetworkPreferenceBuilder.build(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure per-profile networking preference behaves as expected when the enterprise network
|
||||||
|
* goes up and down while the preference is active. Make sure they behave as expected whether
|
||||||
|
* there is a general default network or not when configured to not fallback to default network
|
||||||
|
* along with already connected enterprise work agent
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testPreferenceForUserNetworkUpDownWithNoFallbackWithAlreadyConnectedWorkAgent()
|
||||||
|
throws Exception {
|
||||||
|
ProfileNetworkPreference.Builder profileNetworkPreferenceBuilder =
|
||||||
|
new ProfileNetworkPreference.Builder();
|
||||||
|
profileNetworkPreferenceBuilder.setPreference(
|
||||||
|
PROFILE_NETWORK_PREFERENCE_ENTERPRISE_NO_FALLBACK);
|
||||||
|
testPreferenceForUserNetworkUpDownForGivenPreference(
|
||||||
|
profileNetworkPreferenceBuilder.build(), true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that, in a given networking context, calling setPreferenceForUser to set per-profile
|
* Test that, in a given networking context, calling setPreferenceForUser to set per-profile
|
||||||
* defaults on then off works as expected.
|
* defaults on then off works as expected.
|
||||||
@@ -14057,7 +14130,8 @@ public class ConnectivityServiceTest {
|
|||||||
assertThrows("Should not be able to set an illegal preference",
|
assertThrows("Should not be able to set an illegal preference",
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() -> mCm.setProfileNetworkPreference(testHandle,
|
() -> mCm.setProfileNetworkPreference(testHandle,
|
||||||
PROFILE_NETWORK_PREFERENCE_ENTERPRISE + 1, null, null));
|
PROFILE_NETWORK_PREFERENCE_ENTERPRISE_NO_FALLBACK + 1,
|
||||||
|
null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user