Android9禁止某个app启动

禁止某个app通过开机广播自启动,覆盖住Launcher

代码位置 :

powershell 复制代码
frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java

具体修改如下

java 复制代码
public final int startActivityAsUser(IApplicationThread caller, String callingPackage,
            Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode,
            int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId,
            boolean validateIncomingUser) {
        enforceNotIsolatedCaller("startActivity");
		
		// for disable MQlAUNCHER begin  开始
		if (isMoreLauncherConfig()) {
			Log.d("youdianxs", "MQ CONFIG");
			try{
			ActivityInfo aInfo = resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
			Log.d("youdianxs", "callingPackage = " + callingPackage);
			Log.d("youdianxs", "callingPackageactivity = " + aInfo.taskAffinity);
	//判断包名
			if (MQ_PACKAGE.equals(callingPackage)){
				Log.d("youdianxs", "MQ START===" + isProhibitLauncherTime());
				if (isProhibitLauncherTime() && isNoMqLauncher()) {
					Log.d("youdianxs", "MQ lanjie");
						//核心代码  所有条件成立start cancel
					return ActivityManager.START_CANCELED;
				}
				
				
			}
			}catch(Exception e){
				Log.d("youdianxs", "e.getMessage = " + e.getMessage());
			}
			
		}
		
        // for disable MQlAUNCHER end   结束
		
        userId = mActivityStartController.checkTargetUser(userId, validateIncomingUser,
                Binder.getCallingPid(), Binder.getCallingUid(), "startActivityAsUser");
        // TODO: Switch to user app stacks here.
        return mActivityStartController.obtainStarter(intent, "startActivityAsUser")
                .setCaller(caller)
                .setCallingPackage(callingPackage)
                .setResolvedType(resolvedType)
                .setResultTo(resultTo)
                .setResultWho(resultWho)
                .setRequestCode(requestCode)
                .setStartFlags(startFlags)
                .setProfilerInfo(profilerInfo)
                .setActivityOptions(bOptions)
                .setMayWait(userId)
                .execute();
    }

	//判断是否开机前十分钟之内
	private boolean isProhibitLauncherTime() {
		Log.d("youdianxs", "MQ time====" + (SystemClock.elapsedRealtime() / 1000 / 60));
        return (SystemClock.elapsedRealtime() / 1000 / 60) <= 10;
    }


   //判断此Activity是不是默认Launcher
    private boolean isNoMqLauncher() {
        final ArrayList<ResolveInfo> homeActivities = new ArrayList<>();
		ComponentName currentDefaultHome = mContext.getPackageManager().getHomeActivities(homeActivities);
        if (currentDefaultHome != null) {
			Log.d("youdianxs", "currentDefaultHome.flattenToString()====" + currentDefaultHome.flattenToString());
            return !currentDefaultHome.flattenToString().equals(MQ_PACKAGE + "/" + MQ_ACTIVITY);
        }
        return true;
    }


   //判断配置成立
    private boolean isMoreLauncherConfig() {
        return SvtGeneralProperties.getBoolProperty("SVT_ZC_MORE_HOME_CONFIG");
    }

总结 条件成立时 --------> return ActivityManager.START_CANCELED;

相关推荐
m0_548514773 小时前
2024.12.10——攻防世界Web_php_include
android·前端·php
凤邪摩羯3 小时前
Android-性能优化-03-启动优化-启动耗时
android
凤邪摩羯4 小时前
Android-性能优化-02-内存优化-LeakCanary原理解析
android
喀什酱豆腐4 小时前
Handle
android
m0_748232926 小时前
Android Https和WebView
android·网络协议·https
m0_748251726 小时前
Android webview 打开本地H5项目(Cocos游戏以及Unity游戏)
android·游戏·unity
m0_748254668 小时前
go官方日志库带色彩格式化
android·开发语言·golang
zhangphil8 小时前
Android使用PorterDuffXfermode模式PorterDuff.Mode.SRC_OUT橡皮擦实现“刮刮乐”效果,Kotlin(2)
android·kotlin
爱学测试的李木子8 小时前
从0到1搭建 Android 自动化 python+appium 环境
android·软件测试·python·测试工具·自动化
咸芝麻鱼8 小时前
Android Studio | 连接手机设备后,启动App时出现:Waiting For DebuggerApplication (App名)...
android·adb·智能手机·android studio