Write in front:
The main discussion in this series is to discuss with you the principle of Recovery mode localization display text and how to use the recovery_l10n provided by Google Tool to implement custom localized display text.
Guide:
First, let's discuss how the display of localized text in Recovery mode is implemented.
First look at two pictures, I believe a lot of people are very familiar with, the first is our factory set operation, shutdown restart into recovery mode after the interface, the second is through the key into the recovery mode, The main interface with the Options menu. Generally speaking normal users do not see the second interface, and in the first picture we see, under the green small robot has a line of characters, this line of characters is the key to this article.
Figure 1: Factory Reset - Erase data
Figure 2:Recovery mode main interface - Options Menu
In fact, the above line of text is not displayed in the form of characters, but instead of pictures, such as:
Figure 3: Localized text picture compositing
To add, this means that when the text information needs to be displayed in the Recovery mode, the text information of the corresponding language is intercepted from the above image according to the system language before entering Recovery mode. In other words, this information is not printed directly to the screen in C language.
The System language Library is not supported in Recovery mode, but the localization of text information in Recovery is still in sync with the current language environment of the main system. How does the recovery mode interact with the main system?
The main system interacts with the recovery through specific parameters in the command file.
FrameworkLayer
First look at the code snippet in Framework/base/core/java/android/os/recoverysystem.java:
/** Recovery_dir is a directory used to interact with RECOVERY systems, meaning that the main system interacts with the RECOVERY system through files. For more information, please refer to bootable/recovery/recovery.c. */private static file Recovery_dir = new file ("/cache/recovery"); private static File Command_file = new file (Recovery_dir, "COMMAND");/* Install and restart the specified update package */public static void Installpacka GE (context context, File PackageFile) throws IOException {String filename = Packagefile.getcanonicalpath ()/ /Get update package path ... final String filenamearg = "--update_package=" + filename;//pass the update package path as a parameter to the command file F inal String localearg = "--locale=" + Locale.getdefault (). toString ();//Localization Parameters Bootcommand (context, Filenamearg, Loca LEARG);//restart, and write parameters to the command file}/* erase data and cache partitions and restart */public static void Rebootwipeuserdata (context context, Boolean Shutdown, String reason) throws IOException {... String shutdownarg = null; if (shutdown) {shutdownarg = "--shutdown_after"; } String Reasonarg =Null if (! Textutils.isempty (reason)) {reasonarg = "--reason=" + sanitizearg (reason); Final String Localearg = "--locale=" + Locale.getdefault (). toString ();//localization parameter Bootcommand (context, Shutdow Narg, "--wipe_data", Reasonarg, Localearg); */* Erase data from the cache partition and restart */public static void Rebootwipecache (context context, String reason) throws IOException { ... final String localearg = "--locale=" + Locale.getdefault (). toString ();//localization parameter Bootcommand (context, "--wipe_cache", Reasonarg, Localearg); }/* reboot into recovery mode and specify the corresponding operation according to the specified parameters, such as installing updates, erasing user data, etc. */private static void Bootcommand (context context, String ... args) th Rows IOException {recovery_dir.mkdirs (); In case we need it command_file.delete (); In case it's not writable log_file.delete (); /* Write the specified parameter to the command file */FileWriter command = new FileWriter (command_file); try {for (String Arg:args) {iF (! Textutils.isempty (Arg)) {command.write (ARG); Command.write ("\ n"); }}} finally {Command.close (); }//Having written the command file, go ahead and reboot PowerManager pm= (PowerManager) context.getsystemser Vice (Context.power_service); Pm.reboot (Powermanager.reboot_recovery); throw new IOException ("Reboot failed (no permissions?)"); }
The above code tells us that the main system interacts with recovery in the form of a command_file file , performing different operations according to different command line parameters, such as system upgrade, factory reset, etc.
Recovery mode localized text display (I., framework layer)