当前位置:   article > 正文

Android9禁止某个app启动

Android9禁止某个app启动

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

代码位置 :

frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
  • 1

具体修改如下

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");
    }

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/629987
推荐阅读
相关标签
  

闽ICP备14008679号