- The default RAM value is now device aware

- Hide notch setting defaults to false.
This commit is contained in:
SerpentSpirale 2021-08-13 12:17:20 +02:00
parent 35f0bf3277
commit 35a0b66ec1
7 changed files with 50 additions and 19 deletions

View file

@ -194,7 +194,7 @@ public class MainActivity extends BaseMainActivity {
if (requestCode == 1 && resultCode == Activity.RESULT_OK) {
// Reload PREF_DEFAULTCTRL_PATH
LauncherPreferences.loadPreferences();
LauncherPreferences.loadPreferences(getApplicationContext());
try {
mControlLayout.loadLayout(LauncherPreferences.PREF_DEFAULTCTRL_PATH);
} catch (IOException e) {

View file

@ -346,7 +346,7 @@ public class PojavLoginActivity extends BaseActivity
mLockSelectJRE.wait();
}
}
LauncherPreferences.loadPreferences();
LauncherPreferences.loadPreferences(getApplicationContext());
}
catch(Throwable e){
Tools.showError(this, e);

View file

@ -815,4 +815,17 @@ public final class Tools {
}
}
public static int getTotalDeviceMemory(Context ctx){
ActivityManager actManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
actManager.getMemoryInfo(memInfo);
return (int) (memInfo.totalMem / 1048576L);
}
public static int getFreeDeviceMemory(Context ctx){
ActivityManager actManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
actManager.getMemoryInfo(memInfo);
return (int) (memInfo.availMem / 1048576L);
}
}

View file

@ -11,6 +11,8 @@ import net.kdt.pojavlaunch.Tools;
import android.content.*;
import static net.kdt.pojavlaunch.Architecture.is32BitsDevice;
import static net.kdt.pojavlaunch.Tools.getFreeDeviceMemory;
import static net.kdt.pojavlaunch.Tools.getTotalDeviceMemory;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_NOTCH_SIZE;
public class LauncherPreferenceFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener
@ -50,16 +52,14 @@ public class LauncherPreferenceFragment extends PreferenceFragmentCompat impleme
int maxRAM;
int freeMem = (int) (Runtime.getRuntime().freeMemory() / 1048576L);
ActivityManager actManager = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
actManager.getMemoryInfo(memInfo);
int deviceRam = getTotalDeviceMemory(getContext());
CustomSeekBarPreference seek7 = findPreference("allocation");
seek7.setMin(256);
if(is32BitsDevice()) maxRAM = Math.min(1100, (int)(memInfo.totalMem /1024 /1024));
else maxRAM = freeMem > 4096 ? freeMem : (int)(memInfo.totalMem /1024 /1024);
if(is32BitsDevice()) maxRAM = Math.min(1100, deviceRam);
else maxRAM = deviceRam - (deviceRam < 3064 ? 800 : 1024); //To have a minimum for the device to breathe
seek7.setMax(maxRAM);
seek7.setValue(LauncherPreferences.PREF_RAM_ALLOCATION);
@ -90,6 +90,6 @@ public class LauncherPreferenceFragment extends PreferenceFragmentCompat impleme
@Override
public void onSharedPreferenceChanged(SharedPreferences p, String s) {
LauncherPreferences.loadPreferences();
LauncherPreferences.loadPreferences(getContext());
}
}

View file

@ -3,6 +3,7 @@ package net.kdt.pojavlaunch.prefs;
import android.content.*;
import net.kdt.pojavlaunch.*;
import net.kdt.pojavlaunch.multirt.MultiRTUtils;
import net.kdt.pojavlaunch.utils.JREUtils;
public class LauncherPreferences
{
@ -26,9 +27,9 @@ public class LauncherPreferences
public static boolean PREF_CHECK_LIBRARY_SHA = true;
public static boolean PREF_DISABLE_GESTURES = false;
public static float PREF_MOUSESPEED = 1f;
public static int PREF_RAM_ALLOCATION=300;
public static int PREF_RAM_ALLOCATION;
public static String PREF_DEFAULT_RUNTIME;
public static void loadPreferences() {
public static void loadPreferences(Context ctx) {
PREF_RENDERER = DEFAULT_PREF.getString("renderer", "opengles2");
PREF_BUTTONSIZE = DEFAULT_PREF.getInt("buttonscale", 100);
@ -45,10 +46,7 @@ public class LauncherPreferences
PREF_LANGUAGE = DEFAULT_PREF.getString("language", "default");
PREF_CHECK_LIBRARY_SHA = DEFAULT_PREF.getBoolean("checkLibraries",true);
PREF_DISABLE_GESTURES = DEFAULT_PREF.getBoolean("disableGestures",false);
PREF_RAM_ALLOCATION = DEFAULT_PREF.getInt("allocation",300);
// Get double of max Android heap to set default heap size
int androidHeap = (int) (Runtime.getRuntime().maxMemory() / 1024l / 512l);
int doubleAndroidHeap = androidHeap * 2;
PREF_RAM_ALLOCATION = DEFAULT_PREF.getInt("allocation", findBestRAMAllocation(ctx));
PREF_CUSTOM_JAVA_ARGS = DEFAULT_PREF.getString("javaArgs", "");
/*
if (PREF_CUSTOM_JAVA_ARGS.isEmpty()) {
@ -82,7 +80,7 @@ public class LauncherPreferences
PREF_RENDERER = "opengles" + PREF_RENDERER;
}
String argLwjglLibname = "-Dorg.lwjgl.opengl.libname=";
for (String arg : PREF_CUSTOM_JAVA_ARGS.split(" ")) {
for (String arg : JREUtils.parseJavaArguments(PREF_CUSTOM_JAVA_ARGS)) {
if (arg.startsWith(argLwjglLibname)) {
// purge arg
DEFAULT_PREF.edit().putString("javaArgs",
@ -100,4 +98,24 @@ public class LauncherPreferences
LauncherPreferences.DEFAULT_PREF.edit().putString("defaultRuntime",LauncherPreferences.PREF_DEFAULT_RUNTIME).apply();
}
}
/**
* This functions aims at finding the best default RAM amount,
* according to the RAM amount of the physical device.
* Put not enough RAM ? Minecraft will lag and crash.
* Put too much RAM ?
* The GC will lag, android won't be able to breathe properly.
* @param ctx Context needed to get the total memory of the device.
* @return The best default value found.
*/
private static int findBestRAMAllocation(Context ctx){
int deviceRam = Tools.getTotalDeviceMemory(ctx);
if (deviceRam < 1024) return 300;
if (deviceRam < 1536) return 450;
if (deviceRam < 2048) return 600;
if (deviceRam < 3064) return 936;
if (deviceRam < 4096) return 1148;
if (deviceRam < 6144) return 1536;
return 2048; //Default RAM allocation for 64 bits
}
}

View file

@ -16,7 +16,7 @@ public class LocaleUtils {
public static Context setLocale(Context context) {
if (LauncherPreferences.DEFAULT_PREF == null) {
LauncherPreferences.DEFAULT_PREF = PreferenceManager.getDefaultSharedPreferences(context);
LauncherPreferences.loadPreferences();
LauncherPreferences.loadPreferences(context);
}
Locale locale;

View file

@ -46,7 +46,7 @@
app2:showSeekBarValue="true"
app2:selectable="false"/>
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:defaultValue="false"
android:key="ignoreNotch"
android:summary="@string/mcl_setting_subtitle_ignore_notch"
android:title="@string/mcl_setting_title_ignore_notch"