An incorrect description of the source code Scene Analysis in Android

Source: Internet
Author: User

With the support and encouragement of everyone, the book "scenario analysis of the source code of Android system" was published. Lao Luo thanked everyone first. The content of this book comes from blog articles. After more than half a year of preparation, the first draft is formed. Before the official publication, the final draft was finally obtained after three typographical revisions. However, Lao Luo knows that the content in the book is not perfect, and there will always be many unsatisfactory aspects in addition to errors. Therefore, we welcome readers and domestic and foreign experts to point out to Lao Luo for improvement. In order to achieve this purpose, Luo especially lists the errors in this book.

Currently, the errors in the book are divided into three types: Pen mistakes, expression errors, and technical errors, which are represented by I, II, and III, respectively, the error page number is represented by the letter P.

1. Line 3 (I) of p53, lightpointer. cpp: printf ("destory lightclass object ."). The word destory is misspelled and should be destroy. Thanks to @ hengbo12345, 2012-10-26.

2. p147, the last 9th rows (I): set the value of the work member variable of a binder object to binder_workd_node. The word workd in the middle of the phrase binder_workd_node has a spelling error. an additional letter D should be binder_work_node. Thanks to @ brucechan1973, 2012-10-30.

3. p399, with 2nd rows and 4th rows (I): manactivity component. The spelling of man in the phrase manactivity is incorrect and should be changed to mainactivity. Thanks to @ herodie for pointing out that 2012-11-01.

4. p400, second and third (I): Action = "android. intent. action. main ", the action name and category name of the activity component to be started are" android. intent. action. main "and" android. intent. category. launcher ". The word "Main" should be all capitalized "Main. Thanks to @ herodie for pointing out that 2012-11-01.

5. P3, the last 2nd rows (III): sudo add-Apt-repository PPA: ferramrobert/Java. Because of the license issue (http://askubuntu.com/questions/109209/sun-java6-plugin-has-no-installation-candidate), the official Sun jdk6 cannot be released on Ubuntu, so now from the download source ferramrobert has not downloaded jdk6 to install, you can solve this problem by modifying the installation source, as shown below:

A. sudo add-Apt-repository "Deb http://us.archive.ubuntu.com/ubuntu/ hard Multiverse"

B. sudo apt-Get update

C. sudo apt-Get install sun-java6-jre sun-java6-plugin

D. sudo apt-Get install sun-java6-jdk

If a dependency package is not installed during installation, install the dependency package first. Thanks to @ and @ ++ for pointing out that 2012-11-05.

If the installation is still not successful, it is only manually installed, the official JDK: http://www.oracle.com/technetwork/java/javase/downloads/index.html

For more environment configuration information, see the official documentation: http://source.android.com/source/initializing.html

6. p350, followed by the second and last segment (I): The imemorybase class defines the memoryheapbase service interface and implements four member functions of the imemorybase interface. The spelling of imemorybase in these two sentences is incorrect and should be changed to imemoryheap. Thanks to @ sulliy, 2012-11-06.

7. p378, with a sequential number of 3rd rows (I): The imemoryfile interface defines two member functions: getfiledescriptor and setvalue. The phrase imemoryfile is written incorrectly and should be changed to imemoryservice. Thanks to @ hongbog_cd, 2012-11-14.

8. p155, last four paragraphs (iii): The member variables from_parent and to_parent of the binder_transaction struct are deviated. Should be changed:

---------------------------

The member variables from_parent and to_parent respectively describe another transaction on which a transaction is dependent and the next transaction to be processed by the target thread. Assume that thread a initiates a transaction T1, which must be handled by thread B. When thread B processes transaction T1, thread C needs to process transaction T2 first; when processing transaction T2, thread C needs thread a to process transaction T3 first. In this way, transaction T1 depends on transaction T2, and transaction T2 depends on transaction T3. Their relationships are as follows:

T1-> from_parent = t2; T2-> from_parent = T1; T2-> from_parent = T3; T3-> from_parent = t2;

For thread A, there are two transactions to be processed: T1 and T3. It must first process transaction T3 before processing transaction T1. Therefore, the relationship between transaction T1 and T3 is as follows:
T3-> to_parent = T1;

Consider this scenario: When thread C initiates the process T3 to which thread a belongs, the binder driver selects another thread D of the process to process the transaction, what will happen at this time? At this time, thread A will be in the idle waiting state and cannot do anything, because it must wait until thread D completes transaction T3 before it can continue to execute transaction T1. In this case, instead of leaving thread a idle, it is better to give transaction T3 to it for processing, so that thread D can process other transactions and improve the concurrency of the process.

Now, the key issue comes again-how does the binder driver know that thread a is the target process when distributing transaction T3 to the target process for processing, and waiting for the processing result of transaction T3?When thread B processes transaction T2, it puts transaction T2 at the frontend of its transaction stack transaction_stack. In this way, when thread B initiates transaction T3 for thread C to process, the binder driver can traverse down the transaction stack transaction_stack of thread B, until it finds that the target process of transaction T3 is equal to the target process of transaction T1, it will know that thread a is waiting for the processing result of transaction T3.When thread C processes transaction T2, it puts transaction T2 at the frontend of its transaction stack transaction_stack. In this way, when thread C initiates transaction T3 to process the process to which thread a belongs, the binder driver can traverse down the transaction stack transaction_stack of thread C, that is, it traverses down the member variable from_parent of transaction T2. At last, it will find that the target process of transaction T3 is equal to the target process of transaction T1, and transaction T1 is initiated by thread, at this time, it will know that thread a is waiting for the processing result of transaction T3.

--------------------------

PS: The member variables from_parent and to_parent of the binder_transaction struct can be understood by combining the code blocks from lines 31st to lines 40th of p256 and the code blocks from lines 77th to lines 79th of p267. This is a serious technical error, which causes readers to be confused and puzzled. Luo apologized and thanked the netizen @ hongbog_cd for pointing out that the error was 2012-11-14.

9. P20, 278th line code (III): temp = device_create (freg_class, null, Dev, "% s", freg_device_file_name ). The parameter called by this function is wrong, but it is normal to compile and work properly. The fourth parameter should be set to null, that is, temp = device_create (freg_class, null, Dev, null, "% s", freg_device_file_name ).

The prototype of the function device_create is: struct device * device_create (struct class * CLs, struct device * parent, dev_t devt, void * drvdata, const char * FMT ,...)

The fourth parameter, drvdata, indicates a private data, which can be any value or null. The fifth parameter is a formatted string used to describe the device name, and finally a variable parameter list, is used with the fifth parameter. In the above error call, the value of the parameter drvdata is equal to "% s", and the value of the parameter FMT is equal to freg_device_file_name, that is, "freg ". Because there is no variable parameter list and the FMT value does not contain formatting characters such as % s or % d, the device name set here is equal to "freg ".

Thanks to @ insoonior, 2012-11-14.

10. p240, penultimate, p696, penultimate (III ): the size of this kernel buffer is set by the binder library to 5th kb, and the size of the anonymous shared memory block created by lines of code is 16 kb. The unit to be expressed in these two statements is kilobytes, which should be expressed in KB. B In kb indicates bit, which is not used properly. Thanks to @ hongbog_cd for pointing out 2012-11-17.

11. p242, the last 3 rows (iii) of the last part of the last section: the code from the second row to the second row of the code will be in the list of mhandletoobject n to the second row (handle + 1-N) insert a handle_entry struct respectively. In the last 11th rows, the handle_entry struct corresponding to the handle value is returned to the caller. (Handle + 1-N) Description refers to the number of handle_entry struct to be inserted. Therefore, this statement must be expressed as starting from position N (handle + 1-N) handle_entry struct to the mhandletoobject list. Therefore, in this sentence, the positions from N to (handle + 1-N) should be changed to the positions from N to handle. Thanks to @ hongbog_cd, 2012-11-19.

12. p270, follow the first segment of 2nd rows and 3rd rows (I): it is equivalent to the struct flat_binder_objec described in section 5.1.1 above. One T is missing after flat_binder_objec. It should be changed to flat_binder_object. Thanks to @ hongbog_cd, 2012-11-19.

13. p420, 16th lines of code (III): APP = new processrecordlocked (null, info, processname ). Call the member function newprocessrecordlocked to create a processrecord object instead of directly creating a processrecordlocked object. Correspondingly, the next section of the description text "16th rows will create a processrecordlocked object based on the specified name and user ID" should be changed to processrecord. Thanks to @ Android fans for pointing out that 2012-12-05.

14. P26, followed by the second paragraph of line 2nd (I): these dynamic link library file commands must comply with certain specifications. The command in this sentence should be renamed. Thanks to @ Dongdong, a fan of the dead, for pointing out 2012-12-07.

15. p78, penultimate 1st and 2nd (I): Before analyzing this function, we first introduce three struct variables log_main, log_events, and log_radio, whose types are struct logger. In this sentence, the struct logger should be changed to struct logger_log. Thanks to @ Dongdong, a fan of the dead, for pointing out 2012-12-11.

16. p329, the fourth segment of the Order 2nd rows (I): When the memory of these small blocks is unlocked. The processing in this sentence should be changed to in. Thanks to @ nanfeng5651, 2012-12-13.

17. p497, followed by row 2, Row 2, and row 2 (I): Line 2 to line 2 code check whether there is a receiverdispatcher object RD with the broadcast receiver C as the keyword in the mreceivers OF THE loadedapk class. In this sentence, the broadcast receiver C should be changed to the broadcast receiver R. Thanks to @ nanfeng5651, 2012-12-19.

18. p528, followed by the first segment of the last two rows (I): the former is used to describe a vdn. shy. luo. a collection of articles. The latter is used to describe a vdn. shy. luo. article data, that is, a blog article entry. The two vdn. Shy. Luo. Article in this sentence should be changed to VND. Shy. Luo. Article, and the semicolon; should be changed to a comma ,. Thanks to @ nanfeng5651, 2012-12-20.

19. p528, the first two rows (I) in the last section: db_table and db_version are used to describe the name and version number of the SQLite database. In this sentence, db_table should be changed to db_name. Thanks to @ nanfeng5651, 2012-12-20.

20. p588, the third to bottom line 1st (I): The memobj parameter points to a Java-layer binder proxy object. In this sentence, memobj should be changed to memobj. Thanks to @ nanfeng5651, 2012-12-24.

21. p693, penultimate 1st rows and 2nd rows (I ): save the previously created windowstate object win in the application window list described by mwindows, a member variable of window management service window managerservice. In this sentence, window managerservice has an extra space and is changed to windowmanagerservice. Thanks to @ nanfeng5651, 2012-12-27.

22. p713, the third-to-last section, row 1st (I): The parameters sacnkey and keycode Save the scan code and keyboard code corresponding to the current keyboard event. In this sentence, the sacnkey should be changed to scancode. Thanks to @ nanfeng5651, 2012-12-28.

23. p716, 4 x 1st (I): The first case is to add a new keyboard event to the queue of the keyboard event to be split. In this sentence, the keyboard event queue to be split should be changed to the keyboard event queue to be distributed. Thanks to @ nanfeng5651, 2012-12-28.

24. p730, the fourth and fourth sections of the last sections, 2nd rows and 3rd rows (I): The second line of code gets a reference to it and stores it in the inputhandlerobjglobal variable. In this sentence, inputhandlerobjglobal should be changed to inputhandlerobjlocal. Thanks to @ nanfeng5651, 2013-01-03.

25. p768, penultimate (II): Implementation of the member function quit of the handlerthread class is as follows. The description in this section is incorrect and changed to: As shown in the previous section, the member function quit of the handlerthread class first obtains a logoff object created in the subthread, then call the member function quit of The logoff object to exit the subthread. The implementation of the member function quit of The logoff class is as follows. Thanks to @ nanfeng5651, 2013-01-04.

26. p771, the fifth to last segment (I): Finally, the workerqueue and threadfactory parameters are used to describe the Job Queue and thread creation factory of A threadpoolexecutor thread pool respectively. In this sentence, the workerqueue should be changed to workqueue. Thanks to @ nanfeng5651, 2013-01-04.

27. p807, followed by the second segment of row 3rd and row 4th (I): in this case, the resource access permissions of an application described by the PKG parameter are the same as those of the Linux users it shares. In this statement, the resource access permission should be changed to the resource access permission. Thanks to @ nanfeng5651, 2013-01-05.

28. p812, row 2nd and row 3rd (I) in the third segment of the order: If the row does not exist, the Code in line 22nd will convert the file/data/system/packages. the XML recommand is/data/system/packages-backup.xml. In this sentence, the duplicate command should be renamed. Thanks to @ nanfeng5651, 2013-01-05.

29. p828, the second penultimate row 1st (I): After this step is completed, this will return to the previous step 10. In this sentence, the response is changed to return. Thanks to @ nanfeng5651, 2013-01-05.

30. P20, 297th lines of code: printk (kern_alert "succedded to initialize freg device. \ n "). In this line of code, the succedded should be changed to succeeded. Thanks to @ five_cent_nicl, 2013-02-28.

31. p146, row 1st (I) in the third segment of the order: these work items may belong to a process or a thread in a process. In this sentence, it is also possible to change it. Thanks to @ zhouaijia8, 2013-04-07.

32. p172, first segment 2nd and second (I): Before adding the kernel buffer new_buffer to the idle buffer redblack tree of the target process Proc. In this sentence, the idle buffer should be changed to the idle kernel buffer. Thanks to @ zhouaijia8, 2013-04-07.

33. p225, the directory structure after the second text (I ):~ /Android/frameworks/base/CMD. The number of seconds after CMD is changed to cmds. Thanks to @ zhouaijia8, 2013-04-09.

34. p243, 1st rows (I) in the first segment: Return to the member function getcontextobject OF THE processstate class. In this sentence, the getcontextobject should be changed to getstrongproxyforhandle. Thanks to @ zhouaijia8, 2013-04-09.

35. p244, row 1st and line 2nd (I) in the third segment of the order: when the service process starts, it first registers the service components in the Service Manager. The service starting with this sentence should be changed to server. Thanks to @ zhouaijia8, 2013-04-09.

36. p276, 1st rows (I) in the fourth section of the order: Return to the svcmgr_handler function. In this sentence, svcmgr_handler should be changed to do_add_service. Thanks to @ zhouaijia8, 2013-04-10.

37. p340, 2nd rows and 3rd rows (I) in the fifth to last segment: If yes, the lru_del function is called in five rows to delete it from the global list ashmem_lru_list. In this sentence, the number of rows should be changed to 5th. Thanks to @ zhouaijia8 for pointing out 2013-04-11.

38. p513, follow the first segment of 2nd rows and 3rd rows (I): set the value of the member variable mbroadcastsscheduled OF THE activitymanagerservice class to true in row 11th. In this sentence, "true" should be changed to "false. Thanks to @ zhouaijia8, 2013-04-17.

39. p539, penultimate (I): The member functions of the articlesadapter class getarticlebyid and getarticlebypos obtain the specified blog article entries from the articlesprovider component based on the ID and position values of a blog article respectively. In this sentence, the member function should be changed to the member function. Thanks to @ zhouaijia8, 2013-04-17.

40. p573, row 3rd (I) in the second segment of the order: You can use this interface to access the blog article information in the artivlesproviders component. In this sentence, the artivlesproviders should be changed to articlesproviders. Thanks to @ zhouaijia8, 2013-04-17.

41. p573, row 1st and row 2nd (I) in the third section of the order: we will continue to analyze the process of accessing the blog article information of the artivlesprovider component running in another application process by using the mainactivity component. In this sentence, the artivlesproviders should be changed to articlesproviders. Thanks to @ zhouaijia8, 2013-04-17.

Lao Luo's Sina Weibo: http://weibo.com/shengyangluo. welcome to the attention!

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.