Updater: Allow toggling A/B perf mode

Change-Id: I380a39bf6008b341c8005ac548d42d2413d0d643
This commit is contained in:
TheScarastic
2018-06-12 15:10:04 +05:30
committed by Luca Stefani
parent 5a93f3f91a
commit 608789ff36
7 changed files with 41 additions and 0 deletions

View File

@@ -30,4 +30,12 @@
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:text="@string/menu_mobile_data_warning" android:text="@string/menu_mobile_data_warning"
android:textSize="16sp" /> 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> </LinearLayout>

View File

@@ -70,6 +70,7 @@
<string name="menu_export_update">Export update</string> <string name="menu_export_update">Export update</string>
<string name="menu_show_changelog">Show changelog</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_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_updates_found">New updates found</string>
<string name="snack_no_updates_found">No new updates found</string> <string name="snack_no_updates_found">No new updates found</string>

View File

@@ -409,11 +409,17 @@ public class UpdatesActivity extends UpdatesListActivity {
Switch autoCheck = view.findViewById(R.id.preferences_auto_updates_check); Switch autoCheck = view.findViewById(R.id.preferences_auto_updates_check);
Switch autoDelete = view.findViewById(R.id.preferences_auto_delete_updates); Switch autoDelete = view.findViewById(R.id.preferences_auto_delete_updates);
Switch dataWarning = view.findViewById(R.id.preferences_mobile_data_warning); 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); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
autoCheck.setChecked(prefs.getBoolean(Constants.PREF_AUTO_UPDATES_CHECK, true)); autoCheck.setChecked(prefs.getBoolean(Constants.PREF_AUTO_UPDATES_CHECK, true));
autoDelete.setChecked(prefs.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, false)); autoDelete.setChecked(prefs.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, false));
dataWarning.setChecked(prefs.getBoolean(Constants.PREF_MOBILE_DATA_WARNING, true)); dataWarning.setChecked(prefs.getBoolean(Constants.PREF_MOBILE_DATA_WARNING, true));
abPerfMode.setChecked(prefs.getBoolean(Constants.PREF_AB_PERF_MODE, false));
new AlertDialog.Builder(this) new AlertDialog.Builder(this)
.setTitle(R.string.menu_preferences) .setTitle(R.string.menu_preferences)
@@ -426,6 +432,8 @@ public class UpdatesActivity extends UpdatesListActivity {
autoDelete.isChecked()) autoDelete.isChecked())
.putBoolean(Constants.PREF_MOBILE_DATA_WARNING, .putBoolean(Constants.PREF_MOBILE_DATA_WARNING,
dataWarning.isChecked()) dataWarning.isChecked())
.putBoolean(Constants.PREF_AB_PERF_MODE,
abPerfMode.isChecked())
.apply(); .apply();
if (autoCheck.isChecked()) { if (autoCheck.isChecked()) {
@@ -434,6 +442,9 @@ public class UpdatesActivity extends UpdatesListActivity {
UpdatesCheckReceiver.cancelRepeatingUpdatesCheck(this); UpdatesCheckReceiver.cancelRepeatingUpdatesCheck(this);
UpdatesCheckReceiver.cancelUpdatesCheck(this); UpdatesCheckReceiver.cancelUpdatesCheck(this);
} }
boolean enableABPerfMode = abPerfMode.isChecked();
mUpdaterService.getUpdaterController().setPerformanceMode(enableABPerfMode);
}) })
.show(); .show();
} }

View File

@@ -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(); String zipFileUri = "file://" + file.getAbsolutePath();
mUpdateEngine.applyPayload(zipFileUri, offset, 0, headerKeyValuePairs); mUpdateEngine.applyPayload(zipFileUri, offset, 0, headerKeyValuePairs);
@@ -265,4 +269,8 @@ class ABUpdateInstaller {
return true; return true;
} }
public void setPerformanceMode(boolean enable) {
mUpdateEngine.setPerformanceMode(enable);
}
} }

View File

@@ -525,4 +525,11 @@ public class UpdaterController {
public boolean isWaitingForReboot(String downloadId) { public boolean isWaitingForReboot(String downloadId) {
return ABUpdateInstaller.isWaitingForReboot(mContext, downloadId); return ABUpdateInstaller.isWaitingForReboot(mContext, downloadId);
} }
public void setPerformanceMode(boolean enable) {
if (!Utils.isABDevice()) {
return;
}
ABUpdateInstaller.getInstance(mContext, this).setPerformanceMode(enable);
}
} }

View File

@@ -26,11 +26,13 @@ public final class Constants {
public static final String PREF_LAST_UPDATE_CHECK = "last_update_check"; 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_UPDATES_CHECK = "auto_updates_check";
public static final String PREF_AUTO_DELETE_UPDATES = "auto_delete_updates"; 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_MOBILE_DATA_WARNING = "pref_mobile_data_warning";
public static final String PREF_NEEDS_REBOOT_ID = "needs_reboot_id"; public static final String PREF_NEEDS_REBOOT_ID = "needs_reboot_id";
public static final String UNCRYPT_FILE_EXT = ".uncrypt"; 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_DATE = "ro.build.date.utc";
public static final String PROP_BUILD_VERSION = "ro.lineage.build.version"; public static final String PROP_BUILD_VERSION = "ro.lineage.build.version";
public static final String PROP_BUILD_VERSION_INCREMENTAL = "ro.build.version.incremental"; public static final String PROP_BUILD_VERSION_INCREMENTAL = "ro.build.version.incremental";

View File

@@ -334,6 +334,10 @@ public class Utils {
throw new IllegalStateException(); throw new IllegalStateException();
} }
public static boolean isABDevice() {
return SystemProperties.getBoolean(Constants.PROP_AB_DEVICE, false);
}
public static boolean isABUpdate(ZipFile zipFile) { public static boolean isABUpdate(ZipFile zipFile) {
return zipFile.getEntry(Constants.AB_PAYLOAD_BIN_PATH) != null && return zipFile.getEntry(Constants.AB_PAYLOAD_BIN_PATH) != null &&
zipFile.getEntry(Constants.AB_PAYLOAD_PROPERTIES_PATH) != null; zipFile.getEntry(Constants.AB_PAYLOAD_PROPERTIES_PATH) != null;