Android Service Distribution - android

I have developed an android service. Any android app can use it's API's to get some kind of news updates from this service. I want to distribute this service so that any android app on the phone can use this service. My questions here are :
When some android application try to use its API on the phone and suppose that service is not available on the phone then what will happen ?
How will android application developer will make sure that the service is available on the phone ?
Does application developer has to bundle service with his application ? If yes then wont be there multiple instances of same service on phone if multiple application contains same service on the phone ?
Thanks
Dalvin

When some android application try to use its API on the phone and suppose that service is not available on the phone then what will happen?
If they are smart, they will use PackageManager to see if you are installed first. Otherwise, their attempt to call startService() or bindService() will fail.
How will android application developer will make sure that the service is available on the phone ?
Use PackageManager.
Does application developer has to bundle service with his application?
How are we supposed to know? You are the person who wrote it.
If yes then wont be there multiple instances of same service on phone if multiple application contains same service on the phone ?
Possibly. It is difficult to answer this question in the abstract, as there are multiple ways to distribute this service (as an APK, as an Android library project, as a JAR, as just a hunk of source code) and multiple ways to integrate it (change the source code, use the source/JAR/library as-is, reference the existing APK).

Related

Android application process

I have some very basic questions, Great to get answer.
Q 1. Whenever anyone creates android application which generates *.apk file and installed this apk on device, can we surely say that android has created new process for this apk ?
Q 2. If Android app manifest file has tag for application and inside it has service only. and If it installed on device as apk.
Now this service remotely going to be access by another android application using aidl which has application tag and inside that there is Activity. which access above remote service.
can we say that service accessing App and remote service both are different process ? I think Yes.
My assumption
Any app which has tag inside manifest file and which generates apk and get installed on android device then on launch by any other App remotely or starts its own on some event intent then android framework will launch new process to start for this apk. Please correct ?
android:process can be set if any components of same application want to run in another process or different applications component want to run in the same process.
Please read carefully and then only reply, let me know if need more explanation.
R1. The apk is just a package. When you start your application, low level, the linux machine on which Android is based will fork a process called Zygote. Then the copy of the Zygote (that already has either an instance of the Dalvik Machine mapped in its address space, or the ART libraries and Ahead Of Time compiled application code), will load all application specific java classes, and all core dependencies (native libraries), plus all application specific native code.
So it does create a new process only when you start the application.And hypothetically, you could create any number of processes for the same apk, which is just a container.
R2. If in the AndroidManifest you have a service declared as "exported", it will run in a separate process. Your application will then communicate with this process using an IPC mechanism called Binder, which is a specific implementation of shared memory at kernel level. AIDL is a meta-language interpreted at build time and used to auto-generate Java stubs that will work deep down with native binder code.
Whenever anyone creates android application which generates *.apk file and installed this apk on device, can we surely say that android has created new process for this apk ?
No. Installing an app does not fork a process for that app.
can we say that service accessing App and remote service both are different process ? I think Yes.
By default, they will be in separate processes.

com.android.server.PackageManagerServices and Android

I am trying to debug native code in my Android App development and I need to have com.android.server.PackageManagerServices in the device. I search the info for PackageManagerServices and can't find good info in the web.
My queries are
(1)Where to get com.android.server.PackageManagerServices?
(2)How to create this service available on the device?
Thanks
PackageManagerService is located at /frameworks/base/services/java/com/android/server/pm/
PackageManagerService is a system service which gets started by SystemServer.java at boot time and always keeps running. one need not to create another instance of it.
You can refer aosp source code at http://androidxref.com

creating android service like system service

I want to implement a service which should be running like standard system service on boot up, this service should not be kill-able and should be able to perform action on receiving notification from another process.
Can anyone help me which is the best methodology (AIDL) to create such service,if any example for reference ?
You can't do this unless you are creating your own system ROM.
If creating your own ROM, you can start by modifying the AndroidManifest of the apk containing your service. You need to add an attribute to your manifest node: android:sharedUserId="android.uid.system". That will cause your APK to hold the system ID (which requires the APK to be signed with your platform signing key -- this is why you need to be creating your own system ROM.
That will allow your application to be considered special by the system, and (at least on 4.x, I haven't tested on older Android versions) your application will be auto-started. The application being auto-started doesn't mean much on its own though; either you need to implement a BOOT_COMPLETED receiver as #febinkk suggests, or you can provide a custom Application override (by adding the attribute android:name="your.package.ApplicationSuperClass" to your application node in your AndroidManifest.xml). In your application super class, you can overload onCreate() and have it start your service or whatever else is required.
Additionally, as a system application, I believe (though have not fully tested) you will not be able to be killed through normal means.
You are not able to create non-killable, immune service without creating your own ROM
You could register a BroadcastReciever with filter for android.intent.action.BOOT_COMPLETED for your service and after starting call startForeground(). This may not be what exactly you were looking, but this is probably the only thing that comes near, if you don't want to create ROM.

check to see if an application is a service or contentprovider

I am writing an application to add all our apps to the homescreen of our devices. I need it to skip the apps that are services or contentproviders that just run in the background and are never "launched" by the user.
Any ideas? Right now i am specifying the apps, but would like to have it more automated.
Thanks!
See this thread for information on finding launchable Intent instances from the package manager.

What is android.permission.SET_PROCESS_LIMIT used for in an android application?

I have been trying to figure this out on the web with no information whatsoever as to what this actually does. The Google Manifest information says:
Allows an application to set the maximum number of (not needed) application processes that can be running.
I am thinking this is not a third party app permission but I need to be sure, its for our embedded device.
My guess is that this limits the number of processes that one application can have open when calling android:process=".RemoteActivity" in the manifest.
Anyone? Thank you.
It's a development/debug intended permisson. And just do what it says. Remember that when you run an app, android creates a process for all it's activities. This is, if you start opening the different activities of your application, you use the same process. However, Android let's you choose if an activity uses the main process or another new one. That's why this permission exists.
Sources:
http://developer.android.com/guide/topics/fundamentals/processes-and-threads.html
http://developer.android.com/reference/android/Manifest.permission.html#SET_PROCESS_LIMIT

Categories

Resources