@hanwha-ss1/plugin 0.2.9 → 0.3.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.
@@ -7,8 +7,8 @@ import android.util.Log;
7
7
  public class Bio {
8
8
 
9
9
  public interface OnBioResult {
10
- void onSuccess(int type);
11
- void onFail(int error);
10
+ void onSuccess();
11
+ void onFail(String error);
12
12
  }
13
13
 
14
14
  public String echo(String value) {
@@ -108,131 +108,127 @@ public class BioAuthManager {
108
108
 
109
109
 
110
110
  public void authenticate(Activity activity, Bio.OnBioResult callback) {
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
- }
130
- }
131
111
 
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
- }
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());
139
199
  }
200
+ }
140
201
 
141
- @Override
142
- public void onAuthenticationFailed() {
143
- super.onAuthenticationFailed();
144
- Log.d("bioAuth", "auth failed");
145
- if(callback != null) {
146
- callback.onFail(-1);
147
- }
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();
148
208
  }
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(BIOMETRIC_STRONG)
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);
170
209
  }
171
210
 
172
- biometricPrompt.authenticate(promptInfo);
173
- }
211
+ @Override
212
+ public void onAuthenticationFailed() {
213
+ super.onAuthenticationFailed();
214
+ Log.d("fingerprint", "auth failed");
215
+ if(callback != null) {
216
+ callback.onFail("auth failed");
217
+ }
218
+ }
174
219
 
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);
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
+ }
232
227
  }
233
- }
228
+
229
+ }, null);
234
230
  }
235
231
  }
236
- });
232
+ }
237
233
  }
238
234
  }
@@ -19,4 +19,29 @@ 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
+ }
22
47
  }
@@ -5,13 +5,11 @@ 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
8
 
10
9
 
11
10
  @CapacitorPlugin(name = "Plugin")
12
11
  public class LinkerPlugin extends Plugin{
13
12
  private Linker implementation = new Linker();
14
- private Bio bioImplementation = new Bio();
15
13
 
16
14
  @PluginMethod
17
15
  public void echo(PluginCall call) {
@@ -46,29 +44,4 @@ public class LinkerPlugin extends Plugin{
46
44
  }
47
45
  });
48
46
  }
49
-
50
- @PluginMethod
51
- public void auth(PluginCall call) {
52
- if(bioImplementation == null) {
53
- bioImplementation = new Bio();
54
- }
55
- bioImplementation.authenticate(getActivity(), new Bio.OnBioResult() {
56
- @Override
57
- public void onSuccess(int type) {
58
- JSObject ret = new JSObject();
59
- ret.put("isAvailable", true);
60
- ret.put("biometryType", type);
61
- call.resolve(ret);
62
- }
63
-
64
- @Override
65
- public void onFail(int code) {
66
- JSObject ret = new JSObject();
67
- ret.put("isAvailable", false);
68
- ret.put("biometryType", -1);
69
- ret.put("errorCode", code);
70
- call.resolve(ret);
71
- }
72
- });
73
- }
74
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanwha-ss1/plugin",
3
- "version": "0.2.9",
3
+ "version": "0.3.1",
4
4
  "description": "Plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -44,10 +44,10 @@
44
44
  "prepublishOnly": "npm run build"
45
45
  },
46
46
  "devDependencies": {
47
- "@capacitor/android": "3.6.0",
48
- "@capacitor/core": "3.6.0",
47
+ "@capacitor/android": "3.0.0",
48
+ "@capacitor/core": "3.0.0",
49
49
  "@capacitor/docgen": "0.0.18",
50
- "@capacitor/ios": "3.6.0",
50
+ "@capacitor/ios": "3.0.0",
51
51
  "@ionic/eslint-config": "0.3.0",
52
52
  "@ionic/prettier-config": "1.0.1",
53
53
  "@ionic/swiftlint-config": "1.1.2",
@@ -60,7 +60,7 @@
60
60
  "typescript": "4.0.3"
61
61
  },
62
62
  "peerDependencies": {
63
- "@capacitor/core": "3.6.0"
63
+ "@capacitor/core": "3.0.0"
64
64
  },
65
65
  "prettier": "@ionic/prettier-config",
66
66
  "swiftlint": "@ionic/swiftlint-config",