service that gets registered with service manager - android

I did tried some sample code for service and installed the same on device and started the app. I tried to list this service with adb command, which was running now (could see my logs for the same in logcat)
adb shell service list
But, above command lists only system service and could not see my service listed there.
So, my question,
1. Does all services need to register for service manager or it is only the "system services"
2. If i have aidl implemented for this same service will it behave like system service (i mean, get displayed for command like "adb shell service list")
thanks for reading and appreciate any response for my question
-regards,
Manju

Android system services are different from the sort of services you create within an app. You don't need to worry that they don't appear within adb shell service list.
System services are provided in the ROM of the phone and are core parts of the Android OS, for example the "surface flinger" (graphics compositor), "package manager" etc. They are accessed within the Android frameworks so that a typical Android application developer never contacts them directly. They are looked up based on a simple string.
Normal services inherit from the Service class and you connect to them from within application code using an Intent and typically Context.bindService.

Related

Android: How do I figure out which package provides a service?

On android, I can see a service running with service list:
Let's say:
# service list | grep dropbox
87 dropbox: [com.android.internal.os.IDropBoxManagerService]
How do I map this to the APK that is serving it?
These are system services, and are part of the system server.
App services don't show here.
Note that dropbox service is not related to the Dropbox commercial service.
The way to go to the code would be to simply search for that name on the codebase. If you don't have AOSP checkout, you can use https://cs.android.com
For your example, this is the code:
https://cs.android.com/android/platform/superproject/+/master:frameworks/base/services/core/java/com/android/server/DropBoxManagerService.java;l=52?q=IDropBoxManagerService&sq=
If you want to check "Services component" in apks.
adb shell dumpsys activity services
P.S. dropbox is a system service, and system services are totally different things with service components in apk.

AOSP - Custom System Update

I've been searching for about two days for a way to receive informations about System updates in Nougat 7.1.2.
The reason I'm trying to do this is because I need to to make it more accessible for our type of users (but still be able to use the Google Over-The-Air system for my device).
I already know that it is possible to start the default SystemUpdateActivity by using:
adb shell am start -n com.google.android.gms/com.google.android.gms.update.SystemUpdateActivity
Although, I'd like to avoid calling another activity to achieve this.
I've been searching for any kind of BroadcastReceiver or Action but couldn't find anything clearly functional.

Android: How to get the process id of the foreground app

First of all, please note that this question is not same as all the "android foreground app" questions I found on SO, please read on :-)
I'm trying to write an android app for my own use, using golang, without using android-sdk or ndk (this is the KEY point). It is pretty simple, just use golang to write a http service, compile it for arm CPU and voila my app is running and can be access by simply visit http://localhost.
For the purpose of my app, I need to know the currently running foreground application, to define it precisely:
Foreground application is the application that occupies the screen, or has an "activity" what-so-ever (forgive me I'm not an android developer).
Anything that that is depended by the foreground application (e.g. services) is NOT what I am interested in.
If the phone is LOCKED/screen turned off, I want the solution to tell me there is NO foreground app.
And since I do not use anything android, just treat the phone as a LINUX machine, I want the solution to use native LINUX ways, e.g. by inspect /proc, or by calling any installed android command line tool (including sending messages via these command line tools), but NOT using any SDK/NDK way so that I have to use java or incorporate these thing into my app.
Starting from Android SDK 26 (if I remember well) Apps are executed on -one-User-per-App, so (i.e.) WhatsApp is running on UID=30 and Telegram on UID=76, so executing a ROOT command of "ps -A -o PID,USER,NAME" you can parse output and then Kill all Processes that you don't want to be executed.
36119 u30_a149 <WhatsApp_packagename>
36203 u76_a211 <Telegram_packagename>
37399 root [kworker/1:2H]
37423 u0_a329 su
38069 root sh
Without Root Permissions nothing of what you're trying to achieve is possible simply because is not possibile to denied an application to be executed or to kill it without Superuser privilege.

Which process in android asks ActivityManager to broadcast BOOT_COMPLETED

I have searched this over the web, without an answer. Basically while testing a device, I observe that the display screen fires ON much earlier, while in the logcat the print
Consoleui:bootComplete follows after ~ 8 sec.
Now Device screen is displayed as part of starting Launcher application, so in the natural sequence of events, the system server will ask activitymanager to start launcher in a seperate thread and go on doing more work.
Thus it is only natural that display will come up, but still there might remain some services to be started by activitymanager/systemserver before a BOOT_COMPLETED broadcast can be made.
I have to prove this. In order to do so, I need to know which process tells the activitymanager that now it can broadcast the boot_complete message, if its the system server, please tell me the part of code where it does so. Thanks.
The activity manager service sends the boot complete intent on line 6320 of ActivityManagerService.java.
The activity manager service also starts the launcher using an intent with CATEGORY_HOME on line 3305 of ActivityManagerService.java.
It appears that your original question contains 2 sub-questions:
Q1. Where exactly in the AOSP code is system broadcast Intent BOOT_COMPLETED fired?
Q2. What are all the necessary conditions to trigger the firing of BOOT_COMPLETED?
For Q1, a broad location is in the Activity Manager. In this sense, #Alex Lockwood’s answer is correct. However, I have noticed that the exact location and the way this Intent is fired may change between Android versions. A source code search should be able to lead to the answer. Take AOSP branch “android-8.1.0_r32” as an example. First, find out where file “ActivityManagerService.java” is located using the following shell commands:
$ cd [your AOSP branch’s root directory]
$ find . -name ActivityManagerService.java
Once the file is found, go to its parent directory. For example, in our current case:
$ cd frameworks/base/services/core/java/com/android/server/am
Now perform the following search:
$ grep -rIn ACTION_BOOT_COMPLETED .
The output reveals that the exact location is not in file “ActivityManagerService.java”, but in file “UserController.java”. More exactly, it is in method “UserController.finishUserUnlockedCompleted()”.
For Q2, we can search backwards from the above method. Eventually we may reach method “ActivityManagerService.finishBooting()” where we can see that Boolean “mBootAnimationComplete” must be true. This implies that the boot animation process must be completed in order for BOOT_COMPLETED to be fired, and further implies that while the boot animation process is going on, a lot of system services are being started. For further details, you may refer to some dedicated books that explain which system services must be ready in order for the boot animation process to end.

Stop running application with ADB

is there a simple way to stop a running application using ADB.
Szenario:
Working on App
Have a script which uploads, installs and starts App on change
Problem:
Currently running version gets killed (not shutdown), which make testing cleanup very hard. Option would be to "do cleanup in between", like after a certain time, but I would prefer to do it in the correct location (so like with the OS, as long as the App is still running, so need to save value, as soon as the OS tells me e.g. memory low or calls onDestroy, I want to save stuff)
Chris
I'm not aware of a way to do this. I was hoping there might be a way to send an intent to tell the app to exit using adb shell e.g.
adb shell am start -a [intent] -n [class]
However, I found that somebody asked this question on a Google forum but they haven't got an answer:
http://groups.google.com/group/android-platform/browse_thread/thread/3fd02d01c6c3b41a/56814e518503efd6

Categories

Resources