Skip to content

Commit

Permalink
Set exported attribute to dynamic broadcast receivers
Browse files Browse the repository at this point in the history
  • Loading branch information
avazirna committed Nov 15, 2024
1 parent 5f83b76 commit 88760e3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
10 changes: 9 additions & 1 deletion app/src/org/commcare/activities/CommCareActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.DialogInterface;
import android.content.IntentFilter;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.text.Spannable;
import android.util.DisplayMetrics;
Expand Down Expand Up @@ -302,7 +303,14 @@ protected void onResume() {

if (shouldListenToSyncComplete() && isBackgroundSyncEnabled()) {
dataSyncCompleteBroadcastReceiver = new DataSyncCompleteBroadcastReceiver();
registerReceiver(dataSyncCompleteBroadcastReceiver, new IntentFilter(COMMCARE_DATA_UPDATE_ACTION));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
registerReceiver(
dataSyncCompleteBroadcastReceiver,
new IntentFilter(COMMCARE_DATA_UPDATE_ACTION), Context.RECEIVER_NOT_EXPORTED);
} else {
registerReceiver(
dataSyncCompleteBroadcastReceiver, new IntentFilter(COMMCARE_DATA_UPDATE_ACTION));
}
}
}

Expand Down
12 changes: 10 additions & 2 deletions app/src/org/commcare/activities/FormEntryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,11 @@ public void onReceive(Context context, Intent intent) {
IntentFilter filter = new IntentFilter();
filter.addAction(PollSensorAction.XPATH_ERROR_ACTION);
filter.addAction(GeoUtils.ACTION_LOCATION_ERROR);
registerReceiver(mLocationServiceIssueReceiver, filter);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
registerReceiver(mLocationServiceIssueReceiver, filter, Context.RECEIVER_NOT_EXPORTED);
} else {
registerReceiver(mLocationServiceIssueReceiver, filter);
}
}

@Override
Expand Down Expand Up @@ -997,7 +1001,11 @@ public void onResumeSessionSafe() {
reportVideoUsageIfAny();

IntentFilter intentFilter = new IntentFilter(PENGING_SYNC_ALERT_ACTION);
registerReceiver(pendingSyncAlertBroadcastReceiver, intentFilter);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
registerReceiver(pendingSyncAlertBroadcastReceiver, intentFilter, Context.RECEIVER_NOT_EXPORTED);
} else {
registerReceiver(pendingSyncAlertBroadcastReceiver, intentFilter);
}

// Flag that a background sync shouldn't be triggered when this activity is in the foreground
CommCareApplication.instance().setBackgroundSyncSafe(false);
Expand Down
8 changes: 7 additions & 1 deletion app/src/org/commcare/utils/SessionRegistrationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.content.Intent;
import android.content.IntentFilter;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Build;
import android.util.Log;

import org.commcare.activities.DispatchActivity;
Expand Down Expand Up @@ -52,7 +54,11 @@ public static boolean handleSessionExpiration(AppCompatActivity activity) {
}

public static void registerSessionExpirationReceiver(AppCompatActivity activity) {
activity.registerReceiver(userSessionExpiredReceiver, expirationFilter);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
activity.registerReceiver(userSessionExpiredReceiver, expirationFilter, Context.RECEIVER_NOT_EXPORTED);
} else {
activity.registerReceiver(userSessionExpiredReceiver, expirationFilter);
}
}

/**
Expand Down

0 comments on commit 88760e3

Please sign in to comment.