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;

相关推荐
●VON2 小时前
AtomGit Flutter鸿蒙客户端:文件树与代码浏览
android·服务器·安全·flutter·harmonyos·鸿蒙
故渊at8 小时前
系列三:组件化与模块化进阶 | 第11篇 组件化项目规范与问题根治:依赖、资源、Manifest 与混淆的全链路管控
android·架构·mvvm·模块化·组件化
故渊at8 小时前
系列二:MVVM 深度实战与项目重构 | 第7篇 LiveData & StateFlow 状态管理实战:从“粘包弹”到“丝滑流式”
android·重构
是阿建吖!8 小时前
【Linux】信号
android·linux·c语言·c++
alexhilton10 小时前
AppFunctions:让你的Android应用更容易被AI智能体发现
android·kotlin·android jetpack
qq36219670510 小时前
APK文件签名校验教程:验证APK真伪的完整方法
android·智能手机
赏金术士11 小时前
Android 组件化概念和特征
android·kotlin·组件化
2501_9159090617 小时前
深入解析Mock.js:功能、应用及实战案例,提升前端开发效率
android·ios·小程序·https·uni-app·iphone·webview
流星白龙18 小时前
【MySQL高阶】21.撤销表空间,撤销日志
android·mysql·adb