Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impr(android): support PendingIntent mutable flags #12890

Merged
merged 5 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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