主UI的adb功能固定位对sdk 5.8以上进行控制操作

This commit is contained in:
Yutousama 2020-05-19 17:44:10 +08:00
parent 75fc8065c2
commit 572a74f97a

View File

@ -2,32 +2,22 @@ package com.qy.ui;
import java.awt.Color; import java.awt.Color;
import java.awt.Desktop; import java.awt.Desktop;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.security.Permission; import java.security.Permission;
import java.util.*;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;
import javax.swing.ButtonGroup; import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.LineBorder; import javax.swing.border.LineBorder;
import com.qy.utils.*; import com.qy.utils.*;
@ -42,15 +32,16 @@ public class AppMain extends JFrame {
private JButton zipToJar, jarToBase, reload, btnAdbPull; private JButton zipToJar, jarToBase, reload, btnAdbPull;
private JTextField log; private JTextField log;
public static JSONObject json; public static JSONObject json;
private Vector<String> vector; private Vector<String> vector, phonePackageList = new Vector<>();
private Map<String, String> adbMap;
public static boolean isOpenWindows = false; public static boolean isOpenWindows = false;
/** /**
* *
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private JTextField txtCom; private JComboBox<String> txtCom;
private JButton btnUserBase; private JButton btnUserBase;
private JTextField textPackName; private JComboBox<String> textPackName;
private JButton btnRestartapp; private JButton btnRestartapp;
private JLabel lblactivity; private JLabel lblactivity;
private JTextField textActivity; private JTextField textActivity;
@ -74,6 +65,8 @@ public class AppMain extends JFrame {
setResizable(false); setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
json = Tools.loadConfig(new File("config.cfg")); json = Tools.loadConfig(new File("config.cfg"));
initPhonePackageList();
initAdbData();
initView(); initView();
initData(); initData();
log.setText("已载入配置文件"); log.setText("已载入配置文件");
@ -85,6 +78,34 @@ public class AppMain extends JFrame {
repaint(); repaint();
} }
private void initAdbData() {
adbMap = new HashMap<>(9);
adbMap.put("开屏", "adb shell am broadcast -a com.sdk.debug --es package \"[packname]\" --es type \"open\"");
adbMap.put("插屏", "adb shell am broadcast -a com.sdk.debug --es package \"[packname]\" --es type \"inter\"");
adbMap.put("banner", "adb shell am broadcast -a com.sdk.debug --es package \"[packname]\" --es type \"banner\"");
adbMap.put("视频", "adb shell am broadcast -a com.sdk.debug --es package \"[packname]\" --es type \"video\"");
adbMap.put("激励视频", "adb shell am broadcast -a com.sdk.debug --es package \"[packname]\" --es type \"reward\"");
adbMap.put("SDK信息", "adb shell am broadcast -a com.sdk.debug --es package \"[packname]\" --es type \"systemTest\"");
adbMap.put("重载网络", "adb shell am broadcast -a com.sdk.debug --es package \"[packname]\" --es type \"reloadApi\"");
adbMap.put("获取广告参数", "adb shell am broadcast -a com.sdk.debug --es package \"[packname]\" --es type \"adBean\"");
adbMap.put("查看日志", "adb shell am broadcast -a com.sdk.debug --es package \"[packname]\" --es type \"logcat\"");
}
private void initPhonePackageList() {
try {
phonePackageList.clear();
Process process = Runtime.getRuntime().exec("adb shell pm list packages");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String tmp;
while ((tmp = reader.readLine()) != null) {
phonePackageList.add(tmp.substring(8));
}
Collections.sort(phonePackageList);
} catch (Exception e) {
e.printStackTrace();
}
}
private void initData() { private void initData() {
JSONArray array = json.getJSONArray("array"); JSONArray array = json.getJSONArray("array");
vector = new Vector<>(); vector = new Vector<>();
@ -102,7 +123,7 @@ public class AppMain extends JFrame {
// TODO: handle exception // TODO: handle exception
e.printStackTrace(); e.printStackTrace();
} }
setTitle("\u8F6C\u6362\u5668v2.9"); setTitle("\u8F6C\u6362\u5668v2.10");
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
setSize(900, 456); setSize(900, 456);
getContentPane().setLayout(null); getContentPane().setLayout(null);
@ -180,7 +201,7 @@ public class AppMain extends JFrame {
public void smaliPath(String path) { public void smaliPath(String path) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
File input = new File(json.getString("out") File input = new File(json.getString("out")
+ json.getJSONArray("array").getString(Integer.parseInt(json.getString("switch")) -1) + ".jar"); + json.getJSONArray("array").getString(Integer.parseInt(json.getString("switch")) - 1) + ".jar");
Tools.toAJar(json.getString("dx"), input.getAbsolutePath(), input.getAbsolutePath().replace(input.getName(), "dexTmp.jar")); Tools.toAJar(json.getString("dx"), input.getAbsolutePath(), input.getAbsolutePath().replace(input.getName(), "dexTmp.jar"));
File outFile = new EncryptJar().encrypt(new File(input.getAbsolutePath().replace(input.getName(), "dexTmp.jar")), json.getString("out") File outFile = new EncryptJar().encrypt(new File(input.getAbsolutePath().replace(input.getName(), "dexTmp.jar")), json.getString("out")
+ json.getJSONArray("array").getString(Integer.parseInt(json.getString("switch")) - 1) + "_encrypt.jar", Integer.parseInt(path) + json.getJSONArray("array").getString(Integer.parseInt(json.getString("switch")) - 1) + "_encrypt.jar", Integer.parseInt(path)
@ -221,12 +242,13 @@ public class AppMain extends JFrame {
log.setBounds(51, 340, 766, 31); log.setBounds(51, 340, 766, 31);
getContentPane().add(log); getContentPane().add(log);
txtCom = new JTextField(); Vector<String> adbList = new Vector<>(adbMap.keySet());
txtCom.setHorizontalAlignment(SwingConstants.LEFT); txtCom = new JComboBox<String>(adbList);
txtCom.setText("adb push \"" + new File("").getAbsolutePath() + "/[jar]/data/data/[packname]/plugs/"); //txtCom.setHorizontalAlignment(SwingConstants.LEFT);
//txtCom.setText("adb push \"" + new File("").getAbsolutePath() + "/[jar]/data/data/[packname]/plugs/");
txtCom.setBounds(444, 73, 293, 27); txtCom.setBounds(444, 73, 293, 27);
getContentPane().add(txtCom); getContentPane().add(txtCom);
txtCom.setColumns(10); //txtCom.setColumns(10);
JLabel lblAdb = new JLabel("adb\u6307\u4EE4"); JLabel lblAdb = new JLabel("adb\u6307\u4EE4");
lblAdb.setBounds(444, 51, 72, 18); lblAdb.setBounds(444, 51, 72, 18);
@ -236,9 +258,8 @@ public class AppMain extends JFrame {
btnAdbPull.addMouseListener(new MouseAdapter() { btnAdbPull.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
String cmd = txtCom.getText(); String cmd = adbMap.get((String) txtCom.getSelectedItem());
cmd = cmd.replace("[packname]", textPackName.getText()); cmd = cmd.replace("[packname]", (String) Objects.requireNonNull(textPackName.getSelectedItem()));
cmd = cmd.replace("[jar]", configList.getSelectedValue().toString() + ".jar");
try { try {
System.out.println(cmd); System.out.println(cmd);
Runtime.getRuntime().exec("adb root"); Runtime.getRuntime().exec("adb root");
@ -283,7 +304,7 @@ public class AppMain extends JFrame {
// TODO Auto-generated method stub // TODO Auto-generated method stub
Tools.toAJar(json.getString("dx"), file.getAbsolutePath(), file.getAbsolutePath().replace(file.getName(), "dexTmp.jar")); Tools.toAJar(json.getString("dx"), file.getAbsolutePath(), file.getAbsolutePath().replace(file.getName(), "dexTmp.jar"));
File fileOut = new EncryptJar().encrypt(new File(file.getAbsolutePath().replace(file.getName(), "dexTmp.jar")), file.getAbsolutePath() + "_encrypt.jar", Integer.valueOf(path) File fileOut = new EncryptJar().encrypt(new File(file.getAbsolutePath().replace(file.getName(), "dexTmp.jar")), file.getAbsolutePath() + "_encrypt.jar", Integer.valueOf(path)
, Integer.valueOf(version)); , Integer.parseInt(version));
System.out.println("data路径为:" + fileOut.getAbsolutePath()); System.out.println("data路径为:" + fileOut.getAbsolutePath());
if (log != null) if (log != null)
log.setText("data路径为:" + fileOut.getAbsolutePath()); log.setText("data路径为:" + fileOut.getAbsolutePath());
@ -334,21 +355,20 @@ public class AppMain extends JFrame {
label.setBounds(444, 113, 72, 18); label.setBounds(444, 113, 72, 18);
getContentPane().add(label); getContentPane().add(label);
textPackName = new JTextField(); textPackName = new JComboBox<String>(phonePackageList);
textPackName.setText("com.luckyboy.mmxing");
textPackName.setBounds(444, 135, 293, 24); textPackName.setBounds(444, 135, 293, 24);
getContentPane().add(textPackName); getContentPane().add(textPackName);
textPackName.setColumns(10);
btnRestartapp = new JButton("\u91CD\u542FAPP"); btnRestartapp = new JButton("\u91CD\u542FAPP");
btnRestartapp.addMouseListener(new MouseAdapter() { btnRestartapp.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
try { try {
Runtime.getRuntime().exec("adb shell am force-stop " + textPackName.getText()); Runtime.getRuntime().exec("adb shell am force-stop " + (String) textPackName.getSelectedItem());
Runtime.getRuntime() Runtime.getRuntime()
.exec("adb shell am start " + textPackName.getText() + File.separator + textActivity.getText()); .exec("adb shell am start " + (String) textPackName.getSelectedItem() + File.separator + textActivity.getText());
log.setText("重启完毕"); log.setText("重启完毕");
System.out.println("adb shell am start " + (String) textPackName.getSelectedItem() + File.separator + textActivity.getText());
} catch (IOException e1) { } catch (IOException e1) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e1.printStackTrace(); e1.printStackTrace();
@ -401,15 +421,12 @@ public class AppMain extends JFrame {
getContentPane().add(uFilePath); getContentPane().add(uFilePath);
uFilePath.setColumns(10); uFilePath.setColumns(10);
JButton button = new JButton("\u83B7\u53D6"); JButton button = new JButton("刷新包名");
button.addMouseListener(new MouseAdapter() { button.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
JFileChooser chooser = new JFileChooser(new File(new File("").getAbsolutePath())); initPhonePackageList();
chooser.showOpenDialog(null); log.setText("获取手机包名完毕");
File file = chooser.getSelectedFile();
uFilePath.setText(file.getAbsolutePath());
log.setText("获取自定义文件路径完成");
} }
}); });
@ -500,7 +517,7 @@ public class AppMain extends JFrame {
}); });
menu.add(mntmsdk_1); menu.add(mntmsdk_1);
JMenuItem csj=new JMenuItem("穿山甲资源包"); JMenuItem csj = new JMenuItem("穿山甲资源包");
csj.addActionListener(new ActionListener() { csj.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -509,26 +526,28 @@ public class AppMain extends JFrame {
}); });
menu.add(csj); menu.add(csj);
JMenuItem autoSDK=new JMenuItem("自动生成SDK"); JMenuItem autoSDK = new JMenuItem("自动生成SDK");
autoSDK.addActionListener(new ActionListener() { autoSDK.addActionListener(new ActionListener() {
String version; String version;
String packageName; String packageName;
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
new EditToDalog("提示", "请输入版本号", "", path -> { new EditToDalog("提示", "请输入版本号", "", path -> {
if(!Tools.stringIsNull(path)){ if (!Tools.stringIsNull(path)) {
version=path; version = path;
new EditToDalog("提示", "请输入包名", "com.prujwk.jdyphn", path1 -> { new EditToDalog("提示", "请输入包名", "com.prujwk.jdyphn", path1 -> {
if(!Tools.stringIsNull(path1)){ if (!Tools.stringIsNull(path1)) {
packageName= path1; packageName = path1;
autoPackageSdk(); autoPackageSdk();
} }
}); });
} }
}); });
} }
public void autoPackageSdk(){
new AutoPackageSDK(path -> new TextToDalog("提示",String.format("打包完成%s",path)),version,packageName); public void autoPackageSdk() {
new AutoPackageSDK(path -> new TextToDalog("提示", String.format("打包完成%s", path)), version, packageName);
} }
}); });
menu.add(autoSDK); menu.add(autoSDK);