From 1bbd0626f2d83036b4e1225cc51edfea5e4055b7 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 14 May 2021 15:52:25 +0100 Subject: Make uncompressDex available for use through hiddenAPIModule In order for the bootclasspath_fragment to perform dex encoding on its contents it needs to know whether the dex file is uncompressed or not. This change makes that information available by passing it to initHiddenAPI, storing it in hiddenAPI struct and providing access through the hiddenAPIModule. Bug: 179354495 Test: m droid Change-Id: I913416b4836766de194203fd8ed5124b61dfa3dd --- java/hiddenapi.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'java/hiddenapi.go') diff --git a/java/hiddenapi.go b/java/hiddenapi.go index 04b8fc689..1e838247b 100644 --- a/java/hiddenapi.go +++ b/java/hiddenapi.go @@ -43,6 +43,10 @@ type hiddenAPI struct { // the UnsupportedAppUsage annotation that need to be extracted as part of the hidden API // processing. classesJarPaths android.Paths + + // The compressed state of the dex file being encoded. This is used to ensure that the encoded + // dex file has the same state. + uncompressDexState *bool } func (h *hiddenAPI) bootDexJar() android.Path { @@ -53,6 +57,10 @@ func (h *hiddenAPI) classesJars() android.Paths { return h.classesJarPaths } +func (h *hiddenAPI) uncompressDex() *bool { + return h.uncompressDexState +} + // hiddenAPIModule is the interface a module that embeds the hiddenAPI structure must implement. type hiddenAPIModule interface { android.Module @@ -62,12 +70,16 @@ type hiddenAPIModule interface { type hiddenAPIIntf interface { bootDexJar() android.Path classesJars() android.Paths + uncompressDex() *bool } var _ hiddenAPIIntf = (*hiddenAPI)(nil) // Initialize the hiddenapi structure -func (h *hiddenAPI) initHiddenAPI(ctx android.ModuleContext, dexJar, classesJar android.Path) { +// +// uncompressedDexState should be nil when the module is a prebuilt and so does not require hidden +// API encoding. +func (h *hiddenAPI) initHiddenAPI(ctx android.ModuleContext, dexJar, classesJar android.Path, uncompressedDexState *bool) { // Save the classes jars even if this is not active as they may be used by modular hidden API // processing. @@ -82,6 +94,8 @@ func (h *hiddenAPI) initHiddenAPI(ctx android.ModuleContext, dexJar, classesJar // hiddenAPISingletonPathsStruct.stubFlags file. h.bootDexJarPath = dexJar + h.uncompressDexState = uncompressedDexState + // If hiddenapi processing is disabled treat this as inactive. if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { return @@ -119,12 +133,18 @@ func isModuleInBootClassPath(ctx android.BaseModuleContext, module android.Modul // // Otherwise, it creates a copy of the supplied dex file into which it has encoded the hiddenapi // flags and returns this instead of the supplied dex jar. -func (h *hiddenAPI) hiddenAPIEncodeDex(ctx android.ModuleContext, dexJar android.OutputPath, uncompressDex bool) android.OutputPath { +func (h *hiddenAPI) hiddenAPIEncodeDex(ctx android.ModuleContext, dexJar android.OutputPath) android.OutputPath { if !h.active { return dexJar } + // A nil uncompressDexState prevents the dex file from being encoded. + if h.uncompressDexState == nil { + ctx.ModuleErrorf("cannot encode dex file %s when uncompressDexState is nil", dexJar) + } + uncompressDex := *h.uncompressDexState + hiddenAPIJar := android.PathForModuleOut(ctx, "hiddenapi", dexJar.Base()).OutputPath // Create a copy of the dex jar which has been encoded with hiddenapi flags. -- cgit v1.2.3-59-g8ed1b