Hide root summary if rooted

This commit is contained in:
Mygod
2015-11-09 17:42:02 +08:00
parent 5f0b1a50b2
commit bf9b3f4fde
5 changed files with 13 additions and 21 deletions
@@ -5,7 +5,7 @@ import java.util.Locale
import android.app.AlertDialog
import android.content.{DialogInterface, Intent}
import android.net.Uri
import android.os.Bundle
import android.os.{Build, Bundle}
import android.preference.{Preference, PreferenceFragment}
import android.webkit.{WebViewClient, WebView}
import com.github.shadowsocks.utils.Key
@@ -30,7 +30,11 @@ class ShadowsocksSettings extends PreferenceFragment {
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")
activity.flushDnsCache()
true
@@ -55,7 +55,7 @@ import android.util.{DisplayMetrics, Base64, Log}
import android.view.View.MeasureSpec
import android.view.{Gravity, View, Window}
import android.widget.Toast
import com.github.shadowsocks.BuildConfig
import com.github.shadowsocks.{ShadowsocksApplication, BuildConfig}
import org.xbill.DNS._
@@ -155,24 +155,13 @@ object Utils {
// Blocked > 3 seconds
def toggleAirplaneMode(context: Context) {
if (Build.VERSION.SDK_INT >= 17) {
toggleAboveApiLevel17()
} else {
if (ShadowsocksApplication.isRoot) {
Console.runRootCommand(Array("ndc resolver flushdefaultif", "ndc resolver flushif wlan0"))
} else if (Build.VERSION.SDK_INT < 17) {
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
private def toggleBelowApiLevel17(context: Context) {
// Android 4.2 below