待解决的问题

一个奇怪的动画定义

<? xml version = “1.0″ encoding = “utf-8″ ?>

< rotate xmlns:android = “http://schemas.android.com/apk/res/android”

android:pivotX = “50%” android:pivotY = “50%” android:fromDegrees = “0″

android:toDegrees = “360″ >

< shape android:shape = “ring” android:innerRadiusRatio = “5″

android:thicknessRatio = “6″ android:useLevel = “false” >

< gradient android:type = “sweep” android:useLevel = “false”

android:startColor = “@color/white” android:centerColor = “@color/gray”

android:centerY = “0.50″ android:endColor = “@color/black” />

</ shape >

</ rotate >

    • android 超级用户

编写使用root 权限的android 应用程序

编写使用 root 权限的 android 应用程序

最近事情太多脑子都有点晕了,刚才想写个 android 的小程序需要使用到 root 权限,思来想去一直在自己 fork 个自己上想,可是 java 基本没用过总觉得不好写,后来自己就先用 python 写出来,打算写完后慢慢翻译成 java ,反正也是很简单的一个程序,用 python 代码量就更小了。

可是写着写着就很自然而然的先 su root 权限,然后运行了两条命令, TNND ,原来自己一直想跑偏了,这那里需要什么 fork 自己那么复杂呀,不就是 root 后运行两条命令嘛,真该死,害我一下想了一个多小时…

我很想说知道原理然后代码就简单了,可是对于不懂 java 的我来说依然是不太简单,后来就偷个懒 google 了一把,就很轻易的找到了 java 的实现:

public static boolean runRootCommand(String command) {

Process process = null ;

DataOutputStream os = null ;

try {

process = Runtime.getRuntime().exec( “su” );

os = new DataOutputStream(process.getOutputStream());

os.writeBytes(command+ “/n” );

os.writeBytes( “exit/n” );

os.flush();

process.waitFor();

} catch (Exception e) {

Log.d( “*** DEBUG ***” , “Unexpected error – Here is what I know: “ +e.getMessage());

return false ;

}

finally {

try {

if (os != null ) {

os.close();

}

process.destroy();

} catch (Exception e) {

// nothing

}

}

return true ;

}

}

Android: Requesting root access in your app

by mat on January 17th, 2010

This snippet shows how root access can be requested inside an application in order to write a file into a place we do not have permission to access usually. Requesting root access will only work if your phone allows it, or it has been ‘rooted’ (hacked to allow superuser permissions).

view plaincopy to clipboardprint?

1. Process p;

2. try {

3. // Preform su to get root privledges

4. p = Runtime.getRuntime().exec( “su” );

5.

6. // Attempt to write a file to a root-only

7. DataOutputStream os = new DataOutputStream(p.getOutputStream());

8. os.writeBytes( “echo /”Do I have root?/” >/system/sd/temporary.txt/n” );

9.

10. // Close the terminal

11. os.writeBytes( “exit/n” );

12. os.flush();

13. try {

14. p.waitFor();

15. if (p.exitValue() != 255) {

16. // TODO Code to run on success

17. toastMessage( “root” );

18. }

19. else {

20. // TODO Code to run on unsuccessful

21. toastMessage( “not root” );

22. }

23. } catch (InterruptedException e) {

24. // TODO Code to run in interrupted exception

25. toastMessage( “not root” );

26. }

27. } catch (IOException e) {

28. // TODO Code to run in input/output exception

29. toastMessage( “not root” );

30. }

Process p;

try {

// Preform su to get root privledges

p = Runtime.getRuntime().exec( “su” );

// Attempt to write a file to a root-only

DataOutputStream os = new DataOutputStream(p.getOutputStream());

os.writeBytes( “echo /”Do I have root?/” >/system/sd/temporary.txt/n” );

// Close the terminal

os.writeBytes( “exit/n” );

os.flush();

try {

p.waitFor();

if (p.exitValue() != 255) {

// TODO Code to run on success

toastMessage( “root” );

}

else {

// TODO Code to run on unsuccessful

toastMessage( “not root” );

}

} catch (InterruptedException e) {

// TODO Code to run in interrupted exception

toastMessage( “not root” );

}

} catch (IOException e) {

// TODO Code to run in input/output exception

toastMessage( “not root” );

}

Where my “toastMessage” is just a function which creates a toast to display on the screen. On phones with superuser permissions installed (root access) this will display a dialog asking the user to allow or deny the application permission to have root access:

super user

protected Boolean doInBackground(String[] paramArrayOfString)

{

boolean bool = null ;

Object localObject1 = ” /system/n” ;

Object localObject2 = null ;

Object localObject3 = null ;

Process localProcess;

String str;

label60: Object localObject4;

try

{

localProcess = Runtime.getRuntime().exec( “mount” );

InputStream localInputStream = localProcess.getInputStream();

localObject1 = new InputStreamReader(localInputStream);

BufferedReader localBufferedReader = new BufferedReader((Reader)localObject1);

str = localBufferedReader.readLine();

if (str == null )

{

if ((localObject3 == null ) || (localObject2 == null ))

break label336;

label278: label336: label219: localObject4 = localObject2;

}

}

catch (IOException localIOException1)

{

try

{

localProcess = Runtime.getRuntime().exec( “su” );

localObject1 = localProcess.getOutputStream();

DataOutputStream localDataOutputStream = new DataOutputStream((OutputStream)localObject1);

localObject1 = “mount -o remount,rw “ + localObject4 + ” /system/n” ;

localDataOutputStream.writeBytes((String)localObject1);

localDataOutputStream.writeBytes( “cat /data/data/com.noshufou.android.su/files/su > /system/bin/su/n” );

localDataOutputStream.writeBytes( “chmod 06755 /system/bin/su/n” );

localDataOutputStream.writeBytes( “cat /data/data/com.noshufou.android.su/files/su > /system/sbin/su/n” );

localDataOutputStream.writeBytes( “chmod 06755 /system/sbin/su/n” );

localObject1 = “mount -o remount,ro “ + localObject4 + ” /system/n” ;

localDataOutputStream.writeBytes((String)localObject1);

localObject1 = “exit/n” ;

localDataOutputStream.writeBytes((String)localObject1);

}

catch (IOException localIOException1)

{

try

{

localProcess.waitFor();

localObject1 = localProcess.exitValue();

if (localObject1 != 255)

for (localObject1 = Boolean.valueOf( true ); ; localObject1 = Boolean.valueOf(bool))

{

return localObject1;

String[] arrayOfString = str.split( ” “ );

localObject2 = arrayOfString[ null ];

localObject1 = arrayOfString[1].equals( “on” );

if (localObject1 != 0)

{

localObject1 = arrayOfString[2].equals( “/system” );

if (localObject1 != 0)

break label278;

}

localObject1 = arrayOfString[1].equals( “/system” );

if (localObject1 != 0);

int i = 1;

break label60:

localIOException1 = localIOException1;

Log.e( “Su.Updater” , “Problem remounting /system” , localIOException1);

}

localObject1 = null ;

localObject1 = Boolean.valueOf(localObject1);

}

catch (InterruptedException localInterruptedException)

{

localObject1 = null ;

localObject1 = Boolean.valueOf(localObject1);

break label219:

localIOException2 = localIOException2;

localObject1 = Boolean.valueOf(bool);

break label219:

localObject1 = Boolean.valueOf(bool);

}

}

}

}

    • regiestContentObserver 的问题

更新通讯录时不能提示同步,测试发现getContentResolver().regiestContentObserver() 执行结果和预期目标有偏差,原因未清楚。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值