Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LatinIME
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
keyboard
LatinIME
Commits
b2eac474
Commit
b2eac474
authored
12 years ago
by
Jean Chalard
Browse files
Options
Downloads
Patches
Plain Diff
Don't try to issue delete() commands on missing provider
Bug: 8173622 Change-Id: Id3dc510ae3535169b5290e87075cb2f433a1f603
parent
a92a97d2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
+50
-21
50 additions, 21 deletions
...android/inputmethod/latin/BinaryDictionaryFileDumper.java
with
50 additions
and
21 deletions
java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
+
50
−
21
View file @
b2eac474
...
...
@@ -16,6 +16,7 @@
package
com.android.inputmethod.latin
;
import
android.content.ContentProviderClient
;
import
android.content.ContentResolver
;
import
android.content.ContentValues
;
import
android.content.Context
;
...
...
@@ -93,34 +94,55 @@ public final class BinaryDictionaryFileDumper {
path
);
}
/**
* Finds out whether the dictionary pack is available on this device.
* @param context A context to get the content resolver.
* @return whether the dictionary pack is present or not.
*/
private
static
boolean
isDictionaryPackPresent
(
final
Context
context
)
{
final
ContentResolver
cr
=
context
.
getContentResolver
();
final
ContentProviderClient
client
=
cr
.
acquireContentProviderClient
(
getProviderUriBuilder
(
""
).
build
());
if
(
client
!=
null
)
{
client
.
release
();
return
true
;
}
else
{
return
false
;
}
}
/**
* Queries a content provider for the list of word lists for a specific locale
* available to copy into Latin IME.
*/
private
static
List
<
WordListInfo
>
getWordListWordListInfos
(
final
Locale
locale
,
final
Context
context
,
final
boolean
hasDefaultWordList
)
{
final
ContentResolver
resolver
=
context
.
getContentResolver
();
final
String
clientId
=
context
.
getString
(
R
.
string
.
dictionary_pack_client_id
);
final
Uri
.
Builder
builder
=
getProviderUriBuilder
(
clientId
);
builder
.
appendPath
(
QUERY_PATH_DICT_INFO
);
builder
.
appendPath
(
locale
.
toString
());
builder
.
appendQueryParameter
(
QUERY_PARAMETER_PROTOCOL
,
QUERY_PARAMETER_PROTOCOL_VALUE
);
if
(!
hasDefaultWordList
)
{
builder
.
appendQueryParameter
(
QUERY_PARAMETER_MAY_PROMPT_USER
,
QUERY_PARAMETER_TRUE
);
}
final
Uri
dictionaryPackUri
=
builder
.
build
();
final
Cursor
c
=
resolver
.
query
(
dictionaryPackUri
,
DICTIONARY_PROJECTION
,
null
,
null
,
null
);
if
(
null
==
c
)
{
reinitializeClientRecordInDictionaryContentProvider
(
context
,
resolver
,
clientId
);
return
Collections
.<
WordListInfo
>
emptyList
();
}
if
(
c
.
getCount
()
<=
0
||
!
c
.
moveToFirst
())
{
c
.
close
();
return
Collections
.<
WordListInfo
>
emptyList
();
}
try
{
final
ContentResolver
resolver
=
context
.
getContentResolver
();
final
String
clientId
=
context
.
getString
(
R
.
string
.
dictionary_pack_client_id
);
final
Uri
.
Builder
builder
=
getProviderUriBuilder
(
clientId
);
builder
.
appendPath
(
QUERY_PATH_DICT_INFO
);
builder
.
appendPath
(
locale
.
toString
());
builder
.
appendQueryParameter
(
QUERY_PARAMETER_PROTOCOL
,
QUERY_PARAMETER_PROTOCOL_VALUE
);
if
(!
hasDefaultWordList
)
{
builder
.
appendQueryParameter
(
QUERY_PARAMETER_MAY_PROMPT_USER
,
QUERY_PARAMETER_TRUE
);
}
final
Uri
dictionaryPackUri
=
builder
.
build
();
final
Cursor
c
=
resolver
.
query
(
dictionaryPackUri
,
DICTIONARY_PROJECTION
,
null
,
null
,
null
);
if
(
null
==
c
)
{
if
(
isDictionaryPackPresent
(
context
))
{
reinitializeClientRecordInDictionaryContentProvider
(
context
,
resolver
,
clientId
);
}
return
Collections
.<
WordListInfo
>
emptyList
();
}
if
(
c
.
getCount
()
<=
0
||
!
c
.
moveToFirst
())
{
c
.
close
();
return
Collections
.<
WordListInfo
>
emptyList
();
}
final
List
<
WordListInfo
>
list
=
CollectionUtils
.
newArrayList
();
do
{
final
String
wordListId
=
c
.
getString
(
0
);
...
...
@@ -130,6 +152,13 @@ public final class BinaryDictionaryFileDumper {
}
while
(
c
.
moveToNext
());
c
.
close
();
return
list
;
}
catch
(
IllegalArgumentException
e
)
{
// Since we are testing for the dictionary pack presence before doing anything that may
// crash, it's probably impossible for the code to come here. However it's very
// dangerous because crashing here would brick any encrypted device - we need the
// keyboard to be up and working to enter the password. So let's be as safe as possible.
Log
.
e
(
TAG
,
"IllegalArgumentException: the dictionary pack can't be contacted?"
,
e
);
return
Collections
.<
WordListInfo
>
emptyList
();
}
catch
(
Exception
e
)
{
// Just in case we hit a problem in communication with the dictionary pack.
// We don't want to die.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment