├── .gitignore
├── .idea
├── checkstyle-idea.xml
├── gradle.xml
├── kotlinc.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── bcm
│ │ └── bmprinter
│ │ ├── FingerprintDialog.kt
│ │ ├── MainActivity.kt
│ │ ├── VerifyFingerprintFragment.kt
│ │ └── VerifyPasswordFragment.kt
│ └── res
│ ├── drawable-v24
│ └── ic_launcher_foreground.xml
│ ├── drawable-xhdpi
│ ├── fingerprint_icon.png
│ ├── fingerprint_match_icon.png
│ ├── fingerprint_not_match_icon.png
│ └── next_black_icon.png
│ ├── drawable
│ ├── bg_fingerprint_dialog.xml
│ ├── common_primary_thick_round_selector.xml
│ ├── common_primary_thin_round_selector.xml
│ ├── ic_launcher_background.xml
│ ├── register_input_bg.xml
│ └── register_input_error_bg.xml
│ ├── layout
│ ├── activity_main.xml
│ ├── activity_verify_fingerprint.xml
│ ├── dialog_fingerprint.xml
│ ├── fragment_verify_fingerprint.xml
│ └── fragment_verify_password.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── bmprinter
├── .gitignore
├── build.gradle
├── libs
│ ├── fingerprint.jar
│ ├── pass-v1.2.6.jar
│ └── sdk-v1.0.0.jar
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── bcm
│ │ └── bmprinter
│ │ └── fingerprint
│ │ ├── AospFingerprintHelper.kt
│ │ ├── BiometricPromptHelper.kt
│ │ ├── FingerprintFactory.kt
│ │ ├── IFingerprintUtil.kt
│ │ └── brandfingerprintutils
│ │ ├── AospFingerprintUtil.kt
│ │ ├── MeizuFingerprintUtil.kt
│ │ ├── MiFingerprintUtil.kt
│ │ ├── SamsungFingerprintUtil.kt
│ │ ├── VivoFingerprintInsets.kt
│ │ └── VivoFingerprintUtil.kt
│ └── res
│ └── values
│ └── strings.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/checkstyle-idea.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | 1.8
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BMPrinter
2 | BMPrinter is the first open source project from SKYSTAR and BCM
3 |
4 | Characteristic
5 | -------------------
6 | 1.Has Adapted most of phone with fingerprint above Android N,included XIAOMI,MEIZU,VIVO,OPPO,Samsung and google.
7 | 2.Has Adapted underscreen fingerprint,include XIAOMI,VIVO,OPPO.
8 | 3.Has Adapted some phone above Android L.
9 |
10 |
11 | Add to Your project
12 | -------------------
13 | ```
14 | Gradle:
15 | implementation project(':bmprinter')
16 | ```
17 |
18 | Ussage
19 | -------------------
20 | All code is write with kotlin,so it would be best you know kotlin and java.
21 | 1.get BMPrinter
22 | var fingerprintUtil: IFingerprintUtil = createFingerprintUtil()
23 |
24 | 2.authenticate
25 | fingerprintUtil?.authenticate { success, errCode, errMsg -> if(success){}}
26 |
27 | 3.FingerprintFactory
28 | you can see some status for fingerprint authentication in FingerprintFactory.
29 |
30 |
31 | About Android P
32 | -------------------
33 | It has change FingerPrint api to BiometricPrompt and BiometricPrompt only can be built as a dialog.
34 | New version has support android P.
35 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 26
9 | defaultConfig {
10 | applicationId "com.bcm.bmprinter"
11 | minSdkVersion 23
12 | targetSdkVersion 26
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(include: ['*.jar'], dir: 'libs')
27 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
28 | implementation 'com.android.support:appcompat-v7:26.1.0'
29 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
30 | api 'com.android.support.constraint:constraint-layout:1.1.3'
31 | implementation project(':bmprinter')
32 | }
33 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bcm/bmprinter/FingerprintDialog.kt:
--------------------------------------------------------------------------------
1 | package com.bcm.bmprinter
2 |
3 | import android.content.res.Resources
4 | import android.graphics.Color
5 | import android.graphics.drawable.ColorDrawable
6 | import android.os.Bundle
7 | import android.support.v4.app.DialogFragment
8 | import android.view.LayoutInflater
9 | import android.view.View
10 | import android.view.ViewGroup
11 | import android.view.WindowManager
12 |
13 | import kotlinx.android.synthetic.main.dialog_fingerprint.*
14 |
15 | /**
16 | * Created by Kin on 2018/9/4
17 | */
18 | class FingerprintDialog : DialogFragment() {
19 | private val TAG = "FingerprintDialog"
20 |
21 | private var positiveCallback: (() -> Unit)? = null
22 | private var negativeCallback: (() -> Unit)? = null
23 | private var message = ""
24 | private var hasFingerprint = true
25 |
26 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
27 | dialog.window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
28 | return inflater.inflate(R.layout.dialog_fingerprint, container, false)
29 | }
30 |
31 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
32 | dialog_fingerprint_positive.setOnClickListener {
33 | dismiss()
34 | positiveCallback?.invoke()
35 | }
36 | dialog_fingerprint_negative.setOnClickListener {
37 | dismiss()
38 | negativeCallback?.invoke()
39 | }
40 | if (!hasFingerprint) {
41 | dialog_fingerprint_positive.visibility = View.GONE
42 | }
43 | dialog_fingerprint_text.text = message
44 | }
45 |
46 | override fun onActivityCreated(savedInstanceState: Bundle?) {
47 | super.onActivityCreated(savedInstanceState)
48 | dialog.window.setLayout(dp2Px(resources, 275), WindowManager.LayoutParams.WRAP_CONTENT)
49 | dialog.setCancelable(false)
50 | dialog.setCanceledOnTouchOutside(false)
51 | }
52 |
53 | fun setCallback(positiveCallback: () -> Unit, negativeCallback: () -> Unit): FingerprintDialog {
54 | this.positiveCallback = positiveCallback
55 | this.negativeCallback = negativeCallback
56 | return this
57 | }
58 |
59 | fun setMessage(msg: String): FingerprintDialog {
60 | message = msg
61 | return this
62 | }
63 |
64 | fun setHasFingerprint(hasFingerprint: Boolean): FingerprintDialog {
65 | this.hasFingerprint = hasFingerprint
66 | return this
67 | }
68 | }
69 |
70 | /**
71 | * 单位转换:dp转px
72 | * @param res
73 | * @param dp
74 | * @return
75 | */
76 | fun dp2Px(res: Resources, dp: Int): Int {
77 | return (dp * res.displayMetrics.density + 0.5f).toInt()
78 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/bcm/bmprinter/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.bcm.bmprinter
2 |
3 | import android.app.Activity
4 | import android.support.v7.app.AppCompatActivity
5 | import android.os.Bundle
6 | import android.util.Log
7 | import android.widget.Toast
8 | import com.bcm.bmprinter.fingerprint.IFingerprintUtil
9 | import com.bcm.bmprinter.fingerprint.createFingerprintUtil
10 |
11 | class MainActivity : AppCompatActivity() {
12 | private val TAG = "MainActivity"
13 |
14 | private lateinit var fingerprintUtil: IFingerprintUtil
15 |
16 | override fun onCreate(savedInstanceState: Bundle?) {
17 | super.onCreate(savedInstanceState)
18 | setContentView(R.layout.activity_verify_fingerprint)
19 |
20 | initView()
21 | }
22 |
23 | private fun initView() {
24 | //创建指纹识别辅助器
25 | fingerprintUtil = createFingerprintUtil(applicationContext)
26 | //判断是否可用,设备是否存在锁密码,是否有录过指纹
27 | if (fingerprintUtil.canUseFingerprint() && fingerprintUtil.isDeviceSecure() && fingerprintUtil.hasEnrolledFingerprints()) {
28 | Log.d(TAG, "Device has fingerprint sensor and has enrolled fingerprints, start authenticate fingerprint.")
29 | switchToFingerprintFragment() //跳转到屏幕指纹识别
30 | } else {
31 | Log.d(TAG, "Device has no fingerprint sensor, start authenticate password.")
32 | switchToPasswordFragment(false) //跳转到密码页面
33 | }
34 | }
35 |
36 | /**
37 | * 跳去指纹识别页
38 | */
39 | fun switchToFingerprintFragment() {
40 | val f = VerifyFingerprintFragment()
41 | .setFingerprintUtil(fingerprintUtil)
42 | .setCallback(this::handleCallback)
43 | supportFragmentManager.beginTransaction()
44 | .replace(R.id.container, f)
45 | .commit()
46 | }
47 |
48 | /**
49 | * 跳转密码页
50 | */
51 | fun switchToPasswordFragment(hasFingerprint: Boolean, lockout: Boolean = false) {
52 | val f = VerifyPasswordFragment()
53 | .setHasFingerprint(hasFingerprint)
54 | .setHasLockout(lockout)
55 | .setCallback(this::handleCallback)
56 | supportFragmentManager.beginTransaction()
57 | .replace(R.id.container, f)
58 | .commit()
59 | }
60 |
61 | private fun handleCallback(success: Boolean) {
62 | if (success) {
63 | Log.d(TAG, "Authenticate success.")
64 | setResult(Activity.RESULT_OK)
65 | Toast.makeText(this,"Success", Toast.LENGTH_SHORT).show()
66 | } else {
67 | Log.d(TAG, "Authenticate failed.")
68 | setResult(Activity.RESULT_CANCELED)
69 | Toast.makeText(this,"Fail", Toast.LENGTH_SHORT).show()
70 | }
71 | // finish()
72 | }
73 |
74 | override fun finish() {
75 | super.finish()
76 | fingerprintUtil.destroy() //清理数据
77 | }
78 |
79 | override fun onBackPressed() {
80 | finish()
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bcm/bmprinter/VerifyFingerprintFragment.kt:
--------------------------------------------------------------------------------
1 | package com.bcm.bmprinter
2 |
3 | import android.os.Bundle
4 | import android.os.Handler
5 | import android.os.Looper
6 | import android.support.v4.app.Fragment
7 | import android.util.Log
8 | import android.view.LayoutInflater
9 | import android.view.View
10 | import android.view.ViewGroup
11 | import com.bcm.bmprinter.fingerprint.AUTHENTICATE_FAILED_LOCKOUT
12 | import com.bcm.bmprinter.fingerprint.IFingerprintUtil
13 | import kotlinx.android.synthetic.main.fragment_verify_fingerprint.*
14 |
15 | /**
16 | * Created by Kin on 2018/9/3
17 | */
18 | class VerifyFingerprintFragment : Fragment() {
19 | private val TAG = "VerifyFingerprint"
20 | private val DIALOG_TAG = "Fingerprint_Dialog"
21 |
22 | private var fingerprintUtil: IFingerprintUtil? = null
23 | private var verifyCallback: ((success: Boolean) -> Unit)? = null
24 | private var fragmentOnTop = false
25 |
26 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
27 | return inflater.inflate(R.layout.fragment_verify_fingerprint, container, false)
28 | }
29 |
30 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
31 | verify_fingerprint_cancel.setOnClickListener {
32 | verifyCallback?.invoke(false)
33 | }
34 | verify_fingerprint_password.setOnClickListener {
35 | (activity as? MainActivity)?.switchToPasswordFragment(true)
36 | }
37 | }
38 |
39 | /**
40 | * 开启指纹识别
41 | */
42 | private fun startAuthenticate() {
43 | Log.d(TAG, "Start authenticate")
44 | fingerprintUtil?.authenticate { success, errCode, errMsg ->
45 | Log.d(TAG, "Get authenticate result, success: $success, error code: $errCode, error msg: $errMsg")
46 | if (success) { //返回成功
47 | verify_fingerprint_icon.setImageDrawable(context?.getDrawable(R.drawable.fingerprint_match_icon))
48 | Handler(Looper.getMainLooper()).postDelayed({
49 | verifyCallback?.invoke(true)
50 | verify_fingerprint_icon.postDelayed(resetImage,2000)
51 | }, 1000)
52 | } else {
53 | if (errCode == AUTHENTICATE_FAILED_LOCKOUT) { //如果返回验证超过次数被锁
54 | // 失败被锁,关闭错误提示框,跳转到输入密码界面
55 | val oldDialog = fragmentManager?.findFragmentByTag(DIALOG_TAG)
56 | if (oldDialog is FingerprintDialog) {
57 | oldDialog.dismiss()
58 | }
59 | (activity as? MainActivity)?.switchToPasswordFragment(true, true)
60 | return@authenticate
61 | }
62 | if (fragmentOnTop) { //页面不在顶层
63 | showFailDialog(getString(R.string.fingerprint_not_match), errCode == AUTHENTICATE_FAILED_LOCKOUT)
64 | }
65 | }
66 | fingerprintUtil?.cancelAuthenticate()
67 | }
68 | }
69 |
70 | fun setFingerprintUtil(util: IFingerprintUtil): VerifyFingerprintFragment {
71 | fingerprintUtil = util
72 | return this
73 | }
74 |
75 | /**
76 | * 设置回调
77 | */
78 | fun setCallback(callback: (success: Boolean) -> Unit): VerifyFingerprintFragment {
79 | verifyCallback = callback
80 | return this
81 | }
82 |
83 | val resetImage = Runnable {
84 | verify_fingerprint_icon.setImageDrawable(context?.getDrawable(R.drawable.fingerprint_icon))
85 | startAuthenticate()
86 | }
87 |
88 | private fun showFailDialog(errMsg: String, lockout: Boolean) {
89 | val oldDialog = fragmentManager?.findFragmentByTag(DIALOG_TAG)
90 | if (oldDialog != null) {
91 | return
92 | }
93 | FingerprintDialog()
94 | .setHasFingerprint(true)
95 | .setMessage(errMsg)
96 | .setCallback({
97 | startAuthenticate()
98 | }, {
99 | (activity as? MainActivity)?.switchToPasswordFragment(true, lockout)
100 | })
101 | .show(fragmentManager, DIALOG_TAG)
102 | }
103 |
104 | override fun onResume() {
105 | super.onResume()
106 | fragmentOnTop = true
107 | //开启指纹识别
108 | startAuthenticate()
109 | }
110 |
111 | override fun onStop() {
112 | super.onStop()
113 | fragmentOnTop = false
114 | fingerprintUtil?.cancelAuthenticate()
115 | verify_fingerprint_icon.removeCallbacks(resetImage)
116 | }
117 |
118 | override fun onDetach() {
119 | super.onDetach()
120 | fingerprintUtil = null
121 | verifyCallback = null
122 | }
123 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/bcm/bmprinter/VerifyPasswordFragment.kt:
--------------------------------------------------------------------------------
1 | package com.bcm.bmprinter
2 |
3 | import android.os.Bundle
4 | import android.support.v4.app.Fragment
5 | import android.text.Editable
6 | import android.text.TextWatcher
7 | import android.view.LayoutInflater
8 | import android.view.View
9 | import android.view.ViewGroup
10 | import android.widget.Toast
11 |
12 | import kotlinx.android.synthetic.main.fragment_verify_password.*
13 |
14 | /**
15 | * Created by Kin on 2018/9/3
16 | */
17 | class VerifyPasswordFragment : Fragment() {
18 | private val TAG = "VerifyPasswordFragment"
19 |
20 | private var verifyCallback: ((success: Boolean) -> Unit)? = null
21 | private var hasFingerprint = false
22 | private var lockout = false
23 |
24 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
25 | return inflater.inflate(R.layout.fragment_verify_password, container, false)
26 | }
27 |
28 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
29 | verify_password_fingerprint.setOnClickListener {
30 | (activity as? MainActivity)?.switchToFingerprintFragment()
31 | }
32 | verify_password_confirm.setOnClickListener {
33 | verifyPassword(verify_password_input.text.toString())
34 | }
35 | verify_password_input.addTextChangedListener(object : TextWatcher {
36 | override fun afterTextChanged(s: Editable?) {}
37 |
38 | override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
39 |
40 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
41 | verify_password_confirm.visibility = if (s != null && s.isNotEmpty()) {
42 | View.VISIBLE
43 | } else {
44 | View.GONE
45 | }
46 | }
47 | })
48 | verify_password_cancel.setOnClickListener {
49 | verifyCallback?.invoke(false)
50 | }
51 | if (!hasFingerprint) {
52 | // 设备没有指纹识别,隐藏跳转图标
53 | verify_password_fingerprint.visibility = View.GONE
54 | verify_password_try_again.visibility = View.GONE
55 | }
56 | if (lockout) {
57 | // 失败过多被锁,不允许跳转到指纹识别
58 | verify_password_fingerprint.setOnClickListener {
59 | Toast.makeText(activity,getString(R.string.fingerprint_lockout),Toast.LENGTH_SHORT).show()
60 | }
61 | Toast.makeText(activity,getString(R.string.fingerprint_lockout),Toast.LENGTH_SHORT).show()
62 | }
63 | }
64 |
65 | fun setCallback(callback: (success: Boolean) -> Unit): VerifyPasswordFragment {
66 | verifyCallback = callback
67 | return this
68 | }
69 |
70 | fun setHasFingerprint(hasFingerprint: Boolean): VerifyPasswordFragment {
71 | this.hasFingerprint = hasFingerprint
72 | return this
73 | }
74 |
75 | fun setHasLockout(lockout: Boolean): VerifyPasswordFragment {
76 | this.lockout = lockout
77 | return this
78 | }
79 |
80 | override fun onDetach() {
81 | super.onDetach()
82 | verifyCallback = null
83 | }
84 |
85 | /**
86 | * 校验密码
87 | *
88 | * @param inputPassword 用户输入的密码
89 | */
90 | private fun verifyPassword(inputPassword: String) {
91 | try {
92 | // val loginProfile = AMESelfData.profile
93 | // loginProfile?.let {
94 | // val oldPrivateKeyString = it.privateKey
95 | // ?: throw Exception("account private key is null")
96 | // OpenIdUtils.decodePrivateKey(oldPrivateKeyString, inputPassword)
97 | // verifyCallback?.invoke(true)
98 | // return
99 | // }
100 | Toast.makeText(activity,"Go to password input",Toast.LENGTH_SHORT).show()
101 | } catch (e: Exception) {}
102 | verify_password_input.background = context?.getDrawable(R.drawable.register_input_error_bg)
103 | }
104 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/fingerprint_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/app/src/main/res/drawable-xhdpi/fingerprint_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/fingerprint_match_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/app/src/main/res/drawable-xhdpi/fingerprint_match_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/fingerprint_not_match_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/app/src/main/res/drawable-xhdpi/fingerprint_not_match_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/next_black_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/app/src/main/res/drawable-xhdpi/next_black_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_fingerprint_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/common_primary_thick_round_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 | -
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/common_primary_thin_round_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 | -
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/register_input_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/register_input_error_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_verify_fingerprint.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_fingerprint.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
30 |
31 |
42 |
43 |
55 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_verify_fingerprint.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
19 |
20 |
31 |
32 |
43 |
44 |
54 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_verify_password.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
23 |
24 |
42 |
43 |
53 |
54 |
64 |
65 |
74 |
75 |
87 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #00000000
7 | #E6182331
8 | #ffffff
9 | #ff000000
10 | #379BFF
11 | #C2C2C2
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BMPrinter
3 |
4 |
5 | Verify Fingerprint to show Account Key
6 | Use Password
7 | Enter Account Key Password
8 | Password
9 | Try again
10 | Fingerprint Not Recognised
11 | Fingerprint temporarily disabled due to too many fails attempts
12 | Scan fingerprint timeout
13 | Unknown error
14 | Canceled by user
15 | Cancel
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
17 |
18 |
25 |
26 |
31 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/bmprinter/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/bmprinter/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 |
4 | apply plugin: 'kotlin-android-extensions'
5 |
6 | android {
7 | compileSdkVersion 28
8 |
9 | defaultConfig {
10 | minSdkVersion 21
11 | targetSdkVersion 26
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | androidExtensions {
26 | experimental = true
27 | }
28 | }
29 |
30 | dependencies {
31 | implementation fileTree(dir: 'libs', include: ['*.jar'])
32 | implementation 'com.android.support:appcompat-v7:26.1.0'
33 | api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
34 | implementation files('libs/fingerprint.jar') //魅族
35 | implementation files('libs/pass-v1.2.6.jar') //三星
36 | implementation files('libs/sdk-v1.0.0.jar') //
37 | }
38 | repositories {
39 | mavenCentral()
40 | }
41 |
--------------------------------------------------------------------------------
/bmprinter/libs/fingerprint.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/bmprinter/libs/fingerprint.jar
--------------------------------------------------------------------------------
/bmprinter/libs/pass-v1.2.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/bmprinter/libs/pass-v1.2.6.jar
--------------------------------------------------------------------------------
/bmprinter/libs/sdk-v1.0.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/bmprinter/libs/sdk-v1.0.0.jar
--------------------------------------------------------------------------------
/bmprinter/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/bmprinter/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/bmprinter/src/main/java/com/bcm/bmprinter/fingerprint/AospFingerprintHelper.kt:
--------------------------------------------------------------------------------
1 | package com.bcm.bmprinter.fingerprint
2 |
3 | import android.annotation.SuppressLint
4 | import android.app.KeyguardManager
5 | import android.content.Context
6 | import android.hardware.biometrics.BiometricPrompt
7 | import android.hardware.fingerprint.FingerprintManager
8 | import android.os.Build
9 | import android.os.CancellationSignal
10 | import android.security.keystore.KeyGenParameterSpec
11 | import android.security.keystore.KeyProperties
12 | import android.util.Log
13 | import java.security.KeyStore
14 | import javax.crypto.Cipher
15 | import javax.crypto.KeyGenerator
16 |
17 | /**
18 | * AOSP基础指纹模块,用于Android Marshmallow+进行指纹识别
19 | * https://www.cnblogs.com/popfisher/p/6063835.html 接口详细分析和说明
20 | * @param context Application的引用
21 | *
22 | * Created by cangwang & Kin in 2018/8/31
23 | **/
24 | @SuppressLint("NewApi")
25 | class AospFingerprintHelper(context: Context) {
26 | private val TAG = this::class.java.simpleName
27 | private val KEY_STORE_PROVIDER = "AndroidKeyStore"
28 | private val KEY_STORE_ALIAS = "com.bcm.messenger.fingerprint"
29 | private val biometricPrompt = BiometricPrompt.Builder(context).setTitle("BiometricPrompt").build()
30 | private val fingerprintManager = context.getSystemService(Context.FINGERPRINT_SERVICE) as FingerprintManager
31 | private val keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
32 | private lateinit var cipher: Cipher
33 | private var cancelSignal: CancellationSignal? = null
34 |
35 | init {
36 | //初始化对指纹的加密访问
37 | initKeyAndCipher()
38 | }
39 |
40 | fun isHardwareDetected() = fingerprintManager.isHardwareDetected
41 |
42 | /**
43 | * 是否录入指纹,有些设备上即使录入了指纹,但是没有开启锁屏密码的话此方法还是返回false
44 | */
45 | fun hasEnrolledFingerprints():Boolean {
46 | try {
47 | // 有些厂商api23之前的版本可能没有做好兼容,这个方法内部会崩溃(redmi note2, redmi note3等)
48 | return fingerprintManager.hasEnrolledFingerprints()
49 | }catch (e:SecurityException){
50 |
51 | }catch (e:Throwable){
52 |
53 | }
54 | return false
55 | }
56 |
57 | fun isKeyguardSecure() = keyguardManager.isKeyguardSecure
58 |
59 | fun startAuthenticate(authenticateResult: (success: Boolean, errCode: Int, errMsg: String?) -> Unit) {
60 | cancelSignal = CancellationSignal()
61 | // flags为1是因为设置小米屏下指纹的图标颜色,原生API属于保留字段,未被使用
62 | try {
63 | if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.P){
64 | biometricPrompt.authenticate(BiometricPrompt.CryptoObject(cipher), cancelSignal, null,callbackV28(authenticateResult))
65 | }else {
66 | fingerprintManager.authenticate(FingerprintManager.CryptoObject(cipher), cancelSignal, 1, callback(authenticateResult), null)
67 | }
68 | }catch (e:SecurityException){ //失败重试机制
69 | try {
70 | if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.P){
71 | biometricPrompt.authenticate(null, cancelSignal, null, callbackV28(authenticateResult))
72 | }else {
73 | fingerprintManager.authenticate(null, cancelSignal, 1, callback(authenticateResult), null)
74 | }
75 | }catch (e2:SecurityException){
76 | authenticateResult(false, AUTHENTICATE_FAILED_NOT_MATCH, null)
77 | }
78 | }
79 | }
80 |
81 | @Suppress("DEPRECATION")
82 | fun callback(authenticateResult: (success: Boolean, errCode: Int, errMsg: String?) -> Unit):FingerprintManager.AuthenticationCallback{
83 | return object : FingerprintManager.AuthenticationCallback() {
84 | override fun onAuthenticationError(errorCode: Int, errString: CharSequence?) {
85 | Log.d(TAG, "AOSP authentication error, error code: $errorCode, error msg: $errString")
86 | val resultCode = when (errorCode) {
87 | FingerprintManager.FINGERPRINT_ERROR_LOCKOUT -> AUTHENTICATE_FAILED_LOCKOUT //被锁了
88 | FingerprintManager.FINGERPRINT_ERROR_CANCELED -> AUTHENTICATE_FAILED_CANCELED //取消
89 | FingerprintManager.FINGERPRINT_ERROR_TIMEOUT -> AUTHENTICATE_FAILED_TIMEOUT // 指纹读取超时
90 | FingerprintManager.FINGERPRINT_ACQUIRED_INSUFFICIENT -> AUTHENTICATE_FAILED_DIRTY //指纹扫描脏了
91 | FingerprintManager.FINGERPRINT_ACQUIRED_PARTIAL -> AUTHENTICATE_FAILED_ACQUIRED_PARTIAL //手指上的指纹只读取到部分
92 | else -> AUTHENTICATE_FAILED_UNKNOWN
93 | }
94 | authenticateResult(false, resultCode, errString?.toString())
95 | }
96 |
97 | override fun onAuthenticationSucceeded(result: FingerprintManager.AuthenticationResult?) {
98 | Log.d(TAG, "AOSP authentication success")
99 | authenticateResult(true, AUTHENTICATE_SUCCESS, null)
100 | }
101 |
102 | override fun onAuthenticationFailed() {
103 | Log.d(TAG, "AOSP authentication failed, not match")
104 | authenticateResult(false, AUTHENTICATE_FAILED_NOT_MATCH, null)
105 | }
106 | }
107 | }
108 |
109 | private fun callbackV28(authenticateResult: (success: Boolean, errCode: Int, errMsg: String?) -> Unit):BiometricPrompt.AuthenticationCallback{
110 | return object : BiometricPrompt.AuthenticationCallback() {
111 | override fun onAuthenticationError(errorCode: Int, errString: CharSequence?) {
112 | Log.d(TAG, "AOSP authentication error, error code: $errorCode, error msg: $errString")
113 | val resultCode = when (errorCode) {
114 | BiometricPrompt.BIOMETRIC_ERROR_LOCKOUT -> AUTHENTICATE_FAILED_LOCKOUT
115 | BiometricPrompt.BIOMETRIC_ERROR_CANCELED -> AUTHENTICATE_FAILED_CANCELED
116 | BiometricPrompt.BIOMETRIC_ERROR_TIMEOUT -> AUTHENTICATE_FAILED_TIMEOUT
117 | BiometricPrompt.BIOMETRIC_ACQUIRED_INSUFFICIENT -> AUTHENTICATE_FAILED_DIRTY
118 | BiometricPrompt.BIOMETRIC_ACQUIRED_PARTIAL -> AUTHENTICATE_FAILED_ACQUIRED_PARTIAL
119 | else -> AUTHENTICATE_FAILED_UNKNOWN
120 | }
121 | authenticateResult(false, resultCode, errString?.toString())
122 | }
123 |
124 | override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult?) {
125 | Log.d(TAG, "AOSP authentication success")
126 | authenticateResult(true, AUTHENTICATE_SUCCESS, null)
127 | }
128 |
129 | override fun onAuthenticationFailed() {
130 | Log.d(TAG, "AOSP authentication failed, not match")
131 | authenticateResult(false, AUTHENTICATE_FAILED_NOT_MATCH, null)
132 | }
133 | }
134 | }
135 |
136 | fun stopAuthenticate() {
137 | if (cancelSignal?.isCanceled == false) {
138 | cancelSignal?.cancel()
139 | cancelSignal = null
140 | }
141 | }
142 |
143 | private fun initKeyAndCipher() {
144 | try {
145 | val keyStore = KeyStore.getInstance(KEY_STORE_PROVIDER)
146 | val keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, KEY_STORE_PROVIDER)
147 | keyStore.load(null)
148 | val builder = KeyGenParameterSpec.Builder(KEY_STORE_ALIAS, KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
149 | .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
150 | .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
151 | .setUserAuthenticationRequired(true)
152 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
153 | builder.setInvalidatedByBiometricEnrollment(true)
154 | }
155 | keyGenerator.init(builder.build())
156 | val key = keyGenerator.generateKey()
157 | cipher = Cipher.getInstance("${KeyProperties.KEY_ALGORITHM_AES}/${KeyProperties.BLOCK_MODE_CBC}/${KeyProperties.ENCRYPTION_PADDING_PKCS7}")
158 | cipher.init(Cipher.ENCRYPT_MODE, key)
159 | Log.d(TAG, "Generate key success")
160 | } catch (e: Exception) {
161 | e.printStackTrace()
162 | Log.d(TAG, "Generate key failed")
163 | }
164 | }
165 | }
--------------------------------------------------------------------------------
/bmprinter/src/main/java/com/bcm/bmprinter/fingerprint/BiometricPromptHelper.kt:
--------------------------------------------------------------------------------
1 | package com.bcm.bmprinter.fingerprint
2 |
3 | import android.annotation.SuppressLint
4 | import android.app.KeyguardManager
5 | import android.content.Context
6 | import android.hardware.biometrics.BiometricPrompt
7 | import android.hardware.fingerprint.FingerprintManager
8 | import android.os.Build
9 | import android.os.CancellationSignal
10 | import android.security.keystore.KeyGenParameterSpec
11 | import android.security.keystore.KeyProperties
12 | import android.util.Log
13 | import java.security.KeyStore
14 | import javax.crypto.Cipher
15 | import javax.crypto.KeyGenerator
16 |
17 | /**
18 | * sdk>28 后使用BiometricPrompt识别(等Android P 发出再适配)
19 | * https://developer.android.google.cn/reference/android/hardware/biometrics/BiometricPrompt#public-methods
20 | * Created by cangwang & kin on 2018/9/6.
21 | */
22 | @SuppressLint("NewApi")
23 | class BiometricPromptHelper(context: Context){
24 | private val TAG = this::class.java.simpleName
25 | val biometricPrompt = BiometricPrompt.Builder(context).setTitle("BiometricPrompt").build()
26 | private val fingerprintManager = context.getSystemService(Context.FINGERPRINT_SERVICE) as FingerprintManager
27 | private val keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
28 | private val KEY_STORE_PROVIDER = "AndroidKeyStore"
29 | private val KEY_STORE_ALIAS = "com.bcm.messenger.fingerprint"
30 | private lateinit var cipher: Cipher
31 | private var cancelSignal: CancellationSignal? = null
32 |
33 | init {
34 | initKeyAndCipher()
35 | }
36 |
37 | fun isHardwareDetected() = fingerprintManager.isHardwareDetected
38 |
39 | /**
40 | * 是否录入指纹,有些设备上即使录入了指纹,但是没有开启锁屏密码的话此方法还是返回false
41 | */
42 | fun hasEnrolledFingerprints():Boolean {
43 | try {
44 | // 有些厂商api23之前的版本可能没有做好兼容,这个方法内部会崩溃(redmi note2, redmi note3等)
45 | return fingerprintManager.hasEnrolledFingerprints()
46 | }catch (e:SecurityException){
47 |
48 | }catch (e:Throwable){
49 |
50 | }
51 | return false
52 | }
53 |
54 | fun isKeyguardSecure() = keyguardManager.isKeyguardSecure
55 |
56 | fun startAuthenticate(authenticateResult: (success: Boolean, errCode: Int, errMsg: String?) -> Unit) {
57 | cancelSignal = CancellationSignal()
58 | // flags为1是因为设置小米屏下指纹的图标颜色,原生API属于保留字段,未被使用
59 | try {
60 | biometricPrompt.authenticate(BiometricPrompt.CryptoObject(cipher), cancelSignal, null,callback(authenticateResult))
61 | }catch (e:SecurityException){ //失败重试机制
62 | try {
63 | biometricPrompt.authenticate(null, cancelSignal, null, callback(authenticateResult))
64 | }catch (e2:SecurityException){
65 | authenticateResult(false, AUTHENTICATE_FAILED_NOT_MATCH, null)
66 | }
67 | }
68 | }
69 |
70 | private fun callback(authenticateResult: (success: Boolean, errCode: Int, errMsg: String?) -> Unit):BiometricPrompt.AuthenticationCallback{
71 | return object : BiometricPrompt.AuthenticationCallback() {
72 | override fun onAuthenticationError(errorCode: Int, errString: CharSequence?) {
73 | Log.d(TAG, "AOSP authentication error, error code: $errorCode, error msg: $errString")
74 | val resultCode = when (errorCode) {
75 | BiometricPrompt.BIOMETRIC_ERROR_LOCKOUT -> AUTHENTICATE_FAILED_LOCKOUT
76 | BiometricPrompt.BIOMETRIC_ERROR_CANCELED -> AUTHENTICATE_FAILED_CANCELED
77 | BiometricPrompt.BIOMETRIC_ERROR_TIMEOUT -> AUTHENTICATE_FAILED_TIMEOUT
78 | BiometricPrompt.BIOMETRIC_ACQUIRED_INSUFFICIENT -> AUTHENTICATE_FAILED_DIRTY
79 | BiometricPrompt.BIOMETRIC_ACQUIRED_PARTIAL -> AUTHENTICATE_FAILED_ACQUIRED_PARTIAL
80 | else -> AUTHENTICATE_FAILED_UNKNOWN
81 | }
82 | authenticateResult(false, resultCode, errString?.toString())
83 | }
84 |
85 | override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult?) {
86 | Log.d(TAG, "AOSP authentication success")
87 | authenticateResult(true, AUTHENTICATE_SUCCESS, null)
88 | }
89 |
90 | override fun onAuthenticationFailed() {
91 | Log.d(TAG, "AOSP authentication failed, not match")
92 | authenticateResult(false, AUTHENTICATE_FAILED_NOT_MATCH, null)
93 | }
94 | }
95 | }
96 |
97 | fun stopAuthenticate() {
98 | if (cancelSignal?.isCanceled == false) {
99 | cancelSignal?.cancel()
100 | cancelSignal = null
101 | }
102 | }
103 |
104 | private fun initKeyAndCipher() {
105 | try {
106 | val keyStore = KeyStore.getInstance(KEY_STORE_PROVIDER)
107 | val keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, KEY_STORE_PROVIDER)
108 | keyStore.load(null)
109 | val builder = KeyGenParameterSpec.Builder(KEY_STORE_ALIAS, KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
110 | .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
111 | .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
112 | .setUserAuthenticationRequired(true)
113 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
114 | builder.setInvalidatedByBiometricEnrollment(true)
115 | }
116 | keyGenerator.init(builder.build())
117 | val key = keyGenerator.generateKey()
118 | cipher = Cipher.getInstance("${KeyProperties.KEY_ALGORITHM_AES}/${KeyProperties.BLOCK_MODE_CBC}/${KeyProperties.ENCRYPTION_PADDING_PKCS7}")
119 | cipher.init(Cipher.ENCRYPT_MODE, key)
120 | Log.d(TAG, "Generate key success")
121 | } catch (e: Exception) {
122 | e.printStackTrace()
123 | Log.d(TAG, "Generate key failed")
124 | }
125 | }
126 | }
--------------------------------------------------------------------------------
/bmprinter/src/main/java/com/bcm/bmprinter/fingerprint/FingerprintFactory.kt:
--------------------------------------------------------------------------------
1 | package com.bcm.bmprinter.fingerprint
2 |
3 | import android.content.Context
4 | import android.os.Build
5 | import com.bcm.bmprinter.fingerprint.brandfingerprintutils.*
6 |
7 | /**
8 | * 获取指纹识别接口静态方法
9 | * Java调用函数的方法:FingerprintFactoryKt.MethodName(context)
10 | * Java调用常量的方法:FingerprintFactoryKt.ConstantsName
11 | * Kotlin调用函数的方法:直接访问函数名
12 | * Kotlin调用厂常量的方法:直接访问常量名
13 | *
14 | * Created by cangwang & Kin on 2018/8/31
15 | */
16 | const val AUTHENTICATE_SUCCESS = 0 // 成功
17 | const val AUTHENTICATE_FAILED_NOT_MATCH = 1 // 不匹配
18 | const val AUTHENTICATE_FAILED_CANCELED = 2 // 取消识别
19 | const val AUTHENTICATE_FAILED_DIRTY = 3 // 传感器或手指太脏导致识别失败
20 | const val AUTHENTICATE_FAILED_LOCKOUT = 4 // 尝试次数过多,暂时封锁
21 | const val AUTHENTICATE_FAILED_TIMEOUT = 5 // 超时未识别
22 | const val AUTHENTICATE_FAILED_ACQUIRED_PARTIAL = 6 // 只识别到一部分
23 | const val AUTHENTICATE_FAILED_UNKNOWN = 7 // 其他错误
24 |
25 | /**
26 | * 创建构造器
27 | */
28 | fun createFingerprintUtil(context: Context):IFingerprintUtil {
29 | return when (Build.MANUFACTURER) { //判断厂商
30 | "Meizu" -> createMeizuFingerprintUtil(context) //魅族
31 | "vivo" -> createVivoFingerprintUtil(context) //vivo oppo
32 | "Xiaomi", "xiaomi" -> createMiFingerprintUtil(context) //小米
33 | "Samsung", "samsung" -> createSamsuntFingerprintUtil(context) //三星
34 | else -> AospFingerprintUtil.getInstance(context)
35 | }
36 | }
37 |
38 | private fun createMeizuFingerprintUtil(context: Context): IFingerprintUtil {
39 | return MeizuFingerprintUtil.getInstance(context)
40 | }
41 |
42 | private fun createVivoFingerprintUtil(context: Context): IFingerprintUtil {
43 | return VivoFingerprintUtil.getInstance(context)
44 | }
45 |
46 | private fun createMiFingerprintUtil(context: Context): IFingerprintUtil {
47 | return MiFingerprintUtil.getInstance(context)
48 | }
49 |
50 | private fun createSamsuntFingerprintUtil(context: Context): IFingerprintUtil {
51 | return SamsungFingerprintUtil.getInstance(context)
52 | }
--------------------------------------------------------------------------------
/bmprinter/src/main/java/com/bcm/bmprinter/fingerprint/IFingerprintUtil.kt:
--------------------------------------------------------------------------------
1 | package com.bcm.bmprinter.fingerprint
2 |
3 | /**
4 | * Created cangwang & Kin on 2018/8/31
5 | */
6 | interface IFingerprintUtil {
7 | /**
8 | * Check if device has fingerprint sensor
9 | * 是有拥有指纹识别功能
10 | */
11 | fun canUseFingerprint(): Boolean
12 |
13 | /**
14 | * Check if device has lock screen password
15 | * 是否存在屏幕密码
16 | */
17 | fun isDeviceSecure(): Boolean
18 |
19 | /**
20 | * Check if device has enrolled fingerprints
21 | * 是否已经录制过指纹
22 | */
23 | fun hasEnrolledFingerprints(): Boolean
24 |
25 | /**
26 | * Clean data
27 | * 清理验证数据
28 | */
29 | fun destroy()
30 |
31 | /**
32 | * Start to authenticate fingerprints
33 | * 开始识别指纹
34 | */
35 | fun authenticate(authenticateResult: (success: Boolean, errCode: Int, errMsg: String?) -> Unit)
36 |
37 | /**
38 | * Cancel authenticate fingerprints
39 | * 取消识别指纹
40 | */
41 | fun cancelAuthenticate()
42 |
43 | /**
44 | * Get fingerprint position, enable in under display fingerprint devices, return an IntArray(left, top, right, bottom).
45 | * In normal devices will return empty array.
46 | * 是否屏幕指纹识别位置
47 | */
48 | fun getUnderDisplayFingerprintPosition(): IntArray
49 | }
--------------------------------------------------------------------------------
/bmprinter/src/main/java/com/bcm/bmprinter/fingerprint/brandfingerprintutils/AospFingerprintUtil.kt:
--------------------------------------------------------------------------------
1 | package com.bcm.bmprinter.fingerprint.brandfingerprintutils
2 |
3 | import android.content.Context
4 | import android.os.Build
5 | import android.util.Log
6 | import com.bcm.bmprinter.fingerprint.AospFingerprintHelper
7 | import com.bcm.bmprinter.fingerprint.IFingerprintUtil
8 |
9 | /**
10 | * AOSP指纹识别模块,Android Marshmallow+
11 | *
12 | * Created by cangwang & Kin on 2018/9/3
13 | */
14 | class AospFingerprintUtil private constructor(context: Context) : IFingerprintUtil {
15 | companion object {
16 | private var instance: AospFingerprintUtil? = null
17 |
18 | fun getInstance(context: Context): AospFingerprintUtil {
19 | if (instance == null) {
20 | instance = AospFingerprintUtil(context)
21 | }
22 | Log.d(instance?.TAG, "Return AOSP fingerprint util.")
23 | return instance!!
24 | }
25 | }
26 |
27 | private val TAG = "AospFingerprintUtil"
28 |
29 | private lateinit var aospFingerprintHelper: AospFingerprintHelper
30 |
31 | init {
32 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
33 | aospFingerprintHelper = AospFingerprintHelper(context)
34 | }
35 | }
36 |
37 | override fun canUseFingerprint(): Boolean {
38 | return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
39 | aospFingerprintHelper.isHardwareDetected()
40 | } else false
41 | }
42 |
43 | override fun isDeviceSecure(): Boolean {
44 | return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
45 | aospFingerprintHelper.isKeyguardSecure()
46 | } else false
47 | }
48 |
49 | override fun hasEnrolledFingerprints(): Boolean {
50 | return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
51 | aospFingerprintHelper.hasEnrolledFingerprints()
52 | } else false
53 | }
54 |
55 | override fun destroy() {
56 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
57 | aospFingerprintHelper.stopAuthenticate()
58 | }
59 | }
60 |
61 | override fun authenticate(authenticateResult: (success: Boolean, errCode: Int, errMsg: String?) -> Unit) {
62 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
63 | aospFingerprintHelper.startAuthenticate(authenticateResult)
64 | }
65 | }
66 |
67 | override fun cancelAuthenticate() {
68 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
69 | aospFingerprintHelper.stopAuthenticate()
70 | }
71 | }
72 |
73 | override fun getUnderDisplayFingerprintPosition() = intArrayOf()
74 | }
--------------------------------------------------------------------------------
/bmprinter/src/main/java/com/bcm/bmprinter/fingerprint/brandfingerprintutils/MeizuFingerprintUtil.kt:
--------------------------------------------------------------------------------
1 | package com.bcm.bmprinter.fingerprint.brandfingerprintutils
2 |
3 | import android.content.Context
4 |
5 | import android.os.Build
6 | import android.util.Log
7 | import com.bcm.bmprinter.fingerprint.AUTHENTICATE_FAILED_NOT_MATCH
8 | import com.bcm.bmprinter.fingerprint.AUTHENTICATE_SUCCESS
9 | import com.bcm.bmprinter.fingerprint.AospFingerprintHelper
10 | import com.bcm.bmprinter.fingerprint.IFingerprintUtil
11 | import com.fingerprints.service.FingerprintManager
12 |
13 | /**
14 | * Meizu指纹识别模块,Android M+依赖于AOSP,Android L通过魅族SDK进行支持
15 | * http://open-wiki.flyme.cn/index.php?title=指纹识别API sdk文档地址
16 | * Created by cangwang & Kin on 2018/8/31
17 | */
18 | class MeizuFingerprintUtil private constructor(context: Context) : IFingerprintUtil {
19 | companion object {
20 | private var instance: MeizuFingerprintUtil? = null
21 |
22 | fun getInstance(context: Context): MeizuFingerprintUtil {
23 | if (instance == null) {
24 | instance = MeizuFingerprintUtil(context)
25 | }
26 | instance?.initManager()
27 | Log.d(instance?.TAG, "Return Meizu fingerprint util.")
28 | return instance!!
29 | }
30 | }
31 |
32 | private val TAG = "MeizuFingerprintUtil"
33 |
34 | private var mManager: FingerprintManager? = null
35 | private lateinit var aospFingerprintHelper: AospFingerprintHelper
36 | private var released = true
37 |
38 | init {
39 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { //6.0或以上使用
40 | aospFingerprintHelper = AospFingerprintHelper(context)
41 | } else { //5.0一下使用
42 | initManager()
43 | }
44 | }
45 |
46 | fun initManager() {
47 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
48 | mManager = FingerprintManager.open()
49 | released = false
50 | }
51 | }
52 |
53 | private fun releaseManager() {
54 | mManager?.release()
55 | released = true
56 | }
57 |
58 | override fun canUseFingerprint(): Boolean {
59 | return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
60 | aospFingerprintHelper.isHardwareDetected()
61 | } else {
62 | mManager != null && mManager?.ids != null
63 | }
64 | }
65 |
66 | override fun isDeviceSecure(): Boolean {
67 | return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
68 | aospFingerprintHelper.isKeyguardSecure()
69 | } else {
70 | true
71 | }
72 | }
73 |
74 | override fun hasEnrolledFingerprints(): Boolean {
75 | return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
76 | aospFingerprintHelper.hasEnrolledFingerprints()
77 | } else {
78 | mManager?.ids != null
79 | }
80 | }
81 |
82 | override fun destroy() {
83 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
84 | aospFingerprintHelper.stopAuthenticate()
85 | } else {
86 | mManager?.abort()
87 | releaseManager()
88 | }
89 | }
90 |
91 | override fun authenticate(authenticateResult: (success: Boolean, errCode: Int, errMsg: String?) -> Unit) {
92 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
93 | aospFingerprintHelper.startAuthenticate(authenticateResult)
94 | } else {
95 | if (released) {
96 | initManager()
97 | }
98 | mManager?.startIdentify(object : FingerprintManager.IdentifyCallback {
99 | override fun onNoMatch() {
100 | authenticateResult(false, AUTHENTICATE_FAILED_NOT_MATCH, null)
101 | releaseManager()
102 | }
103 |
104 | override fun onIdentified(p0: Int, p1: Boolean) {
105 | authenticateResult(true, AUTHENTICATE_SUCCESS, null)
106 | releaseManager()
107 | }
108 | }, mManager?.ids)
109 | }
110 | }
111 |
112 | override fun cancelAuthenticate() {
113 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
114 | aospFingerprintHelper.stopAuthenticate()
115 | } else {
116 | mManager?.abort()
117 | releaseManager()
118 | }
119 | }
120 |
121 | override fun getUnderDisplayFingerprintPosition() = intArrayOf()
122 | }
--------------------------------------------------------------------------------
/bmprinter/src/main/java/com/bcm/bmprinter/fingerprint/brandfingerprintutils/MiFingerprintUtil.kt:
--------------------------------------------------------------------------------
1 | package com.bcm.bmprinter.fingerprint.brandfingerprintutils
2 |
3 | import android.content.Context
4 | import android.util.Log
5 | import com.bcm.bmprinter.fingerprint.AospFingerprintHelper
6 | import com.bcm.bmprinter.fingerprint.IFingerprintUtil
7 |
8 | /**
9 | * Xiaomi指纹识别模块,依赖于AOSP,支持返回屏下指纹位置,单位px
10 | *
11 | * Created by cangwang & Kin on 2018/8/31
12 | */
13 | class MiFingerprintUtil private constructor(context: Context) : IFingerprintUtil {
14 | companion object {
15 | private var instance: MiFingerprintUtil? = null
16 |
17 | fun getInstance(context: Context): MiFingerprintUtil {
18 | if (instance == null) {
19 | instance = MiFingerprintUtil(context)
20 | }
21 | Log.d(instance?.TAG, "Return Mi fingerprint util.")
22 | return instance!!
23 | }
24 | }
25 |
26 | private val TAG = "MiFingerprintUtil"
27 | private val fingerprintPosition = intArrayOf(-1, -1, -1, -1)
28 | private var hasUnderDisplayFingerprint = false
29 | private val aospFingerprintUtil = AospFingerprintHelper(context)
30 |
31 | init {
32 | try {
33 | //反射判断是否拥有使用屏下指纹识别
34 | val clazz = Class.forName("android.os.SystemProperties")
35 | val method = clazz.getDeclaredMethod("get", String::class.java)
36 | val value = method.invoke(clazz, "ro.hardware.fp.fod") as String
37 | if (value == "true") {
38 | hasUnderDisplayFingerprint = true
39 | val xy = method.invoke(clazz, "ro.hardware.persist.sys.fp.fod.location.X_Y") as String
40 | val wh = method.invoke(clazz, "persist.sys.fp.fod.size.width_height") as String
41 | val xyArray = xy.split(",")
42 | val whArray = wh.split(",")
43 | //设置指纹位置
44 | fingerprintPosition[0] = xyArray[0].toInt()
45 | fingerprintPosition[1] = xyArray[1].toInt()
46 | fingerprintPosition[2] = xyArray[0].toInt() + whArray[0].toInt()
47 | fingerprintPosition[3] = xyArray[1].toInt() + whArray[1].toInt()
48 | }
49 | } catch (e: Exception) {
50 | e.printStackTrace()
51 | }
52 | }
53 |
54 | override fun canUseFingerprint() = aospFingerprintUtil.isHardwareDetected()
55 |
56 | override fun isDeviceSecure() = aospFingerprintUtil.isKeyguardSecure()
57 |
58 | override fun hasEnrolledFingerprints() = aospFingerprintUtil.hasEnrolledFingerprints()
59 |
60 | override fun destroy() {
61 | aospFingerprintUtil.stopAuthenticate()
62 | }
63 |
64 | override fun authenticate(authenticateResult: (success: Boolean, errCode: Int, errMsg: String?) -> Unit) {
65 | aospFingerprintUtil.startAuthenticate(authenticateResult)
66 | }
67 |
68 | override fun cancelAuthenticate() {
69 | aospFingerprintUtil.stopAuthenticate()
70 | }
71 |
72 | override fun getUnderDisplayFingerprintPosition(): IntArray {
73 | if (hasUnderDisplayFingerprint) {
74 | return fingerprintPosition
75 | }
76 | return intArrayOf()
77 | }
78 | }
--------------------------------------------------------------------------------
/bmprinter/src/main/java/com/bcm/bmprinter/fingerprint/brandfingerprintutils/SamsungFingerprintUtil.kt:
--------------------------------------------------------------------------------
1 | package com.bcm.bmprinter.fingerprint.brandfingerprintutils
2 |
3 | import android.content.Context
4 | import android.os.Build
5 | import android.util.Log
6 | import com.bcm.bmprinter.fingerprint.*
7 | import com.samsung.android.sdk.pass.Spass
8 | import com.samsung.android.sdk.pass.SpassFingerprint
9 |
10 | /**
11 | * Samsung指纹识别模块,Android M+依赖于AOSP,Android 4.2-5.1通过三星SDK进行支持
12 | * https://developer.samsung.com/galaxy/pass sdk文档下载
13 | * Created cangwang & by Kin on 2018/9/3
14 | */
15 | class SamsungFingerprintUtil private constructor(context: Context) : IFingerprintUtil {
16 | companion object {
17 | private var instance: SamsungFingerprintUtil? = null
18 |
19 | fun getInstance(context: Context): SamsungFingerprintUtil {
20 | if (instance == null) {
21 | instance = SamsungFingerprintUtil(context)
22 | }
23 | Log.d(instance?.TAG, "Return Samsung fingerprint util.")
24 | return instance!!
25 | }
26 | }
27 |
28 | private val TAG = "SamsungFingerprintUtil"
29 |
30 | private lateinit var mPass: Spass
31 | private lateinit var sPassFingerprint: SpassFingerprint
32 | private lateinit var aospFingerprintHelper: AospFingerprintHelper
33 | private var passInitialized = false
34 |
35 | init {
36 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
37 | aospFingerprintHelper = AospFingerprintHelper(context)
38 | } else {
39 | mPass = Spass()
40 | try {
41 | mPass.initialize(context)
42 | if (mPass.isFeatureEnabled(Spass.DEVICE_FINGERPRINT)) {
43 | sPassFingerprint = SpassFingerprint(context)
44 | }
45 | } catch (e: Exception) {
46 | e.printStackTrace()
47 | }
48 | }
49 | }
50 |
51 | override fun canUseFingerprint(): Boolean {
52 | return when {
53 | Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ->aospFingerprintHelper.isHardwareDetected()
54 | passInitialized -> mPass.isFeatureEnabled(Spass.DEVICE_FINGERPRINT)
55 | else -> false
56 | }
57 | }
58 |
59 | override fun isDeviceSecure(): Boolean {
60 | return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
61 | aospFingerprintHelper.isKeyguardSecure()
62 | } else {
63 | true
64 | }
65 | }
66 |
67 | override fun hasEnrolledFingerprints(): Boolean {
68 | return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
69 | aospFingerprintHelper.hasEnrolledFingerprints()
70 | } else {
71 | sPassFingerprint.hasRegisteredFinger()
72 | }
73 | }
74 |
75 | override fun destroy() {
76 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
77 | aospFingerprintHelper.stopAuthenticate()
78 | } else {
79 | sPassFingerprint.cancelIdentify()
80 | }
81 | }
82 |
83 | override fun authenticate(authenticateResult: (success: Boolean, errCode: Int, errMsg: String?) -> Unit) {
84 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
85 | aospFingerprintHelper.startAuthenticate(authenticateResult)
86 | } else {
87 | sPassFingerprint.startIdentify(object : SpassFingerprint.IdentifyListener {
88 | override fun onFinished(p0: Int) {
89 | when (p0) {
90 | SpassFingerprint.STATUS_AUTHENTIFICATION_SUCCESS, SpassFingerprint.STATUS_AUTHENTIFICATION_PASSWORD_SUCCESS -> { //识别成功或密码成功
91 | authenticateResult(true, AUTHENTICATE_SUCCESS, null)
92 | }
93 | SpassFingerprint.STATUS_USER_CANCELLED, SpassFingerprint.STATUS_USER_CANCELLED_BY_TOUCH_OUTSIDE -> { //取消识别
94 | authenticateResult(false, AUTHENTICATE_FAILED_CANCELED, null)
95 | }
96 | SpassFingerprint.STATUS_TIMEOUT_FAILED -> { //识别超时
97 | authenticateResult(false, AUTHENTICATE_FAILED_TIMEOUT, null)
98 | }
99 | else -> { //其他未知返回
100 | authenticateResult(false, AUTHENTICATE_FAILED_UNKNOWN, null)
101 | }
102 | }
103 | }
104 |
105 | override fun onReady() {}
106 |
107 | override fun onStarted() {}
108 |
109 | override fun onCompleted() {}
110 | })
111 | }
112 | }
113 |
114 | override fun cancelAuthenticate() {
115 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
116 | aospFingerprintHelper.stopAuthenticate()
117 | } else {
118 | sPassFingerprint.cancelIdentify()
119 | }
120 | }
121 |
122 | override fun getUnderDisplayFingerprintPosition() = intArrayOf()
123 | }
--------------------------------------------------------------------------------
/bmprinter/src/main/java/com/bcm/bmprinter/fingerprint/brandfingerprintutils/VivoFingerprintInsets.kt:
--------------------------------------------------------------------------------
1 | package com.bcm.bmprinter.fingerprint.brandfingerprintutils
2 |
3 | import android.content.ComponentName
4 | import android.content.Context
5 | import android.content.Intent
6 | import android.content.ServiceConnection
7 | import android.graphics.Rect
8 | import android.os.Build
9 | import android.os.Bundle
10 | import android.os.Handler
11 | import android.os.IBinder
12 | import android.os.Message
13 | import android.os.Messenger
14 | import android.os.RemoteException
15 | import android.support.v4.util.ArrayMap
16 | import android.text.TextUtils
17 | import android.util.JsonReader
18 | import android.util.Log
19 |
20 | import java.io.IOException
21 | import java.io.StringReader
22 | import java.lang.ref.WeakReference
23 | import java.util.Locale
24 |
25 | /**
26 | * Created by vivo fingerprint team on 2018/3/20.
27 | * Utils to get fingerprint information such as icon position when
28 | * under display fingerprint valid.
29 | */
30 | class VivoFingerprintInsets private constructor(context: Context) {
31 |
32 | /** Flag indicating whether we have called bind on the service. */
33 | private var mIsBound: Boolean = false
34 |
35 | private val mProperties: MutableMap> = ArrayMap(8)
36 |
37 | private var mListener: FingerprintInsetsListener? = null
38 |
39 | /** Messenger for communicating with service. */
40 | private var mService: Messenger? = null
41 |
42 | private val mHandler: Handler = IncomingHandler(this)
43 |
44 | /**
45 | * Target we publish for clients to send messages to IncomingHandler.
46 | */
47 | private val mMessenger: Messenger = Messenger(mHandler)
48 |
49 | private val mContextRef: WeakReference = WeakReference(context)
50 |
51 | val isReady: Boolean = !mIsBound || mProperties.isEmpty()
52 |
53 | val fingerprintIconState: Int = getPropertyInteger(KEY_ICON_STATE)
54 |
55 | val fingerprintIconPosition: Rect = getPropertyRect(KEY_ICON_POSITION) ?: Rect(-1, -1, -1, -1)
56 |
57 | val fingerprintIconLeft: Int = getPropertyRect(KEY_ICON_POSITION)?.left ?: -1
58 |
59 | val fingerprintIconTop: Int = getPropertyRect(KEY_ICON_POSITION)?.top ?: -1
60 |
61 | val fingerprintIconRight: Int = getPropertyRect(KEY_ICON_POSITION)?.right ?: -1
62 |
63 | val fingerprintIconBottom: Int = getPropertyRect(KEY_ICON_POSITION)?.bottom ?: -1
64 |
65 | /**
66 | * Class for interacting with the main interface of the service.
67 | */
68 | private val mConnection = object : ServiceConnection {
69 | override fun onServiceConnected(className: ComponentName, service: IBinder) {
70 | // This is called when the connection with the service has been
71 | // established, giving us the service object we can use to
72 | // interact with the service. We are communicating with our
73 | // service through an IDL interface, so get a client-side
74 | // representation of that from the raw service object.
75 | mService = Messenger(service)
76 | Log.d(TAG, "Attached.")
77 |
78 | // We want to monitor the service for as long as we are
79 | // connected to it.
80 | try {
81 | val msg = Message.obtain(null, MSG_QUERY_INFO)
82 | msg.arg1 = VERSION_MAJOR
83 | msg.arg2 = VERSION_MINOR
84 |
85 | val context = mContextRef.get()
86 | if (context != null) {
87 | val extras = Bundle()
88 | extras.putString(KEY_TOKEN, context.packageName)
89 | msg.data = extras
90 | }
91 |
92 | msg.replyTo = mMessenger
93 | mService!!.send(msg)
94 | } catch (e: RemoteException) {
95 | // In this case the service has crashed before we could even
96 | // do anything with it; we can count on soon being
97 | // disconnected (and then reconnected if it can be restarted)
98 | // so there is no need to do anything here.
99 | }
100 |
101 | // As part of the sample, tell the user what happened.
102 | }
103 |
104 | override fun onServiceDisconnected(className: ComponentName) {
105 | // This is called when the connection with the service has been
106 | // unexpectedly disconnected -- that is, its process crashed.
107 | mService = null
108 | Log.d(TAG, "Disconnected.")
109 | }
110 | }
111 |
112 | init {
113 | Log.i(TAG, String.format(Locale.ENGLISH,
114 | "model:%s, product:%s, device:%s, manufacturer:%s",
115 | Build.MODEL, Build.PRODUCT, Build.DEVICE, Build.MANUFACTURER))
116 | }
117 |
118 | fun destroy() {
119 | if (sInstance != null) {
120 | doUnbindService()
121 |
122 | mProperties.clear()
123 | mContextRef.clear()
124 |
125 | sInstance = null
126 | }
127 | }
128 |
129 | fun hasUnderDisplayFingerprint(): Boolean {
130 | return getPropertyBoolean(KEY_HAS_UNDER_DISPLAY_FINGERPRINT)
131 | }
132 |
133 | fun setFingerprintInsetsListener(listener: FingerprintInsetsListener) {
134 | mListener = listener
135 | }
136 |
137 | private fun doBindService(): Boolean {
138 | // Establish a connection with the service. We use an explicit
139 | // class name because there is no reason to be able to let other
140 | // applications replace our component.
141 | val context = mContextRef.get()
142 | if (context == null) {
143 | Log.d(TAG, "Context missed!")
144 | return false
145 | }
146 |
147 | val intent = Intent()
148 | intent.setClassName("com.vivo.udfingerprint",
149 | "com.vivo.udfingerprint.service.MessengerService")
150 | intent.putExtra(KEY_MAJOR_VERSION, VERSION_MAJOR)
151 | intent.putExtra(KEY_MINOR_VERSION, VERSION_MINOR)
152 | val binded = context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE)
153 | if (!binded) {
154 | Log.i(TAG, "Service not exist")
155 | mIsBound = false
156 | loadPropertiesOffline()
157 |
158 | Message.obtain(mHandler, MSG_INTERNAL_NOTIFY_READY).sendToTarget()
159 | } else {
160 | Log.d(TAG, "Binding.")
161 | mIsBound = true
162 | }
163 |
164 | return mIsBound
165 | }
166 |
167 | private fun doUnbindService() {
168 | if (!mIsBound) {
169 | Log.d(TAG, "Service not bound")
170 | return
171 | }
172 |
173 | // If we have received the service, and hence registered with
174 | // it, then now is the time to unregister.
175 | if (mService != null) {
176 | try {
177 | val msg = Message.obtain(null,
178 | MSG_CLEAR)
179 | msg.replyTo = mMessenger
180 | mService!!.send(msg)
181 | } catch (e: RemoteException) {
182 | // There is nothing special we need to do if the service
183 | // has crashed.
184 | }
185 |
186 | mService = null
187 | }
188 |
189 | mIsBound = false
190 |
191 | val context = mContextRef.get()
192 | if (context == null) {
193 | Log.d(TAG, "Context missed!")
194 | return
195 | }
196 |
197 | // Detach our existing connection.
198 | context.unbindService(mConnection)
199 | Log.d(TAG, "Unbinding.")
200 | }
201 |
202 | private fun parseQueryResult(jsonString: String?) {
203 | setPropertyBoolean(KEY_HAS_UNDER_DISPLAY_FINGERPRINT, false)
204 |
205 | if (!TextUtils.isEmpty(jsonString)) {
206 | val reader = JsonReader(StringReader(jsonString!!))
207 | try {
208 | parseProperties(reader)
209 | } catch (e: IOException) {
210 | mProperties.clear()
211 | } finally {
212 | try {
213 | reader.close()
214 | } catch (e: IOException) {
215 | //
216 | }
217 |
218 | }
219 | }
220 |
221 | Message.obtain(mHandler, MSG_INTERNAL_NOTIFY_READY).sendToTarget()
222 | }
223 |
224 | @Throws(IOException::class)
225 | private fun parseProperties(reader: JsonReader) {
226 | reader.beginObject()
227 |
228 | while (reader.hasNext()) {
229 | val name = reader.nextName()
230 | if (TextUtils.equals(name, KEY_ICON_STATE)) {
231 | setPropertyInteger(name, reader.nextInt())
232 | } else if (TextUtils.equals(name, KEY_HAS_UNDER_DISPLAY_FINGERPRINT)) {
233 | setPropertyBoolean(name, reader.nextBoolean())
234 | } else if (TextUtils.equals(name, KEY_ICON_POSITION)) {
235 | val positionRect = parsePosition(reader)
236 | setPropertyRect(name, positionRect)
237 | } else {
238 | reader.skipValue()
239 | }
240 | }
241 |
242 | reader.endObject()
243 | }
244 |
245 | @Throws(IOException::class)
246 | private fun parsePosition(reader: JsonReader): Rect {
247 | var left = 0
248 | var top = 0
249 | var right = 0
250 | var bottom = 0
251 |
252 | reader.beginArray()
253 | if (reader.hasNext()) {
254 | left = reader.nextInt()
255 | }
256 |
257 | if (reader.hasNext()) {
258 | top = reader.nextInt()
259 | }
260 |
261 | if (reader.hasNext()) {
262 | right = reader.nextInt()
263 | }
264 |
265 | if (reader.hasNext()) {
266 | bottom = reader.nextInt()
267 | }
268 | reader.endArray()
269 |
270 | return Rect(left, top, right, bottom)
271 | }
272 |
273 | private fun loadPropertiesOffline(): Boolean {
274 | if (Build.VERSION.SDK_INT < 24) {
275 | // There is no device use under display fingerprint lower than android N.
276 | setPropertyBoolean(KEY_HAS_UNDER_DISPLAY_FINGERPRINT, false)
277 | return false
278 | }
279 |
280 | if (Build.VERSION.SDK_INT < 26) {
281 | Log.d(TAG, "fingerprint: $fingerprintModule")
282 | }
283 |
284 | var centerX = 0
285 | var centerY = 0
286 | var iconWidth = 0
287 | var iconHeight = 0
288 | val rect = Rect()
289 | when {
290 | isX20PlusUD -> {
291 | Log.d(TAG, "isX20PlusUD")
292 | centerX = 540
293 | centerY = 2006
294 | iconWidth = 160
295 | iconHeight = 160
296 | }
297 | isX21UD -> {
298 | Log.d(TAG, "isX21UD")
299 | centerX = 540
300 | centerY = 1924
301 | iconWidth = 170
302 | iconHeight = 170
303 | }
304 | else -> {
305 | Log.d(TAG, "No under display fingerprint detected")
306 | }
307 | }
308 |
309 | rect.set(centerX, centerY, centerX + iconWidth, centerY + iconHeight)
310 | rect.offset(-iconWidth / 2, -iconHeight / 2)
311 |
312 | if (rect.isEmpty) {
313 | setPropertyBoolean(KEY_HAS_UNDER_DISPLAY_FINGERPRINT, false)
314 | } else {
315 | setPropertyRect(KEY_ICON_POSITION, rect)
316 | setPropertyInteger(KEY_ICON_STATE, ICON_VISIBLE)
317 | setPropertyBoolean(KEY_HAS_UNDER_DISPLAY_FINGERPRINT, true)
318 | }
319 |
320 | return true
321 | }
322 |
323 | private fun setPropertyBoolean(key: String, value: Boolean) {
324 | if (mProperties.containsKey(key)) {
325 | Log.d(TAG, "update property $key")
326 | }
327 |
328 | val property = Property(key, value)
329 | mProperties[key] = property
330 | }
331 |
332 | private fun setPropertyInteger(key: String, value: Int) {
333 | if (mProperties.containsKey(key)) {
334 | Log.d(TAG, "update property $key")
335 | }
336 |
337 | val property = Property(key, value)
338 | mProperties[key] = property
339 | }
340 |
341 | private fun setPropertyRect(key: String, rect: Rect) {
342 | val property = Property(KEY_ICON_POSITION, rect)
343 | mProperties[key] = property
344 | }
345 |
346 | private fun getPropertyBoolean(key: String): Boolean {
347 | val property = mProperties[key] ?: return false
348 | return property.value as Boolean
349 | }
350 |
351 | private fun getPropertyInteger(key: String): Int {
352 | val property = mProperties[key] ?: return -1
353 | return property.value as Int
354 | }
355 |
356 | private fun getPropertyRect(key: String): Rect? {
357 | val property = mProperties[key] ?: return null
358 | return property.value as Rect
359 | }
360 |
361 | private fun notifyReady() {
362 | if (mListener != null) {
363 | mListener!!.onReady()
364 | }
365 | }
366 |
367 | private fun notifyIconStateChanged(state: Int) {
368 | setPropertyInteger(KEY_ICON_STATE, state)
369 |
370 | if (mListener != null) {
371 | mListener!!.onIconStateChanged(state)
372 | }
373 | }
374 |
375 | interface FingerprintInsetsListener {
376 | fun onReady()
377 | fun onIconStateChanged(state: Int)
378 | }
379 |
380 | private class Property internal constructor(internal var key: String, internal var value: T)
381 |
382 | /**
383 | * Handler of incoming messages from service.
384 | */
385 | private class IncomingHandler internal constructor(insets: VivoFingerprintInsets) : Handler() {
386 | private val mInsets: WeakReference = WeakReference(insets)
387 |
388 | override fun handleMessage(msg: Message) {
389 | val insets = mInsets.get()
390 | if (insets == null) {
391 | Log.d(TAG, "missing insets reference")
392 | super.handleMessage(msg)
393 | return
394 | }
395 |
396 | when (msg.what) {
397 | MSG_QUERY_INFO -> {
398 | Log.d(TAG, String.format(Locale.ENGLISH,
399 | "Received from service, version:%d.%d", msg.arg1, msg.arg2))
400 | val extras = msg.data
401 | val jsonString = extras?.getString(KEY_QUERY_JSON_STRING)
402 | insets.parseQueryResult(jsonString)
403 | }
404 |
405 | MSG_ICON_STATE_CHANGE -> {
406 | val state = msg.arg1
407 | Log.d(TAG, "Received from service, icon state:$state")
408 | insets.notifyIconStateChanged(state)
409 | }
410 |
411 | MSG_INTERNAL_NOTIFY_READY -> insets.notifyReady()
412 |
413 | else -> super.handleMessage(msg)
414 | }
415 | }
416 | }
417 |
418 | companion object {
419 | private const val TAG = "VivoFingerprintInsets"
420 |
421 | const val ICON_INVISIBLE = 0
422 | const val ICON_VISIBLE = 1
423 |
424 | private const val VERSION_MAJOR = 1
425 | private const val VERSION_MINOR = 0
426 |
427 | /** Keep the same as service. */
428 | private const val MSG_QUERY_INFO = 10000
429 | private const val MSG_ICON_STATE_CHANGE = 10001
430 | private const val MSG_CLEAR = 10002
431 |
432 | private const val MSG_INTERNAL_NOTIFY_READY = 10
433 |
434 | private const val KEY_MAJOR_VERSION = "version_major"
435 | private const val KEY_MINOR_VERSION = "version_minor"
436 | private const val KEY_QUERY_JSON_STRING = "query_json"
437 | private const val KEY_HAS_UNDER_DISPLAY_FINGERPRINT = "has_under_display_fingerprint"
438 | private const val KEY_ICON_POSITION = "icon_position"
439 | private const val KEY_ICON_STATE = "icon_state"
440 |
441 | private const val KEY_TOKEN = "token"
442 |
443 | private var sDebuggable = true
444 |
445 | private var sInstance: VivoFingerprintInsets? = null
446 |
447 | fun create(context: Context, listener: FingerprintInsetsListener): VivoFingerprintInsets? {
448 | if (!isVivoDevice) {
449 | return null
450 | }
451 |
452 | if (sInstance == null) {
453 | val insets = VivoFingerprintInsets(context)
454 | insets.setFingerprintInsetsListener(listener)
455 | insets.doBindService()
456 |
457 | sInstance = insets
458 | }
459 |
460 | return sInstance
461 | }
462 |
463 | fun setDebugEnable(enable: Boolean) {
464 | sDebuggable = enable
465 | }
466 |
467 | private val isVivoDevice: Boolean = Build.MANUFACTURER.equals("vivo", ignoreCase = true)
468 |
469 | private// Just support level below O, Api after O_MR1 don't allow use reflection.
470 | val isX20PlusUD: Boolean = Build.DEVICE.equals("PD1721", ignoreCase = true)
471 | || (Build.DEVICE.equals("PD1710", ignoreCase = true) && Build.VERSION.SDK_INT < Build.VERSION_CODES.O && isUdModule)
472 |
473 | private// isUdModule use reflection to get fingerprint property.
474 | // Api after O_MR1 don't allow use reflection.
475 | val isX21UD: Boolean
476 | get() {
477 | if (Build.DEVICE.equals("PD1728UD", ignoreCase = true)) {
478 | return true
479 | }
480 |
481 | if (Build.DEVICE.contains("1728") || Build.DEVICE.contains("1725")) {
482 | if (Build.VERSION.SDK_INT <= 27) {
483 | if (isUdModule) {
484 | return true
485 | }
486 | }
487 | }
488 |
489 | return false
490 | }
491 |
492 | private val isUdModule: Boolean
493 | get() {
494 | val fingerprint = fingerprintModule
495 | return !TextUtils.isEmpty(fingerprint) && fingerprint.startsWith("udfp_")
496 | }
497 |
498 | private val fingerprintModule: String
499 | get() {
500 | var fingerprint = getProperty("sys.fingerprint.boot", "")
501 | if (TextUtils.isEmpty(fingerprint)) {
502 | fingerprint = getProperty("persist.sys.fptype", "unknown")
503 | }
504 | return fingerprint
505 | }
506 |
507 | /**
508 | * TODO: Api after O_MR1 don't allow use reflection.
509 | * @param key property name
510 | * @param defaultValue return value if property is empty.
511 | * @return property
512 | */
513 | private fun getProperty(key: String, defaultValue: String): String {
514 | var value = defaultValue
515 | try {
516 | val c = Class.forName("android.os.SystemProperties")
517 | val get = c.getMethod("get", String::class.java, String::class.java)
518 | value = get.invoke(c, key, defaultValue) as String
519 | } catch (e: Exception) {
520 | Log.d(TAG, e.message)
521 | }
522 |
523 | return value
524 | }
525 | }
526 | }
--------------------------------------------------------------------------------
/bmprinter/src/main/java/com/bcm/bmprinter/fingerprint/brandfingerprintutils/VivoFingerprintUtil.kt:
--------------------------------------------------------------------------------
1 | package com.bcm.bmprinter.fingerprint.brandfingerprintutils
2 |
3 | import android.content.Context
4 | import android.os.Build
5 | import android.util.Log
6 | import com.bcm.bmprinter.fingerprint.AospFingerprintHelper
7 | import com.bcm.bmprinter.fingerprint.IFingerprintUtil
8 |
9 | /**
10 | * Vivo指纹识别模块,依赖于AOSP,支持返回屏下指纹位置,单位px
11 | * https://dev.vivo.com.cn/documentCenter/doc/104 sdk文档地址
12 | * Created cangwang & by Kin on 2018/8/31
13 | */
14 | class VivoFingerprintUtil private constructor(context: Context) : IFingerprintUtil {
15 | companion object {
16 | private var instance: VivoFingerprintUtil? = null
17 |
18 | fun getInstance(context: Context): VivoFingerprintUtil {
19 | if (instance == null) {
20 | instance = VivoFingerprintUtil(context)
21 | }
22 | Log.d(instance?.TAG, "Return Vivo fingerprint util.")
23 | return instance!!
24 | }
25 | }
26 |
27 | private val TAG = "VivoFingerprintUtil"
28 |
29 | private lateinit var aospFingerprint: AospFingerprintHelper
30 | //屏下指纹技术
31 | private var mInset = VivoFingerprintInsets.create(context, object : VivoFingerprintInsets.FingerprintInsetsListener {
32 | override fun onReady() {}
33 |
34 | override fun onIconStateChanged(state: Int) {}
35 | })
36 |
37 | init {
38 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
39 | aospFingerprint = AospFingerprintHelper(context)
40 | }
41 | }
42 |
43 | override fun canUseFingerprint(): Boolean {
44 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
45 | return aospFingerprint.isHardwareDetected()
46 | }
47 | return false
48 | }
49 |
50 | override fun isDeviceSecure(): Boolean {
51 | return aospFingerprint.isKeyguardSecure()
52 | }
53 |
54 | override fun hasEnrolledFingerprints(): Boolean {
55 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
56 | return aospFingerprint.hasEnrolledFingerprints()
57 | }
58 | return false
59 | }
60 |
61 | override fun destroy() {
62 | mInset?.destroy()
63 | aospFingerprint.stopAuthenticate()
64 | }
65 |
66 | override fun authenticate(authenticateResult: (success: Boolean, errCode: Int, errMsg: String?) -> Unit) {
67 | aospFingerprint.startAuthenticate(authenticateResult)
68 | }
69 |
70 | override fun cancelAuthenticate() {
71 | aospFingerprint.stopAuthenticate()
72 | }
73 |
74 | override fun getUnderDisplayFingerprintPosition(): IntArray {
75 | if (mInset?.hasUnderDisplayFingerprint() == true) { //判断是否评下指纹
76 | return intArrayOf(mInset?.fingerprintIconLeft ?: -1, mInset?.fingerprintIconTop ?: -1, mInset?.fingerprintIconRight ?: -1, mInset?.fingerprintIconBottom ?: -1)
77 | }
78 | return intArrayOf()
79 | }
80 | }
--------------------------------------------------------------------------------
/bmprinter/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | bmprinter
3 |
4 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.2.20'
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.3'
11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cangwang/BMPrinter/a600ea3871c33e307a2b1a38476e19fe45642cf6/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Sep 06 15:59:10 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':bmprinter'
2 |
--------------------------------------------------------------------------------