Delete sandboxed_sdk toolbox + acls. PiperOrigin-RevId: 945796451 Change-Id: I161c8cb2f4e2361f6651b3b48d7caa6a0f413752
diff --git a/providers/providers.bzl b/providers/providers.bzl index d29f361..be82377 100644 --- a/providers/providers.bzl +++ b/providers/providers.bzl
@@ -319,50 +319,6 @@ ), ) -AndroidSandboxedSdkInfo = provider( - doc = "Provides information about a sandboxed Android SDK.", - fields = dict( - internal_apk_info = "ApkInfo for SDKs dexes and resources. Note: it cannot " + - "be installed on a device as is. It needs to be further processed by " + - "other sandboxed SDK rules.", - sdk_module_config = "The SDK Module config. For the full definition see " + - "https://github.com/google/bundletool/blob/master/src/main/proto/sdk_modules_config.proto", - sdk_api_descriptors = "Jar file with the SDK API Descriptors. This can later be used to " + - "generate sources for communicating with this SDK from the app " + - "process.", - ), -) - -AndroidArchivedSandboxedSdkInfo = provider( - doc = "Provides information about an Android Sandboxed SDK archive.", - fields = dict( - asar = "Android Sandboxed SDK archive file, as generated by Bundletool.", - sdk_api_descriptors = "Jar file with the SDK API Descriptors. This can later be used to " + - "generate sources for communicating with this SDK from the app " + - "process.", - ), -) - -AndroidSandboxedSdkBundleInfo = provider( - doc = "Provides information about a sandboxed Android SDK Bundle (ASB).", - fields = dict( - sdk_info = "AndroidSandboxedSdkInfo with information about the SDK.", - asb = "Path to the final ASB, unsigned.", - ), -) - -AndroidSandboxedSdkApkInfo = provider( - doc = "Provides information about App and Sandboxed SDK APKs.", - fields = dict( - app_apk_info = "ApkInfo for the host app.", - sandboxed_sdk_apks = "List of APKs for sandboxed SDK dependencies of the host app. " + - "Only present when compat splits are not requested. APKs are signed " + - "with debug keys.", - sandboxed_sdk_splits = "List of APK splits that contain the sandboxed SDK dependencies " + - "of the host app. Only present when compat splits are requested.", - ), -) - AndroidIdeInfo = provider( doc = "AndroidIdeInfo", fields = dict(
diff --git a/rules/acls/android_application_with_sandboxed_sdks_allowlist.bzl b/rules/acls/android_application_with_sandboxed_sdks_allowlist.bzl deleted file mode 100644 index acf1210..0000000 --- a/rules/acls/android_application_with_sandboxed_sdks_allowlist.bzl +++ /dev/null
@@ -1,23 +0,0 @@ -# Copyright 2023 The Bazel Authors. All rights reserved. -# -# 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. -"""Allow list for using sandboxed SDKs in the android_application rule.""" - -load("//rules:visibility.bzl", "PROJECT_VISIBILITY") - -visibility(PROJECT_VISIBILITY) - -# keep sorted -ANDROID_APPLICATION_WITH_SANDBOXED_SDKS_ALLOWLIST = [ - "//:__subpackages__", -]
diff --git a/rules/acls/android_binary_with_sandboxed_sdks_allowlist.bzl b/rules/acls/android_binary_with_sandboxed_sdks_allowlist.bzl deleted file mode 100644 index 2885287..0000000 --- a/rules/acls/android_binary_with_sandboxed_sdks_allowlist.bzl +++ /dev/null
@@ -1,23 +0,0 @@ -# Copyright 2023 The Bazel Authors. All rights reserved. -# -# 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. -"""Allow list of android_binary_with_sandboxed_sdks rule.""" - -load("//rules:visibility.bzl", "PROJECT_VISIBILITY") - -visibility(PROJECT_VISIBILITY) - -# keep sorted -ANDROID_BINARY_WITH_SANDBOXED_SDKS_ALLOWLIST = [ - "//:__subpackages__", -]
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/BUILD b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/BUILD deleted file mode 100644 index 4e24a11..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/BUILD +++ /dev/null
@@ -1,38 +0,0 @@ -# Common tools for managing sandboxed SDKs. -# Sandboxed SDKs are libraries that are released separately from Android apps and can run in the -# Privacy Sandbox. - -load("@rules_java//java:defs.bzl", "java_binary", "java_library") -load("//tools/jdk:jvmopts.bzl", "BASE_JVMOPTS") - -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//:__subpackages__"], -) - -licenses(["notice"]) - -java_library( - name = "sandboxed_sdk_toolbox_lib", - srcs = glob(["*.java"]), - deps = [ - "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors", - "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/clientsources", - "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/proguardspecs", - "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig", - "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest", - "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties", - "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/validatemodulesconfig", - "@rules_android_maven//:info_picocli_picocli", - ], -) - -java_binary( - name = "sandboxed_sdk_toolbox", - jvm_flags = BASE_JVMOPTS, - main_class = "com.google.devtools.build.android.sandboxedsdktoolbox.SandboxedSdkToolbox", - visibility = ["//visibility:public"], - runtime_deps = [ - ":sandboxed_sdk_toolbox_lib", - ], -)
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/SandboxedSdkToolbox.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/SandboxedSdkToolbox.java deleted file mode 100644 index 5fe6617..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/SandboxedSdkToolbox.java +++ /dev/null
@@ -1,55 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox; - -import com.google.devtools.build.android.sandboxedsdktoolbox.apidescriptors.ExtractApiDescriptorsCommand; -import com.google.devtools.build.android.sandboxedsdktoolbox.apidescriptors.ExtractApiDescriptorsFromAsarCommand; -import com.google.devtools.build.android.sandboxedsdktoolbox.clientsources.GenerateClientSourcesCommand; -import com.google.devtools.build.android.sandboxedsdktoolbox.proguardspecs.GenerateSdkProguardSpecsCommand; -import com.google.devtools.build.android.sandboxedsdktoolbox.runtimeenabledsdkconfig.GenerateRuntimeEnabledSdkConfigCommand; -import com.google.devtools.build.android.sandboxedsdktoolbox.runtimeenabledsdkconfig.GenerateRuntimeEnabledSdkTableCommand; -import com.google.devtools.build.android.sandboxedsdktoolbox.sdkdependenciesmanifest.GenerateSdkDependenciesManifestCommand; -import com.google.devtools.build.android.sandboxedsdktoolbox.sdksplitproperties.GenerateSdkSplitPropertiesCommand; -import com.google.devtools.build.android.sandboxedsdktoolbox.validatemodulesconfig.ValidateModulesConfigCommand; -import picocli.CommandLine; -import picocli.CommandLine.Command; - -/** Entrypoint for the Sandboxed SDK Toolbox binary. */ -@Command( - name = "sandboxed-sdk-toolbox", - subcommands = { - ExtractApiDescriptorsCommand.class, - ExtractApiDescriptorsFromAsarCommand.class, - GenerateClientSourcesCommand.class, - GenerateRuntimeEnabledSdkConfigCommand.class, - GenerateRuntimeEnabledSdkTableCommand.class, - GenerateSdkDependenciesManifestCommand.class, - GenerateSdkProguardSpecsCommand.class, - GenerateSdkSplitPropertiesCommand.class, - ValidateModulesConfigCommand.class, - }) -public final class SandboxedSdkToolbox { - - public static final CommandLine create() { - return new CommandLine(new SandboxedSdkToolbox()); - } - - public static final void main(String[] args) { - SandboxedSdkToolbox.create().execute(args); - } - - private SandboxedSdkToolbox() {} -}
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/BUILD b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/BUILD deleted file mode 100644 index f13cbe2..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/BUILD +++ /dev/null
@@ -1,19 +0,0 @@ -# Command to extract API descriptors from a sandboxed SDK. - -load("@rules_java//java:defs.bzl", "java_library") - -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//:__subpackages__"], -) - -licenses(["notice"]) - -java_library( - name = "apidescriptors", - srcs = glob(["*.java"]), - deps = [ - "@rules_android_maven//:androidx_privacysandbox_tools_tools_apipackager", - "@rules_android_maven//:info_picocli_picocli", - ], -)
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/ExtractApiDescriptorsCommand.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/ExtractApiDescriptorsCommand.java deleted file mode 100644 index 22882d1..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/ExtractApiDescriptorsCommand.java +++ /dev/null
@@ -1,80 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.apidescriptors; - -import static java.nio.file.Files.createTempDirectory; - -import androidx.privacysandbox.tools.apipackager.PrivacySandboxApiPackager; -import java.io.IOException; -import java.io.InputStream; -import java.io.UncheckedIOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; -import picocli.CommandLine.Command; -import picocli.CommandLine.Option; - -/** Command that Extracts API descriptors from a sandboxed SDK's classpath. */ -@Command( - name = "extract-api-descriptors", - description = "Extracts API descriptors from a sandboxed SDK's classpath.") -public final class ExtractApiDescriptorsCommand implements Runnable { - - @Option(names = "--sdk-deploy-jar", required = true) - Path sdkDeployJarPath; - - @Option(names = "--output-sdk-api-descriptors", required = true) - Path outputSdkApiDescriptorsPath; - - private final PrivacySandboxApiPackager packager = new PrivacySandboxApiPackager(); - - @Override - public void run() { - try { - Path sdkClasspath = unzipSdkDeployJar(); - packager.packageSdkDescriptors(sdkClasspath, outputSdkApiDescriptorsPath); - } catch (IOException e) { - throw new UncheckedIOException("Failed to package SDK API descriptors.", e); - } - } - - private Path unzipSdkDeployJar() throws IOException { - Path sdkClasspath = createTempDirectory("tmp-sdk-classpath"); - try (InputStream inputStream = Files.newInputStream(sdkDeployJarPath); - ZipInputStream zipInputStream = new ZipInputStream(inputStream)) { - - ZipEntry entry = null; - while ((entry = zipInputStream.getNextEntry()) != null) { - Path entryPath = sdkClasspath.resolve(entry.getName()).normalize(); - if (entry.isDirectory()) { - continue; - } - - if (!entryPath.startsWith(sdkClasspath)) { - throw new IOException( - String.format("Invalid entry name in SDK classpath zip: %s", entry.getName())); - } - - Files.createDirectories(entryPath.getParent()); - Files.copy(zipInputStream, entryPath); - } - } - return sdkClasspath; - } - - private ExtractApiDescriptorsCommand() {} -}
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/ExtractApiDescriptorsFromAsarCommand.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/ExtractApiDescriptorsFromAsarCommand.java deleted file mode 100644 index 62b09c7..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/ExtractApiDescriptorsFromAsarCommand.java +++ /dev/null
@@ -1,59 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.apidescriptors; - -import java.io.IOException; -import java.io.UncheckedIOException; -import java.net.URI; -import java.nio.file.FileSystem; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.HashMap; -import picocli.CommandLine.Command; -import picocli.CommandLine.Option; - -/** Command for extracting API descriptors from a sandboxed SDK Archive. */ -@Command( - name = "extract-api-descriptors-from-asar", - description = "Extract API descriptors from a sandboxed SDK Archive.") -public final class ExtractApiDescriptorsFromAsarCommand implements Runnable { - - private static final String API_DESCRIPTOR_ZIP_ENTRY_PATH = "sdk-interface-descriptors.jar"; - - @Option(names = "--asar", required = true) - Path asarPath; - - @Option(names = "--output-sdk-api-descriptors", required = true) - Path outputSdkApiDescriptorsPath; - - @Override - public void run() { - URI uri = URI.create("jar:" + asarPath.toUri()); - try (FileSystem zipfs = FileSystems.newFileSystem(uri, new HashMap<String, String>())) { - Path descriptorsInZip = zipfs.getPath(API_DESCRIPTOR_ZIP_ENTRY_PATH); - if (!Files.exists(descriptorsInZip)) { - throw new IllegalStateException( - String.format("Could not find %s in %s", API_DESCRIPTOR_ZIP_ENTRY_PATH, asarPath)); - } - Files.copy(descriptorsInZip, outputSdkApiDescriptorsPath); - } catch (IOException e) { - throw new UncheckedIOException("Failed to extract SDK API descriptors.", e); - } - } - - private ExtractApiDescriptorsFromAsarCommand() {} -}
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/clientsources/BUILD b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/clientsources/BUILD deleted file mode 100644 index 5037230..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/clientsources/BUILD +++ /dev/null
@@ -1,19 +0,0 @@ -# Command to generate sources for communicating with a sandboxed SDK. - -load("@rules_java//java:defs.bzl", "java_library") - -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//:__subpackages__"], -) - -licenses(["notice"]) - -java_library( - name = "clientsources", - srcs = glob(["*.java"]), - deps = [ - "@rules_android_maven//:androidx_privacysandbox_tools_tools_apigenerator", - "@rules_android_maven//:info_picocli_picocli", - ], -)
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/clientsources/GenerateClientSourcesCommand.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/clientsources/GenerateClientSourcesCommand.java deleted file mode 100644 index cb5be04..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/clientsources/GenerateClientSourcesCommand.java +++ /dev/null
@@ -1,99 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.clientsources; - -import static java.nio.file.Files.createTempDirectory; -import static java.util.stream.Collectors.toCollection; - -import androidx.privacysandbox.tools.apigenerator.PrivacySandboxApiGenerator; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Stream; -import picocli.CommandLine.Command; -import picocli.CommandLine.Option; - -/** - * Command for generating Kotlin and Java sources for communicating with a sandboxed SDK over IPC. - */ -@Command( - name = "generate-client-sources", - description = - "Generate Kotlin and Java sources for communicating with a sandboxed SDK over IPC.") -public final class GenerateClientSourcesCommand implements Runnable { - - private final PrivacySandboxApiGenerator generator = new PrivacySandboxApiGenerator(); - - @Option(names = "--aidl-compiler", required = true) - Path aidlCompilerPath; - - @Option(names = "--framework-aidl", required = true) - Path frameworkAidlPath; - - @Option(names = "--sdk-api-descriptors", required = true) - Path sdkApiDescriptorsPath; - - @Option( - names = "--output-kotlin-dir", - description = "Directory where Kotlin sources will be written.", - required = true) - Path outputKotlinDirPath; - - @Option( - names = "--output-java-dir", - description = "Directory where Java sources will be written.", - required = true) - Path outputJavaDirPath; - - @Override - public void run() { - try { - Path apiGeneratorOutputDir = createTempDirectory("apigenerator-raw-output"); - generator.generate( - sdkApiDescriptorsPath, aidlCompilerPath, frameworkAidlPath, apiGeneratorOutputDir); - splitSources(apiGeneratorOutputDir, outputKotlinDirPath, outputJavaDirPath); - } catch (IOException e) { - throw new UncheckedIOException("Failed to generate sources.", e); - } - } - - /** Split Java and Kotlin sources into different root directories. */ - private static void splitSources( - Path sourcesDirectory, Path kotlinSourcesDirectory, Path javaSourcesDirectory) - throws IOException { - for (Path path : allFiles(sourcesDirectory)) { - Path targetDir = javaSourcesDirectory; - if (path.toString().endsWith(".kt")) { - targetDir = kotlinSourcesDirectory; - } - Path targetPath = targetDir.resolve(sourcesDirectory.relativize(path)); - - Files.createDirectories(targetPath.getParent()); - Files.move(path, targetPath); - } - } - - private static List<Path> allFiles(Path rootDirectory) throws IOException { - try (Stream<Path> pathStream = Files.walk(rootDirectory)) { - return pathStream.filter(Files::isRegularFile).collect(toCollection(ArrayList::new)); - } - } - - private GenerateClientSourcesCommand() {} -}
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/info/BUILD b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/info/BUILD deleted file mode 100644 index 8842e9d..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/info/BUILD +++ /dev/null
@@ -1,19 +0,0 @@ -# Utilities for extracting information from SDK archives and Bundle metadata. -load("@rules_java//java:defs.bzl", "java_library") - -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//src:__subpackages__"], -) - -licenses(["notice"]) - -java_library( - name = "info", - srcs = glob(["*.java"]), - deps = [ - "@rules_android_maven//:com_android_tools_build_bundletool", - "@com_google_protobuf//:protobuf_java", - "@com_google_protobuf//:protobuf_java_util", - ], -)
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/info/SdkInfo.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/info/SdkInfo.java deleted file mode 100644 index 6968c8e..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/info/SdkInfo.java +++ /dev/null
@@ -1,125 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.info; - -import com.android.bundle.SdkModulesConfigOuterClass.RuntimeEnabledSdkVersion; -import com.android.tools.build.bundletool.model.RuntimeEnabledSdkVersionEncoder; -import java.util.Objects; -import java.util.Optional; - -/** - * Information about a Sandboxed SDK. Used to define an SDK dependency and read from an SDK archive - * or bundle config. - */ -public final class SdkInfo { - - private final String packageName; - private final RuntimeEnabledSdkVersion version; - private final Optional<String> certificateDigest; - private final Optional<String> sdkProviderClassName; - private final Optional<String> compatSdkProviderClassName; - - SdkInfo( - String packageName, - RuntimeEnabledSdkVersion version, - String sdkProviderClassName, - String compatSdkProviderClassName) { - this( - packageName, - version, - Optional.empty(), - Optional.ofNullable(sdkProviderClassName), - Optional.ofNullable(compatSdkProviderClassName)); - } - - SdkInfo(String packageName, RuntimeEnabledSdkVersion version, String certificateDigest) { - this(packageName, version, Optional.of(certificateDigest), Optional.empty(), Optional.empty()); - } - - private SdkInfo( - String packageName, - RuntimeEnabledSdkVersion version, - Optional<String> certificateDigest, - Optional<String> sdkProviderClassName, - Optional<String> compatSdkProviderClassName) { - this.packageName = packageName; - this.version = version; - this.certificateDigest = certificateDigest; - this.sdkProviderClassName = sdkProviderClassName; - this.compatSdkProviderClassName = compatSdkProviderClassName; - } - - /** The SDK unique package name. */ - public String getPackageName() { - return packageName; - } - - public RuntimeEnabledSdkVersion getVersion() { - return version; - } - - /** - * The SDK encoded version major-minor. - * - * <p>This value is constructed from the full SDK version description and it represents the actual - * version of the SDK as used by the package manager later. The major and minor versions are - * merged and the patch version is ignored. - */ - public long getEncodedVersionMajorMinor() { - return RuntimeEnabledSdkVersionEncoder.encodeSdkMajorAndMinorVersion( - version.getMajor(), version.getMinor()); - } - - /** - * Digest of certificate used to sign this SDK's APKs. - * - * <p>Might be missing if the certificate is not known at the time, for example for SDKs signed - * with debug keys for local deployment. - */ - public Optional<String> getCertificateDigest() { - return certificateDigest; - } - - /** The fully qualified name for the platform SDK provider entrypoint class. */ - public Optional<String> getSdkProviderClassName() { - return sdkProviderClassName; - } - - /** The fully qualified name for the compatibility SDK provider entrypoint class. */ - public Optional<String> getCompatSdkProviderClassName() { - return compatSdkProviderClassName; - } - - @Override - @SuppressWarnings("PatternMatchingInstanceof") - public boolean equals(Object object) { - if (object instanceof SdkInfo) { - SdkInfo that = (SdkInfo) object; - return this.packageName.equals(that.packageName) - && this.version.equals(that.version) - && this.certificateDigest.equals(that.certificateDigest) - && this.sdkProviderClassName.equals(that.sdkProviderClassName) - && this.compatSdkProviderClassName.equals(that.compatSdkProviderClassName); - } - return false; - } - - @Override - public int hashCode() { - return Objects.hash( - packageName, version, certificateDigest, sdkProviderClassName, compatSdkProviderClassName); - } -}
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/info/SdkInfoReader.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/info/SdkInfoReader.java deleted file mode 100644 index 2e06374..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/info/SdkInfoReader.java +++ /dev/null
@@ -1,70 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.info; - -import com.android.bundle.SdkMetadataOuterClass.SdkMetadata; -import com.android.bundle.SdkModulesConfigOuterClass.SdkModulesConfig; -import com.google.protobuf.ExtensionRegistry; -import com.google.protobuf.util.JsonFormat; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.net.URI; -import java.nio.file.FileSystem; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.HashMap; - -/** Reads SDK information SDK archives and Bundle metadata files. */ -public final class SdkInfoReader { - - // SDK metadata proto sits at the top level of an ASAR. - private static final String SDK_METADATA_ENTRY_PATH = "SdkMetadata.pb"; - - public static SdkInfo readFromSdkModuleJsonFile(Path sdkModulesConfigPath) { - SdkModulesConfig.Builder modulesConfig = SdkModulesConfig.newBuilder(); - try { - JsonFormat.parser().merge(Files.newBufferedReader(sdkModulesConfigPath), modulesConfig); - return new SdkInfo( - modulesConfig.getSdkPackageName(), - modulesConfig.getSdkVersion(), - modulesConfig.getSdkProviderClassName(), - modulesConfig.getCompatSdkProviderClassName()); - } catch (IOException e) { - throw new UncheckedIOException("Failed to parse SDK Module Config.", e); - } - } - - public static SdkInfo readFromSdkArchive(Path sdkArchivePath) { - URI uri = URI.create("jar:" + sdkArchivePath.toUri()); - try (FileSystem zipfs = FileSystems.newFileSystem(uri, new HashMap<String, String>())) { - Path metadataInAsar = zipfs.getPath(SDK_METADATA_ENTRY_PATH); - if (!Files.exists(metadataInAsar)) { - throw new IllegalStateException( - String.format("Could not find %s in %s", SDK_METADATA_ENTRY_PATH, sdkArchivePath)); - } - SdkMetadata metadata = - SdkMetadata.parseFrom( - Files.readAllBytes(metadataInAsar), ExtensionRegistry.getEmptyRegistry()); - return new SdkInfo( - metadata.getPackageName(), metadata.getSdkVersion(), metadata.getCertificateDigest()); - } catch (IOException e) { - throw new UncheckedIOException("Failed to read SDK archive.", e); - } - } - - private SdkInfoReader() {} -}
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin/BUILD b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin/BUILD deleted file mode 100644 index 250a95b..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin/BUILD +++ /dev/null
@@ -1,19 +0,0 @@ -# Package for mixins with shared logic between commands. -load("@rules_java//java:defs.bzl", "java_library") - -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//src:__subpackages__"], -) - -licenses(["notice"]) - -java_library( - name = "mixin", - srcs = glob(["*.java"]), - deps = [ - "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/info", - "@rules_android_maven//:com_google_guava_guava", - "@rules_android_maven//:info_picocli_picocli", - ], -)
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin/CertificateDigestGenerator.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin/CertificateDigestGenerator.java deleted file mode 100644 index 77a7d14..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin/CertificateDigestGenerator.java +++ /dev/null
@@ -1,66 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.mixin; - -import static java.util.stream.Collectors.joining; - -import com.google.common.hash.Hashing; -import com.google.common.io.ByteSource; -import com.google.common.primitives.Bytes; -import java.io.BufferedInputStream; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.security.GeneralSecurityException; -import java.security.KeyStore; -import java.security.cert.CertificateEncodingException; -import java.security.cert.X509Certificate; - -/** Generates a SHA256 digest of a signing certificate. */ -final class CertificateDigestGenerator { - - static final String generateCertificateDigest( - Path keystorePath, String keystorePassword, String keystoreAlias) { - X509Certificate certificate = readCertificate(keystorePath, keystorePassword, keystoreAlias); - return getCertificateDigest(certificate); - } - - private static X509Certificate readCertificate( - Path keystorePath, String keystorePassword, String keystoreAlias) { - try (BufferedInputStream keystoreInputStream = - new BufferedInputStream(Files.newInputStream(keystorePath))) { - KeyStore keystore = KeyStore.getInstance("JKS"); - keystore.load(keystoreInputStream, keystorePassword.toCharArray()); - return (X509Certificate) keystore.getCertificate(keystoreAlias); - } catch (GeneralSecurityException | IOException e) { - throw new IllegalStateException("Failed to read certificate", e); - } - } - - private static String getCertificateDigest(X509Certificate certificate) { - try { - return Bytes.asList( - ByteSource.wrap(certificate.getEncoded()).hash(Hashing.sha256()).asBytes()) - .stream() - .map(b -> String.format("%02X", b)) - .collect(joining(":")); - } catch (CertificateEncodingException | IOException e) { - throw new IllegalStateException("Failed to generate certificate digest", e); - } - } - - private CertificateDigestGenerator() {} -}
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin/DebugKeystoreCommandMixin.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin/DebugKeystoreCommandMixin.java deleted file mode 100644 index 5c49a12..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin/DebugKeystoreCommandMixin.java +++ /dev/null
@@ -1,50 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.mixin; - -import static com.google.devtools.build.android.sandboxedsdktoolbox.mixin.CertificateDigestGenerator.generateCertificateDigest; - -import java.nio.file.Path; -import picocli.CommandLine.Option; - -/** Parses command line options defining a debug keystore. */ -public final class DebugKeystoreCommandMixin { - - private Path debugKeystorePath; - private String debugKeystorePassword; - private String debugKeystoreAlias; - - public String getDebugCertificateDigest() { - return generateCertificateDigest(debugKeystorePath, debugKeystorePassword, debugKeystoreAlias); - } - - @Option(names = "--debug-keystore", required = true) - void setDebugKeystorePath(Path debugKeystorePath) { - this.debugKeystorePath = debugKeystorePath; - } - - @Option(names = "--debug-keystore-pass", required = true) - void setDebugKeystorePassword(String debugKeystorePassword) { - this.debugKeystorePassword = debugKeystorePassword; - } - - @Option(names = "--debug-keystore-alias", required = true) - void setDebugKeystoreAlias(String debugKeystoreAlias) { - this.debugKeystoreAlias = debugKeystoreAlias; - } - - private DebugKeystoreCommandMixin() {} -}
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin/HostAppInfoMixin.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin/HostAppInfoMixin.java deleted file mode 100644 index 82cadf9..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin/HostAppInfoMixin.java +++ /dev/null
@@ -1,98 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.mixin; - -import static com.google.common.base.Preconditions.checkArgument; - -import com.google.common.collect.ImmutableMap; -import java.io.BufferedReader; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.EnumMap; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import picocli.CommandLine.Option; - -/** Command line mixin for parsing an AAPT xml tree dump of the host app. */ -public final class HostAppInfoMixin { - private enum HostAppInfoType { - PACKAGE_NAME, - VERSION_CODE, - MIN_SDK_VERSION, - } - - private static final ImmutableMap<HostAppInfoType, Pattern> PATTERNS = - ImmutableMap.of( - HostAppInfoType.PACKAGE_NAME, - Pattern.compile("A: package=\"(.*?)\""), - HostAppInfoType.VERSION_CODE, - Pattern.compile( - "http:\\/\\/schemas.android.com\\/apk\\/res\\/android:versionCode\\(.*\\)=(\\d*)"), - HostAppInfoType.MIN_SDK_VERSION, - Pattern.compile( - "http:\\/\\/schemas.android.com\\/apk\\/res\\/android:minSdkVersion\\(.*\\)=(\\d*)")); - - private final Map<HostAppInfoType, String> parsedInfoMap = new EnumMap<>(HostAppInfoType.class); - - @Option( - names = "--manifest-xml-tree", - description = "Path to the manifest xml tree file, as generated by AAPT2 dump command.", - required = true) - public void setManifestXmlTreePath(Path manifestXmlTreePath) { - try (BufferedReader reader = Files.newBufferedReader(manifestXmlTreePath)) { - reader.lines().forEach(this::parseXmlTreeLine); - } catch (IOException e) { - throw new IllegalArgumentException("Invalid manifest xml tree file.", e); - } - } - - private void parseXmlTreeLine(String line) { - for (HostAppInfoType type : HostAppInfoType.values()) { - if (parsedInfoMap.containsKey(type)) { - continue; - } - Matcher matcher = PATTERNS.get(type).matcher(line); - if (matcher.find()) { - parsedInfoMap.put(type, matcher.group(1)); - } - } - } - - public String getPackageName() { - checkArgument( - parsedInfoMap.containsKey(HostAppInfoType.PACKAGE_NAME), - "Package name missing from manifest xml tree file."); - return parsedInfoMap.get(HostAppInfoType.PACKAGE_NAME); - } - - public int getVersionCode() { - checkArgument( - parsedInfoMap.containsKey(HostAppInfoType.VERSION_CODE), - "Version code missing from manifest xml tree file."); - return Integer.parseInt(parsedInfoMap.get(HostAppInfoType.VERSION_CODE)); - } - - public int getMinSdkVersion() { - checkArgument( - parsedInfoMap.containsKey(HostAppInfoType.MIN_SDK_VERSION), - "Min SDK version missing from manifest xml tree file."); - return Integer.parseInt(parsedInfoMap.get(HostAppInfoType.MIN_SDK_VERSION)); - } - - private HostAppInfoMixin() {} -}
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin/SdkDependenciesCommandMixin.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin/SdkDependenciesCommandMixin.java deleted file mode 100644 index fa4aacc..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin/SdkDependenciesCommandMixin.java +++ /dev/null
@@ -1,65 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.mixin; - -import static com.google.common.collect.ImmutableSet.toImmutableSet; - -import com.google.common.collect.ImmutableSet; -import com.google.devtools.build.android.sandboxedsdktoolbox.info.SdkInfo; -import com.google.devtools.build.android.sandboxedsdktoolbox.info.SdkInfoReader; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Stream; -import picocli.CommandLine.Option; - -/** - * Parses command line options that describe SDK dependencies, coming from SDK archives or bundles. - */ -public final class SdkDependenciesCommandMixin { - - private List<Path> sdkModuleConfigPaths = new ArrayList<>(); - private List<Path> sdkArchivePaths = new ArrayList<>(); - - public ImmutableSet<SdkInfo> getSdkDependencies() { - checkValid(); - - return Stream.concat( - sdkModuleConfigPaths.stream().map(SdkInfoReader::readFromSdkModuleJsonFile), - sdkArchivePaths.stream().map(SdkInfoReader::readFromSdkArchive)) - .collect(toImmutableSet()); - } - - - @Option(names = "--sdk-module-configs", split = ",", required = false) - void setSdkModuleConfigPaths(List<Path> sdkModuleConfigPaths) { - this.sdkModuleConfigPaths = sdkModuleConfigPaths; - } - - @Option(names = "--sdk-archives", split = ",", required = false) - void setSdkArchivePaths(List<Path> sdkArchivePaths) { - this.sdkArchivePaths = sdkArchivePaths; - } - - private void checkValid() { - if (sdkModuleConfigPaths.isEmpty() && sdkArchivePaths.isEmpty()) { - throw new IllegalArgumentException( - "At least one of --sdk-module-configs or --sdk-archives must be specified."); - } - } - - private SdkDependenciesCommandMixin() {} -}
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/proguardspecs/BUILD b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/proguardspecs/BUILD deleted file mode 100644 index 8b83024..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/proguardspecs/BUILD +++ /dev/null
@@ -1,19 +0,0 @@ -# Command to generate proguard specs for an SDK modules config. - -load("@rules_java//java:defs.bzl", "java_library") - -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//:__subpackages__"], -) - -licenses(["notice"]) - -java_library( - name = "proguardspecs", - srcs = ["GenerateSdkProguardSpecsCommand.java"], - deps = [ - "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/info", - "@rules_android_maven//:info_picocli_picocli", - ], -)
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/proguardspecs/GenerateSdkProguardSpecsCommand.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/proguardspecs/GenerateSdkProguardSpecsCommand.java deleted file mode 100644 index e90c853..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/proguardspecs/GenerateSdkProguardSpecsCommand.java +++ /dev/null
@@ -1,85 +0,0 @@ -/* - * Copyright 2025 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.proguardspecs; - -import com.google.devtools.build.android.sandboxedsdktoolbox.info.SdkInfo; -import com.google.devtools.build.android.sandboxedsdktoolbox.info.SdkInfoReader; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import picocli.CommandLine.Command; -import picocli.CommandLine.Option; - -/** Generates a proguard specs file for a sandboxed SDK. */ -@Command( - name = "generate-sdk-proguard-specs", - description = "Generates a proguard specs file for a sandboxed SDK.") -public final class GenerateSdkProguardSpecsCommand implements Runnable { - - @Option(names = "--sdk-modules-config", required = true) - Path sdkModuleConfigPath; - - @Option(names = "--output", required = true) - Path output; - - @Override - public void run() { - SdkInfo info = SdkInfoReader.readFromSdkModuleJsonFile(sdkModuleConfigPath); - - List<String> rules = new ArrayList<>(); - rules.add("# Generated by the generate-sdk-proguard-specs command."); - addShimRules(rules); - - info.getSdkProviderClassName().ifPresent(className -> rules.add(keepClassRule(className))); - info.getCompatSdkProviderClassName() - .ifPresent(className -> rules.add(keepClassRule(className))); - rules.add(keepClassRule(info.getPackageName() + ".RPackage")); - - try { - Files.write(output, rules); - } catch (IOException e) { - throw new IllegalStateException("Failed to create output file", e); - } - } - - private void addShimRules(List<String> rules) { - addKeepShimRule(rules, "androidx.privacysandbox.tools.PrivacySandboxValue"); - addKeepShimRule(rules, "androidx.privacysandbox.tools.PrivacySandboxInterface"); - addKeepShimRule(rules, "androidx.privacysandbox.tools.PrivacySandboxService"); - addKeepShimRule(rules, "androidx.privacysandbox.tools.PrivacySandboxCallback"); - } - - private void addKeepShimRule(List<String> rules, String className) { - rules.add(keepShimClassRule(className)); - rules.add(keepShimInterfaceRule(className)); - } - - private String keepClassRule(String className) { - return "-keep class " + className + " { *; }"; - } - - private String keepShimClassRule(String className) { - return "-keep @" + className + " class ** { *; }"; - } - - private String keepShimInterfaceRule(String className) { - return "-keep @" + className + " interface ** { *; }"; - } - - private GenerateSdkProguardSpecsCommand() {} -}
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/BUILD b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/BUILD deleted file mode 100644 index f98b95d..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/BUILD +++ /dev/null
@@ -1,22 +0,0 @@ -# Command to generate the RuntimeEnabledSdkConfig file for app bundles. -load("@rules_java//java:defs.bzl", "java_library") - -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//:__subpackages__"], -) - -licenses(["notice"]) - -java_library( - name = "runtimeenabledsdkconfig", - srcs = glob(["*.java"]), - deps = [ - "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/info", - "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin", - "@com_google_protobuf//:protobuf_java", - "@rules_android_maven//:com_android_tools_build_bundletool", - "@rules_android_maven//:com_google_guava_guava", - "@rules_android_maven//:info_picocli_picocli", - ], -)
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/GenerateRuntimeEnabledSdkConfigCommand.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/GenerateRuntimeEnabledSdkConfigCommand.java deleted file mode 100644 index 9d1304e..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/GenerateRuntimeEnabledSdkConfigCommand.java +++ /dev/null
@@ -1,79 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.runtimeenabledsdkconfig; - -import static com.google.common.base.Preconditions.checkArgument; - -import com.android.bundle.RuntimeEnabledSdkConfigProto.RuntimeEnabledSdk; -import com.android.bundle.RuntimeEnabledSdkConfigProto.RuntimeEnabledSdkConfig; -import com.google.devtools.build.android.sandboxedsdktoolbox.info.SdkInfo; -import com.google.devtools.build.android.sandboxedsdktoolbox.mixin.DebugKeystoreCommandMixin; -import com.google.devtools.build.android.sandboxedsdktoolbox.mixin.HostAppInfoMixin; -import com.google.devtools.build.android.sandboxedsdktoolbox.mixin.SdkDependenciesCommandMixin; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.file.Files; -import java.nio.file.Path; -import picocli.CommandLine.Command; -import picocli.CommandLine.Mixin; -import picocli.CommandLine.Option; - -/** Command for extracting API descriptors from a sandboxed SDK Archive. */ -@Command( - name = "generate-runtime-enabled-sdk-config", - description = - "Generate the RuntimeEnabledSdkConfig file for app bundles that depend on sandboxed SDKs.") -public final class GenerateRuntimeEnabledSdkConfigCommand implements Runnable { - - @Option(names = "--output-config", required = true) - Path outputConfigPath; - - @Mixin SdkDependenciesCommandMixin sdkDependenciesMixin; - @Mixin DebugKeystoreCommandMixin debugKeystoreMixin; - @Mixin HostAppInfoMixin hostAppInfoMixin; - - @Override - public void run() { - ResourceIdGenerator generator = new ResourceIdGenerator(hostAppInfoMixin.getMinSdkVersion()); - checkArgument( - sdkDependenciesMixin.getSdkDependencies().size() <= generator.maxResourceIds(), - "Too many SDK dependencies (%s). For apps with min SDK 26 and above the maximum is 127. " - + "For older versions it's 50.", - sdkDependenciesMixin.getSdkDependencies().size()); - - String debugCertificateDigest = debugKeystoreMixin.getDebugCertificateDigest(); - - RuntimeEnabledSdkConfig.Builder builder = RuntimeEnabledSdkConfig.newBuilder(); - for (SdkInfo sdkInfo : sdkDependenciesMixin.getSdkDependencies()) { - builder.addRuntimeEnabledSdk( - RuntimeEnabledSdk.newBuilder() - .setPackageName(sdkInfo.getPackageName()) - .setVersionMajor(sdkInfo.getVersion().getMajor()) - .setVersionMinor(sdkInfo.getVersion().getMinor()) - .setBuildTimeVersionPatch(sdkInfo.getVersion().getPatch()) - .setCertificateDigest(sdkInfo.getCertificateDigest().orElse(debugCertificateDigest)) - .setResourcesPackageId(generator.nextResourceId())); - } - - try { - Files.write(outputConfigPath, builder.build().toByteArray()); - } catch (IOException e) { - throw new UncheckedIOException("Failed to write runtime-enabled SDK config file.", e); - } - } - - private GenerateRuntimeEnabledSdkConfigCommand() {} -}
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/GenerateRuntimeEnabledSdkTableCommand.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/GenerateRuntimeEnabledSdkTableCommand.java deleted file mode 100644 index 07ba055..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/GenerateRuntimeEnabledSdkTableCommand.java +++ /dev/null
@@ -1,76 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.runtimeenabledsdkconfig; - -import static com.google.common.collect.ImmutableList.toImmutableList; - -import com.android.bundle.RuntimeEnabledSdkConfigProto.RuntimeEnabledSdk; -import com.android.tools.build.bundletool.splitters.RuntimeEnabledSdkTableInjector; -import com.google.common.collect.ImmutableList; -import com.google.devtools.build.android.sandboxedsdktoolbox.mixin.SdkDependenciesCommandMixin; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.file.Files; -import java.nio.file.Path; -import picocli.CommandLine.Command; -import picocli.CommandLine.Mixin; -import picocli.CommandLine.Option; - -/** - * Command for generating the Runtime Enabled SDK table. - * - * <p>This file is a directory of paths to sdk metadata that is required by the Jetpack SDK Runtime - * library. This is required for installing sandboxed SDKs on devices without the Sandbox. - */ -@Command( - name = "generate-runtime-enabled-sdk-table", - description = - "Generate XML file with sandboxed SDK metadata for apps targeting devices without the" - + " sandbox.") -public final class GenerateRuntimeEnabledSdkTableCommand implements Runnable { - - @Mixin SdkDependenciesCommandMixin sdkDependenciesMixin; - - @Option(names = "--output-table", required = true) - Path outputTablePath; - - @Override - public void run() { - ImmutableList<RuntimeEnabledSdk> dependencies = - sdkDependenciesMixin.getSdkDependencies().stream() - .map( - sdkInfo -> - RuntimeEnabledSdk.newBuilder() - .setPackageName(sdkInfo.getPackageName()) - .setVersionMajor(sdkInfo.getVersion().getMajor()) - .setVersionMinor(sdkInfo.getVersion().getMinor()) - // The cert digest, patch version and other fields are not used to create - // the final table, so we can omit them. - .build()) - .collect(toImmutableList()); - try { - Files.write( - outputTablePath, - // Calls bundletool utility class to generate the table for us. This is the same class - // that creates the table for the build-apks command targeting AABs. - RuntimeEnabledSdkTableInjector.generateRuntimeEnabledSdkTableBytes(dependencies)); - } catch (IOException e) { - throw new UncheckedIOException("Failed to write runtime-enabled SDK table.", e); - } - } - - private GenerateRuntimeEnabledSdkTableCommand() {} -}
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/ResourceIdGenerator.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/ResourceIdGenerator.java deleted file mode 100644 index cf0df9b..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/ResourceIdGenerator.java +++ /dev/null
@@ -1,55 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.runtimeenabledsdkconfig; - -/** - * Generator for resource package IDs. This is a prefix byte added to resource IDs. - * - * <p>This ID needs to be generated slightly differently based on the minSdkVersion used by the app. - */ -final class ResourceIdGenerator { - private static final int BASE_RESOURCE_ID = 0x7F; - private static final int ANDROID_O_SDK_VERSION = 26; - - private final int minSdkVersion; - private int currentResourceId; - - ResourceIdGenerator(int minSdkVersion) { - this.minSdkVersion = minSdkVersion; - if (isOlderThanAndroidO()) { - currentResourceId = BASE_RESOURCE_ID - 1; - } else { - currentResourceId = BASE_RESOURCE_ID + 1; - } - } - - int maxResourceIds() { - // Mirrors Android Gradle Plugin implementation of resource IDs for splits: - // https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:build-system/gradle-core/src/main/java/com/android/build/gradle/internal/tasks/featuresplit/FeatureSetMetadata.kt;drc=b1afd3d7dfa38875ff7950b65bd58f6a79e74374 - return isOlderThanAndroidO() ? 50 : 127; - } - - int nextResourceId() { - if (isOlderThanAndroidO()) { - return currentResourceId--; - } - return currentResourceId++; - } - - private boolean isOlderThanAndroidO() { - return minSdkVersion < ANDROID_O_SDK_VERSION; - } -}
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/AndroidManifestWriter.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/AndroidManifestWriter.java deleted file mode 100644 index 87e8717..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/AndroidManifestWriter.java +++ /dev/null
@@ -1,97 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.sdkdependenciesmanifest; - -import com.google.common.collect.ImmutableSet; -import com.google.devtools.build.android.sandboxedsdktoolbox.info.SdkInfo; -import java.io.BufferedOutputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.file.Path; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** Writes an Android manifest that lists SDK dependencies for an app. */ -final class AndroidManifestWriter { - - private static final String ANDROID_NAME_ATTRIBUTE = "android:name"; - private static final String ANDROID_VERSION_MAJOR_ATTRIBUTE = "android:versionMajor"; - private static final String ANDROID_CERTIFICATE_DIGEST_ATTRIBUTE = "android:certDigest"; - private static final String APPLICATION_ELEMENT_NAME = "application"; - private static final String MANIFEST_ELEMENT_NAME = "manifest"; - private static final String MANIFEST_NAMESPACE_URI = "http://schemas.android.com/apk/res/android"; - private static final String MANIFEST_NAMESPACE_NAME = "xmlns:android"; - private static final String MANIFEST_PACKAGE_ATTRIBUTE = "package"; - private static final String SDK_DEPENDENCY_ELEMENT_NAME = "uses-sdk-library"; - - static void writeManifest( - String packageName, - String certificateDigest, - ImmutableSet<SdkInfo> infoSet, - Path outputPath) { - Document root = newEmptyDocument(); - - Element manifestNode = root.createElement(MANIFEST_ELEMENT_NAME); - manifestNode.setAttribute(MANIFEST_NAMESPACE_NAME, MANIFEST_NAMESPACE_URI); - manifestNode.setAttribute(MANIFEST_PACKAGE_ATTRIBUTE, packageName); - root.appendChild(manifestNode); - - Element applicationNode = root.createElement(APPLICATION_ELEMENT_NAME); - manifestNode.appendChild(applicationNode); - - for (SdkInfo sdkInfo : infoSet) { - Element sdkDependencyElement = root.createElement(SDK_DEPENDENCY_ELEMENT_NAME); - sdkDependencyElement.setAttribute(ANDROID_NAME_ATTRIBUTE, sdkInfo.getPackageName()); - sdkDependencyElement.setAttribute( - ANDROID_VERSION_MAJOR_ATTRIBUTE, Long.toString(sdkInfo.getEncodedVersionMajorMinor())); - sdkDependencyElement.setAttribute(ANDROID_CERTIFICATE_DIGEST_ATTRIBUTE, certificateDigest); - applicationNode.appendChild(sdkDependencyElement); - } - - writeDocument(root, outputPath); - } - - private static Document newEmptyDocument() { - try { - return DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - } catch (ParserConfigurationException e) { - throw new IllegalStateException("Failed to create new XML document.", e); - } - } - - private static void writeDocument(Document document, Path outputPath) { - try (BufferedOutputStream outputStream = - new BufferedOutputStream(new FileOutputStream(outputPath.toFile()))) { - Transformer transformer = TransformerFactory.newInstance().newTransformer(); - transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); - transformer.setOutputProperty(OutputKeys.METHOD, "xml"); - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - transformer.transform(new DOMSource(document), new StreamResult(outputStream)); - } catch (TransformerException | IOException e) { - throw new IllegalStateException("Failed to write manifest.", e); - } - } - - private AndroidManifestWriter() {} -}
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/BUILD b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/BUILD deleted file mode 100644 index d087b2c..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/BUILD +++ /dev/null
@@ -1,20 +0,0 @@ -# Command for generating an SDK dependencies Android manifest. -load("@rules_java//java:defs.bzl", "java_library") - -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//src:__subpackages__"], -) - -licenses(["notice"]) - -java_library( - name = "sdkdependenciesmanifest", - srcs = glob(["*.java"]), - deps = [ - "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/info", - "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin", - "@rules_android_maven//:com_google_guava_guava", - "@rules_android_maven//:info_picocli_picocli", - ], -)
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/GenerateSdkDependenciesManifestCommand.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/GenerateSdkDependenciesManifestCommand.java deleted file mode 100644 index bba8d13..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/GenerateSdkDependenciesManifestCommand.java +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.sdkdependenciesmanifest; - -import static com.google.devtools.build.android.sandboxedsdktoolbox.sdkdependenciesmanifest.AndroidManifestWriter.writeManifest; - -import com.google.devtools.build.android.sandboxedsdktoolbox.mixin.DebugKeystoreCommandMixin; -import com.google.devtools.build.android.sandboxedsdktoolbox.mixin.SdkDependenciesCommandMixin; -import java.nio.file.Path; -import picocli.CommandLine.Command; -import picocli.CommandLine.Mixin; -import picocli.CommandLine.Option; - -/** Command for generating SDK dependencies manifest. */ -@Command( - name = "generate-sdk-dependencies-manifest", - description = - "Generates an Android manifest with <uses-sdk-library> tags from the given SDK bundles " - + "or archives.") -public final class GenerateSdkDependenciesManifestCommand implements Runnable { - - @Option(names = "--manifest-package", required = true) - String manifestPackage; - - @Option(names = "--output-manifest", required = true) - Path outputManifestPath; - - @Mixin SdkDependenciesCommandMixin sdkDependenciesMixin; - @Mixin DebugKeystoreCommandMixin debugKeystoreMixin; - - @Override - public void run() { - writeManifest( - manifestPackage, - debugKeystoreMixin.getDebugCertificateDigest(), - sdkDependenciesMixin.getSdkDependencies(), - outputManifestPath); - } - - private GenerateSdkDependenciesManifestCommand() {} -}
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/BUILD b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/BUILD deleted file mode 100644 index f55d085..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/BUILD +++ /dev/null
@@ -1,23 +0,0 @@ -# Command to generate the SdkSplitProperties file for sandboxed SDK dependencies. -load("@rules_java//java:defs.bzl", "java_library") - -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//:__subpackages__"], -) - -licenses(["notice"]) - -java_library( - name = "sdksplitproperties", - srcs = glob(["*.java"]), - deps = [ - "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/info", - "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/mixin", - "@rules_android_maven//:com_android_tools_build_bundletool", - "@rules_android_maven//:com_google_guava_guava", - "@com_google_protobuf//:protobuf_java", - "@com_google_protobuf//:protobuf_java_util", - "@rules_android_maven//:info_picocli_picocli", - ], -)
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/GenerateSdkSplitPropertiesCommand.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/GenerateSdkSplitPropertiesCommand.java deleted file mode 100644 index 0be64bc..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/GenerateSdkSplitPropertiesCommand.java +++ /dev/null
@@ -1,113 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.sdksplitproperties; - -import static com.google.common.base.Preconditions.checkArgument; - -import com.android.bundle.RuntimeEnabledSdkConfigProto.RuntimeEnabledSdk; -import com.android.bundle.RuntimeEnabledSdkConfigProto.RuntimeEnabledSdkConfig; -import com.android.bundle.RuntimeEnabledSdkConfigProto.SdkSplitPropertiesInheritedFromApp; -import com.google.devtools.build.android.sandboxedsdktoolbox.info.SdkInfoReader; -import com.google.devtools.build.android.sandboxedsdktoolbox.mixin.HostAppInfoMixin; -import com.google.protobuf.ExtensionRegistry; -import com.google.protobuf.util.JsonFormat; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.file.Files; -import java.nio.file.Path; -import picocli.CommandLine.Command; -import picocli.CommandLine.Mixin; -import picocli.CommandLine.Option; - -/** - * Generates the {@link SdkSplitPropertiesInheritedFromApp} proto message for a sandboxed SDK - * dependency of an app. - * - * <p>This file is used to create the SDK split added to the app in the Privacy Sandbox - * compatibility mode. It contains information about the host app and the SDK. - */ -@Command( - name = "generate-sdk-split-properties", - description = "Generate the SdkSplitProperties file for a sandboxed SDK dependency of an app.") -public final class GenerateSdkSplitPropertiesCommand implements Runnable { - - @Mixin HostAppInfoMixin hostAppInfoMixin; - - @Option(names = "--runtime-enabled-sdk-config", required = true) - Path runtimeEnabledSdkConfigPath; - - @Option(names = "--sdk-archive", required = false) - Path sdkArchivePath; - - @Option(names = "--sdk-modules-config", required = false) - Path sdkModuleConfigPath; - - @Option(names = "--output-properties", required = true) - Path outputPropertiesPath; - - @Override - public void run() { - SdkSplitPropertiesInheritedFromApp properties = - SdkSplitPropertiesInheritedFromApp.newBuilder() - .setPackageName(hostAppInfoMixin.getPackageName()) - .setVersionCode(hostAppInfoMixin.getVersionCode()) - .setMinSdkVersion(hostAppInfoMixin.getMinSdkVersion()) - .setResourcesPackageId(getSdkResourceId()) - .build(); - try { - Files.writeString(outputPropertiesPath, JsonFormat.printer().print(properties)); - } catch (IOException e) { - throw new UncheckedIOException("Failed to write sdk-split-properties files.", e); - } - } - - private int getSdkResourceId() { - try { - RuntimeEnabledSdkConfig config = - RuntimeEnabledSdkConfig.parseFrom( - Files.readAllBytes(runtimeEnabledSdkConfigPath), - ExtensionRegistry.getEmptyRegistry()); - String sdkPackageName = getSdkPackageName(); - - return config.getRuntimeEnabledSdkList().stream() - .filter(sdk -> sdk.getPackageName().equals(sdkPackageName)) - .map(RuntimeEnabledSdk::getResourcesPackageId) - .findFirst() - .orElseThrow( - () -> - new IllegalArgumentException( - "SDK mentioned in archive/bundle is not present in RuntimeEnabledSdkConfig " - + "file. SDK package name: " - + sdkPackageName)); - } catch (IOException e) { - throw new UncheckedIOException("Failed to read RuntimeEnabledSdkConfig file.", e); - } - } - - private String getSdkPackageName() { - checkArgument( - sdkArchivePath == null ^ sdkModuleConfigPath == null, - "Exactly one of --sdk-archive or --sdk-modules-config must be specified."); - - if (sdkArchivePath != null) { - return SdkInfoReader.readFromSdkArchive(sdkArchivePath).getPackageName(); - } - - return SdkInfoReader.readFromSdkModuleJsonFile(sdkModuleConfigPath).getPackageName(); - } - - private GenerateSdkSplitPropertiesCommand() {} -}
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/validatemodulesconfig/BUILD b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/validatemodulesconfig/BUILD deleted file mode 100644 index e1f0509..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/validatemodulesconfig/BUILD +++ /dev/null
@@ -1,19 +0,0 @@ -# Command to validate SDK modules config. - -load("@rules_java//java:defs.bzl", "java_library") - -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//:__subpackages__"], -) - -licenses(["notice"]) - -java_library( - name = "validatemodulesconfig", - srcs = glob(["*.java"]), - deps = [ - "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/info", - "@rules_android_maven//:info_picocli_picocli", - ], -)
diff --git a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/validatemodulesconfig/ValidateModulesConfigCommand.java b/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/validatemodulesconfig/ValidateModulesConfigCommand.java deleted file mode 100644 index f12dc88..0000000 --- a/src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox/validatemodulesconfig/ValidateModulesConfigCommand.java +++ /dev/null
@@ -1,64 +0,0 @@ -/* - * Copyright 2024 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.validatemodulesconfig; - -import com.google.devtools.build.android.sandboxedsdktoolbox.info.SdkInfo; -import com.google.devtools.build.android.sandboxedsdktoolbox.info.SdkInfoReader; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import picocli.CommandLine.Command; -import picocli.CommandLine.Option; - -/** Checks if the given modules config is valid and compatible with other build parameters. */ -@Command( - name = "validate-modules-config", - description = - "Checks if the given modules config is valid and compatible with other build" - + " parameters.") -public final class ValidateModulesConfigCommand implements Runnable { - - @Option(names = "--sdk-modules-config", required = true) - Path sdkModuleConfigPath; - - @Option(names = "--java-package-name", required = true) - String javaPackageName; - - @Option(names = "--output", required = true) - Path output; - - @Override - public void run() { - SdkInfo info = SdkInfoReader.readFromSdkModuleJsonFile(sdkModuleConfigPath); - - if (!info.getPackageName().equals(javaPackageName)) { - throw new IllegalArgumentException( - String.format( - "The package name in the modules config (%s) does not match the java package name " - + "(%s). This causes runtime errors when running the SDK as a split APK.", - info.getPackageName(), javaPackageName)); - } - - try { - // Empty file representing a successful validation. - Files.createFile(output); - } catch (IOException e) { - throw new IllegalStateException("Failed to create output file", e); - } - } - - private ValidateModulesConfigCommand() {} -}
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/BUILD b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/BUILD deleted file mode 100644 index 7365ecc..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/BUILD +++ /dev/null
@@ -1,24 +0,0 @@ -# Tests for extract-api-descriptors command. -load("@rules_java//java:defs.bzl", "java_test") - -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//src:__subpackages__"], -) - -licenses(["notice"]) - -java_test( - name = "ExtractApiDescriptorsCommandTest", - size = "small", - srcs = ["ExtractApiDescriptorsCommandTest.java"], - data = [ - "//src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/testlibrary:libtestlibrary.jar", - ], - deps = [ - "//src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils", - "@rules_android_maven//:com_google_guava_guava", - "@rules_android_maven//:com_google_truth_truth", - "@rules_android_maven//:junit_junit", - ], -)
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/ExtractApiDescriptorsCommandTest.java b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/ExtractApiDescriptorsCommandTest.java deleted file mode 100644 index 43d0937..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/ExtractApiDescriptorsCommandTest.java +++ /dev/null
@@ -1,65 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.apidescriptors; - -import static com.google.common.collect.ImmutableList.toImmutableList; -import static com.google.common.truth.Truth.assertThat; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.Runner.runCommand; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.TestData.JAVATESTS_DIR; - -import com.google.common.collect.ImmutableList; -import com.google.devtools.build.android.sandboxedsdktoolbox.utils.CommandResult; -import java.nio.file.Path; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public final class ExtractApiDescriptorsCommandTest { - @Rule public final TemporaryFolder testFolder = new TemporaryFolder(); - - private static final Path TEST_LIBRARY_DEPLOY_JAR = - JAVATESTS_DIR.resolve( - Path.of( - "com/google/devtools/build/android/sandboxedsdktoolbox", - "apidescriptors/testlibrary/libtestlibrary.jar")); - - @Test - public void extractApiDescriptors_keepsAnnotatedClassesInDescriptors() throws Exception { - Path outputFile = testFolder.getRoot().toPath().resolve("output.jar"); - - CommandResult result = - runCommand( - "extract-api-descriptors", - "--sdk-deploy-jar", - TEST_LIBRARY_DEPLOY_JAR.toString(), - "--output-sdk-api-descriptors", - outputFile.toString()); - ImmutableList<String> outputJarEntryNames = - new ZipFile(outputFile.toFile()).stream().map(ZipEntry::getName).collect(toImmutableList()); - - assertThat(result.getStatusCode()).isEqualTo(0); - assertThat(result.getOutput()).isEmpty(); - assertThat(outputJarEntryNames) - .containsExactly( - "com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/" - + "testlibrary/AnnotatedClass.class"); - } -}
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/ExtractApiDescriptorsFromAsarCommandTest.java b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/ExtractApiDescriptorsFromAsarCommandTest.java deleted file mode 100644 index ce971e9..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/ExtractApiDescriptorsFromAsarCommandTest.java +++ /dev/null
@@ -1,57 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.apidescriptors; - -import static com.google.common.truth.Truth.assertThat; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.Runner.runCommand; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.Zip.createZipWithSingleEntry; -import static java.nio.charset.StandardCharsets.UTF_8; - -import com.google.devtools.build.android.sandboxedsdktoolbox.utils.CommandResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public final class ExtractApiDescriptorsFromAsarCommandTest { - - @Rule public final TemporaryFolder testFolder = new TemporaryFolder(); - - @Test - public void extractApiDescriptors_fromValidAsar() throws Exception { - Path asar = Paths.get(testFolder.getRoot().getAbsolutePath(), "test.asar"); - byte[] sdkApiDescriptorContents = "fake descriptor contents".getBytes(UTF_8); - Path outputDescriptors = Paths.get(testFolder.getRoot().getAbsolutePath(), "descriptors.jar"); - createZipWithSingleEntry(asar, "sdk-interface-descriptors.jar", sdkApiDescriptorContents); - - CommandResult result = - runCommand( - "extract-api-descriptors-from-asar", - "--asar", - asar.toString(), - "--output-sdk-api-descriptors", - outputDescriptors.toString()); - - assertThat(result.getStatusCode()).isEqualTo(0); - assertThat(result.getOutput()).isEmpty(); - assertThat(Files.readAllBytes(outputDescriptors)).isEqualTo(sdkApiDescriptorContents); - } -}
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/testlibrary/AnnotatedClass.java b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/testlibrary/AnnotatedClass.java deleted file mode 100644 index 7aeee4f..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/testlibrary/AnnotatedClass.java +++ /dev/null
@@ -1,22 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.apidescriptors.testlibrary; - -import androidx.privacysandbox.tools.PrivacySandboxService; - -/** Class that should be part of the SDK API descriptors, since it's properly annotated. */ -@PrivacySandboxService -public final class AnnotatedClass {}
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/testlibrary/BUILD b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/testlibrary/BUILD deleted file mode 100644 index e208cb5..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/testlibrary/BUILD +++ /dev/null
@@ -1,18 +0,0 @@ -# Library to test SDK API descritptor extraction. - -load("//rules:rules.bzl", "android_library") - -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//:__subpackages__"], -) - -licenses(["notice"]) - -android_library( - name = "testlibrary", - srcs = glob(["**/*.java"]), - deps = [ - "@rules_android_maven//:androidx_privacysandbox_tools_tools", - ], -)
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/testlibrary/ClassThatShouldBeIgnored.java b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/testlibrary/ClassThatShouldBeIgnored.java deleted file mode 100644 index eb0dbbc..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/apidescriptors/testlibrary/ClassThatShouldBeIgnored.java +++ /dev/null
@@ -1,22 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.apidescriptors.testlibrary; - -/** - * Test class that should not be present in final SDK API descritors, since it doesn't have a - * Privacy Sandbox tool annotation. - */ -public final class ClassThatShouldBeIgnored {}
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/proguardspecs/BUILD b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/proguardspecs/BUILD deleted file mode 100644 index 1dc19be..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/proguardspecs/BUILD +++ /dev/null
@@ -1,22 +0,0 @@ -# Tests for generate-sdk-proguard-specs command. -load("@rules_java//java:defs.bzl", "java_test") - -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//:__subpackages__"], -) - -licenses(["notice"]) - -java_test( - name = "GenerateSdkProguardSpecsCommandTest", - size = "small", - srcs = ["GenerateSdkProguardSpecsCommandTest.java"], - deps = [ - "//src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils", - "@rules_android_maven//:com_android_tools_build_bundletool", - "@com_google_protobuf//:protobuf_java_util", - "@rules_android_maven//:com_google_truth_truth", - "@rules_android_maven//:junit_junit", - ], -)
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/proguardspecs/GenerateSdkProguardSpecsCommandTest.java b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/proguardspecs/GenerateSdkProguardSpecsCommandTest.java deleted file mode 100644 index b83b342..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/proguardspecs/GenerateSdkProguardSpecsCommandTest.java +++ /dev/null
@@ -1,78 +0,0 @@ -/* - * Copyright 2025 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.proguardspecs; - -import static com.google.common.truth.Truth.assertThat; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.Runner.runCommand; - -import com.android.bundle.SdkModulesConfigOuterClass.SdkModulesConfig; -import com.google.devtools.build.android.sandboxedsdktoolbox.utils.CommandResult; -import com.google.protobuf.util.JsonFormat; -import java.nio.file.Files; -import java.nio.file.Path; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public final class GenerateSdkProguardSpecsCommandTest { - - @Rule public final TemporaryFolder testFolder = new TemporaryFolder(); - - @Test - public void generateSdkProguardSpecs() throws Exception { - SdkModulesConfig config = - SdkModulesConfig.newBuilder() - .setSdkPackageName("com.example.package") - .setSdkProviderClassName("com.example.package.SdkProvider") - .setCompatSdkProviderClassName("com.example.package.CompatSdkProvider") - .build(); - Path output = testFolder.getRoot().toPath().resolve("output"); - - CommandResult result = runGenerateProguardSpecsCommand(config, output); - - assertThat(result.getStatusCode()).isEqualTo(0); - assertThat(result.getOutput()).isEmpty(); - assertThat(Files.readAllLines(output)) - .containsAtLeast( - "# Generated by the generate-sdk-proguard-specs command.", - "-keep @androidx.privacysandbox.tools.PrivacySandboxValue class ** { *; }", - "-keep @androidx.privacysandbox.tools.PrivacySandboxValue interface ** { *; }", - "-keep @androidx.privacysandbox.tools.PrivacySandboxInterface class ** { *; }", - "-keep @androidx.privacysandbox.tools.PrivacySandboxInterface interface ** { *; }", - "-keep @androidx.privacysandbox.tools.PrivacySandboxService class ** { *; }", - "-keep @androidx.privacysandbox.tools.PrivacySandboxService interface ** { *; }", - "-keep @androidx.privacysandbox.tools.PrivacySandboxCallback class ** { *; }", - "-keep @androidx.privacysandbox.tools.PrivacySandboxCallback interface ** { *; }", - "-keep class com.example.package.SdkProvider { *; }", - "-keep class com.example.package.CompatSdkProvider { *; }", - "-keep class com.example.package.RPackage { *; }"); - } - - private CommandResult runGenerateProguardSpecsCommand(SdkModulesConfig config, Path output) - throws Exception { - Path sdkModulesConfigPath = testFolder.getRoot().toPath().resolve("sdk-modules-config.pb.json"); - Files.writeString(sdkModulesConfigPath, JsonFormat.printer().print(config)); - return runCommand( - "generate-sdk-proguard-specs", - "--sdk-modules-config", - sdkModulesConfigPath.toString(), - "--output", - output.toString()); - } -}
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/BUILD b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/BUILD deleted file mode 100644 index e3ba7ff..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/BUILD +++ /dev/null
@@ -1,38 +0,0 @@ -# Tests for generate-runtime-enabled-sdk-config command. -load("@rules_java//java:defs.bzl", "java_test") - -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//:__subpackages__"], -) - -licenses(["notice"]) - -java_test( - name = "GenerateRuntimeEnabledSdkConfigCommandTest", - size = "small", - srcs = ["GenerateRuntimeEnabledSdkConfigCommandTest.java"], - data = glob(["testdata/*"]), - deps = [ - "//src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils", - "@com_google_protobuf//:protobuf_java", - "@rules_android_maven//:com_android_tools_build_bundletool", - "@rules_android_maven//:com_google_guava_guava", - "@rules_android_maven//:com_google_truth_truth", - "@rules_android_maven//:junit_junit", - ], -) - -java_test( - name = "GenerateRuntimeEnabledSdkTableCommandTest", - size = "small", - srcs = ["GenerateRuntimeEnabledSdkTableCommandTest.java"], - deps = [ - "//src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils", - "@rules_android_maven//:com_android_tools_build_bundletool", - "@rules_android_maven//:com_google_guava_guava", - "@com_google_protobuf//:protobuf_java_util", - "@rules_android_maven//:com_google_truth_truth", - "@rules_android_maven//:junit_junit", - ], -)
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/GenerateRuntimeEnabledSdkConfigCommandTest.java b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/GenerateRuntimeEnabledSdkConfigCommandTest.java deleted file mode 100644 index 454aa06..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/GenerateRuntimeEnabledSdkConfigCommandTest.java +++ /dev/null
@@ -1,349 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.runtimeenabledsdkconfig; - -import static com.google.common.collect.ImmutableList.toImmutableList; -import static com.google.common.truth.Truth.assertThat; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.Runner.runCommand; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.TestData.JAVATESTS_DIR; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.Zip.createZipWithSingleEntry; -import static java.util.stream.Collectors.joining; - -import com.android.bundle.RuntimeEnabledSdkConfigProto.RuntimeEnabledSdk; -import com.android.bundle.RuntimeEnabledSdkConfigProto.RuntimeEnabledSdkConfig; -import com.android.bundle.SdkMetadataOuterClass.SdkMetadata; -import com.android.bundle.SdkModulesConfigOuterClass.RuntimeEnabledSdkVersion; -import com.google.common.collect.ImmutableList; -import com.google.devtools.build.android.sandboxedsdktoolbox.utils.CommandResult; -import com.google.protobuf.ExtensionRegistry; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.stream.IntStream; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public final class GenerateRuntimeEnabledSdkConfigCommandTest { - - @Rule public final TemporaryFolder testFolder = new TemporaryFolder(); - - private static final Path TEST_DATA_DIR = - JAVATESTS_DIR.resolve( - Path.of( - "com/google/devtools/build/android/sandboxedsdktoolbox", - "runtimeenabledsdkconfig/testdata")); - private static final Path SDK_CONFIG_JSON_PATH = - TEST_DATA_DIR.resolve("com.example.sdkconfig.json"); - // Fake manifest XML tree file content, with extra data around the important bits. - private static final String MANIFEST_TREE_XML_MIN_VERSION_21 = - "should\nignore http://schemas.android.com/apk/res/android:minSdkVersion(0x0101020c)=21\n" - + "gibberish"; - private static final String MANIFEST_TREE_XML_MIN_VERSION_26 = - "should\nignore http://schemas.android.com/apk/res/android:minSdkVersion(0x0a01030e)=26\n" - + "gibberish"; - /* - The test key was generated with this command, its password is "android" - keytool -genkeypair \ - -alias androiddebugkey \ - -dname "CN=Android Debug, O=Android, C=US" \ - -keystore test_key \ - -sigalg SHA256withDSA \ - -validity 10950 - */ - private static final Path TEST_KEY_PATH = TEST_DATA_DIR.resolve("test_key"); - private static final String TEST_KEY_CERTIFICATE_DIGEST = - "91:8E:A3:7D:7D:D0:E0:A0:14:9F:21:28:83:95:8A:F0:80:E6:F9:7B:4D:5A:39:01:76:02:E8:" - + "2D:7D:FF:A9:10"; - private static final RuntimeEnabledSdkVersion SDK_VERSION = - RuntimeEnabledSdkVersion.newBuilder().setMajor(3).setMinor(2).setPatch(1).build(); - - @Test - public void generateConfig_onApi26_returnsIncreasingResourceIds() throws Exception { - String firstPackageName = "com.example.archivedsdk1"; - String secondPackageName = "com.example.archivedsdk2"; - String digest = "example:fake:digest"; - - RuntimeEnabledSdkConfig result = - runCommandAndReturnConfig( - MANIFEST_TREE_XML_MIN_VERSION_26, - ImmutableList.of( - SdkMetadata.newBuilder() - .setPackageName(firstPackageName) - .setSdkVersion(SDK_VERSION) - .setCertificateDigest(digest) - .build(), - SdkMetadata.newBuilder() - .setPackageName(secondPackageName) - .setSdkVersion(SDK_VERSION) - .setCertificateDigest(digest) - .build()), - ImmutableList.of()); - - RuntimeEnabledSdk expectedCommonSdk = - RuntimeEnabledSdk.newBuilder() - .setVersionMajor(SDK_VERSION.getMajor()) - .setVersionMinor(SDK_VERSION.getMinor()) - .setBuildTimeVersionPatch(SDK_VERSION.getPatch()) - .setCertificateDigest(digest) - .build(); - assertThat(result) - .isEqualTo( - RuntimeEnabledSdkConfig.newBuilder() - .addRuntimeEnabledSdk( - expectedCommonSdk.toBuilder() - .setPackageName(firstPackageName) - .setResourcesPackageId(128)) - .addRuntimeEnabledSdk( - expectedCommonSdk.toBuilder() - .setPackageName(secondPackageName) - .setResourcesPackageId(129)) - .build()); - } - - @Test - public void generateConfig_onApi21_returnsDecreasingResourceIds() throws Exception { - String firstPackageName = "com.example.archivedsdk1"; - String secondPackageName = "com.example.archivedsdk2"; - String digest = "example:fake:digest"; - - RuntimeEnabledSdkConfig result = - runCommandAndReturnConfig( - MANIFEST_TREE_XML_MIN_VERSION_21, - ImmutableList.of( - SdkMetadata.newBuilder() - .setPackageName(firstPackageName) - .setSdkVersion(SDK_VERSION) - .setCertificateDigest(digest) - .build(), - SdkMetadata.newBuilder() - .setPackageName(secondPackageName) - .setSdkVersion(SDK_VERSION) - .setCertificateDigest(digest) - .build()), - ImmutableList.of()); - - RuntimeEnabledSdk expectedCommonSdk = - RuntimeEnabledSdk.newBuilder() - .setVersionMajor(SDK_VERSION.getMajor()) - .setVersionMinor(SDK_VERSION.getMinor()) - .setBuildTimeVersionPatch(SDK_VERSION.getPatch()) - .setCertificateDigest(digest) - .build(); - assertThat(result) - .isEqualTo( - RuntimeEnabledSdkConfig.newBuilder() - .addRuntimeEnabledSdk( - expectedCommonSdk.toBuilder() - .setPackageName(firstPackageName) - .setResourcesPackageId(126)) - .addRuntimeEnabledSdk( - expectedCommonSdk.toBuilder() - .setPackageName(secondPackageName) - .setResourcesPackageId(125)) - .build()); - } - - @Test - public void generateConfig_forModuleConfig_usesDebugKeyDigest() throws Exception { - String sdkArchivePackageName = "com.example.sdkarchive"; - String productionDigest = "fake:prod:digest"; - - RuntimeEnabledSdkConfig result = - runCommandAndReturnConfig( - MANIFEST_TREE_XML_MIN_VERSION_26, - ImmutableList.of( - SdkMetadata.newBuilder() - .setPackageName(sdkArchivePackageName) - .setSdkVersion(SDK_VERSION) - .setCertificateDigest(productionDigest) - .build()), - ImmutableList.of(SDK_CONFIG_JSON_PATH)); - - assertThat(result) - .isEqualTo( - RuntimeEnabledSdkConfig.newBuilder() - .addRuntimeEnabledSdk( - RuntimeEnabledSdk.newBuilder() - .setPackageName("com.example.sdkfrombundle") - .setVersionMajor(42) - .setVersionMinor(25) - .setBuildTimeVersionPatch(2) - .setCertificateDigest(TEST_KEY_CERTIFICATE_DIGEST) - .setResourcesPackageId(128)) - .addRuntimeEnabledSdk( - RuntimeEnabledSdk.newBuilder() - .setPackageName(sdkArchivePackageName) - .setCertificateDigest(productionDigest) - .setVersionMajor(SDK_VERSION.getMajor()) - .setVersionMinor(SDK_VERSION.getMinor()) - .setBuildTimeVersionPatch(SDK_VERSION.getPatch()) - .setResourcesPackageId(129)) - .build()); - } - - @Test - public void generateConfig_withoutSdks_fails() throws Exception { - Path outputConfig = testFolder.newFile().toPath(); - ImmutableList<String> args = - buildArgs( - outputConfig, MANIFEST_TREE_XML_MIN_VERSION_21, ImmutableList.of(), ImmutableList.of()); - CommandResult result = runCommand(args.toArray(String[]::new)); - - assertThat(result.getStatusCode()).isEqualTo(1); - assertThat(result.getOutput()) - .contains("At least one of --sdk-module-configs or --sdk-archives must be specified."); - } - - @Test - public void generateConfig_for51Sdks_onApi21_fails() throws Exception { - Path outputConfig = testFolder.newFile().toPath(); - - ImmutableList<String> args = - buildArgs( - outputConfig, - MANIFEST_TREE_XML_MIN_VERSION_21, - IntStream.range(0, 51) - .mapToObj(i -> SdkMetadata.newBuilder().setPackageName("com.example." + i).build()) - .collect(toImmutableList()), - ImmutableList.of()); - CommandResult result = runCommand(args.toArray(String[]::new)); - - assertThat(result.getStatusCode()).isEqualTo(1); - assertThat(result.getOutput()).contains("Too many SDK dependencies (51)."); - } - - @Test - public void generateConfig_for51Sdks_onApi26_success() throws Exception { - Path outputConfig = testFolder.newFile().toPath(); - - ImmutableList<String> args = - buildArgs( - outputConfig, - MANIFEST_TREE_XML_MIN_VERSION_26, - IntStream.range(0, 51) - .mapToObj(i -> SdkMetadata.newBuilder().setPackageName("com.example." + i).build()) - .collect(toImmutableList()), - ImmutableList.of()); - CommandResult result = runCommand(args.toArray(String[]::new)); - - assertThat(result.getStatusCode()).isEqualTo(0); - assertThat(result.getOutput()).isEmpty(); - } - - @Test - public void generateConfig_for129Sdks_onApi26_fails() throws Exception { - Path outputConfig = testFolder.newFile().toPath(); - - ImmutableList<String> args = - buildArgs( - outputConfig, - MANIFEST_TREE_XML_MIN_VERSION_26, - IntStream.range(0, 129) - .mapToObj(i -> SdkMetadata.newBuilder().setPackageName("com.example." + i).build()) - .collect(toImmutableList()), - ImmutableList.of()); - CommandResult result = runCommand(args.toArray(String[]::new)); - - assertThat(result.getStatusCode()).isEqualTo(1); - assertThat(result.getOutput()).contains("Too many SDK dependencies (129)."); - } - - @Test - public void generateConfig_withMissingMinSdkVersion_fails() throws Exception { - Path outputConfig = testFolder.newFile().toPath(); - - ImmutableList<String> args = - buildArgs(outputConfig, "", ImmutableList.of(), ImmutableList.of(SDK_CONFIG_JSON_PATH)); - CommandResult result = runCommand(args.toArray(String[]::new)); - - assertThat(result.getStatusCode()).isEqualTo(1); - assertThat(result.getOutput()).contains("Min SDK version missing from manifest xml tree file."); - } - - /** - * Runs the generate-runtime-enabled-sdk-config command with the given android manifest, sdk - * archives and SDK module configs. - * - * <p>The archives are represented as a single zip with the given SDK Metadata messages inside. - */ - private RuntimeEnabledSdkConfig runCommandAndReturnConfig( - String manifestXmlTree, - ImmutableList<SdkMetadata> sdkArchives, - ImmutableList<Path> sdkModuleConfigPaths) - throws Exception { - Path outputConfig = testFolder.newFile().toPath(); - ImmutableList<String> args = - buildArgs(outputConfig, manifestXmlTree, sdkArchives, sdkModuleConfigPaths); - CommandResult result = runCommand(args.toArray(String[]::new)); - - assertThat(result.getStatusCode()).isEqualTo(0); - assertThat(result.getOutput()).isEmpty(); - return readConfig(outputConfig); - } - - private ImmutableList<String> buildArgs( - Path outputConfig, - String manifestXmlTree, - ImmutableList<SdkMetadata> sdkArchives, - ImmutableList<Path> sdkModuleConfigPaths) - throws Exception { - Path manifestXmlTreePath = testFolder.newFile("manifest_xml_tree.txt").toPath(); - Files.writeString(manifestXmlTreePath, manifestXmlTree); - - ImmutableList.Builder<String> args = ImmutableList.builder(); - args.add( - "generate-runtime-enabled-sdk-config", - "--debug-keystore", - TEST_KEY_PATH.toString(), - "--debug-keystore-pass", - "android", - "--debug-keystore-alias", - "androiddebugkey", - "--output-config", - outputConfig.toString(), - "--manifest-xml-tree", - manifestXmlTreePath.toString()); - - if (!sdkModuleConfigPaths.isEmpty()) { - args.add( - "--sdk-module-configs", - sdkModuleConfigPaths.stream().map(Path::toString).collect(joining(","))); - } - - if (!sdkArchives.isEmpty()) { - ArrayList<String> sdkArchivePaths = new ArrayList<>(); - for (SdkMetadata sdkMetadata : sdkArchives) { - Path sdkArchivePath = - testFolder.getRoot().toPath().resolve(sdkMetadata.hashCode() + ".asar"); - createZipWithSingleEntry(sdkArchivePath, "SdkMetadata.pb", sdkMetadata.toByteArray()); - sdkArchivePaths.add(sdkArchivePath.toString()); - } - args.add("--sdk-archives", String.join(",", sdkArchivePaths)); - } - - return args.build(); - } - - private static RuntimeEnabledSdkConfig readConfig(Path configPath) throws IOException { - return RuntimeEnabledSdkConfig.parseFrom( - Files.readAllBytes(configPath), ExtensionRegistry.getEmptyRegistry()); - } -}
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/GenerateRuntimeEnabledSdkTableCommandTest.java b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/GenerateRuntimeEnabledSdkTableCommandTest.java deleted file mode 100644 index 28424c9..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/GenerateRuntimeEnabledSdkTableCommandTest.java +++ /dev/null
@@ -1,148 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.runtimeenabledsdkconfig; - -import static com.google.common.truth.Truth.assertThat; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.Runner.runCommand; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.TestData.readFromAbsolutePath; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.Zip.createZipWithSingleEntry; - -import com.android.bundle.SdkMetadataOuterClass.SdkMetadata; -import com.android.bundle.SdkModulesConfigOuterClass.RuntimeEnabledSdkVersion; -import com.android.bundle.SdkModulesConfigOuterClass.SdkModulesConfig; -import com.google.common.collect.ImmutableList; -import com.google.devtools.build.android.sandboxedsdktoolbox.utils.CommandResult; -import com.google.protobuf.util.JsonFormat; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public final class GenerateRuntimeEnabledSdkTableCommandTest { - - @Rule public final TemporaryFolder testFolder = new TemporaryFolder(); - - @Test - public void generateTable_forMultipleSdkArchives_success() throws Exception { - String firstPackageName = "com.example.archivedsdk1"; - String secondPackageName = "com.example.archivedsdk2"; - - String tableContents = - runCommandAndReturnTableContents( - ImmutableList.of( - SdkMetadata.newBuilder() - .setPackageName(firstPackageName) - .setSdkVersion(RuntimeEnabledSdkVersion.newBuilder().setMajor(42).setMinor(42)) - .build(), - SdkMetadata.newBuilder() - .setPackageName(secondPackageName) - .setSdkVersion(RuntimeEnabledSdkVersion.newBuilder().setMajor(1).setMinor(2)) - .build()), - ImmutableList.of()); - - String expectedTable = - "<runtime-enabled-sdk-table>\n" - + " <runtime-enabled-sdk>\n" - + " <package-name>com.example.archivedsdk1</package-name>\n" - + " <version-major>420042</version-major>\n" - + " <compat-config-path>RuntimeEnabledSdk-com.example.archivedsdk1/CompatSdkConfig.xml</compat-config-path>\n" - + " </runtime-enabled-sdk>\n" - + " <runtime-enabled-sdk>\n" - + " <package-name>com.example.archivedsdk2</package-name>\n" - + " <version-major>10002</version-major>\n" - + " <compat-config-path>RuntimeEnabledSdk-com.example.archivedsdk2/CompatSdkConfig.xml</compat-config-path>\n" - + " </runtime-enabled-sdk>\n" - + "</runtime-enabled-sdk-table>"; - assertThat(tableContents).isEqualTo(expectedTable); - } - - @Test - public void generateTable_forMultipleSdkBundles_success() throws Exception { - String firstPackageName = "com.example.sdkbundle1"; - String secondPackageName = "com.example.sdkbundle2"; - - String tableContents = - runCommandAndReturnTableContents( - ImmutableList.of(), - ImmutableList.of( - SdkModulesConfig.newBuilder() - .setSdkPackageName(firstPackageName) - .setSdkVersion(RuntimeEnabledSdkVersion.newBuilder().setMajor(42).setMinor(42)) - .build(), - SdkModulesConfig.newBuilder() - .setSdkPackageName(secondPackageName) - .setSdkVersion(RuntimeEnabledSdkVersion.newBuilder().setMajor(1).setMinor(2)) - .build())); - - String expectedTable = - "<runtime-enabled-sdk-table>\n" - + " <runtime-enabled-sdk>\n" - + " <package-name>com.example.sdkbundle1</package-name>\n" - + " <version-major>420042</version-major>\n" - + " <compat-config-path>RuntimeEnabledSdk-com.example.sdkbundle1/CompatSdkConfig.xml</compat-config-path>\n" - + " </runtime-enabled-sdk>\n" - + " <runtime-enabled-sdk>\n" - + " <package-name>com.example.sdkbundle2</package-name>\n" - + " <version-major>10002</version-major>\n" - + " <compat-config-path>RuntimeEnabledSdk-com.example.sdkbundle2/CompatSdkConfig.xml</compat-config-path>\n" - + " </runtime-enabled-sdk>\n" - + "</runtime-enabled-sdk-table>"; - assertThat(tableContents).isEqualTo(expectedTable); - } - - /** Runs the generate-runtime-enabled-sdk-table command with the given RuntimeEnabledSdkConfig. */ - private String runCommandAndReturnTableContents( - ImmutableList<SdkMetadata> sdkArchives, ImmutableList<SdkModulesConfig> sdkModulesConfigList) - throws Exception { - Path outputTable = testFolder.newFile().toPath(); - - ImmutableList.Builder<String> args = ImmutableList.builder(); - args.add("generate-runtime-enabled-sdk-table", "--output-table", outputTable.toString()); - - if (!sdkArchives.isEmpty()) { - ArrayList<String> sdkArchivePaths = new ArrayList<>(); - for (SdkMetadata sdkMetadata : sdkArchives) { - Path sdkArchivePath = - testFolder.getRoot().toPath().resolve(sdkMetadata.hashCode() + ".asar"); - createZipWithSingleEntry(sdkArchivePath, "SdkMetadata.pb", sdkMetadata.toByteArray()); - sdkArchivePaths.add(sdkArchivePath.toString()); - } - args.add("--sdk-archives", String.join(",", sdkArchivePaths)); - } - - if (!sdkModulesConfigList.isEmpty()) { - ArrayList<String> sdkModulesConfigPaths = new ArrayList<>(); - for (SdkModulesConfig sdkModulesConfig : sdkModulesConfigList) { - Path sdkModulesConfigPath = - testFolder.getRoot().toPath().resolve(sdkModulesConfig.hashCode() + ".pb.json"); - Files.writeString(sdkModulesConfigPath, JsonFormat.printer().print(sdkModulesConfig)); - sdkModulesConfigPaths.add(sdkModulesConfigPath.toString()); - } - args.add("--sdk-module-configs", String.join(",", sdkModulesConfigPaths)); - } - - CommandResult result = runCommand(args.build().toArray(String[]::new)); - - assertThat(result.getStatusCode()).isEqualTo(0); - assertThat(result.getOutput()).isEmpty(); - return readFromAbsolutePath(outputTable); - } -}
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/testdata/com.example.sdkconfig.json b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/testdata/com.example.sdkconfig.json deleted file mode 100644 index a552cde..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/testdata/com.example.sdkconfig.json +++ /dev/null
@@ -1,9 +0,0 @@ -{ - "sdk_package_name": "com.example.sdkfrombundle", - "sdk_provider_class_name": "com.testsdk.lib.FakeSdkProvider", - "sdk_version": { - "major": 42, - "minor": 25, - "patch": 2 - } -} \ No newline at end of file
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/testdata/test_key b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/testdata/test_key deleted file mode 100644 index e0061a5..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/runtimeenabledsdkconfig/testdata/test_key +++ /dev/null Binary files differ
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/BUILD b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/BUILD deleted file mode 100644 index 164d551..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/BUILD +++ /dev/null
@@ -1,23 +0,0 @@ -# Tests for generate-sdk-dependencies-manifest command. -load("@rules_java//java:defs.bzl", "java_test") - -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//:__subpackages__"], -) - -licenses(["notice"]) - -java_test( - name = "GenerateSdkDependenciesManifestCommandTest", - size = "small", - srcs = ["GenerateSdkDependenciesManifestCommandTest.java"], - data = glob(["testdata/*"]), - deps = [ - "//src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils", - "@rules_android_maven//:com_android_tools_build_bundletool", - "@com_google_protobuf//:protobuf_java_util", - "@rules_android_maven//:com_google_truth_truth", - "@rules_android_maven//:junit_junit", - ], -)
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/GenerateSdkDependenciesManifestCommandTest.java b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/GenerateSdkDependenciesManifestCommandTest.java deleted file mode 100644 index 749320e..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/GenerateSdkDependenciesManifestCommandTest.java +++ /dev/null
@@ -1,159 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.sdkdependenciesmanifest; - -import static com.google.common.truth.Truth.assertThat; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.Runner.runCommand; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.TestData.JAVATESTS_DIR; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.TestData.readFromAbsolutePath; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.Zip.createZipWithSingleEntry; - -import com.android.bundle.SdkMetadataOuterClass.SdkMetadata; -import com.google.devtools.build.android.sandboxedsdktoolbox.utils.CommandResult; -import com.google.protobuf.util.JsonFormat; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public final class GenerateSdkDependenciesManifestCommandTest { - - @Rule public final TemporaryFolder testFolder = new TemporaryFolder(); - - private static final Path TEST_DATA_DIR = - JAVATESTS_DIR.resolve( - Path.of( - "com/google/devtools/build/android/sandboxedsdktoolbox", - "sdkdependenciesmanifest/testdata")); - private static final Path FIRST_SDK_CONFIG_JSON_PATH = - TEST_DATA_DIR.resolve("com.example.firstsdkconfig.json"); - private static final Path SECOND_SDK_CONFIG_JSON_PATH = - TEST_DATA_DIR.resolve("com.example.secondsdkconfig.json"); - private static final Path ARCHIVE_CONFIG_JSON_PATH = - TEST_DATA_DIR.resolve("com.example.archivedsdkmetadata.json"); - - /* - The test key was generated with this command, its password is "android" - keytool -genkeypair \ - -alias androiddebugkey \ - -dname "CN=Android Debug, O=Android, C=US" \ - -keystore test_key \ - -sigalg SHA256withDSA \ - -validity 10950 - */ - private static final Path TEST_KEY_PATH = TEST_DATA_DIR.resolve("test_key"); - - @Test - public void generateManifest_forSingleSdkModuleConfig_success() throws Exception { - String manifestPackage = "com.example.generatedmanifest"; - Path outputFile = testFolder.newFile().toPath(); - - CommandResult result = - runCommand( - "generate-sdk-dependencies-manifest", - "--manifest-package", - manifestPackage, - "--sdk-module-configs", - FIRST_SDK_CONFIG_JSON_PATH.toString(), - "--debug-keystore", - TEST_KEY_PATH.toString(), - "--debug-keystore-pass", - "android", - "--debug-keystore-alias", - "androiddebugkey", - "--output-manifest", - outputFile.toString()); - - assertThat(result.getStatusCode()).isEqualTo(0); - assertThat(result.getOutput()).isEmpty(); - assertThat(readFromAbsolutePath(outputFile)) - .isEqualTo(readFromAbsolutePath(TEST_DATA_DIR.resolve("expected_manifest_single_sdk.xml"))); - } - - @Test - public void generateManifest_forMultipleSdkModuleConfigs_success() throws Exception { - String manifestPackage = "com.example.generatedmanifest"; - String configPaths = - String.format("%s,%s", FIRST_SDK_CONFIG_JSON_PATH, SECOND_SDK_CONFIG_JSON_PATH); - Path outputFile = testFolder.newFile().toPath(); - - CommandResult result = - runCommand( - "generate-sdk-dependencies-manifest", - "--manifest-package", - manifestPackage, - "--sdk-module-configs", - configPaths, - "--debug-keystore", - TEST_KEY_PATH.toString(), - "--debug-keystore-pass", - "android", - "--debug-keystore-alias", - "androiddebugkey", - "--output-manifest", - outputFile.toString()); - - assertThat(result.getStatusCode()).isEqualTo(0); - assertThat(result.getOutput()).isEmpty(); - assertThat(readFromAbsolutePath(outputFile)) - .isEqualTo( - readFromAbsolutePath(TEST_DATA_DIR.resolve("expected_manifest_multiple_sdks.xml"))); - } - - @Test - public void generateManifest_forSdksAndArchives_success() throws Exception { - String manifestPackage = "com.example.generatedmanifest"; - // Create a zip with a single file containing the SdkMetadata proto message, serialized. - Path archiveConfigPath = testFolder.getRoot().toPath().resolve("sdk.asar"); - createZipWithSingleEntry(archiveConfigPath, "SdkMetadata.pb", readSdkMetadata().toByteArray()); - Path outputFile = testFolder.newFile().toPath(); - - CommandResult result = - runCommand( - "generate-sdk-dependencies-manifest", - "--manifest-package", - manifestPackage, - "--sdk-module-configs", - FIRST_SDK_CONFIG_JSON_PATH.toString(), - "--sdk-archives", - archiveConfigPath.toString(), - "--debug-keystore", - TEST_KEY_PATH.toString(), - "--debug-keystore-pass", - "android", - "--debug-keystore-alias", - "androiddebugkey", - "--output-manifest", - outputFile.toString()); - - assertThat(result.getStatusCode()).isEqualTo(0); - assertThat(result.getOutput()).isEmpty(); - assertThat(readFromAbsolutePath(outputFile)) - .isEqualTo( - readFromAbsolutePath(TEST_DATA_DIR.resolve("expected_manifest_with_archived_sdk.xml"))); - } - - private static SdkMetadata readSdkMetadata() throws IOException { - SdkMetadata.Builder metadata = SdkMetadata.newBuilder(); - JsonFormat.parser().merge(Files.newBufferedReader(ARCHIVE_CONFIG_JSON_PATH), metadata); - return metadata.build(); - } -}
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/com.example.archivedsdkmetadata.json b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/com.example.archivedsdkmetadata.json deleted file mode 100644 index d3be443..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/com.example.archivedsdkmetadata.json +++ /dev/null
@@ -1,11 +0,0 @@ -{ - "package_name": "com.example.archivedsdk", - "sdk_version": { - "major": 33, - "minor": 2, - "patch": 1 - }, - - // We always use the debug key digest instead of the one provided in the ASAR. - "certificate_digest": "fake digest that should be ignored." -} \ No newline at end of file
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/com.example.firstsdkconfig.json b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/com.example.firstsdkconfig.json deleted file mode 100644 index ac7561e..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/com.example.firstsdkconfig.json +++ /dev/null
@@ -1,9 +0,0 @@ -{ - "sdk_package_name": "com.example.firstsdkconfig", - "sdk_provider_class_name": "com.testsdk.lib.FakeSdkProvider", - "sdk_version": { - "major": 2, - "minor": 3, - "patch": 1 - } -} \ No newline at end of file
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/com.example.secondsdkconfig.json b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/com.example.secondsdkconfig.json deleted file mode 100644 index 7320a85..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/com.example.secondsdkconfig.json +++ /dev/null
@@ -1,9 +0,0 @@ -{ - "sdk_package_name": "com.example.secondsdkconfig", - "sdk_provider_class_name": "com.testsdk.lib.FakeSdkProvider", - "sdk_version": { - "major": 42, - "minor": 1, - "patch": 0 - } -} \ No newline at end of file
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/expected_manifest_multiple_sdks.xml b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/expected_manifest_multiple_sdks.xml deleted file mode 100644 index 1360bf1..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/expected_manifest_multiple_sdks.xml +++ /dev/null
@@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="utf-8" standalone="no"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.generatedmanifest"> - <application> - <uses-sdk-library android:certDigest="91:8E:A3:7D:7D:D0:E0:A0:14:9F:21:28:83:95:8A:F0:80:E6:F9:7B:4D:5A:39:01:76:02:E8:2D:7D:FF:A9:10" android:name="com.example.firstsdkconfig" android:versionMajor="20003"/> - <uses-sdk-library android:certDigest="91:8E:A3:7D:7D:D0:E0:A0:14:9F:21:28:83:95:8A:F0:80:E6:F9:7B:4D:5A:39:01:76:02:E8:2D:7D:FF:A9:10" android:name="com.example.secondsdkconfig" android:versionMajor="420001"/> - </application> -</manifest> \ No newline at end of file
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/expected_manifest_single_sdk.xml b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/expected_manifest_single_sdk.xml deleted file mode 100644 index 4bfc234..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/expected_manifest_single_sdk.xml +++ /dev/null
@@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="utf-8" standalone="no"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.generatedmanifest"> - <application> - <uses-sdk-library android:certDigest="91:8E:A3:7D:7D:D0:E0:A0:14:9F:21:28:83:95:8A:F0:80:E6:F9:7B:4D:5A:39:01:76:02:E8:2D:7D:FF:A9:10" android:name="com.example.firstsdkconfig" android:versionMajor="20003"/> - </application> -</manifest> \ No newline at end of file
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/expected_manifest_with_archived_sdk.xml b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/expected_manifest_with_archived_sdk.xml deleted file mode 100644 index e3bab8f..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/expected_manifest_with_archived_sdk.xml +++ /dev/null
@@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="utf-8" standalone="no"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.generatedmanifest"> - <application> - <uses-sdk-library android:certDigest="91:8E:A3:7D:7D:D0:E0:A0:14:9F:21:28:83:95:8A:F0:80:E6:F9:7B:4D:5A:39:01:76:02:E8:2D:7D:FF:A9:10" android:name="com.example.firstsdkconfig" android:versionMajor="20003"/> - <uses-sdk-library android:certDigest="91:8E:A3:7D:7D:D0:E0:A0:14:9F:21:28:83:95:8A:F0:80:E6:F9:7B:4D:5A:39:01:76:02:E8:2D:7D:FF:A9:10" android:name="com.example.archivedsdk" android:versionMajor="330002"/> - </application> -</manifest> \ No newline at end of file
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/test_key b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/test_key deleted file mode 100644 index e0061a5..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdkdependenciesmanifest/testdata/test_key +++ /dev/null Binary files differ
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/BUILD b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/BUILD deleted file mode 100644 index caac104..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/BUILD +++ /dev/null
@@ -1,24 +0,0 @@ -# Tests for generate-sdk-split-properties command. -load("@rules_java//java:defs.bzl", "java_test") - -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//:__subpackages__"], -) - -licenses(["notice"]) - -java_test( - name = "GenerateSdkSplitPropertiesCommandTest", - size = "small", - srcs = ["GenerateSdkSplitPropertiesCommandTest.java"], - data = glob(["testdata/*"]), - deps = [ - "//src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils", - "@com_google_protobuf//:protobuf_java_util", - "@rules_android_maven//:com_android_tools_build_bundletool", - "@rules_android_maven//:com_google_guava_guava", - "@rules_android_maven//:com_google_truth_truth", - "@rules_android_maven//:junit_junit", - ], -)
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/GenerateSdkSplitPropertiesCommandTest.java b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/GenerateSdkSplitPropertiesCommandTest.java deleted file mode 100644 index 5284718..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/GenerateSdkSplitPropertiesCommandTest.java +++ /dev/null
@@ -1,251 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.sdksplitproperties; - -import static com.google.common.truth.Truth.assertThat; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.Runner.runCommand; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.TestData.JAVATESTS_DIR; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.Zip.createZipWithSingleEntry; - -import com.android.bundle.RuntimeEnabledSdkConfigProto.RuntimeEnabledSdk; -import com.android.bundle.RuntimeEnabledSdkConfigProto.RuntimeEnabledSdkConfig; -import com.android.bundle.RuntimeEnabledSdkConfigProto.SdkSplitPropertiesInheritedFromApp; -import com.android.bundle.SdkMetadataOuterClass.SdkMetadata; -import com.android.bundle.SdkModulesConfigOuterClass.SdkModulesConfig; -import com.google.common.collect.ImmutableList; -import com.google.devtools.build.android.sandboxedsdktoolbox.utils.CommandResult; -import com.google.protobuf.util.JsonFormat; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Optional; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public final class GenerateSdkSplitPropertiesCommandTest { - @Rule public final TemporaryFolder testFolder = new TemporaryFolder(); - - private static final Path TEST_DATA_DIR = - JAVATESTS_DIR.resolve( - Path.of( - "com/google/devtools/build/android/sandboxedsdktoolbox", - "sdksplitproperties/testdata")); - private static final Path MANIFEST_XML_TREE_DUMP_PATH = - TEST_DATA_DIR.resolve("valid_xmltree_dump.txt"); - private static final Path MANIFEST_XML_TREE_DUMP_WITH_DUPLICATE_VALUES_PATH = - TEST_DATA_DIR.resolve("xmltree_dump_with_duplicate_values.txt"); - private static final String HOST_APP_PACKAGE_NAME = "com.example.host.app"; - private static final int HOST_APP_MIN_SDK_VERSION = 30; - private static final int HOST_APP_VERSION_CODE = 42; - private static final int SDK_RESOURCE_ID = 127; - - @Test - public void generateProperties_withSdkArchive_succeeds() throws Exception { - String sdkPackageName = "com.android.sdk.test"; - RuntimeEnabledSdkConfig config = - RuntimeEnabledSdkConfig.newBuilder() - .addRuntimeEnabledSdk( - RuntimeEnabledSdk.newBuilder() - .setPackageName(sdkPackageName) - .setResourcesPackageId(SDK_RESOURCE_ID)) - .build(); - SdkMetadata metadata = SdkMetadata.newBuilder().setPackageName(sdkPackageName).build(); - - SdkSplitPropertiesInheritedFromApp properties = - runCommandAndReturnProperties( - config, MANIFEST_XML_TREE_DUMP_PATH, Optional.of(metadata), Optional.empty()); - - assertThat(properties) - .isEqualTo( - SdkSplitPropertiesInheritedFromApp.newBuilder() - .setPackageName(HOST_APP_PACKAGE_NAME) - .setMinSdkVersion(HOST_APP_MIN_SDK_VERSION) - .setVersionCode(HOST_APP_VERSION_CODE) - .setResourcesPackageId(SDK_RESOURCE_ID) - .build()); - } - - @Test - public void generateProperties_withModuleConfig_succeeds() throws Exception { - String sdkPackageName = "com.android.sdk.test"; - RuntimeEnabledSdkConfig config = - RuntimeEnabledSdkConfig.newBuilder() - .addRuntimeEnabledSdk( - RuntimeEnabledSdk.newBuilder() - .setPackageName(sdkPackageName) - .setResourcesPackageId(SDK_RESOURCE_ID)) - .build(); - SdkModulesConfig modulesConfig = - SdkModulesConfig.newBuilder().setSdkPackageName(sdkPackageName).build(); - - SdkSplitPropertiesInheritedFromApp properties = - runCommandAndReturnProperties( - config, MANIFEST_XML_TREE_DUMP_PATH, Optional.empty(), Optional.of(modulesConfig)); - - assertThat(properties) - .isEqualTo( - SdkSplitPropertiesInheritedFromApp.newBuilder() - .setPackageName(HOST_APP_PACKAGE_NAME) - .setMinSdkVersion(HOST_APP_MIN_SDK_VERSION) - .setVersionCode(HOST_APP_VERSION_CODE) - .setResourcesPackageId(SDK_RESOURCE_ID) - .build()); - } - - @Test - public void generateProperties_readsManifestWithDuplicateValues_usesFirstValuesAndSucceeds() - throws Exception { - String sdkPackageName = "com.android.sdk.test"; - RuntimeEnabledSdkConfig config = - RuntimeEnabledSdkConfig.newBuilder() - .addRuntimeEnabledSdk( - RuntimeEnabledSdk.newBuilder() - .setPackageName(sdkPackageName) - .setResourcesPackageId(SDK_RESOURCE_ID)) - .build(); - SdkMetadata metadata = SdkMetadata.newBuilder().setPackageName(sdkPackageName).build(); - - SdkSplitPropertiesInheritedFromApp properties = - runCommandAndReturnProperties( - config, - MANIFEST_XML_TREE_DUMP_WITH_DUPLICATE_VALUES_PATH, - Optional.of(metadata), - Optional.empty()); - - assertThat(properties) - .isEqualTo( - SdkSplitPropertiesInheritedFromApp.newBuilder() - .setPackageName(HOST_APP_PACKAGE_NAME) - .setMinSdkVersion(HOST_APP_MIN_SDK_VERSION) - .setVersionCode(HOST_APP_VERSION_CODE) - .setResourcesPackageId(SDK_RESOURCE_ID) - .build()); - } - - @Test - public void generateProperties_withNoSdkArchiveOrModuleConfig_fails() throws Exception { - String sdkPackageName = "com.android.sdk.test"; - RuntimeEnabledSdkConfig config = - RuntimeEnabledSdkConfig.newBuilder() - .addRuntimeEnabledSdk( - RuntimeEnabledSdk.newBuilder() - .setPackageName(sdkPackageName) - .setResourcesPackageId(SDK_RESOURCE_ID)) - .build(); - ImmutableList<String> args = - buildArgs( - testFolder.newFile().toPath(), - config, - MANIFEST_XML_TREE_DUMP_PATH, - Optional.empty(), - Optional.empty()); - - CommandResult result = runCommand(args.toArray(String[]::new)); - - assertThat(result.getStatusCode()).isEqualTo(1); - assertThat(result.getOutput()) - .contains("Exactly one of --sdk-archive or --sdk-modules-config must be specified."); - } - - @Test - public void generateProperties_withSdkMissingFromConfig_fails() throws Exception { - String sdkPackageName = "com.android.sdk.test"; - RuntimeEnabledSdkConfig config = - RuntimeEnabledSdkConfig.newBuilder() - .addRuntimeEnabledSdk( - RuntimeEnabledSdk.newBuilder() - .setPackageName("anotherSdkPackageName") - .setResourcesPackageId(SDK_RESOURCE_ID)) - .build(); - ImmutableList<String> args = - buildArgs( - testFolder.newFile().toPath(), - config, - MANIFEST_XML_TREE_DUMP_PATH, - Optional.of(SdkMetadata.newBuilder().setPackageName(sdkPackageName).build()), - Optional.empty()); - - CommandResult result = runCommand(args.toArray(String[]::new)); - - assertThat(result.getStatusCode()).isEqualTo(1); - assertThat(result.getOutput()) - .contains( - "SDK mentioned in archive/bundle is not present in RuntimeEnabledSdkConfig file. SDK" - + " package name: com.android.sdk.test"); - } - - /** - * Runs the generate-sdk-split-properties command with the given parameters. The resulting - * properties are parsed from the output file and returned in proto format for easier assertion. - */ - private SdkSplitPropertiesInheritedFromApp runCommandAndReturnProperties( - RuntimeEnabledSdkConfig config, - Path manifestXmlTreePath, - Optional<SdkMetadata> sdkArchiveMetadata, - Optional<SdkModulesConfig> sdkModulesConfig) - throws Exception { - Path outputProperties = testFolder.newFile().toPath(); - ImmutableList<String> args = - buildArgs( - outputProperties, config, manifestXmlTreePath, sdkArchiveMetadata, sdkModulesConfig); - CommandResult result = runCommand(args.toArray(String[]::new)); - - assertThat(result.getOutput()).isEmpty(); - assertThat(result.getStatusCode()).isEqualTo(0); - SdkSplitPropertiesInheritedFromApp.Builder outputBuilder = - SdkSplitPropertiesInheritedFromApp.newBuilder(); - JsonFormat.parser().merge(Files.readString(outputProperties), outputBuilder); - return outputBuilder.build(); - } - - private ImmutableList<String> buildArgs( - Path outputPropertiesPath, - RuntimeEnabledSdkConfig config, - Path manifestXmlTreePath, - Optional<SdkMetadata> sdkArchiveMetadata, - Optional<SdkModulesConfig> sdkModulesConfig) - throws Exception { - - ImmutableList.Builder<String> args = ImmutableList.builder(); - args.add( - "generate-sdk-split-properties", "--output-properties", outputPropertiesPath.toString()); - - Path configPath = testFolder.newFile("runtime-enabled-sdk-config.pb").toPath(); - Files.write(configPath, config.toByteArray()); - args.add("--runtime-enabled-sdk-config", configPath.toString()); - - args.add("--manifest-xml-tree", manifestXmlTreePath.toString()); - - if (sdkArchiveMetadata.isPresent()) { - Path sdkArchivePath = testFolder.getRoot().toPath().resolve("sdk-archive.asar"); - createZipWithSingleEntry( - sdkArchivePath, "SdkMetadata.pb", sdkArchiveMetadata.get().toByteArray()); - args.add("--sdk-archive", sdkArchivePath.toString()); - } - - if (sdkModulesConfig.isPresent()) { - Path sdkModulesConfigPath = - testFolder.getRoot().toPath().resolve("sdk-modules-config.pb.json"); - Files.writeString(sdkModulesConfigPath, JsonFormat.printer().print(sdkModulesConfig.get())); - args.add("--sdk-modules-config", sdkModulesConfigPath.toString()); - } - - return args.build(); - } -}
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/testdata/valid_xmltree_dump.txt b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/testdata/valid_xmltree_dump.txt deleted file mode 100644 index d339ccc..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/testdata/valid_xmltree_dump.txt +++ /dev/null
@@ -1,13 +0,0 @@ -N: android=http://schemas.android.com/apk/res/android (line=2) - E: manifest (line=2) - A: http://schemas.android.com/apk/res/android:versionCode(0x0101021b)=42 - A: http://schemas.android.com/apk/res/android:compileSdkVersion(0x01010572)=34 - A: http://schemas.android.com/apk/res/android:compileSdkVersionCodename(0x01010573)="VanillaIceCream" (Raw: "VanillaIceCream") - A: package="com.example.host.app" (Raw: "com.example.host.app") - A: platformBuildVersionCode=34 - A: platformBuildVersionName="VanillaIceCream" (Raw: "VanillaIceCream") - E: uses-sdk (line=6) - A: http://schemas.android.com/apk/res/android:minSdkVersion(0x0101020c)=30 - A: http://schemas.android.com/apk/res/android:targetSdkVersion(0x01010270)=23 - E: application (line=10) - A: http://schemas.android.com/apk/res/android:label(0x01010001)=@0x7f010000 \ No newline at end of file
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/testdata/xmltree_dump_with_duplicate_values.txt b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/testdata/xmltree_dump_with_duplicate_values.txt deleted file mode 100644 index 5594498..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/sdksplitproperties/testdata/xmltree_dump_with_duplicate_values.txt +++ /dev/null
@@ -1,25 +0,0 @@ -N: android=http://schemas.android.com/apk/res/android (line=2) - E: manifest (line=2) - A: http://schemas.android.com/apk/res/android:versionCode(0x0101021b)=42 - A: http://schemas.android.com/apk/res/android:compileSdkVersion(0x01010572)=34 - A: http://schemas.android.com/apk/res/android:compileSdkVersionCodename(0x01010573)="VanillaIceCream" (Raw: "VanillaIceCream") - A: package="com.example.host.app" (Raw: "com.example.host.app") - A: platformBuildVersionCode=34 - A: platformBuildVersionName="VanillaIceCream" (Raw: "VanillaIceCream") - E: uses-sdk (line=6) - A: http://schemas.android.com/apk/res/android:minSdkVersion(0x0101020c)=30 - A: http://schemas.android.com/apk/res/android:targetSdkVersion(0x01010270)=23 - E: application (line=10) - A: http://schemas.android.com/apk/res/android:label(0x01010001)=@0x7f010000 - E: manifest (line=2) - A: http://schemas.android.com/apk/res/android:versionCode(0x0101021b)=84 - A: http://schemas.android.com/apk/res/android:compileSdkVersion(0x01010572)=34 - A: http://schemas.android.com/apk/res/android:compileSdkVersionCodename(0x01010573)="VanillaIceCream" (Raw: "VanillaIceCream") - A: package="wrong.host.app" (Raw: "wrong.host.app") - A: platformBuildVersionCode=68 - A: platformBuildVersionName="VanillaIceCream" (Raw: "VanillaIceCream") - E: uses-sdk (line=6) - A: http://schemas.android.com/apk/res/android:minSdkVersion(0x0101020c)=12 - A: http://schemas.android.com/apk/res/android:targetSdkVersion(0x01010270)=23 - E: application (line=10) - A: http://schemas.android.com/apk/res/android:label(0x01010001)=@0x7f010000 \ No newline at end of file
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils/BUILD b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils/BUILD deleted file mode 100644 index a261c84..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils/BUILD +++ /dev/null
@@ -1,18 +0,0 @@ -load("@rules_java//java:defs.bzl", "java_library") - -# Common test utilities for SandboxedSdkToolbox. -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//:__subpackages__"], -) - -licenses(["notice"]) - -java_library( - name = "utils", - srcs = glob(["*.java"]), - deps = [ - "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox:sandboxed_sdk_toolbox_lib", - "@rules_android_maven//:info_picocli_picocli", - ], -)
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils/CommandResult.java b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils/CommandResult.java deleted file mode 100644 index cafd1b2..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils/CommandResult.java +++ /dev/null
@@ -1,35 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.utils; - -/** The result from executing a SandboxedSdkToolbox command. */ -public final class CommandResult { - private final int statusCode; - private final String output; - - CommandResult(int statusCode, String output) { - this.statusCode = statusCode; - this.output = output; - } - - public int getStatusCode() { - return statusCode; - } - - public String getOutput() { - return output; - } -}
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils/Runner.java b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils/Runner.java deleted file mode 100644 index 1010698..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils/Runner.java +++ /dev/null
@@ -1,39 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.utils; - -import com.google.devtools.build.android.sandboxedsdktoolbox.SandboxedSdkToolbox; -import java.io.PrintWriter; -import java.io.StringWriter; -import picocli.CommandLine; - -/** Utilities for running SandboxedSdkToolbox commands. */ -public final class Runner { - public static CommandResult runCommand(String... parameters) { - CommandLine command = SandboxedSdkToolbox.create(); - StringWriter out = new StringWriter(); - StringWriter err = new StringWriter(); - - command.setOut(new PrintWriter(out)); - command.setErr(new PrintWriter(err)); - int statusCode = command.execute(parameters); - out.append(err.toString()); - - return new CommandResult(statusCode, out.toString()); - } - - private Runner() {} -}
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils/TestData.java b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils/TestData.java deleted file mode 100644 index 8e58759..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils/TestData.java +++ /dev/null
@@ -1,50 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.utils; - -import static java.nio.charset.StandardCharsets.UTF_8; - -import java.nio.file.Files; -import java.nio.file.Path; - -/** Utilities for test data. */ -public final class TestData { - - /** Path to the javatests directory in runfiles. */ - public static final Path JAVATESTS_DIR; - - static { - Path javatestsDir = Path.of( - System.getenv("TEST_SRCDIR"), - "rules_android/src/tools/javatests/"); - - // rules_android will be _main with bzlmod, so check both for compatibility. - if (!Files.exists(javatestsDir)) { - javatestsDir = Path.of( - System.getenv("TEST_SRCDIR"), - "_main/src/tools/javatests/"); - } - - JAVATESTS_DIR = javatestsDir; - } - - /** Reads the contents of a file, assuming its path is absolute. */ - public static String readFromAbsolutePath(Path absolutePath) throws Exception { - return String.join("\n", Files.readAllLines(absolutePath, UTF_8)); - } - - private TestData() {} -}
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils/Zip.java b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils/Zip.java deleted file mode 100644 index 38d7eed..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils/Zip.java +++ /dev/null
@@ -1,48 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.utils; - -import java.io.IOException; -import java.net.URI; -import java.nio.file.FileSystem; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.HashMap; -import java.util.Map; - -/** Test utilities for zip files. */ -public final class Zip { - - /** - * Creates a zip file with a single entry inside of it. - * - * @param zipPath Path to the new zip file. If the file already exists {@link IOException} will be - * thrown. - */ - public static void createZipWithSingleEntry(Path zipPath, String entryName, byte[] entryContents) - throws IOException { - Map<String, String> env = new HashMap<>(); - env.put("create", "true"); - - URI uri = URI.create("jar:" + zipPath.toUri()); - try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) { - Files.write(zipfs.getPath(entryName), entryContents); - } - } - - private Zip() {} -}
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/validatemodulesconfig/BUILD b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/validatemodulesconfig/BUILD deleted file mode 100644 index 74df53d..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/validatemodulesconfig/BUILD +++ /dev/null
@@ -1,22 +0,0 @@ -# Tests for validate-modules-config command. -load("@rules_java//java:defs.bzl", "java_test") - -package( - default_applicable_licenses = ["//:license"], - default_visibility = ["//:__subpackages__"], -) - -licenses(["notice"]) - -java_test( - name = "ValidateModulesConfigCommandTest", - size = "small", - srcs = ["ValidateModulesConfigCommandTest.java"], - deps = [ - "//src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/utils", - "@rules_android_maven//:com_android_tools_build_bundletool", - "@com_google_protobuf//:protobuf_java_util", - "@rules_android_maven//:com_google_truth_truth", - "@rules_android_maven//:junit_junit", - ], -)
diff --git a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/validatemodulesconfig/ValidateModulesConfigCommandTest.java b/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/validatemodulesconfig/ValidateModulesConfigCommandTest.java deleted file mode 100644 index 4d5deea..0000000 --- a/src/tools/javatests/com/google/devtools/build/android/sandboxedsdktoolbox/validatemodulesconfig/ValidateModulesConfigCommandTest.java +++ /dev/null
@@ -1,81 +0,0 @@ -/* - * Copyright 2024 The Bazel Authors. All rights reserved. - * - * 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. - */ -package com.google.devtools.build.android.sandboxedsdktoolbox.validatemodulesconfig; - -import static com.google.common.truth.Truth.assertThat; -import static com.google.devtools.build.android.sandboxedsdktoolbox.utils.Runner.runCommand; - -import com.android.bundle.SdkModulesConfigOuterClass.SdkModulesConfig; -import com.google.devtools.build.android.sandboxedsdktoolbox.utils.CommandResult; -import com.google.protobuf.util.JsonFormat; -import java.nio.file.Files; -import java.nio.file.Path; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public final class ValidateModulesConfigCommandTest { - - @Rule public final TemporaryFolder testFolder = new TemporaryFolder(); - - @Test - public void modulesConfig_withTheSameJavaPackage_succeeds() throws Exception { - SdkModulesConfig config = - SdkModulesConfig.newBuilder().setSdkPackageName("com.example.package").build(); - String javaPackageName = "com.example.package"; - Path output = testFolder.getRoot().toPath().resolve("output"); - - CommandResult result = runValidateCommand(config, javaPackageName, output); - - assertThat(result.getOutput()).isEmpty(); - assertThat(result.getStatusCode()).isEqualTo(0); - assertThat(Files.exists(output)).isTrue(); - } - - @Test - public void modulesConfig_withMismatchedJavaPackage_failsValidation() throws Exception { - SdkModulesConfig config = - SdkModulesConfig.newBuilder().setSdkPackageName("com.example.package").build(); - String javaPackageName = "com.example.package.different"; - Path output = testFolder.getRoot().toPath().resolve("output"); - - CommandResult result = runValidateCommand(config, javaPackageName, output); - - assertThat(result.getOutput()) - .contains( - "The package name in the modules config (com.example.package) does not match the java" - + " package name (com.example.package.different)"); - assertThat(result.getStatusCode()).isEqualTo(1); - assertThat(Files.exists(output)).isFalse(); - } - - private CommandResult runValidateCommand( - SdkModulesConfig config, String javaPackageName, Path output) throws Exception { - Path sdkModulesConfigPath = testFolder.getRoot().toPath().resolve("sdk-modules-config.pb.json"); - Files.writeString(sdkModulesConfigPath, JsonFormat.printer().print(config)); - return runCommand( - "validate-modules-config", - "--sdk-modules-config", - sdkModulesConfigPath.toString(), - "--java-package-name", - javaPackageName, - "--output", - output.toString()); - } -}