Skip to content

Commit

Permalink
[STAD-571] Set receiver_not_exported flag on Android 14
Browse files Browse the repository at this point in the history
[STAD-571] Set receiver_not_exported flag on Android 14
  • Loading branch information
hb0 authored Feb 26, 2024
2 parents fb69797 + 7e0a98c commit 8280810
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
Expand Down Expand Up @@ -732,8 +733,13 @@ Context getContext() {
private synchronized void runService(final Measurement measurement,
final @NonNull StartUpFinishedHandler startUpFinishedHandler) throws DataCapturingException {
final Context context = getContext();
context.registerReceiver(startUpFinishedHandler,
new IntentFilter(MessageCodes.getServiceStartedActionId(appId)));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context.registerReceiver(startUpFinishedHandler,
new IntentFilter(MessageCodes.getServiceStartedActionId(appId)), Context.RECEIVER_NOT_EXPORTED);
} else {
context.registerReceiver(startUpFinishedHandler,
new IntentFilter(MessageCodes.getServiceStartedActionId(appId)));
}
Log.d(StartUpFinishedHandler.TAG, "DataCapturingService: StartUpFinishedHandler registered for broadcasts.");

Log.d(TAG, "Starting the background service for measurement " + measurement + "!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Process;
Expand Down Expand Up @@ -136,8 +137,13 @@ public void checkIsRunningAsync(final long timeout, final @NonNull TimeUnit unit
// Run receiver on a different thread so it runs even if calling thread waits for it to return:
pongReceiverThread.start();
Handler receiverHandler = new Handler(pongReceiverThread.getLooper());
context.get().registerReceiver(this, new IntentFilter(pongActionId), null,
receiverHandler);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context.get().registerReceiver(this, new IntentFilter(pongActionId), null,
receiverHandler, Context.RECEIVER_NOT_EXPORTED);
} else {
context.get().registerReceiver(this, new IntentFilter(pongActionId), null,
receiverHandler);
}

long currentUptimeInMillis = SystemClock.uptimeMillis();
long offset = unit.toMillis(timeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SyncResult;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
Expand Down Expand Up @@ -145,7 +146,11 @@ public void testUploadProgressHappyPath() throws CursorIsNullException, NoSuchMe
filter.addAction(CyfaceConnectionStatusListener.SYNC_FINISHED);
filter.addAction(CyfaceConnectionStatusListener.SYNC_PROGRESS);
filter.addAction(CyfaceConnectionStatusListener.SYNC_STARTED);
context.registerReceiver(receiver, filter);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context.registerReceiver(receiver, filter, Context.RECEIVER_NOT_EXPORTED);
} else {
context.registerReceiver(receiver, filter);
}

ContentProviderClient client = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;

import de.cyface.utils.Validate;

Expand Down Expand Up @@ -44,7 +45,11 @@ public ConnectionStatusReceiver(final Context context) {
filter.addAction(SYNC_FINISHED);
filter.addAction(SYNC_PROGRESS);
filter.addAction(SYNC_STARTED);
context.registerReceiver(this, filter);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context.registerReceiver(this, filter, Context.RECEIVER_NOT_EXPORTED);
} else {
context.registerReceiver(this, filter);
}
}

@Override
Expand Down

0 comments on commit 8280810

Please sign in to comment.