From 51cde1e60c43167f649eb62bfaa15429f845dd20 Mon Sep 17 00:00:00 2001 From: Zhomart Mukhamejanov Date: Thu, 31 May 2018 12:19:41 -0700 Subject: updater_sample: validate state only once Test: on device Change-Id: I0a8a87d7b69f0efdcbd17facbf42cb94fb96fe51 Signed-off-by: Zhomart Mukhamejanov --- .../com/example/android/systemupdatersample/UpdateManager.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/updater_sample/src/com/example/android/systemupdatersample/UpdateManager.java b/updater_sample/src/com/example/android/systemupdatersample/UpdateManager.java index 145cc83b1..2fe04bdde 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 @@ public class UpdateManager { 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 @@ public class UpdateManager { * Binds to {@link UpdateEngine}. */ public void bind() { + mStateValidityEnsured.set(false); this.mUpdateEngine.bind(mUpdateEngineCallback); } @@ -468,7 +472,10 @@ public class UpdateManager { 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)); -- cgit v1.2.3 From 842f2a3dca26cb6e91ef531d363d8f68c0f2f5ab Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Thu, 31 May 2018 18:16:28 -0700 Subject: Let gr_init proceed even if we failed to load a font file Some users of minui don't need to draw texts; and we should let them still be able to use the library without providing a font file. Also add check for null pointers in gr_measure() and gr_font_size(). Bug: 80535212 Test: boot into recovery without a font file, and the buttons still work Change-Id: I848e4410f2ce09ea0ab433573e6827b7e9b2c575 --- minui/graphics.cpp | 15 ++++++++++++--- minui/include/minui/minui.h | 4 +++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/minui/graphics.cpp b/minui/graphics.cpp index 202ce71fd..3b386015a 100644 --- a/minui/graphics.cpp +++ b/minui/graphics.cpp @@ -51,12 +51,21 @@ const GRFont* gr_sys_font() { } 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 @@ void gr_flip() { 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{ std::make_unique() }; diff --git a/minui/include/minui/minui.h b/minui/include/minui/minui.h index f9da19999..e96b7ae08 100644 --- a/minui/include/minui/minui.h +++ b/minui/include/minui/minui.h @@ -66,8 +66,10 @@ void gr_texticon(int x, int y, GRSurface* icon); 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); -- cgit v1.2.3