no message

This commit is contained in:
wanjian
2017-04-05 14:13:56 +08:00
parent ccda852879
commit 5bb02f3be1
9 changed files with 240 additions and 6 deletions

BIN
Main.dex Normal file

Binary file not shown.

BIN
adb Executable file

Binary file not shown.

View File

@@ -25,6 +25,6 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations' exclude group: 'com.android.support', module: 'support-annotations'
}) })
compile 'com.android.support:appcompat-v7:24.2.1' compile 'com.android.support:appcompat-v7:24.2.1'
// compile 'com.mogujie:screenshare:0.0.1-SNAPSHOT' // compile 'com.mogujie:screenshare:0.0.1-SNAPSHOT'
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
} }

View File

@@ -1,12 +1,16 @@
package sharescreen.wanjian.com.server; package sharescreen.wanjian.com.server;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.wanjian.puppet.Main;
import java.util.Date; import java.util.Date;
@@ -55,5 +59,6 @@ public class MainActivity extends AppCompatActivity {
}.sendEmptyMessage(0); }.sendEmptyMessage(0);
} }
} }

View File

@@ -38,6 +38,7 @@ public class Client extends JFrame {
final JTextField portField = new JTextField(); final JTextField portField = new JTextField();
portPanel.add(portField, BorderLayout.CENTER); portPanel.add(portField, BorderLayout.CENTER);
portPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); portPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
portField.setText("8888");
JPanel btnPanel = new JPanel(new BorderLayout(5, 5)); JPanel btnPanel = new JPanel(new BorderLayout(5, 5));
JButton btn = new JButton("链接"); JButton btn = new JButton("链接");
@@ -60,6 +61,8 @@ public class Client extends JFrame {
add(label, BorderLayout.CENTER); add(label, BorderLayout.CENTER);
add(createTableBar(), BorderLayout.SOUTH);
setDefaultCloseOperation(EXIT_ON_CLOSE); setDefaultCloseOperation(EXIT_ON_CLOSE);
setBounds(360, 20, 350, 600); setBounds(360, 20, 350, 600);
@@ -81,7 +84,7 @@ public class Client extends JFrame {
@Override @Override
public void mouseClicked(MouseEvent mouseEvent) { public void mouseClicked(MouseEvent mouseEvent) {
super.mouseClicked(mouseEvent); super.mouseClicked(mouseEvent);
System.out.println("down "+mouseEvent); System.out.println("down " + mouseEvent);
int x = mouseEvent.getX(); int x = mouseEvent.getX();
int y = mouseEvent.getY(); int y = mouseEvent.getY();
try { try {
@@ -141,6 +144,59 @@ public class Client extends JFrame {
} }
private JPanel createTableBar() {
JPanel bar = new JPanel(new BorderLayout());
JButton menu = new JButton("menu");
JButton home = new JButton("home");
JButton back = new JButton("back");
bar.add(menu, BorderLayout.WEST);
bar.add(home, BorderLayout.CENTER);
bar.add(back, BorderLayout.EAST);
menu.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent mouseEvent) {
super.mouseClicked(mouseEvent);
try {
writer.write("MENU");
writer.newLine();
writer.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
});
home.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent mouseEvent) {
super.mouseClicked(mouseEvent);
try {
writer.write("HOME");
writer.newLine();
writer.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
});
back.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent mouseEvent) {
super.mouseClicked(mouseEvent);
try {
writer.write("BACK");
writer.newLine();
writer.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
});
return bar;
}
BufferedWriter writer; BufferedWriter writer;
private void read(final String ip, final String port) throws IOException { private void read(final String ip, final String port) throws IOException {

View File

@@ -0,0 +1,135 @@
package com.client;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.util.Arrays;
/**
* Created by wanjian on 2017/4/5.
*/
public class Install {
public static void main(String[] args) {
install();
}
public static void install() {
adbCommond("push Main.dex /sdcard/Main.dex");
String path = "export CLASSPATH=/sdcard/Main.dex";
String app = "exec app_process /sdcard com.wanjian.puppet.Main";
shellCommond(new String[]{path, app});
}
private static void adbCommond(String com) {
System.out.println("adbCommond...."+com);
commond("sh", "./adb " + com);
}
private static void shellCommond(String[] com) {
System.out.println("shell commond..."+ Arrays.toString(com));
try {
Process process = Runtime
.getRuntime()
.exec("./adb shell "); // adb
// shell
final BufferedWriter outputStream = new BufferedWriter(
new OutputStreamWriter(process.getOutputStream()));
for (String s : com) {
outputStream.write(s);
outputStream.write("\n");
}
outputStream.flush();
System.out.println("shell write finished...");
readError(process.getErrorStream());
adbCommond("forward tcp:8888 localabstract:puppet-ver1");
readResult(process.getInputStream());
while (true) {
Thread.sleep(Integer.MAX_VALUE);
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static void readError(final InputStream errorStream) {
new Thread(){
@Override
public void run() {
super.run();
readResult(errorStream);
}
}.start();
}
///////////////
private static void commond(String c, String com) {
System.out.println("---> " + c + com);
try {
Process process = Runtime
.getRuntime()
.exec(c); // adb
final BufferedWriter outputStream = new BufferedWriter(
new OutputStreamWriter(process.getOutputStream()));
outputStream.write(com);
outputStream.write("\n");
outputStream.write("exit\n");
outputStream.flush();
int i = process.waitFor();
readResult(process.getInputStream());
System.out.println("------END-------");
} catch (Exception e) {
e.printStackTrace();
}
}
private static void readResult(final InputStream stream) {
System.out.println("read result.....");
try {
String line;
final BufferedReader reader = new BufferedReader(
new InputStreamReader(stream));
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
System.out.println("-------END------");
} catch (IOException e) {
e.printStackTrace();
try {
stream.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}

View File

@@ -0,0 +1,13 @@
package android.view;
import android.graphics.Bitmap;
/**
* Created by wanjian on 2017/4/5.
*/
public class Surface {
public static Bitmap screenshot(int x, int y){
return null;
}
}

View File

@@ -0,0 +1,13 @@
package android.view;
import android.graphics.Bitmap;
/**
* Created by wanjian on 2017/4/5.
*/
public class SurfaceControl {
public static Bitmap screenshot(int x,int y){
return null;
}
}

View File

@@ -58,7 +58,6 @@ public class Main {
private static void init() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { private static void init() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
System.out.println("init...");
Method getServiceMethod = Class.forName("android.os.ServiceManager").getDeclaredMethod("getService", new Class[]{String.class}); Method getServiceMethod = Class.forName("android.os.ServiceManager").getDeclaredMethod("getService", new Class[]{String.class});
wm = IWindowManager.Stub.asInterface((IBinder) getServiceMethod.invoke(null, new Object[]{"window"})); wm = IWindowManager.Stub.asInterface((IBinder) getServiceMethod.invoke(null, new Object[]{"window"}));
@@ -66,7 +65,6 @@ public class Main {
MotionEvent.class.getDeclaredMethod("obtain", new Class[0]).setAccessible(true); MotionEvent.class.getDeclaredMethod("obtain", new Class[0]).setAccessible(true);
injectInputEventMethod = InputManager.class.getMethod("injectInputEvent", new Class[]{InputEvent.class, Integer.TYPE}); injectInputEventMethod = InputManager.class.getMethod("injectInputEvent", new Class[]{InputEvent.class, Integer.TYPE});
System.out.println("init finished...");
} }
private static void acceptConnect(LocalSocket socket) { private static void acceptConnect(LocalSocket socket) {
@@ -107,6 +105,10 @@ public class Main {
private final String MOVE = "MOVE"; private final String MOVE = "MOVE";
private final String UP = "UP"; private final String UP = "UP";
private final String MENU = "MENU";
private final String HOME = "HOME";
private final String BACK = "BACK";
@Override @Override
public void run() { public void run() {
super.run(); super.run();
@@ -126,11 +128,16 @@ public class Main {
try { try {
if (line.startsWith(DOWN)) { if (line.startsWith(DOWN)) {
hanlerDown(line.substring(DOWN.length())); hanlerDown(line.substring(DOWN.length()));
// hanlerUp(line.substring(DOWN.length()));
} else if (line.startsWith(MOVE)) { } else if (line.startsWith(MOVE)) {
hanlerMove(line.substring(MOVE.length())); hanlerMove(line.substring(MOVE.length()));
} else if (line.startsWith(UP)) { } else if (line.startsWith(UP)) {
hanlerUp(line.substring(UP.length())); hanlerUp(line.substring(UP.length()));
} else if (line.startsWith(MENU)) {
menu();
} else if (line.startsWith(HOME)) {
pressHome();
} else if (line.startsWith(BACK)) {
back();
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@@ -208,12 +215,14 @@ public class Main {
String surfaceClassName; String surfaceClassName;
Point size = SurfaceControlVirtualDisplayFactory.getCurrentDisplaySize(false); Point size = SurfaceControlVirtualDisplayFactory.getCurrentDisplaySize(false);
Bitmap b = null;
if (Build.VERSION.SDK_INT <= 17) { if (Build.VERSION.SDK_INT <= 17) {
surfaceClassName = "android.view.Surface"; surfaceClassName = "android.view.Surface";
} else { } else {
surfaceClassName = "android.view.SurfaceControl"; surfaceClassName = "android.view.SurfaceControl";
// b = android.view.SurfaceControl.screenshot(size.x, size.y);
} }
Bitmap b = (Bitmap) Class.forName(surfaceClassName).getDeclaredMethod("screenshot", new Class[]{Integer.TYPE, Integer.TYPE}).invoke(null, new Object[]{Integer.valueOf(size.x), Integer.valueOf(size.y)}); b = (Bitmap) Class.forName(surfaceClassName).getDeclaredMethod("screenshot", new Class[]{Integer.TYPE, Integer.TYPE}).invoke(null, new Object[]{Integer.valueOf(size.x), Integer.valueOf(size.y)});
int rotation = wm.getRotation(); int rotation = wm.getRotation();
if (rotation == 0) { if (rotation == 0) {
return b; return b;
@@ -229,6 +238,9 @@ public class Main {
return Bitmap.createBitmap(b, 0, 0, size.x, size.y, m, false); return Bitmap.createBitmap(b, 0, 0, size.x, size.y, m, false);
} }
private static void menu() throws InvocationTargetException, IllegalAccessException {
sendKeyEvent(im, injectInputEventMethod, InputDeviceCompat.SOURCE_KEYBOARD, KeyEvent.KEYCODE_MENU, false);
}
private static void back() throws InvocationTargetException, IllegalAccessException { private static void back() throws InvocationTargetException, IllegalAccessException {
sendKeyEvent(im, injectInputEventMethod, InputDeviceCompat.SOURCE_KEYBOARD, 4, false); sendKeyEvent(im, injectInputEventMethod, InputDeviceCompat.SOURCE_KEYBOARD, 4, false);