Android "cannot view ***. Please release some mobile phone memory"

Source: Internet
Author: User

 

Android "cannot be viewed ***. Please release some mobile phone memory"

(Mprc) porting Android 2.1)

After downloading the (ucweb) software in a browser, click Install. the dialog box is displayed, "You cannot view the information ***. Please release some mobile phone memory ".

Check through logcat: "couldn't clear application caches"

The error information found in the following source code is printed from the freestorage () function in packagemanagerservice. Java (frameworks/base/services/Java/COM/Android/Server.

 

Retcode = minstaller. freecache (freestoragesize); <br/> If (retcode <0) log. W (TAG, "couldn't clear application caches "); 

 

Follow up step by step

Freecache ()-> execute ()-> transaction ()-> connect ()

A local socket is instantiated in the connect () function for inter-process communication. So who is it communicating?

 Private Boolean connect () {<br/> If (msocket! = NULL) {<br/> return true; <br/>}< br/> log. I (TAG, "Connecting... "); <br/> // connect to the server for the first time <br/> try {<br/> msocket = new localsocket (); <br/> localsocketaddress address = new localsocketaddress (<br/> "installd", localsocketaddress. namespace. reserved); <br/> msocket. connect (Address); <br/> min = msocket. getinputstream (); <br/> mout = msocket. getoutputstream (); <br/>}catch (ioexception ex) {<br/> disconnect (); <br/> return false; <br/>}< br/> return true; <br/>} 

 

The original packagemanagerservice communicates with the installd daemon enabled in init. RC.

 

We can infer the source of the error:

The cmd "freecache" sent by the client service does not receive a response from the server daemon.

Check the source code of installd in installd. C.

Struct cmdinfo cmds [] ={< br/> {"ping", 0, do_ping}, <br/> {"Install", 3, do_install }, <br/> {"dexopt", 3, do_dexopt}, <br/> {"movedex", 2, do_move_dex}, <br/> {"rmdex", 1, do_rm_dex}, <br/> {"Remove", 1, do_remove}, <br/> {"freecache", 1, do_free_cache}, <br/> {"rmcache ", 1, do_rm_cache}, <br/> {"Protect", 2, do_protect}, <br/> {"getsize", 3, do_get_size }, <br/> {"rmuserdata", 1, do_rm_user_data}, <br/> }; 

We can find the processing function of the response command: do_free_cache

Follow up step by step:

Do_free_cache ()-> free_cache ()-> disk_free ()

Next we will focus on this function:

Static int disk_free (void) <br/>{< br/> struct statfs SFS; <br/> If (statfs (pkg_dir_prefix, & SFS) = 0) {<br/> return SFs. f_bavail * SFs. f_bsize; <br/>}else {<br/> return-1; <br/>}< br/>} 

It can be found that this function first obtains the pkg_dir_prefix ("Data/Data") file system information through statfs, and then returns the number of idle memory blocks that non-superusers can obtain.

Then let's look at the structure that saves the file system information.

Struct statfs {<br/> long f_type; <br/> long f_bsize; // the size of each memory block <br/> long f_blocks; <br/> long f_bfree; <br/> long f_bavail; // Number of idle memory blocks that non-superusers can obtain <br/> long f_files; <br/> long f_ffree; <br/> _ kernel_fsid_t f_fsid; <br/> long f_namelen; <br/> long f_frsize; <br/> long f_spare [5]; <br/> }; 

Finally, by adding debugging information, we found that the root cause of the error is the bug of Google source code:

First, the statfs () function gets the "Data/Data" Information successfully, and then returns the idle memory block size that non-superusers can obtain, that is, SFS. f_bavail * SFs. f_bsize;

The variables SFs. f_bavail and SFs. f_bsize are two long-type variables, which are multiplied and saved in an int-type variable. As a result, the 32-bit variable overflows and a negative number is returned. The free_cache () function returns an error. The packagemanagerservice client finally receives an error message, leading to installation failure.

On the other hand, we have much larger memory space than ordinary entertainment terminals (mobile phones and tablets), so SFs. the f_bavail value is very large, and the result after multiplication is saved in the int type variable, it will certainly overflow.

Solution: Change the return value of the disk_free () function to uint64_t.

Supplement

If you have time, carefully review the application installation process:

· Install using the ADB install command

· Software Installation

· Communication Between installd and packageinstall.apk and packagemanagerservice. Java

 

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.