java 在 Android 应用程序中使用系统 PIN 对话框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10106837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 23:39:11  来源:igfitidea点击:

Use system PIN dialog in Android application

javaandroid

提问by Viktor Apoyan

Background

背景

I am trying to write an application which works like described below.

我正在尝试编写一个应用程序,其工作方式如下所述。

  • When user start application it check if user have registered PIN on his device.
  • If user have registered PIN, application must show button "Continue with PIN".
  • When user press on button "Continue with PIN" system standard PIN dialog must appears. enter image description here
  • User enter his PIN and press "Continue" button.
  • After System must check if entered PIN is correct or no and continue working.
  • 当用户启动应用程序时,它会检查用户是否在其设备上注册了 PIN。
  • 如果用户已经注册了 PIN,应用程序必须显示“继续使用 PIN”按钮。
  • 当用户按下按钮“继续使用 PIN”时,系统标准 PIN 对话框必须出现。 在此处输入图片说明
  • 用户输入他的 PIN 并按“继续”按钮。
  • 之后系统必须检查输入的 PIN 是否正确并继续工作。


Searches

搜索

I have made some searches and found some articles on stackoverflowand other internet sources which say "There is no way to develop a new custom unlock mechanism on a non-rooted phone." or "I would be surprised if you could, because then you would be probably able to steal the pin code, and I don't think anyone would want that.".

我进行了一些搜索,发现了一些关于stackoverflow和其他互联网资源的文章,其中说“没有办法在非 root 手机上开发新的自定义解锁机制。”或“如果可以,我会感到惊讶,因为那样你可能会窃取密码,我认为没有人会想要那样。”。

Also I have watched some video tutorials like Tutorial: Android Internals - Building a Custom ROM, Pt. 1 of 2and Tutorial: Android Internals - Building a Custom ROM, Pt. 2 of 2.

此外,我还观看了一些视频教程,例如教程:Android 内部原理 - 构建自定义 ROM,Pt。1 of 2教程:Android Internals - 构建自定义 ROM,Pt。2 的 2

EDITED

已编辑

I have made some searches today and found a very interesting thing, I think I am on a right way to the solution, and I want to share my ideas with you. So looking in android sources I found an interesting files ChooseLockPassword.java(packages\apps\Settings\src\com\android\settings) and LockPatternUtils.java(*frameworks\base\core\java\com\android\internal\widget*) now I am interest in:

今天搜了一下,发现了一个很有意思的东西,我觉得我的解决方法是正确的,我想和大家分享一下我的想法。因此,在 android 源代码中,我发现了一个有趣的文件ChooseLockPassword.javapackages\apps\Settings\src\com\android\settings)和LockPatternUtils.java(*frameworks\base\core\java\com\android\internal\widget* ) 现在我感兴趣的是:

Question

问题

How can I call LockPatternUtilsclass function from my code? Or Why I cant see that function in Eclipse ?

如何LockPatternUtils从我的代码中调用类函数?或者为什么我在 Eclipse 中看不到该功能?



Decision

决定

So I think that the only way to get access to the Android system PIN dialogis to root the phone make some changes in the system files and use system PIN dialod

所以我认为访问Android系统PIN对话框的唯一方法是root手机在系统文件中进行一些更改并使用系统PIN拨号



Question

问题

  1. Can somebody provide me useful links about getting access to the system PIN dialog in the rooted phone.
  2. Am I on a right way and can I solve my problem in this way?
  3. If anybody encountered such problem please help me to solve.
  1. 有人可以为我提供有关在有根电话中访问系统 PIN 对话框的有用链接。
  2. 我是否走在正确的道路上,我可以用这种方式解决我的问题吗?
  3. 如果有人遇到这样的问题,请帮我解决。

Any Solutions?

任何解决方案?

采纳答案by Viktor Apoyan

Okay, I have solved this problem and now I want to share my solution with you.

好的,我已经解决了这个问题,现在我想与您分享我的解决方案。

At first as I told I have android sources so I have made some changes in android sources to get access to the PIN and Pattern dialogs. And here they are:

起初,正如我所说,我有 android 源代码,因此我对 android 源代码进行了一些更改,以访问 PIN 和模式对话框。他们在这里:

in ~\AndroidSources\pakages\apps\Settings\AndroidManifest.xmlI have changed following lines of code

~\AndroidSources\pakages\apps\Settings\AndroidManifest.xml我更改了以下代码行

<activity android:name="ConfirmLockPattern"
          android:exported="true"> // This line was added by me.
</activity>

<activity android:name="ConfirmLockPassword"
          android:exported="true" // This line was added by me.
          android:them="@android:style/Them.NoTitleBar">
</activity>

<activity android:name="ChooseLockPattern"
          android:exported="true" // This line was added by me.
          android:label="@string/lockpattern_change_lock_pattern_label">
</activity>

This modifications allow me to call "ConfirmLockPattern", "ConfirmLockPassword" and "ChooseLockPattern" activities from my own application. After I compile android Source codes and launch system.img on my emulator.

此修改允许我从我自己的应用程序中调用“ ConfirmLockPattern”、“ ConfirmLockPassword”和“ ChooseLockPattern”活动。在我编译 android 源代码并在我的模拟器上启动 system.img 之后。

In my application I have write following functions in order to call "ConfirmLockPattern" or "ChooseLockPattern" activities:

在我的应用程序中,我编写了以下函数以调用“ ConfirmLockPattern”或“ ChooseLockPattern”活动:

/**
 * Show PIN/Password confirmation dialog.
 */
void ShowConfirmLockPINActivity() {
    CustomLog.i(TAG, "Show Confirm Lock PIN Activity");
    Intent intent = new Intent(Intent.ACTION_RUN);
    intent.setComponent(new ComponentName("com.android.settings",
        "com.android.settings.ConfirmLockPassword"));
    startActivityForResult(intent, mRequestCode);
} /* ShowConfirmLockPINActivity() */

/**
 * Show set PIN/Password dialog.
 */
void ShowSetLockPINActivity() {
    CustomLog.i(TAG, "Show Set Lock PIN Activity");
    Intent intent = new Intent(Intent.ACTION_RUN);
    intent.setComponent(new ComponentName("com.android.settings",
        "com.android.settings.ChooseLockPassword"));
    startActivityForResult(intent, mRequestCode);
} /* ShowSetLockPINActivity() */

/**
 * Show Pattern Confirmation dialog.
 */
void ShowSetLockPatternActivity() {
    CustomLog.i(TAG, "Show Set Lock Pattern Activity");
    Intent intent = new Intent(Intent.ACTION_RUN);
    intent.setComponent(new ComponentName("com.android.settings",
        "com.android.settings.ConfirmLockPattern"));
    startActivityForResult(intent, mRequestCode);
} /* ShowSetLockPatternActivity() */

回答by a.ch.

Here are some considerations regarding your question.

以下是关于您的问题的一些考虑。

  1. Diving deep into Android's code is not very good idea in this particular case, since verifying PIN code is an important security point and its mechanism must be hidden and well protected to avoid any malicious intentions.

  2. Thus, the actions you want to perform (ask for PIN and then check it against real PIN) are prohibited and would look like an intrusion. So, you shouldn't try to get an access to the storage of user passwords.

  3. It would be more correct to try launching standard PIN screen via some Intentand ask it to make all job for you. However, a brief investigation didn't give me any results in this direction; perhaps, you'll find something.

  4. Modifying the ROM is obviously dead-end - no one will flash the phone to install one app. Requiring rooted phone is a bit better, there are apps that cannot run on non-rooted phone, but still it forwards us back to the point #2 (intrusion).

  5. Users may disable PIN check and there are devices with no SIM.

  1. 在这种特殊情况下,深入研究 Android 代码并不是一个好主意,因为验证 PIN 码是一个重要的安全点,其机制必须隐藏并受到良好保护,以避免任何恶意企图。

  2. 因此,您想要执行的操作(要求输入 PIN 码,然后根据真实 PIN 码进行检查)被禁止,并且看起来像是入侵。因此,您不应该尝试访问用户密码的存储。

  3. 尝试通过某些启动标准 PIN 屏幕Intent并要求它为您完成所有工作会更正确。然而,一个简短的调查并没有给我这个方向的任何结果。也许,你会发现一些东西。

  4. 修改ROM​​显然是死路一条——没有人会刷手机安装一款应用。需要有 root 权限的手机会好一些,有些应用程序无法在非 root 权限的手机上运行,​​但它仍然让我们回到第 2 点(入侵)。

  5. 用户可以禁用 PIN 检查,并且有些设备没有 SIM 卡

So, according to the all mentioned I'd suggest you think of different verification method for your app.

因此,根据上述所有内容,我建议您为您的应用考虑不同的验证方法。

回答by Dmitry Kochin

Since API level 21 there is KeyguardManager.createConfirmDeviceCredentialIntentthat can be used to authenticate current user with the device lock pin.

从 API 级别 21 开始KeyguardManager.createConfirmDeviceCredentialIntent,可以使用设备锁定 pin 对当前用户进行身份验证。

See the usage example.

请参阅使用示例