本文整理汇总了Java中com.android.ddmlib.IDevice类的典型用法代码示例。如果您正苦于以下问题:Java IDevice类的具体用法?Java IDevice怎么用?Java IDevice使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IDevice类属于com.android.ddmlib包,在下文中一共展示了IDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onEventReceived
import com.android.ddmlib.IDevice; //导入依赖的package包/类
@Override
public Object onEventReceived(IDevice device) {
File fileDir = new File(dirPath);
if(!fileDir.exists())
throw new RuntimeException("The directory of the files which need to be pushed onto the device is not correct!");
for(File file : fileDir.listFiles()) {
String remoteFilePath = SharedClassesSettings.FUZZY_FILES_DIR_PATH + file.getName();
try {
device.pushFile(file.getAbsolutePath(), remoteFilePath);
} catch (Exception e) {
LoggerHelper.logEvent(MyLevel.EXCEPTION_RUNTIME, "Problem with pushing files onto device: " + e.getMessage());
e.printStackTrace();
}
}
return null;
}
示例2: onEventReceived
import com.android.ddmlib.IDevice; //导入依赖的package包/类
@Override
public Object onEventReceived(IDevice device) {
String senderNumber = "";
for(int i = 0; i < 8; i++)
senderNumber += ThreadLocalRandom.current().nextInt(0, 9 + 1);
String message = UUID.randomUUID().toString().replace("-", "");
EmulatorConsole emulatorConsole = EmulatorConsole.getConsole(device);
if (emulatorConsole == null) {
LoggerHelper.logEvent(MyLevel.ADB_EVENT, adbEventFormat(toString(),"ERROR: Could not send SMS"));
return null;
}
emulatorConsole.sendSms(senderNumber, message);
LoggerHelper.logEvent(MyLevel.ADB_EVENT, adbEventFormat(toString(), String.format("SMS received: Nr: %s | Msg: %s", senderNumber, message)));
return null;
}
示例3: onData
import com.android.ddmlib.IDevice; //导入依赖的package包/类
@Override
public void onData(SocketIOClient arg0, String data, AckRequest arg2) throws Exception {
if (data!=null) {
List<String> list=JsonUtil.jsonTobean(data=data.trim(), List.class);
if (list!=null) {
for (String sernum :list) {
DeviceEntity deviceEntity=DeviceContainerHandler.getDevice(sernum);
IDevice idevice=deviceEntity.getIdevice();
idevice.executeShellCommand(startActivity, receiver);
}
}else {
logger.info("json to bean 失败!!");
}
}
}
示例4: pickDevice
import com.android.ddmlib.IDevice; //导入依赖的package包/类
private IDevice pickDevice() {
List<IDevice> devices = DebugBridge.getDevices();
if (devices.size() == 0) {
MessageDialog.openError(mViewer.getShell(),
"Error obtaining Device Screenshot",
"No Android devices were detected by adb.");
return null;
} else if (devices.size() == 1) {
return devices.get(0);
} else {
DevicePickerDialog dlg = new DevicePickerDialog(mViewer.getShell(), devices);
if (dlg.open() != Window.OK) {
return null;
}
return dlg.getSelectedDevice();
}
}
示例5: initializeSourceCombo
import com.android.ddmlib.IDevice; //导入依赖的package包/类
/**
* Initialize the combo box that shows the log sources
*/
private void initializeSourceCombo() {
mySourceCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
if (myIgnoreActionEvents) return;
Object sel = mySourceCombo.getSelectedItem();
IDevice device = (sel instanceof IDevice) ? (IDevice) sel : null;
myDeviceContext.fireDeviceSelected(device);
}
});
mySourceCombo.setRenderer(new SourceComboBoxRenderer("No Connected Devices"));
Dimension size = mySourceCombo.getMinimumSize();
mySourceCombo.setMinimumSize(new Dimension(200, size.height));
}
示例6: observeForDeviceChange
import com.android.ddmlib.IDevice; //导入依赖的package包/类
/**
* Observe for deviec state changes
*/
private void observeForDeviceChange() {
deviceSelectionListener =
new DeviceContext.DeviceSelectionListener() {
@Override
public void deviceSelected(@Nullable IDevice device) {
notifyDeviceUpdated(device);
}
@Override
public void deviceChanged(@NotNull IDevice device, int changeMask) {
if ((changeMask & IDevice.CHANGE_STATE) == IDevice.CHANGE_STATE) {
notifyDeviceUpdated(device);
}
}
@Override
public void clientSelected(@Nullable final Client c) {
}
};
deviceContext.addListener(deviceSelectionListener, this);
AndroidDebugBridge.addClientChangeListener(this);
AndroidDebugBridge.addDeviceChangeListener(this);
AndroidDebugBridge.addDebugBridgeChangeListener(this);
}
示例7: add
import com.android.ddmlib.IDevice; //导入依赖的package包/类
/**
* Add a new device to the data model, or replace any existing.
*/
private void add(IDevice device) {
String serial = device.getSerialNumber();
do {
// for emulators use their virtual device name as label
String deviceAvdName = device.getAvdName();
if (deviceAvdName != null) {
deviceLabels.put(serial, deviceAvdName + " [" + serial + "]");
break;
}
// for real devices use their model name (something like '<vendor> <device>')
String deviceModelName = device.getProperty("ro.product.model");
if (deviceModelName != null) {
deviceLabels.put(serial, deviceModelName + " [" + serial + "]");
break;
}
} while (false);
// finally, add the serial.
add(serial);
}
示例8: deviceReallyConnected
import com.android.ddmlib.IDevice; //导入依赖的package包/类
private boolean deviceReallyConnected() {
if (adb == null || !adb.isConnected() || !reading || currentDevice == null
|| currentDevice.isOffline() || !currentDevice.isOnline() || !isReading()) {
return false;
}
boolean gotIt = false;
LOG.log(Level.INFO, "searching for device with sn: {0}", currentDevice.getSerialNumber());
for (IDevice d : adb.getDevices()) {
LOG.log(Level.INFO, "device: {0}", d.getSerialNumber());
if (d.getSerialNumber().equals(currentDevice.getSerialNumber())) {
gotIt = true;
}
}
if (!gotIt) {
LOG.info("wasnt found in adb.getDevices");
return false;
}
return true;
}
示例9: getProcessName
import com.android.ddmlib.IDevice; //导入依赖的package包/类
/**
* Get a reference to the name of the process with the given ID. The
* reference may contain a null-object, couldn't be retrieved, but may be
* available later.
*
* @param device Device, where the process runs.
* @param pid ID of the process.
* @return A reference to a string containing the process name or
* {@code null}, if the process couldn't be retrieved yet.
*/
private String[] getProcessName(IDevice device, int pid) {
Map<Integer, String[]> cache = processNameCache.get(device.getSerialNumber());
if (cache == null) {
cache = new HashMap<>();
processNameCache.put(device.getSerialNumber(), cache);
}
String[] nameref = cache.get(pid);
if (nameref == null) {
nameref = new String[1];
cache.put(pid, nameref);
}
if (nameref[0] == null) {
for (Client client : device.getClients()) {
ClientData data = client.getClientData();
if (data.getPid() == pid) {
nameref[0] = data.getClientDescription();
}
}
}
return nameref;
}
示例10: getDevice
import com.android.ddmlib.IDevice; //导入依赖的package包/类
private IDevice getDevice(String devicePort) {
for (IDevice iDev : adb.getDevices()) {
if (iDev.isEmulator() && iDev.getSerialNumber().contains(devicePort)) {
LoggerHelper.logEvent(MyLevel.RUNTIME, "Successfully connected to emulator: "
+ iDev.getAvdName());
return iDev;
}
}
return null;
}
示例11: onEventReceived
import com.android.ddmlib.IDevice; //导入依赖的package包/类
@Override
public Object onEventReceived(IDevice device) {
String deployedApkPath = UtilInstrumenter.SOOT_OUTPUT_DEPLOYED_APK;
try {
String res = device.installPackage(deployedApkPath, true);
if (res != null && !res.isEmpty())
LoggerHelper.logWarning("Not able to install apk " + packageName + ". Error message: " + res);
} catch (Exception e) {
LoggerHelper.logEvent(MyLevel.EXCEPTION_ANALYSIS, "Not able to install apk " + packageName);
e.printStackTrace();
}
return null;
}
示例12: onEventReceived
import com.android.ddmlib.IDevice; //导入依赖的package包/类
@Override
public Object onEventReceived(IDevice device) {
try {
device.uninstallPackage(packageName);
} catch (InstallException e) {
LoggerHelper.logEvent(MyLevel.EXCEPTION_ANALYSIS, e.getMessage());
e.printStackTrace();
System.exit(-1);
}
return null;
}
示例13: onEventReceived
import com.android.ddmlib.IDevice; //导入依赖的package包/类
@Override
public Object onEventReceived(IDevice device) {
String shellCmd = String.format("am start -n %s/.%s", packageName, activityName);
try {
device.executeShellCommand(shellCmd, new GenericReceiver(), 10000, TimeUnit.MILLISECONDS);
LoggerHelper.logEvent(MyLevel.START_ACTIVITY, String.format("started activity %s/%s", packageName, activityName));
} catch (Exception e) {
LoggerHelper.logEvent(MyLevel.EXCEPTION_ANALYSIS, String.format("not able to start activity %s/%s: ", packageName, activityName, e.getMessage()));
e.printStackTrace();
}
return null;
}
示例14: onEventReceived
import com.android.ddmlib.IDevice; //导入依赖的package包/类
@Override
public Object onEventReceived(IDevice device) {
String shellCmd = String.format("am startservice --es \"task\" \"addContact\" -n %s/%s",
packageName, UtilInstrumenter.COMPONENT_CALLER_SERVICE_HELPER);
try {
device.executeShellCommand(shellCmd, new GenericReceiver(), 10000, TimeUnit.MILLISECONDS);
LoggerHelper.logEvent(MyLevel.ADB_EVENT, adbEventFormat(toString(), "contact added..."));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例15: onEventReceived
import com.android.ddmlib.IDevice; //导入依赖的package包/类
@Override
public Object onEventReceived(IDevice device) {
String numberToCall = "";
for(int i = 0; i < 8; i++)
numberToCall += ThreadLocalRandom.current().nextInt(0, 9 + 1);
String shellCmd = String.format("am broadcast -a android.intent.action.NEW_OUTGOING_CALL --es PHONE_NUMBER %s", numberToCall);
try {
device.executeShellCommand(shellCmd, new GenericReceiver(), 10000, TimeUnit.MILLISECONDS);
LoggerHelper.logEvent(MyLevel.ADB_EVENT, adbEventFormat(toString(), shellCmd));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}