Skip to content

Commit bf092f5

Browse files
authored
Merge pull request #9 from tejado/F1-logtab
Merge logtab branch
2 parents 2f14129 + cab3f0c commit bf092f5

37 files changed

+1349
-361
lines changed

.idea/compiler.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "net.tjado.usbgadget"
88
minSdkVersion 26
99
targetSdkVersion 29
10-
versionCode 2
11-
versionName "0.2"
10+
versionCode 3
11+
versionName "0.3"
1212

1313
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1414
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
GADGET="keyboard"
4+
GADGET_PATH="____gadgetPath____"
5+
6+
cd $GADGET_PATH/configs/
7+
CONFIG_PATH="$GADGET_PATH/configs/`ls -1 | head -1`/"
8+
STRINGS_PATH="$GADGET_PATH/strings/0x409/"
9+
10+
11+
mkdir -p $GADGET_PATH/functions/ccid.usb0
12+
cd $GADGET_PATH/functions/ccid.usb0
13+
14+
ln -s ${GADGET_PATH}/functions/ccid.usb0 $CONFIG_PATH/ccid.usb0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
GADGET="keyboard"
4+
GADGET_PATH="____gadgetPath____"
5+
6+
cd $GADGET_PATH/configs/
7+
CONFIG_PATH="$GADGET_PATH/configs/`ls -1 | head -1`/"
8+
STRINGS_PATH="$GADGET_PATH/strings/0x409/"
9+
10+
11+
mkdir -p $GADGET_PATH/functions/hid.ctap
12+
cd $GADGET_PATH/functions/hid.ctap
13+
14+
# HID protocol (according to USB spec: 1 for keyboard)
15+
echo 0 > protocol
16+
# device subclass
17+
echo 0 > subclass
18+
# number of bytes per record
19+
echo 64 > report_length
20+
21+
# writing report descriptor
22+
echo -ne \\x06\\xD0\\xF1\\x09\\x01\\xA1\\x01\\x09\\x20\\x15\\x00\\x26\\xFF\\x00\\x75\\x08\\x95\\x40\\x81\\x02\\x09\\x21\\x15\\x00\\x26\\xFF\\x00\\x75\\x08\\x95\\x40\\x91\\x02\\xC0 > report_desc
23+
24+
ln -s ${GADGET_PATH}/functions/hid.ctap $CONFIG_PATH/hid.ctap
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
GADGET="keyboard"
4+
GADGET_PATH="____gadgetPath____"
5+
6+
cd $GADGET_PATH/configs/
7+
CONFIG_PATH="$GADGET_PATH/configs/`ls -1 | head -1`/"
8+
STRINGS_PATH="$GADGET_PATH/strings/0x409/"
9+
10+
11+
mkdir -p $GADGET_PATH/functions/hid.keyboard
12+
cd $GADGET_PATH/functions/hid.keyboard
13+
14+
# HID protocol (according to USB spec: 1 for keyboard)
15+
echo 1 > protocol
16+
# device subclass
17+
echo 1 > subclass
18+
# number of bytes per record
19+
echo 8 > report_length
20+
21+
# writing report descriptor
22+
echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > report_desc
23+
24+
ln -s ${GADGET_PATH}/functions/hid.keyboard $CONFIG_PATH/hid.keyboard
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
GADGET="keyboard"
4+
GADGET_PATH="____gadgetPath____"
5+
6+
cd $GADGET_PATH/configs/
7+
CONFIG_PATH="$GADGET_PATH/configs/`ls -1 | head -1`/"
8+
STRINGS_PATH="$GADGET_PATH/strings/0x409/"
9+
10+
11+
mkdir -p $GADGET_PATH/functions/hid.mouse
12+
cd $GADGET_PATH/functions/hid.mouse
13+
14+
# HID protocol (according to USB spec: 2 for mouse)
15+
echo 2 > protocol
16+
# device subclass
17+
echo 1 > subclass
18+
# number of bytes per record
19+
echo 4 > report_length
20+
21+
# writing report descriptor
22+
echo -ne \\x05\\x01\\x09\\x02\\xa1\\x01\\x09\\x01\\xa1\\x00\\x05\\x09\\x19\\x01\\x29\\x05\\x15\\x00\\x25\\x01\\x95\\x05\\x75\\x01\\x81\\x02\\x95\\x01\\x75\\x03\\x81\\x01\\x05\\x01\\x09\\x30\\x09\\x31\\x09\\x38\\x15\\x81\\x25\\x7F\\x75\\x08\\x95\\x03\\x81\\x06\\xc0\\xc0 > report_desc
23+
24+
ln -s ${GADGET_PATH}/functions/hid.mouse $CONFIG_PATH/hid.mouse

app/src/main/assets/usbGadgetProfiles/ccid.sh app/src/main/assets/usbGadgetProfiles/CCID

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ echo 0x0525 > idProduct
2222

2323
cd $STRINGS_PATH
2424
echo "tejado" > manufacturer
25-
echo "CCID" > product
25+
echo "Android USB Gadget" > product
2626
echo "42" > serialnumber
2727

2828
cd $CONFIG_PATH
2929
echo 30 > MaxPower
30-
echo "CCID Configuration" > strings/0x409/configuration
30+
echo "Configuration" > strings/0x409/configuration
3131

3232
ln -s ${GADGET_PATH}/functions/ccid.usb0 $CONFIG_PATH/ccid.usb0

app/src/main/assets/usbGadgetProfiles/ctap.sh app/src/main/assets/usbGadgetProfiles/CTAP

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ cd $GADGET_PATH
2929
echo '0xa4ac' > idVendor
3030
echo '0x0525' > idProduct
3131

32-
echo '0x0512' > bcdDevice
33-
echo '0x0200' > bcdUSB
32+
echo '0x1c37' > bcdDevice
33+
echo '0x6190' > bcdUSB
3434
echo 0 > bDeviceProtocol
3535
echo 0 > bDeviceSubClass
3636
echo 8 > bMaxPacketSize0
3737

3838
cd $STRINGS_PATH
3939
echo "tejado" > manufacturer
40-
echo "CTAP" > product
40+
echo "Android USB Gadget" > product
4141
echo "42" > serialnumber
4242

4343
cd $CONFIG_PATH
4444
echo 30 > MaxPower
45-
echo "HID Configuration" > strings/0x409/configuration
45+
echo "Configuration" > strings/0x409/configuration
4646

4747
ln -s ${GADGET_PATH}/functions/hid.usb0 $CONFIG_PATH/hid.usb0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
CONFIGFS_DIR="/config"
4+
GADGETS_PATH="${CONFIGFS_DIR}/usb_gadget"
5+
6+
GADGET="gadget_${RANDOM}"
7+
GADGET_PATH=${GADGETS_PATH}/${GADGET}
8+
9+
CONFIG_PATH="$GADGET_PATH/configs/c.1/"
10+
STRINGS_PATH="$GADGET_PATH/strings/0x409/"
11+
12+
mkdir -p $CONFIG_PATH
13+
mkdir -p $STRINGS_PATH
14+
15+
16+
cd $GADGET_PATH
17+
echo 0x046a > idVendor
18+
echo 0x002a > idProduct
19+
20+
cd $STRINGS_PATH
21+
echo "tejado" > manufacturer
22+
echo "Android USB Gadget" > product
23+
echo "42" > serialnumber
24+
25+
cd $CONFIG_PATH
26+
echo 120 > MaxPower
27+
echo "Configuration" > strings/0x409/configuration

app/src/main/assets/usbGadgetProfiles/mouse+keyboard.sh app/src/main/assets/usbGadgetProfiles/Mouse & Keyboard

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ STRINGS_PATH="$GADGET_PATH/strings/0x409/"
1212
mkdir -p $CONFIG_PATH
1313
mkdir -p $STRINGS_PATH
1414

15-
mkdir -p $GADGET_PATH/functions/hid.usb0
16-
cd $GADGET_PATH/functions/hid.usb0
15+
mkdir -p $GADGET_PATH/functions/hid.keyboard
16+
cd $GADGET_PATH/functions/hid.keyboard
1717

1818
# HID protocol (according to USB spec: 1 for keyboard)
1919
echo 1 > protocol
@@ -25,8 +25,8 @@ echo 8 > report_length
2525
# writing report descriptor
2626
echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > report_desc
2727

28-
mkdir -p $GADGET_PATH/functions/hid.usb1
29-
cd $GADGET_PATH/functions/hid.usb1
28+
mkdir -p $GADGET_PATH/functions/hid.mouse
29+
cd $GADGET_PATH/functions/hid.mouse
3030

3131
# HID protocol (according to USB spec: 2 for mouse)
3232
echo 2 > protocol
@@ -40,17 +40,17 @@ echo -ne \\x05\\x01\\x09\\x02\\xa1\\x01\\x09\\x01\\xa1\\x00\\x05\\x09\\x19\\x01\
4040

4141

4242
cd $GADGET_PATH
43-
echo 0xa4ac > idVendor
44-
echo 0x0525 > idProduct
43+
echo 0x046a > idVendor
44+
echo 0x002a > idProduct
4545

4646
cd $STRINGS_PATH
4747
echo "tejado" > manufacturer
48-
echo "HID" > product
48+
echo "Android USB Gadget" > product
4949
echo "42" > serialnumber
5050

5151
cd $CONFIG_PATH
5252
echo 120 > MaxPower
53-
echo "HID Configuration" > strings/0x409/configuration
53+
echo "Configuration" > strings/0x409/configuration
5454

55-
ln -s ${GADGET_PATH}/functions/hid.usb0 $CONFIG_PATH/hid.usb0
56-
ln -s ${GADGET_PATH}/functions/hid.usb1 $CONFIG_PATH/hid.usb1
55+
ln -s ${GADGET_PATH}/functions/hid.keyboard $CONFIG_PATH/hid.keyboard
56+
ln -s ${GADGET_PATH}/functions/hid.mouse $CONFIG_PATH/hid.mouse
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package net.tjado.usbgadget;
2+
3+
import android.graphics.Typeface;
4+
import android.os.Bundle;
5+
import android.text.Html;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
import android.widget.LinearLayout;
10+
import android.widget.TextView;
11+
12+
import androidx.fragment.app.Fragment;
13+
import androidx.lifecycle.LiveData;
14+
import androidx.lifecycle.MutableLiveData;
15+
16+
import java.io.BufferedReader;
17+
import java.io.StringReader;
18+
import java.util.HashMap;
19+
import java.util.Map;
20+
import java.util.TreeMap;
21+
22+
public class DeviceInfoFragment extends Fragment {
23+
24+
private MutableLiveData<TreeMap<String,String>> deviceData;
25+
private View v;
26+
27+
public DeviceInfoFragment() {}
28+
29+
@Override
30+
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
31+
this.v = inflater.inflate(R.layout.fragment_device_info, container, false);
32+
33+
deviceData = new MutableLiveData<>();
34+
deviceData.setValue(new TreeMap<>(new DeviceInfoMapComparator()));
35+
36+
deviceData.observe(getViewLifecycleOwner(), item -> {
37+
this.loadData(item);
38+
});
39+
40+
GadgetShellApi gsa = new GadgetShellApi();
41+
gsa.updateDeviceInfo(deviceData);
42+
43+
return v;
44+
}
45+
46+
private void loadData(Map<String, String> deviceData) {
47+
48+
LinearLayout list = this.v.findViewById(R.id.list_device_data);
49+
list.removeAllViews();
50+
51+
View viHead = getLayoutInflater().inflate(R.layout.row_device_info, null);
52+
53+
TextView tvHeadName = viHead.findViewById(R.id.name);
54+
tvHeadName.setText("Kernel Config Parameter");
55+
tvHeadName.setTypeface(null, Typeface.BOLD);
56+
57+
TextView tvHeadValue = viHead.findViewById(R.id.value);
58+
tvHeadValue.setText("Value");
59+
tvHeadValue.setTypeface(null, Typeface.BOLD);
60+
list.addView(viHead);
61+
62+
for (Map.Entry<String, String> entry : deviceData.entrySet()) {
63+
View vi = getLayoutInflater().inflate(R.layout.row_device_info, null);
64+
65+
TextView tvName = vi.findViewById(R.id.name);
66+
tvName.setText(entry.getKey().toUpperCase());
67+
68+
TextView tvValue = vi.findViewById(R.id.value);
69+
String value = entry.getValue();
70+
71+
String color;
72+
switch (value) {
73+
case "y":
74+
value = "Yes";
75+
color = "#008000";
76+
break;
77+
case "n":
78+
value = "No";
79+
color = "#ff0000";
80+
break;
81+
case "NOT_SET":
82+
value = "Not set";
83+
color = "#ff0000";
84+
break;
85+
default:
86+
color = "#000000";
87+
}
88+
89+
tvValue.setText(Html.fromHtml(String.format("<font color=%s>%s</font>", color, value), Html.FROM_HTML_MODE_LEGACY));
90+
91+
list.addView(vi);
92+
}
93+
}
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package net.tjado.usbgadget;
2+
3+
import java.util.Comparator;
4+
import java.util.TreeMap;
5+
6+
public class DeviceInfoMapComparator implements Comparator<String> {
7+
8+
@Override
9+
public int compare(String s1, String s2) {
10+
if (s1.equalsIgnoreCase("KERNEL_VERSION")) {
11+
return -1;
12+
} else if (s2.equalsIgnoreCase("KERNEL_VERSION")) {
13+
return 1;
14+
} else {
15+
return s1.compareTo(s2);
16+
}
17+
}
18+
}

app/src/main/java/net/tjado/usbgadget/ExecuteAsRootUtil.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static boolean canRunRootCommands()
5353
exitSu = false;
5454
Log.d("ROOT", "Can't get root access or denied by user");
5555
}
56-
else if (true == currUid.contains("uid=0"))
56+
else if (currUid.contains("uid=0"))
5757
{
5858
retval = true;
5959
exitSu = true;
@@ -85,11 +85,11 @@ else if (true == currUid.contains("uid=0"))
8585
return retval;
8686
}
8787

88-
public static final Pair<Boolean, String> execute(String command) {
88+
public static Pair execute(String command) {
8989
return execute(new String[]{ command });
9090
}
9191

92-
public static final Pair<Boolean, String> execute(String[] commands)
92+
public static Pair execute(String[] commands)
9393
{
9494
Boolean retval = false;
9595
String output = null;
@@ -139,11 +139,7 @@ public static final Pair<Boolean, String> execute(String[] commands)
139139
retval = ! error.equals("Permission denied");
140140
}
141141
}
142-
catch (IOException ex)
143-
{
144-
Log.w("ROOT", "Can't get root access", ex);
145-
}
146-
catch (SecurityException ex)
142+
catch (IOException | SecurityException ex)
147143
{
148144
Log.w("ROOT", "Can't get root access", ex);
149145
}

0 commit comments

Comments
 (0)