use of com.microsoft.appcenter.ingestion.models.Device in project mobile-center-sdk-android by Microsoft.
the class PartAUtilsTest method checkPartAConversion.
/**
* Convert to Part A and check.
*/
private void checkPartAConversion(int appCenterTimeZoneOffset, String commonSchemaTimeZoneOffset) {
Device device = getDevice(appCenterTimeZoneOffset);
/* App Center timestamp and transmission targets. */
Date timestamp = new Date();
String transmissionTarget = "T1UUID1-T2UUID2";
Log log = mock(Log.class);
when(log.getDevice()).thenReturn(device);
when(log.getTimestamp()).thenReturn(timestamp);
when(log.getUserId()).thenReturn("alice");
/* Convert. */
MockCommonSchemaLog commonSchemaLog = new MockCommonSchemaLog();
PartAUtils.addPartAFromLog(log, commonSchemaLog, transmissionTarget);
/* Verify conversion. */
assertEquals("3.0", commonSchemaLog.getVer());
assertEquals(timestamp, commonSchemaLog.getTimestamp());
assertEquals("o:T1UUID1", commonSchemaLog.getIKey());
assertNotNull(commonSchemaLog.getExt());
assertNotNull(commonSchemaLog.getExt().getProtocol());
assertEquals("model", commonSchemaLog.getExt().getProtocol().getDevModel());
assertEquals("oemName", commonSchemaLog.getExt().getProtocol().getDevMake());
assertNotNull(commonSchemaLog.getExt().getUser());
assertEquals("c:alice", commonSchemaLog.getExt().getUser().getLocalId());
assertEquals("en-US", commonSchemaLog.getExt().getUser().getLocale());
assertNotNull(commonSchemaLog.getExt().getOs());
assertEquals("osName", commonSchemaLog.getExt().getOs().getName());
assertEquals("8.1.0-ABC.123-23", commonSchemaLog.getExt().getOs().getVer());
assertNotNull(commonSchemaLog.getExt().getApp());
assertEquals("1.0.0", commonSchemaLog.getExt().getApp().getVer());
assertEquals("a:com.appcenter.test", commonSchemaLog.getExt().getApp().getId());
assertNotNull(commonSchemaLog.getExt().getNet());
assertEquals("carrierName", commonSchemaLog.getExt().getNet().getProvider());
assertNotNull(commonSchemaLog.getExt().getSdk());
assertEquals("appcenter.android-1.5.0", commonSchemaLog.getExt().getSdk().getLibVer());
assertNotNull(commonSchemaLog.getExt().getLoc());
assertEquals(commonSchemaTimeZoneOffset, commonSchemaLog.getExt().getLoc().getTz());
assertEquals(Collections.singleton(transmissionTarget), commonSchemaLog.getTransmissionTargetTokens());
assertNotNull(commonSchemaLog.getExt().getDevice());
}
use of com.microsoft.appcenter.ingestion.models.Device in project mobile-center-sdk-android by Microsoft.
the class DeviceInfoHelperTest method getDeviceInfo.
@Test
public void getDeviceInfo() throws PackageManager.NameNotFoundException, DeviceInfoHelper.DeviceInfoException {
/* Mock data. */
final String appVersion = "1.0";
final String appBuild = "1";
// noinspection SpellCheckingInspection
final String appNamespace = "com.contoso.app";
final String carrierCountry = "us";
final String carrierName = "mock-service";
final Locale locale = Locale.KOREA;
final String model = "mock-model";
final String oemName = "mock-manufacture";
final Integer osApiLevel = 23;
final String osName = "Android";
final String osVersion = "mock-version";
final String osBuild = "mock-os-build";
final String screenSizeLandscape = "100x200";
final String screenSizePortrait = "200x100";
final TimeZone timeZone = TimeZone.getTimeZone("KST");
final Integer timeZoneOffset = timeZone.getOffset(System.currentTimeMillis());
Locale.setDefault(locale);
TimeZone.setDefault(timeZone);
/* Mocking instances. */
Context contextMock = mock(Context.class);
PackageManager packageManagerMock = mock(PackageManager.class);
PackageInfo packageInfoMock = mock(PackageInfo.class);
WindowManager windowManagerMock = mock(WindowManager.class);
TelephonyManager telephonyManagerMock = mock(TelephonyManager.class);
Display displayMock = mock(Display.class);
/* Delegates to mock instances. */
when(contextMock.getPackageName()).thenReturn(appNamespace);
when(contextMock.getPackageManager()).thenReturn(packageManagerMock);
// noinspection WrongConstant
when(contextMock.getSystemService(eq(Context.TELEPHONY_SERVICE))).thenReturn(telephonyManagerMock);
// noinspection WrongConstant
when(contextMock.getSystemService(eq(Context.WINDOW_SERVICE))).thenReturn(windowManagerMock);
// noinspection WrongConstant
when(packageManagerMock.getPackageInfo(anyString(), eq(0))).thenReturn(packageInfoMock);
when(telephonyManagerMock.getNetworkCountryIso()).thenReturn(carrierCountry);
when(telephonyManagerMock.getNetworkOperatorName()).thenReturn(carrierName);
when(windowManagerMock.getDefaultDisplay()).thenReturn(displayMock);
when(displayMock.getRotation()).thenReturn(Surface.ROTATION_0, Surface.ROTATION_90, Surface.ROTATION_180, Surface.ROTATION_270);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
Object[] args = invocationOnMock.getArguments();
/* DO NOT call set method and assign values directly to variables. */
((Point) args[0]).x = 100;
((Point) args[0]).y = 200;
return null;
}
}).when(displayMock).getSize(any(Point.class));
/* Sets values of fields for static classes. */
Whitebox.setInternalState(packageInfoMock, "versionName", appVersion);
Whitebox.setInternalState(packageInfoMock, "versionCode", Integer.parseInt(appBuild));
Whitebox.setInternalState(Build.class, "MODEL", model);
Whitebox.setInternalState(Build.class, "MANUFACTURER", oemName);
Whitebox.setInternalState(Build.VERSION.class, "SDK_INT", osApiLevel);
Whitebox.setInternalState(Build.class, "ID", osBuild);
Whitebox.setInternalState(Build.VERSION.class, "RELEASE", osVersion);
/* First call */
Device device = DeviceInfoHelper.getDeviceInfo(contextMock);
/* Verify device information. */
assertNull(device.getWrapperSdkName());
assertNull(device.getWrapperSdkVersion());
assertEquals(BuildConfig.VERSION_NAME, device.getSdkVersion());
assertEquals(appVersion, device.getAppVersion());
assertEquals(appBuild, device.getAppBuild());
assertEquals(appNamespace, device.getAppNamespace());
assertEquals(carrierCountry, device.getCarrierCountry());
assertEquals(carrierName, device.getCarrierName());
assertEquals(locale.toString(), device.getLocale());
assertEquals(model, device.getModel());
assertEquals(oemName, device.getOemName());
assertEquals(osApiLevel, device.getOsApiLevel());
assertEquals(osName, device.getOsName());
assertEquals(osVersion, device.getOsVersion());
assertEquals(osBuild, device.getOsBuild());
assertEquals(screenSizeLandscape, device.getScreenSize());
assertEquals(timeZoneOffset, device.getTimeZoneOffset());
/* Verify screen size based on different orientations (Surface.ROTATION_90). */
device = DeviceInfoHelper.getDeviceInfo(contextMock);
assertEquals(screenSizePortrait, device.getScreenSize());
/* Verify screen size based on different orientations (Surface.ROTATION_180). */
device = DeviceInfoHelper.getDeviceInfo(contextMock);
assertEquals(screenSizeLandscape, device.getScreenSize());
/* Verify screen size based on different orientations (Surface.ROTATION_270). */
device = DeviceInfoHelper.getDeviceInfo(contextMock);
assertEquals(screenSizePortrait, device.getScreenSize());
/* Make sure screen size is verified for all orientations. */
verify(displayMock, times(4)).getRotation();
/* Set wrapper sdk information. */
WrapperSdk wrapperSdk = new WrapperSdk();
wrapperSdk.setWrapperSdkVersion("1.2.3.4");
wrapperSdk.setWrapperSdkName("ReactNative");
wrapperSdk.setWrapperRuntimeVersion("4.13");
wrapperSdk.setLiveUpdateReleaseLabel("2.0.3-beta2");
wrapperSdk.setLiveUpdateDeploymentKey("staging");
wrapperSdk.setLiveUpdatePackageHash("aa896f791b26a7f464c0f62b0ba69f2b");
DeviceInfoHelper.setWrapperSdk(wrapperSdk);
Device device2 = DeviceInfoHelper.getDeviceInfo(contextMock);
assertEquals(wrapperSdk.getWrapperSdkVersion(), device2.getWrapperSdkVersion());
assertEquals(wrapperSdk.getWrapperSdkName(), device2.getWrapperSdkName());
assertEquals(wrapperSdk.getWrapperRuntimeVersion(), device2.getWrapperRuntimeVersion());
assertEquals(wrapperSdk.getLiveUpdateReleaseLabel(), device2.getLiveUpdateReleaseLabel());
assertEquals(wrapperSdk.getLiveUpdateDeploymentKey(), device2.getLiveUpdateDeploymentKey());
assertEquals(wrapperSdk.getLiveUpdatePackageHash(), device2.getLiveUpdatePackageHash());
/* Check non wrapped sdk information are still generated correctly. */
device2.setWrapperSdkVersion(null);
device2.setWrapperSdkName(null);
device2.setWrapperRuntimeVersion(null);
device2.setLiveUpdateReleaseLabel(null);
device2.setLiveUpdateDeploymentKey(null);
device2.setLiveUpdatePackageHash(null);
assertEquals(device, device2);
/* Remove wrapper SDK information. */
DeviceInfoHelper.setWrapperSdk(null);
assertEquals(device, DeviceInfoHelper.getDeviceInfo(contextMock));
}
use of com.microsoft.appcenter.ingestion.models.Device in project AppCenter-SDK-Android by Microsoft.
the class AndroidTestUtils method generateMockDevice.
@NonNull
private static Device generateMockDevice() {
Device device = new Device();
device.setSdkName("appcenter.android");
device.setSdkVersion(String.format(Locale.ENGLISH, "%d.%d.%d", (RANDOM.nextInt(5) + 1), RANDOM.nextInt(10), RANDOM.nextInt(100)));
device.setModel("S5");
device.setOemName("HTC");
device.setOsName("Android");
device.setOsVersion(String.format(Locale.ENGLISH, "%d.%d.%d", (RANDOM.nextInt(5) + 1), RANDOM.nextInt(10), RANDOM.nextInt(100)));
device.setOsBuild("LMY47X");
device.setOsApiLevel(RANDOM.nextInt(9) + 15);
device.setLocale("en_US");
device.setTimeZoneOffset(RANDOM.nextInt(52) * 30 - 720);
device.setScreenSize(String.format(Locale.ENGLISH, "%dx%d", (RANDOM.nextInt(4) + 1) * 1000, (RANDOM.nextInt(10) + 1) * 100));
device.setAppVersion(String.format(Locale.ENGLISH, "%d.%d.%d", (RANDOM.nextInt(5) + 1), RANDOM.nextInt(10), RANDOM.nextInt(100)));
device.setAppBuild(Integer.toString(RANDOM.nextInt(1000) + 1));
device.setAppNamespace("com.microsoft.unittest");
device.setWrapperSdkVersion("1.2.3.4");
device.setWrapperSdkName("ReactNative");
device.setLiveUpdateReleaseLabel("2.0.3-beta2");
device.setLiveUpdateDeploymentKey("staging");
device.setLiveUpdatePackageHash("aa896f791b26a7f464c0f62b0ba69f2b");
return device;
}
use of com.microsoft.appcenter.ingestion.models.Device in project AppCenter-SDK-Android by Microsoft.
the class AnalyticsSerializerTest method someBatch.
@Test
public void someBatch() throws JSONException {
LogContainer expectedContainer = new LogContainer();
Device device = new Device();
device.setSdkName("appcenter.android");
device.setSdkVersion("1.2.3");
device.setModel("S5");
device.setOemName("HTC");
device.setOsName("Android");
device.setOsVersion("4.0.3");
device.setOsBuild("LMY47X");
device.setOsApiLevel(15);
device.setLocale("en_US");
device.setTimeZoneOffset(120);
device.setScreenSize("800x600");
device.setAppVersion("3.2.1");
device.setAppBuild("42");
List<Log> logs = new ArrayList<>();
{
StartSessionLog startSessionLog = new StartSessionLog();
startSessionLog.setTimestamp(new Date());
logs.add(startSessionLog);
}
expectedContainer.setLogs(logs);
{
PageLog pageLog = new PageLog();
pageLog.setTimestamp(new Date());
pageLog.setName("home");
logs.add(pageLog);
}
{
PageLog pageLog = new PageLog();
pageLog.setTimestamp(new Date());
pageLog.setName("settings");
pageLog.setProperties(new HashMap<String, String>() {
{
put("from", "home_menu");
put("orientation", "portrait");
}
});
logs.add(pageLog);
}
{
EventLog eventLog = new EventLog();
eventLog.setTimestamp(new Date());
eventLog.setId(UUIDUtils.randomUUID());
eventLog.setName("subscribe");
logs.add(eventLog);
}
{
EventLog eventLog = new EventLog();
eventLog.setTimestamp(new Date());
eventLog.setId(UUIDUtils.randomUUID());
eventLog.setName("click");
eventLog.setProperties(new HashMap<String, String>() {
{
put("x", "1");
put("y", "2");
}
});
logs.add(eventLog);
}
UUID sid = UUIDUtils.randomUUID();
for (Log log : logs) {
log.setSid(sid);
log.setDevice(device);
}
LogSerializer serializer = new DefaultLogSerializer();
serializer.addLogFactory(StartSessionLog.TYPE, new StartSessionLogFactory());
serializer.addLogFactory(PageLog.TYPE, new PageLogFactory());
serializer.addLogFactory(EventLog.TYPE, new EventLogFactory());
String payload = serializer.serializeContainer(expectedContainer);
android.util.Log.v(TAG, payload);
LogContainer actualContainer = serializer.deserializeContainer(payload);
Assert.assertEquals(expectedContainer, actualContainer);
}
use of com.microsoft.appcenter.ingestion.models.Device in project AppCenter-SDK-Android by Microsoft.
the class ErrorLogHelperTest method getErrorReportFromErrorLog.
@Test
public void getErrorReportFromErrorLog() throws java.lang.Exception {
/* Mock base. */
Context mockContext = mock(Context.class);
when(Process.myPid()).thenReturn(123);
/* Mock device. */
Device mockDevice = mock(Device.class);
when(DeviceInfoHelper.getDeviceInfo(any(Context.class))).thenReturn(mockDevice);
/* Mock process name. */
ActivityManager activityManager = mock(ActivityManager.class);
RunningAppProcessInfo runningAppProcessInfo = new RunningAppProcessInfo(null, 0, null);
runningAppProcessInfo.pid = 123;
runningAppProcessInfo.processName = "right.process";
when(mockContext.getSystemService(Context.ACTIVITY_SERVICE)).thenReturn(activityManager);
when(activityManager.getRunningAppProcesses()).thenReturn(Arrays.asList(mock(RunningAppProcessInfo.class), runningAppProcessInfo));
/* Mock architecture. */
TestUtils.setInternalState(Build.VERSION.class, "SDK_INT", 23);
TestUtils.setInternalState(Build.class, "SUPPORTED_ABIS", new String[] { "armeabi-v7a", "arm" });
/* Create an error log. */
ManagedErrorLog errorLog = ErrorLogHelper.createErrorLog(mockContext, java.lang.Thread.currentThread(), new RuntimeException(new TestCrashException()), java.lang.Thread.getAllStackTraces(), 900);
assertNotNull(errorLog);
/* Test. */
Throwable throwable = new RuntimeException();
ErrorReport report = ErrorLogHelper.getErrorReportFromErrorLog(errorLog, throwable);
assertNotNull(report);
assertEquals(errorLog.getId().toString(), report.getId());
assertEquals(errorLog.getErrorThreadName(), report.getThreadName());
assertEquals(throwable, report.getThrowable());
assertEquals(errorLog.getAppLaunchTimestamp(), report.getAppStartTime());
assertEquals(errorLog.getTimestamp(), report.getAppErrorTime());
assertEquals(errorLog.getDevice(), report.getDevice());
}
Aggregations