/*
 Copyright (c) 2012 GFT Appverse, S.L., Sociedad Unipersonal.

 This Source  Code Form  is subject to the  terms of  the Appverse Public License 
 Version 2.0  ("APL v2.0").  If a copy of  the APL  was not  distributed with this 
 file, You can obtain one at http://appverse.org/legal/appverse-license/.

 Redistribution and use in  source and binary forms, with or without modification, 
 are permitted provided that the  conditions  of the  AppVerse Public License v2.0 
 are met.

 THIS SOFTWARE IS PROVIDED BY THE  COPYRIGHT HOLDERS  AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS  OR IMPLIED WARRANTIES, INCLUDING, BUT  NOT LIMITED TO,   THE IMPLIED
 WARRANTIES   OF  MERCHANTABILITY   AND   FITNESS   FOR A PARTICULAR  PURPOSE  ARE
 DISCLAIMED. EXCEPT IN CASE OF WILLFUL MISCONDUCT OR GROSS NEGLIGENCE, IN NO EVENT
 SHALL THE  COPYRIGHT OWNER  OR  CONTRIBUTORS  BE LIABLE FOR ANY DIRECT, INDIRECT,
 INCIDENTAL,  SPECIAL,   EXEMPLARY,  OR CONSEQUENTIAL DAMAGES  (INCLUDING, BUT NOT
 LIMITED TO,  PROCUREMENT OF SUBSTITUTE  GOODS OR SERVICES;  LOSS OF USE, DATA, OR
 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) 
 ARISING  IN  ANY WAY OUT  OF THE USE  OF THIS  SOFTWARE,  EVEN  IF ADVISED OF THE 
 POSSIBILITY OF SUCH DAMAGE.
 */
package com.gft.unity.android;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.ArrayList;

import com.gft.unity.core.security.AbstractSecurity;

public class AndroidSecurity extends AbstractSecurity {

	@Override
	public boolean IsDeviceModified() {
		if (checkRootMethod1()){return true;}
        if (checkRootMethod2()){return true;}
        if (checkRootMethod3()){return true;}
        return false;
	}
	
	 private boolean checkRootMethod1(){
	        String buildTags = android.os.Build.TAGS;

	        if (buildTags != null && buildTags.contains("test-keys")) {
	            return true;
	        }
	        return false;
	    }

	    
	 private boolean checkRootMethod2(){
		 try {
			 File file = new File("/system/app/Superuser.apk");
	         if (file.exists()) {
	        	 return true;
	         }
	     } catch (Exception e) { }
	     return false;
	 }

	 private boolean checkRootMethod3() {
		 if (new ExecShell().executeCommand(ExecShell.SHELL_CMD.check_su_binary) != null){
			 return true;
	     }else{
	         return false;
	     }
	 }
	 
	 private static class ExecShell
	 {
		 public static enum SHELL_CMD {
			 
			 check_su_binary(new String[] {"/system/xbin/which","su"});
			 
			 String[] command;
		     SHELL_CMD(String[] command){
		    	 this.command = command;
		     }
		 }

		 public ArrayList<String> executeCommand(SHELL_CMD shellCmd){
			 String line = null;
			 ArrayList<String> fullResponse = new ArrayList<String>();
			 Process localProcess = null;
			 
			 try {
				 localProcess = Runtime.getRuntime().exec(shellCmd.command);
			 } catch (Exception e) {
				 return null;
				 //e.printStackTrace();
			 }

			 BufferedReader in = new BufferedReader(new InputStreamReader(localProcess.getInputStream()));

			 try {
				 while ((line = in.readLine()) != null) {
					 fullResponse.add(line);
				 }
			 } catch (Exception e) {
				 //e.printStackTrace();
			 }
			 return fullResponse;		 
		 }
	 }
}
@@ -1518,24 +1518,52 @@
 rayList;%0D%0A%0D%0A
+import android.os.Build;%0D%0A%0D%0A
 import com.g
@@ -1604,16 +1604,16 @@
 urity;%0D%0A
-
 %0D%0Apublic
@@ -1752,32 +1752,26 @@
 urn true;%7D%0D%0A
-        
+%09%09
 if (checkRoo
@@ -1797,24 +1797,380 @@
 true;%7D%0D%0A
-        
+%0D%0A%09%09// Tactical solution applied (16/01/2013) ::%0D%0A%09%09// ICS devices (levels 14 & 15) hang the application when the checkRootMethod3 is used. %0D%0A%09%09// Application processes are blocked in that case and the address port could not be used anymore by any app till the device is fully restarted.%0D%0A%09%09if(Build.VERSION.SDK_INT %3C 14 %7C%7C Build.VERSION.SDK_INT %3E 15) %7B%0D%0A        %09
 if (chec
@@ -2200,16 +2200,25 @@
 true;%7D%0D%0A
+%09%09%7D%0D%0A%09%09%0D%0A
         

Fix applied to isDeviceRooted feature