Android setting logic to show developer options

Source: Internet
Author: User

The default user version does not have "developer Options", we can display the developer mode by clicking on the version number 7 times, and see how the code is handled today:

The first is the initialization of the Packages/apps/settings/src/com/android/settings/settings.java:

Boolean Showdev whether the developer options are displayed by default:

Final Boolean Showdev = Mdevelopmentpreferences.getboolean (                developmentsettings.pref_show,                Android.os.Build.TYPE.equals ("eng"));

If you want the developer option to display by default, you do not need to click the 7 version number, you can directly set the Showdev to true:


If Showdev is false, the developer options are hidden in the following code:

if (id = = r.id.development_settings) {                if (!showdev) {                    target.remove (i);                }            


Here's a look at the section showing developer options by clicking on the version number:

Code path: Packages/apps/settings/src/com/android/settings/deviceinfosettings.java

The first is to define the number of clicks:

static final int taps_to_be_a_developer = 7;


Click the version number of the processing logic, if the Mdevhitcountdown is less than 0, it means that "developer Options" has been shown, refer to the processing of the resume function:

if (Preference.getkey (). Equals (Key_build_number)) {//Don ' t enable developer options for secondary users.            if (Userhandle.myuserid () = Userhandle.user_owner) return true; if (Mdevhitcountdown > 0) {if (Mdevhitcountdown = = 1) {if (super.ensurepinrestricte                    Dpreference (preference)) {return true;                }} mdevhitcountdown--;                            if (Mdevhitcountdown = = 0) {getactivity (). Getsharedpreferences (Developmentsettings.pref_file, context.mode_private). Edit (). Putboolean (Developmentsettings.pref_sh                    OW, True). Apply ();                    if (mdevhittoast! = null) {Mdevhittoast.cancel (); } mdevhittoast = Toast.maketext (Getactivity (), r.string.show_dev_on, TOAST.L             Ength_long);       Mdevhittoast.show ();                    } else if (Mdevhitcountdown > 0 && mdevhitcountdown < (taps_to_be_a_developer-2)) {                    if (mdevhittoast! = null) {Mdevhittoast.cancel ();                            } mdevhittoast = Toast.maketext (Getactivity (), Getresources (). Getquantitystring (                    R.plurals.show_dev_countdown, Mdevhitcountdown, Mdevhitcountdown), toast.length_short);                Mdevhittoast.show (); }} else if (Mdevhitcountdown < 0) {if (mdevhittoast! = null) {Mdevhitto                Ast.cancel (); } mdevhittoast = Toast.maketext (Getactivity (), R.string.show_dev_already, Toast.leng                 Th_long);            Mdevhittoast.show ();  }        }

Resume function:

@Override public    void Onresume () {        super.onresume ();        Preferencegroup parentpreference = Getpreferencescreen ();        Mdevhitcountdown = Getactivity (). Getsharedpreferences (Developmentsettings.pref_file,                Context.MODE_PRIVATE). Getboolean (Developmentsettings.pref_show,                        android.os.Build.TYPE.equals ("eng")) -1:taps_to_be_a_developer;        Mdevhittoast = null;    }



Reprint Please specify source: Zhou Mushi's csdn blog Http://blog.csdn.net/zhoumushui

My github: Zhou Mushi's GitHub Https://github.com/zhoumushui





Android setting logic to show developer options

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.