Merge changes I335e82e2,I84ba363d,I8f18083b,I854a952d,I00e23441 am: bf97a3ab5e am: ba22df4f9d am: 2d82b40262
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1622621 Change-Id: I5fa8e7b8bf35a5464868fdca4d115b3f9132c65f
This commit is contained in:
@@ -64,6 +64,7 @@ import android.os.RemoteException;
|
||||
import android.os.ResultReceiver;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.ServiceSpecificException;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
@@ -970,6 +971,33 @@ public class ConnectivityManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Preference for {@link #setNetworkPreferenceForUser(UserHandle, int, Executor, Runnable)}.
|
||||
* Specify that the traffic for this user should by follow the default rules.
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
public static final int PROFILE_NETWORK_PREFERENCE_DEFAULT = 0;
|
||||
|
||||
/**
|
||||
* Preference for {@link #setNetworkPreferenceForUser(UserHandle, int, Executor, Runnable)}.
|
||||
* 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
|
||||
* if no such network is available.
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
public static final int PROFILE_NETWORK_PREFERENCE_ENTERPRISE = 1;
|
||||
|
||||
/** @hide */
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef(value = {
|
||||
PROFILE_NETWORK_PREFERENCE_DEFAULT,
|
||||
PROFILE_NETWORK_PREFERENCE_ENTERPRISE
|
||||
})
|
||||
public @interface ProfileNetworkPreference {
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the preferred network type. When the device has more
|
||||
* than one type available the preferred network type will be used.
|
||||
@@ -5066,19 +5094,6 @@ public class ConnectivityManager {
|
||||
TYPE_NONE, new CallbackHandler(handler));
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener for {@link #setOemNetworkPreference(OemNetworkPreferences, Executor,
|
||||
* OnSetOemNetworkPreferenceListener)}.
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
public interface OnSetOemNetworkPreferenceListener {
|
||||
/**
|
||||
* Called when setOemNetworkPreference() successfully completes.
|
||||
*/
|
||||
void onComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by automotive devices to set the network preferences used to direct traffic at an
|
||||
* application level as per the given OemNetworkPreferences. An example use-case would be an
|
||||
@@ -5101,16 +5116,16 @@ public class ConnectivityManager {
|
||||
@RequiresPermission(android.Manifest.permission.CONTROL_OEM_PAID_NETWORK_PREFERENCE)
|
||||
public void setOemNetworkPreference(@NonNull final OemNetworkPreferences preference,
|
||||
@Nullable @CallbackExecutor final Executor executor,
|
||||
@Nullable final OnSetOemNetworkPreferenceListener listener) {
|
||||
@Nullable final Runnable listener) {
|
||||
Objects.requireNonNull(preference, "OemNetworkPreferences must be non-null");
|
||||
if (null != listener) {
|
||||
Objects.requireNonNull(executor, "Executor must be non-null");
|
||||
}
|
||||
final IOnSetOemNetworkPreferenceListener listenerInternal = listener == null ? null :
|
||||
new IOnSetOemNetworkPreferenceListener.Stub() {
|
||||
final IOnCompleteListener listenerInternal = listener == null ? null :
|
||||
new IOnCompleteListener.Stub() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
executor.execute(listener::onComplete);
|
||||
executor.execute(listener::run);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5122,6 +5137,52 @@ public class ConnectivityManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request that a user profile is put by default on a network matching a given preference.
|
||||
*
|
||||
* See the documentation for the individual preferences for a description of the supported
|
||||
* behaviors.
|
||||
*
|
||||
* @param profile the profile concerned.
|
||||
* @param preference the preference for this profile.
|
||||
* @param executor an executor to execute the listener on. Optional if listener is null.
|
||||
* @param listener an optional listener to listen for completion of the operation.
|
||||
* @throws IllegalArgumentException if {@code profile} is not a valid user profile.
|
||||
* @throws SecurityException if missing the appropriate permissions.
|
||||
* @hide
|
||||
*/
|
||||
// This function is for establishing per-profile default networking and can only be called by
|
||||
// the device policy manager, running as the system server. It would make no sense to call it
|
||||
// on a context for a user because it does not establish a setting on behalf of a user, rather
|
||||
// it establishes a setting for a user on behalf of the DPM.
|
||||
@SuppressLint({"UserHandle"})
|
||||
@SystemApi(client = MODULE_LIBRARIES)
|
||||
@RequiresPermission(android.Manifest.permission.NETWORK_STACK)
|
||||
public void setProfileNetworkPreference(@NonNull final UserHandle profile,
|
||||
@ProfileNetworkPreference final int preference,
|
||||
@Nullable @CallbackExecutor final Executor executor,
|
||||
@Nullable final Runnable listener) {
|
||||
if (null != listener) {
|
||||
Objects.requireNonNull(executor, "Pass a non-null executor, or a null listener");
|
||||
}
|
||||
final IOnCompleteListener proxy;
|
||||
if (null == listener) {
|
||||
proxy = null;
|
||||
} else {
|
||||
proxy = new IOnCompleteListener.Stub() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
executor.execute(listener::run);
|
||||
}
|
||||
};
|
||||
}
|
||||
try {
|
||||
mService.setProfileNetworkPreference(profile, preference, proxy);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
// The first network ID of IPSec tunnel interface.
|
||||
private static final int TUN_INTF_NETID_START = 0xFC00; // 0xFC00 = 64512
|
||||
// The network ID range of IPSec tunnel interface.
|
||||
|
||||
Reference in New Issue
Block a user