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

Commit 1faafcb4 authored by Andrei-Valentin Onea's avatar Andrei-Valentin Onea Committed by Gerrit Code Review
Browse files

Merge "Add adb command for overriding platform compat config"

parents 929cb5fc c1ba0192
Loading
Loading
Loading
Loading
+58 −9
Original line number Diff line number Diff line
@@ -16,6 +16,15 @@

package com.android.server.am;

import static android.app.ActivityManager.RESIZE_MODE_SYSTEM;
import static android.app.ActivityManager.RESIZE_MODE_USER;
import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.view.Display.INVALID_DISPLAY;

import static com.android.server.am.TaskRecord.INVALID_TASK_ID;

import android.app.ActivityManager;
import android.app.ActivityOptions;
import android.app.AppGlobals;
@@ -74,6 +83,7 @@ import android.view.Display;
import com.android.internal.util.HexDump;
import com.android.internal.util.MemInfoReader;
import com.android.internal.util.Preconditions;
import com.android.server.compat.CompatConfig;

import java.io.BufferedReader;
import java.io.File;
@@ -96,15 +106,6 @@ import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;

import static android.app.ActivityManager.RESIZE_MODE_SYSTEM;
import static android.app.ActivityManager.RESIZE_MODE_USER;
import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.view.Display.INVALID_DISPLAY;

import static com.android.server.am.TaskRecord.INVALID_TASK_ID;

final class ActivityManagerShellCommand extends ShellCommand {
    public static final String NO_CLASS_ERROR_CODE = "Error type 3";
    private static final String SHELL_PACKAGE_NAME = "com.android.shell";
@@ -277,6 +278,8 @@ final class ActivityManagerShellCommand extends ShellCommand {
                    return runNoHomeScreen(pw);
                case "wait-for-broadcast-idle":
                    return runWaitForBroadcastIdle(pw);
                case "compat":
                    return runCompat(pw);
                default:
                    return handleDefaultCommands(cmd);
            }
@@ -2794,6 +2797,50 @@ final class ActivityManagerShellCommand extends ShellCommand {
        return 0;
    }

    private int runCompat(PrintWriter pw) {
        final CompatConfig config = CompatConfig.get();
        String toggleValue = getNextArgRequired();
        long changeId;
        String changeIdString = getNextArgRequired();
        try {
            changeId = Long.parseLong(changeIdString);
        } catch (NumberFormatException e) {
            changeId = config.lookupChangeId(changeIdString);
        }
        if (changeId == -1) {
            pw.println("Unknown or invalid change: '" + changeIdString + "'.");
        }
        String packageName = getNextArgRequired();
        switch(toggleValue) {
            case "enable":
                if (!config.addOverride(changeId, packageName, true)) {
                    pw.println("Warning! Change " + changeId + " is not known yet. Enabling it"
                            + " could have no effect.");
                }
                pw.println("Enabled change " + changeId + " for " + packageName + ".");
                return 0;
            case "disable":
                if (!config.addOverride(changeId, packageName, false)) {
                    pw.println("Warning! Change " + changeId + " is not known yet. Disabling it"
                            + " could have no effect.");
                }
                pw.println("Disabled change " + changeId + " for " + packageName + ".");
                return 0;
            case "reset":
                if (config.removeOverride(changeId, packageName)) {
                    pw.println("Reset change " + changeId + " for " + packageName
                            + " to default value.");
                } else {
                    pw.println("No override exists for changeId " + changeId + ".");
                }
                return 0;
            default:
                pw.println("Invalid toggle value: '" + toggleValue + "'.");
        }
        return -1;
    }


    private Resources getResources(PrintWriter pw) throws RemoteException {
        // system resources does not contain all the device configuration, construct it manually.
        Configuration config = mInterface.getConfiguration();
@@ -3090,6 +3137,8 @@ final class ActivityManagerShellCommand extends ShellCommand {
            pw.println("      without restarting any processes.");
            pw.println("  write");
            pw.println("      Write all pending state to storage.");
            pw.println("  compat enable|disable|reset <CHANGE_ID|CHANGE_NAME> <PACKAGE_NAME>");
            pw.println("      Toggles a change either by id or by name for <PACKAGE_NAME>.");
            pw.println();
            Intent.printIntentArgsHelp(pw, "");
        }
+11 −3
Original line number Diff line number Diff line
@@ -128,20 +128,24 @@ public final class CompatConfig {
     * <p>Note, package overrides are not persistent and will be lost on system or runtime restart.
     *
     * @param changeId The ID of the change to be overridden. Note, this call will succeed even if
     *                 this change is not known; it will only have any affect if any code in the
     *                 this change is not known; it will only have any effect if any code in the
     *                 platform is gated on the ID given.
     * @param packageName The app package name to override the change for.
     * @param enabled If the change should be enabled or disabled.
     * @return {@code true} if the change existed before adding the override.
     */
    public void addOverride(long changeId, String packageName, boolean enabled) {
    public boolean addOverride(long changeId, String packageName, boolean enabled) {
        boolean alreadyKnown = true;
        synchronized (mChanges) {
            CompatChange c = mChanges.get(changeId);
            if (c == null) {
                alreadyKnown = false;
                c = new CompatChange(changeId);
                addChange(c);
            }
            c.addPackageOverride(packageName, enabled);
        }
        return alreadyKnown;
    }

    /**
@@ -151,14 +155,18 @@ public final class CompatConfig {
     *
     * @param changeId The ID of the change that was overridden.
     * @param packageName The app package name that was overridden.
     * @return {@code true} if an override existed;
     */
    public void removeOverride(long changeId, String packageName) {
    public boolean removeOverride(long changeId, String packageName) {
        boolean overrideExists = false;
        synchronized (mChanges) {
            CompatChange c = mChanges.get(changeId);
            if (c != null) {
                overrideExists = true;
                c.removePackageOverride(packageName);
            }
        }
        return overrideExists;
    }

}