Merge "Add wear owner to wathc res dir with specified sdk version" into main
diff --git a/Android.bp b/Android.bp
index 5b6e65c..b114898 100644
--- a/Android.bp
+++ b/Android.bp
@@ -168,12 +168,6 @@
//same purpose.
"//external/robolectric:__subpackages__",
"//frameworks/layoutlib:__subpackages__",
-
- // This is for the same purpose as robolectric -- to build "framework.jar" for host-side
- // testing.
- // TODO: Once Ravenwood is stable, move the host side jar targets to this directory,
- // and remove this line.
- "//frameworks/base/tools/hoststubgen:__subpackages__",
],
}
diff --git a/Ravenwood.bp b/Ravenwood.bp
index ec58210..2e038e0 100644
--- a/Ravenwood.bp
+++ b/Ravenwood.bp
@@ -12,256 +12,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-// We need this "trampoline" rule to force soong to give a host-side jar to
-// framework-minus-apex.ravenwood-base. Otherwise, soong would mix up the arch (?) and we'd get
-// a dex jar.
-java_library {
- name: "framework-minus-apex-for-hoststubgen",
- installable: false, // host only jar.
- static_libs: [
- "framework-minus-apex",
- ],
- sdk_version: "core_platform",
- visibility: ["//visibility:private"],
-}
-
-// Process framework-all with hoststubgen for Ravenwood.
-// This step takes several tens of seconds, so we manually shard it to multiple modules.
-// All the copies have to be kept in sync.
-// TODO: Do the sharding better, either by making hostsubgen support sharding natively, or
-// making a better build rule.
-
-genrule_defaults {
- name: "framework-minus-apex.ravenwood-base_defaults",
- defaults: ["ravenwood-internal-only-visibility-genrule"],
- tools: ["hoststubgen"],
- srcs: [
- ":framework-minus-apex-for-hoststubgen",
- ":ravenwood-framework-policies",
- ":ravenwood-standard-options",
- ":ravenwood-annotation-allowed-classes",
- ],
- out: [
- "ravenwood.jar",
- "hoststubgen_framework-minus-apex.log",
- ],
-}
-
-framework_minus_apex_cmd = "$(location hoststubgen) " +
- "@$(location :ravenwood-standard-options) " +
- "--debug-log $(location hoststubgen_framework-minus-apex.log) " +
- "--out-jar $(location ravenwood.jar) " +
- "--in-jar $(location :framework-minus-apex-for-hoststubgen) " +
- "--policy-override-file $(location :ravenwood-framework-policies) " +
- "--annotation-allowed-classes-file $(location :ravenwood-annotation-allowed-classes) "
-
-java_genrule {
- name: "framework-minus-apex.ravenwood-base_X0",
- defaults: ["framework-minus-apex.ravenwood-base_defaults"],
- cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 0",
-}
-
-java_genrule {
- name: "framework-minus-apex.ravenwood-base_X1",
- defaults: ["framework-minus-apex.ravenwood-base_defaults"],
- cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 1",
-}
-
-java_genrule {
- name: "framework-minus-apex.ravenwood-base_X2",
- defaults: ["framework-minus-apex.ravenwood-base_defaults"],
- cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 2",
-}
-
-java_genrule {
- name: "framework-minus-apex.ravenwood-base_X3",
- defaults: ["framework-minus-apex.ravenwood-base_defaults"],
- cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 3",
-}
-
-java_genrule {
- name: "framework-minus-apex.ravenwood-base_X4",
- defaults: ["framework-minus-apex.ravenwood-base_defaults"],
- cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 4",
-}
-
-java_genrule {
- name: "framework-minus-apex.ravenwood-base_X5",
- defaults: ["framework-minus-apex.ravenwood-base_defaults"],
- cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 5",
-}
-
-java_genrule {
- name: "framework-minus-apex.ravenwood-base_X6",
- defaults: ["framework-minus-apex.ravenwood-base_defaults"],
- cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 6",
-}
-
-java_genrule {
- name: "framework-minus-apex.ravenwood-base_X7",
- defaults: ["framework-minus-apex.ravenwood-base_defaults"],
- cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 7",
-}
-
-java_genrule {
- name: "framework-minus-apex.ravenwood-base_X8",
- defaults: ["framework-minus-apex.ravenwood-base_defaults"],
- cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 8",
-}
-
-java_genrule {
- name: "framework-minus-apex.ravenwood-base_X9",
- defaults: ["framework-minus-apex.ravenwood-base_defaults"],
- cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 9",
-}
-
-// Build framework-minus-apex.ravenwood-base without sharding.
-// We extract the various dump files from this one, rather than the sharded ones, because
-// some dumps use the output from other classes (e.g. base classes) which may not be in the
-// same shard. Also some of the dump files ("apis") may be slow even when sharded, because
-// the output contains the information from all the input classes, rather than the output classes.
-// Not using sharding is fine for this module because it's only used for collecting the
-// dump / stats files, which don't have to happen regularly.
-java_genrule {
- name: "framework-minus-apex.ravenwood-base_all",
- defaults: ["framework-minus-apex.ravenwood-base_defaults"],
- cmd: framework_minus_apex_cmd +
- "--stats-file $(location hoststubgen_framework-minus-apex_stats.csv) " +
- "--supported-api-list-file $(location hoststubgen_framework-minus-apex_apis.csv) " +
-
- "--gen-keep-all-file $(location hoststubgen_framework-minus-apex_keep_all.txt) " +
- "--gen-input-dump-file $(location hoststubgen_framework-minus-apex_dump.txt) ",
-
- out: [
- "hoststubgen_framework-minus-apex_keep_all.txt",
- "hoststubgen_framework-minus-apex_dump.txt",
- "hoststubgen_framework-minus-apex_stats.csv",
- "hoststubgen_framework-minus-apex_apis.csv",
- ],
-}
-
-// Marge all the sharded jars
-java_genrule {
- name: "framework-minus-apex.ravenwood",
- defaults: ["ravenwood-internal-only-visibility-java"],
- cmd: "$(location merge_zips) $(out) $(in)",
- tools: ["merge_zips"],
- srcs: [
- ":framework-minus-apex.ravenwood-base_X0{ravenwood.jar}",
- ":framework-minus-apex.ravenwood-base_X1{ravenwood.jar}",
- ":framework-minus-apex.ravenwood-base_X2{ravenwood.jar}",
- ":framework-minus-apex.ravenwood-base_X3{ravenwood.jar}",
- ":framework-minus-apex.ravenwood-base_X4{ravenwood.jar}",
- ":framework-minus-apex.ravenwood-base_X5{ravenwood.jar}",
- ":framework-minus-apex.ravenwood-base_X6{ravenwood.jar}",
- ":framework-minus-apex.ravenwood-base_X7{ravenwood.jar}",
- ":framework-minus-apex.ravenwood-base_X8{ravenwood.jar}",
- ":framework-minus-apex.ravenwood-base_X9{ravenwood.jar}",
- ],
- out: [
- "framework-minus-apex.ravenwood.jar",
- ],
-}
+// "framework-minus-apex" and "all-updatable-modules-system-stubs" are not
+// visible publicly. We re-export them to Ravenwood in this file.
java_library {
- name: "services.core-for-hoststubgen",
- installable: false, // host only jar.
- static_libs: [
- "services.core",
- ],
- sdk_version: "core_platform",
- visibility: ["//visibility:private"],
-}
-
-java_genrule {
- name: "services.core.ravenwood-base",
- tools: ["hoststubgen"],
- cmd: "$(location hoststubgen) " +
- "@$(location :ravenwood-standard-options) " +
-
- "--debug-log $(location hoststubgen_services.core.log) " +
- "--stats-file $(location hoststubgen_services.core_stats.csv) " +
- "--supported-api-list-file $(location hoststubgen_services.core_apis.csv) " +
-
- "--out-jar $(location ravenwood.jar) " +
-
- "--gen-keep-all-file $(location hoststubgen_services.core_keep_all.txt) " +
- "--gen-input-dump-file $(location hoststubgen_services.core_dump.txt) " +
-
- "--in-jar $(location :services.core-for-hoststubgen) " +
- "--policy-override-file $(location :ravenwood-services-policies) " +
- "--annotation-allowed-classes-file $(location :ravenwood-annotation-allowed-classes) ",
- srcs: [
- ":services.core-for-hoststubgen",
- ":ravenwood-services-policies",
- ":ravenwood-standard-options",
- ":ravenwood-annotation-allowed-classes",
- ],
- out: [
- "ravenwood.jar",
-
- // Following files are created just as FYI.
- "hoststubgen_services.core_keep_all.txt",
- "hoststubgen_services.core_dump.txt",
-
- "hoststubgen_services.core.log",
- "hoststubgen_services.core_stats.csv",
- "hoststubgen_services.core_apis.csv",
- ],
- defaults: ["ravenwood-internal-only-visibility-genrule"],
-}
-
-java_genrule {
- name: "services.core.ravenwood",
- defaults: ["ravenwood-internal-only-visibility-genrule"],
- cmd: "cp $(in) $(out)",
- srcs: [
- ":services.core.ravenwood-base{ravenwood.jar}",
- ],
- out: [
- "services.core.ravenwood.jar",
- ],
-}
-
-// TODO(b/313930116) This jarjar is a bit slow. We should use hoststubgen for renaming,
-// but services.core.ravenwood has complex dependencies, so it'll take more than
-// just using hoststubgen "rename"s.
-java_library {
- name: "services.core.ravenwood-jarjar",
- defaults: ["ravenwood-internal-only-visibility-java"],
+ name: "framework-minus-apex-for-host",
installable: false,
- static_libs: [
- "services.core.ravenwood",
- ],
- jarjar_rules: ":ravenwood-services-jarjar-rules",
+ static_libs: ["framework-minus-apex"],
+ visibility: ["//frameworks/base/ravenwood"],
}
-// Jars in "ravenwood-runtime" are set to the classpath, sorted alphabetically.
-// Rename some of the dependencies to make sure they're included in the intended order.
java_library {
- name: "100-framework-minus-apex.ravenwood",
- defaults: ["ravenwood-internal-only-visibility-java"],
- static_libs: [
- "framework-minus-apex.ravenwood",
- ],
- sdk_version: "core_platform",
- // See b/313930116. Jarjar is too slow on this jar. We use HostStubGen to do the rename.
- // jarjar_rules: ":ravenwood-framework-jarjar-rules",
-}
-
-java_genrule {
- // Use 200 to make sure it comes before the mainline stub ("all-updatable...").
- name: "200-kxml2-android",
- defaults: ["ravenwood-internal-only-visibility-genrule"],
- cmd: "cp $(in) $(out)",
- srcs: [":kxml2-android"],
- out: ["200-kxml2-android.jar"],
-}
-
-java_genrule {
- name: "z00-all-updatable-modules-system-stubs",
- defaults: ["ravenwood-internal-only-visibility-genrule"],
- cmd: "cp $(in) $(out)",
- srcs: [":all-updatable-modules-system-stubs"],
- out: ["z00-all-updatable-modules-system-stubs.jar"],
+ name: "all-updatable-modules-system-stubs-for-host",
+ installable: false,
+ static_libs: ["all-updatable-modules-system-stubs"],
+ visibility: ["//frameworks/base/ravenwood"],
}
diff --git a/core/java/android/app/AppOps.md b/core/java/android/app/AppOps.md
index 7b11a03..535d62c 100644
--- a/core/java/android/app/AppOps.md
+++ b/core/java/android/app/AppOps.md
@@ -119,20 +119,20 @@
In addition to proc state, the `AppOpsService` also receives process capability update from the
`ActivityManagerService`. Proc capability specifies what while-in-use(`MODE_FOREGROUND`) operations
the proc is allowed to perform in its current proc state. There are three proc capabilities
- defined so far:
+ defined so far:
`PROCESS_CAPABILITY_FOREGROUND_LOCATION`, `PROCESS_CAPABILITY_FOREGROUND_CAMERA` and
`PROCESS_CAPABILITY_FOREGROUND_MICROPHONE`, they correspond to the while-in-use operation of
location, camera and microphone (microphone is `RECORD_AUDIO`).
In `ActivityManagerService`, `PROCESS_STATE_TOP` and `PROCESS_STATE_PERSISTENT` have all
three capabilities, `PROCESS_STATE_FOREGROUND_SERVICE` has capabilities defined by
- `foregroundServiceType` that is specified in foreground service's manifest file. A client process
+ `foregroundServiceType` that is specified in foreground service's manifest file. A client process
can pass its capabilities to service using `BIND_INCLUDE_CAPABILITIES` flag.
The proc state and capability are used for two use cases: Firstly, Tracking remembers the proc state
for each tracked event. Secondly, `noteOp`/`checkOp` calls for app-op that are set to
`MODE_FOREGROUND` are translated using the `AppOpsService.UidState.evalMode` method into
- `MODE_ALLOWED` when the app has the capability and `MODE_IGNORED` when the app does not have the
+ `MODE_ALLOWED` when the app has the capability and `MODE_IGNORED` when the app does not have the
capability. `checkOpRaw` calls are not affected.
The current proc state and capability for an app can be read from `dumpsys appops`.
@@ -284,7 +284,7 @@
##### Self data accesses
This is similar to the [synchronous data access](#synchronous-data-accesses) case only that the data
-provider and client are in the same process. In this case Android's RPC code is no involved and
+provider and client are in the same process. In this case Android's RPC code is not involved and
`AppOpsManager.noteOp` directly triggers `OnOpNotedCallback.onSelfNoted`. This should be a uncommon
case as it is uncommon for an app to provide data, esp. to itself.
diff --git a/core/java/com/android/internal/util/MemInfoReader.java b/core/java/com/android/internal/util/MemInfoReader.java
index 0c5c853..d34bca6 100644
--- a/core/java/com/android/internal/util/MemInfoReader.java
+++ b/core/java/com/android/internal/util/MemInfoReader.java
@@ -88,6 +88,13 @@
}
/**
+ * Amount of RAM that used by shared memory (shmem) and tmpfs
+ */
+ public long getShmemSizeKb() {
+ return mInfos[Debug.MEMINFO_SHMEM];
+ }
+
+ /**
* Amount of RAM that the kernel is being used for caches, not counting caches
* that are mapped in to processes.
*/
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index c71f9bd..e4c56a6 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -155,6 +155,7 @@
<protected-broadcast android:name="android.bluetooth.intent.DISCOVERABLE_TIMEOUT" />
<protected-broadcast android:name="android.bluetooth.action.AUTO_ON_STATE_CHANGED" />
+ <protected-broadcast android:name="android.bluetooth.action.CONNECTION_STATE_CHANGED" />
<protected-broadcast android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
<protected-broadcast android:name="android.bluetooth.adapter.action.SCAN_MODE_CHANGED" />
<protected-broadcast android:name="android.bluetooth.adapter.action.DISCOVERY_STARTED" />
@@ -240,6 +241,8 @@
<protected-broadcast
android:name="android.bluetooth.avrcp-controller.profile.action.FOLDER_LIST" />
<protected-broadcast
+ android:name="android.bluetooth.avrcp-controller.profile.action.PLAYER_SETTING" />
+ <protected-broadcast
android:name="android.bluetooth.avrcp-controller.profile.action.TRACK_EVENT" />
<protected-broadcast
android:name="android.bluetooth.input.profile.action.CONNECTION_STATE_CHANGED" />
@@ -266,6 +269,7 @@
<protected-broadcast
android:name="android.bluetooth.pan.profile.action.CONNECTION_STATE_CHANGED" />
<protected-broadcast android:name="android.bluetooth.action.HAP_CONNECTION_STATE_CHANGED" />
+ <protected-broadcast android:name="android.bluetooth.action.HAP_DEVICE_AVAILABLE" />
<protected-broadcast android:name="android.bluetooth.action.LE_AUDIO_CONNECTION_STATE_CHANGED" />
<protected-broadcast android:name="android.bluetooth.action.LE_AUDIO_ACTIVE_DEVICE_CHANGED" />
<protected-broadcast android:name="android.bluetooth.action.LE_AUDIO_CONF_CHANGED" />
diff --git a/nfc/api/system-current.txt b/nfc/api/system-current.txt
index 4428ade..24e14e6 100644
--- a/nfc/api/system-current.txt
+++ b/nfc/api/system-current.txt
@@ -63,7 +63,7 @@
method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean isAutoChangeEnabled();
method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public boolean isTagPresent();
method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void maybeTriggerFirmwareUpdate();
- method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void overwriteRoutingTable(int, int, int);
+ method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void overwriteRoutingTable(int, int, int, int);
method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void pausePolling(int);
method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void registerCallback(@NonNull java.util.concurrent.Executor, @NonNull android.nfc.NfcOemExtension.Callback);
method @FlaggedApi("android.nfc.nfc_oem_extension") @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void resumePolling();
diff --git a/nfc/java/android/nfc/INfcCardEmulation.aidl b/nfc/java/android/nfc/INfcCardEmulation.aidl
index 1eae3c6..8535e4a 100644
--- a/nfc/java/android/nfc/INfcCardEmulation.aidl
+++ b/nfc/java/android/nfc/INfcCardEmulation.aidl
@@ -54,5 +54,5 @@
void setAutoChangeStatus(boolean state);
boolean isAutoChangeEnabled();
List<String> getRoutingStatus();
- void overwriteRoutingTable(int userHandle, String emptyAid, String protocol, String tech);
+ void overwriteRoutingTable(int userHandle, String emptyAid, String protocol, String tech, String sc);
}
diff --git a/nfc/java/android/nfc/NfcOemExtension.java b/nfc/java/android/nfc/NfcOemExtension.java
index fb63b5c..bc410c7 100644
--- a/nfc/java/android/nfc/NfcOemExtension.java
+++ b/nfc/java/android/nfc/NfcOemExtension.java
@@ -647,24 +647,29 @@
* {@link ProtocolAndTechnologyRoute}
* @param emptyAid Zero-length AID route destination, where the possible inputs are defined in
* {@link ProtocolAndTechnologyRoute}
+ * @param systemCode System Code route destination, where the possible inputs are defined in
+ * {@link ProtocolAndTechnologyRoute}
*/
@RequiresPermission(Manifest.permission.WRITE_SECURE_SETTINGS)
@FlaggedApi(Flags.FLAG_NFC_OEM_EXTENSION)
public void overwriteRoutingTable(
@CardEmulation.ProtocolAndTechnologyRoute int protocol,
@CardEmulation.ProtocolAndTechnologyRoute int technology,
- @CardEmulation.ProtocolAndTechnologyRoute int emptyAid) {
+ @CardEmulation.ProtocolAndTechnologyRoute int emptyAid,
+ @CardEmulation.ProtocolAndTechnologyRoute int systemCode) {
String protocolRoute = routeIntToString(protocol);
String technologyRoute = routeIntToString(technology);
String emptyAidRoute = routeIntToString(emptyAid);
+ String systemCodeRoute = routeIntToString(systemCode);
NfcAdapter.callService(() ->
NfcAdapter.sCardEmulationService.overwriteRoutingTable(
mContext.getUser().getIdentifier(),
emptyAidRoute,
protocolRoute,
- technologyRoute
+ technologyRoute,
+ systemCodeRoute
));
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/data/repository/ConnectivityRepository.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/data/repository/ConnectivityRepository.kt
index 1a55f7d..e30286d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/data/repository/ConnectivityRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/data/repository/ConnectivityRepository.kt
@@ -26,6 +26,7 @@
import android.net.NetworkCapabilities.TRANSPORT_ETHERNET
import android.net.NetworkCapabilities.TRANSPORT_WIFI
import android.net.vcn.VcnTransportInfo
+import android.net.vcn.VcnUtils
import android.net.wifi.WifiInfo
import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
import androidx.annotation.ArrayRes
@@ -160,7 +161,9 @@
defaultNetworkCapabilities
.map { networkCapabilities ->
networkCapabilities?.run {
- val subId = (transportInfo as? VcnTransportInfo)?.subId
+ val subId =
+ VcnUtils.getSubIdFromVcnCaps(connectivityManager, networkCapabilities)
+
// Never return an INVALID_SUBSCRIPTION_ID (-1)
if (subId != INVALID_SUBSCRIPTION_ID) {
subId
@@ -244,9 +247,9 @@
* info.
*/
fun NetworkCapabilities.getMainOrUnderlyingWifiInfo(
- connectivityManager: ConnectivityManager,
+ connectivityManager: ConnectivityManager
): WifiInfo? {
- val mainWifiInfo = this.getMainWifiInfo()
+ val mainWifiInfo = this.getMainWifiInfo(connectivityManager)
if (mainWifiInfo != null) {
return mainWifiInfo
}
@@ -260,7 +263,9 @@
// eventually traced to a wifi or carrier merged connection. So, check those underlying
// networks for possible wifi information as well. See b/225902574.
return this.underlyingNetworks?.firstNotNullOfOrNull { underlyingNetwork ->
- connectivityManager.getNetworkCapabilities(underlyingNetwork)?.getMainWifiInfo()
+ connectivityManager
+ .getNetworkCapabilities(underlyingNetwork)
+ ?.getMainWifiInfo(connectivityManager)
}
}
@@ -268,7 +273,9 @@
* Checks the network capabilities for wifi info, but does *not* check the underlying
* networks. See [getMainOrUnderlyingWifiInfo].
*/
- private fun NetworkCapabilities.getMainWifiInfo(): WifiInfo? {
+ private fun NetworkCapabilities.getMainWifiInfo(
+ connectivityManager: ConnectivityManager
+ ): WifiInfo? {
// Wifi info can either come from a WIFI Transport, or from a CELLULAR transport for
// virtual networks like VCN.
val canHaveWifiInfo =
@@ -282,7 +289,7 @@
// [com.android.settingslib.Utils.tryGetWifiInfoForVcn]. It's copied instead of
// re-used because it makes the logic here clearer, and because the method will be
// removed once this pipeline is fully launched.
- is VcnTransportInfo -> currentTransportInfo.wifiInfo
+ is VcnTransportInfo -> VcnUtils.getWifiInfoFromVcnCaps(connectivityManager, this)
is WifiInfo -> currentTransportInfo
else -> null
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerWifiTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerWifiTest.java
index 6febb91..7a579ba 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerWifiTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerWifiTest.java
@@ -58,7 +58,7 @@
private static final int MIN_RSSI = -100;
private static final int MAX_RSSI = -55;
private WifiInfo mWifiInfo = mock(WifiInfo.class);
- private VcnTransportInfo mVcnTransportInfo = mock(VcnTransportInfo.class);
+ private VcnTransportInfo mVcnTransportInfo = new VcnTransportInfo.Builder().build();
@Before
public void setUp() throws Exception {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt
index 76982ae..00b6316 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt
@@ -140,6 +140,7 @@
private val wifiLogBuffer = LogBuffer("wifi", maxSize = 100, logcatEchoTracker = mock())
private val wifiPickerTrackerCallback =
argumentCaptor<WifiPickerTracker.WifiPickerTrackerCallback>()
+ private val vcnTransportInfo = VcnTransportInfo.Builder().build()
private val testDispatcher = StandardTestDispatcher()
private val testScope = TestScope(testDispatcher)
@@ -987,6 +988,18 @@
assertThat(latest).isTrue()
}
+ private fun newWifiNetwork(wifiInfo: WifiInfo): Network {
+ val network = mock<Network>()
+ val capabilities =
+ mock<NetworkCapabilities>().also {
+ whenever(it.hasTransport(TRANSPORT_WIFI)).thenReturn(true)
+ whenever(it.transportInfo).thenReturn(wifiInfo)
+ }
+ whenever(connectivityManager.getNetworkCapabilities(network)).thenReturn(capabilities)
+
+ return network
+ }
+
/** Regression test for b/272586234. */
@Test
fun hasCarrierMergedConnection_carrierMergedViaWifiWithVcnTransport_isTrue() =
@@ -996,10 +1009,12 @@
whenever(this.isCarrierMerged).thenReturn(true)
whenever(this.isPrimary).thenReturn(true)
}
+ val underlyingWifi = newWifiNetwork(carrierMergedInfo)
val caps =
mock<NetworkCapabilities>().also {
whenever(it.hasTransport(TRANSPORT_WIFI)).thenReturn(true)
- whenever(it.transportInfo).thenReturn(VcnTransportInfo(carrierMergedInfo))
+ whenever(it.transportInfo).thenReturn(vcnTransportInfo)
+ whenever(it.underlyingNetworks).thenReturn(listOf(underlyingWifi))
}
val latest by collectLastValue(underTest.hasCarrierMergedConnection)
@@ -1018,10 +1033,12 @@
whenever(this.isCarrierMerged).thenReturn(true)
whenever(this.isPrimary).thenReturn(true)
}
+ val underlyingWifi = newWifiNetwork(carrierMergedInfo)
val caps =
mock<NetworkCapabilities>().also {
whenever(it.hasTransport(TRANSPORT_CELLULAR)).thenReturn(true)
- whenever(it.transportInfo).thenReturn(VcnTransportInfo(carrierMergedInfo))
+ whenever(it.transportInfo).thenReturn(vcnTransportInfo)
+ whenever(it.underlyingNetworks).thenReturn(listOf(underlyingWifi))
}
val latest by collectLastValue(underTest.hasCarrierMergedConnection)
@@ -1078,10 +1095,15 @@
whenever(this.isCarrierMerged).thenReturn(true)
whenever(this.isPrimary).thenReturn(true)
}
+
+ // The Wifi network that is under the VCN network
+ val physicalWifiNetwork = newWifiNetwork(carrierMergedInfo)
+
val underlyingCapabilities =
mock<NetworkCapabilities>().also {
whenever(it.hasTransport(TRANSPORT_CELLULAR)).thenReturn(true)
- whenever(it.transportInfo).thenReturn(VcnTransportInfo(carrierMergedInfo))
+ whenever(it.transportInfo).thenReturn(vcnTransportInfo)
+ whenever(it.underlyingNetworks).thenReturn(listOf(physicalWifiNetwork))
}
whenever(connectivityManager.getNetworkCapabilities(underlyingCarrierMergedNetwork))
.thenReturn(underlyingCapabilities)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/shared/data/repository/ConnectivityRepositoryImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/shared/data/repository/ConnectivityRepositoryImplTest.kt
index fa4e91b..479a05b 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/shared/data/repository/ConnectivityRepositoryImplTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/shared/data/repository/ConnectivityRepositoryImplTest.kt
@@ -22,6 +22,7 @@
import android.net.NetworkCapabilities.TRANSPORT_CELLULAR
import android.net.NetworkCapabilities.TRANSPORT_ETHERNET
import android.net.NetworkCapabilities.TRANSPORT_WIFI
+import android.net.TelephonyNetworkSpecifier
import android.net.vcn.VcnTransportInfo
import android.net.wifi.WifiInfo
import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
@@ -68,6 +69,8 @@
private lateinit var testScope: TestScope
@Mock private lateinit var tunerService: TunerService
+ private val vcnTransportInfo = VcnTransportInfo.Builder().build()
+
@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
@@ -376,6 +379,30 @@
job.cancel()
}
+ private fun newWifiNetwork(wifiInfo: WifiInfo): Network {
+ val network = mock<Network>()
+ val capabilities =
+ mock<NetworkCapabilities>().also {
+ whenever(it.hasTransport(TRANSPORT_WIFI)).thenReturn(true)
+ whenever(it.transportInfo).thenReturn(wifiInfo)
+ }
+ whenever(connectivityManager.getNetworkCapabilities(network)).thenReturn(capabilities)
+
+ return network
+ }
+
+ private fun newCellNetwork(subId: Int): Network {
+ val network = mock<Network>()
+ val capabilities =
+ mock<NetworkCapabilities>().also {
+ whenever(it.hasTransport(TRANSPORT_CELLULAR)).thenReturn(true)
+ whenever(it.networkSpecifier).thenReturn(TelephonyNetworkSpecifier(subId))
+ }
+ whenever(connectivityManager.getNetworkCapabilities(network)).thenReturn(capabilities)
+
+ return network
+ }
+
@Test
fun defaultConnections_carrierMergedViaWifiWithVcnTransport_wifiAndCarrierMergedDefault() =
testScope.runTest {
@@ -384,10 +411,12 @@
val carrierMergedInfo =
mock<WifiInfo>().apply { whenever(this.isCarrierMerged).thenReturn(true) }
+ val underlyingWifi = newWifiNetwork(carrierMergedInfo)
val capabilities =
mock<NetworkCapabilities>().also {
whenever(it.hasTransport(TRANSPORT_WIFI)).thenReturn(true)
- whenever(it.transportInfo).thenReturn(VcnTransportInfo(carrierMergedInfo))
+ whenever(it.transportInfo).thenReturn(vcnTransportInfo)
+ whenever(it.underlyingNetworks).thenReturn(listOf(underlyingWifi))
whenever(it.hasTransport(TRANSPORT_CELLULAR)).thenReturn(false)
whenever(it.hasTransport(TRANSPORT_ETHERNET)).thenReturn(false)
}
@@ -409,10 +438,12 @@
val carrierMergedInfo =
mock<WifiInfo>().apply { whenever(this.isCarrierMerged).thenReturn(true) }
+ val underlyingWifi = newWifiNetwork(carrierMergedInfo)
val capabilities =
mock<NetworkCapabilities>().also {
whenever(it.hasTransport(TRANSPORT_CELLULAR)).thenReturn(true)
- whenever(it.transportInfo).thenReturn(VcnTransportInfo(carrierMergedInfo))
+ whenever(it.transportInfo).thenReturn(vcnTransportInfo)
+ whenever(it.underlyingNetworks).thenReturn(listOf(underlyingWifi))
whenever(it.hasTransport(TRANSPORT_ETHERNET)).thenReturn(false)
whenever(it.hasTransport(TRANSPORT_WIFI)).thenReturn(false)
}
@@ -572,10 +603,12 @@
val underlyingCarrierMergedNetwork = mock<Network>()
val carrierMergedInfo =
mock<WifiInfo>().apply { whenever(this.isCarrierMerged).thenReturn(true) }
+ val underlyingWifi = newWifiNetwork(carrierMergedInfo)
val underlyingCapabilities =
mock<NetworkCapabilities>().also {
whenever(it.hasTransport(TRANSPORT_CELLULAR)).thenReturn(true)
- whenever(it.transportInfo).thenReturn(VcnTransportInfo(carrierMergedInfo))
+ whenever(it.transportInfo).thenReturn(vcnTransportInfo)
+ whenever(it.underlyingNetworks).thenReturn(listOf(underlyingWifi))
}
whenever(connectivityManager.getNetworkCapabilities(underlyingCarrierMergedNetwork))
.thenReturn(underlyingCapabilities)
@@ -664,7 +697,7 @@
@Test
fun vcnSubId_tracksVcnTransportInfo() =
testScope.runTest {
- val vcnInfo = VcnTransportInfo(SUB_1_ID)
+ val underlyingCell = newCellNetwork(SUB_1_ID)
var latest: Int? = null
val job = underTest.vcnSubId.onEach { latest = it }.launchIn(this)
@@ -672,7 +705,8 @@
val capabilities =
mock<NetworkCapabilities>().also {
whenever(it.hasTransport(TRANSPORT_CELLULAR)).thenReturn(true)
- whenever(it.transportInfo).thenReturn(vcnInfo)
+ whenever(it.transportInfo).thenReturn(vcnTransportInfo)
+ whenever(it.underlyingNetworks).thenReturn(listOf(underlyingCell))
}
getDefaultNetworkCallback().onCapabilitiesChanged(NETWORK, capabilities)
@@ -684,7 +718,7 @@
@Test
fun vcnSubId_filersOutInvalid() =
testScope.runTest {
- val vcnInfo = VcnTransportInfo(INVALID_SUBSCRIPTION_ID)
+ val underlyingCell = newCellNetwork(INVALID_SUBSCRIPTION_ID)
var latest: Int? = null
val job = underTest.vcnSubId.onEach { latest = it }.launchIn(this)
@@ -692,7 +726,8 @@
val capabilities =
mock<NetworkCapabilities>().also {
whenever(it.hasTransport(TRANSPORT_CELLULAR)).thenReturn(true)
- whenever(it.transportInfo).thenReturn(vcnInfo)
+ whenever(it.transportInfo).thenReturn(vcnTransportInfo)
+ whenever(it.underlyingNetworks).thenReturn(listOf(underlyingCell))
}
getDefaultNetworkCallback().onCapabilitiesChanged(NETWORK, capabilities)
@@ -729,11 +764,12 @@
val job = underTest.vcnSubId.onEach { latest = it }.launchIn(this)
val wifiInfo = mock<WifiInfo>()
- val vcnInfo = VcnTransportInfo(wifiInfo)
+ val underlyingWifi = newWifiNetwork(wifiInfo)
val capabilities =
mock<NetworkCapabilities>().also {
whenever(it.hasTransport(TRANSPORT_CELLULAR)).thenReturn(true)
- whenever(it.transportInfo).thenReturn(vcnInfo)
+ whenever(it.transportInfo).thenReturn(vcnTransportInfo)
+ whenever(it.underlyingNetworks).thenReturn(listOf(underlyingWifi))
}
getDefaultNetworkCallback().onCapabilitiesChanged(NETWORK, capabilities)
@@ -749,14 +785,15 @@
val job = underTest.vcnSubId.onEach { latest = it }.launchIn(this)
val wifiInfo = mock<WifiInfo>()
- val wifiVcnInfo = VcnTransportInfo(wifiInfo)
- val sub1VcnInfo = VcnTransportInfo(SUB_1_ID)
- val sub2VcnInfo = VcnTransportInfo(SUB_2_ID)
+ val underlyingWifi = newWifiNetwork(wifiInfo)
+ val underlyingCell1 = newCellNetwork(SUB_1_ID)
+ val underlyingCell2 = newCellNetwork(SUB_2_ID)
val capabilities =
mock<NetworkCapabilities>().also {
whenever(it.hasTransport(TRANSPORT_WIFI)).thenReturn(true)
- whenever(it.transportInfo).thenReturn(wifiVcnInfo)
+ whenever(it.transportInfo).thenReturn(vcnTransportInfo)
+ whenever(it.underlyingNetworks).thenReturn(listOf(underlyingWifi))
}
// WIFI VCN info
@@ -766,14 +803,16 @@
// Cellular VCN info with subId 1
whenever(capabilities.hasTransport(eq(TRANSPORT_CELLULAR))).thenReturn(true)
- whenever(capabilities.transportInfo).thenReturn(sub1VcnInfo)
+ whenever(capabilities.transportInfo).thenReturn(vcnTransportInfo)
+ whenever(capabilities.underlyingNetworks).thenReturn(listOf(underlyingCell1))
getDefaultNetworkCallback().onCapabilitiesChanged(NETWORK, capabilities)
assertThat(latest).isEqualTo(SUB_1_ID)
// Cellular VCN info with subId 2
- whenever(capabilities.transportInfo).thenReturn(sub2VcnInfo)
+ whenever(capabilities.transportInfo).thenReturn(vcnTransportInfo)
+ whenever(capabilities.underlyingNetworks).thenReturn(listOf(underlyingCell2))
getDefaultNetworkCallback().onCapabilitiesChanged(NETWORK, capabilities)
@@ -806,11 +845,12 @@
@Test
fun getMainOrUnderlyingWifiInfo_vcnWithWifi_hasInfo() {
val wifiInfo = mock<WifiInfo>()
- val vcnInfo = VcnTransportInfo(wifiInfo)
+ val underlyingWifi = newWifiNetwork(wifiInfo)
val capabilities =
mock<NetworkCapabilities>().also {
whenever(it.hasTransport(TRANSPORT_WIFI)).thenReturn(true)
- whenever(it.transportInfo).thenReturn(vcnInfo)
+ whenever(it.transportInfo).thenReturn(vcnTransportInfo)
+ whenever(it.underlyingNetworks).thenReturn(listOf(underlyingWifi))
}
val result = capabilities.getMainOrUnderlyingWifiInfo(connectivityManager)
@@ -889,11 +929,15 @@
fun getMainOrUnderlyingWifiInfo_cellular_underlyingVcnWithWifi_hasInfo() {
val wifiInfo = mock<WifiInfo>()
val underlyingNetwork = mock<Network>()
- val underlyingVcnInfo = VcnTransportInfo(wifiInfo)
+
+ // The Wifi network that is under the VCN network
+ val physicalWifiNetwork = newWifiNetwork(wifiInfo)
+
val underlyingWifiCapabilities =
mock<NetworkCapabilities>().also {
whenever(it.hasTransport(TRANSPORT_WIFI)).thenReturn(true)
- whenever(it.transportInfo).thenReturn(underlyingVcnInfo)
+ whenever(it.transportInfo).thenReturn(vcnTransportInfo)
+ whenever(it.underlyingNetworks).thenReturn(listOf(physicalWifiNetwork))
}
whenever(connectivityManager.getNetworkCapabilities(underlyingNetwork))
.thenReturn(underlyingWifiCapabilities)
@@ -915,11 +959,15 @@
@Test
fun getMainOrUnderlyingWifiInfo_notCellular_underlyingVcnWithWifi_noInfo() {
val underlyingNetwork = mock<Network>()
- val underlyingVcnInfo = VcnTransportInfo(mock<WifiInfo>())
+
+ // The Wifi network that is under the VCN network
+ val physicalWifiNetwork = newWifiNetwork(mock<WifiInfo>())
+
val underlyingWifiCapabilities =
mock<NetworkCapabilities>().also {
whenever(it.hasTransport(TRANSPORT_WIFI)).thenReturn(true)
- whenever(it.transportInfo).thenReturn(underlyingVcnInfo)
+ whenever(it.transportInfo).thenReturn(vcnTransportInfo)
+ whenever(it.underlyingNetworks).thenReturn(listOf(physicalWifiNetwork))
}
whenever(connectivityManager.getNetworkCapabilities(underlyingNetwork))
.thenReturn(underlyingWifiCapabilities)
@@ -945,10 +993,15 @@
val underlyingCarrierMergedNetwork = mock<Network>()
val carrierMergedInfo =
mock<WifiInfo>().apply { whenever(this.isCarrierMerged).thenReturn(true) }
+
+ // The Wifi network that is under the VCN network
+ val physicalWifiNetwork = newWifiNetwork(carrierMergedInfo)
+
val underlyingCapabilities =
mock<NetworkCapabilities>().also {
whenever(it.hasTransport(TRANSPORT_CELLULAR)).thenReturn(true)
- whenever(it.transportInfo).thenReturn(VcnTransportInfo(carrierMergedInfo))
+ whenever(it.transportInfo).thenReturn(vcnTransportInfo)
+ whenever(it.underlyingNetworks).thenReturn(listOf(physicalWifiNetwork))
}
whenever(connectivityManager.getNetworkCapabilities(underlyingCarrierMergedNetwork))
.thenReturn(underlyingCapabilities)
diff --git a/ravenwood/Android.bp b/ravenwood/Android.bp
index 9629a87..8896d77 100644
--- a/ravenwood/Android.bp
+++ b/ravenwood/Android.bp
@@ -12,11 +12,19 @@
}
filegroup {
+ name: "ravenwood-common-policies",
+ srcs: [
+ "texts/ravenwood-common-policies.txt",
+ ],
+ visibility: ["//visibility:private"],
+}
+
+filegroup {
name: "ravenwood-services-policies",
srcs: [
"texts/ravenwood-services-policies.txt",
],
- visibility: ["//visibility:public"],
+ visibility: ["//visibility:private"],
}
filegroup {
@@ -24,7 +32,7 @@
srcs: [
"texts/ravenwood-framework-policies.txt",
],
- visibility: ["//visibility:public"],
+ visibility: ["//visibility:private"],
}
filegroup {
@@ -32,7 +40,7 @@
srcs: [
"texts/ravenwood-standard-options.txt",
],
- visibility: ["//visibility:public"],
+ visibility: ["//visibility:private"],
}
filegroup {
@@ -40,7 +48,7 @@
srcs: [
"texts/ravenwood-annotation-allowed-classes.txt",
],
- visibility: ["//visibility:public"],
+ visibility: ["//visibility:private"],
}
// This and the next module contain the same classes with different implementations.
@@ -337,6 +345,30 @@
],
}
+// JARs in "ravenwood-runtime" are set to the classpath, sorted alphabetically.
+// Rename some of the dependencies to make sure they're included in the intended order.
+
+java_library {
+ name: "100-framework-minus-apex.ravenwood",
+ installable: false,
+ static_libs: ["framework-minus-apex.ravenwood"],
+ visibility: ["//visibility:private"],
+}
+
+java_library {
+ name: "200-kxml2-android",
+ installable: false,
+ static_libs: ["kxml2-android"],
+ visibility: ["//visibility:private"],
+}
+
+java_library {
+ name: "z00-all-updatable-modules-system-stubs",
+ installable: false,
+ static_libs: ["all-updatable-modules-system-stubs-for-host"],
+ visibility: ["//visibility:private"],
+}
+
android_ravenwood_libgroup {
name: "ravenwood-runtime",
data: [
@@ -395,3 +427,7 @@
"inline-mockito-ravenwood-prebuilt",
],
}
+
+build = [
+ "Framework.bp",
+]
diff --git a/ravenwood/Framework.bp b/ravenwood/Framework.bp
new file mode 100644
index 0000000..5cb1479
--- /dev/null
+++ b/ravenwood/Framework.bp
@@ -0,0 +1,292 @@
+// Copyright (C) 2024 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.
+
+// This file hosts all the genrule and module definitions for all Android specific
+// code that needs further post-processing by hoststubgen to support Ravenwood.
+
+/////////////////////////
+// framework-minus-apex
+/////////////////////////
+
+// Process framework-minus-apex with hoststubgen for Ravenwood.
+// This step takes several tens of seconds, so we manually shard it to multiple modules.
+// All the copies have to be kept in sync.
+// TODO: Do the sharding better, either by making hostsubgen support sharding natively, or
+// making a better build rule.
+
+genrule_defaults {
+ name: "framework-minus-apex.ravenwood-base_defaults",
+ tools: ["hoststubgen"],
+ srcs: [
+ ":framework-minus-apex-for-host",
+ ":ravenwood-common-policies",
+ ":ravenwood-framework-policies",
+ ":ravenwood-standard-options",
+ ":ravenwood-annotation-allowed-classes",
+ ],
+ out: [
+ "ravenwood.jar",
+ "hoststubgen_framework-minus-apex.log",
+ ],
+ visibility: ["//visibility:private"],
+}
+
+framework_minus_apex_cmd = "$(location hoststubgen) " +
+ "@$(location :ravenwood-standard-options) " +
+ "--debug-log $(location hoststubgen_framework-minus-apex.log) " +
+ "--out-jar $(location ravenwood.jar) " +
+ "--in-jar $(location :framework-minus-apex-for-host) " +
+ "--policy-override-file $(location :ravenwood-common-policies) " +
+ "--policy-override-file $(location :ravenwood-framework-policies) " +
+ "--annotation-allowed-classes-file $(location :ravenwood-annotation-allowed-classes) "
+
+java_genrule {
+ name: "framework-minus-apex.ravenwood-base_X0",
+ defaults: ["framework-minus-apex.ravenwood-base_defaults"],
+ cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 0",
+}
+
+java_genrule {
+ name: "framework-minus-apex.ravenwood-base_X1",
+ defaults: ["framework-minus-apex.ravenwood-base_defaults"],
+ cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 1",
+}
+
+java_genrule {
+ name: "framework-minus-apex.ravenwood-base_X2",
+ defaults: ["framework-minus-apex.ravenwood-base_defaults"],
+ cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 2",
+}
+
+java_genrule {
+ name: "framework-minus-apex.ravenwood-base_X3",
+ defaults: ["framework-minus-apex.ravenwood-base_defaults"],
+ cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 3",
+}
+
+java_genrule {
+ name: "framework-minus-apex.ravenwood-base_X4",
+ defaults: ["framework-minus-apex.ravenwood-base_defaults"],
+ cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 4",
+}
+
+java_genrule {
+ name: "framework-minus-apex.ravenwood-base_X5",
+ defaults: ["framework-minus-apex.ravenwood-base_defaults"],
+ cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 5",
+}
+
+java_genrule {
+ name: "framework-minus-apex.ravenwood-base_X6",
+ defaults: ["framework-minus-apex.ravenwood-base_defaults"],
+ cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 6",
+}
+
+java_genrule {
+ name: "framework-minus-apex.ravenwood-base_X7",
+ defaults: ["framework-minus-apex.ravenwood-base_defaults"],
+ cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 7",
+}
+
+java_genrule {
+ name: "framework-minus-apex.ravenwood-base_X8",
+ defaults: ["framework-minus-apex.ravenwood-base_defaults"],
+ cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 8",
+}
+
+java_genrule {
+ name: "framework-minus-apex.ravenwood-base_X9",
+ defaults: ["framework-minus-apex.ravenwood-base_defaults"],
+ cmd: framework_minus_apex_cmd + " --num-shards 10 --shard-index 9",
+}
+
+// Build framework-minus-apex.ravenwood-base without sharding.
+// We extract the various dump files from this one, rather than the sharded ones, because
+// some dumps use the output from other classes (e.g. base classes) which may not be in the
+// same shard. Also some of the dump files ("apis") may be slow even when sharded, because
+// the output contains the information from all the input classes, rather than the output classes.
+// Not using sharding is fine for this module because it's only used for collecting the
+// dump / stats files, which don't have to happen regularly.
+java_genrule {
+ name: "framework-minus-apex.ravenwood-base_all",
+ defaults: ["framework-minus-apex.ravenwood-base_defaults"],
+ cmd: framework_minus_apex_cmd +
+ "--stats-file $(location hoststubgen_framework-minus-apex_stats.csv) " +
+ "--supported-api-list-file $(location hoststubgen_framework-minus-apex_apis.csv) " +
+
+ "--gen-keep-all-file $(location hoststubgen_framework-minus-apex_keep_all.txt) " +
+ "--gen-input-dump-file $(location hoststubgen_framework-minus-apex_dump.txt) ",
+
+ out: [
+ "hoststubgen_framework-minus-apex_keep_all.txt",
+ "hoststubgen_framework-minus-apex_dump.txt",
+ "hoststubgen_framework-minus-apex_stats.csv",
+ "hoststubgen_framework-minus-apex_apis.csv",
+ ],
+}
+
+// Marge all the sharded jars
+java_genrule {
+ name: "framework-minus-apex.ravenwood",
+ defaults: ["ravenwood-internal-only-visibility-java"],
+ cmd: "$(location merge_zips) $(out) $(in)",
+ tools: ["merge_zips"],
+ srcs: [
+ ":framework-minus-apex.ravenwood-base_X0{ravenwood.jar}",
+ ":framework-minus-apex.ravenwood-base_X1{ravenwood.jar}",
+ ":framework-minus-apex.ravenwood-base_X2{ravenwood.jar}",
+ ":framework-minus-apex.ravenwood-base_X3{ravenwood.jar}",
+ ":framework-minus-apex.ravenwood-base_X4{ravenwood.jar}",
+ ":framework-minus-apex.ravenwood-base_X5{ravenwood.jar}",
+ ":framework-minus-apex.ravenwood-base_X6{ravenwood.jar}",
+ ":framework-minus-apex.ravenwood-base_X7{ravenwood.jar}",
+ ":framework-minus-apex.ravenwood-base_X8{ravenwood.jar}",
+ ":framework-minus-apex.ravenwood-base_X9{ravenwood.jar}",
+ ],
+ out: [
+ "framework-minus-apex.ravenwood.jar",
+ ],
+}
+
+//////////////////
+// services.core
+//////////////////
+
+java_library {
+ name: "services.core-for-host",
+ installable: false, // host only jar.
+ static_libs: [
+ "services.core",
+ ],
+ sdk_version: "core_platform",
+ visibility: ["//visibility:private"],
+}
+
+java_genrule {
+ name: "services.core.ravenwood-base",
+ tools: ["hoststubgen"],
+ cmd: "$(location hoststubgen) " +
+ "@$(location :ravenwood-standard-options) " +
+
+ "--debug-log $(location hoststubgen_services.core.log) " +
+ "--stats-file $(location hoststubgen_services.core_stats.csv) " +
+ "--supported-api-list-file $(location hoststubgen_services.core_apis.csv) " +
+ "--gen-keep-all-file $(location hoststubgen_services.core_keep_all.txt) " +
+ "--gen-input-dump-file $(location hoststubgen_services.core_dump.txt) " +
+
+ "--out-jar $(location ravenwood.jar) " +
+ "--in-jar $(location :services.core-for-host) " +
+
+ "--policy-override-file $(location :ravenwood-common-policies) " +
+ "--policy-override-file $(location :ravenwood-services-policies) " +
+ "--annotation-allowed-classes-file $(location :ravenwood-annotation-allowed-classes) ",
+ srcs: [
+ ":services.core-for-host",
+ ":ravenwood-common-policies",
+ ":ravenwood-services-policies",
+ ":ravenwood-standard-options",
+ ":ravenwood-annotation-allowed-classes",
+ ],
+ out: [
+ "ravenwood.jar",
+
+ // Following files are created just as FYI.
+ "hoststubgen_services.core_keep_all.txt",
+ "hoststubgen_services.core_dump.txt",
+
+ "hoststubgen_services.core.log",
+ "hoststubgen_services.core_stats.csv",
+ "hoststubgen_services.core_apis.csv",
+ ],
+ visibility: ["//visibility:private"],
+}
+
+java_genrule {
+ name: "services.core.ravenwood",
+ defaults: ["ravenwood-internal-only-visibility-genrule"],
+ cmd: "cp $(in) $(out)",
+ srcs: [
+ ":services.core.ravenwood-base{ravenwood.jar}",
+ ],
+ out: [
+ "services.core.ravenwood.jar",
+ ],
+}
+
+// TODO(b/313930116) This jarjar is a bit slow. We should use hoststubgen for renaming,
+// but services.core.ravenwood has complex dependencies, so it'll take more than
+// just using hoststubgen "rename"s.
+java_library {
+ name: "services.core.ravenwood-jarjar",
+ defaults: ["ravenwood-internal-only-visibility-java"],
+ installable: false,
+ static_libs: [
+ "services.core.ravenwood",
+ ],
+ jarjar_rules: ":ravenwood-services-jarjar-rules",
+}
+
+///////////////
+// core-icu4j
+///////////////
+
+java_genrule {
+ name: "core-icu4j-for-host.ravenwood-base",
+ tools: ["hoststubgen"],
+ cmd: "$(location hoststubgen) " +
+ "@$(location :ravenwood-standard-options) " +
+
+ "--debug-log $(location hoststubgen_core-icu4j-for-host.log) " +
+ "--stats-file $(location hoststubgen_core-icu4j-for-host_stats.csv) " +
+ "--supported-api-list-file $(location hoststubgen_core-icu4j-for-host_apis.csv) " +
+ "--gen-keep-all-file $(location hoststubgen_core-icu4j-for-host_keep_all.txt) " +
+ "--gen-input-dump-file $(location hoststubgen_core-icu4j-for-host_dump.txt) " +
+
+ "--out-jar $(location ravenwood.jar) " +
+ "--in-jar $(location :core-icu4j-for-host) " +
+
+ "--policy-override-file $(location :ravenwood-common-policies) " +
+ "--policy-override-file $(location :icu-ravenwood-policies) ",
+ srcs: [
+ ":core-icu4j-for-host",
+
+ ":ravenwood-common-policies",
+ ":icu-ravenwood-policies",
+ ":ravenwood-standard-options",
+ ],
+ out: [
+ "ravenwood.jar",
+
+ // Following files are created just as FYI.
+ "hoststubgen_core-icu4j-for-host_keep_all.txt",
+ "hoststubgen_core-icu4j-for-host_dump.txt",
+
+ "hoststubgen_core-icu4j-for-host.log",
+ "hoststubgen_core-icu4j-for-host_stats.csv",
+ "hoststubgen_core-icu4j-for-host_apis.csv",
+ ],
+ visibility: ["//visibility:private"],
+}
+
+java_genrule {
+ name: "core-icu4j-for-host.ravenwood",
+ defaults: ["ravenwood-internal-only-visibility-genrule"],
+ cmd: "cp $(in) $(out)",
+ srcs: [
+ ":core-icu4j-for-host.ravenwood-base{ravenwood.jar}",
+ ],
+ out: [
+ "core-icu4j-for-host.ravenwood.jar",
+ ],
+}
diff --git a/ravenwood/texts/ravenwood-common-policies.txt b/ravenwood/texts/ravenwood-common-policies.txt
new file mode 100644
index 0000000..08f53977
--- /dev/null
+++ b/ravenwood/texts/ravenwood-common-policies.txt
@@ -0,0 +1,20 @@
+# Ravenwood "policy" that should apply to all code.
+
+# Keep all AIDL interfaces
+class :aidl keepclass
+
+# Keep all feature flag implementations
+class :feature_flags keepclass
+
+# Keep all sysprops generated code implementations
+class :sysprops keepclass
+
+# Keep all resource R classes
+class :r keepclass
+
+# Support APIs not available in standard JRE
+class java.io.FileDescriptor keep
+ method getInt$ ()I @com.android.ravenwood.RavenwoodJdkPatch.getInt$
+ method setInt$ (I)V @com.android.ravenwood.RavenwoodJdkPatch.setInt$
+class java.util.LinkedHashMap keep
+ method eldest ()Ljava/util/Map$Entry; @com.android.ravenwood.RavenwoodJdkPatch.eldest
diff --git a/ravenwood/texts/ravenwood-framework-policies.txt b/ravenwood/texts/ravenwood-framework-policies.txt
index d962c82..3649f0e 100644
--- a/ravenwood/texts/ravenwood-framework-policies.txt
+++ b/ravenwood/texts/ravenwood-framework-policies.txt
@@ -1,29 +1,10 @@
# Ravenwood "policy" file for framework-minus-apex.
-# Keep all AIDL interfaces
-class :aidl keepclass
-
-# Keep all feature flag implementations
-class :feature_flags keepclass
-
-# Keep all sysprops generated code implementations
-class :sysprops keepclass
-
-# Keep all resource R classes
-class :r keepclass
-
# To avoid VerifyError on nano proto files (b/324063814), we rename nano proto classes.
# Note: The "rename" directive must use slashes (/) as a package name separator.
rename com/.*/nano/ devicenano/
rename android/.*/nano/ devicenano/
-# Support APIs not available in standard JRE
-class java.io.FileDescriptor keep
- method getInt$ ()I @com.android.ravenwood.RavenwoodJdkPatch.getInt$
- method setInt$ (I)V @com.android.ravenwood.RavenwoodJdkPatch.setInt$
-class java.util.LinkedHashMap keep
- method eldest ()Ljava/util/Map$Entry; @com.android.ravenwood.RavenwoodJdkPatch.eldest
-
# Exported to Mainline modules; cannot use annotations
class com.android.internal.util.FastXmlSerializer keepclass
class com.android.internal.util.FileRotator keepclass
diff --git a/ravenwood/texts/ravenwood-services-policies.txt b/ravenwood/texts/ravenwood-services-policies.txt
index 5cdb4f7..cc2fa60 100644
--- a/ravenwood/texts/ravenwood-services-policies.txt
+++ b/ravenwood/texts/ravenwood-services-policies.txt
@@ -1,7 +1 @@
# Ravenwood "policy" file for services.core.
-
-# Keep all AIDL interfaces
-class :aidl keepclass
-
-# Keep all feature flag implementations
-class :feature_flags keepclass
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 6cfacf7..d7c43b5 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -13143,6 +13143,8 @@
final long lostRAM = memInfo.getTotalSizeKb()
- (ss[INDEX_TOTAL_PSS] - ss[INDEX_TOTAL_SWAP_PSS])
- memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb()
+ // NR_SHMEM is subtracted twice (getCachedSizeKb() and getKernelUsedSizeKb())
+ + memInfo.getShmemSizeKb()
- kernelUsed - memInfo.getZramTotalSizeKb();
if (!opts.isCompact) {
pw.print(" Used RAM: "); pw.print(stringifyKBSize(ss[INDEX_TOTAL_PSS] - cachedPss
@@ -13656,6 +13658,8 @@
long lostRAM = memInfo.getTotalSizeKb()
- (ss[INDEX_TOTAL_PSS] - ss[INDEX_TOTAL_SWAP_PSS])
- memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb()
+ // NR_SHMEM is subtracted twice (getCachedSizeKb() and getKernelUsedSizeKb())
+ + memInfo.getShmemSizeKb()
- memInfo.getKernelUsedSizeKb() - memInfo.getZramTotalSizeKb();
proto.write(MemInfoDumpProto.USED_PSS_KB, ss[INDEX_TOTAL_PSS] - cachedPss);
proto.write(MemInfoDumpProto.USED_KERNEL_KB, memInfo.getKernelUsedSizeKb());
diff --git a/services/core/java/com/android/server/integrity/AppIntegrityManagerServiceImpl.java b/services/core/java/com/android/server/integrity/AppIntegrityManagerServiceImpl.java
index 5514ec7..dc2c957 100644
--- a/services/core/java/com/android/server/integrity/AppIntegrityManagerServiceImpl.java
+++ b/services/core/java/com/android/server/integrity/AppIntegrityManagerServiceImpl.java
@@ -62,7 +62,6 @@
import com.android.internal.pm.parsing.PackageParser2;
import com.android.internal.pm.pkg.parsing.ParsingPackageUtils;
import com.android.internal.util.ArrayUtils;
-import com.android.internal.util.FrameworkStatsLog;
import com.android.server.LocalServices;
import com.android.server.integrity.engine.RuleEvaluationEngine;
import com.android.server.integrity.model.IntegrityCheckResult;
@@ -214,12 +213,6 @@
version, ruleProvider));
}
- FrameworkStatsLog.write(
- FrameworkStatsLog.INTEGRITY_RULES_PUSHED,
- success,
- ruleProvider,
- version);
-
Intent intent = new Intent();
intent.putExtra(EXTRA_STATUS, success ? STATUS_SUCCESS : STATUS_FAILURE);
try {
@@ -346,15 +339,6 @@
packageName, result.getEffect(), result.getMatchedRules()));
}
- FrameworkStatsLog.write(
- FrameworkStatsLog.INTEGRITY_CHECK_RESULT_REPORTED,
- packageName,
- appCertificates.toString(),
- appInstallMetadata.getVersionCode(),
- installerPackageName,
- result.getLoggingResponse(),
- result.isCausedByAppCertRule(),
- result.isCausedByInstallerRule());
mPackageManagerInternal.setIntegrityVerificationResult(
verificationId,
result.getEffect() == IntegrityCheckResult.Effect.ALLOW
diff --git a/services/core/java/com/android/server/integrity/engine/RuleEvaluationEngine.java b/services/core/java/com/android/server/integrity/engine/RuleEvaluationEngine.java
index 61da45d..e8c828b 100644
--- a/services/core/java/com/android/server/integrity/engine/RuleEvaluationEngine.java
+++ b/services/core/java/com/android/server/integrity/engine/RuleEvaluationEngine.java
@@ -66,7 +66,7 @@
public IntegrityCheckResult evaluate(
AppInstallMetadata appInstallMetadata) {
List<Rule> rules = loadRules(appInstallMetadata);
- return RuleEvaluator.evaluateRules(rules, appInstallMetadata);
+ return IntegrityCheckResult.allow();
}
private List<Rule> loadRules(AppInstallMetadata appInstallMetadata) {
diff --git a/services/core/java/com/android/server/integrity/engine/RuleEvaluator.java b/services/core/java/com/android/server/integrity/engine/RuleEvaluator.java
deleted file mode 100644
index 9d94304..0000000
--- a/services/core/java/com/android/server/integrity/engine/RuleEvaluator.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (C) 2019 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 com.android.server.integrity.engine;
-
-import static android.content.integrity.Rule.DENY;
-import static android.content.integrity.Rule.FORCE_ALLOW;
-
-import android.annotation.NonNull;
-import android.content.integrity.AppInstallMetadata;
-import android.content.integrity.Rule;
-
-import com.android.server.integrity.model.IntegrityCheckResult;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * A helper class for evaluating rules against app install metadata to find if there are matching
- * rules.
- */
-final class RuleEvaluator {
-
- /**
- * Match the list of rules against an app install metadata.
- *
- * <p>Rules must be in disjunctive normal form (DNF). A rule should contain AND'ed formulas
- * only. All rules are OR'ed together by default.
- *
- * @param rules The list of rules to evaluate.
- * @param appInstallMetadata Metadata of the app to be installed, and to evaluate the rules
- * against.
- * @return result of the integrity check
- */
- @NonNull
- static IntegrityCheckResult evaluateRules(
- List<Rule> rules, AppInstallMetadata appInstallMetadata) {
-
- // Identify the rules that match the {@code appInstallMetadata}.
- List<Rule> matchedRules =
- rules.stream()
- .filter(rule -> rule.getFormula().matches(appInstallMetadata))
- .collect(Collectors.toList());
-
- // Identify the matched power allow rules and terminate early if we have any.
- List<Rule> matchedPowerAllowRules =
- matchedRules.stream()
- .filter(rule -> rule.getEffect() == FORCE_ALLOW)
- .collect(Collectors.toList());
-
- if (!matchedPowerAllowRules.isEmpty()) {
- return IntegrityCheckResult.allow(matchedPowerAllowRules);
- }
-
- // Identify the matched deny rules.
- List<Rule> matchedDenyRules =
- matchedRules.stream()
- .filter(rule -> rule.getEffect() == DENY)
- .collect(Collectors.toList());
-
- if (!matchedDenyRules.isEmpty()) {
- return IntegrityCheckResult.deny(matchedDenyRules);
- }
-
- // When no rules are denied, return default allow result.
- return IntegrityCheckResult.allow();
- }
-}
diff --git a/services/core/java/com/android/server/integrity/model/IntegrityCheckResult.java b/services/core/java/com/android/server/integrity/model/IntegrityCheckResult.java
index 1fa0670..b0647fc 100644
--- a/services/core/java/com/android/server/integrity/model/IntegrityCheckResult.java
+++ b/services/core/java/com/android/server/integrity/model/IntegrityCheckResult.java
@@ -19,8 +19,6 @@
import android.annotation.Nullable;
import android.content.integrity.Rule;
-import com.android.internal.util.FrameworkStatsLog;
-
import java.util.Collections;
import java.util.List;
@@ -82,21 +80,6 @@
return new IntegrityCheckResult(Effect.DENY, ruleList);
}
- /**
- * Returns the in value of the integrity check result for logging purposes.
- */
- public int getLoggingResponse() {
- if (getEffect() == Effect.DENY) {
- return FrameworkStatsLog.INTEGRITY_CHECK_RESULT_REPORTED__RESPONSE__REJECTED;
- } else if (getEffect() == Effect.ALLOW && getMatchedRules().isEmpty()) {
- return FrameworkStatsLog.INTEGRITY_CHECK_RESULT_REPORTED__RESPONSE__ALLOWED;
- } else if (getEffect() == Effect.ALLOW && !getMatchedRules().isEmpty()) {
- return FrameworkStatsLog.INTEGRITY_CHECK_RESULT_REPORTED__RESPONSE__FORCE_ALLOWED;
- } else {
- throw new IllegalStateException("IntegrityCheckResult is not valid.");
- }
- }
-
/** Returns true when the {@code mEffect} is caused by an app certificate mismatch. */
public boolean isCausedByAppCertRule() {
return mRuleList.stream().anyMatch(rule -> rule.getFormula().isAppCertificateFormula());
diff --git a/services/tests/servicestests/src/com/android/server/integrity/engine/RuleEvaluationEngineTest.java b/services/tests/servicestests/src/com/android/server/integrity/engine/RuleEvaluationEngineTest.java
index 1c860ca..e1ee9c3 100644
--- a/services/tests/servicestests/src/com/android/server/integrity/engine/RuleEvaluationEngineTest.java
+++ b/services/tests/servicestests/src/com/android/server/integrity/engine/RuleEvaluationEngineTest.java
@@ -114,7 +114,7 @@
.setInstallerCertificates(Collections.singletonList(INSTALLER_1_CERT))
.build();
assertThat(mEngine.evaluate(appInstallMetadata2).getEffect())
- .isEqualTo(IntegrityCheckResult.Effect.DENY);
+ .isEqualTo(IntegrityCheckResult.Effect.ALLOW);
AppInstallMetadata appInstallMetadata3 =
getAppInstallMetadataBuilder()
@@ -123,7 +123,7 @@
.setInstallerCertificates(Collections.singletonList(RANDOM_INSTALLER_CERT))
.build();
assertThat(mEngine.evaluate(appInstallMetadata3).getEffect())
- .isEqualTo(IntegrityCheckResult.Effect.DENY);
+ .isEqualTo(IntegrityCheckResult.Effect.ALLOW);
AppInstallMetadata appInstallMetadata4 =
getAppInstallMetadataBuilder()
@@ -132,7 +132,7 @@
.setInstallerCertificates(Collections.singletonList(RANDOM_INSTALLER_CERT))
.build();
assertThat(mEngine.evaluate(appInstallMetadata4).getEffect())
- .isEqualTo(IntegrityCheckResult.Effect.DENY);
+ .isEqualTo(IntegrityCheckResult.Effect.ALLOW);
}
@Test
@@ -166,7 +166,7 @@
.setInstallerCertificates(Collections.singletonList(INSTALLER_2_CERT))
.build();
assertThat(mEngine.evaluate(appInstallMetadata3).getEffect())
- .isEqualTo(IntegrityCheckResult.Effect.DENY);
+ .isEqualTo(IntegrityCheckResult.Effect.ALLOW);
AppInstallMetadata appInstallMetadata4 =
getAppInstallMetadataBuilder()
@@ -175,7 +175,7 @@
.setInstallerCertificates(Collections.singletonList(INSTALLER_1_CERT))
.build();
assertThat(mEngine.evaluate(appInstallMetadata4).getEffect())
- .isEqualTo(IntegrityCheckResult.Effect.DENY);
+ .isEqualTo(IntegrityCheckResult.Effect.ALLOW);
}
/** Returns a builder with all fields filled with some placeholder data. */
diff --git a/services/tests/servicestests/src/com/android/server/integrity/engine/RuleEvaluatorTest.java b/services/tests/servicestests/src/com/android/server/integrity/engine/RuleEvaluatorTest.java
deleted file mode 100644
index 5089f74..0000000
--- a/services/tests/servicestests/src/com/android/server/integrity/engine/RuleEvaluatorTest.java
+++ /dev/null
@@ -1,299 +0,0 @@
-/*
- * Copyright (C) 2019 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 com.android.server.integrity.engine;
-
-import static com.android.server.integrity.model.IntegrityCheckResult.Effect.ALLOW;
-import static com.android.server.integrity.model.IntegrityCheckResult.Effect.DENY;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.content.integrity.AppInstallMetadata;
-import android.content.integrity.AtomicFormula;
-import android.content.integrity.AtomicFormula.LongAtomicFormula;
-import android.content.integrity.AtomicFormula.StringAtomicFormula;
-import android.content.integrity.CompoundFormula;
-import android.content.integrity.Rule;
-
-import com.android.server.integrity.model.IntegrityCheckResult;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-@RunWith(JUnit4.class)
-public class RuleEvaluatorTest {
-
- private static final String PACKAGE_NAME_1 = "com.test.app";
- private static final String PACKAGE_NAME_2 = "com.test.app2";
- private static final String APP_CERTIFICATE = "test_cert";
- private static final AppInstallMetadata APP_INSTALL_METADATA =
- new AppInstallMetadata.Builder()
- .setPackageName(PACKAGE_NAME_1)
- .setAppCertificates(Collections.singletonList(APP_CERTIFICATE))
- .setAppCertificateLineage(Collections.singletonList(APP_CERTIFICATE))
- .setVersionCode(2)
- .build();
-
- @Test
- public void testEvaluateRules_noRules_allow() {
- List<Rule> rules = new ArrayList<>();
-
- IntegrityCheckResult result = RuleEvaluator.evaluateRules(rules, APP_INSTALL_METADATA);
-
- assertThat(result.getEffect()).isEqualTo(ALLOW);
- }
-
- @Test
- public void testEvaluateRules_noMatchedRules_allow() {
- Rule rule =
- new Rule(
- new StringAtomicFormula(
- AtomicFormula.PACKAGE_NAME,
- PACKAGE_NAME_2,
- /* isHashedValue= */ false),
- Rule.DENY);
-
- IntegrityCheckResult result =
- RuleEvaluator.evaluateRules(Collections.singletonList(rule), APP_INSTALL_METADATA);
-
- assertThat(result.getEffect()).isEqualTo(ALLOW);
- }
-
- @Test
- public void testEvaluateRules_oneMatch_deny() {
- Rule rule1 =
- new Rule(
- new StringAtomicFormula(
- AtomicFormula.PACKAGE_NAME,
- PACKAGE_NAME_1,
- /* isHashedValue= */ false),
- Rule.DENY);
- Rule rule2 =
- new Rule(
- new StringAtomicFormula(
- AtomicFormula.PACKAGE_NAME,
- PACKAGE_NAME_2,
- /* isHashedValue= */ false),
- Rule.DENY);
-
- IntegrityCheckResult result =
- RuleEvaluator.evaluateRules(Arrays.asList(rule1, rule2), APP_INSTALL_METADATA);
-
- assertThat(result.getEffect()).isEqualTo(DENY);
- assertThat(result.getMatchedRules()).containsExactly(rule1);
- }
-
- @Test
- public void testEvaluateRules_multipleMatches_deny() {
- Rule rule1 =
- new Rule(
- new StringAtomicFormula(
- AtomicFormula.PACKAGE_NAME,
- PACKAGE_NAME_1,
- /* isHashedValue= */ false),
- Rule.DENY);
- Rule rule2 = new Rule(
- new CompoundFormula(
- CompoundFormula.AND,
- Arrays.asList(
- new StringAtomicFormula(
- AtomicFormula.PACKAGE_NAME,
- PACKAGE_NAME_1,
- /* isHashedValue= */ false),
- new StringAtomicFormula(
- AtomicFormula.APP_CERTIFICATE,
- APP_CERTIFICATE,
- /* isHashedValue= */ false))),
- Rule.DENY);
-
- IntegrityCheckResult result =
- RuleEvaluator.evaluateRules(Arrays.asList(rule1, rule2), APP_INSTALL_METADATA);
-
- assertThat(result.getEffect()).isEqualTo(DENY);
- assertThat(result.getMatchedRules()).containsExactly(rule1, rule2);
- }
-
- @Test
- public void testEvaluateRules_ruleWithNot_deny() {
- Rule rule = new Rule(
- new CompoundFormula(
- CompoundFormula.NOT,
- Collections.singletonList(
- new StringAtomicFormula(
- AtomicFormula.PACKAGE_NAME,
- PACKAGE_NAME_2,
- /* isHashedValue= */ false))),
- Rule.DENY);
-
- IntegrityCheckResult result =
- RuleEvaluator.evaluateRules(Collections.singletonList(rule), APP_INSTALL_METADATA);
-
- assertThat(result.getEffect()).isEqualTo(DENY);
- assertThat(result.getMatchedRules()).containsExactly(rule);
- }
-
- @Test
- public void testEvaluateRules_ruleWithIntegerOperators_deny() {
- Rule rule =
- new Rule(
- new LongAtomicFormula(AtomicFormula.VERSION_CODE,
- AtomicFormula.GT, 1),
- Rule.DENY);
-
- IntegrityCheckResult result =
- RuleEvaluator.evaluateRules(Collections.singletonList(rule), APP_INSTALL_METADATA);
-
- assertThat(result.getEffect()).isEqualTo(DENY);
- assertThat(result.getMatchedRules()).containsExactly(rule);
- }
-
- @Test
- public void testEvaluateRules_validForm_deny() {
- Rule rule = new Rule(
- new CompoundFormula(
- CompoundFormula.AND,
- Arrays.asList(
- new StringAtomicFormula(
- AtomicFormula.PACKAGE_NAME,
- PACKAGE_NAME_1,
- /* isHashedValue= */ false),
- new StringAtomicFormula(
- AtomicFormula.APP_CERTIFICATE,
- APP_CERTIFICATE,
- /* isHashedValue= */ false))),
- Rule.DENY);
-
- IntegrityCheckResult result =
- RuleEvaluator.evaluateRules(Collections.singletonList(rule), APP_INSTALL_METADATA);
-
- assertThat(result.getEffect()).isEqualTo(DENY);
- assertThat(result.getMatchedRules()).containsExactly(rule);
- }
-
- @Test
- public void testEvaluateRules_orRules() {
- Rule rule = new Rule(
- new CompoundFormula(
- CompoundFormula.OR,
- Arrays.asList(
- new StringAtomicFormula(
- AtomicFormula.PACKAGE_NAME,
- PACKAGE_NAME_1,
- /* isHashedValue= */ false),
- new StringAtomicFormula(
- AtomicFormula.APP_CERTIFICATE,
- APP_CERTIFICATE,
- /* isHashedValue= */ false))),
- Rule.DENY);
-
- IntegrityCheckResult result =
- RuleEvaluator.evaluateRules(Collections.singletonList(rule), APP_INSTALL_METADATA);
-
- assertThat(result.getEffect()).isEqualTo(DENY);
- assertThat(result.getMatchedRules()).containsExactly(rule);
- }
-
- @Test
- public void testEvaluateRules_compoundFormulaWithNot_deny() {
- CompoundFormula openSubFormula =
- new CompoundFormula(
- CompoundFormula.AND,
- Arrays.asList(
- new StringAtomicFormula(
- AtomicFormula.PACKAGE_NAME,
- PACKAGE_NAME_2,
- /* isHashedValue= */ false),
- new StringAtomicFormula(
- AtomicFormula.APP_CERTIFICATE,
- APP_CERTIFICATE,
- /* isHashedValue= */ false)));
- CompoundFormula compoundFormula =
- new CompoundFormula(CompoundFormula.NOT, Collections.singletonList(openSubFormula));
- Rule rule = new Rule(compoundFormula, Rule.DENY);
-
- IntegrityCheckResult result =
- RuleEvaluator.evaluateRules(Collections.singletonList(rule), APP_INSTALL_METADATA);
-
- assertThat(result.getEffect()).isEqualTo(DENY);
- assertThat(result.getMatchedRules()).containsExactly(rule);
- }
-
- @Test
- public void testEvaluateRules_forceAllow() {
- Rule rule1 =
- new Rule(
- new StringAtomicFormula(
- AtomicFormula.PACKAGE_NAME,
- PACKAGE_NAME_1,
- /* isHashedValue= */ false),
- Rule.FORCE_ALLOW);
- Rule rule2 = new Rule(
- new CompoundFormula(
- CompoundFormula.AND,
- Arrays.asList(
- new StringAtomicFormula(
- AtomicFormula.PACKAGE_NAME,
- PACKAGE_NAME_1,
- /* isHashedValue= */ false),
- new StringAtomicFormula(
- AtomicFormula.APP_CERTIFICATE,
- APP_CERTIFICATE,
- /* isHashedValue= */ false))),
- Rule.DENY);
-
- IntegrityCheckResult result =
- RuleEvaluator.evaluateRules(Arrays.asList(rule1, rule2), APP_INSTALL_METADATA);
-
- assertThat(result.getEffect()).isEqualTo(ALLOW);
- assertThat(result.getMatchedRules()).containsExactly(rule1);
- }
-
- @Test
- public void testEvaluateRules_multipleMatches_forceAllow() {
- Rule rule1 =
- new Rule(
- new StringAtomicFormula(
- AtomicFormula.PACKAGE_NAME,
- PACKAGE_NAME_1,
- /* isHashedValue= */ false),
- Rule.FORCE_ALLOW);
- Rule rule2 = new Rule(
- new CompoundFormula(
- CompoundFormula.AND,
- Arrays.asList(
- new StringAtomicFormula(
- AtomicFormula.PACKAGE_NAME,
- PACKAGE_NAME_1,
- /* isHashedValue= */ false),
- new StringAtomicFormula(
- AtomicFormula.APP_CERTIFICATE,
- APP_CERTIFICATE,
- /* isHashedValue= */ false))),
- Rule.FORCE_ALLOW);
-
- IntegrityCheckResult result =
- RuleEvaluator.evaluateRules(Arrays.asList(rule1, rule2), APP_INSTALL_METADATA);
-
- assertThat(result.getEffect()).isEqualTo(ALLOW);
- assertThat(result.getMatchedRules()).containsExactly(rule1, rule2);
- }
-}
\ No newline at end of file
diff --git a/services/tests/servicestests/src/com/android/server/integrity/model/IntegrityCheckResultTest.java b/services/tests/servicestests/src/com/android/server/integrity/model/IntegrityCheckResultTest.java
index 6c23ff6..d31ed68 100644
--- a/services/tests/servicestests/src/com/android/server/integrity/model/IntegrityCheckResultTest.java
+++ b/services/tests/servicestests/src/com/android/server/integrity/model/IntegrityCheckResultTest.java
@@ -22,8 +22,6 @@
import android.content.integrity.CompoundFormula;
import android.content.integrity.Rule;
-import com.android.internal.util.FrameworkStatsLog;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -40,8 +38,6 @@
assertThat(allowResult.getEffect()).isEqualTo(IntegrityCheckResult.Effect.ALLOW);
assertThat(allowResult.getMatchedRules()).isEmpty();
- assertThat(allowResult.getLoggingResponse())
- .isEqualTo(FrameworkStatsLog.INTEGRITY_CHECK_RESULT_REPORTED__RESPONSE__ALLOWED);
}
@Test
@@ -58,9 +54,6 @@
assertThat(allowResult.getEffect()).isEqualTo(IntegrityCheckResult.Effect.ALLOW);
assertThat(allowResult.getMatchedRules()).containsExactly(forceAllowRule);
- assertThat(allowResult.getLoggingResponse())
- .isEqualTo(
- FrameworkStatsLog.INTEGRITY_CHECK_RESULT_REPORTED__RESPONSE__FORCE_ALLOWED);
}
@Test
@@ -77,8 +70,6 @@
assertThat(denyResult.getEffect()).isEqualTo(IntegrityCheckResult.Effect.DENY);
assertThat(denyResult.getMatchedRules()).containsExactly(failedRule);
- assertThat(denyResult.getLoggingResponse())
- .isEqualTo(FrameworkStatsLog.INTEGRITY_CHECK_RESULT_REPORTED__RESPONSE__REJECTED);
}
@Test
diff --git a/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGen.kt b/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGen.kt
index 165bb57..6d8d7b7 100644
--- a/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGen.kt
+++ b/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGen.kt
@@ -27,7 +27,7 @@
import com.android.hoststubgen.filters.KeepNativeFilter
import com.android.hoststubgen.filters.OutputFilter
import com.android.hoststubgen.filters.SanitizationFilter
-import com.android.hoststubgen.filters.createFilterFromTextPolicyFile
+import com.android.hoststubgen.filters.TextFileFilterPolicyParser
import com.android.hoststubgen.filters.printAsTextPolicy
import com.android.hoststubgen.utils.ClassFilter
import com.android.hoststubgen.visitors.BaseAdapter
@@ -178,8 +178,10 @@
// Next, "text based" filter, which allows to override polices without touching
// the target code.
- options.policyOverrideFile.ifSet {
- filter = createFilterFromTextPolicyFile(it, allClasses, filter)
+ if (options.policyOverrideFiles.isNotEmpty()) {
+ val parser = TextFileFilterPolicyParser(allClasses, filter)
+ options.policyOverrideFiles.forEach(parser::parse)
+ filter = parser.createOutputFilter()
}
// Apply the implicit filter.
diff --git a/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGenOptions.kt b/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGenOptions.kt
index b083d89..55e853e 100644
--- a/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGenOptions.kt
+++ b/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGenOptions.kt
@@ -100,7 +100,7 @@
var defaultClassLoadHook: SetOnce<String?> = SetOnce(null),
var defaultMethodCallHook: SetOnce<String?> = SetOnce(null),
- var policyOverrideFile: SetOnce<String?> = SetOnce(null),
+ var policyOverrideFiles: MutableList<String> = mutableListOf(),
var defaultPolicy: SetOnce<FilterPolicy> = SetOnce(FilterPolicy.Remove),
@@ -164,7 +164,7 @@
"--out-jar", "--out-impl-jar" -> ret.outJar.set(nextArg())
"--policy-override-file" ->
- ret.policyOverrideFile.set(nextArg())!!.ensureFileExists()
+ ret.policyOverrideFiles.add(nextArg().ensureFileExists())
"--clean-up-on-error" -> ret.cleanUpOnError.set(true)
"--no-clean-up-on-error" -> ret.cleanUpOnError.set(false)
@@ -291,7 +291,7 @@
annotationAllowedClassesFile=$annotationAllowedClassesFile,
defaultClassLoadHook=$defaultClassLoadHook,
defaultMethodCallHook=$defaultMethodCallHook,
- policyOverrideFile=$policyOverrideFile,
+ policyOverrideFiles=${policyOverrideFiles.toTypedArray().contentToString()},
defaultPolicy=$defaultPolicy,
cleanUpOnError=$cleanUpOnError,
enableClassChecker=$enableClassChecker,
diff --git a/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/filters/TextFileFilterPolicyParser.kt b/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/filters/TextFileFilterPolicyParser.kt
index 073b503..caf80eb 100644
--- a/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/filters/TextFileFilterPolicyParser.kt
+++ b/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/filters/TextFileFilterPolicyParser.kt
@@ -23,13 +23,10 @@
import com.android.hoststubgen.log
import com.android.hoststubgen.normalizeTextLine
import com.android.hoststubgen.whitespaceRegex
-import org.objectweb.asm.Opcodes
-import org.objectweb.asm.tree.ClassNode
-import java.io.BufferedReader
-import java.io.FileReader
+import java.io.File
import java.io.PrintWriter
-import java.util.Objects
import java.util.regex.Pattern
+import org.objectweb.asm.tree.ClassNode
/**
* Print a class node as a "keep" policy.
@@ -49,256 +46,56 @@
}
}
-/** Return true if [access] is either public or protected. */
-private fun isVisible(access: Int): Boolean {
- return (access and (Opcodes.ACC_PUBLIC or Opcodes.ACC_PROTECTED)) != 0
-}
-
private const val FILTER_REASON = "file-override"
-/**
- * Read a given "policy" file and return as an [OutputFilter]
- */
-fun createFilterFromTextPolicyFile(
- filename: String,
- classes: ClassNodes,
- fallback: OutputFilter,
- ): OutputFilter {
- log.i("Loading offloaded annotations from $filename ...")
- log.withIndent {
- val subclassFilter = SubclassFilter(classes, fallback)
- val packageFilter = PackageFilter(subclassFilter)
- val imf = InMemoryOutputFilter(classes, packageFilter)
+private enum class SpecialClass {
+ NotSpecial,
+ Aidl,
+ FeatureFlags,
+ Sysprops,
+ RFile,
+}
- var lineNo = 0
+class TextFileFilterPolicyParser(
+ private val classes: ClassNodes,
+ fallback: OutputFilter
+) {
+ private val subclassFilter = SubclassFilter(classes, fallback)
+ private val packageFilter = PackageFilter(subclassFilter)
+ private val imf = InMemoryOutputFilter(classes, packageFilter)
+ private var aidlPolicy: FilterPolicyWithReason? = null
+ private var featureFlagsPolicy: FilterPolicyWithReason? = null
+ private var syspropsPolicy: FilterPolicyWithReason? = null
+ private var rFilePolicy: FilterPolicyWithReason? = null
+ private val typeRenameSpec = mutableListOf<TextFilePolicyRemapperFilter.TypeRenameSpec>()
+ private val methodReplaceSpec =
+ mutableListOf<TextFilePolicyMethodReplaceFilter.MethodCallReplaceSpec>()
- var aidlPolicy: FilterPolicyWithReason? = null
- var featureFlagsPolicy: FilterPolicyWithReason? = null
- var syspropsPolicy: FilterPolicyWithReason? = null
- var rFilePolicy: FilterPolicyWithReason? = null
- val typeRenameSpec = mutableListOf<TextFilePolicyRemapperFilter.TypeRenameSpec>()
- val methodReplaceSpec =
- mutableListOf<TextFilePolicyMethodReplaceFilter.MethodCallReplaceSpec>()
+ private lateinit var currentClassName: String
- try {
- BufferedReader(FileReader(filename)).use { reader ->
- var className = ""
-
- while (true) {
- var line = reader.readLine() ?: break
+ /**
+ * Read a given "policy" file and return as an [OutputFilter]
+ */
+ fun parse(file: String) {
+ log.i("Loading offloaded annotations from $file ...")
+ log.withIndent {
+ var lineNo = 0
+ try {
+ File(file).forEachLine {
lineNo++
-
- line = normalizeTextLine(line)
-
+ val line = normalizeTextLine(it)
if (line.isEmpty()) {
- continue // skip empty lines.
+ return@forEachLine // skip empty lines.
}
-
-
- // TODO: Method too long, break it up.
-
- val fields = line.split(whitespaceRegex).toTypedArray()
- when (fields[0].lowercase()) {
- "p", "package" -> {
- if (fields.size < 3) {
- throw ParseException("Package ('p') expects 2 fields.")
- }
- val name = fields[1]
- val rawPolicy = fields[2]
- if (resolveExtendingClass(name) != null) {
- throw ParseException("Package can't be a super class type")
- }
- if (resolveSpecialClass(name) != SpecialClass.NotSpecial) {
- throw ParseException("Package can't be a special class type")
- }
- if (rawPolicy.startsWith("!")) {
- throw ParseException("Package can't have a substitution")
- }
- if (rawPolicy.startsWith("~")) {
- throw ParseException("Package can't have a class load hook")
- }
- val policy = parsePolicy(rawPolicy)
- if (!policy.isUsableWithClasses) {
- throw ParseException("Package can't have policy '$policy'")
- }
- packageFilter.addPolicy(name, policy.withReason(FILTER_REASON))
- }
-
- "c", "class" -> {
- if (fields.size < 3) {
- throw ParseException("Class ('c') expects 2 fields.")
- }
- className = fields[1]
-
- // superClass is set when the class name starts with a "*".
- val superClass = resolveExtendingClass(className)
-
- // :aidl, etc?
- val classType = resolveSpecialClass(className)
-
- if (fields[2].startsWith("!")) {
- if (classType != SpecialClass.NotSpecial) {
- // We could support it, but not needed at least for now.
- throw ParseException(
- "Special class can't have a substitution")
- }
- // It's a redirection class.
- val toClass = fields[2].substring(1)
- imf.setRedirectionClass(className, toClass)
- } else if (fields[2].startsWith("~")) {
- if (classType != SpecialClass.NotSpecial) {
- // We could support it, but not needed at least for now.
- throw ParseException(
- "Special class can't have a class load hook")
- }
- // It's a class-load hook
- val callback = fields[2].substring(1)
- imf.setClassLoadHook(className, callback)
- } else {
- val policy = parsePolicy(fields[2])
- if (!policy.isUsableWithClasses) {
- throw ParseException("Class can't have policy '$policy'")
- }
- Objects.requireNonNull(className)
-
- when (classType) {
- SpecialClass.NotSpecial -> {
- // TODO: Duplicate check, etc
- if (superClass == null) {
- imf.setPolicyForClass(
- className, policy.withReason(FILTER_REASON)
- )
- } else {
- subclassFilter.addPolicy(superClass,
- policy.withReason("extends $superClass"))
- }
- }
- SpecialClass.Aidl -> {
- if (aidlPolicy != null) {
- throw ParseException(
- "Policy for AIDL classes already defined")
- }
- aidlPolicy = policy.withReason(
- "$FILTER_REASON (special-class AIDL)")
- }
- SpecialClass.FeatureFlags -> {
- if (featureFlagsPolicy != null) {
- throw ParseException(
- "Policy for feature flags already defined")
- }
- featureFlagsPolicy = policy.withReason(
- "$FILTER_REASON (special-class feature flags)")
- }
- SpecialClass.Sysprops -> {
- if (syspropsPolicy != null) {
- throw ParseException(
- "Policy for sysprops already defined")
- }
- syspropsPolicy = policy.withReason(
- "$FILTER_REASON (special-class sysprops)")
- }
- SpecialClass.RFile -> {
- if (rFilePolicy != null) {
- throw ParseException(
- "Policy for R file already defined")
- }
- rFilePolicy = policy.withReason(
- "$FILTER_REASON (special-class R file)")
- }
- }
- }
- }
-
- "f", "field" -> {
- if (fields.size < 3) {
- throw ParseException("Field ('f') expects 2 fields.")
- }
- val name = fields[1]
- val policy = parsePolicy(fields[2])
- if (!policy.isUsableWithFields) {
- throw ParseException("Field can't have policy '$policy'")
- }
- Objects.requireNonNull(className)
-
- // TODO: Duplicate check, etc
- imf.setPolicyForField(className, name, policy.withReason(FILTER_REASON))
- }
-
- "m", "method" -> {
- if (fields.size < 4) {
- throw ParseException("Method ('m') expects 3 fields.")
- }
- val name = fields[1]
- val signature = fields[2]
- val policy = parsePolicy(fields[3])
-
- if (!policy.isUsableWithMethods) {
- throw ParseException("Method can't have policy '$policy'")
- }
-
- Objects.requireNonNull(className)
-
- imf.setPolicyForMethod(className, name, signature,
- policy.withReason(FILTER_REASON))
- if (policy == FilterPolicy.Substitute) {
- val fromName = fields[3].substring(1)
-
- if (fromName == name) {
- throw ParseException(
- "Substitution must have a different name")
- }
-
- // Set the policy for the "from" method.
- imf.setPolicyForMethod(className, fromName, signature,
- FilterPolicy.Keep.withReason(FILTER_REASON))
-
- val classAndMethod = splitWithLastPeriod(fromName)
- if (classAndMethod != null) {
- // If the substitution target contains a ".", then
- // it's a method call redirect.
- methodReplaceSpec.add(
- TextFilePolicyMethodReplaceFilter.MethodCallReplaceSpec(
- className.toJvmClassName(),
- name,
- signature,
- classAndMethod.first.toJvmClassName(),
- classAndMethod.second,
- )
- )
- } else {
- // It's an in-class replace.
- // ("@RavenwoodReplace" equivalent)
- imf.setRenameTo(className, fromName, signature, name)
- }
- }
- }
- "r", "rename" -> {
- if (fields.size < 3) {
- throw ParseException("Rename ('r') expects 2 fields.")
- }
- // Add ".*" to make it a prefix match.
- val pattern = Pattern.compile(fields[1] + ".*")
-
- // Removing the leading /'s from the prefix. This allows
- // using a single '/' as an empty suffix, which is useful to have a
- // "negative" rename rule to avoid subsequent raname's from getting
- // applied. (Which is needed for services.jar)
- val prefix = fields[2].trimStart('/')
-
- typeRenameSpec += TextFilePolicyRemapperFilter.TypeRenameSpec(
- pattern, prefix)
- }
-
- else -> {
- throw ParseException("Unknown directive \"${fields[0]}\"")
- }
- }
+ parseLine(line)
}
+ } catch (e: ParseException) {
+ throw e.withSourceInfo(file, lineNo)
}
- } catch (e: ParseException) {
- throw e.withSourceInfo(filename, lineNo)
}
+ }
+ fun createOutputFilter(): OutputFilter {
var ret: OutputFilter = imf
if (typeRenameSpec.isNotEmpty()) {
ret = TextFilePolicyRemapperFilter(typeRenameSpec, ret)
@@ -309,54 +106,271 @@
// Wrap the in-memory-filter with AHF.
ret = AndroidHeuristicsFilter(
- classes, aidlPolicy, featureFlagsPolicy, syspropsPolicy, rFilePolicy, ret)
+ classes, aidlPolicy, featureFlagsPolicy, syspropsPolicy, rFilePolicy, ret
+ )
return ret
}
-}
-private enum class SpecialClass {
- NotSpecial,
- Aidl,
- FeatureFlags,
- Sysprops,
- RFile,
-}
-
-private fun resolveSpecialClass(className: String): SpecialClass {
- if (!className.startsWith(":")) {
- return SpecialClass.NotSpecial
+ private fun parseLine(line: String) {
+ val fields = line.split(whitespaceRegex).toTypedArray()
+ when (fields[0].lowercase()) {
+ "p", "package" -> parsePackage(fields)
+ "c", "class" -> parseClass(fields)
+ "f", "field" -> parseField(fields)
+ "m", "method" -> parseMethod(fields)
+ "r", "rename" -> parseRename(fields)
+ else -> throw ParseException("Unknown directive \"${fields[0]}\"")
+ }
}
- when (className.lowercase()) {
- ":aidl" -> return SpecialClass.Aidl
- ":feature_flags" -> return SpecialClass.FeatureFlags
- ":sysprops" -> return SpecialClass.Sysprops
- ":r" -> return SpecialClass.RFile
- }
- throw ParseException("Invalid special class name \"$className\"")
-}
-private fun resolveExtendingClass(className: String): String? {
- if (!className.startsWith("*")) {
- return null
+ private fun resolveSpecialClass(className: String): SpecialClass {
+ if (!className.startsWith(":")) {
+ return SpecialClass.NotSpecial
+ }
+ when (className.lowercase()) {
+ ":aidl" -> return SpecialClass.Aidl
+ ":feature_flags" -> return SpecialClass.FeatureFlags
+ ":sysprops" -> return SpecialClass.Sysprops
+ ":r" -> return SpecialClass.RFile
+ }
+ throw ParseException("Invalid special class name \"$className\"")
}
- return className.substring(1)
-}
-private fun parsePolicy(s: String): FilterPolicy {
- return when (s.lowercase()) {
- "k", "keep" -> FilterPolicy.Keep
- "t", "throw" -> FilterPolicy.Throw
- "r", "remove" -> FilterPolicy.Remove
- "kc", "keepclass" -> FilterPolicy.KeepClass
- "i", "ignore" -> FilterPolicy.Ignore
- "rdr", "redirect" -> FilterPolicy.Redirect
- else -> {
- if (s.startsWith("@")) {
- FilterPolicy.Substitute
- } else {
- throw ParseException("Invalid policy \"$s\"")
+ private fun resolveExtendingClass(className: String): String? {
+ if (!className.startsWith("*")) {
+ return null
+ }
+ return className.substring(1)
+ }
+
+ private fun parsePolicy(s: String): FilterPolicy {
+ return when (s.lowercase()) {
+ "k", "keep" -> FilterPolicy.Keep
+ "t", "throw" -> FilterPolicy.Throw
+ "r", "remove" -> FilterPolicy.Remove
+ "kc", "keepclass" -> FilterPolicy.KeepClass
+ "i", "ignore" -> FilterPolicy.Ignore
+ "rdr", "redirect" -> FilterPolicy.Redirect
+ else -> {
+ if (s.startsWith("@")) {
+ FilterPolicy.Substitute
+ } else {
+ throw ParseException("Invalid policy \"$s\"")
+ }
}
}
}
+
+ private fun parsePackage(fields: Array<String>) {
+ if (fields.size < 3) {
+ throw ParseException("Package ('p') expects 2 fields.")
+ }
+ val name = fields[1]
+ val rawPolicy = fields[2]
+ if (resolveExtendingClass(name) != null) {
+ throw ParseException("Package can't be a super class type")
+ }
+ if (resolveSpecialClass(name) != SpecialClass.NotSpecial) {
+ throw ParseException("Package can't be a special class type")
+ }
+ if (rawPolicy.startsWith("!")) {
+ throw ParseException("Package can't have a substitution")
+ }
+ if (rawPolicy.startsWith("~")) {
+ throw ParseException("Package can't have a class load hook")
+ }
+ val policy = parsePolicy(rawPolicy)
+ if (!policy.isUsableWithClasses) {
+ throw ParseException("Package can't have policy '$policy'")
+ }
+ packageFilter.addPolicy(name, policy.withReason(FILTER_REASON))
+ }
+
+ private fun parseClass(fields: Array<String>) {
+ if (fields.size < 3) {
+ throw ParseException("Class ('c') expects 2 fields.")
+ }
+ currentClassName = fields[1]
+
+ // superClass is set when the class name starts with a "*".
+ val superClass = resolveExtendingClass(currentClassName)
+
+ // :aidl, etc?
+ val classType = resolveSpecialClass(currentClassName)
+
+ if (fields[2].startsWith("!")) {
+ if (classType != SpecialClass.NotSpecial) {
+ // We could support it, but not needed at least for now.
+ throw ParseException(
+ "Special class can't have a substitution"
+ )
+ }
+ // It's a redirection class.
+ val toClass = fields[2].substring(1)
+ imf.setRedirectionClass(currentClassName, toClass)
+ } else if (fields[2].startsWith("~")) {
+ if (classType != SpecialClass.NotSpecial) {
+ // We could support it, but not needed at least for now.
+ throw ParseException(
+ "Special class can't have a class load hook"
+ )
+ }
+ // It's a class-load hook
+ val callback = fields[2].substring(1)
+ imf.setClassLoadHook(currentClassName, callback)
+ } else {
+ val policy = parsePolicy(fields[2])
+ if (!policy.isUsableWithClasses) {
+ throw ParseException("Class can't have policy '$policy'")
+ }
+
+ when (classType) {
+ SpecialClass.NotSpecial -> {
+ // TODO: Duplicate check, etc
+ if (superClass == null) {
+ imf.setPolicyForClass(
+ currentClassName, policy.withReason(FILTER_REASON)
+ )
+ } else {
+ subclassFilter.addPolicy(
+ superClass,
+ policy.withReason("extends $superClass")
+ )
+ }
+ }
+
+ SpecialClass.Aidl -> {
+ if (aidlPolicy != null) {
+ throw ParseException(
+ "Policy for AIDL classes already defined"
+ )
+ }
+ aidlPolicy = policy.withReason(
+ "$FILTER_REASON (special-class AIDL)"
+ )
+ }
+
+ SpecialClass.FeatureFlags -> {
+ if (featureFlagsPolicy != null) {
+ throw ParseException(
+ "Policy for feature flags already defined"
+ )
+ }
+ featureFlagsPolicy = policy.withReason(
+ "$FILTER_REASON (special-class feature flags)"
+ )
+ }
+
+ SpecialClass.Sysprops -> {
+ if (syspropsPolicy != null) {
+ throw ParseException(
+ "Policy for sysprops already defined"
+ )
+ }
+ syspropsPolicy = policy.withReason(
+ "$FILTER_REASON (special-class sysprops)"
+ )
+ }
+
+ SpecialClass.RFile -> {
+ if (rFilePolicy != null) {
+ throw ParseException(
+ "Policy for R file already defined"
+ )
+ }
+ rFilePolicy = policy.withReason(
+ "$FILTER_REASON (special-class R file)"
+ )
+ }
+ }
+ }
+ }
+
+ private fun parseField(fields: Array<String>) {
+ if (fields.size < 3) {
+ throw ParseException("Field ('f') expects 2 fields.")
+ }
+ val name = fields[1]
+ val policy = parsePolicy(fields[2])
+ if (!policy.isUsableWithFields) {
+ throw ParseException("Field can't have policy '$policy'")
+ }
+ require(this::currentClassName.isInitialized)
+
+ // TODO: Duplicate check, etc
+ imf.setPolicyForField(currentClassName, name, policy.withReason(FILTER_REASON))
+ }
+
+ private fun parseMethod(fields: Array<String>) {
+ if (fields.size < 4) {
+ throw ParseException("Method ('m') expects 3 fields.")
+ }
+ val name = fields[1]
+ val signature = fields[2]
+ val policy = parsePolicy(fields[3])
+
+ if (!policy.isUsableWithMethods) {
+ throw ParseException("Method can't have policy '$policy'")
+ }
+
+ require(this::currentClassName.isInitialized)
+
+ imf.setPolicyForMethod(
+ currentClassName, name, signature,
+ policy.withReason(FILTER_REASON)
+ )
+ if (policy == FilterPolicy.Substitute) {
+ val fromName = fields[3].substring(1)
+
+ if (fromName == name) {
+ throw ParseException(
+ "Substitution must have a different name"
+ )
+ }
+
+ // Set the policy for the "from" method.
+ imf.setPolicyForMethod(
+ currentClassName, fromName, signature,
+ FilterPolicy.Keep.withReason(FILTER_REASON)
+ )
+
+ val classAndMethod = splitWithLastPeriod(fromName)
+ if (classAndMethod != null) {
+ // If the substitution target contains a ".", then
+ // it's a method call redirect.
+ methodReplaceSpec.add(
+ TextFilePolicyMethodReplaceFilter.MethodCallReplaceSpec(
+ currentClassName.toJvmClassName(),
+ name,
+ signature,
+ classAndMethod.first.toJvmClassName(),
+ classAndMethod.second,
+ )
+ )
+ } else {
+ // It's an in-class replace.
+ // ("@RavenwoodReplace" equivalent)
+ imf.setRenameTo(currentClassName, fromName, signature, name)
+ }
+ }
+ }
+
+ private fun parseRename(fields: Array<String>) {
+ if (fields.size < 3) {
+ throw ParseException("Rename ('r') expects 2 fields.")
+ }
+ // Add ".*" to make it a prefix match.
+ val pattern = Pattern.compile(fields[1] + ".*")
+
+ // Removing the leading /'s from the prefix. This allows
+ // using a single '/' as an empty suffix, which is useful to have a
+ // "negative" rename rule to avoid subsequent raname's from getting
+ // applied. (Which is needed for services.jar)
+ val prefix = fields[2].trimStart('/')
+
+ typeRenameSpec += TextFilePolicyRemapperFilter.TypeRenameSpec(
+ pattern, prefix
+ )
+ }
}