├── Makefile ├── README.md ├── go.mod ├── go.sum ├── log └── log.go ├── main.go ├── module ├── META-INF │ └── com │ │ └── google │ │ └── android │ │ ├── update-binary │ │ └── updater-script ├── config.yaml ├── config │ └── normal.conf ├── customize.sh ├── module.prop └── service.sh ├── service └── service.go └── utils ├── config.go └── utils.go /Makefile: -------------------------------------------------------------------------------- 1 | NAME=acceleratedcharging 2 | CLANG ?= clang-14 3 | CFLAGS := -O2 -g -Wall -Werror $(CFLAGS) 4 | sign = $(shell sha256sum module/module.prop | sed "s/ module\/module\.prop//g") 5 | BUILD=CGO_ENABLED=0 go build -ldflags '-w -s' -ldflags '-X main.signature=$(sign)' 6 | all: build 7 | 8 | build: 9 | $(BUILD) -o module/bin/charge-current main.go 10 | cd module && zip -r ../build.zip * 11 | 12 | clean: 13 | rm -rf ./module/bin/charge-current -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Acceleratedcharging 2 | 3 | 充电时自动修改温控和强行修改充电电流实现满速充电 4 | 5 | 温度墙45度 6 | 7 | 喜欢就点个stars吧~ 8 | 9 | ## 配置文件 10 | 11 | 在模块目录下的config.yaml配置文件 12 | 如果不习惯yaml语法可以使用.json .toml格式来编辑配置文件(层级和key要保证一致) 13 | 14 | ## 构建 15 | 16 | ```bash 17 | git clone https://github.com/ModuleList/acceleratedcharging.git && cd acceleratedcharging 18 | go mod download 19 | make 20 | ``` 21 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/ModuleList/acceleratedcharging 2 | 3 | require github.com/spf13/viper v1.18.2 4 | 5 | require ( 6 | github.com/fsnotify/fsnotify v1.7.0 // indirect 7 | github.com/hashicorp/hcl v1.0.0 // indirect 8 | github.com/magiconair/properties v1.8.7 // indirect 9 | github.com/mitchellh/mapstructure v1.5.0 // indirect 10 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 11 | github.com/sagikazarmark/locafero v0.4.0 // indirect 12 | github.com/sagikazarmark/slog-shim v0.1.0 // indirect 13 | github.com/sourcegraph/conc v0.3.0 // indirect 14 | github.com/spf13/afero v1.11.0 // indirect 15 | github.com/spf13/cast v1.6.0 // indirect 16 | github.com/spf13/pflag v1.0.5 // indirect 17 | github.com/subosito/gotenv v1.6.0 // indirect 18 | go.uber.org/atomic v1.9.0 // indirect 19 | go.uber.org/multierr v1.9.0 // indirect 20 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect 21 | golang.org/x/sys v0.15.0 // indirect 22 | golang.org/x/text v0.14.0 // indirect 23 | gopkg.in/ini.v1 v1.67.0 // indirect 24 | gopkg.in/yaml.v3 v3.0.1 // indirect 25 | ) 26 | 27 | go 1.21.5 28 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 2 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= 4 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 5 | github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= 6 | github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= 7 | github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= 8 | github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= 9 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 10 | github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 11 | github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= 12 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= 13 | github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= 14 | github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= 15 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 16 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 17 | github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= 18 | github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= 19 | github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= 20 | github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= 21 | github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= 22 | github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= 23 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 24 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= 25 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 26 | github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= 27 | github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= 28 | github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= 29 | github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= 30 | github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= 31 | github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= 32 | github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= 33 | github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= 34 | github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= 35 | github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= 36 | github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= 37 | github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= 38 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 39 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 40 | github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= 41 | github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= 42 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 43 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 44 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 45 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 46 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 47 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 48 | github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= 49 | github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 50 | github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= 51 | github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= 52 | go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= 53 | go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= 54 | go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= 55 | go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= 56 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= 57 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= 58 | golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= 59 | golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 60 | golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= 61 | golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= 62 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 63 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= 64 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 65 | gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= 66 | gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= 67 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 68 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 69 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 70 | -------------------------------------------------------------------------------- /log/log.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | logs "log" 7 | "os" 8 | ) 9 | 10 | var logger *logs.Logger 11 | 12 | func Init() { 13 | writer1 := &bytes.Buffer{} 14 | writer2 := os.Stdout 15 | writer3, err := os.OpenFile("run.log", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755) 16 | if err != nil { 17 | logs.Fatalf("create file log.txt failed: %v", err) 18 | } 19 | logger = logs.New(io.MultiWriter(writer1, writer2, writer3), "", logs.Lshortfile|logs.LstdFlags) 20 | } 21 | 22 | func Info(text string) { 23 | logger.Printf("[info]:%s", text) 24 | } 25 | 26 | func Debug(text string) { 27 | logger.Printf("[debug]:%s", text) 28 | } 29 | 30 | func Warn(text error) { 31 | logger.Panic("[warning]:%s", text) 32 | } 33 | 34 | func Error(text error) { 35 | logger.Fatal("[error]:%s", text) 36 | } 37 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "github.com/ModuleList/acceleratedcharging/log" 6 | "github.com/ModuleList/acceleratedcharging/utils" 7 | s "github.com/ModuleList/acceleratedcharging/service" 8 | ) 9 | 10 | var service bool 11 | var command string 12 | var signature string 13 | 14 | func main() { 15 | log.Init() 16 | utils.Verify("module.prop", signature) 17 | flag.BoolVar(&service, "service", false, "Whether to enable background running") 18 | flag.StringVar(&command, "command", "", "Execute modification of fast charging[modify]/recovery fast charging[recovery] settings") 19 | flag.Parse() 20 | 21 | 22 | if ! utils.IfRoot() { 23 | log.Info("请使用root用户运行") 24 | return 25 | } 26 | if service { 27 | s.Start() 28 | } 29 | if command == "modify" { 30 | utils.Modify() 31 | } else if command == "recovery" { 32 | utils.Recovery() 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /module/META-INF/com/google/android/update-binary: -------------------------------------------------------------------------------- 1 | #!/sbin/sh 2 | 3 | ################# 4 | # Initialization 5 | ################# 6 | 7 | umask 022 8 | 9 | # echo before loading util_functions 10 | ui_print() { echo "$1"; } 11 | 12 | require_new_magisk() { 13 | ui_print "********************************" 14 | ui_print " 请使用 Magisk v24.0+! 安装" 15 | ui_print "********************************" 16 | exit 1 17 | } 18 | 19 | ######################### 20 | # Load util_functions.sh 21 | ######################### 22 | 23 | OUTFD=$2 24 | ZIPFILE=$3 25 | 26 | mount /data 2>/dev/null 27 | 28 | [ -f /data/adb/magisk/util_functions.sh ] || require_new_magisk 29 | . /data/adb/magisk/util_functions.sh 30 | [ $MAGISK_VER_CODE -lt 24000 ] && require_new_magisk 31 | 32 | install_module 33 | exit 0 34 | -------------------------------------------------------------------------------- /module/META-INF/com/google/android/updater-script: -------------------------------------------------------------------------------- 1 | #MAGISK 2 | -------------------------------------------------------------------------------- /module/config.yaml: -------------------------------------------------------------------------------- 1 | temp: 2 | #开启动态移除温控 3 | dynamic: true 4 | #温度墙 电池温度如果高于此值关闭快充 450 = 45.0度 5 | max: 480 6 | #最大充电电流 7 | speed: "300000000" 8 | #进行替换的温控配置文件 9 | file: [ 10 | "thermal-4k.conf", 11 | "thermal-arvr.conf", 12 | "thermal-camera.conf", 13 | "thermal-class0.conf", 14 | "thermal-hp-mgame.conf", 15 | "thermal-hp-normal.conf", 16 | "thermal-mgame.conf", 17 | "thermal-navigation.conf", 18 | "thermal-nolimits.conf", 19 | "thermal-normal.conf", 20 | "thermal-per-camera.conf", 21 | "thermal-per-class0.conf", 22 | "thermal-per-navigation.conf", 23 | "thermal-per-normal.conf", 24 | "thermal-per-video.conf", 25 | "thermal-phone.conf", 26 | "thermal-tgame.conf", 27 | "thermal-video.conf", 28 | "thermal-videochat.conf", 29 | ] 30 | 31 | #每轮监听间隔时长 过短会导致功耗增加 单位:秒 32 | sleep: 120 33 | #顾名思义 34 | debug: false 35 | #进行替换的温控配置文件 36 | configfile: "/data/adb/modules/acceleratedcharging/config/normal.conf" -------------------------------------------------------------------------------- /module/config/normal.conf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModuleList/acceleratedcharging/4f2073ee56fb56c290be029b8e614fe083c6f951/module/config/normal.conf -------------------------------------------------------------------------------- /module/customize.sh: -------------------------------------------------------------------------------- 1 | #!/system/bin/sh 2 | 3 | if [ ! "$KSU" ];then 4 | ui_print "- Magisk ver: $MAGISK_VER" 5 | if [[ $($MAGISK_VER | grep "kitsune") ]] || [[ $($MAGISK_VER | grep "delta") ]]; then 6 | ui_print "*********************************************************" 7 | ui_print "Magisk delta and magisk kitsune are not supported" 8 | echo "">remove 9 | abort "*********************************************************" 10 | fi 11 | 12 | ui_print "- Magisk version: $MAGISK_VER_CODE" 13 | if [ "$MAGISK_VER_CODE" -lt 26301 ]; then 14 | ui_print "*********************************************************" 15 | ui_print "! Please use Magisk alpha 26301+" 16 | abort "*********************************************************" 17 | fi 18 | elif [ "$KSU" ];then 19 | ui_print "- KernelSU version: $KSU_KERNEL_VER_CODE (kernel) + $KSU_VER_CODE (ksud)" 20 | if ! [ "$KSU_KERNEL_VER_CODE" ] || [ "$KSU_KERNEL_VER_CODE" -lt 11413 ]; then 21 | ui_print "*********************************************************" 22 | ui_print "! KernelSU; version is too old!" 23 | ui_print "! Please update KernelSU to latest version" 24 | abort "*********************************************************" 25 | fi 26 | else 27 | ui_print "! Unknown Module Manager" 28 | ui_print "$(set)" 29 | abort 30 | fi 31 | function mk_thermal_folder(){ 32 | if [ ! -d "/data/vendor/thermal" ];then 33 | mkdir -p /data/vendor/thermal/config 34 | fi 35 | chattr -R -i -a /data/vendor/thermal 36 | chmod 0771 /data/vendor/thermal 37 | chmod 0771 /data/vendor/thermal/config 38 | chmod -R 644 /data/vendor/thermal/config 39 | chown -R root:system /data/vendor/thermal 40 | } 41 | 42 | 43 | #避免冻结电量和性能 44 | function enable_miui_powerkeeper(){ 45 | if test "$( pm list package | grep -w 'com.miui.powerkeeper' | wc -l)" -gt "0" ;then 46 | pm enable com.miui.powerkeeper >/dev/null 2>&1 47 | pm unsuspend com.miui.powerkeeper >/dev/null 2>&1 48 | pm unhide com.miui.powerkeeper >/dev/null 2>&1 49 | pm install-existing --user 0 com.miui.powerkeeper >/dev/null 2>&1 50 | fi 51 | } 52 | 53 | #重新启用电量与性能 54 | function call_cloud_conf_release(){ 55 | pm enable com.miui.powerkeeper/com.miui.powerkeeper.cloudcontrol.CloudUpdateReceiver >/dev/null 2>&1 56 | pm enable com.miui.powerkeeper/com.miui.powerkeeper.cloudcontrol.CloudUpdateJobService >/dev/null 2>&1 57 | pm enable com.miui.powerkeeper/com.miui.powerkeeper.ui.CloudInfoActivity >/dev/null 2>&1 58 | pm enable com.miui.powerkeeper/com.miui.powerkeeper.statemachine.PowerStateMachineService >/dev/null 2>&1 59 | am broadcast --user 0 -a update_profile com.miui.powerkeeper/com.miui.powerkeeper.cloudcontrol.CloudUpdateReceiver >/dev/null 2>&1 60 | } 61 | 62 | enable_miui_powerkeeper 63 | call_cloud_conf_release 64 | mk_thermal_folder 65 | 66 | set_perm_recursive "$MODPATH" 0 0 0777 0777 67 | set_perm "$MODPATH/bin/charge-current" 0 0 0777 0777 68 | -------------------------------------------------------------------------------- /module/module.prop: -------------------------------------------------------------------------------- 1 | id=acceleratedcharging 2 | name=充电加速 3 | version=v24 4 | versionCode=2400 5 | author=heinu 6 | description=配置文件在模块目录下的config.yaml文件 -------------------------------------------------------------------------------- /module/service.sh: -------------------------------------------------------------------------------- 1 | #!/system/bin/sh 2 | MODDIR=${0%/*} 3 | 4 | until [ $(getprop init.svc.bootanim) = "stopped" ] ; do 5 | sleep 5 6 | done 7 | 8 | 9 | nohup "${MODDIR}/bin/charge-current" -service & 10 | -------------------------------------------------------------------------------- /service/service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "strings" 5 | "strconv" 6 | "github.com/ModuleList/acceleratedcharging/log" 7 | "github.com/ModuleList/acceleratedcharging/utils" 8 | ) 9 | 10 | func Start() { 11 | status := false 12 | recovery := false 13 | log.Info("=====开始监听=====") 14 | for true { 15 | batterydata := utils.Shell("dumpsys battery") 16 | temperature, _ := strconv.Atoi(utils.Shell("cat /sys/class/power_supply/battery/temp")) 17 | 18 | if strings.Contains(batterydata, "status: 2") || strings.Contains(batterydata, "AC powered: true") && ! strings.Contains(batterydata, "level: 100") { 19 | if utils.GetConfig("debug").(bool) { 20 | log.Debug("监听到已进入充电状态") 21 | log.Debug(strconv.FormatBool(status)) 22 | } 23 | if temperature < utils.GetConfig("temp.max").(int) { 24 | recovery = false 25 | } 26 | 27 | if ! status && ! recovery { 28 | status = true 29 | recovery = false 30 | utils.Modify() 31 | log.Info("已修改快充设置") 32 | } else { 33 | if temperature >= utils.GetConfig("temp.max").(int) && status && ! recovery { 34 | status = false 35 | recovery = true 36 | utils.Recovery() 37 | log.Info("温度超过限制 已恢复快充设置") 38 | } 39 | } 40 | } else { 41 | if status { 42 | utils.Recovery() 43 | log.Info("已拔出充电器或已满电") 44 | } 45 | if utils.GetConfig("debug").(bool) { 46 | log.Debug("未在充电") 47 | } 48 | } 49 | if utils.GetConfig("debug").(bool) { 50 | log.Debug("=====已完成一轮检测 休眠" + strconv.Itoa(utils.GetConfig("sleep").(int)) +"秒=====") 51 | } 52 | utils.Sleep(utils.GetConfig("sleep").(int)) 53 | 54 | } 55 | } -------------------------------------------------------------------------------- /utils/config.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "github.com/spf13/viper" 5 | "github.com/ModuleList/acceleratedcharging/log" 6 | ) 7 | 8 | 9 | func GetConfig(key string) interface{} { 10 | viper.SetConfigName("config") 11 | viper.AddConfigPath(".") 12 | 13 | err := viper.ReadInConfig() 14 | if err != nil { 15 | log.Info("读取温配置文件失败") 16 | log.Error(err) 17 | } 18 | return viper.Get(key) 19 | } 20 | func GetThermalFile() []string { 21 | var ret []string 22 | file := GetConfig("temp.file") 23 | for _, val := range file.([]interface{}) { 24 | ret = append(ret, val.(string)) 25 | } 26 | return ret 27 | } -------------------------------------------------------------------------------- /utils/utils.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "github.com/ModuleList/acceleratedcharging/log" 5 | "fmt" 6 | "os" 7 | "io" 8 | "os/exec" 9 | "strings" 10 | "time" 11 | "sync" 12 | "io/ioutil" 13 | // "strconv" 14 | "crypto/sha256" 15 | ) 16 | var File string; 17 | var allFileNames []string = GetThermalFile(); 18 | 19 | func Verify(file string, verify string) { 20 | f, err := os.Open(file) 21 | if err != nil { 22 | log.Error(err) 23 | } 24 | defer f.Close() 25 | 26 | h := sha256.New() 27 | if _, err := io.Copy(h, f); err != nil { 28 | log.Error(err) 29 | } 30 | 31 | if fmt.Sprintf("%x", h.Sum(nil)) != verify { 32 | log.Info("签名校验失败") 33 | os.Exit(1) 34 | } 35 | } 36 | 37 | func fileExists(filename string) bool { 38 | _, err := os.Stat(filename) 39 | return !os.IsNotExist(err) 40 | } 41 | 42 | func IfRoot() bool { 43 | if os.Geteuid() == 0 { 44 | return true 45 | } 46 | return false 47 | } 48 | 49 | func Shell(command string) string { 50 | var cmd *exec.Cmd 51 | cmd = exec.Command("su", "-c", command) 52 | output, err := cmd.CombinedOutput() 53 | if err != nil { 54 | return err.Error() // 返回错误信息 55 | } 56 | return strings.TrimSpace(string(output)) 57 | } 58 | 59 | func Restart() { 60 | processes := []string{"mi_thermald", "thermal-engine", "thermald"} 61 | for _, p := range processes { 62 | Shell("stop " + p) 63 | Shell("start " + p) 64 | } 65 | Shell("chmod -R 0771 /data/vendor/thermal") 66 | Shell("chown -R root:system /data/vendor/thermal") 67 | Shell("chcon -R u:object_r:vendor_data_file:s0 /data/vendor/thermal") 68 | } 69 | 70 | func Sleep(times int) { //硬核休眠 71 | sum := 1 72 | for sum <= times { 73 | sum = sum + 1 74 | time.Sleep(time.Second); 75 | } 76 | } 77 | func Modify() { //删除温控 78 | speed := GetConfig("temp.speed").(string) 79 | if fileExists("/sys/class/power_supply/battery/constant_charge_current") { 80 | File = "/sys/class/power_supply/battery/constant_charge_current" 81 | } else { 82 | File = "/sys/class/power_supply/battery/constant_charge_current_max" 83 | } 84 | err := ioutil.WriteFile("/data/adb/modules/acceleratedcharging/speed", []byte(speed+"\n"), 644) 85 | if err != nil { 86 | log.Info("写入最大充电电流文件失败") 87 | log.Error(err) 88 | } 89 | Shell("mount /data/adb/modules/acceleratedcharging/speed "+ File) 90 | 91 | if GetConfig("temp.dynamic").(bool) { 92 | var wg sync.WaitGroup 93 | wg.Add(len(allFileNames)) 94 | normal, err := ioutil.ReadFile(GetConfig("configfile").(string)) 95 | if err != nil { 96 | log.Error(err) 97 | } 98 | for _, FileNames := range allFileNames { 99 | go func(FileNames string) { 100 | defer wg.Done() 101 | err := ioutil.WriteFile("/data/vendor/thermal/config/" + FileNames, normal, 440) 102 | if err != nil { 103 | log.Error(err) 104 | } 105 | Shell("dos2unix /data/vendor/thermal/config/" + FileNames) 106 | 107 | }(FileNames) 108 | } 109 | 110 | wg.Wait() 111 | Restart() 112 | } 113 | } 114 | func Recovery() { 115 | if fileExists("/sys/class/power_supply/battery/constant_charge_current") { 116 | File = "/sys/class/power_supply/battery/constant_charge_current" 117 | } else { 118 | File = "/sys/class/power_supply/battery/constant_charge_current_max" 119 | } 120 | Shell("rm -rf /data/vendor/thermal/config") 121 | Shell("mkdir -p /data/vendor/thermal/config") 122 | Shell("umount " + File) 123 | Restart() 124 | } --------------------------------------------------------------------------------