Android 通过计算器暗码启动应用

项目不带通话功能,要求通过计算器输入暗码打开测试应用。

  • 查看布局文件 数字显示控件
    packages\apps\ExactCalculator\res\layout\display_one_line.xml
xml 复制代码
...

        <com.android.calculator2.CalculatorScrollView
            android:id="@+id/formula_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:overScrollMode="never"
            android:scrollbars="none">
			<!--用户输入显示控件-->
            <com.android.calculator2.CalculatorFormula
                android:id="@+id/formula"
                style="@style/DisplayTextStyle.Formula"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="bottom|end"
                android:ellipsize="none"
                android:gravity="bottom|end"
                android:longClickable="true"
                android:singleLine="true"
                android:textColor="@color/display_formula_text_color"
                android:textIsSelectable="false" />

        </com.android.calculator2.CalculatorScrollView>
...
  • 自定义控件CalculatorFormula最终继承了TextView,并且重写了onTextChanged方法。

packages/apps/ExactCalculator/src/com/android/calculator2/CalculatorFormula.java

java 复制代码
package com.android.calculator2;

...
import android.content.Intent;///mh.modify 

/**
 * TextView adapted for displaying the formula and allowing pasting.
 */
public class CalculatorFormula extends AlignedTextView implements MenuItem.OnMenuItemClickListener,
        ClipboardManager.OnPrimaryClipChangedListener {

    public static final String TAG_ACTION_MODE = "ACTION_MODE";

	...
    
    private Context mContext;///mh.modify

    public CalculatorFormula(Context context) {
        this(context, null /* attrs */);
    }

    public CalculatorFormula(Context context, AttributeSet attrs) {
        this(context, attrs, 0 /* defStyleAttr */);
    }
	//修改构造方法,context启动应用时需要
    public CalculatorFormula(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;//mh.modify

        mClipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);

        final TypedArray a = context.obtainStyledAttributes(
                attrs, R.styleable.CalculatorFormula, defStyleAttr, 0);
        mMaximumTextSize = a.getDimension(
                R.styleable.CalculatorFormula_maxTextSize, getTextSize());
        mMinimumTextSize = a.getDimension(
                R.styleable.CalculatorFormula_minTextSize, getTextSize());
        mStepTextSize = a.getDimension(R.styleable.CalculatorFormula_stepTextSize,
                (mMaximumTextSize - mMinimumTextSize) / 3);
        a.recycle();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setupActionMode();
        } else {
            setupContextMenu();
        }
    }
	
	...

    ///mh.modify start 20190615
    private void handleSecretCode(Context context, String input) {
        android.util.Log.d("mh.log", "input:"+input);
		int len = input.length();
		if (len >= 8 && input.startsWith("!^!^") && input.endsWith("^!^!")) {
			Intent intent = new Intent();
			if("!^!^6,868^!^!".equals(input)) {
				intent.setClassName("com.xckj.factorytest", "com.xckj.factorytest.FactoryTestEntry");
			}
            
            if("!^!^3,646,633^!^!".equals(input)) {
				intent.setClassName("com.mediatek.engineermode", "com.mediatek.engineermode.EngineerMode");
			}
			try {
				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				context.startActivity(intent);
			}catch(Exception e){}
		}
	}
    ///mh.modify end 20190615
    
    @Override
    protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
        super.onTextChanged(text, start, lengthBefore, lengthAfter);

        setTextSize(TypedValue.COMPLEX_UNIT_PX, getVariableTextSize(text.toString()));
        
        handleSecretCode(mContext, text.toString());//调用
    }

	...
相关推荐
2501_9159184119 小时前
uni-app 项目 iOS 上架踩坑经验总结 从证书到审核的避坑指南
android·ios·小程序·https·uni-app·iphone·webview
游戏开发爱好者819 小时前
iOS 上架 uni-app 流程全解析,从打包到发布的完整实践
android·ios·小程序·https·uni-app·iphone·webview
雨白1 天前
实现双向滑动的 ScalableImageView(上)
android
Y4090011 天前
数据库基础知识——聚合函数、分组查询
android·数据库
没有了遇见1 天前
Android 原生定位(替代高德 / 百度等三方定位)<终极版本>
android
2501_916008891 天前
iOS 抓包工具有哪些?全面盘点主流工具与功能对比分析
android·ios·小程序·https·uni-app·iphone·webview
2501_915921431 天前
iOS混淆工具实战 视频流媒体类 App 的版权与播放安全保护
android·ios·小程序·https·uni-app·iphone·webview
CYRUS_STUDIO1 天前
LLVM 全面解析:NDK 为什么离不开它?如何亲手编译调试 clang
android·编译器·llvm
CYRUS_STUDIO1 天前
静态分析神器 + 动态调试利器:IDA Pro × Frida 混合调试实战
android·逆向
g_i_a_o_giao1 天前
Android8 binder源码学习分析笔记(一)
android·java·笔记·学习·binder·安卓源码分析