Some devices might skip sending TRIM_BACKGROUND

So be more defensive in when we do the graphics cleanup
in case we are skipped straight to TRIM_COMPLETE

Test: none
Bug: 314251818
Change-Id: I8b03707b30235db6e2c5972531ff2f4437f02f9d
diff --git a/libs/hwui/renderthread/CacheManager.cpp b/libs/hwui/renderthread/CacheManager.cpp
index 30d4612..d5ec365 100644
--- a/libs/hwui/renderthread/CacheManager.cpp
+++ b/libs/hwui/renderthread/CacheManager.cpp
@@ -124,24 +124,19 @@
     // flush and submit all work to the gpu and wait for it to finish
     mGrContext->flushAndSubmit(GrSyncCpu::kYes);
 
-    switch (mode) {
-        case TrimLevel::BACKGROUND:
-            mGrContext->freeGpuResources();
-            SkGraphics::PurgeAllCaches();
-            mRenderThread.destroyRenderingContext();
-            break;
-        case TrimLevel::UI_HIDDEN:
-            // Here we purge all the unlocked scratch resources and then toggle the resources cache
-            // limits between the background and max amounts. This causes the unlocked resources
-            // that have persistent data to be purged in LRU order.
-            mGrContext->setResourceCacheLimit(mBackgroundResourceBytes);
-            SkGraphics::SetFontCacheLimit(mBackgroundCpuFontCacheBytes);
-            mGrContext->purgeUnlockedResources(toSkiaEnum(mMemoryPolicy.purgeScratchOnly));
-            mGrContext->setResourceCacheLimit(mMaxResourceBytes);
-            SkGraphics::SetFontCacheLimit(mMaxCpuFontCacheBytes);
-            break;
-        default:
-            break;
+    if (mode >= TrimLevel::BACKGROUND) {
+        mGrContext->freeGpuResources();
+        SkGraphics::PurgeAllCaches();
+        mRenderThread.destroyRenderingContext();
+    } else if (mode == TrimLevel::UI_HIDDEN) {
+        // Here we purge all the unlocked scratch resources and then toggle the resources cache
+        // limits between the background and max amounts. This causes the unlocked resources
+        // that have persistent data to be purged in LRU order.
+        mGrContext->setResourceCacheLimit(mBackgroundResourceBytes);
+        SkGraphics::SetFontCacheLimit(mBackgroundCpuFontCacheBytes);
+        mGrContext->purgeUnlockedResources(toSkiaEnum(mMemoryPolicy.purgeScratchOnly));
+        mGrContext->setResourceCacheLimit(mMaxResourceBytes);
+        SkGraphics::SetFontCacheLimit(mMaxCpuFontCacheBytes);
     }
 }