We are installing and uninstalling APK(s) every day, might be many time in a day, but have you try to get answer of following questions ?


1. What is Package Manager and Package Installer ?

PackageInstaller is the default application for Android to install interactively normal package. PackateInstaller provide user interface to manage applications/package. PackageInstaller calls InstallAppProgress activity to receives an instruction from the user. InstallAppProgress will ask Package Manager Service to install package via indalld. Source code is available at  <Android Source>/packages/apps/PackageInstaller.


Installd  daemon's primary role is to receive request from Package Manager Service via Linux domain socket / dev/ socket/ installed. installd execute series of steps to install APK with root permission
[Ref: https://github.com/android/platform_frameworks_base/blob/master/cmds/installd/commands.c]


Package Manage is API which actually manage application install, uninstall, upgrade.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.


2. Where APK files stores in Android ?

1. Pre-Install (i.e. Camera, Calendar, Browser,etc.) APK stored in /system/app/
2. User Install (ApiDemo, Any.do, etc.) APK stored in /data/app/
3. 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.

3. 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


4. 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.

1. packages.xml :This file contain list of permissions and Packages/Applications. 
01<packages>
02<last-platform-version external="15" internal="15">
03<permission-trees>
04<permissions>
05<item name="android.permission.CHANGE_WIFI_MULTICAST_STATE" package="android"protection="1">
06<item name="android.permission.CLEAR_APP_USER_DATA" package="android" protection="2">
07.
08.
09.
10.
11</item></item></permissions>
12
13<package codepath="/system/app/Contacts.apk" flags="1" ft="136567b3990" it="136567b3990"name="com.android.contacts" nativelibrarypath="/data/data/com.android.contacts/lib"shareduserid="10001" ut="136567b3990" version="15">
14<sigs count="1">
15<cert index="2">
16</cert></sigs>
17</package>
18.
19.
20.
21.
22<package codepath="/data/app/com.project.t2i-2.apk" flags="0" ft="13a837c2068"it="13a83704ea3" name="com.project.t2i"nativelibrarypath="/data/data/com.project.t2i/lib" userid="10040" ut="13a837c2ecb"version="1">
23<sigs count="1">
24<cert index="3" key="308201e53082014ea0030201020204506825ae300d06092a86
254886f70d01010505003037310b30090603550406130255533110300e060355040a13074
2616e64726f6964311630140603550403130d416e64726f6964204465627567301e170d31
2732303933303130353735305a170d3432303932333130353735305a3037310b300906035
2850406130255533110300e060355040a1307416e64726f6964311630140603550403130d
29416e64726f696420446562756730819f300d06092a864886f70d010101050003818d003
3008189028181009ce1c5fd64db794fd787887e8a2dccf6798ddd2fd6e1d8ab04cd8cdd9e
31bf721fb3ed6be1d67c55ce729b1e1d32b200cbcfc91c798ef056bc9b2cbc66a396aed6b
32a3629a18e4839353314252811412202500f11a11c3bf4eb41b2a8747c3c791c89391443
3339036345b15b5e080469ac5f536fd9edffcd52dcbdf88cf43c580abd0203010001300d0
346092a864886f70d01010505000381810071fa013b4560f16640ed261262f32085a51fca
3563fa6c5c46fde9a862b56b6d6f17dd49643086a39a06314426ba9a38b784601197246f8
36d568e349a93bc6af315455de7a8923f40d4051a51e1658ee34aca41494ab94ce978ae38
37609803dfb3004806634e6e78dd0be26fe75843958711935ffc85f9fcf81523ce23c86bc
38c5c7a">
39</cert></sigs>
40<perms>
41<item name="android.permission.WRITE_EXTERNAL_STORAGE">
42</item></perms>
43</package>
44.
45.
46.
47.
48.
49</permission-trees></last-platform-version></packages>
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.

package tag contain 10 attributes and few sub tags.

SrAttribute NameDescription
1namepackage name
2codePathAPK file installation location (/system/app/ or /data/app/)
3nativeLibraryPathnative library (*.so file) default path is /data/data/<package name>/lib/
4flagStore ApplicationInfo Flags [http://developer.android.com/reference/android/content/pm/ApplicationInfo.html]
5fttimestamp in hex format
6lttimestamp in hex format of first time installation
7uttimestamp in hex format of last update
8versionVersion Code from AndroidManifest.xml file []http://developer.android.com/guide/topics/manifest/manifest-element.html#vcode]
9sharedUserIdThe name of Linux user ID that will be shared with other applications, It is same parameter which we define in AndroidManifest.xml [http://developer.android.com/guide/topics/manifest/manifest-element.html#uid]
10userIdThe name of a Linux user ID

Sub Tags
1. sigs signature information, count attribute represent number of cert tag.
2. cert  contain certification key , index attribute represent global index of certificate, I observer that it increment when new certificate install with application.
3. perms contain permission which developer has set in AndroidManifest.xml

2. 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.

1com.android.launcher 10013 0 /data/data/com.android.launcher
2com.android.quicksearchbox 10033 0 /data/data/com.android.quicksearchbox
3com.android.contacts 10001 0 /data/data/com.android.contacts
4com.android.inputmethod.latin 10006 0 /data/data/com.android.inputmethod.latin

3. packages-stoped.xml : This file contain package list which has stopped state, Stope stated applications can not receive any broadcast. Refer this link for more information about stopped state applicationhttp://yuki312.blogspot.in/2012/03/androidbroadcaststop.html 
1<stopped-packages>
2<pkg name="com.android.widgetpreview" nl="1"></pkg>
3<pkg name="com.example.android.livecubes" nl="1"></pkg>
4<pkg name="com.android.gesture.builder" nl="1"></pkg>
5<pkg name="com.example.android.softkeyboard" nl="1"></pkg>
6</stopped-packages>

4. Where I can find the source code of Package Manager and Package Installer ?

Package Manager

Package Installer
packages/apps/PackageInstaller/src/com/android/packageinstaller/InstallAppProgress.java 

 

Hello friends finally after long waiting Indian developer can sell android app in goolgle play

check this what google says

http://android-developers.blogspot.in/2012/10/google-play-seller-support-in-india.html


Clouds consist of a huge amount of particles of water vapor, reaching hundreds of millions. Clouds do not have central control and basically go where the wind blows. With this perspective, the large number of client computers and servers on the Internet along with many different purposes and entities that direct control of its progress are like clouds. Add this to the wireless data revolution that the cellphone companies have brought us and really feels like we are all covered by a cloud of invisible computing power.
Since early electronic computers, there is a clear division of manpower between four main functional parts of a computer:
  • Input / output (I / O) that provide the interface with people / computer
  • Central processing unit
  • Volatile random access memory (RAM)
  • Nonvolatile memory
The first three parts put the “computer” in computers. It is the fourth part, where the assets of important data are usually stored, that has changed more radically with the advent of cloud computing. Important data assets reside in nonvolatile memory to be protected against power outage – regardless of whether the loss was deliberate. Generally, non-volatile memory devices are hard disks, but can also be solid state devices, such as secure digital cards (SD) and even tape devices (almost obsolete now). But these storage device has its limitations.
Time passes, the technology progresses and brought the computer networks, in which the assets of an organization’s important data can be centralized on a computer shared by several terminals and which can back up regularly, as a basic function needed IT . This model (known as the mainframe model ) offered many advantages – one being lighten the load that each site had terminal. Small offices with little more than a small terminal (keyboard, mouse, monitor and PC) can access gigabytes of corporate data and processing power of large mainframes without cluttering up the place – from which they were connected by wires.
The next major paradigm shift came with the network of networks known affectionately as the Internet, where computer systems absolutely gigantic (LANs) can serve large populations of small terminals anywhere in the world where a dish can be placed. The wireless remote nature of this configuration is known as the cloud.
Then came the personal digital assistants (PDAs), mobile phones and smart phones, for which the miniaturization of computers has progressed to the portable form factor, we know and love so much. Suddenly, intelligent terminals are in the hands of countless millions of productive people, producing and consuming information at prodigious rates.
From mid to late 90s, e-mail and World Wide Web were the most popular applications that dominate the cloud. Most people interacted with the cloud using a Web browser and found that the Internet was a relatively simple application. With the advancement of commercial successes such as Yahoo and Google servers, network connections and terabyte hard drives replaced as the local non-volatile storage devices preferred. Like many visionaries predicted progressive thought, the cloud has become a modern utility, like water, telephones and electricity. Using the digital mobile phone network as an Internet Service Provider (ISP), the cloud grew and uses millions of portable devices as the main tool to display the data residing on these servers.
As the clouds move and are changed by the winds of change, so did the paradigms under which these devices operate – the terminals have become smaller, more powerful and more portable, while the servers, similarly, were more powerful and better able to meet the needs of data users through virtualization software and the measurement of their use.
Companies no longer need to maintain large and expensive “parks” of servers 24 hours a day when there is another less expensive alternative: hiring such services through fully managed cloud hosting providers. Through virtualization, applications that previously ran on custom environments may be duplicated or “having created image” to run in the cloud server provider. And with the proper measurement of these services, the company will not need to pay high prices for those times when their services are being used minimally.
As hardware technology has moved on, the same occurred with software, and saw the creation of new applications. For example, location-based services that map businesses near the site where the cell tower or the global positioning system (GPS) has determined that you are. New markets tailored for download and testing programs and data files useful, as the Android Market. No doubt we will see further advances in these new unique applications of cloud computing – for example, companies could sort and select regional contact information, then automatically download the list of days of random calls to mobile phone based on Android representative regional sales.
Cloud computing, where mobile devices balance powerful servers, needs an operating system that makes the most of the system architects and developers can do on a small client computer. Android is the operating system.
Android Architecture
First, Android is a software stack for mobile devices. This means that top the list of priorities is the preservation of battery power and the efficient management of limited memory resources. There are five distinct layers to the stack of Android:
The core of the Acorn RISC Machine (ARM) Linux form the foundation upon which all other layers are. Linux is a proven technology that is highly reliable and the ARM processor family is known for high performance at very low power requirements.
The libraries provide low-level code reusable and sharable for basic functions such as functions, codecs – software for encoding and decoding of digital video and sound – rich graphics for presentation on a small monitor, support for Secure Shell for TCP / IP traffic encrypted the cloud as well as support for Web browsing component (WebKit), feature SQL database (SQLite) and standard C library functionality, expected in a Linux system.
The bytecode interpreter runtime Dalvik, very similar to the bytecode interpreter in Java ™, includes some distinct features that define uniquely the model of safety and energy conservation Android. Any application currently running, for example, has its own user ID and your own copy of the interpreter running processes to separate rigidly for safety and reliability.
The Android application framework lets you utilize and replace components as required. These high-level Java classes are highly integrated components that define the Android API.
The main applications include the Android WebKit browser, Google calendar, Gmail, Maps application, SMS messenger client, and an e-mail standard, among others. Android applications are written in the Java programming language and you can download many more Android market quickly.
Each Android application can be further divided into distinct functional units:
  • Activities
  • Intents
  • Services
  • Security Model
Activities
Activities are the modules of an Android application that spread out the base class Activity and define an interface that are based on a view that responds to events. If an application consists of three windows (for example, a login window, a window for viewing text and a file viewing window), each one is usually represented by a different class Activity.
The Android keeps a history stack for each running application from the homepage and you can click the Back to scroll back through this history of activities.
Intents
Attempts, such as activities, are a special class of application code that describe and define what an application wants to do. Attempts include a layer without targeting that allows sophisticated reuse and replacement of components. For example, an application can display a button labeled clients that, when clicked, displays a list of contacts who are their clients. And here enters a lack of direction: no need to use the default viewer for those contacts, but instead, you can substitute a different viewer.
For some applications, this can be a very powerful function of application integration. Possibly a topographic map is best for a specific display the default map view.
Classes as a BroadcastReceiver define code that runs when external events trigger the same. Events such as the firing of a timer or the touch of a phone can be tracked that way. Typically, such code does not display a window, but can use the class NotificationManager to alert the user about something that needs attention.
Service
A service is an application running on a low level and without a monitor or UI. It is usually an application that should run long in the background. A perfect example is a software media player playing a song list. Despite a media player application to present a UI that allows users to adjust their playlists, the program passes control to the service to really play the songs from the playlist provided.
Security Model
The Android security model let’s programs have only their own data. If programmers wish to share data between queit a few different programs, they can set content providers for this purpose.
The power of free software should never be underestimated, as the power of free people and creative. Free of proprietary APIs and interests of businesses that generally obstruct progress in software engineering, the Android platform has a large developer community and very active, whose combined talents really make the sum greater than the parts.
Want to empower your programming career?
Learn how to program on the Android platform and, someday, will have millions of mobile phone users in its potential market – some of which may need their program.
The heart of Android is the Linux ARM. That in itself should inspire confidence in the ability of the importance of this platform to grow rapidly. Linux is a fast and secure operating system with many thousands of programmers familiar with it. Many Linux based systems are known to have an uptime of consecutive years online and view applications in the cloud – and that really defines reliability.
Development Environment: Eclipse, Windows, Linux
The developers have several options in relation to Android development environment. They can use the Microsoft ® Windows ® XP or Windows Vista ®, Macintosh OS X (v10.4.8 or later, x86 only) or the Desktop Linux (preferably Ubuntu). There is a software development kit (SDK) that can be downloaded to all these operating systems commonly used.
You can use a GUIIDE like Eclipse or NetBeans, Sun Microsystems, method or the famous “real programmer” from the command line and a default editor. The choice is yours.
Organizations can also put programs and data owners in Android, thanks to the types of software licenses used. This prevents them from escaping the platform, but does not limit consumer choice. It’s a winning combination for all parties.
Developer Resources
There are several resources in the cloud to develop Android, including several community forums and wikis Android, as well as several blogs related to Android programming. The main company that directs the phenomenon Android, Google, is fundamentally a communications company and therefore has many useful forums (known as Google Groups ) for communication between developers of different skill sets and talents.
The links section of Android Resources cannot even begin to show the vastness of the universe Android. Cloud computing – and Android, specifically – is something very, very, very interesting.
Time will tell what new innovative applications of cloud computing will be created in the next few years trying to overcome with all the creations of the great developers who preceded them.

Android Viewflipper Example



Here is a small and easy example of how to use viewflipper in android. Android

 to add multiple views in a single Flipper.ViewFlipperName.showNext() is used to show the next item in flipper. ViewFlipperName.showPrevious() is used to show the previous item in flipper.



Android ViewFlipper Example:
Xml file looks like
[sourcecode language="xml"]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<LinearLayout android:id="@+id/LinearLayout03"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<Button android:id="@+id/Button01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Next"></Button>
<Button android:id="@+id/Button02" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Previous"></Button>
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ViewFlipper android:id="@+id/ViewFlipper01"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<!--adding views to ViewFlipper-->
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Flipper Content 1"></TextView>
<TextView android:id="@+id/TextView02" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Flipper Content 2"></TextView>
<TextView android:id="@+id/TextView03" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Flipper Content 3"></TextView>
</ViewFlipper>
</LinearLayout>
</LinearLayout>
[/sourcecode]
Java file looks like
[sourcecode language="java"]
public class ViewFlipperExample extends Activity implements OnClickListener {
Button next;
Button previous;
ViewFlipper vf;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
vf = (ViewFlipper) findViewById(R.id.ViewFlipper01);
next = (Button) findViewById(R.id.Button01);
previous = (Button) findViewById(R.id.Button02);
next.setOnClickListener(this);
previous.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v == next) {
vf.showNext();
}
if (v == previous) {
vf.showPrevious();
}
}

}
[/sourcecode]
The output will looks like