WallpaperService.java revision 8cc6a5026aeb5cf9cc36529426fe0cc66714f5fb
1/* 2 * Copyright (C) 2009 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 17package android.service.wallpaper; 18 19import com.android.internal.os.HandlerCaller; 20 21import android.app.Service; 22import android.content.Intent; 23import android.os.IBinder; 24import android.os.Message; 25import android.os.RemoteException; 26import android.util.Log; 27 28/** 29 * A wallpaper service is responsible for showing a live wallpaper behind 30 * applications that would like to sit on top of it. 31 */ 32public abstract class WallpaperService extends Service { 33 /** 34 * The {@link Intent} that must be declared as handled by the service. 35 */ 36 public static final String SERVICE_INTERFACE = 37 "android.service.wallpaper.WallpaperService"; 38 39 private static final String LOG_TAG = "WallpaperService"; 40 41 /** 42 * Implement to return the implementation of the internal accessibility 43 * service interface. Subclasses should not override. 44 */ 45 @Override 46 public final IBinder onBind(Intent intent) { 47 return new IWallpaperServiceWrapper(this); 48 } 49 50 /** 51 * Implements the internal {@link IWallpaperService} interface to convert 52 * incoming calls to it back to calls on an {@link WallpaperService}. 53 */ 54 class IWallpaperServiceWrapper extends IWallpaperService.Stub 55 implements HandlerCaller.Callback { 56 57 private static final int DO_ON_INTERRUPT = 10; 58 59 private final HandlerCaller mCaller; 60 61 private WallpaperService mTarget; 62 63 public IWallpaperServiceWrapper(WallpaperService context) { 64 mTarget = context; 65 mCaller = new HandlerCaller(context, this); 66 } 67 68 public void onInterrupt() { 69 Message message = mCaller.obtainMessage(DO_ON_INTERRUPT); 70 mCaller.sendMessage(message); 71 } 72 73 public void executeMessage(Message message) { 74 switch (message.what) { 75 case DO_ON_INTERRUPT : 76 //mTarget.onInterrupt(); 77 return; 78 default : 79 Log.w(LOG_TAG, "Unknown message type " + message.what); 80 } 81 } 82 } 83} 84