Convert ManagedProvisioning to Android.bp

A build system issue causing the linked bug
was only fixed in Android.bp files.

Switch from android.mk to android.bp files.

Bug: 174288414
Test: Compiling all targets and running robotests
Change-Id: I212781ab66e4238f7374dd1fb0ad344c934fc037
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..6f6abfc
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,41 @@
+java_library {
+    name: "managedprovisioning_protoslite",
+    srcs: ["proto/**/*.proto"],
+    proto: {
+        type: "lite",
+    },
+}
+
+android_app {
+    name: "ManagedProvisioning",
+
+    libs: ["android.car"],
+
+    static_libs: [
+        "androidx.legacy_legacy-support-v4",
+        "car-ui-lib",
+        "setupcompat",
+        "setupdesign",
+        "devicepolicyprotosnano",
+        "managedprovisioning_protoslite",
+    ],
+
+    srcs: [
+        "src/**/*.java",
+        "src/**/I*.aidl",
+    ],
+
+    resource_dirs: ["res"],
+
+    platform_apis: true,
+    certificate: "platform",
+    privileged: true,
+    optimize: {
+        proguard_flags_files: ["proguard.flags"],
+    },
+
+    // Packages to be included in code coverage runs. This does not affect production builds.
+    jacoco: {
+        include_filter: ["com.android.managedprovisioning.*"],
+    },
+}
diff --git a/Android.mk b/Android.mk
deleted file mode 100644
index a62b52b..0000000
--- a/Android.mk
+++ /dev/null
@@ -1,46 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := managedprovisioning_protoslite
-LOCAL_SRC_FILES := $(call all-proto-files-under, proto)
-LOCAL_PROTOC_OPTIMIZE_TYPE := lite
-LOCAL_MODULE_TAGS := optional
-include $(BUILD_STATIC_JAVA_LIBRARY)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_JAVA_LIBRARIES += android.car
-
-LOCAL_STATIC_ANDROID_LIBRARIES += \
-        androidx.legacy_legacy-support-v4 \
-        car-ui-lib \
-        setupcompat \
-        setupdesign
-
-LOCAL_STATIC_LIBRARIES := devicepolicyprotosnano
-LOCAL_STATIC_JAVA_LIBRARIES := managedprovisioning_protoslite
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-LOCAL_SRC_FILES += $(call all-Iaidl-files-under, src)
-
-LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
-
-LOCAL_USE_AAPT2 := true
-
-LOCAL_PACKAGE_NAME := ManagedProvisioning
-LOCAL_PRIVATE_PLATFORM_APIS := true
-LOCAL_CERTIFICATE := platform
-LOCAL_PRIVILEGED_MODULE := true
-LOCAL_PROGUARD_FLAG_FILES := proguard.flags
-
-# Packages to be included in code coverage runs. This does not affect production builds.
-LOCAL_JACK_COVERAGE_INCLUDE_FILTER := com.android.managedprovisioning.*
-
-include $(BUILD_PACKAGE)
-
-# additionally, build tests if we build via mmm / mm
-ifeq (,$(ONE_SHOT_MAKEFILE))
-include $(call all-makefiles-under,$(LOCAL_PATH))
-endif
diff --git a/CleanSpec.mk b/CleanSpec.mk
deleted file mode 100644
index 8179bd3..0000000
--- a/CleanSpec.mk
+++ /dev/null
@@ -1,51 +0,0 @@
-# Copyright (C) 2007 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.
-#
-
-# If you don't need to do a full clean build but would like to touch
-# a file or delete some intermediate files, add a clean step to the end
-# of the list.  These steps will only be run once, if they haven't been
-# run before.
-#
-# E.g.:
-#     $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
-#     $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
-#
-# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
-# files that are missing or have been moved.
-#
-# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
-# Use $(OUT_DIR) to refer to the "out" directory.
-#
-# If you need to re-do something that's already mentioned, just copy
-# the command and add it to the bottom of the list.  E.g., if a change
-# that you made last week required touching a file and a change you
-# made today requires touching the same file, just copy the old
-# touch step and add it to the end of the list.
-#
-# ************************************************
-# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
-# ************************************************
-
-# For example:
-#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
-#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
-#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
-#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
-
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/ManagedProvisioningComm_intermediates)
-
-# ************************************************
-# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
-# ************************************************
diff --git a/TEST_MAPPING b/TEST_MAPPING
index 719a46a..3a82970 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -7,22 +7,11 @@
           "exclude-annotation": "androidx.test.filters.FlakyTest"
         }
       ]
-    },
-    {
-      "name": "ManagedProvisioningRoboTests",
-      "options": [
-        {
-          "exclude-annotation": "androidx.test.filters.FlakyTest"
-        }
-      ]
     }
   ],
   "postsubmit": [
     {
       "name": "ManagedProvisioningTests"
-    },
-    {
-      "name": "ManagedProvisioningRoboTests"
     }
   ]
-}
\ No newline at end of file
+}
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/instrumentation/Android.bp b/tests/instrumentation/Android.bp
new file mode 100644
index 0000000..709a8d2
--- /dev/null
+++ b/tests/instrumentation/Android.bp
@@ -0,0 +1,26 @@
+android_test {
+    name: "ManagedProvisioningTests",
+
+    libs: [
+        "android.test.runner",
+        "android.test.base",
+        "android.test.mock",
+    ],
+
+    srcs: ["src/**/*.java"],
+
+    platform_apis: true,
+    certificate: "platform",
+
+    static_libs: [
+        "androidx.test.rules",
+        "mockito-target-minus-junit4",
+        "androidx.test.espresso.core",
+        "androidx.test.espresso.intents",
+        "truth-prebuilt",
+    ],
+
+    instrumentation_for: "ManagedProvisioning",
+    test_suites: ["device-tests"],
+
+}
diff --git a/tests/instrumentation/Android.mk b/tests/instrumentation/Android.mk
deleted file mode 100644
index e3469e0..0000000
--- a/tests/instrumentation/Android.mk
+++ /dev/null
@@ -1,24 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_JAVA_LIBRARIES := android.test.runner android.test.base android.test.mock
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_PACKAGE_NAME := ManagedProvisioningTests
-LOCAL_PRIVATE_PLATFORM_APIS := true
-LOCAL_CERTIFICATE := platform
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
-    androidx.test.rules \
-    mockito-target-minus-junit4 \
-    androidx.test.espresso.core \
-    androidx.test.espresso.intents \
-    truth-prebuilt
-
-LOCAL_INSTRUMENTATION_FOR := ManagedProvisioning
-LOCAL_COMPATIBILITY_SUITE := device-tests
-
-include $(BUILD_PACKAGE)
diff --git a/tests/robotests/Android.bp b/tests/robotests/Android.bp
new file mode 100644
index 0000000..c105cff
--- /dev/null
+++ b/tests/robotests/Android.bp
@@ -0,0 +1,26 @@
+//############################################################
+// ManagedProvisioning Robolectric test target.              #
+//############################################################
+android_robolectric_test {
+
+    name: "ManagedProvisioningRoboTests",
+
+    srcs: ["src/**/*.java"],
+
+    java_resource_dirs: ["config"],
+
+    // Include the testing libraries
+    libs: [
+        "robolectric_android-all-stub",
+        "Robolectric_all-target",
+        "mockito-robolectric-prebuilt",
+        "truth-prebuilt",
+        "androidx.test.core",
+        "androidx.test.rules",
+        "androidx.core_core",
+    ],
+
+    static_libs: ["managedprovisioning_protoslite"],
+
+    instrumentation_for: "ManagedProvisioning",
+}
diff --git a/tests/robotests/Android.mk b/tests/robotests/Android.mk
deleted file mode 100644
index 8903722..0000000
--- a/tests/robotests/Android.mk
+++ /dev/null
@@ -1,57 +0,0 @@
-#############################################################
-# ManagedProvisioning Robolectric test target.              #
-#############################################################
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := ManagedProvisioningRoboTests
-LOCAL_MODULE_CLASS := JAVA_LIBRARIES
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_JAVA_RESOURCE_DIRS := config
-
-# Include the testing libraries
-LOCAL_JAVA_LIBRARIES := \
-    robolectric_android-all-stub \
-    Robolectric_all-target \
-    mockito-robolectric-prebuilt \
-    truth-prebuilt \
-    androidx.test.core \
-    androidx.test.rules \
-    androidx.core_core
-
-LOCAL_STATIC_JAVA_LIBRARIES := managedprovisioning_protoslite
-
-LOCAL_INSTRUMENTATION_FOR := ManagedProvisioning
-LOCAL_COMPATIBILITY_SUITE := general-tests
-
-LOCAL_MODULE_TAGS := optional
-
-# Generate test_config.properties
-include external/robolectric-shadows/gen_test_config.mk
-
-include $(BUILD_STATIC_JAVA_LIBRARY)
-
-#################################################################
-# ManagedProvisioning runner target to run the previous target. #
-#################################################################
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := RunManagedProvisioningRoboTests
-
-LOCAL_JAVA_LIBRARIES := \
-    ManagedProvisioningRoboTests \
-    robolectric_android-all-stub \
-    Robolectric_all-target \
-    mockito-robolectric-prebuilt \
-    truth-prebuilt \
-    androidx.test.core \
-    androidx.test.rules \
-    androidx.core_core
-
-LOCAL_TEST_PACKAGE := ManagedProvisioning
-
-LOCAL_INSTRUMENT_SOURCE_DIRS := $(dir $(LOCAL_PATH))../src
-
-include external/robolectric-shadows/run_robotests.mk
\ No newline at end of file