Showing posts with label Android Developer. Show all posts
Showing posts with label Android Developer. Show all posts

Tuesday, August 16, 2016

New features for reviews and experiments in Google Play Developer Console app



With over one million apps published through the Google Play Developer Console,
we know how important it is to publish with confidence, acquire users, learn
about them, and manage your business. Whether reacting to a critical performance
issue or responding to a negative review, checking on your apps when and where
you need to is invaluable.


The href="https://play.google.com/store/apps/details?id=com.google.android.apps.playconsole&hl=en">Google
Play Developer Console app
, launched in May, has already helped thousands of
developers stay informed of crucial business updates on the go.


We’re excited to tell you about new features, available today:


Receive notifications about new reviews





Use filters to find the reviews you want





Review and apply store listing experiment results





Increase the percent of a staged rollout or halt a bad staged
rollout






Download the href="https://play.google.com/store/apps/details?id=com.google.android.apps.playconsole">Developer
Console app on Google Play
and stay on top of your apps and games, wherever
you are! Also, get the Playbook for Developers app to stay up-to-date with more features and best practices that will help you grow a successful business on Google Play.

Wednesday, July 20, 2016

Strictly Enforced Verified Boot with Error Correction


Posted by Sami Tolvanen, Software Engineer


Overview



Android uses multiple layers of protection to keep users safe. One of these
layers is verified
boot, which improves security by using cryptographic integrity checking to
detect changes to the operating system. Android has href="https://g.co/ABH">alerted about system integrity since Marshmallow,
but starting with devices first shipping with Android 7.0, we require verified
boot to be strictly enforcing. This means that a device with a corrupt boot
image or verified partition will not boot or will boot in a limited capacity
with user consent. Such strict checking, though, means that non-malicious data
corruption, which previously would be less visible, could now start affecting
process functionality more.


By default, Android verifies large partitions using the dm-verity kernel driver,
which divides the partition into 4 KiB blocks and verifies each block when read,
against a signed hash tree. A detected single byte corruption will therefore
result in an entire block becoming inaccessible when dm-verity is in enforcing
mode, leading to the kernel returning EIO errors to userspace on verified
partition data access.


This post describes our work in improving dm-verity robustness by introducing
forward error correction (FEC), and explains how this allowed us to make the
operating system more resistant to data corruption. These improvements are
available to any device running Android 7.0 and this post reflects the default
implementation in AOSP that we ship on our Nexus devices.

Error-correcting codes



Using forward error correction, we can detect and correct errors in source data
by shipping redundant encoding data generated using an error-correcting code.
The exact number of errors that can be corrected depends on the code used and
the amount of space allocated for the encoding data.


href="https://en.wikipedia.org/wiki/Reed%E2%80%93Solomon_error_correction">Reed-Solomon
is one of the most commonly used error-correcting code families, and is readily
available in the Linux kernel, which makes it an obvious candidate for
dm-verity. These codes can correct up to ⌊t/2⌋ unknown errors and up to
t known errors, also called href="https://en.wikipedia.org/wiki/Erasure_code">erasures, when t
encoding symbols are added.


A typical RS(255, 223) code that generates 32 bytes of encoding data for every
223 bytes of source data can correct up to 16 unknown errors in each 255 byte
block. However, using this code results in ~15% space overhead, which is
unacceptable for mobile devices with limited storage. We can decrease the space
overhead by sacrificing error correction capabilities. An RS(255, 253) code can
correct only one unknown error, but also has an overhead of only 0.8%.



An additional complication is that block-based storage corruption often occurs
for an entire block and sometimes spans multiple consecutive blocks. Because
Reed-Solomon is only able to recover from a limited number of corrupted bytes
within relatively short encoded blocks, a naive implementation is not going to
be very effective without a huge space overhead.

Recovering from consecutive corrupted blocks



In the changes we made to href="https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=a739ff3f543afbb4a041c16cd0182c8e8d366e70">dm-verity
for Android 7.0, we used a technique called interleaving to allow us to recover
not only from a loss of an entire 4 KiB source block, but several consecutive
blocks, while significantly reducing the space overhead required to achieve
usable error correction capabilities compared to the naive implementation.


Efficient interleaving means mapping each byte in a block to a separate
Reed-Solomon code, with each code covering N bytes across the corresponding N
source blocks. A trivial interleaving where each code covers a consecutive
sequence of N blocks already makes it possible for us to recover from the
corruption of up to (255 - N) / 2 blocks, which for RS(255, 223) would
mean 64 KiB, for example.


An even better solution is to maximize the distance between the bytes covered by
the same code by spreading each code over the entire partition, thereby
increasing the maximum number of consecutive corrupted blocks an RS(255, N) code
can handle on a partition consisting of T blocks to ⌈T/N⌉ × (255 -
N) / 2
.




Interleaving with distance D and block size B.


An additional benefit of interleaving, when combined with the integrity
verification already performed by dm-verity, is that we can tell exactly where
the errors are in each code. Because each byte of the code covers a different
source block—and we can verify the integrity of each block using the existing
dm-verity metadata—we know which of the bytes contain errors. Being able to
pinpoint erasure locations allows us to effectively double our error correction
performance to at most ⌈T/N⌉ × (255 - N) consecutive blocks.


For a ~2 GiB partition with 524256 4 KiB blocks and RS(255, 253), the maximum
distance between the bytes of a single code is 2073 blocks. Because each code
can recover from two erasures, using this method of interleaving allows us to
recover from up to 4146 consecutive corrupted blocks (~16 MiB). Of course, if
the encoding data itself gets corrupted or we lose more than two of the blocks
covered by any single code, we cannot recover anymore.


While making error correction feasible for block-based storage, interleaving
does have the side effect of making decoding slower, because instead of reading
a single block, we need to read multiple blocks spread across the partition to
recover from an error. Fortunately, this is not a huge issue when combined with
dm-verity and solid-state storage as we only need to resort to decoding if a
block is actually corrupted, which still is rather rare, and random access reads
are relatively fast even if we have to correct errors.

Conclusion



Strictly enforced verified boot improves security, but can also reduce
reliability by increasing the impact of disk corruption that may occur on
devices due to software bugs or hardware issues.


The new error correction feature we developed for dm-verity makes it possible
for devices to recover from the loss of up to 16-24 MiB of consecutive blocks
anywhere on a typical 2-3 GiB system partition with only 0.8% space overhead and
no performance impact unless corruption is detected. This improves the security
and reliability of devices running Android 7.0.

Friday, July 1, 2016

Building for Billions

Posted by Sam Dutton, Ankur Kotwal, Developer Advocates; Liz Yepsen, Program Manager






‘TOP-UP WARNING.’ ‘NO CONNECTION.’ ‘INSUFFICIENT BANDWIDTH TO PLAY THIS
RESOURCE.’



These are common warnings for many smartphone users around the world.



To build products that work for billions of users, developers must address key
challenges: limited or intermittent connectivity, device compatibility, varying
screen sizes, high data costs, short-lived batteries. We first presented href="https://developers.google.com/billions/?utm_campaign=android_discussion_billions_063016&utm_source=anddev&utm_medium=blog">developers.google.com/billions
and related Android and Web resources at Google I/O last month, and today you
can watch the video presentations about href="https://www.youtube.com/watch?v=vaEV8bNi1Dw">Android or the href="https://www.youtube.com/watch?v=E6hGubMkNfM">Web.



These best practices can help developers reach billions by delivering
exceptional performance across a range of connections, data plans, and devices.
g.co/dev/billions will
help you:



Seamlessly transition between slow, intermediate, and offline
environments



Your users move from place to place, from speedy wireless to patchy or expensive
data. Manage these transitions by storing data, queueing requests, optimizing
image handling, and performing core functions entirely offline.



Provide the right content for the right context



Keep context in mind - how and where do your users consume your content?
Selecting text and media that works well across different viewport sizes,
keeping text short (for scrolling on the go), providing a simple UI that doesn’t
distract from content, and removing redundant content can all increase
perception of your app’s quality while giving real performance gains
like reduced data transfer. Once these practices are in place, localization
options can grow audience reach and increase engagement.



Optimize for mobile hardware



Ensure your app or Web content is served and runs well for your widest possible
addressable market, covering all actively used OS versions, while still
following best practices, by testing on virtual or actual devices in target
markets. Native Android apps should set minimum and target SDKs. Also, remember
low cost phones have smaller amounts of RAM; apps should therefore adjust usage
accordingly and minimize background running. For in-depth information on
minimizing APK size, check out this href="https://medium.com/@wkalicinski/smallerapk-part-8-native-libraries-open-from-apk-fc22713861ff">series
of Medium posts. On the Web, optimize JavaScript CPU usage, avoid raster
image rendering, and minimize resource requests. Find out more href="https://developers.google.com/web/fundamentals/performance/?utm_campaign=android_discussion_billions_063016&utm_source=anddev&utm_medium=blog">here.



Reduce battery consumption



Low cost phones usually have shorter battery life. Users are sensitive to
battery consumption levels and excessive consumption can lead to a high
uninstall rate or avoidance of your site. Benchmark your battery usage against
sessions on other pages or apps, or using tools such as Battery Historian, and
avoid long-running processes which drain batteries.



Conserve data usage



Whatever you’re building, conserve data usage in three simple steps: understand
loading requirements, reduce the amount of data required for interaction, and
streamline navigation so users get what they want quickly. Conserving data on
behalf of your users (and with native apps, offering configurable network usage)
helps retain data-sensitive users -- especially those on prepaid plans or
contracts with limited data -- as even “unlimited” plans can become expensive
when roaming or if unexpected fees are applied.



Have another insight, or a success launching in low-connectivity conditions or
on low-cost devices? Let us know on our href="https://plus.sandbox.google.com/+GoogleDevelopers/posts/WffV23WSrc8">G+
post.

Tuesday, June 28, 2016

Android changes for NDK developers

Android changes for NDK developers

Posted by Dmitry Malykhanov, Developer Advocate




Related to other improvements to the Android platform, the dynamic linker in
Android M and N has stricter requirements for writing clean, cross-platform
compatible native code in order to load. It is necessary that an application’s
native code follows the rules and recommendations in order to ensure a smooth
transition to recent Android releases.



Below we outline in detail each individual change related to native code
loading, the consequences and steps you can take to avoid issues.



Required tools: there is an <arch>-linux-android-readelf binary (e.g.
arm-linux-androideabi-readelf or i686-linux-android-readelf) for each
architecture in the NDK (under toolchains/), but you can use readelf for any
architecture, as we will be doing basic inspection only. On Linux you need to
have the “binutils” package installed for readelf, and “pax-utils” for scanelf.


Private API (Enforced since API 24)



Native libraries must use only href="http://developer.android.com/ndk/guides/stable_apis.html?utm_campaign=android_discussion_ndkchanges_062716&utm_source=anddev&utm_medium=blog">public API,
and must not link against non-NDK platform libraries. Starting with API 24 this
rule is enforced and applications are no longer able to load non-NDK platform
libraries. The rule is enforced by the dynamic linker, so non-public libraries
are not accessible regardless of the way code tries to load them:
System.loadLibrary(...), DT_NEEDED entries, and direct calls to dlopen(...) will
fail in exactly the same way.



Users should have a consistent app experience across updates, and developers
shouldn’t have to make emergency app updates to handle platform changes. For
that reason, we recommend against using private C/C++ symbols. Private symbols
aren’t tested as part of the Compatibility Test Suite (CTS) that all Android
devices must pass. They may not exist, or they may behave differently. This
makes apps that use them more likely to fail on specific devices, or on future
releases --- as many developers found when Android 6.0 Marshmallow switched from
OpenSSL to BoringSSL.



In order to reduce the user impact of this transition, we’ve identified a set of
libraries that see significant use from Google Play’s most-installed apps, and
that are feasible for us to support in the short term (including
libandroid_runtime.so, libcutils.so, libcrypto.so, and libssl.so). In order to
give you more time to transition, we will temporarily support these libraries;
so if you see a warning that means your code will not work in a future release
-- please fix it now!



$ readelf --dynamic libBroken.so | grep NEEDED
0x00000001 (NEEDED) Shared library: [libnativehelper.so]
0x00000001 (NEEDED) Shared library: [libutils.so]
0x00000001 (NEEDED) Shared library: [libstagefright_foundation.so]
0x00000001 (NEEDED) Shared library: [libmedia_jni.so]
0x00000001 (NEEDED) Shared library: [liblog.so]
0x00000001 (NEEDED) Shared library: [libdl.so]
0x00000001 (NEEDED) Shared library: [libz.so]
0x00000001 (NEEDED) Shared library: [libstdc++.so]
0x00000001 (NEEDED) Shared library: [libm.so]
0x00000001 (NEEDED) Shared library: [libc.so]


Potential problems: starting from API 24 the dynamic linker will not load
private libraries, preventing the application from loading.



Resolution: rewrite your native code to rely only on public API. As a short term
workaround, platform libraries without complex dependencies (libcutils.so) can
be copied to the project. As a long term solution the relevant code must be
copied to the project tree. SSL/Media/JNI internal/binder APIs should not be
accessed from the native code. When necessary, native code should call
appropriate public Java API methods.



A complete list of public libraries is available within the NDK, under
platforms/android-API/usr/lib.


Note: SSL/crypto is a special case, applications must NOT use platform libcrypto
and libssl libraries directly, even on older platforms. All applications should
use href="http://developer.android.com/training/articles/security-gms-provider.html?utm_campaign=android_discussion_ndkchanges_062716&utm_source=anddev&utm_medium=blog">GMS
Security Provider to ensure they are protected from known vulnerabilities.


Missing Section Headers (Enforced since API 24)



Each ELF file has additional information contained in the section headers. These
headers must be present now, because the dynamic linker uses them for sanity
checking. Some developers try to strip them in an attempt to obfuscate the
binary and prevent reverse engineering. (This doesn’t really help because it is
possible to reconstruct the stripped information using widely-available tools.)



$ readelf --header libBroken.so | grep 'section headers'
Start of section headers: 0 (bytes into file)
Size of section headers: 0 (bytes)
Number of section headers: 0
$


Resolution: remove the extra steps from your build that strip section headers.


Text Relocations (Enforced since API 23)



Starting with API 23, shared objects must not contain text relocations. That is,
the code must be loaded as is and must not be modified. Such an approach reduces
load time and improves security.



The usual reason for text relocations is non-position independent hand-written
assembler. This is not common. Use the href="https://wiki.gentoo.org/wiki/Hardened/Textrels_Guide#Finding_broken_object_code">scanelf
tool as described in href="http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html?utm_campaign=android_discussion_ndkchanges_062716&utm_source=anddev&utm_medium=blog#behavior-runtime">our
documentation for further diagnostics:



$ scanelf -qT libTextRel.so
libTextRel.so: (memory/data?) [0x15E0E2] in (optimized out: previous simd_broken_op1) [0x15E0E0]
libTextRel.so: (memory/data?) [0x15E3B2] in (optimized out: previous simd_broken_op2) [0x15E3B0]
[skipped the rest]


If you have no scanelf tool available, it is possible to do a basic check with
readelf instead, look for either a TEXTREL entry or the TEXTREL flag. Either
alone is sufficient. (The value corresponding to the TEXTREL entry is irrelevant
and typically 0 --- simply the presence of the TEXTREL entry declares that the
.so contains text relocations). This example has both indicators present:



$ readelf --dynamic libTextRel.so | grep TEXTREL
0x00000016 (TEXTREL) 0x0
0x0000001e (FLAGS) SYMBOLIC TEXTREL BIND_NOW
$


Note: it is technically possible to have a shared object with the TEXTREL
entry/flag but without any actual text relocations. This doesn’t happen with the
NDK, but if you’re generating ELF files yourself make sure you’re not generating
ELF files that claim to have text relocations, because the Android dynamic
linker trusts the entry/flag.



Potential problems: Relocations enforce code pages being writable, and
wastefully increase the number of dirty pages in memory. The dynamic linker has
issued warnings about text relocations since Android K (API 19), but on API 23
and above it refuses to load code with text relocations.



Resolution: rewrite assembler to be position independent to ensure no text
relocations are necessary. Check the href="https://wiki.gentoo.org/wiki/Hardened/Textrels_Guide">Gentoo
documentation for cookbook recipes.


Invalid DT_NEEDED Entries (Enforced since API 23)



While library dependencies (DT_NEEDED entries in the ELF headers) can be
absolute paths, that doesn’t make sense on Android because you have no control
over where your library will be installed by the system. A DT_NEEDED entry
should be the same as the needed library’s SONAME, leaving the business of
finding the library at runtime to the dynamic linker.



Before API 23, Android’s dynamic linker ignored the full path, and used only the
basename (the part after the last ‘/’) when looking up the required libraries.
Since API 23 the runtime linker will honor the DT_NEEDED exactly and so it won’t
be able to load the library if it is not present in that exact location on the
device.



Even worse, some build systems have bugs that cause them to insert DT_NEEDED
entries that point to a file on the build host, something that
cannot be found on the device.



$ readelf --dynamic libSample.so | grep NEEDED
0x00000001 (NEEDED) Shared library: [libm.so]
0x00000001 (NEEDED) Shared library: [libc.so]
0x00000001 (NEEDED) Shared library: [libdl.so]
0x00000001 (NEEDED) Shared library:
[C:\Users\build\Android\ci\jni\libBroken.so]
$


Potential problems: before API 23 the DT_NEEDED entry’s basename was used, but
starting from API 23 the Android runtime will try to load the library using the path
specified, and that path won’t exist on the device. There are broken third-party
toolchains/build systems that use a path on a build host instead of the SONAME.



Resolution: make sure all required libraries are referenced by SONAME only. It
is better to let the runtime linker to find and load those libraries as the
location may change from device to device.


Missing SONAME (Used since API 23)



Each ELF shared object (“native library”) must have a SONAME (Shared Object
Name) attribute. The NDK toolchain adds this attribute by default, so its
absence indicates either a misconfigured alternative toolchain or a
misconfiguration in your build system. A missing SONAME may lead to runtime
issues such as the wrong library being loaded: the filename is used instead when
this attribute is missing.



$ readelf --dynamic libWithSoName.so | grep SONAME
0x0000000e (SONAME) Library soname: [libWithSoName.so]
$


Potential problems: namespace conflicts may lead to the wrong library being
loaded at runtime, which leads to crashes when required symbols are not found,
or you try to use an ABI-incompatible library that isn’t the library you were
expecting.



Resolution: the current NDK generates the correct SONAME by default. Ensure
you’re using the current NDK and that you haven’t configured your build system
to generate incorrect SONAME entries (using the -soname linker
option).



Please remember, clean, cross-platform code built with a current NDK should have
no issues on Android N. We encourage you to revise your native code build so
that it produces correct binaries.

Android Mobile Vision restores operation and adds Text API

Posted by Michael Sipe, Product Manager






As an important framework for finding objects in photos and video, Mobile Vision
operation for Android devices is restored in Google Play Services v9.2.



This new version of Google Play Services fixes a download issue in Google Play
Services v.9.0 that caused a service outage. See href="https://developers.google.com/vision/release-notes">release notes for
details.



We’re also pleased to announce the Text API, a new component for Android Mobile
Vision.



The Text API’s optical character recognition technology reads Latin character
text (e.g. English, Spanish, German, French, etc.) in photos and returns the
text as well as the organizational structure (paragraphs, lines, words). Mobile
apps can now:


  • Organize photos that contain text
  • Automate tedious data entry for credit cards, receipts, and business cards
  • Translate documents (along with the href="https://cloud.google.com/translate/">Cloud Translate API)
  • Keep track of real objects, such as reading the numbers on subway trains
  • Provide accessibility features


If you want to get started quickly, you can try our href="http://g.co/codelabs/mobile-vision-ocr">codelab which will get Android
developers reading text with their apps in under an hour.



Like the Mobile Vision Face and Barcode components, the Text API runs on-device
and is suitable for real-time applications. For more information, check out the
Mobile Vision Developer
site
.

Create Intelligent, Context-Aware Apps with the Google Awareness APIs


Posted by Bhavik Singh, Product Manager



Last month at Google I/O 2016 we announced the new Google Awareness APIs,
enabling your apps to intelligently react to user context using snapshots and
fences with minimal impact on system resources.



Today we’re proud to announce that the Google Awareness API is available to all
developers through Google Play services.






Using 7 different types of context—including location, weather, user activity,
and nearby beacons—your app can better understand your users’ current
situations, and use this information to provide optimized and customized
experiences.



The Awareness API offers two ways to take advantage of context signals within
your app:


  • The Snapshot API lets your app easily request information
    about the user's current context. For example, "give me the user's current
    location and the current weather conditions".
  • The Fence API lets your app react to changes in user’s
    context - and when it matches a certain set of conditions. For example, "tell me
    whenever the user is walking and their headphones are plugged in". Similar to
    the Geofencing API, once an awareness fence is registered, it can send callbacks
    to your app even when it's not running.


As a single, simplified surface, the Awareness APIs combine optimally processed
context signals in new ways that were not previously possible, providing more
accurate and insightful context cues, while also managing system resources to
save battery and minimize bandwidth.



We’ve worked closely with some of our partners, who have already found amazing
ways to integrate context awareness into their apps:






href="https://play.google.com/store/apps/details?id=com.trulia.android&hl=en">Trulia,
an online residential real estate site, uses our Fence API to suggest
open houses. When the weather is perfect and the user is walking around near a
house they are interested in, Trulia sends a notification reminding them to stop
by. This sort of tailored notification can help users engage with open houses at
the perfect time for them.




href="https://play.google.com/store/apps/details?id=fm.superplayer.jukebot&hl=en">SuperPlayer
Music, on the other hand, uses our Snapshot API and Fence API to suggest the
perfect music to match your mood. Whether you’re just finishing up a run and
beginning to stretch, setting off on a long car ride, or just getting to the
gym, their assistant can understand your context and suggest the right playlist
for you.



With our initial set of signals and our awesome partners, we’re just getting
started with the Awareness APIs. Join us on a journey to build tailored
experiences within your apps, by getting started with the href="https://developers.google.com/awareness/?utm_campaign=android_launch_awarenessapi_062716&utm_source=anddev&utm_medium=blog">Google Awareness API developer
documentation, and learn more by watching our Google I/O session





Thursday, June 23, 2016

Introducing the Android Basics Nanodegree

Posted by Shanea King-Roberson, Lead Program Manager Twitter: @shaneakr Instagram: @theshanea







Do you have an idea for an app but you don’t know where to start? There are over
1 billion Android devices worldwide, providing a way for you to deliver your
ideas to the right people at the right time. Google, in partnership with
Udacity, is making Android development accessible and understandable to
everyone, so that regardless of your background, you can learn to build apps
that improve the lives of people around you.



Enroll in the new Android Basics
Nanodegree
. This series of courses and services teaches you how to build
simple Android apps--even if you have little or no programming experience. Take
a look at some of the apps built by our students:



The app "ROP Tutorial" built by student Arpy Vanyan raises awareness of a
potentially blinding eye disorder called Retinopathy of Prematurity that can
affect newborn babies.











And user Charles Tommo created an app called “Dr Malaria” that teaches people
ways to prevent malaria.











With courses designed by Google, you can
learn skills that are applicable to building apps that solve real world
problems. You can learn at your own pace to use href="http://developer.android.com/tools/studio/index.html">Android Studio
(Google’s official tool for Android app development) to design app user
interfaces and implement user interactions using the Java programming language.



The courses walk you through
step-by-step on how to build an order form for a coffee shop, an app to track
pets in a shelter, an app that teaches vocabulary words from the Native American
Miwok tribe, and an app on recent earthquakes in the world. At the end of the
course, you will have an entire portfolio of apps to share with your friends and
family.



Upon completing the Android Basics Nanodegree, you also have the opportunity to
continue your learning with the Career-track Android Nanodegree (for
intermediate developers). The first 50 participants to finish the Android Basics
Nanodegree have a chance to win a scholarship for the Career-track Android
Nanodegree. Please visit href="http://udacity.com/legal/scholarship">udacity.com/legal/scholarship
for additional details and eligibility requirements. You now have a complete
learning path to help you become a technology entrepreneur or most importantly,
build very cool Android apps, for yourself, your communities, and even the
world.



All of the individual courses that make
up this Nanodegree are available online for no charge at href="http://udacity.com/google">udacity.com/google. In addition, Udacity
provides paid services, including access to coaches, guidance on your project,
help staying on track, career counseling, and a certificate upon completion for
a fee.



You will be exposed to introductory computer science concepts in the Java
programming language, as you learn the following skills.


  • Build app user interfaces
  • Implement user interactions
  • Store information in a database
  • Pull data from the internet into your app
  • Identify and fix unexpected behavior in the app
  • Localize your app to support other languages


To enroll in the Android Basics Nanodegree program, href="http://udacity.com/nd803">click here.



See you in class!