Skip to content

Commit

Permalink
impr(android): support PendingIntent mutable flags (#12890)
Browse files Browse the repository at this point in the history
Closes TIMOB-28476
  • Loading branch information
garymathews authored Aug 25, 2021
1 parent 15e292e commit 75ce8e4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ public class AndroidModule extends KrollModule
@Kroll.constant
public static final int FLAG_CANCEL_CURRENT = PendingIntent.FLAG_CANCEL_CURRENT;
@Kroll.constant
public static final int FLAG_IMMUTABLE = PendingIntent.FLAG_IMMUTABLE;
@Kroll.constant
public static final int FLAG_MUTABLE = PendingIntent.FLAG_MUTABLE;
@Kroll.constant
public static final int FLAG_NO_CREATE = PendingIntent.FLAG_NO_CREATE;
@Kroll.constant
public static final int FLAG_ONE_SHOT = PendingIntent.FLAG_ONE_SHOT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import android.app.PendingIntent;
import android.content.Context;
import android.os.Build;

@Kroll.proxy(creatableInModule = AndroidModule.class,
propertyAccessors = { TiC.PROPERTY_FLAGS, TiC.PROPERTY_INTENT, TiC.PROPERTY_UPDATE_CURRENT_INTENT })
Expand Down Expand Up @@ -87,7 +88,14 @@ public void handleCreationDict(KrollDict dict)

//add FLAG_UPDATE_CURRENT if updateCurrentIntent is true
if (updateCurrentIntent) {
flags = flags | PendingIntent.FLAG_UPDATE_CURRENT;
flags |= PendingIntent.FLAG_UPDATE_CURRENT;
}

// NOTE: Android 12 requires mutability flags.
// Set `FLAG_IMMUTABLE` if not `FLAG_MUTABLE`.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
&& (flags & PendingIntent.FLAG_MUTABLE) == 0) {
flags |= PendingIntent.FLAG_IMMUTABLE;
}

super.handleCreationDict(dict);
Expand Down
22 changes: 22 additions & 0 deletions apidoc/Titanium/Android/Android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,28 @@ properties:
type: Number
permission: read-only

- name: FLAG_IMMUTABLE
summary: Pending intent should be immutable.
description: |
Use with the <Titanium.Android.PendingIntent.flags> property.
See [PendingIntent.FLAG_IMMUTABLE in the Android API Reference](https://developer.android.com/reference/android/app/PendingIntent.html#FLAG_IMMUTABLE).
type: Number
permission: read-only
since: "10.1.0"
osver: {android: {min: "6.0"}}

- name: FLAG_MUTABLE
summary: Pending intent should be mutable.
description: |
Use with the <Titanium.Android.PendingIntent.flags> property.
See [PendingIntent.FLAG_MUTABLE in the Android API Reference](https://developer.android.com/reference/android/app/PendingIntent.html#FLAG_MUTABLE).
type: Number
permission: read-only
since: "10.1.0"
osver: {android: {min: "12.0"}}

- name: FLAG_NO_CREATE
summary: If the current intent does not exist, do not create it.
description: |
Expand Down
12 changes: 12 additions & 0 deletions tests/Resources/ti.android.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1075,12 +1075,24 @@ describe.android('Titanium.Android', () => {
});
});

describe('.FLAG_IMMUTABLE', () => {
it('is a Number', () => {
should(Ti.Android).have.a.constant('FLAG_IMMUTABLE').which.is.a.Number();
});
});

describe('.FLAG_INSISTENT', () => {
it('is a Number', () => {
should(Ti.Android).have.a.constant('FLAG_INSISTENT').which.is.a.Number();
});
});

describe('.FLAG_MUTABLE', () => {
it('is a Number', () => {
should(Ti.Android).have.a.constant('FLAG_MUTABLE').which.is.a.Number();
});
});

describe('.FLAG_NO_CLEAR', () => {
it('is a Number', () => {
should(Ti.Android).have.a.constant('FLAG_NO_CLEAR').which.is.a.Number();
Expand Down

0 comments on commit 75ce8e4

Please sign in to comment.