1# Copyright (C) 2015 The Android Open Source Project
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
15#
16# Builds a package which can be instrumented to retrieve information about the device under test.
17#
18
19DEVICE_INFO_PACKAGE := com.android.compatibility.common.deviceinfo
20DEVICE_INFO_INSTRUMENT := androidx.test.runner.AndroidJUnitRunner
21DEVICE_INFO_USES_LIBRARY := android.test.runner
22DEVICE_INFO_USES_OPTIONAL_LIBRARIES += \
23  androidx.window.extensions \
24  androidx.window.sidecar
25DEVICE_INFO_PERMISSIONS += \
26  android.permission.READ_PHONE_STATE \
27  android.permission.WRITE_EXTERNAL_STORAGE
28DEVICE_INFO_ACTIVITIES += \
29  $(DEVICE_INFO_PACKAGE).AppStandbyDeviceInfo \
30  $(DEVICE_INFO_PACKAGE).ClientIdDeviceInfo \
31  $(DEVICE_INFO_PACKAGE).ConfigurationDeviceInfo \
32  $(DEVICE_INFO_PACKAGE).CpuDeviceInfo \
33  $(DEVICE_INFO_PACKAGE).FeatureDeviceInfo \
34  $(DEVICE_INFO_PACKAGE).GenericDeviceInfo \
35  $(DEVICE_INFO_PACKAGE).GlesStubActivity \
36  $(DEVICE_INFO_PACKAGE).GraphicsDeviceInfo \
37  $(DEVICE_INFO_PACKAGE).LocaleDeviceInfo \
38  $(DEVICE_INFO_PACKAGE).MediaDeviceInfo \
39  $(DEVICE_INFO_PACKAGE).MemoryDeviceInfo \
40  $(DEVICE_INFO_PACKAGE).PackageDeviceInfo \
41  $(DEVICE_INFO_PACKAGE).ScreenDeviceInfo \
42  $(DEVICE_INFO_PACKAGE).StorageDeviceInfo \
43  $(DEVICE_INFO_PACKAGE).UserDeviceInfo \
44  $(DEVICE_INFO_PACKAGE).VintfDeviceInfo \
45  com.android.compatibility.common.util.DummyActivity
46
47ifeq ($(DEVICE_INFO_MIN_SDK),)
48DEVICE_INFO_MIN_SDK := 8
49endif
50
51ifeq ($(DEVICE_INFO_TARGET_SDK),)
52DEVICE_INFO_TARGET_SDK := 17
53endif
54
55# Add the base device info
56LOCAL_STATIC_JAVA_LIBRARIES += compatibility-device-info compatibility-device-util-axt
57
58# Generator of APK manifests.
59MANIFEST_GENERATOR_JAR := $(HOST_OUT_JAVA_LIBRARIES)/compatibility-manifest-generator.jar
60MANIFEST_GENERATOR := $(JAVA) -jar $(MANIFEST_GENERATOR_JAR)
61
62# Generate the manifest
63manifest_xml := $(call intermediates-dir-for,APPS,$(LOCAL_PACKAGE_NAME))/AndroidManifest.xml
64$(manifest_xml): PRIVATE_INFO_PERMISSIONS := $(foreach permission, $(DEVICE_INFO_PERMISSIONS),-r $(permission))
65$(manifest_xml): PRIVATE_INFO_ACTIVITIES := $(foreach activity,$(DEVICE_INFO_ACTIVITIES),-a $(activity))
66$(manifest_xml): PRIVATE_USES_LIBRARY := $(DEVICE_INFO_USES_LIBRARY)
67$(manifest_xml): PRIVATE_USES_OPTIONAL_LIBRARIES := $(foreach library,$(DEVICE_INFO_USES_OPTIONAL_LIBRARIES),-lo $(library))
68$(manifest_xml): PRIVATE_PACKAGE := $(DEVICE_INFO_PACKAGE)
69$(manifest_xml): PRIVATE_INSTRUMENT := $(DEVICE_INFO_INSTRUMENT)
70$(manifest_xml): PRIVATE_MIN_SDK := $(DEVICE_INFO_MIN_SDK)
71$(manifest_xml): PRIVATE_TARGET_SDK := $(DEVICE_INFO_TARGET_SDK)
72
73# Regenerate manifest.xml if the generator jar, */cts-device-info/Android.mk, or this file is changed.
74$(manifest_xml): $(MANIFEST_GENERATOR_JAR) $(LOCAL_PATH)/Android.mk cts/build/device_info_package.mk
75	$(hide) echo Generating manifest for $(PRIVATE_NAME)
76	$(hide) mkdir -p $(dir $@)
77	$(hide) $(MANIFEST_GENERATOR) \
78						$(PRIVATE_INFO_PERMISSIONS) \
79						$(PRIVATE_INFO_ACTIVITIES) \
80						-l $(PRIVATE_USES_LIBRARY) \
81						$(PRIVATE_USES_OPTIONAL_LIBRARIES) \
82						-p $(PRIVATE_PACKAGE) \
83						-i $(PRIVATE_INSTRUMENT) \
84						-s $(PRIVATE_MIN_SDK) \
85						-t $(PRIVATE_TARGET_SDK) \
86						-o $@
87
88# Reset variables
89DEVICE_INFO_MIN_SDK :=
90DEVICE_INFO_TARGET_SDK :=
91DEVICE_INFO_PACKAGE :=
92DEVICE_INFO_INSTRUMENT :=
93DEVICE_INFO_PERMISSIONS :=
94DEVICE_INFO_ACTIVITIES :=
95
96LOCAL_FULL_MANIFEST_FILE := $(manifest_xml)
97# Disable by default
98LOCAL_DEX_PREOPT := false
99LOCAL_PROGUARD_ENABLED := disabled
100
101# Don't include this package in any target
102LOCAL_MODULE_TAGS := optional
103# And when built explicitly put it in the data partition
104LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
105
106
107#TODO(b/72620511) remove this condition when AtsDeviceInfo can be built with SDK again
108ifneq ($(LOCAL_PRIVATE_PLATFORM_APIS),true)
109LOCAL_SDK_VERSION := current
110endif
111
112include $(BUILD_CTS_SUPPORT_PACKAGE)
113