Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright (C) 2013 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 
     17 package com.android.uiautomator.core;
     18 
     19 import android.app.Service;
     20 import android.app.UiAutomation;
     21 import android.content.Context;
     22 import android.os.PowerManager;
     23 import android.view.Display;
     24 import android.view.ViewConfiguration;
     25 import android.view.WindowManager;
     26 
     27 /**
     28  * @hide
     29  */
     30 public class InstrumentationUiAutomatorBridge extends UiAutomatorBridge {
     31 
     32     private final Context mContext;
     33 
     34     public InstrumentationUiAutomatorBridge(Context context, UiAutomation uiAutomation) {
     35         super(uiAutomation);
     36         mContext = context;
     37     }
     38 
     39     public Display getDefaultDisplay() {
     40         WindowManager windowManager = (WindowManager)
     41                 mContext.getSystemService(Service.WINDOW_SERVICE);
     42         return windowManager.getDefaultDisplay();
     43     }
     44 
     45     @Override
     46     public int getRotation() {
     47         return getDefaultDisplay().getRotation();
     48     }
     49 
     50     @Override
     51     public boolean isScreenOn() {
     52         PowerManager pm = (PowerManager)
     53                 mContext.getSystemService(Service.POWER_SERVICE);
     54         return pm.isScreenOn();
     55     }
     56 
     57     public long getSystemLongPressTime() {
     58         return ViewConfiguration.getLongPressTimeout();
     59     }
     60 }
     61