| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.service.wallpapereffectsgeneration; |
| 18 |
|
| 19 |
import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage; |
| 20 |
|
| 21 |
import android.annotation.CallSuper; |
| 22 |
import android.annotation.MainThread; |
| 23 |
import android.annotation.NonNull; |
| 24 |
import android.annotation.SystemApi; |
| 25 |
import android.app.Service; |
| 26 |
import android.app.wallpapereffectsgeneration.CinematicEffectRequest; |
| 27 |
import android.app.wallpapereffectsgeneration.CinematicEffectResponse; |
| 28 |
import android.app.wallpapereffectsgeneration.IWallpaperEffectsGenerationManager; |
| 29 |
import android.content.Context; |
| 30 |
import android.content.Intent; |
| 31 |
import android.os.Handler; |
| 32 |
import android.os.IBinder; |
| 33 |
import android.os.Looper; |
| 34 |
import android.os.RemoteException; |
| 35 |
import android.os.ServiceManager; |
| 36 |
import android.util.Log; |
| 37 |
import android.util.Slog; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
@SystemApi |
| 65 |
public abstract class WallpaperEffectsGenerationService extends Service { |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public static final String SERVICE_INTERFACE = |
| 75 |
"android.service.wallpapereffectsgeneration.WallpaperEffectsGenerationService"; |
| 76 |
private static final boolean DEBUG = false; |
| 77 |
private static final String TAG = "WallpaperEffectsGenerationService"; |
| 78 |
private Handler mHandler; |
| 79 |
private IWallpaperEffectsGenerationManager mService; |
| 80 |
|
| 81 |
private final IWallpaperEffectsGenerationService mInterface = |
| 82 |
new IWallpaperEffectsGenerationService.Stub() { |
| 83 |
@Override |
| 84 |
public void onGenerateCinematicEffect(CinematicEffectRequest request) { |
| 85 |
mHandler.sendMessage( |
| 86 |
obtainMessage( |
| 87 |
WallpaperEffectsGenerationService::onGenerateCinematicEffect, |
| 88 |
WallpaperEffectsGenerationService.this, request)); |
| 89 |
} |
| 90 |
}; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
@MainThread |
| 101 |
public abstract void onGenerateCinematicEffect(@NonNull CinematicEffectRequest request); |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
public final void returnCinematicEffectResponse(@NonNull CinematicEffectResponse response) { |
| 111 |
try { |
| 112 |
mService.returnCinematicEffectResponse(response); |
| 113 |
} catch (RemoteException e) { |
| 114 |
throw e.rethrowFromSystemServer(); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
@CallSuper |
| 119 |
@Override |
| 120 |
public void onCreate() { |
| 121 |
super.onCreate(); |
| 122 |
if (DEBUG) { |
| 123 |
Log.d(TAG, "onCreate WallpaperEffectsGenerationService"); |
| 124 |
} |
| 125 |
mHandler = new Handler(Looper.getMainLooper(), null, true); |
| 126 |
IBinder b = ServiceManager.getService(Context.WALLPAPER_EFFECTS_GENERATION_SERVICE); |
| 127 |
mService = IWallpaperEffectsGenerationManager.Stub.asInterface(b); |
| 128 |
} |
| 129 |
|
| 130 |
@NonNull |
| 131 |
@Override |
| 132 |
public final IBinder onBind(@NonNull Intent intent) { |
| 133 |
if (DEBUG) { |
| 134 |
Log.d(TAG, "onBind WallpaperEffectsGenerationService"); |
| 135 |
} |
| 136 |
if (SERVICE_INTERFACE.equals(intent.getAction())) { |
| 137 |
return mInterface.asBinder(); |
| 138 |
} |
| 139 |
Slog.w(TAG, |
| 140 |
"Tried to bind to wrong intent (should be " + SERVICE_INTERFACE + ": " + intent); |
| 141 |
return null; |
| 142 |
} |
| 143 |
} |