Beispiel #1
0
        private string GetVersionDisplay()
        {
            PackageInfo package         = PackageManager.GetPackageInfo(PackageName, 0);
            long        longVersionCode = PackageInfoCompat.GetLongVersionCode(package);

            return($"v{package.VersionName}, ({longVersionCode})");
        }
Beispiel #2
0
        public static string GetObbFilename(Context context)
        {
            Regex       regex          = new Regex(@"^main\.([0-9]+)\." + context.PackageName + @"\.obb$", RegexOptions.IgnoreCase);
            PackageInfo packageInfo    = context.PackageManager?.GetPackageInfo(context.PackageName ?? string.Empty, 0);
            long        packageVersion = -1;

            if (packageInfo != null)
            {
                packageVersion = PackageInfoCompat.GetLongVersionCode(packageInfo);
            }
            string obbFile = null;

            Java.IO.File[] obbDirs;
            // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
            {
                obbDirs = context.GetObbDirs();
            }
            else
            {
                obbDirs = new [] { context.ObbDir };
            }
            foreach (Java.IO.File dir in obbDirs)
            {
                try
                {
                    if (dir != null && Directory.Exists(dir.AbsolutePath))
                    {
                        string[] files = Directory.GetFiles(dir.AbsolutePath);
                        foreach (string file in files)
                        {
                            MatchCollection matchesFile = regex.Matches(Path.GetFileName(file));
                            if ((matchesFile.Count == 1) && (matchesFile[0].Groups.Count == 2))
                            {
                                string fileVersion = matchesFile[0].Groups[1].Value;
                                if ((packageVersion < 0) || (Int64.TryParse(fileVersion, out long version) && version <= packageVersion))
                                {
                                    FileInfo fileInfo = new FileInfo(file);
                                    if (fileInfo.Exists && fileInfo.Length == ObbFileSize)
                                    {
                                        obbFile = file;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    // ignored
                }
            }
            return(obbFile);
        }
Beispiel #3
0
        public static bool PlayServicesVersionNumberIsLargeEnough(PackageManager packageManager)
        {
            long minimumPlayServicesVersionNumber = 201300000; //GPS version 20.13.0
            long playServicesVersionNumber        = PackageInfoCompat.
                                                    GetLongVersionCode(CrossCurrentActivity.Current.AppContext.PackageManager.GetPackageInfo(GoogleApiAvailability.GooglePlayServicesPackage, 0));
            bool isLargeEnough = playServicesVersionNumber >= minimumPlayServicesVersionNumber;

            if (!isLargeEnough)
            {
                LogUtils.LogMessage(Enums.LogSeverity.INFO, "PlayServicesVersionUtils: User is prevented from using the app because of too low GPS version");
            }
            return(isLargeEnough);
        }
Beispiel #4
0
        public override void OnCreate()
        {
            Log.Debug(LOGCAT_TAG, $"AndroidApplication:OnCreate SDK == {Android.OS.Build.VERSION.SdkInt}, {(int)Android.OS.Build.VERSION.SdkInt}");
            Log.Debug(LOGCAT_TAG, $"AndroidApplication:OnCreate PackageName == {this.PackageName}");
            SetupExceptionHandler();
            PackageInfo package         = PackageManager.GetPackageInfo(PackageName, 0);
            long        longVersionCode = PackageInfoCompat.GetLongVersionCode(package);

#if DEBUG
            var config = "(Debug)";
#else
            var config = "(Release)";
#endif
            DisplayVersion = $"v{package.VersionName}, ({longVersionCode}), {config}";
            DisplayPackage = $"{PackageName}";
            Log.Debug(LOGCAT_TAG, $"AndroidApplication:OnCreate Version == {DisplayVersion}");

            base.OnCreate();
            var dirs = Context.GetExternalFilesDirs(null);
            if (dirs != null && dirs[0] != null)
            {
                // use our external folder - dependes on package name
                Log.Debug(LOGCAT_TAG, $"AndroidApplication:OnCreate Logs == {dirs[0].AbsolutePath}");
                LoggerFactory = new NLoggerLoggerFactory(dirs[0].AbsolutePath);
            }
            else
            {
                // hard code and hope for the best
                LoggerFactory = new NLoggerLoggerFactory($"/sdcard/Android/data/{this.PackageName}/files/");
            }
            Logger = LoggerFactory.Logger;
            Logger.Debug(() => $"AndroidApplication:Logging init");

            // initialise the IoC container
            IocContainer = InitializeIocContainer();
            AddExtrasToIocContainer(IocContainer);

            Logger.Debug(() => $"AndroidApplication:IoC Init, {DisplayVersion}, {Android.OS.Build.VERSION.SdkInt}, {(int)Android.OS.Build.VERSION.SdkInt}, {this.PackageName}");
            // display the core components version
            List <string> envirnment = WindowsEnvironmentInformationProvider.GetEnvironmentRuntimeDisplayInformation();
            foreach (string line in envirnment)
            {
                Logger.Debug(() => $"AndroidApplication:{line}");
            }

            Analytics = IocContainer.Resolve <IAnalyticsEngine>();
            Analytics?.LifecycleLaunchEvent();
        }
Beispiel #5
0
        public string GetBackGroudServiceVersion()
        {
            string version = "";

            try
            {
                version = PackageInfoCompat.GetLongVersionCode(CrossCurrentActivity.Current.AppContext.PackageManager.GetPackageInfo(GoogleApiAvailability.GooglePlayServicesPackage, 0)).ToString();
            }
            catch (Exception e)
            {
                //Do not log this. It will create a deadlock.
                System.Diagnostics.Debug.Print("Couldn't get versioncode");
                System.Diagnostics.Debug.Print(e.ToString());
            }
            return(version);
        }
Beispiel #6
0
        static string PlatformGetBuild()
        {
            var pm          = Platform.AppContext.PackageManager;
            var packageName = Platform.AppContext.PackageName;

            using (var info = pm.GetPackageInfo(packageName, PackageInfoFlags.MetaData))
            {
#if __ANDROID_28__
                return(PackageInfoCompat.GetLongVersionCode(info).ToString(CultureInfo.InvariantCulture));
#else
#pragma warning disable CS0618 // Type or member is obsolete
                return(info.VersionCode.ToString(CultureInfo.InvariantCulture));

#pragma warning restore CS0618 // Type or member is obsolete
#endif
            }
        }
Beispiel #7
0
        public long GetAppVersionCode()
        {
            #if DEBUG
            System.Diagnostics.Debug.Assert(_currentPackage != null);
            #else
            if (_currentPackage == null)
            {
                return(-1);
            }
            #endif

            var longVersionCode = PackageInfoCompat.GetLongVersionCode(_currentPackage);

            #if DEBUG
            System.Diagnostics.Debug.Assert(longVersionCode != -1);

            return(-1);
            #else
            return(longVersionCode);
            #endif
        }
Beispiel #8
0
        private void StartDownload()
        {
            if (!_storageAccessGranted)
            {
                return;
            }

            if (!_downloadStarted)
            {
                _downloadStarted = true;
                // Before we do anything, are the files we expect already here and
                // delivered (presumably by Market)
                // For free titles, this is probably worth doing. (so no Market
                // request is necessary)
                bool delivered = AreExpansionFilesDelivered();

                if (delivered)
                {
                    try
                    {
                        Intent intent = new Intent(this, typeof(ActivityMain));
                        intent.SetFlags(ActivityFlags.SingleTop | ActivityFlags.NewTask | ActivityFlags.ClearTop);
                        StartActivity(intent);
                        Finish();
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                    return;
                }

                if (!IsFromGooglePlay(this))
                {
                    PackageInfo packageInfo    = PackageManager?.GetPackageInfo(PackageName ?? string.Empty, 0);
                    long        packageVersion = 0;
                    if (packageInfo != null)
                    {
                        packageVersion = PackageInfoCompat.GetLongVersionCode(packageInfo);
                    }
                    string obbFileName = string.Format(CultureInfo.InvariantCulture, "main.{0}.{1}.obb", packageVersion, PackageName);

                    Java.IO.File[] obbDirs;
                    // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                    if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
                    {
                        obbDirs = GetObbDirs();
                    }
                    else
                    {
                        obbDirs = new[] { ObbDir };
                    }

                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    if (obbDirs != null)
                    {
                        foreach (Java.IO.File dir in obbDirs)
                        {
                            if (dir != null && !string.IsNullOrEmpty(dir.AbsolutePath))
                            {
                                if (sb.Length > 0)
                                {
                                    sb.AppendLine();
                                }
                                sb.Append(@"'");
                                sb.Append(dir.AbsolutePath);
                                sb.Append(@"'");
                            }
                        }
                    }

                    string obbDirsName = sb.ToString();
                    if (string.IsNullOrEmpty(obbDirsName))
                    {
                        obbDirsName = "-";
                    }

                    string      message     = string.Format(CultureInfo.InvariantCulture, GetString(Resource.String.exp_down_obb_missing), obbFileName, obbDirsName);
                    AlertDialog alertDialog = new AlertDialog.Builder(this)
                                              .SetMessage(message)
                                              .SetTitle(Resource.String.alert_title_error)
                                              .SetNeutralButton(Resource.String.button_ok, (s, e) => { })
                                              .Show();
                    alertDialog.DismissEvent += (sender, args) =>
                    {
                        if (_actvityDestroyed)
                        {
                            return;
                        }
                        Finish();
                    };
                    return;
                }

                if (!GetExpansionFiles())
                {
                    InitializeDownloadUi();
                }

                if (_activityActive)
                {
                    _downloaderServiceConnection?.Connect(this);
                }
            }
        }