Fix review stuff

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2017-08-07 16:29:13 +02:00 committed by AndyScherzinger
parent 656d5c1ca9
commit 5e974670b4
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
16 changed files with 109 additions and 214 deletions

View file

@ -59,10 +59,6 @@
</intent-filter>
</activity>
<activity
android:name=".ui.activity.FileDisplayActivity"
tools:node="remove"/>
<activity-alias
android:name=".authentication.AuthenticatorActivity"
android:targetActivity=".authentication.ModifiedAuthenticatorActivity"

View file

@ -20,7 +20,9 @@
*/
package com.owncloud.android.datamodel;
/*
Model for filesystem data from the database
*/
public class FileSystemDataSet {
private int id;

View file

@ -30,6 +30,9 @@ import com.owncloud.android.lib.common.utils.Log_OC;
import java.util.HashSet;
import java.util.Set;
/*
Provider for stored filesystem data
*/
public class FilesystemDataProvider {
static private final String TAG = FilesystemDataProvider.class.getSimpleName();

View file

@ -371,11 +371,12 @@ public class UploadsStorageManager extends Observable {
Account account = AccountUtils.getCurrentOwnCloudAccount(mContext);
OCUpload[] uploads = getUploads(
ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_IN_PROGRESS.value + " OR " +
ProviderTableMeta.UPLOADS_LAST_RESULT + "==" + UploadResult.DELAYED_FOR_WIFI.getValue() + " OR " +
ProviderTableMeta.UPLOADS_LAST_RESULT + "==" + UploadResult.LOCK_FAILED.getValue() + " OR " +
ProviderTableMeta.UPLOADS_LAST_RESULT + "==" + UploadResult.DELAYED_FOR_CHARGING.getValue() + " AND " +
ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?",
ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_IN_PROGRESS.value +
" OR " + ProviderTableMeta.UPLOADS_LAST_RESULT + "==" + UploadResult.DELAYED_FOR_WIFI.getValue() +
" OR " + ProviderTableMeta.UPLOADS_LAST_RESULT + "==" + UploadResult.LOCK_FAILED.getValue() +
" OR " + ProviderTableMeta.UPLOADS_LAST_RESULT +
"==" + UploadResult.DELAYED_FOR_CHARGING.getValue() +
" AND " + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?",
new String[]{account.name}
);

View file

@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.owncloud.android.services;
package com.owncloud.android.jobs;
import android.accounts.Account;
import android.accounts.AccountManager;

View file

@ -1,122 +0,0 @@
/**
* Nextcloud Android client application
*
* @author Tobias Kaminsky
* Copyright (C) 2017 Mario Danic
* Copyright (C) 2016 Tobias Kaminsky
* Copyright (C) 2016 Nextcloud
* <p>
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
* <p>
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.owncloud.android.jobs;
import android.accounts.Account;
import android.content.Context;
import android.os.PowerManager;
import android.support.annotation.NonNull;
import com.evernote.android.job.Job;
import com.evernote.android.job.util.support.PersistableBundleCompat;
import com.owncloud.android.MainApp;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.operations.UploadFileOperation;
import com.owncloud.android.utils.MimeTypeUtil;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException;
public class AutoUploadJob extends Job {
public static final String TAG = "AutoUploadJob";
public static final String LOCAL_PATH = "filePath";
public static final String REMOTE_PATH = "remotePath";
public static final String ACCOUNT = "account";
public static final String UPLOAD_BEHAVIOUR = "uploadBehaviour";
public static final String REQUIRES_WIFI = "requiresWifi";
public static final String REQUIRES_CHARGING = "requiresCharging";
@NonNull
@Override
protected Result onRunJob(Params params) {
final Context context = MainApp.getAppContext();
PowerManager powerManager = (PowerManager) context.getSystemService(context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
TAG);
wakeLock.acquire();
PersistableBundleCompat bundle = params.getExtras();
final String filePath = bundle.getString(LOCAL_PATH, "");
final String remotePath = bundle.getString(REMOTE_PATH, "");
final Account account = AccountUtils.getOwnCloudAccountByName(context, bundle.getString(ACCOUNT, ""));
final Integer uploadBehaviour = bundle.getInt(UPLOAD_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_FORGET);
final boolean requiresWifi = bundle.getBoolean(REQUIRES_WIFI, false);
final boolean requiresCharging = bundle.getBoolean(REQUIRES_CHARGING, false);
File file = new File(filePath);
// File can be deleted between job generation and job execution. If file does not exist, just ignore it
if (file.exists()) {
final String mimeType = MimeTypeUtil.getBestMimeTypeByFilename(file.getAbsolutePath());
final FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
FileChannel channel = null;
FileLock lock = null;
try {
channel = new RandomAccessFile(file, "rw").getChannel();
lock = channel.tryLock();
requester.uploadFileWithOverwrite(
context,
account,
filePath,
remotePath,
uploadBehaviour,
mimeType,
true, // create parent folder if not existent
UploadFileOperation.CREATED_AS_INSTANT_PICTURE,
requiresWifi,
requiresCharging,
true
);
lock.release();
wakeLock.release();
return Result.SUCCESS;
} catch (FileNotFoundException e) {
Log_OC.d(TAG, "Something went wrong while trying to access file");
} catch (OverlappingFileLockException e) {
Log_OC.d(TAG, "Overlapping file lock exception");
} catch (IOException e) {
Log_OC.d(TAG, "IO exception");
}
}
wakeLock.release();
return Result.RESCHEDULE;
}
}

View file

@ -30,7 +30,6 @@ import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.evernote.android.job.Job;
import com.evernote.android.job.JobManager;
import com.evernote.android.job.util.support.PersistableBundleCompat;
import com.owncloud.android.MainApp;
import com.owncloud.android.authentication.AccountUtils;
@ -53,10 +52,16 @@ import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
/*
Job that:
- restarts existing jobs if required
- finds new and modified files since we last run this
- creates upload tasks
*/
public class FilesSyncJob extends Job {
public static final String TAG = "FilesSyncJob";
public static String SKIP_CUSTOM = "skipCustom";
public static final String SKIP_CUSTOM = "skipCustom";
@NonNull
@Override
@ -84,62 +89,60 @@ public class FilesSyncJob extends Job {
if ((syncedFolder.isEnabled()) && (!skipCustom || MediaFolder.CUSTOM != syncedFolder.getType())) {
for (String path : filesystemDataProvider.getFilesForUpload(syncedFolder.getLocalPath(),
Long.toString(syncedFolder.getId()))) {
if (JobManager.instance().getAllJobRequests().size() < 80) {
File file = new File(path);
File file = new File(path);
Long lastModificationTime = file.lastModified();
final Locale currentLocale = context.getResources().getConfiguration().locale;
Long lastModificationTime = file.lastModified();
final Locale currentLocale = context.getResources().getConfiguration().locale;
if (MediaFolder.IMAGE == syncedFolder.getType()) {
String mimetypeString = FileStorageUtils.getMimeTypeFromName(file.getAbsolutePath());
if ("image/jpeg".equalsIgnoreCase(mimetypeString) || "image/tiff".
equalsIgnoreCase(mimetypeString)) {
try {
ExifInterface exifInterface = new ExifInterface(file.getAbsolutePath());
String exifDate = exifInterface.getAttribute(ExifInterface.TAG_DATETIME);
if (!TextUtils.isEmpty(exifDate)) {
ParsePosition pos = new ParsePosition(0);
SimpleDateFormat sFormatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss",
currentLocale);
sFormatter.setTimeZone(TimeZone.getTimeZone(TimeZone.getDefault().getID()));
Date dateTime = sFormatter.parse(exifDate, pos);
lastModificationTime = dateTime.getTime();
}
} catch (IOException e) {
Log_OC.d(TAG, "Failed to get the proper time " + e.getLocalizedMessage());
if (MediaFolder.IMAGE == syncedFolder.getType()) {
String mimetypeString = FileStorageUtils.getMimeTypeFromName(file.getAbsolutePath());
if ("image/jpeg".equalsIgnoreCase(mimetypeString) || "image/tiff".
equalsIgnoreCase(mimetypeString)) {
try {
ExifInterface exifInterface = new ExifInterface(file.getAbsolutePath());
String exifDate = exifInterface.getAttribute(ExifInterface.TAG_DATETIME);
if (!TextUtils.isEmpty(exifDate)) {
ParsePosition pos = new ParsePosition(0);
SimpleDateFormat sFormatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss",
currentLocale);
sFormatter.setTimeZone(TimeZone.getTimeZone(TimeZone.getDefault().getID()));
Date dateTime = sFormatter.parse(exifDate, pos);
lastModificationTime = dateTime.getTime();
}
} catch (IOException e) {
Log_OC.d(TAG, "Failed to get the proper time " + e.getLocalizedMessage());
}
}
boolean needsCharging = syncedFolder.getChargingOnly();
boolean needsWifi = syncedFolder.getWifiOnly();
String mimeType = MimeTypeUtil.getBestMimeTypeByFilename(file.getAbsolutePath());
Account account = AccountUtils.getOwnCloudAccountByName(context, syncedFolder.getAccount());
requester.uploadFileWithOverwrite(
context,
account,
file.getAbsolutePath(),
FileStorageUtils.getInstantUploadFilePath(
currentLocale,
syncedFolder.getRemotePath(), file.getName(),
lastModificationTime,
syncedFolder.getSubfolderByDate()),
syncedFolder.getUploadAction(),
mimeType,
true, // create parent folder if not existent
UploadFileOperation.CREATED_AS_INSTANT_PICTURE,
needsWifi,
needsCharging,
true
);
filesystemDataProvider.updateFilesystemFileAsSentForUpload(path,
Long.toString(syncedFolder.getId()));
}
boolean needsCharging = syncedFolder.getChargingOnly();
boolean needsWifi = syncedFolder.getWifiOnly();
String mimeType = MimeTypeUtil.getBestMimeTypeByFilename(file.getAbsolutePath());
Account account = AccountUtils.getOwnCloudAccountByName(context, syncedFolder.getAccount());
requester.uploadFileWithOverwrite(
context,
account,
file.getAbsolutePath(),
FileStorageUtils.getInstantUploadFilePath(
currentLocale,
syncedFolder.getRemotePath(), file.getName(),
lastModificationTime,
syncedFolder.getSubfolderByDate()),
syncedFolder.getUploadAction(),
mimeType,
true, // create parent folder if not existent
UploadFileOperation.CREATED_AS_INSTANT_PICTURE,
needsWifi,
needsCharging,
true
);
filesystemDataProvider.updateFilesystemFileAsSentForUpload(path,
Long.toString(syncedFolder.getId()));
}
}
}

View file

@ -22,7 +22,6 @@ package com.owncloud.android.jobs;
import com.evernote.android.job.Job;
import com.evernote.android.job.JobCreator;
import com.owncloud.android.services.AccountRemovalJob;
/**
* Job creator for android-job
@ -32,8 +31,6 @@ public class NCJobCreator implements JobCreator {
@Override
public Job create(String tag) {
switch (tag) {
case AutoUploadJob.TAG:
return new AutoUploadJob();
case ContactsBackupJob.TAG:
return new ContactsBackupJob();
case ContactsImportJob.TAG:

View file

@ -32,6 +32,9 @@ import com.owncloud.android.utils.FilesSyncHelper;
import java.util.concurrent.TimeUnit;
/*
Job that triggers new FilesSyncJob in case new photo or video were detected
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class NContentObserverJob extends JobService {
@Override

View file

@ -479,7 +479,7 @@ public class UploadFileOperation extends SyncOperation {
try {
fileLock.release();
} catch (IOException e) {
Log_OC.d(TAG, "Failed to unlock file with path " + mOriginalStoragePath);
Log_OC.e(TAG, "Failed to unlock file with path " + mOriginalStoragePath);
}
}

View file

@ -48,10 +48,9 @@ import com.owncloud.android.datamodel.ArbitraryDataProvider;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.files.services.FileDownloader;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.jobs.AutoUploadJob;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.services.AccountRemovalJob;
import com.owncloud.android.jobs.AccountRemovalJob;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.ui.adapter.AccountListAdapter;
import com.owncloud.android.ui.adapter.AccountListItem;
@ -419,7 +418,7 @@ public class ManageAccountsActivity extends FileActivity
// schedule job
PersistableBundleCompat bundle = new PersistableBundleCompat();
bundle.putString(AutoUploadJob.ACCOUNT, account.name);
bundle.putString(AccountRemovalJob.ACCOUNT, account.name);
new JobRequest.Builder(AccountRemovalJob.TAG)
.setExecutionWindow(1_000L, 10_000L)

View file

@ -383,11 +383,16 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
return !pathname.isDirectory();
}
});
Arrays.sort(files, new Comparator<File>(){
public int compare(File f1, File f2)
{
return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
} });
if (files != null) {
Arrays.sort(files, new Comparator<File>() {
public int compare(File f1, File f2) {
return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
}
});
} else {
files = new File[]{};
}
return files;
}

View file

@ -76,6 +76,8 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
private static final String SCREEN_NAME = "Uploads";
private static final String EXPERT_MODE = "expert_mode";
private UploadMessagesReceiver mUploadMessagesReceiver;
private Menu mMenu;
@ -267,7 +269,7 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
public boolean onCreateOptionsMenu(Menu menu) {
SharedPreferences appPrefs =
PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
if (appPrefs.getBoolean("expert_mode", false)) {
if (appPrefs.getBoolean(EXPERT_MODE, false)) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.upload_list_menu, menu);
mMenu = menu;

View file

@ -4,17 +4,17 @@
* @author Andy Scherzinger
* Copyright (C) 2016 Andy Scherzinger
* Copyright (C) 2016 Nextcloud
* <p>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
* <p>
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
* <p>
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View file

@ -59,9 +59,15 @@ import java.io.File;
import java.io.IOException;
import java.util.List;
/*
Various utilities that make auto upload tick
*/
public class FilesSyncHelper {
public static final String TAG = "FileSyncHelper";
public static final String GLOBAL = "global";
public static final String SYNCEDFOLDERINITIATED = "syncedFolderIntitiated_";
public static int ContentSyncJobId = 315;
public static void insertAllDBEntriesForSyncedFolder(SyncedFolder syncedFolder) {
@ -73,13 +79,13 @@ public class FilesSyncHelper {
double currentTimeInSeconds = currentTime / 1000.0;
String currentTimeString = Long.toString((long) currentTimeInSeconds);
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + syncedFolder.getId();
String syncedFolderInitiatedKey = SYNCEDFOLDERINITIATED + syncedFolder.getId();
boolean dryRun = TextUtils.isEmpty(arbitraryDataProvider.getValue
("global", syncedFolderInitiatedKey));
(GLOBAL, syncedFolderInitiatedKey));
if (MediaFolder.IMAGE == syncedFolder.getType()) {
if (dryRun) {
arbitraryDataProvider.storeOrUpdateKeyValue("global", syncedFolderInitiatedKey,
arbitraryDataProvider.storeOrUpdateKeyValue(GLOBAL, syncedFolderInitiatedKey,
currentTimeString);
} else {
FilesSyncHelper.insertContentIntoDB(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI
@ -91,7 +97,7 @@ public class FilesSyncHelper {
} else if (MediaFolder.VIDEO == syncedFolder.getType()) {
if (dryRun) {
arbitraryDataProvider.storeOrUpdateKeyValue("global", syncedFolderInitiatedKey,
arbitraryDataProvider.storeOrUpdateKeyValue(GLOBAL, syncedFolderInitiatedKey,
currentTimeString);
} else {
FilesSyncHelper.insertContentIntoDB(android.provider.MediaStore.Video.Media.INTERNAL_CONTENT_URI,
@ -104,13 +110,13 @@ public class FilesSyncHelper {
try {
if (dryRun) {
arbitraryDataProvider.storeOrUpdateKeyValue("global", syncedFolderInitiatedKey,
arbitraryDataProvider.storeOrUpdateKeyValue(GLOBAL, syncedFolderInitiatedKey,
currentTimeString);
} else {
FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(contentResolver);
Path path = Paths.get(syncedFolder.getLocalPath());
String dateInitiated = arbitraryDataProvider.getValue("global",
String dateInitiated = arbitraryDataProvider.getValue(GLOBAL,
syncedFolderInitiatedKey);
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
@ -135,7 +141,7 @@ public class FilesSyncHelper {
}
} catch (IOException e) {
Log.d(TAG, "Something went wrong while indexing files for auto upload");
Log.e(TAG, "Something went wrong while indexing files for auto upload " + e.getLocalizedMessage());
}
}
}
@ -175,8 +181,8 @@ public class FilesSyncHelper {
path = path + "%";
}
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + syncedFolder.getId();
String dateInitiated = arbitraryDataProvider.getValue("global", syncedFolderInitiatedKey);
String syncedFolderInitiatedKey = SYNCEDFOLDERINITIATED + syncedFolder.getId();
String dateInitiated = arbitraryDataProvider.getValue(GLOBAL, syncedFolderInitiatedKey);
cursor = context.getContentResolver().query(uri, projection, MediaStore.MediaColumns.DATA + " LIKE ?",
new String[]{path}, null);
@ -265,7 +271,6 @@ public class FilesSyncHelper {
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (hasImageFolders || hasVideoFolders) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
scheduleJobOnN(hasImageFolders, hasVideoFolders, force);
@ -275,7 +280,6 @@ public class FilesSyncHelper {
cancelJobOnN();
}
}
}
}
public static void scheduleFilesSyncIfNeeded() {
@ -302,8 +306,7 @@ public class FilesSyncHelper {
boolean force) {
JobScheduler jobScheduler = MainApp.getAppContext().getSystemService(JobScheduler.class);
if (((android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) && (hasImageFolders || hasVideoFolders)) &&
(!isContentObserverJobScheduled() || force)) {
if ((hasImageFolders || hasVideoFolders) && (!isContentObserverJobScheduled() || force)) {
JobInfo.Builder builder = new JobInfo.Builder(ContentSyncJobId, new ComponentName(MainApp.getAppContext(),
NContentObserverJob.class.getName()));
builder.addTriggerContentUri(new JobInfo.TriggerContentUri(android.provider.MediaStore.

View file

@ -29,6 +29,9 @@ import com.evernote.android.job.JobRequest;
import com.evernote.android.job.util.Device;
import com.owncloud.android.MainApp;
/*
Helper for setting up network and power receivers
*/
public class ReceiversHelper {
public static void registerNetworkChangeReceiver() {