Skip to content

Commit

Permalink
try to use reflection instead of rising target sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
JiglioNero committed Nov 23, 2023
1 parent 3b14f7d commit 14e2566
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class InstallStatusReceiver extends BroadcastReceiver {

@VisibleForTesting
static final String INSTALL_STATUS_ACTION = "com.microsoft.appcenter.action.INSTALL_STATUS";
@VisibleForTesting
static final String FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT_NAME = "FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT";

static IntentFilter getInstallerReceiverFilter() {
IntentFilter installerReceiverFilter = new IntentFilter();
Expand All @@ -45,12 +47,12 @@ static IntentFilter getInstallerReceiverFilter() {
* @param requestCode request code for the sender.
* @return IntentSender with receiver.
*/
static IntentSender getInstallStatusIntentSender(Context context, int requestCode) {
static IntentSender getInstallStatusIntentSender(Context context, int requestCode) throws NoSuchFieldException, IllegalAccessException {
int broadcastFlags = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
broadcastFlags = PendingIntent.FLAG_MUTABLE;
if (Build.VERSION.SDK_INT >= 34) {
broadcastFlags |= PendingIntent.FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT;
broadcastFlags |= PendingIntent.class.getDeclaredField(FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT_NAME).getInt(PendingIntent.class);
}
}
PendingIntent pendingIntent = PendingIntent.getBroadcast(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private synchronized void startInstallSession(@NonNull Uri localUri) {
IntentSender statusReceiver = InstallStatusReceiver.getInstallStatusIntentSender(mContext, mSessionId);
session.commit(statusReceiver);
session.close();
} catch (IOException | RuntimeException e) {
} catch (IOException | RuntimeException | NoSuchFieldException | IllegalAccessException e) {
if (session != null) {
session.abandon();
}
Expand Down
4 changes: 2 additions & 2 deletions versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ext {
versionCode = 72
versionName = '5.0.3'
minSdkVersion = 21
compileSdkVersion = 34
targetSdkVersion = 34
compileSdkVersion = 33
targetSdkVersion = 33
annotationVersion = '1.2.0'
}

0 comments on commit 14e2566

Please sign in to comment.