Merge "Make uncompressDex available for use through hiddenAPIModule" into sc-dev

This commit is contained in:
Paul Duffin 2021-05-18 10:40:43 +00:00 committed by Android (Google) Code Review
commit 6acb50e5a3
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.
j.initHiddenAPI(ctx, dexOutputFile, j.implementationJarFile)
j.initHiddenAPI(ctx, dexOutputFile, j.implementationJarFile, j.dexProperties.Uncompress_dex)
// 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
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
// 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.

View File

@ -1309,7 +1309,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.dexJarFile = dexOutputPath
// Initialize the hiddenapi structure.
j.initHiddenAPI(ctx, dexOutputPath, outputFile)
j.initHiddenAPI(ctx, dexOutputPath, outputFile, nil)
} else {
// 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.
@ -1341,10 +1341,10 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}
// 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.
dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile, proptools.Bool(j.dexProperties.Uncompress_dex))
dexOutputFile = j.hiddenAPIEncodeDex(ctx, 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)
if dexOutputPath := di.PrebuiltExportPath(module.BaseModuleName(), ".dexjar"); dexOutputPath != nil {
module.dexJarFile = dexOutputPath
module.initHiddenAPI(ctx, dexOutputPath, module.findScopePaths(apiScopePublic).stubsImplPath[0])
module.initHiddenAPI(ctx, dexOutputPath, module.findScopePaths(apiScopePublic).stubsImplPath[0], nil)
} else {
// 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.