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

Commit 24db0790 authored by Juan Sebastian Martinez's avatar Juan Sebastian Martinez
Browse files

Adding an Empty player in case of a null vibrator.

If a null vibrator is provided, an empty msdl player is created without
any functionality.

Test: presubmit
Flag: NONE usage of this API is flagged separately.
Bug: 368595426

Change-Id: Ic7d20fd72bb2b787c2dc28d0fb155f0c29d202d1
parent 41f9fbd8
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
/*
 * 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.google.android.msdl.domain

import com.google.android.msdl.data.model.FeedbackLevel
import com.google.android.msdl.data.model.MSDLToken
import com.google.android.msdl.logging.MSDLEvent

/** An empty [MSDLPlayer] that was created without a [android.os.Vibrator] */
internal class EmptyMSDLPlayer : MSDLPlayer {
    override fun getSystemFeedbackLevel(): FeedbackLevel = FeedbackLevel.NO_FEEDBACK

    override fun playToken(token: MSDLToken, properties: InteractionProperties?) {}

    override fun getHistory(): List<MSDLEvent> = listOf()

    override fun toString(): String = "Empty MSDL player without a vibrator."
}
+10 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.google.android.msdl.domain

import android.os.Vibrator
import android.util.Log
import com.google.android.msdl.data.model.FeedbackLevel
import com.google.android.msdl.data.model.HapticComposition
import com.google.android.msdl.data.model.MSDLToken
@@ -73,10 +74,18 @@ interface MSDLPlayer {
         *   created using the support information from the given vibrator.
         */
        fun createPlayer(
            vibrator: Vibrator,
            vibrator: Vibrator?,
            executor: Executor = Executors.newSingleThreadExecutor(),
            useHapticFeedbackForToken: Map<MSDLToken, Boolean>? = null,
        ): MSDLPlayer {
            // Return an empty player if no vibrator is available
            if (vibrator == null) {
                Log.w(
                    "MSDLPlayer",
                    "A null vibrator was used to create a MSDLPlayer. An empty player was created",
                )
                return EmptyMSDLPlayer()
            }

            // Create repository
            val repository = MSDLRepositoryImpl()
+8 −0
Original line number Diff line number Diff line
@@ -106,6 +106,14 @@ internal class MSDLPlayerImpl(

    override fun getHistory(): List<MSDLEvent> = historyLogger.getHistory()

    override fun toString(): String =
        """
            Default MSDL player implementation.
            Vibrator: $vibrator
            Repository: $repository
        """
            .trimIndent()

    companion object {
        val REQUIRED_PRIMITIVES =
            listOf(