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

Commit 9a461698 authored by Wenhui Yang's avatar Wenhui Yang Committed by Android (Google) Code Review
Browse files

Merge "Include visible window clients when dumping activities in bugreport" into main

parents ef114f60 ee1bc328
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -128,4 +128,9 @@ oneway interface IWindow {
     * @param callbacks to receive responses
     */
    void requestScrollCapture(in IScrollCaptureResponseListener callbacks);

    /**
     * Dump the details of a window.
     */
    void dumpWindow(in ParcelFileDescriptor pfd);
}
+25 −0
Original line number Diff line number Diff line
@@ -195,6 +195,7 @@ import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.StrictMode;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.Trace;
@@ -268,11 +269,15 @@ import com.android.internal.inputmethod.InputMethodDebug;
import com.android.internal.os.IResultReceiver;
import com.android.internal.os.SomeArgs;
import com.android.internal.policy.PhoneFallbackEventHandler;
import com.android.internal.util.FastPrintWriter;
import com.android.internal.view.BaseSurfaceHolder;
import com.android.internal.view.RootViewSurfaceTaker;
import com.android.internal.view.SurfaceCallbackHelper;
import com.android.modules.expresslog.Counter;
import libcore.io.IoUtils;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
@@ -11521,6 +11526,26 @@ public final class ViewRootImpl implements ViewParent,
                viewAncestor.dispatchScrollCaptureRequest(listener);
            }
        }
        @Override
        public void dumpWindow(ParcelFileDescriptor pfd) {
            final ViewRootImpl viewAncestor = mViewAncestor.get();
            if (viewAncestor == null) {
                return;
            }
            viewAncestor.mHandler.postAtFrontOfQueue(() -> {
                final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
                try {
                    PrintWriter pw = new FastPrintWriter(new FileOutputStream(
                            pfd.getFileDescriptor()));
                    viewAncestor.dump("", pw);
                    pw.flush();
                } finally {
                    IoUtils.closeQuietly(pfd);
                    StrictMode.setThreadPolicy(oldPolicy);
                }
            });
        }
    }
    public static final class CalledFromWrongThreadException extends AndroidRuntimeException {
+5 −0
Original line number Diff line number Diff line
@@ -162,4 +162,9 @@ public class BaseIWindow extends IWindow.Stub {
            // ignore
        }
    }

    @Override
    public void dumpWindow(ParcelFileDescriptor pfd) {

    }
}
+5 −0
Original line number Diff line number Diff line
@@ -409,5 +409,10 @@ public class SystemWindows {
                // ignore
            }
        }

        @Override
        public void dumpWindow(ParcelFileDescriptor pfd) {

        }
    }
}
+33 −1
Original line number Diff line number Diff line
@@ -335,6 +335,7 @@ import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.IResultReceiver;
import com.android.internal.os.TransferPipe;
import com.android.internal.policy.IKeyguardDismissCallback;
import com.android.internal.policy.IKeyguardLockedStateListener;
import com.android.internal.policy.IShortcutService;
@@ -545,13 +546,16 @@ public class WindowManagerService extends IWindowManager.Stub
            if (asProto) {
                return;
            }

            final long timeoutMs = 1000L;
            mAtmService.dumpActivity(fd, pw, /* name= */ "all", /* args= */ new String[]{},
                    /* opti= */ 0,
                    /* dumpAll= */ true,
                    /* dumpVisibleRootTasksOnly= */ true,
                    /* dumpFocusedRootTaskOnly= */ false, INVALID_DISPLAY, UserHandle.USER_ALL,
                    /* timeout= */ 1000
                    timeoutMs
            );
            dumpVisibleWindowClients(fd, pw, timeoutMs);
        }

        @Override
@@ -10350,4 +10354,32 @@ public class WindowManagerService extends IWindowManager.Stub
        }
        return true;
    }

    /**
     * Dump ViewRootImpl for visible non-activity windows.
     */
    private void dumpVisibleWindowClients(FileDescriptor fd, PrintWriter pw, long timeout) {
        final ArrayList<WindowState> systemWindows = new ArrayList<>();
        synchronized (mGlobalLock) {
            mRoot.forAllWindows(w -> {
                if (!w.isActivityWindow() && w.isVisibleNow()) {
                    systemWindows.add(w);
                }
            }, false /* traverseTopToBottom */);
        }

        systemWindows.forEach(w -> {
            pw.println("---------------------------------");
            pw.println(w.toString());
            pw.flush();
            try (TransferPipe tp = new TransferPipe()) {
                w.mClient.dumpWindow(tp.getWriteFd());
                tp.go(fd, timeout);
            } catch (IOException e) {
                pw.println("Failure while dumping the window: " + e);
            } catch (RemoteException e) {
                pw.println("Got a RemoteException while dumping the window");
            }
        });
    }
}
Loading