title: Lock Android Phone after user dials a phone number
body: <p>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.</p>
  
  <pre><code>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);
      } 
  }
  </code></pre>
  
  <p>In this new Activity lockActivity, I need to lock the phone where I have commented // LOCK PHONE</p>
  
  <pre><code>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
  }
  } 
  </code></pre>
  
  <p>The phone is not getting locked with the methods I have tried. These include the following:</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>Android manifest file has below permissions</p>
  
  <pre><code>    &lt;uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /&gt;
      &lt;uses-permission android:name="android.permission.READ_CONTACTS"/&gt;
      &lt;uses-permission android:name="android.permission.DISABLE_KEYGUARD"/&gt; 
      &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
  </code></pre>
  
  <p>Why am I not able to lock the phone? Any pointers? 
  Thanks a lot in advance for your help. Appreciate it!</p>