|
@@ -2,11 +2,16 @@ package de.tudarmstadt.informatik.hostage.ui2.fragment;
|
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
import android.app.DownloadManager;
|
|
|
+import android.app.DownloadManager.Query;
|
|
|
+import android.app.DownloadManager.Request;
|
|
|
import android.app.Fragment;
|
|
|
import android.app.FragmentManager;
|
|
|
+import android.content.BroadcastReceiver;
|
|
|
import android.content.Context;
|
|
|
import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
+import android.content.IntentFilter;
|
|
|
+import android.database.Cursor;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Environment;
|
|
@@ -14,10 +19,22 @@ import android.util.Log;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
+import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.nio.channels.FileChannel;
|
|
|
+import java.util.zip.ZipInputStream;
|
|
|
+
|
|
|
import de.tudarmstadt.informatik.hostage.Hostage;
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
|
+import de.tudarmstadt.informatik.hostage.system.Decompress;
|
|
|
import de.tudarmstadt.informatik.hostage.system.Device;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
|
|
|
|
|
@@ -32,14 +49,18 @@ public class SettingsFragment extends UpNavigatibleFragment {
|
|
|
/**
|
|
|
* {@inheritDoc}
|
|
|
*/
|
|
|
- @Override
|
|
|
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
+
|
|
|
+ private long enqueue;
|
|
|
+ private DownloadManager dm;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
super.onCreateView(inflater, container, savedInstanceState);
|
|
|
getActivity().setTitle(getResources().getString(R.string.drawer_settings));
|
|
|
View v = inflater.inflate(R.layout.fragment_settings, container, false);
|
|
|
|
|
|
- TextView rootedText = (TextView) v.findViewById(R.id.settings_device_rooted);
|
|
|
- TextView porthackText = (TextView) v.findViewById(R.id.settings_porthack_installed);
|
|
|
+ final TextView rootedText = (TextView) v.findViewById(R.id.settings_device_rooted);
|
|
|
+ final TextView porthackText = (TextView) v.findViewById(R.id.settings_porthack_installed);
|
|
|
|
|
|
if (Device.isRooted()) {
|
|
|
rootedText.setText(R.string.yes);
|
|
@@ -57,6 +78,72 @@ public class SettingsFragment extends UpNavigatibleFragment {
|
|
|
porthackText.setTextColor(getResources().getColor(R.color.holo_red));
|
|
|
}
|
|
|
|
|
|
+ //Handle if a download 'may' be needed
|
|
|
+ BroadcastReceiver receiver = new BroadcastReceiver() {
|
|
|
+ @Override
|
|
|
+ public void onReceive(Context context, Intent intent) {
|
|
|
+ String action = intent.getAction();
|
|
|
+ if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
|
|
|
+ long downloadId = intent.getLongExtra(
|
|
|
+ DownloadManager.EXTRA_DOWNLOAD_ID, 0);
|
|
|
+ Query query = new Query();
|
|
|
+ query.setFilterById(enqueue);
|
|
|
+ Cursor c = dm.query(query);
|
|
|
+ if (c.moveToFirst()) {
|
|
|
+ int columnIndex = c
|
|
|
+ .getColumnIndex(DownloadManager.COLUMN_STATUS);
|
|
|
+ if (DownloadManager.STATUS_SUCCESSFUL == c
|
|
|
+ .getInt(columnIndex)) {
|
|
|
+
|
|
|
+ String downloadFile = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME));
|
|
|
+ String makeWritable[]= {"su","-c","chmod","777","/data/local"}; //change permission to allow rw access from x only
|
|
|
+ String allowExec[]= {"su","-c","chmod","711","/data/local/bind"}; //change permission to allow x access
|
|
|
+ String revert[]= {"su","-c","chmod","751","/data/local"}; //change permission back to x only
|
|
|
+
|
|
|
+ try {
|
|
|
+ //Chmod the local directory for write access
|
|
|
+ Process process = Runtime.getRuntime().exec(makeWritable);
|
|
|
+ process.waitFor();
|
|
|
+
|
|
|
+ Log.d("portbinder:","Changing permission on /data/local to allow write access");
|
|
|
+
|
|
|
+ //Decompressing downloaded zip to local directory
|
|
|
+ Decompress dwnld = new Decompress(downloadFile,"/data/local/" );
|
|
|
+ dwnld.unzip();
|
|
|
+ Log.v("portbinder:","Decompressing downloaded file");
|
|
|
+
|
|
|
+ //Chmod the Portbinder to allow it to be executable
|
|
|
+ process = Runtime.getRuntime().exec(allowExec);
|
|
|
+ process.waitFor();
|
|
|
+ Log.v("portbinder:","Changing permission on /data/local/bind to allow the binary to be executed");
|
|
|
+
|
|
|
+ //Chmod the local directory to back to non-read/write access
|
|
|
+ process = Runtime.getRuntime().exec(revert);
|
|
|
+ process.waitFor();
|
|
|
+ Log.v("portbinder:","Changing permission on /data/local back to no-write access");
|
|
|
+
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(Device.updatePorthack()) //if successful
|
|
|
+ {
|
|
|
+ porthackText.setText(R.string.yes);
|
|
|
+ porthackText.setTextColor(getResources().getColor(R.color.holo_dark_green));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ getActivity().registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
|
|
|
+
|
|
|
+
|
|
|
//Allow no porthack text box clickable
|
|
|
if (Device.isRooted() && !Device.isPorthackInstalled())
|
|
|
{
|
|
@@ -86,7 +173,7 @@ public class SettingsFragment extends UpNavigatibleFragment {
|
|
|
|
|
|
}
|
|
|
})
|
|
|
- .setNeutralButton(R.string.portbinder_tutorial, new DialogInterface.OnClickListener() {
|
|
|
+ /*.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");
|
|
@@ -94,7 +181,7 @@ public class SettingsFragment extends UpNavigatibleFragment {
|
|
|
startActivity(intent);
|
|
|
|
|
|
}
|
|
|
- })
|
|
|
+ })*/
|
|
|
.setNegativeButton(R.string.portbinder_website, new DialogInterface.OnClickListener() {
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
@@ -103,6 +190,36 @@ public class SettingsFragment extends UpNavigatibleFragment {
|
|
|
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();
|
|
|
|
|
@@ -122,7 +239,6 @@ public class SettingsFragment extends UpNavigatibleFragment {
|
|
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
|
|
super.onViewCreated(view, savedInstanceState);
|
|
|
|
|
|
-
|
|
|
FragmentManager manager = this.getFragmentManager();
|
|
|
manager.beginTransaction().replace(R.id.settings_fragment_container, new PreferenceHostageFrament()).commit();
|
|
|
}
|