Skip to content
Snippets Groups Projects
Commit 0d2ecc61 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Baseline `logging` support for SysUI.

SysUI code heavily relies on utility classes under the `logging`
internal package, which are pretty straightforward.  This change
enables them under Ravenwood, along with tests to confirm.

Some of the foundational interfaces have been moved to modules-utils,
which isn't yet configured to support our Ravenwood annotations, so
we use hard-coded policies.

Bug: 319647875
Test: atest FrameworksCoreTestsRavenwood
Change-Id: I7e670d31e89a0be741df1c118ecc19c91a24d8fb
parent ff93fc40
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,7 @@ import java.util.Arrays;
* @hide
*/
@SystemApi
@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class LogMaker {
private static final String TAG = "LogBuilder";
......
......@@ -34,6 +34,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
*
* @hide
*/
@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class MetricsLogger {
// define metric categories in frameworks/base/proto/src/metrics_constants.proto.
// mirror changes in native version at system/core/libmetricslogger/metrics_logger.cpp
......
......@@ -12,6 +12,7 @@ import java.util.Queue;
*
* @hide.
*/
@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class FakeMetricsLogger extends MetricsLogger {
private Queue<LogMaker> logs = new LinkedList<>();
......
......@@ -27,6 +27,7 @@ import java.util.List;
*
* @hide.
*/
@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class UiEventLoggerFake implements UiEventLogger {
/**
* Immutable data class used to record fake log events.
......
......@@ -212,8 +212,8 @@ android_ravenwood_test {
"src/android/database/CursorWindowTest.java",
"src/android/os/**/*.java",
"src/android/util/**/*.java",
"src/com/android/internal/logging/**/*.java",
"src/com/android/internal/os/**/*.java",
"src/com/android/internal/os/LongArrayMultiStateCounterTest.java",
"src/com/android/internal/util/**/*.java",
"src/com/android/internal/power/EnergyConsumerStatsTest.java",
......
/*
* Copyright (C) 2024 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 com.google.common.truth.Truth.assertThat;
import android.metrics.LogMaker;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.logging.testing.FakeMetricsLogger;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class MetricsLoggerTest {
private FakeMetricsLogger mLogger;
private static final int TEST_ACTION = 42;
@Before
public void setUp() throws Exception {
mLogger = new FakeMetricsLogger();
}
@Test
public void testEmpty() throws Exception {
assertThat(mLogger.getLogs().size()).isEqualTo(0);
}
@Test
public void testAction() throws Exception {
mLogger.action(TEST_ACTION);
assertThat(mLogger.getLogs().size()).isEqualTo(1);
final LogMaker event = mLogger.getLogs().peek();
assertThat(event.getType()).isEqualTo(MetricsProto.MetricsEvent.TYPE_ACTION);
assertThat(event.getCategory()).isEqualTo(TEST_ACTION);
}
@Test
public void testVisible() throws Exception {
// Limited testing to confirm we don't crash
mLogger.visible(TEST_ACTION);
mLogger.hidden(TEST_ACTION);
mLogger.visibility(TEST_ACTION, true);
mLogger.visibility(TEST_ACTION, false);
}
}
/*
* Copyright (C) 2024 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 com.google.common.truth.Truth.assertThat;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.internal.logging.testing.UiEventLoggerFake;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class UiEventLoggerTest {
private UiEventLoggerFake mLogger;
private static final int TEST_EVENT_ID = 42;
private static final int TEST_INSTANCE_ID = 21;
private enum MyUiEventEnum implements UiEventLogger.UiEventEnum {
@UiEvent(doc = "Example event")
TEST_EVENT(TEST_EVENT_ID);
private final int mId;
MyUiEventEnum(int id) {
mId = id;
}
@Override
public int getId() {
return mId;
}
}
private InstanceId TEST_INSTANCE = InstanceId.fakeInstanceId(TEST_INSTANCE_ID);
@Before
public void setUp() throws Exception {
mLogger = new UiEventLoggerFake();
}
@Test
public void testEmpty() throws Exception {
assertThat(mLogger.numLogs()).isEqualTo(0);
}
@Test
public void testSimple() throws Exception {
mLogger.log(MyUiEventEnum.TEST_EVENT);
assertThat(mLogger.numLogs()).isEqualTo(1);
assertThat(mLogger.eventId(0)).isEqualTo(TEST_EVENT_ID);
}
@Test
public void testWithInstance() throws Exception {
mLogger.log(MyUiEventEnum.TEST_EVENT, TEST_INSTANCE);
assertThat(mLogger.numLogs()).isEqualTo(1);
assertThat(mLogger.eventId(0)).isEqualTo(TEST_EVENT_ID);
assertThat(mLogger.get(0).instanceId.getId()).isEqualTo(TEST_INSTANCE_ID);
}
}
......@@ -112,6 +112,12 @@ class android.os.HandlerExecutor stubclass
class android.os.PatternMatcher stubclass
class android.os.ParcelUuid stubclass
# Logging related interfaces from modules-utils
class com.android.internal.logging.InstanceId stubclass
class com.android.internal.logging.InstanceIdSequence stubclass
class com.android.internal.logging.UiEvent stubclass
class com.android.internal.logging.UiEventLogger stubclass
# XML
class com.android.internal.util.XmlPullParserWrapper stubclass
class com.android.internal.util.XmlSerializerWrapper stubclass
......
# Only classes listed here can use the Ravenwood annotations.
com.android.internal.util.ArrayUtils
com.android.internal.logging.MetricsLogger
com.android.internal.logging.testing.FakeMetricsLogger
com.android.internal.logging.testing.UiEventLoggerFake
com.android.internal.os.BatteryStatsHistory
com.android.internal.os.BatteryStatsHistory$TraceDelegate
com.android.internal.os.BatteryStatsHistory$VarintParceler
......@@ -126,6 +129,8 @@ android.graphics.RectF
android.content.ContentProvider
android.metrics.LogMaker
com.android.server.LocalServices
com.android.server.power.stats.BatteryStatsImpl
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment