diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index da24f129..f52db363 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,8 @@ name: CI on: + push: + branches: "*" pull_request: branches: [ "master" ] diff --git a/BUILD b/BUILD index 0f709ca0..eccf4277 100644 --- a/BUILD +++ b/BUILD @@ -1,4 +1,10 @@ -exports_files(["LICENSE"]) +load("@rules_jvm_external//:defs.bzl", "artifact") + +exports_files([ + "LICENSE", + ".blazeproject", + "WORKSPACE", +]) MANIFEST = "src/main/AndroidManifest.xml" @@ -6,39 +12,12 @@ MANIFEST_DEBUG = "src/main/AndroidManifestDebug.xml" PACKAGE = "com.afwsamples.testdpc" -aar_import( - name = "setupdesign", - aar = "lib/setupdesign.aar", - deps = [ - ":setupdesign_strings", - ":setupcompat", - "@maven//:com_google_android_material_material", - ], -) - -aar_import( - name = "setupcompat", - aar = "lib/setupcompat.aar", -) - -aar_import( - name = "setupdesign_strings", - aar = "lib/strings.aar", -) - -android_library( - name = "setupdesign_deps", - exports = [ - ":setupdesign", - ":setupcompat" - ], -) - android_library( name = "androidx_deps", exports = [ "@maven//:androidx_annotation_annotation", "@maven//:androidx_appcompat_appcompat", + "@maven//:androidx_collection_collection", "@maven//:androidx_core_core", "@maven//:androidx_enterprise_enterprise_feedback", "@maven//:androidx_legacy_legacy_support_v13", @@ -48,7 +27,6 @@ android_library( "@maven//:androidx_localbroadcastmanager_localbroadcastmanager", "@maven//:androidx_preference_preference", "@maven//:androidx_recyclerview_recyclerview", - "@maven//:androidx_collection_collection" ], ) @@ -118,7 +96,8 @@ android_library( ":androidx_deps", ":bouncycastle_deps", ":guava_deps", - ":setupdesign_deps", + "@setupdesign//:setupdesign", + "@setupcompat//:setupcompat", ], ) @@ -136,49 +115,56 @@ java_library( srcs = ["src/test/java/com/afwsamples/testdpc/util/flags/Utils.java"], ) + android_local_test( - name = "PermissionsHelperTest", - srcs = ["src/test/java/com/afwsamples/testdpc/common/PermissionsHelperTest.java"], - manifest = MANIFEST, - deps = [ - ":testdpc_lib", - ":test_deps" - ], - custom_package = "com.afwsamples.testdpc.common" + name = "PermissionsHelperTest", + srcs = ["src/test/java/com/afwsamples/testdpc/common/PermissionsHelperTest.java"], + manifest = MANIFEST, + deps = [ + ":test_deps", + ":testdpc_lib", + "@robolectric//bazel:android-all", + ], + custom_package = "com.afwsamples.testdpc.common" ) android_local_test( - name = "AppStatesServiceTest", - srcs = ["src/test/java/com/afwsamples/testdpc/feedback/AppStatesServiceTest.java"], - manifest = MANIFEST, - deps = [ - ":testdpc_lib", - ":androidx_deps", - ":test_deps" - ], - custom_package = "com.afwsamples.testdpc.feedback" + name = "AppStatesServiceTest", + srcs = ["src/test/java/com/afwsamples/testdpc/feedback/AppStatesServiceTest.java"], + manifest = MANIFEST, + deps = [ + ":androidx_deps", + ":test_deps", + ":testdpc_lib", + "@robolectric//bazel:android-all", + ], + custom_package = "com.afwsamples.testdpc.feedback" ) android_local_test( - name = "WifiConfigUtilTest", - srcs = ["src/test/java/com/afwsamples/testdpc/policy/wifimanagement/WifiConfigUtilTest.java"], - manifest = MANIFEST, - deps = [ - ":testdpc_lib", - ":test_deps" - ], - custom_package = "com.afwsamples.testdpc.policy.wifimanagement" + name = "WifiConfigUtilTest", + srcs = ["src/test/java/com/afwsamples/testdpc/policy/wifimanagement/WifiConfigUtilTest.java"], + manifest = MANIFEST, + deps = [ + ":test_deps", + ":testdpc_lib", + "@robolectric//bazel:android-all", + ], + custom_package = "com.afwsamples.testdpc.policy.wifimanagement" ) android_local_test( - name = "GetProvisioningModeActivityTest", - srcs = ["src/test/java/com/afwsamples/testdpc/provision/GetProvisioningModeActivityTest.java"], - manifest = MANIFEST, - deps = [ - ":testdpc_lib", - ":test_deps" - ], - custom_package = "com.afwsamples.testdpc.provision" + name = "GetProvisioningModeActivityTest", + srcs = ["src/test/java/com/afwsamples/testdpc/provision/GetProvisioningModeActivityTest.java"], + manifest = MANIFEST, + test_class = "com.afwsamples.testdpc.provision.GetProvisioningModeActivityTest", + deps = [ + ":test_deps", + ":testdpc_lib", + "@maven//:org_robolectric_robolectric", + "@robolectric//bazel:android-all", + ], + custom_package = "com.afwsamples.testdpc.provision" ) java_test( @@ -186,9 +172,9 @@ java_test( size = "small", srcs = ["src/test/java/com/afwsamples/testdpc/util/flags/BooleanParserTest.java"], deps = [ + ":test_deps", ":test_utils", ":testdpc_lib", - ":test_deps" ], ) @@ -197,9 +183,9 @@ java_test( size = "small", srcs = ["src/test/java/com/afwsamples/testdpc/util/flags/ByteParserTest.java"], deps = [ + ":test_deps", ":test_utils", ":testdpc_lib", - ":test_deps" ], ) @@ -208,9 +194,9 @@ java_test( size = "small", srcs = ["src/test/java/com/afwsamples/testdpc/util/flags/CharParserTest.java"], deps = [ + ":test_deps", ":test_utils", ":testdpc_lib", - ":test_deps" ], ) @@ -219,9 +205,9 @@ java_test( size = "small", srcs = ["src/test/java/com/afwsamples/testdpc/util/flags/DoubleParserTest.java"], deps = [ + ":test_deps", ":test_utils", ":testdpc_lib", - ":test_deps" ], ) @@ -230,9 +216,9 @@ java_test( size = "small", srcs = ["src/test/java/com/afwsamples/testdpc/util/flags/FloatParserTest.java"], deps = [ + ":test_deps", ":test_utils", ":testdpc_lib", - ":test_deps" ], ) @@ -241,9 +227,9 @@ java_test( size = "small", srcs = ["src/test/java/com/afwsamples/testdpc/util/flags/IntParserTest.java"], deps = [ + ":test_deps", ":test_utils", ":testdpc_lib", - ":test_deps" ], ) @@ -252,9 +238,9 @@ java_test( size = "small", srcs = ["src/test/java/com/afwsamples/testdpc/util/flags/LongParserTest.java"], deps = [ + ":test_deps", ":test_utils", ":testdpc_lib", - ":test_deps" ], ) @@ -263,9 +249,9 @@ java_test( size = "small", srcs = ["src/test/java/com/afwsamples/testdpc/util/flags/ShortParserTest.java"], deps = [ + ":test_deps", ":test_utils", ":testdpc_lib", - ":test_deps" ], ) @@ -274,9 +260,9 @@ java_test( size = "small", srcs = ["src/test/java/com/afwsamples/testdpc/util/flags/StringParserTest.java"], deps = [ + ":test_deps", ":test_utils", ":testdpc_lib", - ":test_deps" ], ) @@ -285,9 +271,9 @@ java_test( size = "small", srcs = ["src/test/java/com/afwsamples/testdpc/util/flags/CustomParserTest.java"], deps = [ + ":test_deps", ":test_utils", ":testdpc_lib", - ":test_deps" ], ) @@ -296,9 +282,9 @@ java_test( size = "small", srcs = ["src/test/java/com/afwsamples/testdpc/util/flags/CallbackTest.java"], deps = [ + ":test_deps", ":test_utils", ":testdpc_lib", - ":test_deps" ], ) @@ -307,9 +293,9 @@ java_test( size = "small", srcs = ["src/test/java/com/afwsamples/testdpc/util/flags/HelpTextGenerationTest.java"], deps = [ + ":test_deps", ":test_utils", ":testdpc_lib", - ":test_deps" ], ) @@ -318,9 +304,9 @@ java_test( size = "small", srcs = ["src/test/java/com/afwsamples/testdpc/util/flags/InvalidCallsTest.java"], deps = [ + ":test_deps", ":test_utils", ":testdpc_lib", - ":test_deps" ], ) @@ -329,9 +315,9 @@ java_test( size = "small", srcs = ["src/test/java/com/afwsamples/testdpc/util/flags/ParamTest.java"], deps = [ + ":test_deps", ":test_utils", ":testdpc_lib", - ":test_deps" ], ) @@ -340,8 +326,8 @@ java_test( size = "small", srcs = ["src/test/java/com/afwsamples/testdpc/util/flags/RegistrationTest.java"], deps = [ + ":test_deps", ":test_utils", ":testdpc_lib", - ":test_deps" ], -) \ No newline at end of file +) diff --git a/README.md b/README.md index df0df5b7..f51c4487 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Provisioning You can find various kinds of provisioning methods [here](https://developers.google.com/android/work/prov-devices#Key_provisioning_differences_across_android_releases). Let's take a few of them as an example. -#### QR code provisioing (Device Owner N+ only) #### +#### QR code provisioning (Device Owner N+ only) #### 1. Factory reset your device and tap the welcome screen in setup wizard 6 times. 2. The setup wizard prompts the user to connect to the Internet so the setup wizard can download a QR code reader. 3. Modify (if needed) and scan [this QR code] (http://down-box.appspot.com/qr/nQB0tw7b). @@ -68,7 +68,7 @@ Android Studio import --------------------- To import this repository in Android Studio, you need to use the -[Bazel for IntelliJ](https://plugins.jetbrains.com/plugin/8609-bazel-for-intellij) +[Bazel for Android Studio](https://plugins.jetbrains.com/plugin/9185-bazel-for-android-studio) Plugin. When importing the project you have to select the folder containing the Bazel's @@ -78,11 +78,20 @@ this repository. Once Bazel has complete the import operation and the first sync of the project, you can create a "Run Configuration". -Select "Bazel Command" as Configuration type and add `//:testdpc` as +Select "Bazel Command" as Configuration type and add `//:testdpc` as "target expression". You can now run the project from inside Android Studio. + +Building with Bazel +------------------- + +The repository includes a `build.sh` script to build the application. The required +[setupdesign library](https://android.googlesource.com/platform/external/setupdesign/+/refs/heads/main) +is now imported and patched dynamically using the command line utility `ed`. This needs to be +available on the path to successfully build the project. + Support ------- diff --git a/WORKSPACE b/WORKSPACE index e91a364a..793ea3f4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,18 +1,22 @@ +workspace(name = "testdpc") + android_sdk_repository( name = "androidsdk", api_level = 34, ) load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external") + +RULES_JVM_EXTERNAL_TAG = "4.5" -RULES_JVM_EXTERNAL_TAG = "4.2" -RULES_JVM_EXTERNAL_SHA = "cd1a77b7b02e8e008439ca76fd34f5b07aecb8c752961f9640dea15e9e5ba1ca" +RULES_JVM_EXTERNAL_SHA = "b17d7388feb9bfa7f2fa09031b32707df529f26c91ab9e5d909eb1676badd9a6" http_archive( name = "rules_jvm_external", - strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, - sha256 = RULES_JVM_EXTERNAL_SHA, - url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG, + sha256 = "d31e369b854322ca5098ea12c69d7175ded971435e55c18dd9dd5f29cc5249ac", + strip_prefix = "rules_jvm_external-5.3", + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/5.3/rules_jvm_external-5.3.tar.gz", ) load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps") @@ -24,6 +28,7 @@ load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup") rules_jvm_external_setup() load("@rules_jvm_external//:defs.bzl", "maven_install") +load("@rules_jvm_external//:specs.bzl", "maven") http_archive( name = "robolectric", @@ -36,10 +41,12 @@ load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories") robolectric_repositories() maven_install( + name = "maven", artifacts = [ - "androidx.annotation:annotation:1.3.0", + "androidx.annotation:annotation:1.5.0", "androidx.appcompat:appcompat:1.6.1", "androidx.appcompat:appcompat-resources:1.6.1", + "androidx.collection:collection:1.2.0", "androidx.constraintlayout:constraintlayout:2.1.3", "androidx.core:core:1.6.0", "androidx.enterprise:enterprise-feedback:1.1.0", @@ -51,19 +58,47 @@ maven_install( "androidx.localbroadcastmanager:localbroadcastmanager:1.1.0", "androidx.preference:preference:1.1.0", "androidx.recyclerview:recyclerview:1.2.0", - "androidx.collection:collection:1.2.0", - "com.google.android.material:material:1.5.0", + "androidx.test:core:1.5.0", + "androidx.test:monitor:1.6.0", + "androidx.test:runner:1.5.0", + "androidx.window:window:1.2.0", + "com.google.android.material:material:1.6.1", "com.google.guava:guava:31.1-android", + "com.google.testparameterinjector:test-parameter-injector:1.15", + "com.google.errorprone:error_prone_annotations:2.26.1", + "junit:junit:4.13.2", + "javax.inject:javax.inject:1", + "org.hamcrest:java-hamcrest:2.0.0.0", + "org.robolectric:robolectric-annotations:3.3.2", + "org.robolectric:shadows-core:3.3.2", "org.bouncycastle:bcpkix-jdk15on:1.70", "org.bouncycastle:bcprov-jdk15on:1.70", - "org.bouncycastle:bcprov-jdk15on:1.70", "org.robolectric:robolectric:4.2", - "com.google.truth:truth:1.4.2", - "androidx.test:core:1.5.0", - "com.google.testparameterinjector:test-parameter-injector:1.15" + "com.google.truth:truth:1.4.2" ], repositories = [ "https://maven.google.com", "https://repo1.maven.org/maven2", ], + # for androidx.annotation 1.5.0. 1.6.0+ uses gradle module metadata + # which rules_jvm_external cannot resolve yet, see + # https://github.com/bazelbuild/rules_jvm_external/issues/909 + version_conflict_policy = "pinned", +) + +http_archive( + name = "setupdesign", + build_file = "@//:setupdesign.BUILD", + url = "https://android.googlesource.com/platform/external/setupdesign/+archive/4634dac90e3c09a78c2fcdfcb16ab9cb16265527.tar.gz", +) + +http_archive( + name = "setupcompat", + build_file = "@//:setupcompat.BUILD", + # Patch source code to avoid "cannot infer type arguments for Creator" in 2 files + patch_cmds = [ + "ed -s main/java/com/google/android/setupcompat/logging/ScreenKey.java <<<$',s/Creator<>/Creator/g\nw'", + "ed -s main/java/com/google/android/setupcompat/logging/SetupMetric.java <<<$',s/Creator<>/Creator/g\nw'", + ], + url = "https://android.googlesource.com/platform/external/setupcompat/+archive/2ce41c8f4de550b5186233cec0a722dd0ffd9a84.tar.gz", ) diff --git a/lib/setupcompat.aar b/lib/setupcompat.aar deleted file mode 100755 index b3a6e713..00000000 Binary files a/lib/setupcompat.aar and /dev/null differ diff --git a/lib/setupdesign.aar b/lib/setupdesign.aar deleted file mode 100755 index fabe684f..00000000 Binary files a/lib/setupdesign.aar and /dev/null differ diff --git a/lib/strings.aar b/lib/strings.aar deleted file mode 100755 index 432aed43..00000000 Binary files a/lib/strings.aar and /dev/null differ diff --git a/setupcompat.BUILD b/setupcompat.BUILD new file mode 100644 index 00000000..66a473f5 --- /dev/null +++ b/setupcompat.BUILD @@ -0,0 +1,58 @@ +android_library( + name = "setupcompat", + srcs = glob([ + "main/java/**/*.java", + "main/java/**/*.kt", + ], exclude = ["partnerconfig/**"]), + custom_package = "com.google.android.setupcompat", + idl_import_root = "external/setupcompat/main/aidl", + idl_parcelables = [ + "main/aidl/com/google/android/setupcompat/portal/NotificationComponent.aidl", + "main/aidl/com/google/android/setupcompat/portal/ProgressServiceComponent.aidl", + ], + idl_srcs = [ + "main/aidl/com/google/android/setupcompat/ISetupCompatService.aidl", + "main/aidl/com/google/android/setupcompat/portal/IPortalProgressCallback.aidl", + "main/aidl/com/google/android/setupcompat/portal/IPortalProgressService.aidl", + "main/aidl/com/google/android/setupcompat/portal/IPortalRegisterResultListener.aidl", + "main/aidl/com/google/android/setupcompat/portal/ISetupNotificationService.aidl", + "main/aidl/com/google/android/setupcompat/portal/v1_1/IPortalProgressCallback.aidl", + ], + manifest = "AndroidManifest.xml", + proguard_specs = ["proguard.flags"], + resource_files = glob([ + "main/res/**", + ]), + deps = [ + ":partnerconfig", + "@maven//:androidx_annotation_annotation", + "@maven//:com_google_errorprone_error_prone_annotations", + ], + visibility = ["//visibility:public"], +) + +android_library( + name = "partnerconfig", + srcs = glob([ + "partnerconfig/java/**/*.java", + ]), + custom_package = "com.google.android.setupcompat.partnerconfig", + exports_manifest = 1, + manifest = "partnerconfig/AndroidManifest.xml", + deps = [ + ":setupcompat_util", + "@maven//:androidx_annotation_annotation", + "@maven//:androidx_window_window", + ], + visibility = ["//visibility:public"], +) + +android_library( + name = "setupcompat_util", + srcs = ["main/java/com/google/android/setupcompat/util/BuildCompatUtils.java"], + custom_package = "com.google.android.setupcompat", + manifest = "AndroidManifest.xml", + deps = [ + "@maven//:androidx_annotation_annotation", + ], +) diff --git a/setupdesign.BUILD b/setupdesign.BUILD new file mode 100644 index 00000000..d713fb00 --- /dev/null +++ b/setupdesign.BUILD @@ -0,0 +1,41 @@ +android_library( + name = "setupdesign", + srcs = glob([ + "main/src/**/*.java", + ]), + custom_package = "com.google.android.setupdesign", + exports_manifest = 1, + manifest = "main/AndroidManifest.xml", + proguard_specs = [ + "proguard.flags", + ], + resource_files = glob( + [ + "main/res/**", + ], + exclude_directories = 1, + ), + + deps = [ + ":setupdesign_strings", + "@setupcompat//:setupcompat", + "@setupcompat//:partnerconfig", + "@maven//:com_google_android_material_material", + "@maven//:androidx_annotation_annotation", + "@maven//:androidx_appcompat_appcompat", + "@maven//:androidx_recyclerview_recyclerview", + "@maven//:androidx_window_window", + "@maven//:androidx_core_core", + "@maven//:androidx_customview_customview", + "@maven//:androidx_fragment_fragment", + "@maven//:androidx_vectordrawable_vectordrawable", + "@maven//:com_google_errorprone_error_prone_annotations", + ], + visibility = ["//visibility:public"], +) + +android_library( + name = "setupdesign_strings", + manifest = "strings/AndroidManifest.xml", + resource_files = glob(["strings/res/**"]), +) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 9627553c..63da92b7 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -74,7 +74,8 @@ android:icon="@drawable/ic_launcher" android:banner="@drawable/ic_launcher" android:theme="@style/AppTheme" - android:label="@string/app_name"> + android:label="@string/app_name" + tools:remove="android:appComponentFactory" > + app:sucHeaderText="@string/add_account" + app:sucUsePartnerResource="true"> + app:sucHeaderText="@string/finish_setup" + app:sucUsePartnerResource="true"> + app:sucHeaderText="@string/set_up_management_header" + app:sucUsePartnerResource="true">