Posts
- Google Wallet Hack - Applying Card Emulation Patch to Android 2.3.4_r1 Source Code and Flashing it on Samsung Nexus S
- C Post
- Near Field Communication - Android Perspective
- Some Questions Compilation
- Gaining Root access and performing Priveleged Commands in Android.
- How I started Gstreamer?
- System Requirements for Buidling the Android ICS
- Creatign two threads to display the task bar and do the background processing..
- GTK Hangout
- Tryst with Hawkboard - Day 1
Sunday, February 19, 2012
Gaining Root access and performing Priveleged Commands in Android.
Here is my code :
package com.packagename.gainroot;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class SuperuserRequestActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
execute();
}
public static boolean canRunRootCommands()
{
boolean retval = false;
Process suProcess;
try
{
suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os =
new DataOutputStream(suProcess.getOutputStream());
DataInputStream osRes =
new DataInputStream(suProcess.getInputStream());
if (null != os && null != osRes)
{
// Getting the id of the current user to check if this is root
os.writeBytes("id\n");
os.flush();
String currUid = osRes.readLine();
boolean exitSu = false;
if (null == currUid)
{
retval = false;
exitSu = false;
Log.d("ROOT", "Can't get root access or denied by user");
}
else if (true == currUid.contains("uid=0"))
{
retval = true;
exitSu = true;
Log.d("ROOT", "Root access granted");
}
else
{
retval = false;
exitSu = true;
Log.d("ROOT", "Root access rejected: " + currUid);
}
if (exitSu)
{
os.writeBytes("exit\n");
os.flush();
}
}
}
catch (Exception e)
{
// Can't get root !
// Probably broken pipe exception on trying to write to output
// stream after su failed, meaning that the device is not rooted
retval = false;
Log.d("ROOT", "Root access rejected [" +
e.getClass().getName() + "] : " + e.getMessage());
}
return retval;
}
protected String[] getCommandsToExecute() {
// TODO Auto-generated method stub
String[] str = {"su", "-c", "chmod 777","/dev/test1"};
// TODO Auto-generated method stub
return str;
}
public final boolean execute()
{
boolean retval = false;
try
{
String[] commands = getCommandsToExecute();
if (null != commands && commands.length > 0)
{
Process suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os =
new DataOutputStream(suProcess.getOutputStream());
// Execute commands that require root access
for (String currCommand : commands)
{
os.writeBytes(currCommand + "\n");
os.flush();
}
os.writeBytes("exit\n");
os.flush();
try
{
int suProcessRetval = suProcess.waitFor();
if (255 != suProcessRetval)
{
// Root access granted
retval = true;
}
else
{
// Root access denied
retval = false;
}
}
catch (Exception ex)
{
//Log.e("Error executing root action", ex);
Log.e("LOGEXCEPTION", "Error executing root action", ex);
}
}
}
catch (IOException ex)
{
Log.w("ROOT", "Can't get root access", ex);
}
catch (SecurityException ex)
{
Log.w("ROOT", "Can't get root access", ex);
}
catch (Exception ex)
{
Log.w("ROOT", "Error executing internal operation", ex);
}
return retval;
}
}
I have pasted my Whole code here.
Monday, February 13, 2012
System Requirements for Buidling the Android ICS
HI,
I have just compiled the system requirements for compiling the Android ICS :
I have just compiled the system requirements for compiling the Android ICS :
-6GB of download.
-25GB disk space to do a single build.
-80GB disk space to build all AOSP configs at the same time.
-16GB RAM recommended, more preferred, anything less will measurably
benefit from using an SSD.
-5+ hours of CPU time for a single build, 25+ minutes of wall time, as
measured on my workstation (dual-E5620 i.e. 2x quad-core 2.4GHz HT,
with 24GB of RAM, no SSD),
-25GB disk space to do a single build.
-80GB disk space to build all AOSP configs at the same time.
-16GB RAM recommended, more preferred, anything less will measurably
benefit from using an SSD.
-5+ hours of CPU time for a single build, 25+ minutes of wall time, as
measured on my workstation (dual-E5620 i.e. 2x quad-core 2.4GHz HT,
with 24GB of RAM, no SSD),
Subscribe to:
Posts (Atom)