仿比心app源码Android系统开发中添加系统后门键

在我平常的开发中经常会遇到这样的情况出现,那就是需要进行系统升级来验证对系统层面的修改是否成功,一般的情况下都是通过串口工具输入命令来进行的。但是这种方式也是有弊端的,因为在正式出货的产品中我们通常是把adb和窜口等功能关闭了。那么在这种情况下就必须预置一些系统级的后门键了。下面就是我平时开发过程中系统后门键的添加,这里以后门升级键添加为例,
1.在/frameworks//base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java文件中添加你需要处理的系统键值,这是因为Android的系统键值在抛向应用层之间都是在该类中的interceptKeyBeforeQueueing被处理的。
2.我们的后台升级后门键是在3秒的时间内,先按三下黄健然后再按三下红键,下面就是我的具体处理逻辑代码:
在interceptKeyBeforeQueueing中的if(down)中添加如下处理函数UpgradeKeyJuge(keyCode);,该函数的相关代码如下:

private int mBackDoorCurIndex = 0;
private long mBackDoorStartTime = 0;
private final int mBACKDOORTIME = 3000;
//three times the blue key them  three times the red key
private final int[] mcBackDoorKeys = {KeyEvent.KEYCODE_PROG_YELLOW,KeyEvent.KEYCODE_PROG_YELLOW,KeyEvent.KEYCODE_PROG_YELLOW,KeyEvent.KEYCODE_PROG_YELLOW,KeyEvent.KEYCODE_PROG_RED,KeyEvent.KEYCODE_PROG_RED,KeyEvent.KEYCODE_PROG_RED,KeyEvent.KEYCODE_PROG_RED};<pre name="code" class="java">	//to route whether there is a sequence of upgrade key
private void UpgradeKeyJuge(int keyCode){
 
	//is the waiting key
	if(keyCode != mcBackDoorKeys[mBackDoorCurIndex]){
		if(0 != mBackDoorCurIndex)
			mBackDoorCurIndex = 0;
		return;
	}
	if(0 == mBackDoorCurIndex)
	{
		mBackDoorStartTime = SystemClock.uptimeMillis();
		mBackDoorCurIndex++;
		return;
	}
	//timeout	
	if(SystemClock.uptimeMillis() - mBackDoorStartTime > mBACKDOORTIME) {
		mBackDoorCurIndex = 0;
		return;
	}		
	mBackDoorCurIndex++;		
	if(mcBackDoorKeys.length <= mBackDoorCurIndex){			
		if(mcBackDoorKeys.length == mBackDoorCurIndex){
			Intent intent = new Intent("com.coship.upgrade.usbupgrade");
			mContext.sendBroadcast(intent);
		}			
		mBackDoorCurIndex = 0;
	}		
		
}

你可能感兴趣的:(技术类,java,android,python,vue,redis)