merges triedEmptyUpdate and lastUpdateCheck prefs into one useful one
This merges the triedEmptyUpdate preference into the lastUpdateCheck pref, and uses that to determine whether the index update has ever run. It seems that lastUpdateCheck used to be used for that, but was semi-disabled. Then triedEmptyUpdate was added. This merges the two into lastUpdateCheck, which also tracks the timestamp of the last index update.
This commit is contained in:
parent
e44ca193dd
commit
0d386b824f
@ -403,7 +403,6 @@ public class FDroidApp extends Application {
|
||||
CleanCacheService.schedule(this);
|
||||
|
||||
notificationHelper = new NotificationHelper(getApplicationContext());
|
||||
UpdateService.schedule(getApplicationContext());
|
||||
bluetoothAdapter = getBluetoothAdapter();
|
||||
|
||||
// There are a couple things to pay attention to with this config: memory usage,
|
||||
@ -452,7 +451,12 @@ public class FDroidApp extends Application {
|
||||
.build();
|
||||
ImageLoader.getInstance().init(config);
|
||||
|
||||
if (preferences.isIndexNeverUpdated()) {
|
||||
// force this check to ensure it starts fetching the index on initial runs
|
||||
networkState = ConnectivityMonitorService.getNetworkState(this);
|
||||
}
|
||||
ConnectivityMonitorService.registerAndStart(this);
|
||||
UpdateService.schedule(getApplicationContext());
|
||||
|
||||
FDroidApp.initWifiSettings();
|
||||
WifiStateChangeService.start(this, null);
|
||||
|
@ -101,7 +101,6 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
|
||||
public static final String PREF_PROXY_PORT = "proxyPort";
|
||||
public static final String PREF_SHOW_NFC_DURING_SWAP = "showNfcDuringSwap";
|
||||
public static final String PREF_POST_PRIVILEGED_INSTALL = "postPrivilegedInstall";
|
||||
public static final String PREF_TRIED_EMPTY_UPDATE = "triedEmptyUpdate";
|
||||
public static final String PREF_PREVENT_SCREENSHOTS = "preventScreenshots";
|
||||
public static final String PREF_PANIC_EXIT = "pref_panic_exit";
|
||||
public static final String PREF_PANIC_HIDE = "pref_panic_hide";
|
||||
@ -114,10 +113,14 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
|
||||
public static final int OVER_NETWORK_ON_DEMAND = 1;
|
||||
public static final int OVER_NETWORK_ALWAYS = 2;
|
||||
|
||||
// not shown in Settings
|
||||
private static final String PREF_LAST_UPDATE_CHECK = "lastUpdateCheck";
|
||||
|
||||
// these preferences are not listed in preferences.xml so the defaults are set here
|
||||
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
|
||||
public static final String DEFAULT_PROXY_HOST = "127.0.0.1"; // TODO move to preferences.xml
|
||||
public static final int DEFAULT_PROXY_PORT = 8118; // TODO move to preferences.xml
|
||||
private static final int DEFAULT_LAST_UPDATE_CHECK = -1;
|
||||
private static final boolean DEFAULT_SHOW_NFC_DURING_SWAP = true;
|
||||
private static final boolean DEFAULT_POST_PRIVILEGED_INSTALL = false;
|
||||
private static final boolean DEFAULT_PANIC_EXIT = true;
|
||||
@ -321,18 +324,23 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used the first time F-Droid is installed to flag whether or not we have tried to request
|
||||
* apps from the repo. This is used so that when there is no apps available, we can differentiate
|
||||
* between whether the repos actually have no apps (in which case we don't need to continue
|
||||
* asking), or whether there is no apps because we have never actually asked to update the repos.
|
||||
*/
|
||||
public boolean hasTriedEmptyUpdate() {
|
||||
return preferences.getBoolean(PREF_TRIED_EMPTY_UPDATE, IGNORED_B);
|
||||
public long getLastUpdateCheck() {
|
||||
return preferences.getLong(PREF_LAST_UPDATE_CHECK, DEFAULT_LAST_UPDATE_CHECK);
|
||||
}
|
||||
|
||||
public void setTriedEmptyUpdate(boolean value) {
|
||||
preferences.edit().putBoolean(PREF_TRIED_EMPTY_UPDATE, value).apply();
|
||||
public void setLastUpdateCheck(long lastUpdateCheck) {
|
||||
preferences.edit().putLong(PREF_LAST_UPDATE_CHECK, lastUpdateCheck).apply();
|
||||
}
|
||||
|
||||
public void resetLastUpdateCheck() {
|
||||
setLastUpdateCheck(DEFAULT_LAST_UPDATE_CHECK);
|
||||
}
|
||||
|
||||
/**
|
||||
* The first time the app has been run since fresh install or clearing all data.
|
||||
*/
|
||||
public boolean isIndexNeverUpdated() {
|
||||
return getLastUpdateCheck() == DEFAULT_LAST_UPDATE_CHECK;
|
||||
}
|
||||
|
||||
public boolean getUnstableUpdates() {
|
||||
|
@ -29,7 +29,6 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
@ -41,7 +40,6 @@ import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.JobIntentService;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
@ -82,7 +80,6 @@ public class UpdateService extends JobIntentService {
|
||||
public static final int STATUS_ERROR_LOCAL_SMALL = 4;
|
||||
public static final int STATUS_INFO = 5;
|
||||
|
||||
private static final String STATE_LAST_UPDATED = "lastUpdateCheck";
|
||||
private static final int JOB_ID = 0xfedcba;
|
||||
|
||||
private static final int NOTIFY_ID_UPDATING = 0;
|
||||
@ -498,10 +495,7 @@ public class UpdateService extends JobIntentService {
|
||||
}
|
||||
}
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
|
||||
SharedPreferences.Editor e = prefs.edit();
|
||||
e.putLong(STATE_LAST_UPDATED, System.currentTimeMillis());
|
||||
e.apply();
|
||||
fdroidPrefs.setLastUpdateCheck(System.currentTimeMillis());
|
||||
|
||||
if (errorRepos == 0) {
|
||||
if (changes) {
|
||||
|
@ -1095,7 +1095,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||
private static void resetTransient(SQLiteDatabase db) {
|
||||
Utils.debugLog(TAG, "Removing all index tables, they will be recreated next time F-Droid updates.");
|
||||
|
||||
Preferences.get().setTriedEmptyUpdate(false);
|
||||
Preferences.get().resetLastUpdateCheck();
|
||||
|
||||
db.beginTransaction();
|
||||
try {
|
||||
@ -1147,7 +1147,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||
return;
|
||||
}
|
||||
|
||||
Preferences.get().setTriedEmptyUpdate(false);
|
||||
Preferences.get().resetLastUpdateCheck();
|
||||
|
||||
db.execSQL("drop table " + AppMetadataTable.NAME);
|
||||
db.execSQL("drop table " + ApkTable.NAME);
|
||||
|
@ -164,10 +164,8 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
|
||||
* don't try to do it automatically again.
|
||||
*/
|
||||
private void initialRepoUpdateIfRequired() {
|
||||
Preferences prefs = Preferences.get();
|
||||
if (!prefs.hasTriedEmptyUpdate()) {
|
||||
if (!Preferences.get().isIndexNeverUpdated()) {
|
||||
Utils.debugLog(TAG, "We haven't done an update yet. Forcing repo update.");
|
||||
prefs.setTriedEmptyUpdate(true);
|
||||
UpdateService.updateNow(this);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user