1212
1313import com .eminayar .panter .PanterDialog ;
1414import com .eminayar .panter .enums .Animation ;
15+ import com .stericson .RootTools .RootTools ;
1516
1617import eu .chainfire .libsuperuser .Shell ;
1718import 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
0 commit comments