1 /* 2 * Copyright (C) 2016 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 android.platform.test.helpers.tests; 18 19 import android.app.ActivityManager; 20 import android.content.Context; 21 import android.platform.test.helpers.IStandardAppHelper; 22 import android.support.test.InstrumentationRegistry; 23 import android.support.test.uiautomator.UiDevice; 24 25 import org.junit.After; 26 import org.junit.Before; 27 28 import android.os.RemoteException; 29 30 public abstract class BaseHelperTest { 31 protected ActivityManager mActivityManager; 32 protected UiDevice mDevice; 33 34 @Before setOrientation()35 public void setOrientation() throws RemoteException { 36 getDevice().setOrientationNatural(); 37 } 38 39 @Before clearAppData()40 public void clearAppData() { 41 getActivityManager().clearApplicationUserData(getHelper().getPackage(), null); 42 } 43 44 @After unsetOrientation()45 public void unsetOrientation() throws RemoteException { 46 getDevice().unfreezeRotation(); 47 } 48 getActivityManager()49 protected ActivityManager getActivityManager() { 50 if (mActivityManager == null) { 51 Context context = InstrumentationRegistry.getContext(); 52 mActivityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); 53 } 54 55 return mActivityManager; 56 } 57 getDevice()58 protected UiDevice getDevice() { 59 if (mDevice == null) { 60 mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); 61 } 62 63 return mDevice; 64 } 65 getHelper()66 protected abstract IStandardAppHelper getHelper(); 67 } 68