33
33
import com .smartpack .busyboxinstaller .utils .RootUtils ;
34
34
import com .smartpack .busyboxinstaller .utils .Utils ;
35
35
36
- import java .lang .ref .WeakReference ;
37
-
38
36
/*
39
37
* Created by sunilpaulmathew <[email protected] > on April 11, 2020
40
38
*/
@@ -234,7 +232,7 @@ private void installDialog() {
234
232
install .setNegativeButton (R .string .cancel , (dialog , which ) -> {
235
233
});
236
234
install .setPositiveButton (R .string .update , (dialog , which ) -> {
237
- installBusyBox (mInstall , new WeakReference <>( this ) );
235
+ installBusyBox (mInstall , this );
238
236
});
239
237
}
240
238
} else {
@@ -243,7 +241,7 @@ private void installDialog() {
243
241
install .setNegativeButton (R .string .cancel , (dialog , which ) -> {
244
242
});
245
243
install .setPositiveButton (R .string .install , (dialog , which ) -> {
246
- installBusyBox (mInstall , new WeakReference <>( this ) );
244
+ installBusyBox (mInstall , this );
247
245
});
248
246
}
249
247
} else {
@@ -261,7 +259,7 @@ private void removeBusyBox() {
261
259
.setNegativeButton (R .string .cancel , (dialog , which ) -> {
262
260
})
263
261
.setPositiveButton (R .string .remove , (dialog , which ) -> {
264
- removeBusyBox (new WeakReference <>( this ) );
262
+ removeBusyBox (this );
265
263
})
266
264
.show ();
267
265
}
@@ -283,13 +281,13 @@ private void shareApp() {
283
281
}
284
282
285
283
@ SuppressLint ("StaticFieldLeak" )
286
- public void installBusyBox (View view , WeakReference < Activity > activityRef ) {
284
+ public void installBusyBox (View view , Activity activity ) {
287
285
new AsyncTask <Void , Void , Void >() {
288
286
@ SuppressLint ("SetTextI18n" )
289
287
@ Override
290
288
protected void onPreExecute () {
291
289
super .onPreExecute ();
292
- mProgressText .setText (activityRef . get () .getString (R .string .installing , Utils .version ) + " ..." );
290
+ mProgressText .setText (activity .getString (R .string .installing , Utils .version ) + " ..." );
293
291
mProgress .setVisibility (View .VISIBLE );
294
292
mInstall .setVisibility (View .GONE );
295
293
if (Utils .mOutput == null ) {
@@ -310,12 +308,12 @@ protected Void doInBackground(Void... voids) {
310
308
} else {
311
309
Utils .mountable = false ;
312
310
Utils .mOutput .append ("** Both 'root' & '/system' partitions on your device are not writable! *\n \n " );
313
- Utils .mOutput .append (activityRef . get () .getString (R .string .install_busybox_failed ));
311
+ Utils .mOutput .append (activity .getString (R .string .install_busybox_failed ));
314
312
}
315
313
if (Utils .mountable ) {
316
314
Utils .sleep (1 );
317
315
Utils .mOutput .append ("** Copying BusyBox v" + Utils .version + " binary into '" ).append (Environment .getExternalStorageDirectory ().getPath ()).append ("': Done *\n \n " );
318
- Utils .copyBinary (activityRef . get () );
316
+ Utils .copyBinary (activity );
319
317
if (!Utils .existFile ("/system/xbin/" )) {
320
318
RootUtils .runCommand ("mkdir /system/xbin/" );
321
319
Utils .mOutput .append ("** Creating '/system/xbin/': Done*\n \n " );
@@ -351,14 +349,13 @@ protected Void doInBackground(Void... voids) {
351
349
Utils .mOutput .append (Utils .mountSystem ("ro" ));
352
350
Utils .mOutput .append ("** Making 'system' partition read-only: Done*\n \n " );
353
351
}
354
- Utils .mOutput .append (activityRef . get () .getString (R .string .install_busybox_success ));
352
+ Utils .mOutput .append (activity .getString (R .string .install_busybox_success ));
355
353
}
356
354
return null ;
357
355
}
358
356
@ Override
359
357
protected void onPostExecute (Void aVoid ) {
360
358
super .onPostExecute (aVoid );
361
- Activity activity = activityRef .get ();
362
359
if (activity .isFinishing () || activity .isDestroyed ()) return ;
363
360
mProgress .setVisibility (View .GONE );
364
361
mInstall .setVisibility (View .VISIBLE );
@@ -371,7 +368,7 @@ protected void onPostExecute(Void aVoid) {
371
368
status .setNeutralButton (R .string .save_log , (dialog , which ) -> {
372
369
Utils .create ("## BusyBox Installation log created by BusyBox Installer v" + BuildConfig .VERSION_NAME + "\n \n " +
373
370
Utils .mOutput .toString (),Environment .getExternalStorageDirectory ().getPath () + "/bb_log" );
374
- Utils .snackbar (view , activityRef . get () .getString (R .string .save_log_summary , Environment .getExternalStorageDirectory ().getPath () + "/bb_log" ));
371
+ Utils .snackbar (view , activity .getString (R .string .save_log_summary , Environment .getExternalStorageDirectory ().getPath () + "/bb_log" ));
375
372
});
376
373
status .setNegativeButton (R .string .cancel , (dialog , which ) -> {
377
374
});
@@ -388,13 +385,13 @@ protected void onPostExecute(Void aVoid) {
388
385
}
389
386
390
387
@ SuppressLint ("StaticFieldLeak" )
391
- public void removeBusyBox (WeakReference < Activity > activityRef ) {
388
+ public void removeBusyBox (Activity activity ) {
392
389
new AsyncTask <Void , Void , Void >() {
393
390
@ SuppressLint ("SetTextI18n" )
394
391
@ Override
395
392
protected void onPreExecute () {
396
393
super .onPreExecute ();
397
- mProgressText .setText (activityRef . get () .getString (R .string .removing_busybox , Utils .version ) + " ..." );
394
+ mProgressText .setText (activity .getString (R .string .removing_busybox , Utils .version ) + " ..." );
398
395
mProgress .setVisibility (View .VISIBLE );
399
396
mInstall .setVisibility (View .GONE );
400
397
if (Utils .mOutput == null ) {
@@ -431,13 +428,12 @@ protected Void doInBackground(Void... voids) {
431
428
Utils .mOutput .append (Utils .mountSystem ("ro" ));
432
429
Utils .mOutput .append ("** Making 'system' partition read-only: Done*\n \n " );
433
430
}
434
- Utils .mOutput .append (activityRef . get () .getString (R .string .remove_busybox_completed , Utils .version ));
431
+ Utils .mOutput .append (activity .getString (R .string .remove_busybox_completed , Utils .version ));
435
432
return null ;
436
433
}
437
434
@ Override
438
435
protected void onPostExecute (Void aVoid ) {
439
436
super .onPostExecute (aVoid );
440
- Activity activity = activityRef .get ();
441
437
if (activity .isFinishing () || activity .isDestroyed ()) return ;
442
438
mProgress .setVisibility (View .VISIBLE );
443
439
mInstall .setVisibility (View .VISIBLE );
@@ -497,7 +493,7 @@ public void onStart() {
497
493
update .setView (checkBoxView );
498
494
update .setNegativeButton (R .string .cancel , (dialog , which ) -> {
499
495
});
500
- update .setPositiveButton (R .string .update , (dialog , which ) -> installBusyBox (mInstall , new WeakReference <>( this ) ));
496
+ update .setPositiveButton (R .string .update , (dialog , which ) -> installBusyBox (mInstall , this ));
501
497
update .show ();
502
498
}
503
499
}
0 commit comments