Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit 3e9e621

Browse files
committed
feat: add support for setDirectBootOk on OptionsBuilder
and mark setDryRun as deprecated v1 FCM on OptionsBuilder
1 parent fc2c9a8 commit 3e9e621

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [v1.x.x]
8+
9+
- Add support for setDirectBootOk on OptionsBuilder
10+
- Mark setDryRun as deprecated v1 FCM on OptionsBuilder
11+
712
## [v1.5.0]
813

914
- Add support for images on PayloadNotificationBuilder

src/Message/Options.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ class Options implements Arrayable
6565
*/
6666
protected $isDryRun = false;
6767

68+
/**
69+
* @internal
70+
*
71+
* @var bool
72+
*/
73+
protected $directBootOk = false;
74+
6875
/**
6976
* Options constructor.
7077
*
@@ -80,6 +87,7 @@ public function __construct(OptionsBuilder $builder)
8087
$this->timeToLive = $builder->getTimeToLive();
8188
$this->restrictedPackageName = $builder->getRestrictedPackageName();
8289
$this->isDryRun = $builder->isDryRun();
90+
$this->directBootOk = $builder->isDirectBootOk();
8391
}
8492

8593
/**
@@ -93,6 +101,7 @@ public function toArray()
93101
$mutableContent = $this->isMutableContent ? true : null;
94102
$delayWhileIdle = $this->delayWhileIdle ? true : null;
95103
$dryRun = $this->isDryRun ? true : null;
104+
$directBootOk = $this->directBootOk ? true : null;
96105

97106
$options = [
98107
'collapse_key' => $this->collapseKey,
@@ -103,6 +112,7 @@ public function toArray()
103112
'time_to_live' => $this->timeToLive,
104113
'restricted_package_name' => $this->restrictedPackageName,
105114
'dry_run' => $dryRun,
115+
'direct_boot_ok' => $directBootOk,
106116
];
107117

108118
return array_filter($options);

src/Message/OptionsBuilder.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ class OptionsBuilder
6969
*/
7070
protected $dryRun = false;
7171

72+
/**
73+
* @internal
74+
*
75+
* @var bool
76+
*/
77+
protected $directBootOk;
78+
7279
/**
7380
* This parameter identifies a group of messages
7481
* A maximum of 4 different collapse keys is allowed at any given time.
@@ -84,6 +91,23 @@ public function setCollapseKey($collapseKey)
8491
return $this;
8592
}
8693

94+
/**
95+
* If set to true, messages will be allowed to be delivered to the app while the device is in direct boot mode.
96+
* See Support Direct Boot mode (https://developer.android.com/training/articles/direct-boot).
97+
*
98+
* @see https://developer.android.com/training/articles/direct-boot
99+
*
100+
* @param true $directBootOk (only true is valid, do not use for false it is pointless)
101+
*
102+
* @return \LaravelFCM\Message\OptionsBuilder
103+
*/
104+
public function setDirectBootOk($directBootOk)
105+
{
106+
$this->directBootOk = $directBootOk;
107+
108+
return $this;
109+
}
110+
87111
/**
88112
* Sets the priority of the message. Valid values are "normal" and "high."
89113
* By default, messages are sent with normal priority.
@@ -175,6 +199,7 @@ public function setTimeToLive($timeToLive)
175199

176200
/**
177201
* This parameter specifies the package name of the application where the registration tokens must match in order to receive the message.
202+
* (Android only)
178203
*
179204
* @param string $restrictedPackageName
180205
*
@@ -191,6 +216,7 @@ public function setRestrictedPackageName($restrictedPackageName)
191216
* This parameter, when set to true, allows developers to test a request without actually sending a message.
192217
* It should only be used for the development.
193218
*
219+
* @deprecated v1 (https://stackoverflow.com/a/53885050/5155484)
194220
* @param bool $isDryRun
195221
*
196222
* @return \LaravelFCM\Message\OptionsBuilder
@@ -282,6 +308,16 @@ public function isDryRun()
282308
return $this->dryRun;
283309
}
284310

311+
/**
312+
* is direct boot ok
313+
*
314+
* @return bool
315+
*/
316+
public function isDirectBootOk()
317+
{
318+
return $this->directBootOk;
319+
}
320+
285321
/**
286322
* build an instance of Options.
287323
*

tests/MessageTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,43 @@ public function it_construct_a_valid_json_with_option()
4646
$this->assertJsonStringEqualsJsonString($targetFull, $json);
4747
}
4848

49+
public function testBuildOptionsDirectBootOk()
50+
{
51+
$targetPartial = '{
52+
"direct_boot_ok": true,
53+
"content_available":true
54+
}';
55+
56+
$targetFull = '{
57+
"collapse_key":"collapseKey",
58+
"content_available":true,
59+
"priority":"high",
60+
"delay_while_idle":true,
61+
"time_to_live":200,
62+
"restricted_package_name":"customPackageName",
63+
"dry_run": true,
64+
"direct_boot_ok": true
65+
}';
66+
67+
$optionBuilder = new OptionsBuilder();
68+
69+
$optionBuilder->setDirectBootOk(true);
70+
$optionBuilder->setContentAvailable(true);
71+
72+
$json = json_encode($optionBuilder->build()->toArray());
73+
$this->assertJsonStringEqualsJsonString($targetPartial, $json);
74+
75+
$optionBuilder->setPriority(OptionsPriorities::high)
76+
->setCollapseKey('collapseKey')
77+
->setDelayWhileIdle(true)
78+
->setDryRun(true)
79+
->setRestrictedPackageName('customPackageName')
80+
->setTimeToLive(200);
81+
82+
$json = json_encode($optionBuilder->build()->toArray());
83+
$this->assertJsonStringEqualsJsonString($targetFull, $json);
84+
}
85+
4986
/**
5087
* @test
5188
*/

0 commit comments

Comments
 (0)