-
Notifications
You must be signed in to change notification settings - Fork 11
ADFA-2778: ensure binaries in build-tools are executable after installation #916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
143 changes: 78 additions & 65 deletions
143
app/src/main/java/com/itsaky/androidide/assets/BaseAssetsInstaller.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,89 +1,102 @@ | ||
| package com.itsaky.androidide.assets | ||
|
|
||
| import android.content.Context | ||
| import com.itsaky.androidide.utils.Environment | ||
| import com.itsaky.androidide.utils.FeatureFlags | ||
| import com.termux.shared.termux.TermuxConstants | ||
| import org.slf4j.LoggerFactory | ||
| import java.io.File | ||
| import java.nio.file.Path | ||
| import java.util.concurrent.TimeUnit | ||
| import com.termux.shared.termux.TermuxConstants | ||
| import com.itsaky.androidide.utils.Environment | ||
| import com.itsaky.androidide.utils.FeatureFlags | ||
| import kotlin.concurrent.thread | ||
| import kotlin.system.measureTimeMillis | ||
|
|
||
|
|
||
| abstract class BaseAssetsInstaller : AssetsInstaller { | ||
| private val logger = LoggerFactory.getLogger(BaseAssetsInstaller::class.java) | ||
| private val logger = LoggerFactory.getLogger(BaseAssetsInstaller::class.java) | ||
|
|
||
| override suspend fun postInstall( | ||
| context: Context, | ||
| stagingDir: Path | ||
| ) { | ||
| Environment.AAPT2.setExecutable(true) | ||
| override suspend fun postInstall( | ||
| context: Context, | ||
| stagingDir: Path, | ||
| ) { | ||
| for (bin in arrayOf( | ||
| "aapt", | ||
| "aapt2", | ||
| "aidl", | ||
| "dexdump", | ||
| "split-select", | ||
| "zipalign", | ||
| )) { | ||
| Environment.setExecutable(Environment.BUILD_TOOLS_DIR.resolve(bin)) | ||
| } | ||
|
|
||
| installNdk( | ||
| File(Environment.ANDROID_HOME, Environment.NDK_TAR_XZ), | ||
| Environment.ANDROID_HOME | ||
| ) | ||
| } | ||
| installNdk( | ||
| File(Environment.ANDROID_HOME, Environment.NDK_TAR_XZ), | ||
| Environment.ANDROID_HOME, | ||
| ) | ||
| } | ||
|
|
||
| private fun installNdk(archiveFile: File, outputDir: File): Boolean { | ||
| if (!FeatureFlags.isExperimentsEnabled) return false | ||
| private fun installNdk( | ||
| archiveFile: File, | ||
| outputDir: File, | ||
| ): Boolean { | ||
| if (!FeatureFlags.isExperimentsEnabled) return false | ||
|
|
||
| if (!archiveFile.exists()) { | ||
| logger.debug("NDK installable package not found: ${archiveFile.absolutePath}") | ||
| return false | ||
| } | ||
| if (!archiveFile.exists()) { | ||
| logger.debug("NDK installable package not found: ${archiveFile.absolutePath}") | ||
| return false | ||
| } | ||
|
|
||
| logger.debug("Starting installation of ${archiveFile.absolutePath}") | ||
| logger.debug("Starting installation of ${archiveFile.absolutePath}") | ||
|
|
||
| var exitCode: Int | ||
| var result: String | ||
| val elapsed = measureTimeMillis { | ||
| val processBuilder = ProcessBuilder( | ||
| "${TermuxConstants.TERMUX_BIN_PREFIX_DIR_PATH}/bash", | ||
| "-c", | ||
| "tar -xJf ${archiveFile.absolutePath} -C ${outputDir.absolutePath} --no-same-owner" | ||
| ) | ||
| .redirectErrorStream(true) | ||
| var exitCode: Int | ||
| var result: String | ||
| val elapsed = | ||
| measureTimeMillis { | ||
| val processBuilder = | ||
| ProcessBuilder( | ||
| "${TermuxConstants.TERMUX_BIN_PREFIX_DIR_PATH}/bash", | ||
| "-c", | ||
| "tar -xJf ${archiveFile.absolutePath} -C ${outputDir.absolutePath} --no-same-owner", | ||
| ).redirectErrorStream(true) | ||
|
|
||
| val env = processBuilder.environment() | ||
| env["PATH"] = "${TermuxConstants.TERMUX_BIN_PREFIX_DIR_PATH}:${env["PATH"]}" | ||
| val env = processBuilder.environment() | ||
| env["PATH"] = "${TermuxConstants.TERMUX_BIN_PREFIX_DIR_PATH}:${env["PATH"]}" | ||
|
|
||
| val process = processBuilder.start() | ||
| val process = processBuilder.start() | ||
|
|
||
| val output = StringBuilder() | ||
| val reader = thread(start = true, name = "ndk-extract-output") { | ||
| process.inputStream.bufferedReader().useLines { lines -> | ||
| lines.forEach { output.appendLine(it) } | ||
| } | ||
| } | ||
| val output = StringBuilder() | ||
| val reader = | ||
| thread(start = true, name = "ndk-extract-output") { | ||
| process.inputStream.bufferedReader().useLines { lines -> | ||
| lines.forEach { output.appendLine(it) } | ||
| } | ||
| } | ||
|
|
||
| val completed = process.waitFor(2, TimeUnit.MINUTES) | ||
| if (!completed) process.destroyForcibly() | ||
| reader.join() | ||
| result = output.toString() | ||
| exitCode = if (completed) process.exitValue() else -1 | ||
| } | ||
| val completed = process.waitFor(2, TimeUnit.MINUTES) | ||
| if (!completed) process.destroyForcibly() | ||
| reader.join() | ||
| result = output.toString() | ||
| exitCode = if (completed) process.exitValue() else -1 | ||
| } | ||
|
|
||
| return if (exitCode == 0) { | ||
| logger.debug("Extraction of ${archiveFile.absolutePath} successful took ${elapsed}ms : $result") | ||
| return if (exitCode == 0) { | ||
| logger.debug("Extraction of ${archiveFile.absolutePath} successful took ${elapsed}ms : $result") | ||
|
|
||
| if (archiveFile.exists()) { | ||
| val deleted = archiveFile.delete() | ||
| if (deleted) { | ||
| logger.debug("${archiveFile.absolutePath} deleted successfully.") | ||
| } else { | ||
| logger.debug("Failed to delete ${archiveFile.absolutePath}.") | ||
| } | ||
| deleted | ||
| } else { | ||
| logger.debug("Archive file not found for deletion.") | ||
| false | ||
| } | ||
| } else { | ||
| logger.error("Extraction failed with code $exitCode: $result") | ||
| false | ||
| } | ||
| } | ||
| if (archiveFile.exists()) { | ||
| val deleted = archiveFile.delete() | ||
| if (deleted) { | ||
| logger.debug("${archiveFile.absolutePath} deleted successfully.") | ||
| } else { | ||
| logger.debug("Failed to delete ${archiveFile.absolutePath}.") | ||
| } | ||
| deleted | ||
| } else { | ||
| logger.debug("Archive file not found for deletion.") | ||
| false | ||
| } | ||
| } else { | ||
| logger.error("Extraction failed with code $exitCode: $result") | ||
| false | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.