• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jiangxincode / ApkToolBoxGUI / #1150

31 Aug 2025 03:46AM UTC coverage: 2.985% (-0.04%) from 3.023%
#1150

push

jiangxincode
add dumpsys feature

0 of 104 new or added lines in 2 files covered. (0.0%)

1 existing line in 1 file now uncovered.

248 of 8308 relevant lines covered (2.99%)

0.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/edu/jiangxin/apktoolbox/android/dumpsys/DumpsysPanel.java
1
package edu.jiangxin.apktoolbox.android.dumpsys;
2

3
import edu.jiangxin.apktoolbox.swing.extend.EasyPanel;
4
import edu.jiangxin.apktoolbox.swing.extend.filepanel.FilePanel;
5
import edu.jiangxin.apktoolbox.utils.Constants;
6
import org.apache.commons.exec.CommandLine;
7
import org.apache.commons.exec.DefaultExecutor;
8
import org.apache.commons.exec.PumpStreamHandler;
9
import org.apache.commons.io.FileUtils;
10
import org.apache.commons.lang3.StringUtils;
11

12
import javax.swing.*;
13
import java.awt.*;
14
import java.awt.event.ActionEvent;
15
import java.awt.event.ActionListener;
16
import java.io.ByteArrayOutputStream;
17
import java.io.File;
18
import java.io.IOException;
19
import java.text.SimpleDateFormat;
20
import java.util.Date;
21

22
public class DumpsysPanel extends EasyPanel {
23
    private static final long serialVersionUID = 1L;
24

25
    private FilePanel targetFilePanel;
26

27
    private JPanel optionPanel;
28
    private JPanel dumpsysTypeChoosePanel;
29

30
    private JPanel operationPanel;
31
    private JButton startButton;
32

33

34
    public DumpsysPanel() {
NEW
35
        super();
×
NEW
36
    }
×
37

38
    @Override
39
    public void initUI() {
NEW
40
        setPreferredSize(new Dimension(Constants.DEFAULT_PANEL_WIDTH, Constants.DEFAULT_PANEL_HEIGHT));
×
41

NEW
42
        BoxLayout layout = new BoxLayout(this, BoxLayout.Y_AXIS);
×
NEW
43
        setLayout(layout);
×
44

NEW
45
        createTargetPanel();
×
NEW
46
        add(targetFilePanel);
×
NEW
47
        add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
48

NEW
49
        createOptionPanel();
×
NEW
50
        add(optionPanel);
×
NEW
51
        add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
52

NEW
53
        createOperationPanel();
×
NEW
54
        add(operationPanel);
×
55

NEW
56
    }
×
57

58
    private void createTargetPanel() {
NEW
59
        targetFilePanel = new FilePanel("Target Directory");
×
NEW
60
        targetFilePanel.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
×
NEW
61
    }
×
62

63
    private void createOptionPanel() {
NEW
64
        optionPanel = new JPanel();
×
NEW
65
        BoxLayout boxLayout = new BoxLayout(optionPanel, BoxLayout.Y_AXIS);
×
NEW
66
        optionPanel.setLayout(boxLayout);
×
67

NEW
68
        dumpsysTypeChoosePanel = new JPanel();
×
NEW
69
        dumpsysTypeChoosePanel.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 3));
×
70

NEW
71
        JCheckBox inputCheckBox = new JCheckBox("input");
×
NEW
72
        inputCheckBox.setSelected(true);
×
NEW
73
        JCheckBox windowCheckBox = new JCheckBox("window");
×
NEW
74
        dumpsysTypeChoosePanel.add(windowCheckBox);
×
NEW
75
        JCheckBox SurfaceFlingerCheckBox = new JCheckBox("SurfaceFlinger");
×
NEW
76
        dumpsysTypeChoosePanel.add(SurfaceFlingerCheckBox);
×
NEW
77
        JCheckBox activityCheckBox = new JCheckBox("activity");
×
NEW
78
        dumpsysTypeChoosePanel.add(activityCheckBox);
×
NEW
79
        JCheckBox accessibilityCheckBox = new JCheckBox("accessibility");
×
NEW
80
        dumpsysTypeChoosePanel.add(accessibilityCheckBox);
×
NEW
81
        JCheckBox packageCheckBox = new JCheckBox("package");
×
NEW
82
        dumpsysTypeChoosePanel.add(packageCheckBox);
×
NEW
83
        JCheckBox alarmCheckBox = new JCheckBox("alarm");
×
NEW
84
        dumpsysTypeChoosePanel.add(alarmCheckBox);
×
NEW
85
        JCheckBox inputMethodCheckBox = new JCheckBox("input_method");
×
NEW
86
        dumpsysTypeChoosePanel.add(inputMethodCheckBox);
×
NEW
87
        JCheckBox sensorServiceCheckBox = new JCheckBox("sensorservice");
×
NEW
88
        dumpsysTypeChoosePanel.add(sensorServiceCheckBox);
×
NEW
89
        JCheckBox accountCheckBox = new JCheckBox("account");
×
NEW
90
        dumpsysTypeChoosePanel.add(accountCheckBox);
×
NEW
91
        JCheckBox displayCheckBox = new JCheckBox("display");
×
NEW
92
        dumpsysTypeChoosePanel.add(displayCheckBox);
×
NEW
93
        JCheckBox powerCheckBox = new JCheckBox("power");
×
NEW
94
        dumpsysTypeChoosePanel.add(powerCheckBox);
×
NEW
95
        JCheckBox batteryCheckBox = new JCheckBox("battery");
×
NEW
96
        dumpsysTypeChoosePanel.add(batteryCheckBox);
×
97

NEW
98
        optionPanel.add(dumpsysTypeChoosePanel);
×
NEW
99
    }
×
100

101
    private void createOperationPanel() {
NEW
102
        operationPanel = new JPanel();
×
NEW
103
        BoxLayout boxLayout = new BoxLayout(operationPanel, BoxLayout.X_AXIS);
×
NEW
104
        operationPanel.setLayout(boxLayout);
×
105

NEW
106
        startButton = new JButton("Start");
×
NEW
107
        startButton.setEnabled(true);
×
NEW
108
        startButton.addActionListener(new OperationButtonActionListener());
×
NEW
109
        operationPanel.add(startButton);
×
NEW
110
    }
×
111

NEW
112
    class OperationButtonActionListener implements ActionListener {
×
113
        @Override
114
        public void actionPerformed(ActionEvent e) {
NEW
115
            startButton.setEnabled(false);
×
NEW
116
            File targetDirFile = targetFilePanel.getFile();
×
NEW
117
            if (!targetDirFile.exists()) {
×
NEW
118
                JOptionPane.showMessageDialog(getFrame(), "Target directory does not exist!", "ERROR", JOptionPane.ERROR_MESSAGE);
×
NEW
119
                return;
×
120
            }
121

NEW
122
            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date(System.currentTimeMillis()));
×
NEW
123
            File targetDirWithTimestamp = new File(targetDirFile, timeStamp);
×
124

NEW
125
            if (!targetDirWithTimestamp.exists()) {
×
NEW
126
                boolean success = targetDirWithTimestamp.mkdirs();
×
NEW
127
                if (!success) {
×
NEW
128
                    JOptionPane.showMessageDialog(getFrame(), "Create target directory failed!", "ERROR", JOptionPane.ERROR_MESSAGE);
×
NEW
129
                    return;
×
130
                }
131
            }
132

NEW
133
            Component[] components = dumpsysTypeChoosePanel.getComponents();
×
NEW
134
            for (Component component : components) {
×
NEW
135
                if (component instanceof JCheckBox checkBox) {
×
NEW
136
                    String dumpsysType = checkBox.getText();
×
NEW
137
                    if (checkBox.isSelected()) {
×
NEW
138
                        dumpsysAndSaveToFile(dumpsysType, targetDirWithTimestamp);
×
139
                    }
140
                }
141
            }
NEW
142
            startButton.setEnabled(true);
×
NEW
143
        }
×
144

145
        private void dumpsysAndSaveToFile(String dumpsysType, File targetDir) {
NEW
146
            String command = "adb shell dumpsys " + dumpsysType;
×
NEW
147
            CommandLine cmdLine = CommandLine.parse(command);
×
NEW
148
            DefaultExecutor executor = new DefaultExecutor();
×
NEW
149
            try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
×
NEW
150
                 ByteArrayOutputStream errorStream = new ByteArrayOutputStream();) {
×
NEW
151
                PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, errorStream);
×
NEW
152
                executor.setStreamHandler(streamHandler);
×
NEW
153
                int exitValue = executor.execute(cmdLine);
×
NEW
154
                if (exitValue == 0) {
×
NEW
155
                    String result = outputStream.toString().trim();
×
NEW
156
                    if (StringUtils.isNotEmpty(result)) {
×
NEW
157
                        File outputFile = new File(targetDir, dumpsysType + ".dumpsys");
×
NEW
158
                        FileUtils.writeStringToFile(outputFile, result, "UTF-8");
×
159
                    }
NEW
160
                } else {
×
NEW
161
                    String errorResult = errorStream.toString().trim();
×
NEW
162
                    if (StringUtils.isNotEmpty(errorResult)) {
×
NEW
163
                        File errorFile = new File(targetDir, dumpsysType + ".error");
×
NEW
164
                        FileUtils.writeStringToFile(errorFile, errorResult, "UTF-8");
×
165
                    }
166
                }
NEW
167
            } catch (IOException ex) {
×
NEW
168
                JOptionPane.showMessageDialog(getFrame(), "Execute command failed:\n" + ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
×
NEW
169
            }
×
NEW
170
        }
×
171
    }
172

173
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc