正在查看: Housing v14.7.8 应用的 RNDeviceModule.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Housing v14.7.8 应用的 RNDeviceModule.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.learnium.RNDeviceInfo;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.KeyguardManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.FeatureInfo;
import android.content.pm.PackageInfo;
import android.hardware.camera2.CameraManager;
import android.location.LocationManager;
import android.media.AudioManager;
import android.media.MediaCodecList;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Environment;
import android.os.PowerManager;
import android.os.Process;
import android.os.StatFs;
import android.os.SystemClock;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebSettings;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.firebase.remoteconfig.RemoteConfigConstants;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.annotation.Nonnull;
@ReactModule(name = RNDeviceModule.NAME)
public class RNDeviceModule extends ReactContextBaseJavaModule {
private static String BATTERY_LEVEL = "batteryLevel";
private static String BATTERY_STATE = "batteryState";
private static String LOW_POWER_MODE = "lowPowerMode";
public static final String NAME = "RNDeviceInfo";
private final na.a deviceIdResolver;
private final na.b deviceTypeResolver;
private BroadcastReceiver headphoneBluetoothConnectionReceiver;
private BroadcastReceiver headphoneConnectionReceiver;
private BroadcastReceiver headphoneWiredConnectionReceiver;
private InputMethodManager inputMethodManager;
private f installReferrerClient;
private double mLastBatteryLevel;
private String mLastBatteryState;
private boolean mLastPowerSaveState;
private BroadcastReceiver receiver;
public class a extends BroadcastReceiver {
public a() {
}
@Override
public final void onReceive(Context context, Intent intent) {
WritableMap powerStateFromIntent = RNDeviceModule.this.getPowerStateFromIntent(intent);
if (powerStateFromIntent == null) {
return;
}
String string = powerStateFromIntent.getString(RNDeviceModule.BATTERY_STATE);
double d = powerStateFromIntent.getDouble(RNDeviceModule.BATTERY_LEVEL);
Double valueOf = Double.valueOf(d);
boolean z = powerStateFromIntent.getBoolean(RNDeviceModule.LOW_POWER_MODE);
if (!RNDeviceModule.this.mLastBatteryState.equalsIgnoreCase(string) || RNDeviceModule.this.mLastPowerSaveState != z) {
WritableMap createMap = Arguments.createMap();
createMap.putString(RNDeviceModule.BATTERY_STATE, string);
createMap.putDouble(RNDeviceModule.BATTERY_LEVEL, d);
createMap.putBoolean(RNDeviceModule.LOW_POWER_MODE, z);
RNDeviceModule rNDeviceModule = RNDeviceModule.this;
rNDeviceModule.sendEvent(rNDeviceModule.getReactApplicationContext(), "RNDeviceInfo_powerStateDidChange", createMap);
RNDeviceModule.this.mLastBatteryState = string;
RNDeviceModule.this.mLastPowerSaveState = z;
}
if (RNDeviceModule.this.mLastBatteryLevel != d) {
RNDeviceModule rNDeviceModule2 = RNDeviceModule.this;
rNDeviceModule2.sendEvent(rNDeviceModule2.getReactApplicationContext(), "RNDeviceInfo_batteryLevelDidChange", valueOf);
if (d <= 0.15d) {
RNDeviceModule rNDeviceModule3 = RNDeviceModule.this;
rNDeviceModule3.sendEvent(rNDeviceModule3.getReactApplicationContext(), "RNDeviceInfo_batteryLevelIsLow", valueOf);
}
RNDeviceModule.this.mLastBatteryLevel = d;
}
}
}
public class b extends BroadcastReceiver {
public b() {
}
@Override
public final void onReceive(Context context, Intent intent) {
boolean isHeadphonesConnectedSync = RNDeviceModule.this.isHeadphonesConnectedSync();
RNDeviceModule rNDeviceModule = RNDeviceModule.this;
rNDeviceModule.sendEvent(rNDeviceModule.getReactApplicationContext(), "RNDeviceInfo_headphoneConnectionDidChange", Boolean.valueOf(isHeadphonesConnectedSync));
}
}
public class c extends BroadcastReceiver {
public c() {
}
@Override
public final void onReceive(Context context, Intent intent) {
boolean isWiredHeadphonesConnectedSync = RNDeviceModule.this.isWiredHeadphonesConnectedSync();
RNDeviceModule rNDeviceModule = RNDeviceModule.this;
rNDeviceModule.sendEvent(rNDeviceModule.getReactApplicationContext(), "RNDeviceInfo_headphoneWiredConnectionDidChange", Boolean.valueOf(isWiredHeadphonesConnectedSync));
}
}
public class d extends BroadcastReceiver {
public d() {
}
@Override
public final void onReceive(Context context, Intent intent) {
boolean isBluetoothHeadphonesConnectedSync = RNDeviceModule.this.isBluetoothHeadphonesConnectedSync();
RNDeviceModule rNDeviceModule = RNDeviceModule.this;
rNDeviceModule.sendEvent(rNDeviceModule.getReactApplicationContext(), "RNDeviceInfo_headphoneBluetoothConnectionDidChange", Boolean.valueOf(isBluetoothHeadphonesConnectedSync));
}
}
public RNDeviceModule(ReactApplicationContext reactApplicationContext) {
super(reactApplicationContext);
this.mLastBatteryLevel = -1.0d;
this.mLastBatteryState = "";
this.mLastPowerSaveState = false;
this.deviceTypeResolver = new na.b(reactApplicationContext);
this.deviceIdResolver = new na.a(reactApplicationContext);
this.installReferrerClient = new f(reactApplicationContext.getBaseContext());
this.inputMethodManager = (InputMethodManager) reactApplicationContext.getSystemService("input_method");
}
private long getBlockSize(StatFs statFs, Boolean bool) {
return bool.booleanValue() ? statFs.getBlockSizeLong() : statFs.getBlockSize();
}
private BigInteger getDirTotalCapacity(StatFs statFs) {
return BigInteger.valueOf(statFs.getBlockCountLong()).multiply(BigInteger.valueOf(statFs.getBlockSizeLong()));
}
private PackageInfo getPackageInfo() throws Exception {
return getReactApplicationContext().getPackageManager().getPackageInfo(getReactApplicationContext().getPackageName(), 0);
}
public WritableMap getPowerStateFromIntent(Intent intent) {
if (intent == null) {
return null;
}
int intExtra = intent.getIntExtra(FirebaseAnalytics.Param.LEVEL, -1);
int intExtra2 = intent.getIntExtra("scale", -1);
int intExtra3 = intent.getIntExtra("plugged", -1);
int intExtra4 = intent.getIntExtra("status", -1);
float f = intExtra / intExtra2;
String str = intExtra3 == 0 ? "unplugged" : intExtra4 == 2 ? "charging" : intExtra4 == 5 ? "full" : "unknown";
boolean isPowerSaveMode = ((PowerManager) getReactApplicationContext().getSystemService("power")).isPowerSaveMode();
WritableMap createMap = Arguments.createMap();
createMap.putString(BATTERY_STATE, str);
createMap.putDouble(BATTERY_LEVEL, f);
createMap.putBoolean(LOW_POWER_MODE, isPowerSaveMode);
return createMap;
}
public static SharedPreferences getRNDISharedPreferences(Context context) {
return context.getSharedPreferences("react-native-device-info", 0);
}
private long getTotalAvailableBlocks(StatFs statFs, Boolean bool) {
return bool.booleanValue() ? statFs.getAvailableBlocksLong() : statFs.getAvailableBlocks();
}
@SuppressLint({"MissingPermission"})
private WifiInfo getWifiInfo() {
WifiManager wifiManager = (WifiManager) getReactApplicationContext().getApplicationContext().getSystemService("wifi");
if (wifiManager != null) {
return wifiManager.getConnectionInfo();
}
return null;
}
private boolean hasKeyboard(String str) {
List<InputMethodInfo> enabledInputMethodList = this.inputMethodManager.getEnabledInputMethodList();
if (enabledInputMethodList == null || enabledInputMethodList.isEmpty()) {
return false;
}
for (InputMethodInfo inputMethodInfo : enabledInputMethodList) {
String lowerCase = inputMethodInfo.getServiceName().toLowerCase();
String lowerCase2 = inputMethodInfo.getId().toLowerCase();
if (lowerCase.contains(str.toLowerCase()) || lowerCase2.contains(str.toLowerCase())) {
return true;
}
}
return false;
}
private void initializeHeadphoneConnectionReceivers() {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.intent.action.HEADSET_PLUG");
intentFilter.addAction("android.media.ACTION_SCO_AUDIO_STATE_UPDATED");
this.headphoneConnectionReceiver = new b();
registerReceiver(getReactApplicationContext(), this.headphoneConnectionReceiver, intentFilter);
new IntentFilter().addAction("android.intent.action.HEADSET_PLUG");
this.headphoneWiredConnectionReceiver = new c();
registerReceiver(getReactApplicationContext(), this.headphoneWiredConnectionReceiver, intentFilter);
new IntentFilter().addAction("android.media.ACTION_SCO_AUDIO_STATE_UPDATED");
this.headphoneBluetoothConnectionReceiver = new d();
registerReceiver(getReactApplicationContext(), this.headphoneBluetoothConnectionReceiver, intentFilter);
}
@Nonnull
private Boolean isLowRamDevice() {
return Boolean.valueOf(((ActivityManager) getReactApplicationContext().getSystemService("activity")).isLowRamDevice());
}
@SuppressLint({"UnspecifiedRegisterReceiverFlag"})
private void registerReceiver(Context context, BroadcastReceiver broadcastReceiver, IntentFilter intentFilter) {
if (Build.VERSION.SDK_INT < 34 || context.getApplicationInfo().targetSdkVersion < 34) {
context.registerReceiver(broadcastReceiver, intentFilter);
} else {
context.registerReceiver(broadcastReceiver, intentFilter, 4);
}
}
public void sendEvent(ReactContext reactContext, String str, @Nullable Object obj) {
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(str, obj);
}
@ReactMethod
public void addListener(String str) {
}
@ReactMethod
public void getAndroidId(Promise promise) {
promise.resolve(getAndroidIdSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
@SuppressLint({"HardwareIds"})
public String getAndroidIdSync() {
return getUniqueIdSync();
}
@ReactMethod
public void getApiLevel(Promise promise) {
promise.resolve(Integer.valueOf(getApiLevelSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public int getApiLevelSync() {
return Build.VERSION.SDK_INT;
}
@ReactMethod
public void getAvailableLocationProviders(Promise promise) {
promise.resolve(getAvailableLocationProvidersSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public WritableMap getAvailableLocationProvidersSync() {
LocationManager locationManager = (LocationManager) getReactApplicationContext().getSystemService(FirebaseAnalytics.Param.LOCATION);
WritableMap createMap = Arguments.createMap();
try {
for (String str : locationManager.getProviders(false)) {
createMap.putBoolean(str, locationManager.isProviderEnabled(str));
}
} catch (Exception unused) {
System.err.println("Unable to get location providers. LocationManager was null");
}
return createMap;
}
@ReactMethod
public void getBaseOs(Promise promise) {
promise.resolve(getBaseOsSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getBaseOsSync() {
return Build.VERSION.BASE_OS;
}
@ReactMethod
public void getBatteryLevel(Promise promise) {
promise.resolve(Double.valueOf(getBatteryLevelSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public double getBatteryLevelSync() {
WritableMap powerStateFromIntent = getPowerStateFromIntent(getReactApplicationContext().registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED")));
if (powerStateFromIntent == null) {
return 0.0d;
}
return powerStateFromIntent.getDouble(BATTERY_LEVEL);
}
@ReactMethod
public void getBootloader(Promise promise) {
promise.resolve(getBootloaderSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getBootloaderSync() {
return Build.BOOTLOADER;
}
@ReactMethod
public void getBuildId(Promise promise) {
promise.resolve(getBuildIdSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getBuildIdSync() {
return Build.ID;
}
@ReactMethod
public void getCarrier(Promise promise) {
promise.resolve(getCarrierSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getCarrierSync() {
TelephonyManager telephonyManager = (TelephonyManager) getReactApplicationContext().getSystemService("phone");
if (telephonyManager != null) {
return telephonyManager.getNetworkOperatorName();
}
System.err.println("Unable to get network operator name. TelephonyManager was null");
return "unknown";
}
@ReactMethod
public void getCodename(Promise promise) {
promise.resolve(getCodenameSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getCodenameSync() {
return Build.VERSION.CODENAME;
}
public Map<String, Object> getConstants() {
String str;
String str2;
String str3;
try {
str = getPackageInfo().versionName;
str2 = Integer.toString(getPackageInfo().versionCode);
str3 = getReactApplicationContext().getApplicationInfo().loadLabel(getReactApplicationContext().getPackageManager()).toString();
} catch (Exception unused) {
str = "unknown";
str2 = "unknown";
str3 = str2;
}
HashMap hashMap = new HashMap();
hashMap.put("deviceId", Build.BOARD);
hashMap.put("bundleId", getReactApplicationContext().getPackageName());
hashMap.put("systemName", "Android");
hashMap.put("systemVersion", Build.VERSION.RELEASE);
hashMap.put(RemoteConfigConstants.RequestFieldKey.APP_VERSION, str);
hashMap.put("buildNumber", str2);
hashMap.put("isTablet", Boolean.valueOf(this.deviceTypeResolver.a() == com.learnium.RNDeviceInfo.a.TABLET));
hashMap.put("isLowRamDevice", isLowRamDevice());
hashMap.put("appName", str3);
hashMap.put("brand", Build.BRAND);
hashMap.put("model", Build.MODEL);
hashMap.put("deviceType", this.deviceTypeResolver.a().getValue());
return hashMap;
}
@ReactMethod
public void getDevice(Promise promise) {
promise.resolve(getDeviceSync());
}
@ReactMethod
public void getDeviceName(Promise promise) {
promise.resolve(getDeviceNameSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getDeviceNameSync() {
String string;
try {
if (Build.VERSION.SDK_INT <= 31 && (string = Settings.Secure.getString(getReactApplicationContext().getContentResolver(), "bluetooth_name")) != null) {
return string;
}
String string2 = Settings.Global.getString(getReactApplicationContext().getContentResolver(), "device_name");
return string2 != null ? string2 : "unknown";
} catch (Exception unused) {
return "unknown";
}
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getDeviceSync() {
return Build.DEVICE;
}
@ReactMethod
public void getDisplay(Promise promise) {
promise.resolve(getDisplaySync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getDisplaySync() {
return Build.DISPLAY;
}
@ReactMethod
public void getFingerprint(Promise promise) {
promise.resolve(getFingerprintSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getFingerprintSync() {
return Build.FINGERPRINT;
}
@ReactMethod
public void getFirstInstallTime(Promise promise) {
promise.resolve(Double.valueOf(getFirstInstallTimeSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public double getFirstInstallTimeSync() {
try {
return getPackageInfo().firstInstallTime;
} catch (Exception unused) {
return -1.0d;
}
}
@ReactMethod
public void getFontScale(Promise promise) {
promise.resolve(Float.valueOf(getFontScaleSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public float getFontScaleSync() {
return getReactApplicationContext().getResources().getConfiguration().fontScale;
}
@ReactMethod
public void getFreeDiskStorage(Promise promise) {
promise.resolve(Double.valueOf(getFreeDiskStorageSync()));
}
@ReactMethod
public void getFreeDiskStorageOld(Promise promise) {
promise.resolve(Double.valueOf(getFreeDiskStorageOldSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public double getFreeDiskStorageOldSync() {
try {
StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
return BigInteger.valueOf(statFs.getAvailableBlocksLong()).multiply(BigInteger.valueOf(statFs.getBlockSizeLong())).doubleValue();
} catch (Exception unused) {
return -1.0d;
}
}
@ReactMethod(isBlockingSynchronousMethod = true)
public double getFreeDiskStorageSync() {
try {
StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
StatFs statFs2 = new StatFs(Environment.getDataDirectory().getAbsolutePath());
return BigInteger.valueOf(getTotalAvailableBlocks(statFs, true)).multiply(BigInteger.valueOf(getBlockSize(statFs, true))).doubleValue() + BigInteger.valueOf(getTotalAvailableBlocks(statFs2, true)).multiply(BigInteger.valueOf(getBlockSize(statFs2, true))).doubleValue();
} catch (Exception unused) {
return -1.0d;
}
}
@ReactMethod
public void getHardware(Promise promise) {
promise.resolve(getHardwareSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getHardwareSync() {
return Build.HARDWARE;
}
@ReactMethod
public void getHost(Promise promise) {
promise.resolve(getHostSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getHostSync() {
return Build.HOST;
}
@ReactMethod
public void getIncremental(Promise promise) {
promise.resolve(getIncrementalSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getIncrementalSync() {
return Build.VERSION.INCREMENTAL;
}
@ReactMethod
public void getInstallReferrer(Promise promise) {
promise.resolve(getInstallReferrerSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getInstallReferrerSync() {
return getRNDISharedPreferences(getReactApplicationContext()).getString("installReferrer", "unknown");
}
@ReactMethod
public void getInstallerPackageName(Promise promise) {
promise.resolve(getInstallerPackageNameSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getInstallerPackageNameSync() {
String installerPackageName = getReactApplicationContext().getPackageManager().getInstallerPackageName(getReactApplicationContext().getPackageName());
return installerPackageName == null ? "unknown" : installerPackageName;
}
@ReactMethod
public void getInstanceId(Promise promise) {
promise.resolve(getInstanceIdSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getInstanceIdSync() {
return this.deviceIdResolver.c();
}
@ReactMethod
public void getIpAddress(Promise promise) {
promise.resolve(getIpAddressSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getIpAddressSync() {
try {
return InetAddress.getByAddress(ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(getWifiInfo().getIpAddress()).array()).getHostAddress();
} catch (Exception unused) {
return "unknown";
}
}
@ReactMethod
public void getLastUpdateTime(Promise promise) {
promise.resolve(Double.valueOf(getLastUpdateTimeSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public double getLastUpdateTimeSync() {
try {
return getPackageInfo().lastUpdateTime;
} catch (Exception unused) {
return -1.0d;
}
}
@ReactMethod
public void getMacAddress(Promise promise) {
promise.resolve(getMacAddressSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
@SuppressLint({"HardwareIds"})
public String getMacAddressSync() {
WifiInfo wifiInfo = getWifiInfo();
String macAddress = wifiInfo != null ? wifiInfo.getMacAddress() : "";
if (getReactApplicationContext().checkCallingOrSelfPermission("android.permission.INTERNET") == 0) {
try {
for (NetworkInterface networkInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
if (networkInterface.getName().equalsIgnoreCase("wlan0")) {
byte[] hardwareAddress = networkInterface.getHardwareAddress();
if (hardwareAddress == null) {
macAddress = "";
} else {
StringBuilder sb = new StringBuilder();
for (byte b2 : hardwareAddress) {
sb.append(String.format("%02X:", Byte.valueOf(b2)));
}
if (sb.length() > 0) {
sb.deleteCharAt(sb.length() - 1);
}
macAddress = sb.toString();
}
}
}
} catch (Exception unused) {
}
}
return macAddress;
}
@ReactMethod
public void getMaxMemory(Promise promise) {
promise.resolve(Double.valueOf(getMaxMemorySync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public double getMaxMemorySync() {
return Runtime.getRuntime().maxMemory();
}
@Nonnull
public String getName() {
return NAME;
}
@ReactMethod
public void getPowerState(Promise promise) {
promise.resolve(getPowerStateSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public WritableMap getPowerStateSync() {
return getPowerStateFromIntent(getReactApplicationContext().registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED")));
}
@ReactMethod
public void getPreviewSdkInt(Promise promise) {
promise.resolve(getPreviewSdkIntSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getPreviewSdkIntSync() {
return Integer.toString(Build.VERSION.PREVIEW_SDK_INT);
}
@ReactMethod
public void getProduct(Promise promise) {
promise.resolve(getProductSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getProductSync() {
return Build.PRODUCT;
}
@ReactMethod
public void getSecurityPatch(Promise promise) {
promise.resolve(getSecurityPatchSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getSecurityPatchSync() {
return Build.VERSION.SECURITY_PATCH;
}
@ReactMethod
public void getSerialNumber(Promise promise) {
promise.resolve(getSerialNumberSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
@SuppressLint({"HardwareIds", "MissingPermission"})
public String getSerialNumberSync() {
try {
return Build.getSerial();
} catch (Exception e) {
System.err.println("getSerialNumber failed, it probably should not be used: " + e.getMessage());
return "unknown";
}
}
@ReactMethod
public void getStartupTime(Promise promise) {
promise.resolve(Double.valueOf(getStartupTimeSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public double getStartupTimeSync() {
long currentTimeMillis = System.currentTimeMillis();
return BigInteger.valueOf((currentTimeMillis - SystemClock.uptimeMillis()) + Process.getStartUptimeMillis()).doubleValue();
}
@ReactMethod
public void getSupported32BitAbis(Promise promise) {
promise.resolve(getSupported32BitAbisSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public WritableArray getSupported32BitAbisSync() {
WritableNativeArray writableNativeArray = new WritableNativeArray();
for (String str : Build.SUPPORTED_32_BIT_ABIS) {
writableNativeArray.pushString(str);
}
return writableNativeArray;
}
@ReactMethod
public void getSupported64BitAbis(Promise promise) {
promise.resolve(getSupported64BitAbisSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public WritableArray getSupported64BitAbisSync() {
WritableNativeArray writableNativeArray = new WritableNativeArray();
for (String str : Build.SUPPORTED_64_BIT_ABIS) {
writableNativeArray.pushString(str);
}
return writableNativeArray;
}
@ReactMethod
public void getSupportedAbis(Promise promise) {
promise.resolve(getSupportedAbisSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public WritableArray getSupportedAbisSync() {
WritableNativeArray writableNativeArray = new WritableNativeArray();
for (String str : Build.SUPPORTED_ABIS) {
writableNativeArray.pushString(str);
}
return writableNativeArray;
}
@ReactMethod
public void getSupportedMediaTypeList(Promise promise) {
promise.resolve(getSupportedMediaTypeListSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public WritableArray getSupportedMediaTypeListSync() {
WritableNativeArray writableNativeArray = new WritableNativeArray();
for (int i = 0; i < MediaCodecList.getCodecCount(); i++) {
for (String str : MediaCodecList.getCodecInfoAt(i).getSupportedTypes()) {
writableNativeArray.pushString(str);
}
}
return writableNativeArray;
}
@ReactMethod
public void getSystemAvailableFeatures(Promise promise) {
promise.resolve(getSystemAvailableFeaturesSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public WritableArray getSystemAvailableFeaturesSync() {
FeatureInfo[] systemAvailableFeatures = getReactApplicationContext().getPackageManager().getSystemAvailableFeatures();
WritableArray createArray = Arguments.createArray();
for (FeatureInfo featureInfo : systemAvailableFeatures) {
String str = featureInfo.name;
if (str != null) {
createArray.pushString(str);
}
}
return createArray;
}
@ReactMethod
public void getSystemManufacturer(Promise promise) {
promise.resolve(getSystemManufacturerSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getSystemManufacturerSync() {
return Build.MANUFACTURER;
}
@ReactMethod
public void getTags(Promise promise) {
promise.resolve(getTagsSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getTagsSync() {
return Build.TAGS;
}
@ReactMethod
public void getTotalDiskCapacity(Promise promise) {
promise.resolve(Double.valueOf(getTotalDiskCapacitySync()));
}
@ReactMethod
public void getTotalDiskCapacityOld(Promise promise) {
promise.resolve(Double.valueOf(getTotalDiskCapacityOldSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
@Deprecated
public double getTotalDiskCapacityOldSync() {
try {
StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
return BigInteger.valueOf(statFs.getBlockCount()).multiply(BigInteger.valueOf(statFs.getBlockSize())).doubleValue();
} catch (Exception unused) {
return -1.0d;
}
}
@ReactMethod(isBlockingSynchronousMethod = true)
public double getTotalDiskCapacitySync() {
try {
return getDirTotalCapacity(new StatFs(Environment.getRootDirectory().getAbsolutePath())).add(getDirTotalCapacity(new StatFs(Environment.getDataDirectory().getAbsolutePath()))).doubleValue();
} catch (Exception unused) {
return -1.0d;
}
}
@ReactMethod
public void getTotalMemory(Promise promise) {
promise.resolve(Double.valueOf(getTotalMemorySync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public double getTotalMemorySync() {
ActivityManager activityManager = (ActivityManager) getReactApplicationContext().getSystemService("activity");
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
if (activityManager != null) {
activityManager.getMemoryInfo(memoryInfo);
return memoryInfo.totalMem;
}
System.err.println("Unable to getMemoryInfo. ActivityManager was null");
return -1.0d;
}
@ReactMethod
public void getType(Promise promise) {
promise.resolve(getTypeSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getTypeSync() {
return Build.TYPE;
}
@ReactMethod
public void getUniqueId(Promise promise) {
promise.resolve(getUniqueIdSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
@SuppressLint({"HardwareIds"})
public String getUniqueIdSync() {
return Settings.Secure.getString(getReactApplicationContext().getContentResolver(), "android_id");
}
@ReactMethod
public void getUsedMemory(Promise promise) {
promise.resolve(Double.valueOf(getUsedMemorySync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public double getUsedMemorySync() {
ActivityManager activityManager = (ActivityManager) getReactApplicationContext().getSystemService("activity");
if (activityManager == null) {
System.err.println("Unable to getProcessMemoryInfo. ActivityManager was null");
return -1.0d;
}
if (activityManager.getProcessMemoryInfo(new int[]{Process.myPid()}).length == 1) {
return r0[0].getTotalPss() * 1024.0d;
}
System.err.println("Unable to getProcessMemoryInfo. getProcessMemoryInfo did not return any info for the PID");
return -1.0d;
}
@ReactMethod
public void getUserAgent(Promise promise) {
promise.resolve(getUserAgentSync());
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String getUserAgentSync() {
try {
return WebSettings.getDefaultUserAgent(getReactApplicationContext());
} catch (RuntimeException unused) {
return System.getProperty("http.agent");
}
}
@ReactMethod
public void hasGms(Promise promise) {
promise.resolve(Boolean.valueOf(hasGmsSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public boolean hasGmsSync() {
try {
int i = GoogleApiAvailability.GOOGLE_PLAY_SERVICES_VERSION_CODE;
Object invoke = GoogleApiAvailability.class.getMethod("getInstance", new Class[0]).invoke(null, new Object[0]);
return ((Integer) invoke.getClass().getMethod("isGooglePlayServicesAvailable", Context.class).invoke(invoke, getReactApplicationContext())).intValue() == 0;
} catch (Exception unused) {
return false;
}
}
@ReactMethod
public void hasHms(Promise promise) {
promise.resolve(Boolean.valueOf(hasHmsSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public boolean hasHmsSync() {
try {
Object invoke = Class.forName("com.huawei.hms.api.HuaweiApiAvailability").getMethod("getInstance", new Class[0]).invoke(null, new Object[0]);
return ((Integer) invoke.getClass().getMethod("isHuaweiMobileServicesAvailable", Context.class).invoke(invoke, getReactApplicationContext())).intValue() == 0;
} catch (Exception unused) {
return false;
}
}
@ReactMethod
public void hasSystemFeature(String str, Promise promise) {
promise.resolve(Boolean.valueOf(hasSystemFeatureSync(str)));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public boolean hasSystemFeatureSync(String str) {
if (str == null || str.equals("")) {
return false;
}
return getReactApplicationContext().getPackageManager().hasSystemFeature(str);
}
public void initialize() {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.intent.action.BATTERY_CHANGED");
intentFilter.addAction("android.intent.action.ACTION_POWER_CONNECTED");
intentFilter.addAction("android.intent.action.ACTION_POWER_DISCONNECTED");
intentFilter.addAction("android.os.action.POWER_SAVE_MODE_CHANGED");
this.receiver = new a();
registerReceiver(getReactApplicationContext(), this.receiver, intentFilter);
initializeHeadphoneConnectionReceivers();
}
public void invalidate() {
getReactApplicationContext().unregisterReceiver(this.receiver);
getReactApplicationContext().unregisterReceiver(this.headphoneConnectionReceiver);
getReactApplicationContext().unregisterReceiver(this.headphoneWiredConnectionReceiver);
getReactApplicationContext().unregisterReceiver(this.headphoneBluetoothConnectionReceiver);
}
@ReactMethod
public void isAirplaneMode(Promise promise) {
promise.resolve(Boolean.valueOf(isAirplaneModeSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public boolean isAirplaneModeSync() {
return Settings.Global.getInt(getReactApplicationContext().getContentResolver(), "airplane_mode_on", 0) != 0;
}
@ReactMethod
public void isBatteryCharging(Promise promise) {
promise.resolve(Boolean.valueOf(isBatteryChargingSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public boolean isBatteryChargingSync() {
Intent registerReceiver = getReactApplicationContext().registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
return (registerReceiver != null ? registerReceiver.getIntExtra("status", -1) : 0) == 2;
}
@ReactMethod
public void isBluetoothHeadphonesConnected(Promise promise) {
promise.resolve(Boolean.valueOf(isBluetoothHeadphonesConnectedSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public boolean isBluetoothHeadphonesConnectedSync() {
return ((AudioManager) getReactApplicationContext().getSystemService("audio")).isBluetoothA2dpOn();
}
@ReactMethod
public void isCameraPresent(Promise promise) {
promise.resolve(Boolean.valueOf(isCameraPresentSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public boolean isCameraPresentSync() {
return ((CameraManager) getReactApplicationContext().getSystemService("camera")).getCameraIdList().length > 0;
}
@ReactMethod
public void isEmulator(Promise promise) {
promise.resolve(Boolean.valueOf(isEmulatorSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
@SuppressLint({"HardwareIds"})
public boolean isEmulatorSync() {
String str = Build.FINGERPRINT;
if (str.startsWith("generic") || str.startsWith("unknown")) {
return true;
}
String str2 = Build.MODEL;
if (str2.contains("google_sdk")) {
return true;
}
Locale locale = Locale.ROOT;
if (str2.toLowerCase(locale).contains("droid4x") || str2.contains("Emulator") || str2.contains("Android SDK built for x86") || Build.MANUFACTURER.contains("Genymotion")) {
return true;
}
String str3 = Build.HARDWARE;
if (str3.contains("goldfish") || str3.contains("ranchu") || str3.contains("vbox86")) {
return true;
}
String str4 = Build.PRODUCT;
if (str4.contains("sdk") || str4.contains("google_sdk") || str4.contains("sdk_google") || str4.contains("sdk_x86") || str4.contains("vbox86p") || str4.contains("emulator") || str4.contains("simulator") || Build.BOARD.toLowerCase(locale).contains("nox") || Build.BOOTLOADER.toLowerCase(locale).contains("nox") || str3.toLowerCase(locale).contains("nox") || str4.toLowerCase(locale).contains("nox") || Build.SERIAL.toLowerCase(locale).contains("nox")) {
return true;
}
return (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic")) || hasKeyboard("memuime");
}
@ReactMethod
public void isHeadphonesConnected(Promise promise) {
promise.resolve(Boolean.valueOf(isHeadphonesConnectedSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public boolean isHeadphonesConnectedSync() {
AudioManager audioManager = (AudioManager) getReactApplicationContext().getSystemService("audio");
return audioManager.isWiredHeadsetOn() || audioManager.isBluetoothA2dpOn();
}
@ReactMethod
public void isLocationEnabled(Promise promise) {
promise.resolve(Boolean.valueOf(isLocationEnabledSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public boolean isLocationEnabledSync() {
if (Build.VERSION.SDK_INT < 28) {
return Settings.Secure.getInt(getReactApplicationContext().getContentResolver(), "location_mode", 0) != 0;
}
try {
return androidx.core.view.accessibility.d.x((LocationManager) getReactApplicationContext().getSystemService(FirebaseAnalytics.Param.LOCATION));
} catch (Exception unused) {
System.err.println("Unable to determine if location enabled. LocationManager was null");
return false;
}
}
@ReactMethod
public void isPinOrFingerprintSet(Promise promise) {
promise.resolve(Boolean.valueOf(isPinOrFingerprintSetSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public boolean isPinOrFingerprintSetSync() {
KeyguardManager keyguardManager = (KeyguardManager) getReactApplicationContext().getSystemService("keyguard");
if (keyguardManager != null) {
return keyguardManager.isKeyguardSecure();
}
System.err.println("Unable to determine keyguard status. KeyguardManager was null");
return false;
}
@ReactMethod
public void isWiredHeadphonesConnected(Promise promise) {
promise.resolve(Boolean.valueOf(isWiredHeadphonesConnectedSync()));
}
@ReactMethod(isBlockingSynchronousMethod = true)
public boolean isWiredHeadphonesConnectedSync() {
return ((AudioManager) getReactApplicationContext().getSystemService("audio")).isWiredHeadsetOn();
}
public void onCatalystInstanceDestroy() {
invalidate();
}
@ReactMethod
public void removeListeners(Integer num) {
}
}