Commit 608789ff authored by TheScarastic's avatar TheScarastic Committed by Luca Stefani

Updater: Allow toggling A/B perf mode

Change-Id: I380a39bf6008b341c8005ac548d42d2413d0d643
parent 5a93f3f9
......@@ -30,4 +30,12 @@
android:layout_marginBottom="16dp"
android:text="@string/menu_mobile_data_warning"
android:textSize="16sp" />
<Switch
android:id="@+id/preferences_ab_perf_mode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="@string/menu_ab_perf_mode"
android:textSize="16sp" />
</LinearLayout>
......@@ -70,6 +70,7 @@
<string name="menu_export_update">Export update</string>
<string name="menu_show_changelog">Show changelog</string>
<string name="menu_changelog_url" translatable="false">https://download.lineageos.org/<xliff:g id="device_name">%1$s</xliff:g>/changes</string>
<string name="menu_ab_perf_mode">Install updates faster</string>
<string name="snack_updates_found">New updates found</string>
<string name="snack_no_updates_found">No new updates found</string>
......
......@@ -409,11 +409,17 @@ public class UpdatesActivity extends UpdatesListActivity {
Switch autoCheck = view.findViewById(R.id.preferences_auto_updates_check);
Switch autoDelete = view.findViewById(R.id.preferences_auto_delete_updates);
Switch dataWarning = view.findViewById(R.id.preferences_mobile_data_warning);
Switch abPerfMode = view.findViewById(R.id.preferences_ab_perf_mode);
if (!Utils.isABDevice()) {
abPerfMode.setVisibility(View.GONE);
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
autoCheck.setChecked(prefs.getBoolean(Constants.PREF_AUTO_UPDATES_CHECK, true));
autoDelete.setChecked(prefs.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, false));
dataWarning.setChecked(prefs.getBoolean(Constants.PREF_MOBILE_DATA_WARNING, true));
abPerfMode.setChecked(prefs.getBoolean(Constants.PREF_AB_PERF_MODE, false));
new AlertDialog.Builder(this)
.setTitle(R.string.menu_preferences)
......@@ -426,6 +432,8 @@ public class UpdatesActivity extends UpdatesListActivity {
autoDelete.isChecked())
.putBoolean(Constants.PREF_MOBILE_DATA_WARNING,
dataWarning.isChecked())
.putBoolean(Constants.PREF_AB_PERF_MODE,
abPerfMode.isChecked())
.apply();
if (autoCheck.isChecked()) {
......@@ -434,6 +442,9 @@ public class UpdatesActivity extends UpdatesListActivity {
UpdatesCheckReceiver.cancelRepeatingUpdatesCheck(this);
UpdatesCheckReceiver.cancelUpdatesCheck(this);
}
boolean enableABPerfMode = abPerfMode.isChecked();
mUpdaterService.getUpdaterController().setPerformanceMode(enableABPerfMode);
})
.show();
}
......
......@@ -200,6 +200,10 @@ class ABUpdateInstaller {
}
}
boolean enableABPerfMode = PreferenceManager.getDefaultSharedPreferences(mContext)
.getBoolean(Constants.PREF_AB_PERF_MODE, false);
mUpdateEngine.setPerformanceMode(enableABPerfMode);
String zipFileUri = "file://" + file.getAbsolutePath();
mUpdateEngine.applyPayload(zipFileUri, offset, 0, headerKeyValuePairs);
......@@ -265,4 +269,8 @@ class ABUpdateInstaller {
return true;
}
public void setPerformanceMode(boolean enable) {
mUpdateEngine.setPerformanceMode(enable);
}
}
......@@ -525,4 +525,11 @@ public class UpdaterController {
public boolean isWaitingForReboot(String downloadId) {
return ABUpdateInstaller.isWaitingForReboot(mContext, downloadId);
}
public void setPerformanceMode(boolean enable) {
if (!Utils.isABDevice()) {
return;
}
ABUpdateInstaller.getInstance(mContext, this).setPerformanceMode(enable);
}
}
......@@ -26,11 +26,13 @@ public final class Constants {
public static final String PREF_LAST_UPDATE_CHECK = "last_update_check";
public static final String PREF_AUTO_UPDATES_CHECK = "auto_updates_check";
public static final String PREF_AUTO_DELETE_UPDATES = "auto_delete_updates";
public static final String PREF_AB_PERF_MODE = "ab_perf_mode";
public static final String PREF_MOBILE_DATA_WARNING = "pref_mobile_data_warning";
public static final String PREF_NEEDS_REBOOT_ID = "needs_reboot_id";
public static final String UNCRYPT_FILE_EXT = ".uncrypt";
public static final String PROP_AB_DEVICE = "ro.build.ab_update";
public static final String PROP_BUILD_DATE = "ro.build.date.utc";
public static final String PROP_BUILD_VERSION = "ro.lineage.build.version";
public static final String PROP_BUILD_VERSION_INCREMENTAL = "ro.build.version.incremental";
......
......@@ -334,6 +334,10 @@ public class Utils {
throw new IllegalStateException();
}
public static boolean isABDevice() {
return SystemProperties.getBoolean(Constants.PROP_AB_DEVICE, false);
}
public static boolean isABUpdate(ZipFile zipFile) {
return zipFile.getEntry(Constants.AB_PAYLOAD_BIN_PATH) != null &&
zipFile.getEntry(Constants.AB_PAYLOAD_PROPERTIES_PATH) != null;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment