From 2e0e9579c1818bb31e8f93e51234dba73e964b4d Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Tue, 30 Apr 2024 17:05:35 -0400 Subject: [PATCH] fix: Strickmode Error --- .../mparticle/internal/DeviceAttributes.java | 17 ++++++++--------- .../java/com/mparticle/internal/MPUtility.java | 11 ++++------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/android-core/src/main/java/com/mparticle/internal/DeviceAttributes.java b/android-core/src/main/java/com/mparticle/internal/DeviceAttributes.java index 7948a3f4f..ddd1d85ed 100644 --- a/android-core/src/main/java/com/mparticle/internal/DeviceAttributes.java +++ b/android-core/src/main/java/com/mparticle/internal/DeviceAttributes.java @@ -1,5 +1,6 @@ package com.mparticle.internal; +import android.app.Application; import android.content.Context; import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; @@ -8,7 +9,6 @@ import android.os.Build; import android.telephony.TelephonyManager; import android.util.DisplayMetrics; -import android.view.WindowManager; import com.mparticle.MParticle; import com.mparticle.internal.Constants.MessageKey; @@ -196,9 +196,9 @@ JSONObject getStaticDeviceInfo(Context appContext) { attributes.put(MessageKey.OS_VERSION_INT, Build.VERSION.SDK_INT); attributes.put(MessageKey.MODEL, android.os.Build.MODEL); attributes.put(MessageKey.RELEASE_VERSION, Build.VERSION.RELEASE); - + Application application = (Application) appContext; // device ID - addAndroidId(attributes, appContext); + addAndroidId(attributes, application); attributes.put(MessageKey.DEVICE_BLUETOOTH_ENABLED, MPUtility.isBluetoothEnabled(appContext)); attributes.put(MessageKey.DEVICE_BLUETOOTH_VERSION, MPUtility.getBluetoothVersion(appContext)); @@ -210,12 +210,11 @@ JSONObject getStaticDeviceInfo(Context appContext) { attributes.put(MessageKey.DEVICE_ROOTED, rootedObject); // screen height/width - WindowManager windowManager = (WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE); - DisplayMetrics metrics = new DisplayMetrics(); - windowManager.getDefaultDisplay().getMetrics(metrics); - attributes.put(MessageKey.SCREEN_HEIGHT, metrics.heightPixels); - attributes.put(MessageKey.SCREEN_WIDTH, metrics.widthPixels); - attributes.put(MessageKey.SCREEN_DPI, metrics.densityDpi); + DisplayMetrics displayMetrics = appContext.getResources().getDisplayMetrics(); + + attributes.put(MessageKey.SCREEN_HEIGHT, displayMetrics.heightPixels); + attributes.put(MessageKey.SCREEN_WIDTH, displayMetrics.widthPixels); + attributes.put(MessageKey.SCREEN_DPI, displayMetrics.densityDpi); // locales Locale locale = Locale.getDefault(); diff --git a/android-core/src/main/java/com/mparticle/internal/MPUtility.java b/android-core/src/main/java/com/mparticle/internal/MPUtility.java index 1eb623638..176c208b8 100644 --- a/android-core/src/main/java/com/mparticle/internal/MPUtility.java +++ b/android-core/src/main/java/com/mparticle/internal/MPUtility.java @@ -20,8 +20,7 @@ import android.os.StatFs; import android.provider.Settings; import android.telephony.TelephonyManager; -import android.view.Display; -import android.view.WindowManager; +import android.util.DisplayMetrics; import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; @@ -369,14 +368,12 @@ public static String getTimeZone() { } public static int getOrientation(Context context) { - WindowManager windowManager = (WindowManager) context - .getSystemService(Context.WINDOW_SERVICE); - Display getOrient = windowManager.getDefaultDisplay(); + DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); int orientation = Configuration.ORIENTATION_UNDEFINED; - if (getOrient.getWidth() == getOrient.getHeight()) { + if (displayMetrics.widthPixels == displayMetrics.heightPixels) { orientation = Configuration.ORIENTATION_SQUARE; } else { - if (getOrient.getWidth() < getOrient.getHeight()) { + if (displayMetrics.widthPixels < displayMetrics.heightPixels) { orientation = Configuration.ORIENTATION_PORTRAIT; } else { orientation = Configuration.ORIENTATION_LANDSCAPE;