Loading src/com/android/settings/homepage/contextualcards/CardContentProvider.java +2 −23 Original line number Diff line number Diff line Loading @@ -98,17 +98,7 @@ public class CardContentProvider extends ContentProvider { @Override public int delete(Uri uri, String selection, String[] selectionArgs) { final StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy(); try { maybeEnableStrictMode(); final SQLiteDatabase database = mDBHelper.getWritableDatabase(); final String table = getTableFromMatch(uri); final int rowsDeleted = database.delete(table, selection, selectionArgs); getContext().getContentResolver().notifyChange(uri, null /* observer */); return rowsDeleted; } finally { StrictMode.setThreadPolicy(oldPolicy); } throw new UnsupportedOperationException("delete operation not supported currently."); } @Override Loading Loading @@ -140,18 +130,7 @@ public class CardContentProvider extends ContentProvider { @Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { final StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy(); try { maybeEnableStrictMode(); final SQLiteDatabase database = mDBHelper.getWritableDatabase(); final String table = getTableFromMatch(uri); final int rowsUpdated = database.update(table, values, selection, selectionArgs); getContext().getContentResolver().notifyChange(uri, null /* observer */); return rowsUpdated; } finally { StrictMode.setThreadPolicy(oldPolicy); } throw new UnsupportedOperationException("update operation not supported currently."); } @VisibleForTesting Loading tests/robotests/src/com/android/settings/homepage/contextualcards/CardContentProviderTest.java +2 −59 Original line number Diff line number Diff line Loading @@ -95,15 +95,12 @@ public class CardContentProviderTest { assertThat(count).isGreaterThan(0); } @Test @Test(expected = UnsupportedOperationException.class) public void cardData_delete() { mResolver.insert(mUri, generateOneRow()); final int delCount = mResolver.delete(mUri, null, null); assertThat(delCount).isGreaterThan(0); } @Test @Test(expected = UnsupportedOperationException.class) public void cardData_update() { mResolver.insert(mUri, generateOneRow()); Loading @@ -113,16 +110,6 @@ public class CardContentProviderTest { final String strWhere = CardDatabaseHelper.CardColumns.NAME + "=?"; final String[] selectionArgs = {"auto_rotate"}; final int updateCount = mResolver.update(mUri, values, strWhere, selectionArgs); assertThat(updateCount).isGreaterThan(0); final String[] columns = {CardDatabaseHelper.CardColumns.SCORE}; final Cursor cr = mResolver.query(mUri, columns, strWhere, selectionArgs, null); cr.moveToFirst(); final double qryScore = cr.getDouble(0); cr.close(); assertThat(qryScore).isEqualTo(updatingScore); } @Test Loading @@ -145,28 +132,6 @@ public class CardContentProviderTest { verify(mProvider).enableStrictMode(); } @Test public void delete_isMainThread_shouldEnableStrictMode() { ShadowThreadUtils.setIsMainThread(true); ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", true); mProvider.delete(mUri, null, null); verify(mProvider).enableStrictMode(); } @Test public void update_isMainThread_shouldEnableStrictMode() { ShadowThreadUtils.setIsMainThread(true); ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", true); final ContentValues values = new ContentValues(); values.put(CardDatabaseHelper.CardColumns.SCORE, "0.01"); mProvider.update(mUri, values, null, null); verify(mProvider).enableStrictMode(); } @Test public void insert_notMainThread_shouldNotEnableStrictMode() { ShadowThreadUtils.setIsMainThread(false); Loading @@ -187,28 +152,6 @@ public class CardContentProviderTest { verify(mProvider, never()).enableStrictMode(); } @Test public void delete_notMainThread_shouldNotEnableStrictMode() { ShadowThreadUtils.setIsMainThread(false); ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", true); mProvider.delete(mUri, null, null); verify(mProvider, never()).enableStrictMode(); } @Test public void update_notMainThread_shouldNotEnableStrictMode() { ShadowThreadUtils.setIsMainThread(false); ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", true); final ContentValues values = new ContentValues(); values.put(CardDatabaseHelper.CardColumns.SCORE, "0.01"); mProvider.update(mUri, values, null, null); verify(mProvider, never()).enableStrictMode(); } @Test(expected = UnsupportedOperationException.class) public void getType_shouldCrash() { mProvider.getType(null); Loading Loading
src/com/android/settings/homepage/contextualcards/CardContentProvider.java +2 −23 Original line number Diff line number Diff line Loading @@ -98,17 +98,7 @@ public class CardContentProvider extends ContentProvider { @Override public int delete(Uri uri, String selection, String[] selectionArgs) { final StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy(); try { maybeEnableStrictMode(); final SQLiteDatabase database = mDBHelper.getWritableDatabase(); final String table = getTableFromMatch(uri); final int rowsDeleted = database.delete(table, selection, selectionArgs); getContext().getContentResolver().notifyChange(uri, null /* observer */); return rowsDeleted; } finally { StrictMode.setThreadPolicy(oldPolicy); } throw new UnsupportedOperationException("delete operation not supported currently."); } @Override Loading Loading @@ -140,18 +130,7 @@ public class CardContentProvider extends ContentProvider { @Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { final StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy(); try { maybeEnableStrictMode(); final SQLiteDatabase database = mDBHelper.getWritableDatabase(); final String table = getTableFromMatch(uri); final int rowsUpdated = database.update(table, values, selection, selectionArgs); getContext().getContentResolver().notifyChange(uri, null /* observer */); return rowsUpdated; } finally { StrictMode.setThreadPolicy(oldPolicy); } throw new UnsupportedOperationException("update operation not supported currently."); } @VisibleForTesting Loading
tests/robotests/src/com/android/settings/homepage/contextualcards/CardContentProviderTest.java +2 −59 Original line number Diff line number Diff line Loading @@ -95,15 +95,12 @@ public class CardContentProviderTest { assertThat(count).isGreaterThan(0); } @Test @Test(expected = UnsupportedOperationException.class) public void cardData_delete() { mResolver.insert(mUri, generateOneRow()); final int delCount = mResolver.delete(mUri, null, null); assertThat(delCount).isGreaterThan(0); } @Test @Test(expected = UnsupportedOperationException.class) public void cardData_update() { mResolver.insert(mUri, generateOneRow()); Loading @@ -113,16 +110,6 @@ public class CardContentProviderTest { final String strWhere = CardDatabaseHelper.CardColumns.NAME + "=?"; final String[] selectionArgs = {"auto_rotate"}; final int updateCount = mResolver.update(mUri, values, strWhere, selectionArgs); assertThat(updateCount).isGreaterThan(0); final String[] columns = {CardDatabaseHelper.CardColumns.SCORE}; final Cursor cr = mResolver.query(mUri, columns, strWhere, selectionArgs, null); cr.moveToFirst(); final double qryScore = cr.getDouble(0); cr.close(); assertThat(qryScore).isEqualTo(updatingScore); } @Test Loading @@ -145,28 +132,6 @@ public class CardContentProviderTest { verify(mProvider).enableStrictMode(); } @Test public void delete_isMainThread_shouldEnableStrictMode() { ShadowThreadUtils.setIsMainThread(true); ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", true); mProvider.delete(mUri, null, null); verify(mProvider).enableStrictMode(); } @Test public void update_isMainThread_shouldEnableStrictMode() { ShadowThreadUtils.setIsMainThread(true); ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", true); final ContentValues values = new ContentValues(); values.put(CardDatabaseHelper.CardColumns.SCORE, "0.01"); mProvider.update(mUri, values, null, null); verify(mProvider).enableStrictMode(); } @Test public void insert_notMainThread_shouldNotEnableStrictMode() { ShadowThreadUtils.setIsMainThread(false); Loading @@ -187,28 +152,6 @@ public class CardContentProviderTest { verify(mProvider, never()).enableStrictMode(); } @Test public void delete_notMainThread_shouldNotEnableStrictMode() { ShadowThreadUtils.setIsMainThread(false); ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", true); mProvider.delete(mUri, null, null); verify(mProvider, never()).enableStrictMode(); } @Test public void update_notMainThread_shouldNotEnableStrictMode() { ShadowThreadUtils.setIsMainThread(false); ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", true); final ContentValues values = new ContentValues(); values.put(CardDatabaseHelper.CardColumns.SCORE, "0.01"); mProvider.update(mUri, values, null, null); verify(mProvider, never()).enableStrictMode(); } @Test(expected = UnsupportedOperationException.class) public void getType_shouldCrash() { mProvider.getType(null); Loading