Convert Settings to Android.bp

See build/soong/README.md for more information.

Test: m checkbuild
Test: m RunSettingsRoboTests-jacoco
Change-Id: I267534c095c30833f77273dbdb1893b7830ed45d
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..fb1a802
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,65 @@
+java_library {
+    name: "settings-logtags",
+    srcs: ["src/**/*.logtags"],
+}
+
+// Build the Settings APK
+android_library {
+    name: "Settings-core",
+    platform_apis: true,
+    defaults: [
+        "SettingsLibDefaults",
+        "SettingsLib-search-defaults",
+    ],
+
+    srcs: ["src/**/*.java"],
+
+    static_libs: [
+        "androidx-constraintlayout_constraintlayout",
+        "androidx.slice_slice-builders",
+        "androidx.slice_slice-core",
+        "androidx.slice_slice-view",
+        "androidx.core_core",
+        "androidx.appcompat_appcompat",
+        "androidx.cardview_cardview",
+        "androidx.preference_preference",
+        "androidx.recyclerview_recyclerview",
+        "com.google.android.material_material",
+        "setupcompat",
+        "setupdesign",
+        "androidx-constraintlayout_constraintlayout-solver",
+        "androidx.lifecycle_lifecycle-runtime",
+        "androidx.lifecycle_lifecycle-extensions",
+        "guava",
+        "jsr305",
+        "settings-contextual-card-protos-lite",
+        "settings-log-bridge-protos-lite",
+        "contextualcards",
+        "settings-logtags",
+        "zxing-core-1.7",
+    ],
+
+    libs: [
+        "telephony-common",
+        "ims-common",
+    ],
+}
+
+android_app {
+    name: "Settings",
+    platform_apis: true,
+    certificate: "platform",
+    product_specific: true,
+    privileged: true,
+    required: ["privapp_whitelist_com.android.settings"],
+    static_libs: ["Settings-core"],
+    resource_dirs: [],
+    optimize: {
+        proguard_flags_files: ["proguard.flags"],
+    },
+}
+
+android_library_import {
+    name: "contextualcards",
+    aars: ["libs/contextualcards.aar"],
+}
diff --git a/Android.mk b/Android.mk
deleted file mode 100644
index 906cfc7..0000000
--- a/Android.mk
+++ /dev/null
@@ -1,78 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-        $(call all-logtags-files-under, src)
-
-LOCAL_MODULE := settings-logtags
-
-include $(BUILD_STATIC_JAVA_LIBRARY)
-
-# Build the Settings APK
-include $(CLEAR_VARS)
-
-LOCAL_PACKAGE_NAME := Settings
-LOCAL_PRIVATE_PLATFORM_APIS := true
-LOCAL_CERTIFICATE := platform
-LOCAL_PRODUCT_MODULE := true
-LOCAL_PRIVILEGED_MODULE := true
-LOCAL_REQUIRED_MODULES := privapp_whitelist_com.android.settings
-LOCAL_MODULE_TAGS := optional
-LOCAL_USE_AAPT2 := true
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_STATIC_ANDROID_LIBRARIES := \
-    androidx-constraintlayout_constraintlayout \
-    androidx.slice_slice-builders \
-    androidx.slice_slice-core \
-    androidx.slice_slice-view \
-    androidx.core_core \
-    androidx.appcompat_appcompat \
-    androidx.cardview_cardview \
-    androidx.preference_preference \
-    androidx.recyclerview_recyclerview \
-    com.google.android.material_material \
-    setupcompat \
-    setupdesign
-
-LOCAL_JAVA_LIBRARIES := \
-    telephony-common \
-    ims-common
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
-    androidx-constraintlayout_constraintlayout-solver \
-    androidx.lifecycle_lifecycle-runtime \
-    androidx.lifecycle_lifecycle-extensions \
-    guava \
-    jsr305 \
-    settings-contextual-card-protos-lite \
-    settings-log-bridge-protos-lite \
-    contextualcards \
-    settings-logtags \
-    zxing-core-1.7
-
-LOCAL_PROGUARD_FLAG_FILES := proguard.flags
-
-ifneq ($(INCREMENTAL_BUILDS),)
-    LOCAL_PROGUARD_ENABLED := disabled
-    LOCAL_JACK_ENABLED := incremental
-    LOCAL_JACK_FLAGS := --multi-dex native
-endif
-
-include frameworks/base/packages/SettingsLib/common.mk
-include frameworks/base/packages/SettingsLib/search/common.mk
-
-include $(BUILD_PACKAGE)
-
-# ====  prebuilt library  ========================
-include $(CLEAR_VARS)
-
-LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
-    contextualcards:libs/contextualcards.aar
-include $(BUILD_MULTI_PREBUILT)
-
-# Use the following include to make our test apk.
-ifeq (,$(ONE_SHOT_MAKEFILE))
-include $(call all-makefiles-under,$(LOCAL_PATH))
-endif
diff --git a/tests/Android.mk b/tests/Android.mk
deleted file mode 100644
index fd297e3..0000000
--- a/tests/Android.mk
+++ /dev/null
@@ -1,5 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-# Include all makefiles in subdirectories
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tests/anomaly-tester/Android.bp b/tests/anomaly-tester/Android.bp
new file mode 100644
index 0000000..29181af
--- /dev/null
+++ b/tests/anomaly-tester/Android.bp
@@ -0,0 +1,24 @@
+android_test {
+    name: "AnomalyTester",
+
+    certificate: "platform",
+
+    libs: ["android.test.runner"],
+
+    static_libs: [
+        "androidx.test.rules",
+        "mockito-target",
+        "ub-uiautomator",
+        "truth-prebuilt",
+    ],
+
+    srcs: ["**/*.java"],
+
+    optimize: {
+        enabled: false,
+    },
+
+    platform_apis: true,
+
+    instrumentation_for: "Settings",
+}
diff --git a/tests/anomaly-tester/Android.mk b/tests/anomaly-tester/Android.mk
deleted file mode 100644
index 4dffeab..0000000
--- a/tests/anomaly-tester/Android.mk
+++ /dev/null
@@ -1,26 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-LOCAL_CERTIFICATE := platform
-
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
-    androidx.test.rules \
-    mockito-target \
-    ub-uiautomator \
-    truth-prebuilt \
-
-LOCAL_SRC_FILES := $(call all-subdir-java-files)
-
-LOCAL_PROGUARD_ENABLED := disabled
-
-LOCAL_PACKAGE_NAME := AnomalyTester
-LOCAL_PRIVATE_PLATFORM_APIS := true
-
-LOCAL_INSTRUMENTATION_FOR := Settings
-
-LOCAL_USE_AAPT2 := true
-
-include $(BUILD_PACKAGE)
diff --git a/tests/robotests/Android.bp b/tests/robotests/Android.bp
new file mode 100644
index 0000000..a86834f
--- /dev/null
+++ b/tests/robotests/Android.bp
@@ -0,0 +1,77 @@
+//############################################################
+// Build SettingsRoboTestStub.apk which includes test-only resources.#
+//############################################################
+
+android_app {
+    name: "SettingsRoboTestStub",
+    defaults: [
+        "SettingsLibDefaults",
+        "SettingsLib-search-defaults",
+    ],
+    platform_apis: true,
+    certificate: "platform",
+    privileged: true,
+
+    resource_dirs: ["res"],
+
+    static_libs: [
+        "Settings-core",
+        "androidx-constraintlayout_constraintlayout",
+        "androidx.slice_slice-builders",
+        "androidx.slice_slice-core",
+        "androidx.slice_slice-view",
+        "androidx.core_core",
+        "androidx.appcompat_appcompat",
+        "androidx.cardview_cardview",
+        "androidx.preference_preference",
+        "androidx.recyclerview_recyclerview",
+        "com.google.android.material_material",
+        "setupcompat",
+        "setupdesign",
+        "androidx-constraintlayout_constraintlayout-solver",
+        "androidx.lifecycle_lifecycle-runtime",
+        "androidx.lifecycle_lifecycle-extensions",
+        "guava",
+        "jsr305",
+        "settings-contextual-card-protos-lite",
+        "settings-log-bridge-protos-lite",
+        "contextualcards",
+        "settings-logtags",
+        "zxing-core-1.7",
+    ],
+
+    aaptflags: ["--extra-packages com.android.settings"],
+
+    libs: [
+        "telephony-common",
+        "ims-common",
+    ],
+}
+
+//############################################################
+// Settings Robolectric test target.                         #
+//############################################################
+android_robolectric_test {
+    name: "SettingsRoboTests",
+    srcs: [
+        "src/**/*.java",
+    ],
+
+    static_libs: [
+        "SettingsLib-robo-testutils",
+    ],
+
+    java_resource_dirs: ["config"],
+
+    instrumentation_for: "SettingsRoboTestStub",
+
+    test_options: {
+        timeout: "36000",
+    },
+
+    coverage_libs: [
+        "Settings-core",
+        "SettingsLib",
+        "SettingsLib-search",
+    ],
+}
diff --git a/tests/robotests/Android.mk b/tests/robotests/Android.mk
deleted file mode 100644
index 727da06..0000000
--- a/tests/robotests/Android.mk
+++ /dev/null
@@ -1,111 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-SETTINGS_AOSP_PATH := packages/apps/Settings
-
-#############################################################
-# Build SettingsRoboTestStub.apk which includes test-only resources.#
-#############################################################
-include $(CLEAR_VARS)
-
-LOCAL_PACKAGE_NAME := SettingsRoboTestStub
-LOCAL_PRIVATE_PLATFORM_APIS := true
-LOCAL_CERTIFICATE := platform
-LOCAL_PRIVILEGED_MODULE := true
-LOCAL_MODULE_TAGS := optional
-LOCAL_USE_AAPT2 := true
-
-RELATIVE_SETTINGS_AOSP_PATH := ../../../../../$(SETTINGS_AOSP_PATH)
-
-LOCAL_MANIFEST_FILE := $(RELATIVE_SETTINGS_AOSP_PATH)/AndroidManifest.xml
-
-LOCAL_SRC_FILES := $(call all-java-files-under, $(RELATIVE_SETTINGS_AOSP_PATH)/src)
-
-LOCAL_RESOURCE_DIR += \
-	$(LOCAL_PATH)/res \
-	$(SETTINGS_AOSP_PATH)/res
-
-LOCAL_STATIC_ANDROID_LIBRARIES := \
-    androidx-constraintlayout_constraintlayout \
-    androidx.slice_slice-builders \
-    androidx.slice_slice-core \
-    androidx.slice_slice-view \
-    androidx.core_core \
-    androidx.appcompat_appcompat \
-    androidx.cardview_cardview \
-    androidx.preference_preference \
-    androidx.recyclerview_recyclerview \
-    com.google.android.material_material \
-    setupcompat \
-    setupdesign
-
-LOCAL_JAVA_LIBRARIES := \
-    telephony-common \
-    ims-common
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
-    androidx-constraintlayout_constraintlayout-solver \
-    androidx.lifecycle_lifecycle-runtime \
-    androidx.lifecycle_lifecycle-extensions \
-    guava \
-    jsr305 \
-    settings-contextual-card-protos-lite \
-    settings-log-bridge-protos-lite \
-    contextualcards \
-    settings-logtags \
-    zxing-core-1.7
-
-include frameworks/base/packages/SettingsLib/common.mk
-include frameworks/base/packages/SettingsLib/search/common.mk
-
-include $(BUILD_PACKAGE)
-
-#############################################################
-# Settings Robolectric test target.                         #
-#############################################################
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := SettingsRoboTests
-LOCAL_MODULE_CLASS := JAVA_LIBRARIES
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src) \
-    $(call all-java-files-under, ../../../../../frameworks/base/packages/SettingsLib/tests/robotests/src/com/android/settingslib/testutils)
-
-LOCAL_JAVA_RESOURCE_DIRS := config
-
-LOCAL_JAVA_LIBRARIES := \
-    robolectric_android-all-stub \
-    Robolectric_all-target \
-    mockito-robolectric-prebuilt \
-    truth-prebuilt
-
-LOCAL_INSTRUMENTATION_FOR := SettingsRoboTestStub
-
-LOCAL_MODULE_TAGS := optional
-
-# Generate test_config.properties
-include external/robolectric-shadows/gen_test_config.mk
-
-include $(BUILD_STATIC_JAVA_LIBRARY)
-
-#############################################################
-# Settings runner target to run the previous target.        #
-#############################################################
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := RunSettingsRoboTests
-
-LOCAL_JAVA_LIBRARIES := \
-    SettingsRoboTests \
-    robolectric_android-all-stub \
-    Robolectric_all-target \
-    mockito-robolectric-prebuilt \
-    truth-prebuilt
-
-LOCAL_TEST_PACKAGE := SettingsRoboTestStub
-
-LOCAL_INSTRUMENT_SOURCE_DIRS := $(dir $(LOCAL_PATH))../src \
-    frameworks/base/packages/SettingsLib/search/src \
-
-LOCAL_ROBOTEST_TIMEOUT := 36000
-
-include external/robolectric-shadows/run_robotests.mk
diff --git a/tests/robotests/AndroidManifest.xml b/tests/robotests/AndroidManifest.xml
new file mode 100644
index 0000000..e0050ef
--- /dev/null
+++ b/tests/robotests/AndroidManifest.xml
@@ -0,0 +1,8 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+          xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
+	  coreApp="true"
+          package="com.android.settings">
+
+    <application/>
+
+</manifest>
diff --git a/tests/uitests/Android.bp b/tests/uitests/Android.bp
new file mode 100644
index 0000000..8a3e374
--- /dev/null
+++ b/tests/uitests/Android.bp
@@ -0,0 +1,41 @@
+// Copyright (C) 2018 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+android_test {
+    name: "SettingsUITests",
+    platform_apis: true,
+    certificate: "platform",
+    test_suites: ["device-tests"],
+    srcs: ["src/**/*.java"],
+
+    libs: [
+        "android.test.runner",
+        "android.test.base",
+    ],
+
+    static_libs: [
+        "androidx.test.rules",
+        "app-helpers-core",
+        "launcher-helper-lib",
+        "metrics-helper-lib",
+        "platform-test-annotations",
+        "settings-helper",
+        "sysui-helper",
+        "timeresult-helper-lib",
+        "truth-prebuilt",
+        "ub-uiautomator",
+    ],
+
+    //sdk_version: "current",
+}
diff --git a/tests/uitests/Android.mk b/tests/uitests/Android.mk
deleted file mode 100644
index fb7258c..0000000
--- a/tests/uitests/Android.mk
+++ /dev/null
@@ -1,43 +0,0 @@
-# Copyright (C) 2018 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_PACKAGE_NAME := SettingsUITests
-LOCAL_PRIVATE_PLATFORM_APIS := true
-LOCAL_CERTIFICATE := platform
-LOCAL_COMPATIBILITY_SUITE := device-tests
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_JAVA_LIBRARIES := \
-    android.test.runner \
-    android.test.base
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
-    androidx.test.rules \
-    app-helpers-core \
-    launcher-helper-lib \
-    metrics-helper-lib \
-    platform-test-annotations \
-    settings-helper \
-    sysui-helper \
-    timeresult-helper-lib \
-    truth-prebuilt \
-    ub-uiautomator \
-
-#LOCAL_SDK_VERSION := current
-
-include $(BUILD_PACKAGE)
diff --git a/tests/unit/Android.bp b/tests/unit/Android.bp
new file mode 100644
index 0000000..43bf02c
--- /dev/null
+++ b/tests/unit/Android.bp
@@ -0,0 +1,32 @@
+android_test {
+    name: "SettingsUnitTests",
+
+    certificate: "platform",
+
+    libs: [
+        "android.test.runner",
+        "telephony-common",
+        "ims-common",
+        "android.test.base",
+        "android.test.mock",
+    ],
+
+    static_libs: [
+        "androidx.test.rules",
+        "androidx.test.espresso.core",
+        "androidx.test.espresso.contrib-nodeps",
+        "androidx.test.espresso.intents-nodeps",
+        "mockito-target-minus-junit4",
+        "platform-test-annotations",
+        "truth-prebuilt",
+        "ub-uiautomator",
+    ],
+
+    // Include all test java files.
+    srcs: ["src/**/*.java"],
+
+    platform_apis: true,
+    test_suites: ["device-tests"],
+
+    instrumentation_for: "Settings",
+}
diff --git a/tests/unit/Android.mk b/tests/unit/Android.mk
deleted file mode 100644
index 35d2205..0000000
--- a/tests/unit/Android.mk
+++ /dev/null
@@ -1,35 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-# We only want this apk build for tests.
-LOCAL_MODULE_TAGS := tests
-LOCAL_CERTIFICATE := platform
-
-LOCAL_JAVA_LIBRARIES := \
-    android.test.runner \
-    telephony-common \
-    ims-common \
-    android.test.base \
-    android.test.mock \
-
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
-    androidx.test.rules \
-    androidx.test.espresso.core \
-    androidx.test.espresso.contrib-nodeps \
-    androidx.test.espresso.intents-nodeps \
-    mockito-target-minus-junit4 \
-    platform-test-annotations \
-    truth-prebuilt \
-    ub-uiautomator
-
-# Include all test java files.
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_PACKAGE_NAME := SettingsUnitTests
-LOCAL_PRIVATE_PLATFORM_APIS := true
-LOCAL_COMPATIBILITY_SUITE := device-tests
-
-LOCAL_INSTRUMENTATION_FOR := Settings
-
-include $(BUILD_PACKAGE)