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;

相关推荐
wk灬丨22 分钟前
Android Kotlin Flow 冷流 热流
android·kotlin·flow
千雅爸爸23 分钟前
Android MVVM demo(使用DataBinding,LiveData,Fresco,RecyclerView,Room,ViewModel 完成)
android
晨曦_子画1 小时前
编程语言之战:AI 之后的 Kotlin 与 Java
android·java·开发语言·人工智能·kotlin
孤客网络科技工作室1 小时前
AJAX 全面教程:从基础到高级
android·ajax·okhttp
Mr Lee_3 小时前
android 配置鼠标右键快捷对apk进行反编译
android
顾北川_野3 小时前
Android CALL关于电话音频和紧急电话设置和获取
android·音视频
&岁月不待人&3 小时前
Kotlin by lazy和lateinit的使用及区别
android·开发语言·kotlin
Winston Wood5 小时前
Android Parcelable和Serializable的区别与联系
android·序列化
清风徐来辽5 小时前
Android 项目模型配置管理
android
帅得不敢出门6 小时前
Gradle命令编译Android Studio工程项目并签名
android·ide·android studio·gradlew