Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b26dd5ff authored by Anton Kulakov's avatar Anton Kulakov
Browse files

Use SDK Sandbox process UserHandle for SDK context creation.

In some scenarios application.uid could be not set for RE-SDKs.
For thouse use cases current process (sdk_sandbox) UserHandle should be used.

Without this change SYSTEM (0) user will be used (-1 / PER_USER_RANGE)

Bug: 323267234
Test: CustomizedSdkContextTest from secondary user
Change-Id: I04527c8b89341020460cae1adb1b80269b68fbcd
parent 60f5711d
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -2626,12 +2626,18 @@ class ContextImpl extends Context {
    @Override
    public Context createApplicationContext(ApplicationInfo application, int flags)
            throws NameNotFoundException {
        final UserHandle user = new UserHandle(UserHandle.getUserId(application.uid));
        return createApplicationContextAsUser(application, flags, user);
    }

    private Context createApplicationContextAsUser(ApplicationInfo application, int flags,
                                                   UserHandle user) throws NameNotFoundException {
        LoadedApk pi = mMainThread.getPackageInfo(application, mResources.getCompatibilityInfo(),
                flags | CONTEXT_REGISTER_PACKAGE);
        if (pi != null) {
            ContextImpl c = new ContextImpl(this, mMainThread, pi, ContextParams.EMPTY,
                    mAttributionSource.getAttributionTag(), mAttributionSource.getNext(), null,
                    mToken, new UserHandle(UserHandle.getUserId(application.uid)), flags, null,
                    mToken, user, flags, null,
                    null, mDeviceId, mIsExplicitDeviceId);

            final int displayId = getDisplayId();
@@ -2656,7 +2662,9 @@ class ContextImpl extends Context {
            throw new SecurityException("API can only be called from SdkSandbox process");
        }

        ContextImpl ctx = (ContextImpl) createApplicationContext(sdkInfo, flags);
        final UserHandle user = sdkInfo.uid >= 0
                ? new UserHandle(UserHandle.getUserId(sdkInfo.uid)) : Process.myUserHandle();
        ContextImpl ctx = (ContextImpl) createApplicationContextAsUser(sdkInfo, flags, user);

        // Set sandbox app's context as the application context for sdk context
        ctx.mPackageInfo.makeApplicationInner(/*forceDefaultAppClass=*/false,