rhodes 5.5.0.7 → 5.5.0.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +1 -1
  3. data/CREDITS +3 -3
  4. data/Rakefile +24 -0
  5. data/extensions/instrumentation/ext/platform/android/src/com/rho/instrumentation/Instrumentation.java +5 -0
  6. data/extensions/rhoconnect-push/ext/rhoconnect-push/platform/android/Rakefile +1 -1
  7. data/lib/build/jake.rb +5 -0
  8. data/lib/commonAPI/clipboard/ext.yml +17 -0
  9. data/lib/commonAPI/clipboard/ext/Clipboard.xml +49 -0
  10. data/lib/commonAPI/clipboard/ext/build +19 -0
  11. data/lib/commonAPI/clipboard/ext/build.bat +29 -0
  12. data/lib/commonAPI/clipboard/ext/platform/android/Rakefile +141 -0
  13. data/lib/commonAPI/clipboard/ext/platform/android/ext_java.files +9 -0
  14. data/lib/commonAPI/clipboard/ext/platform/android/ext_native.files +7 -0
  15. data/lib/commonAPI/clipboard/ext/platform/android/jni/Clipboard_impl.cpp +61 -0
  16. data/lib/commonAPI/clipboard/ext/platform/android/src/com/rho/clipboard/Clipboard.java +15 -0
  17. data/lib/commonAPI/clipboard/ext/platform/android/src/com/rho/clipboard/ClipboardFactory.java +18 -0
  18. data/lib/commonAPI/clipboard/ext/platform/android/src/com/rho/clipboard/ClipboardSingleton.java +146 -0
  19. data/lib/commonAPI/clipboard/ext/platform/iphone/Clipboard.xcodeproj/project.pbxproj +368 -0
  20. data/lib/commonAPI/clipboard/ext/platform/iphone/Clipboard_Prefix.pch +7 -0
  21. data/lib/commonAPI/clipboard/ext/platform/iphone/Rakefile +73 -0
  22. data/lib/commonAPI/clipboard/ext/platform/iphone/impl/Clipboard.h +11 -0
  23. data/lib/commonAPI/clipboard/ext/platform/iphone/impl/Clipboard.m +12 -0
  24. data/lib/commonAPI/clipboard/ext/platform/iphone/impl/ClipboardFactorySingleton.m +16 -0
  25. data/lib/commonAPI/clipboard/ext/platform/iphone/impl/ClipboardSetup.m +9 -0
  26. data/lib/commonAPI/clipboard/ext/platform/iphone/impl/ClipboardSingleton.h +18 -0
  27. data/lib/commonAPI/clipboard/ext/platform/iphone/impl/ClipboardSingleton.m +43 -0
  28. data/lib/commonAPI/clipboard/ext/platform/iphone/impl/readme.txt +7 -0
  29. data/lib/commonAPI/coreapi/ext/NativeTabbar.xml +3 -3
  30. data/lib/commonAPI/coreapi/ext/shared/TimerImpl.cpp +36 -27
  31. data/lib/commonAPI/coreapi/public/api/rhoapi-force.ajax.js +3 -1
  32. data/lib/commonAPI/coreapi/public/api/rhoapi.js +2 -1
  33. data/lib/commonAPI/devicesecurity/ext.yml +11 -0
  34. data/lib/commonAPI/devicesecurity/ext/DeviceSecurity.xml +91 -0
  35. data/lib/commonAPI/devicesecurity/ext/build +19 -0
  36. data/lib/commonAPI/devicesecurity/ext/build.bat +29 -0
  37. data/lib/commonAPI/devicesecurity/ext/platform/android/InbuiltValues.erb +16 -0
  38. data/lib/commonAPI/devicesecurity/ext/platform/android/Rakefile +166 -0
  39. data/lib/commonAPI/devicesecurity/ext/platform/android/ext_java.files +10 -0
  40. data/lib/commonAPI/devicesecurity/ext/platform/android/ext_native.files +7 -0
  41. data/lib/commonAPI/devicesecurity/ext/platform/android/jni/DeviceSecurity_impl.cpp +61 -0
  42. data/lib/commonAPI/devicesecurity/ext/platform/android/src/com/rho/devicesecurity/DeviceSecurity.java +14 -0
  43. data/lib/commonAPI/devicesecurity/ext/platform/android/src/com/rho/devicesecurity/DeviceSecurityFactory.java +18 -0
  44. data/lib/commonAPI/devicesecurity/ext/platform/android/src/com/rho/devicesecurity/DeviceSecuritySingleton.java +412 -0
  45. data/lib/commonAPI/devicesecurity/ext/platform/iphone/DeviceSecurity.xcodeproj/project.pbxproj +368 -0
  46. data/lib/commonAPI/devicesecurity/ext/platform/iphone/DeviceSecurity_Prefix.pch +7 -0
  47. data/lib/commonAPI/devicesecurity/ext/platform/iphone/Rakefile +73 -0
  48. data/lib/commonAPI/devicesecurity/ext/platform/iphone/impl/DeviceSecurity.h +11 -0
  49. data/lib/commonAPI/devicesecurity/ext/platform/iphone/impl/DeviceSecurity.m +12 -0
  50. data/lib/commonAPI/devicesecurity/ext/platform/iphone/impl/DeviceSecurityFactorySingleton.m +16 -0
  51. data/lib/commonAPI/devicesecurity/ext/platform/iphone/impl/DeviceSecuritySetup.m +9 -0
  52. data/lib/commonAPI/devicesecurity/ext/platform/iphone/impl/DeviceSecuritySingleton.h +19 -0
  53. data/lib/commonAPI/devicesecurity/ext/platform/iphone/impl/DeviceSecuritySingleton.m +106 -0
  54. data/lib/commonAPI/devicesecurity/ext/platform/iphone/impl/readme.txt +7 -0
  55. data/platform/android/Rhodes/src/com/rhomobile/rhodes/LocalFileProvider.java +5 -1
  56. data/platform/android/Rhodes/src/com/rhomobile/rhodes/util/Utils.java +9 -0
  57. data/platform/android/build/android.rake +42 -1
  58. data/platform/android/build/androidcommon.rb +4 -2
  59. data/platform/iphone/Classes/RhoWKWebView.m +4 -0
  60. data/platform/iphone/Classes/URLProtocol/CRhoURLProtocol.h +2 -0
  61. data/platform/iphone/Classes/URLProtocol/CRhoURLProtocol.m +195 -30
  62. data/platform/iphone/Classes/rho/net/IPhoneNetRequest.mm +91 -4
  63. data/platform/iphone/rbuild/iphone.rake +297 -231
  64. data/platform/iphone/rbuild/putsOverride.rake +8 -0
  65. data/platform/shared/common/RhoTime.cpp +81 -40
  66. data/platform/shared/common/RhodesApp.cpp +16 -18
  67. data/platform/shared/db/DBAdapter.cpp +33 -0
  68. data/platform/shared/db/DBAdapter.h +5 -0
  69. data/platform/shared/net/HttpServer.cpp +27 -1
  70. data/platform/shared/net/INetRequest.cpp +33 -6
  71. data/platform/shared/qt/rhodes/qkineticscroller.cpp +2 -2
  72. data/platform/shared/qt/rhodes/qkineticscroller_p.h +1 -1
  73. data/platform/shared/qt/rhodes/qtscrollerfilter.cpp +3 -3
  74. data/platform/shared/qt/rhodes/qtscrollevent.cpp +2 -2
  75. data/platform/shared/qt/rhodes/qwebviewkineticscroller.cpp +1 -1
  76. data/platform/shared/qt/rhodes/qwebviewkineticscroller.h +1 -1
  77. data/platform/wm/build/wm.rake +7 -3
  78. data/platform/wm/rhodes/browser/BrowserFactory.cpp +4 -6
  79. data/platform/wm/rhodes/browser/stubs.cpp +5 -0
  80. data/platform/wm/rhodes/rhodes.vcproj +31 -2
  81. data/rakefile.rb +24 -0
  82. data/res/generators/templates/application/app/Settings/home.erb +1 -1
  83. data/res/generators/templates/application/build.yml +61 -4
  84. data/res/generators/templates/application/icon/icon.png +0 -0
  85. data/res/generators/templates/application/icon/icon114.png +0 -0
  86. data/res/generators/templates/application/icon/icon120.png +0 -0
  87. data/res/generators/templates/application/icon/icon144.png +0 -0
  88. data/res/generators/templates/application/icon/icon152.png +0 -0
  89. data/res/generators/templates/application/icon/icon180.png +0 -0
  90. data/res/generators/templates/application/icon/icon57.png +0 -0
  91. data/res/generators/templates/application/icon/icon60.png +0 -0
  92. data/res/generators/templates/application/icon/icon72.png +0 -0
  93. data/res/generators/templates/application/icon/icon76.png +0 -0
  94. data/res/generators/templates/application/production/iTunesArtwork.png +0 -0
  95. data/res/generators/templates/application/production/iTunesArtwork@2x.png +0 -0
  96. data/res/generators/templates/iphone_project/Bremen7.xcodeproj/project.pbxproj +1 -0
  97. data/res/generators/templates/iphone_project/buildRhoBundle +23 -7
  98. data/res/generators/templates/iphone_project/root/Info.plist +0 -2
  99. data/res/generators/templates/iphone_project/root/iTunesArtwork +0 -0
  100. data/res/generators/templates/iphone_project/root/iTunesArtwork@2x +0 -0
  101. data/res/generators/templates/iphone_project/root/icon114.png +0 -0
  102. data/res/generators/templates/iphone_project/root/icon120.png +0 -0
  103. data/res/generators/templates/iphone_project/root/icon144.png +0 -0
  104. data/res/generators/templates/iphone_project/root/icon152.png +0 -0
  105. data/res/generators/templates/iphone_project/root/icon180.png +0 -0
  106. data/res/generators/templates/iphone_project/root/icon57.png +0 -0
  107. data/res/generators/templates/iphone_project/root/icon60.png +0 -0
  108. data/res/generators/templates/iphone_project/root/icon72.png +0 -0
  109. data/res/generators/templates/iphone_project/root/icon76.png +0 -0
  110. data/res/generators/templates/iphone_project/root/rhorunner_development.entitlements +6 -0
  111. data/rhodes.gemspec +19 -17
  112. data/version +1 -1
  113. metadata +118 -44
@@ -0,0 +1,19 @@
1
+ #!/bin/sh
2
+
3
+
4
+ if [ "$RHO_PLATFORM" = "android" ]; then
5
+
6
+ cd platform/android
7
+ rake --trace
8
+
9
+ elif [ "$RHO_PLATFORM" = "iphone" ]; then
10
+
11
+ cd platform/iphone
12
+ rake --trace
13
+
14
+ elif [ "$RHO_PLATFORM" = "osx" ]; then
15
+
16
+ cd platform/qt
17
+ rake --trace
18
+
19
+ fi
@@ -0,0 +1,29 @@
1
+
2
+ if "%RHO_PLATFORM%" == "android" (
3
+
4
+ cd platform\android
5
+ rake --trace
6
+
7
+ )
8
+
9
+ if "%RHO_PLATFORM%" == "iphone" (
10
+
11
+ cd platform\phone
12
+ rake --trace
13
+
14
+ )
15
+
16
+ if "%RHO_PLATFORM%" == "win32" (
17
+
18
+ call "%RHO_VSCMNTOOLS%..\..\VC\vcvarsall.bat" x86
19
+ cd platform\qt
20
+ rake --trace
21
+
22
+ )
23
+
24
+ if "%RHO_PLATFORM%" == "bb" (
25
+
26
+ cd platform\bb
27
+ rake --trace
28
+
29
+ )
@@ -0,0 +1,16 @@
1
+ package com.rho.devicesecurity;
2
+
3
+ class InbuiltValues {
4
+
5
+ public static final String[] ALLOWED_CERT_SIGNATURES = {
6
+ <% for s in allowed_signatures %>
7
+ <%= "\"#{s}\"," %>
8
+ <% end %>
9
+ };
10
+
11
+ public static final String[] ALLOWED_INSTALLERS = {
12
+ <% for i in allowed_installers %>
13
+ <%= "\"#{i}\"," %>
14
+ <% end %>
15
+ };
16
+ };
@@ -0,0 +1,166 @@
1
+ require 'fileutils'
2
+
3
+ SOURCEPATH = ENV['SOURCEPATH']
4
+ raise 'SOURCEPATH is not set' if SOURCEPATH.nil?
5
+
6
+ SOURCELIST = ENV['SOURCELIST']
7
+ raise 'SOURCELIS is not setT' if SOURCELIST.nil?
8
+
9
+ BUILDARGS = ENV['BUILDARGS'].split if ENV['BUILDARGS']
10
+
11
+ TARGETDIR = ENV['TARGETPATH']
12
+ raise "TARGETPATH is not set" if TARGETDIR.nil?
13
+
14
+ TARGETLIB = ENV['TARGETLIB']
15
+ raise "TARGETLIB is not set" if TARGETLIB.nil?
16
+
17
+ OBJDIR = ENV['TEMP_FILES_DIR']
18
+ raise "TEMP_FILES_DIR is not set" if OBJDIR.nil?
19
+
20
+ $rootdir = ENV['RHO_ROOT']
21
+ raise "RHO_ROOT is not set" if $rootdir.nil?
22
+
23
+ $appincdir = ENV["RHO_INC"]
24
+ raise "RHO_INC is not set" if $appincdir.nil?
25
+
26
+ ANDROID_NDK = ENV['ANDROID_NDK']
27
+ raise 'ANDROID_NDK is not set' if ANDROID_NDK.nil?
28
+
29
+ ANDROID_API_LEVEL = ENV['ANDROID_API_LEVEL']
30
+ raise 'ANDROID_API_LEVEL is not set' if ANDROID_API_LEVEL.nil?
31
+
32
+ $debug = ENV['RHO_DEBUG'] == 'true'
33
+
34
+ cd SOURCEPATH
35
+
36
+ require File.join($rootdir, 'platform/android/build/androidcommon.rb')
37
+
38
+ ARGS = ['-Iext/platform/android/generated/jni',
39
+ '-Iext/platform/android/jni',
40
+ '-Iext/shared',
41
+ "-I\"#{$rootdir}/platform/android/Rhodes/jni/include\"",
42
+ "-I\"#{$rootdir}/platform/android/Rhodes/jni/include/rhodes/details\"",
43
+ "-I\"#{$rootdir}/platform/shared/ruby/include\"",
44
+ "-I\"#{$rootdir}/platform/shared\"",
45
+ "-I\"#{$rootdir}/platform/shared/common\"",
46
+ "-I\"#{$rootdir}/platform/shared/api_generator\"",
47
+ "-I\"#{$appincdir}\"",
48
+ "-I\"#{$rootdir}/platform/shared/ruby\"",
49
+ "-I\"#{$rootdir}/platform/shared/ruby/android\"",
50
+ "-I\"#{$rootdir}/platform/shared/ruby/generated\""]
51
+
52
+ OBJDIR_ARM = File.join(OBJDIR,'arm')
53
+ OBJDIR_x86 = File.join(OBJDIR,'x86')
54
+ OBJDIR_MIPS = File.join(OBJDIR,'mips')
55
+
56
+
57
+ SRC = get_sources File.join(SOURCELIST)
58
+
59
+ OBJ_ARM = FileList.new(get_objects(SRC, OBJDIR_ARM))
60
+ OBJ_x86 = FileList.new(get_objects(SRC, OBJDIR_x86))
61
+ OBJ_MIPS = FileList.new(get_objects(SRC, OBJDIR_MIPS))
62
+
63
+ TARGETDIR_ARM = File.join(TARGETDIR,'armeabi')
64
+ TARGETDIR_x86 = File.join(TARGETDIR,'x86')
65
+ TARGETDIR_MIPS = File.join(TARGETDIR,'mips')
66
+
67
+ TARGETLIB_ARM = File.join(TARGETDIR_ARM,TARGETLIB)
68
+ TARGETLIB_x86 = File.join(TARGETDIR_x86,TARGETLIB)
69
+ TARGETLIB_MIPS = File.join(TARGETDIR_MIPS,TARGETLIB)
70
+
71
+ cd '../../..'
72
+
73
+ namespace 'config' do
74
+ task :arm do
75
+ setup_ndk(ANDROID_NDK, ANDROID_API_LEVEL,'arm')
76
+ end
77
+
78
+ task :x86 do
79
+ setup_ndk(ANDROID_NDK, ANDROID_API_LEVEL,'x86')
80
+ end
81
+
82
+ task :mips do
83
+ setup_ndk(ANDROID_NDK, ANDROID_API_LEVEL,'mips')
84
+ end
85
+ end
86
+
87
+ directory TARGETDIR_ARM
88
+ directory TARGETDIR_x86
89
+ directory TARGETDIR_MIPS
90
+ directory OBJDIR_ARM
91
+ directory OBJDIR_x86
92
+ directory OBJDIR_MIPS
93
+
94
+ rule '.o' => lambda {|obj| find_source(obj) } do |t|
95
+ abi = File.basename(File.dirname(t.name))
96
+ Rake::Task["config:#{abi}"].invoke
97
+ cc_compile(find_source(t.name), File.dirname(t.name), BUILDARGS.nil? ? ARGS : BUILDARGS) or raise "\e[31mCompilation failed: #{find_source(t.name)}\e[0m"
98
+ end
99
+
100
+ task OBJ_ARM => OBJDIR_ARM
101
+ task OBJ_x86 => OBJDIR_x86
102
+ task OBJ_MIPS => OBJDIR_MIPS
103
+
104
+ def find_source(objfile)
105
+ base = File.basename(objfile, '.o')
106
+ src = SRC.find { |s| File.basename(s) == base }
107
+ src
108
+ end
109
+
110
+ file TARGETLIB_ARM => TARGETDIR_ARM do |t|
111
+ Rake::Task["config:arm"].invoke
112
+ cc_ar t.name, OBJ_ARM or raise "\e[31mCreating library failed: #{t.name}\e[0m"
113
+ end
114
+ multitask TARGETLIB_ARM => OBJ_ARM
115
+
116
+ file TARGETLIB_x86 => TARGETDIR_x86 do |t|
117
+ Rake::Task["config:x86"].invoke
118
+ cc_ar t.name, OBJ_x86 or raise "\e[31mCreating library failed: #{t.name}\e[0m"
119
+ end
120
+ multitask TARGETLIB_x86 => OBJ_x86
121
+
122
+ file TARGETLIB_MIPS => TARGETDIR_MIPS do |t|
123
+ Rake::Task["config:mips"].invoke
124
+ cc_ar t.name, OBJ_MIPS or raise "\e[31mCreating library failed: #{t.name}\e[0m"
125
+ end
126
+ multitask TARGETLIB_MIPS => OBJ_MIPS
127
+
128
+
129
+ namespace 'build' do
130
+ task :arm => OBJ_ARM
131
+ task :x86 => OBJ_x86
132
+ task :mips => OBJ_MIPS
133
+ end
134
+
135
+ namespace 'arch' do
136
+ task :arm => TARGETLIB_ARM
137
+ task :x86 => TARGETLIB_x86
138
+ task :mips => TARGETLIB_MIPS
139
+ end
140
+
141
+ task :generate_inbuilt_values do
142
+ require File.join(ENV['RHO_ROOT'], 'lib/build/jake.rb')
143
+
144
+ cfg = Jake.config( File.open( File.join( ENV['RHO_APP_DIR'], 'build.yml' )))
145
+ andr_cfg = cfg['android']
146
+ security_cfg = andr_cfg['security'] if andr_cfg
147
+
148
+ allowed_signatures = []
149
+ allowed_installers = []
150
+
151
+ if security_cfg
152
+ allowed_signatures = security_cfg[ 'allowed_cert_signatures' ] || []
153
+ allowed_installers = security_cfg[ 'allowed_installers' ] || []
154
+ end
155
+
156
+ require 'erb'
157
+
158
+ myroot = File.join(ENV['SOURCEPATH'],'ext/platform/android/')
159
+
160
+ inbuilt_template = File.read( File.join(myroot, 'InbuiltValues.erb' ) )
161
+ result = ERB.new( inbuilt_template ).result( binding )
162
+
163
+ File.write( File.join( myroot, 'generated/src/com/rho/devicesecurity/InbuiltValues.java' ), result )
164
+ end
165
+
166
+ task :default => ["arch:arm"]
@@ -0,0 +1,10 @@
1
+ ext/platform/android/generated/src/com/rho/devicesecurity/DeviceSecurityBase.java
2
+ ext/platform/android/generated/src/com/rho/devicesecurity/DeviceSecurityFactorySingleton.java
3
+ ext/platform/android/generated/src/com/rho/devicesecurity/DeviceSecuritySingletonBase.java
4
+ ext/platform/android/generated/src/com/rho/devicesecurity/IDeviceSecurity.java
5
+ ext/platform/android/generated/src/com/rho/devicesecurity/IDeviceSecurityFactory.java
6
+ ext/platform/android/generated/src/com/rho/devicesecurity/IDeviceSecuritySingleton.java
7
+ ext/platform/android/generated/src/com/rho/devicesecurity/InbuiltValues.java
8
+ ext/platform/android/src/com/rho/devicesecurity/DeviceSecurity.java
9
+ ext/platform/android/src/com/rho/devicesecurity/DeviceSecurityFactory.java
10
+ ext/platform/android/src/com/rho/devicesecurity/DeviceSecuritySingleton.java
@@ -0,0 +1,7 @@
1
+ ext/platform/android/generated/jni/DeviceSecurity.cpp
2
+ ext/platform/android/generated/jni/devicesecurity_ruby_wrap.cpp
3
+ ext/platform/android/generated/jni/devicesecurity_js_wrap.cpp
4
+ ext/platform/android/jni/DeviceSecurity_impl.cpp
5
+ ext/shared/generated/devicesecurity_api_init.cpp
6
+ ext/shared/generated/devicesecurity_js_api.cpp
7
+ ext/shared/generated/devicesecurity_ruby_api.c
@@ -0,0 +1,61 @@
1
+ #include "rhodes.h"
2
+ #include "DeviceSecurity.h"
3
+
4
+ #include "logging/RhoLog.h"
5
+ #undef DEFAULT_LOGCATEGORY
6
+ #define DEFAULT_LOGCATEGORY "DeviceSecurity_impl"
7
+
8
+ #define DEVICESECURITY_FACTORY_CLASS "com.rho.devicesecurity.DeviceSecurityFactory"
9
+
10
+ extern "C" void Init_DeviceSecurity_API(void);
11
+
12
+ extern "C" void Init_DeviceSecurity(void)
13
+ {
14
+ RAWTRACE(__FUNCTION__);
15
+
16
+ JNIEnv *env = jnienv();
17
+ if(env)
18
+ {
19
+ jclass cls = rho_find_class(env, DEVICESECURITY_FACTORY_CLASS);
20
+ if(!cls)
21
+ {
22
+ RAWLOG_ERROR1("Failed to find java class: %s", DEVICESECURITY_FACTORY_CLASS);
23
+ return;
24
+ }
25
+ jmethodID midFactory = env->GetMethodID(cls, "<init>", "()V");
26
+ if(!midFactory)
27
+ {
28
+ RAWLOG_ERROR1("Failed to get constructor for java class %s", DEVICESECURITY_FACTORY_CLASS);
29
+ return;
30
+ }
31
+ jobject jFactory = env->NewObject(cls, midFactory);
32
+ if(env->IsSameObject(jFactory, NULL))
33
+ {
34
+ RAWLOG_ERROR1("Failed to create %s instance", DEVICESECURITY_FACTORY_CLASS);
35
+ return;
36
+ }
37
+
38
+ RAWTRACE("Initializing Java factory");
39
+
40
+ rho::CDeviceSecurityBase::setJavaFactory(env, jFactory);
41
+
42
+ RAWTRACE("Deleting JNI reference");
43
+
44
+ env->DeleteLocalRef(jFactory);
45
+
46
+ RAWTRACE("Initializing API");
47
+
48
+ Init_DeviceSecurity_API();
49
+
50
+ RAWTRACE("Init_DeviceSecurity succeeded");
51
+ }
52
+ else
53
+ {
54
+ RAWLOG_ERROR("Failed to initialize DeviceSecurity API: jnienv() is failed");
55
+ }
56
+
57
+ }
58
+
59
+ extern "C" void Init_DeviceSecurity_extension() {
60
+ Init_DeviceSecurity();
61
+ }
@@ -0,0 +1,14 @@
1
+ package com.rho.devicesecurity;
2
+
3
+ import java.util.Map;
4
+
5
+ import com.rhomobile.rhodes.api.IMethodResult;
6
+ import com.rhomobile.rhodes.api.MethodResult;
7
+
8
+ public class DeviceSecurity extends DeviceSecurityBase implements IDeviceSecurity {
9
+
10
+ public DeviceSecurity(String id) {
11
+ super(id);
12
+ }
13
+
14
+ }
@@ -0,0 +1,18 @@
1
+ package com.rho.devicesecurity;
2
+
3
+ import com.rhomobile.rhodes.api.RhoApiFactory;
4
+
5
+ public class DeviceSecurityFactory
6
+ extends RhoApiFactory< DeviceSecurity, DeviceSecuritySingleton>
7
+ implements IDeviceSecurityFactory {
8
+
9
+ @Override
10
+ protected DeviceSecuritySingleton createSingleton() {
11
+ return new DeviceSecuritySingleton(this);
12
+ }
13
+
14
+ @Override
15
+ protected DeviceSecurity createApiObject(String id) {
16
+ return new DeviceSecurity(id);
17
+ }
18
+ }
@@ -0,0 +1,412 @@
1
+ package com.rho.devicesecurity;
2
+
3
+ import java.util.Collection;
4
+ import java.util.LinkedList;
5
+ import java.util.List;
6
+ import java.util.ArrayList;
7
+
8
+ import java.io.File;
9
+ import java.io.BufferedReader;
10
+ import java.io.InputStreamReader;
11
+
12
+ import java.security.MessageDigest;
13
+
14
+ import android.util.Base64;
15
+ import android.os.Build;
16
+ import android.os.Environment;
17
+ import android.bluetooth.BluetoothAdapter;
18
+
19
+ import android.content.pm.ApplicationInfo;
20
+ import android.content.pm.PackageInfo;
21
+ import android.content.pm.PackageManager;
22
+ import android.content.pm.Signature;
23
+
24
+ import android.content.Context;
25
+ import com.rhomobile.rhodes.RhodesService;
26
+ import com.rhomobile.rhodes.api.IMethodResult;
27
+ import com.rhomobile.rhodes.Logger;
28
+ import com.rhomobile.rhodes.util.Utils;
29
+
30
+ class DeviceSecuritySingleton extends DeviceSecuritySingletonBase implements IDeviceSecuritySingleton {
31
+
32
+ protected static String TAG = DeviceSecuritySingleton.class.getSimpleName();
33
+
34
+ public DeviceSecuritySingleton(DeviceSecurityFactory factory) {
35
+ super();
36
+ }
37
+
38
+
39
+ @Override
40
+ public void isDeviceSecured(IMethodResult result) {
41
+ result.set((!checkDeviceRooted()) && (!checkEmulator()) && (!checkDebuggable()) && checkAllowedInstallers() && checkAllowedSignatures() );
42
+ }
43
+
44
+ @Override
45
+ public void isDeviceJailbroken(IMethodResult result) {
46
+ result.set(false);
47
+ }
48
+
49
+
50
+ public static boolean checkDeviceRooted() {
51
+ return checkRootMethod1() || checkRootMethod2() || checkRootMethod3();
52
+ }
53
+
54
+ private static boolean checkRootMethod1() {
55
+ String buildTags = android.os.Build.TAGS;
56
+ return buildTags != null && buildTags.contains("test-keys");
57
+ }
58
+
59
+ private static boolean checkRootMethod2() {
60
+ String[] paths = { "/system/app/Superuser.apk", "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su",
61
+ "/system/bin/failsafe/su", "/data/local/su", "/su/bin/su"};
62
+ for (String path : paths) {
63
+ if (new File(path).exists()) return true;
64
+ }
65
+ return false;
66
+ }
67
+
68
+ private static boolean checkRootMethod3() {
69
+ Process process = null;
70
+ try {
71
+ process = Runtime.getRuntime().exec(new String[] { "/system/xbin/which", "su" });
72
+ BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
73
+ if (in.readLine() != null) return true;
74
+ return false;
75
+ } catch (Throwable t) {
76
+ return false;
77
+ } finally {
78
+ if (process != null) process.destroy();
79
+ }
80
+ }
81
+
82
+
83
+
84
+ @Override
85
+ public void isDeviceRooted(IMethodResult result) {
86
+ result.set(checkDeviceRooted());
87
+ }
88
+
89
+
90
+ private static String getSystemProperty(String name) throws Exception {
91
+
92
+ Class systemPropertyClazz = Class.forName("android.os.SystemProperties");
93
+ return (String) systemPropertyClazz.getMethod("get", new Class[] { String.class }).invoke(systemPropertyClazz, new Object[] { name });
94
+ }
95
+
96
+ private static boolean checkEmulator() {
97
+ return checkEmulatorMethod3();
98
+ }
99
+
100
+ private static boolean checkEmulatorMethod1() {
101
+
102
+ try {
103
+
104
+ boolean goldfish = getSystemProperty("ro.hardware").contains("goldfish");
105
+
106
+ boolean emu = getSystemProperty("ro.kernel.qemu").length() > 0;
107
+
108
+ boolean sdk = getSystemProperty("ro.product.model").equals("sdk");
109
+
110
+ if (emu || goldfish || sdk) {
111
+
112
+ return true;
113
+
114
+ }
115
+
116
+ } catch (Exception e) {
117
+
118
+ }
119
+
120
+ return false;
121
+
122
+ }
123
+
124
+ private static boolean checkEmulatorMethod2() {
125
+ return Build.FINGERPRINT.startsWith("generic")
126
+ || Build.FINGERPRINT.startsWith("unknown")
127
+ || Build.MODEL.contains("google_sdk")
128
+ || Build.MODEL.contains("Emulator")
129
+ || Build.MODEL.contains("Android SDK built for x86")
130
+ || Build.MANUFACTURER.contains("Genymotion")
131
+ || (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
132
+ || "google_sdk".equals(Build.PRODUCT)
133
+ || "goldfish".equals(Build.HARDWARE);
134
+ }
135
+
136
+ private static boolean checkEmulatorMethod3() {
137
+ int rating = 0;
138
+
139
+ if (Build.PRODUCT.contains("sdk") ||
140
+ Build.PRODUCT.contains("Andy") ||
141
+ Build.PRODUCT.contains("ttVM_Hdragon") ||
142
+ Build.PRODUCT.contains("google_sdk") ||
143
+ Build.PRODUCT.contains("Droid4X") ||
144
+ Build.PRODUCT.contains("sdk_x86") ||
145
+ Build.PRODUCT.contains("sdk_google") ||
146
+ Build.PRODUCT.contains("vbox86p")) {
147
+ rating++;
148
+ }
149
+
150
+ if (Build.MANUFACTURER.equals("unknown") ||
151
+ Build.MANUFACTURER.equals("Genymotion") ||
152
+ Build.MANUFACTURER.contains("Andy") ||
153
+ Build.MANUFACTURER.contains("TiantianVM")){
154
+ rating++;
155
+ }
156
+
157
+ if (Build.BRAND.equals("generic") ||
158
+ Build.BRAND.equals("generic_x86") ||
159
+ Build.BRAND.equals("TTVM") ||
160
+ Build.BRAND.contains("Andy")) {
161
+ rating++;
162
+ }
163
+
164
+ if (Build.DEVICE.contains("generic") ||
165
+ Build.DEVICE.contains("generic_x86") ||
166
+ Build.DEVICE.contains("Andy") ||
167
+ Build.DEVICE.contains("ttVM_Hdragon") ||
168
+ Build.DEVICE.contains("Droid4X") ||
169
+ Build.DEVICE.contains("generic_x86_64") ||
170
+ Build.DEVICE.contains("vbox86p")) {
171
+ rating++;
172
+ }
173
+
174
+ if (Build.MODEL.equals("sdk") ||
175
+ Build.MODEL.equals("google_sdk") ||
176
+ Build.MODEL.contains("Droid4X") ||
177
+ Build.MODEL.contains("TiantianVM") ||
178
+ Build.MODEL.contains("Andy") ||
179
+ Build.MODEL.equals("Android SDK built for x86_64") ||
180
+ Build.MODEL.equals("Android SDK built for x86")) {
181
+ rating++;
182
+ }
183
+
184
+ if (Build.HARDWARE.equals("goldfish") ||
185
+ Build.HARDWARE.equals("vbox86") ||
186
+ Build.HARDWARE.contains("ttVM_x86")) {
187
+ rating++;
188
+ }
189
+
190
+ if (Build.FINGERPRINT.contains("generic/sdk/generic") ||
191
+ Build.FINGERPRINT.contains("generic_x86/sdk_x86/generic_x86") ||
192
+ Build.FINGERPRINT.contains("Andy") ||
193
+ Build.FINGERPRINT.contains("ttVM_Hdragon") ||
194
+ Build.FINGERPRINT.contains("generic_x86_64") ||
195
+ Build.FINGERPRINT.contains("generic/google_sdk/generic") ||
196
+ Build.FINGERPRINT.contains("vbox86p") ||
197
+ Build.FINGERPRINT.contains("generic/vbox86p/vbox86p")) {
198
+ rating++;
199
+ }
200
+ /*
201
+ try {
202
+ String opengl = android.opengl.GLES20.glGetString(android.opengl.GLES20.GL_RENDERER);
203
+ if (opengl != null && opengl.contains("Bluestacks")){
204
+ rating += 10;
205
+ }
206
+ } catch (Exception e) {
207
+ e.printStackTrace();
208
+ }
209
+ */
210
+ try {
211
+ File sharedFolder = new File(Environment
212
+ .getExternalStorageDirectory().toString()
213
+ + File.separatorChar
214
+ + "windows"
215
+ + File.separatorChar
216
+ + "BstSharedFolder");
217
+
218
+ if (sharedFolder.exists()) {
219
+ rating += 10;
220
+ }
221
+ } catch (Exception e) {
222
+ e.printStackTrace();
223
+ }
224
+
225
+ try {
226
+ BluetoothAdapter m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
227
+ String m_bluetoothAdd = m_BluetoothAdapter.getAddress();
228
+ if (m_bluetoothAdd == null){
229
+ rating += 3;
230
+ }
231
+ } catch (Exception e) {
232
+ e.printStackTrace();
233
+ }
234
+
235
+ return rating > 3;
236
+ }
237
+
238
+ private static Context getContext() {
239
+ Context context = null;
240
+ try {
241
+ context = RhodesService.getContext();
242
+ }
243
+ catch (IllegalStateException e) {
244
+ context = null;
245
+ Logger.E(TAG, "Check Debuggable ERROR : Rhodes main Service (com.rhomobile.rhodes.RhodesService) is not run !!!");
246
+ }
247
+
248
+ return context;
249
+ }
250
+
251
+ @Override
252
+ public void isRunOnSimulator(IMethodResult result) {
253
+ result.set(checkEmulator());
254
+ }
255
+
256
+ private static boolean checkDebuggable(){
257
+
258
+ Context context = getContext();
259
+
260
+ boolean res = false;
261
+ if (context != null) {
262
+ res = (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
263
+ }
264
+ return res;
265
+
266
+ }
267
+
268
+
269
+ @Override
270
+ public void isDebugMode(IMethodResult result) {
271
+ result.set(checkDebuggable());
272
+
273
+ }
274
+
275
+ //should always be 1 signature really...
276
+ private Signature[] getSignatures() {
277
+ try {
278
+ Context context = getContext();
279
+ PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
280
+ return packageInfo.signatures;
281
+ } catch ( Exception e ) {
282
+ e.printStackTrace();
283
+ }
284
+
285
+ return null;
286
+ }
287
+
288
+ private String signatureToString( Signature signature ) {
289
+ try {
290
+ byte[] signatureBytes = signature.toByteArray();
291
+ MessageDigest md = MessageDigest.getInstance("SHA");
292
+ md.update(signature.toByteArray());
293
+ return Base64.encodeToString(md.digest(), Base64.DEFAULT).trim();
294
+ } catch ( Exception e ) {
295
+ e.printStackTrace();
296
+ }
297
+
298
+ return null;
299
+ }
300
+
301
+ @Override
302
+ public void getAppCertificateSignatures(IMethodResult result) {
303
+
304
+ Collection<Object> signatures = new ArrayList<Object>();
305
+
306
+ try {
307
+ Signature[] sigs = getSignatures();
308
+
309
+ for (Signature signature : sigs ) {
310
+ signatures.add( signatureToString( signature ) );
311
+ }
312
+
313
+ result.set(signatures);
314
+
315
+ } catch (Exception e) {
316
+ result.setError( Utils.getExceptionDetails(e) );
317
+ }
318
+ }
319
+
320
+ @Override
321
+ public void getAllowedCertificateSignatures(IMethodResult result) {
322
+ Collection<Object> signatures = new ArrayList<Object>();
323
+ for ( String s : InbuiltValues.ALLOWED_CERT_SIGNATURES ) {
324
+ signatures.add( s );
325
+ }
326
+
327
+ result.set( signatures );
328
+ }
329
+
330
+ private String getInsallerPackage() {
331
+ Context context = getContext();
332
+ return context.getPackageManager().getInstallerPackageName(context.getPackageName());
333
+ }
334
+
335
+ @Override
336
+ public void getInstallerPackageName(IMethodResult result) {
337
+ Context context = getContext();
338
+
339
+ try {
340
+ final String installer = getInsallerPackage();
341
+ result.set( installer );
342
+ } catch ( Exception e ) {
343
+ result.setError( Utils.getExceptionDetails(e) );
344
+ }
345
+ }
346
+
347
+ @Override
348
+ public void getAllowedInstallerPackages(IMethodResult result) {
349
+ Collection<Object> packages = new ArrayList<Object>();
350
+ for ( String p : InbuiltValues.ALLOWED_INSTALLERS ) {
351
+ packages.add( p );
352
+ }
353
+
354
+ result.set( packages );
355
+ }
356
+
357
+ private boolean checkAllowedInstallers() {
358
+ //allow any installer if none specified
359
+ boolean res = (InbuiltValues.ALLOWED_INSTALLERS.length == 0);
360
+ final String myInstaller = getInsallerPackage();
361
+
362
+ for ( String installer: InbuiltValues.ALLOWED_INSTALLERS ) {
363
+ if ( installer.equals( myInstaller ) ) {
364
+ res = true;
365
+ break;
366
+ }
367
+ }
368
+
369
+ return res;
370
+ }
371
+
372
+ @Override
373
+ public void haveAnyInstallerIssues(IMethodResult result) {
374
+ result.set( !checkAllowedInstallers() );
375
+ }
376
+
377
+ private boolean checkAllowedSignatures() {
378
+ Signature[] mySignatures = getSignatures();
379
+
380
+ //allow any signature if none specified
381
+ final int requiredMatches = (InbuiltValues.ALLOWED_CERT_SIGNATURES.length==0)?0:mySignatures.length;
382
+ int foundMatches = 0;
383
+
384
+ for ( Signature mySignature : mySignatures ) {
385
+ for ( String allowedSignature : InbuiltValues.ALLOWED_CERT_SIGNATURES ) {
386
+
387
+ final String sMySignature = signatureToString( mySignature );
388
+
389
+ //Logger.I( TAG, "Comparing signatures, system: "
390
+ // + sMySignature + " ;len:" + String.valueOf(sMySignature.length() ) +
391
+ // "; inbuilt: " + allowedSignature + " ;len: " + String.valueOf(allowedSignature.length() ) );
392
+
393
+ if ( sMySignature.equals(allowedSignature) ) {
394
+ //Logger.I( TAG, "Found matching signature: " + sMySignature );
395
+ ++foundMatches;
396
+ break;
397
+ }
398
+ }
399
+ }
400
+
401
+ //Logger.I( TAG, "checkAllowedSignatures, requiredMatches: "
402
+ // + String.valueOf(requiredMatches) + " ; foundMatches: " + String.valueOf( foundMatches ) );
403
+
404
+ return (foundMatches>=requiredMatches);
405
+ }
406
+
407
+ @Override
408
+ public void haveAnySignatureIssues(IMethodResult result) {
409
+ result.set( !checkAllowedSignatures() );
410
+ }
411
+
412
+ }