cordova-plugin-buildinfo-patch 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Mikihiro Hayashi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "cordova-plugin-buildinfo-patch",
3
+ "version": "4.0.1",
4
+ "description": "Cordova/PhoneGap Build Information Plugin.",
5
+ "cordova": {
6
+ "id": "cordova-plugin-buildinfo",
7
+ "platforms": ["android"]
8
+ },
9
+ "keywords": [
10
+ "debug",
11
+ "buildconfig",
12
+ "buildinfo",
13
+ "phonegap",
14
+ "cordova",
15
+ "ecosystem:cordova",
16
+ "cordova-android"
17
+ ],
18
+ "scripts": {
19
+ "test": "npm run jshint",
20
+ "jshint": "jshint www && jshint src"
21
+ },
22
+ "engines": {
23
+ "...": "..."
24
+ },
25
+ "devDependencies": {
26
+ "jshint": "^2.13.6"
27
+ }
28
+ }
package/plugin.xml ADDED
@@ -0,0 +1,69 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <plugin
3
+ xmlns="http://apache.org/cordova/ns/plugins/1.0"
4
+ xmlns:android="http://schemas.android.com/apk/res/android"
5
+ id="cordova-plugin-buildinfo"
6
+ version="4.0.0">
7
+ <name>BuildInfo</name>
8
+ <description>Cordova/Phonegap Build Information Plugin. Get PackageName, Version, Debug and more...</description>
9
+ <license>MIT</license>
10
+ <keywords>debug,buildconfig,buildinfo,phonegap,cordova</keywords>
11
+ <author>Mikihiro Hayashi</author>
12
+ <hook type="after_plugin_install" src="scripts/after_install.js" />
13
+ <hook type="before_plugin_uninstall" src="scripts/before_uninstall.js" />
14
+
15
+ <js-module src="www/buildinfo.js" name="BuildInfo">
16
+ <clobbers target="BuildInfo"/>
17
+ </js-module>
18
+
19
+ <platform name="android">
20
+ <config-file target="res/xml/config.xml" parent="/*">
21
+ <feature name="BuildInfo">
22
+ <param name="android-package" value="org.apache.cordova.buildinfo.BuildInfo"/>
23
+ </feature>
24
+ </config-file>
25
+ <source-file src="src/android/BuildInfo.java" target-dir="src/org/apache/cordova/buildinfo"/>
26
+ <framework src="src/android/BuildInfo.gradle" custom="true" type="gradleReference"/>
27
+ </platform>
28
+
29
+ <platform name="ios">
30
+ <config-file target="config.xml" parent="/*">
31
+ <feature name="BuildInfo">
32
+ <param name="ios-package" value="CDVBuildInfo"/>
33
+ </feature>
34
+ </config-file>
35
+ <header-file src="src/ios/CDVBuildInfo.h"/>
36
+ <source-file src="src/ios/CDVBuildInfo.m"/>
37
+ </platform>
38
+
39
+ <platform name="windows">
40
+ <js-module src="src/windows/BuildInfoProxy.js" name="BuildInfoProxy">
41
+ <merges target=""/>
42
+ </js-module>
43
+ <resource-file src="src/windows/buildinfo.resjson" target="strings/buildinfo.resjson" />
44
+ </platform>
45
+
46
+ <platform name="osx">
47
+ <config-file target="config.xml" parent="/*">
48
+ <feature name="BuildInfo">
49
+ <param name="osx-package" value="CDVBuildInfo"/>
50
+ </feature>
51
+ </config-file>
52
+ <header-file src="src/osx/CDVBuildInfo.h"/>
53
+ <source-file src="src/osx/CDVBuildInfo.m"/>
54
+ </platform>
55
+
56
+ <platform name="browser">
57
+ <js-module src="src/browser/BuildInfoProxy.js" name="BuildInfoProxy">
58
+ <merges target=""/>
59
+ </js-module>
60
+ <hook type="after_prepare" src="scripts/browser_after_prepare.js" />
61
+ </platform>
62
+
63
+ <platform name="electron">
64
+ <js-module src="src/browser/BuildInfoProxy.js" name="BuildInfoProxy">
65
+ <merges target=""/>
66
+ </js-module>
67
+ <hook type="after_prepare" src="scripts/browser_after_prepare.js" />
68
+ </platform>
69
+ </plugin>
@@ -0,0 +1,85 @@
1
+ /*
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2019 Mikihiro Hayashi
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */
24
+
25
+ 'use strict';
26
+
27
+ const path = require('path'),
28
+ fs = require('fs');
29
+
30
+ function installWindows(windowsPath) {
31
+
32
+ const targetPath = path.join(windowsPath, 'CordovaApp.projitems');
33
+ let projitems = fs.readFileSync(targetPath).toString();
34
+ let changed = false;
35
+
36
+ // Replace <Content Include="strings\buildinfo.resjson"> to <PRIResource Include="strings\buildinfo.resjson">
37
+ if (projitems.match(/<ItemGroup>[\s]*?<Content +.*?Include="strings\/buildinfo.resjson".+/m)) {
38
+ const search = /<ItemGroup>[\s]*?<Content +.*?Include="strings\/buildinfo.resjson"[^]*?<\/ItemGroup>/m;
39
+
40
+ const replace
41
+ = "<ItemGroup>\r\n"
42
+ + " <PRIResource Include=\"strings\/buildinfo.resjson\" />\r\n"
43
+ + " </ItemGroup>";
44
+
45
+ projitems = projitems.replace(search, replace);
46
+ changed = true;
47
+ }
48
+
49
+ // Add <Target Name="BuildInfo_Timestamp" BeforeTargets=BeforeBuild">
50
+ if (!projitems.match(/<Target +.*?Name="BuildInfo_Timestamp".*?/)) {
51
+ const search = /<\/Project>/;
52
+
53
+ const replace
54
+ = " <Target Name=\"BuildInfo_Timestamp\" BeforeTargets=\"BeforeBuild\">\r\n"
55
+ + " <PropertyGroup>\r\n"
56
+ + " <BuildInfoTimestamp>$([System.DateTime]::Now.ToString(\"yyyy-MM-dd\THH:mm:sszzz\"))</BuildInfoTimestamp>\r\n"
57
+ + " </PropertyGroup>\r\n"
58
+ + " <ItemGroup>\r\n"
59
+ + " <BuildInfoResJson Include=\"{\" />\r\n"
60
+ + " <BuildInfoResJson Include=\"&quot;Timestamp&quot;: &quot;$(BuildInfoTimestamp)&quot;\" />\r\n"
61
+ + " <BuildInfoResJson Include=\"}\" />\r\n"
62
+ + " </ItemGroup>\r\n"
63
+ + " <WriteLinesToFile File=\"strings\\buildinfo.resjson\" Lines=\"@(BuildInfoResJson)\" Overwrite=\"true\" Encoding=\"UTF-8\" />\r\n"
64
+ + " </Target>\r\n"
65
+ + "</Project>";
66
+
67
+ projitems = projitems.replace(search, replace);
68
+ changed = true;
69
+ }
70
+
71
+ // if variable "changed" is true, write to file.
72
+ if (changed) {
73
+ fs.writeFileSync(targetPath, projitems);
74
+ }
75
+ }
76
+
77
+ module.exports = function (context) {
78
+ const projectRoot = context.opts.projectRoot;
79
+
80
+ // Exists platform/windows
81
+ const windowsPath = path.join(projectRoot, 'platforms', 'windows');
82
+ if (fs.existsSync(windowsPath) && context.opts.plugin.platform == 'windows') {
83
+ installWindows(windowsPath);
84
+ }
85
+ };
@@ -0,0 +1,77 @@
1
+ /*
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2019 Mikihiro Hayashi
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */
24
+
25
+ 'use strict';
26
+
27
+ const path = require('path'),
28
+ fs = require('fs');
29
+
30
+ function uninstallWindows(context, windowsPath) {
31
+ const targetPath = path.join(windowsPath, 'CordovaApp.projitems');
32
+ let projitems = fs.readFileSync(targetPath).toString();
33
+ let changed = false;
34
+
35
+ // Replace <PRIResource Include="strings\buildinfo.resjson"> to <Content Include="strings\buildinfo.resjson">
36
+ if (projitems.match(/<ItemGroup>[\s]*?<PRIResource +.*?Include="strings\/buildinfo.resjson".+/m)) {
37
+
38
+ const search = /<ItemGroup>[\s]*?<PRIResource +.*?Include="strings\/buildinfo.resjson"[^]*?<\/ItemGroup>/m;
39
+
40
+ const replace
41
+ = "<ItemGroup>\r\n"
42
+ + " <Content Include=\"strings\/buildinfo.resjson\" />\r\n"
43
+ + " </ItemGroup>";
44
+
45
+ projitems = projitems.replace(search, replace);
46
+ changed = true;
47
+ }
48
+
49
+ // Remove <Target Name="BuildInfo_Timestamp" BeforeTargets=BeforeBuild">
50
+ if (projitems.match(/<Target +.*?Name="BuildInfo_Timestamp".*/)) {
51
+
52
+ const search = /[\r\n ]*<Target +.*?Name="BuildInfo_Timestamp"[^]*?<\/Target>/gm;
53
+
54
+ projitems = projitems.replace(search, '');
55
+ changed = true;
56
+ }
57
+
58
+ // if variable "changed" is true, write to file.
59
+ if (changed) {
60
+ fs.writeFileSync(targetPath, projitems);
61
+ }
62
+ }
63
+
64
+ module.exports = function (context) {
65
+ const opts = context.opts || {};
66
+ const projectRoot = opts.projectRoot;
67
+
68
+ if ('string' != typeof projectRoot) {
69
+ return;
70
+ }
71
+
72
+ // Exists platform/windows
73
+ const windowsPath = path.join(projectRoot, 'platforms', 'windows');
74
+ if (context.opts.plugin.platform == 'windows' && fs.existsSync(windowsPath)) {
75
+ uninstallWindows(context, windowsPath);
76
+ }
77
+ };
@@ -0,0 +1,89 @@
1
+ /*
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2019 Mikihiro Hayashi
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */
24
+
25
+ 'use strict';
26
+
27
+ const path = require('path'),
28
+ fs = require('fs');
29
+
30
+ function rewriteBuildInfoProxy(context, pathPrefix) {
31
+
32
+ const opts = context.opts || {};
33
+ const options = opts.options || {};
34
+ const release = options.release || false;
35
+ const debug = options.debug || !release;
36
+
37
+ const pluginId = (opts.plugin || {}).id || 'cordova-plugin-buildinfo';
38
+
39
+ const pathRewriteFile = path.join(pathPrefix, 'www', 'plugins', pluginId, 'src', 'browser', 'BuildInfoProxy.js');
40
+
41
+ if (!fs.existsSync(pathRewriteFile)) {
42
+ console.error('File not found: '.pathRewriteFile);
43
+ return;
44
+ }
45
+
46
+ const ConfigParser = context.requireCordovaModule('cordova-common').ConfigParser;
47
+ const cfg = new ConfigParser('config.xml');
48
+
49
+ const json = {
50
+ debug: debug,
51
+ packageName: cfg.packageName(),
52
+ basePackageName: cfg.packageName(),
53
+ name: cfg.name(),
54
+ displayName: cfg.shortName(),
55
+ version: cfg.version(),
56
+ versionCode: cfg.version()
57
+ };
58
+
59
+ const code = 'const json = ' + JSON.stringify(json) + ';';
60
+
61
+ const contentJs = fs.readFileSync(pathRewriteFile, 'utf8');
62
+ const outputJs = contentJs.replace(/(\/\* <EMBED_CODE> \*\/).*?(\s*)(\/\* <\/EMBED_CODE> \*\/)/s, '$1$2' + code + '$2$3');
63
+
64
+ fs.writeFileSync(pathRewriteFile, outputJs);
65
+ }
66
+
67
+
68
+ module.exports = function (context) {
69
+
70
+ const opts = context.opts || {};
71
+ const projectRoot = opts.projectRoot;
72
+ const platforms = opts.platforms || [];
73
+
74
+ if ('string' != typeof projectRoot) {
75
+ return;
76
+ }
77
+
78
+ ['browser', 'electron'].forEach((value, index, array) => {
79
+
80
+ if (!platforms.includes(value)) {
81
+ return;
82
+ }
83
+
84
+ const pathPrefix = path.join(projectRoot, 'platforms', value);
85
+ if (fs.existsSync(pathPrefix)) {
86
+ rewriteBuildInfoProxy(context, pathPrefix);
87
+ }
88
+ });
89
+ };
@@ -0,0 +1,5 @@
1
+ android {
2
+ defaultConfig {
3
+ //buildConfigField "long", "_BUILDINFO_TIMESTAMP", System.currentTimeMillis() + "L"
4
+ }
5
+ }
@@ -0,0 +1,289 @@
1
+ /*
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2016 Mikihiro Hayashi
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */
24
+
25
+ package org.apache.cordova.buildinfo;
26
+
27
+ import android.app.Activity;
28
+ import android.content.pm.PackageInfo;
29
+ import android.content.pm.PackageManager;
30
+ import android.util.Log;
31
+
32
+ import org.apache.cordova.CallbackContext;
33
+ import org.apache.cordova.CordovaPlugin;
34
+ import org.json.JSONArray;
35
+ import org.json.JSONException;
36
+ import org.json.JSONObject;
37
+
38
+ import java.lang.reflect.Field;
39
+ import java.text.SimpleDateFormat;
40
+
41
+ /**
42
+ * BuildInfo Cordova Plugin
43
+ *
44
+ * @author Mikihiro Hayashi
45
+ * @since 1.0.0
46
+ */
47
+ public class BuildInfo extends CordovaPlugin {
48
+ private static final String TAG = "BuildInfo";
49
+
50
+ /**
51
+ * Cache of result JSON
52
+ */
53
+ private static JSONObject mBuildInfoCache;
54
+
55
+ /**
56
+ * Constructor
57
+ */
58
+ public BuildInfo() {
59
+ }
60
+
61
+ /**
62
+ * execute
63
+ * @param action The action to execute.
64
+ * @param args The exec() arguments.
65
+ * @param callbackContext The callback context used when calling back into JavaScript.
66
+ * @return
67
+ * @throws JSONException
68
+ */
69
+ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
70
+
71
+ if ("init".equals(action)) {
72
+ String buildConfigClassName = null;
73
+ if (1 < args.length()) {
74
+ buildConfigClassName = args.getString(0);
75
+ }
76
+
77
+ init(buildConfigClassName, callbackContext);
78
+ return true;
79
+ }
80
+
81
+ return false;
82
+ }
83
+
84
+ /**
85
+ * init
86
+ * @param buildConfigClassName null or specified BuildConfig class name
87
+ * @param callbackContext
88
+ */
89
+ private void init(String buildConfigClassName, CallbackContext callbackContext) {
90
+ // Cached check
91
+ if (null != mBuildInfoCache) {
92
+ callbackContext.success(mBuildInfoCache);
93
+ return;
94
+ }
95
+
96
+ // Load PackageInfo
97
+ Activity activity = cordova.getActivity();
98
+ String packageName = activity.getPackageName();
99
+ String basePackageName = packageName;
100
+ CharSequence displayName = "";
101
+ long firstInstallTime = 0;
102
+
103
+ PackageManager pm = activity.getPackageManager();
104
+
105
+ try {
106
+ PackageInfo pi = pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
107
+ firstInstallTime = pi.firstInstallTime;
108
+
109
+ if (null != pi.applicationInfo) {
110
+ displayName = pi.applicationInfo.loadLabel(pm);
111
+ }
112
+ } catch (PackageManager.NameNotFoundException e) {
113
+ e.printStackTrace();
114
+ }
115
+
116
+ // Load BuildConfig class
117
+ Class c = null;
118
+
119
+ if (null == buildConfigClassName) {
120
+ buildConfigClassName = packageName + ".BuildConfig";
121
+ }
122
+
123
+ try {
124
+ c = Class.forName(buildConfigClassName);
125
+ } catch (ClassNotFoundException e) {
126
+ }
127
+
128
+ if (null == c) {
129
+ basePackageName = activity.getClass().getPackage().getName();
130
+ buildConfigClassName = basePackageName + ".BuildConfig";
131
+
132
+ try {
133
+ c = Class.forName(buildConfigClassName);
134
+ } catch (ClassNotFoundException e) {
135
+ callbackContext.error("BuildConfig ClassNotFoundException: " + e.getMessage());
136
+ return;
137
+ }
138
+ }
139
+
140
+ // Create result
141
+ mBuildInfoCache = new JSONObject();
142
+ try {
143
+ boolean debug = getClassFieldBoolean(c, "DEBUG", false);
144
+
145
+ mBuildInfoCache.put("packageName" , packageName);
146
+ mBuildInfoCache.put("basePackageName", basePackageName);
147
+ mBuildInfoCache.put("displayName" , displayName);
148
+ mBuildInfoCache.put("name" , displayName); // same as displayName
149
+ mBuildInfoCache.put("version" , getClassFieldString(c, "VERSION_NAME", ""));
150
+ mBuildInfoCache.put("versionCode" , getClassFieldInt(c, "VERSION_CODE", 0));
151
+ mBuildInfoCache.put("debug" , debug);
152
+ //mBuildInfoCache.put("buildDate" , convertLongToDateTimeString(getClassFieldLong(c, "_BUILDINFO_TIMESTAMP", 0L)));
153
+ mBuildInfoCache.put("installDate" , convertLongToDateTimeString(firstInstallTime));
154
+ mBuildInfoCache.put("buildType" , getClassFieldString(c, "BUILD_TYPE", ""));
155
+ mBuildInfoCache.put("flavor" , getClassFieldString(c, "FLAVOR", ""));
156
+
157
+ if (debug) {
158
+ Log.d(TAG, "packageName : \"" + mBuildInfoCache.getString("packageName") + "\"");
159
+ Log.d(TAG, "basePackageName: \"" + mBuildInfoCache.getString("basePackageName") + "\"");
160
+ Log.d(TAG, "displayName : \"" + mBuildInfoCache.getString("displayName") + "\"");
161
+ Log.d(TAG, "name : \"" + mBuildInfoCache.getString("name") + "\"");
162
+ Log.d(TAG, "version : \"" + mBuildInfoCache.getString("version") + "\"");
163
+ Log.d(TAG, "versionCode : " + mBuildInfoCache.getInt("versionCode"));
164
+ Log.d(TAG, "debug : " + (mBuildInfoCache.getBoolean("debug") ? "true" : "false"));
165
+ Log.d(TAG, "buildType : \"" + mBuildInfoCache.getString("buildType") + "\"");
166
+ Log.d(TAG, "flavor : \"" + mBuildInfoCache.getString("flavor") + "\"");
167
+ //Log.d(TAG, "buildDate : \"" + mBuildInfoCache.getString("buildDate") + "\"");
168
+ Log.d(TAG, "installDate : \"" + mBuildInfoCache.getString("installDate") + "\"");
169
+ }
170
+ } catch (JSONException e) {
171
+ e.printStackTrace();
172
+ callbackContext.error("JSONException: " + e.getMessage());
173
+ return;
174
+ }
175
+
176
+ callbackContext.success(mBuildInfoCache);
177
+ }
178
+
179
+ /**
180
+ * Get boolean of field from Class
181
+ * @param c
182
+ * @param fieldName
183
+ * @param defaultReturn
184
+ * @return
185
+ */
186
+ private static boolean getClassFieldBoolean(Class c, String fieldName, boolean defaultReturn) {
187
+ boolean ret = defaultReturn;
188
+ Field field = getClassField(c, fieldName);
189
+
190
+ if (null != field) {
191
+ try {
192
+ ret = field.getBoolean(c);
193
+ } catch (IllegalAccessException iae) {
194
+ iae.printStackTrace();
195
+ }
196
+ }
197
+
198
+ return ret;
199
+ }
200
+
201
+ /**
202
+ * Get string of field from Class
203
+ * @param c
204
+ * @param fieldName
205
+ * @param defaultReturn
206
+ * @return
207
+ */
208
+ private static String getClassFieldString(Class c, String fieldName, String defaultReturn) {
209
+ String ret = defaultReturn;
210
+ Field field = getClassField(c, fieldName);
211
+
212
+ if (null != field) {
213
+ try {
214
+ ret = (String)field.get(c);
215
+ } catch (IllegalAccessException iae) {
216
+ iae.printStackTrace();
217
+ }
218
+ }
219
+
220
+ return ret;
221
+ }
222
+
223
+ /**
224
+ * Get int of field from Class
225
+ * @param c
226
+ * @param fieldName
227
+ * @param defaultReturn
228
+ * @return
229
+ */
230
+ private static int getClassFieldInt(Class c, String fieldName, int defaultReturn) {
231
+ int ret = defaultReturn;
232
+ Field field = getClassField(c, fieldName);
233
+
234
+ if (null != field) {
235
+ try {
236
+ ret = field.getInt(c);
237
+ } catch (IllegalAccessException iae) {
238
+ iae.printStackTrace();
239
+ }
240
+ }
241
+
242
+ return ret;
243
+ }
244
+
245
+ /**
246
+ * Get long of field from Class
247
+ * @param c
248
+ * @param fieldName
249
+ * @param defaultReturn
250
+ * @return
251
+ */
252
+ private static long getClassFieldLong(Class c, String fieldName, long defaultReturn) {
253
+ long ret = defaultReturn;
254
+ Field field = getClassField(c, fieldName);
255
+
256
+ if (null != field) {
257
+ try {
258
+ ret = field.getLong(c);
259
+ } catch (IllegalAccessException iae) {
260
+ iae.printStackTrace();
261
+ }
262
+ }
263
+
264
+ return ret;
265
+ }
266
+
267
+ /**
268
+ * Get field from Class
269
+ * @param c
270
+ * @param fieldName
271
+ * @return
272
+ */
273
+ private static Field getClassField(Class c, String fieldName) {
274
+ Field field = null;
275
+
276
+ try {
277
+ field = c.getField(fieldName);
278
+ } catch (NoSuchFieldException nsfe) {
279
+ nsfe.printStackTrace();
280
+ }
281
+
282
+ return field;
283
+ }
284
+
285
+ private static String convertLongToDateTimeString(long mills) {
286
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
287
+ return formatter.format(mills);
288
+ }
289
+ }
@@ -0,0 +1,162 @@
1
+ /*
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2016 Mikihiro Hayashi
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */
24
+
25
+ var exec = require('cordova/exec');
26
+ var channel = require('cordova/channel');
27
+
28
+ module.exports = {
29
+ baseUrl: null,
30
+ packageName: '',
31
+ basePackageName: '',
32
+ displayName: '',
33
+ name: '',
34
+ version: '',
35
+ versionCode: 0,
36
+ debug: false,
37
+ //buildDate: null,
38
+ installDate: null,
39
+ buildType: '',
40
+ flavor: ''
41
+ };
42
+
43
+ function _buldinfoCheckCordovaPlatform() {
44
+ var allowPlatforms = ['android', 'ios', 'windows', 'osx', 'browser', 'electron'];
45
+ var platformId = (cordova && cordova.platformId) ? cordova.platformId : null;
46
+ return (-1 !== allowPlatforms.indexOf(platformId));
47
+ }
48
+
49
+ function _findBaseUrl() {
50
+ var path = null;
51
+ var scripts = document.getElementsByTagName('script');
52
+ var findScriptPath = '/cordova.js';
53
+ var findScriptPathLen = findScriptPath.length;
54
+
55
+ for (var i = scripts.length - 1; i >= 0; i--) {
56
+ var src = scripts[i].src.replace(/\?.*$/, '');
57
+
58
+ if (src.length >= findScriptPathLen && src.substring(src.length - findScriptPathLen) == findScriptPath) {
59
+ path = src.substring(0, src.length - findScriptPathLen) + '/';
60
+ break;
61
+ }
62
+ }
63
+
64
+ return path;
65
+ }
66
+
67
+
68
+ if (_buldinfoCheckCordovaPlatform()) {
69
+
70
+ channel.onCordovaReady.subscribe(function () {
71
+ // Platform Check
72
+ var allowPlatforms = ['android', 'ios', 'windows', 'osx', 'browser', 'electron'];
73
+ var platformId = (cordova && cordova.platformId) ? cordova.platformId : null;
74
+ if (-1 == allowPlatforms.indexOf(platformId)) {
75
+ console.debug('BuildInfo init skip.');
76
+ return;
77
+ }
78
+
79
+ var args = [];
80
+
81
+ // Android Only
82
+ // defined buildInfoBuildConfigClassName variable
83
+ // BuildConfig class name.
84
+ // ex: <script>var buildInfoBuildConfigClassName = 'org.apache.cordova.sample.BuildConfig';</script>
85
+ if ('undefined' !== typeof buildInfoBuildConfigClassName) {
86
+ args.push(buildInfoBuildConfigClassName);
87
+ }
88
+
89
+ exec(
90
+ function (res) {
91
+ if (!res) {
92
+ return;
93
+ }
94
+
95
+ module.exports.baseUrl = _findBaseUrl();
96
+
97
+ if ('undefined' !== typeof res.packageName) {
98
+ module.exports.packageName = res.packageName;
99
+ }
100
+
101
+ if ('undefined' !== typeof res.basePackageName) {
102
+ module.exports.basePackageName = res.basePackageName;
103
+ }
104
+
105
+ if ('undefined' !== typeof res.displayName) {
106
+ module.exports.displayName = res.displayName;
107
+ }
108
+
109
+ if ('undefined' !== typeof res.name) {
110
+ module.exports.name = res.name;
111
+ }
112
+
113
+ if ('undefined' !== typeof res.version) {
114
+ module.exports.version = res.version;
115
+ }
116
+
117
+ if ('undefined' !== typeof res.versionCode) {
118
+ module.exports.versionCode = res.versionCode;
119
+ }
120
+
121
+ if ('undefined' !== typeof res.debug) {
122
+ module.exports.debug = res.debug;
123
+ }
124
+
125
+ if ('undefined' !== typeof res.buildType) {
126
+ module.exports.buildType = res.buildType;
127
+ }
128
+
129
+ if ('undefined' !== typeof res.flavor) {
130
+ module.exports.flavor = res.flavor;
131
+ }
132
+
133
+ /*if ('undefined' !== typeof res.buildDate) {
134
+ if (res.buildDate instanceof Date) {
135
+ module.exports.buildDate = res.buildDate;
136
+ } else {
137
+ module.exports.buildDate = new Date(res.buildDate);
138
+ }
139
+ }*/
140
+
141
+ if ('undefined' !== typeof res.installDate) {
142
+ if (res.installDate instanceof Date) {
143
+ module.exports.installDate = res.installDate;
144
+ } else {
145
+ module.exports.installDate = new Date(res.installDate);
146
+ }
147
+ }
148
+
149
+ if ('undefined' !== typeof res.windows) {
150
+ module.exports.windows = res.windows;
151
+ }
152
+ },
153
+ function (msg) {
154
+ console.error('BuildInfo init fail');
155
+ console.error(msg);
156
+ },
157
+ 'BuildInfo',
158
+ 'init',
159
+ args
160
+ );
161
+ });
162
+ }