Solve the shortage of internal storage space, do not load desktop wallpaper, desktop wallpaper display

Source: Internet
Author: User
Note:

When the internal storage space is insufficient, do not load wallpaper to save resources.


Method of modification: modify the content in wallpapermanagerservice. java. Train of Thought: Before loading the wallpaper, we need to determine whether the current storage space is insufficient. The Code is as follows: (Source Code address)
Public Boolean isstoragelow () {try {If (mipackagemanager! = NULL) {return mipackagemanager. isstoragelow ();}
} Catch (RemoteException e) {} return false ;}


Boolean Bindwallpapercomponentlocked(Componentname, Boolean force,
0813 Boolean fromuser, wallpaperdata wallpaper, iremotecallback reply ){
0814 if (Debug) slog. V (TAG, "bindwallpapercomponentlocked: componentname =" + componentname );
If (isstoragelow () {return false ;}

0815 // has the component changed?
0816 if (! Force ){
0817 if (wallpaper. connection! = NULL ){
0818 if (wallpaper. wallpapercomponent = NULL ){
0819 if (componentname = NULL ){
0820 if (Debug) slog. V (TAG, "bindwallpapercomponentlocked: Still using default ");
0821 // still using default wallpaper.
0822 return true;
0823}
0824} else if (wallpaper. wallpapercomponent. Equals (componentname )){
0825 // changing to same wallpaper.
0826 if (Debug) slog. V (TAG, "same wallpaper ");
0827 return true;
0828}
0829}
0830}
0831
0832 try {
0833 if (componentname = NULL ){
0834 string defacomponcomponent =
0835 mcontext. getstring (COM. Android. Internal. R. String. default_wallpaper_component );
0836 if (defacomponcomponent! = NULL ){
0837 // see if there is a default wallpaper component specified
0838 componentname = componentname. unflattenfromstring (defaultcomponent );
0839 if (Debug) slog. V (TAG, "use default component Wallpaper:" + componentname );
0840}
0841 if (componentname = NULL ){
0842 // Fall back to static image Wallpaper
0843 componentname = image_wall paper;
0844 // clearwallpapercomponentlocked ();
0845 // return;
0846 if (Debug) slog. V (TAG, "using image Wallpaper ");
0847}
0848}
0849 int serviceuserid = wallpaper. userid;
0850 serviceinfo Si = mipackagemanager. getserviceinfo (componentname,
0851 packagemanager. get_meta_data | packagemanager. get_permissions, serviceuserid );
0852 if (SI = NULL ){
0853 // The wallpaper component we're trying to use doesn' t exist
0854 slog. W (TAG, "attempted Wallpaper" + componentname + "is unavailable ");
0855 return false;
0856}
0857 if (! Android. manifest. Permission. bind_wallpaper.equals (Si. Permission )){
0858 string MSG = "selected service does not require"
0859 + Android. manifest. Permission. bind_wallpaper
0860 + ":" + componentname;
0861 if (fromuser ){
0862 throw new securityexception (MSG );
0863}
0864 slog. W (TAG, MSG );
0865 return false;
0866}
0867
0868 wallpaperinfo Wi = NULL;
0869
0870 intent = new intent (wallpaperservice. service_interface );
0871 if (componentname! = NULL &&! Componentname. Equals (image_wallpaper )){
0872 // make sure the selected service is actually a wallpaper service.
0873 list <resolveinfo> RIS =
0874 mipackagemanager. queryintentservices (intent,
0875 intent. resolvetypeifneeded (mcontext. getcontentresolver ()),
0876 packagemanager. get_meta_data, serviceuserid );
0877 for (INT I = 0; I <ris. Size (); I ++ ){
0878 serviceinfo RSI = ris. Get (I). serviceinfo;
0879 if (RSI. Name. Equals (Si. Name )&&
0880 RSI. packagename. Equals (Si. packagename )){
0881 try {
0882 Wi = new wallpaperinfo (mcontext, RIS. Get (I ));
0883} catch (xmlpullparserexception e ){
0884 if (fromuser ){
0885 throw new illegalargumentexception (E );
0886}
0887 slog. W (TAG, e );
0888 return false;
0889} catch (ioexception e ){
0890 if (fromuser ){
0891 throw new illegalargumentexception (E );
0892}
0893 slog. W (TAG, e );
0894 return false;
0895}
0896 break;
0897}
0898}
0899 if (Wi = NULL ){
0900 string MSG = "selected service is not a wallpaper :"
0901 + componentname;
0902 if (fromuser ){
0903 throw new securityexception (MSG );
0904}
0905 slog. W (TAG, MSG );
0906 return false;
0907}
0908}
0909
0910 // bind the service!
0911 if (Debug) slog. V (TAG, "binding to:" + componentname );
0912 wallpaperconnection newconn = new wallpaperconnection (WI, wallpaper );
0913 intent. setcomponent (componentname );
0914 intent. putextra (intent. extra_client_label,
0915 com. Android. Internal. R. String. wallpaper_binding_label );
0916 intent. putextra (intent. extra_client_intent, pendingintent. getactivityasuser (
0917 mcontext, 0,
0918 intent. createchooser (new intent (intent. action_set_wallpaper ),
0919 mcontext. gettext (COM. Android. Internal. R. String. chooser_wallpaper )),
0920 0, null, new userhandle (serviceuserid )));
0921 if (! Mcontext. bindserviceasuser (intent, newconn,
0922 context. bind_auto_create | context. bind_showing_ui,
0923 new userhandle (serviceuserid ))){
0924 string MSG = "unable to bind Service :"
0925 + componentname;
0926 if (fromuser ){
0927 throw new illegalargumentexception (MSG );
0928}
0929 slog. W (TAG, MSG );
0930 return false;
0931}
0932 if (wallpaper. userid = mcurrentuserid & mlastwallpaper! = NULL ){
0933 detachwallpaperlocked (mlastwallpaper );
0934}
0935 wallpaper. wallpapercomponent = componentname;
0936 wallpaper. Connection = newconn;
0937 wallpaper. lastdiedtime = systemclock. uptimemillis ();
0938 newconn. mreply = reply;
0939 try {
0940 if (wallpaper. userid = mcurrentuserid ){
0941 if (Debug)
0942 slog. V (TAG, "adding window token:" + newconn. mtoken );
0943 miwindowmanager. addwindowtoken (newconn. mtoken,
0944 windowmanager. layoutparams. type_wallpaper );
0945 mlastwallpaper = wallpaper;
0946}
0947} catch (RemoteException e ){
0948}
0949} catch (RemoteException e ){
0950 string MSG = "remote exception for" + componentname + "\ n" + E;
0951 if (fromuser ){
0952 throw new illegalargumentexception (MSG );
0953}
0954 slog. W (TAG, MSG );
0955 return false;
0956}
0957 return true;
0958}

Note!

The red part adds code.


Solve the shortage of internal storage space, do not load desktop wallpaper, desktop wallpaper display

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.