Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lock Android Phone after user dials a phone number

Tags:

android

I am developing a security application whereby, if a user dials a phone number that is not frequently called and he has never called before, the user will have to reauthenticate himself. For this purpose I want to lock the phone after checking the phone number.

public class outgoingCalls extends BroadcastReceiver {

public void onReceive(Context context, Intent intent) {

    Log.v("onReceive", "In onReceive()");
    if (confidence == 0) {
        Log.v("onReceive","confidence zeroed");
        Intent i = new Intent();
        i.setClassName("abc.xyz.SECURITY","abc.xyz.SECURITY.lockActivity");
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    } 
}

In this new Activity lockActivity, I need to lock the phone where I have commented // LOCK PHONE

public class lockActivity extends Activity {  

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    Log.v("lock","lockActivity onCreate method called");
        //  setContentView(R.layout.main); 
        Log.v("lock","locking");
// LOCK PHONE
}
} 

The phone is not getting locked with the methods I have tried. These include the following:

1.  KeyguardManager mgr = (KeyguardManager)   getSystemService(Activity.KEYGUARD_SERVICE); 
KeyguardLock lock = mgr.newKeyguardLock("edu.Boston.SECURITY.lockActivity"); 
((KeyguardLock) lock).reenableKeyguard(); 

2.  PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);
manager.goToSleep(100);//int amountOfTime

3. PowerManager.WakeLock wl = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,    "Tag");
wl.acquire();
wl.release();

4. WindowManager.LayoutParams params = getWindow().getAttributes();
   params.screenBrightness = 0;
   getWindow().setAttributes(params);

Android manifest file has below permissions

    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
    <uses-permission android:name="android.permission.READ_CONTACTS"/>
    <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/> 
    <uses-permission android:name="android.permission.WAKE_LOCK" />

Why am I not able to lock the phone? Any pointers? Thanks a lot in advance for your help. Appreciate it!

like image 722
user1773209 Avatar asked Oct 25 '12 05:10

user1773209


People also ask

How do you Lock dialer on Android?

Open up Settings. Locate and tap Security. Locate and tap Smart lock.


1 Answers

Try creating a DevicePolicyManager

http://developer.android.com/training/enterprise/device-management-policy.html

and then call:

DevicePolicyManager mDPM  = (DevicePolicyManager)context.getSystemService(Context.DEVICE_POLICY_SERVICE);
mDPM.lockNow();
like image 133
Johny B Avatar answered Oct 22 '22 13:10

Johny B