Thursday 25 August 2016

Android Nougat kind of arrives on the Nexus 5, if you’re bold


Although there’s a lot of community affection for the Nexus 5, many users were dismayed to learn that it would not be receiving Android Nougat. However, in this age of constant modding and customizing, it was only a matter of time before someone came up with a way to run Nougat on their beloved Nexus 5… and it turns out that time was quite short indeed.
Yes, even though the firmware for Android 7.0 just arrived this week, XDA Developers have come up with a port from the AOSP  ROM. If you’re particularly brave, you can now run Nougat on the Nexus 5. There are, however, a few key caveats.
The camera, for instance, doesn’t work. Or Bluetooth. And there’s a slew of stability issues.
Basically, if your Nexus 5 is your primary device, you might want to hold off on unofficially upgrading to Nougat until a little more progress is made. Frankly, the cult fandom of this device seems strong enough that we’d be surprised if an essentially fully-functional Nexus 5 version of Android 7.0 doesn’t emerge from the modding community in the coming months.
The camera, for instance, doesn’t work. Or Bluetooth. And there’s a slew of stability issues.
In order to flash Nougat to your aging pride and joy, you’ll need to have TWRP, do a full wipe and install the rom, then reboot. Full details can be found over at XDA Forums courtesy of user Santhosh M.
What do you think of this early version of Nougat for the Nexus 5? Will you be flashing it to your device? Let us know in the comments below!

Tuesday 16 August 2016

“Bottom navigation” officially added to Material Design

What is Bottom Navigation?

Bottom navigation bars make it easy to explore and switch between top-level views in a single tap. – Material Design spec

Bottom navigation has now officially been added to Google’s Material Design guidelines, meaning you’ll likely start seeing more and more navigation bars being added to the bottom of your favorite apps rather than having different sections separated out into tabs at the top or in sections in the navigation drawer.

Google added the new bottom navigation rules to the Material Design guidelines. That is, the standard by which all Android developers are supposed to adhere if they want to be following the official design rules Google lays out for Android. Now, Google itself doesn’t even strictly follow the rules, and the same can be said of the bottom navigation bars in Google Photos and Google+.



In case you don’t know what “bottom navigation” means, it’s the presence of a navigation bar at the bottom of an app just above the on-screen navigation buttons. It’s designed to replace the need for tabbed sections at the top of an app or in the navigation drawer, arguably because it puts navigation closer to your fingertips. However, Google’s new guidelines allow for both tabs and bottom navigation as well as the hamburger menu.
Check out the full update and all the bottom bar goodness at the link below.

Wednesday 22 June 2016

Codility - CyclicRotation problem solution


Task description



A zero-indexed array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is also moved to the first place.
For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7]. The goal is to rotate array A K times; that is, each element of A will be shifted to the right by K indexes.
Write a function:
class Solution { public int[] solution(int[] A, int K); }
that, given a zero-indexed array A consisting of N integers and an integer K, returns the array A rotated K times.
For example, given array A = [3, 8, 9, 7, 6] and K = 3, the function should return [9, 7, 6, 3, 8].
Assume that:
  • N and K are integers within the range [0..100];
  • each element of array A is an integer within the range [−1,000..1,000].
In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.

Solution:// you can also use imports, for example: // import java.util.*; // you can write to stdout for debugging purposes, e.g. // System.out.println("this is a debug message"); class Solution { public int[] solution(int[] A, int K) { // write your code in Java SE 8 for (int i = 0; i < K; i ++) { for (int j = A.length-1; j > 0; j-- ) { int number = A[j]; A[j] = A[j-1]; A[j-1] = number; } } return A; } } My score from Codility:


Sunday 2 November 2014

How To Install Java on Ubuntu with Apt-Get



Introduction

As a lot of articles and programs require to have Java installed, this article will guide you through the process of installing and managing different versions of Java.

Installing default JRE/JDK

This is the recommended and easiest option. This will install OpenJDK 6 on Ubuntu 12.04 and earlier and on 12.10+ it will install OpenJDK 7.
Installing Java with apt-get is easy. First, update the package index:
sudo apt-get update
Then, check if Java is not already installed:
java -version
If it returns "The program java can be found in the following packages", Java hasn't been installed yet, so execute the following command:
sudo apt-get install default-jre
This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), which is usually needed to compile Java applications (for example Apache AntApache MavenEclipseand IntelliJ IDEA execute the following command:
sudo apt-get install default-jdk
That is everything that is needed to install Java.
All other steps are optional and must only be executed when needed.

Installing OpenJDK 7 (optional)

To install OpenJDK 7, execute the following command:
sudo apt-get install openjdk-7-jre 
This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), execute the following command:
sudo apt-get install openjdk-7-jdk

Installing Oracle JDK (optional)

The Oracle JDK is the official JDK; however, it is no longer provided by Oracle as a default installation for Ubuntu.
You can still install it using apt-get. To install any version, first execute the following commands:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
Then, depending on the version you want to install, execute one of the following commands:

Oracle JDK 6

This is an old version but still in use.
sudo apt-get install oracle-java6-installer

Oracle JDK 7

This is the latest stable version.
sudo apt-get install oracle-java7-installer

Oracle JDK 8

This is a developer preview, the general release is scheduled for March 2014. This external article about Java 8 may help you to understand what it's all about.
sudo apt-get install oracle-java8-installer

Managing Java (optional)

When there are multiple Java installations on your Droplet, the Java version to use as default can be chosen. To do this, execute the following command:
sudo update-alternatives --config java
It will usually return something like this if you have 2 installations (if you have more, it will of course return more):
There are 2 choices for the alternative java (providing /usr/bin/java).

Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      manual mode

Press enter to keep the current choice[*], or type selection number:
You can now choose the number to use as default. This can also be done for the Java compiler (javac):
sudo update-alternatives --config javac
It is the same selection screen as the previous command and should be used in the same way. This command can be executed for all other commands which have different installations. In Java, this includes but is not limited to: keytooljavadoc and jarsigner.

Setting the "JAVA_HOME" environment variable

To set the JAVA_HOME environment variable, which is needed for some programs, first find out the path of your Java installation:
sudo update-alternatives --config java
It returns something like:
There are 2 choices for the alternative java (providing /usr/bin/java).

Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      manual mode

Press enter to keep the current choice[*], or type selection number:
The path of the installation is for each:
  1. /usr/lib/jvm/java-7-oracle
  2. /usr/lib/jvm/java-6-openjdk-amd64
  3. /usr/lib/jvm/java-7-oracle
Copy the path from your preferred installation and then edit the file /etc/environment:
sudo nano /etc/environment
In this file, add the following line (replacing YOUR_PATH by the just copied path):
JAVA_HOME="YOUR_PATH"
That should be enough to set the environment variable. Now reload this file:
source /etc/environment
Test it by executing:
echo $JAVA_HOME
If it returns the just set path, the environment variable has been set successfully. If it doesn't, please make sure you followed all steps correctly.

Tuesday 28 October 2014

In Depth : Android Package Manager and Package Installer


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 ?
2. Where APK files stores in Android ?
3. What is APK installation process in detail ?
4. How Package Manager store data ?
5. Where I can find source code of Package Manager and Package Installer ?



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.

Sr Attribute Name Description
1 name package name
2 codePath APK file installation location (/system/app/ or /data/app/)
3 nativeLibraryPath native library (*.so file) default path is /data/data/<package name>/lib/
4 flag Store ApplicationInfo Flags [http://developer.android.com/reference/android/content/pm/ApplicationInfo.html]
5 ft timestamp in hex format
6 lt timestamp in hex format of first time installation
7 ut timestamp in hex format of last update
8 version Version Code from AndroidManifest.xml file []http://developer.android.com/guide/topics/manifest/manifest-element.html#vcode]
9 sharedUserId The 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]
10 userId The 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 application http://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 

Monday 27 October 2014

Android 5.0 Lollipop API Change




src: http://www.android.com/new/images/banners/lollipop-1600.png
Android 5.0 Lollipop Features


  • Material design
  • Performance focus
  • Notifications
  • Your apps on the big screen - TV
  • Document-centric apps
  • Advanced connectivity
  • High-performance graphics
  • More Powerful Audio
  • Enhanced Camera & Video
  • Screen capturing and sharing
  • New types of sensors
  • Chromium WebView
  • Accessibility & Input
  • Tools for building battery-efficient apps



TypeAdditionsChangesRemovalsTotal
Packages1457172
Classes and Interfaces1473600507
Constructors9831102
Methods77011729916
Fields11507521227
Total2179612332824


The overall difference between API Levels 20 and 21 is approximately 6.51%.





Android L Preview API Changes


TypeAdditionsChangesRemovalsTotal
Packages843051
Classes and Interfaces872320319
Constructors842086
Methods4086917494
Fields754221777
Total1341368181727
The overall difference between API Levels 20 and L-preview is approximately 3.77%.