gt: 				if (task != null) {
context: /*
   *
   * Copyright (C) 2011, 2015 Cisco Systems, Inc.
   * Copyright (C) 2015 CBA research group, Technical University of Catalonia.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at:
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   *
   */
  
  package org.lispmob.noroot;
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.util.Timer;
  import java.util.TimerTask;
  
  import org.lispmob.noroot.R;
  
  import android.annotation.TargetApi;
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.location.Location;
  import android.net.VpnService;
  import android.os.Build;
  import android.os.Bundle;
  import android.os.Handler;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.content.res.Resources;
  import android.graphics.Color;
  import android.widget.CheckBox;
  import android.widget.Button;
  import android.widget.TextView;
  import android.util.Log;
  import android.view.View;
  import android.view.View.OnClickListener;
  
  @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
  public class LISPmob extends Activity implements OnClickListener {
  
  	public static String lispd_path = null;
  	private static String system_dns[] = new String[2];
  	private boolean lispdWasRunning = false;
  	private static boolean lispdRunning = false;
  	private static boolean err_msg_detected = false;
  	private static boolean startVPN = false;
  	private Intent vpn_intent	= null;
  	private static final int CONF_ACT = 1;
  	private static final int VPN_SER = 2;
  	
  	private Handler handler;
  	private Runnable doUpdateView;
  
  	
  	
  	/** Called when the activity is first created. */
  	@Override
  	public void onCreate(Bundle savedInstanceState) {
  		super.onCreate(savedInstanceState);
  		setContentView(R.layout.main);
  		
  		//shell = new SuShell();
  		
  		/* Get the directory of the executable */
  		
  		try{
  			lispd_path =  getPackageManager().getApplicationInfo("org.lispmob.noroot", 0).nativeLibraryDir;
  			
  		}catch(Exception e)
  		{
  			e.printStackTrace();
  		};
  
  		/*
  		 * Set up the button handlers
  		 */
  		CheckBox lispCheckBox = (CheckBox)findViewById(R.id.startStopCheckbox);
  		lispCheckBox.setOnClickListener(this);
  		handler = new Handler(); 
  		doUpdateView = new Runnable() { 
  			public void run() { 
  				updateStatus();
  			} 
  		};
  
  		Button log = (Button) findViewById(R.id.showLogButton);
  		log.setOnClickListener(new View.OnClickListener() {
  			public void onClick(View view) {
  				Intent myIntent = new Intent(view.getContext(), logActivity.class);
  				startActivity(myIntent);
  			}
  		}
  				);
  		Button conf = (Button) findViewById(R.id.showConfButton);
  		conf.setOnClickListener(new View.OnClickListener() {
  			public void onClick(View view) {
  				Intent myIntent = new Intent(view.getContext(), confActivity.class);
  				startActivity(myIntent);
  			}
  		}
  				);
  
  		Button updateconf = (Button) findViewById(R.id.updateConfButton);
  		updateconf.setOnClickListener(new View.OnClickListener() {
  			public void onClick(View view) {
  				Intent myIntent = new Intent(view.getContext(), updateConfActivity.class);
  				startActivityForResult(myIntent, CONF_ACT);
  				
  			}
  		}
  				);
  		
  		//system_dns = get_dns_servers();
  		
  	}
  
  
  	Location lastLocation;
  
  	Timer mUpdateTimer = null;
  	@Override
  	protected void onPause() {
  		Log.v("lispMonitor", "Pausing..");
  		super.onPause();
  
  		// Stop all timers
  		mUpdateTimer.cancel();
  	}
  
  	@Override
  	protected void onStop() {
  		Log.v("LISPmob", "Stopping...");
  		super.onStop();
  		// Stop all timers
  		mUpdateTimer.cancel();
  	}
  
  	@Override
  	protected void onResume() {
  		Log.v("lispMonitor", "Resuming...");
  		super.onResume();
  
  		// Rebuild the timer
  		if (mUpdateTimer != null) {
  			mUpdateTimer.cancel();
  		}
  		mUpdateTimer = new Timer();
  		mUpdateTimer.scheduleAtFixedRate(new statusTask(), 0, 1000);
  	}
  
  	static public String runTask(String command, String args, boolean ignoreOutput) {
  		StringBuffer output = new StringBuffer();
  		Process process = null;
  		try {
  			process = new ProcessBuilder()
  			.command(command, args)
  			.redirectErrorStream(true)
  			.start();
  			InputStream in = process.getInputStream();
  			BufferedReader reader = new BufferedReader(new InputStreamReader(in));
  			String line;
  			process.waitFor();
  			if (!ignoreOutput) {
  				while ((line = reader.readLine()) != null) {
  					output.append(line);
  					output.append('\n');
  				}
  			}
  		} catch (IOException e1) {
  			System.out.println("LISPmob: Command Failed.");
  			e1.printStackTrace();
  			return("Command Failed.");
  		} catch (InterruptedException e) {
  			e.printStackTrace();
  		} 
  		return(output.toString());
  	}
  
  	
  	public void updateStatus() {
  		final CheckBox lispCheckBox = (CheckBox) findViewById(R.id.startStopCheckbox);
  		final TextView lispCheckBoxLabel = (TextView) findViewById(R.id.startStopCheckboxLabel);
  		final TextView statusView = (TextView) findViewById(R.id.infoView);
  		
  
  		lispdRunning = LISPmobVPNService.vpn_running;
  
  		if (LISPmobVPNService.vpn_running) {
  			lispCheckBoxLabel.setText(R.string.lispRunning);
  			lispCheckBoxLabel.setTextColor(Color.WHITE);
  			lispCheckBox.setChecked(true);
  			//updateInfoView();
  			statusView.setText("");
  			lispdWasRunning = true;
  		} else if (lispdWasRunning) {
  			lispCheckBoxLabel.setText("lispd has exited, click to restart.");
  			lispCheckBoxLabel.setTextColor(Color.RED);
  			lispCheckBox.setChecked(false);
  			//updateInfoView();
  			statusView.setText("");
  		} else {
  			lispCheckBoxLabel.setText(R.string.lispNotRunning);
  			lispCheckBoxLabel.setTextColor(Color.WHITE);
  			lispCheckBox.setChecked(false);
  			//updateInfoView();
  			statusView.setText("");
  		}
  		
  		if (!err_msg_detected && LISPmobVPNService.err_msg_code != 0){
  			err_msg_detected = true;
  			Resources res = getResources();
  			String[] err_msg = res.getStringArray(R.array.ErrMsgArray);
  			showMessage(err_msg[LISPmobVPNService.err_msg_code],
  					false, new Runnable() { public void run() {
  						LISPmobVPNService.err_msg_code =0;
  						err_msg_detected = false;
  					}
  			});
  		}
  
  	}
  	
  	
  
  	public final class statusTask extends TimerTask {
  		public void run() {
  			handler.post(doUpdateView);
  		}
  	}
  
  	public void showMessage(String message, boolean cancelAble, final Runnable task) {
  
  		AlertDialog.Builder builder = new AlertDialog.Builder(this);
  		builder.setTitle("Attention:");
  		builder.setMessage(message)
  		.setCancelable(cancelAble)
  		.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
  			public void onClick(DialogInterface dialog, int id) {
  