From 701bf914e8a3d8c0cbef7f4dc71e0202e651b1a5 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 12 Nov 2019 18:48:37 +0200 Subject: [PATCH] Fix some memory leaks from static views variables --- app/src/main/java/com/hijacker/CrackFragment.java | 3 +-- .../main/java/com/hijacker/CustomActionEditorFragment.java | 3 +-- app/src/main/java/com/hijacker/CustomActionFragment.java | 3 +-- .../java/com/hijacker/CustomActionManagerFragment.java | 3 +-- app/src/main/java/com/hijacker/DevOptionsFragment.java | 3 +-- app/src/main/java/com/hijacker/IsolatedFragment.java | 3 +-- app/src/main/java/com/hijacker/MDKFragment.java | 3 +-- app/src/main/java/com/hijacker/MainActivity.java | 7 +++---- app/src/main/java/com/hijacker/MyListFragment.java | 3 +-- app/src/main/java/com/hijacker/ReaverFragment.java | 3 +-- app/src/main/java/com/hijacker/SettingsFragment.java | 3 +-- 11 files changed, 13 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/hijacker/CrackFragment.java b/app/src/main/java/com/hijacker/CrackFragment.java index a8c135f..f4b92b1 100644 --- a/app/src/main/java/com/hijacker/CrackFragment.java +++ b/app/src/main/java/com/hijacker/CrackFragment.java @@ -57,7 +57,6 @@ import static com.hijacker.MainActivity.notification; import static com.hijacker.MainActivity.path; import static com.hijacker.MainActivity.progress; -import static com.hijacker.MainActivity.refreshDrawer; import static com.hijacker.MainActivity.stop; import static com.hijacker.MainActivity.wl_path; @@ -234,7 +233,7 @@ public boolean accept(File file, String s){ public void onResume() { super.onResume(); currentFragment = FRAGMENT_CRACK; - refreshDrawer(); + ((MainActivity)getActivity()).refreshDrawer(); //Console text is saved/restored on pause/resume consoleView.setText(console_text); diff --git a/app/src/main/java/com/hijacker/CustomActionEditorFragment.java b/app/src/main/java/com/hijacker/CustomActionEditorFragment.java index 9d0cfaf..f5f6ffc 100644 --- a/app/src/main/java/com/hijacker/CustomActionEditorFragment.java +++ b/app/src/main/java/com/hijacker/CustomActionEditorFragment.java @@ -40,7 +40,6 @@ import static com.hijacker.MainActivity.actions_path; import static com.hijacker.MainActivity.currentFragment; import static com.hijacker.MainActivity.mFragmentManager; -import static com.hijacker.MainActivity.refreshDrawer; public class CustomActionEditorFragment extends Fragment{ View fragmentView; @@ -194,6 +193,6 @@ public void onResume(){ save_btn.setEnabled(true); } - refreshDrawer(); + ((MainActivity)getActivity()).refreshDrawer(); } } diff --git a/app/src/main/java/com/hijacker/CustomActionFragment.java b/app/src/main/java/com/hijacker/CustomActionFragment.java index 2fdd0ff..67d513b 100644 --- a/app/src/main/java/com/hijacker/CustomActionFragment.java +++ b/app/src/main/java/com/hijacker/CustomActionFragment.java @@ -50,7 +50,6 @@ import static com.hijacker.MainActivity.mFragmentManager; import static com.hijacker.MainActivity.notification; import static com.hijacker.MainActivity.progress; -import static com.hijacker.MainActivity.refreshDrawer; import static com.hijacker.Shell.runOne; public class CustomActionFragment extends Fragment{ @@ -115,7 +114,7 @@ public void onClick(View view){ public void onResume(){ super.onResume(); currentFragment = FRAGMENT_CUSTOM; - refreshDrawer(); + ((MainActivity)getActivity()).refreshDrawer(); //Console text is saved/restored on pause/resume consoleView.setText(console_text); diff --git a/app/src/main/java/com/hijacker/CustomActionManagerFragment.java b/app/src/main/java/com/hijacker/CustomActionManagerFragment.java index e1c70a7..97a3b6c 100644 --- a/app/src/main/java/com/hijacker/CustomActionManagerFragment.java +++ b/app/src/main/java/com/hijacker/CustomActionManagerFragment.java @@ -32,7 +32,6 @@ import static com.hijacker.MainActivity.currentFragment; import static com.hijacker.MainActivity.custom_action_adapter; import static com.hijacker.MainActivity.mFragmentManager; -import static com.hijacker.MainActivity.refreshDrawer; public class CustomActionManagerFragment extends Fragment{ @Override @@ -98,6 +97,6 @@ public void onClick(View view){ public void onResume(){ super.onResume(); currentFragment = FRAGMENT_CUSTOM; - refreshDrawer(); + ((MainActivity)getActivity()).refreshDrawer(); } } diff --git a/app/src/main/java/com/hijacker/DevOptionsFragment.java b/app/src/main/java/com/hijacker/DevOptionsFragment.java index 2f9d665..f3cca19 100644 --- a/app/src/main/java/com/hijacker/DevOptionsFragment.java +++ b/app/src/main/java/com/hijacker/DevOptionsFragment.java @@ -31,7 +31,6 @@ import static com.hijacker.MainActivity.FRAGMENT_SETTINGS; import static com.hijacker.MainActivity.NETHUNTER_BOOTKALI_BASH; import static com.hijacker.MainActivity.bootkali_init_bin; -import static com.hijacker.MainActivity.refreshDrawer; import static com.hijacker.MainActivity.currentFragment; import static com.hijacker.ReaverFragment.get_chroot_env; @@ -89,7 +88,7 @@ public boolean onPreferenceClick(Preference preference) { public void onResume() { super.onResume(); currentFragment = FRAGMENT_SETTINGS; - refreshDrawer(); + ((MainActivity)getActivity()).refreshDrawer(); fragmentView = getView(); } } diff --git a/app/src/main/java/com/hijacker/IsolatedFragment.java b/app/src/main/java/com/hijacker/IsolatedFragment.java index 38acf04..80032e0 100644 --- a/app/src/main/java/com/hijacker/IsolatedFragment.java +++ b/app/src/main/java/com/hijacker/IsolatedFragment.java @@ -35,7 +35,6 @@ import static com.hijacker.MainActivity.isolate; import static com.hijacker.MainActivity.mFragmentManager; import static com.hijacker.MainActivity.menu; -import static com.hijacker.MainActivity.refreshDrawer; import static com.hijacker.MainActivity.runInHandler; import static com.hijacker.MainActivity.wpa_thread; @@ -100,7 +99,7 @@ public void run(){ public void onResume() { super.onResume(); currentFragment = FRAGMENT_AIRODUMP; - refreshDrawer(); + ((MainActivity)getActivity()).refreshDrawer(); thread = new Thread(runnable); thread.start(); ((Button)fragmentView.findViewById(R.id.crack)).setText(wpa_thread.isAlive() ? R.string.stop : R.string.crack); diff --git a/app/src/main/java/com/hijacker/MDKFragment.java b/app/src/main/java/com/hijacker/MDKFragment.java index 4436ad1..ee49b81 100644 --- a/app/src/main/java/com/hijacker/MDKFragment.java +++ b/app/src/main/java/com/hijacker/MDKFragment.java @@ -36,7 +36,6 @@ import static com.hijacker.MainActivity.PROCESS_MDK_DOS; import static com.hijacker.MainActivity.currentFragment; import static com.hijacker.MainActivity.mFragmentManager; -import static com.hijacker.MainActivity.refreshDrawer; import static com.hijacker.MainActivity.runInHandler; import static com.hijacker.MainActivity.startAdos; import static com.hijacker.MainActivity.startBeaconFlooding; @@ -138,7 +137,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){ tkip_cb.setOnCheckedChangeListener(listener); aes_cb.setChecked(aes); aes_cb.setOnCheckedChangeListener(listener); - refreshDrawer(); + ((MainActivity)getActivity()).refreshDrawer(); } @Override public void onPause(){ diff --git a/app/src/main/java/com/hijacker/MainActivity.java b/app/src/main/java/com/hijacker/MainActivity.java index fe6bf77..1486a79 100644 --- a/app/src/main/java/com/hijacker/MainActivity.java +++ b/app/src/main/java/com/hijacker/MainActivity.java @@ -82,7 +82,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.HashMap; -import java.util.concurrent.Semaphore; import javax.net.ssl.HttpsURLConnection; @@ -126,8 +125,6 @@ public class MainActivity extends AppCompatActivity{ static ProgressBar progress; static Toolbar toolbar; static View rootView; - static DrawerLayout mDrawerLayout; - static NavigationView navigationView; static SparseArray navTitlesMap = new SparseArray<>(); //SparseArray to map fragment IDs to their respective navigation titles static Drawable[] overflow = {null, null, null, null, null, null, null, null}; //Drawables to use for overflow button icon static ImageView[] status = {null, null, null, null, null}; //Icons in TestDialog, set in TestDialog class @@ -168,6 +165,8 @@ public class MainActivity extends AppCompatActivity{ ReaverFragment reaverFragment = new ReaverFragment(); CrackFragment crackFragment = new CrackFragment(); CustomActionFragment customActionFragment = new CustomActionFragment(); + DrawerLayout mDrawerLayout; + NavigationView navigationView; @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); @@ -1589,7 +1588,7 @@ static void refreshState(){ progress.setProgress(deauthWait); } } - static void refreshDrawer(){ + void refreshDrawer(){ navigationView.getMenu().findItem(currentFragment).setChecked(true); actionBar.setTitle(navTitlesMap.get(currentFragment)); } diff --git a/app/src/main/java/com/hijacker/MyListFragment.java b/app/src/main/java/com/hijacker/MyListFragment.java index 281eb75..410feba 100644 --- a/app/src/main/java/com/hijacker/MyListFragment.java +++ b/app/src/main/java/com/hijacker/MyListFragment.java @@ -25,7 +25,6 @@ import android.widget.ListView; import static com.hijacker.MainActivity.FRAGMENT_AIRODUMP; import static com.hijacker.MainActivity.currentFragment; -import static com.hijacker.MainActivity.refreshDrawer; public class MyListFragment extends ListFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -42,6 +41,6 @@ public void onListItemClick(ListView l, final View v, int position, long id){ public void onResume(){ super.onResume(); currentFragment = FRAGMENT_AIRODUMP; - refreshDrawer(); + ((MainActivity)getActivity()).refreshDrawer(); } } diff --git a/app/src/main/java/com/hijacker/ReaverFragment.java b/app/src/main/java/com/hijacker/ReaverFragment.java index 3b7030a..b06fc05 100644 --- a/app/src/main/java/com/hijacker/ReaverFragment.java +++ b/app/src/main/java/com/hijacker/ReaverFragment.java @@ -69,7 +69,6 @@ import static com.hijacker.MainActivity.prefix; import static com.hijacker.MainActivity.progress; import static com.hijacker.MainActivity.reaver_dir; -import static com.hijacker.MainActivity.refreshDrawer; import static com.hijacker.MainActivity.runInHandler; import static com.hijacker.MainActivity.stop; @@ -234,7 +233,7 @@ static void stopReaver(){ public void onResume() { super.onResume(); currentFragment = FRAGMENT_REAVER; - refreshDrawer(); + ((MainActivity)getActivity()).refreshDrawer(); //Console text is saved/restored on pause/resume consoleView.setText(console_text); diff --git a/app/src/main/java/com/hijacker/SettingsFragment.java b/app/src/main/java/com/hijacker/SettingsFragment.java index 88e60f2..0640b83 100644 --- a/app/src/main/java/com/hijacker/SettingsFragment.java +++ b/app/src/main/java/com/hijacker/SettingsFragment.java @@ -32,7 +32,6 @@ import static com.hijacker.MainActivity.isArchValid; import static com.hijacker.MainActivity.mFragmentManager; import static com.hijacker.MainActivity.pref_edit; -import static com.hijacker.MainActivity.refreshDrawer; import static com.hijacker.MainActivity.versionName; import static com.hijacker.MainActivity.watchdog; import static com.hijacker.MainActivity.currentFragment; @@ -166,7 +165,7 @@ public boolean onPreferenceClick(Preference preference){ public void onResume() { super.onResume(); currentFragment = FRAGMENT_SETTINGS; - refreshDrawer(); + ((MainActivity)getActivity()).refreshDrawer(); listener = new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {