OpenDelta: Hold a WakeLock when installing an AB update

Otherwise they're really really slow if they even make any progress
Allow the user to disable this incase they want to
This commit is contained in:
Ido Ben-Hur 2022-12-07 00:31:16 +02:00
parent 6b5dc06b04
commit 10a91b3321
No known key found for this signature in database
GPG Key ID: 0B827201D8C20BFE
6 changed files with 42 additions and 1 deletions

View File

@ -128,6 +128,8 @@
<string name="progress_status_9">Disabled.</string>
<string name="ab_perf_mode_title">AB performance mode</string>
<string name="ab_perf_mode_summary_new">Increase priority of the update process. Might influence normal usage when an update is in progress.</string>
<string name="ab_wake_lock_title">AB wake lock</string>
<string name="ab_wake_lock_summary">Keep the CPU awake when installing an update. Makes updating fast even if the screen is off</string>
<string name="state_error_flash_file_title">Couldn\'t flash that file</string>
<string name="select_file_activity_title">Select ZIP file</string>
<string name="button_select_file">File</string>

View File

@ -26,6 +26,12 @@
android:persistent="false"
android:title="@string/ab_perf_mode_title"
android:summary="@string/ab_perf_mode_summary_new" />
<SwitchPreference
android:defaultValue="true"
android:key="ab_wake_lock"
android:persistent="false"
android:title="@string/ab_wake_lock_title"
android:summary="@string/ab_wake_lock_summary" />
</PreferenceCategory>
<PreferenceCategory
android:key="category_scheduler"

View File

@ -15,6 +15,7 @@
*/
package eu.chainfire.opendelta;
import android.os.PowerManager.WakeLock;
import android.os.UpdateEngine;
import android.os.UpdateEngineCallback;
import android.util.Log;
@ -125,6 +126,11 @@ class ABUpdate {
}
static synchronized void setInstallingUpdate(boolean installing, UpdateService us) {
final boolean enabled = us.getConfig().getABWakeLockCurrent();
final WakeLock wakeLock = us.getWakeLock();
if (installing && enabled) wakeLock.acquire();
else if (wakeLock.isHeld()) wakeLock.release();
us.getPrefs().edit()
.putBoolean(PREFS_IS_INSTALLING_UPDATE, installing).commit();
}

View File

@ -49,6 +49,7 @@ public class Config {
private final static String PREF_SECURE_MODE_NAME = "secure_mode";
private final static String PREF_SHOW_INFO_NAME = "show_info";
private final static String PREF_AB_PERF_MODE_NAME = "ab_perf_mode";
private final static String PREF_AB_WAKE_LOCK_NAME = "ab_wake_lock";
private final static boolean PREF_AB_PERF_MODE_DEFAULT = true;
private static final String PROP_AB_DEVICE = "ro.build.ab_update";
@ -188,6 +189,15 @@ public class Config {
prefs.edit().putBoolean(PREF_AB_PERF_MODE_NAME, enable).commit();
}
public boolean getABWakeLockCurrent() {
return getABPerfModeSupport() && prefs.getBoolean(
PREF_AB_WAKE_LOCK_NAME, true);
}
public void setABWakeLockCurrent(boolean enable) {
prefs.edit().putBoolean(PREF_AB_WAKE_LOCK_NAME, enable).commit();
}
public boolean getShowInfo() {
return prefs.getBoolean(PREF_SHOW_INFO_NAME, true);
}

View File

@ -48,6 +48,7 @@ public class SettingsFragment extends PreferenceFragment implements
OnPreferenceChangeListener, OnTimeSetListener {
private static final String KEY_NETWORKS = "metered_networks_config";
private static final String KEY_AB_PERF_MODE = "ab_perf_mode";
private static final String KEY_AB_WAKE_LOCK = "ab_wake_lock";
private static final String KEY_CATEGORY_DOWNLOAD = "category_download";
private static final String KEY_CATEGORY_FLASHING = "category_flashing";
private static final String KEY_SHOW_INFO = "show_info";
@ -58,6 +59,7 @@ public class SettingsFragment extends PreferenceFragment implements
private ListPreference mBatteryLevel;
private SwitchPreference mChargeOnly;
private SwitchPreference mABPerfMode;
private SwitchPreference mABWakeLock;
private Config mConfig;
private PreferenceCategory mAutoDownloadCategory;
private ListPreference mSchedulerMode;
@ -93,13 +95,21 @@ public class SettingsFragment extends PreferenceFragment implements
mShowInfo.setChecked(mConfig.getShowInfo());
if (!Config.isABDevice() || !mConfig.getABPerfModeSupport()) {
getPreferenceScreen().removePreference(findPreference(KEY_CATEGORY_FLASHING));
getPreferenceScreen().removePreference(findPreference(KEY_AB_PERF_MODE));
} else {
mABPerfMode = findPreference(KEY_AB_PERF_MODE);
mABPerfMode.setChecked(mConfig.getABPerfModeCurrent());
mABPerfMode.setOnPreferenceChangeListener(this);
}
if (!Config.isABDevice()) {
getPreferenceScreen().removePreference(findPreference(KEY_CATEGORY_FLASHING));
} else {
mABWakeLock = findPreference(KEY_AB_WAKE_LOCK);
mABWakeLock.setChecked(mConfig.getABWakeLockCurrent());
mABWakeLock.setOnPreferenceChangeListener(this);
}
mAutoDownloadCategory = findPreference(KEY_CATEGORY_DOWNLOAD);
mAutoDownloadCategory
.setEnabled(autoDownloadValue > UpdateService.PREF_AUTO_DOWNLOAD_CHECK);
@ -186,6 +196,9 @@ public class SettingsFragment extends PreferenceFragment implements
} else if (preference.equals(mABPerfMode)) {
mConfig.setABPerfModeCurrent((boolean) newValue);
return true;
} else if (preference.equals(mABWakeLock)) {
mConfig.setABWakeLockCurrent((boolean) newValue);
return true;
} else if (preference.equals(mShowInfo)) {
mConfig.setShowInfo((boolean) newValue);
return true;

View File

@ -1490,6 +1490,10 @@ public class UpdateService extends Service implements OnNetworkStateListener,
return mConfig;
}
public PowerManager.WakeLock getWakeLock() {
return mWakeLock;
}
public void setFlashFilename(String flashFilename) {
setFlashFilename(flashFilename, false);
}