当前位置: 首页>>代码示例>>Java>>正文


Java UiAutomation类代码示例

本文整理汇总了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();
}
 
开发者ID:evernote,项目名称:kgb,代码行数:25,代码来源:KeyboardSwitcher.java

示例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();
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:14,代码来源:HideApiOverrideU.java

示例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;
        }
    }
}
 
开发者ID:appium,项目名称:appium-uiautomator2-server,代码行数:35,代码来源:NotificationListener.java

示例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());
  }
}
 
开发者ID:jksiezni,项目名称:permissive,代码行数:15,代码来源:PermissiveTestRule.java

示例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);
  }
}
 
开发者ID:jksiezni,项目名称:permissive,代码行数:10,代码来源:PermissiveTestRule.java

示例6: getUiAutomation

import android.app.UiAutomation; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
public UiAutomation getUiAutomation() {
    return mBase.getUiAutomation();
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:6,代码来源:InstrumentationHook.java

示例7: getUiAutomation

import android.app.UiAutomation; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
public UiAutomation getUiAutomation() {
	return base.getUiAutomation();
}
 
开发者ID:7763sea,项目名称:VirtualHook,代码行数:6,代码来源:InstrumentationDelegate.java

示例8: getUiAutomation

import android.app.UiAutomation; //导入依赖的package包/类
public UiAutomation getUiAutomation() {
    return mUiAutomation;
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:4,代码来源:HideApiOverrideU.java

示例9: getUiAutomation

import android.app.UiAutomation; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public UiAutomation getUiAutomation() {
    return mInstrumentation.getUiAutomation();
}
 
开发者ID:LiangMaYong,项目名称:android-apkbox,代码行数:5,代码来源:HookActivityInstrumentationHnadler.java

示例10: getUiAutomation

import android.app.UiAutomation; //导入依赖的package包/类
@Override
@TargetApi(18)
public UiAutomation getUiAutomation() {
    return this.mBase.getUiAutomation();
}
 
开发者ID:bunnyblue,项目名称:ACDD,代码行数:6,代码来源:InstrumentationHook.java

示例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();
	}
}
 
开发者ID:MagicHry,项目名称:EnhancedPUMA,代码行数:75,代码来源:MyUiAutomatorTestRunner.java

示例12: getUiAutomation

import android.app.UiAutomation; //导入依赖的package包/类
public UiAutomation getUiAutomation() {
	return this.mAutomation;
}
 
开发者ID:MagicHry,项目名称:EnhancedPUMA,代码行数:4,代码来源:MyUiDevice.java

示例13: setUiAutomation

import android.app.UiAutomation; //导入依赖的package包/类
public void setUiAutomation(UiAutomation uiauto) {
	this.mAutomation = uiauto;
}
 
开发者ID:MagicHry,项目名称:EnhancedPUMA,代码行数:4,代码来源:MyUiDevice.java

示例14: getUiAutomation

import android.app.UiAutomation; //导入依赖的package包/类
public UiAutomation getUiAutomation() {
    return (UiAutomation)getField(CLASS_UI_AUTOMATOR_BRIDGE, FIELD_UI_AUTOMATOR, uiAutomatorBridge);
}
 
开发者ID:appium,项目名称:appium-uiautomator2-server,代码行数:4,代码来源:UiAutomatorBridge.java

示例15: KeyboardTypeAction

import android.app.UiAutomation; //导入依赖的package包/类
public KeyboardTypeAction(UiAutomation uiAutomation) {
  this.uiAutomation = uiAutomation;
}
 
开发者ID:evernote,项目名称:kgb,代码行数:4,代码来源:KeyboardTypeAction.java


注:本文中的android.app.UiAutomation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。