This commit is contained in:
hyb1996
2017-05-06 21:42:18 +08:00
parent ed2ebe1599
commit 840bb56528
83 changed files with 110 additions and 442 deletions

View File

@@ -9,10 +9,13 @@ android {
applicationId "com.stardust.scriptdroid" applicationId "com.stardust.scriptdroid"
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 23 targetSdkVersion 23
versionCode 120 versionCode 121
versionName "2.0.9 Beta" versionName "2.0.9b Beta"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true multiDexEnabled true
ndk {
abiFilters 'armeabi-v7a'
}
} }
buildTypes { buildTypes {
release { release {
@@ -62,7 +65,7 @@ android {
enableForInstantRun = false enableForInstantRun = false
teamCitySlug = null teamCitySlug = null
runOnEachAssemble = true runOnEachAssemble = true
maxMethodCount = 64000 maxMethodCount = 128000
} }
configurations.all { configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1' resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1'

View File

@@ -55,7 +55,7 @@ public class AccessibilityServiceTool {
public static boolean enableAccessibilityServiceByRoot(Class<? extends AccessibilityService> accessibilityService) { public static boolean enableAccessibilityServiceByRoot(Class<? extends AccessibilityService> accessibilityService) {
String serviceName = App.getApp().getPackageName() + "/" + accessibilityService.getName(); String serviceName = App.getApp().getPackageName() + "/" + accessibilityService.getName();
return TextUtils.isEmpty(ProcessShell.exec(String.format(Locale.getDefault(), cmd, serviceName), true).error); return TextUtils.isEmpty(ProcessShell.execCommand(String.format(Locale.getDefault(), cmd, serviceName), true).error);
} }
public static boolean enableAccessibilityServiceByRootAndWaitFor(long timeOut) { public static boolean enableAccessibilityServiceByRootAndWaitFor(long timeOut) {

View File

@@ -2,6 +2,7 @@ package com.stardust.scriptdroid.ui.main.script_list;
import android.content.Context; import android.content.Context;
import android.os.Build; import android.os.Build;
import android.os.Parcelable;
import android.support.annotation.AttrRes; import android.support.annotation.AttrRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@@ -104,4 +105,16 @@ public class ScriptListWithProgressBarView extends FrameLayout {
public void setCurrentDirectory(ScriptFile directory) { public void setCurrentDirectory(ScriptFile directory) {
mScriptAndFolderListRecyclerView.setCurrentDirectory(directory); mScriptAndFolderListRecyclerView.setCurrentDirectory(directory);
} }
@Override
protected void onRestoreInstanceState(Parcelable state) {
super.onRestoreInstanceState(state);
//in some phones, SwipeRefreshLayout will keep refreshing after screen orientation change
mSwipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
mSwipeRefreshLayout.setRefreshing(false);
}
});
}
} }

View File

@@ -43,7 +43,11 @@ public class TaskListRecyclerView extends ThemeColorRecyclerView implements Java
@Override @Override
public void onClick(View v) { public void onClick(View v) {
int position = getChildViewHolder((View) v.getParent()).getAdapterPosition(); int position = getChildViewHolder((View) v.getParent()).getAdapterPosition();
mScriptEngines.get(position).forceStop(); if(position >= 0){
mScriptEngines.get(position).forceStop();
}else {
updateEngineList();
}
} }
}; };

Binary file not shown.

After

Width:  |  Height:  |  Size: 548 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 810 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 131 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 194 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 616 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 924 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 180 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 265 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 307 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="ring"
android:thicknessRatio="2"
android:useLevel="false">
<solid android:color="@android:color/white"/>
</shape>

View File

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="ring"
android:thicknessRatio="2"
android:useLevel="false">
<solid android:color="@color/colorPrimary"/>
</shape>

View File

@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="ring"
android:thicknessRatio="2"
android:useLevel="false">
<solid android:color="@android:color/white"/>
<stroke
android:width="1dp"
android:color="@android:color/black"/>
</shape>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 227 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 965 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 546 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 457 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 353 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 608 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 835 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#42000000"/>
<corners android:radius="5dp"/>
</shape>

View File

@@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:clipOrientation="vertical"
android:drawable="@drawable/toolbar_bg"
android:gravity="top"/>

View File

@@ -1,19 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="?selectableItemBackground"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingLeft="36dp"
android:paddingRight="16dp"
android:textColor="#444444"
android:textSize="16sp">
<TextView
android:id="@+id/clip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"/>
</LinearLayout>

View File

@@ -79,7 +79,7 @@
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:padding="6dp" android:padding="6dp"
android:src="@drawable/ic_settings_applications_green_48dp"/> android:src="@drawable/ic_settings"/>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -102,7 +102,7 @@
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:padding="6dp" android:padding="6dp"
android:src="@drawable/ic_exit_to_app_green_48dp"/> android:src="@drawable/ic_exit"/>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -9,5 +9,5 @@
android:layout_width="46dp" android:layout_width="46dp"
android:layout_height="46dp" android:layout_height="46dp"
android:padding="5dp" android:padding="5dp"
android:src="@drawable/debug_console_icon_128"/> android:src="@drawable/ic_debug_console"/>
</LinearLayout> </LinearLayout>

View File

@@ -1,34 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingBottom="10dp">
<android.support.design.widget.TabLayout
android:id="@+id/tab"
android:layout_width="match_parent"
android:layout_height="48dp"
app:tabGravity="fill"
app:tabIndicatorColor="@color/colorAccent"
app:tabMode="fixed"
app:tabSelectedTextColor="@android:color/primary_text_dark"
app:tabTextColor="#c4c4c4"
tools:background="@color/colorPrimary"/>
</FrameLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</LinearLayout>

View File

@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/attr"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

View File

@@ -1,118 +0,0 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="64dp"
android:background="@android:color/white"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_margin="8dp"
android:src="@drawable/ic_android_eat_js"/>
<LinearLayout
android:id="@+id/start_or_pause"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:background="@drawable/btn_selector"
android:clickable="true"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="4dp">
<ImageView
android:id="@+id/img_start_or_pause"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_play_arrow_grey600_48dp"/>
<TextView
android:id="@+id/text_start_or_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/text_start_record"
android:textColor="#777777"
android:textSize="12sp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/stop"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:background="@drawable/btn_selector"
android:clickable="true"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="4dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_stop_grey600_48dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/text_stop_record"
android:textColor="#777777"
android:textSize="12sp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/redo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:background="@drawable/btn_selector"
android:clickable="true"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="4dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:padding="5dp"
android:src="@drawable/ic_redo_gray600"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/text_re_record"
android:textColor="#777777"
android:textSize="12sp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:background="@drawable/btn_selector"
android:clickable="true"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="4dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_close_gray600_48dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/text_close"
android:textColor="#777777"
android:textSize="12sp"/>
</LinearLayout>
</LinearLayout>

View File

@@ -1,89 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:selectableItemBackground"
android:orientation="vertical"
android:paddingBottom="8dp"
android:paddingLeft="12dp"
android:paddingTop="8dp">
<ImageView
android:id="@+id/icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:contentDescription="@string/_app_name"
android:scaleType="fitCenter"
android:src="@drawable/ic_node_js_black"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="56dp"
android:layout_marginRight="80dp"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@android:color/primary_text_light"
android:textSize="18sp"
tools:text="正在运行的服务"/>
<TextView
android:id="@+id/path"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:ellipsize="end"
android:maxLines="1"
android:textColor="#777777"
android:textSize="14sp"
tools:text="/storage/emulated/0/脚本/正在运行的服务.txt"/>
</LinearLayout>
<FrameLayout
android:id="@+id/run"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="52dp"
android:background="?attr/selectableItemBackgroundBorderless">
<ImageView
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_gravity="center"
android:contentDescription="@string/_app_name"
android:src="@drawable/ic_ali_run"/>
</FrameLayout>
<FrameLayout
android:id="@+id/edit"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_alignParentRight="true"
android:layout_marginRight="8dp"
android:layout_centerVertical="true"
android:background="?attr/selectableItemBackgroundBorderless">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center"
android:contentDescription="@string/_app_name"
android:src="@drawable/ic_ali_edit"/>
</FrameLayout>
</RelativeLayout>

View File

@@ -9,16 +9,10 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/sliding_up_panel_shadow_color"/> android:background="@color/sliding_up_panel_shadow_color"/>
<RelativeLayout <FrameLayout
android:id="@+id/content_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
<FrameLayout
android:id="@+id/content_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</FrameLayout> </FrameLayout>

View File

@@ -1,6 +0,0 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.stardust.scriptdroid.ui.main.MainActivity">
</menu>

View File

@@ -1,13 +1,9 @@
<resources> <resources>
<string name="_app_name">AutoJs</string> <string name="_app_name">AutoJs</string>
<string name="action_settings">Settings</string> <string name="action_settings">Settings</string>
<string name="action_disable_service">Disable Service</string>
<string name="text_accessibility_service_description">Required by the script automatic operation (click, long press, slide, etc.).</string> <string name="text_accessibility_service_description">Required by the script automatic operation (click, long press, slide, etc.).</string>
<string name="text_new_file">New File</string> <string name="text_new_file">New File</string>
<string name="text_import_from_file">Import File</string> <string name="text_import_from_file">Import File</string>
<string name="action_exit">Exit</string>
<string name="text_service_disabled">Service disabled.</string>
<string name="text_file_manager_not_found">No file explorer T.T</string>
<string name="text_create_fail">Creation failed</string> <string name="text_create_fail">Creation failed</string>
<string name="text_please_input_name">Input name</string> <string name="text_please_input_name">Input name</string>
<string name="text_name">Name</string> <string name="text_name">Name</string>
@@ -41,11 +37,9 @@
<string name="github">Source Code</string> <string name="github">Source Code</string>
<string name="text_already_copy_to_clip">Copied</string> <string name="text_already_copy_to_clip">Copied</string>
<string name="donate_developer">Donate</string> <string name="donate_developer">Donate</string>
<string name="text_email">Email</string>
<string name="my_github">https://github.com/hyb1996/NoRootScriptDroid</string> <string name="my_github">https://github.com/hyb1996/NoRootScriptDroid</string>
<string name="share_app">[UiAutomator]Download:http://www.coolapk.com/apk/com.stardust.scriptdroid </string> <string name="share_app">[UiAutomator]Download:http://www.coolapk.com/apk/com.stardust.scriptdroid </string>
<string name="text_floating_window">Floating Window</string> <string name="text_floating_window">Floating Window</string>
<string name="text_others">Others</string>
<string name="text_error_report">Bug Report</string> <string name="text_error_report">Bug Report</string>
<string name="text_press_again_to_exit">Press again to exit</string> <string name="text_press_again_to_exit">Press again to exit</string>
<string name="text_common_function">Common using functions</string> <string name="text_common_function">Common using functions</string>
@@ -54,49 +48,36 @@
<string name="text_start_running">Running</string> <string name="text_start_running">Running</string>
<string name="text_open_by_other_apps">Open by other apps</string> <string name="text_open_by_other_apps">Open by other apps</string>
<string name="text_rename">Rename</string> <string name="text_rename">Rename</string>
<string name="text_rename_file_meanwhile">Rename file</string>
<string name="text_please_input_new_name">Input new name</string>
<string name="text_send_shortcut">Create shortcut</string> <string name="text_send_shortcut">Create shortcut</string>
<string name="text_already_create">Created</string> <string name="text_already_create">Created</string>
<string name="text_delete">Delete</string> <string name="text_delete">Delete</string>
<string name="text_delete_absolutly">Delete file</string>
<string name="text_already_delete">Deleted</string> <string name="text_already_delete">Deleted</string>
<string name="text_delete_failed">File deletion failed</string>
<string name="text_choose_file">Choose a file</string>
<string name="folder_name">/Scripts/</string> <string name="folder_name">/Scripts/</string>
<string name="text_error">Error</string> <string name="text_error">Error</string>
<string name="text_load_failed">There is no documentation yet/(ㄒoㄒ)/~~</string> <string name="text_load_failed">There is no documentation yet/(ㄒoㄒ)/~~</string>
<string name="text_copy_debug_info">Copy debugging log</string> <string name="text_copy_debug_info">Copy debugging log</string>
<string name="text_it_is_the_developer_of_app">This is a software developer(。・・)ノ</string> <string name="text_it_is_the_developer_of_app">This is a software developer(。・・)ノ</string>
<string name="text_lll">lol</string> <string name="text_lll">lol</string>
<string name="text_choose_email_app">Choose a email application</string>
<string name="text_script_stopped">Script stopped</string>
<string name="text_please_choose">Please choose </string> <string name="text_please_choose">Please choose </string>
<string name="text_crash">Crash~ o(≧口≦)o</string> <string name="text_crash">Crash~ o(≧口≦)o</string>
<string name="crash_feedback">(ಥ _ ಥ)Exit or submit a bug report or copy debugging log to the developer(≧∇≦)ノ</string> <string name="crash_feedback">(ಥ _ ಥ)Exit or submit a bug report or copy debugging log to the developer(≧∇≦)ノ</string>
<string name="text_fail">Failed</string>
<string name="text_clear">Clear</string> <string name="text_clear">Clear</string>
<string name="text_console">Console</string> <string name="text_console">Console</string>
<string name="text_report_bug">Submit Bug report</string> <string name="text_report_bug">Submit Bug report</string>
<string name="text_bug_report">Bug Report</string>
<string name="text_report_fail">Submission Failed</string> <string name="text_report_fail">Submission Failed</string>
<string name="text_report_succeed">Submitted successfully</string> <string name="text_report_succeed">Submitted successfully</string>
<string name="edit_and_run_handle_intent_error">Cannot process file</string> <string name="edit_and_run_handle_intent_error">Cannot process file</string>
<string name="text_crash_en">Crash</string>
<string name="text_issue_report">Feedback</string> <string name="text_issue_report">Feedback</string>
<string name="text_script_record">Record touches</string> <string name="text_script_record">Record touches</string>
<string name="text_start_record">Start</string> <string name="text_start_record">Start</string>
<string name="text_stop_record">Stop</string> <string name="text_stop_record">Stop</string>
<string name="text_not_recording">Recording is not started</string>
<string name="text_pause_record">Pause</string> <string name="text_pause_record">Pause</string>
<string name="text_resume_record">Resume</string> <string name="text_resume_record">Resume</string>
<string name="text_recorded">Recording stopped</string> <string name="text_recorded">Recording stopped</string>
<string name="text_copy_to_clip">Copy</string> <string name="text_copy_to_clip">Copy</string>
<string name="text_file_write_fail">File writing failed</string> <string name="text_file_write_fail">File writing failed</string>
<string name="text_need_enable_accessibility_service_to_record">Need to enable the Accessibility Service</string>
<string name="text_join_qq_group">Join in QQ Group</string> <string name="text_join_qq_group">Join in QQ Group</string>
<string name="text_copied">Copied</string> <string name="text_copied">Copied</string>
<string name="text_close">Close</string>
<string name="text_use_volume_control_record">Use the volume keys to control</string> <string name="text_use_volume_control_record">Use the volume keys to control</string>
<string name="summary_use_volume_control_record">Stop or start recording when volume changes</string> <string name="summary_use_volume_control_record">Stop or start recording when volume changes</string>
<string name="key_use_volume_control_record">key_use_volume_control_record</string> <string name="key_use_volume_control_record">key_use_volume_control_record</string>
@@ -116,7 +97,6 @@
<string name="text_select_image">Choose a picture</string> <string name="text_select_image">Choose a picture</string>
<string name="text_help">Help</string> <string name="text_help">Help</string>
<string name="text_no_floating_window_permission">No floating window permission</string> <string name="text_no_floating_window_permission">No floating window permission</string>
<string name="text_node_info">Node info</string>
<string name="text_layout_hierarchy">View layout hierarchy</string> <string name="text_layout_hierarchy">View layout hierarchy</string>
<string name="text_layout_bounds">View layout bounds</string> <string name="text_layout_bounds">View layout bounds</string>
<string name="text_no_accessibility_permission_to_capture">Accessibility service is not activated</string> <string name="text_no_accessibility_permission_to_capture">Accessibility service is not activated</string>
@@ -124,7 +104,6 @@
<string name="text_my_script">My Scripts</string> <string name="text_my_script">My Scripts</string>
<string name="hint_no_script">Click ADD to create your first script~(。・・)ノ</string> <string name="hint_no_script">Click ADD to create your first script~(。・・)ノ</string>
<string name="text_reset_background">Reset background settings</string> <string name="text_reset_background">Reset background settings</string>
<string name="text_restart_app_to_apply">Restart to apply</string>
<string name="text_record_with_root">Recording with Rooting</string> <string name="text_record_with_root">Recording with Rooting</string>
<string name="text_record_msg">Recording Prompt</string> <string name="text_record_msg">Recording Prompt</string>
<string name="text_text_changed">Text Changed</string> <string name="text_text_changed">Text Changed</string>
@@ -148,9 +127,6 @@
<string name="key_use_volume_control_running">key_use_volume_control_running</string> <string name="key_use_volume_control_running">key_use_volume_control_running</string>
<string name="text_use_volume_to_stop_running">Stop all scripts when volume changes</string> <string name="text_use_volume_to_stop_running">Stop all scripts when volume changes</string>
<string name="text_need_to_enable_accessibility_service">Need to enable Accessibility Service</string> <string name="text_need_to_enable_accessibility_service">Need to enable Accessibility Service</string>
<string name="text_advanced">Advanced</string>
<string name="text_command_run_mode">Auto operation function running mode</string>
<string name="summary_command_run_mode">If the app responses slowly when running script, choose Thread Pool or Create Thread. But it may causes rebooting of the device</string>
<string name="text_on">ON</string> <string name="text_on">ON</string>
<string name="text_off">OFF</string> <string name="text_off">OFF</string>
<string name="text_please_choose_file_to_import">Select script file to import</string> <string name="text_please_choose_file_to_import">Select script file to import</string>
@@ -169,17 +145,10 @@
<item>Camera</item> <item>Camera</item>
</string-array> </string-array>
<string-array name="run_mode_keys">
<item>Single Thread</item>
<item>Create New Thread Every Time</item>
<item>Thread Pool</item>
</string-array>
<string name="text_update">Update</string> <string name="text_update">Update</string>
<string name="text_task_manage">Tasks</string> <string name="text_task_manage">Tasks</string>
<string name="text_script">Script</string>
<string name="text_root_script_record"></string> <string name="text_root_script_record"></string>
<string name="text_processing">Processing</string> <string name="text_processing">Processing</string>
<string name="text_re_import_succeed"></string>
<string name="text_pre_execute_script">Pre-execute script</string> <string name="text_pre_execute_script">Pre-execute script</string>
<string name="text_check_update">Check for updates</string> <string name="text_check_update">Check for updates</string>
<string name="text_new_directory">New Directory</string> <string name="text_new_directory">New Directory</string>

View File

@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="colorPrimary">#009688</color> <color name="colorPrimary">#009688</color>
<color name="colorPrimaryOld">#8ea22a</color>
<color name="colorPrimaryDark">#00796B</color> <color name="colorPrimaryDark">#00796B</color>
<color name="colorAccent">#536DFE</color> <color name="colorAccent">#536DFE</color>
<color name="sliding_up_panel_shadow_color">#99444444</color> <color name="sliding_up_panel_shadow_color">#99444444</color>

View File

@@ -2,7 +2,6 @@
<!-- Default screen margins, per the Android Design guidelines. --> <!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen> <dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen> <dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="level_beam_view_padding_left">3dp</dimen> <dimen name="level_beam_view_padding_left">3dp</dimen>
<dimen name="level_beam_view_line_width">6dp</dimen> <dimen name="level_beam_view_line_width">6dp</dimen>
<dimen name="level_beam_view_line_offset">2dp</dimen> <dimen name="level_beam_view_line_offset">2dp</dimen>

View File

@@ -1,13 +1,9 @@
<resources> <resources>
<string name="_app_name">AutoJs</string> <string name="_app_name">AutoJs</string>
<string name="action_settings">设置</string> <string name="action_settings">设置</string>
<string name="action_disable_service">关闭服务</string>
<string name="text_accessibility_service_description">使脚本自动操作(点击、长按、滑动等)所需,若关闭则只能执行不涉及自动操作的脚本。</string> <string name="text_accessibility_service_description">使脚本自动操作(点击、长按、滑动等)所需,若关闭则只能执行不涉及自动操作的脚本。</string>
<string name="text_new_file">新建文件</string> <string name="text_new_file">新建文件</string>
<string name="text_import_from_file">从文件导入</string> <string name="text_import_from_file">从文件导入</string>
<string name="action_exit">退出</string>
<string name="text_service_disabled">服务已关闭</string>
<string name="text_file_manager_not_found">找不到文件管理器T.T</string>
<string name="text_create_fail">创建失败</string> <string name="text_create_fail">创建失败</string>
<string name="text_please_input_name">请输入名称</string> <string name="text_please_input_name">请输入名称</string>
<string name="text_name">名称</string> <string name="text_name">名称</string>
@@ -17,7 +13,6 @@
<string name="text_path_is_empty">路径为空</string> <string name="text_path_is_empty">路径为空</string>
<string name="text_file_not_exists">文件不存在</string> <string name="text_file_not_exists">文件不存在</string>
<string name="text_no_file_rw_permission">无文件读写权限</string> <string name="text_no_file_rw_permission">无文件读写权限</string>
<string name="action_test">内嵌920测试</string>
<string name="text_no_accessibility_permission">无障碍服务未启动,脚本已停止运行</string> <string name="text_no_accessibility_permission">无障碍服务未启动,脚本已停止运行</string>
<string name="text_drawer_close">关闭侧拉菜单</string> <string name="text_drawer_close">关闭侧拉菜单</string>
<string name="text_drawer_open">打开侧拉菜单</string> <string name="text_drawer_open">打开侧拉菜单</string>
@@ -37,9 +32,6 @@
<string name="text_about">关于</string> <string name="text_about">关于</string>
<string name="text_licenses">开放源代码许可</string> <string name="text_licenses">开放源代码许可</string>
<string name="text_do_not_remind_again">不再提示</string> <string name="text_do_not_remind_again">不再提示</string>
<string name="text_sample_alipay_scan">支付宝扫一扫</string>
<string name="text_sample_open_running_services">示例:打开正在运行的服务(安卓6.0+)</string>
<string name="text_sample_simple_calculator">示例:简单计算器</string>
<string name="copyright">Copyright©2016 All right reserves.</string> <string name="copyright">Copyright©2016 All right reserves.</string>
<string name="developer">星尘幻影</string> <string name="developer">星尘幻影</string>
<string name="qq">2732014414</string> <string name="qq">2732014414</string>
@@ -47,16 +39,10 @@
<string name="github">软件源代码</string> <string name="github">软件源代码</string>
<string name="text_already_copy_to_clip">已复制到剪贴板</string> <string name="text_already_copy_to_clip">已复制到剪贴板</string>
<string name="donate_developer">打赏作者</string> <string name="donate_developer">打赏作者</string>
<string name="text_email">邮箱</string>
<string name="my_github">https://github.com/hyb1996/NoRootScriptDroid</string> <string name="my_github">https://github.com/hyb1996/NoRootScriptDroid</string>
<string name="share_app">[AutoJs]下载地址:http://www.coolapk.com/apk/com.stardust.scriptdroid </string> <string name="share_app">[AutoJs]下载地址:http://www.coolapk.com/apk/com.stardust.scriptdroid </string>
<string name="text_floating_window">悬浮窗</string> <string name="text_floating_window">悬浮窗</string>
<string name="text_assist_service_notification">通知栏点击区域辅助开关</string>
<string name="text_others">其他</string>
<string name="text_assist_mode_enabled">点击区域辅助服务已开启(点击关闭)</string>
<string name="text_assist_mode_disabled">点击区域辅助服务已关闭(点击开启)</string>
<string name="text_error_report">错误报告</string> <string name="text_error_report">错误报告</string>
<string name="text_sample_qq_hongbao">示例:QQ自动抢红包</string>
<string name="text_press_again_to_exit">再按一次退出程序</string> <string name="text_press_again_to_exit">再按一次退出程序</string>
<string name="text_common_function">常用函数</string> <string name="text_common_function">常用函数</string>
<string name="sorry_for_crash">很抱歉(ಥ _ ಥ)程序遇到未知错误,即将停止运行\n错误代码:</string> <string name="sorry_for_crash">很抱歉(ಥ _ ಥ)程序遇到未知错误,即将停止运行\n错误代码:</string>
@@ -65,59 +51,37 @@
<string name="text_start_running">开始运行</string> <string name="text_start_running">开始运行</string>
<string name="text_open_by_other_apps">用其他应用打开</string> <string name="text_open_by_other_apps">用其他应用打开</string>
<string name="text_rename">重命名</string> <string name="text_rename">重命名</string>
<string name="text_rename_file_meanwhile">同时重命名原文件</string>
<string name="text_please_input_new_name">请输入新名称</string>
<string name="text_send_shortcut">创建桌面快捷方式</string> <string name="text_send_shortcut">创建桌面快捷方式</string>
<string name="text_already_create">已创建</string> <string name="text_already_create">已创建</string>
<string name="text_delete">删除</string> <string name="text_delete">删除</string>
<string name="text_delete_absolutly">彻底删除</string>
<string name="text_already_delete">已删除</string> <string name="text_already_delete">已删除</string>
<string name="text_delete_failed">文件删除失败</string>
<string name="text_choose_file">选择一个文件</string>
<string name="folder_name">/脚本/</string> <string name="folder_name">/脚本/</string>
<string name="text_error">错误</string> <string name="text_error">错误</string>
<string name="text_load_failed">还没有文档/(ㄒoㄒ)/~~</string> <string name="text_load_failed">还没有文档/(ㄒoㄒ)/~~</string>
<string name="text_copy_debug_info">复制调试信息</string> <string name="text_copy_debug_info">复制调试信息</string>
<string name="text_it_is_the_developer_of_app">这是软件开发者(。・・)ノ</string> <string name="text_it_is_the_developer_of_app">这是软件开发者(。・・)ノ</string>
<string name="text_lll">略略略</string> <string name="text_lll">略略略</string>
<string name="text_choose_email_app">请选择邮件应用</string>
<string name="text_assist_clip">点击定位剪贴板</string>
<string name="text_script_stopped">脚本已停止</string>
<string name="assist_mode_notice">\"点击区域辅助服务\"是在要点击的区域不是文本时使用的,参见\"帮助\"。\"点击区域辅助服务\"只有在\"无障碍服务\"开启时才有效。</string>
<string name="text_please_choose">请选择</string> <string name="text_please_choose">请选择</string>
<string name="text_crash">崩溃了o(≧口≦)o</string> <string name="text_crash">崩溃了o(≧口≦)o</string>
<string name="crash_feedback">点击\"退出\"退出程序(ಥ _ ಥ)或者提交错误报告或者复制调试信息反馈给开发者(≧∇≦)ノ</string> <string name="crash_feedback">点击\"退出\"退出程序(ಥ _ ಥ)或者提交错误报告或者复制调试信息反馈给开发者(≧∇≦)ノ</string>
<string name="text_cannot_create_dialog_when_app_invisible">无法在后台显示弹框,脚本已停止运行</string>
<string name="text_sample_for_qq_chat">示例:QQ强制聊天</string>
<string name="text_re_import_samples">重新导入示例脚本文件</string>
<string name="text_re_import_succeed">导入成功</string>
<string name="text_fail">失败</string>
<string name="text_clear">清空</string> <string name="text_clear">清空</string>
<string name="text_console">控制台</string> <string name="text_console">控制台</string>
<string name="text_log">日志</string> <string name="text_log">日志</string>
<string name="text_sample_wechat_scan">微信扫一扫</string>
<string name="text_report_bug">提交错误报告</string> <string name="text_report_bug">提交错误报告</string>
<string name="text_bug_report">Bug Report</string>
<string name="text_report_fail">提交失败</string> <string name="text_report_fail">提交失败</string>
<string name="text_report_succeed">提交成功</string> <string name="text_report_succeed">提交成功</string>
<string name="edit_and_run_handle_intent_error">无法处理文件</string> <string name="edit_and_run_handle_intent_error">无法处理文件</string>
<string name="text_crash_en">Crash</string>
<string name="text_issue_report">问题反馈</string> <string name="text_issue_report">问题反馈</string>
<string name="text_script_record">录制脚本</string> <string name="text_script_record">录制脚本</string>
<string name="hint_start_record">在通知栏中开始录制</string>
<string name="text_start_record">开始录制</string> <string name="text_start_record">开始录制</string>
<string name="text_stop_record">停止录制</string> <string name="text_stop_record">停止录制</string>
<string name="text_not_recording">录制未开始</string>
<string name="text_pause_record">暂停录制</string> <string name="text_pause_record">暂停录制</string>
<string name="text_resume_record">继续录制</string> <string name="text_resume_record">继续录制</string>
<string name="text_recorded">录制结束</string> <string name="text_recorded">录制结束</string>
<string name="text_copy_to_clip">复制到剪贴板</string> <string name="text_copy_to_clip">复制到剪贴板</string>
<string name="text_file_write_fail">文件写入失败</string> <string name="text_file_write_fail">文件写入失败</string>
<string name="text_need_enable_accessibility_service_to_record">需要打开\"无障碍服务“才能录制脚本</string>
<string name="text_join_qq_group">加入QQ交流群</string> <string name="text_join_qq_group">加入QQ交流群</string>
<string name="text_copied">已复制到剪贴板</string> <string name="text_copied">已复制到剪贴板</string>
<string name="text_close">关闭</string>
<string name="text_re_record">重新录制</string>
<string name="text_use_volume_control_record">使用音量键控制</string> <string name="text_use_volume_control_record">使用音量键控制</string>
<string name="summary_use_volume_control_record">开启后每次音量变化会开始或停止脚本录制</string> <string name="summary_use_volume_control_record">开启后每次音量变化会开始或停止脚本录制</string>
<string name="key_use_volume_control_record">key_use_volume_control_record</string> <string name="key_use_volume_control_record">key_use_volume_control_record</string>
@@ -137,9 +101,7 @@
<string name="text_select_image">选择图片</string> <string name="text_select_image">选择图片</string>
<string name="text_help">帮助</string> <string name="text_help">帮助</string>
<string name="text_root_script_record">录制脚本(root)</string> <string name="text_root_script_record">录制脚本(root)</string>
<string name="hint_start_root_record">使用音量上键,音量下键结束录制</string>
<string name="text_no_floating_window_permission">没有悬浮窗权限</string> <string name="text_no_floating_window_permission">没有悬浮窗权限</string>
<string name="text_node_info">节点信息</string>
<string name="text_layout_hierarchy">布局层次分析</string> <string name="text_layout_hierarchy">布局层次分析</string>
<string name="text_layout_bounds">布局范围查看</string> <string name="text_layout_bounds">布局范围查看</string>
<string name="text_no_accessibility_permission_to_capture">无障碍服务未启动</string> <string name="text_no_accessibility_permission_to_capture">无障碍服务未启动</string>
@@ -147,7 +109,6 @@
<string name="text_my_script">我的脚本</string> <string name="text_my_script">我的脚本</string>
<string name="hint_no_script">点击右上角新建第一个脚本吧~(。・・)ノ</string> <string name="hint_no_script">点击右上角新建第一个脚本吧~(。・・)ノ</string>
<string name="text_reset_background">重置背景图片设置</string> <string name="text_reset_background">重置背景图片设置</string>
<string name="text_restart_app_to_apply">重启软件生效</string>
<string name="text_record_with_root">使用root权限录制</string> <string name="text_record_with_root">使用root权限录制</string>
<string name="text_record_msg">录制提示</string> <string name="text_record_msg">录制提示</string>
<string name="text_text_changed">文字改变</string> <string name="text_text_changed">文字改变</string>
@@ -171,15 +132,9 @@
<string name="key_use_volume_control_running">key_use_volume_control_running</string> <string name="key_use_volume_control_running">key_use_volume_control_running</string>
<string name="text_use_volume_to_stop_running">每次音量键变化停止所有脚本</string> <string name="text_use_volume_to_stop_running">每次音量键变化停止所有脚本</string>
<string name="text_need_to_enable_accessibility_service">需要启用无障碍服务</string> <string name="text_need_to_enable_accessibility_service">需要启用无障碍服务</string>
<string name="text_advanced">高级</string>
<string name="key_run_mode">运行方式</string> <string name="key_run_mode">运行方式</string>
<string name="text_command_run_mode">自动操作函数执行方式</string>
<string name="summary_command_run_mode">如果运行脚本后界面卡顿请尝试多线程或线程池,但这可能导致设备重启</string>
<string name="key_single_thread">KEY_SINGLE_THREAD</string>
<string name="text_on">已开启</string> <string name="text_on">已开启</string>
<string name="text_off">已关闭</string> <string name="text_off">已关闭</string>
<string name="text_script">脚本</string>
<string name="text_manage">管理</string>
<string name="text_task_manage">任务管理</string> <string name="text_task_manage">任务管理</string>
<string name="text_name_should_not_be_empty">名称不能为空</string> <string name="text_name_should_not_be_empty">名称不能为空</string>
<string name="text_new_directory">新文件夹</string> <string name="text_new_directory">新文件夹</string>
@@ -215,7 +170,6 @@
<string name="text_guard_mode">保护模式</string> <string name="text_guard_mode">保护模式</string>
<string name="summary_guard_mode">在本软件界面无法运行自动操作命令以免误触</string> <string name="summary_guard_mode">在本软件界面无法运行自动操作命令以免误触</string>
<string name="key_guard_mode">key_guard_mode</string> <string name="key_guard_mode">key_guard_mode</string>
<string name="text_console_floating_window">控制台悬浮窗</string>
<string name="text_layout_inspector_is_dumping">布局分析中,请稍后点击</string> <string name="text_layout_inspector_is_dumping">布局分析中,请稍后点击</string>
<string name="text_force_stop">强制停止</string> <string name="text_force_stop">强制停止</string>
<string name="text_execution_finished" formatted="false">\n------------\n[%s]运行结束,用时%f秒</string> <string name="text_execution_finished" formatted="false">\n------------\n[%s]运行结束,用时%f秒</string>
@@ -235,15 +189,4 @@
<item>KEY_CAMERA</item> <item>KEY_CAMERA</item>
</string-array> </string-array>
<string-array name="run_mode_keys">
<item>单线程</item>
<item>每次都创建新线程</item>
<item>线程池</item>
</string-array>
<string-array name="run_mode_values">
<item>KEY_SINGLE_THREAD</item>
<item>KEY_NEW_THREAD_EVERY_TIME</item>
<item>KEY_THREAD_POOL</item>
</string-array>
</resources> </resources>

View File

@@ -69,7 +69,7 @@ public class ScriptRuntime extends AbstractScriptRuntime {
} }
public AbstractShell.Result shell(String cmd, int root) { public AbstractShell.Result shell(String cmd, int root) {
return ProcessShell.exec(cmd, root != 0); return ProcessShell.execCommand(cmd, root != 0);
} }
public UiSelector selector(JavaScriptEngine engine) { public UiSelector selector(JavaScriptEngine engine) {

View File

@@ -28,8 +28,8 @@ public abstract class AbstractShell {
} }
} }
private static final String COMMAND_SU = "su"; static final String COMMAND_SU = "su";
private static final String COMMAND_SH = "sh"; static final String COMMAND_SH = "sh";
static final String COMMAND_EXIT = "exit\n"; static final String COMMAND_EXIT = "exit\n";
static final String COMMAND_LINE_END = "\n"; static final String COMMAND_LINE_END = "\n";

View File

@@ -1,12 +1,15 @@
package com.stardust.autojs.runtime.api; package com.stardust.autojs.runtime.api;
import android.util.Log;
import com.stardust.pio.UncheckedIOException; import com.stardust.pio.UncheckedIOException;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader;
/** /**
* Created by Stardust on 2017/1/20. * Created by Stardust on 2017/1/20.
@@ -109,26 +112,23 @@ public class ProcessShell extends AbstractShell implements AutoCloseable {
} }
public ProcessShell readSucceedOutput() { public ProcessShell readSucceedOutput() {
try { read(mSucceedReader, mSucceedOutput);
while (mSucceedReader.ready()) {
String line = mSucceedReader.readLine();
mSucceedOutput.append(line).append("\n");
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return this; return this;
} }
public ProcessShell readErrorOutput() { private void read(BufferedReader reader, StringBuilder sb) {
String line;
try { try {
while ((line = mErrorReader.readLine()) != null) { String line;
mErrorOutput.append(line).append("\n"); while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
} }
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
}
public ProcessShell readErrorOutput() {
read(mErrorReader, mErrorOutput);
return this; return this;
} }
@@ -173,5 +173,68 @@ public class ProcessShell extends AbstractShell implements AutoCloseable {
} }
} }
public static Result execCommand(String[] commands, boolean isRoot) {
Result commandResult = new Result();
if (commands == null || commands.length == 0) return commandResult;
Process process = null;
DataOutputStream os = null;
BufferedReader successResult = null;
BufferedReader errorResult = null;
StringBuilder successMsg = null;
StringBuilder errorMsg = null;
try {
process = Runtime.getRuntime().exec(isRoot ? COMMAND_SU : COMMAND_SH);
os = new DataOutputStream(process.getOutputStream());
for (String command : commands) {
if (command != null) {
os.write(command.getBytes());
os.writeBytes(COMMAND_LINE_END);
os.flush();
}
}
os.writeBytes(COMMAND_EXIT);
os.flush();
commandResult.code = process.waitFor();
//获取错误信息
successMsg = new StringBuilder();
errorMsg = new StringBuilder();
successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s;
while ((s = successResult.readLine()) != null) successMsg.append(s);
while ((s = errorResult.readLine()) != null) errorMsg.append(s);
commandResult.result = successMsg.toString();
commandResult.error = errorMsg.toString();
Log.i(TAG, commandResult.toString());
} catch (Exception e) {
String errmsg = e.getMessage();
if (errmsg != null) {
Log.e(TAG, errmsg);
} else {
e.printStackTrace();
}
} finally {
try {
if (os != null) os.close();
if (successResult != null) successResult.close();
if (errorResult != null) errorResult.close();
} catch (IOException e) {
String errmsg = e.getMessage();
if (errmsg != null) {
Log.e(TAG, errmsg);
} else {
e.printStackTrace();
}
}
if (process != null) process.destroy();
}
return commandResult;
}
public static Result execCommand(String command, boolean isRoot) {
String[] commands = command.split("\n");
return execCommand(commands, isRoot);
}
} }