Skip to content

Commit 42aa15d

Browse files
Fabio Goncalvesfmatosqg
authored andcommitted
Adding network toggle command + power button command
1 parent 25c669d commit 42aa15d

File tree

9 files changed

+150
-0
lines changed

9 files changed

+150
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
public class InternetOff extends AdbAction {
8+
9+
public void actionPerformed(AnActionEvent e, Project project) {
10+
AdbFacade.toggleInternet(project,false);
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
public class InternetOn extends AdbAction {
8+
9+
public void actionPerformed(AnActionEvent e, Project project) {
10+
AdbFacade.toggleInternet(project,true);
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
public class PressPower extends AdbAction {
8+
9+
public void actionPerformed(AnActionEvent e, Project project) {
10+
AdbFacade.pressPower(project);
11+
}
12+
}

src/main/java/com/developerphil/adbidea/action/QuickListAction.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ protected void fillActions(@Nullable final Project project,
2525
addAction("com.developerphil.adbidea.action.ClearDataAction", group);
2626
addAction("com.developerphil.adbidea.action.ClearDataAndRestartAction", group);
2727
addAction("com.developerphil.adbidea.action.RevokePermissionsAction", group);
28+
addAction("com.developerphil.adbidea.action.PressPower", group);
29+
addAction("com.developerphil.adbidea.action.InternetOff", group);
30+
addAction("com.developerphil.adbidea.action.InternetOn", group);
31+
2832

2933
if (isDebuggingAvailable()) {
3034
group.addSeparator();

src/main/java/com/developerphil/adbidea/adb/AdbFacade.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ public static void clearDataAndRestart(Project project) {
6161
executeOnDevice(project, new ClearDataAndRestartCommand());
6262
}
6363

64+
public static void pressPower(Project project) {
65+
executeOnDevice(project, new PressPowerCommand());
66+
}
67+
68+
public static void toggleInternet(Project project,boolean toggle) {
69+
executeOnDevice(project, new ToggleInternet(toggle));
70+
71+
}
72+
6473
private static void executeOnDevice(final Project project, final Command runnable) {
6574

6675
if (isGradleSyncInProgress(project)) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.developerphil.adbidea.adb.command;
2+
3+
import com.android.ddmlib.IDevice;
4+
import com.intellij.openapi.project.Project;
5+
import org.jetbrains.android.facet.AndroidFacet;
6+
7+
/**
8+
* Created by fmatos on 1/05/2016.
9+
*/
10+
public class PressPowerCommand extends ShellCommand {
11+
@Override
12+
public String getCommandLine() {
13+
return getEvent("26");
14+
}
15+
16+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.developerphil.adbidea.adb.command;
2+
3+
import com.android.ddmlib.IDevice;
4+
import com.developerphil.adbidea.adb.command.receiver.GenericReceiver;
5+
import com.intellij.openapi.project.Project;
6+
import org.jetbrains.android.facet.AndroidFacet;
7+
8+
import java.util.concurrent.TimeUnit;
9+
10+
import static com.developerphil.adbidea.adb.AdbUtil.isAppInstalled;
11+
import static com.developerphil.adbidea.ui.NotificationHelper.*;
12+
13+
/**
14+
* Created by fmatos on 1/05/2016.
15+
*/
16+
public abstract class ShellCommand implements Command {
17+
18+
@Override
19+
public boolean run(Project project, IDevice device, AndroidFacet facet, String packageName) {
20+
21+
GenericReceiver receiver = new GenericReceiver();
22+
23+
try {
24+
if (isAppInstalled(device, packageName)) {
25+
String commandLine = getCommandLine();
26+
device.executeShellCommand(commandLine, receiver, 15L, TimeUnit.SECONDS);
27+
info(String.format("<b>%s</b> %s --> %s", packageName, device.getName(),commandLine));
28+
29+
if ( ! receiver.isSuccess() ) {
30+
error("Shell error " + receiver.getAdbOutputLines());
31+
return false;
32+
}
33+
return true;
34+
} else {
35+
error(String.format("<b>%s</b> is not installed on %s", packageName, device.getName()));
36+
}
37+
} catch (Exception e1) {
38+
error("Custom message 2... " + e1.getMessage());
39+
}
40+
return false;
41+
}
42+
43+
44+
public String getEvent(String event) {
45+
return " input keyevent " + event;
46+
}
47+
48+
public abstract String getCommandLine();
49+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.developerphil.adbidea.adb.command;
2+
3+
/**
4+
* Created by fmatos on 1/05/2016.
5+
*/
6+
public class ToggleInternet extends ShellCommand {
7+
8+
private final boolean turnOn;
9+
10+
11+
public ToggleInternet(boolean turnOn) {
12+
this.turnOn = turnOn;
13+
}
14+
15+
@Override
16+
public String getCommandLine() {
17+
18+
return "svc data " + (turnOn ? "enable" : "disable");
19+
}
20+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,22 @@
197197
text="ADB Restart App With Debugger"
198198
description="Restarts the current application and attach the debugger">
199199
</action>
200+
<action id="com.developerphil.adbidea.action.PressPower"
201+
class="com.developerphil.adbidea.action.PressPower"
202+
text="ADB Press Power"
203+
description="Presses power button to light up screen (not effective with emulators)">
204+
</action>
205+
<action id="com.developerphil.adbidea.action.InternetOff"
206+
class="com.developerphil.adbidea.action.InternetOff"
207+
text="ADB Turns off internet"
208+
description="Turns off all internet (not effective with some devices)">
209+
</action>
210+
<action id="com.developerphil.adbidea.action.InternetOn"
211+
class="com.developerphil.adbidea.action.InternetOn"
212+
text="ADB Turns on internet"
213+
description="Turns on all internet (not effective with some devices)">
214+
</action>
215+
200216
<add-to-group group-id="AndroidToolsGroup" anchor="first"/>
201217
</group>
202218
</actions>

0 commit comments

Comments
 (0)