diff --git a/CHANGES.txt b/CHANGES.txt index f16f9cd..cd1565e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,12 @@ Change log for AWARE-Light +4.1.5.light.bundle +- Logging if the application is terminated by user actions or system actions to aware_log table +- Screen reader function improved preformance + +4.1.4.light.bundle +- same as 4.1.3.light.bundle + 4.1.3.light.bundle - Fixed bug for random EMA triggered condition - Screen reader function improved preformance diff --git a/aware-core/src/main/java/com/aware/Aware.java b/aware-core/src/main/java/com/aware/Aware.java index 803c6ab..5e7bf84 100644 --- a/aware-core/src/main/java/com/aware/Aware.java +++ b/aware-core/src/main/java/com/aware/Aware.java @@ -212,7 +212,7 @@ public class Aware extends Service { /** * Variable for the Doze ignore list */ - private static final int AWARE_BATTERY_OPTIMIZATION_ID = 567567; + public static final int AWARE_BATTERY_OPTIMIZATION_ID = 567567; /** * Holds a reference to the AWARE account, automatically restore in each plugin. @@ -2663,6 +2663,9 @@ public static boolean isSyncEnabled(Context context, String authority) { public static void stopAWARE(Context context) { if (context == null) return; + // Check if the activity is finishing + boolean isFinishing = ((Activity) context).isFinishing(); + Intent aware = new Intent(context, Aware.class); context.stopService(aware); @@ -2694,6 +2697,16 @@ public static void stopAWARE(Context context) { stopKeyboard(context); stopScreenText(context); stopScheduler(context); + + + // Handle based on whether it's user-initiated or system-initiated closure + if (isFinishing) { + // User initiated closure + Aware.debug(context, "AWARE-Light interface cleaned from the array of frequently used apps"); + } else { + // System-initiated closure + Aware.debug(context, "AWARE-Light interface cleaned by smartphone system"); + } } /** diff --git a/aware-phone/src/main/java/com/aware/phone/ui/Aware_Light_Client.java b/aware-phone/src/main/java/com/aware/phone/ui/Aware_Light_Client.java index a3e18d0..8336e3d 100644 --- a/aware-phone/src/main/java/com/aware/phone/ui/Aware_Light_Client.java +++ b/aware-phone/src/main/java/com/aware/phone/ui/Aware_Light_Client.java @@ -1,7 +1,10 @@ package com.aware.phone.ui; import android.Manifest; +import android.app.Activity; import android.app.Dialog; +import android.app.NotificationManager; +import android.app.PendingIntent; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -18,6 +21,7 @@ import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; +import android.os.PowerManager; import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; import android.preference.ListPreference; @@ -51,10 +55,13 @@ import java.util.UUID; import androidx.appcompat.widget.Toolbar; +import androidx.core.app.NotificationCompat; import androidx.core.content.ContextCompat; import androidx.core.content.PermissionChecker; +import static com.aware.Aware.AWARE_NOTIFICATION_IMPORTANCE_GENERAL; import static com.aware.Aware.TAG; +import static com.aware.Aware.setNotificationProperties; /** * @@ -469,8 +476,71 @@ protected void onPause() { if (prefs != null) prefs.unregisterOnSharedPreferenceChangeListener(this); } + public static boolean isBatteryOptimizationIgnored(Context context, String package_name) { + boolean is_ignored = true; + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { + PowerManager pm = (PowerManager) context.getApplicationContext().getSystemService(Context.POWER_SERVICE); + is_ignored = pm.isIgnoringBatteryOptimizations(package_name); + } + + if (!is_ignored) { + NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, Aware.AWARE_NOTIFICATION_CHANNEL_GENERAL); + mBuilder.setSmallIcon(com.aware.R.drawable.ic_stat_aware_recharge); + mBuilder.setContentTitle(context.getApplicationContext().getResources().getString(com.aware.R.string.aware_activate_battery_optimize_ignore_title)); + mBuilder.setContentText(context.getApplicationContext().getResources().getString(com.aware.R.string.aware_activate_battery_optimize_ignore)); + mBuilder.setAutoCancel(true); + mBuilder.setOnlyAlertOnce(true); //notify the user only once + mBuilder.setDefaults(NotificationCompat.DEFAULT_ALL); + mBuilder = setNotificationProperties(mBuilder, AWARE_NOTIFICATION_IMPORTANCE_GENERAL); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + mBuilder.setChannelId(Aware.AWARE_NOTIFICATION_CHANNEL_GENERAL); + + Intent batteryIntent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); + batteryIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + + PendingIntent clickIntent = PendingIntent.getActivity(context, 0, batteryIntent, PendingIntent.FLAG_UPDATE_CURRENT); + mBuilder.setContentIntent(clickIntent); + + NotificationManager notManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + notManager.notify(Aware.AWARE_BATTERY_OPTIMIZATION_ID, mBuilder.build()); + } + + Log.d(Aware.TAG, "Battery Optimizations: " + is_ignored); + + return is_ignored; + } + + @Override + protected void onStop() { + // Check if the activity is finishing + boolean isFinishing = this.isFinishing(); + + // Handle based on whether it's system-initiated closure + if (!isFinishing) { + if (isBatteryOptimizationIgnored(this, "com.aware.phone")) { + Log.d("AWARE-Light_Client", "AWARE-Light stopped from background: may be caused by battery optimization"); + Aware.debug(this, "AWARE-Light stopped from background: may be caused by battery optimization"); + } else { + Log.d("AWARE-Light_Client", "AWARE-Light stopped from background: may be caused by system settings"); + Aware.debug(this, "AWARE-Light stopped from background: may be caused by system settings"); + } + } + super.onStop(); + } + + @Override protected void onDestroy() { + // Check if the activity is finishing + boolean isFinishing = this.isFinishing(); + + // Handle based on whether it's user-initiated or system-initiated closure + if (isFinishing) { + // User initiated closure + Aware.debug(this, "AWARE-Light interface cleaned from the list of frequently used apps"); + } + Log.d("AWARE-Light_Client", "AWARE-Light interface cleaned from the list of frequently used apps"); super.onDestroy(); unregisterReceiver(packageMonitor); } diff --git a/build.gradle b/build.gradle index 996e351..ac500cd 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { mqtt_libs = '1.2.1' ion_libs = "2.+" google_libs = "17.0.0" - version_code = 3 + version_code = 5 version_readable = "4.1." + version_code + ".light.bundle" compile_sdk = 28 target_sdk = 28 diff --git a/resources/aware-phone-armeabi-v7a-release.apk b/resources/aware-phone-armeabi-v7a-release.apk index ed3d89a..e9a082d 100644 Binary files a/resources/aware-phone-armeabi-v7a-release.apk and b/resources/aware-phone-armeabi-v7a-release.apk differ