本文整理汇总了Java中android.app.UiAutomation类的典型用法代码示例。如果您正苦于以下问题:Java UiAutomation类的具体用法?Java UiAutomation怎么用?Java UiAutomation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UiAutomation类属于android.app包,在下文中一共展示了UiAutomation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: injectTap
import android.app.UiAutomation; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static void injectTap(int x, int y, UiAutomation uiAutomation, boolean sync) {
long downTime = System.currentTimeMillis();
MotionEvent eventDown = MotionEvent.obtain(downTime,
downTime, MotionEvent.ACTION_DOWN,
x, y, 0);
eventDown.setSource(InputDevice.SOURCE_TOUCHSCREEN);
Log.d(TAG, "Injecting " + eventDown);
if (!uiAutomation.injectInputEvent(eventDown, sync)) {
Log.d(TAG, "Injection failed");
}
MotionEvent eventUp = MotionEvent.obtain(eventDown);
eventUp.setAction(MotionEvent.ACTION_UP);
Log.d(TAG, "Injecting " + eventUp);
if (!uiAutomation.injectInputEvent(eventUp, sync)) {
Log.d(TAG, "Injection failed");
}
eventDown.recycle();
eventUp.recycle();
}
示例2: connect
import android.app.UiAutomation; //导入依赖的package包/类
public void connect() {
if (mHandlerThread.isAlive()) {
throw new IllegalStateException("Already connected!");
}
mHandlerThread.start();
mUiAutomation = new UiAutomation(mHandlerThread.getLooper(), new UiAutomationConnection());
try {
mUiAutomation.disconnect();
} catch (RuntimeException e) {
// do nothing
}
mUiAutomation.connect();
}
示例3: run
import android.app.UiAutomation; //导入依赖的package包/类
public void run() {
while (true) {
AccessibilityEvent accessibilityEvent = null;
toastMessages = init();
//return true if the AccessibilityEvent type is NOTIFICATION type
UiAutomation.AccessibilityEventFilter eventFilter = new UiAutomation.AccessibilityEventFilter() {
@Override
public boolean accept(AccessibilityEvent event) {
return event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
}
};
Runnable runnable = new Runnable() {
@Override
public void run() {
// Not performing any event.
}
};
try {
//wait for AccessibilityEvent filter
accessibilityEvent = UiAutomatorBridge.getInstance().getUiAutomation()
.executeAndWaitForEvent(runnable /*executable event*/, eventFilter /* event to filter*/, 500 /*time out in ms*/);
} catch (Exception ignore) {}
if (accessibilityEvent != null) {
toastMessages = accessibilityEvent.getText();
previousTime = currentTimeMillis();
}
if(stopLooping){
break;
}
}
}
示例4: grantAllPermissions
import android.app.UiAutomation; //导入依赖的package包/类
private void grantAllPermissions() {
Context context = InstrumentationRegistry.getTargetContext();
try {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
UiAutomation uiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation();
for (int i = 0; i < packageInfo.requestedPermissions.length; ++i) {
if ((packageInfo.requestedPermissionsFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) == 0) {
grantReal(uiAutomation, packageInfo.requestedPermissions[i]);
}
}
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "packageInfo not found for: " + context.getPackageName());
}
}
示例5: grantReal
import android.app.UiAutomation; //导入依赖的package包/类
private static void grantReal(UiAutomation automation, String permission) {
try {
String targetPackageName = InstrumentationRegistry.getTargetContext().getPackageName();
ParcelFileDescriptor pfn = automation.executeShellCommand("pm grant " + targetPackageName + " " + permission);
pfn.close();
} catch (IOException e) {
Log.w(TAG, e);
}
}
示例6: getUiAutomation
import android.app.UiAutomation; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
public UiAutomation getUiAutomation() {
return mBase.getUiAutomation();
}
示例7: getUiAutomation
import android.app.UiAutomation; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
public UiAutomation getUiAutomation() {
return base.getUiAutomation();
}
示例8: getUiAutomation
import android.app.UiAutomation; //导入依赖的package包/类
public UiAutomation getUiAutomation() {
return mUiAutomation;
}
示例9: getUiAutomation
import android.app.UiAutomation; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public UiAutomation getUiAutomation() {
return mInstrumentation.getUiAutomation();
}
示例10: getUiAutomation
import android.app.UiAutomation; //导入依赖的package包/类
@Override
@TargetApi(18)
public UiAutomation getUiAutomation() {
return this.mBase.getUiAutomation();
}
示例11: start
import android.app.UiAutomation; //导入依赖的package包/类
/**
* Called after all test classes are in place, ready to test
*/
protected void start() {
TestCaseCollector collector = getTestCaseCollector(this.getClass().getClassLoader());
try {
collector.addTestClasses(mTestClasses);
} catch (ClassNotFoundException e) {
// will be caught by uncaught handler
throw new RuntimeException(e.getMessage(), e);
}
if (mDebug) {
Debug.waitForDebugger();
}
mHandlerThread = new HandlerThread(HANDLER_THREAD_NAME);
mHandlerThread.setDaemon(true);
mHandlerThread.start();
UiAutomationShellWrapper automationWrapper = new UiAutomationShellWrapper();
automationWrapper.connect();
long startTime = SystemClock.uptimeMillis();
TestResult testRunResult = new TestResult();
ResultReporter resultPrinter;
String outputFormat = mParams.getString("outputFormat");
List<TestCase> testCases = collector.getTestCases();
Bundle testRunOutput = new Bundle();
if ("simple".equals(outputFormat)) {
resultPrinter = new SimpleResultPrinter(System.out, true);
} else {
resultPrinter = new WatcherResultPrinter(testCases.size());
}
try {
automationWrapper.setRunAsMonkey(mMonkey);
mUiDevice = MyUiDevice.getInstance();
UiAutomation uiAutomation = automationWrapper.getUiAutomation();
mUiDevice.initialize(new ShellUiAutomatorBridge(uiAutomation));
mUiDevice.setUiAutomation(uiAutomation);
String traceType = mParams.getString("traceOutputMode");
if (traceType != null) {
Tracer.Mode mode = Tracer.Mode.valueOf(Tracer.Mode.class, traceType);
if (mode == Tracer.Mode.FILE || mode == Tracer.Mode.ALL) {
String filename = mParams.getString("traceLogFilename");
if (filename == null) {
throw new RuntimeException("Name of log file not specified. " + "Please specify it using traceLogFilename parameter");
}
Tracer.getInstance().setOutputFilename(filename);
}
Tracer.getInstance().setOutputMode(mode);
}
// add test listeners
testRunResult.addListener(resultPrinter);
// add all custom listeners
for (TestListener listener : mTestListeners) {
testRunResult.addListener(listener);
}
// run tests for realz!
for (TestCase testCase : testCases) {
prepareTestCase(testCase);
testCase.run(testRunResult);
}
} catch (Throwable t) {
// catch all exceptions so a more verbose error message can be outputted
resultPrinter.printUnexpectedError(t);
} finally {
long runTime = SystemClock.uptimeMillis() - startTime;
resultPrinter.print(testRunResult, runTime, testRunOutput);
automationWrapper.disconnect();
automationWrapper.setRunAsMonkey(false);
mHandlerThread.quit();
}
}
示例12: getUiAutomation
import android.app.UiAutomation; //导入依赖的package包/类
public UiAutomation getUiAutomation() {
return this.mAutomation;
}
示例13: setUiAutomation
import android.app.UiAutomation; //导入依赖的package包/类
public void setUiAutomation(UiAutomation uiauto) {
this.mAutomation = uiauto;
}
示例14: getUiAutomation
import android.app.UiAutomation; //导入依赖的package包/类
public UiAutomation getUiAutomation() {
return (UiAutomation)getField(CLASS_UI_AUTOMATOR_BRIDGE, FIELD_UI_AUTOMATOR, uiAutomatorBridge);
}
示例15: KeyboardTypeAction
import android.app.UiAutomation; //导入依赖的package包/类
public KeyboardTypeAction(UiAutomation uiAutomation) {
this.uiAutomation = uiAutomation;
}