1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-10-12 08:08:09 +02:00
Gadgetbridge/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/PendingIntentUtils.java

62 lines
2.3 KiB
Java
Raw Normal View History

Bangle.js: Bump flavor targetSdkVersion to 31 This also touches parts of the app not only used for bangle.js. E.g. pending intents gets new flags from SDK 23 inclusive. Bluetooth permissions are updated to work on SDK 31. Permission handling is updated to the new way for doing it with introduction of a new function. This is called for newer sdk versions. bump Bangle.js flavor targetSdkVersion to 31 update comments re SDK 31 set the 'exported=true' I introduced to false instead - except for three places add uses-permission for handling bluetooth in order to work on api >30 add if-blocks adding FLAG_IMMUTABLE to PendingIntents on api >30 add link to bluetooth documentation Add comment to banglejs manifest. Add requirement annotation to ControlCenterv bump compileSdkVersion to 31 add "OpenAppSettings" permission popup while working out individual permission popups on android 13 if SDK < 31 do permissions one by one, else send user to app info page to switch permissions manually working solution, but needs cleaning do some cleaning, not done though remove some logging remove import Log tweak and remove toasts in new permissions handling Change conditions `> Build.VERSION_CODES.Q` to `>= Build.VERSION_CODES.R` matching the style used everywhere else Revert "Change conditions `> Build.VERSION_CODES.Q` to `>= Build.VERSION_CODES.R` matching the style used everywhere else" This reverts commit 2929629ff43fbb685eb3d15e42459f321f68fa11. Revert "add if-blocks adding FLAG_IMMUTABLE to PendingIntents on api >30" This reverts commit ed8e1df7bb8b71fee745fbf9d10747d47c8f6cb8. Pending intents gets `PendingIntent.FLAG_IMMUTABLE` if `(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)`. Bangle.js: undo `@RequiresApi` code R ... to remove error in Android Studio where declared required api was higher then minSDK version. Use FLAG_MUTABLE for reply to test notification This should fix Gadgetbridge crashing when replying to the test notification from the debug activity. As reported here: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/2924#issuecomment-917282 Change to use FLAG_IMMUTABLE/_MUTABLE from SDK 23 ... as suggested by Android Studio. This is supposed to make the app more secure by not allowing certain changes to pending intents where they are not expected. If I understood correctly. Add PendingIntentUtils class to manage mutability
2022-10-09 14:53:04 +02:00
package nodomain.freeyourgadget.gadgetbridge.util;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
public class PendingIntentUtils {
public static PendingIntent getBroadcast(Context context,
int requestCode,
Intent intent,
int flags,
boolean makeMutable) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (makeMutable) {
flags |= PendingIntent.FLAG_MUTABLE;
} else {
flags |= PendingIntent.FLAG_IMMUTABLE;
}
return PendingIntent.getBroadcast(context, requestCode, intent, flags);
}
return PendingIntent.getBroadcast(context, requestCode, intent, flags);
}
public static PendingIntent getActivity(Context context,
int requestCode,
Intent intent,
int flags,
boolean makeMutable) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (makeMutable) {
flags |= PendingIntent.FLAG_MUTABLE;
} else {
flags |= PendingIntent.FLAG_IMMUTABLE;
}
return PendingIntent.getActivity(context, requestCode, intent, flags);
}
return PendingIntent.getActivity(context, requestCode, intent, flags);
}
public static PendingIntent getService(Context context,
int requestCode,
Intent intent,
int flags,
boolean makeMutable) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (makeMutable) {
flags |= PendingIntent.FLAG_MUTABLE;
} else {
flags |= PendingIntent.FLAG_IMMUTABLE;
}
return PendingIntent.getService(context, requestCode, intent, flags);
}
return PendingIntent.getService(context, requestCode, intent, flags);
}
}