package code.name.monkey.retromusic.activities.bugreport.model; import android.annotation.SuppressLint; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Build; import androidx.annotation.IntRange; import code.name.monkey.retromusic.util.PreferenceUtil; import java.util.Arrays; import java.util.Locale; public class DeviceInfo { @SuppressLint("NewApi") @SuppressWarnings("deprecation") private final String[] abis = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? Build.SUPPORTED_ABIS : new String[] {Build.CPU_ABI, Build.CPU_ABI2}; @SuppressLint("NewApi") private final String[] abis32Bits = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? Build.SUPPORTED_32_BIT_ABIS : null; @SuppressLint("NewApi") private final String[] abis64Bits = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? Build.SUPPORTED_64_BIT_ABIS : null; private final String baseTheme; private final String brand = Build.BRAND; private final String buildID = Build.DISPLAY; private final String buildVersion = Build.VERSION.INCREMENTAL; private final String device = Build.DEVICE; private final String hardware = Build.HARDWARE; private final boolean isAdaptive; private final String manufacturer = Build.MANUFACTURER; private final String model = Build.MODEL; private final String nowPlayingTheme; private final String product = Build.PRODUCT; private final String releaseVersion = Build.VERSION.RELEASE; @IntRange(from = 0) private final int sdkVersion = Build.VERSION.SDK_INT; private final int versionCode; private final String versionName; private final String selectedLang; public DeviceInfo(Context context) { PackageInfo packageInfo; try { packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { packageInfo = null; } if (packageInfo != null) { versionCode = packageInfo.versionCode; versionName = packageInfo.versionName; } else { versionCode = -1; versionName = null; } baseTheme = PreferenceUtil.INSTANCE.getBaseTheme(); nowPlayingTheme = context.getString(PreferenceUtil.INSTANCE.getNowPlayingScreen().getTitleRes()); isAdaptive = PreferenceUtil.INSTANCE.isAdaptiveColor(); selectedLang = PreferenceUtil.INSTANCE.getLanguageCode(); } public String toMarkdown() { return "Device info:\n" + "---\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
App version" + versionName + "
App version code" + versionCode + "
Android build version" + buildVersion + "
Android release version" + releaseVersion + "
Android SDK version" + sdkVersion + "
Android build ID" + buildID + "
Device brand" + brand + "
Device manufacturer" + manufacturer + "
Device name" + device + "
Device model" + model + "
Device product name" + product + "
Device hardware name" + hardware + "
ABIs" + Arrays.toString(abis) + "
ABIs (32bit)" + Arrays.toString(abis32Bits) + "
ABIs (64bit)" + Arrays.toString(abis64Bits) + "
Language" + selectedLang + "
\n"; } @Override public String toString() { return "App version: " + versionName + "\n" + "App version code: " + versionCode + "\n" + "Android build version: " + buildVersion + "\n" + "Android release version: " + releaseVersion + "\n" + "Android SDK version: " + sdkVersion + "\n" + "Android build ID: " + buildID + "\n" + "Device brand: " + brand + "\n" + "Device manufacturer: " + manufacturer + "\n" + "Device name: " + device + "\n" + "Device model: " + model + "\n" + "Device product name: " + product + "\n" + "Device hardware name: " + hardware + "\n" + "ABIs: " + Arrays.toString(abis) + "\n" + "ABIs (32bit): " + Arrays.toString(abis32Bits) + "\n" + "ABIs (64bit): " + Arrays.toString(abis64Bits) + "\n" + "Base theme: " + baseTheme + "\n" + "Now playing theme: " + nowPlayingTheme + "\n" + "Adaptive: " + isAdaptive + "\n" + "System language: " + Locale.getDefault().toLanguageTag() + "\n" + "In-App Language: " + selectedLang; } }