Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
KDE Connect Android
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
29
Merge Requests
29
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Network
KDE Connect Android
Commits
f923ce19
Commit
f923ce19
authored
Jul 05, 2019
by
Albert Vaca
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'albertvaka/sms-lock-fix'
parents
cbbec32b
a9508a7f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
17 deletions
+13
-17
src/org/kde/kdeconnect/Plugins/SMSPlugin/SMSPlugin.java
src/org/kde/kdeconnect/Plugins/SMSPlugin/SMSPlugin.java
+13
-17
No files found.
src/org/kde/kdeconnect/Plugins/SMSPlugin/SMSPlugin.java
View file @
f923ce19
...
...
@@ -163,18 +163,15 @@ public class SMSPlugin extends Plugin {
private
final
Lock
mostRecentTimestampLock
=
new
ReentrantLock
();
private
class
MessageContentObserver
extends
ContentObserver
{
final
SMSPlugin
mPlugin
;
/**
* Create a ContentObserver to watch the Messages database. onChange is called for
* every subscribed change
*
* @param parent Plugin which owns this observer
* @param handler Handler object used to make the callback
*/
MessageContentObserver
(
SMSPlugin
parent
,
Handler
handler
)
{
MessageContentObserver
(
Handler
handler
)
{
super
(
handler
);
mPlugin
=
parent
;
}
/**
...
...
@@ -185,29 +182,28 @@ public class SMSPlugin extends Plugin {
*/
@Override
public
void
onChange
(
boolean
selfChange
)
{
if
(
mPlugin
.
mostRecentTimestamp
==
0
)
{
// Lock so no one uses the mostRecentTimestamp between the moment we read it and the
// moment we update it. This is because reading the Messages DB can take long.
mostRecentTimestampLock
.
lock
();
if
(
mostRecentTimestamp
==
0
)
{
// Since the timestamp has not been initialized, we know that nobody else
// has requested a message. That being the case, there is most likely
// nobody listening for message updates, so just drop them
mostRecentTimestampLock
.
unlock
();
return
;
}
mostRecentTimestampLock
.
lock
();
// Grab the mostRecentTimestamp into the local stack because reading the Messages
// database could potentially be a long operation
long
mostRecentTimestamp
=
mPlugin
.
mostRecentTimestamp
;
mostRecentTimestampLock
.
unlock
();
SMSHelper
.
Message
message
=
SMSHelper
.
getNewestMessage
(
mPlugin
.
context
);
SMSHelper
.
Message
message
=
SMSHelper
.
getNewestMessage
(
context
);
if
(
message
.
date
<=
mostRecentTimestamp
)
{
//
Our onChange often gets called many times for a single message. Don't make unnecessary
// noise
if
(
message
==
null
||
message
.
date
<=
mostRecentTimestamp
)
{
//
onChange can trigger many times for a single message. Don't make unnecessary noise
mostRecentTimestampLock
.
unlock
();
return
;
}
// Update the most recent counter
mostRecentTimestampLock
.
lock
();
mPlugin
.
mostRecentTimestamp
=
message
.
date
;
mostRecentTimestamp
=
message
.
date
;
mostRecentTimestampLock
.
unlock
();
// Send the alert about the update
...
...
@@ -281,7 +277,7 @@ public class SMSPlugin extends Plugin {
context
.
registerReceiver
(
receiver
,
filter
);
Looper
helperLooper
=
SMSHelper
.
MessageLooper
.
getLooper
();
ContentObserver
messageObserver
=
new
MessageContentObserver
(
this
,
new
Handler
(
helperLooper
));
ContentObserver
messageObserver
=
new
MessageContentObserver
(
new
Handler
(
helperLooper
));
SMSHelper
.
registerObserver
(
messageObserver
,
context
);
return
true
;
...
...
Write
Preview
Markdown
is supported
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