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

Commit 1761cfac authored by Alan Viverette's avatar Alan Viverette
Browse files

Public API for statically accessing global list of window views

Android Studio's UI inspection tool needs access to the currently displayed
window(s) via publicly-accessible APIs given only a classloader -- it does
not have any activity or app Context.

Bug: 124516440
Test: atest WindowInspectorTest
Change-Id: I960165813c260ac8f8e17cc163fabf65b1417480
parent 9515cc29
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -53987,6 +53987,10 @@ package android.view.inspector {
    ctor public PropertyReader.PropertyTypeMismatchException(int, @NonNull String, @NonNull String);
  }
  public final class WindowInspector {
    method @NonNull public static java.util.List<android.view.View> getGlobalWindowViews();
  }
}
package android.view.textclassifier {
+11 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.view;

import android.animation.ValueAnimator;
import android.annotation.NonNull;
import android.annotation.UnsupportedAppUsage;
import android.app.ActivityManager;
import android.content.ComponentCallbacks2;
@@ -269,6 +270,16 @@ public final class WindowManagerGlobal {
        return views;
    }

    /**
     * @return the list of all views attached to the global window manager
     */
    @NonNull
    public ArrayList<View> getWindowViews() {
        synchronized (mLock) {
            return new ArrayList<>(mViews);
        }
    }

    public View getWindowView(IBinder windowToken) {
        synchronized (mLock) {
            final int numViews = mViews.size();
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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 android.view.inspector;

import android.annotation.NonNull;
import android.view.View;
import android.view.WindowManagerGlobal;

import java.util.List;

/**
 * Provides access to window inspection information.
 */
public final class WindowInspector {
    private WindowInspector() {
        // Non-instantiable.
    }

    /**
     * @return the list of all window views attached to the current process
     */
    @NonNull
    public static List<View> getGlobalWindowViews() {
        return WindowManagerGlobal.getInstance().getWindowViews();
    }
}