package com.cookpad.android.issuereporter;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import java.util.Locale;

public class SystemProfile {
    private String packageName;
    private String manufacturer;
    private String model;
    private String sdkInt;
    private String language;
    private String country;
    private int screenLayout;
    private float density;

    public SystemProfile(Context context) {
        Resources resources = context.getResources();
        this.packageName = context.getPackageName();
        this.manufacturer = android.os.Build.MANUFACTURER;
        this.model = android.os.Build.MODEL;
        this.sdkInt = String.valueOf(android.os.Build.VERSION.SDK_INT);

        Locale locale = resources.getConfiguration().locale;
        this.language = locale.getLanguage();
        this.country = locale.getCountry();

        this.screenLayout = Configuration.SCREENLAYOUT_SIZE_MASK & resources.getConfiguration().screenLayout;
        DisplayMetrics metrics = new DisplayMetrics();
        ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(metrics);
        this.density = metrics.density;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("packageName=").append(packageName).append("\n");
        builder.append("manufacturer=").append(manufacturer).append("\n");
        builder.append("model=").append(model).append("\n");
        builder.append("sdk-int=").append(sdkInt).append("\n");
        builder.append("language=").append(language).append("\n");
        builder.append("country=").append(country).append("\n");
        builder.append("screen-layout=").append(screenLayout).append("\n");
        builder.append("density=").append(density).append("\n");
        return builder.toString();
    }

}

@@ -69,16 +69,140 @@
 ontext;%0A
+import android.content.pm.ApplicationInfo;%0Aimport android.content.pm.PackageInfo;%0Aimport android.content.pm.PackageManager;%0A
 import a
@@ -400,16 +400,53 @@
 ofile %7B%0A
+%0A    private CharSequence appLabel;%0A%0A
     priv
@@ -456,17 +456,20 @@
  String 
-p
+appP
 ackageNa
@@ -472,16 +472,86 @@
 geName;%0A
+%0A    private String appVersionName;%0A%0A    private int appVersionCode;%0A%0A
     priv
@@ -575,16 +575,17 @@
 cturer;%0A
+%0A
     priv
@@ -602,16 +602,17 @@
  model;%0A
+%0A
     priv
@@ -630,16 +630,17 @@
 sdkInt;%0A
+%0A
     priv
@@ -660,16 +660,17 @@
 nguage;%0A
+%0A
     priv
@@ -689,16 +689,17 @@
 ountry;%0A
+%0A
     priv
@@ -716,24 +716,25 @@
 reenLayout;%0A
+%0A
     private 
@@ -859,61 +859,276 @@
     
-this.packageName = context.getPackageName(
+appPackageName = context.getPackageName();%0A%0A        try %7B%0A            PackageManager pm = context.getPackageManager();%0A            ApplicationInfo a = pm.getApplicationInfo(appPackageName, 0);%0A            PackageInfo p = pm.getPackageInfo(appPackageName, 0
 );%0A
+%0A
         
 this
@@ -1123,21 +1123,289 @@
         
-this.
+    appLabel = pm.getApplicationLabel(a);%0A            appVersionName = p.versionName;%0A            appVersionCode = p.versionCode;%0A        %7D catch (PackageManager.NameNotFoundException e) %7B%0A            throw new IllegalStateException(%22never reached%22, e);%0A        %7D%0A%0A        
 manufact
@@ -1450,21 +1450,16 @@
         
-this.
 model = 
@@ -1490,21 +1490,16 @@
         
-this.
 sdkInt =
@@ -1619,21 +1619,16 @@
         
-this.
 language
@@ -1660,21 +1660,16 @@
         
-this.
 country 
@@ -1700,21 +1700,16 @@
         
-this.
 screenLa
@@ -1755,32 +1755,49 @@
 MASK & resources
+%0A                
 .getConfiguratio
@@ -1963,16 +1963,33 @@
 isplay()
+%0A                
 .getMetr
@@ -2014,13 +2014,8 @@
     
-this.
 dens
@@ -2166,17 +2166,87 @@
 append(%22
-p
+appLabel=%22).append(appLabel).append(%22%5Cn%22);%0A        builder.append(%22appP
 ackageNa
@@ -2258,17 +2258,20 @@
 .append(
-p
+appP
 ackageNa
@@ -2280,32 +2280,191 @@
 ).append(%22%5Cn%22);%0A
+        builder.append(%22appVersion=%22).append(appVersionName)%0A                .append(%22 (%22).append(appVersionCode).append(%22)%5Cn%22);%0A        builder.append(%22%5Cn%22);%0A
         builder.

add appLabel and appVersion to system profiles