-
Notifications
You must be signed in to change notification settings - Fork 10
ADFA-2741: ensure INTERNET permission is added to child apps during debugging sessions #1025
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
Open
itsaky-adfa
wants to merge
18
commits into
stage
Choose a base branch
from
fix/ADFA-2741
base: stage
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
234c0b6
fix: do not wrap binders in BinderContainer
itsaky-adfa a27023d
fix: add more debug logs for JDWP connections
itsaky-adfa 0510673
fix: add custom SocketListeningConnector to overcome socket protocol …
itsaky-adfa 7bca477
Merge branch 'stage' into fix/ADFA-2741
itsaky-adfa 973d0f6
fix: automatically add INTERNET permission when JDWP is enabled
itsaky-adfa 9f7cea4
fix: remove custom socket listening connector
itsaky-adfa 81dad10
refactor: reformat
itsaky-adfa 8669917
Merge branch 'stage' into fix/ADFA-2741
itsaky-adfa f0a7a2e
fix: remove unnecessary files
itsaky-adfa e031049
fix: enable JdwpPlugin only for debug builds
itsaky-adfa 9ccf087
fix: use namespace-aware document builder
itsaky-adfa b4c11cb
chore: resolve typo
itsaky-adfa dc3c382
refactor: reformat
itsaky-adfa eda8469
Merge branch 'stage' into fix/ADFA-2741
itsaky-adfa 7e3a1b5
Merge branch 'stage' into fix/ADFA-2741
itsaky-adfa 1f3996c
Merge branch 'stage' into fix/ADFA-2741
itsaky-adfa ca17039
fix: revert unintended changes to gradle.properties
itsaky-adfa 422e715
Merge branch 'stage' into fix/ADFA-2741
itsaky-adfa 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
There are no files selected for viewing
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
59 changes: 59 additions & 0 deletions
59
gradle-plugin-config/src/main/java/com/itsaky/androidide/tooling/api/GradlePluginConfig.java
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 |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * This file is part of AndroidIDE. | ||
| * | ||
| * AndroidIDE is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * AndroidIDE is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.itsaky.androidide.tooling.api; | ||
|
|
||
| /** | ||
| * Configuration options for the Gradle plugin. | ||
| * | ||
| * @author Akash Yadav | ||
| */ | ||
| public final class GradlePluginConfig { | ||
|
|
||
| /** | ||
| * Property used by the Gradle plugin to determine whether the Gradle build includes JDWP (debugging) support. This is usually set when for builds which are intended to be launched in debug mode. | ||
| */ | ||
| public static final String PROPERTY_JDWP_ENABLED = "cotg.jdwp.enabled"; | ||
|
|
||
| /** | ||
| * Property to enable or disable <code>LogSender</code> in the project. Value can be <code>true</code> or <code>false</code>. | ||
| */ | ||
| public static final String PROPERTY_LOGSENDER_ENABLED = "androidide.logsender.isEnabled"; | ||
|
|
||
| /** | ||
| * The path to the LogSender AAR file. | ||
| */ | ||
| public static final String PROPERTY_LOGSENDER_AAR = "androidide.logsender.aar"; | ||
|
|
||
| /** | ||
| * Property that is set in tests to indicate that the plugin is being applied in a test environment. | ||
| * <p> | ||
| * <b>This is an internal property and should not be manually set by users.</b> | ||
| */ | ||
| public static final String _PROPERTY_IS_TEST_ENV = "androidide.plugins.internal.isTestEnv"; | ||
|
|
||
| /** | ||
| * Property that is set in tests to provide path to the local maven repository. If this property is empty, `null` or not set at all, the default maven local repository is used. | ||
| * | ||
| * <b>This is an internal property and should not be manually set by users.</b> | ||
| */ | ||
| public static final String _PROPERTY_MAVEN_LOCAL_REPOSITORY = "androidide.plugins.internal.mavenLocalRepositories"; | ||
|
|
||
| private GradlePluginConfig() { | ||
| throw new UnsupportedOperationException("This class cannot be instantiated."); | ||
| } | ||
| } |
58 changes: 0 additions & 58 deletions
58
gradle-plugin-config/src/main/java/com/itsaky/androidide/tooling/api/LogSenderConfig.java
This file was deleted.
Oops, something went wrong.
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
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
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
107 changes: 107 additions & 0 deletions
107
gradle-plugin/src/main/java/com/itsaky/androidide/gradle/JdwpPlugin.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 |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| package com.itsaky.androidide.gradle | ||
|
|
||
| import com.android.build.api.artifact.SingleArtifact | ||
| import com.android.build.api.variant.ApplicationAndroidComponentsExtension | ||
| import org.gradle.api.DefaultTask | ||
| import org.gradle.api.Plugin | ||
| import org.gradle.api.Project | ||
| import org.gradle.api.file.RegularFileProperty | ||
| import org.gradle.api.tasks.InputFile | ||
| import org.gradle.api.tasks.OutputFile | ||
| import org.gradle.api.tasks.TaskAction | ||
| import javax.xml.XMLConstants | ||
| import javax.xml.parsers.DocumentBuilderFactory | ||
| import javax.xml.transform.OutputKeys | ||
| import javax.xml.transform.TransformerFactory | ||
| import javax.xml.transform.dom.DOMSource | ||
| import javax.xml.transform.stream.StreamResult | ||
|
|
||
| class JdwpPlugin : Plugin<Project> { | ||
| override fun apply(target: Project) = | ||
| target | ||
| .run { | ||
| if (!target.plugins.hasPlugin(APP_PLUGIN)) { | ||
| return | ||
| } | ||
itsaky-adfa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| logger.info("Applying {} to project '${target.path}'", JdwpPlugin::class.simpleName) | ||
|
|
||
| extensions.getByType(ApplicationAndroidComponentsExtension::class.java).apply { | ||
| onDebuggableVariants { variant -> | ||
| val jdwpManifestTransformer = | ||
| tasks.register( | ||
| variant.generateTaskName("transform", "JdwpManifest"), | ||
| JdwpManifestTransformerTask::class.java, | ||
| ) | ||
|
|
||
| variant.artifacts | ||
| .use(jdwpManifestTransformer) | ||
| .wiredWithFiles( | ||
| taskInput = JdwpManifestTransformerTask::mergedManifest, | ||
| taskOutput = JdwpManifestTransformerTask::updatedManifest, | ||
| ).toTransform(SingleArtifact.MERGED_MANIFEST) | ||
| } | ||
| } | ||
| }.let { } | ||
| } | ||
|
|
||
| abstract class JdwpManifestTransformerTask : DefaultTask() { | ||
| @get:InputFile | ||
| abstract val mergedManifest: RegularFileProperty | ||
|
|
||
| @get:OutputFile | ||
| abstract val updatedManifest: RegularFileProperty | ||
|
|
||
| @TaskAction | ||
| fun transform() { | ||
| val inputFile = mergedManifest.get().asFile | ||
| val outputFile = updatedManifest.get().asFile | ||
|
|
||
| val factory = | ||
| DocumentBuilderFactory.newInstance().apply { | ||
| isNamespaceAware = true | ||
| setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true) | ||
| setFeature("http://apache.org/xml/features/disallow-doctype-decl", true) | ||
| setFeature("http://xml.org/sax/features/external-general-entities", false) | ||
| setFeature("http://xml.org/sax/features/external-parameter-entities", false) | ||
| setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false) | ||
| } | ||
|
|
||
| val documentBuilder = factory.newDocumentBuilder() | ||
| val document = documentBuilder.parse(inputFile) | ||
|
|
||
| val manifest = document.documentElement | ||
| val androidNs = "http://schemas.android.com/apk/res/android" | ||
|
|
||
| // Check if INTERNET permission already exists | ||
| val existingPermissions = document.getElementsByTagName("uses-permission") | ||
| var hasInternetPermission = false | ||
|
|
||
| for (i in 0 until existingPermissions.length) { | ||
| val node = existingPermissions.item(i) | ||
| val nameAttr = node.attributes?.getNamedItemNS(androidNs, "name") | ||
| if (nameAttr?.nodeValue == "android.permission.INTERNET") { | ||
| hasInternetPermission = true | ||
| break | ||
| } | ||
| } | ||
|
|
||
| if (!hasInternetPermission) { | ||
| logger.info("Adding INTERNET permission") | ||
| val permissionNode = document.createElement("uses-permission") | ||
| permissionNode.setAttributeNS( | ||
| androidNs, | ||
| "android:name", | ||
| "android.permission.INTERNET", | ||
| ) | ||
| manifest.appendChild(permissionNode) | ||
| } | ||
|
|
||
| val transformer = TransformerFactory.newInstance().newTransformer() | ||
| transformer.setOutputProperty(OutputKeys.INDENT, "yes") | ||
| transformer.transform( | ||
| DOMSource(document), | ||
| StreamResult(outputFile), | ||
| ) | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JDWP debug gating can miss valid debug task flows.
Line 357 derives debug intent from
getBuildType(...), which only inspects the first task and only mapsassembleDebugto debug. If a debug session runsinstallDebug/bundleDebug(or debug task is not first), Line 363 will disable JDWP and skip the intended manifest permission path.🔧 Proposed fix
🤖 Prompt for AI Agents