-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils_android_id.go
61 lines (50 loc) · 1.11 KB
/
utils_android_id.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
package go_android_utils
import (
"encoding/base64"
"encoding/hex"
"math/rand"
"strconv"
)
func NewAndroidID() *AndroidID {
result := &AndroidID{}
_ = result.Random()
return result
}
func (id *AndroidID) FromHex(idStr string) error {
result, err := strconv.ParseUint(idStr, 16, 64)
if err == nil {
id.SetID(result)
}
return err
}
func (id *AndroidID) Random() error {
b := make([]byte, 8)
_, err := rand.Read(b)
if err == nil {
err = id.FromHex(hex.EncodeToString(b))
}
return err
}
func (id *AndroidID) ToDecimalString() string {
return strconv.FormatUint(id.GetID(), 10)
}
func (id *AndroidID) ToHexString() string {
return strconv.FormatUint(id.GetID(), 16)
}
func (id *AndroidID) ToBase64String() string {
hByte, _ := hex.DecodeString(id.ToHexString())
return base64.StdEncoding.EncodeToString(hByte)
}
func (id *AndroidID) Equals(comparison *AndroidID) bool {
return id.GetID() == comparison.GetID()
}
func (id *AndroidID) IsNull() bool {
return id.GetID() < 1
}
func (id *AndroidID) GetID() uint64 {
result := id.Id
return result
}
func (id *AndroidID) SetID(idN uint64) {
id.Id = idN
}