Skip to content

Commit 991a058

Browse files
author
Arief Nur Putranto
committed
fix issue get db, crash, and issue security
1 parent c242ab9 commit 991a058

File tree

7 files changed

+39
-27
lines changed

7 files changed

+39
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Second, you need to add SDK dependencies inside your app .gradle. Then, you need
5454
```
5555
dependencies {
5656
...
57-
implementation 'com.qiscus.sdk:chat-core:1.9.0'
57+
implementation 'com.qiscus.sdk:chat-core:1.9.1'
5858
}
5959
```
6060

chat-core/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343

4444
<service
4545
android:name=".service.QiscusNetworkCheckerJobService"
46-
android:exported="true"
46+
android:exported="false"
4747
android:label="QiscusNetworkCheckerJobService"
4848
android:permission="android.permission.BIND_JOB_SERVICE" />
4949
<service android:name="org.eclipse.paho.android.service.MqttService" />
5050
<service android:name=".service.QiscusSyncService" />
5151

5252
<service
5353
android:name=".service.QiscusSyncJobService"
54-
android:exported="true"
54+
android:exported="false"
5555
android:label="QiscusSyncJobService"
5656
android:permission="android.permission.BIND_JOB_SERVICE" />
5757
</application>

chat-core/src/main/java/com/qiscus/sdk/chat/core/QiscusAppComponent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public synchronized String getAppId() {
8383
}
8484

8585
public synchronized String getAppServer() {
86-
return appServer;
86+
return this.appServer;
8787
}
8888

8989
public synchronized void setAppServer(String appServer) {
@@ -107,11 +107,11 @@ public synchronized void setAutomaticHeartBeat(int automaticHeartBeat) {
107107
}
108108

109109
public synchronized int getNetworkConnectionInterval() {
110-
return networkConnectionInterval;
110+
return this.networkConnectionInterval;
111111
}
112112

113113
public synchronized void setNetworkConnectionInterval(int automaticHeartBeatnetworkConnectionInterval) {
114-
this.networkConnectionInterval = networkConnectionInterval;
114+
this.networkConnectionInterval = automaticHeartBeatnetworkConnectionInterval;
115115
}
116116

117117
public synchronized Boolean getEnableEventReport() {

chat-core/src/main/java/com/qiscus/sdk/chat/core/data/local/QiscusDb.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
final class QiscusDb {
3939

4040
static final String DATABASE_NAME = "qiscus.db";
41-
static final int DATABASE_VERSION = 20;
42-
static final int DATABASE_MINIMUM_VERSION = 20;
41+
static final int DATABASE_VERSION = 21;
42+
static final int DATABASE_MINIMUM_VERSION = 21;
4343
private static final String JSON_EMPTY_FORMAT = "{}";
4444
private static final String TAG = QiscusDb.class.getSimpleName();
4545

@@ -283,14 +283,14 @@ static ContentValues toContentValues(QiscusComment qiscusComment) {
283283
values.put(COLUMN_ROOM_ID, qiscusComment.getRoomId());
284284
values.put(COLUMN_UNIQUE_ID, qiscusComment.getUniqueId());
285285
values.put(COLUMN_COMMENT_BEFORE_ID, qiscusComment.getCommentBeforeId());
286-
values.put(COLUMN_MESSAGE, set(qiscusComment.getMessage()));
286+
values.put(COLUMN_MESSAGE, qiscusComment.getMessage());
287287
values.put(COLUMN_SENDER, set(qiscusComment.getSender()));
288288
values.put(COLUMN_SENDER_EMAIL, set(qiscusComment.getSenderEmail()));
289289
values.put(COLUMN_SENDER_AVATAR, set(qiscusComment.getSenderAvatar()));
290290
values.put(COLUMN_TIME, qiscusComment.getTime().getTime());
291-
values.put(COLUMN_STATE, set(qiscusComment.getState()));
292-
values.put(COLUMN_DELETED, set(qiscusComment.isDeleted()));
293-
values.put(COLUMN_HARD_DELETED, set(qiscusComment.isHardDeleted()));
291+
values.put(COLUMN_STATE, qiscusComment.getState());
292+
values.put(COLUMN_DELETED, qiscusComment.isDeleted() ? 1 : 0);
293+
values.put(COLUMN_HARD_DELETED, qiscusComment.isHardDeleted() ? 1: 0);
294294
values.put(COLUMN_TYPE, set(qiscusComment.getRawType()));
295295
values.put(COLUMN_PAYLOAD, set(qiscusComment.getExtraPayload()));
296296
values.put(COLUMN_EXTRAS, set(
@@ -316,9 +316,9 @@ static QiscusComment parseCursor(Cursor cursor) {
316316
qiscusComment.setCommentBeforeId(
317317
cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_COMMENT_BEFORE_ID))
318318
);
319-
qiscusComment.setMessage(getString(
319+
qiscusComment.setMessage(
320320
cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_MESSAGE))
321-
));
321+
);
322322
qiscusComment.setSender(getString(
323323
cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_SENDER))
324324
));
@@ -331,15 +331,13 @@ static QiscusComment parseCursor(Cursor cursor) {
331331
qiscusComment.setTime(new Date(
332332
cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_TIME))
333333
));
334-
qiscusComment.setState(getInteger(
335-
cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_STATE))
336-
));
337-
qiscusComment.setDeleted(getBoolean(
338-
cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_DELETED))
339-
));
340-
qiscusComment.setHardDeleted(getBoolean(
341-
cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_HARD_DELETED))
334+
qiscusComment.setState(
335+
cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_STATE)
342336
));
337+
qiscusComment.setDeleted(
338+
cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_DELETED)) == 1
339+
);
340+
qiscusComment.setHardDeleted(cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_HARD_DELETED)) == 1);
343341
qiscusComment.setRawType(getString(
344342
cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_TYPE))
345343
));

chat-core/src/main/java/com/qiscus/sdk/chat/core/service/QiscusNetworkCheckerJobService.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void onCreate() {
118118
@Override
119119
public void onDestroy() {
120120

121-
Executors.newSingleThreadExecutor().execute(() -> {
121+
if (Thread.currentThread().getId() != 1){
122122
try {
123123
unregisterReceiver(networkStateReceiver);
124124
QiscusLogger.print(TAG, "onDestroy");
@@ -130,7 +130,21 @@ public void onDestroy() {
130130
} catch (Exception e) {
131131
QiscusErrorLogger.print(e);
132132
}
133-
});
133+
}else{
134+
Executors.newSingleThreadExecutor().execute(() -> {
135+
try {
136+
unregisterReceiver(networkStateReceiver);
137+
QiscusLogger.print(TAG, "onDestroy");
138+
EventBus.getDefault().unregister(this);
139+
}catch (IllegalArgumentException e) {
140+
// already unregistered
141+
}catch (RuntimeException r) {
142+
QiscusErrorLogger.print(r);
143+
} catch (Exception e) {
144+
QiscusErrorLogger.print(e);
145+
}
146+
});
147+
}
134148

135149
super.onDestroy();
136150
}

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Secondly, you need to add SDK dependencies inside your app .gradle. Then, you ne
8080
```
8181
dependencies {
8282
...
83-
implementation 'com.qiscus.sdk:chat-core:1.9.0'
83+
implementation 'com.qiscus.sdk:chat-core:1.9.1'
8484
}
8585
```
8686

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ chatVersionPatch=0
4343
# === qiscus chat-core library version ===
4444
chatCoreVersionMajor=1
4545
chatCoreVersionMinor=9
46-
chatCoreVersionPatch=0
46+
chatCoreVersionPatch=1
4747

4848
# === qiscus default base url
4949
BASE_URL_SERVER="https://api.qiscus.com/"
@@ -59,7 +59,7 @@ android.useAndroidX=true
5959

6060
libraryGroupId=com.qiscus.sdk
6161
libraryArtifactId=chat-core
62-
libraryVersion=1.9.0
62+
libraryVersion=1.9.1
6363

6464
libraryGroupIdChat=com.qiscus.sdk
6565
libraryArtifactIdChat=chat

0 commit comments

Comments
 (0)