Advanced Android Programming George Nychis Srinivasan Seshan.

Slides:



Advertisements
Similar presentations
Android Application Development A Tutorial Driven Course.
Advertisements

Google Android Introduction to Mobile Computing. Android is part of the build a better phone process Open Handset Alliance produces Android Comprises.
 data/data-storage.html#pref data/data-storage.html#pref 
Programming with Android: SDK install and initial setup Luca Bedogni Marco Di Felice Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna.
DCM Embedded Software Infrastructure, Build Environment and Kernel Modules A.Norman (U.Virginia) 1 July '09 NOvA Collaboration Mtg.
Operating-System Structures
Cosc 4/5730 Android and Blackberry Near Field Communications (NFC)
PROJECT IN DISTRIBUTED SYSTEMS IPERF FOR ANDROID Developers: Shir Degani, Yuval Degani Supervisors: Prof. Roy Friedman, Alex Kogan.
Android and Project Structure. Android Android OS – Built on Linux Kernel – Phones – Netbooks – Readers – Other???
V0.01 © 2009 Research In Motion Limited Introduction to Java Application Development for the BlackBerry Smartphone Trainer name Date.
Low level CASE: Source Code Management. Source Code Management  Also known as Configuration Management  Source Code Managers are tools that: –Archive.
Android Tutorial Android Written in Java Utilizes Dalvik VM – Just in time (JIT) compilation since Android 2.2.
Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department.
ANDROID PROGRAMMING MODULE 1 – GETTING STARTED
UFCFX5-15-3Mobile Device Development Android Development Environments and Windows.
Emerging Platform#4: Android Bina Ramamurthy.  Android is an Operating system.  Android is an emerging platform for mobile devices.  Initially developed.
File System. NET+OS 6 File System Architecture Design Goals File System Layer Design Storage Services Layer Design RAM Services Layer Design Flash Services.
Data Storage: Part 1 (Preferences)
Introduction to The Linaro Toolchain Embedded Processors Training Multicore Software Applications Literature Number: SPRPXXX 1.
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
Android Introduction Platform Overview.
Intro to Android Programming George Nychis Srinivasan Seshan.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Hands-On Microsoft Windows Server 2008
Cosc 4/5730 Android and Blackberry Near Field Communications (NFC)
CS5103 Software Engineering Lecture 08 Android Development II.
Chapter 12: Finale! Publishing Your Android App. Objectives In this chapter, you learn to: Understand Google Play Target various device configurations.
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
Copyright© Jeffrey Jongko, Ateneo de Manila University Android.
ANDROID Presented By Mastan Vali.SK. © artesis 2008 | 2 1. Introduction 2. Platform 3. Software development 4. Advantages Main topics.
DUE Hello World on the Android Platform.
CS378 - Mobile Computing Persistence. Saving State We have already seen saving app state into a Bundle on orientation changes or when an app is killed.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Operating.
Presented By: Muhammad Tariq Software Engineer Android Training course.
Java Introduction to JNI Prepared by Humaira Siddiqui.
Nilesh Singh Local Data Storage option Android provides several options for you to save persistent application data. - Shared preferences - Creation.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
ADV. NETWORK SECURITY CODY WATSON What’s in Your Dongle and Bank Account? Mandatory and Discretionary Protections of External Resources.
CE Operating Systems Lecture 13 Linux/Unix interprocess communication.
SKYPIAX, how to add Skype capabilities to FreeSWITCH (and Asterisk) CHICAGO, USA, September 2009.
Nachos Overview Lecturer: Hao-Hua Chu TA: Chun-Po Wang (Artoo) Date: 2008/09/18 Material Provided by Yuan-Hao Chang, Yung-Feng Lu.
1 Android Introduction Platform Overview. 2 What is Android?  Android is a software stack for mobile devices that includes an operating system, middleware.
Ryan Rasmussen Maggie Krause Jiajun Yang. Hardware Progress Mechanical assembly complete Received APM case and power module last week Connected wi-fi.
ANDROID APPLICATION DEVELOPMENT. ANDROID DEVELOPMENT DEVELOPER.ANDROID.COM/INDEX.HTML THE OFFICIAL SITE FOR ANDROID DEVELOPERS. PROVIDES THE ANDROID SDK.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
TODAY Android Studio Installation Getting started Creating your 1 st App Beginning to understanding Intents.
VMM Based Rootkit Detection on Android
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
1 Android Workshop Platform Overview. 2 What is Android?  Android is a software stack for mobile devices that includes an operating system, middleware.
CHAPTER 9 File Storage Shared Preferences SQLite.
By: Eliav Menachi.  On Android, all application data (including files) are private to that application  Android provides a standard way for an application.
Android. Android An Open Handset Alliance Project A software platform and operating system for mobile devices Based on the Linux kernel Developed by Google.
The Basics of Android App Development Sankarshan Mridha Satadal Sengupta.
Mobile Device Development
Android Mobile Application Development
Containers as a Service with Docker to Extend an Open Platform
Data Virtualization Tutorial: Introduction to SQL Script
Obtaining the Required Tools
Android Studio, Android System Basics and Git
Android.
Chapter 2: System Structures
CMPE419 Mobile Application Development
Operation System Program 4
Application Development A Tutorial Driven Course
Android Platform, Android App Basic Components
Emerging Platform#3 Android & Programming an App
Mobile Programming Dr. Mohsin Ali Memon.
CMPE419 Mobile Application Development
In Today’s Class.. General Kernel Responsibilities Kernel Organization
Presentation transcript:

Advanced Android Programming George Nychis Srinivasan Seshan

A Recap of Last Lecture Use these lectures as a reference, in addition to documentation Last Lecture: A higher level overview and the basics Application and interface basics Application and hardware permissions (“Android Manifest”) How to multi-thread on Android (“AsyncTask”) How info is passed between threads, interface, HW (“Intents”)

Advanced Android Topics The first mile on Android: relatively straight forward Should already know Java GUI is roughly drag and drop Lots of documentation and examples online… Let’s get a little more advanced… Debugging on an Android device Persistent application storage (Preferences, Database) Writing and linking non-Java code (e.g., C and C++) Cross-compiling useful libraries to Android Modifying the kernel (e.g., to add support, remove permissions) NFC support

Some More Advanced Layouts As mentioned, we have a research project on Android which uses a lot of advanced features and different layouts Good examples of how to embed layouts within each other… These layouts are available in our project:

Root: What do you need it for? Like “jailbreaking” -- a term most are familiar with Think of it as: it literally just gives you Linux root access What don’t you need it for? Writing a standard application that uses standard APIs and HW Writing native code that does not touch some aspects of F.S. What do you need it for? Modifying and replacing the kernel E.g., to remove permission checks, modify TCP, modify WiFi stack… Loading and/or removing new kernel modules Modifying anything in /system or snooping around /data Modifying the Android OS or APIs Changing the ROM on the device (new OS + kernel)

Debugging As usual, two ways to have debug information: 1.Android has a logging utility to print information to 2.Full debugger through ADB and Eclipse Logging utility: good for printing periodic status of application and/or certain variables Debugger: great for stepping through code, able to: Set breakpoints and conditions Check the values of any variable TagMessage

Debugging Example Live demo…

Persistent Storage You are likely going to want to persistently store data In Android, there are 5 main ways to store data: 1.Shared Preferences – private key-value pair storage 2.Internal Storage – private storage per-application 3.External Storage – local shared storage (e.g., on SD card) 4.SQLite Database – private structured data 5.Network Storage – store data on your own server You should be able to make a decision on which solution is best for various data in your application Use multiple storage options!

Shared Preferences Overview Good for basic data storage, simple examples: Has the user completed the application settings? (boolean) What is the user’s username? (string) Shared Preferences accessed by string key, value can be: boolean, float, int, long, string Arbitrary objects cannot be stored in Shared Preferences, best two options for arbitrary objects: Marshal to/from a private database (best) Marshal to/from binary files in private storage

Shared Preferences Example Name preference file (does not need to be globally unique) Get a handle to your preferences: Can read in values by key, specify value if does not exist Writing needs specific handle, and need to commit all changes Do not forget

SQLite Database Should hopefully know the basics of databases Best to store your main data/objects Marshal your classes to and from a row in a database Android provides some useful helper classes SQLiteDatabase, Cursor, ContentValues…. Ultimately, I want to push you in the right direction, but you should be able to find the details… Good example: sqlite-database-tutorial/

Writing Native Code (JNI) JNI: framework that allows Java code to call, or be called by, native applications/libraries in other languages E.g., Java code can call a function written in C++, and visa-versa Easiest way to integrate pre-existing code and libraries in other languages (e.g., a pre-existing C encryption library) Good to implement certain functionality which can be written more optimally in C, for example Native code still runs within the application’s VM Follows AndroidManifest (e.g., need “INTERNET” for sockets) Android NDK: Toolset integrate/compile JNI in to Android app

The Structure of Native Code Directory structure: native code fits in “jni” directory ndk-build uses Android.mk in each native directory

Top-Level Android.mk Best way to make top-level Android.mk: You can cross-reference in-between libraries E.g., stringlib can use a function found in mathlib, the stringlib Android.mk file just needs to specify it links mathlib List each subdirectory for ndk-build to enter and build individually.

Individual Library Android.mk Each library needs its own Android.mk, with: Local source files, linker/compiler flags, output (e.g., shared lib) Something a little more advanced, for example: Creates lib_____.so (i.e., libawmon.so)

Simple Native C Code Example Need to include JNI environment header, logging also useful Native function is passed … Java environment: often used to allocate new Java objects Java class object: Your Parameters: any C/C++ primitives __android_log_print(ANDROID_LOG_INFO, “NativeMath”, ”Error: %d”, eval); Must match your package name (case sensitive) Must match the class accessing and calling the native code (case sensitive)

Building NDK Code Make sure ndk-build is in your PATH env. Variable Standard Android documentation should get you this far… From the base of your application directory (outside jni dir): All of your built libraries are copied to libs/armeabi/

The Eclipse Gotcha YOU MUST REFRESH YOUR DIRECTORY IN ECLIPSE!! Eclipse does not look for changes, even if you were to rebuild app You must refresh every time you run ndk-build otherwise your changes will not be included Maybe something built in to Eclipse now?

Accessing Native Code in Java Must load each native library: e.g., Can be done in any class or thread It is a blocking call, to keep in mind if loading large libraries… Must create native function prototypes in respective classes: Once done, you can access these functions directly:

Using External Libraries “I need a library to help me with _____, but it is a standard C or Linux implementation” (e.g., crypto library) Proceed in this order: 1.Google “____ Android” – many libraries already cross-compiled 2.Write custom Android.mk to cross-compile it You will be surprised how many libraries you find cross- compiled, and even if an older version: use their Android.mk

Cross-Compiling Libraries For many libraries, look at the Makefile and see which source files it uses to build the library Add these sources to Android.mk “LOCAL_SRC_FILES” Use similar CFLAGS, LDFLAGS Common for libraries to link to pthread, remove –lpthread but keep most pthread code. Custom pthread force linked Look at the many examples online, including our own: libpcap, libnl, libgcrpyt, libglib, libgpg, libusb ….

Modifying the Kernel Several key steps to modifying the kernel… 1.Obtaining the proper source code for HW + OS version If you get the wrong kernel: phone will not boot (I’ll help you…) 2.Modifying the kernel (we’ll give you some pointers…) 3.Cross-compiling the kernel using the NDK 4.Installing the kernel (BE CAREFUL: CAN BRICK PHONE) Best to use something called “AnyKernel” package This needs to be done in Linux (e.g., in a Virtual Machine)

Obtaining Kernel Source Code The two possible phones you are using for this class: Galaxy Nexus: code name “maguro” (“tuna” for kernel) Galaxy S: code name “crespo” Best to start at this link: Kernel source code depends on the HW, for you: Galaxy Nexus: Nexus S: In “About Phone” you can find your git kernel commit: g (i.e., d5a18e0)d5a18e0 … make sure to drop the g that is prepended to the hash

Building the Kernel Build using cross-compiler provided by Google: Setup your environment: Checkout your kernel version: git checkout Setup with the proper configuration Galaxy Nexus: make tuna_defconfig Nexus S: make crespo_defconfig Finally, you can build with: make

Packaging the Kernel – Pt1 Need to create a ramdisk with the the proper init scripts Can be extracted from the device, but we will provide you with it Can be extracted from the device See example… Modifications to ramdisk are needed if you want to: Load kernel modules on boot Set permissions to certain devices/files on boot Change the order services are initialized

Packaging the Kernel – Pt2 This is very tricky, and must be done properly or you will “brick” the phone, i.e., it will not boot and must be repaired Install without building the entire OS by creating “update” ZIP Runs a script to mount FS and extract kernel & modules Usually includes system directory which is extracted What the updater script looks like for Galaxy Nexus:

Packaging the Kernel – Pt3 Example hierarchy of the update ZIP Boot image with kernel at root These are standard Specific to device, updater script MUST put all kernel modules in here that were rebuilt with kernel

Installing the Kernel Need to use “recovery” mode on the phone to install Dedicated, bootable partition with recovery console Put your updater zip on your SD card, then: Use recovery to install the ZIP

Kernel Pointers Based on the project page, some kernel locations you might be interested in…. WiFi Driver: drivers/net/wireless/bcmdhd TCP Protocol / Sockets: net/ipv4 include/net Permissions (e.g., sockets): kernel/capability.c

Near Field Communication Low rate short distance wireless communication Approx. 10 centimeters supported 424 kbit/s across 13.56MHz Current applications: payments, smart posters, check-ins… Two major NFC modes: Reader / Writer mode Peer-to-Peer mode (emulate tags on Android) Nexus S was first phone to really “mainstream” NFC

NDEF (NFC Data Exchange Format) Standard data format created by NFC Forum NDEF Messages: basic transportation mechanism Can contain one or more NDEF Records NDEF Record: contain specific structure with payload TNF contains the record type (e.g., URI)

Tag Read / Write Example Start with basic tag read and write example Includes P2P mode ability This was an example posted by Google that we modified to make a little more intuitive Sample code was posted for you:

The Basic NFC Permissions As usual, you need to have Android permissions Important to specify minimum SDK Ensure that the phone has NFC support

Receiving NFC Tag Information Remember, all information in Android is broadcast For NFC, you register to receive TAG read broadcasts:

Registering for NFC Data Specify that the Activity should receive NFC Intents: Can specify which data types the application should receive: Need a handle to the “NFC Adapter” (i.e., hardware) Apply and enable the filter in onResume()

Receiving the NFC Data – Pt1 Receive callbacks in “onNewIntent()” you override:

Receiving the NFC Data – Pt2 NDEF Messages come in as an array Then, you can go through the msgs array and get the payload:

Detecting Nearby Tag to Write Just like you registered to receive NFC tag data, you register to know when a tag is simply detected and then use it to trigger a write to it: When the user specifies to write, you enable this filter and use a software flag to know that you should write when the tag is detected nearby:

Writing to a Nearby Tag Once you detect a tag is nearby, you should ensure: 1.The tag is not read-only 2.The tag’s capacity is sufficient See the following code to perform those checks and actually write the message:following code

Wrap-up Over time, I will fill in this wiki: Expect to find there (in the next 2 weeks): Links to your kernel sources Links to your ramdisks for each of the phones Scripts to help you build and package the kernels If you want to root your phone… Ask for permission (it voids the warranty), and come to us We will root it for you