Skip to content

Commit a1a15ad

Browse files
openscript: don't allow to flash if access not granted
1 parent 1445eb7 commit a1a15ad

File tree

2 files changed

+49
-32
lines changed

2 files changed

+49
-32
lines changed

app/src/main/java/io/github/otaupdater/otaupdater/activity/OpenScriptGenerator.java

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import com.eminayar.panter.PanterDialog;
1414
import com.eminayar.panter.enums.Animation;
15+
import com.stericson.RootTools.RootTools;
1516

1617
import eu.chainfire.libsuperuser.Shell;
1718
import io.github.otaupdater.otaupdater.R;
@@ -28,7 +29,6 @@ public class OpenScriptGenerator extends AppCompatActivity {
2829
private TextView Path;
2930
private Button FlashButton;
3031
private String p,SCRIPT_PATH = "/cache/recovery/openrecoveryscript";
31-
private boolean WipeData,WipeCache;
3232
private PanterDialog FlashDialog;
3333
@Override
3434
protected void onCreate(Bundle savedInstanceState) {
@@ -73,36 +73,47 @@ public void onClick(View v) {
7373
FlashButton.setOnClickListener(new View.OnClickListener() {
7474
@Override
7575
public void onClick(View v) {
76-
Tools.shell("mount -o rw,remount,rw /cache",true);
77-
Tools.shell("touch "+SCRIPT_PATH,true);
78-
Tools.shell("echo 'install "+p+" ' > "+ SCRIPT_PATH,true);
79-
if(mWipeData.isChecked()){
80-
Tools.shell("echo 'install wipe data ' >> " + SCRIPT_PATH,true);
81-
}
82-
if(mWipeCache.isChecked()){
83-
Tools.shell("echo 'install wipe cache ' >> "+ SCRIPT_PATH,true);
84-
}
76+
if(RootTools.isRootAvailable()) {
77+
78+
if (RootTools.isAccessGiven()) {
79+
Tools.shell("mount -o rw,remount,rw /cache", true);
80+
Tools.shell("touch " + SCRIPT_PATH, true);
81+
Tools.shell("echo 'install " + p + " ' > " + SCRIPT_PATH, true);
82+
if (mWipeData.isChecked()) {
83+
Tools.shell("echo 'install wipe data ' >> " + SCRIPT_PATH, true);
84+
}
85+
if (mWipeCache.isChecked()) {
86+
Tools.shell("echo 'install wipe cache ' >> " + SCRIPT_PATH, true);
87+
}
88+
89+
FlashDialog.setTitle("Are you sure ?")
90+
.setHeaderBackground(R.color.colorPrimaryDark)
91+
.setMessage(p)
92+
.setPositive("Flash", new View.OnClickListener() {
93+
@Override
94+
public void onClick(View view) {
95+
Shell.SU.run("reboot recovery");
96+
FlashDialog.dismiss();
97+
98+
}
99+
})
100+
.setNegative("Cancel", new View.OnClickListener() {
101+
@Override
102+
public void onClick(View view) {
103+
FlashDialog.dismiss();
104+
}
105+
})
106+
.isCancelable(false)
107+
.withAnimation(Animation.SIDE);
108+
FlashDialog.show();
109+
} else {
110+
Snackbar.make(v, "Not having enough permission .", Snackbar.LENGTH_LONG).show();
111+
112+
}
113+
}else{
114+
Snackbar.make(v, "Device not rooted .", Snackbar.LENGTH_LONG).show();
85115

86-
FlashDialog.setTitle("Are you sure ?")
87-
.setHeaderBackground(R.color.colorPrimaryDark)
88-
.setMessage(p)
89-
.setPositive("Flash", new View.OnClickListener() {
90-
@Override
91-
public void onClick(View view) {
92-
Shell.SU.run("reboot recovery");
93-
FlashDialog.dismiss();
94-
95-
}
96-
})
97-
.setNegative("Cancel", new View.OnClickListener() {
98-
@Override
99-
public void onClick(View view) {
100-
FlashDialog.dismiss();
101-
}
102-
})
103-
.isCancelable(false)
104-
.withAnimation(Animation.SIDE);
105-
FlashDialog.show();
116+
}
106117
}
107118
});
108119

app/src/main/java/io/github/otaupdater/otaupdater/adapter/GithubReleasesAdapter.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import com.eminayar.panter.PanterDialog;
1414
import com.eminayar.panter.enums.Animation;
15+
import com.stericson.RootTools.RootTools;
1516

1617
import org.json.JSONException;
1718
import org.json.JSONObject;
@@ -90,12 +91,17 @@ public void onClick(View v)
9091
@Override
9192
public void onClick(View v) {
9293
PutStringPreferences(mContext,"FilePath", fileIns.getPath());
94+
if (!RootTools.isRootAvailable()) {
9395

94-
if (!suAvailable) {
96+
if (!RootTools.isAccessGiven()) {
9597
mContext.startActivity(new Intent(mContext, OpenScriptGenerator.class));
9698
}
9799
else {
98-
Snackbar.make(finalConvertView, "Device not rooted .", Snackbar.LENGTH_LONG).show();
100+
Snackbar.make(v, "Not having enough permission .", Snackbar.LENGTH_LONG).show();
101+
102+
}
103+
}else {
104+
Snackbar.make(v, "Device not rooted .", Snackbar.LENGTH_LONG).show();
99105

100106
}
101107

0 commit comments

Comments
 (0)