3

I am developing a security apps, when the phone is lost or stolen, the phone screen is locked automatically and if the theft tries to login to the phone by randomly enters password, the phone will record until 3 failed attempts.

After 3 failed attempts, the current layout will change to a black layout with nothing inside the layout, and I will set the timer for this layout, during this layout no any key can wake this layout up unless the timer is expired. I have successfully implement the timer but when I pressed the back button on the phone the layout back to the login layout. How can I disable all the phone buttons? Is it possible? Thanks

Android_Rookie
  • 509
  • 2
  • 10
  • 25
  • 1
    But Android already has a security mechanism... – Oliver Charlesworth May 19 '12 at 11:35
  • 6
    Wouldn't it be a pretty big flaw if any 3rd party app could "brick" the phone by disabling the physical buttons? – Alexis Pigeon May 19 '12 at 11:35
  • 2
    Talented developers would not write something like this, because talented developers realize that anyone can trivially get past what you are trying to create, simply by removing your app after rebooting the device into safe mode. Talented developers realize that this sort of security needs to be part of the firmware, working in conjunction with the existing device admin APIs. – CommonsWare May 19 '12 at 14:23
  • @CommonsWare Thankfully phone thieves are rarely talented developers. – RyanfaeScotland Mar 16 '15 at 14:23

2 Answers2

3

Don't do it.

The "hack" you are trying to implement can be bypassed simply by removing your app after rebooting the device into safe mode. Disabling the hard buttons won't do anything to prevent this.

Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
1

You can disable back button using this code:

@Override
    public void onBackPressed() { //disable back button in this activity
        return;
    }

http://developer.android.com/reference/android/app/Activity.html#onBackPressed()

Also disable home button using:

@Override
    public void onAttachedToWindow() { //disable home button in this activity
        this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
        super.onAttachedToWindow();
    }

http://developer.android.com/reference/android/app/Activity.html#onAttachedToWindow()

Nik NexAndrX
  • 302
  • 1
  • 6