Skip to content

Commit

Permalink
Fix storing/restoring icon mappings
Browse files Browse the repository at this point in the history
I am an idiot. Object serialization can't work (over app updates)
when the code is obfuscated, of course.

Object serialization works with the *name* of an object, and R8
shortens the names to some abbreviation that can and will vary
from build to build.

So yes, this means everyone will loose all icon mappings with the
next update. Sorry.
  • Loading branch information
markusfisch committed Feb 10, 2024
1 parent cac05d0 commit be0770a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ public void selectPack(PackageManager pm, String packageName) {
}

public Drawable getIcon(String packageName) {
PackAndDrawable pad = mappings.get(packageName);
String drawableName = null;
PackAndDrawable pad = mappings.get(packageName);
if (pad != null) {
if (selectedPack != null &&
pad.packageName.equals(selectedPack.packageName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,61 @@

import android.content.Context;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;

import de.markusfisch.android.pielauncher.graphics.IconPack;

public class IconMappings {
private static final String SEPARATOR = ";";
private static final String MAPPINGS_FILE = "mappings";

@SuppressWarnings("unchecked")
public static void restore(Context context,
HashMap<String, IconPack.PackAndDrawable> mappings) {
mappings.clear();
try {
FileInputStream fis = context.openFileInput(MAPPINGS_FILE);
ObjectInputStream ois = new ObjectInputStream(fis);
mappings.clear();
mappings.putAll((HashMap<String, IconPack.PackAndDrawable>)
ois.readObject());
ois.close();
fis.close();
} catch (IOException | ClassCastException | ClassNotFoundException e) {
// Ignore, can't do nothing about this.
BufferedReader reader = new BufferedReader(new InputStreamReader(
context.openFileInput(MAPPINGS_FILE)));
String line;
while ((line = reader.readLine()) != null) {
String[] parts = line.split(SEPARATOR);
if (parts.length < 3) {
continue;
}
mappings.put(parts[0], new IconPack.PackAndDrawable(
parts[1], parts[2]));
}
reader.close();
} catch (FileNotFoundException e) {
// Return an empty array.
} catch (IOException e) {
// Return an empty array.
}
}

public static void store(Context context,
HashMap<String, IconPack.PackAndDrawable> mappings) {
try {
FileOutputStream fos = context.openFileOutput(
MAPPINGS_FILE, Context.MODE_PRIVATE);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(mappings);
oos.close();
fos.close();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
context.openFileOutput(MAPPINGS_FILE,
Context.MODE_PRIVATE)));
for (Map.Entry<String, IconPack.PackAndDrawable> mapping :
mappings.entrySet()) {
writer.write(mapping.getKey());
writer.write(SEPARATOR);
IconPack.PackAndDrawable pad = mapping.getValue();
writer.write(pad.packageName);
writer.write(SEPARATOR);
writer.write(pad.drawableName);
writer.newLine();
}
writer.close();
} catch (IOException e) {
// Ignore, can't do nothing about this.
}
Expand Down

0 comments on commit be0770a

Please sign in to comment.