1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.media.taptotransfer.receiver 18 19 import android.app.StatusBarManager 20 import android.util.Log 21 import com.android.internal.logging.UiEventLogger 22 23 /** 24 * A class that stores all the information necessary to display the media tap-to-transfer chip on 25 * the receiver device. 26 */ 27 enum class ChipStateReceiver( 28 @StatusBarManager.MediaTransferSenderState val stateInt: Int, 29 val uiEvent: UiEventLogger.UiEventEnum 30 ) { 31 CLOSE_TO_SENDER( 32 StatusBarManager.MEDIA_TRANSFER_RECEIVER_STATE_CLOSE_TO_SENDER, 33 MediaTttReceiverUiEvents.MEDIA_TTT_RECEIVER_CLOSE_TO_SENDER 34 ), 35 FAR_FROM_SENDER( 36 StatusBarManager.MEDIA_TRANSFER_RECEIVER_STATE_FAR_FROM_SENDER, 37 MediaTttReceiverUiEvents.MEDIA_TTT_RECEIVER_FAR_FROM_SENDER 38 ), 39 TRANSFER_TO_RECEIVER_SUCCEEDED( 40 StatusBarManager.MEDIA_TRANSFER_RECEIVER_STATE_TRANSFER_TO_RECEIVER_SUCCEEDED, 41 MediaTttReceiverUiEvents.MEDIA_TTT_RECEIVER_TRANSFER_TO_RECEIVER_SUCCEEDED, 42 ), 43 TRANSFER_TO_RECEIVER_FAILED( 44 StatusBarManager.MEDIA_TRANSFER_RECEIVER_STATE_TRANSFER_TO_RECEIVER_FAILED, 45 MediaTttReceiverUiEvents.MEDIA_TTT_RECEIVER_TRANSFER_TO_RECEIVER_FAILED, 46 ); 47 48 companion object { 49 /** 50 * Returns the receiver state enum associated with the given [displayState] from 51 * [StatusBarManager]. 52 */ getReceiverStateFromIdnull53 fun getReceiverStateFromId( 54 @StatusBarManager.MediaTransferReceiverState displayState: Int 55 ): ChipStateReceiver? = 56 try { 57 values().first { it.stateInt == displayState } 58 } catch (e: NoSuchElementException) { 59 Log.e(TAG, "Could not find requested state $displayState", e) 60 null 61 } 62 63 /** 64 * Returns the state int from [StatusBarManager] associated with the given sender state 65 * name. 66 * 67 * @param name the name of one of the [ChipStateReceiver] enums. 68 */ 69 @StatusBarManager.MediaTransferReceiverState getReceiverStateIdFromNamenull70 fun getReceiverStateIdFromName(name: String): Int = valueOf(name).stateInt 71 } 72 } 73 74 private const val TAG = "ChipStateReceiver" 75