-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdevice.go
72 lines (58 loc) · 1.51 KB
/
device.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package ewelink
import (
"fmt"
"math/rand"
)
var (
iphoneModels = [3]string{"6,1", "6,2", "7,1"}
romVersions = [2]string{"10.0", "10.0.2"}
imeiFormat = "DF7425A0-%d-%d-9F5E-3BC9179E48FB"
)
// MobileDevice is the interface implemented by types that can deliver information about a mobile device.
type MobileDevice interface {
Model() string
Imei() string
Os() string
RomVersion() string
}
// IOSDevice holds the contextual information for a IOS device.
type IOSDevice struct {
model string
imei string
os string
romVersion string
}
func (i IOSDevice) String() string {
return fmt.Sprintf("%#v", i)
}
// Model returns the IOS model.
func (i IOSDevice) Model() string {
return i.model
}
// Imei returns the IOS IMEI.
func (i IOSDevice) Imei() string {
return i.imei
}
// Os returns the Os model.
func (i IOSDevice) Os() string {
return i.os
}
// RomVersion returns the Rom version.
func (i IOSDevice) RomVersion() string {
return i.romVersion
}
func newIOSDevice() *IOSDevice {
return &IOSDevice{model: getRandomIphoneModel(), imei: getRandomImei(), os: "iOS", romVersion: getRandomRomVersion()}
}
func getRandomIphoneModel() string {
return "iPhone" + iphoneModels[rand.Intn(len(iphoneModels))] // #nosec:G404
}
func getRandomRomVersion() string {
return romVersions[rand.Intn(len(romVersions))] // #nosec:G404
}
func getRandomImei() string {
const highest = 9999
const lowest = 1000
return fmt.Sprintf(imeiFormat,
getRandomNumber(lowest, highest), getRandomNumber(lowest, highest))
}