Merge cherrypicks of [4255363, 4255364, 4254607, 4254608, 4254909, 4254910, 4254911, 4255904, 4255905, 4255906, 4255907, 4254912, 4254624, 4255365, 4254609, 4254610, 4254611, 4254612, 4254613, 4254614, 4254615, 4254691, 4254692, 4254693, 4254694, 4254695, 4254696, 4254697, 4254698, 4254699, 4254700, 4255981, 4254913, 4255282, 4255283, 4255284, 4255366, 4256001, 4256002, 4254616, 4255367, 4256003, 4254957, 4254958, 4255403, 4255404, 4255405, 4255406, 4255407, 4255408, 4255409, 4255410, 4255411, 4255412, 4255413, 4255414, 4255415, 4255416, 4253350, 4256013, 4254991, 4256014, 4254959, 4254960, 4254992, 4254993, 4254994] into sparse-4732991-L15500000179240506

Change-Id: I1789059db7f5aaf42119b2882acee04532c060d4
diff --git a/src/com/android/providers/userdictionary/UserDictionaryProvider.java b/src/com/android/providers/userdictionary/UserDictionaryProvider.java
index c0f67e9..5abeefa 100644
--- a/src/com/android/providers/userdictionary/UserDictionaryProvider.java
+++ b/src/com/android/providers/userdictionary/UserDictionaryProvider.java
@@ -152,6 +152,11 @@
     @Override
     public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
             String sortOrder) {
+        // Only the enabled IMEs and spell checkers can access this provider.
+        if (!canCallerAccessUserDictionary()) {
+            return getEmptyCursorOrThrow(projection);
+        }
+
         SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
 
         switch (sUriMatcher.match(uri)) {
@@ -170,11 +175,6 @@
                 throw new IllegalArgumentException("Unknown URI " + uri);
         }
 
-        // Only the enabled IMEs and spell checkers can access this provider.
-        if (!canCallerAccessUserDictionary()) {
-            return getEmptyCursorOrThrow(projection);
-        }
-
         // If no sort order is specified use the default
         String orderBy;
         if (TextUtils.isEmpty(sortOrder)) {
@@ -257,6 +257,11 @@
 
     @Override
     public int delete(Uri uri, String where, String[] whereArgs) {
+        // Only the enabled IMEs and spell checkers can access this provider.
+        if (!canCallerAccessUserDictionary()) {
+            return 0;
+        }
+
         SQLiteDatabase db = mOpenHelper.getWritableDatabase();
         int count;
         switch (sUriMatcher.match(uri)) {
@@ -274,11 +279,6 @@
                 throw new IllegalArgumentException("Unknown URI " + uri);
         }
 
-        // Only the enabled IMEs and spell checkers can access this provider.
-        if (!canCallerAccessUserDictionary()) {
-            return 0;
-        }
-
         getContext().getContentResolver().notifyChange(uri, null);
         mBackupManager.dataChanged();
         return count;
@@ -286,6 +286,11 @@
 
     @Override
     public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
+        // Only the enabled IMEs and spell checkers can access this provider.
+        if (!canCallerAccessUserDictionary()) {
+            return 0;
+        }
+
         SQLiteDatabase db = mOpenHelper.getWritableDatabase();
         int count;
         switch (sUriMatcher.match(uri)) {
@@ -303,11 +308,6 @@
                 throw new IllegalArgumentException("Unknown URI " + uri);
         }
 
-        // Only the enabled IMEs and spell checkers can access this provider.
-        if (!canCallerAccessUserDictionary()) {
-            return 0;
-        }
-
         getContext().getContentResolver().notifyChange(uri, null);
         mBackupManager.dataChanged();
         return count;