| | |
| | | import android.os.Build; |
| | | import android.provider.Settings; |
| | | |
| | | import com.secondworld.sdk.GameApp; |
| | | import com.secondworld.sdk.GameAppProxy; |
| | | |
| | | import java.net.NetworkInterface; |
| | | import java.util.Enumeration; |
| | |
| | | public static final String FAKE_MAC = "02:00:00:00:00:00"; |
| | | |
| | | |
| | | |
| | | public static long getVersionCode() { |
| | | long appVersionCode = 0; |
| | | try { |
| | | PackageInfo packageInfo = GameApp.I.getApplicationContext() |
| | | PackageInfo packageInfo = GameAppProxy.app.getApplicationContext() |
| | | .getPackageManager() |
| | | .getPackageInfo(GameApp.I.getPackageName(), 0); |
| | | .getPackageInfo(GameAppProxy.app.getPackageName(), 0); |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { |
| | | appVersionCode = packageInfo.getLongVersionCode(); |
| | | } else { |
| | |
| | | |
| | | public static String getVersionName() { |
| | | String appVersionName = ""; |
| | | try { |
| | | PackageInfo packageInfo = GameApp.I.getApplicationContext() |
| | | .getPackageManager() |
| | | .getPackageInfo(GameApp.I.getPackageName(), 0); |
| | | appVersionName = packageInfo.versionName; |
| | | } catch (PackageManager.NameNotFoundException e) { |
| | | LogUtil.e("getAppVersionName", e); |
| | | } |
| | | // try { |
| | | // PackageInfo packageInfo = GameAppProxy.app.getApplicationContext() |
| | | // .getPackageManager() |
| | | // .getPackageInfo(GameAppProxy.app.getPackageName(), 0); |
| | | // appVersionName = packageInfo.versionName; |
| | | // } catch (PackageManager.NameNotFoundException e) { |
| | | // LogUtil.e("getAppVersionName", e); |
| | | // } |
| | | return appVersionName; |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | public static long getTotalRAMSize() { |
| | | ActivityManager manager = (ActivityManager) GameApp.I.getSystemService(Context.ACTIVITY_SERVICE); |
| | | ActivityManager manager = (ActivityManager) GameAppProxy.app.getSystemService(Context.ACTIVITY_SERVICE); |
| | | ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo(); |
| | | manager.getMemoryInfo(info); |
| | | return info.totalMem; |
| | | } |
| | | |
| | | public static String getAndroidId() { |
| | | String ANDROID_ID = Settings.System.getString(GameApp.I.getContentResolver(), Settings.System.ANDROID_ID); |
| | | if (ANDROID_ID == null || ANDROID_ID.equals("9774d56d682e549c")) |
| | | return ""; |
| | | return ANDROID_ID; |
| | | // String ANDROID_ID = Settings.System.getString(GameAppProxy.app.getContentResolver(), Settings.System.ANDROID_ID); |
| | | // if (ANDROID_ID == null || ANDROID_ID.equals("9774d56d682e549c")) |
| | | // return ""; |
| | | // return ANDROID_ID; |
| | | return ""; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | public static String getLocalMac() { |
| | | String mac = SPUtils.get().getString(SPUtils.MAC, ""); |
| | | if (!mac.trim().isEmpty()) |
| | | return mac; |
| | | try { |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
| | | String interfaceName = "wlan0"; |
| | | Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); |
| | | NetworkInterface intf = null; |
| | | while (interfaces.hasMoreElements()) { |
| | | intf = interfaces.nextElement(); |
| | | if (!intf.getName().equalsIgnoreCase(interfaceName)) |
| | | continue; |
| | | byte[] addresses = intf.getHardwareAddress(); |
| | | if (mac != null) { |
| | | StringBuilder buf = new StringBuilder(); |
| | | for (byte aMac : addresses) { |
| | | buf.append(String.format("%02X:", aMac)); |
| | | } |
| | | if (buf.length() > 0) { |
| | | buf.deleteCharAt(buf.length() - 1); |
| | | } |
| | | mac = buf.toString(); |
| | | } |
| | | break; |
| | | } |
| | | } else { |
| | | WifiManager wifi = (WifiManager) GameApp.I.getSystemService(Context.WIFI_SERVICE); |
| | | if (wifi != null) { |
| | | WifiInfo wifiInfo = wifi.getConnectionInfo(); |
| | | if (wifiInfo != null) { |
| | | mac = wifiInfo.getMacAddress(); |
| | | } |
| | | } |
| | | } |
| | | } catch (Throwable e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | mac = mac.toUpperCase(Locale.ENGLISH); |
| | | |
| | | if (mac.equals(FAKE_MAC)) |
| | | mac = ""; |
| | | |
| | | SPUtils.get() |
| | | .edit() |
| | | .putString(SPUtils.MAC, mac.trim()) |
| | | .apply(); |
| | | |
| | | return mac; |
| | | return ""; |
| | | // String mac = SPUtils.get().getString(SPUtils.MAC, ""); |
| | | // if (!mac.trim().isEmpty()) |
| | | // return mac; |
| | | // try { |
| | | // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
| | | // String interfaceName = "wlan0"; |
| | | // Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); |
| | | // NetworkInterface intf = null; |
| | | // while (interfaces.hasMoreElements()) { |
| | | // intf = interfaces.nextElement(); |
| | | // if (!intf.getName().equalsIgnoreCase(interfaceName)) |
| | | // continue; |
| | | // byte[] addresses = intf.getHardwareAddress(); |
| | | // if (mac != null) { |
| | | // StringBuilder buf = new StringBuilder(); |
| | | // for (byte aMac : addresses) { |
| | | // buf.append(String.format("%02X:", aMac)); |
| | | // } |
| | | // if (buf.length() > 0) { |
| | | // buf.deleteCharAt(buf.length() - 1); |
| | | // } |
| | | // mac = buf.toString(); |
| | | // } |
| | | // break; |
| | | // } |
| | | // } else { |
| | | // WifiManager wifi = (WifiManager) GameAppProxy.app.getSystemService(Context.WIFI_SERVICE); |
| | | // if (wifi != null) { |
| | | // WifiInfo wifiInfo = wifi.getConnectionInfo(); |
| | | // if (wifiInfo != null) { |
| | | // mac = wifiInfo.getMacAddress(); |
| | | // } |
| | | // } |
| | | // } |
| | | // } catch (Throwable e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // |
| | | // mac = mac.toUpperCase(Locale.ENGLISH); |
| | | // |
| | | // if (mac.equals(FAKE_MAC)) |
| | | // mac = ""; |
| | | // |
| | | // SPUtils.get() |
| | | // .edit() |
| | | // .putString(SPUtils.MAC, mac.trim()) |
| | | // .apply(); |
| | | // |
| | | // return mac; |
| | | } |
| | | |
| | | |