Android6.0 Recovery之后创建读写文件

来源:互联网 发布:淘宝网刷收藏 编辑:程序博客网 时间:2024/06/16 02:45

Recovery之后会创建”/data/misc/unlocked.txt” 并写入“true”

android6.0\bootable\recovery\recovery.cpp
static const char *UI_UNLOCK_FILE = “/data/misc/unlocked.txt”;
char* unlock = “true”;

// clear the recovery command and prepare to boot a (hopefully working) system,
// copy our log file to cache as well (for the system to read), and
// record any intent we were asked to communicate back to the system.
// this function is idempotent: call it as many times as you like.
static void
finish_recovery(const char *send_intent) {
// By this point, we’re ready to return to the main system…
if (send_intent != NULL) {
FILE *fp = fopen_path(INTENT_FILE, “w”);
if (fp == NULL) {
LOGE(“Can’t open %s\n”, INTENT_FILE);
} else {
fputs(send_intent, fp);
check_and_fclose(fp, INTENT_FILE);
}
}

// Save the locale to cache, so if recovery is next started up// without a --locale argument (eg, directly from the bootloader)// it will use the last-known locale.if (locale != NULL) {    LOGI("Saving locale \"%s\"\n", locale);    FILE* fp = fopen_path(LOCALE_FILE, "w");    fwrite(locale, 1, strlen(locale), fp);    fflush(fp);    fsync(fileno(fp));    check_and_fclose(fp, LOCALE_FILE);}

//ADD BY SONG START===============================
if (unlock != NULL) {
LOGI(“Saving Launcher Unlocked \”%s\”\n”, unlock);
FILE* fpl = fopen_path(UI_UNLOCK_FILE, “w”); //打开文件,文件不存在创建文件。
fwrite(unlock, 1, strlen(unlock), fpl); //写文件
fflush(fpl); //
fsync(fileno(fpl));
check_and_fclose(fpl, UI_UNLOCK_FILE);
chmod(UI_UNLOCK_FILE, 0755); //修改文件权限
chown(UI_UNLOCK_FILE, 1000, 1000); // system system //修改文件所属 system:system
}
//ADD BY SONG END =================================

copy_logs();// Reset to normal system boot so recovery won't cycle indefinitely.struct bootloader_message boot;memset(&boot, 0, sizeof(boot));set_bootloader_message(&boot);// Remove the command file, so recovery won't repeat indefinitely.if (ensure_path_mounted(COMMAND_FILE) != 0 ||    (unlink(COMMAND_FILE) && errno != ENOENT)) {    LOGW("Can't unlink %s\n", COMMAND_FILE);}ensure_path_unmounted(CACHE_ROOT);sync();  // For good measure.

}

原创粉丝点击