屏蔽launcher桌面应用

今天接到一个需求、需求如下、

默认开机以后屏蔽所有界面,待机界面上只有短信和拨号这两个图标,只能发短信息和拨打电话其它操作都不能使用,然后输入一个代码就可以切换到正常界面了(我们之前的切换代码是:屏蔽*#123456789*#,正常*#9876543231*#)

当时想了半天无从下手、最后一个朋友告诉了一个方法、最后得以实现、先将实现过程记下、作日后用之、高手莫笑

首先我们要做的是拿到一个主要的东西就是屏蔽码、这个代码其实是我们自己做的、也是我们自己设置。 怎么设置首先

我们在自己的项目主配置文件里面加上如下代码:

        <receiver android:name="LauncherDecryption">
            <intent-filter>
                 <action android:name="android.provider.Telephony.SECRET_CODE" />
                 <data android:scheme="android_secret_code" android:host="123456789" />
                 <data android:scheme="android_secret_code" android:host="987654321" />
            </intent-filter>
       </receiver> 

 这是监听一个输入码的receiver、然后怎么去拿到了?

首先要的是可定要去实现LauncherDecryption解密的receiver了代码如下

public class LauncherDecryption extends BroadcastReceiver {

	// process *#*#3646633#*#*
	Uri openApp = Uri.parse("android_secret_code://123456789");
	// process *#*#66#*#*
	Uri closeApp = Uri.parse("android_secret_code://987654321");

	@Override
	public void onReceive(Context context, Intent intent) {
		try {
			if (intent.getAction().equals(SECRET_CODE_ACTION)) {// android.provider.Telephony.SECRET_CODE
				Uri uri = intent.getData();
				File file = new File("/data/data/com.mediatek.launcherplus/LauncherDecryption");
				if ((uri.toString()).equals(closeApp.toString())) {// 屏蔽状态 文件不存在
					
					if (file.exists()) {
						file.delete();
					} else {
					}
				} else if ((uri.toString()).equals(openApp.toString())) {// 正常状态// 文件存在
					if (file.exists()) {
					} else {
						file.mkdir();
						file.createNewFile();
					}
				}

				PowerManager pm = (PowerManager) context.getSystemService("power");
				pm.reboot(null);
			}

		} catch (Exception e) {
			Log.e("FactoryMode", "Package exception.");
		}
	}

}

这就是拿到了该注册码之后所做的事情、其他的你想干嘛就干吗了、就算你要对手机五马分尸也行、

然后我拿到了这个注册码之后我只是做了一件事情就算生成了一个目录文件而已、我什么都没有做;

这样根本没有达到我的需求、接下来我就到我们launcher的下面的一个celllayout类跟allApp2D类里面经行拦截枪杀、

拦截代码简单

	public void addView(View child, int index, ViewGroup.LayoutParams params) {
		// Generate an id for each view, this assumes we have at most 256x256
		// cells
		// per workspace screen
		final LayoutParams cellParams = (LayoutParams) params;
		cellParams.regenerateId = true;

		File file = new File(
				"/data/data/com.mediatek.launcherplus/LauncherDecryption");
		Object tag = child.getTag();
		if (!file.exists()) {
			if (tag instanceof ShortcutInfo) {

				ShortcutInfo shortcutInfo = (ShortcutInfo) tag;
				Intent intent = ((ShortcutInfo) tag).intent;
				if (("com.android.mms.ui.ConversationList").equals(intent.getComponent().getClassName().toString())
						|| ("com.android.contacts.DialtactsActivity").equals(intent.getComponent().getClassName().toString())) {
					super.addView(child, index, params);
				}
			}
		} else {
			super.addView(child, index, params);
		}
	}

 这是在赖在celllayout里面进行的三光政策、我只显示了短信跟拨号、使得launcher桌面成了三毛的哥哥、二弟在世

呵呵、然后还有一个allApp2D类里面加入如下

    public void addApps(ArrayList<ApplicationInfo> list) {
		
        final int N = list.size();
        for (int i=0; i<N; i++) {
            final ApplicationInfo item = list.get(i);
            int index = Collections.binarySearch(mAllAppsList, item,
                    LauncherModel.APP_NAME_COMPARATOR);
            if (index < 0) {
                index = -(index+1);
            }
            File file = new File("/data/data/com.mediatek.launcherplus/LauncherDecryption");
            if(file.exists() || ("com.android.mms.ui.ConversationList").equals(item.componentName.getClassName().toString())
            		|| ("com.android.contacts.DialtactsActivity").equals(item.componentName.getClassName().toString())){
            	mAllAppsList.add(index, item);
            }else {
            }
        }
		
        if (FeatureOption.MTK_YMCAPROP_SUPPORT) {
        	reorderApps();
        }
        mAppsAdapter.notifyDataSetChanged();
    }

这样需求基本完成、鄙人之拙见高人路过请勿笑话、需求完成收工、有相互学习的朋友call me:[email protected]或加好友

猜你喜欢

转载自329716228.iteye.com/blog/1612183