Add Slices Data object and DB Contract

Add in a Data object used to represent one row
in a new SQLite database used for building Slices.

The database has the following schema:
- Key
- Title
- Subtitle
- Screentitle
- Icon
- Fragment
- Controller

The key is the preference key.
Title, subtitle and Icon are for UI info.
Screentitle and fragment are for the intent.
Controller is used to get dynamic ui info (like summary),
and to take actions on the slice (like a toggle).

The actual indexing and a Slice will be handled in a subsquent CL,
but a prototype can be found here: ag/3324435

Test: robotests
Bug: 67996923
Change-Id: Id91deb58a3ab89ce1dab5a3f34cdb9ade6263aa8
This commit is contained in:
Matthew Fritze
2017-12-11 15:01:11 -08:00
parent 84e8c795b1
commit 7fddfebf6c
9 changed files with 701 additions and 44 deletions

View File

@@ -0,0 +1,87 @@
package com.android.settings.slices;
import static com.google.common.truth.Truth.assertThat;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.android.settings.TestConfig;
import com.android.settings.slices.SlicesDatabaseHelper.IndexColumns;
import com.android.settings.testutils.DatabaseTestUtils;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SlicesDatabaseHelperTest {
private Context mContext;
private SlicesDatabaseHelper mSlicesDatabaseHelper;
private SQLiteDatabase mDatabase;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mSlicesDatabaseHelper = new SlicesDatabaseHelper(mContext);
mDatabase = mSlicesDatabaseHelper.getWritableDatabase();
}
@After
public void cleanUp() {
DatabaseTestUtils.clearDb(mContext);
}
@Test
public void testDatabaseSchema() {
Cursor cursor = mDatabase.rawQuery("SELECT * FROM slices_index", null);
String[] columnNames = cursor.getColumnNames();
String[] expectedNames = new String[]{
IndexColumns.KEY,
IndexColumns.TITLE,
IndexColumns.SUBTITLE,
IndexColumns.SCREENTITLE,
IndexColumns.ICON_RESOURCE,
IndexColumns.FRAGMENT,
IndexColumns.CONTROLLER
};
assertThat(columnNames).isEqualTo(expectedNames);
}
@Test
public void testUpgrade_dropsOldData() {
ContentValues dummyValues = getDummyRow();
mDatabase.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, dummyValues);
Cursor baseline = mDatabase.rawQuery("SELECT * FROM slices_index", null);
assertThat(baseline.getCount()).isEqualTo(1);
mSlicesDatabaseHelper.onUpgrade(mDatabase, 0, 1);
Cursor newCursor = mDatabase.rawQuery("SELECT * FROM slices_index", null);
assertThat(newCursor.getCount()).isEqualTo(0);
}
private ContentValues getDummyRow() {
ContentValues values;
values = new ContentValues();
values.put(IndexColumns.KEY, "key");
values.put(IndexColumns.TITLE, "title");
values.put(IndexColumns.SUBTITLE, "subtitle");
values.put(IndexColumns.ICON_RESOURCE, 99);
values.put(IndexColumns.FRAGMENT, "fragmentClassName");
values.put(IndexColumns.CONTROLLER, "preferenceController");
return values;
}
}