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

Commit c0ccc33e authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN Committed by Android (Google) Code Review
Browse files

Merge changes I77a3efca,I2c4a37ff into sc-dev

* changes:
  Migrate framework-connectivity internal resources
  Add connectivity protos to framework-connectivity
parents 0fc7834f dd5f6037
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -23,6 +23,25 @@ package {
    default_applicable_licenses: ["frameworks_base_license"],
}

java_library {
    name: "framework-connectivity-protos",
    proto: {
        type: "nano",
    },
    srcs: [
        // TODO: consider moving relevant .proto files directly to the module directory
        ":framework-javastream-protos",
    ],
    apex_available: [
        "//apex_available:platform",
        "com.android.tethering",
    ],
    jarjar_rules: "jarjar-rules-proto.txt",
    visibility: [
        "//visibility:private",
    ],
}

filegroup {
    name: "framework-connectivity-internal-sources",
    srcs: [
@@ -111,6 +130,7 @@ java_library {
        "ServiceConnectivityResources",
    ],
    static_libs: [
        "framework-connectivity-protos",
        "net-utils-device-common",
    ],
    jarjar_rules: "jarjar-rules.txt",
+3 −0
Original line number Diff line number Diff line
keep android.net.NetworkCapabilitiesProto
keep android.net.NetworkProto
keep android.net.NetworkRequestProto
+3 −0
Original line number Diff line number Diff line
@@ -5,3 +5,6 @@ zap android.annotation.**
zap com.android.net.module.annotation.**
zap com.android.internal.annotations.**

rule android.net.NetworkCapabilitiesProto* android.net.connectivity.proto.NetworkCapabilitiesProto@1
rule android.net.NetworkProto* android.net.connectivity.proto.NetworkProto@1
rule android.net.NetworkRequestProto* android.net.connectivity.proto.NetworkRequestProto@1
+35 −10
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.server.connectivity;
package android.net;

import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;

@@ -27,13 +27,14 @@ import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.util.Log;

import com.android.server.ConnectivityService;
import com.android.internal.annotations.VisibleForTesting;

import java.util.List;

/**
 * Utility to obtain the {@link ConnectivityService} {@link Resources}, in the
 * Utility to obtain the {@link com.android.server.ConnectivityService} {@link Resources}, in the
 * ServiceConnectivityResources APK.
 * @hide
 */
public class ConnectivityResources {
    private static final String RESOURCES_APK_INTENT =
@@ -44,18 +45,35 @@ public class ConnectivityResources {
    private final Context mContext;

    @Nullable
    private Resources mResources = null;
    private Context mResourcesContext = null;

    @Nullable
    private static Context sTestResourcesContext = null;

    public ConnectivityResources(Context context) {
        mContext = context;
    }

    /**
     * Get the {@link Resources} of the ServiceConnectivityResources APK.
     * Convenience method to mock all resources for the duration of a test.
     *
     * Call with a null context to reset after the test.
     */
    @VisibleForTesting
    public static void setResourcesContextForTest(@Nullable Context testContext) {
        sTestResourcesContext = testContext;
    }

    /**
     * Get the {@link Context} of the resources package.
     */
    public synchronized Resources get() {
        if (mResources != null) {
            return mResources;
    public synchronized Context getResourcesContext() {
        if (sTestResourcesContext != null) {
            return sTestResourcesContext;
        }

        if (mResourcesContext != null) {
            return mResourcesContext;
        }

        final List<ResolveInfo> pkgs = mContext.getPackageManager()
@@ -77,7 +95,14 @@ public class ConnectivityResources {
            throw new IllegalStateException("Resolved package not found", e);
        }

        mResources = pkgContext.getResources();
        return mResources;
        mResourcesContext = pkgContext;
        return pkgContext;
    }

    /**
     * Get the {@link Resources} of the ServiceConnectivityResources APK.
     */
    public Resources get() {
        return getResourcesContext().getResources();
    }
}
+44 −4
Original line number Diff line number Diff line
@@ -19,12 +19,12 @@ package android.net.apf;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.content.Context;
import android.content.res.Resources;
import android.net.ConnectivityResources;
import android.os.Parcel;
import android.os.Parcelable;

import com.android.internal.R;

/**
 * APF program support capabilities. APF stands for Android Packet Filtering and it is a flexible
 * way to drop unwanted network packets to save power.
@@ -36,6 +36,8 @@ import com.android.internal.R;
 */
@SystemApi
public final class ApfCapabilities implements Parcelable {
    private static ConnectivityResources sResources;

    /**
     * Version of APF instruction set supported for packet filtering. 0 indicates no support for
     * packet filtering using APF programs.
@@ -65,6 +67,14 @@ public final class ApfCapabilities implements Parcelable {
        apfPacketFormat = in.readInt();
    }

    @NonNull
    private static synchronized ConnectivityResources getResources(@NonNull Context ctx) {
        if (sResources == null)  {
            sResources = new ConnectivityResources(ctx);
        }
        return sResources;
    }


    @Override
    public int describeContents() {
@@ -121,13 +131,43 @@ public final class ApfCapabilities implements Parcelable {
     * @return Whether the APF Filter in the device should filter out IEEE 802.3 Frames.
     */
    public static boolean getApfDrop8023Frames() {
        return Resources.getSystem().getBoolean(R.bool.config_apfDrop802_3Frames);
        // TODO(b/183076074): remove reading resources from system resources
        final Resources systemRes = Resources.getSystem();
        final int id = systemRes.getIdentifier("config_apfDrop802_3Frames", "bool", "android");
        return systemRes.getBoolean(id);
    }

    /**
     * @return Whether the APF Filter in the device should filter out IEEE 802.3 Frames.
     * @hide
     */
    public static boolean getApfDrop8023Frames(@NonNull Context context) {
        final ConnectivityResources res = getResources(context);
        // TODO(b/183076074): use R.bool.config_apfDrop802_3Frames directly
        final int id = res.get().getIdentifier("config_apfDrop802_3Frames", "bool",
                res.getResourcesContext().getPackageName());
        return res.get().getBoolean(id);
    }

    /**
     * @return An array of denylisted EtherType, packets with EtherTypes within it will be dropped.
     */
    public static @NonNull int[] getApfEtherTypeBlackList() {
        return Resources.getSystem().getIntArray(R.array.config_apfEthTypeBlackList);
        // TODO(b/183076074): remove reading resources from system resources
        final Resources systemRes = Resources.getSystem();
        final int id = systemRes.getIdentifier("config_apfEthTypeBlackList", "array", "android");
        return systemRes.getIntArray(id);
    }

    /**
     * @return An array of denylisted EtherType, packets with EtherTypes within it will be dropped.
     * @hide
     */
    public static @NonNull int[] getApfEtherTypeDenyList(@NonNull Context context) {
        final ConnectivityResources res = getResources(context);
        // TODO(b/183076074): use R.array.config_apfEthTypeDenyList directly
        final int id = res.get().getIdentifier("config_apfEthTypeDenyList", "array",
                res.getResourcesContext().getPackageName());
        return res.get().getIntArray(id);
    }
}
Loading