Skip to content

Commit

Permalink
Merge pull request #22 from awareframework/main_beta_bridge
Browse files Browse the repository at this point in the history
Code updated: aware log messages
  • Loading branch information
tinazhang128 authored Dec 11, 2023
2 parents 3fb3f1c + d721390 commit 584cd76
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 14 additions & 1 deletion aware-core/src/main/java/com/aware/Aware.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified resources/aware-phone-armeabi-v7a-release.apk
Binary file not shown.

0 comments on commit 584cd76

Please sign in to comment.