12
12
#include < sstream>
13
13
#include < cctype>
14
14
#include < dirent.h>
15
+ #include < errno.h>
16
+ #include < android/log.h>
17
+ #include < unistd.h>
15
18
#include " ManualInstrumentation.h"
16
19
#include " JSONObjectHelper.h"
17
20
21
+
22
+
18
23
#include " v8.h"
19
24
20
25
using namespace v8 ;
@@ -1785,8 +1790,37 @@ void MetadataNode::BuildMetadata(const string& filesPath) {
1785
1790
baseDir.append (" /metadata" );
1786
1791
1787
1792
DIR* dir = opendir (baseDir.c_str ());
1793
+
1788
1794
if (dir == nullptr ){
1789
- throw NativeScriptException (string (" metadata folder couldn't be opened!" ));
1795
+ stringstream ss;
1796
+ ss << " metadata folder couldn't be opened! (Error: " ;
1797
+ ss << errno;
1798
+ ss << " ) " ;
1799
+
1800
+ // TODO: Is there a way to detect if the screen is locked as verification
1801
+ // We assume based on the error that this is the only way to get this specific error here at this point
1802
+ if (errno == ENOENT) {
1803
+ // Log the error with error code
1804
+ __android_log_print (ANDROID_LOG_ERROR, " TNS.error" , " %s" , ss.str ().c_str ());
1805
+
1806
+ // While the screen is locked after boot; we cannot access our own apps directory on Android 9+
1807
+ // So the only thing to do at this point is just exit normally w/o crashing!
1808
+
1809
+ // The only reason we should be in this specific path; is if:
1810
+ // 1) android:directBootAware="true" flag is set on receiver
1811
+ // 2) android.intent.action.LOCKED_BOOT_COMPLETED intent is set in manifest on above receiver
1812
+ // See: https://developer.android.com/guide/topics/manifest/receiver-element
1813
+ // and: https://developer.android.com/training/articles/direct-boot
1814
+ // This specific path occurs if you using the NativeScript-Local-Notification plugin, the
1815
+ // receiver code runs fine, but the app actually doesn't need to startup. The Native code tries to
1816
+ // startup because the receiver is triggered. So even though we are exiting, the receiver will have
1817
+ // done its job
1818
+
1819
+ exit (0 );
1820
+ }
1821
+ else {
1822
+ throw NativeScriptException (ss.str ());
1823
+ }
1790
1824
}
1791
1825
1792
1826
string nodesFile = baseDir + " /treeNodeStream.dat" ;
@@ -1795,7 +1829,12 @@ void MetadataNode::BuildMetadata(const string& filesPath) {
1795
1829
1796
1830
FILE* f = fopen (nodesFile.c_str (), " rb" );
1797
1831
if (f == nullptr ) {
1798
- throw NativeScriptException (string (" metadata file (treeNodeStream.dat) couldn't be opened!" ));
1832
+ stringstream ss;
1833
+ ss << " metadata file (treeNodeStream.dat) couldn't be opened! (Error: " ;
1834
+ ss << errno;
1835
+ ss << " ) " ;
1836
+
1837
+ throw NativeScriptException (ss.str ());
1799
1838
}
1800
1839
fseek (f, 0 , SEEK_END);
1801
1840
int lenNodes = ftell (f);
@@ -1809,7 +1848,11 @@ void MetadataNode::BuildMetadata(const string& filesPath) {
1809
1848
1810
1849
f = fopen (namesFile.c_str (), " rb" );
1811
1850
if (f == nullptr ) {
1812
- throw NativeScriptException (string (" metadata file (treeStringsStream.dat) couldn't be opened!" ));
1851
+ stringstream ss;
1852
+ ss << " metadata file (treeStringsStream.dat) couldn't be opened! (Error: " ;
1853
+ ss << errno;
1854
+ ss << " ) " ;
1855
+ throw NativeScriptException (ss.str ());
1813
1856
}
1814
1857
fseek (f, 0 , SEEK_END);
1815
1858
int lenNames = ftell (f);
@@ -1820,7 +1863,11 @@ void MetadataNode::BuildMetadata(const string& filesPath) {
1820
1863
1821
1864
f = fopen (valuesFile.c_str (), " rb" );
1822
1865
if (f == nullptr ) {
1823
- throw NativeScriptException (string (" metadata file (treeValueStream.dat) couldn't be opened!" ));
1866
+ stringstream ss;
1867
+ ss << " metadata file (treeValueStream.dat) couldn't be opened! (Error: " ;
1868
+ ss << errno;
1869
+ ss << " ) " ;
1870
+ throw NativeScriptException (ss.str ());
1824
1871
}
1825
1872
fseek (f, 0 , SEEK_END);
1826
1873
int lenValues = ftell (f);
0 commit comments