Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Challenges of Building HTC Sense (O'Reilly Andr...

David Wu
October 11, 2011

Challenges of Building HTC Sense (O'Reilly Android Open Conference 2011)

The success of Android as an open platform in the past couple of years is made evident by the huge volume and diversity of devices offered by manufacturers. In this highly competitive market, device manufacturers strive to differentiate themselves via innovation over the existing platform.

HTC Sense is a customized UI framework that enhances the stock Android by centering its design around people and their social networks. One of its design goals is to provide a seamless social experience across applications and widgets in different contexts, while conserving battery life and maintaining performance. In this session we will share some of the technical challenges in designing HTC Sense and our experiences to overcome those challenges.

The session will begin with a brief overview of unique features in HTC Sense. We will demonstrate that HTC Sense is not just an additional collection of applications and widgets, but an experience around the user and his/her social networks.

We will then go over four technical challenges in designing HTC Sense to provide such a social experience. We hope to share some of our experiences in overcoming those challenges.

David Wu

October 11, 2011
Tweet

More Decks by David Wu

Other Decks in Programming

Transcript

  1. Challenges of Building HTC Sense David Wu [email protected] O’Reilly Android

    Open Conference 2011 October 11, 2011 HTC Proprietary and Confidential – Internal use and strategic partner use only © 2010 HTC Corporation. All rights reserved.
  2. HTC Proprietary and Confidential 9 Agenda •  Social Features in

    HTC Sense •  Challenge 1 - Seamlessness •  Challenge 2 – Sync •  Challenge 3 – Performance
  3. S c a E p r e c HTC Proprietary

    and Confidential 15
  4. HTC Proprietary and Confidential 26 Agenda •  Social Features in

    HTC Sense •  Challenge 1 - Seamlessness •  Challenge 2 – Sync •  Challenge 3 – Performance
  5. Host Host HTC Proprietary and Confidential 28 Host Plugin Plugin

    Plugin Query Request •  Aggregated data retrieval •  UI rendering •  Refresh •  Load more
  6. HTC Proprietary and Confidential 29 Broadcast Intent and Class Loading

    •  Request with callback: •  Host broadcast Intents •  Plugin registers an IntentReceiver •  Query: •  Dynamic class loading T y #1
  7. HTC Proprietary and Confidential 30 Problems •  Broadcast Intent problems:

    •  Overhead in receiving the Broadcast Intent •  Difficult synchronization between requests coming from different hosts •  Dynamic class loading problems: •  Host and plugins require the same UID •  Huge performance penalty due to dynamic class loading via Java Reflection •  Fat host processes •  Debugging difficulty •  Unintuitive control code for dynamic content filtering
  8. HTC Proprietary and Confidential 31 Binder IPC and ContentProvider • 

    Request with callback: •  Remote binder call with callback mechanism •  Query: •  ContentProvider with ContentObserver •  Standardized data types •  Limited UI rendering with markup languages T y #2
  9. HTC Proprietary and Confidential 32 Problems •  Database access performance

    issues •  Schema optimization via indexing •  Query optimization •  Prepared statements •  Transactions •  Reduce disk I/O by implementing a memcache layer •  Multiple ContentObservers may make the system unusually busy •  Use dirty flag and do lazy requery
  10. HTC Proprietary and Confidential 35 Important Problem with Trade-Off Solutions

    •  Can’t disclose actual sales numbers, but to put things in perspective: •  2 out of every 5 Android phones sold is an HTC •  1 out of every 2 Windows phones sold is an HTC •  Every 0.68 sec there is a new HTC phone activated •  Who cares? •  Network operators •  Online services •  Users
  11. HTC Proprietary and Confidential 36 Improving Bandwidth and Battery Usage

    •  Monitor device states •  Partial sync •  Smart sync
  12. HTC Proprietary and Confidential 37 Monitoring Device States •  Network

    connectivity •  Online vs. Offline •  Roaming vs. Not Roaming •  WiFi vs. GPRS/EDGE •  Battery level •  Storage capacity •  The less free space left, the higher the disk latency •  AlarmManager intervals •  Best interval (sleep) vs. Minimum interval (wakeup) •  Check out Reto Meier’s “Android Protips” session at Google I/O 2011
  13. HTC Proprietary and Confidential 38 Partial Sync •  Sync only

    important data •  Only contacts explicitly marked as “favorite” or with frequent interactivities
  14. HTC Proprietary and Confidential 39 Partial Sync •  Sync only

    important data •  Only contacts explicitly marked as “favorite” or with frequent interactivities •  Only a limited number of most recent stream posts Current time
  15. HTC Proprietary and Confidential 40 Partial Sync •  Sync only

    important data •  Only contacts explicitly marked as “favorite” or with frequent interactivities •  Only a limited number of most recent stream posts Current time
  16. HTC Proprietary and Confidential 41 Partial Sync •  Sync only

    important data •  Only contacts explicitly marked as “favorite” or with frequent interactivities •  Only a limited number of most recent stream posts Current time Current time
  17. HTC Proprietary and Confidential 42 Partial Sync •  Avoid fetching

    or writing the same data more than once •  Use hash to speed up data comparisons
  18. HTC Proprietary and Confidential 43 Partial Sync •  Avoid fetching

    or writing the same data more than once •  Use hash to speed up data comparisons •  Deep integration with native clients •  Facebook vs. Facebook for HTC Sense
  19. HTC Proprietary and Confidential 44 Smart Sync •  Use application

    heuristics •  Sync if and only if •  At least one widget is installed on the Home screen •  It has been at least one hour since the last sync •  Do not sync if historically the stream timeline has sparse data
  20. HTC Proprietary and Confidential 46 Outline for Improving Performance • 

    Aggregated content retrieval from multiple data sources •  Improving application launch time •  Scrolling performance •  General coding practices
  21. HTC Proprietary and Confidential 47 Aggregated Content Retrieval Host Host

    Application Data Source Data Source Data Source Sorted
  22. HTC Proprietary and Confidential 48 Aggregated Content Retrieval •  Aggregated

    content retrieval from multiple data sources •  Quick sort •  Need all content to be in memory •  Long startup delay
  23. HTC Proprietary and Confidential 49 Aggregated Content Retrieval •  Aggregated

    content retrieval from multiple data sources •  Quick sort •  Need all content to be in memory •  Long startup delay •  Merge sort •  Make use of SQLite indexed sorting capability •  Maintain a min/max heap and a set of position markers for each data source •  Minimal startup delay •  Amortized sorting cost, which is barely noticeable
  24. HTC Proprietary and Confidential 50 Aggregated Content Retrieval •  Aggregated

    content retrieval from multiple data sources •  Quick sort •  Need all content to be in memory •  Long startup delay •  Merge sort •  Make use of SQLite indexed sorting capability •  Maintain a min/max heap and a set of position markers for each data source •  Minimal startup delay •  Amortized sorting cost, which is barely noticeable •  Reduces application launch time from 1800ms to 600ms in FriendStream
  25. HTC Proprietary and Confidential 51 Aggregated Content Retrieval •  Aggregated

    content retrieval from multiple data sources •  Quick sort •  Need all content to be in memory •  Long startup delay •  Merge sort •  Make use of SQLite indexed sorting capability •  Maintain a min/max heap and a set of position markers for each data source •  Minimal startup delay •  Amortized sorting cost, which is barely noticeable •  Reduces application launch time from 1800ms to 600ms in FriendStream •  Same technique used in Contacts, Messages, Calendar, etc.
  26. HTC Proprietary and Confidential 52 Outline for Improving Performance • 

    Aggregated content retrieval from multiple data sources •  Improving application launch time •  Scrolling performance •  General coding practices
  27. HTC Proprietary and Confidential 53 Application Launch Times •  Perceived

    launch time (fake screen) • android:windowBackground=“@drawable/fakebg”!
  28. HTC Proprietary and Confidential 54 Application Launch Times •  Perceived

    launch time (fake screen) • android:windowBackground=“@drawable/fakebg”! • getWindow().setBackgroundDrawable(null);!
  29. HTC Proprietary and Confidential 55 Application Launch Times •  Perceived

    launch time (fake screen) • android:windowBackground=“@drawable/fakebg”! • getWindow().setBackgroundDrawable(null);! •  Reduce layout complexity
  30. HTC Proprietary and Confidential 56 Application Launch Times •  Perceived

    launch time (fake screen) • android:windowBackground=“@drawable/fakebg”! • getWindow().setBackgroundDrawable(null);! •  Reduce layout complexity •  Optimize database query •  Minimize fillWindow time •  Only select columns that are needed •  Use limits •  Profile SQLite queries
  31. HTC Proprietary and Confidential 57 Prepared Statements •  Precompiling frequently

    used SQL statements String sql = “INSERT INTO table VALUES (?, ?)”;! SQLiteStatement stmt = mDatabase.compileStatement(sql);! ! DatabaseUtils.bindObjectToProgram(stmt, 1, 1);! DatabaseUtils.bindObjectToProgram(stmt, 2, 2);! ! stmt.execute();! stmt.close();!
  32. HTC Proprietary and Confidential 58 Outline for Improving Performance • 

    Aggregated content retrieval from multiple data sources •  Improving application launch time •  Perceived launch time •  Database query optimization •  Prepared statements •  Transactions •  Scrolling performance •  General coding practices
  33. HTC Proprietary and Confidential 59 Improve Scrolling Performance •  Minimize

    getView() and draw() •  Check your ListAdapter.getView() •  Use convertViews •  Cache findViewById() results •  Do not set a Window background •  Avoid runtime scaling of images •  Reuse byte buffer in BitmapFactory.decodeStream() to avoid unnecessary GC
  34. HTC Proprietary and Confidential 60 Outline for Improving Performance • 

    Aggregated content retrieval from multiple data sources •  Improving application launch time •  Perceived launch time •  Database query optimization •  Prepared statements •  Transactions •  Scrolling performance •  General coding practices
  35. HTC Proprietary and Confidential 61 General Coding Tips •  Use

    System.arraycopy • for (int i = 0; i<size; i++) a2[i] = a1[i]; // 315ms! • System.arraycopy(a1, 0, a2, 0, size); // 29ms
  36. HTC Proprietary and Confidential 62 General Coding Tips •  Use

    System.arraycopy • for (int i = 0; i<size; i++) a2[i] = a1[i]; // 315ms! • System.arraycopy(a1, 0, a2, 0, size); // 29ms •  Always supply an initial capacity for Collections •  ArrayUtils.idealXXXArraySize()
  37. HTC Proprietary and Confidential 63 General Coding Tips •  Use

    System.arraycopy • for (int i = 0; i<size; i++) a2[i] = a1[i]; // 315ms! • System.arraycopy(a1, 0, a2, 0, size); // 29ms •  Always supply an initial capacity for Collections •  ArrayUtils.idealXXXArraySize() •  Use Object pool to minimize object allocations and garbage collection
  38. HTC Proprietary and Confidential 64 D v d W @w

    m n d v d@w -m n.c m b o .w -m n.c m