START_ANY_ACTIVITY

  • 需要启动exported为false的页面可以使用START_ANY_ACTIVITY权限,在AndroidManifeset.xml中直接声明就可以,当然应用得有系统签名的权限,三方签名的应用是没有该权限的
// ActivityStarter.java
 private int startActivity(IApplicationThread caller, Intent intent, Intent ephemeralIntent,
            String resolvedType, ActivityInfo aInfo, ResolveInfo rInfo,
            IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
            IBinder resultTo, String resultWho, int requestCode, int callingPid, int callingUid,
            String callingPackage, int realCallingPid, int realCallingUid, int startFlags,
            SafeActivityOptions options,
            boolean ignoreTargetSecurity, boolean componentSpecified, ActivityRecord[] outActivity,
            TaskRecord inTask, boolean allowPendingRemoteAnimationRegistryLookup) {
        ......
        boolean abort = !mSupervisor.checkStartAnyActivityPermission(intent, aInfo, resultWho,
                requestCode, callingPid, callingUid, callingPackage, ignoreTargetSecurity,
                inTask != null, callerApp, resultRecord, resultStack);
        ......
}
// ActivityStackSupervisor.java
 boolean checkStartAnyActivityPermission(Intent intent, ActivityInfo aInfo,
            String resultWho, int requestCode, int callingPid, int callingUid,
            String callingPackage, boolean ignoreTargetSecurity, boolean launchingInTask,
            ProcessRecord callerApp, ActivityRecord resultRecord, ActivityStack resultStack) {
        final boolean isCallerRecents = mService.getRecentTasks() != null &&
                mService.getRecentTasks().isCallerRecents(callingUid);
        // 校验START_ANY_ACTIVITY权限 
        final int startAnyPerm = mService.checkPermission(START_ANY_ACTIVITY, callingPid,
                callingUid);
        if (startAnyPerm == PERMISSION_GRANTED || (isCallerRecents && launchingInTask)) {
            // If the caller has START_ANY_ACTIVITY, ignore all checks below. In addition, if the
            // caller is the recents component and we are specifically starting an activity in an
            // existing task, then also allow the activity to be fully relaunched.
            return true;
        }
      ......
    }
  • 可以解决SecurityException: Permission Denial异常
java.lang.SecurityException: Permission Denial: starting Intent { flg=0x10000000 cmp=com.chan.test/com.chan.test.activities.MainActivity } from ProcessRecord{168983d 2145:com.chan.test1/u0a15} (pid=2145, uid=10015) not exported from uid 10063
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容