Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
os
eDrive
Commits
b799d424
Commit
b799d424
authored
Dec 14, 2019
by
vince-bourgmayer
Browse files
rewrite OMS onStartCommand() part that load data from intent. add a check that intent isn't null
parent
f7ba4bd8
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/foundation/e/drive/services/OperationManagerService.java
View file @
b799d424
...
...
@@ -229,58 +229,59 @@ public class OperationManagerService extends Service implements OnRemoteOperatio
Log
.
i
(
TAG
,
"onStartCommand()"
);
CommonUtils
.
setServiceUnCaughtExceptionHandler
(
this
);
if
(
intent
==
null
||
intent
.
getExtras
()
==
null
){
Log
.
w
(
TAG
,
"Intent or it's extras is null."
);
return
super
.
onStartCommand
(
intent
,
flags
,
startId
);
}
Bundle
extras
=
intent
.
getExtras
();
Log
.
d
(
TAG
,
"OperationManagerService recieved "
+(
extras
==
null
?
"null extras"
:
extras
.
size
()+
" operations to perform"
)
);
if
(
extras
!=
null
)
{
//Load operation from intent
this
.
mOperationsQueue
=
new
ConcurrentLinkedDeque
<>();
for
(
String
key
:
extras
.
keySet
())
{
//Load operation from intent
this
.
mOperationsQueue
=
new
ConcurrentLinkedDeque
<>();
for
(
String
key
:
extras
.
keySet
())
{
Parcelable
parcelableObject
=
extras
.
getParcelable
(
key
);
if
(
key
.
equals
(
"account"
)){
this
.
mAccount
=
(
Account
)
parcelableObject
;
}
else
if
(
parcelableObject
.
getClass
().
getName
().
equals
(
DownloadFileOperation
.
class
.
getName
()))
{
DownloadFileOperation
download
=
(
DownloadFileOperation
)
parcelableObject
;
download
.
setContext
(
getApplicationContext
());
mOperationsQueue
.
add
(
download
);
}
else
if
(
parcelableObject
.
getClass
().
getName
().
equals
(
UploadFileOperation
.
class
.
getName
()))
{
UploadFileOperation
upload
=
(
UploadFileOperation
)
parcelableObject
;
upload
.
setContext
(
getApplicationContext
());
mOperationsQueue
.
add
(
upload
);
}
else
if
(
parcelableObject
.
getClass
().
getName
().
equals
(
RemoveFileOperation
.
class
.
getName
()))
{
mOperationsQueue
.
add
((
RemoveFileOperation
)
parcelableObject
);
}
Parcelable
parcelableObject
=
extras
.
getParcelable
(
key
);
String
parcelableClassName
=
parcelableObject
.
getClass
().
getSimpleName
();
if
(
key
.
equals
(
"account"
)){
mAccount
=
(
Account
)
parcelableObject
;
}
if
(
mAccount
==
null
||
mOperationsQueue
.
isEmpty
()){
Log
.
w
(
TAG
,
"No account or Operation queue is empty"
);
return
super
.
onStartCommand
(
intent
,
flags
,
startId
);
else
if
(
parcelableClassName
.
equals
(
DownloadFileOperation
.
class
.
getSimpleName
()))
{
DownloadFileOperation
download
=
(
DownloadFileOperation
)
parcelableObject
;
download
.
setContext
(
getApplicationContext
());
mOperationsQueue
.
add
(
download
);
}
else
if
(
parcelableClassName
.
equals
(
UploadFileOperation
.
class
.
getSimpleName
()))
{
UploadFileOperation
upload
=
(
UploadFileOperation
)
parcelableObject
;
upload
.
setContext
(
getApplicationContext
());
mOperationsQueue
.
add
(
upload
);
}
else
if
(
parcelableClassName
.
equals
(
RemoveFileOperation
.
class
.
getSimpleName
()))
{
mOperationsQueue
.
add
((
RemoveFileOperation
)
parcelableObject
);
}
}
//Initialize class's field
this
.
workerAmount
=
4
;
//This variable could be replace later by an option in settings
this
.
mThreadPool
=
new
Thread
[
workerAmount
];
this
.
mThreadWorkingState
=
new
boolean
[
workerAmount
];
this
.
mHandler
=
new
OperationManagerHandler
(
this
);
this
.
mStartedOperations
=
new
Hashtable
<
RemoteOperation
,
Integer
>();
mClient
=
DavClientProvider
.
getInstance
().
getClientInstance
(
mAccount
,
getApplicationContext
());
if
(
mClient
!=
null
)
{
getSharedPreferences
(
AppConstants
.
SHARED_PREFERENCE_NAME
,
Context
.
MODE_PRIVATE
)
.
edit
()
.
putBoolean
(
AppConstants
.
KEY_OMS_IS_WORKING
,
true
)
.
apply
();
if
(
mAccount
==
null
||
mOperationsQueue
.
isEmpty
()){
Log
.
w
(
TAG
,
"No account or Operation queue is empty"
);
return
super
.
onStartCommand
(
intent
,
flags
,
startId
);
}
startAllThreads
();
}
else
{
Log
.
w
(
TAG
,
"No Client, Can't Work!"
);
stopSelf
();
}
}
else
{
Log
.
w
(
TAG
,
"Intent's extras is null."
);
//Initialize class's field
this
.
workerAmount
=
4
;
//This variable could be replace later by an option in settings
this
.
mThreadPool
=
new
Thread
[
workerAmount
];
this
.
mThreadWorkingState
=
new
boolean
[
workerAmount
];
this
.
mHandler
=
new
OperationManagerHandler
(
this
);
this
.
mStartedOperations
=
new
Hashtable
<
RemoteOperation
,
Integer
>();
mClient
=
DavClientProvider
.
getInstance
().
getClientInstance
(
mAccount
,
getApplicationContext
());
if
(
mClient
!=
null
)
{
getSharedPreferences
(
AppConstants
.
SHARED_PREFERENCE_NAME
,
Context
.
MODE_PRIVATE
)
.
edit
()
.
putBoolean
(
AppConstants
.
KEY_OMS_IS_WORKING
,
true
)
.
apply
();
startAllThreads
();
}
else
{
Log
.
w
(
TAG
,
"No Client, Can't Work!"
);
stopSelf
();
}
return
super
.
onStartCommand
(
intent
,
flags
,
startId
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment