mirror of
https://github.com/nextcloud/android.git
synced 2024-12-19 15:33:00 +03:00
Check BOOT_COMPLETED BroadcastReceiver Usage
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
2a3ade90b7
commit
9810020dec
3 changed files with 48 additions and 25 deletions
|
@ -352,7 +352,8 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log_OC.d("Debug", "Failed to disable uri exposure");
|
Log_OC.d("Debug", "Failed to disable uri exposure");
|
||||||
}
|
}
|
||||||
initSyncOperations(this,
|
initSyncOperations(true,
|
||||||
|
this,
|
||||||
preferences,
|
preferences,
|
||||||
uploadsStorageManager,
|
uploadsStorageManager,
|
||||||
accountManager,
|
accountManager,
|
||||||
|
@ -363,7 +364,7 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC
|
||||||
viewThemeUtils,
|
viewThemeUtils,
|
||||||
walledCheckCache,
|
walledCheckCache,
|
||||||
syncedFolderProvider);
|
syncedFolderProvider);
|
||||||
initContactsBackup(accountManager, backgroundJobManager);
|
initContactsBackup(accountManager, backgroundJobManager, true);
|
||||||
notificationChannels();
|
notificationChannels();
|
||||||
|
|
||||||
if (backgroundJobManager != null) {
|
if (backgroundJobManager != null) {
|
||||||
|
@ -505,7 +506,11 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initContactsBackup(UserAccountManager accountManager, BackgroundJobManager backgroundJobManager) {
|
public static void initContactsBackup(UserAccountManager accountManager, BackgroundJobManager backgroundJobManager, boolean shouldSchedulePeriodicContactsBackup) {
|
||||||
|
if (!shouldSchedulePeriodicContactsBackup) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProviderImpl(appContext.get());
|
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProviderImpl(appContext.get());
|
||||||
if (accountManager == null) {
|
if (accountManager == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -606,7 +611,14 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param shouldSync Android 15 restricts BOOT_COMPLETED broadcast receivers from starting certain foreground
|
||||||
|
* services (dataSync, mediaPlayback, mediaProjection ...), throwing a
|
||||||
|
* ForegroundServiceStartNotAllowedException if violated. Under the hood, WorkManager manages and
|
||||||
|
* runs a foreground service. The shouldSync flag ensures proper WorkManager usage.
|
||||||
|
*/
|
||||||
public static void initSyncOperations(
|
public static void initSyncOperations(
|
||||||
|
final boolean shouldSync,
|
||||||
final Context context,
|
final Context context,
|
||||||
final AppPreferences preferences,
|
final AppPreferences preferences,
|
||||||
final UploadsStorageManager uploadsStorageManager,
|
final UploadsStorageManager uploadsStorageManager,
|
||||||
|
@ -618,6 +630,7 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC
|
||||||
final ViewThemeUtils viewThemeUtils,
|
final ViewThemeUtils viewThemeUtils,
|
||||||
final WalledCheckCache walledCheckCache,
|
final WalledCheckCache walledCheckCache,
|
||||||
final SyncedFolderProvider syncedFolderProvider) {
|
final SyncedFolderProvider syncedFolderProvider) {
|
||||||
|
|
||||||
updateToAutoUpload(context);
|
updateToAutoUpload(context);
|
||||||
cleanOldEntries(clock);
|
cleanOldEntries(clock);
|
||||||
updateAutoUploadEntries(clock);
|
updateAutoUploadEntries(clock);
|
||||||
|
@ -630,11 +643,12 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!preferences.isAutoUploadInitialized()) {
|
if (!preferences.isAutoUploadInitialized() && shouldSync) {
|
||||||
FilesSyncHelper.startFilesSyncForAllFolders(syncedFolderProvider, backgroundJobManager,false, new String[]{});
|
FilesSyncHelper.startFilesSyncForAllFolders(syncedFolderProvider, backgroundJobManager,false, new String[]{});
|
||||||
preferences.setAutoUploadInit(true);
|
preferences.setAutoUploadInit(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shouldSync) {
|
||||||
FilesSyncHelper.scheduleFilesSyncForAllFoldersIfNeeded(appContext.get(), syncedFolderProvider, backgroundJobManager);
|
FilesSyncHelper.scheduleFilesSyncForAllFoldersIfNeeded(appContext.get(), syncedFolderProvider, backgroundJobManager);
|
||||||
FilesSyncHelper.restartUploadsIfNeeded(
|
FilesSyncHelper.restartUploadsIfNeeded(
|
||||||
uploadsStorageManager,
|
uploadsStorageManager,
|
||||||
|
@ -643,22 +657,26 @@ public class MainApp extends Application implements HasAndroidInjector, NetworkC
|
||||||
powerManagementService);
|
powerManagementService);
|
||||||
|
|
||||||
backgroundJobManager.scheduleOfflineSync();
|
backgroundJobManager.scheduleOfflineSync();
|
||||||
|
}
|
||||||
|
|
||||||
ReceiversHelper.registerNetworkChangeReceiver(uploadsStorageManager,
|
ReceiversHelper.registerNetworkChangeReceiver(uploadsStorageManager,
|
||||||
accountManager,
|
accountManager,
|
||||||
connectivityService,
|
connectivityService,
|
||||||
powerManagementService,
|
powerManagementService,
|
||||||
walledCheckCache);
|
walledCheckCache,
|
||||||
|
shouldSync);
|
||||||
|
|
||||||
ReceiversHelper.registerPowerChangeReceiver(uploadsStorageManager,
|
ReceiversHelper.registerPowerChangeReceiver(uploadsStorageManager,
|
||||||
accountManager,
|
accountManager,
|
||||||
connectivityService,
|
connectivityService,
|
||||||
powerManagementService);
|
powerManagementService,
|
||||||
|
shouldSync);
|
||||||
|
|
||||||
ReceiversHelper.registerPowerSaveReceiver(uploadsStorageManager,
|
ReceiversHelper.registerPowerSaveReceiver(uploadsStorageManager,
|
||||||
accountManager,
|
accountManager,
|
||||||
connectivityService,
|
connectivityService,
|
||||||
powerManagementService);
|
powerManagementService,
|
||||||
|
shouldSync);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void notificationChannels() {
|
public static void notificationChannels() {
|
||||||
|
|
|
@ -14,6 +14,7 @@ package com.owncloud.android.files;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
import com.nextcloud.client.account.UserAccountManager;
|
import com.nextcloud.client.account.UserAccountManager;
|
||||||
import com.nextcloud.client.core.Clock;
|
import com.nextcloud.client.core.Clock;
|
||||||
|
@ -62,7 +63,10 @@ public class BootupBroadcastReceiver extends BroadcastReceiver {
|
||||||
AndroidInjection.inject(this, context);
|
AndroidInjection.inject(this, context);
|
||||||
|
|
||||||
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
|
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
|
||||||
MainApp.initSyncOperations(context,
|
boolean isApiLevel35OrHigher = (Build.VERSION.SDK_INT >= 35);
|
||||||
|
|
||||||
|
MainApp.initSyncOperations(!isApiLevel35OrHigher,
|
||||||
|
context,
|
||||||
preferences,
|
preferences,
|
||||||
uploadsStorageManager,
|
uploadsStorageManager,
|
||||||
accountManager,
|
accountManager,
|
||||||
|
@ -74,7 +78,7 @@ public class BootupBroadcastReceiver extends BroadcastReceiver {
|
||||||
walledCheckCache,
|
walledCheckCache,
|
||||||
syncedFolderProvider
|
syncedFolderProvider
|
||||||
);
|
);
|
||||||
MainApp.initContactsBackup(accountManager, backgroundJobManager);
|
MainApp.initContactsBackup(accountManager, backgroundJobManager, !isApiLevel35OrHigher);
|
||||||
} else {
|
} else {
|
||||||
Log_OC.d(TAG, "Getting wrong intent: " + intent.getAction());
|
Log_OC.d(TAG, "Getting wrong intent: " + intent.getAction());
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,8 @@ public final class ReceiversHelper {
|
||||||
final UserAccountManager accountManager,
|
final UserAccountManager accountManager,
|
||||||
final ConnectivityService connectivityService,
|
final ConnectivityService connectivityService,
|
||||||
final PowerManagementService powerManagementService,
|
final PowerManagementService powerManagementService,
|
||||||
final WalledCheckCache walledCheckCache) {
|
final WalledCheckCache walledCheckCache,
|
||||||
|
final boolean shouldRegister) {
|
||||||
Context context = MainApp.getAppContext();
|
Context context = MainApp.getAppContext();
|
||||||
|
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
|
@ -48,7 +49,7 @@ public final class ReceiversHelper {
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
DNSCache.clear();
|
DNSCache.clear();
|
||||||
walledCheckCache.clear();
|
walledCheckCache.clear();
|
||||||
if (connectivityService.getConnectivity().isConnected()) {
|
if (connectivityService.getConnectivity().isConnected() && shouldRegister) {
|
||||||
FilesSyncHelper.restartUploadsIfNeeded(uploadsStorageManager,
|
FilesSyncHelper.restartUploadsIfNeeded(uploadsStorageManager,
|
||||||
accountManager,
|
accountManager,
|
||||||
connectivityService,
|
connectivityService,
|
||||||
|
@ -64,8 +65,8 @@ public final class ReceiversHelper {
|
||||||
final UploadsStorageManager uploadsStorageManager,
|
final UploadsStorageManager uploadsStorageManager,
|
||||||
final UserAccountManager accountManager,
|
final UserAccountManager accountManager,
|
||||||
final ConnectivityService connectivityService,
|
final ConnectivityService connectivityService,
|
||||||
final PowerManagementService powerManagementService
|
final PowerManagementService powerManagementService,
|
||||||
) {
|
final boolean shouldRegister) {
|
||||||
Context context = MainApp.getAppContext();
|
Context context = MainApp.getAppContext();
|
||||||
|
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
|
@ -75,7 +76,7 @@ public final class ReceiversHelper {
|
||||||
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
|
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (Intent.ACTION_POWER_CONNECTED.equals(intent.getAction())) {
|
if (Intent.ACTION_POWER_CONNECTED.equals(intent.getAction()) && shouldRegister) {
|
||||||
FilesSyncHelper.restartUploadsIfNeeded(uploadsStorageManager,
|
FilesSyncHelper.restartUploadsIfNeeded(uploadsStorageManager,
|
||||||
accountManager,
|
accountManager,
|
||||||
connectivityService,
|
connectivityService,
|
||||||
|
@ -91,8 +92,8 @@ public final class ReceiversHelper {
|
||||||
final UploadsStorageManager uploadsStorageManager,
|
final UploadsStorageManager uploadsStorageManager,
|
||||||
final UserAccountManager accountManager,
|
final UserAccountManager accountManager,
|
||||||
final ConnectivityService connectivityService,
|
final ConnectivityService connectivityService,
|
||||||
final PowerManagementService powerManagementService
|
final PowerManagementService powerManagementService,
|
||||||
) {
|
final boolean shouldRegister) {
|
||||||
Context context = MainApp.getAppContext();
|
Context context = MainApp.getAppContext();
|
||||||
|
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
|
@ -101,7 +102,7 @@ public final class ReceiversHelper {
|
||||||
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
|
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (!powerManagementService.isPowerSavingEnabled()) {
|
if (!powerManagementService.isPowerSavingEnabled() && shouldRegister) {
|
||||||
FilesSyncHelper.restartUploadsIfNeeded(uploadsStorageManager,
|
FilesSyncHelper.restartUploadsIfNeeded(uploadsStorageManager,
|
||||||
accountManager,
|
accountManager,
|
||||||
connectivityService,
|
connectivityService,
|
||||||
|
|
Loading…
Reference in a new issue