Migrate framework-connectivity internal resources
Use ServiceConnectivityResources instead. Start by creating resources in the ServiceConnectivityResources package to match the internal configuration, and common overlays. Bug: 182125649 Test: device boots, has connectivity Change-Id: I77a3efca2cd644f9828db1ed5d3cae8070fb8363 Merged-In: I77a3efca2cd644f9828db1ed5d3cae8070fb8363
This commit is contained in:
committed by
Lorenzo Colitti
parent
e2139a0be2
commit
0d4c78d80d
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user