Snap for 4818218 from 92824456bd66b98e512baf405722ba59113b2766 to qt-release

Change-Id: I65b6e71ec4cd1664f2659791fe58d10d9d26d978
diff --git a/minui/graphics.cpp b/minui/graphics.cpp
index 202ce71..3b38601 100644
--- a/minui/graphics.cpp
+++ b/minui/graphics.cpp
@@ -51,12 +51,21 @@
 }
 
 int gr_measure(const GRFont* font, const char* s) {
+  if (font == nullptr) {
+    return -1;
+  }
+
   return font->char_width * strlen(s);
 }
 
-void gr_font_size(const GRFont* font, int* x, int* y) {
+int gr_font_size(const GRFont* font, int* x, int* y) {
+  if (font == nullptr) {
+    return -1;
+  }
+
   *x = font->char_width;
   *y = font->char_height;
+  return 0;
 }
 
 // Blends gr_current onto pix value, assumes alpha as most significant byte.
@@ -319,8 +328,8 @@
 int gr_init() {
   int ret = gr_init_font("font", &gr_font);
   if (ret != 0) {
-    printf("Failed to init font: %d\n", ret);
-    return -1;
+    printf("Failed to init font: %d, continuing graphic backend initialization without font file\n",
+           ret);
   }
 
   auto backend = std::unique_ptr<MinuiBackend>{ std::make_unique<MinuiBackendAdf>() };
diff --git a/minui/include/minui/minui.h b/minui/include/minui/minui.h
index f9da199..e96b7ae 100644
--- a/minui/include/minui/minui.h
+++ b/minui/include/minui/minui.h
@@ -66,8 +66,10 @@
 const GRFont* gr_sys_font();
 int gr_init_font(const char* name, GRFont** dest);
 void gr_text(const GRFont* font, int x, int y, const char* s, bool bold);
+// Return -1 if font is nullptr.
 int gr_measure(const GRFont* font, const char* s);
-void gr_font_size(const GRFont* font, int* x, int* y);
+// Return -1 if font is nullptr.
+int gr_font_size(const GRFont* font, int* x, int* y);
 
 void gr_blit(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy);
 unsigned int gr_get_width(GRSurface* surface);
diff --git a/updater_sample/src/com/example/android/systemupdatersample/UpdateManager.java b/updater_sample/src/com/example/android/systemupdatersample/UpdateManager.java
index 145cc83..2fe04bd 100644
--- a/updater_sample/src/com/example/android/systemupdatersample/UpdateManager.java
+++ b/updater_sample/src/com/example/android/systemupdatersample/UpdateManager.java
@@ -64,6 +64,9 @@
 
     private AtomicBoolean mManualSwitchSlotRequired = new AtomicBoolean(true);
 
+    /** Validate state only once when app binds to UpdateEngine. */
+    private AtomicBoolean mStateValidityEnsured = new AtomicBoolean(false);
+
     @GuardedBy("mLock")
     private UpdateData mLastUpdateData = null;
 
@@ -90,6 +93,7 @@
      * Binds to {@link UpdateEngine}.
      */
     public void bind() {
+        mStateValidityEnsured.set(false);
         this.mUpdateEngine.bind(mUpdateEngineCallback);
     }
 
@@ -468,7 +472,10 @@
         mUpdateEngineStatus.set(status);
         mProgress.set(progress);
 
-        ensureCorrectUpdaterState();
+        if (!mStateValidityEnsured.getAndSet(true)) {
+            // We ensure correct state once only when sample app is bound to UpdateEngine.
+            ensureCorrectUpdaterState();
+        }
 
         getOnProgressUpdateCallback().ifPresent(callback -> callback.accept(progress));