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

Commit 2b2cfe57 authored by Brad Hinegardner's avatar Brad Hinegardner Committed by Automerger Merge Worker
Browse files

Merge "Create Flashlight Prebuilt quick affordance" into tm-qpr-dev am: b96b7ad9 am: 5149cb02

parents 8e7404af 5149cb02
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
<!--
  ~ Copyright (C) 2022 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
  -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24"
    android:tint="?attr/colorControlNormal">
  <path
      android:fillColor="#1f1f1f"
      android:pathData="M8,22V11L6,8V2H18V8L16,11V22ZM12,15.5Q11.375,15.5 10.938,15.062Q10.5,14.625 10.5,14Q10.5,13.375 10.938,12.938Q11.375,12.5 12,12.5Q12.625,12.5 13.062,12.938Q13.5,13.375 13.5,14Q13.5,14.625 13.062,15.062Q12.625,15.5 12,15.5ZM8,5H16V4H8ZM16,7H8V7.4L10,10.4V20H14V10.4L16,7.4ZM12,12Z"/>
</vector>
+25 −0
Original line number Diff line number Diff line
<!--
  ~ Copyright (C) 2022 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
  -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24"
    android:tint="?attr/colorControlNormal">
  <path
      android:fillColor="#1f1f1f"
      android:pathData="M6,5V2H18V5ZM12,15.5Q12.625,15.5 13.062,15.062Q13.5,14.625 13.5,14Q13.5,13.375 13.062,12.938Q12.625,12.5 12,12.5Q11.375,12.5 10.938,12.938Q10.5,13.375 10.5,14Q10.5,14.625 10.938,15.062Q11.375,15.5 12,15.5ZM8,22V11L6,8V7H18V8L16,11V22Z"/>
</vector>
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ package com.android.systemui.keyguard.data.quickaffordance
object BuiltInKeyguardQuickAffordanceKeys {
    // Please keep alphabetical order of const names to simplify future maintenance.
    const val CAMERA = "camera"
    const val FLASHLIGHT = "flashlight"
    const val HOME_CONTROLS = "home"
    const val QR_CODE_SCANNER = "qr_code_scanner"
    const val QUICK_ACCESS_WALLET = "wallet"
+144 −0
Original line number Diff line number Diff line
/*
 *  Copyright (C) 2022 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.keyguard.data.quickaffordance

import android.content.Context
import com.android.systemui.R
import com.android.systemui.animation.Expandable
import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.common.shared.model.ContentDescription
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.keyguard.shared.quickaffordance.ActivationState
import com.android.systemui.statusbar.policy.FlashlightController
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@SysUISingleton
class FlashlightQuickAffordanceConfig @Inject constructor(
        @Application private val context: Context,
        private val flashlightController: FlashlightController,
) : KeyguardQuickAffordanceConfig {

    private sealed class FlashlightState {

        abstract fun toLockScreenState(): KeyguardQuickAffordanceConfig.LockScreenState

        object On: FlashlightState() {
            override fun toLockScreenState(): KeyguardQuickAffordanceConfig.LockScreenState =
                KeyguardQuickAffordanceConfig.LockScreenState.Visible(
                    Icon.Resource(
                        R.drawable.ic_flashlight_on,
                        ContentDescription.Resource(R.string.quick_settings_flashlight_label)
                    ),
                    ActivationState.Active
                )
        }

        object OffAvailable: FlashlightState() {
            override fun toLockScreenState(): KeyguardQuickAffordanceConfig.LockScreenState =
                KeyguardQuickAffordanceConfig.LockScreenState.Visible(
                    Icon.Resource(
                        R.drawable.ic_flashlight_off,
                        ContentDescription.Resource(R.string.quick_settings_flashlight_label)
                    ),
                    ActivationState.Inactive
                )
        }

        object Unavailable: FlashlightState() {
            override fun toLockScreenState(): KeyguardQuickAffordanceConfig.LockScreenState =
                KeyguardQuickAffordanceConfig.LockScreenState.Hidden
        }
    }

    override val key: String
        get() = BuiltInKeyguardQuickAffordanceKeys.FLASHLIGHT

    override val pickerName: String
        get() = context.getString(R.string.quick_settings_flashlight_label)

    override val pickerIconResourceId: Int
        get() = if (flashlightController.isEnabled) {
            R.drawable.ic_flashlight_on
        } else {
            R.drawable.ic_flashlight_off
        }

    override val lockScreenState: Flow<KeyguardQuickAffordanceConfig.LockScreenState> =
            conflatedCallbackFlow {
        val flashlightCallback = object : FlashlightController.FlashlightListener {
            override fun onFlashlightChanged(enabled: Boolean) {
                trySendWithFailureLogging(
                    if (enabled) {
                        FlashlightState.On.toLockScreenState()
                    } else {
                        FlashlightState.OffAvailable.toLockScreenState()
                    },
                    TAG
                )
            }

            override fun onFlashlightError() {
                trySendWithFailureLogging(FlashlightState.OffAvailable.toLockScreenState(), TAG)
            }

            override fun onFlashlightAvailabilityChanged(available: Boolean) {
                trySendWithFailureLogging(
                    if (!available) {
                        FlashlightState.Unavailable.toLockScreenState()
                    } else {
                        if (flashlightController.isEnabled) {
                            FlashlightState.On.toLockScreenState()
                        } else {
                            FlashlightState.OffAvailable.toLockScreenState()
                        }
                    },
                    TAG
                )
            }
        }

        flashlightController.addCallback(flashlightCallback)

        awaitClose {
            flashlightController.removeCallback(flashlightCallback)
        }
    }

    override fun onTriggered(expandable: Expandable?):
            KeyguardQuickAffordanceConfig.OnTriggeredResult {
        flashlightController
                .setFlashlight(flashlightController.isAvailable && !flashlightController.isEnabled)
        return KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled
    }

    override suspend fun getPickerScreenState(): KeyguardQuickAffordanceConfig.PickerScreenState =
        if (flashlightController.isAvailable) {
            KeyguardQuickAffordanceConfig.PickerScreenState.Default
        } else {
            KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice
        }

    companion object {
        private const val TAG = "FlashlightQuickAffordanceConfig"
    }
}
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ object KeyguardDataQuickAffordanceModule {
    @Provides
    @ElementsIntoSet
    fun quickAffordanceConfigs(
        flashlight: FlashlightQuickAffordanceConfig,
        home: HomeControlsKeyguardQuickAffordanceConfig,
        quickAccessWallet: QuickAccessWalletKeyguardQuickAffordanceConfig,
        qrCodeScanner: QrCodeScannerKeyguardQuickAffordanceConfig,
@@ -33,6 +34,7 @@ object KeyguardDataQuickAffordanceModule {
    ): Set<KeyguardQuickAffordanceConfig> {
        return setOf(
            camera,
            flashlight,
            home,
            quickAccessWallet,
            qrCodeScanner,
Loading