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

Commit d2c5f456 authored by Ember Rose's avatar Ember Rose
Browse files

Refactor Inspector API

InspectionHelper has been renamed to InspectionCompanion for clarity
about its lifecycle. The APIs needed to be accessed from the context of
an inspection agent injected by the profiler have been made public.

With a tightend focus on platfrom views and XML resource IDs, the
@InspectableProperty annotation now has affordances for specifying an
attribute resource ID and for defining @IntDef flag and enum mappings.
@InspectableChildren has been removed, as this will be special cased in
the injected inspector. Additionally, support for attribute ID is now
provided in all PropertyMapper methods.

Additionally, PropertyMapper and PropertyReader now have support for
Gravity ints, @ColorInt, @ColorLong, and Color objects.

Test: mmma frameworks/base
Bug: 120224687
Change-Id: If455e2d1d9693eac39c33fc35f892baf75671ba4
parent 9ebc59e9
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -777,9 +777,11 @@ java_library {
java_library_host {
    name: "inspector-annotation",
    srcs: [
        "core/java/android/view/inspector/InspectableChildren.java",
        "core/java/android/view/inspector/InspectableNodeName.java",
        "core/java/android/view/inspector/InspectableProperty.java",
        // Needed for the ResourceId.ID_NULL constant
        "core/java/android/content/res/ResourceId.java",
        "core/java/android/annotation/AnyRes.java",
    ],
}

+80 −0
Original line number Diff line number Diff line
@@ -51842,6 +51842,86 @@ package android.view.inputmethod {
}
package android.view.inspector {
  public abstract interface InspectionCompanion<T> {
    method public default java.lang.String getNodeName();
    method public abstract void mapProperties(android.view.inspector.PropertyMapper);
    method public abstract void readProperties(T, android.view.inspector.PropertyReader);
  }
  public static class InspectionCompanion.UninitializedPropertyMapException extends java.lang.RuntimeException {
    ctor public InspectionCompanion.UninitializedPropertyMapException();
  }
  public final class IntEnumMapping {
    method public java.lang.String nameOf(int);
  }
  public static final class IntEnumMapping.Builder {
    ctor public IntEnumMapping.Builder();
    method public android.view.inspector.IntEnumMapping.Builder addValue(java.lang.String, int);
    method public android.view.inspector.IntEnumMapping build();
    method public void clear();
  }
  public final class IntFlagMapping {
    method public java.lang.String[] namesOf(int);
  }
  public static final class IntFlagMapping.Builder {
    ctor public IntFlagMapping.Builder();
    method public android.view.inspector.IntFlagMapping.Builder addFlag(java.lang.String, int);
    method public android.view.inspector.IntFlagMapping.Builder addFlag(java.lang.String, int, int);
    method public android.view.inspector.IntFlagMapping build();
    method public void clear();
  }
  public abstract interface PropertyMapper {
    method public abstract int mapBoolean(java.lang.String, int);
    method public abstract int mapByte(java.lang.String, int);
    method public abstract int mapChar(java.lang.String, int);
    method public abstract int mapColor(java.lang.String, int);
    method public abstract int mapDouble(java.lang.String, int);
    method public abstract int mapFloat(java.lang.String, int);
    method public abstract int mapGravity(java.lang.String, int);
    method public abstract int mapInt(java.lang.String, int);
    method public abstract int mapIntEnum(java.lang.String, int, android.view.inspector.IntEnumMapping);
    method public abstract int mapIntFlag(java.lang.String, int, android.view.inspector.IntFlagMapping);
    method public abstract int mapLong(java.lang.String, int);
    method public abstract int mapObject(java.lang.String, int);
    method public abstract int mapShort(java.lang.String, int);
  }
  public static class PropertyMapper.PropertyConflictException extends java.lang.RuntimeException {
    ctor public PropertyMapper.PropertyConflictException(java.lang.String, java.lang.String, java.lang.String);
  }
  public abstract interface PropertyReader {
    method public abstract void readBoolean(int, boolean);
    method public abstract void readByte(int, byte);
    method public abstract void readChar(int, char);
    method public abstract void readColor(int, int);
    method public abstract void readColor(int, long);
    method public abstract void readColor(int, android.graphics.Color);
    method public abstract void readDouble(int, double);
    method public abstract void readFloat(int, float);
    method public abstract void readGravity(int, int);
    method public abstract void readInt(int, int);
    method public abstract void readIntEnum(int, int);
    method public abstract void readIntFlag(int, int);
    method public abstract void readLong(int, long);
    method public abstract void readObject(int, java.lang.Object);
    method public abstract void readShort(int, short);
  }
  public static class PropertyReader.PropertyTypeMismatchException extends java.lang.RuntimeException {
    ctor public PropertyReader.PropertyTypeMismatchException(int, java.lang.String, java.lang.String, java.lang.String);
    ctor public PropertyReader.PropertyTypeMismatchException(int, java.lang.String, java.lang.String);
  }
}
package android.view.intelligence {
  public final class IntelligenceManager {
+0 −46
Original line number Diff line number Diff line
/*
 * Copyright 2018 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;

/**
 * Interface for visiting all the child nodes of an inspectable object.
 *
 * Inspectable objects may return a collection of children as an array, an {@link Iterable} or an
 * {@link java.util.Iterator}. This provides a unified API for traversing across all the children
 * of an inspectable node.
 *
 * This interface is consumed by {@link InspectionHelper#traverseChildren(Object, ChildTraverser)}
 * and may be implemented as a lambda.
 *
 * @see InspectionHelper#traverseChildren(Object, ChildTraverser)
 * @hide
 */
@FunctionalInterface
public interface ChildTraverser {
    /**
     * Visit one child object of a parent inspectable object.
     *
     * The iteration interface will filter null values out before passing them to this method, but
     * some child objects may not be inspectable. It is up to the implementor to determine their
     * inspectablity and what to do with them.
     *
     * @param child A child object, guaranteed not to be null.
     */
    void traverseChild(@NonNull Object child);
}
+0 −46
Original line number Diff line number Diff line
/*
 * Copyright 2018 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 static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.SOURCE;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

/**
 * Marks a getter for an inspectable node's inspectable children.
 *
 * This annotation can be applied to any getter that returns a collection of objects, either an
 * array, an {@link Iterable} or a {@link java.util.Iterator}. The getter may return null, which
 * will be treated as an empty collection. Additionally, the inspector will discard any null
 * entries in the collection.
 *
 * By default, this annotation is inherited. At runtime, the inspector introspects on the class
 * hierachy and uses the annotated getter from the bottommost class, if different from any
 * annoated getters of the parent class. If a class inherits from a parent class with an annotated
 * getter, but does not include this annotation, the child class will be traversed using the
 * getter annotated on the parent. This holds true even if the child class overrides the getter.
 *
 * @see InspectionHelper#traverseChildren(Object, ChildTraverser)
 * @see InspectionHelper#hasChildTraversal()
 * @hide
 */
@Target({METHOD})
@Retention(SOURCE)
public @interface InspectableChildren {
}
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ import java.lang.annotation.Target;
 * This annotation does not inherit. If a class extends an annotated parent class, but does not
 * annotate itself, its node name will be inferred from its Java name.
 *
 * @see InspectionHelper#getNodeName()
 * @see InspectionCompanion#getNodeName()
 * @hide
 */
@Target({TYPE})
Loading