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

Commit cc9c2a00 authored by Hongming Jin's avatar Hongming Jin
Browse files

Restructure tracing code to prepare for the adding of filtering and

searching features.

Bug: 157601519
Test: adb shell cmd accessibility start-trace
      adb shell cmd accessibility stop-trace
Change-Id: I4da67416139d018b8024f693b7dc88666867cff1
parent e7cfb0bb
Loading
Loading
Loading
Loading
+141 −145

File changed.

Preview size limit exceeded, changes collapsed.

+2 −16
Original line number Original line Diff line number Diff line
@@ -59,9 +59,8 @@ final class AccessibilityShellCommand extends ShellCommand {
                return runCallSystemAction();
                return runCallSystemAction();
            }
            }
            case "start-trace":
            case "start-trace":
                return startTrace();
            case "stop-trace":
            case "stop-trace":
                return stopTrace();
                return mService.getTraceManager().onShellCommand(cmd);
        }
        }
        return -1;
        return -1;
    }
    }
@@ -107,16 +106,6 @@ final class AccessibilityShellCommand extends ShellCommand {
        return -1;
        return -1;
    }
    }


    private int startTrace() {
        mService.startTrace();
        return 0;
    }

    private int stopTrace() {
        mService.stopTrace();
        return 0;
    }

    private Integer parseUserId() {
    private Integer parseUserId() {
        final String option = getNextOption();
        final String option = getNextOption();
        if (option != null) {
        if (option != null) {
@@ -142,9 +131,6 @@ final class AccessibilityShellCommand extends ShellCommand {
        pw.println("    Get whether binding to services provided by instant apps is allowed.");
        pw.println("    Get whether binding to services provided by instant apps is allowed.");
        pw.println("  call-system-action <ACTION_ID>");
        pw.println("  call-system-action <ACTION_ID>");
        pw.println("    Calls the system action with the given action id.");
        pw.println("    Calls the system action with the given action id.");
        pw.println("  start-trace");
        mService.getTraceManager().onHelp(pw);
        pw.println("    Start the debug tracing.");
        pw.println("  stop-trace");
        pw.println("    Stop the debug tracing.");
    }
    }
}
}
+100 −0
Original line number Original line Diff line number Diff line
/**
 * 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.
 */
package com.android.server.accessibility;

import android.annotation.NonNull;
import android.os.Binder;

import com.android.server.wm.WindowManagerInternal;

import java.io.PrintWriter;

/**
 * Manager of accessibility trace.
 */
class AccessibilityTraceManager implements AccessibilityTrace {
    private final WindowManagerInternal.AccessibilityControllerInternal mA11yController;
    private final AccessibilityManagerService mService;

    AccessibilityTraceManager(
            @NonNull WindowManagerInternal.AccessibilityControllerInternal a11yController,
            @NonNull AccessibilityManagerService service) {
        mA11yController = a11yController;
        mService = service;
    }

    @Override
    public boolean isA11yTracingEnabled() {
        return mA11yController.isAccessibilityTracingEnabled();
    }

    @Override
    public void startTrace() {
        if (!mA11yController.isAccessibilityTracingEnabled()) {
            mA11yController.startTrace();
            mService.scheduleUpdateClientsIfNeeded(mService.getCurrentUserState());
        }
    }

    @Override
    public void stopTrace() {
        if (mA11yController.isAccessibilityTracingEnabled()) {
            mA11yController.stopTrace();
            mService.scheduleUpdateClientsIfNeeded(mService.getCurrentUserState());
        }
    }

    @Override
    public void logTrace(String where) {
        logTrace(where, "");
    }

    @Override
    public void logTrace(String where, String callingParams) {
        mA11yController.logTrace(where, callingParams, "".getBytes(),
                Binder.getCallingUid(), Thread.currentThread().getStackTrace());
    }

    @Override
    public void logTrace(long timestamp, String where, String callingParams, int processId,
            long threadId, int callingUid, StackTraceElement[] callStack) {
        if (mA11yController.isAccessibilityTracingEnabled()) {
            mA11yController.logTrace(where, callingParams, "".getBytes(), callingUid, callStack,
                    timestamp, processId, threadId);
        }
    }

    int onShellCommand(String cmd) {
        switch (cmd) {
            case "start-trace": {
                startTrace();
                return 0;
            }
            case "stop-trace": {
                stopTrace();
                return 0;
            }
        }
        return -1;
    }

    void onHelp(PrintWriter pw) {
        pw.println("  start-trace");
        pw.println("    Start the debug tracing.");
        pw.println("  stop-trace");
        pw.println("    Stop the debug tracing.");
    }
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -157,7 +157,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase {
                new Object(),
                new Object(),
                mMockSecurityPolicy,
                mMockSecurityPolicy,
                mMockSystemSupport,
                mMockSystemSupport,
                mA11yms,
                mA11yms.getTraceManager(),
                mMockWindowManagerService,
                mMockWindowManagerService,
                mMockSystemActionPerformer,
                mMockSystemActionPerformer,
                mMockA11yWindowManager,
                mMockA11yWindowManager,