// Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. using System.Text; using UnityEngine; namespace Google.Play.AppUpdate.Internal { /// /// Internal implementation that wraps Play Core's InstallState which represents the current state of an AppUpdate download. /// internal class AppUpdateState { /// /// The number of bytes downloaded so far. /// public long BytesDownloaded { get; private set; } /// /// The total number of bytes that need to be downloaded. /// public long TotalBytesToDownload { get; private set; } /// /// The status of the associated download session (downloading, downloaded, installed, etc). /// public int Status { get; private set; } /// /// The error code indicating the reason the download session failed. /// public int ErrorCode { get; private set; } /// /// Creates an AppUpdateState with the fields of the underlying AppUpdateInfo Java object, disposing the Java /// object in the process. /// /// /// A java object of class: com.google.android.play.core.appupdate.AppUpdateInfo that contains all the fields of /// the com.google.android.play.core.install.InstallState class except for the InstallErrorCode field. /// public AppUpdateState(AndroidJavaObject javaAppUpdateInfo) { using (javaAppUpdateInfo) { BytesDownloaded = javaAppUpdateInfo.Call("bytesDownloaded"); TotalBytesToDownload = javaAppUpdateInfo.Call("totalBytesToDownload"); Status = javaAppUpdateInfo.Call("installStatus"); } } public override string ToString() { var stateDescription = new StringBuilder(); stateDescription.AppendFormat("status: {0} ", Status); stateDescription.AppendFormat("bytes downloaded: {0} ", BytesDownloaded); stateDescription.AppendFormat("total downloaded: {0}", TotalBytesToDownload); return stateDescription.ToString(); } } }