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

Commit 0f4986c2 authored by Hongming Jin's avatar Hongming Jin Committed by Android (Google) Code Review
Browse files

Merge "Restructure tracing code to prepare for the adding of filtering and...

Merge "Restructure tracing code to prepare for the adding of filtering and searching features." into sc-dev
parents e2b7cb3d cc9c2a00
Loading
Loading
Loading
Loading
+141 −145

File changed.

Preview size limit exceeded, changes collapsed.

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

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

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

    private Integer parseUserId() {
        final String option = getNextOption();
        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("  call-system-action <ACTION_ID>");
        pw.println("    Calls the system action with the given action id.");
        pw.println("  start-trace");
        pw.println("    Start the debug tracing.");
        pw.println("  stop-trace");
        pw.println("    Stop the debug tracing.");
        mService.getTraceManager().onHelp(pw);
    }
}
+100 −0
Original line number 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 Diff line number Diff line
@@ -157,7 +157,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase {
                new Object(),
                mMockSecurityPolicy,
                mMockSystemSupport,
                mA11yms,
                mA11yms.getTraceManager(),
                mMockWindowManagerService,
                mMockSystemActionPerformer,
                mMockA11yWindowManager,