Skip to content

Commit d1a4a67

Browse files
committed
Merge branch 'task/bugfix_and_improvements' into 'master'
Improvements and bug fixes. See merge request app-frameworks/esp-rainmaker-android!93
2 parents 50658f9 + f65f6f0 commit d1a4a67

10 files changed

+161
-90
lines changed

app/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ android {
5656
applicationId "com.espressif.rainmaker"
5757
minSdkVersion 27
5858
targetSdkVersion 34
59-
versionCode 129
60-
versionName "3.4.1 - ${getGitHash()}"
59+
versionCode 130
60+
versionName "3.4.2 - ${getGitHash()}"
6161
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
6262

6363
buildConfigField "String", "GitHash", "\"${getGitHash()}\""
@@ -231,7 +231,7 @@ dependencies {
231231
implementation 'com.larswerkman:HoloColorPicker:1.5'
232232
implementation 'com.aventrix.jnanoid:jnanoid:2.0.0'
233233
implementation 'com.github.yuriy-budiyev:code-scanner:2.1.2'
234-
implementation 'com.github.espressif:esp-idf-provisioning-android:lib-2.2.0'
234+
implementation 'com.github.espressif:esp-idf-provisioning-android:lib-2.2.1'
235235
implementation 'com.github.warkiz.tickseekbar:tickseekbar:0.1.4'
236236
implementation 'com.github.abdularis:TapHoldUpButton:0.1.2'
237237
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'

app/src/main/java/com/espressif/AppConstants.kt

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class AppConstants {
5959
const val ESP_DEVICE_SECURITY_PANEL = "esp.device.security-panel"
6060
const val ESP_DEVICE_OTHER = "esp.device.other"
6161

62+
const val MATTER_DEVICE_ON_OFF_LIGHT = 256
63+
const val MATTER_DEVICE_DIMMABLE_LIGHT = 257
6264
const val MATTER_DEVICE_LIGHT_BULB = 269
6365
const val MATTER_DEVICE_SWITCH = 259
6466
const val MATTER_DEVICE_CONTACT_SENSOR = 21
@@ -148,6 +150,7 @@ class AppConstants {
148150
const val CHANNEL_NODE_SHARING = "notify_node_sharing_id"
149151
const val CHANNEL_NODE_AUTOMATION_TRIGGER = "notify_node_automation_trigger"
150152
const val CHANNEL_GROUP_SHARING = "notify_group_sharing_id"
153+
const val CHANNEL_ADMIN = "notify_admin"
151154

152155
// Notification button actions
153156
const val ACTION_ACCEPT = "com.espressif.rainmaker.ACTION_ACCEPT"
@@ -165,6 +168,7 @@ class AppConstants {
165168
const val EVENT_GROUP_SHARING_ADD = "rmaker.event.user_node_group_sharing_add"
166169
const val EVENT_GROUP_SHARE_ADDED = "rmaker.event.user_node_group_added"
167170
const val EVENT_GROUP_SHARE_REMOVED = "rmaker.event.user_node_group_removed"
171+
const val EVENT_NODE_OTA = "rmaker.event.user_node_ota"
168172

169173
/* App related constants */
170174

app/src/main/java/com/espressif/EspApplication.java

+4
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,9 @@ private void setupNotificationChannels() {
12191219
NotificationChannel groupSharingChannel = new NotificationChannel(AppConstants.CHANNEL_GROUP_SHARING,
12201220
getString(R.string.channel_node_group_sharing), NotificationManager.IMPORTANCE_HIGH);
12211221

1222+
NotificationChannel adminChannel = new NotificationChannel(AppConstants.CHANNEL_ADMIN,
1223+
getString(R.string.channel_admin), NotificationManager.IMPORTANCE_HIGH);
1224+
12221225
NotificationManager notificationManager = getSystemService(NotificationManager.class);
12231226
notificationManager.createNotificationChannel(nodeConnectedChannel);
12241227
notificationManager.createNotificationChannel(nodeDisconnectedChannel);
@@ -1228,6 +1231,7 @@ private void setupNotificationChannels() {
12281231
notificationManager.createNotificationChannel(alertChannel);
12291232
notificationManager.createNotificationChannel(automationChannel);
12301233
notificationManager.createNotificationChannel(groupSharingChannel);
1234+
notificationManager.createNotificationChannel(adminChannel);
12311235
}
12321236
}
12331237

app/src/main/java/com/espressif/NotificationWorker.java

+88-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.espressif.db.EspDatabase;
3939
import com.espressif.rainmaker.BuildConfig;
4040
import com.espressif.rainmaker.R;
41+
import com.espressif.ui.activities.FwUpdateActivity;
4142
import com.espressif.ui.activities.GroupShareActivity;
4243
import com.espressif.ui.activities.NotificationsActivity;
4344
import com.espressif.ui.activities.SplashActivity;
@@ -120,6 +121,10 @@ public Result doWork() {
120121

121122
processAutomationTriggerEvent(title, notificationEvent, jsonEventData);
122123

124+
} else if (AppConstants.EVENT_NODE_OTA.equals(eventType)) {
125+
126+
processNodeOta(title, notificationEvent, jsonEventData);
127+
123128
} else if (AppConstants.EVENT_NODE_PARAM_MODIFIED.equals(eventType)) {
124129

125130
String nodeId = jsonEventData.optString(AppConstants.KEY_NODE_ID);
@@ -712,12 +717,12 @@ private void sendSharingRequestNotification(String title, String contentText, St
712717
declineIntent.putExtra(AppConstants.KEY_ID, id);
713718
PendingIntent declinePendingIntent;
714719
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
715-
declinePendingIntent = PendingIntent.getActivity(espApp,
720+
declinePendingIntent = PendingIntent.getBroadcast(espApp,
716721
notificationId++ /* Request code */,
717722
declineIntent,
718723
PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_ONE_SHOT);
719724
} else {
720-
declinePendingIntent = PendingIntent.getActivity(espApp,
725+
declinePendingIntent = PendingIntent.getBroadcast(espApp,
721726
notificationId++ /* Request code */,
722727
declineIntent,
723728
PendingIntent.FLAG_ONE_SHOT);
@@ -930,9 +935,50 @@ private void processAlertEvent(String title, NotificationEvent notificationEvent
930935
EventBus.getDefault().post(new UpdateEvent(UpdateEventType.EVENT_DEVICE_STATUS_UPDATE));
931936
}
932937

933-
private void sendNotification(String title, String messageBody, String channelId, Class activityClass) {
938+
// Event type - Node OTA
939+
940+
private void processNodeOta(String title, NotificationEvent notificationEvent, JSONObject jsonEventData) {
941+
942+
EspApplication espApp = (EspApplication) getApplicationContext();
943+
String nodeId = jsonEventData.optString(AppConstants.KEY_NODE_ID);
944+
StringBuilder msgBuilder = new StringBuilder();
945+
msgBuilder.append("New OTA is available");
946+
Log.d(TAG, "Node Id : " + nodeId);
947+
948+
if (!espApp.nodeMap.containsKey(nodeId)) {
949+
ApiManager.getInstance(espApp).getNodeDetails(nodeId);
950+
}
951+
952+
if (!espApp.nodeMap.containsKey(nodeId)) {
953+
loadDataFromLocalStorage();
954+
}
934955

935-
Log.e(TAG, "Message : " + messageBody);
956+
if (espApp.nodeMap.containsKey(nodeId)) {
957+
958+
EspNode node = espApp.nodeMap.get(nodeId);
959+
ArrayList<Device> devices = node.getDevices();
960+
ArrayList<String> deviceNames = new ArrayList<>();
961+
if (devices != null) {
962+
for (int deviceIndex = 0; deviceIndex < devices.size(); deviceIndex++) {
963+
deviceNames.add(devices.get(deviceIndex).getUserVisibleName());
964+
}
965+
}
966+
msgBuilder.append(" for ");
967+
msgBuilder.append(getDeviceNameString(deviceNames));
968+
969+
} else {
970+
Log.e(TAG, "Node id is not available for this event.");
971+
}
972+
973+
notificationEvent.setNotificationMsg(msgBuilder.toString());
974+
EspDatabase.getInstance(espApp).getNotificationDao().insertOrUpdate(notificationEvent);
975+
Log.d(TAG, "OTA Notification inserted in database");
976+
if (isNotificationAllowed) {
977+
sendOtaNotification(title, msgBuilder.toString(), AppConstants.CHANNEL_ADMIN);
978+
}
979+
}
980+
981+
private void sendNotification(String title, String messageBody, String channelId, Class activityClass) {
936982

937983
Intent activityIntent = new Intent(espApp, activityClass);
938984

@@ -974,6 +1020,44 @@ private void sendNotification(String title, String messageBody, String channelId
9741020
notificationManager.notify(notificationId++, notification);
9751021
}
9761022

1023+
private void sendOtaNotification(String title, String messageBody, String nodeId) {
1024+
1025+
Intent activityIntent = new Intent(espApp, FwUpdateActivity.class);
1026+
activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1027+
activityIntent.putExtra(AppConstants.KEY_NODE_ID, nodeId);
1028+
1029+
PendingIntent contentIntent;
1030+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
1031+
contentIntent = PendingIntent.getActivity(espApp,
1032+
0 /* Request code */,
1033+
activityIntent,
1034+
PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
1035+
} else {
1036+
contentIntent = PendingIntent.getActivity(espApp,
1037+
0 /* Request code */,
1038+
activityIntent,
1039+
PendingIntent.FLAG_UPDATE_CURRENT);
1040+
}
1041+
1042+
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
1043+
1044+
Notification notification = new NotificationCompat.Builder(espApp, AppConstants.CHANNEL_ADMIN)
1045+
.setSmallIcon(R.drawable.ic_notify_rainmaker)
1046+
.setColor(espApp.getColor(R.color.color_esp_logo))
1047+
.setContentTitle(title)
1048+
.setContentText(messageBody)
1049+
.setStyle(new NotificationCompat.BigTextStyle()
1050+
.bigText(messageBody))
1051+
.setContentIntent(contentIntent)
1052+
.setShowWhen(true)
1053+
.setAutoCancel(true)
1054+
.setSound(defaultSoundUri)
1055+
.setPriority(NotificationCompat.PRIORITY_HIGH)
1056+
.build();
1057+
1058+
notificationManager.notify(notificationId++, notification);
1059+
}
1060+
9771061
private void loadDataFromLocalStorage() {
9781062

9791063
EspDatabase espDatabase = EspDatabase.getInstance(getApplicationContext());

app/src/main/java/com/espressif/matter/ThreadBRActivity.kt

-6
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,6 @@ class ThreadBRActivity : AppCompatActivity() {
144144
}
145145
?: run {
146146
Log.d(TAG, "ThreadClient: no preferred credentials found")
147-
Toast.makeText(
148-
this,
149-
"No preferred credentials found",
150-
Toast.LENGTH_SHORT
151-
)
152-
.show()
153147

154148
val matterNodeId = espApp.matterRmNodeIdMap.get(nodeId)
155149
val id = matterNodeId?.let { BigInteger(it, 16) }

app/src/main/java/com/espressif/ui/Utils.java

+2
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,8 @@ public static void setDeviceIcon(ImageView ivDevice, String deviceType) {
543543
public static String getEspDeviceTypeForMatterDevice(int deviceType) {
544544

545545
switch (deviceType) {
546+
case AppConstants.MATTER_DEVICE_ON_OFF_LIGHT:
547+
case AppConstants.MATTER_DEVICE_DIMMABLE_LIGHT:
546548
case AppConstants.MATTER_DEVICE_LIGHT_BULB:
547549
return AppConstants.ESP_DEVICE_LIGHT_BULB;
548550

app/src/main/java/com/espressif/ui/activities/FwUpdateActivity.java

+26-17
Original file line numberDiff line numberDiff line change
@@ -281,28 +281,30 @@ private void updateUi(EspOtaUpdate otaUpdate) {
281281
txtUpdateBtn.setText(R.string.btn_update);
282282
tvUpdateStatus.setText(R.string.fw_update_available);
283283
btnCheckUpdate.setVisibility(View.VISIBLE);
284-
StringBuilder versionInfo = new StringBuilder();
285-
versionInfo.append(getString(R.string.current_version));
286-
versionInfo.append(": ");
287-
versionInfo.append(espApp.nodeMap.get(nodeId).getFwVersion());
288-
versionInfo.append("\n\n");
289-
versionInfo.append(getString(R.string.available_version));
290-
versionInfo.append(": ");
291-
versionInfo.append(otaUpdate.getFwVersion());
292-
tvAdditionalInfo.setText(versionInfo.toString());
284+
tvAdditionalInfo.setText(versionInfoString());
293285
tvAdditionalInfo.setVisibility(View.VISIBLE);
294286
ivUpdateProgress.setImageResource(R.drawable.ic_update);
295287
ivUpdateProgress.setVisibility(View.VISIBLE);
296288
break;
297289

298290
case AppConstants.OTA_STATUS_IN_PROGRESS:
299291
case AppConstants.OTA_STATUS_STARTED:
292+
case AppConstants.OTA_STATUS_FAILED:
300293
long ts1 = System.currentTimeMillis();
301294
long ts2 = otaUpdate.getTimestamp();
302295
long diff = ts1 - ts2;
303296
if (diff > TIMEOUT_IN_MILLIS) {
304297
stopUpdateValueTask();
305-
displayFailure(getString(R.string.error_fw_update), getString(R.string.error_device_connection));
298+
updateInProgress = false;
299+
txtUpdateBtn.setText(R.string.btn_update);
300+
tvUpdateStatus.setText(R.string.fw_update_available);
301+
btnCheckUpdate.setVisibility(View.VISIBLE);
302+
tvAdditionalInfo.setText(versionInfoString());
303+
tvAdditionalInfo.setVisibility(View.VISIBLE);
304+
ivUpdateProgress.setImageResource(R.drawable.ic_update);
305+
ivUpdateProgress.setVisibility(View.VISIBLE);
306+
gifDownloading.setVisibility(View.GONE);
307+
btnCheckUpdate.setVisibility(View.VISIBLE);
306308
} else {
307309
updateInProgress = true;
308310
btnCheckUpdate.setVisibility(View.INVISIBLE);
@@ -338,12 +340,6 @@ private void updateUi(EspOtaUpdate otaUpdate) {
338340
displayFailure(otaUpdate.getAdditionalInfo(), getString(R.string.error_fw_update_rejected));
339341
break;
340342

341-
case AppConstants.OTA_STATUS_FAILED:
342-
stopUpdateValueTask();
343-
updateInProgress = false;
344-
displayFailure(otaUpdate.getAdditionalInfo(), getString(R.string.error_fw_update_failed));
345-
break;
346-
347343
case AppConstants.OTA_STATUS_UNKNOWN:
348344
stopUpdateValueTask();
349345
updateInProgress = false;
@@ -354,7 +350,8 @@ private void updateUi(EspOtaUpdate otaUpdate) {
354350
Log.e(TAG, "OTA update status is not available.");
355351
}
356352

357-
if (isUpdateAvailable && !TextUtils.isEmpty(otaUpdate.getOtaStatusDescription())) {
353+
if (isUpdateAvailable && !TextUtils.isEmpty(otaUpdate.getOtaStatusDescription())
354+
&& updateInProgress) {
358355
tvDescription.setVisibility(View.VISIBLE);
359356
tvDescription.setText(otaUpdate.getOtaStatusDescription());
360357
} else {
@@ -465,6 +462,18 @@ public void onClick(DialogInterface dialog, int which) {
465462
userDialog.show();
466463
}
467464

465+
private String versionInfoString() {
466+
StringBuilder versionInfo = new StringBuilder();
467+
versionInfo.append(getString(R.string.current_version));
468+
versionInfo.append(": ");
469+
versionInfo.append(espApp.nodeMap.get(nodeId).getFwVersion());
470+
versionInfo.append("\n\n");
471+
versionInfo.append(getString(R.string.available_version));
472+
versionInfo.append(": ");
473+
versionInfo.append(otaUpdate.getFwVersion());
474+
return versionInfo.toString();
475+
}
476+
468477
private void startUpdateValueTask() {
469478
isTaskStarted = true;
470479
handler.removeCallbacks(updateValuesTask);

app/src/main/java/com/espressif/ui/activities/NodeDetailsActivity.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,15 @@ private void setNodeInfo() {
154154
nodeInfoList.add(getString(R.string.node_id));
155155
nodeInfoValueList.add(node.getNodeId());
156156

157-
nodeInfoList.add(getString(R.string.node_type));
158-
nodeInfoValueList.add(node.getNodeType());
157+
if (!TextUtils.isEmpty(node.getNodeType())) {
158+
nodeInfoList.add(getString(R.string.node_type));
159+
nodeInfoValueList.add(node.getNodeType());
160+
}
159161

160-
nodeInfoList.add(getString(R.string.node_fw_version));
161-
nodeInfoValueList.add(node.getFwVersion());
162+
if (!TextUtils.isEmpty(node.getFwVersion())) {
163+
nodeInfoList.add(getString(R.string.node_fw_version));
164+
nodeInfoValueList.add(node.getFwVersion());
165+
}
162166

163167
nodeInfoList.add(getString(R.string.node_fw_update));
164168
nodeInfoValueList.add(getString(R.string.btn_check_update));

0 commit comments

Comments
 (0)