Skip to content

Commit 931f866

Browse files
committed
feat: 实现三态切换功能并优化日志系统
- 新增auto文件支持,实现关闭PPS/固定PPS/自动识别三态切换 - 替换自定义日志宏为android_logger,提升日志可靠性 - 优化文件监控逻辑,处理同时修改free和auto文件的情况 - 更新module.prop描述,显示当前工作模式状态 - 调整PD验证逻辑,区分固定PPS和自动识别模式 - 升级依赖版本,包括libc和android_logger等 - 修改版本号为v1.5.0-beta,准备测试发布
1 parent dd9c026 commit 931f866

20 files changed

Lines changed: 540 additions & 326 deletions

Cargo.lock

Lines changed: 83 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ edition = "2024"
55
authors = ["Seyud"]
66

77
[dependencies]
8-
libc = "0.2"
8+
libc = "0.2.177"
99
anyhow = "1.0.100"
1010
thiserror = "2.0.17"
11+
log = "0.4.28"
12+
android_logger = "0.15.1"
1113

1214
[profile.release]
1315
opt-level = 3

module/action.sh

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
11
#!/system/bin/sh
2+
23
MODDIR=${0%/*}
34
FREE_FILE="$MODDIR/free"
4-
if [ ! -f "$FREE_FILE" ]; then
5-
echo "1" > "$FREE_FILE"
6-
echo "文件不存在,已创建并开启PPS支持"
5+
AUTO_FILE="$MODDIR/auto"
6+
7+
if [ -f "$FREE_FILE" ]; then
8+
FREE_VALUE=$(cat "$FREE_FILE" | tr -d '[:space:]')
79
else
8-
CURRENT=$(<"$FREE_FILE")
9-
case "$CURRENT" in
10-
0)
11-
echo "1" > "$FREE_FILE"
12-
echo "开启PPS支持"
13-
;;
14-
1)
15-
echo "0" > "$FREE_FILE"
16-
echo "关闭PPS支持"
17-
;;
18-
*)
19-
echo "1" > "$FREE_FILE"
20-
echo "内容无效,已重置为PPS支持"
21-
;;
22-
esac
10+
FREE_VALUE="0"
2311
fi
12+
13+
AUTO_EXISTS=0
14+
if [ -f "$AUTO_FILE" ]; then
15+
AUTO_EXISTS=1
16+
fi
17+
18+
# 三种状态循环切换
19+
if [ "$FREE_VALUE" = "0" ] && [ "$AUTO_EXISTS" = "0" ]; then
20+
# 状态1: free=0, 无auto → 状态2: free=1, 无auto
21+
printf "1" > "$FREE_FILE"
22+
echo "固定PPS支持"
23+
elif [ "$FREE_VALUE" = "1" ] && [ "$AUTO_EXISTS" = "0" ]; then
24+
# 状态2: free=1, 无auto → 状态3: free=1, 有auto
25+
touch "$AUTO_FILE"
26+
echo "开启协议自动识别"
27+
else
28+
# 状态3: free=1, 有auto → 状态1: free=0, 无auto
29+
printf "0" > "$FREE_FILE"
30+
rm -f "$AUTO_FILE"
31+
echo "关闭PPS支持"
32+
fi
33+
2434
sleep 0.3
2535
sleep 0.27
26-
sleep 1

module/bin/FreePPS

-8.53 KB
Binary file not shown.

module/module.prop

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
id=FreePPS
22
name=FreePPS
3-
version=v1.5.0-alpha
4-
versionCode=20251019
3+
version=v1.5.0-beta
4+
versionCode=20251020
55
author=酷安@瓦力喀
66
description=启用米系设备的公版 PPS 支持。(感谢“酷安@低线阻狂魔”、“酷安@花橋桥”提供方案)
77
updateJson=https://gitee.com/Seyud/FreePPS/raw/master/Update.json

module/service.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ wait_until_login() {
2121
wait_until_login
2222

2323
if [ -f "$MODDIR/debug" ]; then
24-
nohup $MODDIR/bin/FreePPS &> "$MODDIR/FreePPS.log" &
24+
nohup $MODDIR/bin/FreePPS >/dev/null 2>&1 &
25+
FREEPPS_PID=$!
26+
sleep 0.2
27+
nohup nice -n 10 logcat -b main --pid=$FREEPPS_PID -s FreePPS:V > "$MODDIR/FreePPS.log" 2>&1 &
2528
else
26-
nohup $MODDIR/bin/FreePPS &>/dev/null &
29+
nohup $MODDIR/bin/FreePPS >/dev/null 2>&1 &
2730
fi

src/common.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
pub mod constants;
22
pub mod error;
3-
pub mod logger;
43
pub mod utils;
54

65
pub use constants::*;

src/common/constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub const IN_DELETE: u32 = 0x00000200;
1212
#[cfg(unix)]
1313
pub const MODULE_BASE_PATH: &str = "/data/adb/modules/FreePPS";
1414
pub const FREE_FILE: &str = "/data/adb/modules/FreePPS/free";
15+
pub const AUTO_FILE: &str = "/data/adb/modules/FreePPS/auto";
1516
pub const DISABLE_FILE: &str = "/data/adb/modules/FreePPS/disable";
1617
#[cfg(unix)]
1718
pub const MODULE_PROP: &str = "/data/adb/modules/FreePPS/module.prop";

src/common/logger.rs

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/common/utils.rs

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,4 @@
11
use std::thread;
2-
use std::time::{SystemTime, UNIX_EPOCH};
3-
4-
// 获取当前时间戳(YYYY-MM-DD HH:MM:SS.mmm 格式)
5-
pub fn get_timestamp() -> String {
6-
// 获取当前 Unix 时间戳
7-
let now = SystemTime::now()
8-
.duration_since(UNIX_EPOCH)
9-
.unwrap_or_default();
10-
11-
let total_secs = now.as_secs();
12-
let millis = now.subsec_millis();
13-
14-
// 尝试获取本地时区偏移(优先读取Android系统时区)
15-
let timezone_offset = get_timezone_offset();
16-
let adjusted_secs = total_secs.saturating_add(timezone_offset as u64);
17-
18-
// 计算真实的日期时间(基于1970年1月1日,考虑时区)
19-
// 处理闰年和平年
20-
let mut remaining_secs = adjusted_secs;
21-
let mut year = 1970;
22-
23-
// 计算年份
24-
loop {
25-
let days_in_year = if is_leap_year(year) { 366 } else { 365 };
26-
let secs_in_year = days_in_year * 24 * 3600;
27-
28-
if remaining_secs >= secs_in_year {
29-
remaining_secs -= secs_in_year;
30-
year += 1;
31-
} else {
32-
break;
33-
}
34-
}
35-
36-
// 计算一年中的第几天
37-
let day_of_year = remaining_secs / (24 * 3600);
38-
let secs_today = remaining_secs % (24 * 3600);
39-
40-
// 计算时分秒
41-
let hour = secs_today / 3600;
42-
let minute = (secs_today % 3600) / 60;
43-
let second = secs_today % 60;
44-
45-
// 计算月份和日期
46-
let (month, day) = get_month_day_from_year_day(year, day_of_year);
47-
48-
format!(
49-
"{:04}-{:02}-{:02} {:02}:{:02}:{:02}.{:03}",
50-
year, month, day, hour, minute, second, millis
51-
)
52-
}
53-
54-
/// 获取本地时区偏移(秒)
55-
fn get_timezone_offset() -> i64 {
56-
// 方法1: 尝试读取Android系统时区文件
57-
if let Ok(content) = std::fs::read_to_string("/system/usr/share/zoneinfo/tzdata") {
58-
// 简化处理:如果是中国时区,返回+8小时
59-
if content.contains("Asia/Shanghai") || content.contains("CST") {
60-
return 8 * 3600;
61-
}
62-
}
63-
64-
// 方法2: 尝试读取环境变量
65-
if let Ok(tz) = std::env::var("TZ")
66-
&& (tz.contains("Asia/Shanghai") || tz.contains("Hongkong"))
67-
{
68-
return 8 * 3600;
69-
}
70-
71-
// 方法3: 尝试读取系统属性(Android常用)
72-
if let Ok(output) = std::process::Command::new("getprop")
73-
.arg("persist.sys.timezone")
74-
.output()
75-
&& output.status.success()
76-
{
77-
let timezone = String::from_utf8_lossy(&output.stdout);
78-
if timezone.contains("Asia/Shanghai") || timezone.contains("Hongkong") {
79-
return 8 * 3600;
80-
}
81-
}
82-
83-
// 默认返回UTC+8(中国标准时间)
84-
8 * 3600
85-
}
86-
87-
/// 判断是否为闰年
88-
fn is_leap_year(year: u64) -> bool {
89-
year.is_multiple_of(4) && (!year.is_multiple_of(100) || year.is_multiple_of(400))
90-
}
91-
92-
/// 根据年份和一年中的第几天,计算月份和日期
93-
fn get_month_day_from_year_day(year: u64, day_of_year: u64) -> (u8, u8) {
94-
let days_in_month = if is_leap_year(year) {
95-
[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
96-
} else {
97-
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
98-
};
99-
100-
let mut remaining_days = day_of_year;
101-
let mut month = 1;
102-
103-
for &days in &days_in_month {
104-
if remaining_days < days as u64 {
105-
return (month, (remaining_days + 1) as u8);
106-
}
107-
remaining_days -= days as u64;
108-
month += 1;
109-
}
110-
111-
(12, 31) // 最后一天
112-
}
1132

1143
/// 获取当前线程的名称
1154
pub fn get_current_thread_name() -> String {

0 commit comments

Comments
 (0)