Commit bf9b3f4f authored by Mygod's avatar Mygod

Hide root summary if rooted

parent 5f0b1a50
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
<string name="about">关于</string> <string name="about">关于</string>
<string name="about_title">影梭(shadowsocks)%s</string> <string name="about_title">影梭(shadowsocks)%s</string>
<string name="flush_dnscache">刷新 DNS 缓存</string> <string name="flush_dnscache">刷新 DNS 缓存</string>
<string name="flush_dnscache_summary">需要 ROOT 权限</string> <string name="flush_dnscache_summary_disabled">需要 ROOT 权限</string>
<string name="flushing">刷新中……</string> <string name="flushing">刷新中……</string>
<string name="qrcode">二维码</string> <string name="qrcode">二维码</string>
<string name="add_profile">添加配置文件</string> <string name="add_profile">添加配置文件</string>
......
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
<string name="about_title">Shadowsocks %s</string> <string name="about_title">Shadowsocks %s</string>
<string name="qrcode">QR Code</string> <string name="qrcode">QR Code</string>
<string name="flush_dnscache">Flush DNS cache</string> <string name="flush_dnscache">Flush DNS cache</string>
<string name="flush_dnscache_summary">Requires ROOT permission</string> <string name="flush_dnscache_summary_disabled">Requires ROOT permission</string>
<string name="flushing">Flushing</string> <string name="flushing">Flushing</string>
<string name="add_profile">Add Profile</string> <string name="add_profile">Add Profile</string>
<string name="action_export">Export to Clipboard</string> <string name="action_export">Export to Clipboard</string>
......
...@@ -104,8 +104,7 @@ ...@@ -104,8 +104,7 @@
android:summary="@string/nat_summary"/> android:summary="@string/nat_summary"/>
<Preference android:key="recovery" android:title="@string/recovery" <Preference android:key="recovery" android:title="@string/recovery"
android:summary="@string/recovery_summary"/> android:summary="@string/recovery_summary"/>
<Preference android:key="flush_dnscache" android:title="@string/flush_dnscache" <Preference android:key="flush_dnscache" android:title="@string/flush_dnscache"/>
android:summary="@string/flush_dnscache_summary"/>
<Preference android:key="about" android:title="@string/about"/> <Preference android:key="about" android:title="@string/about"/>
</PreferenceCategory> </PreferenceCategory>
......
...@@ -5,7 +5,7 @@ import java.util.Locale ...@@ -5,7 +5,7 @@ import java.util.Locale
import android.app.AlertDialog import android.app.AlertDialog
import android.content.{DialogInterface, Intent} import android.content.{DialogInterface, Intent}
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.{Build, Bundle}
import android.preference.{Preference, PreferenceFragment} import android.preference.{Preference, PreferenceFragment}
import android.webkit.{WebViewClient, WebView} import android.webkit.{WebViewClient, WebView}
import com.github.shadowsocks.utils.Key import com.github.shadowsocks.utils.Key
...@@ -30,7 +30,11 @@ class ShadowsocksSettings extends PreferenceFragment { ...@@ -30,7 +30,11 @@ class ShadowsocksSettings extends PreferenceFragment {
true true
}) })
findPreference("flush_dnscache").setOnPreferenceClickListener((preference: Preference) => { val flush = findPreference("flush_dnscache")
if (Build.VERSION.SDK_INT >= 17 && !ShadowsocksApplication.isRoot) {
flush.setEnabled(false)
flush.setSummary(R.string.flush_dnscache_summary_disabled)
} else flush.setOnPreferenceClickListener((preference: Preference) => {
ShadowsocksApplication.track(Shadowsocks.TAG, "flush_dnscache") ShadowsocksApplication.track(Shadowsocks.TAG, "flush_dnscache")
activity.flushDnsCache() activity.flushDnsCache()
true true
......
...@@ -55,7 +55,7 @@ import android.util.{DisplayMetrics, Base64, Log} ...@@ -55,7 +55,7 @@ import android.util.{DisplayMetrics, Base64, Log}
import android.view.View.MeasureSpec import android.view.View.MeasureSpec
import android.view.{Gravity, View, Window} import android.view.{Gravity, View, Window}
import android.widget.Toast import android.widget.Toast
import com.github.shadowsocks.BuildConfig import com.github.shadowsocks.{ShadowsocksApplication, BuildConfig}
import org.xbill.DNS._ import org.xbill.DNS._
...@@ -155,24 +155,13 @@ object Utils { ...@@ -155,24 +155,13 @@ object Utils {
// Blocked > 3 seconds // Blocked > 3 seconds
def toggleAirplaneMode(context: Context) { def toggleAirplaneMode(context: Context) {
if (Build.VERSION.SDK_INT >= 17) { if (ShadowsocksApplication.isRoot) {
toggleAboveApiLevel17() Console.runRootCommand(Array("ndc resolver flushdefaultif", "ndc resolver flushif wlan0"))
} else { } else if (Build.VERSION.SDK_INT < 17) {
toggleBelowApiLevel17(context) toggleBelowApiLevel17(context)
} }
} }
private def toggleAboveApiLevel17() {
// Android 4.2 and above
Console.runRootCommand(Array("ndc resolver flushdefaultif", "ndc resolver flushif wlan0"))
//Utils.runRootCommand("settings put global airplane_mode_on 1\n"
// + "am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true\n"
// + "settings put global airplane_mode_on 0\n"
// + "am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false\n")
}
//noinspection ScalaDeprecation //noinspection ScalaDeprecation
private def toggleBelowApiLevel17(context: Context) { private def toggleBelowApiLevel17(context: Context) {
// Android 4.2 below // Android 4.2 below
......
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