From cec293e19e3fcb259b5751cc385aef3456cce769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Hern=C3=A1ndez?= Date: Fri, 26 Jun 2015 10:31:49 +0200 Subject: [PATCH 1/8] Changes applied to GpiiActivity.java and AndroidManifest.xml for upgrading GpiiActivity Android application in order to autodeploy it --- platform/app/AndroidManifest.xml | 5 +- .../app/src/net/gpii/app/GpiiActivity.java | 705 ++++++++++++++---- 2 files changed, 573 insertions(+), 137 deletions(-) diff --git a/platform/app/AndroidManifest.xml b/platform/app/AndroidManifest.xml index 6ec2fd6..1592442 100644 --- a/platform/app/AndroidManifest.xml +++ b/platform/app/AndroidManifest.xml @@ -2,7 +2,7 @@ + android:versionName="1.1"> @@ -17,6 +17,9 @@ + + + diff --git a/platform/app/src/net/gpii/app/GpiiActivity.java b/platform/app/src/net/gpii/app/GpiiActivity.java index 6848e6d..d6d34ff 100644 --- a/platform/app/src/net/gpii/app/GpiiActivity.java +++ b/platform/app/src/net/gpii/app/GpiiActivity.java @@ -1,158 +1,591 @@ package net.gpii.app; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; import java.util.List; -import android.os.AsyncTask; -import android.os.Bundle; -import android.os.Process; +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; + +import android.annotation.SuppressLint; import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityManager.RunningAppProcessInfo; +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.DownloadManager; +import android.app.DownloadManager.Query; +import android.app.DownloadManager.Request; +import android.content.BroadcastReceiver; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; +import android.content.IntentFilter; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; +import android.database.Cursor; import android.graphics.Color; +import android.graphics.PixelFormat; import android.graphics.Typeface; +import android.net.Uri; +import android.os.AsyncTask; +import android.os.Build; +import android.os.Bundle; +import android.os.Environment; +import android.os.Process; import android.util.Log; -import android.view.Menu; +import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; +import android.view.WindowManager; import android.widget.Button; import android.widget.EditText; +import android.widget.RelativeLayout; import android.widget.TextView; +import android.widget.Toast; + +@SuppressLint("NewApi") +public class GpiiActivity extends Activity { + + private boolean isSystemApp; + private static String TAG = "Cloud4all"; + private static String filepathgpii = Environment + .getExternalStorageDirectory() + "/"; + + private boolean higherVersionKitKat = false; + + private static String uriTar = "http://docs.google.com/uc?authuser=0&id=0B9NaK6yZUAngMzdsRDdQWi1rbDg&export=download"; + + private static String gpiiJS = "gpii-android.tar.gz"; + private static String gpiiAPK = "net.gpii.app-1.apk"; + + private static String privSystemDir = "/system/priv-app"; + private static String systemDir = "/system/app"; + + private View progressView; + + private WindowManager.LayoutParams progressparams; + + private WindowManager wm; + + public static final int GPII_STATE_RUNNING = 0; + public static final int GPII_STATE_NOT_RUNNING = 1; + private static final String ACTION_GPII_UNZIP_COMPLETE = "net.gpii.app.ACTION_GPII_UNZIP_COMPLETE"; + + private TextView gpiiStatus; + private EditText gpiiScriptUri; + private Button gpiiStartButton; + private Button gpiiStopButton; + private Button gpiiKillButton; + private Button gpiiUpdateStatusButton; + private Button installationButton; + private Button downloadButton; + private RelativeLayout gpiiInfo; + + private long enqueue; + private DownloadManager dm; + + private AlertDialog.Builder alertDialogBuilder; + + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + try { + isSystemApp = isSystemPackage(this.getPackageManager() + .getApplicationInfo("net.gpii.app", 0)); + } catch (NameNotFoundException e1) { + Log.i("APPSISTEMA", "NO SE ENCUENTRA"); + e1.printStackTrace(); + } + + wm = (WindowManager) getSystemService(WINDOW_SERVICE); + getAndroidVersion(); + executeShellCommand("su"); + appInstalled("stericson.busybox"); + + progressparams = new WindowManager.LayoutParams( + WindowManager.LayoutParams.MATCH_PARENT, + WindowManager.LayoutParams.MATCH_PARENT, + WindowManager.LayoutParams.TYPE_SYSTEM_ALERT + | WindowManager.LayoutParams.TYPE_PHONE + | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, + WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE + | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL + | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, + PixelFormat.TRANSLUCENT); + + LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); + progressView = inflater + .inflate(R.layout.progress_download_layout, null); + + installationButton = (Button) findViewById(R.id.installButton); + downloadButton = (Button) findViewById(R.id.downloadButton); + + gpiiInfo = (RelativeLayout) findViewById(R.id.gpii_Info); + + File file = new File(Environment.getExternalStorageDirectory(), "gpii"); + + if (file.exists()) { + downloadButton.setVisibility(View.GONE); + installationButton.setVisibility(View.VISIBLE); + } + + if (isSystemApp) { + + downloadButton.setVisibility(View.GONE); + installationButton.setVisibility(View.GONE); + gpiiInfo.setVisibility(View.VISIBLE); + + } + + if (!gpiiApkInstalled("net.gpii.app")) { + Toast.makeText(getApplicationContext(), "GPII NOT INSTALLED", + Toast.LENGTH_LONG).show(); + downloadButton.setVisibility(View.VISIBLE); + installationButton.setVisibility(View.GONE); + } + + final 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)) { + + new ExtractGpiiZipFileSystem().execute(); + + } + } + + } else if (action.equals(ACTION_GPII_UNZIP_COMPLETE)) { + + downloadButton.setVisibility(View.GONE); + installationButton.setVisibility(View.VISIBLE); + wm.removeView(progressView); + + } + } + }; + + try { + unregisterReceiver(receiver); + } catch (IllegalArgumentException iae) { + iae.printStackTrace(); + } + + registerReceiver(receiver, new IntentFilter( + DownloadManager.ACTION_DOWNLOAD_COMPLETE)); + + registerReceiver(receiver, new IntentFilter(ACTION_GPII_UNZIP_COMPLETE)); + + installationButton.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + + new InstallationProccessTask().execute(); + + } + }); + + downloadButton.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + + wm.addView(progressView, progressparams); + dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); + Request request = new Request(Uri.parse(uriTar)); + request.setDestinationUri(Uri.fromFile(new File(filepathgpii + + gpiiJS))); + enqueue = dm.enqueue(request); + + } + }); + + gpiiStatus = (TextView) findViewById(R.id.gpii_status); + gpiiScriptUri = (EditText) findViewById(R.id.gpii_script_uri); + gpiiStartButton = (Button) findViewById(R.id.gpii_start_button); + gpiiStopButton = (Button) findViewById(R.id.gpii_stop_button); + gpiiKillButton = (Button) findViewById(R.id.gpii_kill_button); + gpiiUpdateStatusButton = (Button) findViewById(R.id.gpii_update_status_button); + + gpiiStartButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(); + intent.setAction("org.meshpoint.anode.START"); + intent.putExtra("cmdline", gpiiScriptUri.getText().toString()); + sendBroadcast(intent); + } + }); + + gpiiStopButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(); + intent.setAction("org.meshpoint.anode.STOPALL"); + sendBroadcast(intent); + } + }); + + gpiiKillButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + try { + ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); + List services = manager + .getRunningAppProcesses(); + RunningAppProcessInfo process = null; + + for (int i = 0; i < services.size(); i++) { + process = services.get(i); + String name = process.processName; + if (name.equals("net.gpii.app")) { + break; + } + } + + Process.killProcess(process.pid); + + } catch (Throwable e) { + e.printStackTrace(); + } + } + }); + + gpiiUpdateStatusButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + checkGPIIServer(); + } + }); + + checkGPIIServer(); + gpiiStatus.requestFocus(); + + } + + protected void checkGPIIServer() { + SocketClient sc = new SocketClient(); + sc.execute(GpiiActivity.this); + } + + public void updateStatus(Object status) { + if (status == (Object) GpiiActivity.GPII_STATE_RUNNING) { + gpiiStatus.setText(R.string.gpii_status_running); + gpiiStatus.setBackgroundColor(Color.GREEN); + gpiiStatus.setTypeface(null, Typeface.BOLD); + } else { + gpiiStatus.setText(R.string.gpii_status_not_running); + gpiiStatus.setBackgroundColor(Color.RED); + gpiiStatus.setTypeface(null, Typeface.BOLD); + } + } + + class SocketClient extends AsyncTask { + private static final String GPII_SERVER_HOST = "0.0.0.0"; + private static final int GPII_SERVER_PORT = 8081; + private static final int CONNECTION_TIMEOUT = 3000; + + @Override + protected Object doInBackground(Object... arg0) { + GpiiActivity activity = (GpiiActivity) arg0[0]; + Object result = null; + + try { + InetAddress address = InetAddress.getByName(GPII_SERVER_HOST); + Socket socket = new Socket(); + + socket.connect( + new InetSocketAddress(address, GPII_SERVER_PORT), + CONNECTION_TIMEOUT); + + if (socket.isConnected()) { + result = GpiiActivity.GPII_STATE_RUNNING; + } + + socket.close(); + } catch (Exception ex) { + result = GpiiActivity.GPII_STATE_NOT_RUNNING; + } + + return result; + } + + @Override + protected void onPostExecute(Object result) { + super.onPostExecute(result); + GpiiActivity.this.updateStatus(result); + } + } + + // Check Android version + public void getAndroidVersion() { + + int sdkVersion = Build.VERSION.SDK_INT; + String release = Build.VERSION.RELEASE; + + if (sdkVersion < 14 || sdkVersion > 21) { + + Intent browserIntent = new Intent( + Intent.ACTION_VIEW, + Uri.parse("http://wiki.gpii.net/index.php/GPII_Android_Devices_Compatibility_Table")); + startActivity(browserIntent); + } + // Log.i(TAG, "Android SDK: " + sdkVersion + " (" + release + ")"); + + if (sdkVersion > 18) { + higherVersionKitKat = true; + } + + } + + // Check rooted device + private void executeShellCommand(String command) { + + java.lang.Process process; + + try { + process = Runtime.getRuntime().exec(command); + Log.i(TAG, "Rooted device"); + } catch (Exception e) { + Log.i(TAG, "Not rooted device"); + Intent browserIntent = new Intent(Intent.ACTION_VIEW, + Uri.parse("http://wiki.gpii.net/w/List_of_root_devices")); + startActivity(browserIntent); + } + } + + // Check BusyBox installed + private void appInstalled(String app) { + + PackageManager pm = getPackageManager(); + + try { + + pm.getPackageInfo(app, PackageManager.GET_ACTIVITIES); + + } catch (PackageManager.NameNotFoundException e) { + + busyBoxNotInstalledDialog(app); + + } + } + + private boolean gpiiApkInstalled(String app) { + + PackageManager pm = getPackageManager(); + try { + pm.getPackageInfo(app, PackageManager.GET_ACTIVITIES); + return true; + } catch (PackageManager.NameNotFoundException e) { + + Log.i(TAG, "Gpii APK not installed"); + return false; + + } + } + + protected void gunzip(File tarFile, File dest) { + + try { + dest.mkdir(); + TarArchiveInputStream tarIn = null; + + tarIn = new TarArchiveInputStream(new GzipCompressorInputStream( + new BufferedInputStream(new FileInputStream(tarFile)))); + + TarArchiveEntry tarEntry = tarIn.getNextTarEntry(); + // tarIn is a TarArchiveInputStream + while (tarEntry != null) {// create a file with the same name as the + // tarEntry + File destPath = new File(dest, tarEntry.getName()); + System.out.println("working: " + destPath.getCanonicalPath()); + if (tarEntry.isDirectory()) { + destPath.mkdirs(); + } else { + destPath.createNewFile(); + // byte [] btoRead = new byte[(int)tarEntry.getSize()]; + byte[] btoRead = new byte[1024]; + // FileInputStream fin + // = new FileInputStream(destPath.getCanonicalPath()); + BufferedOutputStream bout = new BufferedOutputStream( + new FileOutputStream(destPath)); + int len = 0; + + while ((len = tarIn.read(btoRead)) != -1) { + bout.write(btoRead, 0, len); + } + + bout.close(); + btoRead = null; + + } + tarEntry = tarIn.getNextTarEntry(); + } + + tarIn.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + + } + + + public static void installGpiiApkIntoSystem(String apkname, + String privilegedDir) { + + java.lang.Process process; + + try { + + if (new File("/data/app", apkname).exists()) { + + process = Runtime.getRuntime().exec("su"); + DataOutputStream out = new DataOutputStream( + process.getOutputStream()); + out.writeBytes("mount -o rw,remount yaffs2 /system\n"); + out.writeBytes("chmod 777 " + privilegedDir + "\n"); + out.writeBytes("chmod 777 /data/app/" + apkname + "\n"); + out.writeBytes("cat /data/app/" + apkname + " > " + + privilegedDir + "/" + apkname + "\n"); + out.writeBytes("chmod 644 " + privilegedDir + "/" + apkname + + "\n"); + out.writeBytes("mount -o remount,ro -t yaffs2 /system\n"); + out.writeBytes("reboot\n"); + out.flush(); + process.waitFor(); + + } else { + Log.e("ERRORINSTALL", "No existe el apk de gpii"); + } + + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } + + private Dialog busyBoxNotInstalledDialog(String app) { + + final String appInstalled = app; + + alertDialogBuilder = new AlertDialog.Builder(this); + + // set title + alertDialogBuilder.setTitle("BusyBox Not Installed"); + + // set dialog message + alertDialogBuilder + .setMessage("Click download to download BusyBox") + // .setCancelable(false) + .setPositiveButton("Download", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + startActivity(new Intent(Intent.ACTION_VIEW, + Uri.parse("market://details?id=" + + appInstalled))); + } + }) + .setNegativeButton("Exit", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + + dialog.cancel(); + GpiiActivity.this.finish(); + + } + }); + + alertDialogBuilder.create(); + + return alertDialogBuilder.show(); + + } + + private class ExtractGpiiZipFileSystem extends AsyncTask { + + @Override + protected void onPostExecute(Void result) { + + super.onPostExecute(result); + + Intent nfcDiscoveredIntent = new Intent(ACTION_GPII_UNZIP_COMPLETE); + sendBroadcast(nfcDiscoveredIntent); + + } + + @Override + protected Void doInBackground(Void... params) { + + File fileTar = new File(filepathgpii + gpiiJS); + File fileDest = new File(filepathgpii); + + gunzip(fileTar, fileDest); + + return null; + } + + } + + + private class InstallationProccessTask extends AsyncTask { + + @Override + protected void onPostExecute(Void result) { + + super.onPostExecute(result); + + } + + @Override + protected Void doInBackground(Void... params) { + + if (higherVersionKitKat) { + + installGpiiApkIntoSystem(gpiiAPK, privSystemDir); + + } else { + + installGpiiApkIntoSystem(gpiiAPK, systemDir); + } + + return null; + } + + } + + private boolean isSystemPackage(ApplicationInfo applicationInfo) { + + return ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0); + } -public class GpiiActivity extends Activity -{ - - public static final int GPII_STATE_RUNNING = 0; - public static final int GPII_STATE_NOT_RUNNING = 1; - - private TextView gpiiStatus; - private EditText gpiiScriptUri; - private Button gpiiStartButton; - private Button gpiiStopButton; - private Button gpiiKillButton; - private Button gpiiUpdateStatusButton; - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - setContentView(R.layout.main); - - gpiiStatus = (TextView)findViewById(R.id.gpii_status); - gpiiScriptUri = (EditText)findViewById(R.id.gpii_script_uri); - gpiiStartButton = (Button)findViewById(R.id.gpii_start_button); - gpiiStopButton = (Button)findViewById(R.id.gpii_stop_button); - gpiiKillButton = (Button)findViewById(R.id.gpii_kill_button); - gpiiUpdateStatusButton = (Button)findViewById(R.id.gpii_update_status_button); - - gpiiStartButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(); - intent.setAction("org.meshpoint.anode.START"); - intent.putExtra("cmdline", gpiiScriptUri.getText().toString()); - sendBroadcast(intent); - } - }); - - gpiiStopButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(); - intent.setAction("org.meshpoint.anode.STOPALL"); - sendBroadcast(intent); - } - }); - - gpiiKillButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - try { - ActivityManager manager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); - List services = manager.getRunningAppProcesses(); - RunningAppProcessInfo process = null; - - for (int i = 0; i < services.size(); i++) { - process = services.get(i); - String name = process.processName; - if (name.equals("net.gpii.app")) { - break; - } - } - - Process.killProcess(process.pid); - - } catch (Throwable e) { - e.printStackTrace(); - } - } - }); - - gpiiUpdateStatusButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - checkGPIIServer(); - } - }); - - checkGPIIServer(); - gpiiStatus.requestFocus(); - } - - protected void checkGPIIServer (){ - SocketClient sc = new SocketClient(); - sc.execute(GpiiActivity.this); - } - - public void updateStatus (Object status) { - if (status == (Object) GpiiActivity.GPII_STATE_RUNNING){ - gpiiStatus.setText(R.string.gpii_status_running); - gpiiStatus.setBackgroundColor(Color.GREEN); - gpiiStatus.setTypeface(null,Typeface.BOLD); - } else { - gpiiStatus.setText(R.string.gpii_status_not_running); - gpiiStatus.setBackgroundColor(Color.RED); - gpiiStatus.setTypeface(null,Typeface.BOLD); - } - } - - class SocketClient extends AsyncTask { - private static final String GPII_SERVER_HOST = "0.0.0.0"; - private static final int GPII_SERVER_PORT = 8081; - private static final int CONNECTION_TIMEOUT = 3000; - - @Override - protected Object doInBackground(Object... arg0) { - GpiiActivity activity = (GpiiActivity) arg0[0]; - Object result = null; - - try { - InetAddress address = InetAddress.getByName(GPII_SERVER_HOST); - Socket socket = new Socket(); - - socket.connect(new InetSocketAddress(address, GPII_SERVER_PORT), CONNECTION_TIMEOUT); - - if (socket.isConnected()) { - result = GpiiActivity.GPII_STATE_RUNNING; - } - - socket.close(); - } catch (Exception ex) { - result = GpiiActivity.GPII_STATE_NOT_RUNNING; - } - - return result; - } - - @Override - protected void onPostExecute(Object result) { - super.onPostExecute(result); - GpiiActivity.this.updateStatus(result); - } - } } From 02c1f08d632fc37d20bab89226fe318cb9fcf8c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Hern=C3=A1ndez?= Date: Tue, 7 Jul 2015 14:50:41 +0200 Subject: [PATCH 2/8] Added 4 spaces instead tabulation on GpiiActivity.java. Added header --- .../app/src/net/gpii/app/GpiiActivity.java | 752 +++++++++--------- 1 file changed, 382 insertions(+), 370 deletions(-) diff --git a/platform/app/src/net/gpii/app/GpiiActivity.java b/platform/app/src/net/gpii/app/GpiiActivity.java index 442edc8..74f005c 100644 --- a/platform/app/src/net/gpii/app/GpiiActivity.java +++ b/platform/app/src/net/gpii/app/GpiiActivity.java @@ -1,3 +1,16 @@ +/* +* GPII Android Personalization Framework +* +* Licensed under the New BSD license. You may not use this file except in +* compliance with this License. +* +* The research leading to these results has received funding from the European Union's +* Seventh Framework Programme (FP7/2007-2013) +* under grant agreement no. 289016. +* +* You may obtain a copy of the License at +* https://github.com/GPII/universal/blob/master/LICENSE.txt +*/ package net.gpii.app; import java.io.BufferedInputStream; @@ -62,9 +75,9 @@ public class GpiiActivity extends Activity { private static String filepathgpii = Environment .getExternalStorageDirectory() + "/"; - private boolean higherVersionKitKat = false; + private boolean higherVersionKitKat = false; - private static String uriTar = "http://docs.google.com/uc?authuser=0&id=0B9NaK6yZUAngMzdsRDdQWi1rbDg&export=download"; + private static String uriTar = "http://docs.google.com/uc?authuser=0&id=0B9NaK6yZUAngMzdsRDdQWi1rbDg&export=download"; private static String gpiiCompatibleAndroidDevicesUrl = "http://wiki.gpii.net/index.php/GPII_Android_Devices_Compatibility_Table"; @@ -82,92 +95,91 @@ public class GpiiActivity extends Activity { private WindowManager wm; - public static final int GPII_STATE_RUNNING = 0; - public static final int GPII_STATE_NOT_RUNNING = 1; - private static final String ACTION_GPII_UNZIP_COMPLETE = "net.gpii.app.ACTION_GPII_UNZIP_COMPLETE"; - - private TextView gpiiStatus; - private EditText gpiiScriptUri; - private Button gpiiStartButton; - private Button gpiiStopButton; - private Button gpiiKillButton; - private Button gpiiUpdateStatusButton; - private Button installationButton; - private Button downloadButton; - private RelativeLayout gpiiInfo; - - private long enqueue; + public static final int GPII_STATE_RUNNING = 0; + public static final int GPII_STATE_NOT_RUNNING = 1; + private static final String ACTION_GPII_UNZIP_COMPLETE = "net.gpii.app.ACTION_GPII_UNZIP_COMPLETE"; + + private TextView gpiiStatus; + private EditText gpiiScriptUri; + private Button gpiiStartButton; + private Button gpiiStopButton; + private Button gpiiKillButton; + private Button gpiiUpdateStatusButton; + private Button installationButton; + private Button downloadButton; + private RelativeLayout gpiiInfo; + + private long enqueue; private DownloadManager dm; private AlertDialog.Builder alertDialogBuilder; /** Called when the activity is first created. */ @Override - public void onCreate(Bundle savedInstanceState) { - - super.onCreate(savedInstanceState); - setContentView(R.layout.main); - - try { - isSystemApp = isSystemPackage(this.getPackageManager() - .getApplicationInfo("net.gpii.app", 0)); - } catch (NameNotFoundException e1) { - e1.printStackTrace(); - } - - wm = (WindowManager) getSystemService(WINDOW_SERVICE); - getAndroidVersion(); - executeShellCommand("su"); - appInstalled("stericson.busybox"); - - progressparams = new WindowManager.LayoutParams( - WindowManager.LayoutParams.MATCH_PARENT, - WindowManager.LayoutParams.MATCH_PARENT, - WindowManager.LayoutParams.TYPE_SYSTEM_ALERT - | WindowManager.LayoutParams.TYPE_PHONE - | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, - WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE - | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL - | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, - PixelFormat.TRANSLUCENT); - - LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); - progressView = inflater - .inflate(R.layout.progress_download_layout, null); - - installationButton = (Button) findViewById(R.id.installButton); - downloadButton = (Button) findViewById(R.id.downloadButton); - - gpiiInfo = (RelativeLayout) findViewById(R.id.gpii_Info); - - File file = new File(Environment.getExternalStorageDirectory(), "gpii"); - - if (file.exists()) { - downloadButton.setVisibility(View.GONE); - installationButton.setVisibility(View.VISIBLE); - } - - if (isSystemApp) { - - downloadButton.setVisibility(View.GONE); - installationButton.setVisibility(View.GONE); - gpiiInfo.setVisibility(View.VISIBLE); - - } - - if (!gpiiApkInstalled("net.gpii.app")) { - Toast.makeText(getApplicationContext(), "GPII NOT INSTALLED", - Toast.LENGTH_LONG).show(); - downloadButton.setVisibility(View.VISIBLE); - installationButton.setVisibility(View.GONE); - } - - final BroadcastReceiver receiver = new BroadcastReceiver() { - - @Override - public void onReceive(Context context, Intent intent) { + public void onCreate(Bundle savedInstanceState) { + + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + try { + isSystemApp = isSystemPackage(this.getPackageManager() + .getApplicationInfo("net.gpii.app", 0)); + } catch (NameNotFoundException e1) { + e1.printStackTrace(); + } + + wm = (WindowManager) getSystemService(WINDOW_SERVICE); + getAndroidVersion(); + executeShellCommand("su"); + appInstalled("stericson.busybox"); + + progressparams = new WindowManager.LayoutParams( + WindowManager.LayoutParams.MATCH_PARENT, + WindowManager.LayoutParams.MATCH_PARENT, + WindowManager.LayoutParams.TYPE_SYSTEM_ALERT + | WindowManager.LayoutParams.TYPE_PHONE + | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, + WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE + | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL + |WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, + PixelFormat.TRANSLUCENT); + + LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); + progressView = inflater + .inflate(R.layout.progress_download_layout, null); + + installationButton = (Button)findViewById(R.id.installButton); + downloadButton = (Button) findViewById(R.id.downloadButton); + + gpiiInfo = (RelativeLayout) findViewById(R.id.gpii_Info); + + File file = new File(Environment.getExternalStorageDirectory(), "gpii"); + + if (file.exists()) { + downloadButton.setVisibility(View.GONE); + installationButton.setVisibility(View.VISIBLE); + } + + if (isSystemApp) { + + downloadButton.setVisibility(View.GONE); + installationButton.setVisibility(View.GONE); + gpiiInfo.setVisibility(View.VISIBLE); + } + + if (!gpiiApkInstalled("net.gpii.app")) { + Toast.makeText(getApplicationContext(), "GPII NOT INSTALLED", + Toast.LENGTH_LONG).show(); + downloadButton.setVisibility(View.VISIBLE); + installationButton.setVisibility(View.GONE); + } + + final BroadcastReceiver receiver = new BroadcastReceiver() { + + @Override + public void onReceive(Context context, Intent intent) { String action = intent.getAction(); - if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { + if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { long downloadId = intent.getLongExtra( DownloadManager.EXTRA_DOWNLOAD_ID, 0); Query query = new Query(); @@ -176,337 +188,337 @@ public void onReceive(Context context, Intent intent) { if (c.moveToFirst()) { int columnIndex = c .getColumnIndex(DownloadManager.COLUMN_STATUS); - if (DownloadManager.STATUS_SUCCESSFUL == c + if (DownloadManager.STATUS_SUCCESSFUL == c .getInt(columnIndex)) { new ExtractGpiiZipFileSystem().execute(); - } - } + } + } - } else if (action.equals(ACTION_GPII_UNZIP_COMPLETE)) { + } else if (action.equals(ACTION_GPII_UNZIP_COMPLETE)) { downloadButton.setVisibility(View.GONE); installationButton.setVisibility(View.VISIBLE); wm.removeView(progressView); - } - } - }; + } + } + }; - try { - unregisterReceiver(receiver); - } catch (IllegalArgumentException iae) { - iae.printStackTrace(); - } + try { + unregisterReceiver(receiver); + } catch (IllegalArgumentException iae) { + iae.printStackTrace(); + } - registerReceiver(receiver, new IntentFilter( + registerReceiver(receiver, new IntentFilter( DownloadManager.ACTION_DOWNLOAD_COMPLETE)); - registerReceiver(receiver, new IntentFilter(ACTION_GPII_UNZIP_COMPLETE)); + registerReceiver(receiver, new IntentFilter(ACTION_GPII_UNZIP_COMPLETE)); - installationButton.setOnClickListener(new OnClickListener() { + installationButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { + @Override + public void onClick(View v) { - new InstallationProccessTask().execute(); + new InstallationProccessTask().execute(); - } - }); + } + }); - downloadButton.setOnClickListener(new OnClickListener() { + downloadButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { + @Override + public void onClick(View v) { - wm.addView(progressView, progressparams); - dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); - Request request = new Request(Uri.parse(uriTar)); + wm.addView(progressView, progressparams); + dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); + Request request = new Request(Uri.parse(uriTar)); request.setDestinationUri(Uri.fromFile(new File(filepathgpii + gpiiJS))); - enqueue = dm.enqueue(request); - - } - }); - - gpiiStatus = (TextView) findViewById(R.id.gpii_status); - gpiiScriptUri = (EditText) findViewById(R.id.gpii_script_uri); - gpiiStartButton = (Button) findViewById(R.id.gpii_start_button); - gpiiStopButton = (Button) findViewById(R.id.gpii_stop_button); - gpiiKillButton = (Button) findViewById(R.id.gpii_kill_button); - gpiiUpdateStatusButton = (Button) findViewById(R.id.gpii_update_status_button); - - gpiiStartButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(); - intent.setAction("org.meshpoint.anode.START"); - intent.putExtra("cmdline", gpiiScriptUri.getText().toString()); - sendBroadcast(intent); - } - }); - - gpiiStopButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(); - intent.setAction("org.meshpoint.anode.STOPALL"); - sendBroadcast(intent); - } - }); - - gpiiKillButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - try { - ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); - List services = manager + enqueue = dm.enqueue(request); + + } + }); + + gpiiStatus = (TextView) findViewById(R.id.gpii_status); + gpiiScriptUri = (EditText) findViewById(R.id.gpii_script_uri); + gpiiStartButton = (Button) findViewById(R.id.gpii_start_button); + gpiiStopButton = (Button) findViewById(R.id.gpii_stop_button); + gpiiKillButton = (Button) findViewById(R.id.gpii_kill_button); + gpiiUpdateStatusButton = (Button) findViewById(R.id.gpii_update_status_button); + + gpiiStartButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(); + intent.setAction("org.meshpoint.anode.START"); + intent.putExtra("cmdline", gpiiScriptUri.getText().toString()); + sendBroadcast(intent); + } + }); + + gpiiStopButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(); + intent.setAction("org.meshpoint.anode.STOPALL"); + sendBroadcast(intent); + } + }); + + gpiiKillButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + try { + ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); + List services = manager .getRunningAppProcesses(); RunningAppProcessInfo process = null; - for (int i = 0; i < services.size(); i++) { + for (int i = 0; i < services.size(); i++) { process = services.get(i); - String name = process.processName; - if (name.equals("net.gpii.app")) { - break; - } - } - - Process.killProcess(process.pid); - - } catch (Throwable e) { - e.printStackTrace(); - } - } - }); - - gpiiUpdateStatusButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - checkGPIIServer(); - } - }); - - checkGPIIServer(); - gpiiStatus.requestFocus(); - - } - - protected void checkGPIIServer() { - SocketClient sc = new SocketClient(); - sc.execute(GpiiActivity.this); - } - - public void updateStatus(Object status) { - if (status == (Object) GpiiActivity.GPII_STATE_RUNNING) { - gpiiStatus.setText(R.string.gpii_status_running); - gpiiStatus.setBackgroundColor(Color.GREEN); - gpiiStatus.setTypeface(null, Typeface.BOLD); - } else { - gpiiStatus.setText(R.string.gpii_status_not_running); - gpiiStatus.setBackgroundColor(Color.RED); - gpiiStatus.setTypeface(null, Typeface.BOLD); - } - } - - class SocketClient extends AsyncTask { - private static final String GPII_SERVER_HOST = "0.0.0.0"; - private static final int GPII_SERVER_PORT = 8081; - private static final int CONNECTION_TIMEOUT = 3000; - - @Override - protected Object doInBackground(Object... arg0) { - GpiiActivity activity = (GpiiActivity) arg0[0]; - Object result = null; - - try { - InetAddress address = InetAddress.getByName(GPII_SERVER_HOST); - Socket socket = new Socket(); - - socket.connect( + String name = process.processName; + if (name.equals("net.gpii.app")) { + break; + } + } + + Process.killProcess(process.pid); + + } catch (Throwable e) { + e.printStackTrace(); + } + } + + }); + + gpiiUpdateStatusButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + checkGPIIServer(); + } + }); + + checkGPIIServer(); + gpiiStatus.requestFocus(); + + } + + protected void checkGPIIServer() { + SocketClient sc = new SocketClient(); + sc.execute(GpiiActivity.this); + } + + public void updateStatus(Object status) { + if (status == (Object) GpiiActivity.GPII_STATE_RUNNING) { + gpiiStatus.setText(R.string.gpii_status_running); + gpiiStatus.setBackgroundColor(Color.GREEN); + gpiiStatus.setTypeface(null, Typeface.BOLD); + } else { + gpiiStatus.setText(R.string.gpii_status_not_running); + gpiiStatus.setBackgroundColor(Color.RED); + gpiiStatus.setTypeface(null, Typeface.BOLD); + } + } + + class SocketClient extends AsyncTask { + private static final String GPII_SERVER_HOST = "0.0.0.0"; + private static final int GPII_SERVER_PORT = 8081; + private static final int CONNECTION_TIMEOUT = 3000; + + @Override + protected Object doInBackground(Object... arg0) { + GpiiActivity activity = (GpiiActivity) arg0[0]; + Object result = null; + + try { + InetAddress address = InetAddress.getByName(GPII_SERVER_HOST); + Socket socket = new Socket(); + + socket.connect( new InetSocketAddress(address, GPII_SERVER_PORT), CONNECTION_TIMEOUT); - if (socket.isConnected()) { + if (socket.isConnected()) { result = GpiiActivity.GPII_STATE_RUNNING; - } + } - socket.close(); - } catch (Exception ex) { - result = GpiiActivity.GPII_STATE_NOT_RUNNING; - } + socket.close(); + } catch (Exception ex) { + result = GpiiActivity.GPII_STATE_NOT_RUNNING; + } - return result; - } + return result; + } - @Override - protected void onPostExecute(Object result) { - super.onPostExecute(result); - GpiiActivity.this.updateStatus(result); - } - } + @Override + protected void onPostExecute(Object result) { + super.onPostExecute(result); + GpiiActivity.this.updateStatus(result); + } + } - // Check Android version - public void getAndroidVersion() { + // Check Android version + public void getAndroidVersion() { - int sdkVersion = Build.VERSION.SDK_INT; - String release = Build.VERSION.RELEASE; + int sdkVersion = Build.VERSION.SDK_INT; + String release = Build.VERSION.RELEASE; - if (sdkVersion < 14 || sdkVersion > 21) { + if (sdkVersion < 14 || sdkVersion > 21) { - launchWebPage(gpiiCompatibleAndroidDevicesUrl); + launchWebPage(gpiiCompatibleAndroidDevicesUrl); - } + } - if (sdkVersion > 18) { - higherVersionKitKat = true; - } + if (sdkVersion > 18) { + higherVersionKitKat = true; + } - } + } - // Check rooted device - private void executeShellCommand(String command) { + // Check rooted device + private void executeShellCommand(String command) { - java.lang.Process process; + java.lang.Process process; - try { - process = Runtime.getRuntime().exec(command); - Log.i(TAG, "Rooted device"); - } catch (Exception e) { - Log.i(TAG, "Not rooted device"); - launchWebPage(gpiiRootDevicesUrl); - } - } + try { + process = Runtime.getRuntime().exec(command); + Log.i(TAG, "Rooted device"); + } catch (Exception e) { + Log.i(TAG, "Not rooted device"); + launchWebPage(gpiiRootDevicesUrl); + } + } - // Check BusyBox installed - private void appInstalled(String app) { + // Check BusyBox installed + private void appInstalled(String app) { - PackageManager pm = getPackageManager(); + PackageManager pm = getPackageManager(); - try { + try { - pm.getPackageInfo(app, PackageManager.GET_ACTIVITIES); + pm.getPackageInfo(app, PackageManager.GET_ACTIVITIES); - } catch (PackageManager.NameNotFoundException e) { + } catch (PackageManager.NameNotFoundException e) { - busyBoxNotInstalledDialog(app); + busyBoxNotInstalledDialog(app); - } - } + } + } - private boolean gpiiApkInstalled(String app) { + private boolean gpiiApkInstalled(String app) { - PackageManager pm = getPackageManager(); - try { - pm.getPackageInfo(app, PackageManager.GET_ACTIVITIES); - return true; - } catch (PackageManager.NameNotFoundException e) { + PackageManager pm = getPackageManager(); + try { + pm.getPackageInfo(app, PackageManager.GET_ACTIVITIES); + return true; + } catch (PackageManager.NameNotFoundException e) { - Log.i(TAG, "Gpii APK not installed"); - return false; + Log.i(TAG, "Gpii APK not installed"); + return false; - } - } + } + } - protected void gunzip(File tarFile, File dest) { + protected void gunzip(File tarFile, File dest) { - try { - dest.mkdir(); - TarArchiveInputStream tarIn = null; + try { + dest.mkdir(); + TarArchiveInputStream tarIn = null; - tarIn = new TarArchiveInputStream(new GzipCompressorInputStream( + tarIn = new TarArchiveInputStream(new GzipCompressorInputStream( new BufferedInputStream(new FileInputStream(tarFile)))); - TarArchiveEntry tarEntry = tarIn.getNextTarEntry(); - // tarIn is a TarArchiveInputStream - while (tarEntry != null) {// create a file with the same name as the + TarArchiveEntry tarEntry = tarIn.getNextTarEntry(); + // tarIn is a TarArchiveInputStream + while (tarEntry != null) {// create a file with the same name as the // tarEntry - File destPath = new File(dest, tarEntry.getName()); - System.out.println("working: " + destPath.getCanonicalPath()); - if (tarEntry.isDirectory()) { - destPath.mkdirs(); - } else { - destPath.createNewFile(); - // byte [] btoRead = new byte[(int)tarEntry.getSize()]; - byte[] btoRead = new byte[1024]; - // FileInputStream fin - // = new FileInputStream(destPath.getCanonicalPath()); - BufferedOutputStream bout = new BufferedOutputStream( - new FileOutputStream(destPath)); - int len = 0; - - while ((len = tarIn.read(btoRead)) != -1) { - bout.write(btoRead, 0, len); - } - - bout.close(); - btoRead = null; - - } - tarEntry = tarIn.getNextTarEntry(); - } - - tarIn.close(); - - } catch (IOException e) { - e.printStackTrace(); - } - - } + File destPath = new File(dest, tarEntry.getName()); + System.out.println("working: " + destPath.getCanonicalPath()); + if (tarEntry.isDirectory()) { + destPath.mkdirs(); + } else { + destPath.createNewFile(); + // byte [] btoRead = new byte[(int)tarEntry.getSize()]; + byte[] btoRead = new byte[1024]; + // FileInputStream fin + // = new FileInputStream(destPath.getCanonicalPath()); + BufferedOutputStream bout = new BufferedOutputStream( + new FileOutputStream(destPath)); + int len = 0; + + while ((len = tarIn.read(btoRead)) != -1) { + bout.write(btoRead, 0, len); + } + + bout.close(); + btoRead = null; + + } + tarEntry = tarIn.getNextTarEntry(); + } + + tarIn.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + + } - public static void installGpiiApkIntoSystem(String apkname, + public static void installGpiiApkIntoSystem(String apkname, String privilegedDir) { - java.lang.Process process; + java.lang.Process process; - try { + try { - if (new File("/data/app", apkname).exists()) { + if (new File("/data/app", apkname).exists()) { - process = Runtime.getRuntime().exec("su"); - DataOutputStream out = new DataOutputStream( + process = Runtime.getRuntime().exec("su"); + DataOutputStream out = new DataOutputStream( process.getOutputStream()); - out.writeBytes("mount -o rw,remount yaffs2 /system\n"); - out.writeBytes("chmod 777 " + privilegedDir + "\n"); - out.writeBytes("chmod 777 /data/app/" + apkname + "\n"); - out.writeBytes("cat /data/app/" + apkname + " > " + out.writeBytes("mount -o rw,remount yaffs2 /system\n"); + out.writeBytes("chmod 777 " + privilegedDir + "\n"); + out.writeBytes("chmod 777 /data/app/" + apkname + "\n"); + out.writeBytes("cat /data/app/" + apkname + " > " + privilegedDir + "/" + apkname + "\n"); - out.writeBytes("chmod 644 " + privilegedDir + "/" + apkname + out.writeBytes("chmod 644 " + privilegedDir + "/" + apkname + "\n"); - out.writeBytes("mount -o remount,ro -t yaffs2 /system\n"); - out.writeBytes("reboot\n"); - out.flush(); - process.waitFor(); + out.writeBytes("mount -o remount,ro -t yaffs2 /system\n"); + out.writeBytes("reboot\n"); + out.flush(); + process.waitFor(); - } else { + } else { - Log.e(TAG, "THERE IS NOT APK"); - } + Log.e(TAG, "THERE IS NOT APK"); + } - } catch (IOException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); - } + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } - } + } - private Dialog busyBoxNotInstalledDialog(String app) { + private Dialog busyBoxNotInstalledDialog(String app) { - final String appInstalled = app; + final String appInstalled = app; - alertDialogBuilder = new AlertDialog.Builder(this); + alertDialogBuilder = new AlertDialog.Builder(this); - // set title - alertDialogBuilder.setTitle("BusyBox Not Installed"); + // set title + alertDialogBuilder.setTitle("BusyBox Not Installed"); - // set dialog message - alertDialogBuilder - .setMessage("Click download to download BusyBox") - // .setCancelable(false) - .setPositiveButton("Download", + // set dialog message + alertDialogBuilder.setMessage("Click download to download BusyBox") + // .setCancelable(false) + .setPositiveButton("Download", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { startActivity(new Intent(Intent.ACTION_VIEW, @@ -524,73 +536,73 @@ public void onClick(DialogInterface dialog, int id) { } }); - alertDialogBuilder.create(); + alertDialogBuilder.create(); - return alertDialogBuilder.show(); + return alertDialogBuilder.show(); - } + } - private class ExtractGpiiZipFileSystem extends AsyncTask { + private class ExtractGpiiZipFileSystem extends AsyncTask { - @Override - protected void onPostExecute(Void result) { + @Override + protected void onPostExecute(Void result) { - super.onPostExecute(result); + super.onPostExecute(result); - Intent nfcDiscoveredIntent = new Intent(ACTION_GPII_UNZIP_COMPLETE); - sendBroadcast(nfcDiscoveredIntent); + Intent nfcDiscoveredIntent = new Intent(ACTION_GPII_UNZIP_COMPLETE); + sendBroadcast(nfcDiscoveredIntent); - } + } - @Override - protected Void doInBackground(Void... params) { + @Override + protected Void doInBackground(Void... params) { - File fileTar = new File(filepathgpii + gpiiJS); - File fileDest = new File(filepathgpii); + File fileTar = new File(filepathgpii + gpiiJS); + File fileDest = new File(filepathgpii); - gunzip(fileTar, fileDest); + gunzip(fileTar, fileDest); - return null; - } + return null; + } - } + } - private class InstallationProccessTask extends AsyncTask { + private class InstallationProccessTask extends AsyncTask { - @Override - protected void onPostExecute(Void result) { + @Override + protected void onPostExecute(Void result) { - super.onPostExecute(result); + super.onPostExecute(result); - } + } - @Override - protected Void doInBackground(Void... params) { + @Override + protected Void doInBackground(Void... params) { - if (higherVersionKitKat) { + if (higherVersionKitKat) { - installGpiiApkIntoSystem(gpiiAPK, privSystemDir); + installGpiiApkIntoSystem(gpiiAPK, privSystemDir); - } else { + } else { - installGpiiApkIntoSystem(gpiiAPK, systemDir); - } + installGpiiApkIntoSystem(gpiiAPK, systemDir); + } - return null; - } + return null; + } - } + } - private boolean isSystemPackage(ApplicationInfo applicationInfo) { + private boolean isSystemPackage(ApplicationInfo applicationInfo) { - return ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0); - } + return ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0); + } private void launchWebPage(String url){ - Intent browserIntent = new Intent(Intent.ACTION_VIEW, + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - startActivity(browserIntent); + startActivity(browserIntent); } } From 5df96c2512e7e9b1c23e42b3308f2ecab1207d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Hern=C3=A1ndez?= Date: Mon, 13 Jul 2015 13:08:40 +0200 Subject: [PATCH 3/8] New indentation added to whole class with four spaces --- .../app/src/net/gpii/app/GpiiActivity.java | 166 +++++++++--------- 1 file changed, 82 insertions(+), 84 deletions(-) diff --git a/platform/app/src/net/gpii/app/GpiiActivity.java b/platform/app/src/net/gpii/app/GpiiActivity.java index 74f005c..0736404 100644 --- a/platform/app/src/net/gpii/app/GpiiActivity.java +++ b/platform/app/src/net/gpii/app/GpiiActivity.java @@ -78,7 +78,7 @@ public class GpiiActivity extends Activity { private boolean higherVersionKitKat = false; private static String uriTar = "http://docs.google.com/uc?authuser=0&id=0B9NaK6yZUAngMzdsRDdQWi1rbDg&export=download"; - + private static String gpiiCompatibleAndroidDevicesUrl = "http://wiki.gpii.net/index.php/GPII_Android_Devices_Compatibility_Table"; private static String gpiiRootDevicesUrl = "http://wiki.gpii.net/w/List_of_root_devices"; @@ -114,15 +114,15 @@ public class GpiiActivity extends Activity { private AlertDialog.Builder alertDialogBuilder; - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) { + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { - isSystemApp = isSystemPackage(this.getPackageManager() + isSystemApp = isSystemPackage(this.getPackageManager() .getApplicationInfo("net.gpii.app", 0)); } catch (NameNotFoundException e1) { e1.printStackTrace(); @@ -134,19 +134,19 @@ public void onCreate(Bundle savedInstanceState) { appInstalled("stericson.busybox"); progressparams = new WindowManager.LayoutParams( - WindowManager.LayoutParams.MATCH_PARENT, - WindowManager.LayoutParams.MATCH_PARENT, - WindowManager.LayoutParams.TYPE_SYSTEM_ALERT - | WindowManager.LayoutParams.TYPE_PHONE - | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, - WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE - | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL - |WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, - PixelFormat.TRANSLUCENT); + WindowManager.LayoutParams.MATCH_PARENT, + WindowManager.LayoutParams.MATCH_PARENT, + WindowManager.LayoutParams.TYPE_SYSTEM_ALERT | + WindowManager.LayoutParams.TYPE_PHONE | + WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, + WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | + WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | + WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, + PixelFormat.TRANSLUCENT); LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); progressView = inflater - .inflate(R.layout.progress_download_layout, null); + .inflate(R.layout.progress_download_layout, null); installationButton = (Button)findViewById(R.id.installButton); downloadButton = (Button) findViewById(R.id.downloadButton); @@ -169,38 +169,35 @@ public void onCreate(Bundle savedInstanceState) { if (!gpiiApkInstalled("net.gpii.app")) { Toast.makeText(getApplicationContext(), "GPII NOT INSTALLED", - Toast.LENGTH_LONG).show(); + Toast.LENGTH_LONG).show(); downloadButton.setVisibility(View.VISIBLE); installationButton.setVisibility(View.GONE); } final 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)) { - - new ExtractGpiiZipFileSystem().execute(); - + @Override + public void onReceive(Context context, Intent intent) { + 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)) { + + new ExtractGpiiZipFileSystem().execute(); + } } } else if (action.equals(ACTION_GPII_UNZIP_COMPLETE)) { - downloadButton.setVisibility(View.GONE); - installationButton.setVisibility(View.VISIBLE); - wm.removeView(progressView); + downloadButton.setVisibility(View.GONE); + installationButton.setVisibility(View.VISIBLE); + wm.removeView(progressView); } } @@ -212,8 +209,7 @@ public void onReceive(Context context, Intent intent) { iae.printStackTrace(); } - registerReceiver(receiver, new IntentFilter( - DownloadManager.ACTION_DOWNLOAD_COMPLETE)); + registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); registerReceiver(receiver, new IntentFilter(ACTION_GPII_UNZIP_COMPLETE)); @@ -235,8 +231,7 @@ public void onClick(View v) { wm.addView(progressView, progressparams); dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); Request request = new Request(Uri.parse(uriTar)); - request.setDestinationUri(Uri.fromFile(new File(filepathgpii - + gpiiJS))); + request.setDestinationUri(Uri.fromFile(new File(filepathgpii + gpiiJS))); enqueue = dm.enqueue(request); } @@ -272,14 +267,16 @@ public void onClick(View v) { @Override public void onClick(View v) { try { - ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); + ActivityManager manager = + (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); List services = manager - .getRunningAppProcesses(); - RunningAppProcessInfo process = null; + .getRunningAppProcesses(); + RunningAppProcessInfo process = null; for (int i = 0; i < services.size(); i++) { - process = services.get(i); + process = services.get(i); String name = process.processName; + if (name.equals("net.gpii.app")) { break; } @@ -337,20 +334,19 @@ protected Object doInBackground(Object... arg0) { InetAddress address = InetAddress.getByName(GPII_SERVER_HOST); Socket socket = new Socket(); - socket.connect( - new InetSocketAddress(address, GPII_SERVER_PORT), - CONNECTION_TIMEOUT); + socket.connect(new InetSocketAddress(address, GPII_SERVER_PORT), + CONNECTION_TIMEOUT); if (socket.isConnected()) { - result = GpiiActivity.GPII_STATE_RUNNING; + result = GpiiActivity.GPII_STATE_RUNNING; } socket.close(); - } catch (Exception ex) { - result = GpiiActivity.GPII_STATE_NOT_RUNNING; - } + } catch (Exception ex) { + result = GpiiActivity.GPII_STATE_NOT_RUNNING; + } - return result; + return result; } @Override @@ -429,24 +425,25 @@ protected void gunzip(File tarFile, File dest) { TarArchiveInputStream tarIn = null; tarIn = new TarArchiveInputStream(new GzipCompressorInputStream( - new BufferedInputStream(new FileInputStream(tarFile)))); + new BufferedInputStream(new FileInputStream(tarFile)))); TarArchiveEntry tarEntry = tarIn.getNextTarEntry(); // tarIn is a TarArchiveInputStream - while (tarEntry != null) {// create a file with the same name as the - // tarEntry + while (tarEntry != null) { + // create a file with the same name as the + // tarEntry File destPath = new File(dest, tarEntry.getName()); System.out.println("working: " + destPath.getCanonicalPath()); if (tarEntry.isDirectory()) { destPath.mkdirs(); } else { destPath.createNewFile(); - // byte [] btoRead = new byte[(int)tarEntry.getSize()]; + // byte [] btoRead = new byte[(int)tarEntry.getSize()]; byte[] btoRead = new byte[1024]; // FileInputStream fin // = new FileInputStream(destPath.getCanonicalPath()); - BufferedOutputStream bout = new BufferedOutputStream( - new FileOutputStream(destPath)); + BufferedOutputStream bout = + new BufferedOutputStream(new FileOutputStream(destPath)); int len = 0; while ((len = tarIn.read(btoRead)) != -1) { @@ -467,10 +464,10 @@ protected void gunzip(File tarFile, File dest) { } } - + public static void installGpiiApkIntoSystem(String apkname, - String privilegedDir) { + String privilegedDir) { java.lang.Process process; @@ -480,21 +477,21 @@ public static void installGpiiApkIntoSystem(String apkname, process = Runtime.getRuntime().exec("su"); DataOutputStream out = new DataOutputStream( - process.getOutputStream()); + process.getOutputStream()); out.writeBytes("mount -o rw,remount yaffs2 /system\n"); out.writeBytes("chmod 777 " + privilegedDir + "\n"); out.writeBytes("chmod 777 /data/app/" + apkname + "\n"); out.writeBytes("cat /data/app/" + apkname + " > " - + privilegedDir + "/" + apkname + "\n"); + + privilegedDir + "/" + apkname + "\n"); out.writeBytes("chmod 644 " + privilegedDir + "/" + apkname - + "\n"); + + "\n"); out.writeBytes("mount -o remount,ro -t yaffs2 /system\n"); out.writeBytes("reboot\n"); out.flush(); process.waitFor(); } else { - + Log.e(TAG, "THERE IS NOT APK"); } @@ -517,24 +514,25 @@ private Dialog busyBoxNotInstalledDialog(String app) { // set dialog message alertDialogBuilder.setMessage("Click download to download BusyBox") - // .setCancelable(false) - .setPositiveButton("Download", - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - startActivity(new Intent(Intent.ACTION_VIEW, - Uri.parse("market://details?id=" - + appInstalled))); - } - }) - .setNegativeButton("Exit", - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - - dialog.cancel(); - GpiiActivity.this.finish(); - - } - }); + .setPositiveButton("Download", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + startActivity(new Intent(Intent.ACTION_VIEW, + Uri.parse("market://details?id=" + + appInstalled))); + } + } + ) + .setNegativeButton("Exit", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + + dialog.cancel(); + GpiiActivity.this.finish(); + + } + } + ); alertDialogBuilder.create(); @@ -598,10 +596,10 @@ private boolean isSystemPackage(ApplicationInfo applicationInfo) { return ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0); } - + private void launchWebPage(String url){ Intent browserIntent = new Intent(Intent.ACTION_VIEW, - Uri.parse(url)); + Uri.parse(url)); startActivity(browserIntent); } From 419e5201e0831481f945a1078398b3ed5e1926d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Hern=C3=A1ndez?= Date: Fri, 17 Jul 2015 13:56:18 +0200 Subject: [PATCH 4/8] Adding dependencies for tar an gzip --- platform/app/src/net/gpii/app/GpiiActivity.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/platform/app/src/net/gpii/app/GpiiActivity.java b/platform/app/src/net/gpii/app/GpiiActivity.java index 0736404..71a5c2c 100644 --- a/platform/app/src/net/gpii/app/GpiiActivity.java +++ b/platform/app/src/net/gpii/app/GpiiActivity.java @@ -66,6 +66,9 @@ import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; @SuppressLint("NewApi") public class GpiiActivity extends Activity { From 08e4c9005192bb91dd5d8134e2ca926ad05622b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Hern=C3=A1ndez?= Date: Wed, 12 Aug 2015 17:27:16 +0200 Subject: [PATCH 5/8] prebuild.sh file modified to import common compress library --- platform/prebuild.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/prebuild.sh b/platform/prebuild.sh index aab1f1b..478071a 100755 --- a/platform/prebuild.sh +++ b/platform/prebuild.sh @@ -25,6 +25,7 @@ else fi curl -o app/libs/jtar-1.0.4.jar https://jtar.googlecode.com/files/jtar-1.0.4.jar +curl -o app/libs/commons-compress-1.5.jar https://docs.google.com/uc?export=download&id=0B9NaK6yZUAngSXlKNTBOMHRIcXM # Create Assets directory if it doesn't exist yet if [ -d 'app/assets' ]; then From 04160938f5d88096723485b8acc36c0edb29e805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Hern=C3=A1ndez?= Date: Thu, 3 Sep 2015 19:18:47 +0200 Subject: [PATCH 6/8] Some errors fixed. Added modification into prebuild.sh to download right jar library from maven repository --- platform/app/res/layout-xlarge-land/main.xml | 194 +++++++++--------- platform/app/res/layout-xlarge/main.xml | 194 +++++++++--------- platform/app/res/layout/main.xml | 189 ++++++++++------- .../app/src/net/gpii/app/GpiiActivity.java | 2 +- platform/prebuild.sh | 2 +- 5 files changed, 308 insertions(+), 273 deletions(-) diff --git a/platform/app/res/layout-xlarge-land/main.xml b/platform/app/res/layout-xlarge-land/main.xml index c6767b4..9e7645c 100644 --- a/platform/app/res/layout-xlarge-land/main.xml +++ b/platform/app/res/layout-xlarge-land/main.xml @@ -37,104 +37,104 @@ android:id="@+id/gpii_Info" android:visibility="gone" android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_below="@+id/imageView1"> + android:layout_height="wrap_content" + android:layout_below="@+id/imageView1"> + + + + + + + + - - - - - - - - - - -