Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b1cd4d7b authored by Chalard Jean's avatar Chalard Jean
Browse files

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
parent 0bd0dc2c
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
/**
 *
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.net;

/** @hide */
oneway interface IOnCompleteListener {
    void onComplete();
}
+71 −0
Original line number Diff line number Diff line
@@ -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.
+5 −0
Original line number Diff line number Diff line
@@ -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);
}
+19 −0
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ import android.net.INetworkActivityListener;
import android.net.INetworkMonitor;
import android.net.INetworkMonitorCallbacks;
import android.net.INetworkPolicyListener;
import android.net.IOnCompleteListener;
import android.net.IOnSetOemNetworkPreferenceListener;
import android.net.IQosCallback;
import android.net.ISocketKeepaliveCallback;
@@ -9109,6 +9110,24 @@ public class ConnectivityService extends IConnectivityManager.Stub
        }
    }

    /**
     * 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, as one of the PROFILE_NETWORK_PREFERENCE_*
     *                   constants.
     * @param listener an optional listener to listen for completion of the operation.
     */
    @Override
    public void setProfileNetworkPreference(@NonNull final UserHandle profile,
            @ConnectivityManager.ProfileNetworkPreference final int preference,
            @Nullable final IOnCompleteListener listener) {
        throw new UnsupportedOperationException("Not implemented yet");
    }

    /**
     * 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