1 /* 2 * Copyright (C) 2024 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.wallpaper.effects 18 19 import android.app.WallpaperManager 20 import android.content.ComponentName 21 import android.content.Context 22 import android.net.Uri 23 import android.os.Bundle 24 import javax.inject.Inject 25 import javax.inject.Singleton 26 27 @Singleton 28 class FakeEffectsController @Inject constructor() : EffectsController() { 29 30 var fakeAreEffectsAvailable: Boolean = true 31 var fakeIsEffectTriggered: Boolean = true 32 var fakeEffectTitle: String = "" 33 var fakeEffectFailedTitle: String = "" 34 var fakeEffectSubTitle: String = "" 35 var fakeRetryInstruction: String = "" 36 var fakeNoEffectInstruction: String = "" 37 38 enum class Effect : EffectEnumInterface { 39 NONE, 40 FAKE_EFFECT, 41 } 42 43 private var effectsServiceListener: EffectsServiceListener? = null 44 generateEffectnull45 override fun generateEffect(effect: EffectEnumInterface?, image: Uri?) { 46 effectsServiceListener?.onEffectFinished( 47 Effect.FAKE_EFFECT, 48 Bundle().apply { 49 putParcelable( 50 WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, 51 ComponentName( 52 LIVE_WALLPAPER_COMPONENT_PKG_NAME, 53 LIVE_WALLPAPER_COMPONENT_CLASS_NAME, 54 ) 55 ) 56 putInt(EffectContract.ASSET_ID, 1) 57 }, 58 RESULT_SUCCESS, 59 RESULT_ORIGINAL_UNKNOWN, 60 null, /* errorMessage */ 61 ) 62 } 63 areEffectsAvailablenull64 override fun areEffectsAvailable(): Boolean = fakeAreEffectsAvailable 65 66 override fun triggerEffect(context: Context?) { 67 effectsServiceListener?.onEffectFinished( 68 Effect.FAKE_EFFECT, 69 Bundle(), 70 RESULT_PROBE_SUCCESS, 71 RESULT_ORIGINAL_UNKNOWN, 72 null, /* errorMessage */ 73 ) 74 } 75 setListenernull76 override fun setListener(listener: EffectsServiceListener?) { 77 effectsServiceListener = listener 78 } 79 getTargetEffectnull80 override fun getTargetEffect(): EffectEnumInterface = Effect.FAKE_EFFECT 81 82 override fun isEffectTriggered(): Boolean = fakeIsEffectTriggered 83 84 override fun getEffectTitle(): String = fakeEffectTitle 85 86 override fun getEffectFailedTitle(): String = fakeEffectFailedTitle 87 88 override fun getEffectSubTitle(): String = fakeEffectSubTitle 89 90 override fun getRetryInstruction(): String = fakeRetryInstruction 91 92 override fun getNoEffectInstruction(): String = fakeNoEffectInstruction 93 94 override fun getContentUri(): Uri = CONTENT_URI 95 96 override fun startForegroundDownload(effect: com.android.wallpaper.effects.Effect?) { 97 effectsServiceListener?.onEffectFinished( 98 Effect.FAKE_EFFECT, 99 Bundle(), 100 RESULT_FOREGROUND_DOWNLOAD_SUCCEEDED, 101 RESULT_ORIGINAL_UNKNOWN, 102 null, /* errorMessage */ 103 ) 104 } 105 106 companion object { 107 const val LIVE_WALLPAPER_COMPONENT_PKG_NAME = "com.test.effects" 108 const val LIVE_WALLPAPER_COMPONENT_CLASS_NAME = "test.Effects" 109 const val AUTHORITY = "com.test.effects" 110 private const val EFFECT_PATH = "/effects" 111 val CONTENT_URI: Uri = Uri.parse("content://$AUTHORITY$EFFECT_PATH") 112 } 113 } 114