public int getAndroidSDKVers()
        {
            AndroidJavaClass version = PlatformIntegrationUtil.GetAndroidJavaClass("android.os.Build$VERSION");

            if (version == null)
            {
                Logger.Log("Unable to get Build Version");
                return(0);
            }
            return(PlatformIntegrationUtil.GetStatic <int>(version, "SDK_INT"));
        }
Пример #2
0
        public String GetUniqueID()
        {
            AndroidJavaClass unityPlayer = PlatformIntegrationUtil.GetAndroidJavaClass("com.unity3d.player.UnityPlayer");

            if (unityPlayer == null)
            {
                Logger.Log("Can't get UnityPlayer");
                return(null);
            }

            AndroidJavaObject activity = PlatformIntegrationUtil.GetStatic <AndroidJavaObject>(unityPlayer, "currentActivity");

            if (activity == null)
            {
                Logger.Log("Can't find an activity!");
                return(null);
            }

            AndroidJavaObject context = PlatformIntegrationUtil.Call <AndroidJavaObject>(activity, "getApplicationContext");

            if (context == null)
            {
                Logger.Log("Can't find an app context!");
                return(null);
            }

            AndroidJavaObject contentResolver = PlatformIntegrationUtil.Call <AndroidJavaObject>(context, "getContentResolver");

            if (contentResolver == null)
            {
                Logger.Log("Can't get content resolver from context");
                return(null);
            }

            AndroidJavaClass secureClass = PlatformIntegrationUtil.GetAndroidJavaClass("android.provider.Settings$Secure");

            if (secureClass == null)
            {
                Logger.Log("Can't get secure class");
                return(null);
            }

            AndroidJavaObject androidID = PlatformIntegrationUtil.GetStatic <AndroidJavaObject>(secureClass, "ANDROID_ID");

            if (androidID == null)
            {
                Logger.Log("Cant get Android ID static string");
                return(null);
            }

            object[] parameters = new object[2];
            parameters[0] = contentResolver;
            parameters[1] = androidID;

            string aid = PlatformIntegrationUtil.CallStatic <string>(secureClass, "getString", parameters);

            if (aid != null)
            {
                string hashedAdId = HexUtil.HexStringSha512(aid);
                return(hashedAdId);
            }
            return(aid);
        }
    // Placeholder, if available, just use the Unity version
#if UNITY_ANDROID
    public Dictionary<string, string> GetDeviceInfo()
    {
      CarrierInfoClass carrierInfo = new CarrierInfoClass();
      Dictionary<string, string> map = new Dictionary<string, string>();
      int sdk_int = carrierInfo.getAndroidSDKVers();
      map["Build.VERSION.SDK_INT"] = sdk_int.ToString();
      if (UnityEngine.XR.XRSettings.loadedDeviceName.Contains("oculus"))
      {
          return map;
      }
      AndroidJavaObject telephonyManager = carrierInfo.GetTelephonyManager();
      if (telephonyManager == null)
      {
          Logger.Log("No TelephonyManager!");
          return map;
      }
      const string readPhoneStatePermissionString = "android.permission.READ_PHONE_STATE";
      try
      {
        if (Permission.HasUserAuthorizedPermission(readPhoneStatePermissionString))
        {
          string ver = PlatformIntegrationUtil.Call<string>(telephonyManager, "getDeviceSoftwareVersion");
          if (ver != null)
          {
            map["DeviceSoftwareVersion"] = ver.ToString();
          }
        }
      }
      catch (Exception e)
      {
        Logger.LogWarning("Exception retrieving properties: " + e.GetBaseException() + ", " + e.Message);
      }

      try
      {
        if (Permission.HasUserAuthorizedPermission(readPhoneStatePermissionString))
        {
          int nType = PlatformIntegrationUtil.Call<int>(telephonyManager, "getDataNetworkType");
          NetworkDataType datatype = (NetworkDataType)nType;
          map["DataNetworkType"] = datatype.ToString();
        }
      }
      catch (Exception e)
      {
        Logger.LogWarning("Exception retrieving properties: " + e.GetBaseException() + ", " + e.Message);
      }

      AndroidJavaClass versionCodesClass = new AndroidJavaClass("android.os.Build$VERSION_CODES");
      int versionCode = PlatformIntegrationUtil.GetStatic<int>(versionCodesClass, "Q");
      if (sdk_int > versionCode)
      {
        string mc = PlatformIntegrationUtil.Call<string>(telephonyManager, "getManufacturerCode");
        if (mc != null)
        {
          map["ManufacturerCode"] = mc;
        }
      }

      string niso = PlatformIntegrationUtil.Call<string>(telephonyManager, "getNetworkCountryIso");
      if (niso != null)
      {
        map["NetworkCountryIso"] = niso;
      }

      string siso = PlatformIntegrationUtil.Call<string>(telephonyManager, "getSimCountryIso");
      if (siso != null)
      {
        map["SimCountryCodeIso"] = siso;
      }

      int phoneType = PlatformIntegrationUtil.Call<int>(telephonyManager, "getPhoneType");
      map["PhoneType"] = phoneType.ToString();

      // Default one.
      string simOperatorName = PlatformIntegrationUtil.Call<string>(telephonyManager, "getSimOperatorName");
      if (simOperatorName != null)
      {
        map["SimOperatorName"] = simOperatorName;
      }

      // Default one.
      string networkOperator = PlatformIntegrationUtil.Call<string>(telephonyManager, "getNetworkOperatorName");
      if (networkOperator != null)
      {
        map["NetworkOperatorName"] = networkOperator;
      }

      return map;
    }
        public AndroidJavaObject GetTelephonyManager()
        {
            AndroidJavaClass unityPlayer = PlatformIntegrationUtil.GetAndroidJavaClass("com.unity3d.player.UnityPlayer");

            if (unityPlayer == null)
            {
                Logger.Log("Unable to get UnityPlayer");
                return(null);
            }
            AndroidJavaObject activity = PlatformIntegrationUtil.GetStatic <AndroidJavaObject>(unityPlayer, "currentActivity");

            if (activity == null)
            {
                Logger.Log("Can't find an activity!");
                return(null);
            }

            AndroidJavaObject context = PlatformIntegrationUtil.Call <AndroidJavaObject>(activity, "getApplicationContext");

            if (context == null)
            {
                Logger.Log("Can't find an app context!");
                return(null);
            }

            // Context.TELEPHONY_SERVICE:
            string CONTEXT_TELEPHONY_SERVICE = context.GetStatic <string>("TELEPHONY_SERVICE");

            if (CONTEXT_TELEPHONY_SERVICE == null)
            {
                Logger.Log("Can't get Context Telephony Service");
                return(null);
            }

            AndroidJavaObject telManager = PlatformIntegrationUtil.Call <AndroidJavaObject>(context, "getSystemService", new object[] { CONTEXT_TELEPHONY_SERVICE });

            sdkVersion = getAndroidSDKVers();

            if (sdkVersion < 24)
            {
                return(telManager);
            }

            // Call SubscriptionManager to get a specific telManager:
            AndroidJavaClass subscriptionManagerCls = PlatformIntegrationUtil.GetAndroidJavaClass("android.telephony.SubscriptionManager");

            if (subscriptionManagerCls == null)
            {
                Logger.Log("Can't get Subscription Manager Class.");
                return(null);
            }
            int subId        = PlatformIntegrationUtil.CallStatic <int>(subscriptionManagerCls, "getDefaultDataSubscriptionId");
            int invalidSubId = PlatformIntegrationUtil.GetStatic <int>(subscriptionManagerCls, "INVALID_SUBSCRIPTION_ID");

            if (subId == invalidSubId)
            {
                Logger.Log("The Subscription ID is invalid: " + subId);
                return(null);
            }
            object[] idParam = new object[1] {
                subId
            };
            telManager = PlatformIntegrationUtil.Call <AndroidJavaObject>(telManager, "createForSubscriptionId", idParam);

            return(telManager);
        }