implemented new Util function isSimulatorOrEmulator

This commit is contained in:
Alexander Ziskind
2020-11-24 20:39:09 -05:00
parent bd7c686aaf
commit 4474dee6a8
8 changed files with 64 additions and 33 deletions

View File

@ -93,7 +93,7 @@ export type { InstrumentationMode, TimerInfo } from './profiling';
export { encoding } from './text'; export { encoding } from './text';
export * from './trace'; export * from './trace';
export * from './ui'; export * from './ui';
import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source } from './utils'; import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, isSimulatorOrEmulator, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source } from './utils';
import { ClassInfo, getClass, getBaseClasses, getClassInfo, isBoolean, isDefined, isFunction, isNullOrUndefined, isNumber, isObject, isString, isUndefined, toUIString, verifyCallback } from './utils/types'; import { ClassInfo, getClass, getBaseClasses, getClassInfo, isBoolean, isDefined, isFunction, isNullOrUndefined, isNumber, isObject, isString, isUndefined, toUIString, verifyCallback } from './utils/types';
export declare const Utils: { export declare const Utils: {
GC: typeof GC; GC: typeof GC;
@ -111,6 +111,7 @@ export declare const Utils: {
openFile: typeof openFile; openFile: typeof openFile;
openUrl: typeof openUrl; openUrl: typeof openUrl;
isRealDevice: typeof isRealDevice; isRealDevice: typeof isRealDevice;
isSimulatorOrEmulator: typeof isSimulatorOrEmulator;
layout: typeof layout; layout: typeof layout;
android: typeof androidUtils; android: typeof androidUtils;
ad: typeof androidUtils; ad: typeof androidUtils;

View File

@ -110,7 +110,7 @@ export * from './trace';
export * from './ui'; export * from './ui';
import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, queueMacrotask, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source, RESOURCE_PREFIX, FILE_PREFIX } from './utils'; import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, queueMacrotask, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, isSimulatorOrEmulator, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source, RESOURCE_PREFIX, FILE_PREFIX } from './utils';
import { ClassInfo, getClass, getBaseClasses, getClassInfo, isBoolean, isDefined, isFunction, isNullOrUndefined, isNumber, isObject, isString, isUndefined, toUIString, verifyCallback } from './utils/types'; import { ClassInfo, getClass, getBaseClasses, getClassInfo, isBoolean, isDefined, isFunction, isNullOrUndefined, isNumber, isObject, isString, isUndefined, toUIString, verifyCallback } from './utils/types';
export const Utils = { export const Utils = {
@ -131,6 +131,7 @@ export const Utils = {
openFile, openFile,
openUrl, openUrl,
isRealDevice, isRealDevice,
isSimulatorOrEmulator,
layout, layout,
android: androidUtils, android: androidUtils,

View File

@ -167,3 +167,7 @@ Please ensure you have your manifest correctly configured with the FileProvider.
export function isRealDevice(): boolean { export function isRealDevice(): boolean {
return ad.isRealDevice(); return ad.isRealDevice();
} }
export function isSimulatorOrEmulator(): boolean {
return ad.isSimulatorOrEmulator();
}

View File

@ -286,3 +286,5 @@ export function eliminateDuplicates(arr: Array<any>): Array<any>;
* Checks whether the application is running on real device and not on simulator/emulator. * Checks whether the application is running on real device and not on simulator/emulator.
*/ */
export function isRealDevice(): boolean; export function isRealDevice(): boolean;
export function isSimulatorOrEmulator(): boolean;

View File

@ -47,4 +47,8 @@ export function isRealDevice(): boolean {
return iOSNativeHelper.isRealDevice(); return iOSNativeHelper.isRealDevice();
} }
export function isSimulatorOrEmulator(): boolean {
return iOSNativeHelper.isSimulatorOrEmulator();
}
export const ad = 0; export const ad = 0;

View File

@ -1,5 +1,6 @@
import { getNativeApplication, android as androidApp } from '../application'; import { getNativeApplication, android as androidApp } from '../application';
import { Trace } from '../trace'; import { Trace } from '../trace';
import { isNullOrUndefined } from './types';
// We are using "ad" here to avoid namespace collision with the global android object // We are using "ad" here to avoid namespace collision with the global android object
export namespace ad { export namespace ad {
@ -153,9 +154,17 @@ export namespace ad {
export function isRealDevice(): boolean { export function isRealDevice(): boolean {
const fingerprint = android.os.Build.FINGERPRINT; const fingerprint = android.os.Build.FINGERPRINT;
return fingerprint != null && (fingerprint.indexOf('vbox') > -1 || fingerprint.indexOf('generic') > -1); return fingerprint != null && (fingerprint.indexOf('vbox') > -1 || fingerprint.indexOf('generic') > -1);
} }
export function isSimulatorOrEmulator(): boolean {
const fingerprint = android.os.Build.FINGERPRINT;
if (isNullOrUndefined(fingerprint)) {
return true;
} else {
return fingerprint.includes('vbox') || fingerprint.includes('generic');
}
}
} }
export const iOSNativeHelper = 0; export const iOSNativeHelper = 0;

View File

@ -88,6 +88,8 @@ export namespace ad {
* Checks whether the application is running on real device and not on emulator. * Checks whether the application is running on real device and not on emulator.
*/ */
export function isRealDevice(): boolean; export function isRealDevice(): boolean;
export function isSimulatorOrEmulator(): boolean;
} }
/** /**
* Module with ios specific utilities. * Module with ios specific utilities.
@ -168,13 +170,15 @@ export namespace iOSNativeHelper {
*/ */
export function applyRotateTransform(transform: any /* CATransform3D*/, x: number, y: number, z: number): any; /* CATransform3D*/ export function applyRotateTransform(transform: any /* CATransform3D*/, x: number, y: number, z: number): any; /* CATransform3D*/
/** /**
* Create a UIDocumentInteractionControllerDelegate implementation for use with UIDocumentInteractionController * Create a UIDocumentInteractionControllerDelegate implementation for use with UIDocumentInteractionController
*/ */
export function createUIDocumentInteractionControllerDelegate(): any; export function createUIDocumentInteractionControllerDelegate(): any;
/** /**
* Checks whether the application is running on real device and not on simulator. * Checks whether the application is running on real device and not on simulator.
*/ */
export function isRealDevice(): boolean; export function isRealDevice(): boolean;
export function isSimulatorOrEmulator(): boolean;
} }

View File

@ -1,4 +1,5 @@
import { Trace } from '../trace'; import { Trace } from '../trace';
import { isNullOrUndefined } from './types';
declare let UIImagePickerControllerSourceType: any; declare let UIImagePickerControllerSourceType: any;
@ -125,33 +126,33 @@ export namespace iOSNativeHelper {
} }
return transform; return transform;
} }
export function createUIDocumentInteractionControllerDelegate(): NSObject { export function createUIDocumentInteractionControllerDelegate(): NSObject {
@NativeClass @NativeClass
class UIDocumentInteractionControllerDelegateImpl extends NSObject implements UIDocumentInteractionControllerDelegate { class UIDocumentInteractionControllerDelegateImpl extends NSObject implements UIDocumentInteractionControllerDelegate {
public static ObjCProtocols = [UIDocumentInteractionControllerDelegate]; public static ObjCProtocols = [UIDocumentInteractionControllerDelegate];
public getViewController(): UIViewController { public getViewController(): UIViewController {
const app = UIApplication.sharedApplication; const app = UIApplication.sharedApplication;
return app.keyWindow.rootViewController; return app.keyWindow.rootViewController;
} }
public documentInteractionControllerViewControllerForPreview(controller: UIDocumentInteractionController) { public documentInteractionControllerViewControllerForPreview(controller: UIDocumentInteractionController) {
return this.getViewController(); return this.getViewController();
} }
public documentInteractionControllerViewForPreview(controller: UIDocumentInteractionController) { public documentInteractionControllerViewForPreview(controller: UIDocumentInteractionController) {
return this.getViewController().view; return this.getViewController().view;
} }
public documentInteractionControllerRectForPreview(controller: UIDocumentInteractionController): CGRect { public documentInteractionControllerRectForPreview(controller: UIDocumentInteractionController): CGRect {
return this.getViewController().view.frame; return this.getViewController().view.frame;
} }
} }
return new UIDocumentInteractionControllerDelegateImpl(); return new UIDocumentInteractionControllerDelegateImpl();
} }
export function isRealDevice() { export function isRealDevice() {
try { try {
@ -164,4 +165,9 @@ export namespace iOSNativeHelper {
return true; return true;
} }
} }
export function isSimulatorOrEmulator(): boolean {
const realDevice = isRealDevice();
return isNullOrUndefined(realDevice);
}
} }