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

Commit 25360a2f authored by Ryan Mitchell's avatar Ryan Mitchell
Browse files

Version LoadedApk cache using base code path

When a context is requested through Context#createApplicationContext,
the underlying LoadedApk cached in ActivityThread#mResourcePackages is
updated using the ApplicationInfo passed in. This creates unexpected
problems when using APIs that expect to be able to read resources from
a previous version of a package after that package has been updated.

With this change, contexts requested through
Context#createPackageContext and Context#createApplicationContext will
will have an underlying LoadedAPK that is tied to the version of the
package represented by the ApplicationInfo. If createPackageContext
is invoked before a package updates and then after a package updates,
the two contexts will have different underlying LoaddApks.

The ActivityThread#mPackages and ActivityThread#mResourcePackages now
only hold LoadedAPKs of that were created using ApplicationInfos that
were sent to this process from system_server in order to run the
application. Whenever a newer version of  an ApplicationInfo is
delivered from system_server for one of these packages, the previously
cached LoadedAPK will be updated using the new ApplicationInfo. This
will usually be because of an overlay change or "don't kill" package
upgrade.

Bug: 188059515
Test: atest FrameworksCoreTests:ContextTest
Change-Id: Iea54abf38449c9d8ab9dae16d36d95cbb4d7d8b0
parent 5a41b45a
Loading
Loading
Loading
Loading
+296 −229

File changed.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UiContext;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.AttributionSource;
import android.content.AutofillOptions;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -60,7 +61,6 @@ import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.content.AttributionSource;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
@@ -2461,7 +2461,7 @@ class ContextImpl extends Context {
    public Context createApplicationContext(ApplicationInfo application, int flags)
            throws NameNotFoundException {
        LoadedApk pi = mMainThread.getPackageInfo(application, mResources.getCompatibilityInfo(),
                flags | CONTEXT_REGISTER_PACKAGE);
                flags | CONTEXT_REGISTER_PACKAGE, false);
        if (pi != null) {
            ContextImpl c = new ContextImpl(this, mMainThread, pi, ContextParams.EMPTY,
                    mAttributionSource.getAttributionTag(),
+2 −0
Original line number Diff line number Diff line
@@ -121,6 +121,8 @@ java_genrule {
        ":FrameworksCoreTests_keyset_splat_api",
        ":FrameworksCoreTests_locales",
        ":FrameworksCoreTests_overlay_config",
        ":FrameworksCoreTests_res_version_after",
        ":FrameworksCoreTests_res_version_before",
        ":FrameworksCoreTests_version_1",
        ":FrameworksCoreTests_version_1_diff",
        ":FrameworksCoreTests_version_1_nosys",
+22 −0
Original line number Diff line number Diff line
package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "frameworks_base_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["frameworks_base_license"],
}

android_test_helper_app {
    name: "FrameworksCoreTests_res_version_before",
    defaults: ["FrameworksCoreTests_apks_defaults"],
    resource_dirs: ["res_before"],
    certificate: ":FrameworksCoreTests_unit_test_cert",
}

android_test_helper_app {
    name: "FrameworksCoreTests_res_version_after",
    defaults: ["FrameworksCoreTests_apks_defaults"],
    resource_dirs: ["res_after"],
    certificate: ":FrameworksCoreTests_unit_test_cert",
}
+20 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2021 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.android.frameworks.coretests.res_version">
    <application android:hasCode="false"/>
</manifest>
Loading