Checkpoint from VS Code for cloud agent session

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
RainySY
2026-04-29 20:08:41 +08:00
parent 2fe35e5a35
commit 2c2c0273ff
9 changed files with 2517 additions and 2397 deletions

98
tools/core/app_utils.sh Normal file
View File

@@ -0,0 +1,98 @@
#!/system/bin/sh
# module: app_utils.sh
Process_Information() {
dumpsys activity processes | awk -v key="$1" -v user="$user" 'function getUserFromUid(uid){return int(uid/100000)} /^ *user #[0-9]+ uid=/ {if($0 ~ /ISOLATED uid=[0-9]+/){uid="";pid="";pkg="";next} if(pkg!="" && uid!="" && pid!=""){if((key=="" || pkg==key) && (user=="" || getUserFromUid(uid)==user)){print pid}} uid="";pid="";pkg=""; if($0 ~ /uid=/ && uid==""){tmp=$0; sub(/^.*uid=/,"",tmp); sub(/ .*/,"",tmp); uid=tmp}} /packageList=\{/ {tmp=$0; sub(/^.*packageList=\{/,"",tmp); sub(/\}.*/,"",tmp); pkg=tmp} /pid=/ {tmp=$0; sub(/^.*pid=/,"",tmp); sub(/ .*/,"",tmp); pid=tmp} END {if(pkg!="" && uid!="" && pid!=""){if((key=="" || pkg==key) && (user=="" || getUserFromUid(uid)==user)){print pid}}}'
}
Background_application_list() {
[[ $activity != false ]] && {
if [[ $Background_apps_ignore = true || $1 = debug ]]; then
unset Backstage
#獲取後台
Backstage="$(dumpsys activity activities | awk -v uid="$user" '/ActivityRecord\{/{split($4,a,"/"); user=$3; pkg=a[1]; if(user~/^u[0-9]+$/ && pkg!~/\//){sub(/^u/,"",user); if(uid=="" || user==uid) if(!seen[user","pkg]++) print pkg}}')"
if [[ $Backstage = "" ]]; then
Backstage="$(am stack list | awk -v uid="$user" '/taskId/&&!/unknown/{split($2,a,"/"); pkg=a[1]; user="unknown"; for(i=1;i<=NF;i++) if($i~/^userId=/){split($i,b,"="); user=b[2]; break} if(uid==""|user==uid) if(!seen[pkg]++) print pkg}')"
[[ $Backstage = "" ]] && {
echoRgb "獲取當前後台應用失敗" "0" && unset Backstage
}
fi
fi
}
}
kill_app() {
process_Information="$(Process_Information "$name2")"
if [[ $name2 != bin.mt.plus && $name2 != com.termux && $name2 != bin.mt.plus.canary ]]; then
if [[ $process_Information != "" ]]; then
am force-stop --user "$user" "$name2" &>/dev/null
echo "$process_Information" | xargs -r kill -9
pkill -9 -f "$name2$|$name2[:/_]"
#killall -9 "$name2" &>/dev/null
#am kill "$name2" &>/dev/null
echoRgb "殺死$name1進程"
fi
fi
}
disable_verify() {
#禁用apk驗證
settings put global verifier_verify_adb_installs 0 2>/dev/null
#禁用安裝包驗證
settings put global package_verifier_enable 0 2>/dev/null
#未知來源
settings put secure install_non_market_apps 1 2>/dev/null
#關閉play安全校驗
if [[ $(settings get global package_verifier_user_consent 2>/dev/null) != -1 ]]; then
settings put global package_verifier_user_consent -1 2>/dev/null
settings put global upload_apk_enable 0 2>/dev/null
echoRgb "PLAY安全驗證為開啟狀態已被腳本關閉防止apk安裝失敗" "3"
fi
# 設定檔案路徑
FILE="/data/data/com.android.vending/shared_prefs/finsky.xml"
if [[ -f $FILE ]]; then
# 提取當前的 auto_update_enabled 值
CURRENT_VALUE="$(sed -n '/<boolean name="auto_update_enabled" /s/.*value="\([^"]*\)".*/\1/p' "$FILE")"
if [[ $CURRENT_VALUE = true ]]; then
sed -i '/<boolean name="auto_update_enabled" /s/value="true"/value="false"/' "$FILE"
[[ $(sed -n '/<boolean name="auto_update_enabled" /s/.*value="\([^"]*\)".*/\1/p' "$FILE") = false ]] && echoRgb "play自動更新已關閉" "3"
echoRgb "殺死 Google Play 商店..."
am force-stop com.android.vending
else
if [[ $CURRENT_VALUE = "" ]]; then
sed -i '/<\/map>/i \ <boolean name="auto_update_enabled" value="false" />' "$FILE"
[[ $(sed -n '/<boolean name="auto_update_enabled" /s/.*value="\([^"]*\)".*/\1/p' "$FILE") = false ]] && echoRgb "auto_update_enabled已插入false,play自動更新已關閉" "3"
echoRgb "殺死 Google Play 商店..."
am force-stop com.android.vending
else
[[ $CURRENT_VALUE != false ]] && echoRgb "無法識別play auto_update_enabled當前$CURRENT_VALUE值" "0"
fi
fi
fi
}
restore_permissions () {
echoRgb "恢復權限"
appops reset --user "$user" "$name2" &>/dev/null
true_permissions="$(jq -r 'to_entries[] | select(.value.permissions != null) | .value.permissions | to_entries | map(select(.value | startswith("true")) | .key) | join(" ")' "$app_details")"
false_permissions="$(jq -r 'to_entries[] | select(.value.permissions != null) | .value.permissions | to_entries | map(select(.value | startswith("false")) | .key) | join(" ")' "$app_details")"
Set_Ops_permissions="$(jq -r '.[] | select(.permissions != null).permissions | to_entries | map(.value | split(" ")) | map(select(.[1] != "-1")) | map(.[1:]) | flatten | join(" ")' "$app_details")"
[[ $true_permissions != "" ]] && {
Set_true_Permissions "$name2" "$true_permissions"
[[ $? != 0 ]] && echo_log "設置允許權限"
}
[[ $false_permissions != "" ]] && {
Set_false_Permissions "$name2" "$false_permissions"
[[ $? != 0 ]] && echo_log "設置拒絕權限"
}
[[ $Set_Ops_permissions != "" ]] && {
Set_Ops "$name2" "$Set_Ops_permissions"
[[ $? != 0 ]] && echo_log "設置ops權限"
}
}
#分區佔用信息
partition_info() {
unset Skip
Occupation_status="$(df -B1 "${1%/*}" | sed -n 's|% /.*|%|p' | awk '{print $(NF-1)}')"
Filesize2="$(size "$Filesize")"
echo " -$2大小:$Filesize2 剩餘大小:$(size "$Occupation_status")"
[[ $Filesize != "" ]] && [[ $(echo "$Filesize > $Occupation_status" | bc) -eq 1 ]] && echoRgb "$2備份大小將超出rom可用大小" "0" && Skip=1
Occupation_status="$(df -h "${Backup%/*}" | sed -n 's|% /.*|%|p' | awk '{print $(NF-1),$(NF)}')"
}