1/* 2 * Copyright (C) 2013 DroidDriver committers 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 com.google.android.droiddriver.uiautomation; 18 19import android.app.UiAutomation; 20import android.graphics.Bitmap; 21import android.util.Log; 22 23import com.google.android.droiddriver.base.BaseUiDevice; 24import com.google.android.droiddriver.exceptions.UnrecoverableException; 25import com.google.android.droiddriver.uiautomation.UiAutomationContext.UiAutomationCallable; 26import com.google.android.droiddriver.util.Logs; 27 28class UiAutomationUiDevice extends BaseUiDevice { 29 private final UiAutomationContext context; 30 31 UiAutomationUiDevice(UiAutomationContext context) { 32 this.context = context; 33 } 34 35 @Override 36 protected Bitmap takeScreenshot() { 37 try { 38 return context.callUiAutomation(new UiAutomationCallable<Bitmap>() { 39 @Override 40 public Bitmap call(UiAutomation uiAutomation) { 41 return uiAutomation.takeScreenshot(); 42 } 43 }); 44 } catch (UnrecoverableException e) { 45 throw e; 46 } catch (Throwable e) { 47 Logs.log(Log.ERROR, e); 48 return null; 49 } 50 } 51 52 @Override 53 protected UiAutomationContext getContext() { 54 return context; 55 } 56} 57