Browse Source

-added automation of porthack

Shankar Karuppayah 10 years ago
parent
commit
bf1e3d6cc1

+ 3 - 31
src/de/tudarmstadt/informatik/hostage/ui2/fragment/HomeFragment.java

@@ -397,48 +397,20 @@ public class HomeFragment extends TrackerFragment {
                                 if(!Device.isPorthackInstalled()) {
                                     new AlertDialog.Builder(getActivity())
                                             .setTitle(R.string.information)
-                                            .setMessage(R.string.no_portbinder_msg)
+                                            .setMessage(R.string.no_portbinder_msg2)
                                             .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                                                 public void onClick(DialogInterface dialog, int which) {
 
                                                 }
                                             })
                                             .setNegativeButton(R.string.help, new DialogInterface.OnClickListener() {
-
                                                 public void onClick(DialogInterface dialog, int which) {
-                                                    dialog.dismiss();
-                                                    final AlertDialog alert;
-
-                                                    new AlertDialog.Builder(getActivity())
-                                                            .setTitle(R.string.portbinder)
-                                                            .setMessage(R.string.helpPortbinder)
-                                                            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
-                                                                public void onClick(DialogInterface dialog, int which) {
-
-                                                                }
-                                                            })
-                                                            .setNeutralButton(R.string.portbinder_tutorial, new DialogInterface.OnClickListener() {
-                                                                public void onClick(DialogInterface dialog, int which) {
-
-                                                                    Uri uri = Uri.parse("https://www.youtube.com/watch?v=gi6fSiIJASk");
-                                                                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
-                                                                    startActivity(intent);
+                                                    MainActivity.getInstance().displayView(MainActivity.MainMenuItem.SETTINGS.getValue());
 
-                                                                }
-                                                            })
-                                                            .setNegativeButton(R.string.portbinder_website, new DialogInterface.OnClickListener() {
-                                                                public void onClick(DialogInterface dialog, int which) {
-
-                                                                    Uri uri = Uri.parse("https://www.tk.informatik.tu-darmstadt.de/de/research/secure-smart-infrastructures/hostage/");
-                                                                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
-                                                                    startActivity(intent);
-
-                                                                }
-                                                            })
-                                                            .setIcon(android.R.drawable.ic_dialog_info).show();
 
                                                 }
                                             })
+
                                             .setIcon(android.R.drawable.ic_dialog_info).show();
 
                                 }

+ 125 - 87
src/de/tudarmstadt/informatik/hostage/ui2/fragment/SettingsFragment.java

@@ -11,6 +11,7 @@ import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.content.SharedPreferences;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.Bundle;
@@ -52,6 +53,111 @@ public class SettingsFragment extends UpNavigatibleFragment {
 
     private long enqueue;
     private DownloadManager dm;
+    private BroadcastReceiver receiver;
+    /**
+     * Hold the shared preferences for the app
+     */
+    private SharedPreferences mSharedPreferences;
+
+    public void portbinderAlert(final SharedPreferences.Editor editor){
+        new AlertDialog.Builder(getActivity())
+                .setTitle(R.string.information)
+                .setMessage(R.string.no_portbinder_msg)
+                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+                    public void onClick(DialogInterface dialog, int which) {
+
+                    }
+                })
+                .setNegativeButton(R.string.no_thanks, new DialogInterface.OnClickListener() {
+                            public void onClick(DialogInterface dialog, int which) {
+                                //never show this to users again
+                                if (editor != null) {
+                                    editor.putBoolean("donotshowagain", true);
+                                    editor.commit(); //commit if any changes on the preferences
+                                }
+                            }
+                        }
+                )
+                .setNeutralButton(R.string.how, new DialogInterface.OnClickListener() {
+
+                    public void onClick(DialogInterface dialog, int which) {
+                        dialog.dismiss();
+                        final AlertDialog alert;
+
+                        new AlertDialog.Builder(getActivity())
+                                .setTitle(R.string.portbinder)
+                                .setMessage(R.string.helpPortbinder)
+                                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+                                    public void onClick(DialogInterface dialog, int which) {
+
+                                    }
+                                })
+                                .setNegativeButton(R.string.portbinder_website, new DialogInterface.OnClickListener() {
+                                    public void onClick(DialogInterface dialog, int which) {
+
+                                        Uri uri = Uri.parse("https://www.tk.informatik.tu-darmstadt.de/de/research/secure-smart-infrastructures/hostage/");
+                                        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
+                                        startActivity(intent);
+
+                                    }
+                                })
+                                        //Testing automated installation of portbinder
+                                .setNeutralButton(R.string.help_me, new DialogInterface.OnClickListener() {
+                                    public void onClick(DialogInterface dialog, int which) {
+                                        dialog.dismiss();
+
+                                        new AlertDialog.Builder(getActivity())
+                                                .setTitle(R.string.portbinder)
+                                                .setMessage(R.string.confirm_msg)
+                                                .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
+                                                    public void onClick(DialogInterface dialog, int which) {
+                                                        //Download Portbinder
+                                                        dm = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
+
+                                                        //Identify architecture
+                                                        String arch = System.getProperty("os.arch"); //get the device architecture
+                                                        String fileName = "";
+
+                                                        //selecting necessary PortBinder architecture
+                                                        if (arch.matches("arm.*"))      //arm
+                                                            fileName = "bind-arm.zip";
+                                                        else if (arch.matches("x86"))   //x86
+                                                            fileName = "bind-x86.zip";
+                                                        else if (arch.matches("mips"))  //mips
+                                                            fileName = "bind-mips.zip";
+
+                                                        Uri uri = Uri.parse("https://www.tk.informatik.tu-darmstadt.de/fileadmin/user_upload/Group_TK/"+fileName);
+
+                                                        if (!fileName.isEmpty()) //As long we have a valid string (non-empty)
+                                                        {
+                                                            Request request = new Request(uri)
+                                                                    .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
+                                                            enqueue = dm.enqueue(request);
+                                                        }
+                                                        else {
+                                                            //report to user of an unknown architecture
+                                                        }
+
+                                                    }
+                                                })
+                                                .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
+                                                    public void onClick(DialogInterface dialog, int which) {
+
+
+
+                                                    }
+                                                })
+                                                .setIcon(android.R.drawable.ic_dialog_alert).show();
+                                                ;
+
+                                    }
+                                })
+                                .setIcon(android.R.drawable.ic_dialog_info).show();
+
+                    }
+                })
+                .setIcon(android.R.drawable.ic_dialog_info).show();
+    }
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@@ -59,6 +165,9 @@ public class SettingsFragment extends UpNavigatibleFragment {
 		getActivity().setTitle(getResources().getString(R.string.drawer_settings));
 		View v = inflater.inflate(R.layout.fragment_settings, container, false);
 
+        mSharedPreferences = getActivity().getSharedPreferences(getString(R.string.shared_preference_path), Hostage.MODE_PRIVATE);
+        final SharedPreferences.Editor editor = mSharedPreferences.edit();
+
 		final TextView rootedText = (TextView) v.findViewById(R.id.settings_device_rooted);
 		final TextView porthackText = (TextView) v.findViewById(R.id.settings_porthack_installed);
 
@@ -74,12 +183,16 @@ public class SettingsFragment extends UpNavigatibleFragment {
 			porthackText.setText(R.string.yes);
 			porthackText.setTextColor(getResources().getColor(R.color.holo_dark_green));
 		} else {
+
+            if (!mSharedPreferences.getBoolean("donotshowagain", false))
+                portbinderAlert(editor);
+
 			porthackText.setText(R.string.no);
 			porthackText.setTextColor(getResources().getColor(R.color.holo_red));
 		}
 
         //Handle if a download 'may' be needed
-        BroadcastReceiver receiver = new BroadcastReceiver() {
+        receiver = new BroadcastReceiver() {
             @Override
             public void onReceive(Context context, Intent intent) {
                 String action = intent.getAction();
@@ -143,92 +256,6 @@ public class SettingsFragment extends UpNavigatibleFragment {
 
         getActivity().registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
 
-
-        //Allow no porthack text box clickable
-        if (Device.isRooted() && !Device.isPorthackInstalled())
-        {
-            porthackText.setOnClickListener(new View.OnClickListener() {
-
-                @Override
-                public void onClick(View arg0) {
-                    new AlertDialog.Builder(getActivity())
-                            .setTitle(R.string.information)
-                            .setMessage(R.string.no_portbinder_msg)
-                            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
-                                public void onClick(DialogInterface dialog, int which) {
-
-                                }
-                            })
-                            .setNegativeButton(R.string.help, new DialogInterface.OnClickListener() {
-
-                                public void onClick(DialogInterface dialog, int which) {
-                                    dialog.dismiss();
-                                    final AlertDialog alert;
-
-                                    new AlertDialog.Builder(getActivity())
-                                            .setTitle(R.string.portbinder)
-                                            .setMessage(R.string.helpPortbinder)
-                                            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
-                                                public void onClick(DialogInterface dialog, int which) {
-
-                                                }
-                                            })
-                                            /*.setNeutralButton(R.string.portbinder_tutorial, new DialogInterface.OnClickListener() {
-                                                public void onClick(DialogInterface dialog, int which) {
-
-                                                    Uri uri = Uri.parse("https://www.youtube.com/watch?v=gi6fSiIJASk");
-                                                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
-                                                    startActivity(intent);
-
-                                                }
-                                            })*/
-                                            .setNegativeButton(R.string.portbinder_website, new DialogInterface.OnClickListener() {
-                                                public void onClick(DialogInterface dialog, int which) {
-
-                                                    Uri uri = Uri.parse("https://www.tk.informatik.tu-darmstadt.de/de/research/secure-smart-infrastructures/hostage/");
-                                                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
-                                                    startActivity(intent);
-
-                                                }
-                                            })
-                                                    //Testing automated installation of portbinder
-                                            .setNeutralButton(R.string.help_me, new DialogInterface.OnClickListener() {
-                                                public void onClick(DialogInterface dialog, int which) {
-                                                    //Download Portbinder
-                                                    dm = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
-
-                                                    //Identify architecture
-                                                    String arch = System.getProperty("os.arch"); //get the device architecture
-
-                                                    //selecting necessary PortBinder
-                                                    Uri uri = Uri.EMPTY; //initialize variable
-
-                                                    if (arch.matches("arm.*"))      //arm
-                                                        uri = Uri.parse("https://www.tk.informatik.tu-darmstadt.de/fileadmin/user_upload/Group_TK/bind-arm.zip");
-                                                    else if (arch.matches("x86"))   //x86
-                                                        uri = Uri.parse("https://www.tk.informatik.tu-darmstadt.de/fileadmin/user_upload/Group_TK/bind-x86.zip");
-                                                    else if (arch.matches("mips"))  //mips
-                                                        uri = Uri.parse("https://www.tk.informatik.tu-darmstadt.de/fileadmin/user_upload/Group_TK/bind-mips.zip");
-
-                                                    if (uri != Uri.EMPTY) {
-                                                        Request request = new Request(uri)
-                                                                .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "bind.zip");
-                                                        enqueue = dm.enqueue(request);
-//                                                    dm.enqueue(request);
-                                                    }
-                                                    else {
-                                                        //report to user of an unknown architecture
-                                                    }
-                                                }
-                                            })
-                                            .setIcon(android.R.drawable.ic_dialog_info).show();
-
-                                }
-                            })
-                            .setIcon(android.R.drawable.ic_dialog_info).show();}
-                });
-        }
-
             return v;
 	}
 
@@ -242,4 +269,15 @@ public class SettingsFragment extends UpNavigatibleFragment {
 		FragmentManager manager = this.getFragmentManager();
 		manager.beginTransaction().replace(R.id.settings_fragment_container, new PreferenceHostageFrament()).commit();
 	}
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        getActivity().unregisterReceiver(receiver);
+
+    }
+
 }