no message
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
135
lib/src/main/java/com/client/Install.java
Normal file
135
lib/src/main/java/com/client/Install.java
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
13
shareandcontrollib/src/main/java/android/view/Surface.java
Normal file
13
shareandcontrollib/src/main/java/android/view/Surface.java
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user