Keep contextual card dismissal info upon deletion
Add a config for contextual dismissal. This config is used to
determine whether the existing dismissal timestamp should be
kept before an insertion.
The new dismissal behaviour design replaces the boolean
value(isDismissed) with a long value(dismissedTimestamp) to give
this behaviour more flexibility. Utilizing the timestamp allows
developers to define new criteria of card's display (e.g cards being
dismissed can be shown again after a period of time).
While newly inserted data from SettingsIntelligence or other clients
may not have dismissal timestamp recorded. Turning on the config gives
the capability to persist dismissal timestamp, and more customized
behaviour can be created.
Bug: 143055685
Test: robotests
Change-Id: I9d095955e9c51f2aa3332d49ee230d3ded9ae744
Merged-In: I9d095955e9c51f2aa3332d49ee230d3ded9ae744
(cherry picked from commit 377125bf96
)
This commit is contained in:
@@ -38,6 +38,7 @@ import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@@ -85,6 +86,25 @@ public class CardContentProviderTest {
|
||||
assertThat(rowsAfterInsert - rowsBeforeInsert).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "mcc999")
|
||||
public void bulkInsert_keepDismissalTimestamp_shouldHaveTimestamp() {
|
||||
mResolver.bulkInsert(mUri, generateTwoRowsWithDismissTimestamp());
|
||||
|
||||
mResolver.bulkInsert(mUri, generateTwoRows());
|
||||
|
||||
assertThat(queryDismissedTimestamp()).isEqualTo(10001L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bulkInsert_notKeepDismissalTimestamp_shouldNotHaveTimestamp() {
|
||||
mResolver.bulkInsert(mUri, generateTwoRowsWithDismissTimestamp());
|
||||
|
||||
mResolver.bulkInsert(mUri, generateTwoRows());
|
||||
|
||||
assertThat(queryDismissedTimestamp()).isEqualTo(0L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cardData_query() {
|
||||
mResolver.insert(mUri, generateOneRow());
|
||||
@@ -198,10 +218,40 @@ public class CardContentProviderTest {
|
||||
return twoRows;
|
||||
}
|
||||
|
||||
private ContentValues[] generateTwoRowsWithDismissTimestamp() {
|
||||
final ContentValues[] twoRows = new ContentValues[2];
|
||||
twoRows[0] = generateOneRow();
|
||||
|
||||
final ContentValues values = new ContentValues();
|
||||
values.put(CardDatabaseHelper.CardColumns.NAME, "toggle_airplane");
|
||||
values.put(CardDatabaseHelper.CardColumns.TYPE, 1);
|
||||
values.put(CardDatabaseHelper.CardColumns.SCORE, 0.95);
|
||||
values.put(CardDatabaseHelper.CardColumns.SLICE_URI,
|
||||
"content://com.android.settings.slices/action/toggle_airplane");
|
||||
values.put(CardDatabaseHelper.CardColumns.CATEGORY, 2);
|
||||
values.put(CardDatabaseHelper.CardColumns.PACKAGE_NAME, "com.android.settings");
|
||||
values.put(CardDatabaseHelper.CardColumns.APP_VERSION, 10001);
|
||||
values.put(CardDatabaseHelper.CardColumns.DISMISSED_TIMESTAMP, 10001L);
|
||||
twoRows[1] = values;
|
||||
|
||||
return twoRows;
|
||||
}
|
||||
|
||||
private int getRowCount() {
|
||||
final Cursor cr = mResolver.query(mUri, null, null, null);
|
||||
final int count = cr.getCount();
|
||||
cr.close();
|
||||
return count;
|
||||
}
|
||||
|
||||
private long queryDismissedTimestamp() {
|
||||
final String[] columns = {CardDatabaseHelper.CardColumns.DISMISSED_TIMESTAMP};
|
||||
final String selection = CardDatabaseHelper.CardColumns.NAME + "=?";
|
||||
final String[] selectionArgs = {"toggle_airplane"};
|
||||
final Cursor cr = mResolver.query(mUri, columns, selection, selectionArgs, null);
|
||||
cr.moveToFirst();
|
||||
final long dismissedTimestamp = cr.getLong(0);
|
||||
cr.close();
|
||||
return dismissedTimestamp;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user