Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f0a4c738 authored by Mark Harman's avatar Mark Harman Committed by Mohammed Althaf T
Browse files

Need to specify RECEIVER_NOT_EXPORTED for Android 14.

parent c1e8d19f
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
package net.sourceforge.opencamera.remotecontrol;

import static android.content.Context.RECEIVER_NOT_EXPORTED;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -262,8 +264,17 @@ public class BluetoothRemoteControl {
            if( MyDebug.LOG )
                Log.d(TAG, "Remote enabled, starting service");
            main_activity.bindService(gattServiceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
            // For Android 14 (UPSIDE_DOWN_CAKE) onwards, a flag of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED must be specified when using
            // registerReceiver with non-system intents, otherwise a SecurityException will be thrown.
            // The if condition is for TIRAMISU as there seems no harm doing this for earlier versions too, but RECEIVER_NOT_EXPORTED
            // requires Android 13.
            if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU ) {
                main_activity.registerReceiver(remoteControlCommandReceiver, makeRemoteCommandIntentFilter(), RECEIVER_NOT_EXPORTED);
            }
            else {
                main_activity.registerReceiver(remoteControlCommandReceiver, makeRemoteCommandIntentFilter());
            }
        }
        else {
            if( MyDebug.LOG )
                Log.d(TAG, "Remote disabled, stopping service");