Skip to content

Commit aba82cf

Browse files
committed
add fa share support
1 parent 8a1798f commit aba82cf

File tree

7 files changed

+300
-258
lines changed

7 files changed

+300
-258
lines changed

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
- [x] support `fa shell`
1414
- [x] colorful logcat and filter with package name
1515
- [ ] install apk and auto click confirm
16-
- [.] check device health status
16+
- [ ] check device health status
1717
- [ ] show current app
1818
- [ ] unlock device
1919
- [ ] reset device state, clean up installed packages
2020
- [ ] show wlan (ip,mac,signal), enable and disable it
21-
- [ ] share device to public web
21+
- [x] share device to public web
22+
- [ ] fa share-server
2223
- [ ] install ipa support
24+
- [x] fahub service
2325

2426
## Install
2527
**For mac**
@@ -126,6 +128,23 @@ $ fa shell busybox ls
126128
$ adb shell /data/local/tmp/busybox ls
127129
```
128130
131+
### Share
132+
Share local device
133+
134+
```bash
135+
$ fa share
136+
# here will print a address, eg: tcp://max.labstack.me:8000
137+
```
138+
139+
In another machine use `adb connect`, for example the share addr is `max.labstack.me:8000`
140+
141+
```bash
142+
$ adb connect max.labstack.me:8000
143+
device connected
144+
$ adb -s max.labstack.me:8000 shell pwd
145+
/
146+
```
147+
129148
### Pidcat (logcat)
130149
Current implementation is wrapper of [pidcat.py](https://github.com/JakeWharton/pidcat)
131150
So use this feature, you need python installed.

adb/client.go

Lines changed: 0 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@ package adb
22

33
import (
44
"fmt"
5-
"io"
6-
"io/ioutil"
75
"net"
8-
"os"
96
"os/exec"
107
"strings"
118
"time"
129

13-
shellquote "github.com/kballard/go-shellquote"
1410
"github.com/pkg/errors"
1511
)
1612

@@ -127,137 +123,3 @@ func (c *Client) Device(descriptor DeviceDescriptor) *Device {
127123
func (c *Client) DeviceWithSerial(serial string) *Device {
128124
return c.Device(DeviceWithSerial(serial))
129125
}
130-
131-
// Device
132-
type Device struct {
133-
descriptor DeviceDescriptor
134-
client *Client
135-
}
136-
137-
func (d *Device) String() string {
138-
return d.descriptor.String()
139-
// return fmt.Sprintf("%s:%v", ad.serial, ad.State)
140-
}
141-
142-
func (d *Device) Serial() (serial string, err error) {
143-
return
144-
}
145-
146-
// OpenTransport is a low level function
147-
// Connect to adbd.exe and send <host-prefix>:transport and check OKAY
148-
// conn should be Close after using
149-
func (d *Device) OpenTransport() (conn *ADBConn, err error) {
150-
req := "host:" + d.descriptor.getTransportDescriptor()
151-
conn, err = d.client.roundTrip(req)
152-
if err != nil {
153-
return
154-
}
155-
conn.CheckOKAY()
156-
if conn.Err() != nil {
157-
conn.Close()
158-
}
159-
return conn, conn.Err()
160-
}
161-
162-
func (d *Device) OpenShell(cmd string) (rwc io.ReadWriteCloser, err error) {
163-
req := "host:" + d.descriptor.getTransportDescriptor()
164-
conn, err := d.client.roundTrip(req)
165-
if err != nil {
166-
return
167-
}
168-
conn.CheckOKAY()
169-
conn.EncodeString("shell:" + cmd)
170-
conn.CheckOKAY()
171-
if conn.Err() != nil {
172-
conn.Close()
173-
}
174-
return conn, conn.Err()
175-
}
176-
177-
func (d *Device) RunCommand(args ...string) (output string, err error) {
178-
cmd := shellquote.Join(args...)
179-
rwc, err := d.OpenShell(cmd)
180-
if err != nil {
181-
return
182-
}
183-
data, err := ioutil.ReadAll(rwc)
184-
if err != nil {
185-
return
186-
}
187-
return string(data), err
188-
}
189-
190-
type adbFileInfo struct {
191-
name string
192-
mode os.FileMode
193-
size uint32
194-
mtime time.Time
195-
}
196-
197-
func (f *adbFileInfo) Name() string {
198-
return f.name
199-
}
200-
201-
func (f *adbFileInfo) Size() int64 {
202-
return int64(f.size)
203-
}
204-
func (f *adbFileInfo) Mode() os.FileMode {
205-
return f.mode
206-
}
207-
208-
func (f *adbFileInfo) ModTime() time.Time {
209-
return f.mtime
210-
}
211-
212-
func (f *adbFileInfo) IsDir() bool {
213-
return f.mode.IsDir()
214-
}
215-
216-
func (f *adbFileInfo) Sys() interface{} {
217-
return nil
218-
}
219-
220-
func (d *Device) Stat(path string) (info os.FileInfo, err error) {
221-
req := "host:" + d.descriptor.getTransportDescriptor()
222-
conn, err := d.client.roundTrip(req)
223-
if err != nil {
224-
return
225-
}
226-
defer conn.Close()
227-
if err = conn.CheckOKAY(); err != nil {
228-
return
229-
}
230-
conn.EncodeString("sync:")
231-
conn.CheckOKAY()
232-
conn.WriteObjects("STAT", uint32(len(path)), path)
233-
234-
id, err := conn.ReadNString(4)
235-
if err != nil {
236-
return
237-
}
238-
if id != "STAT" {
239-
return nil, fmt.Errorf("Invalid status: %q", id)
240-
}
241-
adbMode, _ := conn.ReadUint32()
242-
size, _ := conn.ReadUint32()
243-
seconds, err := conn.ReadUint32()
244-
if err != nil {
245-
return nil, err
246-
}
247-
return &adbFileInfo{
248-
name: path,
249-
size: size,
250-
mtime: time.Unix(int64(seconds), 0).Local(),
251-
mode: fileModeFromAdb(adbMode),
252-
}, nil
253-
}
254-
255-
type PropValue string
256-
257-
func (p PropValue) Bool() bool {
258-
return p == "true"
259-
}
260-
261-
func (ad *Device) Properties() (props map[string]PropValue, err error) {
262-
return
263-
}

adb/device.go

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
package adb
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"io/ioutil"
7+
"net"
8+
"os"
9+
"time"
10+
11+
shellquote "github.com/kballard/go-shellquote"
12+
)
13+
14+
// Device
15+
type Device struct {
16+
descriptor DeviceDescriptor
17+
client *Client
18+
}
19+
20+
func (d *Device) String() string {
21+
return d.descriptor.String()
22+
// return fmt.Sprintf("%s:%v", ad.serial, ad.State)
23+
}
24+
25+
func (d *Device) Serial() (serial string, err error) {
26+
return
27+
}
28+
29+
// OpenTransport is a low level function
30+
// Connect to adbd.exe and send <host-prefix>:transport and check OKAY
31+
// conn should be Close after using
32+
func (d *Device) OpenTransport() (conn *ADBConn, err error) {
33+
req := "host:" + d.descriptor.getTransportDescriptor()
34+
conn, err = d.client.roundTrip(req)
35+
if err != nil {
36+
return
37+
}
38+
conn.CheckOKAY()
39+
if conn.Err() != nil {
40+
conn.Close()
41+
}
42+
return conn, conn.Err()
43+
}
44+
45+
func (d *Device) OpenShell(cmd string) (rwc io.ReadWriteCloser, err error) {
46+
req := "host:" + d.descriptor.getTransportDescriptor()
47+
conn, err := d.client.roundTrip(req)
48+
if err != nil {
49+
return
50+
}
51+
conn.CheckOKAY()
52+
conn.EncodeString("shell:" + cmd)
53+
conn.CheckOKAY()
54+
if conn.Err() != nil {
55+
conn.Close()
56+
}
57+
return conn, conn.Err()
58+
}
59+
60+
func (d *Device) RunCommand(args ...string) (output string, err error) {
61+
cmd := shellquote.Join(args...)
62+
rwc, err := d.OpenShell(cmd)
63+
if err != nil {
64+
return
65+
}
66+
data, err := ioutil.ReadAll(rwc)
67+
if err != nil {
68+
return
69+
}
70+
return string(data), err
71+
}
72+
73+
// ServeTCP acts as adbd(Daemon) for adb connect
74+
func (d *Device) ServeTCP(in net.Conn) {
75+
NewSession(in, d).Serve() // conn will be Closed inside
76+
}
77+
78+
type adbFileInfo struct {
79+
name string
80+
mode os.FileMode
81+
size uint32
82+
mtime time.Time
83+
}
84+
85+
func (f *adbFileInfo) Name() string {
86+
return f.name
87+
}
88+
89+
func (f *adbFileInfo) Size() int64 {
90+
return int64(f.size)
91+
}
92+
func (f *adbFileInfo) Mode() os.FileMode {
93+
return f.mode
94+
}
95+
96+
func (f *adbFileInfo) ModTime() time.Time {
97+
return f.mtime
98+
}
99+
100+
func (f *adbFileInfo) IsDir() bool {
101+
return f.mode.IsDir()
102+
}
103+
104+
func (f *adbFileInfo) Sys() interface{} {
105+
return nil
106+
}
107+
108+
func (d *Device) Stat(path string) (info os.FileInfo, err error) {
109+
req := "host:" + d.descriptor.getTransportDescriptor()
110+
conn, err := d.client.roundTrip(req)
111+
if err != nil {
112+
return
113+
}
114+
defer conn.Close()
115+
if err = conn.CheckOKAY(); err != nil {
116+
return
117+
}
118+
conn.EncodeString("sync:")
119+
conn.CheckOKAY()
120+
conn.WriteObjects("STAT", uint32(len(path)), path)
121+
122+
id, err := conn.ReadNString(4)
123+
if err != nil {
124+
return
125+
}
126+
if id != "STAT" {
127+
return nil, fmt.Errorf("Invalid status: %q", id)
128+
}
129+
adbMode, _ := conn.ReadUint32()
130+
size, _ := conn.ReadUint32()
131+
seconds, err := conn.ReadUint32()
132+
if err != nil {
133+
return nil, err
134+
}
135+
return &adbFileInfo{
136+
name: path,
137+
size: size,
138+
mtime: time.Unix(int64(seconds), 0).Local(),
139+
mode: fileModeFromAdb(adbMode),
140+
}, nil
141+
}
142+
143+
type PropValue string
144+
145+
func (p PropValue) Bool() bool {
146+
return p == "true"
147+
}
148+
149+
func (ad *Device) Properties() (props map[string]PropValue, err error) {
150+
return
151+
}

adb/reader.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,6 @@ func xorBytes(a, b []byte) []byte {
5454
return dst
5555
}
5656

57-
type AdbServer struct {
58-
version int
59-
mayPayload int
60-
authorized bool
61-
syncToken int
62-
remoteID int
63-
services map[string]string
64-
remoteAddress string
65-
token string
66-
signature string
67-
}
68-
6957
type PacketReader struct {
7058
C chan Packet
7159
reader io.Reader

0 commit comments

Comments
 (0)