Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Silence-Android
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
268
Issues
268
List
Boards
Labels
Service Desk
Milestones
Merge Requests
11
Merge Requests
11
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Silence
Silence-Android
Commits
0caf1f8e
Commit
0caf1f8e
authored
May 21, 2016
by
Bastien Le Querrec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix NPE if contacts database is not available
parent
ebfcbc5a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
25 deletions
+52
-25
src/org/smssecure/smssecure/contacts/ContactsCursorLoader.java
...rg/smssecure/smssecure/contacts/ContactsCursorLoader.java
+11
-4
src/org/smssecure/smssecure/contacts/ContactsDatabase.java
src/org/smssecure/smssecure/contacts/ContactsDatabase.java
+41
-21
No files found.
src/org/smssecure/smssecure/contacts/ContactsCursorLoader.java
View file @
0caf1f8e
...
...
@@ -18,6 +18,7 @@ package org.smssecure.smssecure.contacts;
import
android.content.Context
;
import
android.database.Cursor
;
import
android.database.CursorWrapper
;
import
android.database.MergeCursor
;
import
android.support.v4.content.CursorLoader
;
import
android.text.TextUtils
;
...
...
@@ -50,18 +51,24 @@ public class ContactsCursorLoader extends CursorLoader {
@Override
public
Cursor
loadInBackground
()
{
ContactsDatabase
contactsDatabase
=
DatabaseFactory
.
getContactsDatabase
(
getContext
());
ArrayList
<
Cursor
>
cursorList
=
new
ArrayList
<>(
3
);
ArrayList
<
Cursor
>
cursorList
=
new
ArrayList
<>();
cursorList
.
add
(
contactsDatabase
.
querySilenceContacts
(
filter
));
Cursor
silenceContacts
=
contactsDatabase
.
querySilenceContacts
(
filter
);
if
(
silenceContacts
!=
null
)
cursorList
.
add
(
silenceContacts
);
if
(
includeSmsContacts
)
{
cursorList
.
add
(
contactsDatabase
.
querySystemContacts
(
filter
));
Cursor
systemContacts
=
contactsDatabase
.
querySystemContacts
(
filter
);
if
(
systemContacts
!=
null
)
cursorList
.
add
(
systemContacts
);
}
if
(!
TextUtils
.
isEmpty
(
filter
)
&&
NumberUtil
.
isValidSmsOrEmail
(
filter
))
{
cursorList
.
add
(
contactsDatabase
.
getNewNumberCursor
(
filter
));
}
return
new
MergeCursor
(
cursorList
.
toArray
(
new
Cursor
[
0
]));
if
(
cursorList
.
size
()
>
0
)
{
return
new
MergeCursor
(
cursorList
.
toArray
(
new
Cursor
[
0
]));
}
else
{
return
null
;
}
}
}
src/org/smssecure/smssecure/contacts/ContactsDatabase.java
View file @
0caf1f8e
...
...
@@ -23,10 +23,10 @@ import android.database.MatrixCursor;
import
android.net.Uri
;
import
android.os.Build
;
import
android.provider.ContactsContract
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.text.TextUtils
;
import
android.util.Pair
;
import
android.util.Log
;
import
org.smssecure.smssecure.R
;
...
...
@@ -61,7 +61,7 @@ public class ContactsDatabase {
this
.
context
=
context
;
}
public
@N
onNull
Cursor
querySystemContacts
(
String
filter
)
{
public
@N
ullable
Cursor
querySystemContacts
(
String
filter
)
{
Uri
uri
;
if
(!
TextUtils
.
isEmpty
(
filter
))
{
...
...
@@ -90,17 +90,28 @@ public class ContactsDatabase {
put
(
LABEL_COLUMN
,
ContactsContract
.
CommonDataKinds
.
Phone
.
LABEL
);
}};
Cursor
cursor
=
context
.
getContentResolver
().
query
(
uri
,
projection
,
ContactsContract
.
Data
.
SYNC2
+
" IS NULL OR "
+
ContactsContract
.
Data
.
SYNC2
+
" != ?"
,
new
String
[]
{
"__TS"
},
sort
);
Cursor
cursor
;
try
{
cursor
=
context
.
getContentResolver
().
query
(
uri
,
projection
,
ContactsContract
.
Data
.
SYNC2
+
" IS NULL OR "
+
ContactsContract
.
Data
.
SYNC2
+
" != ?"
,
new
String
[]
{
"__TS"
},
sort
);
}
catch
(
NullPointerException
npe
)
{
/*
* On a few phone (+ Sailfish OS 2.0), this throws a NPE. We just
* catch it and return a blank result.
*/
Log
.
w
(
TAG
,
npe
);
return
null
;
}
return
new
ProjectionMappingCursor
(
cursor
,
projectionMap
,
new
Pair
<
String
,
Object
>(
CONTACT_TYPE_COLUMN
,
NORMAL_TYPE
));
}
public
@N
onNull
Cursor
querySilenceContacts
(
String
filter
)
{
public
@N
ullable
Cursor
querySilenceContacts
(
String
filter
)
{
String
[]
projection
=
new
String
[]
{
ContactsContract
.
Data
.
_ID
,
ContactsContract
.
Contacts
.
DISPLAY_NAME
,
ContactsContract
.
Data
.
DATA1
};
...
...
@@ -115,19 +126,28 @@ public class ContactsDatabase {
Cursor
cursor
;
if
(
TextUtils
.
isEmpty
(
filter
))
{
cursor
=
context
.
getContentResolver
().
query
(
ContactsContract
.
Data
.
CONTENT_URI
,
projection
,
ContactsContract
.
Data
.
MIMETYPE
+
" = ?"
,
new
String
[]
{
"vnd.android.cursor.item/vnd.org.smssecure.smssecure.contact"
},
sort
);
}
else
{
cursor
=
context
.
getContentResolver
().
query
(
ContactsContract
.
Data
.
CONTENT_URI
,
projection
,
ContactsContract
.
Data
.
MIMETYPE
+
" = ? AND "
+
ContactsContract
.
Contacts
.
DISPLAY_NAME
+
" LIKE ?"
,
new
String
[]
{
"vnd.android.cursor.item/vnd.org.smssecure.smssecure.contact"
,
"%"
+
filter
+
"%"
},
sort
);
try
{
if
(
TextUtils
.
isEmpty
(
filter
))
{
cursor
=
context
.
getContentResolver
().
query
(
ContactsContract
.
Data
.
CONTENT_URI
,
projection
,
ContactsContract
.
Data
.
MIMETYPE
+
" = ?"
,
new
String
[]
{
"vnd.android.cursor.item/vnd.org.smssecure.smssecure.contact"
},
sort
);
}
else
{
cursor
=
context
.
getContentResolver
().
query
(
ContactsContract
.
Data
.
CONTENT_URI
,
projection
,
ContactsContract
.
Data
.
MIMETYPE
+
" = ? AND "
+
ContactsContract
.
Contacts
.
DISPLAY_NAME
+
" LIKE ?"
,
new
String
[]
{
"vnd.android.cursor.item/vnd.org.smssecure.smssecure.contact"
,
"%"
+
filter
+
"%"
},
sort
);
}
}
catch
(
NullPointerException
npe
)
{
/*
* On a few phone (+ Sailfish OS 2.0), this throws a NPE. We just
* catch it and return an empty result.
*/
Log
.
w
(
TAG
,
npe
);
return
null
;
}
return
new
ProjectionMappingCursor
(
cursor
,
projectionMap
,
...
...
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