mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-07-30 09:06:35 -04:00
port 1.x swap startup to 2.x
The whole swap setup was designed around having certain tiny background
processes start at app start. They are designed to be very low impact, run
at lowest priority, and be scheduled via WorkManager.
port was in 0f73f9ca0e
This commit is contained in:
10
app/src/basic/kotlin/org/fdroid/AppFull.kt
Normal file
10
app/src/basic/kotlin/org/fdroid/AppFull.kt
Normal file
@@ -0,0 +1,10 @@
|
||||
package org.fdroid
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/** In the basic flavor, this class is just a placeholder. */
|
||||
class AppFull {
|
||||
companion object {
|
||||
fun onCreate(context: Context) = println()
|
||||
}
|
||||
}
|
||||
@@ -363,8 +363,6 @@ public class SwapService extends Service {
|
||||
@Nullable
|
||||
private Timer timer;
|
||||
|
||||
private final WifiStateChangeReceiver wifiStateChangeReceiver = new WifiStateChangeReceiver();
|
||||
|
||||
public class Binder extends android.os.Binder {
|
||||
public SwapService getService() {
|
||||
return SwapService.this;
|
||||
@@ -375,8 +373,6 @@ public class SwapService extends Service {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
startForeground(NOTIFICATION, createNotification());
|
||||
WifiStateChangeService.start(this, null);
|
||||
WifiStateChangeService.registerReceiver(this, wifiStateChangeReceiver);
|
||||
localBroadcastManager = LocalBroadcastManager.getInstance(this);
|
||||
swapPreferences = getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
|
||||
|
||||
@@ -486,7 +482,6 @@ public class SwapService extends Service {
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
Utils.debugLog(TAG, "Destroying service, will disable swapping if required, and unregister listeners.");
|
||||
WifiStateChangeService.unregisterReceiver(this, wifiStateChangeReceiver);
|
||||
Preferences.get().unregisterLocalRepoHttpsListeners(httpsEnabledListener);
|
||||
localBroadcastManager.unregisterReceiver(onWifiChange);
|
||||
localBroadcastManager.unregisterReceiver(bluetoothPeerFound);
|
||||
|
||||
@@ -84,18 +84,14 @@ public class WifiStateChangeService extends Worker {
|
||||
super(context, workerParams);
|
||||
}
|
||||
|
||||
public static void registerReceiver(Context context, WifiStateChangeReceiver wifiStateChangeReceiver) {
|
||||
public static void registerReceiver(Context context) {
|
||||
ContextCompat.registerReceiver(
|
||||
context,
|
||||
wifiStateChangeReceiver,
|
||||
new WifiStateChangeReceiver(),
|
||||
new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION),
|
||||
ContextCompat.RECEIVER_NOT_EXPORTED);
|
||||
}
|
||||
|
||||
public static void unregisterReceiver(Context context, WifiStateChangeReceiver wifiStateChangeReceiver) {
|
||||
context.unregisterReceiver(wifiStateChangeReceiver);
|
||||
}
|
||||
|
||||
public static void start(Context context, @Nullable Intent intent) {
|
||||
int networkInfoStateInt = NETWORK_INFO_STATE_NOT_SET;
|
||||
if (intent != null) {
|
||||
|
||||
14
app/src/full/kotlin/org/fdroid/AppFull.kt
Normal file
14
app/src/full/kotlin/org/fdroid/AppFull.kt
Normal file
@@ -0,0 +1,14 @@
|
||||
package org.fdroid
|
||||
|
||||
import android.content.Context;
|
||||
import org.fdroid.fdroid.nearby.WifiStateChangeService
|
||||
|
||||
/** Wrapper class to isolate things only needed in the full flavor. */
|
||||
class AppFull {
|
||||
companion object {
|
||||
fun onCreate(context: Context) {
|
||||
WifiStateChangeService.registerReceiver(context)
|
||||
WifiStateChangeService.start(context, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import org.acra.config.dialog
|
||||
import org.acra.config.mailSender
|
||||
import org.acra.data.StringFormat.JSON
|
||||
import org.acra.ktx.initAcra
|
||||
import org.fdroid.AppFull
|
||||
import org.fdroid.BuildConfig.APPLICATION_ID
|
||||
import org.fdroid.BuildConfig.VERSION_NAME
|
||||
import org.fdroid.download.DownloadRequest
|
||||
@@ -106,6 +107,8 @@ class App : Application(), Configuration.Provider, SingletonImageLoader.Factory
|
||||
|
||||
RepoUpdateWorker.scheduleOrCancel(applicationContext, settingsManager.repoUpdates)
|
||||
AppUpdateWorker.scheduleOrCancel(applicationContext, settingsManager.autoUpdateApps)
|
||||
|
||||
AppFull.onCreate(applicationContext)
|
||||
}
|
||||
|
||||
private fun isAcraProces(): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user