Bug 1373964 - On profile migrate, delete <dir>/res/fonts. r=vladbaicu

The previous implementation attempted to delete files from /res/fonts (i.e.
root). I don't believe this was intended either:
https://bugzilla.mozilla.org/show_bug.cgi?id=878674#c0 indicates the fonts
directory should be inside the data dir of the application. The crash occurs
when the /res/fonts directory exists (only some devices) but the user doesn't
have read access. If the user has write access, our code may actually delete
these system files: uh oh!

My fix is to change the deletion from /res/fonts to <dir>/res/fonts. I verified
this fix worked by creating a clean profile, adding dummy files to the
res/fonts dir, and making sure only the correct ones were deleted (in zsh):

export DIR=/data/data/org.mozilla.fennec_mcomella; \
    adb shell pm clear org.mozilla.fennec_mcomella && \
    adb shell mkdir -p $DIR/res/fonts && \
    for i in touch.ttf lol.rdf; do adb shell touch $DIR/res/fonts/$i; done && \
    adb shell ls $DIR/res/fonts

MozReview-Commit-ID: 8atpcjYjGu0
This commit is contained in:
Michael Comella 2018-08-14 18:43:42 -07:00
parent c1f1141676
commit efc0d9d92c

View File

@ -54,6 +54,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.graphics.BitmapFactory;
@ -2240,8 +2241,9 @@ public abstract class GeckoApp extends GeckoActivity
// the res/fonts directory: we no longer need to copy our
// bundled fonts out of the APK in order to use them.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=878674.
File dir = new File("res/fonts");
if (dir.exists() && dir.isDirectory()) {
final File dataDir = new File(context.getApplicationInfo().dataDir);
final File dir = new File(dataDir, "res/fonts");
if (dir.exists() && dir.isDirectory() && dir.listFiles() != null) {
for (File file : dir.listFiles()) {
if (file.isFile() && file.getName().endsWith(".ttf")) {
file.delete();