Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix Display name and manufacter name #59

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified database/android-devices.db
Binary file not shown.
Binary file modified database/android-devices.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ class DatabaseGenerator(

DriverManager.getConnection(url)?.let { conn ->
conn.createStatement().execute(SQL_DROP)
conn.createStatement().execute(SQL_ANDROID_METADATA_TABLE_DROP)
conn.createStatement().execute(SQL_CREATE)
conn.createStatement().execute(SQL_ANDROID_METADATA_TABLE)
val statement = conn.prepareStatement(SQL_INSERT)
devices.forEach { device ->
statement.setString(1, device.marketName)
statement.setString(2, device.codename)
statement.setString(3, device.model)
statement.setString(1, device.manufacturer)
statement.setString(2, device.marketName)
statement.setString(3, device.codename)
statement.setString(4, device.model)
statement.addBatch()
}
statement.executeBatch()
Expand All @@ -68,13 +71,16 @@ class DatabaseGenerator(

companion object {
private const val SQL_INSERT =
"INSERT INTO devices (name, codename, model) VALUES (?, ?, ?)"
"INSERT INTO devices (manufacturer, name, codename, model) VALUES (? ,?, ?, ?)"
private const val SQL_DROP = "DROP TABLE IF EXISTS devices;"
private const val SQL_ANDROID_METADATA_TABLE_DROP = "DROP TABLE IF EXISTS android_metadata;"
private const val SQL_CREATE = "CREATE TABLE devices (\n" +
"_id INTEGER PRIMARY KEY,\n" +
"manufacturer TEXT,\n" +
"name TEXT,\n" +
"codename TEXT,\n" +
"model TEXT\n" +
");"
private const val SQL_ANDROID_METADATA_TABLE = "CREATE TABLE \"android_metadata\" (\"locale\" TEXT DEFAULT 'en_US');"
}
}
Binary file modified library/src/main/assets/android-devices.db
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ public class DeviceDatabase extends SQLiteOpenHelper {

private static final String TABLE_DEVICES = "devices";

private static final String COLUMN_MANUFACTURER = "manufacturer";
private static final String COLUMN_NAME = "name";
private static final String COLUMN_CODENAME = "codename";
private static final String COLUMN_MODEL = "model";

private static final String NAME = "android-devices.db";
private static final int VERSION = 1;
private static final int VERSION = 2;

private final File file;
private final Context context;
Expand Down Expand Up @@ -58,7 +59,7 @@ public String query(@Nullable String codename, @Nullable String model) {
String selection;
String[] selectionArgs;
if (codename != null && model != null) {
selection = COLUMN_CODENAME + " LIKE ? OR " + COLUMN_MODEL + " LIKE ?";
selection = COLUMN_CODENAME + " LIKE ? AND " + COLUMN_MODEL + " LIKE ?";
selectionArgs = new String[] { codename, model };
} else if (codename != null) {
selection = COLUMN_CODENAME + " LIKE ?";
Expand Down Expand Up @@ -95,17 +96,17 @@ public String query(@Nullable String codename, @Nullable String model) {
public DeviceInfo queryToDevice(@Nullable String codename, @Nullable String model) {
SQLiteDatabase database = getReadableDatabase();

String[] columns = new String[] { COLUMN_NAME, COLUMN_CODENAME, COLUMN_MODEL };
String[] columns = new String[] { COLUMN_MANUFACTURER ,COLUMN_NAME, COLUMN_CODENAME, COLUMN_MODEL };
String selection;
String[] selectionArgs;

if (!TextUtils.isEmpty(codename) && !TextUtils.isEmpty(model)) {
selection = COLUMN_CODENAME + " LIKE ? OR " + COLUMN_MODEL + " LIKE ?";
selection = COLUMN_CODENAME + " LIKE ? AND " + COLUMN_MODEL + " LIKE ?";
selectionArgs = new String[] { codename, model };
} else if (!TextUtils.isEmpty(codename)) {
selection = COLUMN_CODENAME + " LIKE ?";
selectionArgs = new String[] { codename };
} else if (TextUtils.isEmpty(model)) {
} else if (!TextUtils.isEmpty(model)) {
selection = COLUMN_MODEL + " LIKE ?";
selectionArgs = new String[] { model };
} else {
Expand All @@ -118,10 +119,11 @@ public DeviceInfo queryToDevice(@Nullable String codename, @Nullable String mode
DeviceInfo deviceInfo = null;

if (cursor.moveToFirst()) {
String manufacturer = cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_MANUFACTURER));
String name = cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_NAME));
codename = cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_CODENAME));
model = cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_MODEL));
deviceInfo = new DeviceInfo(name, codename, model);
deviceInfo = new DeviceInfo(manufacturer,name, codename, model);
}

close(cursor);
Expand Down
Loading