Skip to content
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
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
Change Log
==========

Version 1.0.6 *(2019-03-07)*
----------------------------

* Fix: Fix query error
* Fix: Fix DebugDb class not found error


Version 1.0.5 *(2019-02-18)*
----------------------------

* Reduce size by taking out encrypted database library as a separate module
* New: Add support for database delete
* Changed compile to implementation
* Fix: Minor bug fixes


Version 1.0.4 *(2018-06-23)*
----------------------------

Expand Down Expand Up @@ -48,7 +64,7 @@ Version 0.5.0 *(2017-01-21)*

* New: Export DB
* New: Method to get DB version
* Fix: Fix prouard issue and other minor issues
* Fix: Fix proguard issue and other minor issues


Version 0.4.0 *(2016-11-29)*
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@
Add this to your app's build.gradle

```groovy
debugImplementation 'com.amitshekhar.android:debug-db:1.0.4'
debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'
```

Using the Android Debug Database with encrypted database

```groovy
debugImplementation 'com.amitshekhar.android:debug-db-encrypt:1.0.6'
```

Use `debugImplementation` so that it will only compile in your debug build and not in your release build.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
Expand Down
4 changes: 1 addition & 3 deletions debug-db-base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ android {

dependencies {
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'net.zetetic:android-database-sqlcipher:3.5.9'
implementation 'android.arch.persistence.room:runtime:1.1.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

//apply from: 'debug-db-upload.gradle'
//apply from: 'debug-db-base-upload.gradle'
104 changes: 104 additions & 0 deletions debug-db-base/debug-db-base-upload.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
*
* * Copyright (C) 2019 Amit Shekhar
* * Copyright (C) 2011 Android Open Source Project
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*/

apply plugin: 'com.github.dcendents.android-maven'
apply plugin: "com.jfrog.bintray"

def siteUrl = 'https://github.com/amitshekhariitbhu/Android-Debug-Database'
def gitUrl = 'https://github.com/amitshekhariitbhu/Android-Debug-Database.git'

group = "com.amitshekhar.android"
version = '1.0.6'

install {
repositories.mavenInstaller {
pom.project {
packaging 'aar'

name 'Android Debug Database'
description 'Android Debug Database is a powerful library for debugging databases in Android applications'

url siteUrl

licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}

developers {
developer {
id 'amitshekhariitbhu'
name 'Amit Shekhar'
email 'amit.shekhar.iitbhu@gmail.com'
}
}

scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
}
}

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}

task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
failOnError false
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
classpath += configurations.compile
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}

if (project.rootProject.file("local.properties").exists()) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")

configurations = ['archives']
dryRun = false

pkg {
repo = "maven"
name = "debug-db-base"
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = ["Apache-2.0"]
publish = true
}
}
}
5 changes: 3 additions & 2 deletions debug-db-base/src/main/java/com/amitshekhar/DebugDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.util.Pair;

import com.amitshekhar.server.ClientServer;
import com.amitshekhar.sqlite.DBFactory;
import com.amitshekhar.utils.NetworkUtils;

import java.io.File;
Expand All @@ -45,7 +46,7 @@ private DebugDB() {
// This class in not publicly instantiable
}

public static void initialize(Context context) {
public static void initialize(Context context, DBFactory dbFactory) {
int portNumber;

try {
Expand All @@ -56,7 +57,7 @@ public static void initialize(Context context) {
Log.i(TAG, "Using Default port : " + DEFAULT_PORT);
}

clientServer = new ClientServer(context, portNumber);
clientServer = new ClientServer(context, portNumber, dbFactory);
clientServer.start();
addressLog = NetworkUtils.getAddressLog(context, portNumber);
Log.d(TAG, addressLog);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
* Created by amitshekhar on 15/11/16.
*/


import android.arch.persistence.db.SupportSQLiteDatabase;
import android.content.Context;
import android.util.Log;
import android.util.Pair;

import com.amitshekhar.sqlite.DBFactory;

import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
Expand All @@ -45,8 +46,8 @@ public class ClientServer implements Runnable {
private boolean mIsRunning;
private ServerSocket mServerSocket;

public ClientServer(Context context, int port) {
mRequestHandler = new RequestHandler(context);
public ClientServer(Context context, int port, DBFactory dbFactory) {
mRequestHandler = new RequestHandler(context, dbFactory);
mPort = port;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.amitshekhar.model.RowDataRequest;
import com.amitshekhar.model.TableDataResponse;
import com.amitshekhar.model.UpdateRowResponse;
import com.amitshekhar.sqlite.DebugSQLiteDB;
import com.amitshekhar.sqlite.DBFactory;
import com.amitshekhar.sqlite.InMemoryDebugSQLiteDB;
import com.amitshekhar.sqlite.SQLiteDB;
import com.amitshekhar.utils.Constants;
Expand All @@ -42,8 +42,6 @@
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

import net.sqlcipher.database.SQLiteDatabase;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
Expand All @@ -63,17 +61,19 @@ public class RequestHandler {
private final Context mContext;
private final Gson mGson;
private final AssetManager mAssets;
private final DBFactory mDbFactory;
private boolean isDbOpened;
private SQLiteDB sqLiteDB;
private HashMap<String, Pair<File, String>> mDatabaseFiles;
private HashMap<String, Pair<File, String>> mCustomDatabaseFiles;
private String mSelectedDatabase = null;
private HashMap<String, SupportSQLiteDatabase> mRoomInMemoryDatabases = new HashMap<>();

public RequestHandler(Context context) {
public RequestHandler(Context context, DBFactory dbFactory) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Correctness Issue

Breaking API Change: Constructor Parameter Added.

The RequestHandler constructor now requires a DBFactory parameter, which will break all existing code that instantiates this class.

Current Code (Diff):

- public RequestHandler(Context context) {
+ public RequestHandler(Context context, DBFactory dbFactory) {

mContext = context;
mAssets = context.getResources().getAssets();
mGson = new GsonBuilder().serializeNulls().create();
mDbFactory = dbFactory;
}

public void handle(Socket socket) throws IOException {
Expand Down Expand Up @@ -184,8 +184,7 @@ private void openDatabase(String database) {
} else {
File databaseFile = mDatabaseFiles.get(database).first;
String password = mDatabaseFiles.get(database).second;
SQLiteDatabase.loadLibs(mContext);
sqLiteDB = new DebugSQLiteDB(SQLiteDatabase.openOrCreateDatabase(databaseFile.getAbsolutePath(), password, null));
sqLiteDB = mDbFactory.create(mContext, databaseFile.getAbsolutePath(), password);
}
isDbOpened = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.amitshekhar.sqlite;

import android.content.Context;

public interface DBFactory {

SQLiteDB create(Context context, String path, String password);

}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ public static TableDataResponse getTableData(SQLiteDB db, String selectQuery, St

tableData.isSuccessful = true;
tableData.rows = new ArrayList<>();

String[] columnNames = cursor.getColumnNames();

List<TableDataResponse.TableInfo> tableInfoListModified = new ArrayList<>();

for (String columnName : columnNames) {
for (TableDataResponse.TableInfo tableInfo : tableData.tableInfos) {
if (columnName.equals(tableInfo.title)) {
tableInfoListModified.add(tableInfo);
break;
}
}
}

if (tableData.tableInfos.size() != tableInfoListModified.size()) {
tableData.tableInfos = tableInfoListModified;
tableData.isEditable = false;
}

if (cursor.getCount() > 0) {

do {
Expand Down
5 changes: 4 additions & 1 deletion debug-db-encrypt/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ android {
}

dependencies {
implementation project(':debug-db-base')
api project(':debug-db-base')
implementation 'net.zetetic:android-database-sqlcipher:3.5.9'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

//apply from: 'debug-db-encrypt-upload.gradle'
Loading