mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 18:28:59 +03:00
added log output
fix multiple calls of ConnectivityActionReceiver
This commit is contained in:
parent
d3be204240
commit
8e9cf480ab
5 changed files with 86 additions and 44 deletions
|
@ -6,19 +6,23 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
import android.net.NetworkInfo.State;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.owncloud.android.files.InstantUploadBroadcastReceiver;
|
import com.owncloud.android.files.InstantUploadBroadcastReceiver;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receives all connectivity action from Android OS at all times and performs required OC actions.
|
* Receives all connectivity action from Android OS at all times and performs
|
||||||
* For now that are:
|
* required OC actions. For now that are: - Signal connectivity to
|
||||||
* - Signal connectivity to {@link FileUploadService}.
|
* {@link FileUploadService}.
|
||||||
*
|
*
|
||||||
* Later can be added:
|
* Later can be added: - Signal connectivity to download service, deletion
|
||||||
* - Signal connectivity to download service, deletion service, ...
|
* service, ... - Handle offline mode (cf.
|
||||||
* - Handle offline mode (cf. https://github.com/owncloud/android/issues/162)
|
* https://github.com/owncloud/android/issues/162)
|
||||||
*
|
*
|
||||||
* @author LukeOwncloud
|
* @author LukeOwncloud
|
||||||
*
|
*
|
||||||
|
@ -28,43 +32,64 @@ public class ConnectivityActionReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(final Context context, Intent intent) {
|
public void onReceive(final Context context, Intent intent) {
|
||||||
// if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
|
// LOG ALL EVENTS:
|
||||||
Log.v(TAG, "action: " + intent.getAction());
|
Log.v(TAG, "action: " + intent.getAction());
|
||||||
Log.v(TAG, "component: " + intent.getComponent());
|
Log.v(TAG, "component: " + intent.getComponent());
|
||||||
Bundle extras = intent.getExtras();
|
Bundle extras = intent.getExtras();
|
||||||
if (extras != null) {
|
if (extras != null) {
|
||||||
for (String key : extras.keySet()) {
|
for (String key : extras.keySet()) {
|
||||||
Log.v(TAG, "key [" + key + "]: " + extras.get(key));
|
Log.v(TAG, "key [" + key + "]: " + extras.get(key));
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Log.v(TAG, "no extras");
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Log.v(TAG, "no extras");
|
||||||
|
}
|
||||||
|
|
||||||
if (InstantUploadBroadcastReceiver.isOnline(context)) {
|
|
||||||
FileUploadService.retry(context);
|
/**
|
||||||
|
* Just checking for State.CONNECTED will is not good enough, as it ends here multiple times.
|
||||||
|
* Work around from:
|
||||||
|
* http://stackoverflow.com/questions/17287178/connectivitymanager-getactivenetworkinfo-returning-true-when-internet-is-off
|
||||||
|
*/
|
||||||
|
if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
|
||||||
|
NetworkInfo networkInfo =
|
||||||
|
intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
||||||
|
if(networkInfo.isConnected()) {
|
||||||
|
Log.d(TAG, "Wifi is connected: " + String.valueOf(networkInfo));
|
||||||
|
wifiConnected(context);
|
||||||
}
|
}
|
||||||
// }
|
} else if(intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
|
||||||
|
ConnectivityManager cm =
|
||||||
|
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
|
||||||
|
if(networkInfo.getType() == ConnectivityManager.TYPE_WIFI &&
|
||||||
|
! networkInfo.isConnected()) {
|
||||||
|
Log.d(TAG, "Wifi is disconnected: " + String.valueOf(networkInfo));
|
||||||
|
wifiDisconnected(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static public void enable(Context context) {
|
private void wifiConnected(Context context) {
|
||||||
PackageManager pm = context.getPackageManager();
|
Log_OC.d(TAG, "FileUploadService.retry() called by onReceive()");
|
||||||
ComponentName compName =
|
FileUploadService.retry(context);
|
||||||
new ComponentName(context.getApplicationContext(),
|
|
||||||
ConnectivityActionReceiver.class);
|
|
||||||
pm.setComponentEnabledSetting(
|
|
||||||
compName,
|
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
|
|
||||||
PackageManager.DONT_KILL_APP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static public void disable(Context context) {
|
private void wifiDisconnected(Context context) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static public void enableActionReceiver(Context context) {
|
||||||
PackageManager pm = context.getPackageManager();
|
PackageManager pm = context.getPackageManager();
|
||||||
ComponentName compName =
|
ComponentName compName = new ComponentName(context.getApplicationContext(), ConnectivityActionReceiver.class);
|
||||||
new ComponentName(context.getApplicationContext(),
|
pm.setComponentEnabledSetting(compName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
|
||||||
ConnectivityActionReceiver.class);
|
PackageManager.DONT_KILL_APP);
|
||||||
pm.setComponentEnabledSetting(
|
}
|
||||||
compName,
|
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
static public void disableActionReceiver(Context context) {
|
||||||
PackageManager.DONT_KILL_APP);
|
PackageManager pm = context.getPackageManager();
|
||||||
|
ComponentName compName = new ComponentName(context.getApplicationContext(), ConnectivityActionReceiver.class);
|
||||||
|
pm.setComponentEnabledSetting(compName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||||
|
PackageManager.DONT_KILL_APP);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -254,6 +254,7 @@ public class FileUploadService extends IntentService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(InstantUploadBroadcastReceiver.isOnline(getApplicationContext())) {
|
if(InstantUploadBroadcastReceiver.isOnline(getApplicationContext())) {
|
||||||
|
Log_OC.d(TAG, "FileUploadService.retry() called by onCreate()");
|
||||||
FileUploadService.retry(getApplicationContext());
|
FileUploadService.retry(getApplicationContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -281,7 +282,10 @@ public class FileUploadService extends IntentService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
|
Log_OC.i(TAG, "onHandleIntent start");
|
||||||
|
Log_OC.i(TAG, "mPendingUploads size:" + mPendingUploads.size() + " - before adding new uploads.");
|
||||||
if (intent == null || intent.hasExtra(KEY_RETRY)) {
|
if (intent == null || intent.hasExtra(KEY_RETRY)) {
|
||||||
|
Log_OC.d(TAG, "Receive null intent.");
|
||||||
// service was restarted by OS (after return START_STICKY and kill
|
// service was restarted by OS (after return START_STICKY and kill
|
||||||
// service) or connectivity change was detected. ==> check persistent upload
|
// service) or connectivity change was detected. ==> check persistent upload
|
||||||
// list.
|
// list.
|
||||||
|
@ -301,7 +305,7 @@ public class FileUploadService extends IntentService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Log_OC.d(TAG, "Receive upload intent.");
|
||||||
UploadSingleMulti uploadType = (UploadSingleMulti) intent.getSerializableExtra(KEY_UPLOAD_TYPE);
|
UploadSingleMulti uploadType = (UploadSingleMulti) intent.getSerializableExtra(KEY_UPLOAD_TYPE);
|
||||||
if (uploadType == null) {
|
if (uploadType == null) {
|
||||||
Log_OC.e(TAG, "Incorrect or no upload type provided");
|
Log_OC.e(TAG, "Incorrect or no upload type provided");
|
||||||
|
@ -406,17 +410,21 @@ public class FileUploadService extends IntentService {
|
||||||
|
|
||||||
// at this point mPendingUploads is filled.
|
// at this point mPendingUploads is filled.
|
||||||
|
|
||||||
Log_OC.i(TAG, "mPendingUploads size:" + mPendingUploads.size());
|
Log_OC.i(TAG, "mPendingUploads size:" + mPendingUploads.size() + " - before uploading.");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Iterator<String> it = mPendingUploads.keySet().iterator();
|
Iterator<String> it = mPendingUploads.keySet().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
UploadDbObject uploadDbObject = mPendingUploads.get(it.next());
|
String up = it.next();
|
||||||
|
Log_OC.d(TAG, "Calling uploadFile for " + up);
|
||||||
|
UploadDbObject uploadDbObject = mPendingUploads.get(up);
|
||||||
boolean uploadSuccessful = uploadFile(uploadDbObject);
|
boolean uploadSuccessful = uploadFile(uploadDbObject);
|
||||||
}
|
}
|
||||||
} catch (ConcurrentModificationException e) {
|
} catch (ConcurrentModificationException e) {
|
||||||
// for now: ignore. TODO: fix this.
|
// for now: ignore. TODO: fix this.
|
||||||
}
|
}
|
||||||
|
Log_OC.i(TAG, "mPendingUploads size:" + mPendingUploads.size() + " - after uploading.");
|
||||||
|
Log_OC.i(TAG, "onHandleIntent end");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -951,6 +959,7 @@ public class FileUploadService extends IntentService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void retry(Context context) {
|
public static void retry(Context context) {
|
||||||
|
Log_OC.d(TAG, "FileUploadService.retry()");
|
||||||
Intent i = new Intent(context, FileUploadService.class);
|
Intent i = new Intent(context, FileUploadService.class);
|
||||||
i.putExtra(FileUploadService.KEY_RETRY, true);
|
i.putExtra(FileUploadService.KEY_RETRY, true);
|
||||||
context.startService(i);
|
context.startService(i);
|
||||||
|
|
|
@ -459,6 +459,10 @@ public class UploadFileOperation extends RemoteOperation {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
|
if (mUploadOperation == null) {
|
||||||
|
Log_OC.e(TAG, "UploadFileOperation.cancel(): mUploadOperation == null for file: " + mFile + ". Fix that.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
mUploadOperation.cancel();
|
mUploadOperation.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1221,6 +1221,8 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
|
||||||
if (sameAccount && sameFile && detailFragmentIsShown) {
|
if (sameAccount && sameFile && detailFragmentIsShown) {
|
||||||
if (uploadWasFine) {
|
if (uploadWasFine) {
|
||||||
setFile(getStorageManager().getFileByPath(uploadedRemotePath));
|
setFile(getStorageManager().getFileByPath(uploadedRemotePath));
|
||||||
|
} else {
|
||||||
|
//TODO remove upload progress bar after upload failed.
|
||||||
}
|
}
|
||||||
if (renamedInUpload) {
|
if (renamedInUpload) {
|
||||||
String newName = (new File(uploadedRemotePath)).getName();
|
String newName = (new File(uploadedRemotePath)).getName();
|
||||||
|
|
|
@ -70,6 +70,7 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
|
||||||
// no break; to start upload immediately.
|
// no break; to start upload immediately.
|
||||||
case UPLOAD_LATER:
|
case UPLOAD_LATER:
|
||||||
case UPLOAD_FAILED_RETRY:
|
case UPLOAD_FAILED_RETRY:
|
||||||
|
Log_OC.d(TAG, "FileUploadService.retry() called by onUploadItemClick()");
|
||||||
FileUploadService.retry(this);
|
FileUploadService.retry(this);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -89,6 +90,7 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
|
||||||
boolean retval = true;
|
boolean retval = true;
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_retry_uploads: {
|
case R.id.action_retry_uploads: {
|
||||||
|
Log_OC.d(TAG, "FileUploadService.retry() called by onMenuItemSelected()");
|
||||||
FileUploadService.retry(this);
|
FileUploadService.retry(this);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue