1// Copyright 2020 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
18	"android/soong/android"
19	"android/soong/java/config"
20)
21
22var legacyCorePlatformApiModules = []string{
23	"ArcSettings",
24	"BTTestApp",
25	"CapCtrlInterface",
26	"com.qti.location.sdk",
27	"face-V1-0-javalib",
28	"FloralClocks",
29	"framework-jobscheduler",
30	"framework-minus-apex",
31	"framework-minus-apex-headers",
32	"framework-minus-apex-intdefs",
33	"FrameworksCoreTests",
34	"HelloOslo",
35	"izat.lib.glue",
36	"mediatek-ims-base",
37	"ModemTestMode",
38	"MtkCapCtrl",
39	"my.tests.snapdragonsdktest",
40	"NetworkSetting",
41	"PerformanceMode",
42	"pxp-monitor",
43	"QColor",
44	"qcom.fmradio",
45	"Qmmi",
46	"QPerformance",
47	"sam",
48	"saminterfacelibrary",
49	"sammanagerlibrary",
50	"services",
51	"services.core.unboosted",
52	"Settings-core",
53	"SettingsGoogle",
54	"SettingsGoogleOverlayCoral",
55	"SettingsGoogleOverlayFlame",
56	"SettingsLib",
57	"SettingsRoboTests",
58	"SimContact",
59	"SimContacts",
60	"SimSettings",
61	"tcmiface",
62	"telephony-common",
63	"TeleService",
64	"UxPerformance",
65	"WfdCommon",
66}
67
68var legacyCorePlatformApiLookup = make(map[string]struct{})
69
70func init() {
71	for _, module := range legacyCorePlatformApiModules {
72		legacyCorePlatformApiLookup[module] = struct{}{}
73	}
74}
75
76var legacyCorePlatformApiLookupKey = android.NewOnceKey("legacyCorePlatformApiLookup")
77
78func getLegacyCorePlatformApiLookup(config android.Config) map[string]struct{} {
79	return config.Once(legacyCorePlatformApiLookupKey, func() interface{} {
80		return legacyCorePlatformApiLookup
81	}).(map[string]struct{})
82}
83
84// useLegacyCorePlatformApi checks to see whether the supplied module name is in the list of modules
85// that are able to use the legacy core platform API and returns true if it does, false otherwise.
86//
87// This method takes the module name separately from the context as this may be being called for a
88// module that is not the target of the supplied context.
89func useLegacyCorePlatformApi(ctx android.EarlyModuleContext, moduleName string) bool {
90	lookup := getLegacyCorePlatformApiLookup(ctx.Config())
91	_, found := lookup[moduleName]
92	return found
93}
94
95func corePlatformSystemModules(ctx android.EarlyModuleContext) string {
96	if useLegacyCorePlatformApi(ctx, ctx.ModuleName()) {
97		return config.LegacyCorePlatformSystemModules
98	} else {
99		return config.StableCorePlatformSystemModules
100	}
101}
102
103func corePlatformBootclasspathLibraries(ctx android.EarlyModuleContext) []string {
104	if useLegacyCorePlatformApi(ctx, ctx.ModuleName()) {
105		return config.LegacyCorePlatformBootclasspathLibraries
106	} else {
107		return config.StableCorePlatformBootclasspathLibraries
108	}
109}
110