View - Launchpad Developer Community

advertisement
APPFORUM2014
Helping the developer community build
next-generation, multi-platform apps.
SCHAUMBURG, ILLINOIS | SEPTEMBER 8-10
Android Bootcamp
Ritesh Gupta Ι Sr. Manager – WW Technical Operations
APPFORUM2014
Android Bootcamp Agenda
Welcome to Appforum 2014
• Android Overview & Architecture
• ADB – Getting connected
• Android Application basics
• Build an simple android application
Android Overview
Show of Hands
How many people know what Android is?
How many are Windows developers?
Do you have the Android SDK Installed?
Android overview
What is Android?
A software platform and OS for
mobile devices
• Based on the Linux kernel, but most
things around the kernel are developed
anew
• Developed by initially by Android Inc,
acquired by Google in 2005
• Supports writing managed code in Java
• Source available via AOSP project
(Android Open Source Project)
Android overview
Development options
Android Java (Google SDK + Motorola EMDK)




Most Android apps (and some system services) are written this way
Easy to manage
Not Sun/Oracle Java (discussed in detail later)
Google SDK and other dev tools downloadable on
http://developer.android.com for free
 Motorola EMDK available on support website for free
Android Native SDK (Google NDK)
 Write some code in C/C++ (high-performance routines).
 Cannot write the whole app in C++, still must build a Java app.
 Different APIs, high complexity, less portable
RhoMobile (Motorola)
 Use web technologies to build cross-platform applications
 Packaged as standard Android app when deployed to the device
Android OS Architecture Requirements
Design constraints for Android
Platform
• Constrained processing power, memory,
storage and battery life
• Variety of device form factors and
capabilities (screen size, keyboard,
wireless interfaces)
Results
• Minimalistic OS kernel
• Minimizing memory use through sharing,
etc
• Sleep whenever possible
• Application runtime must be abstracted
from the OS and hardware platform
• Variety of target CPUs (variations of ARM,
x86, etc)
• Application runtime must be sandboxed to
minimize malware impact
• Non tech-savvy users
• Apple / MS are already ahead in the game
• Reuse standard components as much as
possible
• Provide ‘bare’ OS core and have app
developers create lots of portable apps
Android OS Architecture
Resulting choices
Modified Linux 3.x Kernel

Lightweight build, variety of CPU architectures and hardware supported, proven tech, lots of security options

Tweaks and modifications to support advanced memory/power/etc management for resource-constrained
devices
Java for applications

Proven technology popular among developers - Enterprise (JSP, etc), mobile (J2ME, etc) and many others

Runs in JavaVM = OS/hw independent = supports diverse set of devices - Missing HW features can be
virtualized or replaced with stubs

But – greater CPU/RAM requirements - Custom Java libraries using open source and in-house developed
components to address this
Dalvik Java VM

A custom Java VM optimized for mobile devices - Memory sharing, extra security and sandboxing, quick
startup, etc

Provide tools to build Dalvik Java apps from ‘standard’ Java source code
Android OS Architecture
Resulting System Architecture Diagram
Android OS Architecture
Libraries and Versioning
Every OS Version has an API Level.
 Even minor versions may have a
different API Level
App developer targets application
for a minimum API level
 Because apps are targeted for a
minimum API level, most older Android
apps will work just fine on new Android
releases.
 Does not apply to low-level system
apps and hacks
Accessing Android Devices
Android SDK for non-developers
Contains useful tools and drivers
– Enable device troubleshooting and lowlevel management (ADB, DDMS, etc)
– USB drivers
Non-developer SDK install
– http://developer.android.com/sdk/
– Select “Download for other platforms” > “SDK Tools Only”
•
•
Choose bundle for your platform. EXE
for simple install, ZIP for custom
Install to a path with NO SPACES
– Run SDK Manager and install only
•
•
Android SDK Tools and PlatformTools
Add the <SDK>\tools and
<SDK>\platform-tools to system PATH
– Install Motorola Android USB Driver
•
Support Central
– Validate with ‘adb devices’
•
More on ADB later
ADB – Getting
Connected
Agenda
•Get Connected
• Pass around jump drive – copy to desktop folder
• Do the ADB Super-Fast Installation
• Talk about USB connection modes
•ADB Usage Modes (command line, gui)
•What you can do with ADB and scripts
(and what you CAN’T do, and why – actually SEE how file
permissions control your access)
•Summary of Online Resources
ADB Super-Fast Installation
When you install the Android SDK, ADB is installed as
part of that process
– Gives both visual and command line access
– But it takes how long ?!?
If you search “15 second ADB install” you will find a
windows install for ADB and Fastboot
– Yes it’s about that fist
– Quick and easy
You can also do a “super-fast install” by dropping just a
few files into your PC
– Gives command line access
– Really quick and easy
Setup Directions
From the memory stick being handed around..
Copy the folder “ADB” to your desktop
Look in the folder, find and install the MSI Android USB
drivers
Connect your device with a USB cable
Go to Settings…Developer Options..
– enable Developer Options (slide ON)
– check USB Debugging and Stay Awake
Run “adb devices” to check connection
USB Connection Modes
USB Mass Storage – direct connection to PC
– Raw, not sharable, access only to sdcards
– Complete control - can format, FATonly
– Seems to be downplayed as of JellyBean
PTP, MTP – managed connection to PC
– Picture Transfer Protocol – for camera (pics)
Media Transfer Protocol – all kinds of files
– File managed, sharable, access only to sdcards
– Limited control – read, write files and folder
How ADB Connection Differs
ADB allows much greater access to files
– File access not limited to sdcards
– Access from “/” limited only by file permissions
• /data/tmp, sdcards, /enterprise/usr, …
ADB allows interactive running of commands on device
ADB also has higher-level functions for support of
development/debugging/screen sharing
USB Connection Modes
Android
PC
storage volumes
/
|-/etc
|-/data
|-/enterprise
|-/sdcard
|-/system
|-/storage
| |-/sdcard
| …
File Transfer
mass storage switch
OFF
ON
ATAPI
SD card
U
S
B
USBScan
File system access
USBStor
Raw device access
USB Connection Modes
Android
Debug Agent
PC
storage volumes
ADB
/
|-/etc
|-/data
|-/enterprise
|-/sdcard
|-/system
|-/storage
| |-/sdcard
| …
File Transfer
mass storage switch
OFF
ON
ATAPI
SD card
U
S
B
cmd or
shell
USBScan
File system access
USBStor
Raw device access
ADB Connection Test
ADB Installation needs to be finished by this time
– Folder with ADB
– Installation of latest Drivers
Run “adb devices”
– Be sure you have a connection
– Check USB mode
All good – ready to proceed?
Why Study ADB?
Easiest way to get familiar with basics of how
device is set up and some basics about file
security.
Can be used as tool to deploy apps and settings.
Great tool for TESTing what you are about to
deploy, even if you will be using an MDM
This is as close as we are going to get to the
feeling we had on MW/CE that we could use
ActiveSync connection to run RAPI installs or to
“drop in” files to achieve unit configuration.
ADB capabilities to cover..
Shell or remote execution
File/folder transfer.. push/pull/sync
Package install/update/uninstall
Package run/run with parms/stop
Use with multiple devices, use over WiFi
Use to find out things..
– Explore filesystem and permissions problems
– adb shell getprop | find “MX”
– adb pm list .. packsges, permissions, features
ADB Capabilities - Backup
Rumored to be able to
“clone” setup..
– It cannot (at least in JB)
– It’s a darn GOOD thing that it
cannot.. Why?
– Expect future versions of the
OS to further restrict what can
be exported from a device.
Way too slow for use in
actual deployments
How Easy it Used to Be
In Windows CE, you could could..
– set up a folder on our desktop, with all the
files arranged just as we wanted them on the
mobile,
– Connect USB via ActiveSync, open the AS
file browser window
– then drag and drop the \application folder as
a single item..
– It copied all the files..
Then cold boot to test your setup.
- you could deploy devices the same way
- Or build a custom image from the folder
How easy it can be now..
Now with ADB, you can
– make a folder on your desktop, with all the files
arranged just as we want them on the mobile
– and arrange all the files as I want them to be
– Connect USB via and configure ADB Debug
– then run a script that
• Uses “adb push” the folder as a single item..
• Installs and runs some APKs
Script can end with a command to run ER
– tests persistence
– disables USB Debug
– When setup tests OK, SAME procedure deploys units
File Management & ADB
Using ADB shell:
– df, mount
– cd, pwd, ls, ls -la, mkdir, cp, etc…
– Piping ‘|’ and redirecting to a file ‘>’
• Including external launches
• adb shell “cd /system/bin; ls” > commandList.txt
• adb shell “cd /system/bin; ls –l | find “toolbox” > toolbox.txt
• grep, more, busybox
– Understanding permissions (rwxd, user/group/all)
– Understanding storage modes
• When USB Storage mode is available
– Check Linux kernel version (cat /proc/version)
ADB push/pull file to/from SD Card
ADB Scripting
Even COMPLEX tasks can be made simple, reliable and
fast..
– Though you still have to enable USB Debug
– And remember to disable it when you’re done
– And prevent users from re-enabling it
Combine that with the “quick install” and..
– You can send quick install and some scripts to a partner, and he can be
staging units without an MDM this afternoon.
Remember - ADB is Dangerous
Imagine that you deploy devices, containing..
– Corporate owned applications
– Corporate data
– Corporate WLAN settings
Now imagine someone takes a device home and connects
ADB…
– Hey, it’s just a portable device,
what could possibly go wrong?
(and if it does -- who will get blamed?)
Rule: Never deploy with ADB enabled.
Ideal: Never allow users to enable ADB.
Android Application
Fundamentals
Download