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

Commit 4eb68e06 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Reduce reading apk resources in startActivity

The permission callback is usually called from
startActivityUnchecked
 > postStartActivityProcessing
  > Interceptor#onActivityLaunched

This centralizes the resource accesses to window style cache.

Bug: 350394503
Flag: com.android.window.flags.cache_window_style
Test: atest ActivityRecordTests#testReadWindowStyle
Change-Id: Ia70c369af6f86879a2fe54e0f1f345c2a7e76bee
parent 47112c62
Loading
Loading
Loading
Loading
+7 −15
Original line number Diff line number Diff line
@@ -82,12 +82,10 @@ import android.util.LongSparseLongArray;
import android.util.Slog;
import android.util.SparseBooleanArray;

import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.app.IAppOpsCallback;
import com.android.internal.app.IAppOpsService;
import com.android.internal.infra.AndroidFuture;
import com.android.internal.policy.AttributeCache;
import com.android.internal.util.IntPair;
import com.android.internal.util.function.pooled.PooledLambda;
import com.android.server.FgThread;
@@ -167,6 +165,7 @@ public final class PermissionPolicyService extends SystemService {
    private Context mContext;
    private PackageManagerInternal mPackageManagerInternal;
    private PermissionManagerServiceInternal mPermissionManagerInternal;
    private ActivityTaskManagerInternal mActivityTaskManagerInternal;
    private NotificationManagerInternal mNotificationManager;
    private TelephonyManager mTelephonyManager;
    private final KeyguardManager mKeyguardManager;
@@ -189,6 +188,7 @@ public final class PermissionPolicyService extends SystemService {
                PackageManagerInternal.class);
        mPermissionManagerInternal = LocalServices.getService(
                PermissionManagerServiceInternal.class);
        mActivityTaskManagerInternal = LocalServices.getService(ActivityTaskManagerInternal.class);
        final IAppOpsService appOpsService = IAppOpsService.Stub.asInterface(
                ServiceManager.getService(Context.APP_OPS_SERVICE));

@@ -1154,7 +1154,7 @@ public final class PermissionPolicyService extends SystemService {
                                activityInfo.packageName, info.getCallingPackage(),
                                info.getIntent(), info.getCheckedOptions(), activityInfo.name,
                                true)
                                || isNoDisplayActivity(activityInfo)) {
                                || isNoDisplayActivity(activityInfo, info.getUserId())) {
                            return;
                        }
                        UserHandle user = UserHandle.of(taskInfo.userId);
@@ -1170,9 +1170,7 @@ public final class PermissionPolicyService extends SystemService {
                };

        private void onActivityManagerReady() {
            ActivityTaskManagerInternal atm =
                    LocalServices.getService(ActivityTaskManagerInternal.class);
            atm.registerActivityStartInterceptor(
            mActivityTaskManagerInternal.registerActivityStartInterceptor(
                    ActivityInterceptorCallback.PERMISSION_POLICY_ORDERED_ID,
                    mActivityInterceptorCallback);
        }
@@ -1227,20 +1225,14 @@ public final class PermissionPolicyService extends SystemService {
                    null, activityName, false);
        }

        private boolean isNoDisplayActivity(@NonNull ActivityInfo aInfo) {
        private boolean isNoDisplayActivity(@NonNull ActivityInfo aInfo, int userId) {
            final int themeResource = aInfo.getThemeResource();
            if (themeResource == Resources.ID_NULL) {
                return false;
            }

            boolean noDisplay = false;
            final AttributeCache.Entry ent = AttributeCache.instance()
                    .get(aInfo.packageName, themeResource, R.styleable.Window, 0);
            if (ent != null) {
                noDisplay = ent.array.getBoolean(R.styleable.Window_windowNoDisplay, false);
            }

            return noDisplay;
            return mActivityTaskManagerInternal.isNoDisplay(aInfo.packageName, themeResource,
                    userId);
        }

        /**
+3 −0
Original line number Diff line number Diff line
@@ -617,6 +617,9 @@ public abstract class ActivityTaskManagerInternal {
     */
    public abstract boolean isBaseOfLockedTask(String packageName);

    /** Returns the value of {@link android.R.attr#windowNoDisplay} from the given theme. */
    public abstract boolean isNoDisplay(String packageName, int theme, int userId);

    /**
     * Creates an interface to update configuration for the calling application.
     */
+12 −0
Original line number Diff line number Diff line
@@ -7447,6 +7447,18 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
            }
        }

        @Override
        public boolean isNoDisplay(String packageName, int theme, int userId) {
            if (!com.android.window.flags.Flags.cacheWindowStyle()) {
                final AttributeCache.Entry ent = AttributeCache.instance()
                        .get(packageName, theme, R.styleable.Window, userId);
                return ent != null
                        && ent.array.getBoolean(R.styleable.Window_windowNoDisplay, false);
            }
            final ActivityRecord.WindowStyle style = getWindowStyle(packageName, theme, userId);
            return style != null && style.noDisplay();
        }

        @Override
        public PackageConfigurationUpdater createPackageConfigurationUpdater() {
            return new PackageConfigurationUpdaterImpl(Binder.getCallingPid(),
+2 −0
Original line number Diff line number Diff line
@@ -1009,6 +1009,8 @@ public class ActivityRecordTests extends WindowTestsBase {
        assertTrue(style.disablePreview());
        assertTrue(style.optOutEdgeToEdge());
        assertEquals(1 /* icon_preferred */, style.mSplashScreenBehavior);
        assertEquals(style.noDisplay(), mAtm.mInternal.isNoDisplay(activity.packageName,
                activity.info.theme, activity.mUserId));
    }

    /**