package uk.co.whiteoctober.cordova;

import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageManager;

public class AppVersion extends CordovaPlugin {
	@Override
        public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {

		try {	
			if (action.equals("getAppName")) {
				PackageManager packageManager = this.cordova.getActivity().getPackageManager();
				ApplicationInfo app = packageManager.getApplicationInfo(this.cordova.getActivity().getPackageName(), 0);
				callbackContext.success((String)packageManager.getApplicationLabel(app));
				return true;
			}
			if (action.equals("getPackageName")) {
				callbackContext.success(this.cordova.getActivity().getPackageName());
				return true;
			}
			if (action.equals("getVersionNumber")) {
				PackageManager packageManager = this.cordova.getActivity().getPackageManager();
				callbackContext.success(packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionName);
			return true;
			}
			if (action.equals("getVersionCode")) {
				PackageManager packageManager = this.cordova.getActivity().getPackageManager();
				callbackContext.success(packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionCode);
			return true;
			}
			return false;
		} catch (NameNotFoundException e) {
			callbackContext.success("N/A");
			return true;
		}
	}

}

@@ -399,17 +399,18 @@
 lugin %7B%0A
-%09
+  
 @Overrid
@@ -411,22 +411,16 @@
 verride%0A
-      
   public
@@ -528,20 +528,24 @@
  %7B%0A%0A
-%09%09
+    
 try %7B
-%09%0A%09%09%09
+%0A      
 if (
@@ -571,28 +571,32 @@
 ppName%22)) %7B%0A
-%09%09%09%09
+        
 PackageManag
@@ -663,20 +663,24 @@
 ager();%0A
-%09%09%09%09
+        
 Applicat
@@ -776,20 +776,24 @@
 (), 0);%0A
-%09%09%09%09
+        
 callback
@@ -854,28 +854,32 @@
 abel(app));%0A
-%09%09%09%09
+        
 return true;
@@ -875,32 +875,38 @@
 eturn true;%0A
-%09%09%09%7D%0A%09%09%09
+      %7D%0A      
 if (action.e
@@ -932,20 +932,24 @@
 me%22)) %7B%0A
-%09%09%09%09
+        
 callback
@@ -1010,20 +1010,24 @@
 ame());%0A
-%09%09%09%09
+        
 return t
@@ -1027,32 +1027,38 @@
 eturn true;%0A
-%09%09%09%7D%0A%09%09%09
+      %7D%0A      
 if (action.e
@@ -1082,28 +1082,32 @@
 Number%22)) %7B%0A
-%09%09%09%09
+        
 PackageManag
@@ -1166,36 +1166,40 @@
 ckageManager();%0A
-%09%09%09%09
+        
 callbackContext.
@@ -1294,27 +1294,30 @@
 rsionName);%0A
-%09%09%09
+      
 return true;
@@ -1317,24 +1317,30 @@
 n true;%0A
-%09%09%09%7D%0A%09%09%09
+      %7D%0A      
 if (acti
@@ -1370,20 +1370,24 @@
 de%22)) %7B%0A
-%09%09%09%09
+        
 PackageM
@@ -1462,12 +1462,16 @@
 ();%0A
-%09%09%09%09
+        
 call
@@ -1582,19 +1582,22 @@
 nCode);%0A
-%09%09%09
+      
 return t
@@ -1605,16 +1605,22 @@
 ue;%0A
-%09%09%09%7D%0A%09%09%09
+      %7D%0A      
 retu
@@ -1629,18 +1629,20 @@
  false;%0A
-%09%09
+    
 %7D catch 
@@ -1669,19 +1669,22 @@
 on e) %7B%0A
-%09%09%09
+      
 callback
@@ -1711,11 +1711,14 @@
 %22);%0A
-%09%09%09
+      
 retu
@@ -1730,13 +1730,16 @@
 ue;%0A
-%09%09%7D%0A%09
+    %7D%0A  
 %7D%0A%0A%7D

Fix indentation for consistency (tabs -> 2 spaces)