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
This commit is contained in:
Paul Duffin
2021-05-14 15:52:25 +01:00
parent 45897dd663
commit 1bbd0626f2
4 changed files with 28 additions and 8 deletions

View File

@@ -1218,10 +1218,10 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
} }
// Initialize the hiddenapi structure. // Initialize the hiddenapi structure.
j.initHiddenAPI(ctx, dexOutputFile, j.implementationJarFile) j.initHiddenAPI(ctx, dexOutputFile, j.implementationJarFile, j.dexProperties.Uncompress_dex)
// Encode hidden API flags in dex file. // Encode hidden API flags in dex file.
dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile, proptools.Bool(j.dexProperties.Uncompress_dex)) dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile)
// merge dex jar with resources if necessary // merge dex jar with resources if necessary
if j.resourceJar != nil { if j.resourceJar != nil {

View File

@@ -43,6 +43,10 @@ type hiddenAPI struct {
// the UnsupportedAppUsage annotation that need to be extracted as part of the hidden API // the UnsupportedAppUsage annotation that need to be extracted as part of the hidden API
// processing. // processing.
classesJarPaths android.Paths 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 { func (h *hiddenAPI) bootDexJar() android.Path {
@@ -53,6 +57,10 @@ func (h *hiddenAPI) classesJars() android.Paths {
return h.classesJarPaths return h.classesJarPaths
} }
func (h *hiddenAPI) uncompressDex() *bool {
return h.uncompressDexState
}
// hiddenAPIModule is the interface a module that embeds the hiddenAPI structure must implement. // hiddenAPIModule is the interface a module that embeds the hiddenAPI structure must implement.
type hiddenAPIModule interface { type hiddenAPIModule interface {
android.Module android.Module
@@ -62,12 +70,16 @@ type hiddenAPIModule interface {
type hiddenAPIIntf interface { type hiddenAPIIntf interface {
bootDexJar() android.Path bootDexJar() android.Path
classesJars() android.Paths classesJars() android.Paths
uncompressDex() *bool
} }
var _ hiddenAPIIntf = (*hiddenAPI)(nil) var _ hiddenAPIIntf = (*hiddenAPI)(nil)
// Initialize the hiddenapi structure // 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 // Save the classes jars even if this is not active as they may be used by modular hidden API
// processing. // processing.
@@ -82,6 +94,8 @@ func (h *hiddenAPI) initHiddenAPI(ctx android.ModuleContext, dexJar, classesJar
// hiddenAPISingletonPathsStruct.stubFlags file. // hiddenAPISingletonPathsStruct.stubFlags file.
h.bootDexJarPath = dexJar h.bootDexJarPath = dexJar
h.uncompressDexState = uncompressedDexState
// If hiddenapi processing is disabled treat this as inactive. // If hiddenapi processing is disabled treat this as inactive.
if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
return 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 // 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. // 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 { if !h.active {
return dexJar 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 hiddenAPIJar := android.PathForModuleOut(ctx, "hiddenapi", dexJar.Base()).OutputPath
// Create a copy of the dex jar which has been encoded with hiddenapi flags. // Create a copy of the dex jar which has been encoded with hiddenapi flags.

View File

@@ -1309,7 +1309,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.dexJarFile = dexOutputPath j.dexJarFile = dexOutputPath
// Initialize the hiddenapi structure. // Initialize the hiddenapi structure.
j.initHiddenAPI(ctx, dexOutputPath, outputFile) j.initHiddenAPI(ctx, dexOutputPath, outputFile, nil)
} else { } else {
// This should never happen as a variant for a prebuilt_apex is only created if the // This should never happen as a variant for a prebuilt_apex is only created if the
// prebuilt_apex has been configured to export the java library dex file. // prebuilt_apex has been configured to export the java library dex file.
@@ -1341,10 +1341,10 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
} }
// Initialize the hiddenapi structure. // Initialize the hiddenapi structure.
j.initHiddenAPI(ctx, dexOutputFile, outputFile) j.initHiddenAPI(ctx, dexOutputFile, outputFile, j.dexProperties.Uncompress_dex)
// Encode hidden API flags in dex file. // Encode hidden API flags in dex file.
dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile, proptools.Bool(j.dexProperties.Uncompress_dex)) dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile)
j.dexJarFile = dexOutputFile j.dexJarFile = dexOutputFile
} }

View File

@@ -2121,7 +2121,7 @@ func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo
di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo) di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo)
if dexOutputPath := di.PrebuiltExportPath(module.BaseModuleName(), ".dexjar"); dexOutputPath != nil { if dexOutputPath := di.PrebuiltExportPath(module.BaseModuleName(), ".dexjar"); dexOutputPath != nil {
module.dexJarFile = dexOutputPath module.dexJarFile = dexOutputPath
module.initHiddenAPI(ctx, dexOutputPath, module.findScopePaths(apiScopePublic).stubsImplPath[0]) module.initHiddenAPI(ctx, dexOutputPath, module.findScopePaths(apiScopePublic).stubsImplPath[0], nil)
} else { } else {
// This should never happen as a variant for a prebuilt_apex is only created if the // This should never happen as a variant for a prebuilt_apex is only created if the
// prebuilt_apex has been configured to export the java library dex file. // prebuilt_apex has been configured to export the java library dex file.