mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-11-07 12:47:02 +01:00
fix: ensure thread safety for class StringRef
(#273)
This commit is contained in:
parent
954e60191e
commit
f5c5fcb5e4
@ -5,16 +5,20 @@ import android.content.res.Resources;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import app.revanced.integrations.utils.LogHelper;
|
||||
import app.revanced.integrations.utils.ReVancedUtils;
|
||||
|
||||
// should probably move this class into utils package
|
||||
public class StringRef {
|
||||
private static Resources resources;
|
||||
private static String packageName;
|
||||
|
||||
private static final HashMap<String, StringRef> strings = new HashMap<>();
|
||||
// must use a thread safe map, as this class is used both on and off the main thread
|
||||
private static final Map<String, StringRef> strings = Collections.synchronizedMap(new HashMap());
|
||||
|
||||
/**
|
||||
* Gets strings reference from shared collection or creates if not exists yet,
|
||||
@ -90,9 +94,11 @@ public class StringRef {
|
||||
@NonNull
|
||||
public String toString() {
|
||||
if (!resolved) {
|
||||
if (resources == null || packageName == null) {
|
||||
Context context = ReVancedUtils.getContext();
|
||||
resources = context.getResources();
|
||||
packageName = context.getPackageName();
|
||||
}
|
||||
resolved = true;
|
||||
if (resources != null) {
|
||||
final int identifier = resources.getIdentifier(value, "string", packageName);
|
||||
|
Loading…
Reference in New Issue
Block a user