summaryrefslogtreecommitdiffhomepage
path: root/app/src/main
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-06-01 16:45:56 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-06-01 16:48:08 +0200
commit3d57eb633ec86d1dc357951995dcee81657b4c35 (patch)
treee427a0d645e09e7dbf17bea99abbe6a19637574d /app/src/main
parent1e45898d7035b5d617a3181cf1b6dfab8a10eae9 (diff)
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 <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/com/wireguard/android/activity/BaseActivity.java18
1 files changed, 18 insertions, 0 deletions
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();
}