Synthesis for Programming on Mobile Platforms

Similar documents
Synthesis for Developing Apps on Mobile Platforms

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

Moving from CS 61A Scheme to CS 61B Java

Table of Contents. Adding Build Targets to the SDK 8 The Android Developer Tools (ADT) Plug-in for Eclipse 9

Mocean Android SDK Developer Guide

Computing Concepts with Java Essentials

Iotivity Programmer s Guide Soft Sensor Manager for Android

WebView addjavascriptinterface Remote Code Execution 23/09/2013

Frameworks & Android. Programmeertechnieken, Tim Cocx

Design by Contract beyond class modelling

AndroLIFT: A Tool for Android Application Life Cycles

Recovering Business Rules from Legacy Source Code for System Modernization

AP Computer Science Java Subset

The BSN Hardware and Software Platform: Enabling Easy Development of Body Sensor Network Applications

HVM TP : A Time Predictable and Portable Java Virtual Machine for Hard Real-Time Embedded Systems JTRES 2014

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Java Application Developer Certificate Program Competencies

Graduate presentation for CSCI By Janakiram Vantipalli ( Janakiram.vantipalli@colorado.edu )

How to develop your own app

Introduction to Software Testing Chapter 8.1 Building Testing Tools Instrumentation. Chapter 8 Outline

OPC UA App development for Android

A model driven approach for Android applications development

Mobile Application Development Android

Lecture 1 Introduction to Android

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Java CPD (I) Frans Coenen Department of Computer Science

How to Program an Android Application to Access and Manage the Wi-Fi Capabilities of a Smartphone

C Compiler Targeting the Java Virtual Machine

Android Application Development Course Program

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Introduction to Android. CSG250 Wireless Networks Fall, 2008

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Glossary of Object Oriented Terms

Example of Standard API

Android Basics. Xin Yang

CS 111 Classes I 1. Software Organization View to this point:

Affdex SDK for Android. Developer Guide For SDK version 1.0

Qlik REST Connector Installation and User Guide

Euler: A System for Numerical Optimization of Programs

Android Application Development

Java Interview Questions and Answers

Integrating SharePoint Sites within WebSphere Portal

Introduction to Android Development. Jeff Avery CS349, Mar 2013

ECM (ELO-KIT-ECMG2-AND)

Service Provider awareness Universal Apparatus

A Short Introduction to Android

Creating a 2D Game Engine for Android OS. Introduction

A Look through the Android Stack

Android Studio Application Development

Creating a Simple, Multithreaded Chat System with Java

Introduction to Parallel Programming and MapReduce

Chapter 13: Program Development and Programming Languages

Boogie: A Modular Reusable Verifier for Object-Oriented Programs

Introduction to HP ArcSight ESM Web Services APIs

Android Development. Marc Mc Loughlin

Pseudo code Tutorial and Exercises Teacher s Version

The Recipe for Sarbanes-Oxley Compliance using Microsoft s SharePoint 2010 platform

Appium mobile test automation

Lecture 9. Semantic Analysis Scoping and Symbol Table

Logistics. Software Testing. Logistics. Logistics. Plan for this week. Before we begin. Project. Final exam. Questions?

Software Engineering Techniques

Secure Authentication and Session. State Management for Web Services

Basics of Android Development 1

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

Fundamentals of Java Programming

Explorer's Guide to the Semantic Web

: provid.ir

Budget Event Management Design Document

Using Extensions or Cordova Plugins in your RhoMobile Application Darryn

How To Develop Android On Your Computer Or Tablet Or Phone

Getting Started with Android Smartphones and ThingWorx

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Object Relational Database Mapping. Alex Boughton Spring 2011

Contents. Introduction and System Engineering 1. Introduction 2. Software Process and Methodology 16. System Engineering 53

Software Test Plan (STP) Template

1 Which of the following questions can be answered using the goal flow report?

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

GETTING STARTED WITH ANDROID DEVELOPMENT FOR EMBEDDED SYSTEMS

INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011

Messing with the Android Runtime

Part I. Multiple Choice Questions (2 points each):

Amazon Glacier. Developer Guide API Version

CS 40 Computing for the Web

Compiler I: Syntax Analysis Human Thought

06 Team Project: Android Development Crash Course; Project Introduction

App Development with Talkamatic Dialogue Manager

An Overview of Java. overview-1

Specialized Programme on Web Application Development using Open Source Tools

Compiler Construction

Linked Statistical Data Analysis

Java Memory Model: Content

Transcription:

Synthesis for Programming on Mobile Platforms Jeff Foster University of Maryland, College Park Armando Solar-Lezama Massachusetts Institute of Technology

Android Popularity Android most popular smartphone platform 80% of the market in 2Q13 850K Android apps on Google Play (4/13) 40 billion apps downloaded (4/13) Apps written in Java Extensive framework that apps hook into Everything Android-specific happens in Java Native code calls back into Java to access phone features Lots of exciting app development underway Interesting apps don t need to be large 2

Many Opportunities for Synthesis Synthesis for tool developers Making existing analysis technologies work for Android presents a programming challenge that synthesis can help address Synthesis for expert programmers Similar challenges to other Big Code environments Synthesis for the end user Can every phone user be a developer? 3

Synthesis for Android Tool Developers New Collaborative Project enabled by ExCAPE Solar-Lezama Madhusudan Foster Leverages combined expertise in Analysis for mobile code Constraint based synthesis Foster Project has recently been joined by Xiaokang Qiu Former student of PI Madhusudan New collaboration brings in additional expertise in verification 4

Synthesis for Android Tool Developers Motivation: Program analysis and synthesis tools for Android need to understand the Android framework Example: SymDroid, symbolic execution for Dalvik bytecode Can t execute any app without modeling the framework Challenges App code is tightly tied to the Android framework Framework is big and complex Symbolic execution of the framework is infeasible Hand creation of models is brittle and expensive Can we synthesize a model of Android? Model can be used in later synthesis work as well 5

Android Programming Model Event driven programming model No main() Many entry points invoked in response to events from software or hardware Framework provides an abstraction around hardware Convey hardware generated events Provide API access to hardware state Application Event A Event B API Calls Android Framework Event C Hardware Goal: Automatically discover a simple model of the framework 6

Qualities of an Android Model Tailored for analyzability Simpler than original framework E.g., may need to model GUI callbacks, but need not worry about exact placement of widgets on screen Code need not be extensible and maintainable Need not be precise Over- or under-approximations can be acceptable Depends on the goal 7

The Synthesis Problem Reactive synthesis with a few twists Model is not just a state machine Although many of its components are Requirements come in the form of multiple artifacts Record of interactions between framework and application High-level structural constraints in terms of design patterns High-level properties and invariants Note: Same ideas can apply to many software frameworks 8

Current Approach samples (.log) templates (.java) Encoder templates (.sk) SKETCH Synthesizer platform (.java) Decoder synthesis results (.c) Logs gathered from range of executions Use bytecode instrumentation framework to record all calls/returns between app and framework Templates represent knowledge of system Type signatures from APIs Design patterns from SDK documentation, naming conventions Other insights from reading documentation Key challenge: Minimizing necessary knowledge 9

Creating Templates: Example What the user knows Date User Talk notifies users about change Which users? In what order? Talk observes changes to the date Users register with Talk Talk 10

Template Using Observer Pattern Pattern elements Class and method signatures Methods identified by function based on design pattern Main must implement an event listener loop class User { String _name; @Notified void update(talk t, Date arg); } class Main { public static void main() {... // setup @React; } } class Date { int _date; } class Talk { int _date; String _title; @Event(Date) void datechanged(date date); @Attach void addobserver(user user); @Detach void deleteobserver(user user); } 11

Annotation Translation Expand structural information from annotations Basically, implement the design patterns Add unknowns as appropriate Holes?? indicating unknown values Regular expression generators { e1 en } Translate from Java to Sketch Map class hierarchy and dynamic dispatch into appropriate Sketch primitives 12

Annotation Translation (cont d) class Talk { @Event(Date) void datechanged(date date); } void datechanged_talk(talk self, Date date) { // General Event handling code: } // log function entry and parameters // iterate over some of the registered users // call the @Notified methods of users who pass a test // log the function exit 13

Annotation Translation (cont d) class Talk { @Event(Date) void datechanged(date date); } void datechanged_talk(talk self, Date date) { } // log function entry and parameters void f(user u){ if (P(u, self, date)){ update_user(o, self, date); } } { (forwarditer backwarditer)(f, self.obs) } // log the function exit 14

Log Translation... Date change event # event (external) > Talk.dateChanged(Talk@4885, Date@2013) # call (internal)... < Talk.dateChanged() # ret (internal)... harness void sample() { Event e0 = new Event(kind=0, date=...);... // event setting: insert events into the queue main(); // main program... log = read@log(idx++); assert log == /* Talk.dateChanged(Talk@4885, Date@2013) */... log = read@log(idx++); assert log == /* Talk.dateChanged() */... } 15

(Very) Preliminary Results Synthesis for observer pattern Template: 3 classes, 26 lines of code, 4 observer-related annotations Samples: 3 total, with 40, 60, and 18 calls, including 5, 5, and 2 events Intermediate outputs: 619 lines of sketch code 308 lines for encoding classes and scenarios 246 lines for encoding logs/samples Running time Translation less than 1 second Sketch synthesis time 17 seconds Final output 147 lines of Java code 16

Scaling Up to Android Support for more design patterns Accessors, state machines, single-/multiton, factories, builders, plus a few others Reduce knowledge encoded in templates Increase burden on synthesizer Modularity may be important here Test results against actual executions Try on several different Android platform versions (1) Synthesize model supporting additional features (2) Detect changes in platform (though not likely) 17

Other Synthesis Challenges Synthesis to help programmers CodeHint: Interactive synthesis for IDEs (PI Bodik) Sort of a super autocomplete feature Focus is Java in general, but works with Android Synthesis to help end users Programming by Demonstration Autolayout by dragging/resizing elements of graphs (PI Bodik) LifeJoin query by demonstration (PI Solar-Lezama) Both may be very useful for designing mobile apps 18

Broader Impacts A huge number of people use Android today Synthesizing model could help researchers building Android analysis and synthesis tools Which in turn will help Android users E.g., tools that analyze Android apps for security concerns Making Android programmers more productive could help apps be easier to write, maintain, and be more reliable and secure Enabling end-users to build apps they want could lead to innovative new mobile device ideas 19

End

Synthesis for Expert Programmers Motivation: Give Android programmers tools to make their job easier Build on experience with synthesis tools for frameworks Prospector, MatchMaker Key problems How to describe what you want How to cope with complexity Technical directions Combining data-driven techniques with logic-based engines 21

Synthesis for End Users Motivation: Lots of people have ideas for apps they want to build Can t do it if they don t know Java at a fairly high level Can we make every phone user an app developer? Focus: mashups that combine abilities of existing apps Ex: Map contacts whose addresses are nearby current location Ex: Auto-translate SMS messages from certain phone numbers Ex: Convert units from recipe app into metric Technical directions Finding valid combinations of high-level pathways through apps 22

Android Model as a Reactive Program Inputs External events Timers, user gestures, Include method being called + parameters Application calls Application return Outputs Calls from the framework to the application Model is not just an FSM Basic building blocks include FSMs, Stacks, internal data structures User-provided sketch helps guide the choice of building blocks Leverage known design patterns 23

High-level User Knowledge Sort of Knowledge Type signatures, design patterns, partial programs, etc. Source of Knowledge SDK documentations, naming conventions, insight(!) Sketch of Knowledge Java: best fit for type signatures Android platform and apps are written in Java Annotations Knowledge can be represented in a declarative manner Designed to add meta-data into Java code 24

Synthesis Challenges Conveying Structure Sketch is too low level Solution: use design patterns to give complex structures concisely Scalability Early experiments are encouraging Modularity will be crucial Client-Synthesis feedback loop Model should only be as complex as required by the analysis 25

Translation into Sketch 1. parsing high-level templates written in Java modify Java grammar to allow annotations at every level, including class, method, field, and expression keep AST to generate final results easier 2. rule-based annotation reduction introduce appropriate data structures, fields, or expressions to reflect semantics of annotations 3. Java-to-C translation virtual structure for class hierarchy class per file, due to the scope of static fields 26

Interpretation of Synthesis Result find what operators/methods/values are selected dump out AST after substituting holes with such chosen operators/methods/values void datechanged_talk (Talk self, Date date, ref global int[5][50] ev_s532, ref global int log_cnt_s533)/*talk.sk:6*/ {... bit sa4 = ((self._obs.elts[0])!= (null)) && 1; while( sa4) { User o; o = self._obs.elts[idx]; if((self._date) == (date._date))/*talk.sk:13*/ { update_user(o, self, date, ev_s532, log_cnt_s533); } idx = idx + 1; sa4 = ((self._obs.elts[idx])!= (null)) && (idx < 6); }... } /*Talk.sk:33*/ 27

Current Results templates 3 participating classes 26 lines of Java code with 4 observer-related annotations main harness methods for 3 scenarios samples 42 lines of Java code with 4 reaction annotations 40, 60, and 18 lines of call sequences including 5, 5, and 2 events to react 28

Current Results (cont d) intermediate outputs 614 lines of sketch code 303 lines for encoding classes and scenarios 245 lines for encoding samples translation time: within a second sketch running time: 9.5 seconds final results 144 lines of Java code 29

Towards Android Modeling Accessors @Get, @Set, @Is, @Has, @Put based on naming convention Uncertain methods @Tag( tag-name ) or @All() class ClipboardManager { @Get @Set @Has Clipdata primaryclip; } class Activity { @Tag( ActivityLifecycle ) void oncreate( ); @Tag( ActivityLifecycle ) void onresume(); } class Platform { void step_up_act (Activity act) { act.@tag( ActivityLifecycle ); act.@tag( ActivityLifecycle ); act.@tag( ActivityLifecycle ); } } 30

More Patterns State machine a field to maintain a @State an expression to retrieve the designated @State an expression to @Update the state class Activity { @State(@Tag( ActivityLifecycle )) int _state; boolean isfinishing() { return @State(this) ==??; } @Tag( ActivityLifecycle ) void oncreate( ); } 31

More Patterns (cont d) @Singleton and @Multiton one and only Activity stack, a.k.a. back stack one and only instance for resource managers, associated with distinct name tags class Platform { @Signleton Stack<Activity> back_stack; } class Context { final static String LOCATION_SERVICE = location ; @Multiton({ LocationManager, }) Map<String, Object> systemservice; } 32

More Patterns (cont d) @Factory method returns a new instance of the target class whose constructor has a private modifier Builder pattern class PowerManager { @Factory WakeLock newwakelock( ); class WakeLock { } } @Append and then @Assemble class Uri { @Get @Set(Builder) private String scheme; @Get @Set(Builder) @Append(Builder) private String path; // cont d } @Factory Builder buildupon(); class Builder { @Assemble Uri build(); } 33