/// <summary> /// The get expansion files. /// </summary> /// <returns> /// The get expansion files. /// </returns> private bool GetExpansionFiles() { bool result = false; try { // Build the intent that launches this activity. Intent launchIntent = this.Intent; var intent = new Intent(this, typeof(SampleDownloaderActivity)); intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop); intent.SetAction(launchIntent.Action); if (launchIntent.Categories != null) { foreach (string category in launchIntent.Categories) { intent.AddCategory(category); } } // Build PendingIntent used to open this activity when user // taps the notification. PendingIntent pendingIntent = PendingIntent.GetActivity( this, 0, intent, PendingIntentFlags.UpdateCurrent); // Request to start the download DownloadServiceRequirement startResult = DownloaderService.StartDownloadServiceIfRequired( this, pendingIntent, typeof(SampleDownloaderService)); // The DownloaderService has started downloading the files, // show progress otherwise, the download is not needed so we // fall through to starting the actual app. if (startResult != DownloadServiceRequirement.NoDownloadRequired) { this.InitializeDownloadUi(); result = true; } } catch (PackageManager.NameNotFoundException e) { Debug.WriteLine("Cannot find own package! MAYDAY!"); e.PrintStackTrace(); } return(result); }
private bool GetExpansionFiles() { bool result = false; // Build the intent that launches this activity. Intent launchIntent = this.Intent; var intent = new Intent(this, typeof(SuperSimpleActivity)); intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop); intent.SetAction(launchIntent.Action); if (launchIntent.Categories != null) { foreach (string category in launchIntent.Categories) { intent.AddCategory(category); } } // Build PendingIntent used to open this activity when user // taps the notification. PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent); // Request to start the download DownloadServiceRequirement startResult = DownloaderService.StartDownloadServiceIfRequired(this, pendingIntent, typeof(SampleDownloaderService)); // The DownloaderService has started downloading the files, // show progress otherwise, the download is not needed so we // fall through to starting the actual app. if (startResult != DownloadServiceRequirement.NoDownloadRequired) { this.downloaderServiceConnection = ClientMarshaller.CreateStub(this, typeof(SampleDownloaderService)); result = true; } return(result); }
private bool GetExpansionFiles() { bool result = false; try { Intent launchIntent = Intent; var intent = new Intent(this, typeof(LibraryDownloaderActivity)); intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop); intent.SetAction(launchIntent.Action); if (launchIntent.Categories != null) { foreach (string category in launchIntent.Categories) { intent.AddCategory(category); } } PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent); DownloadServiceRequirement startResult = DownloaderService.StartDownloadServiceIfRequired(this, pendingIntent, typeof(LibraryDownloaderService)); if (startResult != DownloadServiceRequirement.NoDownloadRequired) { InitializeDownloadUI(); result = true; } } catch (PackageManager.NameNotFoundException e) { Console.WriteLine("Cannot find own package! MAYDAY!"); e.PrintStackTrace(); } return(result); }
/// <summary> /// The allow. /// </summary> /// <param name="reason"> /// The reason. /// </param> /// <exception cref="Java.Lang.RuntimeException"> /// Error with LVL checking and database integrity /// </exception> /// <exception cref="Java.Lang.RuntimeException"> /// Error with getting information from package name /// </exception> public void Allow(PolicyServerResponse reason) { try { int count = this.policy.GetExpansionFilesCount(); if (count == 0) { Debug.WriteLine("No expansion packs."); } ExpansionDownloadStatus status = 0; for (int index = 0; index < count; index++) { var type = (ApkExpansionPolicy.ExpansionFileType)index; ApkExpansionPolicy.ExpansionFile expansionFile = this.policy.GetExpansionFile(type); string currentFileName = expansionFile.FileName; if (currentFileName != null) { var di = new DownloadInfo { ExpansionFileType = type, FileName = currentFileName, }; if (this.Context.HandleFileUpdated(currentFileName, expansionFile.FileSize)) { status = ExpansionDownloadStatus.Unknown; di.ResetDownload(); di.Uri = expansionFile.Url; di.TotalBytes = expansionFile.FileSize; di.Status = status; DownloadsDatabase.UpdateDownload(di); } else { // we need to read the download information from the database DownloadInfo dbdi = DownloadsDatabase.GetDownloadInfo(di.FileName); if (dbdi == null) { // the file exists already and is the correct size // was delivered by Market or through another mechanism Debug.WriteLine(string.Format("file {0} found. Not downloading.", di.FileName)); di.Status = ExpansionDownloadStatus.Success; di.TotalBytes = expansionFile.FileSize; di.CurrentBytes = expansionFile.FileSize; di.Uri = expansionFile.Url; DownloadsDatabase.UpdateDownload(di); } else if (dbdi.Status != ExpansionDownloadStatus.Success) { // we just update the URL dbdi.Uri = expansionFile.Url; DownloadsDatabase.UpdateDownload(dbdi); status = ExpansionDownloadStatus.Unknown; } } } } // first: do we need to do an LVL update? // we begin by getting our APK version from the package manager try { PackageInfo pi = this.Context.PackageManager.GetPackageInfo(this.Context.PackageName, 0); DownloadsDatabase.UpdateMetadata(pi.VersionCode, status); DownloadServiceRequirement required = StartDownloadServiceIfRequired( this.Context, this.Context.pPendingIntent, this.Context.GetType()); switch (required) { case DownloadServiceRequirement.NoDownloadRequired: this.Context.downloadNotification.OnDownloadStateChanged(DownloaderState.Completed); break; case DownloadServiceRequirement.LvlCheckRequired: // DANGER WILL ROBINSON! Debug.WriteLine("In LVL checking loop!"); this.Context.downloadNotification.OnDownloadStateChanged( DownloaderState.FailedUnlicensed); throw new RuntimeException("Error with LVL checking and database integrity"); case DownloadServiceRequirement.DownloadRequired: // do nothing: the download will notify the application when things are done break; } } catch (PackageManager.NameNotFoundException e1) { e1.PrintStackTrace(); throw new RuntimeException("Error with getting information from package name"); } catch (Exception ex) { Debug.WriteLine("LVL Update Exception: " + ex.Message); throw; } } catch (Exception ex) { Debug.WriteLine("Allow Exception: " + ex.Message); throw; } finally { this.Context.IsServiceRunning = false; } }