├── .github └── workflows │ ├── build.yml │ └── check-studio-compatibility.yml ├── .gitignore ├── .run ├── Run.run.xml └── RunLocal.run.xml ├── CHANGELOG.md ├── DEVELOP.md ├── LICENSE.txt ├── README.md ├── build.gradle.kts ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── list-studio-versions.sh ├── release.sh ├── src ├── main │ ├── kotlin │ │ └── com │ │ │ └── developerphil │ │ │ └── adbidea │ │ │ ├── Application.kt │ │ │ ├── HelperMethods.kt │ │ │ ├── ObjectGraph.kt │ │ │ ├── ReflectKt.kt │ │ │ ├── action │ │ │ ├── AdbAction.kt │ │ │ ├── ClearDataAction.kt │ │ │ ├── ClearDataAndRestartAction.kt │ │ │ ├── ClearDataAndRestartWithDebuggerAction.kt │ │ │ ├── DisableMobileAction.kt │ │ │ ├── DisableWifiAction.kt │ │ │ ├── EnableMobileAction.kt │ │ │ ├── EnableWifiAction.kt │ │ │ ├── GrantPermissionsAction.kt │ │ │ ├── KillAction.kt │ │ │ ├── QuickListAction.kt │ │ │ ├── RestartAction.kt │ │ │ ├── RestartWithDebuggerAction.kt │ │ │ ├── RevokePermissionsAction.kt │ │ │ ├── RevokePermissionsAndRestartAction.kt │ │ │ ├── StartAction.kt │ │ │ ├── StartWithDebuggerAction.kt │ │ │ └── UninstallAction.kt │ │ │ ├── adb │ │ │ ├── AdbFacade.kt │ │ │ ├── AdbUtil.kt │ │ │ ├── Bridge.kt │ │ │ ├── DeviceResultFetcher.kt │ │ │ ├── ShellCommandsFactory.kt │ │ │ ├── UseSameDevicesHelper.kt │ │ │ └── command │ │ │ │ ├── ClearDataAndRestartCommand.kt │ │ │ │ ├── ClearDataAndRestartWithDebuggerCommand.kt │ │ │ │ ├── ClearDataCommand.kt │ │ │ │ ├── Command.kt │ │ │ │ ├── CommandList.kt │ │ │ │ ├── GrantPermissionsCommand.kt │ │ │ │ ├── KillCommand.kt │ │ │ │ ├── RestartPackageCommand.kt │ │ │ │ ├── RevokePermissionsAndRestartCommand.kt │ │ │ │ ├── RevokePermissionsCommand.kt │ │ │ │ ├── StartDefaultActivityCommand.kt │ │ │ │ ├── ToggleSvcCommand.kt │ │ │ │ ├── UninstallCommand.kt │ │ │ │ └── receiver │ │ │ │ └── GenericReceiver.kt │ │ │ ├── compatibility │ │ │ └── BackwardCompatibleGetter.kt │ │ │ ├── debugger │ │ │ └── Debugger.kt │ │ │ ├── preference │ │ │ ├── ApplicationPreferences.kt │ │ │ ├── ProjectPreferences.kt │ │ │ └── accessor │ │ │ │ ├── PreferenceAccessor.kt │ │ │ │ └── PreferenceAccessorImpl.kt │ │ │ └── ui │ │ │ ├── DeviceChooserDialog.form │ │ │ ├── DeviceChooserDialog.kt │ │ │ ├── DeviceChooserListener.kt │ │ │ ├── ModuleChooserDialogHelper.kt │ │ │ ├── MyDeviceChooser.kt │ │ │ └── NotificationHelper.kt │ └── resources │ │ └── META-INF │ │ └── plugin.xml └── test │ └── kotlin │ └── com │ └── developerphil │ └── adbidea │ ├── adb │ ├── FakeDevice.kt │ ├── ShellCommandsFactoryTest.kt │ ├── UseSameDevicesHelperTest.kt │ └── command │ │ ├── StartDefaultActivityCommandTest.kt │ │ └── receiver │ │ └── GenericReceiverTest.kt │ ├── compatibility │ └── BackwardCompatibleGetterTest.kt │ └── preference │ ├── ApplicationPreferencesTests.kt │ ├── ProjectPreferencesTests.kt │ └── accessor │ └── InMemoryPreferenceAccessor.kt └── website ├── adb_operations_popup.png ├── debug_howto.png └── find_actions.png /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build and Test Plugin 2 | on: [push] 3 | jobs: 4 | build-and-test: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - name: Checkout Sources 8 | uses: actions/checkout@v4 9 | - name: Setup JDK 21 10 | uses: actions/setup-java@v4 11 | with: 12 | distribution: temurin 13 | java-version: 21 14 | - name: Setup Gradle 15 | uses: gradle/actions/setup-gradle@v3 16 | - name: Build with Gradle 17 | run: ./gradlew build --no-configuration-cache 18 | -------------------------------------------------------------------------------- /.github/workflows/check-studio-compatibility.yml: -------------------------------------------------------------------------------- 1 | name: Check compatibility with latest Android Studio Canary 2 | on: 3 | schedule: 4 | - cron: '25 21 * * *' 5 | jobs: 6 | fetch-studio-version: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Fetch latest studio version 10 | id: fetch-studio-version 11 | run: | 12 | # Fetch the latest Canary version of Android Studio 13 | curl -sL https://jb.gg/android-studio-releases-list.json > studio-releases.json 14 | 15 | VERSION=$(cat studio-releases.json | jq -r '.content.item[] | select(.channel == "Canary") | .version' | head -n 1) 16 | echo "Testing with Android Studio Canary version **$VERSION**" >> "$GITHUB_STEP_SUMMARY" 17 | echo "STUDIO_VERSION=$VERSION" >> "$GITHUB_OUTPUT" 18 | 19 | # Print JSON content to the job summary 20 | echo '```json' >> "$GITHUB_STEP_SUMMARY" 21 | cat studio-releases.json | jq '.content.item | map(select(.channel == "Canary")) | .[0] | del(.download)' >> "$GITHUB_STEP_SUMMARY" 22 | echo '```' >> "$GITHUB_STEP_SUMMARY" 23 | - name: Checkout Sources 24 | uses: actions/checkout@v4 25 | - name: Setup JDK 17 26 | uses: actions/setup-java@v4 27 | with: 28 | distribution: temurin 29 | java-version: 17 30 | - name: Setup Gradle 31 | uses: gradle/actions/setup-gradle@v3 32 | - name: Build with latest canary version 33 | env: 34 | STUDIO_VERSION: ${{ steps.fetch-studio-version.outputs.STUDIO_VERSION }} 35 | run: | 36 | echo "Building with Android Studio Canary version: $STUDIO_VERSION" 37 | ./gradlew build -PideVersion=$STUDIO_VERSION --no-configuration-cache 38 | 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea/workspace.xml 3 | *.ipr 4 | workspace.xml 5 | local.properties 6 | 7 | .gradle 8 | 9 | build/ 10 | 11 | .idea/ 12 | *.iml 13 | *.iws 14 | 15 | .intellijPlatform/ 16 | 17 | .kotlin -------------------------------------------------------------------------------- /.run/Run.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 16 | 18 | true 19 | true 20 | false 21 | false 22 | 23 | 24 | -------------------------------------------------------------------------------- /.run/RunLocal.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 16 | 18 | true 19 | true 20 | false 21 | false 22 | 23 | 24 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [[Unreleased]] 4 | 5 | ## [1.6.19] - 2024-11-17 6 | - Compatibility with AS Ladybug Feature Drop 2024.2.2 7 | 8 | ## [1.6.18] - 2024-08-18 9 | - Compatibility with AS Ladybug 10 | 11 | ## [1.6.17] - 2024-07-22 12 | - Fix regression in 1.6.16 that broke device selection in Android Studio Koala 13 | 14 | ## [1.6.16] - 2024-07-21 15 | - Compatibility with Android Studio Ladybug 16 | 17 | ## [1.6.15] - 2024-03-17 18 | - Compatibility with Android Studio Jellyfish 19 | 20 | ## [1.6.14] - 2024-03-17 21 | - Fix [#162](https://github.com/pbreault/adb-idea/issues/162) : Bug (v1.6.11): for a project with multiple modules, it always asks on which to perform any operation 22 | 23 | ## [1.6.13] - 2023-12-05 24 | - Compatibility with AS Iguana Canary 16 25 | 26 | ## [1.6.12] - 2023-07-30 27 | - Compatibility with AS Giraffe 28 | 29 | ## [1.6.11] - 2023-06-11 30 | - Compatibility with AS Hedgehog 31 | 32 | ## [1.6.10] - 2023-04-10 33 | - Fix device selection on Android Studio Giraffe 34 | 35 | ## [1.6.9] - 2023-04-10 36 | 37 | ### Fixed 38 | - Fix attach debugger action on Flamingo 39 | 40 | ## [1.6.8] - 2022-09-11 41 | 42 | ### Fixed 43 | - Compatibility with AS Dolphin and Electric Eel 44 | 45 | ## [1.6.7] - 2022-09-11 46 | 47 | ### Fixed 48 | - exception on "* with debugger" commands in AS Chipmunk | 2021.2.1 #144 49 | 50 | ## [1.6.6] - 2022-05-29 51 | 52 | ### Fixed 53 | - Compatibility with Android Studio Electric Eel 2022.1.1 Canary 54 | 55 | ## [1.6.5] - 2022-04-18 56 | 57 | ### Fixed 58 | - Compatibility with Android Studio 2021.2 59 | - Stop spamming that no device is found when cancelling out of the module selection dialog 60 | - Stop showing androidTest and unit tests modules in the module selection dialog 61 | - Set minimum dimensions on the module selection dialog 62 | 63 | ## [1.6.4] - 2021-11-28 64 | 65 | ### Fixed 66 | - Fix multiple device support on Android Studio 7.1+\ 67 | 68 | ## [1.6.3] - 2021-08-01 69 | 70 | ### Fixed 71 | - Compatibility with Android Studio 7.0 72 | 73 | ## [1.6.2] - 2020-07-08 74 | 75 | ### Fixed 76 | - Notifications don't show up on Studio 4.0 77 | - Debugger sometime fails to attach on Studio 4.0 78 | 79 | ## [1.6.1] - 2020-05-19 80 | 81 | ### Fixed 82 | - Can't attach a debugger on Android Studio 3.6 83 | 84 | ## [1.6.0] - 2020-05-04 85 | 86 | ### Added 87 | - New command to Enable/Disable Wi-Fi 88 | - New command to Enable/Disable Mobile Data 89 | 90 | ### Fixed 91 | - Compatibility with Android Studio 4.1-alpha07+ 92 | 93 | ## [1.5.4] - 2019-09-20 94 | 95 | ### Fixed 96 | - Compatibility with Android Studio 3.6-alpha12+ 97 | 98 | ## [1.5.3] - 2019-01-26 99 | 100 | ### Fixed 101 | - Show all connected devices on Android Studio 3.4+ 102 | 103 | ## [1.5.2] - 2018-06-10 104 | 105 | ### Fixed 106 | - Show the name of the devices in addition to the serial number when multiple devices are connected 107 | 108 | ## [1.5.1] - 2018-02-09 109 | 110 | ### Fixed 111 | - Support Android Studio 3.2 Preview1 112 | 113 | ## [1.5.0] - 2017-12-09 114 | 115 | ### Added 116 | - New command to Revoke Runtime Permissions 117 | 118 | ### Fixed 119 | - Support apps using string templating in the applicationId in the gradle build file 120 | - Show an appropriate error message instead of crashing when gradle is sy 121 | 122 | ## [1.4.1] - 2017-03-15 123 | 124 | ### Fixed 125 | - No Device 126 | 127 | ## [1.4.0] - 2016-11-06 128 | 129 | ### Added 130 | - New command to restart the app and attach the debugger 131 | 132 | ## [1.3.0] - 2016-10-23 133 | 134 | ### Added 135 | - Checkbox to reuse the same devices for the current session 136 | 137 | ### Changed 138 | - Only show notifications for errors 139 | 140 | ## [1.2.8] - 2016-09-06 141 | 142 | ### Fixed 143 | - NoSuchMethodException on Android Studio 2.2 Preview 144 | 145 | ## [1.2.7] - 2016-03-20 146 | 147 | ### Fixed 148 | - Can't start or restart on Android Studio 2.1 Preview 149 | 150 | ## [1.2.6] - 2016-02-07 151 | 152 | ### Fixed 153 | - NoSuchMethodException on Android Studio 2.0 Preview 8 154 | 155 | ## [1.2.5] - 2016-01-17 156 | 157 | ### Fixed 158 | - NoSuchMethodException on Android Studio 2.0 Preview 5 159 | 160 | ## [1.2.4] - 2015-12-20 161 | 162 | ### Fixed 163 | - NoSuchMethodError on Android Studio 2.0 Preview 1 164 | 165 | ## [1.2.3] - 2015-10-25 166 | 167 | ### Fixed 168 | - NoSuchMethodError on Android Studio 1.5 169 | 170 | ## [1.2.2] - 2015-10-04 171 | 172 | ### Fixed 173 | - Doesn't work on Android Studio 1.4 with multiple devices attached 174 | 175 | ## [1.2.1] - 2015-09-01 176 | 177 | ### Fixed 178 | - Can't start or restart app in Android Studio 1.4 179 | 180 | ## [1.2.0] - 2015-05-19 181 | 182 | ### Added 183 | - New "ADB Operations Popup...". Windows: `Ctrl+Alt+Shift+A` - Mac OSX: `Ctrl+Shift+A` 184 | 185 | ## [1.1.3] - 2014-09-14 186 | 187 | ### Fixed 188 | - Fixed crash in Android Studio 0.8.10 189 | 190 | ## [1.1.2] - 2014-06-30 191 | 192 | ### Fixed 193 | - Fixed device chooser in Android Studio 0.6+ 194 | 195 | ## [1.1.1] - 2014-02-06 196 | 197 | ### Fixed 198 | - Fixed crash in Android Studio 0.4.4 199 | - Don't show test projects in the module selection dialog 200 | 201 | ## [1.1.0] - 2014-01-26 202 | 203 | ### Added 204 | - Now support Build-Types and flavors in Gradle projects 205 | - Now support projects with more than one application module 206 | 207 | ## [1.0.0] - 2014-01-20 208 | 209 | ### Added 210 | - Command to start app 211 | - Command to kill app 212 | - Command to uninstall app 213 | - Command to restart app 214 | - Command to clear data 215 | - Command to clear data and restart 216 | 217 | [Unreleased]: https://github.com/pbreault/adb-idea/compare/1.6.18...HEAD 218 | [1.6.19]: https://github.com/pbreault/adb-idea/compare/1.6.18...1.6.19 219 | [1.6.18]: https://github.com/pbreault/adb-idea/compare/1.6.17...1.6.18 220 | [1.6.17]: https://github.com/pbreault/adb-idea/compare/1.6.16...1.6.17 221 | [1.6.16]: https://github.com/pbreault/adb-idea/compare/1.6.15...1.6.16 222 | [1.6.15]: https://github.com/pbreault/adb-idea/compare/1.6.14...1.6.15 223 | [1.6.14]: https://github.com/pbreault/adb-idea/compare/1.6.13...1.6.14 224 | [1.6.13]: https://github.com/pbreault/adb-idea/compare/1.6.12...1.6.13 225 | [1.6.12]: https://github.com/pbreault/adb-idea/compare/1.6.11...1.6.12 226 | [1.6.11]: https://github.com/pbreault/adb-idea/compare/1.6.10...1.6.11 227 | [1.6.10]: https://github.com/pbreault/adb-idea/compare/1.6.9...1.6.10 228 | [1.6.9]: https://github.com/pbreault/adb-idea/compare/1.6.8...1.6.9 229 | [1.6.8]: https://github.com/pbreault/adb-idea/compare/1.6.7...1.6.8 230 | [1.6.7]: https://github.com/pbreault/adb-idea/compare/1.6.6...1.6.7 231 | [1.6.6]: https://github.com/pbreault/adb-idea/compare/1.6.5...1.6.6 232 | [1.6.5]: https://github.com/pbreault/adb-idea/compare/1.6.4...1.6.5 233 | [1.6.4]: https://github.com/pbreault/adb-idea/compare/1.6.3...1.6.4 234 | [1.6.3]: https://github.com/pbreault/adb-idea/compare/1.6.2...1.6.3 235 | [1.6.2]: https://github.com/pbreault/adb-idea/compare/1.6.1...1.6.2 236 | [1.6.1]: https://github.com/pbreault/adb-idea/compare/1.6.0...1.6.1 237 | [1.6.0]: https://github.com/pbreault/adb-idea/compare/1.5.4...1.6.0 238 | [1.5.4]: https://github.com/pbreault/adb-idea/compare/1.5.3...1.5.4 239 | [1.5.3]: https://github.com/pbreault/adb-idea/compare/1.5.2...1.5.3 240 | [1.5.2]: https://github.com/pbreault/adb-idea/compare/1.5.1...1.5.2 241 | [1.5.1]: https://github.com/pbreault/adb-idea/compare/1.5.0...1.5.1 242 | [1.5.0]: https://github.com/pbreault/adb-idea/compare/1.4.1...1.5.0 243 | [1.4.1]: https://github.com/pbreault/adb-idea/compare/1.4.0...1.4.1 244 | [1.4.0]: https://github.com/pbreault/adb-idea/compare/1.3.0...1.4.0 245 | [1.3.0]: https://github.com/pbreault/adb-idea/compare/1.2.8...1.3.0 246 | [1.2.8]: https://github.com/pbreault/adb-idea/compare/1.2.7...1.2.8 247 | [1.2.7]: https://github.com/pbreault/adb-idea/compare/1.2.6...1.2.7 248 | [1.2.6]: https://github.com/pbreault/adb-idea/compare/1.2.5...1.2.6 249 | [1.2.5]: https://github.com/pbreault/adb-idea/compare/1.2.4...1.2.5 250 | [1.2.4]: https://github.com/pbreault/adb-idea/compare/1.2.3...1.2.4 251 | [1.2.3]: https://github.com/pbreault/adb-idea/compare/1.2.2...1.2.3 252 | [1.2.2]: https://github.com/pbreault/adb-idea/compare/1.2.1...1.2.2 253 | [1.2.1]: https://github.com/pbreault/adb-idea/compare/1.2.0...1.2.1 254 | [1.2.0]: https://github.com/pbreault/adb-idea/compare/1.1.3...1.2.0 255 | [1.1.3]: https://github.com/pbreault/adb-idea/compare/1.1.2...1.1.3 256 | [1.1.2]: https://github.com/pbreault/adb-idea/compare/1.1.1...1.1.2 257 | [1.1.1]: https://github.com/pbreault/adb-idea/compare/1.1.0...1.1.1 258 | [1.1.0]: https://github.com/pbreault/adb-idea/compare/1.0.0...1.1.0 259 | [1.0.0]: https://github.com/pbreault/adb-idea/releases/tag/1.0.0 260 | -------------------------------------------------------------------------------- /DEVELOP.md: -------------------------------------------------------------------------------- 1 | Run/Debug 2 | ========= 3 | 4 | * Open project in Intellij 5 | * Open _edit configurations_ to create a new run/debug configuration 6 | * Choose a new gradle configuration and name it `build and run` that runs `./gradlew runIde` 7 | ![Create debug configuration](website/debug_howto.png) 8 | * Hit debug button as usual 9 | 10 | Running from command line 11 | ------------------------- 12 | * Execute command 13 | ```shell script 14 | ./gradlew runIde 15 | ``` 16 | 17 | Create new menu item 18 | ==================== 19 | 20 | * Add entry to plugin.xml inside actions tab (below line 100) 21 | ```xml 22 | 26 | 27 | ``` 28 | 29 | * Create and implement a new `NewAction` class that extends from `AdbAction` (you can create that from the plugin view, right click on the class name and choose `create class` 30 | * Implement its abstract methods 31 | * Add new entry in `QuickListAction.kt` like this 32 | ```kotlin 33 | addAction("com.developerphil.adbidea.action.NewAction", group) 34 | ``` -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ADB Idea 2 | ======== 3 | 4 | A plugin for Android Studio and Intellij IDEA that speeds up your day to day android development. 5 | 6 | The following commands are provided: 7 | 8 | * Uninstall App 9 | * Kill App 10 | * Start App 11 | * Restart App 12 | * Clear App Data 13 | * Clear App Data and Restart 14 | 15 | Usage 16 | ===== 17 | 18 | Quick Operations Popup 19 | ----------------- 20 | 21 | The number on the left is a shortcut that will stay the same for your muscle memory pleasure. 22 | 23 | * Mac OSX: Ctrl+Shift+A 24 | * Windows/Linux: Ctrl+Alt+Shift+A 25 | 26 | ![Logo](website/adb_operations_popup.png) 27 | 28 | Find Actions 29 | ----------------- 30 | Each command is prefixed by "ADB", so you can quickly filter through adb commands using the "[Find Actions](http://www.jetbrains.com/idea/webhelp/navigating-to-action.html)" shortcut. 31 | 32 | ![Logo](website/find_actions.png) 33 | 34 | The Menu Way 35 | ------------ 36 | You can find every command in the following menu: 37 | `Tools->Android->ADB Idea` 38 | 39 | 40 | Installation 41 | ======== 42 | 43 | Download and install *ADB Idea* directly from Intellij / Android Studio: 44 | `Preferences/Settings->Plugins->Browse Repositories` 45 | 46 | Alternatively, you can [download the plugin](http://plugins.jetbrains.com/plugin/7380?pr=idea) from the jetbrains plugin site and install it manually in: 47 | `Preferences/Settings->Plugins->Install plugin from disk` 48 | 49 | License 50 | ======= 51 | 52 | Copyright 2017 Philippe Breault 53 | 54 | Licensed under the Apache License, Version 2.0 (the "License"); 55 | you may not use this file except in compliance with the License. 56 | You may obtain a copy of the License at 57 | 58 | http://www.apache.org/licenses/LICENSE-2.0 59 | 60 | Unless required by applicable law or agreed to in writing, software 61 | distributed under the License is distributed on an "AS IS" BASIS, 62 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 63 | See the License for the specific language governing permissions and 64 | limitations under the License. 65 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.changelog.Changelog 2 | import org.jetbrains.changelog.Changelog.OutputType.HTML 3 | import org.jetbrains.changelog.Changelog.OutputType.MARKDOWN 4 | 5 | plugins { 6 | // Must match the Kotlin version bundled with the IDE 7 | // https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#kotlin-standard-library 8 | // https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html 9 | id("org.jetbrains.kotlin.jvm") version "2.1.0" 10 | 11 | // https://github.com/JetBrains/intellij-platform-gradle-plugin 12 | id("org.jetbrains.intellij.platform") version "2.4.0" 13 | 14 | // https://github.com/ajoberstar/reckon 15 | id("org.ajoberstar.reckon") version "0.14.0" 16 | 17 | // https://github.com/b3er/gradle-local-properties-plugin 18 | id("com.github.b3er.local.properties") version "1.1" 19 | 20 | // https://github.com/JetBrains/gradle-changelog-plugin 21 | id("org.jetbrains.changelog") version "2.2.1" 22 | 23 | } 24 | repositories { 25 | mavenCentral() 26 | intellijPlatform { 27 | defaultRepositories() 28 | } 29 | } 30 | 31 | intellijPlatform { 32 | pluginConfiguration { 33 | name = "adb_idea" 34 | group = "com.developerphil.intellij.plugin.adbidea" 35 | changeNotes.set(provider { recentChanges(HTML) }) 36 | ideaVersion.sinceBuild.set(project.property("sinceBuild").toString()) 37 | ideaVersion.untilBuild.set(provider { null }) 38 | } 39 | buildSearchableOptions.set(false) 40 | instrumentCode = true 41 | } 42 | 43 | changelog { 44 | repositoryUrl.set("https://github.com/pbreault/adb-idea") 45 | itemPrefix.set("-") 46 | keepUnreleasedSection.set(true) 47 | unreleasedTerm.set("[Unreleased]") 48 | groups.empty() 49 | combinePreReleases.set(true) 50 | } 51 | 52 | reckon { 53 | scopeFromProp() 54 | snapshotFromProp() 55 | } 56 | 57 | kotlin { 58 | jvmToolchain(21) 59 | } 60 | 61 | tasks.runIde { 62 | jvmArgs = listOf("-Xmx4096m", "-XX:+UnlockDiagnosticVMOptions") 63 | } 64 | 65 | tasks.register("printLastChanges") { 66 | notCompatibleWithConfigurationCache("Uses recentChanges function which is not cacheable") 67 | doLast { 68 | println(recentChanges(outputType = MARKDOWN)) 69 | println(recentChanges(outputType = HTML)) 70 | } 71 | } 72 | val localIdePath: String? by project.extra 73 | localIdePath?.let { 74 | val runLocalIde by intellijPlatformTesting.runIde.registering { 75 | localPath.set(file(it)) 76 | } 77 | } 78 | 79 | dependencies { 80 | intellijPlatform { 81 | bundledPlugin("org.jetbrains.android") 82 | instrumentationTools() 83 | if (project.hasProperty("localIdeOverride")) { 84 | local(property("localIdeOverride").toString()) 85 | } else { 86 | androidStudio(property("ideVersion").toString()) 87 | } 88 | 89 | } 90 | 91 | implementation("org.jooq:joor:0.9.15") 92 | 93 | testImplementation("junit:junit:4.13.2") 94 | testImplementation("org.mockito:mockito-core:4.7.0") 95 | testImplementation("com.google.truth:truth:1.4.4") 96 | } 97 | 98 | fun recentChanges(outputType: Changelog.OutputType): String { 99 | var s = "" 100 | changelog.getAll().toList().drop(1) // drop the [Unreleased] section 101 | .take(5) // last 5 changes 102 | .forEach { (key, _) -> 103 | s += changelog.renderItem( 104 | changelog.get(key).withHeader(true).withEmptySections(false), outputType 105 | ) 106 | } 107 | 108 | return s 109 | } 110 | 111 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Android Studio Version 2 | # Get it from `list-studio-versions.sh` 3 | ideVersion=2025.1.1.2 4 | 5 | # Minimum Intellij PLatform version supported by this plugin 6 | # see https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html 7 | sinceBuild=251.23774.16 8 | 9 | # The path to a local Android Studio installation. 10 | # This will enable the `runLocalIde` task. 11 | # Should provide this either as a command line argument or in your home gradle.properties 12 | #localIdePath=/Users/your_user/Applications/Android Studio.app/Contents 13 | 14 | # The kotlin stdlib is provided by the platform 15 | # https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#kotlin-standard-library 16 | kotlin.stdlib.default.dependency = false 17 | 18 | org.gradle.parallel=true 19 | org.gradle.caching=true 20 | org.gradle.configuration-cache=true 21 | org.gradle.jvmargs=-Xmx4096m 22 | kotlin.code.style=official 23 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pbreault/adb-idea/58dd4e481cb0e0948589f76f751a3389b9721346/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Dec 25 15:42:43 IST 2024 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip 5 | networkTimeout=10000 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 147 | # shellcheck disable=SC3045 148 | MAX_FD=$( ulimit -H -n ) || 149 | warn "Could not query maximum file descriptor limit" 150 | esac 151 | case $MAX_FD in #( 152 | '' | soft) :;; #( 153 | *) 154 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 155 | # shellcheck disable=SC3045 156 | ulimit -n "$MAX_FD" || 157 | warn "Could not set maximum file descriptor limit to $MAX_FD" 158 | esac 159 | fi 160 | 161 | # Collect all arguments for the java command, stacking in reverse order: 162 | # * args from the command line 163 | # * the main class name 164 | # * -classpath 165 | # * -D...appname settings 166 | # * --module-path (only if needed) 167 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 168 | 169 | # For Cygwin or MSYS, switch paths to Windows format before running java 170 | if "$cygwin" || "$msys" ; then 171 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 172 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 173 | 174 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 175 | 176 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 177 | for arg do 178 | if 179 | case $arg in #( 180 | -*) false ;; # don't mess with options #( 181 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 182 | [ -e "$t" ] ;; #( 183 | *) false ;; 184 | esac 185 | then 186 | arg=$( cygpath --path --ignore --mixed "$arg" ) 187 | fi 188 | # Roll the args list around exactly as many times as the number of 189 | # args, so each arg winds up back in the position where it started, but 190 | # possibly modified. 191 | # 192 | # NB: a `for` loop captures its iteration list before it begins, so 193 | # changing the positional parameters here affects neither the number of 194 | # iterations, nor the values presented in `arg`. 195 | shift # remove old arg 196 | set -- "$@" "$arg" # push replacement arg 197 | done 198 | fi 199 | 200 | # Collect all arguments for the java command; 201 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 202 | # shell script including quotes and variable substitutions, so put them in 203 | # double quotes to make sure that they get re-expanded; and 204 | # * put everything else in single quotes, so that it's not re-expanded. 205 | 206 | set -- \ 207 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 208 | -classpath "$CLASSPATH" \ 209 | org.gradle.wrapper.GradleWrapperMain \ 210 | "$@" 211 | 212 | # Stop when "xargs" is not available. 213 | if ! command -v xargs >/dev/null 2>&1 214 | then 215 | die "xargs is not available" 216 | fi 217 | 218 | # Use "xargs" to parse quoted args. 219 | # 220 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 221 | # 222 | # In Bash we could simply go: 223 | # 224 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 225 | # set -- "${ARGS[@]}" "$@" 226 | # 227 | # but POSIX shell has neither arrays nor command substitution, so instead we 228 | # post-process each arg (as a line of input to sed) to backslash-escape any 229 | # character that might be a shell metacharacter, then use eval to reverse 230 | # that process (while maintaining the separation between arguments), and wrap 231 | # the whole thing up as a single "set" statement. 232 | # 233 | # This will of course break if any of these variables contains a newline or 234 | # an unmatched quote. 235 | # 236 | 237 | eval "set -- $( 238 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 239 | xargs -n1 | 240 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 241 | tr '\n' ' ' 242 | )" '"$@"' 243 | 244 | exec "$JAVACMD" "$@" 245 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /list-studio-versions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Lists the latest 10 Android Studio versions 3 | 4 | # Function to check if a command exists 5 | command_exists() { 6 | type "$1" &> /dev/null 7 | } 8 | 9 | # Check if curl is installed 10 | if ! command_exists curl; then 11 | echo "Error: curl is not installed. Please install it and try again." 12 | exit 1 13 | fi 14 | 15 | # Check if xmlstarlet is installed 16 | if ! command_exists xmlstarlet; then 17 | echo "Error: xmlstarlet is not installed. Please install it and try again." 18 | exit 1 19 | fi 20 | 21 | # If all commands exist, execute the provided command 22 | curl -sL https://jb.gg/android-studio-releases-list.xml | xmlstarlet sel -t -m "//item" -v "concat(name, ': ', version)" -nl | head -n 10 23 | -------------------------------------------------------------------------------- /release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Fetch the token 4 | TOKEN=$(git config --get github.token) 5 | 6 | # Check if GitHub token exists 7 | if [ -z "$TOKEN" ]; then 8 | echo "GitHub token not found in your git config. Please generate a new token at https://github.com/settings/tokens" 9 | exit 1 10 | fi 11 | 12 | # Make sure that the token is valid (a 200 is good enough, not checking scopes) 13 | RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token $TOKEN" https://api.github.com) 14 | if [ "$RESPONSE" != "200" ]; then 15 | echo "Invalid GitHub token. Please generate a new token at https://github.com/settings/tokens" 16 | exit 1 17 | fi 18 | 19 | # If we made it here, the token is valid 20 | echo -e "GitHub Token is valid. Success!\n " 21 | 22 | # Get the latest tag 23 | TAG=$(git describe --tags `git rev-list --tags --max-count=1`) 24 | 25 | # Release to upload 26 | FILE="./build/distributions/adb-idea-$TAG.zip" 27 | 28 | # Check if the file exists 29 | if [ ! -f "$FILE" ]; then 30 | echo "$FILE does not exist." 31 | exit 1 32 | else 33 | # Get file creation date 34 | echo "This file will be uploaded:" 35 | ls -la "$FILE" 36 | echo "" 37 | fi 38 | 39 | # Show the tag to the user 40 | echo -e "Latest tag is: \033[0;32m$TAG\033[0m" 41 | read -p "Is this the correct tag? (yes/no): " answer 42 | 43 | if [[ "$answer" != "yes" && "$answer" != "y" ]]; then 44 | echo "Time to fix the tag." 45 | exit 1 46 | fi 47 | 48 | # Upload the release using the ghr tool 49 | ghr_output=$(ghr ${TAG} ${FILE} 2>&1) 50 | 51 | if [[ $? -ne 0 ]]; then 52 | echo -e "\033[0;31mUpload failed with error: $ghr_output\033[0m" 53 | exit 1 54 | else 55 | echo -e "\n\033[0;32mRelease uploaded successfully!\033[0m" 56 | echo -e "\033[0;32mhttps://github.com/pbreault/adb-idea/releases/tag/${TAG}\033[0m" 57 | fi 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/Application.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea 2 | 3 | import com.developerphil.adbidea.preference.ApplicationPreferences 4 | import com.developerphil.adbidea.preference.accessor.PreferenceAccessorImpl 5 | import com.developerphil.adbidea.ui.NotificationHelper 6 | import com.intellij.ide.plugins.PluginManagerCore 7 | import com.intellij.ide.util.PropertiesComponent 8 | import com.intellij.openapi.components.Service 9 | import com.intellij.openapi.diagnostic.Logger 10 | import com.intellij.openapi.extensions.PluginId 11 | import com.intellij.util.text.SemVer 12 | 13 | // This is more of a service locator than a proper DI framework. 14 | // It's not used often enough in the codebase to warrant the complexity of a DI solution like dagger. 15 | @Service 16 | class Application { 17 | 18 | private val logger = Logger.getInstance(Application::class.java) 19 | private val pluginPackage = "com.developerphil.adbidea" 20 | private val applicationPreferencesAccessor = PreferenceAccessorImpl(PropertiesComponent.getInstance()) 21 | private val applicationPreferences = ApplicationPreferences(applicationPreferencesAccessor) 22 | 23 | init { 24 | try { 25 | val pluginId = PluginId.getId(pluginPackage) 26 | val pluginDescriptor = PluginManagerCore.getPlugin(pluginId) 27 | val version = pluginDescriptor?.version 28 | if (version != null) { 29 | applicationPreferences.savePreviousPluginVersion(SemVer.parseFromText(version)!!) 30 | } else { 31 | logger.error("Plugin version is null for plugin ID: $pluginId") 32 | } 33 | } catch (e: Exception) { 34 | NotificationHelper.error("Couldn't initialize ADB Idea: ${e.message}") 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/HelperMethods.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea 2 | 3 | fun waitUntil(timeoutMillis: Long = 30000L, step: Long = 100L, condition: () -> Boolean) { 4 | val endTime = System.currentTimeMillis() + timeoutMillis 5 | while (System.currentTimeMillis() < endTime) { 6 | if (condition()) { 7 | return 8 | } 9 | Thread.sleep(step) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/ObjectGraph.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea 2 | 3 | import com.developerphil.adbidea.adb.BridgeImpl 4 | import com.developerphil.adbidea.adb.DeviceResultFetcher 5 | import com.developerphil.adbidea.adb.UseSameDevicesHelper 6 | import com.developerphil.adbidea.preference.ProjectPreferences 7 | import com.developerphil.adbidea.preference.accessor.PreferenceAccessorImpl 8 | import com.intellij.ide.util.PropertiesComponent 9 | import com.intellij.openapi.components.Service 10 | import com.intellij.openapi.project.Project 11 | import kotlinx.coroutines.CoroutineScope 12 | 13 | // This is more of a service locator than a proper DI framework. 14 | // It's not used often enough in the codebase to warrant the complexity of a DI solution like dagger. 15 | @Service(Service.Level.PROJECT) 16 | class ObjectGraph(private val project: Project, coroutineScope: CoroutineScope) { 17 | 18 | val deviceResultFetcher by lazy { DeviceResultFetcher(project, useSameDevicesHelper, bridge) } 19 | val projectPreferences: ProjectPreferences by lazy { ProjectPreferences(projectPreferenceAccessor) } 20 | val projectScope: CoroutineScope = coroutineScope 21 | 22 | private val useSameDevicesHelper by lazy { UseSameDevicesHelper(projectPreferences, bridge) } 23 | private val projectPreferenceAccessor by lazy { PreferenceAccessorImpl(PropertiesComponent.getInstance(project)) } 24 | private val bridge by lazy { BridgeImpl(project) } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/ReflectKt.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea 2 | 3 | import org.joor.Reflect 4 | 5 | inline fun on() = Reflect.onClass(T::class.java) 6 | inline fun Reflect.asType() = this.`as`(T::class.java) -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/AdbAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.intellij.openapi.actionSystem.AnAction 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import com.intellij.openapi.actionSystem.PlatformDataKeys 6 | import com.intellij.openapi.project.Project 7 | 8 | abstract class AdbAction : AnAction() { 9 | override fun actionPerformed(event: AnActionEvent) = actionPerformed(event, event.getData(PlatformDataKeys.PROJECT)!!) 10 | abstract fun actionPerformed(e: AnActionEvent, project: Project) 11 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/ClearDataAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.developerphil.adbidea.adb.AdbFacade 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import com.intellij.openapi.project.Project 6 | 7 | class ClearDataAction : AdbAction() { 8 | override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.clearData(project) 9 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/ClearDataAndRestartAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.developerphil.adbidea.adb.AdbFacade 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import com.intellij.openapi.project.Project 6 | 7 | class ClearDataAndRestartAction : AdbAction() { 8 | override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.clearDataAndRestart(project) 9 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/ClearDataAndRestartWithDebuggerAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.developerphil.adbidea.adb.AdbFacade 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import com.intellij.openapi.project.Project 6 | 7 | class ClearDataAndRestartWithDebuggerAction : AdbAction() { 8 | override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.clearDataAndRestartWithDebugger(project) 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/DisableMobileAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.developerphil.adbidea.adb.AdbFacade 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import com.intellij.openapi.project.Project 6 | 7 | class DisableMobileAction : AdbAction() { 8 | override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.disableMobile(project) 9 | } 10 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/DisableWifiAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.developerphil.adbidea.adb.AdbFacade 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import com.intellij.openapi.project.Project 6 | 7 | class DisableWifiAction : AdbAction() { 8 | override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.disableWifi(project) 9 | } 10 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/EnableMobileAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.developerphil.adbidea.adb.AdbFacade 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import com.intellij.openapi.project.Project 6 | 7 | class EnableMobileAction : AdbAction() { 8 | override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.enableMobile(project) 9 | } 10 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/EnableWifiAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.developerphil.adbidea.adb.AdbFacade 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import com.intellij.openapi.project.Project 6 | 7 | class EnableWifiAction : AdbAction() { 8 | override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.enableWifi(project) 9 | } 10 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/GrantPermissionsAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.developerphil.adbidea.adb.AdbFacade 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import com.intellij.openapi.project.Project 6 | 7 | class GrantPermissionsAction : AdbAction() { 8 | override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.grantPermissions(project) 9 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/KillAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.developerphil.adbidea.adb.AdbFacade 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import com.intellij.openapi.project.Project 6 | 7 | class KillAction : AdbAction() { 8 | override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.kill(project) 9 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/QuickListAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.intellij.ide.actions.QuickSwitchSchemeAction 4 | import com.intellij.openapi.actionSystem.ActionManager 5 | import com.intellij.openapi.actionSystem.AnActionEvent 6 | import com.intellij.openapi.actionSystem.DataContext 7 | import com.intellij.openapi.actionSystem.DefaultActionGroup 8 | import com.intellij.openapi.project.DumbAware 9 | import com.intellij.openapi.project.Project 10 | 11 | class QuickListAction : QuickSwitchSchemeAction(), DumbAware { 12 | override fun fillActions(project: Project?, group: DefaultActionGroup, dataContext: DataContext) { 13 | 14 | if (project == null) { 15 | return 16 | } 17 | 18 | addAction("com.developerphil.adbidea.action.UninstallAction", group) 19 | addAction("com.developerphil.adbidea.action.KillAction", group) 20 | addAction("com.developerphil.adbidea.action.StartAction", group) 21 | addAction("com.developerphil.adbidea.action.RestartAction", group) 22 | addAction("com.developerphil.adbidea.action.ClearDataAction", group) 23 | addAction("com.developerphil.adbidea.action.ClearDataAndRestartAction", group) 24 | addAction("com.developerphil.adbidea.action.RevokePermissionsAction", group) 25 | group.addSeparator() 26 | addAction("com.developerphil.adbidea.action.StartWithDebuggerAction", group) 27 | addAction("com.developerphil.adbidea.action.RestartWithDebuggerAction", group) 28 | } 29 | 30 | 31 | private fun addAction(actionId: String, toGroup: DefaultActionGroup) { 32 | // add action to group if it is available 33 | ActionManager.getInstance().getAction(actionId)?.let { 34 | toGroup.add(it) 35 | } 36 | } 37 | 38 | override fun isEnabled() = true 39 | override fun getPopupTitle(e: AnActionEvent) = "ADB Operations Popup" 40 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/RestartAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.developerphil.adbidea.adb.AdbFacade 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import com.intellij.openapi.project.Project 6 | 7 | class RestartAction : AdbAction() { 8 | override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.restartDefaultActivity(project) 9 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/RestartWithDebuggerAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.developerphil.adbidea.adb.AdbFacade 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import com.intellij.openapi.project.Project 6 | 7 | class RestartWithDebuggerAction : AdbAction() { 8 | override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.restartDefaultActivityWithDebugger(project) 9 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/RevokePermissionsAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.developerphil.adbidea.adb.AdbFacade 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import com.intellij.openapi.project.Project 6 | 7 | class RevokePermissionsAction : AdbAction() { 8 | override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.revokePermissions(project) 9 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/RevokePermissionsAndRestartAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.developerphil.adbidea.adb.AdbFacade 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import com.intellij.openapi.project.Project 6 | 7 | class RevokePermissionsAndRestartAction : AdbAction() { 8 | override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.revokePermissionsAndRestart(project) 9 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/StartAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.developerphil.adbidea.adb.AdbFacade 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import com.intellij.openapi.project.Project 6 | 7 | class StartAction : AdbAction() { 8 | override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.startDefaultActivity(project) 9 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/StartWithDebuggerAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.developerphil.adbidea.adb.AdbFacade 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import com.intellij.openapi.project.Project 6 | 7 | class StartWithDebuggerAction : AdbAction() { 8 | override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.startDefaultActivityWithDebugger(project) 9 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/action/UninstallAction.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.action 2 | 3 | import com.developerphil.adbidea.adb.AdbFacade 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import com.intellij.openapi.project.Project 6 | 7 | class UninstallAction : AdbAction() { 8 | override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.uninstall(project) 9 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/AdbFacade.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb 2 | 3 | import com.developerphil.adbidea.ObjectGraph 4 | import com.developerphil.adbidea.adb.DeviceResult.SuccessfulDeviceResult 5 | import com.developerphil.adbidea.adb.command.* 6 | import com.developerphil.adbidea.adb.command.SvcCommand.MOBILE 7 | import com.developerphil.adbidea.adb.command.SvcCommand.WIFI 8 | import com.developerphil.adbidea.ui.NotificationHelper 9 | import com.google.common.util.concurrent.ThreadFactoryBuilder 10 | import com.intellij.openapi.project.Project 11 | import java.util.concurrent.Executors 12 | 13 | object AdbFacade { 14 | private val EXECUTOR = Executors.newCachedThreadPool(ThreadFactoryBuilder().setNameFormat("AdbIdea-%d").build()) 15 | 16 | fun uninstall(project: Project) = executeOnDevice(project, UninstallCommand()) 17 | fun kill(project: Project) = executeOnDevice(project, KillCommand()) 18 | fun grantPermissions(project: Project) = executeOnDevice(project, GrantPermissionsCommand()) 19 | fun revokePermissions(project: Project) = executeOnDevice(project, RevokePermissionsCommand()) 20 | fun revokePermissionsAndRestart(project: Project) = executeOnDevice(project, RevokePermissionsAndRestartCommand()) 21 | fun startDefaultActivity(project: Project) = executeOnDevice(project, StartDefaultActivityCommand(false)) 22 | fun startDefaultActivityWithDebugger(project: Project) = executeOnDevice(project, StartDefaultActivityCommand(true)) 23 | fun restartDefaultActivity(project: Project) = executeOnDevice(project, RestartPackageCommand()) 24 | fun restartDefaultActivityWithDebugger(project: Project) = 25 | executeOnDevice(project, CommandList(KillCommand(), StartDefaultActivityCommand(true))) 26 | 27 | fun clearData(project: Project) = executeOnDevice(project, ClearDataCommand()) 28 | fun clearDataAndRestart(project: Project) = executeOnDevice(project, ClearDataAndRestartCommand()) 29 | fun clearDataAndRestartWithDebugger(project: Project) = 30 | executeOnDevice(project, ClearDataAndRestartWithDebuggerCommand()) 31 | 32 | fun enableWifi(project: Project) = executeOnDevice(project, ToggleSvcCommand(WIFI, true)) 33 | fun disableWifi(project: Project) = executeOnDevice(project, ToggleSvcCommand(WIFI, false)) 34 | fun enableMobile(project: Project) = executeOnDevice(project, ToggleSvcCommand(MOBILE, true)) 35 | fun disableMobile(project: Project) = executeOnDevice(project, ToggleSvcCommand(MOBILE, false)) 36 | 37 | private fun executeOnDevice(project: Project, runnable: Command) { 38 | if (AdbUtil.isGradleSyncInProgress(project)) { 39 | NotificationHelper.error("Gradle sync is in progress") 40 | return 41 | } 42 | 43 | val objectGraph = project.getService(ObjectGraph::class.java) 44 | when (val result = objectGraph.deviceResultFetcher.fetch()) { 45 | is SuccessfulDeviceResult -> { 46 | result.devices.forEach { device -> 47 | EXECUTOR.submit { 48 | runnable.run( 49 | CommandContext( 50 | project = project, 51 | device = device, 52 | facet = result.facet, 53 | packageName = result.packageName, 54 | coroutineScope = objectGraph.projectScope 55 | ) 56 | ) 57 | } 58 | } 59 | } 60 | 61 | is DeviceResult.Cancelled -> Unit 62 | is DeviceResult.DeviceNotFound, null -> NotificationHelper.error("No device found") 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/AdbUtil.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb 2 | 3 | import com.android.ddmlib.AdbCommandRejectedException 4 | import com.android.ddmlib.IDevice 5 | import com.android.ddmlib.ShellCommandUnresponsiveException 6 | import com.android.ddmlib.TimeoutException 7 | import com.android.tools.idea.gradle.project.sync.GradleSyncState 8 | import com.developerphil.adbidea.adb.command.receiver.GenericReceiver 9 | import com.developerphil.adbidea.ui.NotificationHelper.info 10 | import com.intellij.openapi.project.Project 11 | import java.io.IOException 12 | import java.util.concurrent.TimeUnit 13 | 14 | object AdbUtil { 15 | @Throws(TimeoutException::class, AdbCommandRejectedException::class, ShellCommandUnresponsiveException::class, IOException::class) 16 | fun isAppInstalled(device: IDevice, packageName: String): Boolean { 17 | val receiver = GenericReceiver() 18 | // "pm list packages com.my.package" will return one line per package installed that corresponds to this package. 19 | // if this list is empty, we know for sure that the app is not installed 20 | device.executeShellCommand("pm list packages $packageName", receiver, 15L, TimeUnit.SECONDS) 21 | //TODO make sure that it is the exact package name and not a subset. 22 | // e.g. if our app is called com.example but there is another app called com.example.another.app, it will match and return a false positive 23 | return receiver.adbOutputLines.isNotEmpty() 24 | } 25 | 26 | fun isGradleSyncInProgress(project: Project): Boolean { 27 | return try { 28 | GradleSyncState.getInstance(project).isSyncInProgress 29 | } catch (t: Throwable) { 30 | info("Couldn't determine if a gradle sync is in progress") 31 | false 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/Bridge.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb 2 | 3 | import com.android.ddmlib.AndroidDebugBridge 4 | import com.android.ddmlib.IDevice 5 | import com.intellij.openapi.project.Project 6 | import org.jetbrains.android.sdk.AndroidSdkUtils 7 | 8 | interface Bridge { 9 | fun isReady(): Boolean 10 | fun connectedDevices(): List 11 | } 12 | 13 | 14 | class BridgeImpl(private val project: Project) : Bridge { 15 | 16 | private val androidBridge: AndroidDebugBridge? 17 | get() = AndroidSdkUtils.getDebugBridge(project) 18 | 19 | override fun isReady() = androidBridge?.let { 20 | it.isConnected && it.hasInitialDeviceList() 21 | } ?: false 22 | 23 | override fun connectedDevices(): List { 24 | return androidBridge?.devices?.asList() ?: emptyList() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/DeviceResultFetcher.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb 2 | 3 | import com.android.ddmlib.IDevice 4 | import com.android.tools.idea.insights.isAndroidApp 5 | import com.android.tools.idea.model.AndroidModel 6 | import com.android.tools.idea.projectsystem.gradle.getHolderModule 7 | import com.android.tools.idea.util.androidFacet 8 | import com.developerphil.adbidea.adb.DeviceResult.DeviceNotFound 9 | import com.developerphil.adbidea.adb.DeviceResult.SuccessfulDeviceResult 10 | import com.developerphil.adbidea.compatibility.BackwardCompatibleGetter 11 | import com.developerphil.adbidea.ui.DeviceChooserDialog 12 | import com.developerphil.adbidea.ui.ModuleChooserDialogHelper 13 | import com.developerphil.adbidea.ui.NotificationHelper 14 | import com.intellij.facet.ProjectFacetManager 15 | import com.intellij.openapi.module.Module 16 | import com.intellij.openapi.module.impl.ModuleImpl 17 | import com.intellij.openapi.project.Project 18 | import com.intellij.openapi.ui.DialogWrapper 19 | import org.jetbrains.android.facet.AndroidFacet 20 | import org.joor.Reflect 21 | 22 | 23 | class DeviceResultFetcher( 24 | private val project: Project, 25 | private val useSameDevicesHelper: UseSameDevicesHelper, 26 | private val bridge: Bridge 27 | ) { 28 | 29 | fun fetch(): DeviceResult? { 30 | val facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID) 31 | if (facets.isNotEmpty()) { 32 | val facet = getFacet(facets) ?: return null 33 | 34 | val packageName = AndroidModel.get(facet)?.applicationId ?: return null 35 | 36 | if (!bridge.isReady()) { 37 | NotificationHelper.error("No platform configured") 38 | return null 39 | } 40 | 41 | val rememberedDevices = useSameDevicesHelper.getRememberedDevices() 42 | if (rememberedDevices.isNotEmpty()) { 43 | return SuccessfulDeviceResult(rememberedDevices, facet, packageName) 44 | } 45 | 46 | val devices = bridge.connectedDevices() 47 | return if (devices.size == 1) { 48 | SuccessfulDeviceResult(devices, facet, packageName) 49 | } else if (devices.size > 1) { 50 | showDeviceChooserDialog(facet, packageName) 51 | } else { 52 | DeviceNotFound 53 | } 54 | } 55 | return null 56 | } 57 | 58 | private fun getFacet(facets: List): AndroidFacet? { 59 | val appFacets = facets 60 | .map { HolderModuleGetter(it).get() } 61 | .filter { it.isAndroidApp } 62 | .mapNotNull { it.androidFacet } 63 | .distinct() 64 | 65 | return if (appFacets.size > 1) { 66 | ModuleChooserDialogHelper.showDialogForFacets(project, appFacets) 67 | } else { 68 | appFacets[0] 69 | } 70 | } 71 | 72 | // Can be removed after 242.23339 73 | class HolderModuleGetter(private val facet: AndroidFacet) : BackwardCompatibleGetter() { 74 | override fun getCurrentImplementation(): Module { 75 | return facet.module.getHolderModule() 76 | } 77 | 78 | override fun getPreviousImplementation(): Module { 79 | return Reflect.onClass("com.android.tools.idea.projectsystem.ModuleSystemUtil") 80 | .call("getHolderModule", facet.module).get() 81 | } 82 | } 83 | 84 | 85 | private fun showDeviceChooserDialog(facet: AndroidFacet, packageName: String): DeviceResult { 86 | val chooser = DeviceChooserDialog(facet) 87 | chooser.show() 88 | 89 | if (chooser.exitCode != DialogWrapper.OK_EXIT_CODE) { 90 | return DeviceResult.Cancelled 91 | } 92 | 93 | 94 | val selectedDevices = chooser.selectedDevices 95 | 96 | if (chooser.useSameDevices()) { 97 | useSameDevicesHelper.rememberDevices() 98 | } 99 | 100 | if (selectedDevices.isEmpty()) { 101 | return DeviceResult.Cancelled 102 | } 103 | 104 | return SuccessfulDeviceResult(selectedDevices.asList(), facet, packageName) 105 | } 106 | } 107 | 108 | 109 | sealed class DeviceResult { 110 | data class SuccessfulDeviceResult( 111 | val devices: List, 112 | val facet: AndroidFacet, 113 | val packageName: String 114 | ) : DeviceResult() 115 | 116 | data object Cancelled : DeviceResult() 117 | data object DeviceNotFound : DeviceResult() 118 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/ShellCommandsFactory.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb 2 | 3 | object ShellCommandsFactory { 4 | 5 | @JvmStatic 6 | fun startActivity(packageName: String, activityName: String, attachDebugger: Boolean): String { 7 | val debugFlag = if (attachDebugger) "-D " else "" 8 | return "am start $debugFlag-n $packageName/$activityName" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/UseSameDevicesHelper.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb 2 | 3 | import com.android.ddmlib.IDevice 4 | import com.developerphil.adbidea.preference.ProjectPreferences 5 | 6 | class UseSameDevicesHelper(private val projectPreferences: ProjectPreferences, private val bridge: Bridge) { 7 | 8 | var previouslyConnectedDevices: List? = null 9 | 10 | fun getRememberedDevices(): List { 11 | val selectedDeviceSerials = projectPreferences.getSelectedDeviceSerials() 12 | val currentlyConnectedDevices = bridge.connectedDevices() 13 | 14 | if (currentlyConnectedDevices == previouslyConnectedDevices) { 15 | val rememberedDevices = currentlyConnectedDevices.filter { selectedDeviceSerials.contains(it.serialNumber) } 16 | if (rememberedDevices.size == selectedDeviceSerials.size) { 17 | return rememberedDevices 18 | } 19 | } 20 | 21 | return emptyList() 22 | } 23 | 24 | fun rememberDevices() { 25 | previouslyConnectedDevices = bridge.connectedDevices() 26 | } 27 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/command/ClearDataAndRestartCommand.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb.command 2 | 3 | class ClearDataAndRestartCommand : CommandList(ClearDataCommand(), StartDefaultActivityCommand(false)) 4 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/command/ClearDataAndRestartWithDebuggerCommand.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb.command 2 | 3 | class ClearDataAndRestartWithDebuggerCommand : CommandList(ClearDataCommand(), StartDefaultActivityCommand(true)) 4 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/command/ClearDataCommand.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb.command 2 | 3 | import com.developerphil.adbidea.adb.AdbUtil 4 | import com.developerphil.adbidea.adb.command.receiver.GenericReceiver 5 | import com.developerphil.adbidea.ui.NotificationHelper 6 | import java.util.concurrent.TimeUnit 7 | 8 | class ClearDataCommand : Command { 9 | override fun run(context: CommandContext): Boolean = with(context) { 10 | try { 11 | if (AdbUtil.isAppInstalled(device, packageName)) { 12 | device.executeShellCommand("pm clear $packageName", GenericReceiver(), 15L, TimeUnit.SECONDS) 13 | NotificationHelper.info(String.format("%s cleared data for app on %s", packageName, device.name)) 14 | return true 15 | } else { 16 | NotificationHelper.error(String.format("%s is not installed on %s", packageName, device.name)) 17 | } 18 | } catch (e1: Exception) { 19 | NotificationHelper.error("Clear data failed... " + e1.message) 20 | } 21 | return false 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/command/Command.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb.command 2 | 3 | import com.android.ddmlib.IDevice 4 | import com.intellij.openapi.project.Project 5 | import kotlinx.coroutines.CoroutineScope 6 | import org.jetbrains.android.facet.AndroidFacet 7 | 8 | interface Command { 9 | /** 10 | * @return true if the command executed properly 11 | */ 12 | fun run(context: CommandContext): Boolean 13 | } 14 | 15 | data class CommandContext( 16 | val project: Project, 17 | val device: IDevice, 18 | val facet: AndroidFacet, 19 | val packageName: String, 20 | val coroutineScope: CoroutineScope 21 | ) 22 | 23 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/command/CommandList.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb.command 2 | 3 | open class CommandList(vararg commands: Command) : Command { 4 | 5 | private val commands = listOf(*commands) 6 | 7 | override fun run(context: CommandContext): Boolean { 8 | for (command in commands) { 9 | if (!command.run(context)) { 10 | return false 11 | } 12 | } 13 | return true 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/command/GrantPermissionsCommand.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb.command 2 | 3 | import com.android.ddmlib.IDevice 4 | import com.developerphil.adbidea.adb.AdbUtil 5 | import com.developerphil.adbidea.adb.command.receiver.GenericReceiver 6 | import com.developerphil.adbidea.ui.NotificationHelper 7 | import java.util.* 8 | import java.util.concurrent.TimeUnit 9 | import java.util.function.Consumer 10 | 11 | class GrantPermissionsCommand : Command { 12 | override fun run(context: CommandContext): Boolean = with(context) { 13 | try { 14 | if (deviceHasMarshmallow(device)) if (AdbUtil.isAppInstalled(device, packageName)) { 15 | val shellOutputReceiver = GenericReceiver() 16 | device.executeShellCommand("dumpsys package $packageName", shellOutputReceiver, 15L, TimeUnit.SECONDS) 17 | val adbOutputLines = getRequestedPermissions(shellOutputReceiver.adbOutputLines) 18 | NotificationHelper.info(adbOutputLines.toTypedArray().contentToString()) 19 | adbOutputLines.forEach(Consumer { s: String -> 20 | try { 21 | device.executeShellCommand("pm grant $packageName $s", GenericReceiver(), 15L, TimeUnit.SECONDS) 22 | NotificationHelper.info(String.format("Permission %s granted on %s", s, device.name)) 23 | } catch (e: Exception) { 24 | NotificationHelper.error(String.format("Granting %s failed on %s: %s", s, device.name, e.message)) 25 | } 26 | }) 27 | return true 28 | } else { 29 | NotificationHelper.error(String.format("%s is not installed on %s", packageName, device.name)) 30 | } else { 31 | NotificationHelper.error(String.format("%s must be at least api level 23", device.name)) 32 | } 33 | } catch (e1: Exception) { 34 | NotificationHelper.error("Granting permissions fail... " + e1.message) 35 | } 36 | return false 37 | } 38 | 39 | private fun deviceHasMarshmallow(device: IDevice): Boolean { 40 | return device.version.apiLevel >= 23 41 | } 42 | 43 | private fun getRequestedPermissions(list: List): List { 44 | var requestedPermissionsSection = false 45 | val requestPermissions: MutableList = ArrayList() 46 | for (s in list) { 47 | if (!s.contains(".permission.")) { 48 | requestedPermissionsSection = false 49 | } 50 | if (s.contains("requested permissions:")) { 51 | requestedPermissionsSection = true 52 | continue 53 | } 54 | if (requestedPermissionsSection) { 55 | val permissionName = s.replace(":", "").trim { it <= ' ' } 56 | requestPermissions.add(permissionName) 57 | } 58 | } 59 | return requestPermissions 60 | } 61 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/command/KillCommand.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb.command 2 | 3 | import com.developerphil.adbidea.adb.AdbUtil 4 | import com.developerphil.adbidea.adb.command.receiver.GenericReceiver 5 | import com.developerphil.adbidea.ui.NotificationHelper.error 6 | import com.developerphil.adbidea.ui.NotificationHelper.info 7 | import java.util.concurrent.TimeUnit 8 | 9 | class KillCommand : Command { 10 | override fun run(context: CommandContext): Boolean = with(context) { 11 | try { 12 | if (AdbUtil.isAppInstalled(device, packageName)) { 13 | device.executeShellCommand("am force-stop $packageName", GenericReceiver(), 15L, TimeUnit.SECONDS) 14 | info(String.format("%s forced-stop on %s", packageName, device.name)) 15 | return true 16 | } else { 17 | error(String.format("%s is not installed on %s", packageName, device.name)) 18 | } 19 | } catch (e1: Exception) { 20 | error("Kill fail... " + e1.message) 21 | } 22 | return false 23 | } 24 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/command/RestartPackageCommand.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb.command 2 | 3 | class RestartPackageCommand : CommandList(KillCommand(), StartDefaultActivityCommand(false)) -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/command/RevokePermissionsAndRestartCommand.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb.command 2 | 3 | class RevokePermissionsAndRestartCommand : CommandList(RevokePermissionsCommand(), StartDefaultActivityCommand(false)) -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/command/RevokePermissionsCommand.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb.command 2 | 3 | import com.android.ddmlib.IDevice 4 | import com.developerphil.adbidea.adb.AdbUtil 5 | import com.developerphil.adbidea.adb.command.receiver.GenericReceiver 6 | import com.developerphil.adbidea.ui.NotificationHelper 7 | import com.developerphil.adbidea.ui.NotificationHelper.error 8 | import java.util.concurrent.TimeUnit 9 | 10 | class RevokePermissionsCommand : Command { 11 | override fun run(context: CommandContext): Boolean = with(context) { 12 | try { 13 | if (deviceHasMarshmallow(device)) if (AdbUtil.isAppInstalled(device, packageName)) { 14 | val shellOutputReceiver = GenericReceiver() 15 | device.executeShellCommand("dumpsys package $packageName", shellOutputReceiver, 15L, TimeUnit.SECONDS) 16 | shellOutputReceiver.adbOutputLines.stream() //only granted permissions, they come in "android.permission.CAMERA: granted=true" 17 | .filter { s: String -> s.contains("permission") }.filter { s: String -> s.contains("granted=true") } //just the permission name is important 18 | .map { s: String -> s.split(":".toRegex()).toTypedArray()[0].trim { it <= ' ' } } 19 | .forEach { s: String -> 20 | try { 21 | device.executeShellCommand("pm revoke $packageName $s", GenericReceiver(), 15L, TimeUnit.SECONDS) 22 | NotificationHelper.info(String.format("Permission %s revoked on %s", s, device.name)) 23 | } catch (e: Exception) { 24 | error(String.format("Revoking %s failed on %s: %s", s, device.name, e.message)) 25 | } 26 | } 27 | return true 28 | } else { 29 | error(String.format("%s is not installed on %s", packageName, device.name)) 30 | } else { 31 | error(String.format("%s must be at least api level 23", device.name)) 32 | } 33 | } catch (e1: Exception) { 34 | error("Revoking permissions fail... " + e1.message) 35 | } 36 | return false 37 | } 38 | 39 | private fun deviceHasMarshmallow(device: IDevice) = device.version.apiLevel >= 23 40 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/command/StartDefaultActivityCommand.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb.command 2 | 3 | import com.android.ddmlib.IDevice 4 | import com.android.ddmlib.MultiLineReceiver 5 | import com.android.tools.idea.run.activity.ActivityLocator.ActivityLocatorException 6 | import com.android.tools.idea.run.activity.DefaultActivityLocator 7 | import com.developerphil.adbidea.adb.ShellCommandsFactory.startActivity 8 | import com.developerphil.adbidea.debugger.Debugger 9 | import com.developerphil.adbidea.ui.NotificationHelper.error 10 | import com.developerphil.adbidea.ui.NotificationHelper.info 11 | import com.google.common.base.Joiner 12 | import com.google.common.base.Strings 13 | import com.intellij.openapi.application.ApplicationManager 14 | import com.intellij.openapi.util.ThrowableComputable 15 | import org.jetbrains.android.facet.AndroidFacet 16 | import java.util.* 17 | import java.util.concurrent.TimeUnit 18 | 19 | class StartDefaultActivityCommand(private val withDebugger: Boolean) : Command { 20 | override fun run(context: CommandContext): Boolean = with(context) { 21 | try { 22 | val activityName = getDefaultActivityName(facet, device) 23 | val receiver = StartActivityReceiver() 24 | val shellCommand = startActivity(packageName, activityName, withDebugger) 25 | device.executeShellCommand(shellCommand, receiver, 15L, TimeUnit.SECONDS) 26 | if (withDebugger) { 27 | Debugger(project, device, packageName, coroutineScope).attach() 28 | } 29 | if (receiver.isSuccess) { 30 | info(String.format("%s started on %s", packageName, device.name)) 31 | return true 32 | } else { 33 | error( 34 | String.format( 35 | "%s could not be started on %s. \n\nADB Output: \n%s", 36 | packageName, 37 | device.name, 38 | receiver.message 39 | ) 40 | ) 41 | } 42 | } catch (e: Exception) { 43 | error("Start fail... " + e.message) 44 | } 45 | return false 46 | } 47 | 48 | @Throws(ActivityLocatorException::class) 49 | private fun getDefaultActivityName(facet: AndroidFacet, device: IDevice): String { 50 | return ApplicationManager.getApplication() 51 | .runReadAction(ThrowableComputable { 52 | DefaultActivityLocator(facet).getQualifiedActivityName( 53 | device 54 | ) 55 | }) 56 | } 57 | 58 | class StartActivityReceiver : MultiLineReceiver() { 59 | var message = "Nothing Received" 60 | var currentLines: MutableList = ArrayList() 61 | override fun processNewLines(strings: Array) { 62 | for (s in strings) { 63 | if (!Strings.isNullOrEmpty(s)) { 64 | currentLines.add(s) 65 | } 66 | } 67 | computeMessage() 68 | } 69 | 70 | private fun computeMessage() { 71 | message = Joiner.on("\n").join(currentLines) 72 | } 73 | 74 | override fun isCancelled(): Boolean { 75 | return false 76 | } 77 | 78 | val isSuccess: Boolean 79 | get() = currentLines.size in 1..2 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/command/ToggleSvcCommand.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb.command 2 | 3 | import com.developerphil.adbidea.adb.command.receiver.GenericReceiver 4 | import com.developerphil.adbidea.ui.NotificationHelper.error 5 | import com.developerphil.adbidea.ui.NotificationHelper.info 6 | import java.util.concurrent.TimeUnit 7 | 8 | enum class SvcCommand(val parameter: String, val description: String) { 9 | WIFI("wifi", "Wi-Fi"), 10 | MOBILE("data", "Mobile data") 11 | } 12 | 13 | class ToggleSvcCommand( 14 | private val command: SvcCommand, 15 | private val enable: Boolean) : Command { 16 | 17 | private val shellCommand = "svc ${command.parameter} ${enable.toState()}" 18 | 19 | override fun run(context: CommandContext): Boolean = with(context) { 20 | try { 21 | device.executeShellCommand(shellCommand, GenericReceiver(), 30L, TimeUnit.SECONDS) 22 | info(String.format("%s %s%s on %s", command.description, enable.toState(), "d", device.name)) 23 | return true 24 | } catch (e: Exception) { 25 | error("Failure while attempting to ${enable.toState()} ${command.description} on ${device.name}: " + e.message) 26 | } 27 | return false 28 | } 29 | 30 | private fun Boolean.toState() = if (this) "enable" else "disable" 31 | } 32 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/command/UninstallCommand.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb.command 2 | 3 | import com.android.ddmlib.InstallException 4 | import com.developerphil.adbidea.ui.NotificationHelper.error 5 | import com.developerphil.adbidea.ui.NotificationHelper.info 6 | 7 | class UninstallCommand : Command { 8 | override fun run(context: CommandContext): Boolean = with(context) { 9 | try { 10 | val errorCode = device.uninstallPackage(packageName) 11 | if (errorCode == null) { 12 | info(String.format("%s uninstalled on %s", packageName, device.name)) 13 | return true 14 | } else { 15 | error(String.format("%s is not installed on %s", packageName, device.name)) 16 | } 17 | } catch (e1: InstallException) { 18 | error("Uninstall fail... " + e1.message) 19 | } 20 | return false 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/adb/command/receiver/GenericReceiver.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb.command.receiver 2 | 3 | import com.android.ddmlib.MultiLineReceiver 4 | import java.util.* 5 | import java.util.regex.Pattern 6 | 7 | class GenericReceiver : MultiLineReceiver() { 8 | 9 | val adbOutputLines: MutableList = ArrayList() 10 | private var errorMessage: String? = null 11 | 12 | override fun processNewLines(lines: Array) { 13 | adbOutputLines.addAll(listOf(*lines)) 14 | for (line in lines) { 15 | if (line.isNotEmpty()) { 16 | errorMessage = if (line.startsWith(SUCCESS_OUTPUT)) { 17 | null 18 | } else { 19 | val m = FAILURE_PATTERN.matcher(line) 20 | if (m.matches()) { 21 | m.group(1) 22 | } else { 23 | "Unknown failure" 24 | } 25 | } 26 | } 27 | } 28 | } 29 | 30 | override fun isCancelled() = false 31 | 32 | } 33 | 34 | private const val SUCCESS_OUTPUT = "Success" //$NON-NLS-1$ 35 | private val FAILURE_PATTERN = Pattern.compile("Failure\\s+\\[(.*)\\]") //$NON-NLS-1$ 36 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/compatibility/BackwardCompatibleGetter.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.compatibility 2 | 3 | import org.joor.ReflectException 4 | 5 | /** 6 | * Abstracts the logic to call the current implementation and fall back on reflection for previous versions 7 | */ 8 | abstract class BackwardCompatibleGetter { 9 | fun get(): T { 10 | return try { 11 | getCurrentImplementation() 12 | } catch (error: LinkageError) { 13 | getPreviousImplementation() 14 | } catch (e: Throwable) { 15 | if (isReflectiveException(e)) { 16 | getPreviousImplementation() 17 | } else { 18 | throw RuntimeException(e) 19 | } 20 | } 21 | } 22 | 23 | private fun isReflectiveException(t: Throwable): Boolean { 24 | return t is ClassNotFoundException || 25 | t is NoSuchFieldException || 26 | t is LinkageError || 27 | t is NoSuchMethodException || 28 | t is ReflectException 29 | } 30 | 31 | abstract fun getCurrentImplementation() : T 32 | 33 | abstract fun getPreviousImplementation() : T 34 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/debugger/Debugger.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.debugger 2 | 3 | import com.android.ddmlib.Client 4 | import com.android.ddmlib.IDevice 5 | import com.android.tools.idea.execution.common.debug.AndroidDebugger 6 | import com.android.tools.idea.execution.common.debug.AndroidDebuggerState 7 | import com.android.tools.idea.execution.common.debug.DebugSessionStarter 8 | import com.android.tools.idea.execution.common.processhandler.AndroidProcessHandler 9 | import com.developerphil.adbidea.compatibility.BackwardCompatibleGetter 10 | import com.developerphil.adbidea.on 11 | import com.developerphil.adbidea.waitUntil 12 | import com.intellij.execution.ExecutionManager 13 | import com.intellij.execution.process.ProcessHandler 14 | import com.intellij.execution.process.ProcessOutputTypes 15 | import com.intellij.openapi.project.Project 16 | import com.intellij.util.concurrency.AppExecutorUtil 17 | import kotlinx.coroutines.CoroutineScope 18 | import kotlinx.coroutines.launch 19 | import org.joor.Reflect.on 20 | 21 | class Debugger( 22 | private val project: Project, 23 | private val device: IDevice, 24 | private val packageName: String, 25 | private val coroutineScope: CoroutineScope 26 | ) { 27 | 28 | fun attach() { 29 | var client: Client? = null 30 | waitUntil { 31 | client = device.getClient(packageName) 32 | AndroidDebugger.EP_NAME.extensions.isNotEmpty() && client != null 33 | } 34 | for (androidDebugger in AndroidDebugger.EP_NAME.extensions) { 35 | if (androidDebugger.supportsProject(project)) { 36 | AppExecutorUtil.getAppExecutorService().execute { 37 | closeOldSessionAndRun(androidDebugger, device.getClient(packageName) ?: client!!) 38 | } 39 | break 40 | } 41 | } 42 | } 43 | 44 | private fun closeOldSessionAndRun(androidDebugger: AndroidDebugger, client: Client) { 45 | terminateRunSessions(client) 46 | 47 | coroutineScope.launch { 48 | DebugSessionStarter.attachDebuggerToClientAndShowTab( 49 | project, 50 | client, 51 | androidDebugger, 52 | androidDebugger.createState() 53 | ) 54 | } 55 | } 56 | 57 | // Disconnect any active run sessions to the same client 58 | private fun terminateRunSessions(selectedClient: Client) { 59 | TerminateRunSession(selectedClient, project).get() 60 | } 61 | } 62 | 63 | class TerminateRunSession( 64 | private val selectedClient: Client, 65 | private val project: Project 66 | ) : BackwardCompatibleGetter() { 67 | override fun getCurrentImplementation() { 68 | val pid = selectedClient.clientData.pid 69 | // find if there are any active run sessions to the same client, and terminate them if so 70 | for (handler in ExecutionManager.getInstance(project).getRunningProcesses()) { 71 | if (handler is AndroidProcessHandler) { 72 | val client = handler.getClient(selectedClient.device) 73 | if (client != null && client.clientData.pid == pid) { 74 | handler.detachProcess() 75 | handler.notifyTextAvailable("Disconnecting run session: a new debug session will be established.\n", ProcessOutputTypes.STDOUT) 76 | break 77 | } 78 | } 79 | } 80 | } 81 | 82 | override fun getPreviousImplementation() { 83 | val pid = pidFrom(selectedClient) 84 | // find if there are any active run sessions to the same client, and terminate them if so 85 | for (handler in RunningProcessesGetter(project).get()) { 86 | if (handler is AndroidProcessHandler) { 87 | val device = on(selectedClient).call("getDevice").get() 88 | val client = handler.getClient(device) 89 | if (client != null && pidFrom(client) == pid) { 90 | handler.detachProcess() 91 | handler.notifyTextAvailable("Disconnecting run session: a new debug session will be established.\n", ProcessOutputTypes.STDOUT) 92 | break 93 | } 94 | } 95 | } 96 | 97 | } 98 | 99 | private fun pidFrom(client: Client) = on(client).call("getClientData").call("getPid").get()!! 100 | } 101 | 102 | private class RunningProcessesGetter( 103 | val project: Project 104 | ) : BackwardCompatibleGetter>() { 105 | override fun getCurrentImplementation(): Array { 106 | return ExecutionManager.getInstance(project).getRunningProcesses() 107 | } 108 | 109 | override fun getPreviousImplementation(): Array { 110 | return on().call("getInstance", project).call("getRunningProcesses").get() 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/preference/ApplicationPreferences.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.preference 2 | 3 | import com.developerphil.adbidea.preference.accessor.PreferenceAccessor 4 | import com.intellij.util.text.SemVer 5 | import java.util.* 6 | 7 | private const val PREVIOUS_VERSION_PROPERTY = "com.developerphil.adbidea.previousversion" 8 | 9 | class ApplicationPreferences(private val preferenceAccessor: PreferenceAccessor) { 10 | 11 | fun savePreviousPluginVersion(semVer: SemVer) { 12 | preferenceAccessor.saveString(PREVIOUS_VERSION_PROPERTY, semVer.toString()) 13 | } 14 | 15 | fun getPreviousPluginVersion(): Optional { 16 | val version = preferenceAccessor.getString(PREVIOUS_VERSION_PROPERTY, defaultValue = "") 17 | return SemVer.parseFromText(version)?.let { Optional.of(it) } ?: Optional.empty() 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/preference/ProjectPreferences.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.preference 2 | 3 | import com.developerphil.adbidea.preference.accessor.PreferenceAccessor 4 | 5 | private const val SELECTED_SERIALS_PROPERTY = "com.developerphil.adbidea.selecteddevices" 6 | 7 | class ProjectPreferences(private val preferenceAccessor: PreferenceAccessor) { 8 | 9 | fun saveSelectedDeviceSerials(serials: List) { 10 | preferenceAccessor.saveString(SELECTED_SERIALS_PROPERTY, serials.joinToString(separator = " ")) 11 | } 12 | 13 | fun getSelectedDeviceSerials(): List { 14 | return with(preferenceAccessor.getString(SELECTED_SERIALS_PROPERTY, "")) { 15 | if (isEmpty()) { 16 | emptyList() 17 | } else { 18 | split(" ") 19 | } 20 | } 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/preference/accessor/PreferenceAccessor.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.preference.accessor 2 | 3 | interface PreferenceAccessor { 4 | fun saveString(key: String, value: String) 5 | fun getString(key: String, defaultValue: String): String 6 | } 7 | 8 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/preference/accessor/PreferenceAccessorImpl.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.preference.accessor 2 | 3 | import com.intellij.ide.util.PropertiesComponent 4 | 5 | class PreferenceAccessorImpl(private val propertiesComponent: PropertiesComponent) : PreferenceAccessor { 6 | 7 | override fun saveString(key: String, value: String) { 8 | propertiesComponent.setValue(key, value) 9 | } 10 | 11 | override fun getString(key: String, defaultValue: String): String { 12 | return propertiesComponent.getValue(key) ?: defaultValue 13 | } 14 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/ui/DeviceChooserDialog.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
41 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/ui/DeviceChooserDialog.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.ui 2 | 3 | import com.android.ddmlib.IDevice 4 | import com.developerphil.adbidea.ObjectGraph 5 | import com.developerphil.adbidea.preference.ProjectPreferences 6 | import com.intellij.openapi.project.Project 7 | import com.intellij.openapi.ui.DialogWrapper 8 | import com.intellij.openapi.util.Disposer 9 | import org.jetbrains.android.facet.AndroidFacet 10 | import org.jetbrains.android.util.AndroidBundle 11 | import org.joor.Reflect 12 | import javax.swing.JCheckBox 13 | import javax.swing.JComponent 14 | import javax.swing.JPanel 15 | 16 | /** 17 | * https://android.googlesource.com/platform/tools/adt/idea/+/refs/heads/mirror-goog-studio-master-dev/android/src/com/android/tools/idea/run/DeviceChooserDialog.java 18 | */ 19 | class DeviceChooserDialog(facet: AndroidFacet) : DialogWrapper(facet.module.project, true) { 20 | 21 | lateinit var myPanel: JPanel 22 | lateinit var myDeviceChooserWrapper: JPanel 23 | lateinit var useSameDeviceSCheckBox: JCheckBox 24 | 25 | private val myProject: Project 26 | private val myDeviceChooser: MyDeviceChooser 27 | private val projectPreferences: ProjectPreferences 28 | 29 | val selectedDevices: Array 30 | get() = myDeviceChooser.selectedDevices 31 | 32 | init { 33 | title = AndroidBundle.message("choose.device.dialog.title") 34 | myProject = facet.module.project 35 | projectPreferences = myProject.getService(ObjectGraph::class.java).projectPreferences 36 | okAction.isEnabled = false 37 | myDeviceChooser = MyDeviceChooser(true, okAction, facet, null) 38 | Disposer.register(myDisposable, myDeviceChooser) 39 | myDeviceChooser.addListener(object : DeviceChooserListener { 40 | override fun selectedDevicesChanged() { 41 | updateOkButton() 42 | } 43 | }) 44 | myDeviceChooserWrapper.add(myDeviceChooser.panel) 45 | myDeviceChooser.init(projectPreferences.getSelectedDeviceSerials()) 46 | init() 47 | updateOkButton() 48 | } 49 | 50 | private fun persistSelectedSerialsToPreferences() { 51 | projectPreferences.saveSelectedDeviceSerials(myDeviceChooser.selectedDevices.map { it.serialNumber }.toList()) 52 | } 53 | 54 | private fun updateOkButton() { 55 | okAction.isEnabled = selectedDevices.isNotEmpty() 56 | } 57 | 58 | override fun getPreferredFocusedComponent(): JComponent? { 59 | return try { 60 | myDeviceChooser.preferredFocusComponent 61 | } catch (e: NoSuchMethodError) { // that means that we are probably on a preview version of android studio or in intellij 13 62 | Reflect.on(myDeviceChooser).call("getDeviceTable").get() 63 | } 64 | } 65 | 66 | override fun doOKAction() { 67 | myDeviceChooser.finish() 68 | persistSelectedSerialsToPreferences() 69 | super.doOKAction() 70 | } 71 | 72 | override fun getDimensionServiceKey() = javaClass.canonicalName 73 | override fun createCenterPanel(): JComponent = myPanel 74 | 75 | fun useSameDevices() = useSameDeviceSCheckBox.isSelected 76 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/ui/DeviceChooserListener.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.ui 2 | 3 | interface DeviceChooserListener { 4 | fun selectedDevicesChanged() 5 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/ui/ModuleChooserDialogHelper.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.ui 2 | 3 | import com.intellij.ide.util.PropertiesComponent 4 | import com.intellij.openapi.module.Module 5 | import com.intellij.openapi.project.Project 6 | import com.intellij.openapi.roots.ui.configuration.ChooseModulesDialog 7 | import com.intellij.util.ui.UIUtil 8 | import org.jetbrains.android.facet.AndroidFacet 9 | import java.awt.Component 10 | import java.awt.Dimension 11 | import javax.swing.JTable 12 | 13 | object ModuleChooserDialogHelper { 14 | 15 | fun showDialogForFacets(project: Project, facets: List): AndroidFacet? { 16 | val modules = facets.map { it.module } 17 | val previousModuleName = getSavedModuleName(project) 18 | val previousSelectedModule = modules.firstOrNull { it.name == previousModuleName } 19 | 20 | val selectedModule = showDialog(project, modules, previousSelectedModule) ?: return null 21 | saveModuleName(project, selectedModule.name) 22 | return facets[modules.indexOf(selectedModule)] 23 | } 24 | 25 | private fun showDialog(project: Project, modules: List, previousSelectedModule: Module?): Module? { 26 | with(ChooseModulesDialog(project, modules, "Choose Module", "")) { 27 | setSingleSelectionMode() 28 | getSizeForTableContainer(preferredFocusedComponent)?.let { 29 | // Set the height to 0 to allow the dialog to resize itself to fit the content. 30 | setSize(it.width, 0) 31 | } 32 | previousSelectedModule?.let { selectElements(listOf(it)) } 33 | return showAndGetResult().firstOrNull() 34 | } 35 | } 36 | 37 | // Fix an issue where the modules dialog is not wide enough to display the whole module name. 38 | // This code is lifted from com.intellij.openapi.ui.impl.DialogWrapperPeerImpl.MyDialog.getSizeForTableContainer 39 | private fun getSizeForTableContainer(component: Component?): Dimension? { 40 | if (component == null) return null 41 | val tables = UIUtil.uiTraverser(component).filter(JTable::class.java) 42 | if (!tables.isNotEmpty) return null 43 | val size = component.preferredSize 44 | for (table in tables) { 45 | val tableSize = table.preferredSize 46 | size.width = size.width.coerceAtLeast(tableSize.width) 47 | } 48 | size.width = size.width.coerceIn(600, 1000) 49 | return size 50 | } 51 | 52 | private fun saveModuleName(project: Project, moduleName: String) { 53 | PropertiesComponent.getInstance(project).setValue(SELECTED_MODULE_PROPERTY, moduleName) 54 | } 55 | 56 | private fun getSavedModuleName(project: Project): String? { 57 | return PropertiesComponent.getInstance(project).getValue(SELECTED_MODULE_PROPERTY) 58 | } 59 | } 60 | 61 | private val SELECTED_MODULE_PROPERTY = ModuleChooserDialogHelper::class.java.canonicalName + "-SELECTED_MODULE" -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/ui/MyDeviceChooser.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2000-2010 JetBrains s.r.o. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.developerphil.adbidea.ui 17 | 18 | import com.android.ddmlib.AndroidDebugBridge 19 | import com.android.ddmlib.IDevice 20 | import com.android.ddmlib.IDevice.HardwareFeature 21 | import com.android.sdklib.AndroidVersion 22 | import com.android.sdklib.IAndroidTarget 23 | import com.android.tools.idea.model.AndroidModel 24 | import com.android.tools.idea.model.StudioAndroidModuleInfo 25 | import com.android.tools.idea.run.AndroidDevice 26 | import com.android.tools.idea.run.FakeAndroidDevice 27 | import com.android.tools.idea.run.LaunchCompatibility 28 | import com.android.tools.idea.run.LaunchCompatibility.State 29 | import com.developerphil.adbidea.compatibility.BackwardCompatibleGetter 30 | import com.google.common.util.concurrent.ListenableFuture 31 | import com.intellij.openapi.Disposable 32 | import com.intellij.openapi.application.ApplicationManager 33 | import com.intellij.openapi.application.ModalityState 34 | import com.intellij.openapi.util.Condition 35 | import com.intellij.openapi.util.text.StringUtil 36 | import com.intellij.ui.ColoredTableCellRenderer 37 | import com.intellij.ui.DoubleClickListener 38 | import com.intellij.ui.ScrollPaneFactory 39 | import com.intellij.ui.SimpleTextAttributes 40 | import com.intellij.ui.table.JBTable 41 | import com.intellij.util.Alarm 42 | import com.intellij.util.containers.ContainerUtil 43 | import gnu.trove.TIntArrayList 44 | import org.jetbrains.android.dom.manifest.UsesFeature 45 | import org.jetbrains.android.facet.AndroidFacet 46 | import org.jetbrains.android.sdk.AndroidSdkUtils 47 | import org.jetbrains.android.sdk.getInstance 48 | import org.joor.Reflect 49 | import java.awt.Dimension 50 | import java.awt.event.KeyAdapter 51 | import java.awt.event.KeyEvent 52 | import java.awt.event.MouseEvent 53 | import java.util.* 54 | import java.util.concurrent.ExecutionException 55 | import java.util.concurrent.atomic.AtomicReference 56 | import javax.swing.Action 57 | import javax.swing.JComponent 58 | import javax.swing.JTable 59 | import javax.swing.ListSelectionModel 60 | import javax.swing.table.AbstractTableModel 61 | 62 | /** 63 | * @author Eugene.Kudelevsky 64 | * 65 | * https://android.googlesource.com/platform/tools/adt/idea/+/refs/heads/mirror-goog-studio-master-dev/android/src/com/android/tools/idea/run/DeviceChooser.java 66 | */ 67 | class MyDeviceChooser( 68 | multipleSelection: Boolean, 69 | okAction: Action, 70 | private val myFacet: AndroidFacet, 71 | private val myFilter: Condition? 72 | ) : Disposable { 73 | private val myListeners = ContainerUtil.createLockFreeCopyOnWriteList() 74 | private val myRefreshingAlarm: Alarm 75 | private val myBridge: AndroidDebugBridge? 76 | private val myMinSdkVersion: ListenableFuture = 77 | StudioAndroidModuleInfo.getInstance(myFacet).runtimeMinSdkVersion 78 | 79 | private val myProjectTarget: IAndroidTarget = 80 | getInstance(myFacet.module)?.target ?: error("Module [${myFacet.module.name}] already disposed") 81 | 82 | private val androidModuleModel = AndroidModel.get(myFacet) 83 | private val mySupportedAbis = androidModuleModel?.supportedAbis ?: Collections.emptySet() 84 | 85 | @Volatile 86 | private var myProcessSelectionFlag = true 87 | 88 | /** The current list of devices that is displayed in the table. */ 89 | private var myDisplayedDevices = EMPTY_DEVICE_ARRAY 90 | 91 | /** 92 | * The current list of devices obtained from the debug bridge. This is updated in a background thread. 93 | * If it is different than [.myDisplayedDevices], then a [.refreshTable] invocation in the EDT thread 94 | * will update the displayed list to match the detected list. 95 | */ 96 | private val myDetectedDevicesRef = AtomicReference(EMPTY_DEVICE_ARRAY) 97 | private val myPanel: JComponent 98 | private val myDeviceTable = JBTable() 99 | private var mySelectedRows: IntArray? = null 100 | private var hadUserInteraction = false 101 | private var previouslySelectedSerials: Array? = null 102 | private fun setColumnWidth(deviceTable: JBTable, columnIndex: Int, sampleText: String) { 103 | val width = getWidth(deviceTable, sampleText) 104 | deviceTable.columnModel.getColumn(columnIndex).preferredWidth = width 105 | } 106 | 107 | private fun getWidth(deviceTable: JBTable, sampleText: String): Int { 108 | val metrics = deviceTable.getFontMetrics(deviceTable.font) 109 | return metrics.stringWidth(sampleText) 110 | } 111 | 112 | fun init(selectedSerials: Array?) { 113 | previouslySelectedSerials = selectedSerials 114 | updateTable() 115 | addUpdatingRequest() 116 | } 117 | 118 | fun init(selectedSerials: List) { 119 | init(selectedSerials.toTypedArray()) 120 | } 121 | 122 | private fun updatePreviouslySelectedSerials() { 123 | if (previouslySelectedSerials != null && !hadUserInteraction) { 124 | resetSelection(previouslySelectedSerials!!) 125 | } 126 | } 127 | 128 | private val myUpdateRequest = Runnable { 129 | updateTable() 130 | addUpdatingRequest() 131 | } 132 | 133 | private fun addUpdatingRequest() { 134 | if (myRefreshingAlarm.isDisposed) { 135 | return 136 | } 137 | myRefreshingAlarm.cancelAllRequests() 138 | myRefreshingAlarm.addRequest(myUpdateRequest, REFRESH_INTERVAL_MS) 139 | } 140 | 141 | private fun resetSelection(selectedSerials: Array) { 142 | val model = myDeviceTable.model as MyDeviceTableModel 143 | val selectedSerialsSet = mutableSetOf() 144 | Collections.addAll(selectedSerialsSet, *selectedSerials) 145 | val myDevices = model.myDevices 146 | val selectionModel = myDeviceTable.selectionModel 147 | var cleared = false 148 | var i = 0 149 | val n = myDevices.size 150 | while (i < n) { 151 | val serialNumber = myDevices[i].serialNumber 152 | if (selectedSerialsSet.contains(serialNumber)) { 153 | if (!cleared) { 154 | selectionModel.clearSelection() 155 | cleared = true 156 | } 157 | selectionModel.addSelectionInterval(i, i) 158 | } 159 | i++ 160 | } 161 | } 162 | 163 | fun updateTable() { 164 | val devices = myBridge?.let { getFilteredDevices(it) } ?: EMPTY_DEVICE_ARRAY 165 | if (devices.size > 1) { // sort by API level 166 | Arrays.sort(devices, object : Comparator { 167 | override fun compare(device1: IDevice, device2: IDevice): Int { 168 | val apiLevel1 = safeGetApiLevel(device1) 169 | val apiLevel2 = safeGetApiLevel(device2) 170 | return apiLevel2 - apiLevel1 171 | } 172 | 173 | private fun safeGetApiLevel(device: IDevice): Int { 174 | return try { 175 | val s = device.getProperty(IDevice.PROP_BUILD_API_LEVEL) 176 | if (StringUtil.isNotEmpty(s)) s.toInt() else 0 177 | } catch (e: Exception) { 178 | 0 179 | } 180 | } 181 | }) 182 | } 183 | if (!myDisplayedDevices.contentEquals(devices)) { 184 | myDetectedDevicesRef.set(devices) 185 | ApplicationManager.getApplication() 186 | .invokeLater({ refreshTable() }, ModalityState.stateForComponent(myDeviceTable)) 187 | } 188 | } 189 | 190 | private fun refreshTable() { 191 | val devices = myDetectedDevicesRef.get() 192 | myDisplayedDevices = devices 193 | val selectedDevices = selectedDevices 194 | val selectedRows = TIntArrayList() 195 | for (i in devices.indices) { 196 | if (selectedDevices.contains(devices[i])) { 197 | selectedRows.add(i) 198 | } 199 | } 200 | myProcessSelectionFlag = false 201 | myDeviceTable.model = MyDeviceTableModel(devices) 202 | if (selectedRows.size() == 0 && devices.isNotEmpty()) { 203 | myDeviceTable.selectionModel.setSelectionInterval(0, 0) 204 | } 205 | for (selectedRow in selectedRows.toNativeArray()) { 206 | if (selectedRow < devices.size) { 207 | myDeviceTable.selectionModel.addSelectionInterval(selectedRow, selectedRow) 208 | } 209 | } 210 | fireSelectedDevicesChanged() 211 | myProcessSelectionFlag = true 212 | updatePreviouslySelectedSerials() 213 | } 214 | 215 | fun hasDevices(): Boolean { 216 | return myDetectedDevicesRef.get().isNotEmpty() 217 | } 218 | 219 | val preferredFocusComponent: JComponent 220 | get() = myDeviceTable 221 | 222 | val panel: JComponent 223 | get() = myPanel 224 | 225 | val selectedDevices: Array 226 | get() { 227 | val rows = if (mySelectedRows != null) mySelectedRows!! else myDeviceTable.selectedRows 228 | val result = mutableListOf() 229 | for (row in rows) { 230 | if (row >= 0) { 231 | val serial = myDeviceTable.getValueAt(row, SERIAL_COLUMN_INDEX) 232 | val bridge = AndroidSdkUtils.getDebugBridge(myFacet.module.project) ?: return EMPTY_DEVICE_ARRAY 233 | val devices = getFilteredDevices(bridge) 234 | for (device in devices) { 235 | if (device.serialNumber == serial.toString()) { 236 | result.add(device) 237 | break 238 | } 239 | } 240 | } 241 | } 242 | return result.toTypedArray() 243 | } 244 | 245 | private fun getFilteredDevices(bridge: AndroidDebugBridge): Array { 246 | val filteredDevices: MutableList = ArrayList() 247 | for (device in bridge.devices) { 248 | if (myFilter == null || myFilter.value(device)) { 249 | filteredDevices.add(device) 250 | } 251 | } 252 | // Do not filter launching cloud devices as they are just unselectable progress markers 253 | // that are replaced with the actual cloud devices as soon as they are up and the actual cloud devices will be filtered above. 254 | return filteredDevices.toTypedArray() 255 | } 256 | 257 | fun finish() { 258 | mySelectedRows = myDeviceTable.selectedRows 259 | } 260 | 261 | override fun dispose() {} 262 | fun setEnabled(enabled: Boolean) { 263 | myDeviceTable.isEnabled = enabled 264 | } 265 | 266 | fun fireSelectedDevicesChanged() { 267 | for (listener in myListeners) { 268 | listener.selectedDevicesChanged() 269 | } 270 | } 271 | 272 | fun addListener(listener: DeviceChooserListener) { 273 | myListeners.add(listener) 274 | } 275 | 276 | private inner class MyDeviceTableModel(val myDevices: Array) : AbstractTableModel() { 277 | override fun getColumnName(column: Int): String { 278 | return COLUMN_TITLES[column] 279 | } 280 | 281 | override fun getRowCount(): Int { 282 | return myDevices.size 283 | } 284 | 285 | override fun getColumnCount(): Int { 286 | return COLUMN_TITLES.size 287 | } 288 | 289 | override fun getValueAt(rowIndex: Int, columnIndex: Int): Any? { 290 | if (rowIndex >= myDevices.size) { 291 | return null 292 | } 293 | val device = myDevices[rowIndex] 294 | when (columnIndex) { 295 | DEVICE_NAME_COLUMN_INDEX -> return generateDeviceName(device) 296 | SERIAL_COLUMN_INDEX -> return device.serialNumber 297 | DEVICE_STATE_COLUMN_INDEX -> return getDeviceState(device) 298 | COMPATIBILITY_COLUMN_INDEX -> { 299 | val connectedDevice: AndroidDevice = androidDevice(device).get() 300 | return try { 301 | if (myMinSdkVersion.isDone) connectedDevice.canRun( 302 | myMinSdkVersion.get(), 303 | myProjectTarget, 304 | { EnumSet.noneOf(HardwareFeature::class.java) }, 305 | mySupportedAbis 306 | ) else false 307 | } catch (e: InterruptedException) { 308 | false 309 | } catch (e: ExecutionException) { 310 | false 311 | } 312 | } 313 | } 314 | return null 315 | } 316 | 317 | /** 318 | * Remove after 241.18034 319 | */ 320 | private fun androidDevice(device: IDevice) = object : BackwardCompatibleGetter() { 321 | override fun getCurrentImplementation(): AndroidDevice { 322 | return FakeAndroidDevice(device) 323 | } 324 | 325 | override fun getPreviousImplementation(): AndroidDevice { 326 | return Reflect.onClass("com.android.tools.idea.run.ConnectedAndroidDevice").create(device).get() 327 | } 328 | 329 | } 330 | 331 | private fun generateDeviceName(device: IDevice): String { 332 | return device.name 333 | .replace(device.serialNumber, "") 334 | .replace("[-_]".toRegex(), " ") 335 | .replace("[\\[\\]]".toRegex(), "") 336 | } 337 | 338 | override fun getColumnClass(columnIndex: Int): Class<*> { 339 | return when (columnIndex) { 340 | COMPATIBILITY_COLUMN_INDEX -> { 341 | LaunchCompatibility::class.java 342 | } 343 | DEVICE_NAME_COLUMN_INDEX -> { 344 | IDevice::class.java 345 | } 346 | else -> { 347 | String::class.java 348 | } 349 | } 350 | } 351 | 352 | } 353 | 354 | private class LaunchCompatibilityRenderer : ColoredTableCellRenderer() { 355 | override fun customizeCellRenderer( 356 | table: JTable, 357 | value: Any?, 358 | selected: Boolean, 359 | hasFocus: Boolean, 360 | row: Int, 361 | column: Int 362 | ) { 363 | try { 364 | if (value !is LaunchCompatibility) { 365 | return 366 | } 367 | val compatible = value.state 368 | if (compatible == State.OK) { 369 | append("Yes") 370 | } else { 371 | if (compatible == State.ERROR) { 372 | append("No", SimpleTextAttributes.ERROR_ATTRIBUTES) 373 | } else { 374 | append("Maybe") 375 | } 376 | val reason = value.reason 377 | if (reason != null) { 378 | append(", ") 379 | append(reason) 380 | } 381 | } 382 | } catch (e: Error) { 383 | // Expected on Intellij 2021.2. 384 | // Should be removed once the android plugin is upgraded to 7.0 385 | } 386 | } 387 | } 388 | 389 | companion object { 390 | private val COLUMN_TITLES = arrayOf("Device", "Serial Number", "State", "Compatible") 391 | private const val DEVICE_NAME_COLUMN_INDEX = 0 392 | private const val SERIAL_COLUMN_INDEX = 1 393 | private const val DEVICE_STATE_COLUMN_INDEX = 2 394 | private const val COMPATIBILITY_COLUMN_INDEX = 3 395 | private const val REFRESH_INTERVAL_MS = 500 396 | val EMPTY_DEVICE_ARRAY = arrayOf() 397 | private fun getRequiredHardwareFeatures(requiredFeatures: List): EnumSet { // Currently, this method is hardcoded to only search if the list of required features includes a watch. 398 | // We may not want to search the device for every possible feature, but only a small subset of important 399 | // features, starting with hardware type watch.. 400 | for (feature in requiredFeatures) { 401 | val name = feature.name 402 | if (name != null && UsesFeature.HARDWARE_TYPE_WATCH == name.stringValue) { 403 | return EnumSet.of(HardwareFeature.WATCH) 404 | } 405 | } 406 | return EnumSet.noneOf(HardwareFeature::class.java) 407 | } 408 | 409 | private fun getDeviceState(device: IDevice): String { 410 | val state = device.state 411 | return if (state != null) StringUtil.capitalize(state.name.lowercase(Locale.getDefault())) else "" 412 | } 413 | } 414 | 415 | init { 416 | myPanel = ScrollPaneFactory.createScrollPane(myDeviceTable) 417 | myPanel.preferredSize = Dimension(450, 220) 418 | myDeviceTable.model = MyDeviceTableModel(EMPTY_DEVICE_ARRAY) 419 | myDeviceTable.setSelectionMode(if (multipleSelection) ListSelectionModel.MULTIPLE_INTERVAL_SELECTION else ListSelectionModel.SINGLE_SELECTION) 420 | myDeviceTable.selectionModel.addListSelectionListener { 421 | if (myProcessSelectionFlag) { 422 | hadUserInteraction = true 423 | fireSelectedDevicesChanged() 424 | } 425 | } 426 | object : DoubleClickListener() { 427 | override fun onDoubleClick(e: MouseEvent): Boolean { 428 | if (myDeviceTable.isEnabled && okAction.isEnabled) { 429 | okAction.actionPerformed(null) 430 | return true 431 | } 432 | return false 433 | } 434 | }.installOn(myDeviceTable) 435 | myDeviceTable.setDefaultRenderer(LaunchCompatibility::class.java, LaunchCompatibilityRenderer()) 436 | myDeviceTable.addKeyListener(object : KeyAdapter() { 437 | override fun keyPressed(e: KeyEvent) { 438 | if (e.keyCode == KeyEvent.VK_ENTER && okAction.isEnabled) { 439 | okAction.actionPerformed(null) 440 | } 441 | } 442 | }) 443 | setColumnWidth(myDeviceTable, DEVICE_NAME_COLUMN_INDEX, "Samsung Galaxy Nexus Android 4.1 (API 17)") 444 | setColumnWidth(myDeviceTable, SERIAL_COLUMN_INDEX, "0000-0000-00000") 445 | setColumnWidth(myDeviceTable, DEVICE_STATE_COLUMN_INDEX, "offline") 446 | setColumnWidth(myDeviceTable, COMPATIBILITY_COLUMN_INDEX, "yes") 447 | // Do not recreate columns on every model update - this should help maintain the column sizes set above 448 | myDeviceTable.autoCreateColumnsFromModel = false 449 | // Allow sorting by columns (in lexicographic order) 450 | myDeviceTable.autoCreateRowSorter = true 451 | myRefreshingAlarm = Alarm(Alarm.ThreadToUse.POOLED_THREAD, this) 452 | myBridge = AndroidSdkUtils.getDebugBridge(myFacet.module.project) 453 | } 454 | } 455 | -------------------------------------------------------------------------------- /src/main/kotlin/com/developerphil/adbidea/ui/NotificationHelper.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.ui 2 | 3 | import com.intellij.notification.NotificationGroup 4 | import com.intellij.notification.NotificationGroupManager 5 | import com.intellij.notification.NotificationType 6 | 7 | object NotificationHelper { 8 | fun info(message: String) { 9 | sendNotification( 10 | message, 11 | NotificationType.INFORMATION, 12 | NotificationGroupManager 13 | .getInstance() 14 | .getNotificationGroup("ADB Idea (Logging)") 15 | ) 16 | } 17 | 18 | // Function to send an error notification 19 | fun error(message: String) { 20 | sendNotification( 21 | message, 22 | NotificationType.ERROR, 23 | NotificationGroupManager 24 | .getInstance() 25 | .getNotificationGroup("ADB Idea (Errors)") 26 | ) 27 | } 28 | 29 | // Helper function to create and display a notification 30 | private fun sendNotification( 31 | message: String, 32 | notificationType: NotificationType, 33 | notificationGroup: NotificationGroup, 34 | ) { 35 | // Create the notification without a listener 36 | val notification = notificationGroup.createNotification( 37 | "ADB IDEA", 38 | escapeString(message), 39 | notificationType, 40 | ) 41 | 42 | // Display the notification 43 | notification.notify(null) 44 | } 45 | 46 | private fun escapeString(string: String) = string.replace( 47 | "\n".toRegex(), 48 | "\n
" 49 | ) 50 | } -------------------------------------------------------------------------------- /src/main/resources/META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | com.developerphil.adbidea 3 | ADB Idea 4 | Philippe Breault 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 |
    15 |
  • ADB Uninstall App
  • 16 |
  • ADB Kill App
  • 17 |
  • ADB Start App
  • 18 |
  • ADB Restart App
  • 19 |
  • ADB Clear App Data
  • 20 |
  • ADB Clear App Data and Restart
  • 21 |
  • ADB Start App With Debugger
  • 22 |
  • ADB Restart App With Debugger
  • 23 |
  • ADB Grant/Revoke Permissions
  • 24 |
  • ADB Enable/Disable Wi-Fi
  • 25 |
  • ADB Enable/Disable Mobile Data
  • 26 |
27 |
28 | There are two basic ways to invoke a command: 29 |
    30 |
  • Through the Tools->Android->ADB Idea menu
  • 31 |
  • By searching for "ADB" in "Find Actions" (osx: cmd+shift+a, windows/linux: ctrl+shift+a)
  • 32 |
33 | ]]>
34 | 35 | com.intellij.modules.platform 36 | com.intellij.modules.androidstudio 37 | org.jetbrains.android 38 | 39 | 40 | 41 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 55 | 56 | 60 | 61 | 65 | 66 | 70 | 71 | 74 | 77 | 80 | 84 | 88 | 92 | 93 | 97 | 98 | 102 | 103 | 104 | 105 | 109 | 110 | 114 | 115 | 119 | 120 | 124 | 125 | 126 | 127 |
128 | -------------------------------------------------------------------------------- /src/test/kotlin/com/developerphil/adbidea/adb/FakeDevice.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb 2 | 3 | import com.android.ddmlib.* 4 | import java.lang.reflect.Proxy 5 | 6 | data class FakeDevice(private val serialNumber: String) : IDevice by stub() { 7 | override fun getSerialNumber(): String { 8 | return serialNumber 9 | } 10 | } 11 | 12 | inline fun stub(): T = Proxy.newProxyInstance( 13 | T::class.java.classLoader, 14 | arrayOf(T::class.java) 15 | ) { _, _, _ -> throw NotImplementedError() } as T -------------------------------------------------------------------------------- /src/test/kotlin/com/developerphil/adbidea/adb/ShellCommandsFactoryTest.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb 2 | 3 | import com.google.common.truth.Truth.assertThat 4 | import org.junit.Test 5 | 6 | class ShellCommandsFactoryTest { 7 | 8 | @Test 9 | fun startActivityWithoutDebugger() { 10 | 11 | val command = ShellCommandsFactory.startActivity( 12 | packageName = "com.example", 13 | activityName = "com.example.MyActivity", 14 | attachDebugger = false) 15 | 16 | assertThat(command).isEqualTo("am start -n com.example/com.example.MyActivity") 17 | } 18 | 19 | @Test 20 | fun startActivityWithDebugger() { 21 | val command = ShellCommandsFactory.startActivity( 22 | packageName = "com.example", 23 | activityName = "com.example.MyActivity", 24 | attachDebugger = true) 25 | 26 | assertThat(command).isEqualTo("am start -D -n com.example/com.example.MyActivity") 27 | } 28 | } -------------------------------------------------------------------------------- /src/test/kotlin/com/developerphil/adbidea/adb/UseSameDevicesHelperTest.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb 2 | 3 | import com.android.ddmlib.IDevice 4 | import com.developerphil.adbidea.preference.ProjectPreferences 5 | import com.developerphil.adbidea.preference.accessor.InMemoryPreferenceAccessor 6 | import com.google.common.truth.Truth.assertThat 7 | import org.junit.Test 8 | 9 | class UseSameDevicesHelperTest { 10 | 11 | val pluginPrefs = ProjectPreferences(InMemoryPreferenceAccessor()) 12 | val bridge = FakeBridge() 13 | val helper: UseSameDevicesHelper = UseSameDevicesHelper(pluginPrefs, bridge) 14 | 15 | @Test 16 | fun onFirstRun_shouldNotTryToReturnDevices() { 17 | assertThat(helper.getRememberedDevices()).isEmpty() 18 | } 19 | 20 | @Test 21 | fun whenAskingToRememberDevices_shouldReturnDevicesInSharedPrefs() { 22 | bridge.willReturn("1", "2", "3", "4") 23 | pluginPrefs.willReturn("1", "2") 24 | 25 | helper.rememberDevices() 26 | assertRememberedDevices("1", "2") 27 | } 28 | 29 | @Test 30 | fun whenTheConnectedDevicesChanges_shouldNotUseSameDevice() { 31 | bridge.willReturn("1", "2", "3") 32 | pluginPrefs.willReturn("1", "2") 33 | 34 | helper.rememberDevices() 35 | assertRememberedDevices("1", "2") 36 | 37 | bridge.willReturn("1", "2") 38 | assertNoRememberedDevices() 39 | } 40 | 41 | @Test 42 | fun whenSharedPrefsAreEmpty_shouldNotUseSameDevice() { 43 | bridge.willReturn("1", "2", "3") 44 | 45 | helper.rememberDevices() 46 | assertNoRememberedDevices() 47 | } 48 | 49 | @Test 50 | fun whenSharedPrefsAndHelperAreNotSynced_shouldNotUseSameDevice() { 51 | bridge.willReturn("1", "2", "3", "4") 52 | pluginPrefs.willReturn("2", "4") 53 | 54 | helper.rememberDevices() 55 | 56 | assertRememberedDevices("2", "4") 57 | 58 | pluginPrefs.willReturn("2", "id_of_device_not_connected_right_now") 59 | assertNoRememberedDevices() 60 | } 61 | 62 | fun assertNoRememberedDevices() { 63 | assertThat(helper.getRememberedDevices()).isEmpty() 64 | } 65 | 66 | fun assertRememberedDevices(vararg ids: String) { 67 | assertThat(helper.getRememberedDevices()).isEqualTo(ids.map(::FakeDevice).toList()) 68 | } 69 | 70 | class FakeBridge : Bridge { 71 | var ready = true 72 | var devices: List = emptyList() 73 | 74 | override fun isReady(): Boolean { 75 | return ready 76 | } 77 | 78 | override fun connectedDevices(): List { 79 | return devices 80 | } 81 | 82 | fun willReturn(vararg ids: String) { 83 | devices = ids.map(::FakeDevice) 84 | } 85 | } 86 | 87 | private fun ProjectPreferences.willReturn(vararg ids: String) = saveSelectedDeviceSerials(ids.asList()) 88 | } -------------------------------------------------------------------------------- /src/test/kotlin/com/developerphil/adbidea/adb/command/StartDefaultActivityCommandTest.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb.command 2 | 3 | import com.developerphil.adbidea.adb.command.StartDefaultActivityCommand.StartActivityReceiver 4 | import com.google.common.truth.Truth.assertThat 5 | import org.junit.Test 6 | 7 | class StartDefaultActivityCommandTest { 8 | 9 | @Test 10 | fun testReceiverSuccess() { 11 | with(StartActivityReceiver()) { 12 | assertThat(isSuccess).isFalse() 13 | processNewLines(arrayOf( 14 | "Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.untitled/.MyActivity }" 15 | )) 16 | processNewLines(TRAILING_EMPTY_LINE) 17 | assertThat(isSuccess).isTrue() 18 | } 19 | } 20 | 21 | @Test 22 | fun testIsSuccessWhenAppIsAlreadyStarted() { 23 | with(StartActivityReceiver()) { 24 | processNewLines(arrayOf( 25 | "Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.untitled/.MyActivity }", 26 | "Warning: Activity not started, its current task has been brought to the front" 27 | )) 28 | processNewLines(TRAILING_EMPTY_LINE) 29 | assertThat(isSuccess).isTrue() 30 | } 31 | } 32 | 33 | @Test 34 | fun testIsFailureWhenAppIsUninstalled() { 35 | with(StartActivityReceiver()) { 36 | processNewLines(arrayOf( 37 | "Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.cxategory.LAUNCHER] cmp=com.example.untitled/.MyActivity }", 38 | "Error type 3", 39 | "Error: Activity class {com.example.untitled/com.example.untitled.MyActivity} does not exist." 40 | )) 41 | processNewLines(TRAILING_EMPTY_LINE) 42 | assertThat(isSuccess).isFalse() 43 | assertThat(message).isEqualTo( 44 | "Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.cxategory.LAUNCHER] cmp=com.example.untitled/.MyActivity }\n" + 45 | "Error type 3\n" + 46 | "Error: Activity class {com.example.untitled/com.example.untitled.MyActivity} does not exist." 47 | ) 48 | } 49 | } 50 | } 51 | 52 | private val TRAILING_EMPTY_LINE = arrayOf("") 53 | -------------------------------------------------------------------------------- /src/test/kotlin/com/developerphil/adbidea/adb/command/receiver/GenericReceiverTest.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.adb.command.receiver 2 | 3 | import com.google.common.truth.Truth.assertThat 4 | import org.junit.Test 5 | 6 | class GenericReceiverTest { 7 | @Test 8 | fun testReceiverRecordsAdbOutput() { 9 | val receiver = GenericReceiver() 10 | assertThat(receiver.adbOutputLines).isEmpty() 11 | 12 | receiver.processNewLines(arrayOf("1", "2", "3")) 13 | assertThat(receiver.adbOutputLines).containsExactly("1", "2", "3") 14 | 15 | receiver.processNewLines(arrayOf("4")) 16 | assertThat(receiver.adbOutputLines).containsExactly("1", "2", "3", "4") 17 | } 18 | } -------------------------------------------------------------------------------- /src/test/kotlin/com/developerphil/adbidea/compatibility/BackwardCompatibleGetterTest.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.compatibility 2 | 3 | import com.google.common.truth.Truth.assertThat 4 | import org.joor.ReflectException 5 | import org.junit.Assert.fail 6 | import org.junit.Test 7 | 8 | class BackwardCompatibleGetterTest { 9 | @Test 10 | fun onlyCallCurrentImplementationWhenItIsValid() { 11 | var value = false 12 | object : BackwardCompatibleGetter() { 13 | override fun getCurrentImplementation(): Boolean { 14 | value = true 15 | return true 16 | } 17 | 18 | override fun getPreviousImplementation(): Boolean { 19 | fail("should not be called") 20 | return true 21 | } 22 | }.get() 23 | assertThat(value).isTrue() 24 | } 25 | 26 | @Test 27 | fun callPreviousImplementationWhenCurrentThrowsErrors() { 28 | expectPreviousImplementationIsCalledFor(ClassNotFoundException()) 29 | expectPreviousImplementationIsCalledFor(NoSuchMethodException()) 30 | expectPreviousImplementationIsCalledFor(NoSuchFieldException()) 31 | expectPreviousImplementationIsCalledFor(LinkageError()) 32 | expectPreviousImplementationIsCalledFor(ReflectException()) 33 | } 34 | 35 | @Test(expected = RuntimeException::class) 36 | fun throwExceptionsWhenTheyAreNotRelatedToBackwardCompatibility() { 37 | object : BackwardCompatibleGetter() { 38 | override fun getCurrentImplementation(): Boolean { 39 | throw RuntimeException("exception!") 40 | } 41 | 42 | override fun getPreviousImplementation(): Boolean { 43 | fail("should not be called") 44 | return false 45 | } 46 | }.get() 47 | } 48 | 49 | private fun expectPreviousImplementationIsCalledFor(throwable: Throwable) { 50 | var value = false 51 | object : BackwardCompatibleGetter() { 52 | override fun getCurrentImplementation(): Boolean { 53 | throw throwable 54 | } 55 | 56 | override fun getPreviousImplementation(): Boolean { 57 | value = true 58 | return true 59 | } 60 | }.get() 61 | 62 | assertThat(value).isTrue() 63 | } 64 | } -------------------------------------------------------------------------------- /src/test/kotlin/com/developerphil/adbidea/preference/ApplicationPreferencesTests.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.preference 2 | 3 | import com.developerphil.adbidea.preference.accessor.InMemoryPreferenceAccessor 4 | import com.google.common.truth.Truth.assertThat 5 | import com.intellij.util.text.SemVer 6 | import org.junit.Test 7 | import java.util.* 8 | 9 | class ApplicationPreferencesTests { 10 | 11 | private val prefAccessor = InMemoryPreferenceAccessor() 12 | private val prefs: ApplicationPreferences = ApplicationPreferences(prefAccessor) 13 | 14 | @Test 15 | fun `If no previous version is saved, return an empty optional`() { 16 | assertThat(prefs.getPreviousPluginVersion()).isEqualTo(Optional.empty()) 17 | } 18 | 19 | @Test 20 | fun `If a previous version is saved, return it`() { 21 | verifySaveAndRetrieveVersion("0.0.0") 22 | verifySaveAndRetrieveVersion("1.2.3") 23 | verifySaveAndRetrieveVersion("1.5.4") 24 | verifySaveAndRetrieveVersion("1.6.0-SNAPSHOT") 25 | } 26 | 27 | private fun verifySaveAndRetrieveVersion(version: String) { 28 | prefAccessor.clear() 29 | val semVer = SemVer.parseFromText(version)!! 30 | prefs.savePreviousPluginVersion(semVer) 31 | assertThat(prefs.getPreviousPluginVersion()).isEqualTo(Optional.of(semVer)) 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /src/test/kotlin/com/developerphil/adbidea/preference/ProjectPreferencesTests.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.preference 2 | 3 | import com.developerphil.adbidea.preference.accessor.InMemoryPreferenceAccessor 4 | import com.google.common.truth.Truth.assertThat 5 | import org.junit.Test 6 | 7 | class ProjectPreferencesTests { 8 | 9 | private val prefAccessor = InMemoryPreferenceAccessor() 10 | private val prefs: ProjectPreferences = ProjectPreferences(prefAccessor) 11 | 12 | @Test 13 | fun `Can save a single selected device`() { 14 | val serials = listOf("first") 15 | prefs.saveSelectedDeviceSerials(serials) 16 | assertThat(prefs.getSelectedDeviceSerials()).isEqualTo(serials) 17 | } 18 | 19 | @Test 20 | fun `Can save multiple selected devices`() { 21 | val serials = listOf("first", "second", "third") 22 | prefs.saveSelectedDeviceSerials(serials) 23 | assertThat(prefs.getSelectedDeviceSerials()).isEqualTo(serials) 24 | } 25 | 26 | @Test 27 | fun `Can save an empty selected devices list`() { 28 | val serials = emptyList() 29 | prefs.saveSelectedDeviceSerials(serials) 30 | assertThat(prefs.getSelectedDeviceSerials()).isEqualTo(serials) 31 | } 32 | 33 | @Test 34 | fun `When no selected serials are saved, return an empty list`() { 35 | assertThat(prefs.getSelectedDeviceSerials()).isEqualTo(emptyList()) 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /src/test/kotlin/com/developerphil/adbidea/preference/accessor/InMemoryPreferenceAccessor.kt: -------------------------------------------------------------------------------- 1 | package com.developerphil.adbidea.preference.accessor 2 | 3 | class InMemoryPreferenceAccessor : PreferenceAccessor { 4 | private val prefs = mutableMapOf() 5 | 6 | override fun saveString(key: String, value: String) { 7 | prefs[key] = value 8 | } 9 | 10 | override fun getString(key: String, defaultValue: String): String { 11 | return prefs.getOrDefault(key, defaultValue) 12 | } 13 | 14 | fun clear() = prefs.clear() 15 | } -------------------------------------------------------------------------------- /website/adb_operations_popup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pbreault/adb-idea/58dd4e481cb0e0948589f76f751a3389b9721346/website/adb_operations_popup.png -------------------------------------------------------------------------------- /website/debug_howto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pbreault/adb-idea/58dd4e481cb0e0948589f76f751a3389b9721346/website/debug_howto.png -------------------------------------------------------------------------------- /website/find_actions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pbreault/adb-idea/58dd4e481cb0e0948589f76f751a3389b9721346/website/find_actions.png --------------------------------------------------------------------------------