Android.bp
// 定义C++可执行二进制模块
cc_binary {
name: "bugreport", // 目标二进制文件名:bugreport
srcs: ["bugreport.cpp"], // 源文件列表:bugreport.cpp(即用户之前提供的C代码)
cflags: ["-Wall", "-Werror"], // 编译选项:开启所有警告,并将警告视为错误
shared_libs: ["libcutils"], // 依赖的共享库:Android C工具库
}
bugreport.cpp
// 引入标准输入输出库,用于fprintf等函数
#include <stdio.h>
/**
* @brief 主函数 - 输出弃用警告信息
* @details 当调用旧版flat bugreport命令时,此程序会被执行,用于提醒用户:
* 1. 纯文本格式的bugreport已被弃用
* 2. 推荐使用新的bugreportz工具生成压缩格式的报告
* 3. 提供了主机端和设备端的具体使用方法
* @return 始终返回0,表示程序正常退出
*/
int main() {
// 打印顶部分隔线,增强警告信息的视觉显著性
fprintf(stderr,
"=============================================================================\n");
// 警告1:说明纯文本(非压缩)bugreport已被弃用
fprintf(stderr, "WARNING: Flat (text file, non-zipped) bugreports are deprecated.\n");
// 警告2:建议用户生成压缩格式的bugreport
fprintf(stderr, "WARNING: Please generate zipped bugreports instead.\n");
// 警告3:说明在主机端应使用adb bugreport命令并指定zip文件名
fprintf(stderr, "WARNING: On the host use: adb bugreport filename.zip\n");
// 警告4:说明在设备端应直接使用bugreportz命令
fprintf(stderr, "WARNING: On the device use: bugreportz\n");
// 警告5:提示bugreportz会输出文件名,供adb pull命令使用
fprintf(stderr, "WARNING: bugreportz will output the filename to use with adb pull.\n");
// 打印底部分隔线,并添加空行使信息更清晰
fprintf(stderr,
"=============================================================================\n\n\n");
// 程序正常结束,返回0
return 0;
}
// =================================== 总结 ===================================
//
// 本程序是一个弃用警告工具,主要功能:
// 1. 当用户尝试使用旧的flat bugreport命令时,拦截并显示警告信息
// 2. 通过标准错误流(stderr)输出多行警告,提示用户采用新的bugreportz方式
// 3. 提供了清晰的使用指引:主机端用"adb bugreport",设备端用"bugreportz"
// 4. 程序逻辑简单,仅输出警告信息后正常退出,不执行任何实际操作
// 5. 使用场景:Android系统开发中,保持工具链的向后兼容性过渡
//
// ============================================================================
示例
# bugreport
=============================================================================
WARNING: Flat (text file, non-zipped) bugreports are deprecated.
WARNING: Please generate zipped bugreports instead.
WARNING: On the host use: adb bugreport filename.zip
WARNING: On the device use: bugreportz
WARNING: bugreportz will output the filename to use with adb pull.
=============================================================================