WallpaperService.java revision 8cc6a5026aeb5cf9cc36529426fe0cc66714f5fb
18cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn/* 28cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * Copyright (C) 2009 The Android Open Source Project 38cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * 48cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License"); 58cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * you may not use this file except in compliance with the License. 68cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * You may obtain a copy of the License at 78cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * 88cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * http://www.apache.org/licenses/LICENSE-2.0 98cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * 108cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * Unless required by applicable law or agreed to in writing, software 118cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS, 128cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * See the License for the specific language governing permissions and 148cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * limitations under the License. 158cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn */ 168cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn 178cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackbornpackage android.service.wallpaper; 188cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn 198cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackbornimport com.android.internal.os.HandlerCaller; 208cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn 218cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackbornimport android.app.Service; 228cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackbornimport android.content.Intent; 238cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackbornimport android.os.IBinder; 248cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackbornimport android.os.Message; 258cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackbornimport android.os.RemoteException; 268cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackbornimport android.util.Log; 278cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn 288cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn/** 298cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * A wallpaper service is responsible for showing a live wallpaper behind 308cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * applications that would like to sit on top of it. 318cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn */ 328cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackbornpublic abstract class WallpaperService extends Service { 338cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn /** 348cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * The {@link Intent} that must be declared as handled by the service. 358cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn */ 368cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn public static final String SERVICE_INTERFACE = 378cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn "android.service.wallpaper.WallpaperService"; 388cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn 398cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn private static final String LOG_TAG = "WallpaperService"; 408cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn 418cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn /** 428cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * Implement to return the implementation of the internal accessibility 438cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * service interface. Subclasses should not override. 448cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn */ 458cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn @Override 468cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn public final IBinder onBind(Intent intent) { 478cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn return new IWallpaperServiceWrapper(this); 488cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn } 498cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn 508cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn /** 518cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * Implements the internal {@link IWallpaperService} interface to convert 528cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn * incoming calls to it back to calls on an {@link WallpaperService}. 538cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn */ 548cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn class IWallpaperServiceWrapper extends IWallpaperService.Stub 558cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn implements HandlerCaller.Callback { 568cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn 578cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn private static final int DO_ON_INTERRUPT = 10; 588cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn 598cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn private final HandlerCaller mCaller; 608cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn 618cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn private WallpaperService mTarget; 628cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn 638cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn public IWallpaperServiceWrapper(WallpaperService context) { 648cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn mTarget = context; 658cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn mCaller = new HandlerCaller(context, this); 668cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn } 678cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn 688cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn public void onInterrupt() { 698cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn Message message = mCaller.obtainMessage(DO_ON_INTERRUPT); 708cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn mCaller.sendMessage(message); 718cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn } 728cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn 738cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn public void executeMessage(Message message) { 748cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn switch (message.what) { 758cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn case DO_ON_INTERRUPT : 768cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn //mTarget.onInterrupt(); 778cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn return; 788cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn default : 798cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn Log.w(LOG_TAG, "Unknown message type " + message.what); 808cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn } 818cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn } 828cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn } 838cc6a5026aeb5cf9cc36529426fe0cc66714f5fbDianne Hackborn} 84