packages/apps/Superuser
Revisión | 2a71bef0dfd91d8cf4adf52ff4aa617102531258 (tree) |
---|---|
Tiempo | 2010-08-28 15:31:06 |
Autor | tprochazka <tomas.prochazka@atom...> |
Commiter | tprochazka |
- fixed problem with freeze on startup if original version of su is avalaible on device and "su -v" doesn't return any stream and application will block on readLine() method.
+ added nullpointer exception handling if downloading of manifest file failed from some reason
* if "su -v" doesn't return nothing version will be show as 'original'
@@ -17,6 +17,8 @@ | ||
17 | 17 | <string name="su_up_to_date">su is up to date</string> |
18 | 18 | <string name="checking">Checking...</string> |
19 | 19 | <string name="no_connection">No network connection. Could not check for updates</string> |
20 | + <string name="manifest_download_failed">Checking avalaible version failed</string> | |
21 | + <string name="su_original">original</string> | |
20 | 22 | |
21 | 23 | <string name="tab_apps">Apps</string> |
22 | 24 | <string name="tab_log">Log</string> |
@@ -2,8 +2,11 @@ package com.noshufou.android.su; | ||
2 | 2 | |
3 | 3 | import java.io.BufferedReader; |
4 | 4 | import java.io.IOException; |
5 | +import java.io.InputStream; | |
5 | 6 | import java.io.InputStreamReader; |
6 | 7 | |
8 | +import org.w3c.dom.ProcessingInstruction; | |
9 | + | |
7 | 10 | import android.app.TabActivity; |
8 | 11 | import android.content.Intent; |
9 | 12 | import android.content.SharedPreferences; |
@@ -85,13 +88,25 @@ public class Su extends TabActivity { | ||
85 | 88 | Process process = null; |
86 | 89 | try { |
87 | 90 | process = Runtime.getRuntime().exec("su -v"); |
88 | - BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream())); | |
89 | - String suVersion = stdInput.readLine(); | |
90 | - stdInput.close(); | |
91 | - return suVersion; | |
91 | + InputStream processInputStream = process.getInputStream(); | |
92 | + BufferedReader stdInput = new BufferedReader(new InputStreamReader(processInputStream)); | |
93 | + Thread.sleep(500); | |
94 | + try { | |
95 | + if (stdInput.ready()) { | |
96 | + String suVersion = stdInput.readLine(); | |
97 | + return suVersion; | |
98 | + } else { | |
99 | + return " " + R.string.su_original; | |
100 | + } | |
101 | + } finally { | |
102 | + stdInput.close(); | |
103 | + } | |
92 | 104 | } catch (IOException e) { |
93 | 105 | Log.e(TAG, "Call to su failed. Perhaps the wrong version of su is present", e); |
94 | - return null; | |
95 | - } | |
106 | + return " " + R.string.su_original; | |
107 | + } catch (InterruptedException e) { | |
108 | + Log.e(TAG, "Call to su failed.", e); | |
109 | + return " ..."; | |
110 | + } | |
96 | 111 | } |
97 | 112 | } |
@@ -173,7 +173,9 @@ public class Updater { | ||
173 | 173 | |
174 | 174 | @Override |
175 | 175 | protected void onPostExecute(String result) { |
176 | - if (result.equals("manifest.json")) { | |
176 | + if (result == null) { | |
177 | + Toast.makeText(mContext, R.string.manifest_download_failed, Toast.LENGTH_SHORT).show(); | |
178 | + } else if (result.equals("manifest.json")) { | |
177 | 179 | postManifest(); |
178 | 180 | } else if (result.equals("su")) { |
179 | 181 | new AutoUpdateTask().execute(); |