Android - Force Stop Google Framework - android

I am having some problems on my C2DM connection, and to fix it I need to Force Stop "Google Services Framework".
I would like to automate it, so I have two questions.
1 - Is possible to write some Java code or terminal commands to my application reproduce:
Settings > Apps > All > Google Services Framework > Force Stop ?
(I have SU)
Just kill the process will do exactly that?
2 - What is the package name of Google Services Framework?
com.google...?

GSF package is com.google.android.gsf
On adb:
This does the trick
adb shell ps | grep com.google.android.gsf | awk '{print $2}' | xargs adb shell kill
In Java:
I'm going out on a limb with the kill command, but shell command running code is perfecto.
String killer = "ps | grep com.google.android.gsf | awk '{print $2}' | xargs kill"
Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes(killer+"\n");
os.writeBytes("exit\n");
os.flush();
Have fun killing GSF!

Related

Error killing Camera process in ADB, Android R

I was trying to kill my camera process in adb (i'm running android R) using this command:
kill -HUP ps -A | grep camera | awk '{print $2}'
but after i hit enter, it gave me an error:
/system/bin/sh: kill: ps: arguments must be jobs or process IDs
/system/bin/sh: kill: -A: arguments must be jobs or process IDs
Any idea on how to fix this?
Suggest to use command pkill and learn about pgrep as well.
pkill -9 -f "camera"

[Android]How to pass a process number to cmd line "adb shell kill "

I would like to find a specific target's pid and kill this process.
Then, i made a shell:
#!/bin/bash
#
func(){
while true; do
adb shell ps | grep my-target-process | awk '{print $2}' | xargs adb shell kill
sleep 1
done
}
But, i always get errors like below :
usage: kill [-s signame | -signum | -signame] { job | pid | pgrp } ...
kill -l [exit_status ...]
Is there anything wrong? Thanks.
I will add an explanation the logic I suggested in the comments section. The reason why
| xargs -I{} adb shell kill "{}"
works is, with the -I{} flag in xargs, the {} becomes a placeholder for the output returned from the previous command, i.e. the process-id is now present in {} and can be passed as an argument/input to your kill command.
(also) As an alternative, if your Android version supports pidof command, which returns the process-id pid directly, you can do
adb shell pidof -s "my-target-process" | xargs -I{} kill "{}"

How do I kill all active tasks/apps using ADB?

Is it possible to kill ALL the active tasks/apps in the task manager using ADB? This would be equivalent of opening the task manager and killing each task one by one...
I tried using the the following adb shell command but that didn't kill all the task.
adb shell am kill-all
I can't use the adb shell am force-stop <PACKAGE> command because it would require me to know which package/app is running. I want to kill ALL the user apps task that are running. Similarly to using the task manager and killing each task one by one.
According to the command description, kill-all kills all background processes. Are background processes equivalent to "services" and task equivalent to "activities"?
Also, is it possible to clear cache of apps using ADB while keeping the user data? I seems that the adb shell pm clear clears all the user data. I want to only clear the cache.
The reason why I am asking is because I am doing some performance testing on few user apps. To make each test valid, I want to ensure none of the user apps have any task, activities, services, and cache already in the background.
You can use force-stop, it doesn't require root permission.
adb shell am force-stop <PACKAGE>
And you can get the package name from the top running activity/app
adb shell "dumpsys activity | grep top-activity"
After that you need to play a bit with the result, to extract the package, here my java code that does that:
public void parseResult(String line){
int i = line.indexOf(" 0 ");
if(i == -1){
return;
}
line = line.substring(i);
i = line.indexOf(":");
if(i == -1){
return;
}
line = line.substring(i + 1);
i = line.indexOf("/");
return line.substring(0, i);
}
If you want to start clean slate i.e close the app and clear its data too you can do the following
adb shell pm clear com.yourapp.package
For non rooted devices I expanded on Faisal Ameer's Script
adb shell ps | grep -v root | grep -v system | grep -v "android.process." | grep -v radio | grep -v "com.google.process." | grep -v "com.lge." | grep -v shell | grep -v NAME | awk '{print $NF}' | tr '\r' ' ' | xargs adb shell am force-stop
The adb shell am force-stop does not require root permission. Note that the applications still show up in the devices running application drawer but I have verified that the packages processes have been cleared using.
adb shell dumpsys meminfo relevant.package.names
find running apps, ignoring system apps etc and kill, the following command does it all;
adb shell ps|grep -v root|grep -v system|grep -v NAME|grep -v shell|grep -v smartcard|grep -v androidshmservice|grep -v bluetooth|grep -v radio|grep -v nfc|grep -v "com.android."|grep -v "android.process."|grep -v "com.google.android."|grep -v "com.sec.android."|grep -v "com.google.process."|grep -v "com.samsung.android."|grep -v "com.smlds" |awk '{print $2}'| xargs adb shell kill
you can add more exceptions if you find any like this; grep -v "exception"

How to kill a unix process by grabbing its PID and not using awk?

Killing a process can be done by grabbing the process pid and awk:
kill $(ps aux | grep '[m]yprocess' | awk '{print $2}')
How can I achieve the exact same thing without using awk, pkill or anything else not available in Android's shell?
In most of the newer *nix systems you have pkill available. So just use:
pkill -f myprocess
to kill a process by name. (Use killall on OSX)
In absence of pkill you can do:
read s _ < <(ps ax | grep '[m]yprocess') && kill "$s"
OR if BASH isn't available then use:
ps ax | grep '[m]yprocess' | while read s _; do kill "$s"; done
use cut -cn1-n2 to cut everything but chars from n1 to n2 in place of awk call. Find the right columns by looking at the result of ps aux and counting char positions for the field PID.

Android adb shell ,ps-ef does not show any process?

i have many application running on my emulator but ps -ef does not show any process y?
It seems like Android's ps does not accept the argument -ef. Try issuing ps only?
adb shell ps | grep com.android.mms | awk '{print $2}'
This gives the process id of the attached process

Categories

Resources