1/* 2 * Copyright (C) 2010 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.urlrenderer; 18 19import android.annotation.SdkConstant; 20import android.annotation.SdkConstant.SdkConstantType; 21import android.app.Service; 22import android.os.ParcelFileDescriptor; 23import android.os.RemoteException; 24 25import java.util.List; 26 27/** 28 * TODO(phanna): Complete documentation. 29 * {@hide} while developing 30 */ 31public abstract class UrlRendererService extends Service { 32 /** 33 * The {@link Intent} that must be declared as handled by the service. 34 */ 35 @SdkConstant(SdkConstantType.SERVICE_ACTION) 36 public static final String SERVICE_INTERFACE = 37 "android.service.urlrenderer.UrlRendererService"; 38 39 static final String TAG = "UrlRendererService"; 40 41 private static class InternalCallback implements UrlRenderer.Callback { 42 private final IUrlRendererCallback mCallback; 43 InternalCallback(IUrlRendererCallback cb) { 44 mCallback = cb; 45 } 46 47 public void complete(String url, ParcelFileDescriptor result) { 48 try { 49 mCallback.complete(url, result); 50 } catch (RemoteException ex) { 51 } 52 } 53 } 54 55 private final IUrlRendererService.Stub mBinderInterface = 56 new IUrlRendererService.Stub() { 57 public void render(List<String> urls, int width, int height, 58 IUrlRendererCallback cb) { 59 processRequest(urls, width, height, 60 new InternalCallback(cb)); 61 } 62 }; 63 64 /** 65 * Implement to return the implementation of the internal accessibility 66 * service interface. Subclasses should not override. 67 */ 68 @Override 69 public final android.os.IBinder onBind(android.content.Intent intent) { 70 return mBinderInterface; 71 } 72 73 /** 74 * When all clients unbind from the service, stop the service. Subclasses 75 * should not override. 76 */ 77 @Override 78 public final boolean onUnbind(android.content.Intent intent) { 79 stopSelf(); 80 return false; 81 } 82 83 /** 84 * Subclasses implement this function to process the given urls. When each 85 * url is complete, the subclass must invoke the callback with the result. 86 * @param urls A list of urls to render at the given dimensions. 87 * @param width The desired width of the result. 88 * @param height The desired height of the result. 89 * @param cb The callback to invoke when each url is complete. 90 */ 91 public abstract void processRequest(List<String> urls, int width, 92 int height, UrlRenderer.Callback cb); 93} 94