fix sharing for beta

This commit is contained in:
tobiasKaminsky 2016-07-30 18:38:21 +02:00
parent 9587af3e9d
commit ac695b7444
14 changed files with 102 additions and 34 deletions

View file

@ -195,6 +195,8 @@
<intent-filter>
<!--action android:name="android.net.conn.CONNECTIVITY_CHANGE"/-->
<action android:name="android.net.wifi.STATE_CHANGE"/>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
</intent-filter>
</receiver>
<receiver android:name=".files.InstantUploadBroadcastReceiver">
@ -212,13 +214,6 @@
<data android:mimeType="video/*" />
</intent-filter>
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
</intent-filter>
</receiver>
<receiver android:name=".files.BootupBroadcastReceiver" >
<intent-filter>

View file

@ -293,6 +293,7 @@
<string name="instant_upload_on_wifi">Upload pictures via wifi only</string>
<string name="instant_video_upload_on_wifi">Upload videos via wifi only</string>
<string name="instant_video_upload_on_charging">Upload when charging only</string>
<string name="instant_upload_on_charging">Upload when charging only</string>
<string name="instant_upload_path">/InstantUpload</string>
<string name="conflict_title">File conflict</string>
<string name="conflict_message">Which files do you want to keep? If you select both versions, the local file will have a number added to its name.</string>
@ -458,6 +459,7 @@
<string name="local_file_not_found_toast">The file was not found in the local file system</string>
<string name="confirmation_remove_files_alert">Do you really want to remove the selected items?</string>
<string name="confirmation_remove_folders_alert">Do you really want to remove the selected items and their contents?</string>
<string name="uploads_view_upload_status_waiting_for_charging">Waiting for device charging</string>
<plurals name="items_selected_count">
<!--
As a developer, you should always supply "one" and "other"

View file

@ -36,11 +36,8 @@
android:title="@string/instant_upload_on_wifi"
android:key="instant_upload_on_wifi"/>
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
android:dependency="instant_uploading"
android:disableDependentsState="true"
android:title="@string/instant_upload_on_charging"
android:key="instant_upload_on_charging"/>
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
android:key="instant_video_uploading"
android:title="@string/prefs_instant_video_upload"
@ -56,8 +53,6 @@
android:title="@string/instant_video_upload_on_wifi"
android:key="instant_video_upload_on_wifi"/>
<com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
android:dependency="instant_video_uploading"
android:disableDependentsState="true"
android:title="@string/instant_video_upload_on_charging"
android:key="instant_video_upload_on_charging"/>
<com.owncloud.android.ui.dialog.OwnCloudListPreference android:key="prefs_instant_behaviour"

View file

@ -365,7 +365,8 @@ public class UploadsStorageManager extends Observable {
public OCUpload[] getCurrentAndPendingUploads() {
return getUploads(
ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_IN_PROGRESS.value + " OR " +
ProviderTableMeta.UPLOADS_LAST_RESULT + "==" + UploadResult.DELAYED_FOR_WIFI.getValue(),
ProviderTableMeta.UPLOADS_LAST_RESULT + "==" + UploadResult.DELAYED_FOR_WIFI.getValue() + " OR " +
ProviderTableMeta.UPLOADS_LAST_RESULT + "==" + UploadResult.DELAYED_FOR_CHARGING.getValue(),
null
);
}
@ -388,10 +389,11 @@ public class UploadsStorageManager extends Observable {
* Get all failed uploads, except for those that were not performed due to lack of Wifi connection
* @return Array of failed uploads, except for those that were not performed due to lack of Wifi connection.
*/
public OCUpload[] getFailedButNotDelayedForWifiUploads() {
public OCUpload[] getFailedButNotDelayedUploads() {
return getUploads(
ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_FAILED.value + " AND " +
ProviderTableMeta.UPLOADS_LAST_RESULT + "<>" + UploadResult.DELAYED_FOR_WIFI.getValue(),
ProviderTableMeta.UPLOADS_LAST_RESULT + "<>" + UploadResult.DELAYED_FOR_WIFI.getValue() + " AND " +
ProviderTableMeta.UPLOADS_LAST_RESULT + "<>" + UploadResult.DELAYED_FOR_CHARGING.getValue(),
null
);
}
@ -400,11 +402,12 @@ public class UploadsStorageManager extends Observable {
return mContentResolver;
}
public long clearFailedButNotDelayedForWifiUploads() {
public long clearFailedButNotDelayedUploads() {
long result = getDB().delete(
ProviderTableMeta.CONTENT_URI_UPLOADS,
ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_FAILED.value + " AND " +
ProviderTableMeta.UPLOADS_LAST_RESULT + "<>" + UploadResult.DELAYED_FOR_WIFI.getValue(),
ProviderTableMeta.UPLOADS_LAST_RESULT + "<>" + UploadResult.DELAYED_FOR_WIFI.getValue() + " AND " +
ProviderTableMeta.UPLOADS_LAST_RESULT + "<>" + UploadResult.DELAYED_FOR_CHARGING.getValue(),
null
);
Log_OC.d(TAG, "delete all failed uploads but those delayed for Wifi");
@ -426,14 +429,15 @@ public class UploadsStorageManager extends Observable {
return result;
}
public long clearAllFinishedButNotDelayedForWifiUploads() {
public long clearAllFinishedButNotDelayedUploads() {
String[] whereArgs = new String[2];
whereArgs[0] = String.valueOf(UploadStatus.UPLOAD_SUCCEEDED.value);
whereArgs[1] = String.valueOf(UploadStatus.UPLOAD_FAILED.value);
long result = getDB().delete(
ProviderTableMeta.CONTENT_URI_UPLOADS,
ProviderTableMeta.UPLOADS_STATUS + "=? OR " + ProviderTableMeta.UPLOADS_STATUS + "=? AND " +
ProviderTableMeta.UPLOADS_LAST_RESULT + "<>" + UploadResult.DELAYED_FOR_WIFI.getValue(),
ProviderTableMeta.UPLOADS_LAST_RESULT + "<>" + UploadResult.DELAYED_FOR_WIFI.getValue() + " AND " +
ProviderTableMeta.UPLOADS_LAST_RESULT + "<>" + UploadResult.DELAYED_FOR_CHARGING.getValue(),
whereArgs
);
Log_OC.d(TAG, "delete all finished uploads");

View file

@ -67,6 +67,12 @@ public abstract class PreferenceManager {
public static boolean instantVideoUploadViaWiFiOnly(Context context) {
return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_VIDEO_UPLOAD_ON_WIFI, false);
}
public static boolean instantPictureUploadWhenChargingOnly(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_upload_on_charging", false);
}
public static boolean instantVideoUploadWhenChargingOnly(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_video_upload_on_charging", false);
}
/**
* Gets the path where the user selected to do the last upload of a file shared from other app.

View file

@ -34,7 +34,8 @@ public enum UploadResult {
CANCELLED(7),
FILE_NOT_FOUND(8),
DELAYED_FOR_WIFI(9),
SERVICE_INTERRUPTED(10);
SERVICE_INTERRUPTED(10),
DELAYED_FOR_CHARGING(11);
private final int value;
@ -71,6 +72,8 @@ public enum UploadResult {
return DELAYED_FOR_WIFI;
case 10:
return SERVICE_INTERRUPTED;
case 11:
return DELAYED_FOR_CHARGING;
}
return null;
}
@ -105,6 +108,8 @@ public enum UploadResult {
return CANCELLED;
case DELAYED_FOR_WIFI:
return DELAYED_FOR_WIFI;
case DELAYED_FOR_CHARGING:
return DELAYED_FOR_CHARGING;
case UNKNOWN_ERROR:
if (result.getException() instanceof java.io.FileNotFoundException) {
return FILE_ERROR;

View file

@ -57,9 +57,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log_OC.d(TAG, "Received: " + intent.getAction());
if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION) || intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)) {
handleConnectivityAction(context, intent);
} else if (intent.getAction().equals(NEW_PHOTO_ACTION_UNOFFICIAL)) {
if (intent.getAction().equals(NEW_PHOTO_ACTION_UNOFFICIAL)) {
handleNewPictureAction(context, intent);
Log_OC.d(TAG, "UNOFFICIAL processed: com.android.camera.NEW_PICTURE");
} else if (intent.getAction().equals(NEW_PHOTO_ACTION)) {
@ -101,7 +99,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
}
String[] CONTENT_PROJECTION = {
Images.Media.DATA, Images.Media.DISPLAY_NAME, Images.Media.MIME_TYPE, Images.Media.SIZE};
Images.Media.DATA, Images.Media.DISPLAY_NAME, Images.Media.MIME_TYPE, Images.Media.SIZE };
int permissionCheck = ContextCompat.checkSelfPermission(context,
Manifest.permission.READ_EXTERNAL_STORAGE);
@ -194,11 +192,6 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
date_taken = System.currentTimeMillis();
Log_OC.d(TAG, file_path + "");
// save always temporally the picture to upload
DbHandler db = new DbHandler(context);
db.putFileForLater(file_path, account.name, null);
db.close();
int behaviour = getUploadBehaviour(context);
FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
requester.uploadNewFile(

View file

@ -70,6 +70,24 @@ public class ConnectivityActionReceiver extends BroadcastReceiver {
Log_OC.v(TAG, "no extras");
}
if (intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)) {
// for the moment, only recovery of instant uploads, similar to behaviour in release 1.9.1
if (
(PreferenceManager.instantPictureUploadEnabled(context) &&
PreferenceManager.instantPictureUploadWhenChargingOnly(context)) ||
(PreferenceManager.instantVideoUploadEnabled(context) &&
PreferenceManager.instantVideoUploadWhenChargingOnly(context))
) {
Log_OC.d(TAG, "Requesting retry of instant uploads (& friends) due to charging");
FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
requester.retryFailedUploads(
context,
null,
UploadResult.DELAYED_FOR_CHARGING // for the rest of enqueued when Wifi fell
);
}
}
/**
* There is an interesting mess to process WifiManager.NETWORK_STATE_CHANGED_ACTION and
* ConnectivityManager.CONNECTIVITY_ACTION in a simple and reliable way.

View file

@ -1031,7 +1031,8 @@ public class FileUploader extends Service
// Show the result: success or fail notification
if (!uploadResult.isCancelled() &&
!uploadResult.getCode().equals(ResultCode.DELAYED_FOR_WIFI)) {
!uploadResult.getCode().equals(ResultCode.DELAYED_FOR_WIFI) &&
!uploadResult.getCode().equals(ResultCode.DELAYED_FOR_CHARGING)) {
int tickerId = (uploadResult.isSuccess()) ? R.string.uploader_upload_succeeded_ticker :
R.string.uploader_upload_failed_ticker;

View file

@ -300,6 +300,12 @@ public class UploadFileOperation extends SyncOperation {
return new RemoteOperationResult(ResultCode.DELAYED_FOR_WIFI);
}
// Check if charging conditions are met and delays the upload otherwise
if (delayForCharging()){
Log_OC.d(TAG, "Upload delayed until the device is charging: " + getRemotePath());
return new RemoteOperationResult(ResultCode.DELAYED_FOR_CHARGING);
}
/// check if the file continues existing before schedule the operation
if (!originalFile.exists()) {
Log_OC.d(TAG, mOriginalStoragePath.toString() + " not exists anymore");
@ -468,6 +474,22 @@ public class UploadFileOperation extends SyncOperation {
);
}
/**
* Check if upload should be delayed due to not charging
*
* @return 'True' if the upload was delayed until device is charging, 'false' otherwise.
*/
private boolean delayForCharging() {
boolean delayInstantPicture = isInstantPicture() &&
PreferenceManager.instantPictureUploadWhenChargingOnly(mContext);
boolean delayInstantVideo = isInstantVideo() &&
PreferenceManager.instantVideoUploadViaWiFiOnly(mContext);
return ((delayInstantPicture || delayInstantVideo)
&& !ConnectivityUtils.isCharging(mContext));
}
/**
* Checks the existence of the folder where the current file will be uploaded both

View file

@ -82,11 +82,13 @@ public class Preferences extends PreferenceActivity {
private Preference mPrefInstantUploadBehaviour;
private Preference mPrefInstantUploadPath;
private Preference mPrefInstantUploadUseSubfolders;
private Preference mPrefInstantPictureUploadOnlyOnCharging;
private Preference mPrefInstantUploadPathWiFi;
private Preference mPrefInstantVideoUpload;
private Preference mPrefInstantVideoUploadPath;
private Preference mPrefInstantVideoUploadUseSubfolders;
private Preference mPrefInstantVideoUploadPathWiFi;
private Preference mPrefInstantVideoUploadOnlyOnCharging;
private String mUploadVideoPath;
@SuppressWarnings("deprecation")
@ -291,6 +293,7 @@ public class Preferences extends PreferenceActivity {
mPrefInstantUploadUseSubfolders = findPreference("instant_upload_path_use_subfolders");
mPrefInstantUploadPathWiFi = findPreference("instant_upload_on_wifi");
mPrefInstantPictureUploadOnlyOnCharging = findPreference("instant_upload_on_charging");
mPrefInstantUpload = findPreference("instant_uploading");
toggleInstantPictureOptions(((CheckBoxPreference) mPrefInstantUpload).isChecked());
@ -328,6 +331,7 @@ public class Preferences extends PreferenceActivity {
mPrefInstantVideoUploadUseSubfolders = findPreference("instant_video_upload_path_use_subfolders");
mPrefInstantVideoUploadPathWiFi = findPreference("instant_video_upload_on_wifi");
mPrefInstantVideoUpload = findPreference("instant_video_uploading");
mPrefInstantVideoUploadOnlyOnCharging = findPreference("instant_video_upload_on_charging");
toggleInstantVideoOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked());
mPrefInstantVideoUpload.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@ -364,10 +368,12 @@ public class Preferences extends PreferenceActivity {
mPrefInstantUploadCategory.addPreference(mPrefInstantUploadPathWiFi);
mPrefInstantUploadCategory.addPreference(mPrefInstantUploadPath);
mPrefInstantUploadCategory.addPreference(mPrefInstantUploadUseSubfolders);
mPrefInstantUploadCategory.addPreference(mPrefInstantPictureUploadOnlyOnCharging);
} else {
mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPathWiFi);
mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPath);
mPrefInstantUploadCategory.removePreference(mPrefInstantUploadUseSubfolders);
mPrefInstantUploadCategory.removePreference(mPrefInstantPictureUploadOnlyOnCharging);
}
}
@ -376,10 +382,12 @@ public class Preferences extends PreferenceActivity {
mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadPathWiFi);
mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadPath);
mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadUseSubfolders);
mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadOnlyOnCharging);
} else {
mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPathWiFi);
mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPath);
mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadUseSubfolders);
mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadOnlyOnCharging);
}
}
@ -587,7 +595,7 @@ public class Preferences extends PreferenceActivity {
SharedPreferences appPrefs =
PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
mUploadVideoPath = appPrefs.getString("instant_video_upload_path", getString(R.string.instant_upload_path));
// mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath);
mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath);
}
/**

View file

@ -203,7 +203,7 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
case R.id.action_clear_failed_uploads:
storageManager = new UploadsStorageManager(getContentResolver());
storageManager.clearFailedButNotDelayedForWifiUploads();
storageManager.clearFailedButNotDelayedUploads();
uploadListFragment.updateUploads();
break;
@ -215,7 +215,7 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
case R.id.action_clear_finished_uploads:
storageManager = new UploadsStorageManager(getContentResolver());
storageManager.clearAllFinishedButNotDelayedForWifiUploads();
storageManager.clearAllFinishedButNotDelayedUploads();
uploadListFragment.updateUploads();
break;

View file

@ -150,7 +150,7 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
mUploadGroups[1] = new UploadGroup(mParentActivity.getString(R.string.uploads_view_group_failed_uploads)) {
@Override
public void refresh() {
items = mUploadsStorageManager.getFailedButNotDelayedForWifiUploads();
items = mUploadsStorageManager.getFailedButNotDelayedUploads();
Arrays.sort(items, comparator);
}
@ -551,6 +551,10 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
R.string.uploads_view_upload_status_waiting_for_wifi
);
break;
case DELAYED_FOR_CHARGING:
status = mParentActivity.getString(
R.string.uploads_view_upload_status_waiting_for_charging);
break;
case CONFLICT_ERROR:
status = mParentActivity.getString(
R.string.uploads_view_upload_status_conflict

View file

@ -20,8 +20,11 @@
package com.owncloud.android.utils;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.BatteryManager;
import com.owncloud.android.lib.common.utils.Log_OC;
@ -44,4 +47,16 @@ public class ConnectivityUtils {
return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected();
}
public static boolean isCharging(Context context){
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = context.registerReceiver(null, ifilter);
int status = 0;
if (batteryStatus != null) {
status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
}
return status == BatteryManager.BATTERY_STATUS_CHARGING ||
status == BatteryManager.BATTERY_STATUS_FULL;
}
}