Only treat PNG_COLOR_TYPE_RGB as 565

Bug: 190188264
Bug: skia:5616
Test: imagedecoder_png_fuzzer
Test: Codec_PngRoundTrip

If a PNG's sBIT specifies that the significant bits are 565, SkPngCodec
treats the image as defaulting to kRGB_565_SkColorType, rather than the
typical kN32_SkColorType. This feature is likely rarely used in the
wild, but it is used by Skia to encode kRGB_565_SkColorType to a PNG and
then recreate the original SkPixmap. These Skia-created PNGs always use
PNG_COLOR_TYPE_RGB, so only respect this sBIT with PNG_COLOR_TYPE_RGB.

Further, if the PNG is PNG_COLOR_TYPE_PALETTE, treating it as 565 means
that we read it incorrectly.

Change-Id: I15d9571398870ecf67a150e46d28d4545afcf3c8
(cherry picked from commit f6de97fce5c06b0388d278f63179d7282c136e2e)
diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp
index 4eaa034..9202e8a 100644
--- a/src/codec/SkPngCodec.cpp
+++ b/src/codec/SkPngCodec.cpp
@@ -934,22 +934,39 @@
             }
         }
 
-        if (encodedColorType == PNG_COLOR_TYPE_GRAY_ALPHA) {
-            png_color_8p sigBits;
-            if (png_get_sBIT(fPng_ptr, fInfo_ptr, &sigBits)) {
-                if (8 == sigBits->alpha && kGraySigBit_GrayAlphaIsJustAlpha == sigBits->gray) {
-                    color = SkEncodedInfo::kXAlpha_Color;
+        switch (encodedColorType) {
+            case PNG_COLOR_TYPE_GRAY_ALPHA:{
+                png_color_8p sigBits;
+                if (png_get_sBIT(fPng_ptr, fInfo_ptr, &sigBits)) {
+                    if (8 == sigBits->alpha && kGraySigBit_GrayAlphaIsJustAlpha == sigBits->gray) {
+                        color = SkEncodedInfo::kXAlpha_Color;
+                    }
                 }
+                break;
             }
-        } else if (SkEncodedInfo::kOpaque_Alpha == alpha) {
+            case PNG_COLOR_TYPE_RGB:{
+                png_color_8p sigBits;
+                if (png_get_sBIT(fPng_ptr, fInfo_ptr, &sigBits)) {
+                    if (5 == sigBits->red && 6 == sigBits->green && 5 == sigBits->blue) {
+                        // Recommend a decode to 565 if the sBIT indicates 565.
+                        color = SkEncodedInfo::k565_Color;
+                    }
+                }
+                break;
+            }
+        }
+
+#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
+        if (encodedColorType != PNG_COLOR_TYPE_GRAY_ALPHA
+            && SkEncodedInfo::kOpaque_Alpha == alpha) {
             png_color_8p sigBits;
             if (png_get_sBIT(fPng_ptr, fInfo_ptr, &sigBits)) {
                 if (5 == sigBits->red && 6 == sigBits->green && 5 == sigBits->blue) {
-                    // Recommend a decode to 565 if the sBIT indicates 565.
-                    color = SkEncodedInfo::k565_Color;
+                    SkAndroidFrameworkUtils::SafetyNetLog("190188264");
                 }
             }
         }
+#endif // SK_BUILD_FOR_ANDROID_FRAMEWORK
 
         SkEncodedInfo encodedInfo = SkEncodedInfo::Make(origWidth, origHeight, color, alpha,
                                                         bitDepth, std::move(profile));