Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 85773c3b authored by Jorge Ruesga's avatar Jorge Ruesga
Browse files

cmfm: don't allow load files bigger than available memory



Change-Id: I6b1bc0d1aecfac2c6f1948b63eb0a51921c0497b
Signed-off-by: default avatarJorge Ruesga <jorge@ruesga.com>
parent 4eeecf99
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -427,7 +427,7 @@ public class EditorActivity extends Activity implements TextWatcher {
    FileSystemObject mFso;

    private int mBufferSize;
    private int mMaxFileSize;
    private long mMaxFileSize;

    /**
     * @hide
@@ -542,10 +542,10 @@ public class EditorActivity extends Activity implements TextWatcher {
        setContentView(R.layout.editor);

        // Get the limit vars
        this.mBufferSize =
                getApplicationContext().getResources().getInteger(R.integer.buffer_size);
        this.mMaxFileSize =
                getApplicationContext().getResources().getInteger(R.integer.editor_max_file_size);
        this.mBufferSize = getResources().getInteger(R.integer.buffer_size);
        long availMem = AndroidHelper.getAvailableMemory(this);
        this.mMaxFileSize = Math.min(availMem,
                getResources().getInteger(R.integer.editor_max_file_size));

        //Initialize
        initTitleActionBar();
@@ -616,7 +616,7 @@ public class EditorActivity extends Activity implements TextWatcher {
        configuration.setContentDescription(getString(R.string.actionbar_button_overflow_cd));

        View status = findViewById(R.id.editor_status);
        boolean showOptionsMenu = AndroidHelper.showOptionsMenu(getApplicationContext());
        boolean showOptionsMenu = AndroidHelper.showOptionsMenu(this);
        configuration.setVisibility(showOptionsMenu ? View.VISIBLE : View.GONE);
        this.mOptionsAnchorView = showOptionsMenu ? configuration : status;

+10 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.cyanogenmod.filemanager.util;

import android.app.ActivityManager;
import android.app.ActivityManager.MemoryInfo;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
@@ -115,4 +117,12 @@ public final class AndroidHelper {
        return AndroidHelper.hasSupportForMultipleUsers(context)
                && !AndroidHelper.isUserOwner();
    }

    public static long getAvailableMemory(Context context) {
        ActivityManager am = (ActivityManager) context.getSystemService(
                Context.ACTIVITY_SERVICE);
        MemoryInfo memoryInfo = new MemoryInfo();
        am.getMemoryInfo(memoryInfo);
        return memoryInfo.availMem;
    }
}