【定制Android系统】Android 7.1 在 user 版本中默认关闭 开发者选项 的总开关

需求:user 版本中,Settings 中的开发者选项默认隐藏,且总开关默认关闭。eng 版本默认存在且默认打开总开关。
源码位置:packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java
解决方案:
在 DevelopmentSettings.java 的 onResume() 函数中,做出如下修改。
源码是这么写的:

        final ContentResolver cr = getActivity().getContentResolver();
607        mLastEnabledState = Settings.Global.getInt(cr,
608                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
609        mSwitchBar.setChecked(mLastEnabledState);
610        setPrefsEnabledState(mLastEnabledState);
611
612        if (mHaveDebugSettings && !mLastEnabledState) {
613            // Overall debugging is disabled, but there are some debug
614            // settings that are enabled.  This is an invalid state.  Switch
615            // to debug settings being enabled, so the user knows there is
616            // stuff enabled and can turn it all off if they want.
617            Settings.Global.putInt(getActivity().getContentResolver(),
618                    Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
619            mLastEnabledState = true;
620            mSwitchBar.setChecked(mLastEnabledState);
621            setPrefsEnabledState(mLastEnabledState);
622        }
623        mSwitchBar.show();
624
625        if (mColorModePreference != null) {
626            mColorModePreference.startListening();
627            mColorModePreference.updateCurrentAndSupported();
628        }

在其中 的 第一个 if 语句中 加入 “eng”.equals(android.os.Build.TYPE) 即可。
修改后的源码如下:

        final ContentResolver cr = getActivity().getContentResolver();
607        mLastEnabledState = Settings.Global.getInt(cr,
608                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
609        mSwitchBar.setChecked(mLastEnabledState);
610        setPrefsEnabledState(mLastEnabledState);
611
612        if (mHaveDebugSettings && !mLastEnabledState && "eng".equals(android.os.Build.TYPE)) {
613            // Overall debugging is disabled, but there are some debug
614            // settings that are enabled.  This is an invalid state.  Switch
615            // to debug settings being enabled, so the user knows there is
616            // stuff enabled and can turn it all off if they want.
617            Settings.Global.putInt(getActivity().getContentResolver(),
618                    Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
619            mLastEnabledState = true;
620            mSwitchBar.setChecked(mLastEnabledState);
621            setPrefsEnabledState(mLastEnabledState);
622        }
623        mSwitchBar.show();
624
625        if (mColorModePreference != null) {
626            mColorModePreference.startListening();
627            mColorModePreference.updateCurrentAndSupported();
628        }

以上内容是我今天刚刚从网上查到并借鉴修改的。如果存在任何问题,请不吝赐教。

你可能感兴趣的:(Android)