Skip to content

Commit 5e9e864

Browse files
Removed WeakReference as we moved install/remove functions to MainActivity
Signed-off-by: sunilpaulmathew <[email protected]>
1 parent e870718 commit 5e9e864

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

app/src/main/java/com/smartpack/busyboxinstaller/MainActivity.java

+13-17
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import com.smartpack.busyboxinstaller.utils.RootUtils;
3434
import com.smartpack.busyboxinstaller.utils.Utils;
3535

36-
import java.lang.ref.WeakReference;
37-
3836
/*
3937
* Created by sunilpaulmathew <[email protected]> on April 11, 2020
4038
*/
@@ -234,7 +232,7 @@ private void installDialog() {
234232
install.setNegativeButton(R.string.cancel, (dialog, which) -> {
235233
});
236234
install.setPositiveButton(R.string.update, (dialog, which) -> {
237-
installBusyBox(mInstall, new WeakReference<>(this));
235+
installBusyBox(mInstall, this);
238236
});
239237
}
240238
} else {
@@ -243,7 +241,7 @@ private void installDialog() {
243241
install.setNegativeButton(R.string.cancel, (dialog, which) -> {
244242
});
245243
install.setPositiveButton(R.string.install, (dialog, which) -> {
246-
installBusyBox(mInstall, new WeakReference<>(this));
244+
installBusyBox(mInstall, this);
247245
});
248246
}
249247
} else {
@@ -261,7 +259,7 @@ private void removeBusyBox() {
261259
.setNegativeButton(R.string.cancel, (dialog, which) -> {
262260
})
263261
.setPositiveButton(R.string.remove, (dialog, which) -> {
264-
removeBusyBox(new WeakReference<>(this));
262+
removeBusyBox(this);
265263
})
266264
.show();
267265
}
@@ -283,13 +281,13 @@ private void shareApp() {
283281
}
284282

285283
@SuppressLint("StaticFieldLeak")
286-
public void installBusyBox(View view, WeakReference<Activity> activityRef) {
284+
public void installBusyBox(View view, Activity activity) {
287285
new AsyncTask<Void, Void, Void>() {
288286
@SuppressLint("SetTextI18n")
289287
@Override
290288
protected void onPreExecute() {
291289
super.onPreExecute();
292-
mProgressText.setText(activityRef.get().getString(R.string.installing, Utils.version) + " ...");
290+
mProgressText.setText(activity.getString(R.string.installing, Utils.version) + " ...");
293291
mProgress.setVisibility(View.VISIBLE);
294292
mInstall.setVisibility(View.GONE);
295293
if (Utils.mOutput == null) {
@@ -310,12 +308,12 @@ protected Void doInBackground(Void... voids) {
310308
} else {
311309
Utils.mountable = false;
312310
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));
314312
}
315313
if (Utils.mountable) {
316314
Utils.sleep(1);
317315
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);
319317
if (!Utils.existFile("/system/xbin/")) {
320318
RootUtils.runCommand("mkdir /system/xbin/");
321319
Utils.mOutput.append("** Creating '/system/xbin/': Done*\n\n");
@@ -351,14 +349,13 @@ protected Void doInBackground(Void... voids) {
351349
Utils.mOutput.append(Utils.mountSystem("ro"));
352350
Utils.mOutput.append("** Making 'system' partition read-only: Done*\n\n");
353351
}
354-
Utils.mOutput.append(activityRef.get().getString(R.string.install_busybox_success));
352+
Utils.mOutput.append(activity.getString(R.string.install_busybox_success));
355353
}
356354
return null;
357355
}
358356
@Override
359357
protected void onPostExecute(Void aVoid) {
360358
super.onPostExecute(aVoid);
361-
Activity activity = activityRef.get();
362359
if (activity.isFinishing() || activity.isDestroyed()) return;
363360
mProgress.setVisibility(View.GONE);
364361
mInstall.setVisibility(View.VISIBLE);
@@ -371,7 +368,7 @@ protected void onPostExecute(Void aVoid) {
371368
status.setNeutralButton(R.string.save_log, (dialog, which) -> {
372369
Utils.create("## BusyBox Installation log created by BusyBox Installer v" + BuildConfig.VERSION_NAME + "\n\n" +
373370
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"));
375372
});
376373
status.setNegativeButton(R.string.cancel, (dialog, which) -> {
377374
});
@@ -388,13 +385,13 @@ protected void onPostExecute(Void aVoid) {
388385
}
389386

390387
@SuppressLint("StaticFieldLeak")
391-
public void removeBusyBox(WeakReference<Activity> activityRef) {
388+
public void removeBusyBox(Activity activity) {
392389
new AsyncTask<Void, Void, Void>() {
393390
@SuppressLint("SetTextI18n")
394391
@Override
395392
protected void onPreExecute() {
396393
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) + " ...");
398395
mProgress.setVisibility(View.VISIBLE);
399396
mInstall.setVisibility(View.GONE);
400397
if (Utils.mOutput == null) {
@@ -431,13 +428,12 @@ protected Void doInBackground(Void... voids) {
431428
Utils.mOutput.append(Utils.mountSystem("ro"));
432429
Utils.mOutput.append("** Making 'system' partition read-only: Done*\n\n");
433430
}
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));
435432
return null;
436433
}
437434
@Override
438435
protected void onPostExecute(Void aVoid) {
439436
super.onPostExecute(aVoid);
440-
Activity activity = activityRef.get();
441437
if (activity.isFinishing() || activity.isDestroyed()) return;
442438
mProgress.setVisibility(View.VISIBLE);
443439
mInstall.setVisibility(View.VISIBLE);
@@ -497,7 +493,7 @@ public void onStart() {
497493
update.setView(checkBoxView);
498494
update.setNegativeButton(R.string.cancel, (dialog, which) -> {
499495
});
500-
update.setPositiveButton(R.string.update, (dialog, which) -> installBusyBox(mInstall, new WeakReference<>(this)));
496+
update.setPositiveButton(R.string.update, (dialog, which) -> installBusyBox(mInstall, this));
501497
update.show();
502498
}
503499
}

0 commit comments

Comments
 (0)