import android.os.Handler;
import android.os.Looper;
import java.util.concurrent.Executor;
class WorkerThread extends Thread implements Executor {
private Handler handler;
private boolean isAlive = false;
public WorkerThread() {
super("WorkerThread-" + System.currentTimeMillis());
}
public void run() {
Looper.prepare();
this.isAlive = true;
this.handler = new Handler();
synchronized (this) {
super.notifyAll();
}
Looper.loop();
}
public Handler getHandler() {
return this.handler;
}
public void stopThread() {
this.isAlive = false;
this.handler.getLooper().quit();
this.handler.removeCallbacksAndMessages(null);
}
public static WorkerThread createWorkerThread() {
WorkerThread thread = new WorkerThread();
synchronized (thread) {
thread.start();
try {
thread.wait();
} catch (InterruptedException e) {
throw new RuntimeException();
}
return thread;
}
}
public void execute(Runnable command)
{
if (this.isAlive)
this.handler.post(command);
}
}
Thursday, March 5, 2015
Android WorkerThread class
How to check whether device is rooted in Android
Normally we detect whether device is rooted by checking for su binary. Problem is su binary can be in many location based on rooting techniques.
protected static boolean checkForRoot()
{
String[] arrayOfString = new String[8];
arrayOfString[0] = "/sbin/";
arrayOfString[1] = "/system/bin/";
arrayOfString[2] = "/system/xbin/";
arrayOfString[3] = "/data/local/xbin/";
arrayOfString[4] = "/data/local/bin/";
arrayOfString[5] = "/system/sd/xbin/";
arrayOfString[6] = "/system/bin/failsafe/";
arrayOfString[7] = "/data/local/";
int j = arrayOfString.length;
int i = 0;
while (i < j)
{
String str = arrayOfString[i];
if (new File(str + "su").exists()) {
return true;
}
i += 1;
}
return false;
}
Subscribe to:
Posts (Atom)