屏蔽Settings里面连续五次点击版本号打开开发者模式,并且通过计算器暗码来打开开发者模式

1.屏蔽Settings里面的连续五次点击版本号打开开发者模式功能 

开发者模式是在Settings里面

找到对应目录:alps/packages/app/Settings/src/com/android/settings/deviceinfo

对应的Java文件:BuildNumberPreferenceController.java

对应的方法:handlePreferenceTreeClick()

@Override
    public boolean handlePreferenceTreeClick(Preference preference) {
        if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
            return false;
        }
        if (Utils.isMonkeyRunning()) {
            return false;
        }
        // Don't enable developer options for secondary non-demo users.
        if (!(mUm.isAdminUser() || mUm.isDemoUser())) {
            mMetricsFeatureProvider.action(
                    mContext, SettingsEnums.ACTION_SETTINGS_BUILD_NUMBER_PREF);
            return false;
        }


        // Don't enable developer options until device has been provisioned
        if (!Utils.isDeviceProvisioned(mContext)) {
            mMetricsFeatureProvider.action(
                    mContext, SettingsEnums.ACTION_SETTINGS_BUILD_NUMBER_PREF);
            return false;
        }


        if (mUm.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES)) {
            if (mUm.isDemoUser()) {
                // Route to demo device owner to lift the debugging restriction.
                final ComponentName componentName = Utils.getDeviceOwnerComponent(mContext);
                if (componentName != null) {
                    final Intent requestDebugFeatures = new Intent()
                            .setPackage(componentName.getPackageName())
                            .setAction("com.android.settings.action.REQUEST_DEBUG_FEATURES");
                    final ResolveInfo resolveInfo = mContext.getPackageManager().resolveActivity(
                            requestDebugFeatures, 0);
                    if (resolveInfo != null) {
                        mContext.startActivity(requestDebugFeatures);
                        return false;
                    }
                }
            }
            if (mDebuggingFeaturesDisallowedAdmin != null &&
                    !mDebuggingFeaturesDisallowedBySystem) {
                RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mContext,
                        mDebuggingFeaturesDisallowedAdmin);
            }
            mMetricsFeatureProvider.action(
                    mContext, SettingsEnums.ACTION_SETTINGS_BUILD_NUMBER_PREF);
            return false;
        }


        if (mDevHitCountdown > 0) {
            mDevHitCountdown--;
            if (mDevHitCountdown == 0 && !mProcessingLastDevHit) {
                // Add 1 count back, then start password confirmation flow.
                mDevHitCountdown++;
                final ChooseLockSettingsHelper helper =
                        new ChooseLockSettingsHelper(mActivity, mFragment);
                mProcessingLastDevHit = helper.launchConfirmationActivity(
                        REQUEST_CONFIRM_PASSWORD_FOR_DEV_PREF,
                        mContext.getString(R.string.unlock_set_unlock_launch_picker_title));
                //这个就是连续点击五次之后打开开发者模式的函数,注释掉
                //enableDevelopmentSettings();
                mMetricsFeatureProvider.action(
                        mMetricsFeatureProvider.getAttribution(mActivity),
                        MetricsEvent.FIELD_SETTINGS_BUILD_NUMBER_DEVELOPER_MODE_ENABLED,
                        mFragment.getMetricsCategory(),
                        null,
                        mProcessingLastDevHit ? 0 : 1);
            } else if (mDevHitCountdown > 0
                    && mDevHitCountdown < (TAPS_TO_BE_A_DEVELOPER - 2)) {
                if (mDevHitToast != null) {
                    mDevHitToast.cancel();
                }
                mDevHitToast = Toast.makeText(mContext,
                        mContext.getResources().getQuantityString(
                                R.plurals.show_dev_countdown, mDevHitCountdown,
                                mDevHitCountdown),
                        Toast.LENGTH_SHORT);
                //这个是当你点击版本号的时,会弹出来toast提示还要点击多少次,这个也注释掉
                //mDevHitToast.show();
            }


            mMetricsFeatureProvider.action(
                    mMetricsFeatureProvider.getAttribution(mActivity),
                    MetricsEvent.FIELD_SETTINGS_BUILD_NUMBER_DEVELOPER_MODE_ENABLED,
                    mFragment.getMetricsCategory(),
                    null,
                    0);
        } else if (mDevHitCountdown < 0) {
            if (mDevHitToast != null) {
                mDevHitToast.cancel();
            }
            mDevHitToast = Toast.makeText(mContext, R.string.show_dev_already,
                    Toast.LENGTH_LONG);
            mDevHitToast.show();
            mMetricsFeatureProvider.action(
                    mMetricsFeatureProvider.getAttribution(mActivity),
                    MetricsEvent.FIELD_SETTINGS_BUILD_NUMBER_DEVELOPER_MODE_ENABLED,
                    mFragment.getMetricsCategory(),
                    null,
                    1);
        }
        return true;
    }
/**
     * Enables development settings. Only call this after confirming password.
     */
    private void enableDevelopmentSettings() {
        mDevHitCountdown = 0;
        mProcessingLastDevHit = false;
        DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(mContext, true);//最终打开开发者模式的地方
        if (mDevHitToast != null) {
            mDevHitToast.cancel();
        }
        mDevHitToast = Toast.makeText(mContext, R.string.show_dev_on,
                Toast.LENGTH_LONG);
        mDevHitToast.show();
    }

注释掉对应的code之后,就成功屏蔽了点击版本号打开开发者模式的功能了

2.通过计算器暗码来打开开发者模式

2.1添加暗码:

路径:packages/apps/ExactCalculator/src/com/android/calculator2/Calculator.java

网上有很多计算器添加暗码的案例,这里就不细说了,贴上代码:

@@ -999,6 +1000,25 @@ public class Calculator extends Activity
                 mEvaluator.requireResult(Evaluator.MAIN_INDEX, this, mResultText);
             }
         }
+            if (mFormulaText.getText().toString().equals("%147%+")) {
+            Log.i("xyx", "input %147%+  ==============>");
+            Intent intent = new Intent();
+            intent.setAction("action.wiwood.enable_Development_Settings");
+                       sendBroadcast(intent);
+            Log.i("xyx", "start intent com.boll.factorymodetest  ==============>");
+        }
+        //end
     }


     private void onDelete() {

这里是通过发送广播的方式来打开开发者模式;

2.2添加广播接收器

路径:alps/packages/app/Settings/src/com/android/settings/deviceinfo

这里用的是静态广播的办法,在这里新建一个DevelopmentEnabledReceiver.java

/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.deviceinfo;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.android.settingslib.development.DevelopmentSettingsEnabler;

public class DevelopmentEnabledReceiver extends BroadcastReceiver {
	private final String TAG = "DevelopmentEnabledReceiver";
    @Override
    public void onReceive(Context context, Intent intent) {
		Log.i(TAG, "Receive BroadCast:-----------------> action.wiwood.enable_Development_Settings");
        DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(context, true);
    }
}

添加了广播接收器之后还要在AndroidManifest.xml里面声明一下:

--- a/mediatek/proprietary/packages/apps/MtkSettings/AndroidManifest.xml
+++ b/mediatek/proprietary/packages/apps/MtkSettings/AndroidManifest.xml
@@ -1918,6 +1918,16 @@
         <receiver android:name=".deviceinfo.StorageUnmountReceiver"
                 android:exported="true"
                 android:permission="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
+
+               <!-- xyx: add for development enabled-->
+               <receiver android:name=".deviceinfo.DevelopmentEnabledReceiver"
+                               android:enabled="true"
+                               android:exported="true">
+                       <intent-filter>
+                               <action android:name="action.wiwood.enable_Development_Settings"/>
+                       </intent-filter>
+               </receiver>
+               <!-- end xyx -->

至此,就完成了所有代码的修改,编译Settings.apk和Calculator.apk,push到机器对应的路径下验证就ok了

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值