开发者

Android: App not working on some rooted devices... Why?

I have an app on the market that is for rooted devices only. I have tested the app extensively on a rooted and unrooted G1, MT3G and Cliq with no errors. I am receiving a number of low ratings from people with supposedly rooted devices, saying that the app tells them that they are not rooted (of course, they usually don't leave important info like what phone and what rom)

Here is the code开发者_JAVA技巧 that generates the error... can anyone see out what the problem might be?

final Button button = (Button) findViewById(R.id.******);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                String command1 = "mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system";
                String command2 = "cp -f /sdcard/******* /etc/";
                String command3 = "dos2unix -u /etc/*****";
                String command4 = "mount -o ro,remount -t yaffs2 /dev/block/mtdblock3 /system";

                execCommandLine1(command1);
                execCommandLine1(command2);
                execCommandLine1(command3);
                execCommandLine1(command4);
}



void execCommandLine1(String command)
    {
        Runtime runtime = Runtime.getRuntime();
        Process proc = null;
        OutputStreamWriter osw = null;

        try
        {
            proc = runtime.exec("su");
            osw = new OutputStreamWriter(proc.getOutputStream());
            osw.write(command);
            osw.flush();
            osw.close();
        }
        catch (IOException ex)
        {

            Log.e("execCommandLine()", "Command resulted in an IO Exception: " + command);
            return;
        }
        finally
        {
            if (osw != null)
            {
                try
                {
                    osw.close();
                }
                catch (IOException e){}
            }
        }

        try 
        {
            proc.waitFor();
        }
        catch (InterruptedException e){}

        if (proc.exitValue() != 0)
        {
            **// Error Dialog that is being erroneously displayed**

        }
        else {

               // Success Dialog
        }

    }


I agree with Christopher's comment: you appear to be making some assumptions:

  • /system is at /dev/block/mtdblock3
  • /dev/block/mtdblock3 is yaffs2
  • /etc/ is a hardlink or symlink to something on /system
  • mount exists
  • dos2unix exists
  • cp exists
  • su exists

Most of those should be testable at runtime, though the /etc/ check might be a bit tricky. Test that stuff out on the first run of your app, then do whatever makes sense:

  • an "sorry, this app won't work" if you detect a failure
  • disable the menu/button/whatever that leads to whatever is executing your code
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜