How to kill a not running process in Android - android

Does anybody meet this situation before? I force stop an app in the setting dialog in a Android device.
But when I use ps command via adb it is still displayed on the screen. But this process can't be get by the activityManager.getRunningAppProcesses(). This process even exists after I uninstall this app, It happened randomly.
Because I opened a port in my app using ServerSocket, the port can't be released after I stop my app.
The next time I tried to open my app, it failed to using this port again.
I am using a ASUS EeePad and this problem seems only happened on that device.
By the way, the process can't be get by any 3rd party tools such as process manager.
But it really exists with a pid when I use ps via adb shell to list all processes.

Since there is no code .. here are some hints :
1-do you close your connection ??? that will be the main reason to hold the port busy.
2- deal with socket more safely when your app going to pause , stop, or being destroyed .. you can override onpause,onstop, or ondesotry ..and free the port before closing the app.
3- make connection in a separated thread and implement a timer to check if you really need the port or not ( I mean if your app is alive or not ) and based on that kill/leave the thread (connection)
4- in worst cases .. if you have control over the other side of connection ( server, device .. ) try to make your solution more flexible like making range of ports to firstly check then use if they are available.
good luck

Related

Android remote webview list of active sites is empty

I do some automated tasks an android over adb commands, at one part i need to access a webview inside the app and control it. Until now i did these things:
I get the running webview processes with this command adb shell cat /proc/net/unix
For each process i do a protforwarding with this command adb forward tcp:9222 localabstract:webview_devtools_remote_25866
I do a get request to http://localhost:9222/json and get an array with webvies accessible over this proccess (so i clould check the title and the attaced state to find the right one)
My problem is now that since a few days I always get an empty array. I still able to see the webvies at chrome://inspect/#devices and can connect.
Does anyone have an idea why i only get an empty array or know an alternative solution?
In the meantime I have found the problem. The app I control no longer uses a webview but a browser popup, so it can't be found via the search with webview.

Is it possible to android to lost part of a command writen to a characteristic via BlueTooth via BLE?

I'm developing an adaptation for an android app, to communicate with a remote control, which has some pre defined commands.
I've followed this implementation to do the Bluetooth communication and it's working fine for sometime.
This app should communicate with the remote control every 5 minutes or less, and I've been using the app for almost 6 months now. The last week I've some command clashes problem and looking at the logs I couldn't identify why did that happened. The last time that this had happened the app was running for more than 24h, communicating with the remote control, without any communication issue.
Two of it's commands have some similar characters, the first one that have to be done, to establish the connection.
OK_CONN
And an sniffer command which keeps the pilot awake listening for some sensor data:
N
Looking at the logs I can see the answer for command N, after applying the command OK_CONN.
Is it possible for a Bluetooth command to lost part of it's data, during an established communication or am I doing something wrong when writing to a characteristic? Should I change the command names to avoid this kind of clash?
I'm using android 9, at a Sony XPeria XZ phone.
Edit to clarify #Emil comment
07:02:12.880 [BleThread] writing <OK+CONN> to characteristic
07:02:12.368 [Binder:19249_F] [onCharacteristicChanged():274]:
n command confirme
Looking at the logs I see that the last written command as an ok_conn but it has written only the N, this is been show as the last line, it has confirmed to receive the n command alone, instead of receiving the full data of ok_conn.
By name clashes I mean that maybe the last N of the ok_conn command is been accepted as the command.
I just realized what's going on, you can post that as an answer #Emil, my problem was at the logic that sends the first command, sometimes I send this command and the micro controller is not started yet, that's probably the reason of it getting only part of the command.
Not sure what you mean by name clashes, but Android will always write what you told it to write, without packet loss, as long as you follow the rules to never have more than one outstanding operation (always wait for callback before you send the next operation) and that your data must fit within the maximum length for the corresponding operation.

Listening on socket under Android with C++ app

I would need to create C++ console application that runs under non-privileged user under Android 5 (rooted). This application listens on some socket port and accepts connections. It is implemented with boost::asio. When application runs as a root, then everything works. When it runs as an ordinary user, then application crashes when it tries to open acceptor:
const boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 3784);
boost::asio::ip::tcp::acceptor acceptor(ioService);
acceptor.open(endpoint.protocol()); // Here it throws an exception
The exception is a bit confusing but probably it means that I don't have access rights to touch sockets:
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >'
what(): open: Permission denied
Aborted
I tried to run application under user shell and under user media. I also tried to run it under user u0_a83, that is assigned to ProxyDroid on my device.
I changed /system/etc/permissions/platform.xml -- I assigned permission android.permission.INTERNET to user shell and media . I also tried to add group media to android.permission.INTERNET, but nothing has helped.
Btw. this is a special case when I really need to implement application in C++ to run under Android. Implementation in Java is not acceptable in my project.
It seems that the best solution is to use users that are predefined in Android and corresponds to capabilities available on the system: https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h . In my case I can run the app under user inet (3003) that can create sockets.

Android: Emulator frequently disconnected (offline)!

Sometime just after I launched a new emulator, for very first time I was trying to upload my apk, however I got "emulator: ERROR: the user data image is used by another emulator. aborting".
I launched a new emulator, and left it alone, several minutes later, DDMS showed "device offline".
I had to restart a new one, you know, minutes wasted.
It's really bothering that I keep getting this error and slowed down debugging.
How do I fix it?
If the emulator is still alive, you can tell adb to connect to it via tcp (which is I believe what it does anyway, only it normally uses an 'emulator' class of name and would now get a ip:port one)
It's been a while since I've had to do that, but I think that if you were using emulator-5554 you would connect to your development machine's loopback one port higher, ie:
adb connect localhost:5555
If it works adb devices will show it an eclipse should see it as a deployment option
The 'in use' problem sounds like a stale lockfile perhaps left behind in a crash
I have another solution. try this
Run configurations > Target > Wipe user data > Run
In my case it happens when I have another process listening on emulator port.
e.g. if I see:
emulator-5554 offline
it means that something is using port 5554
Manually delete these following folders:
C:\Users\%UserName%.android\avd\AVD2.1.avd\cache.img.lock
C:\Users\%UserName%.android\avd\AVD2.1.avd\userdata-qemu.img.lock
this always works for me. :3
On Arch Linux x64, I had this similar problem which led me to this question. Using Eclipse, the emulator-5554 window would freeze, and Eclipse prompted me to start a new one. In the following dialog, emulator-5554 was reported to be offline, with an unknown target. If I started a new instance, it would be emulator-5556. This problem persisted through Eclipse restarts and log-off-on cycles too! Further, killx would close the window, but the process was still running.
So, find the emulator64-arm process id (not emulator-arm!):
ps ax | grep "emulator64-arm"
...and then just kill -9 it:
sudo kill -9 6728
...where 6728 was its PID. This completely disconnects the emulator so Eclipse can try to run it again.
Open android debug monitor window by
typing "monitor" command in cmd,
then select device in the monitor window,
click on down arrow as shown in the figure then just click on reset tab thats all you will get internet connection.
It was some strange
I had that problem, automatically stopped the emulator localhost:5554 after to launch the application.
I didn't know why it happens but intil today I did something different at I could launch as normality.
What I did as different was to change the prespective of Eclipse ADT. I was executing the application from Debug and now I executed from Java Prespective, it worked, I don't know the reason, I had to share it, sound some .. this answer but I resolved doing that without deleting and creating again my android virtual device.

how can i use 'adb shell' command to know application response or current activity

I have created a batch file that fires adb shell command to start activity, send events to enter text into username and password text fields & click login buttons to navigate to other activity(screen).
how can i know that application navigate to other activity or want to know the response that tell me if login successful or not using shell commands.
Thanks,
Bhushan
Dollop, where I work, provides a record-and-play-back tool for Android that will do the things you suggest and save you the hassle of interacting with low-level shell commands. (It is currently limited to running on Windows in communication with Android devices). It's easy to configure and use, requires no programming, runs against real devices (which do NOT have to be rooted) and automatically saves screenshots as it plays tests. I'd love to hear your feedback.
try to get process (ps aux | grep xxxxx ) information to know the activity running or not

Categories

Resources