Android/adb redirect console app output - android

I am trying to get the output of a WLAN driver control interface via adb shell on a motorola droid 2. The command is called wlan_cu. To run the command,I am using:
% wlan_cu -itiwlan0 -s /data/jay/stat.sh
Connection established with supplicant .../Connection> Bssid_list,
Connect, Disassociate, Status, Full_bssid_list, wPs/
Status : DISCONNECT MAC : f8.7b.7a.7b.b7.9b SSID : <empty>
BSSID : 00.00.00.00.00.00
Channel : <empty>
Driver/, Connection/, Management/, Show/, Privacy/, scAn/, roaminG/, qOs/, poWer/, eVents/, Bt coexsistance/, Report/, dEbug/, biT/, aboUt, Quit
[1] Segmentation fault wlan_cu -itiwlan0 -s /data/jay/stat.sh
The -s option is to read wlan_cu commands from a script.
% cat /data/jay/stat.sh
c s
/
q
If I try to redirect the output i.e.
% wlan_cu -itiwlan0 -s /data/jay/stat.sh &> out.txt
out.txt is created, but empty and the output still goes to screen. Anyone have an idea? been stuck on this for quite a while.

you can try to redirect both stdout and stderr to the out.txt. Try this,
# wlan_cu -itiwlan0 -s /data/jay/stat.sh > out.txt 2>&1

Related

Why Android JNI code has different result than adb shell with the same command?

I am trying to get Android network stats using the code below:
string cmd = "cat /proc/net/xt_qtaguid/stats";
string info = Utils::exec(cmd);
It returns only headers of the information table, like:
idx iface acct_tag_hex uid_tag_int cnt_set rx_bytes rx_packets tx_bytes tx_packets rx_tcp_bytes rx_tcp_packets rx_udp_bytes rx_udp_packets rx_other_bytes rx_other_packets tx_tcp_bytes tx_tcp_packets tx_udp_bytes tx_udp_packets tx_other_bytes tx_other_packets
But when I execute this command via adb shell cat /proc/net/xt_qtaguid/stats, the result sames fine.
How can I deal with this issue? Do I need to root my phone?
EDIT
adb shell id's output:
uid=2000(shell) gid=2000(shell) groups=2000(shell),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats) context=u:r:shell:s0

Connecting Raspberry Pi running Android Things to wifi

I've been trying to connect to my Raspberry Pi running Android Things to wifi but to no avail.
I've followed this guide to connect to Wifi. I had connected my Pi via ethernet port to get the IP address and then was able to connect via adb connect Android.Local. But when starting the WifiSetupService via the below command
adb shell am startservice \
-n com.google.wifisetup/.WifiSetupService \
-a WifiSetupService.Connect \
-e ssid <Network_SSID> \
-e passphrase <Network_Passcode>
and then getting the logcat output via adb logcat -d | grep Wifi command, I get the below output:
12-28 17:27:19.761 1133 1133 D WifiSetupService: onStartCommand(Intent { act=WifiSetupService.Connect cmp=com.google.wifisetup/.WifiSetupService (has extras) })
12-28 17:27:19.761 1133 1133 I WifiConfigurator: Connecting to network with SSID "winterfell"
12-28 17:27:19.764 408 1052 D WifiService: setWifiEnabled: true pid=1133, uid=10023
12-28 17:27:19.771 1133 1360 D WifiConfigurator: Updating existing network 0
12-28 17:27:19.845 408 1361 D WifiNetworkHistory: saving network history: "winterfell"WPA_PSK gw: null Network Selection-status: NETWORK_SELECTION_ENABLED ephemeral=false choice:null link:0 status:2 nid:0 hasEverConnected: false
12-28 17:27:19.845 408 1361 V WifiNetworkHistory: writeKnownNetworkHistory write config "winterfell"WPA_PSK
12-28 17:27:19.883 408 1362 D WifiNetworkHistory: saving network history: "winterfell"WPA_PSK gw: null Network Selection-status: NETWORK_SELECTION_ENABLED ephemeral=false choice:null link:0 status:2 nid:0 hasEverConnected: false
12-28 17:27:19.884 408 1362 V WifiNetworkHistory: writeKnownNetworkHistory write config "winterfell"WPA_PSK
12-28 17:27:19.884 408 457 I WifiConnectivityManager: forceConnectivityScan
12-28 17:27:19.886 408 457 E WifiScanner: listener cannot be found
12-28 17:27:49.884 1133 1360 E WifiConfigurator: Wifi failed to connect in 30000 ms
I don't know where I am missing or why Pi is unable to connect to Wifi. I have verified multiple times that I'm sending the correct passphrase to the shell am command.
Any help will be highly appreciated!
the ssid for
-e ssid <Network_SSID> \
is case sensitive :-)
Try Winterfell
I got the same problem but my solution was different, I had an error when I tried to copy the code to the terminal:
adb shell am startservice \
-n com.google.wifisetup/.WifiSetupService \
enter code here
-a WifiSetupService.Connect \
enter code here
-e ssid Network \
-e passphrase Network_Password
It is important to add an space after: Network_Password, I mean an the end like:
adb shell am startservice \
-n com.google.wifisetup/.WifiSetupService \
enter code here
-a WifiSetupService.Connect \
enter code here
-e ssid Network \
enter code here
-e passphrase Network_Password" "
(Without Quotation marks, just a space at the end)
I think I had similar problem. It might be caused by my previous attempts to log to the same network but with wrong SSID/Password (issue with spaces solved here). First I tried to connect to another network, I used hotspot on my Android phone, with WPA2 and simple SSID/Password without any spaces or strange characters just to be sure. It connected without problems but I still couldn't connect to my target access point. What solved my problem was re-flashing the microSD card and trying to connect again but this time with correct SSID/Password for the first time.

Why does adb push/pull redirect STDOUT to STDERR?

When using 'adb pull ...' the output is sent to stderr regardless of success. Is there any reason for this? For an example, pulling a file that is there and pulling a file that doesn't exist:
When I run:
adb pull /data/data/good_file.txt /tmp`
I get the following:
stdout:
stderr: 0 KB/s (13 bytes in 0.078s)
(i.e. no stdout)
Then when when I run:
adb pull /data/data/bad_file.txt /tmp
I get the following:
stdout:
stderr: remote object '/data/bad_file.txt' does not exist
The program below was used to generate the above results:
from subprocess import Popen
cmd = "adb pull /data/data/good_file.txt /tmp"
p = Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
print cmd
print "stdout: " + out
print "stderr: " + err
I have the same issue with: adb install -r /foo/bar.apk and sound like adb always send his result to stderr, just add 2>&1 at end and it solves the problem.
cmd = "adb pull /data/data/good_file.txt /tmp 2>&1"
The 2>&1 just redirects Channel 2 (Standard Error) and Channel 1
(Standard Output) to the same place which in this context is Channel 1
(Standard Output), and thence your log file.

How to prevent calabash-android "App did not start" error?

I work on linux pc,
Ensured that AndroidManifest.xml has permission for INTERNET.
Tried command both with and without proxy, observation is same.
my real device has 4.1.1 android software,
AVD has 4.2.2 android with API level 17, Would that be problem?
I observe that, sample demo app gets launched on device, while I run 'calabash-android run AndroidDemoProject.apk...
but command throws error saying "App did not start" (RunTimeError).
Error details:
Feature: Demo feature
Scenario: I can start my app # features/my_first.feature:3
I wait for "Hello World, AndroidDemoProject" to appear
3707 KB/s (553745 bytes in 0.145s)
3045 KB/s (36301 bytes in 0.011s)
App did not start (RuntimeError)
/usr/lib/ruby/gems/1.8/gems/calabash-android-0.4.9/lib/calabash-android/operations.rb:512:in `start_test_server_in_background'
/usr/lib/ruby/gems/1.8/gems/retriable-1.3.3.1/lib/retriable/retriable.rb:31:in `perform'
/usr/lib/ruby/gems/1.8/gems/retriable-1.3.3.1/lib/retriable/retriable.rb:59:in `retriable'
/usr/lib/ruby/gems/1.8/gems/calabash-android-0.4.9/lib/calabash-android/operations.rb:511:in `start_test_server_in_background'
/usr/lib/ruby/gems/1.8/gems/calabash-android-0.4.9/lib/calabash-android/operations.rb:92:in `start_test_server_in_background'
/home/vijayvk/Downloads/AndroidDemoProject/calabash/features/support/app_life_cycle_hooks.rb:15:in `Before'
Failing Scenarios:
cucumber features/my_first.feature:3 # Scenario: I can start my app
I wait for "Hello World, AndroidDemoProject" to appear
1 scenario (1 failed)
0 steps
0m22.337s
===========================================================================
$calabash-android run ../AndroidDemoProject.apk --verbose, leads to below output
013-09-04 15:42:45 - /usr/bin/ruby1.8 -S cucumber --verbose MAIN_ACTIVITY=sh.calaba.demoproject.AndroidDemoProjectActivity APP_PATH="/home/vijayvk/Downloads/AndroidDemoProject/AndroidDemoProject.apk" TEST_APP_PATH="test_servers/d06f94e698e2dfae7d59f229087ea78f_0.4.9.apk"
Code:
* features/support/env.rb
* features/support/app_installation_hooks.rb
* features/support/app_life_cycle_hooks.rb
* features/support/hooks.rb
* features/step_definitions/calabash_steps.rb
Features:
* features/my_first.feature
Parsing feature files took 0m0.002s
Feature: Demo feature
Scenario: I can start my app # features/my_first.feature:3
I wait for "Hello World, AndroidDemoProject" to appear
2013-09-04 15:42:46 - First scenario in feature - reinstalling apps
2013-09-04 15:42:46 - "/home/vijayvk/Development/adt-bundle-linux-x86-20130219/sdk/platform-tools/adb" -s 00000D6300009613 forward tcp:34777 tcp:7102
2013-09-04 15:42:46 -
2013-09-04 15:42:46 - Uninstalling: sh.calaba.demoproject.test
2013-09-04 15:42:47 - Success
2013-09-04 15:42:47 - Uninstalling: sh.calaba.demoproject
2013-09-04 15:42:49 - Success
2013-09-04 15:42:49 - Installing: test_servers/d06f94e698e2dfae7d59f229087ea78f_0.4.9.apk
3153 KB/s (553745 bytes in 0.171s)
2013-09-04 15:42:54 - pkg: /data/local/tmp/d06f94e698e2dfae7d59f229087ea78f_0.4.9.apk
Success
2013-09-04 15:42:55 - Installing: /home/vijayvk/Downloads/AndroidDemoProject/AndroidDemoProject.apk
4513 KB/s (36306 bytes in 0.007s)
2013-09-04 15:42:56 - pkg: /data/local/tmp/AndroidDemoProject.apk
Success
2013-09-04 15:42:59 - Waking up device using:
2013-09-04 15:42:59 - "/home/vijayvk/Development/adt-bundle-linux-x86-20130219/sdk/platform-tools/adb" -s 00000D6300009613 shell am start -a android.intent.action.MAIN -n sh.calaba.demoproject.test/sh.calaba.instrumentationbackend.WakeUp
Starting: Intent { act=android.intent.action.MAIN cmp=sh.calaba.demoproject.test/sh.calaba.instrumentationbackend.WakeUp }
2013-09-04 15:43:01 - Starting test server using:
2013-09-04 15:43:01 - "/home/vijayvk/Development/adt-bundle-linux-x86-20130219/sdk/platform-tools/adb" -s 00000D6300009613 shell am instrument -e class sh.calaba.instrumentationbackend.InstrumentationBackend -e target_package sh.calaba.demoproject -e test_server_port 7102 -e main_activity sh.calaba.demoproject.AndroidDemoProjectActivity -e debug false sh.calaba.demoproject.test/sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner
App did not start (RuntimeError)
/usr/lib/ruby/gems/1.8/gems/calabash-android-0.4.9/lib/calabash-android/operations.rb:512:in `start_test_server_in_background'
/usr/lib/ruby/gems/1.8/gems/retriable-1.3.3.1/lib/retriable/retriable.rb:31:in `perform'
/usr/lib/ruby/gems/1.8/gems/retriable-1.3.3.1/lib/retriable/retriable.rb:59:in `retriable'
/usr/lib/ruby/gems/1.8/gems/calabash-android-0.4.9/lib/calabash-android/operations.rb:511:in `start_test_server_in_background'
/usr/lib/ruby/gems/1.8/gems/calabash-android-0.4.9/lib/calabash-android/operations.rb:92:in `start_test_server_in_background'
/home/vijayvk/Downloads/AndroidDemoProject/calabash/features/support/app_life_cycle_hooks.rb:15:in `Before'
Failing Scenarios:
cucumber features/my_first.feature:3 # Scenario: I can start my app
I wait for "Hello World, AndroidDemoProject" to appear
1 scenario (1 failed)
0 steps
0m26.737s
==========================================================================
$ calabash-android console AndroidDemoProject/AndroidDemoProject.apk
No test server found for this combination of app and calabash version. Recreating test server.
Done signing the test server. Moved it to test_servers/d06f94e698e2dfae7d59f229087ea78f_0.4.9.apk
irb(main):004:0> ARGV << "-v"
[
[0] "--readline",
[1] "--prompt-mode",
[2] "simple",
[3] "-v"
]
irb(main):005:0> start_test_server_in_background
2013-09-04 16:29:06 - Starting test server using:
2013-09-04 16:29:06 - "/home/vijayvk/Development/adt-bundle-linux-x86-20130219/sdk//platform-tools/adb" -s 00000D6300009613 shell am instrument -e test_server_port 7102 -e class sh.calaba.instrumentationbackend.InstrumentationBackend -e debug false -e target_package sh.calaba.demoproject -e main_activity sh.calaba.demoproject.AndroidDemoProjectActivity sh.calaba.demoproject.test/sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner
RuntimeError: App did not start
from /usr/lib/ruby/gems/1.8/gems/calabash-android-0.4.9/lib/calabash-android/operations.rb:512:in `start_test_server_in_background'
from /usr/lib/ruby/gems/1.8/gems/retriable-1.3.3.1/lib/retriable/retriable.rb:31:in `perform'
from /usr/lib/ruby/gems/1.8/gems/retriable-1.3.3.1/lib/retriable/retriable.rb:59:in `retriable'
from /usr/lib/ruby/gems/1.8/gems/calabash-android-0.4.9/lib/calabash-android/operations.rb:511:in `start_test_server_in_background'
from /usr/lib/ruby/gems/1.8/gems/calabash-android-0.4.9/lib/calabash-android/operations.rb:92:in `start_test_server_in_background'
from (irb):5
Please let me know if there is any work around for this problem...
I could resolve this when I had come across this error, by doing this:
1) Close the AVD and restart
2) If (1) doesnt fix the issue, uninstall the app, and execute reinstall_apps for your app again
3) if (2) doesnt fix the issue, delete the test servers folder and execute start_test_server_in_background again.
Adding the following solves the problem as well.
<uses-permission android:name="android.permission.INTERNET" />
Reference:
http://www.luisdelarosa.com/2013/04/18/how-to-fix-problem-when-app-wont-start-when-testing-with-calabash-android/
Also you can try this way.
Inside your ruby folder find file operations.rb. Path is like this "C:\Ruby23-x64\lib\ruby\gems\2.3.0\gems\calabash-android-0.7.3\lib\calabash-android". Open the file and find the block of code:
Retriable.retriable :tries => 100, :interval => 0.1 do
raise "App did not start" unless app_running?
Change "tries" parameter value on 300 instead of 100. It will help your app run in case of insufficiently productive device.
We've tested 6 different devices with default settings, but only 2 flagship smartphones (Samsung galaxy S6) could run app with "tries" parameter value => 100.
Now all our devices can run apps great!

GSM module with Android on BeagleBoard

I'm using http://www.sparkfun.com/products/9427 as GSM module. I've built for FTDI and generic usb-serial driver. Everytime I try to pppd call GPRS I'll get pppd: connect script failed.
The commands executed were:
1. pppd /dev/ttyUSB0
2. netcfg ppp0 up
3. pppd call gprs
gprs script:
/dev/ttyUSB0
460800
crtscts
modem
noauth
debug
nodetach
usepeerdns
noipdefault
defaultroute
user ""
0.0.0.0:0.0.0.0
connect '/system/bin/chat -s -v -f /system/etc/ppp/gprs-connect-chat' `
gprs-connect-chat script:
TIMEOUT 15
ABORT "DELAYED"
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
ABORT "NO CARRIER"
TIMEOUT 40
'' \rAT
OK ATZ
OK "ATQ0 V1 E0 S0=0 &C1 &D2 +FCLASS=0"
OK AT+CGDCONT=1,"IP","Singtel"
OK ATDT*99#
CONNECT

Categories

Resources