diff options
| author | Corina Grigoras <corinac@google.com> | 2022-03-18 14:19:43 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2022-03-18 14:19:43 +0000 |
| commit | 2907ec82abf8639cf0226bdd3eb56afa43c908d3 (patch) | |
| tree | e2be2120bc028fc6ed6dbfd691527bf18b3726c5 /core/java | |
| parent | 4fbf274bc42f0bf0d680c50d0e8910b267156908 (diff) | |
| parent | cbc4d681e7993db270a808022f572dfcc1bb55b6 (diff) | |
Merge "Move UiEventLogger interface to modules-utils." into tm-dev
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/Android.bp | 8 | ||||
| -rw-r--r-- | core/java/com/android/internal/logging/InstanceId.java | 98 | ||||
| -rw-r--r-- | core/java/com/android/internal/logging/InstanceIdSequence.java | 62 | ||||
| -rw-r--r-- | core/java/com/android/internal/logging/UiEvent.java | 30 | ||||
| -rw-r--r-- | core/java/com/android/internal/logging/UiEventLogger.java | 111 |
5 files changed, 4 insertions, 305 deletions
diff --git a/core/java/Android.bp b/core/java/Android.bp index a5526bc66431..f081a439c49c 100644 --- a/core/java/Android.bp +++ b/core/java/Android.bp @@ -145,16 +145,16 @@ genrule { out: ["com/android/internal/util/FrameworkStatsLog.java"], } +// Library that provides functionality to log UiEvents in framework space. +// If this functionality is needed outside the framework, the interfaces library +// can be re-used and a local implementation is needed. java_library { name: "uieventloggerlib", srcs: [ - "com/android/internal/logging/UiEvent.java", - "com/android/internal/logging/UiEventLogger.java", "com/android/internal/logging/UiEventLoggerImpl.java", - "com/android/internal/logging/InstanceId.java", - "com/android/internal/logging/InstanceIdSequence.java", ":statslog-framework-java-gen", ], + static_libs: ["modules-utils-uieventlogger-interface"], } filegroup { diff --git a/core/java/com/android/internal/logging/InstanceId.java b/core/java/com/android/internal/logging/InstanceId.java deleted file mode 100644 index c90d851201a2..000000000000 --- a/core/java/com/android/internal/logging/InstanceId.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2020 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.internal.logging; - -import static java.lang.Math.max; -import static java.lang.Math.min; - -import android.annotation.Nullable; -import android.os.Parcel; -import android.os.Parcelable; - -import com.android.internal.annotations.VisibleForTesting; - -/** - * An opaque identifier used to disambiguate which logs refer to a particular instance of some - * UI element. Useful when there might be multiple instances simultaneously active. - * Obtain from InstanceIdSequence. Clipped to range [0, INSTANCE_ID_MAX]. - */ -public final class InstanceId implements Parcelable { - // At most 20 bits: ~1m possibilities, ~0.5% probability of collision in 100 values - static final int INSTANCE_ID_MAX = 1 << 20; - - private final int mId; - InstanceId(int id) { - mId = min(max(0, id), INSTANCE_ID_MAX); - } - - private InstanceId(Parcel in) { - this(in.readInt()); - } - - @VisibleForTesting - public int getId() { - return mId; - } - - /** - * Create a fake instance ID for testing purposes. Not for production use. See also - * InstanceIdSequenceFake, which is a testing replacement for InstanceIdSequence. - * @param id The ID you want to assign. - * @return new InstanceId. - */ - @VisibleForTesting - public static InstanceId fakeInstanceId(int id) { - return new InstanceId(id); - } - - @Override - public int hashCode() { - return mId; - } - - @Override - public boolean equals(@Nullable Object obj) { - if (!(obj instanceof InstanceId)) { - return false; - } - return mId == ((InstanceId) obj).mId; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeInt(mId); - } - - public static final Parcelable.Creator<InstanceId> CREATOR = - new Parcelable.Creator<InstanceId>() { - @Override - public InstanceId createFromParcel(Parcel in) { - return new InstanceId(in); - } - - @Override - public InstanceId[] newArray(int size) { - return new InstanceId[size]; - } - }; - -} diff --git a/core/java/com/android/internal/logging/InstanceIdSequence.java b/core/java/com/android/internal/logging/InstanceIdSequence.java deleted file mode 100644 index 34643105b965..000000000000 --- a/core/java/com/android/internal/logging/InstanceIdSequence.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2020 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.internal.logging; - -import static java.lang.Math.max; -import static java.lang.Math.min; - -import com.android.internal.annotations.VisibleForTesting; - -import java.security.SecureRandom; -import java.util.Random; - -/** - * Generates random InstanceIds in range [1, instanceIdMax] for passing to - * UiEventLogger.logWithInstanceId(). Holds a SecureRandom, which self-seeds on - * first use; try to give it a long lifetime. Safe for concurrent use. - */ -public class InstanceIdSequence { - protected final int mInstanceIdMax; - private final Random mRandom = new SecureRandom(); - - /** - * Constructs a sequence with identifiers [1, instanceIdMax]. Capped at INSTANCE_ID_MAX. - * @param instanceIdMax Limiting value of identifiers. Normally positive: otherwise you get - * an all-1 sequence. - */ - public InstanceIdSequence(int instanceIdMax) { - mInstanceIdMax = min(max(1, instanceIdMax), InstanceId.INSTANCE_ID_MAX); - } - - /** - * Gets the next instance from the sequence. Safe for concurrent use. - * @return new InstanceId - */ - public InstanceId newInstanceId() { - return newInstanceIdInternal(1 + mRandom.nextInt(mInstanceIdMax)); - } - - /** - * Factory function for instance IDs, used for testing. - * @param id - * @return new InstanceId(id) - */ - @VisibleForTesting - protected InstanceId newInstanceIdInternal(int id) { - return new InstanceId(id); - } -} diff --git a/core/java/com/android/internal/logging/UiEvent.java b/core/java/com/android/internal/logging/UiEvent.java deleted file mode 100644 index 0407b0704e80..000000000000 --- a/core/java/com/android/internal/logging/UiEvent.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 com.android.internal.logging; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.RetentionPolicy.SOURCE; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -@Retention(SOURCE) -@Target(FIELD) -public @interface UiEvent { - /** An explanation, suitable for Android analysts, of the UI event that this log represents. */ - String doc(); -} diff --git a/core/java/com/android/internal/logging/UiEventLogger.java b/core/java/com/android/internal/logging/UiEventLogger.java deleted file mode 100644 index 5378b03fe1c5..000000000000 --- a/core/java/com/android/internal/logging/UiEventLogger.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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 com.android.internal.logging; - -import android.annotation.NonNull; -import android.annotation.Nullable; - -/** - * Logging interface for UI events. Normal implementation is UiEventLoggerImpl. - * For testing, use fake implementation UiEventLoggerFake. - * - * See go/sysui-event-logs and UiEventReported atom in atoms.proto. - */ -public interface UiEventLogger { - /** Put your Event IDs in enums that implement this interface, and document them using the - * UiEventEnum annotation. - * Event IDs must be globally unique. This will be enforced by tooling (forthcoming). - * OEMs should use event IDs above 100000 and below 1000000 (1 million). - */ - interface UiEventEnum { - - /** - * Tag used to request new UI Event IDs via presubmit analysis. - * - * <p>Use RESERVE_NEW_UI_EVENT_ID as the constructor parameter for a new {@link EventEnum} - * to signal the presubmit analyzer to reserve a new ID for the event. The new ID will be - * returned as a Gerrit presubmit finding. Do not submit {@code RESERVE_NEW_UI_EVENT_ID} as - * the constructor parameter for any event. - * - * <pre> - * @UiEvent(doc = "Briefly describe the interaction when this event will be logged") - * UNIQUE_EVENT_NAME(RESERVE_NEW_UI_EVENT_ID); - * </pre> - */ - int RESERVE_NEW_UI_EVENT_ID = Integer.MIN_VALUE; // Negative IDs are ignored by the logger. - - int getId(); - } - - /** - * Log a simple event, with no package information. Does nothing if event.getId() <= 0. - * @param event an enum implementing UiEventEnum interface. - */ - void log(@NonNull UiEventEnum event); - - /** - * Log a simple event with an instance id, without package information. - * Does nothing if event.getId() <= 0. - * @param event an enum implementing UiEventEnum interface. - * @param instance An identifier obtained from an InstanceIdSequence. If null, reduces to log(). - */ - void log(@NonNull UiEventEnum event, @Nullable InstanceId instance); - - /** - * Log an event with package information. Does nothing if event.getId() <= 0. - * Give both uid and packageName if both are known, but one may be omitted if unknown. - * @param event an enum implementing UiEventEnum interface. - * @param uid the uid of the relevant app, if known (0 otherwise). - * @param packageName the package name of the relevant app, if known (null otherwise). - */ - void log(@NonNull UiEventEnum event, int uid, @Nullable String packageName); - - /** - * Log an event with package information and an instance ID. - * Does nothing if event.getId() <= 0. - * @param event an enum implementing UiEventEnum interface. - * @param uid the uid of the relevant app, if known (0 otherwise). - * @param packageName the package name of the relevant app, if known (null otherwise). - * @param instance An identifier obtained from an InstanceIdSequence. If null, reduces to log(). - */ - void logWithInstanceId(@NonNull UiEventEnum event, int uid, @Nullable String packageName, - @Nullable InstanceId instance); - - /** - * Log an event with ranked-choice information along with package. - * Does nothing if event.getId() <= 0. - * @param event an enum implementing UiEventEnum interface. - * @param uid the uid of the relevant app, if known (0 otherwise). - * @param packageName the package name of the relevant app, if known (null otherwise). - * @param position the position picked. - */ - void logWithPosition(@NonNull UiEventEnum event, int uid, @Nullable String packageName, - int position); - - /** - * Log an event with ranked-choice information along with package and instance ID. - * Does nothing if event.getId() <= 0. - * @param event an enum implementing UiEventEnum interface. - * @param uid the uid of the relevant app, if known (0 otherwise). - * @param packageName the package name of the relevant app, if known (null otherwise). - * @param instance An identifier obtained from an InstanceIdSequence. If null, reduces to - * logWithPosition(). - * @param position the position picked. - */ - void logWithInstanceIdAndPosition(@NonNull UiEventEnum event, int uid, - @Nullable String packageName, @Nullable InstanceId instance, int position); -} |
