Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added actions for helping using battery idle state and charging #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -68,7 +69,6 @@ dependencies {
testCompile "org.mockito:mockito-core:1.+"
testCompile "com.google.truth:truth:0.30"


}

task(verifySetup) {
Expand All @@ -81,4 +81,5 @@ task(verifySetup) {
}



compileJava.dependsOn verifySetup
15 changes: 0 additions & 15 deletions gradle.properties.change_me

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
28 changes: 27 additions & 1 deletion src/main/java/com/developerphil/adbidea/adb/AdbFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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("<b>%s</b> is not installed on %s", packageName, device.getName()));
}
} catch (Exception e1) {
error("dumpsys deviceidle step... " + e1.getMessage());
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -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("<b>%s</b> is not installed on %s", packageName, device.getName()));
}
} catch (Exception e1) {
error("dumpsys battery reset... " + e1.getMessage());
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -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("<b>%s</b> is not installed on %s", packageName, device.getName()));
}
} catch (Exception e1) {
error("dumpsys battery unplug... " + e1.getMessage());
}
return false;
}
}
Loading