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:
@@ -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.
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.app.PendingIntent;
|
||||
import android.net.ConnectionInfo;
|
||||
import android.net.ConnectivityDiagnosticsManager;
|
||||
import android.net.IConnectivityDiagnosticsCallback;
|
||||
import android.net.IOnCompleteListener;
|
||||
import android.net.IOnSetOemNetworkPreferenceListener;
|
||||
import android.net.INetworkActivityListener;
|
||||
import android.net.IQosCallback;
|
||||
@@ -43,6 +44,7 @@ import android.os.Messenger;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.PersistableBundle;
|
||||
import android.os.ResultReceiver;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.connectivity.aidl.INetworkAgent;
|
||||
|
||||
@@ -216,4 +218,7 @@ interface IConnectivityManager
|
||||
|
||||
void setOemNetworkPreference(in OemNetworkPreferences preference,
|
||||
in IOnSetOemNetworkPreferenceListener listener);
|
||||
|
||||
void setProfileNetworkPreference(in UserHandle profile, int preference,
|
||||
in IOnCompleteListener listener);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user