当前位置: 首页>>代码示例>>Scala>>正文


Scala Shell类代码示例

本文整理汇总了Scala中eu.chainfire.libsuperuser.Shell的典型用法代码示例。如果您正苦于以下问题:Scala Shell类的具体用法?Scala Shell怎么用?Scala Shell使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Shell类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: sendEnabled

//设置package包名称以及导入依赖的类
package com.github.shadowsocks.utils

import java.io.File

import eu.chainfire.libsuperuser.Shell

import scala.collection.JavaConverters._


  lazy val supported = "^(\\d+)\\.(\\d+)\\.(\\d+)".r.findFirstMatchIn(System.getProperty("os.version")) match {
    case Some(m) =>
      val kernel = m.group(1).toInt
      if (kernel < 3) false else if (kernel > 3) true else {
        val major = m.group(2).toInt
        if (major < 7) false else if (major > 7) true else m.group(3).toInt >= 1
      }
    case _ => false
  }

  def sendEnabled = {
    val file = new File("/proc/sys/net/ipv4/tcp_fastopen")
    file.canRead && (Utils.readAllLines(file).toInt & 1) > 0
  }

  def enabled(value: Boolean): String = if (sendEnabled != value) {
    val res = Shell.run("su", Array(
      "if echo " + (if (value) 3 else 0) + " > /proc/sys/net/ipv4/tcp_fastopen; then",
      "  echo Success.",
      "else",
      "  echo Failed.",
      "fi"), null, true)
    if (res != null) res.asScala.mkString("\n") else null
  } else null
} 
开发者ID:RoomArchitect,项目名称:test0000,代码行数:35,代码来源:TcpFastOpen.scala

示例2: KcpCliPreferenceDialogFragment

//设置package包名称以及导入依赖的类
package com.github.shadowsocks.preferences

import android.app.AlertDialog
import android.content.DialogInterface
import eu.chainfire.libsuperuser.Shell
import be.mygod.preference.EditTextPreferenceDialogFragment

import scala.collection.JavaConverters._


class KcpCliPreferenceDialogFragment extends EditTextPreferenceDialogFragment {
  override def onPrepareDialogBuilder(builder: AlertDialog.Builder) {
    super.onPrepareDialogBuilder(builder)
    builder.setNeutralButton("?", ((_, _) => new AlertDialog.Builder(builder.getContext)
      .setTitle("?")
      .setMessage(Shell.SH.run(builder.getContext.getApplicationInfo.dataDir + "/kcptun --help")
        .asScala
        .dropWhile(line => line != "GLOBAL OPTIONS:")
        .drop(1)
        .takeWhile(line => line.length() > 3)
        .filter(line =>
          !line.startsWith("   --localaddr ") &&
          !line.startsWith("   --remoteaddr ") &&
          !line.startsWith("   --path ") &&
          !line.startsWith("   --help,") &&
          !line.startsWith("   --version,"))
        .mkString("\n")
        .replaceAll(" {2,}", "\n")
        .substring(1))  // remove 1st \n
      .show()): DialogInterface.OnClickListener)
  }
} 
开发者ID:RoomArchitect,项目名称:test0000,代码行数:33,代码来源:KcpCliPreferenceDialogFragment.scala

示例3: sendEnabled

//设置package包名称以及导入依赖的类
package com.github.shadowsocks.utils

import java.io.File

import eu.chainfire.libsuperuser.Shell

import scala.collection.JavaConverters._


  lazy val supported = "^(\\d+)\\.(\\d+)\\.(\\d+)".r.findFirstMatchIn(System.getProperty("os.version")) match {
    case Some(m) =>
      val kernel = m.group(1).toInt
      if (kernel < 3) false else if (kernel > 3) true else {
        val major = m.group(2).toInt
        if (major < 7) false else if (major > 7) true else m.group(3).toInt >= 1
      }
    case _ => false
  }

  def sendEnabled = {
    val file = new File("/proc/sys/net/ipv4/tcp_fastopen")
    file.canRead && (Utils.readAllLines(file).toInt & 1) > 0
  }

  def enabled(value: Boolean): String = if (sendEnabled != value) {
    val suAvailable = Shell.SU.available();
    if (suAvailable == true) {
      val res = Shell.run("su", Array(
        "if echo " + (if (value) 3 else 0) + " > /proc/sys/net/ipv4/tcp_fastopen; then",
        "  echo Success.",
        "else",
        "  echo Failed.",
        "fi"), null, true)
      if (res != null) res.asScala.mkString("\n") else null
    } else null
  } else null
} 
开发者ID:wfjsw,项目名称:shadowsocksr-android-with-patches,代码行数:38,代码来源:TcpFastOpen.scala


注:本文中的eu.chainfire.libsuperuser.Shell类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。