Skip to content
Closed
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
12 changes: 12 additions & 0 deletions src/main/java/com/developerphil/adbidea/action/InternetOff.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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 InternetOff extends AdbAction {

public void actionPerformed(AnActionEvent e, Project project) {
AdbFacade.toggleInternet(project,false);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/developerphil/adbidea/action/InternetOn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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 InternetOn extends AdbAction {

public void actionPerformed(AnActionEvent e, Project project) {
AdbFacade.toggleInternet(project,true);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/developerphil/adbidea/action/PressPower.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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 PressPower extends AdbAction {

public void actionPerformed(AnActionEvent e, Project project) {
AdbFacade.pressPower(project);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ protected void fillActions(@Nullable final Project project,
addAction("com.developerphil.adbidea.action.ClearDataAction", group);
addAction("com.developerphil.adbidea.action.ClearDataAndRestartAction", group);
addAction("com.developerphil.adbidea.action.RevokePermissionsAction", group);
addAction("com.developerphil.adbidea.action.PressPower", group);
addAction("com.developerphil.adbidea.action.InternetOff", group);
addAction("com.developerphil.adbidea.action.InternetOn", group);


if (isDebuggingAvailable()) {
group.addSeparator();
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/developerphil/adbidea/adb/AdbFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ public static void clearDataAndRestart(Project project) {
executeOnDevice(project, new ClearDataAndRestartCommand());
}

public static void pressPower(Project project) {
executeOnDevice(project, new PressPowerCommand());
}

public static void toggleInternet(Project project,boolean toggle) {
executeOnDevice(project, new ToggleInternet(toggle));

}

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,16 @@
package com.developerphil.adbidea.adb.command;

import com.android.ddmlib.IDevice;
import com.intellij.openapi.project.Project;
import org.jetbrains.android.facet.AndroidFacet;

/**
* Created by fmatos on 1/05/2016.
*/
public class PressPowerCommand extends ShellCommand {
@Override
public String getCommandLine() {
return getEvent("26");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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.*;

/**
* Created by fmatos on 1/05/2016.
*/
public abstract class ShellCommand implements Command {

@Override
public boolean run(Project project, IDevice device, AndroidFacet facet, String packageName) {

GenericReceiver receiver = new GenericReceiver();

try {
if (isAppInstalled(device, packageName)) {
String commandLine = getCommandLine();
device.executeShellCommand(commandLine, receiver, 15L, TimeUnit.SECONDS);
info(String.format("<b>%s</b> %s --> %s", packageName, device.getName(),commandLine));

if ( ! receiver.isSuccess() ) {
error("Shell error " + receiver.getAdbOutputLines());
return false;
}
return true;
} else {
error(String.format("<b>%s</b> is not installed on %s", packageName, device.getName()));
}
} catch (Exception e1) {
error("Custom message 2... " + e1.getMessage());
}
return false;
}


public String getEvent(String event) {
return " input keyevent " + event;
}

public abstract String getCommandLine();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.developerphil.adbidea.adb.command;

/**
* Created by fmatos on 1/05/2016.
*/
public class ToggleInternet extends ShellCommand {

private final boolean turnOn;


public ToggleInternet(boolean turnOn) {
this.turnOn = turnOn;
}

@Override
public String getCommandLine() {

return "svc data " + (turnOn ? "enable" : "disable");
}
}
16 changes: 16 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,22 @@
text="ADB Restart App With Debugger"
description="Restarts the current application and attach the debugger">
</action>
<action id="com.developerphil.adbidea.action.PressPower"
class="com.developerphil.adbidea.action.PressPower"
text="ADB Press Power"
description="Presses power button to light up screen (not effective with emulators)">
</action>
<action id="com.developerphil.adbidea.action.InternetOff"
class="com.developerphil.adbidea.action.InternetOff"
text="ADB Turns off internet"
description="Turns off all internet (not effective with some devices)">
</action>
<action id="com.developerphil.adbidea.action.InternetOn"
class="com.developerphil.adbidea.action.InternetOn"
text="ADB Turns on internet"
description="Turns on all internet (not effective with some devices)">
</action>

<add-to-group group-id="AndroidToolsGroup" anchor="first"/>
</group>
</actions>
Expand Down