Code Monkey home page Code Monkey logo

device's Introduction

“[device] is being sponsored by the following tool; please help to support us by taking a look and signing up to a free trial”

Android Device API Based on ddmlib

A lot of code quote from selendroid,but we will foucs on simplify ddmlib's usage

device-keeper

A distributed android device monitor system based on device-api

Quick Start

You require the following to build:

And be sure that JAVA_HOME,ANDROID_HOME at your environment path.

Plug a android device via usb or boot an emulator

git clone https://github.com/cosysoft/device.git
cd device/device-keeper
bower install

cd ..
gradle bootRun

Open http://localhost:8080/keeper in your browser

device-api

Focus on stabilized android device operation via Android Debug Bridge

Quick Start

Download

Maven

<dependency>
		<groupId>com.github.cosysoft</groupId>
		<artifactId>device-api</artifactId>
		<version>0.9.3</version>
</dependency>

Gradle

dependencies {
		compile 'com.github.cosysoft:device-api:0.9.3'
}

Take Devices

TreeSet<AndroidDevice> devices = AndroidDeviceStore.getInstance()
		.getDevices();

for (AndroidDevice d : devices) {
  System.out.println(d.getSerialNumber());
}
AndroidDevice device = devices.pollFirst();
System.out.println(device.getName());

Screenshot

BufferedImage image = device.takeScreenshot();
String imagePath = new File(System.getProperty("java.io.tmpdir"),
		"screenshot.png").getAbsolutePath();
ImageUtils.writeToFile(image, imagePath);

Install/Uninstall App

AndroidApp app = new DefaultAndroidApp(new File(
		"d:\\uat\\com.android.chrome.apk"));
device.install(app);
if (device.isInstalled(app)) {
	device.uninstall(app);
}

LogCat with custom filter

final LogCatFilter filter = new LogCatFilter("", "", "com.android", "",
		"", LogLevel.WARN);
final LogCatListener lcl = new LogCatListener() {
	@Override
	public void log(List<LogCatMessage> msgList) {
		for (LogCatMessage msg : msgList) {
			if (filter.matches(msg)) {
				System.out.println(msg);
			}
		}
	}
};

device.addLogCatListener(lcl);
Thread.sleep(60000);

Monitor

Ddmlib can monitor one app's cpu/heap/threads and much more,but we need list running client first.

List running client for app

@Test
public void testListClients() {

  Client[] clients = device.getAllClient();
  for (Client client : clients) {
    ClientData clientData = client.getClientData();
    System.out.println(clientData.getClientDescription() + " " + clientData.getPid());
  }
}

List selected app threads

@Test
public void testListTheads() {

  Client runningApp = device.getClientByAppName("com.android.calendar");

  ThreadInfo[] threads = runningApp.getClientData().getThreads();

  for (int i = 0; i < threads.length; i++) {
    System.out.println(threads[i].getThreadName()
        + " at "
        + threads[i].getStatus());
  }
}

License

The Apache Software License, Version 2.0

device's People

Contributors

cosyman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.