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;

相关推荐
郑州光合科技余经理29 分钟前
国际版外卖系统:税率字段怎么和订单主流程解耦
android·java·开发语言·前端·后端·php·ai编程
andyweike5 小时前
Android Automotive
android
又见情义6 小时前
记一次 RK3568 Android 13 蓝牙反复重启问题的排查与修复
android
hai_android6 小时前
Kotlin Flow combine 源码剖析:一个 Channel 如何优雅合并多条流
android·java·kotlin
敲代码的瓦龙7 小时前
Jetpack?ViewModel!!!
android·开发语言·kotlin·android-studio
Godikov8 小时前
Android 工控终端实战:从秒级卡顿到毫秒响应,SQLite/LitePal 性能优化全记录
android
星间都市山脉10 小时前
Android16 SystemService.onBootPhase 调用时机
android·java·linux·windows·ubuntu
swithun10 小时前
不用 WebView,我用 Kotlin + Compose Multiplatform 重写 Mermaid,并做了 2048 组对拍
android·开源·kotlin
AI吃大瓜10 小时前
人脸检测和行人检测4:Android实现YOLOv8 YOLO11 YOLO26人脸检测和人体检测(含源码,可实时检测)
android·yolo·人脸检测·人体检测·行人检测·yolo26
与海boy10 小时前
Prompt模版
android·prompt