Android Open Source - nfcunlocker Input Unlock






From Project

Back to project page nfcunlocker.

License

The source code is released under:

Apache License

If you think the Android project nfcunlocker listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.steelrat.nfcunlocker.unlockmethods;
//w  ww  .  j  a  v  a 2 s .co  m
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.acra.ACRA;

import com.steelrat.nfcunlocker.R;
import com.stericson.RootTools.RootTools;

import android.app.Activity;
import android.content.Context;
import android.widget.Toast;

public class InputUnlock extends UnlockMethod {
  public InputUnlock(Activity activity) {
    super(activity);
  }
  
  public void unlock(String password) {
    super.unlock(password);
        
        List<String> cmds = new ArrayList<String>();
        cmds.add("input text \"" + getPassword() + "\"");
        cmds.add("input keyevent 66");
        
        runAsRoot(cmds);
  }
  
  @Override
  public boolean onActivate() {
    super.onActivate();
  
    boolean isRootAccess = RootTools.isAccessGiven();
    if (!isRootAccess) {
      Context c = getActivity();
      Toast.makeText(c, c.getString(R.string.error_root_access), Toast.LENGTH_LONG).show();
    }
    
    return isRootAccess;
  }
  
  /**
   * Executes commands with Root privileges.
   * 
   * @param cmds
   */
  private void runAsRoot(List<String> cmds) {
      Process process;
    try {
      process = Runtime.getRuntime().exec("su");
    
            DataOutputStream os = new DataOutputStream(process.getOutputStream());

            if (cmds != null) {
              for (String tmpCmd : cmds) {
                os.writeBytes(tmpCmd+"\n");
              }
            }         
            
            os.writeBytes("exit\n");
            os.flush();
            os.close();
            
            process.waitFor();
    } catch (IOException e) {
      e.printStackTrace();
      ACRA.getErrorReporter().handleException(e);
    } catch (InterruptedException e) {
      e.printStackTrace();
      ACRA.getErrorReporter().handleException(e);
    }
  }
  
  @Override
  public void onActivityEvent(String event) {
    super.onActivityEvent(event);
    
    // We can finish activity just after unlock.
    if (event.equals("onCreate")) {             
      getActivity().finish();
    }
  }
}




Java Source Code List

com.steelrat.nfcunlocker.AddActivity.java
com.steelrat.nfcunlocker.DiscoveredActivity.java
com.steelrat.nfcunlocker.MainActivity.java
com.steelrat.nfcunlocker.NFCApplication.java
com.steelrat.nfcunlocker.helpers.AppDeviceAdminReceiver.java
com.steelrat.nfcunlocker.helpers.TagsStorage.java
com.steelrat.nfcunlocker.settingsactivity.SettingsActivityBase.java
com.steelrat.nfcunlocker.settingsactivity.SettingsActivityOA.java
com.steelrat.nfcunlocker.settingsactivity.SettingsActivity.java
com.steelrat.nfcunlocker.unlockmethods.DevicePolicyUnlockMethod.java
com.steelrat.nfcunlocker.unlockmethods.FlagUnlock.java
com.steelrat.nfcunlocker.unlockmethods.InputUnlock.java
com.steelrat.nfcunlocker.unlockmethods.KeyguardUnlock.java
com.steelrat.nfcunlocker.unlockmethods.UnlockMethodFactory.java
com.steelrat.nfcunlocker.unlockmethods.UnlockMethod.java