diff --git a/Main.dex b/Main.dex new file mode 100644 index 0000000..d3b9192 Binary files /dev/null and b/Main.dex differ diff --git a/adb b/adb new file mode 100755 index 0000000..738344f Binary files /dev/null and b/adb differ diff --git a/app/build.gradle b/app/build.gradle index d41b990..a62face 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,6 +25,6 @@ dependencies { exclude group: 'com.android.support', module: 'support-annotations' }) 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' } diff --git a/app/src/main/java/sharescreen/wanjian/com/server/MainActivity.java b/app/src/main/java/sharescreen/wanjian/com/server/MainActivity.java index 0179d00..1d45aef 100644 --- a/app/src/main/java/sharescreen/wanjian/com/server/MainActivity.java +++ b/app/src/main/java/sharescreen/wanjian/com/server/MainActivity.java @@ -1,12 +1,16 @@ package sharescreen.wanjian.com.server; import android.content.Intent; +import android.graphics.Bitmap; import android.os.Handler; import android.os.Message; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.TextView; +import android.widget.Toast; + +import com.wanjian.puppet.Main; import java.util.Date; @@ -55,5 +59,6 @@ public class MainActivity extends AppCompatActivity { }.sendEmptyMessage(0); + } } diff --git a/lib/src/main/java/com/client/Client.java b/lib/src/main/java/com/client/Client.java index 40632c7..dd58660 100644 --- a/lib/src/main/java/com/client/Client.java +++ b/lib/src/main/java/com/client/Client.java @@ -38,6 +38,7 @@ public class Client extends JFrame { final JTextField portField = new JTextField(); portPanel.add(portField, BorderLayout.CENTER); portPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); + portField.setText("8888"); JPanel btnPanel = new JPanel(new BorderLayout(5, 5)); JButton btn = new JButton("链接"); @@ -60,6 +61,8 @@ public class Client extends JFrame { add(label, BorderLayout.CENTER); + add(createTableBar(), BorderLayout.SOUTH); + setDefaultCloseOperation(EXIT_ON_CLOSE); setBounds(360, 20, 350, 600); @@ -81,7 +84,7 @@ public class Client extends JFrame { @Override public void mouseClicked(MouseEvent mouseEvent) { super.mouseClicked(mouseEvent); - System.out.println("down "+mouseEvent); + System.out.println("down " + mouseEvent); int x = mouseEvent.getX(); int y = mouseEvent.getY(); 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; private void read(final String ip, final String port) throws IOException { diff --git a/lib/src/main/java/com/client/Install.java b/lib/src/main/java/com/client/Install.java new file mode 100644 index 0000000..f5bb703 --- /dev/null +++ b/lib/src/main/java/com/client/Install.java @@ -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(); + } + } + } + + +} diff --git a/shareandcontrollib/src/main/java/android/view/Surface.java b/shareandcontrollib/src/main/java/android/view/Surface.java new file mode 100644 index 0000000..bdef6b8 --- /dev/null +++ b/shareandcontrollib/src/main/java/android/view/Surface.java @@ -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; + } +} diff --git a/shareandcontrollib/src/main/java/android/view/SurfaceControl.java b/shareandcontrollib/src/main/java/android/view/SurfaceControl.java new file mode 100644 index 0000000..ffdffdf --- /dev/null +++ b/shareandcontrollib/src/main/java/android/view/SurfaceControl.java @@ -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; + } +} diff --git a/shareandcontrollib/src/main/java/com/wanjian/puppet/Main.java b/shareandcontrollib/src/main/java/com/wanjian/puppet/Main.java index cc6576b..214c307 100644 --- a/shareandcontrollib/src/main/java/com/wanjian/puppet/Main.java +++ b/shareandcontrollib/src/main/java/com/wanjian/puppet/Main.java @@ -58,7 +58,6 @@ public class Main { 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}); 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); injectInputEventMethod = InputManager.class.getMethod("injectInputEvent", new Class[]{InputEvent.class, Integer.TYPE}); - System.out.println("init finished..."); } private static void acceptConnect(LocalSocket socket) { @@ -107,6 +105,10 @@ public class Main { private final String MOVE = "MOVE"; private final String UP = "UP"; + private final String MENU = "MENU"; + private final String HOME = "HOME"; + private final String BACK = "BACK"; + @Override public void run() { super.run(); @@ -126,11 +128,16 @@ public class Main { try { if (line.startsWith(DOWN)) { hanlerDown(line.substring(DOWN.length())); -// hanlerUp(line.substring(DOWN.length())); } else if (line.startsWith(MOVE)) { hanlerMove(line.substring(MOVE.length())); } else if (line.startsWith(UP)) { 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) { e.printStackTrace(); @@ -208,12 +215,14 @@ public class Main { String surfaceClassName; Point size = SurfaceControlVirtualDisplayFactory.getCurrentDisplaySize(false); + Bitmap b = null; if (Build.VERSION.SDK_INT <= 17) { surfaceClassName = "android.view.Surface"; } else { 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(); if (rotation == 0) { return b; @@ -229,6 +238,9 @@ public class Main { 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 { sendKeyEvent(im, injectInputEventMethod, InputDeviceCompat.SOURCE_KEYBOARD, 4, false);