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

Commit a0dccf47 authored by Julia Tuttle's avatar Julia Tuttle Committed by Android (Google) Code Review
Browse files

Merge "Add Dagger-injectable version of android.util.EventLog" into main

parents b02c0f06 cf6278cb
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -130,6 +130,7 @@ import com.android.systemui.tuner.dagger.TunerModule;
import com.android.systemui.unfold.SysUIUnfoldModule;
import com.android.systemui.user.UserModule;
import com.android.systemui.user.domain.UserDomainLayerModule;
import com.android.systemui.util.EventLogModule;
import com.android.systemui.util.concurrency.SysUIConcurrencyModule;
import com.android.systemui.util.dagger.UtilModule;
import com.android.systemui.util.kotlin.CoroutinesModule;
@@ -186,6 +187,7 @@ import javax.inject.Named;
        DisableFlagsModule.class,
        DisplayModule.class,
        DreamModule.class,
        EventLogModule.class,
        FalsingModule.class,
        FlagsModule.class,
        FlagDependenciesModule.class,
+43 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.systemui.util

/**
 * Testable wrapper around {@link android.util.EventLog}.
 *
 * Dagger can inject this wrapper into your classes. The implementation just proxies calls to the
 * real EventLog.
 *
 * In tests, pass an instance of FakeEventLog, which allows you to examine the values passed to the
 * various methods below.
 */
interface EventLog {
    /** @see android.util.EventLog.writeEvent */
    fun writeEvent(tag: Int, value: Int): Int

    /** @see android.util.EventLog.writeEvent */
    fun writeEvent(tag: Int, value: Long): Int

    /** @see android.util.EventLog.writeEvent */
    fun writeEvent(tag: Int, value: Float): Int

    /** @see android.util.EventLog.writeEvent */
    fun writeEvent(tag: Int, value: String): Int

    /** @see android.util.EventLog.writeEvent */
    fun writeEvent(tag: Int, vararg values: Any): Int
}
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.systemui.util

import javax.inject.Inject

/** Default implementation of [com.android.systemui.util.EventLog]. */
class EventLogImpl @Inject constructor() : EventLog {
    override fun writeEvent(tag: Int, value: Int): Int =
        android.util.EventLog.writeEvent(tag, value)

    override fun writeEvent(tag: Int, value: Long): Int =
        android.util.EventLog.writeEvent(tag, value)

    override fun writeEvent(tag: Int, value: Float): Int =
        android.util.EventLog.writeEvent(tag, value)

    override fun writeEvent(tag: Int, value: String): Int =
        android.util.EventLog.writeEvent(tag, value)

    override fun writeEvent(tag: Int, vararg values: Any): Int =
        android.util.EventLog.writeEvent(tag, *values)
}
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.systemui.util

import com.android.systemui.dagger.SysUISingleton
import dagger.Binds
import dagger.Module

@Module
interface EventLogModule {
    @SysUISingleton @Binds fun bindEventLog(eventLogImpl: EventLogImpl?): EventLog?
}
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.systemui.util

/** A fake [com.android.systemui.util.EventLog] for tests. */
class FakeEventLog : EventLog {
    data class Event(val tag: Int, val value: Any)

    private val _events: MutableList<Event> = mutableListOf()
    val events: List<Event>
        get() = _events

    fun clear() {
        _events.clear()
    }

    override fun writeEvent(tag: Int, value: Int): Int {
        _events.add(Event(tag, value))
        return 1
    }

    override fun writeEvent(tag: Int, value: Long): Int {
        _events.add(Event(tag, value))
        return 1
    }

    override fun writeEvent(tag: Int, value: Float): Int {
        _events.add(Event(tag, value))
        return 1
    }

    override fun writeEvent(tag: Int, value: String): Int {
        _events.add(Event(tag, value))
        return 1
    }

    override fun writeEvent(tag: Int, vararg values: Any): Int {
        _events.add(Event(tag, values))
        return 1
    }
}