@hanwha-ss1/plugin 0.2.8 → 0.3.0

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.
@@ -7,8 +7,8 @@ import android.util.Log;
7
7
  public class Bio {
8
8
 
9
9
  public interface OnBioResult {
10
- void onSuccess();
11
- void onFail(String error);
10
+ void onSuccess(int type);
11
+ void onFail(int error);
12
12
  }
13
13
 
14
14
  public String echo(String value) {
@@ -58,7 +58,7 @@ public class BioAuthManager {
58
58
  Intent intent;
59
59
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
60
60
  BiometricManager biometricManager = BiometricManager.from(activity);
61
- switch (biometricManager.canAuthenticate(BIOMETRIC_STRONG)) {
61
+ switch (biometricManager.canAuthenticate(DEVICE_CREDENTIAL)) {
62
62
  case BiometricManager.BIOMETRIC_SUCCESS:
63
63
  Log.d("MY_APP_TAG", "App can authenticate using biometrics.");
64
64
  return true;
@@ -72,10 +72,10 @@ public class BioAuthManager {
72
72
  // Prompts the user to create credentials that your app accepts.
73
73
  Log.d("MY_APP_TAG", "enrolled biometric doesn't existed. please enroll");
74
74
 
75
- intent = new Intent(Settings.ACTION_FINGERPRINT_ENROLL);
76
- intent.putExtra(Settings.EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED,
77
- BIOMETRIC_STRONG | DEVICE_CREDENTIAL);
78
- activity.startActivityForResult(intent, REQUEST_FINGERPRINT_ENROLLMENT_AUTH);
75
+ // intent = new Intent(Settings.ACTION_FINGERPRINT_ENROLL);
76
+ // intent.putExtra(Settings.EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED,
77
+ // BIOMETRIC_STRONG | DEVICE_CREDENTIAL);
78
+ // activity.startActivityForResult(intent, REQUEST_FINGERPRINT_ENROLLMENT_AUTH);
79
79
  return false;
80
80
  }
81
81
  } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
@@ -97,8 +97,8 @@ public class BioAuthManager {
97
97
  // 등록된 지문이 없는 경우
98
98
  else if (!fingerprintManager.hasEnrolledFingerprints()) {
99
99
  Log.d("fingerprint", "please enroll fingerprint");
100
- intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
101
- activity.startActivityForResult(intent, REQUEST_FINGERPRINT_ENROLLMENT_AUTH);
100
+ // intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
101
+ // activity.startActivityForResult(intent, REQUEST_FINGERPRINT_ENROLLMENT_AUTH);
102
102
  return false;
103
103
  }
104
104
  return true;
@@ -108,127 +108,131 @@ public class BioAuthManager {
108
108
 
109
109
 
110
110
  public void authenticate(Activity activity, Bio.OnBioResult callback) {
111
-
112
- keyManager = KeyManager.getInstance();
113
- // api 28 ( ANDROID 9.0 ) 이상은 biometricPrompt 사용
114
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
115
- Log.d("bioAuth", "start biometricPrompt");
116
-
117
- if (canAuthenticate(activity)) {
118
- executor = activity.getMainExecutor();
119
-
120
- biometricPrompt = new BiometricPrompt((FragmentActivity) activity, executor, new BiometricPrompt.AuthenticationCallback() {
121
- @Override
122
- public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
123
- super.onAuthenticationError(errorCode, errString);
124
- Log.d("bioAuth", errString.toString());
125
- if(callback != null) {
126
- callback.onFail(errString.toString());
127
- }
128
- }
129
-
130
- @Override
131
- public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
132
- super.onAuthenticationSucceeded(result);
133
- Log.d("bioAuth", "auth success");
134
- if(callback != null) {
135
- callback.onSuccess();
136
- }
137
- }
138
-
139
- @Override
140
- public void onAuthenticationFailed() {
141
- super.onAuthenticationFailed();
142
- Log.d("bioAuth", "auth failed");
143
- if(callback != null) {
144
- callback.onFail("auth failed");
145
- }
146
- }
147
- });
148
-
149
- // DEVICE_CREDENTIAL 및 BIOMETRIC_STRING | DEVICE_CREDENTIAL 은 안드로이드 10 이하에서 지원되지 않는다.
150
- // 안드로이드 10 이하에서 PIN 이나 패턴, 비밀번호가 있는지 확인하려면 KeyguardManager.isDeviceSecure() 함수를 사용할 것
151
- promptInfo = new BiometricPrompt.PromptInfo.Builder()
152
- .setTitle("지문 인증")
153
- .setSubtitle("기기에 등록된 지문을 이용하여 지문을 인증해주세요.")
154
- // .setDescription("생체 인증 설명")
155
- // BIOMETRIC_STRONG 은 안드로이드 11 에서 정의한 클래스 3 생체 인식을 사용하는 인증 - 암호회된 키 필요
156
- // BIOMETRIC_WEAK 은 안드로이드 11 에서 정의한 클래스 2 생체 인식을 사용하는 인증 - 암호화된 키까지 필요하지는 않음
157
- // DEVICE_CREDENTIAL 은 화면 잠금 사용자 인증 정보를 사용하는 인증 - 사용자의 PIN, 패턴 또는 비밀번호
158
- .setAllowedAuthenticators(BIOMETRIC_STRONG)
159
- .setConfirmationRequired(false) // 명시적인 사용자 작업 ( 생체 인식 전 한번더 체크 ) 없이 인증할건지 default : true
160
- .setNegativeButtonText("취소")
161
- .build();
162
-
163
- keyManager.generateKey();
164
-
165
- if (keyManager.cipherInit()) {
166
- bioCryptoObject = new BiometricPrompt.CryptoObject(keyManager.getCipher());
167
- biometricPrompt.authenticate(promptInfo, bioCryptoObject);
168
- }
169
-
170
- biometricPrompt.authenticate(promptInfo);
171
- }
172
-
173
- }
174
- // api 23 ( ANDROID 6.0 ) 부터 api 28 ( ANDROID 9.0 ) 까지는 fingerprint 사용
175
- else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
176
- Log.d("fingerprint", "fingerprint start");
177
-
178
- fingerprintManager = (FingerprintManager) activity.getSystemService(FINGERPRINT_SERVICE);
179
- keyguardManager = (KeyguardManager) activity.getSystemService(KEYGUARD_SERVICE);
180
-
181
- if (canAuthenticate(activity)) {
182
- Log.d("fingerprint", "requirement fingerprint needed all pass");
183
-
184
- keyManager.generateKey();
185
-
186
- if (keyManager.cipherInit()) {
187
-
188
- Cipher cipher = keyManager.getCipher();
189
-
190
- cryptoObject = new FingerprintManager.CryptoObject(cipher);
191
-
192
- fingerprintManager.authenticate(cryptoObject, new CancellationSignal(), 0, new FingerprintManager.AuthenticationCallback() {
193
- @Override
194
- public void onAuthenticationError(int errorCode, CharSequence errString) {
195
- super.onAuthenticationError(errorCode, errString);
196
- Log.d("fingerprint", String.valueOf(errorCode));
197
- if(callback != null) {
198
- callback.onFail(errString.toString());
111
+ activity.runOnUiThread(new Runnable() {
112
+ @Override
113
+ public void run() {
114
+ keyManager = KeyManager.getInstance();
115
+ // api 28 ( ANDROID 9.0 ) 이상은 biometricPrompt 사용
116
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
117
+ Log.d("bioAuth", "start biometricPrompt");
118
+
119
+ if (canAuthenticate(activity)) {
120
+ executor = activity.getMainExecutor();
121
+
122
+ biometricPrompt = new BiometricPrompt((FragmentActivity) activity, executor, new BiometricPrompt.AuthenticationCallback() {
123
+ @Override
124
+ public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
125
+ super.onAuthenticationError(errorCode, errString);
126
+ Log.d("bioAuth", errString.toString());
127
+ if(callback != null) {
128
+ callback.onFail(errorCode);
129
+ }
199
130
  }
200
- }
201
131
 
202
- @Override
203
- public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
204
- super.onAuthenticationSucceeded(result);
205
- Log.d("fingerprint", "auth success");
206
- if(callback != null) {
207
- callback.onSuccess();
132
+ @Override
133
+ public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
134
+ super.onAuthenticationSucceeded(result);
135
+ Log.d("bioAuth", "auth success");
136
+ if(callback != null) {
137
+ callback.onSuccess(result.getAuthenticationType());
138
+ }
208
139
  }
209
- }
210
140
 
211
- @Override
212
- public void onAuthenticationFailed() {
213
- super.onAuthenticationFailed();
214
- Log.d("fingerprint", "auth failed");
215
- if(callback != null) {
216
- callback.onFail("auth failed");
141
+ @Override
142
+ public void onAuthenticationFailed() {
143
+ super.onAuthenticationFailed();
144
+ Log.d("bioAuth", "auth failed");
145
+ if(callback != null) {
146
+ callback.onFail(-1);
147
+ }
217
148
  }
149
+ });
150
+
151
+ // DEVICE_CREDENTIAL 및 BIOMETRIC_STRING | DEVICE_CREDENTIAL 은 안드로이드 10 이하에서 지원되지 않는다.
152
+ // 안드로이드 10 이하에서 PIN 이나 패턴, 비밀번호가 있는지 확인하려면 KeyguardManager.isDeviceSecure() 함수를 사용할 것
153
+ promptInfo = new BiometricPrompt.PromptInfo.Builder()
154
+ .setTitle("생체 인증")
155
+ .setSubtitle("기기에 등록된 생체 인증을 이용하여 인증해주세요.")
156
+ // .setDescription("생체 인증")
157
+ // BIOMETRIC_STRONG 은 안드로이드 11 에서 정의한 클래스 3 생체 인식을 사용하는 인증 - 암호회된 키 필요
158
+ // BIOMETRIC_WEAK 은 안드로이드 11 에서 정의한 클래스 2 생체 인식을 사용하는 인증 - 암호화된 키까지 필요하지는 않음
159
+ // DEVICE_CREDENTIAL 은 화면 잠금 사용자 인증 정보를 사용하는 인증 - 사용자의 PIN, 패턴 또는 비밀번호
160
+ // .setAllowedAuthenticators(DEVICE_CREDENTIAL)
161
+ .setConfirmationRequired(false) // 명시적인 사용자 작업 ( 생체 인식 전 한번더 체크 ) 없이 인증할건지 default : true
162
+ .setNegativeButtonText("취소")
163
+ .build();
164
+
165
+ keyManager.generateKey();
166
+
167
+ if (keyManager.cipherInit()) {
168
+ bioCryptoObject = new BiometricPrompt.CryptoObject(keyManager.getCipher());
169
+ biometricPrompt.authenticate(promptInfo, bioCryptoObject);
218
170
  }
219
171
 
220
- @Override
221
- public void onAuthenticationHelp(int helpCode, CharSequence helpString) {
222
- super.onAuthenticationHelp(helpCode, helpString);
223
- Log.d("fingerprint", helpString.toString());
224
- if(callback != null) {
225
- callback.onFail(helpString.toString());
226
- }
227
- }
172
+ biometricPrompt.authenticate(promptInfo);
173
+ }
228
174
 
229
- }, null);
175
+ }
176
+ // api 23 ( ANDROID 6.0 ) 부터 api 28 ( ANDROID 9.0 ) 까지는 fingerprint 사용
177
+ else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
178
+ Log.d("fingerprint", "fingerprint start");
179
+
180
+ fingerprintManager = (FingerprintManager) activity.getSystemService(FINGERPRINT_SERVICE);
181
+ keyguardManager = (KeyguardManager) activity.getSystemService(KEYGUARD_SERVICE);
182
+
183
+ if (canAuthenticate(activity)) {
184
+ Log.d("fingerprint", "requirement fingerprint needed all pass");
185
+
186
+ keyManager.generateKey();
187
+
188
+ if (keyManager.cipherInit()) {
189
+
190
+ Cipher cipher = keyManager.getCipher();
191
+
192
+ cryptoObject = new FingerprintManager.CryptoObject(cipher);
193
+
194
+ fingerprintManager.authenticate(cryptoObject, new CancellationSignal(), 0, new FingerprintManager.AuthenticationCallback() {
195
+ @Override
196
+ public void onAuthenticationError(int errorCode, CharSequence errString) {
197
+ super.onAuthenticationError(errorCode, errString);
198
+ Log.d("fingerprint", String.valueOf(errorCode));
199
+ if(callback != null) {
200
+ callback.onFail(errorCode);
201
+ }
202
+ }
203
+
204
+ @Override
205
+ public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
206
+ super.onAuthenticationSucceeded(result);
207
+ Log.d("fingerprint", "auth success");
208
+ if(callback != null) {
209
+ callback.onSuccess(-1);
210
+ }
211
+ }
212
+
213
+ @Override
214
+ public void onAuthenticationFailed() {
215
+ super.onAuthenticationFailed();
216
+ Log.d("fingerprint", "auth failed");
217
+ if(callback != null) {
218
+ callback.onFail(-1);
219
+ }
220
+ }
221
+
222
+ @Override
223
+ public void onAuthenticationHelp(int helpCode, CharSequence helpString) {
224
+ super.onAuthenticationHelp(helpCode, helpString);
225
+ Log.d("fingerprint", helpString.toString());
226
+ if(callback != null) {
227
+ callback.onFail(helpCode);
228
+ }
229
+ }
230
+
231
+ }, null);
232
+ }
233
+ }
230
234
  }
231
235
  }
232
- }
236
+ });
233
237
  }
234
238
  }
@@ -19,29 +19,4 @@ public class BioPlugin extends Plugin{
19
19
  ret.put("value", implementation.echo(value));
20
20
  call.resolve(ret);
21
21
  }
22
-
23
- @PluginMethod
24
- public void auth(PluginCall call) {
25
- if(implementation == null) {
26
- implementation = new Bio();
27
- }
28
- implementation.authenticate(getActivity(), new Bio.OnBioResult() {
29
- @Override
30
- public void onSuccess() {
31
- JSObject ret = new JSObject();
32
- ret.put("result", true);
33
- ret.put("message", "완료");
34
- call.resolve(ret);
35
- }
36
-
37
- @Override
38
- public void onFail(String error) {
39
- JSObject ret = new JSObject();
40
- ret.put("result", false);
41
- ret.put("message", error);
42
- call.resolve(ret);
43
- }
44
- });
45
-
46
- }
47
22
  }
@@ -19,33 +19,4 @@ public class ContactPlugin extends Plugin{
19
19
  ret.put("value", implementation.echo(value));
20
20
  call.resolve(ret);
21
21
  }
22
-
23
- @PluginMethod
24
- public void addContact(PluginCall call) {
25
- String name = call.getString("name");
26
- String mobile = call.getString("phone");
27
- String phone = call.getString("ext");
28
- String department = call.getString("dept");
29
- String email = call.getString("email");
30
- if(implementation == null) {
31
- implementation = new Contact();
32
- }
33
- implementation.save(getActivity(), name, email, mobile, phone, department, new Contact.OnResult() {
34
- @Override
35
- public void onSuccess() {
36
- JSObject ret = new JSObject();
37
- ret.put("result", true);
38
- ret.put("message", "완료");
39
- call.resolve(ret);
40
- }
41
-
42
- @Override
43
- public void onFail() {
44
- JSObject ret = new JSObject();
45
- ret.put("result", false);
46
- ret.put("message", "존재하는 번호입니다.");
47
- call.resolve(ret);
48
- }
49
- });
50
- }
51
22
  }
@@ -5,11 +5,17 @@ import com.getcapacitor.Plugin;
5
5
  import com.getcapacitor.PluginCall;
6
6
  import com.getcapacitor.PluginMethod;
7
7
  import com.getcapacitor.annotation.CapacitorPlugin;
8
+ import com.plugin.bio.Bio;
9
+ import com.plugin.contact.Contact;
10
+ import com.plugin.openbrowser.OpenBrowser;
8
11
 
9
12
 
10
13
  @CapacitorPlugin(name = "Plugin")
11
14
  public class LinkerPlugin extends Plugin{
12
15
  private Linker implementation = new Linker();
16
+ private Bio bioImplementation = new Bio();
17
+ private Contact contactImplementation = new Contact();
18
+ private OpenBrowser openBrowserImplementation = new OpenBrowser();
13
19
 
14
20
  @PluginMethod
15
21
  public void echo(PluginCall call) {
@@ -44,4 +50,68 @@ public class LinkerPlugin extends Plugin{
44
50
  }
45
51
  });
46
52
  }
53
+
54
+ @PluginMethod
55
+ public void auth(PluginCall call) {
56
+ if(bioImplementation == null) {
57
+ bioImplementation = new Bio();
58
+ }
59
+ bioImplementation.authenticate(getActivity(), new Bio.OnBioResult() {
60
+ @Override
61
+ public void onSuccess(int type) {
62
+ JSObject ret = new JSObject();
63
+ ret.put("isAvailable", true);
64
+ ret.put("biometryType", type);
65
+ call.resolve(ret);
66
+ }
67
+
68
+ @Override
69
+ public void onFail(int code) {
70
+ JSObject ret = new JSObject();
71
+ ret.put("isAvailable", false);
72
+ ret.put("biometryType", -1);
73
+ ret.put("errorCode", code);
74
+ call.resolve(ret);
75
+ }
76
+ });
77
+ }
78
+
79
+ @PluginMethod
80
+ public void addContact(PluginCall call) {
81
+ String name = call.getString("name");
82
+ String mobile = call.getString("phone");
83
+ String phone = call.getString("ext");
84
+ String department = call.getString("dept");
85
+ String email = call.getString("email");
86
+ if(contactImplementation == null) {
87
+ contactImplementation = new Contact();
88
+ }
89
+ contactImplementation.save(getActivity(), name, email, mobile, phone, department, new Contact.OnResult() {
90
+ @Override
91
+ public void onSuccess() {
92
+ JSObject ret = new JSObject();
93
+ ret.put("result", true);
94
+ ret.put("message", "완료");
95
+ call.resolve(ret);
96
+ }
97
+
98
+ @Override
99
+ public void onFail() {
100
+ JSObject ret = new JSObject();
101
+ ret.put("result", false);
102
+ ret.put("message", "존재하는 번호입니다.");
103
+ call.resolve(ret);
104
+ }
105
+ });
106
+ }
107
+
108
+ @PluginMethod
109
+ public void open(PluginCall call) {
110
+ String url = call.getString("url");
111
+ boolean isExternal = call.getBoolean("ext");
112
+ if(openBrowserImplementation == null) {
113
+ openBrowserImplementation = new OpenBrowser();
114
+ }
115
+ openBrowserImplementation.open(getActivity(), url, isExternal);
116
+ }
47
117
  }
@@ -19,14 +19,4 @@ public class OpenBrowserPlugin extends Plugin {
19
19
  ret.put("value", implementation.echo(value));
20
20
  call.resolve(ret);
21
21
  }
22
-
23
- @PluginMethod
24
- public void open(PluginCall call) {
25
- String url = call.getString("url");
26
- boolean isExternal = call.getBoolean("ext");
27
- if(implementation == null) {
28
- implementation = new OpenBrowser();
29
- }
30
- implementation.open(getActivity(), url, isExternal);
31
- }
32
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanwha-ss1/plugin",
3
- "version": "0.2.8",
3
+ "version": "0.3.0",
4
4
  "description": "Plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",