From 96dce200756bc5ca742f235b55323e9cb4d12c70 Mon Sep 17 00:00:00 2001 From: yosi Date: Thu, 16 Aug 2018 13:27:24 +0300 Subject: [PATCH 1/2] added actions for helping using battery idle state and charging --- build.gradle | 3 +- gradle.properties.change_me | 15 -- .../adbidea/action/DeviceIdleStepAction.java | 13 ++ .../action/ResetBatteryChargingAction.java | 13 ++ .../action/UnplugBatteryChargingAction.java | 13 ++ .../developerphil/adbidea/adb/AdbFacade.java | 28 +++- .../adb/command/DeviceIdleStepCommand.java | 33 +++++ .../command/ResetBatteryChargingCommand.java | 31 ++++ .../adb/command/UnplugBatteryCharging.java | 31 ++++ src/main/resources/META-INF/plugin.xml | 140 +++++++++--------- 10 files changed, 237 insertions(+), 83 deletions(-) delete mode 100644 gradle.properties.change_me create mode 100644 src/main/java/com/developerphil/adbidea/action/DeviceIdleStepAction.java create mode 100644 src/main/java/com/developerphil/adbidea/action/ResetBatteryChargingAction.java create mode 100644 src/main/java/com/developerphil/adbidea/action/UnplugBatteryChargingAction.java create mode 100644 src/main/java/com/developerphil/adbidea/adb/command/DeviceIdleStepCommand.java create mode 100644 src/main/java/com/developerphil/adbidea/adb/command/ResetBatteryChargingCommand.java create mode 100644 src/main/java/com/developerphil/adbidea/adb/command/UnplugBatteryCharging.java diff --git a/build.gradle b/build.gradle index f36fa68c..d9ba4d2d 100644 --- a/build.gradle +++ b/build.gradle @@ -60,6 +60,7 @@ dependencies { compileOnly fileTree(dir: "$StudioCompilePath/plugins/android/lib", include: ['*.jar']) compileOnly fileTree(dir: "$StudioCompilePath/lib", include: ['*.jar']) compile 'com.google.dagger:dagger:2.6' + kapt "com.google.dagger:dagger-compiler:2.6" testCompile 'junit:junit:4.12' @@ -68,7 +69,6 @@ dependencies { testCompile "org.mockito:mockito-core:1.+" testCompile "com.google.truth:truth:0.30" - } task(verifySetup) { @@ -81,4 +81,5 @@ task(verifySetup) { } + compileJava.dependsOn verifySetup diff --git a/gradle.properties.change_me b/gradle.properties.change_me deleted file mode 100644 index 91c5847a..00000000 --- a/gradle.properties.change_me +++ /dev/null @@ -1,15 +0,0 @@ -# Copy this file as gradle.properties -# It will be used for both compiling and running the adb-idea plugin. - - -# Path to a downloaded instance of Android Studio -# This is used to add the android plugin dependencies to the project. -# must point to the latest version of Android Studio. -# You'll know it's right if you can find "$StudioCompilePath/lib/idea.jar" -StudioCompilePath=/Applications/Android Studio.app/Contents - - -# Determines which IDE to run when using the "./gradlew runIdea" command. -# This is useful to test the plugin on older versions of Android Studio or Intellij -# Default value: $StudioCompilePath -#StudioRunPath=/Applications/Android Studio.app/Contents \ No newline at end of file diff --git a/src/main/java/com/developerphil/adbidea/action/DeviceIdleStepAction.java b/src/main/java/com/developerphil/adbidea/action/DeviceIdleStepAction.java new file mode 100644 index 00000000..4c41b921 --- /dev/null +++ b/src/main/java/com/developerphil/adbidea/action/DeviceIdleStepAction.java @@ -0,0 +1,13 @@ +package com.developerphil.adbidea.action; + +import com.developerphil.adbidea.adb.AdbFacade; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.Project; + +public class DeviceIdleStepAction extends AdbAction { + + public void actionPerformed(AnActionEvent e, Project project) { + AdbFacade.deviceIdleStep(project); + } + +} diff --git a/src/main/java/com/developerphil/adbidea/action/ResetBatteryChargingAction.java b/src/main/java/com/developerphil/adbidea/action/ResetBatteryChargingAction.java new file mode 100644 index 00000000..f5cc7e2f --- /dev/null +++ b/src/main/java/com/developerphil/adbidea/action/ResetBatteryChargingAction.java @@ -0,0 +1,13 @@ +package com.developerphil.adbidea.action; + +import com.developerphil.adbidea.adb.AdbFacade; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.Project; + +public class ResetBatteryChargingAction extends AdbAction { + + public void actionPerformed(AnActionEvent e, Project project) { + AdbFacade.resetBatteryCharging(project); + } + +} diff --git a/src/main/java/com/developerphil/adbidea/action/UnplugBatteryChargingAction.java b/src/main/java/com/developerphil/adbidea/action/UnplugBatteryChargingAction.java new file mode 100644 index 00000000..08d9b3da --- /dev/null +++ b/src/main/java/com/developerphil/adbidea/action/UnplugBatteryChargingAction.java @@ -0,0 +1,13 @@ +package com.developerphil.adbidea.action; + +import com.developerphil.adbidea.adb.AdbFacade; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.Project; + +public class UnplugBatteryChargingAction extends AdbAction { + + public void actionPerformed(AnActionEvent e, Project project) { + AdbFacade.unplugBatteryCharging(project); + } + +} diff --git a/src/main/java/com/developerphil/adbidea/adb/AdbFacade.java b/src/main/java/com/developerphil/adbidea/adb/AdbFacade.java index 9ab35b04..7f473f07 100644 --- a/src/main/java/com/developerphil/adbidea/adb/AdbFacade.java +++ b/src/main/java/com/developerphil/adbidea/adb/AdbFacade.java @@ -2,7 +2,20 @@ import com.android.ddmlib.IDevice; import com.developerphil.adbidea.ObjectGraph; -import com.developerphil.adbidea.adb.command.*; +import com.developerphil.adbidea.adb.command.ClearDataAndRestartCommand; +import com.developerphil.adbidea.adb.command.ClearDataCommand; +import com.developerphil.adbidea.adb.command.Command; +import com.developerphil.adbidea.adb.command.CommandList; +import com.developerphil.adbidea.adb.command.DeviceIdleStepCommand; +import com.developerphil.adbidea.adb.command.GrantPermissionsCommand; +import com.developerphil.adbidea.adb.command.KillCommand; +import com.developerphil.adbidea.adb.command.ResetBatteryChargingCommand; +import com.developerphil.adbidea.adb.command.RestartPackageCommand; +import com.developerphil.adbidea.adb.command.RevokePermissionsAndRestartCommand; +import com.developerphil.adbidea.adb.command.RevokePermissionsCommand; +import com.developerphil.adbidea.adb.command.StartDefaultActivityCommand; +import com.developerphil.adbidea.adb.command.UninstallCommand; +import com.developerphil.adbidea.adb.command.UnplugBatteryCharging; import com.developerphil.adbidea.ui.NotificationHelper; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.intellij.openapi.project.Project; @@ -61,6 +74,19 @@ public static void clearDataAndRestart(Project project) { executeOnDevice(project, new ClearDataAndRestartCommand()); } + public static void unplugBatteryCharging(Project project) { + executeOnDevice(project, new UnplugBatteryCharging()); + } + + public static void resetBatteryCharging(Project project) { + executeOnDevice(project, new ResetBatteryChargingCommand()); + } + + public static void deviceIdleStep(Project project) { + executeOnDevice(project, new DeviceIdleStepCommand()); + } + + private static void executeOnDevice(final Project project, final Command runnable) { if (isGradleSyncInProgress(project)) { diff --git a/src/main/java/com/developerphil/adbidea/adb/command/DeviceIdleStepCommand.java b/src/main/java/com/developerphil/adbidea/adb/command/DeviceIdleStepCommand.java new file mode 100644 index 00000000..6b0e4200 --- /dev/null +++ b/src/main/java/com/developerphil/adbidea/adb/command/DeviceIdleStepCommand.java @@ -0,0 +1,33 @@ +package com.developerphil.adbidea.adb.command; + +import com.android.ddmlib.IDevice; +import com.developerphil.adbidea.adb.command.receiver.GenericReceiver; +import com.intellij.openapi.project.Project; + +import org.jetbrains.android.facet.AndroidFacet; + +import java.util.concurrent.TimeUnit; + +import static com.developerphil.adbidea.adb.AdbUtil.isAppInstalled; +import static com.developerphil.adbidea.ui.NotificationHelper.error; +import static com.developerphil.adbidea.ui.NotificationHelper.info; + +public class DeviceIdleStepCommand implements Command { + @Override + public boolean run(Project project, IDevice device, AndroidFacet facet, String packageName) { + try { + if (isAppInstalled(device, packageName)) { + GenericReceiver receiver = new GenericReceiver(); + device.executeShellCommand("dumpsys deviceidle step", receiver, 15L, TimeUnit.SECONDS); + receiver.getAdbOutputLines().stream().filter(s -> s.toLowerCase().contains("stepped")).forEach(s -> + info(String.format(s, packageName, device.getName()))); + return true; + } else { + error(String.format("%s is not installed on %s", packageName, device.getName())); + } + } catch (Exception e1) { + error("dumpsys deviceidle step... " + e1.getMessage()); + } + return false; + } +} diff --git a/src/main/java/com/developerphil/adbidea/adb/command/ResetBatteryChargingCommand.java b/src/main/java/com/developerphil/adbidea/adb/command/ResetBatteryChargingCommand.java new file mode 100644 index 00000000..9725089b --- /dev/null +++ b/src/main/java/com/developerphil/adbidea/adb/command/ResetBatteryChargingCommand.java @@ -0,0 +1,31 @@ +package com.developerphil.adbidea.adb.command; + +import com.android.ddmlib.IDevice; +import com.developerphil.adbidea.adb.command.receiver.GenericReceiver; +import com.intellij.openapi.project.Project; + +import org.jetbrains.android.facet.AndroidFacet; + +import java.util.concurrent.TimeUnit; + +import static com.developerphil.adbidea.adb.AdbUtil.isAppInstalled; +import static com.developerphil.adbidea.ui.NotificationHelper.error; +import static com.developerphil.adbidea.ui.NotificationHelper.info; + +public class ResetBatteryChargingCommand implements Command { + @Override + public boolean run(Project project, IDevice device, AndroidFacet facet, String packageName) { + try { + if (isAppInstalled(device, packageName)) { + device.executeShellCommand("dumpsys battery reset", new GenericReceiver(), 15L, TimeUnit.SECONDS); + info(String.format("Reset battery charging on %s", device.getName())); + return true; + } else { + error(String.format("%s is not installed on %s", packageName, device.getName())); + } + } catch (Exception e1) { + error("dumpsys battery reset... " + e1.getMessage()); + } + return false; + } +} diff --git a/src/main/java/com/developerphil/adbidea/adb/command/UnplugBatteryCharging.java b/src/main/java/com/developerphil/adbidea/adb/command/UnplugBatteryCharging.java new file mode 100644 index 00000000..d2245051 --- /dev/null +++ b/src/main/java/com/developerphil/adbidea/adb/command/UnplugBatteryCharging.java @@ -0,0 +1,31 @@ +package com.developerphil.adbidea.adb.command; + +import com.android.ddmlib.IDevice; +import com.developerphil.adbidea.adb.command.receiver.GenericReceiver; +import com.intellij.openapi.project.Project; + +import org.jetbrains.android.facet.AndroidFacet; + +import java.util.concurrent.TimeUnit; + +import static com.developerphil.adbidea.adb.AdbUtil.isAppInstalled; +import static com.developerphil.adbidea.ui.NotificationHelper.error; +import static com.developerphil.adbidea.ui.NotificationHelper.info; + +public class UnplugBatteryCharging implements Command { + @Override + public boolean run(Project project, IDevice device, AndroidFacet facet, String packageName) { + try { + if (isAppInstalled(device, packageName)) { + device.executeShellCommand("dumpsys battery unplug", new GenericReceiver(), 15L, TimeUnit.SECONDS); + info(String.format("Unplugging battery charging. on %s", packageName, device.getName())); + return true; + } else { + error(String.format("%s is not installed on %s", packageName, device.getName())); + } + } catch (Exception e1) { + error("dumpsys battery unplug... " + e1.getMessage()); + } + return false; + } +} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index bd5b1fcf..c2d1088b 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -1,7 +1,7 @@ com.developerphil.adbidea ADB Idea - 1.5.2 + 1.5.3 Philippe Breault - + com.intellij.modules.platform org.jetbrains.android - - - - - + + + + + - + - - + - - + - - + - - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + From 538d87c4dfeda04b8030c8c66da9354321b851ad Mon Sep 17 00:00:00 2001 From: yosi Date: Thu, 16 Aug 2018 13:45:30 +0300 Subject: [PATCH 2/2] added release notes --- src/main/resources/META-INF/plugin.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index c2d1088b..aacd3cfb 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -16,6 +16,9 @@
  • ADB Revoke Permissions
  • ADB Start App With Debugger
  • ADB Restart App With Debugger
  • +
  • Battery Unplug Battery Charging
  • +
  • Battery Reset Battery Charging
  • +
  • Battery Step into idle state

  • There are two basic ways to invoke a command: @@ -27,6 +30,10 @@ 1.5.3 +
      +
    • FEATURE: Added Battery and idle state commands
    • +
    1.5.2
    • BUGFIX: Show the name of the devices in addition to the serial number when multiple devices are connected