|
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 == 2) { |
| 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";
|
|
0 commit comments