Android does not open the shared SDcard feature, built-in SD card prefabricated resources, delete resources, restore factory settings restore

Source: Internet
Author: User
Tags sprintf

When there is a built-in SD card and the shared SDcard feature is not turned on, some customer resources need to be provisioned in the SD card.
These resources end user visible and can also be deleted. After the resource has been deleted by user, the factory reset function is performed and the provisioned resources need to be restored.


1. Pre-provision the same resources to user-invisible partitions, such as/system.
Create a directory under Alps\vendor\mediatek\project_name\artifacts\out\target\product\your_project_name\system\,
The prefab resources are placed in this directory, and the system image has prefabricated resources after the new build.

2. Recovery end, copy resources to SD card.
At the end of the recovery main function, which is to restore the factory settings, or after the SD card upgrade, through the custom function, the specific file copy to the SD card.

Int
Main (int argc, char **argv) {
...
Add this custom function to recover all files under a specific folder, including subdirectories, here is the case:/data/app/--->/sdcard/app/
Recovery_restore_special ("/sdcard/app", "/data/app");

Otherwise, get ready to boot the main system ...
Finish_recovery (send_intent);
Ui->print ("rebooting...\n");
Property_set (Android_rb_property, "reboot,");
return exit_success;
}

int recovery_restore_special (char *des_dir_path, char *src_dir_path)
{
int ret= 0;
printf ("\n\n++%s ++\n\n", __func__);
printf ("src dir:%s\n", src_dir_path);
printf ("Des dir:%s\n", des_dir_path);
Mount Path
ret = ensure_path_mounted (Src_dir_path);
if (Ret < 0) {
printf ("Mount Src dir error:%s\n", Src_dir_path);
return-1;
}
printf ("mount:%s ret=%d\n", Src_dir_path, ret);

ret = ensure_path_mounted (Des_dir_path);
if (Ret < 0) {
printf ("Mount des dir error:%s\n", Des_dir_path);
Ensure_path_unmounted (Src_dir_path);
return-1;
}
printf ("mount:%s ret=%d\n", Des_dir_path, ret);
Restore dir and file
ret = Restore_dir_file (Des_dir_path, Src_dir_path);
printf ("Restore ret=%d\n", ret);

Unmount
Ensure_path_unmounted (Src_dir_path);
Ensure_path_unmounted (Des_dir_path);
printf ("\n\n--%s--\n\n", __func__);
return 0;
}

static int Restore_dir_file (char *des_dir_path, char *src_dir_path)
{
int ret= 0;
dir* dir_des = NULL;
dir* dir_src = NULL;
struct dirent* de_des = NULL;
struct dirent* de_src = NULL;
FILE * fdes = NULL;
FILE * fsrc = NULL;
Char src_file_path[256] = {0};
Char des_file_path[256] = {0};
Char buf[256] = {0};
int name_len = 0;
int size = 0, File_len = 0;
printf ("\n\nenter,%s \ n \ nthe", __func__);
printf ("src dir:%s\n", src_dir_path);
printf ("Des dir:%s\n", des_dir_path);
Open dir
DIR_SRC = Opendir (Src_dir_path);
if (dir_src = = NULL) {
printf ("Open src dir error:%s\n", Src_dir_path);
return-1;
}
Dir_des = Opendir (Des_dir_path);
if (dir_des = = NULL) {
ret =-1;
if (errno = = ENOENT) {
printf ("Des dir not exist:%s\n", Des_dir_path);
ret = mkdir (Des_dir_path, (S_irwxu | S_irwxg | S_IRWXO));
}
if (Ret < 0) {
Closedir (DIR_SRC);
printf ("Open des dir error:%s\n", Des_dir_path);
return-1;
}
else {
printf ("MkDir des dir:%s\n", des_dir_path);
Dir_des = Opendir (Des_dir_path);
}
}
printf ("dir_src=%d, dir_des=%d\n", DIR_SRC, Dir_des);
while ((de_src = Readdir (dir_src)) = NULL) {
printf ("D_name:%s\n", de_src->d_name);

if (De_src->d_type = = Dt_dir) {
Name_len = strlen (de_src->d_name);

Skip "." and ":" Entries
if ((Name_len = = 1 && de_src->d_name[0] = = '. ') | |
(Name_len = = 2 && de_src->d_name[0] = = '. ' && de_src->d_name[1] = = '. ')) {
Continue
}
else {
src dir path Append the folder ' s D_name
sprintf (Src_file_path, "%s/%s", Src_dir_path, De_src->d_name);
printf ("src dir path:%s\n", Src_file_path);
Des dir path Append the folder ' s D_name
sprintf (Des_file_path, "%s/%s", Des_dir_path, De_src->d_name);
printf ("Des dir path:%s\n", Des_file_path);
printf ("---entry sub dir to restore\n");
ret = Restore_dir_file (Des_file_path, Src_file_path);
printf ("Sub dir restore ret=%d\n", ret);
}
}
else if (De_src->d_type = = Dt_reg) {
Open src File
sprintf (Src_file_path, "%s/%s", Src_dir_path, De_src->d_name);
printf ("Src_file_path:%s\n", Src_file_path);
FSRC = fopen (Src_file_path, "R");
printf ("fsrc=%d\n", FSRC);
Create des file
sprintf (Des_file_path, "%s/%s", Des_dir_path, De_src->d_name);
printf ("Des_file_path:%s\n", Des_file_path);
Fdes = Fopen_path (Des_file_path, "w");
printf ("fdes=%d\n", fdes);
Read from src file, write to des file
file_len= 0;
while (!feof (FSRC)) {
Size = fread (buf, sizeof (char), sizeof (BUF), FSRC);
Fwrite (buf, sizeof (char), size, fdes);
memset (buf, 0, sizeof (BUF));
File_len + = size;
}
Fflush (Fdes);
printf ("%s:file_len=%d\n", De_src->d_name, File_len);

Close File
Fclose (FSRC);
Fclose (Fdes);
}
}
Close Dir
Closedir (DIR_SRC);
Closedir (Dir_des);

printf ("\n\nexit,%s \ n \ nthe", __func__);
return 0;
}

Android does not open the shared SDcard feature, built-in SD card prefabricated resources, delete resources, restore factory settings restore

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.