1 /*
2  * Copyright (C) 2022 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 package com.android.wallpaper.effects;
17 
18 import android.app.WallpaperInfo;
19 import android.content.Context;
20 import android.net.Uri;
21 import android.os.Bundle;
22 
23 import androidx.annotation.NonNull;
24 
25 /**
26  * Utility class to provide methods to generate effects for the wallpaper.
27  */
28 public abstract class EffectsController {
29     public static final int ERROR_ORIGINAL_DESTROY_CONTROLLER = -16;
30     public static final int ERROR_ORIGINAL_FINISH_ONGOING_SERVICE = -8;
31     public static final int ERROR_ORIGINAL_SERVICE_DISCONNECT = -4;
32     public static final int ERROR_ORIGINAL_TIME_OUT = -2;
33 
34     public static final int RESULT_ORIGINAL_UNKNOWN = -1;
35     public static final int RESULT_SUCCESS = 0;
36     public static final int RESULT_ERROR_TRY_ANOTHER_PHOTO = 1;
37     public static final int RESULT_ERROR_TRY_AGAIN_LATER = 2;
38     public static final int RESULT_ERROR_CONTINUE = 4;
39     public static final int RESULT_ERROR_DEFAULT =
40             RESULT_ERROR_TRY_ANOTHER_PHOTO + RESULT_ERROR_CONTINUE;
41     public static final int RESULT_ERROR_DISCONNECT_NO_BUTTON = 8;
42     public static final int RESULT_PROBE_SUCCESS = 16;
43     public static final int RESULT_PROBE_ERROR = 32;
44     public static final int RESULT_SUCCESS_REUSED = 64;
45     public static final int RESULT_SUCCESS_WITH_GENERATION_ERROR = 128;
46     public static final int RESULT_ERROR_PROBE_SUPPORT_FOREGROUND = 256;
47     public static final int RESULT_FOREGROUND_DOWNLOAD_SUCCEEDED = 512;
48     public static final int RESULT_FOREGROUND_DOWNLOAD_FAILED = 1024;
49     public static final int RESULT_PROBE_FOREGROUND_DOWNLOADING = 2048;
50 
51     /**
52      * Interface of the Effect enum.
53      */
54     public interface EffectEnumInterface {
55     }
56 
57     public enum Effect implements EffectEnumInterface {
58         NONE,
59         UNKNOWN,
60     }
61 
62     protected boolean mBound = false;
63 
64     /**
65      * Call to generate an effect.
66      *
67      * @param effect the effect type we want to generate.
68      * @param image  the image that will have the effect applied.
69      */
generateEffect(EffectEnumInterface effect, Uri image)70     public void generateEffect(EffectEnumInterface effect, Uri image) {
71     }
72 
73     /**
74      * Binds the Effects Service.
75      */
bindEffectsService()76     public void bindEffectsService() {
77     }
78 
79     /**
80      * Returns true if an effects component is available on the current device
81      */
areEffectsAvailable()82     public boolean areEffectsAvailable() {
83         return false;
84     }
85 
86     /**
87      * Returns true if the given {@link WallpaperInfo} corresponds to a wallpaper matching the
88      * "Effects" wallpaper.
89      */
isEffectsWallpaper(@onNull WallpaperInfo info)90     public boolean isEffectsWallpaper(@NonNull WallpaperInfo info) {
91         return false;
92     }
93 
94     /**
95      * Destroys the controller
96      */
destroy()97     public void destroy() {
98     }
99 
100     /**
101      * If the Effects Service is bound.
102      *
103      * @return if the Effects Service is bound.
104      */
isBound()105     public boolean isBound() {
106         return mBound;
107     }
108 
109     /**
110      * Triggers the effect.
111      *
112      * @param context the context
113      */
triggerEffect(Context context)114     public void triggerEffect(Context context) {
115     }
116 
117     /** Sets the {@link EffectsServiceListener} to receive updates. */
setListener(EffectsServiceListener listener)118     public void setListener(EffectsServiceListener listener) {
119     }
120 
121     /** Removes the listener set via {@link #setListener(EffectsServiceListener)}. */
removeListener()122     public void removeListener() {
123     }
124 
125     /** Returns true if the effect is expected by this controller. */
isTargetEffect(EffectEnumInterface effect)126     public boolean isTargetEffect(EffectEnumInterface effect) {
127         return effect == getTargetEffect();
128     }
129 
130     /**
131      * Interface to listen to different key moments of the connection with the Effects Service.
132      */
133     public interface EffectsServiceListener {
134         /**
135          * Called when an effect has finished being processed.
136          *
137          * @param effect The effect that was generated.
138          * @param bundle The data that the Service might have sent to the picker.
139          * @param error The error code. if there's an error, value is greater than
140          *              zero.
141          * @param originalStatusCode The original status code used for metrics logging.
142          * @param errorMessage The error message.
143          */
onEffectFinished(EffectEnumInterface effect, Bundle bundle, int error, int originalStatusCode, String errorMessage)144         void onEffectFinished(EffectEnumInterface effect, Bundle bundle, int error,
145                 int originalStatusCode, String errorMessage);
146     }
147 
getTargetEffect()148     public EffectEnumInterface getTargetEffect() {
149         return Effect.NONE;
150     }
151 
152     /**
153      * Gets whether the effect triggering is successful or not.
154      *
155      * @return whether the effect triggering is successful or not.
156      */
isEffectTriggered()157     public boolean isEffectTriggered() {
158         return false;
159     }
160 
getEffectTitle()161     public String getEffectTitle() {
162         return "";
163     }
164 
getEffectFailedTitle()165     public String getEffectFailedTitle() {
166         return "";
167     }
168 
getEffectSubTitle()169     public String getEffectSubTitle() {
170         return "";
171     }
172 
getRetryInstruction()173     public String getRetryInstruction() {
174         return "";
175     }
176 
getNoEffectInstruction()177     public String getNoEffectInstruction() {
178         return "";
179     }
180 
getContentUri()181     public Uri getContentUri() {
182         return Uri.EMPTY;
183     }
184 
185     /** */
interruptGenerate(com.android.wallpaper.effects.Effect effect)186     public void interruptGenerate(com.android.wallpaper.effects.Effect effect) {}
187 
188     /**
189      * This initiates the downloading of the ML models for a given effect
190      *
191      * @param effect The Effect for which we want to download the ML model
192      */
startForegroundDownload(com.android.wallpaper.effects.Effect effect)193     public void startForegroundDownload(com.android.wallpaper.effects.Effect effect){}
194 
195     /**
196      * Sends the interrupt foreground downloading to effect.
197      *
198      * @param effect The effect that is being downloaded.
199      */
interruptForegroundDownload(com.android.wallpaper.effects.Effect effect)200     public void interruptForegroundDownload(com.android.wallpaper.effects.Effect effect) {}
201 }
202