@@ -8,6 +8,9 @@ ARCH=$(getprop ro.product.cpu.abi)
88CSC=$( getprop ro.boot.sales_code)
99TOOL=" $MODDIR /libs/$ARCH /csc_tool"
1010
11+ # ===== Debug 开关 =====
12+ DEBUG=0 # 0=关闭 1=开启
13+
1114# --- 辅助函数 ---
1215
1316# 统一日志输出
@@ -16,98 +19,123 @@ log() {
1619 echo " $1 "
1720}
1821
19- # 清理过大日志 (保留最后 1000 行)
22+ # Debug 日志
23+ debug () {
24+ [ " $DEBUG " = " 1" ] && log " [DEBUG] $1 "
25+ }
26+
27+ # 每次启动重新生成日志
2028prepare_log () {
21- if [ -f " $LOG_FILE " ]; then
22- echo " $( tail -n 1000 " $LOG_FILE " ) " > " $LOG_FILE "
23- fi
24- log " === 模块启动: CSC=$CSC , ARCH=$ARCH ==="
29+ : > " $LOG_FILE "
30+ log " === 模块启动: CSC=$CSC , ARCH=$ARCH , DEBUG=$DEBUG ==="
2531}
2632
2733# 动态寻找文件路径
2834find_file () {
2935 local filename=$1
30- # 锁定在 /optics 分区中寻找当前销售代码 (CSC) 的配置
31- local path=$( find " /optics/configs/carriers/$CSC " -name " $filename " 2> /dev/null | head -n 1)
36+ local base=" /optics/configs/carriers/$CSC "
37+
38+ debug " 查找文件: $filename (base=$base )"
39+
40+ local path=$( find " $base " -name " $filename " 2> /dev/null | head -n 1)
41+
3242 if [ -f " $path " ]; then
43+ debug " 找到文件: $path "
3344 echo " $path "
3445 return 0
3546 fi
47+
48+ debug " 未找到文件: $filename "
3649 return 1
3750}
3851
3952# 安全挂载函数
4053safe_mount () {
4154 local src=$1
4255 local target=$2
56+
57+ debug " 准备挂载: $src -> $target "
58+
4359 if [ ! -f " $src " ] || [ ! -f " $target " ]; then
4460 log " 错误: 挂载源或目标不存在 ($src -> $target )"
4561 return 1
4662 fi
4763
48- # 清理旧挂载 (容错)
4964 umount -l " $target " > /dev/null 2>&1
50-
5165 mount --bind " $src " " $target "
52- if [ $? -eq 0 ]; then
66+
67+ local ret=$?
68+
69+ if [ $ret -eq 0 ]; then
5370 log " 成功挂载: $target "
71+ debug " mount 返回值: $ret "
5472 return 0
5573 else
5674 log " 失败: 无法挂载 $target "
75+ debug " mount 返回值: $ret "
5776 return 1
5877 fi
5978}
6079
61- # 处理单个文件逻辑 (Decode -> Patch -> Encode -> Mount)
80+ # 处理单个文件逻辑
6281process_feature_file () {
63- local label=$1 # 标识符: csc, ff, carrier
64- local filename=$2 # 原始文件名
65- local config_name=$3 # 用户 JSON 配置名
82+ local label=$1
83+ local filename=$2
84+ local config_name=$3
6685
6786 log " 正在处理 $label ($filename )..."
68-
87+
6988 # 1. 寻找原始文件
7089 local origin_path=$( find_file " $filename " )
90+ local decoded_file=" $MODDIR /decoded_$label "
91+
7192 if [ -z " $origin_path " ]; then
72- # 特殊处理 floating_feature,它通常在 /etc/
7393 if [ " $label " = " ff" ] && [ -f " /etc/floating_feature.xml" ]; then
7494 origin_path=" /etc/floating_feature.xml"
95+ debug " 使用 fallback floating_feature: $origin_path "
96+ cp " $origin_path " " $decoded_file "
7597 else
7698 log " 跳过: 未找到原始文件 $filename "
7799 return
78100 fi
79101 fi
80102
81- # 2. 解码 (如果是加密的 XML/JSON)
82- local decoded_file=" $MODDIR /decoded_$label "
103+ debug " origin_path=$origin_path "
104+
105+ # 2. 解码
106+
107+ debug " 执行 decode: $TOOL --decode $origin_path $decoded_file "
108+
83109 $TOOL --decode " $origin_path " " $decoded_file " >> " $LOG_FILE " 2>&1
84-
85- # 如果解码失败(可能是明文),则直接拷贝
86- if [ ! -f " $decoded_file " ]; then
87- cp " $origin_path " " $decoded_file "
88- fi
89110
90- # 3. 应用补丁 (Patching + CSC_SORT)
111+ # 3. Patch
91112 local user_config=" $CONFIG_PATH /$config_name "
92113 local patched_file=" $MODDIR /patched_$label "
114+
115+ debug " user_config=$user_config "
116+
93117 if [ -f " $user_config " ]; then
118+ debug " 执行 patch"
94119 $TOOL --patch " $decoded_file " " $user_config " " $patched_file " >> " $LOG_FILE " 2>&1
95120 else
96121 log " 注意: 未找到用户配置 $config_name ,将保持原始状态"
97122 cp " $decoded_file " " $patched_file "
98123 fi
99124
100- # 4. 编码 (重新加密)
125+ # 4. Encode
101126 local final_file=" $MODDIR /final_$label "
127+
128+ debug " 执行 encode"
102129 $TOOL --encode " $patched_file " " $final_file " >> " $LOG_FILE " 2>&1
103-
130+
104131 # 5. 挂载
105- # 优先挂载加密后的 final_file,如果不存在则尝试挂载 patched_file (明文)
106132 if [ -f " $final_file " ]; then
133+ debug " 使用加密文件挂载"
107134 safe_mount " $final_file " " $origin_path "
108135 restorecon " $origin_path "
109136 else
110137 log " 注意: 加密失败,尝试挂载明文文件"
138+ debug " 使用明文挂载"
111139 safe_mount " $patched_file " " $origin_path "
112140 restorecon " $origin_path "
113141 fi
@@ -117,19 +145,16 @@ process_feature_file() {
117145
118146prepare_log
119147
120- # 检查工具是否存在
148+ debug " MODDIR=$MODDIR "
149+ debug " CONFIG_PATH=$CONFIG_PATH "
150+ debug " TOOL=$TOOL "
151+
121152if [ ! -f " $TOOL " ]; then
122153 log " 致命错误: 未在 $TOOL 找到核心工具"
123- # 回退到尝试使用老的二进制(如果存在)或退出
124154fi
125155
126- # 处理 CSC
127156process_feature_file " csc" " cscfeature.xml" " csc.json"
128-
129- # 处理 Carrier
130157process_feature_file " carrier" " customer_carrier_feature.json" " carrier.json"
131-
132- # 处理 Floating Feature
133158process_feature_file " ff" " floating_feature.xml" " ff.json"
134159
135- log " === 处理完成 ==="
160+ log " === 处理完成 ==="
0 commit comments