Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip networking check for Phone storage as remote #1856

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 13 additions & 48 deletions app/src/main/java/com/money/manager/ex/sync/SyncManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public Context getContext() {
* @return boolean indicating if auto sync should be done.
*/
public boolean canSync() {
//
if (isPhoneStorage()) return true;
// check if online
if (!isActive()) return false;

Expand Down Expand Up @@ -131,16 +133,20 @@ public MmxDate getRemoteLastModifiedDatePreferenceFor(String remotePath) {
return new MmxDate(dateString, Constants.ISO_8601_FORMAT);
}

// public Date getModificationDateFrom(CloudMetaData remoteFile) {
// return new MmxDate(remoteFile.getModifiedAt()).toDate();
// }

public String getRemotePath() {
DatabaseMetadata db = getDatabases().getCurrent();
if (db == null) return null;

String fileName = db.remotePath;
return fileName;
return db.remotePath;
}

private boolean isPhoneStorage() {
String remotePath = getRemotePath();
if (TextUtils.isEmpty(remotePath)) {
return false;
}

return Uri.parse(remotePath).getAuthority().startsWith("com.android");
}

public void invokeSyncService(String action) {
Expand Down Expand Up @@ -184,7 +190,7 @@ public void invokeSyncService(String action) {
* remote file is set.
* @return A boolean indicating that sync service can be performed.
*/
public boolean isActive() {
private boolean isActive() {
// network is online.
NetworkUtils networkUtils = new NetworkUtils(getContext());
if (!networkUtils.isOnline()) {
Expand Down Expand Up @@ -291,51 +297,10 @@ public void useDownloadedDatabase() {
getContext().startActivity(intent);
}

/*
Private
*/

/**
* Compares the local and remote db filenames. Use for safety check before synchronization.
* @return A boolean indicating if the filenames are the same.
*/
private boolean areFileNamesSame(String localPath, String remotePath) {
if (TextUtils.isEmpty(localPath)) return false;
if (TextUtils.isEmpty(remotePath)) return false;

File localFile = new File(localPath);
String localName = localFile.getName();

File remoteFile = new File(remotePath);
String remoteName = remoteFile.getName();

return localName.equalsIgnoreCase(remoteName);
}

private RecentDatabasesProvider getDatabases() {
return mDatabases.get();
}

private File getExternalStorageDirectoryForSync() {
// todo check this after refactoring the database utils.
//MmxDatabaseUtils dbUtils = new MmxDatabaseUtils(getContext());
DatabaseManager dbManager = new DatabaseManager(getContext());
File folder = new File(dbManager.getDefaultDatabaseDirectory());

// manage folder
if (folder.exists() && folder.isDirectory() && folder.canWrite()) {
// create a folder for remote files
File folderSync = new File(folder + "/sync");
// check if folder exists otherwise create
if (!folderSync.exists()) {
if (!folderSync.mkdirs()) return getContext().getFilesDir();
}
return folderSync;
} else {
return mContext.getFilesDir();
}
}

private SyncPreferences getPreferences() {
if (mPreferences == null) {
mPreferences = new SyncPreferences(getContext());
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/com/money/manager/ex/sync/SyncService.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,6 @@ protected void onHandleWork(Intent intent) {
outMessenger = intent.getParcelableExtra(SyncService.INTENT_EXTRA_MESSENGER);
}

// check if the device is online.
NetworkUtils network = new NetworkUtils(getApplicationContext());
if (!network.isOnline()) {
Timber.i("Can't sync. Device not online.");
sendMessage(outMessenger, SyncServiceMessage.NOT_ON_WIFI);
// sendStopEvent();
return;
}

String localFilename = intent.getStringExtra(SyncConstants.INTENT_EXTRA_LOCAL_FILE);
String remoteFilename = intent.getStringExtra(SyncConstants.INTENT_EXTRA_REMOTE_FILE);
// check if file is correct
Expand All @@ -117,6 +108,15 @@ protected void onHandleWork(Intent intent) {
return;
}

// check if the device is online.
NetworkUtils network = new NetworkUtils(getApplicationContext());
if (!network.isOnline() && !Uri.parse(remoteFilename).getAuthority().startsWith("com.android")) {
Timber.i("Can't sync. Device not online.");
sendMessage(outMessenger, SyncServiceMessage.NOT_ON_WIFI);
// sendStopEvent();
return;
}

File localFile = new File(localFilename);
DatabaseMetadata currentDb = this.recentDatabasesProvider.get(localFile.getAbsolutePath());
FileStorageHelper storage = new FileStorageHelper(getApplicationContext());
Expand Down
Loading