| 1835 | } |
| 1836 | |
| 1837 | void MetadataNode::BuildMetadata(const string& filesPath) { |
| 1838 | timeval time1; |
| 1839 | gettimeofday(&time1, nullptr); |
| 1840 | |
| 1841 | string baseDir = filesPath; |
| 1842 | baseDir.append("/metadata"); |
| 1843 | |
| 1844 | DIR* dir = opendir(baseDir.c_str()); |
| 1845 | |
| 1846 | if(dir == nullptr){ |
| 1847 | stringstream ss; |
| 1848 | ss << "metadata folder couldn't be opened! (Error: "; |
| 1849 | ss << errno; |
| 1850 | ss << ") "; |
| 1851 | |
| 1852 | // TODO: Is there a way to detect if the screen is locked as verification |
| 1853 | // We assume based on the error that this is the only way to get this specific error here at this point |
| 1854 | if (errno == ENOENT || errno == EACCES) { |
| 1855 | // Log the error with error code |
| 1856 | __android_log_print(ANDROID_LOG_ERROR, "TNS.error", "%s", ss.str().c_str()); |
| 1857 | |
| 1858 | // While the screen is locked after boot; we cannot access our own apps directory on Android 9+ |
| 1859 | // So the only thing to do at this point is just exit normally w/o crashing! |
| 1860 | |
| 1861 | // The only reason we should be in this specific path; is if: |
| 1862 | // 1) android:directBootAware="true" flag is set on receiver |
| 1863 | // 2) android.intent.action.LOCKED_BOOT_COMPLETED intent is set in manifest on above receiver |
| 1864 | // See: https://developer.android.com/guide/topics/manifest/receiver-element |
| 1865 | // and: https://developer.android.com/training/articles/direct-boot |
| 1866 | // This specific path occurs if you using the NativeScript-Local-Notification plugin, the |
| 1867 | // receiver code runs fine, but the app actually doesn't need to startup. The Native code tries to |
| 1868 | // startup because the receiver is triggered. So even though we are exiting, the receiver will have |
| 1869 | // done its job |
| 1870 | |
| 1871 | _Exit(0); |
| 1872 | } |
| 1873 | else { |
| 1874 | throw NativeScriptException(ss.str()); |
| 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | string nodesFile = baseDir + "/treeNodeStream.dat"; |
| 1879 | string namesFile = baseDir + "/treeStringsStream.dat"; |
| 1880 | string valuesFile = baseDir + "/treeValueStream.dat"; |
| 1881 | |
| 1882 | FILE* f = fopen(nodesFile.c_str(), "rb"); |
| 1883 | if (f == nullptr) { |
| 1884 | stringstream ss; |
| 1885 | ss << "metadata file (treeNodeStream.dat) couldn't be opened! (Error: "; |
| 1886 | ss << errno; |
| 1887 | ss << ") "; |
| 1888 | |
| 1889 | throw NativeScriptException(ss.str()); |
| 1890 | } |
| 1891 | fseek(f, 0, SEEK_END); |
| 1892 | int lenNodes = ftell(f); |
| 1893 | assert((lenNodes % sizeof(MetadataTreeNodeRawData)) == 0); |
| 1894 | char* nodes = new char[lenNodes]; |
nothing calls this directly
no test coverage detected