Public API for per-profile network preference.

This patch defines the API, but does not make it public
yet as there is no implementation yet.

Test: none so far
Change-Id: I854a952dfe35cc80847eb62f522b1667b8e9b8a0
This commit is contained in:
Chalard Jean
2021-02-25 17:23:40 +09:00
parent 3453ec5024
commit ad565e26d9
2 changed files with 76 additions and 0 deletions

View File

@@ -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
*/
// TODO : @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
*/
// TODO : @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.
@@ -5053,6 +5081,8 @@ public class ConnectivityManager {
* OnSetOemNetworkPreferenceListener)}.
* @hide
*/
// TODO : remove this in favor of a vanilla runnable to follow API guidance to use
// functional interfaces when they are appropriate.
@SystemApi
public interface OnSetOemNetworkPreferenceListener {
/**
@@ -5104,6 +5134,47 @@ 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
*/
// TODO : @SystemApi
@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.