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

Commit cf909694 authored by Chip Fukuhara's avatar Chip Fukuhara
Browse files

Avoid appcompat logs if old or disabled

For performance savings, we will only log appcompat changes to debug if
it targets the latest sdk version and it is not disabled. These can
still be turned back on with `adb setprop
log.tag.CompatChangeReporter=DEBUG`.

Test: atest PlatformCompatFrameworkTests; atest FrameworksServicesTests:ActivityManagerServiceTest; atest FrameworksServicesTests:ProcessRecordTests; atest FrameworksServicesTests:CompatConfigTest; atest FrameworksServicesTests:PlatformCompatTest
Bug: 323949942
Flag: skip_old_and_disabled_compat_logging

Change-Id: I9efef3af940d7597105ef796774f8cc474194c19
parent 6d31e865
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ aconfig_declarations_group {
        "camera_platform_flags_core_java_lib",
        "com.android.hardware.input-aconfig-java",
        "com.android.input.flags-aconfig-java",
        "com.android.internal.compat.flags-aconfig-java",
        "com.android.internal.foldables.flags-aconfig-java",
        "com.android.internal.pm.pkg.component.flags-aconfig-java",
        "com.android.media.flags.bettertogether-aconfig-java",
@@ -663,6 +664,13 @@ java_aconfig_library {
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
}

// Platform Compat
java_aconfig_library {
    name: "com.android.internal.compat.flags-aconfig-java",
    aconfig_declarations: "compat_logging_flags",
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
}

// Multi user
aconfig_declarations {
    name: "android.multiuser.flags-aconfig",
+4 −1
Original line number Diff line number Diff line
@@ -974,6 +974,7 @@ public final class ActivityThread extends ClientTransactionHandler
        ContentCaptureOptions contentCaptureOptions;

        long[] disabledCompatChanges;
        long[] mLoggableCompatChanges;

        SharedMemory mSerializedSystemFontMap;

@@ -1283,6 +1284,7 @@ public final class ActivityThread extends ClientTransactionHandler
                AutofillOptions autofillOptions,
                ContentCaptureOptions contentCaptureOptions,
                long[] disabledCompatChanges,
                long[] loggableCompatChanges,
                SharedMemory serializedSystemFontMap,
                long startRequestedElapsedTime,
                long startRequestedUptime) {
@@ -1337,6 +1339,7 @@ public final class ActivityThread extends ClientTransactionHandler
            data.autofillOptions = autofillOptions;
            data.contentCaptureOptions = contentCaptureOptions;
            data.disabledCompatChanges = disabledCompatChanges;
            data.mLoggableCompatChanges = loggableCompatChanges;
            data.mSerializedSystemFontMap = serializedSystemFontMap;
            data.startRequestedElapsedTime = startRequestedElapsedTime;
            data.startRequestedUptime = startRequestedUptime;
@@ -7123,7 +7126,7 @@ public final class ActivityThread extends ClientTransactionHandler
        Process.setStartTimes(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis(),
                data.startRequestedElapsedTime, data.startRequestedUptime);

        AppCompatCallbacks.install(data.disabledCompatChanges);
        AppCompatCallbacks.install(data.disabledCompatChanges, data.mLoggableCompatChanges);
        // Let libcore handle any compat changes after installing the list of compat changes.
        AppSpecializationHooks.handleCompatChangesBeforeBindingApplication();

+31 −13
Original line number Diff line number Diff line
@@ -30,41 +30,59 @@ import java.util.Arrays;
 */
public final class AppCompatCallbacks implements Compatibility.BehaviorChangeDelegate {
    private final long[] mDisabledChanges;
    private final long[] mLoggableChanges;
    private final ChangeReporter mChangeReporter;

    /**
     * Install this class into the current process.
     * Install this class into the current process using the disabled and loggable changes lists.
     *
     * @param disabledChanges Set of compatibility changes that are disabled for this process.
     * @param loggableChanges Set of compatibility changes that we want to log.
     */
    public static void install(long[] disabledChanges) {
        Compatibility.setBehaviorChangeDelegate(new AppCompatCallbacks(disabledChanges));
    public static void install(long[] disabledChanges, long[] loggableChanges) {
        Compatibility.setBehaviorChangeDelegate(
                new AppCompatCallbacks(disabledChanges, loggableChanges));
    }

    private AppCompatCallbacks(long[] disabledChanges) {
    private AppCompatCallbacks(long[] disabledChanges, long[] loggableChanges) {
        mDisabledChanges = Arrays.copyOf(disabledChanges, disabledChanges.length);
        mLoggableChanges = Arrays.copyOf(loggableChanges, loggableChanges.length);
        Arrays.sort(mDisabledChanges);
        mChangeReporter = new ChangeReporter(
                ChangeReporter.SOURCE_APP_PROCESS);
        Arrays.sort(mLoggableChanges);
        mChangeReporter = new ChangeReporter(ChangeReporter.SOURCE_APP_PROCESS);
    }

    /**
     * Helper to determine if a list contains a changeId.
     *
     * @param list to search through
     * @param changeId for which to search in the list
     * @return true if the given changeId is found in the provided array.
     */
    private boolean changeIdInChangeList(long[] list, long changeId) {
        return Arrays.binarySearch(list, changeId) >= 0;
    }

    public void onChangeReported(long changeId) {
        reportChange(changeId, ChangeReporter.STATE_LOGGED);
        boolean isLoggable = changeIdInChangeList(mLoggableChanges, changeId);
        reportChange(changeId, ChangeReporter.STATE_LOGGED, isLoggable);
    }

    public boolean isChangeEnabled(long changeId) {
        if (Arrays.binarySearch(mDisabledChanges, changeId) < 0) {
            // Not present in the disabled array
            reportChange(changeId, ChangeReporter.STATE_ENABLED);
        boolean isEnabled = !changeIdInChangeList(mDisabledChanges, changeId);
        boolean isLoggable = changeIdInChangeList(mLoggableChanges, changeId);
        if (isEnabled) {
            // Not present in the disabled changeId array
            reportChange(changeId, ChangeReporter.STATE_ENABLED, isLoggable);
            return true;
        }
        reportChange(changeId, ChangeReporter.STATE_DISABLED);
        reportChange(changeId, ChangeReporter.STATE_DISABLED, isLoggable);
        return false;
    }

    private void reportChange(long changeId, int state) {
    private void reportChange(long changeId, int state, boolean isLoggable) {
        int uid = Process.myUid();
        mChangeReporter.reportChange(uid, changeId, state);
        mChangeReporter.reportChange(uid, changeId, state, isLoggable);
    }

}
+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ oneway interface IApplicationThread {
            in CompatibilityInfo compatInfo, in Map services,
            in Bundle coreSettings, in String buildSerial, in AutofillOptions autofillOptions,
            in ContentCaptureOptions contentCaptureOptions, in long[] disabledCompatChanges,
            in SharedMemory serializedSystemFontMap,
            in long[] loggableCompatChanges, in SharedMemory serializedSystemFontMap,
            long startRequestedElapsedTime, long startRequestedUptime);
    void runIsolatedEntryPoint(in String entryPoint, in String[] entryPointArgs);
    void scheduleExit();
+7 −0
Original line number Diff line number Diff line
aconfig_declarations {
    name: "compat_logging_flags",
    package: "com.android.internal.compat.flags",
    srcs: [
        "compat_logging_flags.aconfig",
    ],
}
Loading