Commit 3d664377 authored by Max Lv's avatar Max Lv

clean up

parent a74c3fde
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" <item android:state_pressed="true"
android:drawable="@drawable/btn_cab_done_pressed_shadow" /> android:drawable="@drawable/btn_cab_done_pressed_shadow"/>
<item android:state_focused="true" android:state_enabled="true" <item android:state_focused="true" android:state_enabled="true"
android:drawable="@drawable/btn_cab_done_focused_shadow" /> android:drawable="@drawable/btn_cab_done_focused_shadow"/>
<item android:state_enabled="true" <item android:state_enabled="true"
android:drawable="@drawable/btn_cab_done_default_shadow" /> android:drawable="@drawable/btn_cab_done_default_shadow"/>
</selector> </selector>
...@@ -18,5 +18,5 @@ ...@@ -18,5 +18,5 @@
--> -->
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/pressed_shadow" /> <solid android:color="@color/pressed_shadow"/>
</shape> </shape>
...@@ -20,16 +20,16 @@ ...@@ -20,16 +20,16 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" <item android:id="@android:id/background"
android:drawable="@drawable/progress_bg_shadow" /> android:drawable="@drawable/progress_bg_shadow"/>
<item android:id="@android:id/secondaryProgress"> <item android:id="@android:id/secondaryProgress">
<scale android:scaleWidth="100%" <scale android:scaleWidth="100%"
android:drawable="@drawable/progress_secondary_shadow" /> android:drawable="@drawable/progress_secondary_shadow"/>
</item> </item>
<item android:id="@android:id/progress"> <item android:id="@android:id/progress">
<scale android:scaleWidth="100%" <scale android:scaleWidth="100%"
android:drawable="@drawable/progress_primary_shadow" /> android:drawable="@drawable/progress_primary_shadow"/>
</item> </item>
</layer-list> </layer-list>
...@@ -18,8 +18,9 @@ ...@@ -18,8 +18,9 @@
--> -->
<selector xmlns:android="http://schemas.android.com/apk/res/android" <selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_mediumAnimTime" > android:exitFadeDuration="@android:integer/config_mediumAnimTime">
<item android:state_pressed="false" android:state_focused="true" android:drawable="@drawable/list_focused_shadow" /> <item android:state_pressed="false" android:state_focused="true"
<item android:state_pressed="true" android:drawable="@drawable/pressed_background_shadow" /> android:drawable="@drawable/list_focused_shadow"/>
<item android:drawable="@android:color/transparent" /> <item android:state_pressed="true" android:drawable="@drawable/pressed_background_shadow"/>
<item android:drawable="@android:color/transparent"/>
</selector> </selector>
\ No newline at end of file
...@@ -19,10 +19,10 @@ ...@@ -19,10 +19,10 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" <item android:state_enabled="false"
android:drawable="@drawable/spinner_ab_disabled_shadow" /> android:drawable="@drawable/spinner_ab_disabled_shadow"/>
<item android:state_pressed="true" <item android:state_pressed="true"
android:drawable="@drawable/spinner_ab_pressed_shadow" /> android:drawable="@drawable/spinner_ab_pressed_shadow"/>
<item android:state_pressed="false" android:state_focused="true" <item android:state_pressed="false" android:state_focused="true"
android:drawable="@drawable/spinner_ab_focused_shadow" /> android:drawable="@drawable/spinner_ab_focused_shadow"/>
<item android:drawable="@drawable/spinner_ab_default_shadow" /> <item android:drawable="@drawable/spinner_ab_default_shadow"/>
</selector> </selector>
...@@ -19,19 +19,27 @@ ...@@ -19,19 +19,27 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states --> <!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@android:color/transparent" /> <item android:state_focused="false" android:state_selected="false" android:state_pressed="false"
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_shadow" /> android:drawable="@android:color/transparent"/>
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false"
android:drawable="@drawable/tab_selected_shadow"/>
<!-- Focused states --> <!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_focused_shadow" /> <item android:state_focused="true" android:state_selected="false" android:state_pressed="false"
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_focused_shadow" /> android:drawable="@drawable/tab_unselected_focused_shadow"/>
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false"
android:drawable="@drawable/tab_selected_focused_shadow"/>
<!-- Pressed --> <!-- Pressed -->
<!-- Non focused states --> <!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_shadow" /> <item android:state_focused="false" android:state_selected="false" android:state_pressed="true"
<item android:state_focused="false" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_shadow" /> android:drawable="@drawable/tab_unselected_pressed_shadow"/>
<item android:state_focused="false" android:state_selected="true" android:state_pressed="true"
android:drawable="@drawable/tab_selected_pressed_shadow"/>
<!-- Focused states --> <!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_shadow" /> <item android:state_focused="true" android:state_selected="false" android:state_pressed="true"
<item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_shadow" /> android:drawable="@drawable/tab_unselected_pressed_shadow"/>
<item android:state_focused="true" android:state_selected="true" android:state_pressed="true"
android:drawable="@drawable/tab_selected_pressed_shadow"/>
</selector> </selector>
...@@ -3,4 +3,4 @@ ...@@ -3,4 +3,4 @@
android:minWidth="80dp" android:maxWidth="80dp" android:gravity="center" android:minWidth="80dp" android:maxWidth="80dp" android:gravity="center"
android:textSize="70sp" android:textColor="#ffffffff" android:textSize="70sp" android:textColor="#ffffffff"
android:background="#99000088" android:padding="10dp" android:background="#99000088" android:padding="10dp"
android:visibility="invisible" /> android:visibility="invisible"/>
\ No newline at end of file \ No newline at end of file
...@@ -35,7 +35,8 @@ ...@@ -35,7 +35,8 @@
</style> </style>
<style name="ActionBar.Solid.Shadow" parent="@style/Widget.Sherlock.Light.ActionBar.Solid.Inverse"> <style name="ActionBar.Solid.Shadow"
parent="@style/Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:background">@drawable/ab_solid_shadow</item> <item name="android:background">@drawable/ab_solid_shadow</item>
<item name="android:backgroundStacked">@drawable/ab_stacked_solid_shadow</item> <item name="android:backgroundStacked">@drawable/ab_stacked_solid_shadow</item>
<item name="android:backgroundSplit">@drawable/ab_bottom_solid_shadow</item> <item name="android:backgroundSplit">@drawable/ab_bottom_solid_shadow</item>
......
...@@ -35,7 +35,8 @@ ...@@ -35,7 +35,8 @@
</style> </style>
<style name="ActionBar.Solid.Shadow" parent="@style/Widget.Sherlock.Light.ActionBar.Solid.Inverse"> <style name="ActionBar.Solid.Shadow"
parent="@style/Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="background">@drawable/ab_solid_shadow</item> <item name="background">@drawable/ab_solid_shadow</item>
<item name="backgroundStacked">@drawable/ab_stacked_solid_shadow</item> <item name="backgroundStacked">@drawable/ab_stacked_solid_shadow</item>
<item name="backgroundSplit">@drawable/ab_bottom_solid_shadow</item> <item name="backgroundSplit">@drawable/ab_bottom_solid_shadow</item>
...@@ -69,7 +70,8 @@ ...@@ -69,7 +70,8 @@
<item name="android:progressDrawable">@drawable/progress_horizontal_shadow</item> <item name="android:progressDrawable">@drawable/progress_horizontal_shadow</item>
</style> </style>
<style name="ActionButton.CloseMode.Shadow" parent="@style/Widget.Sherlock.ActionButton.CloseMode"> <style name="ActionButton.CloseMode.Shadow"
parent="@style/Widget.Sherlock.ActionButton.CloseMode">
<item name="android:background">@drawable/btn_cab_done_shadow</item> <item name="android:background">@drawable/btn_cab_done_shadow</item>
</style> </style>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android" <preference-headers
xmlns:unified="http://schemas.android.com/apk/res-auto"> xmlns:unified="http://schemas.android.com/apk/res-auto">
<header <header
......
This diff is collapsed.
...@@ -31,9 +31,7 @@ public class Exec { ...@@ -31,9 +31,7 @@ public class Exec {
java.lang.System.loadLibrary("exec"); java.lang.System.loadLibrary("exec");
} }
/** /** Close a given file descriptor. */
* Close a given file descriptor.
*/
public static native void close(FileDescriptor fd); public static native void close(FileDescriptor fd);
/** /**
...@@ -53,13 +51,10 @@ public class Exec { ...@@ -53,13 +51,10 @@ public class Exec {
* process will be written. * process will be written.
* @return File descriptor * @return File descriptor
*/ */
public static native FileDescriptor createSubprocess(int rdt, String cmd, public static native FileDescriptor createSubprocess(int rdt, String cmd, String[] args,
String[] args, String[] envVars, String[] envVars, String scripts, int[] processId);
String scripts, int[] processId);
/** /** Send SIGHUP to a process group. */
* Send SIGHUP to a process group.
*/
public static native void hangupProcessGroup(int processId); public static native void hangupProcessGroup(int processId);
/** /**
......
...@@ -45,7 +45,6 @@ import android.graphics.Bitmap; ...@@ -45,7 +45,6 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.widget.ImageView; import android.widget.ImageView;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
...@@ -72,7 +71,6 @@ public class ImageLoader { ...@@ -72,7 +71,6 @@ public class ImageLoader {
// Find the dir to save cached images // Find the dir to save cached images
cacheDir = context.getCacheDir(); cacheDir = context.getCacheDir();
} }
public void clearCache() { public void clearCache() {
...@@ -98,9 +96,7 @@ public class ImageLoader { ...@@ -98,9 +96,7 @@ public class ImageLoader {
int width_tmp = o.outWidth, height_tmp = o.outHeight; int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 1; int scale = 1;
while (true) { while (true) {
if (width_tmp / 2 < REQUIRED_SIZE if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE) break;
|| height_tmp / 2 < REQUIRED_SIZE)
break;
width_tmp /= 2; width_tmp /= 2;
height_tmp /= 2; height_tmp /= 2;
scale *= 2; scale *= 2;
...@@ -116,9 +112,9 @@ public class ImageLoader { ...@@ -116,9 +112,9 @@ public class ImageLoader {
} }
public void DisplayImage(int uid, Activity activity, ImageView imageView) { public void DisplayImage(int uid, Activity activity, ImageView imageView) {
if (cache.containsKey(uid)) if (cache.containsKey(uid)) {
imageView.setImageBitmap(cache.get(uid)); imageView.setImageBitmap(cache.get(uid));
else { } else {
queuePhoto(uid, activity, imageView); queuePhoto(uid, activity, imageView);
imageView.setImageResource(stub_id); imageView.setImageResource(stub_id);
} }
...@@ -132,13 +128,11 @@ public class ImageLoader { ...@@ -132,13 +128,11 @@ public class ImageLoader {
// from SD cache // from SD cache
Bitmap b = decodeFile(f); Bitmap b = decodeFile(f);
if (b != null) if (b != null) return b;
return b;
// from web // from web
try { try {
BitmapDrawable icon = (BitmapDrawable) Utils.getAppIcon(context, BitmapDrawable icon = (BitmapDrawable) Utils.getAppIcon(context, uid);
uid);
return icon.getBitmap(); return icon.getBitmap();
} catch (Exception ex) { } catch (Exception ex) {
return null; return null;
...@@ -156,8 +150,7 @@ public class ImageLoader { ...@@ -156,8 +150,7 @@ public class ImageLoader {
} }
// start thread if it's not started yet // start thread if it's not started yet
if (photoLoaderThread.getState() == Thread.State.NEW) if (photoLoaderThread.getState() == Thread.State.NEW) photoLoaderThread.start();
photoLoaderThread.start();
} }
public void stopThread() { public void stopThread() {
...@@ -176,12 +169,13 @@ public class ImageLoader { ...@@ -176,12 +169,13 @@ public class ImageLoader {
@Override @Override
public void run() { public void run() {
if (bitmap != null) if (bitmap != null) {
imageView.setImageBitmap(bitmap); imageView.setImageBitmap(bitmap);
else } else {
imageView.setImageResource(stub_id); imageView.setImageResource(stub_id);
} }
} }
}
class PhotosLoader extends Thread { class PhotosLoader extends Thread {
@Override @Override
...@@ -190,10 +184,11 @@ public class ImageLoader { ...@@ -190,10 +184,11 @@ public class ImageLoader {
while (true) { while (true) {
// thread waits until there are any images to load in the // thread waits until there are any images to load in the
// queue // queue
if (photosQueue.photosToLoad.size() == 0) if (photosQueue.photosToLoad.size() == 0) {
synchronized (photosQueue.photosToLoad) { synchronized (photosQueue.photosToLoad) {
photosQueue.photosToLoad.wait(); photosQueue.photosToLoad.wait();
} }
}
if (photosQueue.photosToLoad.size() != 0) { if (photosQueue.photosToLoad.size() != 0) {
PhotoToLoad photoToLoad; PhotoToLoad photoToLoad;
synchronized (photosQueue.photosToLoad) { synchronized (photosQueue.photosToLoad) {
...@@ -203,15 +198,12 @@ public class ImageLoader { ...@@ -203,15 +198,12 @@ public class ImageLoader {
cache.put(photoToLoad.uid, bmp); cache.put(photoToLoad.uid, bmp);
Object tag = photoToLoad.imageView.getTag(); Object tag = photoToLoad.imageView.getTag();
if (tag != null && ((Integer) tag) == photoToLoad.uid) { if (tag != null && ((Integer) tag) == photoToLoad.uid) {
BitmapDisplayer bd = new BitmapDisplayer(bmp, BitmapDisplayer bd = new BitmapDisplayer(bmp, photoToLoad.imageView);
photoToLoad.imageView); Activity a = (Activity) photoToLoad.imageView.getContext();
Activity a = (Activity) photoToLoad.imageView
.getContext();
a.runOnUiThread(bd); a.runOnUiThread(bd);
} }
} }
if (Thread.interrupted()) if (Thread.interrupted()) break;
break;
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
// allow thread to exit // allow thread to exit
...@@ -227,8 +219,11 @@ public class ImageLoader { ...@@ -227,8 +219,11 @@ public class ImageLoader {
public void Clean(ImageView image) { public void Clean(ImageView image) {
synchronized (photosToLoad) { synchronized (photosToLoad) {
for (int j = 0; j < photosToLoad.size(); ) { for (int j = 0; j < photosToLoad.size(); ) {
if (photosToLoad.get(j).imageView == image) photosToLoad.remove(j); if (photosToLoad.get(j).imageView == image) {
else ++j; photosToLoad.remove(j);
} else {
++j;
}
} }
} }
} }
...@@ -244,5 +239,4 @@ public class ImageLoader { ...@@ -244,5 +239,4 @@ public class ImageLoader {
imageView = i; imageView = i;
} }
} }
} }
...@@ -47,86 +47,62 @@ public class ProxyedApp { ...@@ -47,86 +47,62 @@ public class ProxyedApp {
private String name; private String name;
private boolean proxyed = false; private boolean proxyed = false;
/** /** @return the name */
* @return the name
*/
public String getName() { public String getName() {
return name; return name;
} }
/** /** @param name the name to set */
* @param name the name to set
*/
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
/** /** @return the procname */
* @return the procname
*/
public String getProcname() { public String getProcname() {
return procname; return procname;
} }
/** /** @param procname the procname to set */
* @param procname the procname to set
*/
public void setProcname(String procname) { public void setProcname(String procname) {
this.procname = procname; this.procname = procname;
} }
/** /** @return the uid */
* @return the uid
*/
public int getUid() { public int getUid() {
return uid; return uid;
} }
/** /** @param uid the uid to set */
* @param uid the uid to set
*/
public void setUid(int uid) { public void setUid(int uid) {
this.uid = uid; this.uid = uid;
} }
/** /** @return the username */
* @return the username
*/
public String getUsername() { public String getUsername() {
return username; return username;
} }
/** /** @param username the username to set */
* @param username the username to set
*/
public void setUsername(String username) { public void setUsername(String username) {
this.username = username; this.username = username;
} }
/** /** @return the enabled */
* @return the enabled
*/
public boolean isEnabled() { public boolean isEnabled() {
return enabled; return enabled;
} }
/** /** @param enabled the enabled to set */
* @param enabled the enabled to set
*/
public void setEnabled(boolean enabled) { public void setEnabled(boolean enabled) {
this.enabled = enabled; this.enabled = enabled;
} }
/** /** @return the proxyed */
* @return the proxyed
*/
public boolean isProxyed() { public boolean isProxyed() {
return proxyed; return proxyed;
} }
/** /** @param proxyed the proxyed to set */
* @param proxyed the proxyed to set
*/
public void setProxyed(boolean proxyed) { public void setProxyed(boolean proxyed) {
this.proxyed = proxyed; this.proxyed = proxyed;
} }
......
This diff is collapsed.
...@@ -54,5 +54,4 @@ public class ShadowsocksApplication extends Application { ...@@ -54,5 +54,4 @@ public class ShadowsocksApplication extends Application {
EasyTracker.getInstance().setContext(this); EasyTracker.getInstance().setContext(this);
sTmpDir = getCacheDir().getAbsolutePath(); sTmpDir = getCacheDir().getAbsolutePath();
} }
} }
...@@ -63,7 +63,8 @@ public class ShadowsocksReceiver extends BroadcastReceiver { ...@@ -63,7 +63,8 @@ public class ShadowsocksReceiver extends BroadcastReceiver {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
String versionName; String versionName;
try { try {
versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; versionName =
context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
versionName = "NONE"; versionName = "NONE";
} }
...@@ -89,5 +90,4 @@ public class ShadowsocksReceiver extends BroadcastReceiver { ...@@ -89,5 +90,4 @@ public class ShadowsocksReceiver extends BroadcastReceiver {
context.startService(it); context.startService(it);
} }
} }
} }
...@@ -45,14 +45,19 @@ import android.content.pm.PackageManager.NameNotFoundException; ...@@ -45,14 +45,19 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Environment; import android.os.Environment;
import android.util.Log; import android.util.Log;
import org.apache.http.conn.util.InetAddressUtils; import java.io.BufferedReader;
import java.io.File;
import java.io.*; import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.apache.http.conn.util.InetAddressUtils;
public class Utils { public class Utils {
...@@ -76,9 +81,7 @@ public class Utils { ...@@ -76,9 +81,7 @@ public class Utils {
private static String iptables = null; private static String iptables = null;
private static String data_path = null; private static String data_path = null;
/** /** Get IP address from first non-localhost interface */
* Get IP address from first non-localhost interface
*/
public static boolean isIPv6Support() { public static boolean isIPv6Support() {
try { try {
List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
...@@ -158,13 +161,11 @@ public class Utils { ...@@ -158,13 +161,11 @@ public class Utils {
boolean version = false; boolean version = false;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String command = iptables + " --version\n" + iptables String command = iptables + " --version\n" + iptables + " -L -t nat -n\n" + "exit\n";
+ " -L -t nat -n\n" + "exit\n";
int exitcode = runScript(command, sb, 10 * 1000, true); int exitcode = runScript(command, sb, 10 * 1000, true);
if (exitcode == TIME_OUT) if (exitcode == TIME_OUT) return;
return;
lines = sb.toString(); lines = sb.toString();
...@@ -177,27 +178,22 @@ public class Utils { ...@@ -177,27 +178,22 @@ public class Utils {
if (!compatible || !version) { if (!compatible || !version) {
iptables = ALTERNATIVE_IPTABLES; iptables = ALTERNATIVE_IPTABLES;
if (!new File(iptables).exists()) if (!new File(iptables).exists()) iptables = "iptables";
iptables = "iptables";
} }
} }
public static Drawable getAppIcon(Context c, int uid) { public static Drawable getAppIcon(Context c, int uid) {
PackageManager pm = c.getPackageManager(); PackageManager pm = c.getPackageManager();
Drawable appIcon = c.getResources().getDrawable( Drawable appIcon = c.getResources().getDrawable(android.R.drawable.sym_def_app_icon);
android.R.drawable.sym_def_app_icon);
String[] packages = pm.getPackagesForUid(uid); String[] packages = pm.getPackagesForUid(uid);
if (packages != null) { if (packages != null) {
if (packages.length == 1) { if (packages.length == 1) {
try { try {
ApplicationInfo appInfo = pm.getApplicationInfo( ApplicationInfo appInfo = pm.getApplicationInfo(packages[0], 0);
packages[0], 0);
appIcon = pm.getApplicationIcon(appInfo); appIcon = pm.getApplicationIcon(appInfo);
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
Log.e(c.getPackageName(), Log.e(c.getPackageName(), "No package found matching with the uid " + uid);
"No package found matching with the uid " + uid);
} }
} }
} else { } else {
...@@ -211,10 +207,8 @@ public class Utils { ...@@ -211,10 +207,8 @@ public class Utils {
if (data_path == null) { if (data_path == null) {
if (Environment.MEDIA_MOUNTED.equals(Environment if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
.getExternalStorageState())) { data_path = Environment.getExternalStorageDirectory().getAbsolutePath();
data_path = Environment.getExternalStorageDirectory()
.getAbsolutePath();
} else { } else {
data_path = ctx.getFilesDir().getAbsolutePath(); data_path = ctx.getFilesDir().getAbsolutePath();
} }
...@@ -226,34 +220,30 @@ public class Utils { ...@@ -226,34 +220,30 @@ public class Utils {
} }
public static boolean getHasRedirectSupport() { public static boolean getHasRedirectSupport() {
if (hasRedirectSupport == -1) if (hasRedirectSupport == -1) initHasRedirectSupported();
initHasRedirectSupported();
return hasRedirectSupport == 1; return hasRedirectSupport == 1;
} }
public static String getIptables() { public static String getIptables() {
if (iptables == null) if (iptables == null) checkIptables();
checkIptables();
return iptables; return iptables;
} }
private static String getShell() { private static String getShell() {
if (shell == null) { if (shell == null) {
shell = DEFAULT_SHELL; shell = DEFAULT_SHELL;
if (!new File(shell).exists()) if (!new File(shell).exists()) shell = "sh";
shell = "sh";
} }
return shell; return shell;
} }
public static void initHasRedirectSupported() { public static void initHasRedirectSupported() {
if (!Utils.isRoot()) if (!Utils.isRoot()) return;
return;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String command = Utils.getIptables() String command =
+ " -t nat -A OUTPUT -p udp --dport 54 -j REDIRECT --to 8154"; Utils.getIptables() + " -t nat -A OUTPUT -p udp --dport 54 -j REDIRECT --to 8154";
int exitcode = runScript(command, sb, 10 * 1000, true); int exitcode = runScript(command, sb, 10 * 1000, true);
...@@ -264,8 +254,7 @@ public class Utils { ...@@ -264,8 +254,7 @@ public class Utils {
// flush the check command // flush the check command
Utils.runRootCommand(command.replace("-A", "-D")); Utils.runRootCommand(command.replace("-A", "-D"));
if (exitcode == TIME_OUT) if (exitcode == TIME_OUT) return;
return;
if (lines.contains("No chain/target/match")) { if (lines.contains("No chain/target/match")) {
hasRedirectSupport = 0; hasRedirectSupport = 0;
...@@ -273,19 +262,17 @@ public class Utils { ...@@ -273,19 +262,17 @@ public class Utils {
} }
public static boolean isInitialized() { public static boolean isInitialized() {
if (initialized) if (initialized) {
return true; return true;
else { } else {
initialized = true; initialized = true;
return false; return false;
} }
} }
public static boolean isRoot() { public static boolean isRoot() {
if (isRoot != -1) if (isRoot != -1) return isRoot == 1;
return isRoot == 1;
// switch between binaries // switch between binaries
if (new File(DEFAULT_ROOT).exists()) { if (new File(DEFAULT_ROOT).exists()) {
...@@ -319,7 +306,6 @@ public class Utils { ...@@ -319,7 +306,6 @@ public class Utils {
public static boolean runCommand(String command) { public static boolean runCommand(String command) {
return runCommand(command, 10 * 1000); return runCommand(command, 10 * 1000);
} }
public static boolean runCommand(String command, int timeout) { public static boolean runCommand(String command, int timeout) {
...@@ -334,7 +320,6 @@ public class Utils { ...@@ -334,7 +320,6 @@ public class Utils {
public static boolean runRootCommand(String command) { public static boolean runRootCommand(String command) {
return runRootCommand(command, 10 * 1000); return runRootCommand(command, 10 * 1000);
} }
public static boolean runRootCommand(String command, int timeout) { public static boolean runRootCommand(String command, int timeout) {
...@@ -351,8 +336,8 @@ public class Utils { ...@@ -351,8 +336,8 @@ public class Utils {
return true; return true;
} }
private synchronized static int runScript(String script, StringBuilder result, private synchronized static int runScript(String script, StringBuilder result, long timeout,
long timeout, boolean asroot) { boolean asroot) {
final ScriptRunner runner = new ScriptRunner(script, result, asroot); final ScriptRunner runner = new ScriptRunner(script, result, asroot);
runner.start(); runner.start();
try { try {
...@@ -373,9 +358,7 @@ public class Utils { ...@@ -373,9 +358,7 @@ public class Utils {
return runner.exitcode; return runner.exitcode;
} }
/** /** Internal thread used to execute scripts (as root or not). */
* Internal thread used to execute scripts (as root or not).
*/
private static final class ScriptRunner extends Thread { private static final class ScriptRunner extends Thread {
private final String scripts; private final String scripts;
private final StringBuilder result; private final StringBuilder result;
...@@ -404,8 +387,7 @@ public class Utils { ...@@ -404,8 +387,7 @@ public class Utils {
* @param result result output * @param result result output
* @param asroot if true, executes the script as root * @param asroot if true, executes the script as root
*/ */
public ScriptRunner(String script, StringBuilder result, public ScriptRunner(String script, StringBuilder result, boolean asroot) {
boolean asroot) {
this.scripts = script; this.scripts = script;
this.result = result; this.result = result;
this.asroot = asroot; this.asroot = asroot;
...@@ -416,8 +398,8 @@ public class Utils { ...@@ -416,8 +398,8 @@ public class Utils {
String arg0 = argList.get(0); String arg0 = argList.get(0);
String[] args = argList.toArray(new String[1]); String[] args = argList.toArray(new String[1]);
return Exec.createSubprocess(result != null ? 1 : 0, arg0, args, null, return Exec.createSubprocess(result != null ? 1 : 0, arg0, args, null, scripts + "\nexit\n",
scripts + "\nexit\n", processId); processId);
} }
private ArrayList<String> parse(String cmd) { private ArrayList<String> parse(String cmd) {
...@@ -497,11 +479,9 @@ public class Utils { ...@@ -497,11 +479,9 @@ public class Utils {
read = stdout.read(buf); read = stdout.read(buf);
result.append(new String(buf, 0, read)); result.append(new String(buf, 0, read));
} }
} catch (Exception ex) { } catch (Exception ex) {
Log.e(TAG, "Cannot execute command", ex); Log.e(TAG, "Cannot execute command", ex);
if (result != null) if (result != null) result.append("\n").append(ex);
result.append("\n").append(ex);
} finally { } finally {
if (pipe != null) { if (pipe != null) {
Exec.close(pipe); Exec.close(pipe);
......
...@@ -3,7 +3,6 @@ package com.github.shadowsocks.preferences; ...@@ -3,7 +3,6 @@ package com.github.shadowsocks.preferences;
import android.content.Context; import android.content.Context;
import android.preference.EditTextPreference; import android.preference.EditTextPreference;
import android.util.AttributeSet; import android.util.AttributeSet;
import com.github.shadowsocks.R;
public class SummaryEditTextPreference extends EditTextPreference { public class SummaryEditTextPreference extends EditTextPreference {
...@@ -24,15 +23,11 @@ public class SummaryEditTextPreference extends EditTextPreference { ...@@ -24,15 +23,11 @@ public class SummaryEditTextPreference extends EditTextPreference {
} }
@Override @Override
public void onDialogClosed(boolean positiveResult) { public void setSummary(CharSequence summary) {
super.onDialogClosed(positiveResult); if (summary.toString().isEmpty()) {
if (positiveResult) { super.setSummary(mDefaultSummary);
String value = getEditText().getText().toString();
if (value.isEmpty()) {
setSummary(mDefaultSummary);
} else { } else {
setSummary(value); super.setSummary(summary);
}
} }
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment