12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package system
- import (
- "context"
- "net"
- "os/exec"
- "strings"
- "time"
- )
- func EnableCompatibilityMode() {
- fixTimezone()
- fixDNSResolver()
- }
- func fixTimezone() {
- out, err := exec.Command("/system/bin/getprop", "persist.sys.timezone").Output()
- if err != nil {
- return
- }
- loc, err := time.LoadLocation(strings.TrimSpace(string(out)))
- if err != nil {
- return
- }
- time.Local = loc
- }
- func fixDNSResolver() {
-
-
-
- if net.DefaultResolver != nil {
- timeoutCtx, cancel := context.WithTimeout(context.Background(), time.Second)
- defer cancel()
- _, err := net.DefaultResolver.LookupHost(timeoutCtx, "google.com")
- if err == nil {
- return
- }
- }
-
-
- net.DefaultResolver = &net.Resolver{
- PreferGo: true,
- Dial: func(ctx context.Context, network, addr string) (net.Conn, error) {
- if addr == "127.0.0.1:53" || addr == "[::1]:53" {
- addr = "8.8.8.8:53"
- }
- var d net.Dialer
- return d.DialContext(ctx, network, addr)
- },
- }
- }
|