OSDN Git Service

Allow su to execute binary directly if -c is not supplied.
[android-x86/external-koush-Superuser.git] / Superuser / src / com / koushikdutta / superuser / util / SuHelper.java
1 package com.koushikdutta.superuser.util;
2
3 import android.content.Context;
4 import android.util.Log;
5
6 public class SuHelper {
7     public static String CURRENT_VERSION = "9";
8     public static void checkSu(Context context) throws Exception {
9         Process p = Runtime.getRuntime().exec("su -v");
10         String result = Settings.readToEnd(p.getInputStream());
11         Log.i("Superuser", "Result: " + result);
12         if (0 != p.waitFor())
13             throw new Exception("non zero result");
14         if (result == null)
15             throw new Exception("no data");
16         if (!result.contains(context.getPackageName()))
17             throw new Exception("unknown su");
18         
19         String[] parts = result.split(" ");
20         if (!CURRENT_VERSION.equals(parts[0]))
21             throw new Exception("binary is old");
22     }
23
24 }