"How are" Android applications (Facebook etc.) installed to an android phone? [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I know how to install an application to an Android device e.g from Play-Store or via an .apk file. But I'd like to understand the actual process of installation.
E.g. on Windows:
Serial codes etc. are placed in the registry
Files important to the running of software are placed within the Program Files folder (the main .exe etc.)
So far, what I do know about the Android application installation process is:
After an android application has been executed (post-installation), data freshly downloaded is placed in locations like: Android/data or Android/obb etc.
If specifically expressed by an Android developer, files can also be placed elsewhere e.g. on secondary storage (memory cards, cloud storage etc.)
But other than that, my knowledge concerning the Android installation process is pretty slim e.g.:
I don't know where important files relating to an Android program's execution are placed (in the case of Windows, the .exe, related media, libraries etc.)
I similarly don't know how these files are structured upon an Android device (post-installation) e.g. are these files structured in folders like: java, res, menu, layout etc. as during development within environments like Android Studio?
Neither do I know how what application file-types are stored on a user's device post-installation (after being unpacked from the android installation file or apk) e.g. are they stored as .java and or .xml files, as during development etc.
Hopefully someone can fill in the blanks, thank you.

Beginnning
PackageInstaller calls InstallAppProgress activity to receives an instruction from the user. InstallAppProgress will ask PackageManager Service to install package via installd. Source code is available at <Android Source>/packages/apps/PackageInstaller.
When we install APK file, Package Manager parse the package(APK) file and display confirmation, When user press OK button, Package Manager call method named installPackage with these four parameters namely uri, installFlags, observer, installPackageName. Package Manager start one service named "package", now all fuzzy things happen in this service. you can check PackageInstallerActivity.java and InstallAppProgress.java in PackageInstaller source code. Package Manager Service running in system_service process and install daemon (installd) that runs as a native process both start at system boot time.
Where APK files stores in Android ?
Pre-Install (i.e. Camera, Calendar, Browser,etc.) APK stored in /system/app/
User Install (ApiDemo, Any.do, etc.) APK stored in /data/app/
Package Manager create data directory /data/data/<package name>/ to store database, shared preference, native library and cache data
You might see apk file and *.odex file for same APK, ODEX file is totally different discussion and purpose.
What is APK installation process in detail ?
Following process execute in Package Manager Service.
Waiting
Add a package to the queue for the installation process
Determine the appropriate location of the package installation
Determine installation Install / Update new
A copy of the apk file to a given directory
Determine the UID of the app
Request to installd daemon process
Create the application directory and set permissions
Extraction of dex code to the cache directory
To reflect and packages.list /system/data/packages.xml the latest status
Broadcast to the system along with the name of the effect of the installation is complete package
Intent.ACTION_PACKAGE_ADDED: If the new ( Intent.ACTION_PACKAGE_REPLACED): the case of an update.
How Package Manager store data ?
Package Manager store application information in three files, located in /data/system. Following sample is extracted from Android 4 ICS emulator image.
packages.xml:This file contain list of permissions and Packages/Applications.
This xml file stores two things 1. permissions 2. package (application), permission are store under <permissions> tag. Each Permission has three attributes namely name, package and protection. Name attribute has permission name which we are using in AndroidManifest.xml, package attribute indicate permission belong to package, In majority cases "android" is values because <permission> tag contain default permissions and protection indicate level of security.
packages.list: It is simple text file contain package name, user id, flag and data directory, I can't find any perfect description but I assume it that packages.list file may provide faster lookup of installed package because it file keep important information only.
com.android.launcher 10013 0 /data/data/com.android.launcher
com.android.quicksearchbox 10033 0 /data/data/com.android.quicksearchbox
com.android.contacts 10001 0 /data/data/com.android.contacts
com.android.inputmethod.latin 10006 0 /data/data/com.android.inputmethod.latin
packages-stoped.xml: This file contain package list which has stopped state, Stope stated applications can not receive any broadcast.
Where I can find the source code of Package Manager and Package Installer ?
Package Manager
frameworks/base/services/java/com/android/server/pm/Settings.java
frameworks/base/services/java/com/android/server/pm/PackageManagerService.java
frameworks/base/services/java/com/android/server/pm/IPackageManager.aidl
frameworks/base/services/java/com/android/server/pm/PackageSignatures.java
frameworks/base/services/java/com/android/server/pm/PreferredActivity.java
frameworks/services/java/com/android/server/PreferredComponent.java
frameworks/core/java/android/content/IntentFilter.java
frameworks/base/core/java/android/content/pm/PackageParser.java
frameworks/base/services/java/com/android/server/pm/Installer.java
frameworks/base/core/java/com/android/internal/app/IMediaContainerService.aidl
frameworks/base/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java
Package Installer
packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java
packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageUtil.java
packages/apps/PackageInstaller/src/com/android/packageinstaller/InstallAppProgress.java.
Links to refer: link 1 and link 2.

Related

What is the right way (resp. folder) to save files under Android 11 (API30)?

My Android-APP creates text files that have to be read by other apps.
I originally chose the following directory, which no longer works:
Environment.getExternalStoragePublicDirectory((Environment.DIRECTORY_DOCUMENTS))
Right now I'm trying the directory:
getFilesDir()
The problem here is that no other app can access this folder.
I'm puzzled as I simply don't know which directory I can use for an exchange between apps.

Do i need to copy .so files to System/libs?

I want to make my application as a system application. But my application crashes when i make it as system app (placed .apk file inside System/app).
It crashes because its not able to load .so files.
My first question here is do i need to copy the libs( Extract .apk and i will be getting libs) inside System/libs or the System automatically does it?
My Second question here is does the system load libraries(.so files) from System/libs or data/data/myApp.PackageName/lib folder?
Any Help would be Appreciated.
My first question here is do i need to copy the libs( Extract .apk and i will be getting libs) inside System/libs or the System automatically does it?
You don't need to manually copy the .so files.
But, please double check why
It crashes because its not able to load .so files.
you need to ensure that you have the corresponding ABI for your target phone, e.g. you need to have arm64-v8a for your real devices, but this ABI won't work for emulators as usually emulators are x86 or x86_64.
My Second question here is does the system load libraries(.so files) from System/libs or data/data/myApp.PackageName/lib folder?
From data/data/myApp.PackageName/lib

How to download files from server to a plugin's internal storage directory

I have an app called MyNiceApp installed in the internal storage /data/app/com.myniceapp.root_pkg.
QUESTIONS 1
Is it possible to programatically download files into /data/app/com.myniceapp.root_pkg
QUESTIONS 2
MyNiceApp is the core app that only contains the main core view that is to be populated by views generated by plugins that a user will download in APK format from my server as wishes.
Is it possible to download these plugin APKs from a personal server into this directory (/data/app/com.myniceapp.root_pkg) and launch the views into the main core view?
I'm thinking it would be better organized if I had a folder created under /data/app/com.myniceapp.root_pkg/plugins, then have DexClassLoader crawl /data/app/com.myniceapp.root_pkg/plugins for downloaded plugins, then I could call my Class implementations, and dynamically load the plugin views to the core view at runtime.
Thank you all in advance.
Answer 1:
There
is a sample (SOF question) for downloading. If u would like write to an internal directory you can use this: File myDir = context.getDir("MyInternalDirectory", Context.MODE_PRIVATE);
That will create a directory in your package folder (comment: the 'context' is not needed if you are in the main thread).
Answer 2:
Working on it....
I hope this will help.

Downloading google app engine database (java project)

I would download the google app engine datastore. I'm following several guides, but none of those helps me.
My web.xml file is setted correctly for the use of remote_api.
I have installed the python sdk and relative google appengine launcher.
I run these instructions in ../Google/google_appengine:
bulkloader.py --dump --application=appID --url=http://appID.appspot.com/remote_api --filename=x.dump
The result is: "Have 11 entities, 0 previusly transferred"; "11 entities transferred in .. seconds"
But I don't find this file, so I don't know if the download is occurred.
I have to create the .dump file previously or it is created automatically.
I have the same problem also with the "--download_data" command.
It works if change the --filename path (where it saves the .dump file).
Probably ../Google/google_appengine folder is protected.

Java: Where to write config without requiring administrative rights

I actually can't believe I'm saying this but since porting my programs to OSX and getting used to permissions, I've realized that what I planned to do on Windows will not work how I want it to. Currently, on windows, my program stores it's setting's in the registry (HKLM) and some user editable resources in a folder next to the program file. For various reasons, I have now decided that the configuration/settings will be stored in a file and the user will be able to in which folder the other resources are kept.
So the question I have now is where to store the configuration file. Obviously it will be updated, but I don't want to program to have to require administrator permissions to run. I would like to offer an option so that all users can use the program (like most programs do), which will of course require Admin, so this leads be onto the second query: where should I store the configuration file (and the folder in which other resources are kept) and how can I detect whether the program has been installed for all users or just one!
Thanks in advance
PS If you didn't guess, the program is written in Java so I would like to know how to programatically get the location you suggest as well please.
Its normal practice in *nix compatible programs to store information in folders starting with name . in the home directory of the users like,
.bash_history
.bashrc
You could use the same on OSX in my opinion and create a directory say,
.myapp
You can store any number of files with any format under that directory.
To get the location of the folder, you can do
String homeDir = System.getProperty("user.home");
File myAppDir = new File(homeDir, ".myapp");
That is roughly the code that can get you your custom config directory for your app.
Please not that dot files / folders are somewhat similar to hidden folders in windows. Your File Manager will not generally show these files / folders by default.
To identify if the program is installed for all the users or not, you could create the configuration at some administrator (root) controlled location like /etc (not sure about Mac) The user configuration can always override the default config. There could be a better way to handle this though.
On both windows and unix, User(usually) has a (home)folder to which it has full permissions. You may create a directory in the home folder and have your user configuration files reside there.

Categories