Android Open Source - PTScreenOff Screen Off Util






From Project

Back to project page PTScreenOff.

License

The source code is released under:

GNU General Public License

If you think the Android project PTScreenOff 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 org.liberty.android.ptplugin.screenoff;
//from  w  ww  .ja v a  2 s.  c  o m
import android.content.Context;
import eu.chainfire.libsuperuser.Shell;
import android.util.Log;
import java.util.List;

public class ScreenOffUtil {

    private static Shell.Interactive rootSession;

    public static void screenOff() {
        openShell();
    }

    private static void openShell() {
        rootSession = new Shell.Builder().
            useSU().
            setWantSTDERR(true).
            setWatchdogTimeout(5).
            setMinimalLogging(true).
            open(new Shell.OnCommandResultListener() {
                // Callback to report whether the shell was successfully started up
                @Override
                public void onCommandResult(int commandCode, int exitCode, List<String> output) {
                    if (exitCode != Shell.OnCommandResultListener.SHELL_RUNNING) {
                        Log.e("MainReceiver", "Error opening root shell: exitCode " + exitCode);
                    } else {
                        sendRootCommand();
                    }
                }
            });
    }

    private static void sendRootCommand() {
        rootSession.addCommand(new String[] { "input keyevent 26" }, 0,
                new Shell.OnCommandResultListener() {
                    public void onCommandResult(int commandCode, int exitCode, List<String> output) {
                        if (exitCode < 0) {
                            Log.e("MainReceiver", "Error executing commands: exitCode " + exitCode);
                        }
                    }
                });
    }
}




Java Source Code List

eu.chainfire.libsuperuser.Application.java
eu.chainfire.libsuperuser.Debug.java
eu.chainfire.libsuperuser.HideOverlaysReceiver.java
eu.chainfire.libsuperuser.ShellNotClosedException.java
eu.chainfire.libsuperuser.ShellOnMainThreadException.java
eu.chainfire.libsuperuser.Shell.java
eu.chainfire.libsuperuser.StreamGobbler.java
org.liberty.android.ptplugin.screenoff.MainActivityTest.java
org.liberty.android.ptplugin.screenoff.MainActivity.java
org.liberty.android.ptplugin.screenoff.MainReceiver.java
org.liberty.android.ptplugin.screenoff.PowerTogglesPlugin.java
org.liberty.android.ptplugin.screenoff.ScreenOffUtil.java