Loading res/layout/preferences_dialog.xml +18 −4 Original line number Diff line number Diff line Loading @@ -7,14 +7,28 @@ android:paddingStart="24dp" android:paddingTop="16dp"> <Switch android:id="@+id/preferences_auto_updates_check" <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/menu_auto_updates_check" android:textColor="@color/inverted" android:textSize="16sp" /> <Spinner android:id="@+id/preferences_auto_updates_check_interval" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:entries="@array/menu_auto_updates_check_interval_entries" /> </LinearLayout> <Switch android:id="@+id/preferences_auto_delete_updates" android:layout_width="match_parent" Loading res/values/arrays.xml 0 → 100644 +24 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2019 The LineageOS Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <resources> <string-array name="menu_auto_updates_check_interval_entries" translatable="false"> <item>@string/menu_auto_updates_check_interval_never</item> <item>@string/menu_auto_updates_check_interval_daily</item> <item>@string/menu_auto_updates_check_interval_weekly</item> <item>@string/menu_auto_updates_check_interval_monthly</item> </string-array> </resources> res/values/strings.xml +4 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,10 @@ <string name="menu_refresh">Refresh</string> <string name="menu_preferences">Preferences</string> <string name="menu_auto_updates_check">Auto updates check</string> <string name="menu_auto_updates_check_interval_daily">Once a day</string> <string name="menu_auto_updates_check_interval_weekly">Once a week</string> <string name="menu_auto_updates_check_interval_monthly">Once a month</string> <string name="menu_auto_updates_check_interval_never">Never</string> <string name="menu_auto_delete_updates">Delete updates when installed</string> <string name="menu_delete_update">Delete</string> <string name="menu_copy_url">Copy URL</string> Loading src/org/lineageos/updater/UpdatesActivity.java +8 −6 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ import android.view.View; import android.view.animation.Animation; import android.view.animation.LinearInterpolator; import android.view.animation.RotateAnimation; import android.widget.Spinner; import android.widget.Switch; import android.widget.TextView; Loading Loading @@ -292,7 +293,7 @@ public class UpdatesActivity extends UpdatesListActivity { long millis = System.currentTimeMillis(); preferences.edit().putLong(Constants.PREF_LAST_UPDATE_CHECK, millis).apply(); updateLastCheckedString(); if (json.exists() && preferences.getBoolean(Constants.PREF_AUTO_UPDATES_CHECK, true) && if (json.exists() && Utils.isUpdateCheckEnabled(this) && Utils.checkForNewUpdates(json, jsonNew)) { UpdatesCheckReceiver.updateRepeatingUpdatesCheck(this); } Loading Loading @@ -406,7 +407,8 @@ public class UpdatesActivity extends UpdatesListActivity { private void showPreferencesDialog() { View view = LayoutInflater.from(this).inflate(R.layout.preferences_dialog, null); Switch autoCheck = view.findViewById(R.id.preferences_auto_updates_check); Spinner autoCheckInterval = view.findViewById(R.id.preferences_auto_updates_check_interval); 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); Loading @@ -416,7 +418,7 @@ public class UpdatesActivity extends UpdatesListActivity { } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); autoCheck.setChecked(prefs.getBoolean(Constants.PREF_AUTO_UPDATES_CHECK, true)); autoCheckInterval.setSelection(Utils.getUpdateCheckSetting(this)); 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)); Loading @@ -426,8 +428,8 @@ public class UpdatesActivity extends UpdatesListActivity { .setView(view) .setOnDismissListener(dialogInterface -> { prefs.edit() .putBoolean(Constants.PREF_AUTO_UPDATES_CHECK, autoCheck.isChecked()) .putInt(Constants.PREF_AUTO_UPDATES_CHECK_INTERVAL, autoCheckInterval.getSelectedItemPosition()) .putBoolean(Constants.PREF_AUTO_DELETE_UPDATES, autoDelete.isChecked()) .putBoolean(Constants.PREF_MOBILE_DATA_WARNING, Loading @@ -436,7 +438,7 @@ public class UpdatesActivity extends UpdatesListActivity { abPerfMode.isChecked()) .apply(); if (autoCheck.isChecked()) { if (Utils.isUpdateCheckEnabled(this)) { UpdatesCheckReceiver.scheduleRepeatingUpdatesCheck(this); } else { UpdatesCheckReceiver.cancelRepeatingUpdatesCheck(this); Loading src/org/lineageos/updater/UpdatesCheckReceiver.java +12 −54 Original line number Diff line number Diff line Loading @@ -59,7 +59,8 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); if (!preferences.getBoolean(Constants.PREF_AUTO_UPDATES_CHECK, true)) { if (!Utils.isUpdateCheckEnabled(context)) { return; } Loading Loading @@ -155,15 +156,19 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { } public static void scheduleRepeatingUpdatesCheck(Context context) { long millisToNextRelease = millisToNextRelease(context); if (!Utils.isUpdateCheckEnabled(context)) { return; } PendingIntent updateCheckIntent = getRepeatingUpdatesCheckIntent(context); AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + millisToNextRelease, AlarmManager.INTERVAL_DAY, updateCheckIntent); alarmMgr.setRepeating(AlarmManager.RTC, System.currentTimeMillis() + Utils.getUpdateCheckInterval(context), Utils.getUpdateCheckInterval(context), updateCheckIntent); Date nextCheckDate = new Date(System.currentTimeMillis() + millisToNextRelease); Log.d(TAG, "Setting daily updates check: " + nextCheckDate); Date nextCheckDate = new Date(System.currentTimeMillis() + Utils.getUpdateCheckInterval(context)); Log.d(TAG, "Setting automatic updates check: " + nextCheckDate); } public static void cancelRepeatingUpdatesCheck(Context context) { Loading Loading @@ -194,51 +199,4 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { alarmMgr.cancel(getUpdatesCheckIntent(context)); Log.d(TAG, "Cancelling pending one-shot check"); } private static long millisToNextRelease(Context context) { final long extraMillis = 3 * AlarmManager.INTERVAL_HOUR; List<UpdateInfo> updates = null; try { updates = Utils.parseJson(Utils.getCachedUpdateList(context), false); } catch (IOException | JSONException ignored) { } if (updates == null || updates.size() == 0) { return SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY; } long buildTimestamp = 0; for (UpdateInfo update : updates) { if (update.getTimestamp() > buildTimestamp) { buildTimestamp = update.getTimestamp(); } } buildTimestamp *= 1000; Calendar c = Calendar.getInstance(); long now = c.getTimeInMillis(); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); c.setTimeInMillis(c.getTimeInMillis() + millisSinceMidnight(buildTimestamp)); long millisToNextRelease = (c.getTimeInMillis() - now); millisToNextRelease += extraMillis; if (c.getTimeInMillis() < now) { millisToNextRelease += AlarmManager.INTERVAL_DAY; } return millisToNextRelease; } private static long millisSinceMidnight(long millis) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(millis); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return millis - c.getTimeInMillis(); } } Loading
res/layout/preferences_dialog.xml +18 −4 Original line number Diff line number Diff line Loading @@ -7,14 +7,28 @@ android:paddingStart="24dp" android:paddingTop="16dp"> <Switch android:id="@+id/preferences_auto_updates_check" <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/menu_auto_updates_check" android:textColor="@color/inverted" android:textSize="16sp" /> <Spinner android:id="@+id/preferences_auto_updates_check_interval" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:entries="@array/menu_auto_updates_check_interval_entries" /> </LinearLayout> <Switch android:id="@+id/preferences_auto_delete_updates" android:layout_width="match_parent" Loading
res/values/arrays.xml 0 → 100644 +24 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2019 The LineageOS Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <resources> <string-array name="menu_auto_updates_check_interval_entries" translatable="false"> <item>@string/menu_auto_updates_check_interval_never</item> <item>@string/menu_auto_updates_check_interval_daily</item> <item>@string/menu_auto_updates_check_interval_weekly</item> <item>@string/menu_auto_updates_check_interval_monthly</item> </string-array> </resources>
res/values/strings.xml +4 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,10 @@ <string name="menu_refresh">Refresh</string> <string name="menu_preferences">Preferences</string> <string name="menu_auto_updates_check">Auto updates check</string> <string name="menu_auto_updates_check_interval_daily">Once a day</string> <string name="menu_auto_updates_check_interval_weekly">Once a week</string> <string name="menu_auto_updates_check_interval_monthly">Once a month</string> <string name="menu_auto_updates_check_interval_never">Never</string> <string name="menu_auto_delete_updates">Delete updates when installed</string> <string name="menu_delete_update">Delete</string> <string name="menu_copy_url">Copy URL</string> Loading
src/org/lineageos/updater/UpdatesActivity.java +8 −6 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ import android.view.View; import android.view.animation.Animation; import android.view.animation.LinearInterpolator; import android.view.animation.RotateAnimation; import android.widget.Spinner; import android.widget.Switch; import android.widget.TextView; Loading Loading @@ -292,7 +293,7 @@ public class UpdatesActivity extends UpdatesListActivity { long millis = System.currentTimeMillis(); preferences.edit().putLong(Constants.PREF_LAST_UPDATE_CHECK, millis).apply(); updateLastCheckedString(); if (json.exists() && preferences.getBoolean(Constants.PREF_AUTO_UPDATES_CHECK, true) && if (json.exists() && Utils.isUpdateCheckEnabled(this) && Utils.checkForNewUpdates(json, jsonNew)) { UpdatesCheckReceiver.updateRepeatingUpdatesCheck(this); } Loading Loading @@ -406,7 +407,8 @@ public class UpdatesActivity extends UpdatesListActivity { private void showPreferencesDialog() { View view = LayoutInflater.from(this).inflate(R.layout.preferences_dialog, null); Switch autoCheck = view.findViewById(R.id.preferences_auto_updates_check); Spinner autoCheckInterval = view.findViewById(R.id.preferences_auto_updates_check_interval); 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); Loading @@ -416,7 +418,7 @@ public class UpdatesActivity extends UpdatesListActivity { } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); autoCheck.setChecked(prefs.getBoolean(Constants.PREF_AUTO_UPDATES_CHECK, true)); autoCheckInterval.setSelection(Utils.getUpdateCheckSetting(this)); 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)); Loading @@ -426,8 +428,8 @@ public class UpdatesActivity extends UpdatesListActivity { .setView(view) .setOnDismissListener(dialogInterface -> { prefs.edit() .putBoolean(Constants.PREF_AUTO_UPDATES_CHECK, autoCheck.isChecked()) .putInt(Constants.PREF_AUTO_UPDATES_CHECK_INTERVAL, autoCheckInterval.getSelectedItemPosition()) .putBoolean(Constants.PREF_AUTO_DELETE_UPDATES, autoDelete.isChecked()) .putBoolean(Constants.PREF_MOBILE_DATA_WARNING, Loading @@ -436,7 +438,7 @@ public class UpdatesActivity extends UpdatesListActivity { abPerfMode.isChecked()) .apply(); if (autoCheck.isChecked()) { if (Utils.isUpdateCheckEnabled(this)) { UpdatesCheckReceiver.scheduleRepeatingUpdatesCheck(this); } else { UpdatesCheckReceiver.cancelRepeatingUpdatesCheck(this); Loading
src/org/lineageos/updater/UpdatesCheckReceiver.java +12 −54 Original line number Diff line number Diff line Loading @@ -59,7 +59,8 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); if (!preferences.getBoolean(Constants.PREF_AUTO_UPDATES_CHECK, true)) { if (!Utils.isUpdateCheckEnabled(context)) { return; } Loading Loading @@ -155,15 +156,19 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { } public static void scheduleRepeatingUpdatesCheck(Context context) { long millisToNextRelease = millisToNextRelease(context); if (!Utils.isUpdateCheckEnabled(context)) { return; } PendingIntent updateCheckIntent = getRepeatingUpdatesCheckIntent(context); AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + millisToNextRelease, AlarmManager.INTERVAL_DAY, updateCheckIntent); alarmMgr.setRepeating(AlarmManager.RTC, System.currentTimeMillis() + Utils.getUpdateCheckInterval(context), Utils.getUpdateCheckInterval(context), updateCheckIntent); Date nextCheckDate = new Date(System.currentTimeMillis() + millisToNextRelease); Log.d(TAG, "Setting daily updates check: " + nextCheckDate); Date nextCheckDate = new Date(System.currentTimeMillis() + Utils.getUpdateCheckInterval(context)); Log.d(TAG, "Setting automatic updates check: " + nextCheckDate); } public static void cancelRepeatingUpdatesCheck(Context context) { Loading Loading @@ -194,51 +199,4 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { alarmMgr.cancel(getUpdatesCheckIntent(context)); Log.d(TAG, "Cancelling pending one-shot check"); } private static long millisToNextRelease(Context context) { final long extraMillis = 3 * AlarmManager.INTERVAL_HOUR; List<UpdateInfo> updates = null; try { updates = Utils.parseJson(Utils.getCachedUpdateList(context), false); } catch (IOException | JSONException ignored) { } if (updates == null || updates.size() == 0) { return SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY; } long buildTimestamp = 0; for (UpdateInfo update : updates) { if (update.getTimestamp() > buildTimestamp) { buildTimestamp = update.getTimestamp(); } } buildTimestamp *= 1000; Calendar c = Calendar.getInstance(); long now = c.getTimeInMillis(); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); c.setTimeInMillis(c.getTimeInMillis() + millisSinceMidnight(buildTimestamp)); long millisToNextRelease = (c.getTimeInMillis() - now); millisToNextRelease += extraMillis; if (c.getTimeInMillis() < now) { millisToNextRelease += AlarmManager.INTERVAL_DAY; } return millisToNextRelease; } private static long millisSinceMidnight(long millis) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(millis); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return millis - c.getTimeInMillis(); } }