From 3d57eb633ec86d1dc357951995dcee81657b4c35 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 1 Jun 2018 16:45:56 +0200 Subject: BaseActivity: flush themed icon cache on theme change The most terrible hack you have ever seen. The drawable cache isn't properly flushed when changing the theme -- a frameworks bug, evidently -- so we work around it by digging deep into the mud. Signed-off-by: Jason A. Donenfeld --- .../com/wireguard/android/activity/BaseActivity.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'app/src') diff --git a/app/src/main/java/com/wireguard/android/activity/BaseActivity.java b/app/src/main/java/com/wireguard/android/activity/BaseActivity.java index 16e66817..7b6923f9 100644 --- a/app/src/main/java/com/wireguard/android/activity/BaseActivity.java +++ b/app/src/main/java/com/wireguard/android/activity/BaseActivity.java @@ -11,6 +11,7 @@ import android.databinding.CallbackRegistry; import android.databinding.CallbackRegistry.NotifierCallback; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.util.Log; import com.wireguard.android.Application; import com.wireguard.android.backend.GoBackend; @@ -18,6 +19,7 @@ import com.wireguard.android.model.Tunnel; import com.wireguard.android.model.TunnelManager; import com.wireguard.android.util.Topic; +import java.lang.reflect.Field; import java.util.Objects; /** @@ -25,6 +27,8 @@ import java.util.Objects; */ public abstract class BaseActivity extends AppCompatActivity implements Topic.Subscriber { + private static final String TAG = "WireGuard/" + BaseActivity.class.getSimpleName(); + private static final String KEY_SELECTED_TUNNEL = "selected_tunnel"; private final SelectionChangeRegistry selectionChangeRegistry = new SelectionChangeRegistry(); @@ -117,6 +121,20 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Su @Override public void onTopicPublished(Topic topic) { + try { + Field f = getResources().getClass().getDeclaredField("mResourcesImpl"); + f.setAccessible(true); + Object o = f.get(getResources()); + f = o.getClass().getDeclaredField("mDrawableCache"); + f.setAccessible(true); + o = f.get(o); + f = o.getClass().getSuperclass().getDeclaredField("mThemedEntries"); + f.setAccessible(true); + o = f.get(o); + o.getClass().getMethod("clear").invoke(o); + } catch (Exception e) { + Log.e(TAG, "Failed to flush icon cache", e); + } recreate(); } -- cgit v1.2.3