mirror of
https://github.com/MengMengCode/VoCat.git
synced 2026-08-13 03:13:43 +08:00
- Added `automatic_tasks.go` and `automatic_tasks_test.go` for backend logic and testing of automatic tasks. - Created `automatic_tasks_test.go` to validate task claiming and deletion behavior. - Developed `AutomaticTasksPage.tsx` for frontend management of automatic tasks, including task creation, editing, and execution. - Integrated device and eSIM profile selection for task configuration. - Implemented automatic task scheduling and retry logic in the backend.
67 lines
2.0 KiB
Go
67 lines
2.0 KiB
Go
package device
|
|
|
|
import (
|
|
_ "embed"
|
|
"encoding/json"
|
|
"strings"
|
|
)
|
|
|
|
// The offline table is generated by scripts/update-carriers.py from Android's
|
|
// versioned carrier ID database, with the previous global table retained as a
|
|
// fallback for PLMNs that Android does not yet catalogue.
|
|
//
|
|
//go:embed mccmnc.json
|
|
var carrierDatabaseJSON []byte
|
|
|
|
type carrierDatabase struct {
|
|
Carriers map[string][]string `json:"c"`
|
|
}
|
|
|
|
var globalCarrierDatabase = func() carrierDatabase {
|
|
var database carrierDatabase
|
|
if err := json.Unmarshal(carrierDatabaseJSON, &database); err != nil {
|
|
panic("device: invalid embedded MCC/MNC database: " + err.Error())
|
|
}
|
|
return database
|
|
}()
|
|
|
|
// CarrierForPLMN returns the offline carrier display name and ISO alpha-2
|
|
// country/territory code for a numeric five- or six-digit PLMN.
|
|
func CarrierForPLMN(plmn string) (name, countryCode string, ok bool) {
|
|
plmn = strings.TrimSpace(plmn)
|
|
if !decimalDigits(plmn, 5, 6) {
|
|
return "", "", false
|
|
}
|
|
entry, ok := globalCarrierDatabase.Carriers[plmn]
|
|
if !ok || len(entry) == 0 || strings.TrimSpace(entry[0]) == "" {
|
|
return "", "", false
|
|
}
|
|
name = strings.TrimSpace(entry[0])
|
|
if len(entry) > 1 {
|
|
countryCode = strings.ToUpper(strings.TrimSpace(entry[1]))
|
|
}
|
|
return name, countryCode, true
|
|
}
|
|
|
|
// CarrierForIMSI resolves the home PLMN carried by an IMSI. MNCs may contain
|
|
// either two or three digits, so prefer an exact six-digit database match and
|
|
// then fall back to the five-digit form. This avoids treating the first three
|
|
// subscriber digits as a three-digit MNC for networks such as 234-33.
|
|
func CarrierForIMSI(imsi string) (plmn, name, countryCode string, ok bool) {
|
|
imsi = strings.TrimSpace(imsi)
|
|
if !decimalDigits(imsi, 5, 20) {
|
|
return "", "", "", false
|
|
}
|
|
for _, length := range []int{6, 5} {
|
|
if len(imsi) < length {
|
|
continue
|
|
}
|
|
candidate := imsi[:length]
|
|
carrier, country, found := CarrierForPLMN(candidate)
|
|
if found {
|
|
return candidate, carrier, country, true
|
|
}
|
|
}
|
|
return "", "", "", false
|
|
}
|