Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
d7eeef2c
Commit
d7eeef2c
authored
Sep 29, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate fingerprint authentication dialog code
parent
4f626897
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
55 deletions
+67
-55
SettingsFragment.java
...java/com/topjohnwu/magisk/fragments/SettingsFragment.java
+4
-55
FingerprintHelper.java
...ll/java/com/topjohnwu/magisk/utils/FingerprintHelper.java
+63
-0
No files found.
app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java
View file @
d7eeef2c
...
@@ -3,15 +3,9 @@ package com.topjohnwu.magisk.fragments;
...
@@ -3,15 +3,9 @@ package com.topjohnwu.magisk.fragments;
import
android.annotation.SuppressLint
;
import
android.annotation.SuppressLint
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
android.content.SharedPreferences
;
import
android.content.res.Resources
;
import
android.content.res.TypedArray
;
import
android.graphics.Color
;
import
android.graphics.drawable.Drawable
;
import
android.hardware.fingerprint.FingerprintManager
;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.view.Gravity
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
...
@@ -24,7 +18,6 @@ import com.topjohnwu.magisk.MagiskManager;
...
@@ -24,7 +18,6 @@ import com.topjohnwu.magisk.MagiskManager;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.asyncs.CheckUpdates
;
import
com.topjohnwu.magisk.asyncs.CheckUpdates
;
import
com.topjohnwu.magisk.asyncs.PatchAPK
;
import
com.topjohnwu.magisk.asyncs.PatchAPK
;
import
com.topjohnwu.magisk.components.CustomAlertDialog
;
import
com.topjohnwu.magisk.receivers.DownloadReceiver
;
import
com.topjohnwu.magisk.receivers.DownloadReceiver
;
import
com.topjohnwu.magisk.utils.Download
;
import
com.topjohnwu.magisk.utils.Download
;
import
com.topjohnwu.magisk.utils.FingerprintHelper
;
import
com.topjohnwu.magisk.utils.FingerprintHelper
;
...
@@ -277,54 +270,10 @@ public class SettingsFragment extends PreferenceFragmentCompat
...
@@ -277,54 +270,10 @@ public class SettingsFragment extends PreferenceFragmentCompat
case
Const
.
Key
.
SU_FINGERPRINT
:
case
Const
.
Key
.
SU_FINGERPRINT
:
boolean
checked
=
((
SwitchPreference
)
preference
).
isChecked
();
boolean
checked
=
((
SwitchPreference
)
preference
).
isChecked
();
((
SwitchPreference
)
preference
).
setChecked
(!
checked
);
((
SwitchPreference
)
preference
).
setChecked
(!
checked
);
CustomAlertDialog
dialog
=
new
CustomAlertDialog
(
requireActivity
());
FingerprintHelper
.
showAuthDialog
(
requireActivity
(),
()
->
{
CustomAlertDialog
.
ViewHolder
vh
=
dialog
.
getViewHolder
();
((
SwitchPreference
)
preference
).
setChecked
(
checked
);
Drawable
fingerprint
=
getResources
().
getDrawable
(
R
.
drawable
.
ic_fingerprint
);
mm
.
mDB
.
setSettings
(
key
,
checked
?
1
:
0
);
fingerprint
.
setBounds
(
0
,
0
,
Utils
.
dpInPx
(
50
),
Utils
.
dpInPx
(
50
));
});
Resources
.
Theme
theme
=
requireActivity
().
getTheme
();
TypedArray
ta
=
theme
.
obtainStyledAttributes
(
new
int
[]
{
R
.
attr
.
imageColorTint
});
fingerprint
.
setTint
(
ta
.
getColor
(
0
,
Color
.
GRAY
));
ta
.
recycle
();
vh
.
messageView
.
setCompoundDrawables
(
null
,
null
,
null
,
fingerprint
);
vh
.
messageView
.
setCompoundDrawablePadding
(
Utils
.
dpInPx
(
20
));
vh
.
messageView
.
setGravity
(
Gravity
.
CENTER
);
try
{
FingerprintHelper
helper
=
new
FingerprintHelper
()
{
@Override
public
void
onAuthenticationError
(
int
errorCode
,
CharSequence
errString
)
{
vh
.
messageView
.
setTextColor
(
Color
.
RED
);
vh
.
messageView
.
setText
(
errString
);
}
@Override
public
void
onAuthenticationHelp
(
int
helpCode
,
CharSequence
helpString
)
{
vh
.
messageView
.
setTextColor
(
Color
.
RED
);
vh
.
messageView
.
setText
(
helpString
);
}
@Override
public
void
onAuthenticationFailed
()
{
vh
.
messageView
.
setTextColor
(
Color
.
RED
);
vh
.
messageView
.
setText
(
R
.
string
.
auth_fail
);
}
@Override
public
void
onAuthenticationSucceeded
(
FingerprintManager
.
AuthenticationResult
result
)
{
dialog
.
dismiss
();
((
SwitchPreference
)
preference
).
setChecked
(
checked
);
mm
.
mDB
.
setSettings
(
key
,
checked
?
1
:
0
);
}
};
dialog
.
setMessage
(
R
.
string
.
auth_fingerprint
)
.
setNegativeButton
(
R
.
string
.
close
,
(
d
,
w
)
->
helper
.
cancel
())
.
setOnCancelListener
(
d
->
helper
.
cancel
())
.
show
();
helper
.
authenticate
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
Utils
.
toast
(
R
.
string
.
auth_fail
,
Toast
.
LENGTH_SHORT
);
}
break
;
break
;
}
}
return
true
;
return
true
;
...
...
app/src/full/java/com/topjohnwu/magisk/utils/FingerprintHelper.java
View file @
d7eeef2c
package
com
.
topjohnwu
.
magisk
.
utils
;
package
com
.
topjohnwu
.
magisk
.
utils
;
import
android.annotation.TargetApi
;
import
android.annotation.TargetApi
;
import
android.app.Activity
;
import
android.app.Dialog
;
import
android.app.KeyguardManager
;
import
android.app.KeyguardManager
;
import
android.content.Context
;
import
android.content.res.Resources
;
import
android.content.res.TypedArray
;
import
android.graphics.Color
;
import
android.graphics.drawable.Drawable
;
import
android.hardware.fingerprint.FingerprintManager
;
import
android.hardware.fingerprint.FingerprintManager
;
import
android.os.Build
;
import
android.os.Build
;
import
android.os.CancellationSignal
;
import
android.os.CancellationSignal
;
import
android.security.keystore.KeyGenParameterSpec
;
import
android.security.keystore.KeyGenParameterSpec
;
import
android.security.keystore.KeyPermanentlyInvalidatedException
;
import
android.security.keystore.KeyPermanentlyInvalidatedException
;
import
android.security.keystore.KeyProperties
;
import
android.security.keystore.KeyProperties
;
import
android.view.Gravity
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.Const
;
import
com.topjohnwu.magisk.Const
;
import
com.topjohnwu.magisk.Data
;
import
com.topjohnwu.magisk.Data
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.components.CustomAlertDialog
;
import
java.security.KeyStore
;
import
java.security.KeyStore
;
...
@@ -19,6 +30,8 @@ import javax.crypto.Cipher;
...
@@ -19,6 +30,8 @@ import javax.crypto.Cipher;
import
javax.crypto.KeyGenerator
;
import
javax.crypto.KeyGenerator
;
import
javax.crypto.SecretKey
;
import
javax.crypto.SecretKey
;
import
androidx.preference.SwitchPreference
;
@TargetApi
(
Build
.
VERSION_CODES
.
M
)
@TargetApi
(
Build
.
VERSION_CODES
.
M
)
public
abstract
class
FingerprintHelper
{
public
abstract
class
FingerprintHelper
{
...
@@ -35,6 +48,56 @@ public abstract class FingerprintHelper {
...
@@ -35,6 +48,56 @@ public abstract class FingerprintHelper {
return
km
.
isKeyguardSecure
()
&&
fm
!=
null
&&
fm
.
isHardwareDetected
()
&&
fm
.
hasEnrolledFingerprints
();
return
km
.
isKeyguardSecure
()
&&
fm
!=
null
&&
fm
.
isHardwareDetected
()
&&
fm
.
hasEnrolledFingerprints
();
}
}
public
static
void
showAuthDialog
(
Activity
activity
,
Runnable
onSuccess
)
{
CustomAlertDialog
dialog
=
new
CustomAlertDialog
(
activity
);
CustomAlertDialog
.
ViewHolder
vh
=
dialog
.
getViewHolder
();
try
{
FingerprintHelper
helper
=
new
FingerprintHelper
()
{
@Override
public
void
onAuthenticationError
(
int
errorCode
,
CharSequence
errString
)
{
vh
.
messageView
.
setTextColor
(
Color
.
RED
);
vh
.
messageView
.
setText
(
errString
);
}
@Override
public
void
onAuthenticationHelp
(
int
helpCode
,
CharSequence
helpString
)
{
vh
.
messageView
.
setTextColor
(
Color
.
RED
);
vh
.
messageView
.
setText
(
helpString
);
}
@Override
public
void
onAuthenticationFailed
()
{
vh
.
messageView
.
setTextColor
(
Color
.
RED
);
vh
.
messageView
.
setText
(
R
.
string
.
auth_fail
);
}
@Override
public
void
onAuthenticationSucceeded
(
FingerprintManager
.
AuthenticationResult
result
)
{
dialog
.
dismiss
();
onSuccess
.
run
();
}
};
Drawable
fingerprint
=
activity
.
getResources
().
getDrawable
(
R
.
drawable
.
ic_fingerprint
);
fingerprint
.
setBounds
(
0
,
0
,
Utils
.
dpInPx
(
50
),
Utils
.
dpInPx
(
50
));
Resources
.
Theme
theme
=
activity
.
getTheme
();
TypedArray
ta
=
theme
.
obtainStyledAttributes
(
new
int
[]
{
R
.
attr
.
imageColorTint
});
fingerprint
.
setTint
(
ta
.
getColor
(
0
,
Color
.
GRAY
));
ta
.
recycle
();
vh
.
messageView
.
setCompoundDrawables
(
null
,
null
,
null
,
fingerprint
);
vh
.
messageView
.
setCompoundDrawablePadding
(
Utils
.
dpInPx
(
20
));
vh
.
messageView
.
setGravity
(
Gravity
.
CENTER
);
dialog
.
setMessage
(
R
.
string
.
auth_fingerprint
)
.
setNegativeButton
(
R
.
string
.
close
,
(
d
,
w
)
->
helper
.
cancel
())
.
setOnCancelListener
(
d
->
helper
.
cancel
())
.
show
();
helper
.
authenticate
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
Utils
.
toast
(
R
.
string
.
auth_fail
,
Toast
.
LENGTH_SHORT
);
}
}
protected
FingerprintHelper
()
throws
Exception
{
protected
FingerprintHelper
()
throws
Exception
{
KeyStore
keyStore
=
KeyStore
.
getInstance
(
"AndroidKeyStore"
);
KeyStore
keyStore
=
KeyStore
.
getInstance
(
"AndroidKeyStore"
);
manager
=
Data
.
MM
().
getSystemService
(
FingerprintManager
.
class
);
manager
=
Data
.
MM
().
getSystemService
(
FingerprintManager
.
class
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment