Merge AOSP android-9.0.0_r3

Fix conflicts and make it build in 5.1, 6.0, 7.1, 8.1, and 9.0

Change-Id: Ida0a64c29ff27d339b7f42a18d820930964ac6e4
diff --git a/gui/keyboard.cpp b/gui/keyboard.cpp
index 849cf19..ca7006d 100644
--- a/gui/keyboard.cpp
+++ b/gui/keyboard.cpp
@@ -322,7 +322,7 @@
 		gr_color(mFontColorSmall.red, mFontColorSmall.green, mFontColorSmall.blue, mFontColorSmall.alpha);
 	}
 
-	if (labelImage)
+	if (labelImage && labelImage->GetResource())
 	{
 		int w = labelImage->GetWidth();
 		int h = labelImage->GetHeight();
@@ -330,7 +330,7 @@
 		int y = keyY + (keyH - h) / 2;
 		gr_blit(labelImage->GetResource(), 0, 0, w, h, x, y);
 	}
-	else if (!labelText.empty())
+	else if (!labelText.empty() && labelFont && labelFont->GetResource())
 	{
 		void* fontResource = labelFont->GetResource();
 		int textW = gr_ttf_measureEx(labelText.c_str(), fontResource);
@@ -342,7 +342,7 @@
 
 	// longpress key label (only if font is defined)
 	keychar = key.longpresskey;
-	if (keychar > 32 && keychar < 127 && mLongpressFont->GetResource()) {
+	if (keychar > 32 && keychar < 127 && mLongpressFont && mLongpressFont->GetResource()) {
 		void* fontResource = mLongpressFont->GetResource();
 		gr_color(mLongpressFontColor.red, mLongpressFontColor.green, mLongpressFontColor.blue, mLongpressFontColor.alpha);
 		string text(1, keychar);