Ticket #26574: 0001-Bug-26574-Save-TBA-updates-in-the-internal-android-s.patch

File 0001-Bug-26574-Save-TBA-updates-in-the-internal-android-s.patch, 2.7 KB (added by igt0, 17 months ago)
  • mobile/android/base/java/org/mozilla/gecko/updater/UpdateService.java

    From 570bcdb0a9fc2be1a7a8b1b5e94d7374fc306547 Mon Sep 17 00:00:00 2001
    From: Igor Oliveira <igt0@torproject.org>
    Date: Fri, 29 Jun 2018 16:48:24 -0300
    Subject: [PATCH] Bug 26574 - Save TBA updates in the internal android storage
    
    Fennec stores the updated APK in the user's external storage. That,
    violates the tor browser disk avoidance rule.
    
    This patch updates the UpdateService to store it in the internal app
    storage directory.
    ---
     .../org/mozilla/gecko/updater/UpdateService.java   | 29 ++++++++--------------
     1 file changed, 11 insertions(+), 18 deletions(-)
    
    diff --git a/mobile/android/base/java/org/mozilla/gecko/updater/UpdateService.java b/mobile/android/base/java/org/mozilla/gecko/updater/UpdateService.java
    index 6f2a0b091803..cc74af9ec015 100644
    a b public class UpdateService extends IntentService { 
    287287
    288288        Log.i(LOGTAG, "update available, buildID = " + info.buildID);
    289289
    290         Permissions.from(this)
    291                 .withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
    292                 .doNotPrompt()
    293                 .andFallback(new Runnable() {
    294                     @Override
    295                     public void run() {
    296                         showPermissionNotification();
    297                         sendCheckUpdateResult(CheckUpdateResult.NOT_AVAILABLE);
    298                     }
    299                 })
    300                 .run(new Runnable() {
    301                     @Override
    302                     public void run() {
    303                         startDownload(info, flags);
    304                     }
    305                 });
     290        startDownload(info, flags);
    306291    }
    307292
    308293    private void startDownload(UpdateInfo info, int flags) {
    public class UpdateService extends IntentService { 
    535520            return null;
    536521        }
    537522
    538         File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
     523        File path = getApplicationContext().getDir("update", Context.MODE_PRIVATE);
    539524        path.mkdirs();
    540525        String fileName = new File(url.getFile()).getName();
    541         File downloadFile = new File(path, fileName);
     526
     527        File downloadFile;
     528        try {
     529            downloadFile = File.createTempFile(fileName, "apk", path);
     530        } catch (java.io.IOException e) {
     531            Log.e(LOGTAG, "Unable to create update file", e);
     532            return null;
     533        }
     534        downloadFile.setReadable(true, false);
    542535
    543536        if (!overwriteExisting && info.buildID.equals(getLastBuildID()) && downloadFile.exists()) {
    544537            // The last saved buildID is the same as the one for the current update. We also have a file