예제 #1
0
        private static void InstallApk(string packageName, string apkPath, string vmName)
        {
            Logger.Info("Installing apk: {0}", (object)apkPath);
            string str = ApkInstall.InstallApk(apkPath, vmName);

            Logger.Info("Apk installer exit result : {0}", (object)str);
            Thread.Sleep(2000);
            if (str.Equals("Success", StringComparison.InvariantCultureIgnoreCase))
            {
                Stats.SendMiscellaneousStatsAsyncForDMM(Stats.DMMEvent.app_install_success.ToString(), str, packageName, apkPath, (string)null, "Android", 0);
                HDAgent.sApkUpgradingList[vmName + packageName] = false;
                HDAgent.sApkDownloadInstallStatusList.Remove(vmName + packageName);
                Logger.Info("Installation successful : " + packageName);
                try
                {
                    System.IO.File.Delete(apkPath);
                }
                catch
                {
                }
            }
            else
            {
                Stats.SendMiscellaneousStatsAsyncForDMM(Stats.DMMEvent.app_install_failed.ToString(), str, packageName, apkPath, (string)null, "Android", 0);
                int num = 24;
                try
                {
                    num = (int)System.Enum.Parse(typeof(ReturnCodes), str);
                }
                catch
                {
                    try
                    {
                        num = (int)System.Enum.Parse(typeof(GuestApkInstallFailCodes), str);
                    }
                    catch
                    {
                        Logger.Error("unable to parse install apk error code: {0}", (object)str);
                    }
                }
                uint errorCode = 0;
                if (num > 0)
                {
                    errorCode = ReturnCodesUInt.INSTALL_FAILED_HOST_BASE_VALUE + (uint)num;
                }
                else if (num < 0)
                {
                    errorCode = ReturnCodesUInt.INSTALL_FAILED_GUEST_BASE_VALUE - (uint)num;
                }
                Logger.Info("Installation failed : " + packageName + ", Error code : " + errorCode.ToString());
                DownloadInstallApk.UpdateInstallStatus(packageName, vmName, errorCode, DownloadInstallStatus.InstallFailed);
                Stats.SendMiscellaneousStatsAsync("ApkInstallFailure", packageName, str, errorCode.ToString(), RegistryManager.Instance.UserGuid, RegistryManager.Instance.Version, "bgp", (string)null, (string)null, "Android", 0);
            }
        }
예제 #2
0
 public static bool CreateHardLinkForFile(string existingFilePath, string newFilePath)
 {
     try
     {
         Logger.Info("Creating hard link from " + existingFilePath + " to " + newFilePath);
         int num = ApkInstall.CreateHardLink(newFilePath, existingFilePath, IntPtr.Zero) ? 1 : 0;
         if (num == 0)
         {
             Logger.Error("Failed to create hard link: " + Marshal.GetLastWin32Error().ToString() + ".." + new Win32Exception()?.ToString());
         }
         else
         {
             Logger.Info("Hard link created successfully");
         }
         return(num != 0);
     }
     catch (Exception ex)
     {
         Logger.Error("Error in creating hard link.." + ex?.ToString());
         return(false);
     }
 }
예제 #3
0
        public static string InstallApk(string apk, string vmName)
        {
            string str1 = "";

            Logger.Info("apk to be installed is " + apk);
            Stats.SendMiscellaneousStatsAsyncForDMM(Stats.DMMEvent.app_install_started.ToString(), apk, (string)null, (string)null, (string)null, "Android", 0);
            try
            {
                int    num1 = RegistryManager.Instance.Guest[vmName].FileSystem;
                string json = (string)null;
                if (num1 == 1)
                {
                    try
                    {
                        string sharedFolder0Name = RegistryManager.Instance.Guest[vmName].SharedFolder0Name;
                        string sharedFolder0Path = RegistryManager.Instance.Guest[vmName].SharedFolder0Path;
                        if (string.IsNullOrEmpty(sharedFolder0Name) || string.IsNullOrEmpty(sharedFolder0Path))
                        {
                            Logger.Error("Name or Path missing in sharedfolder regkey");
                            num1 = 0;
                        }
                        else
                        {
                            str1 = Path.Combine(sharedFolder0Path, "Bst-" + DateTime.Now.Ticks.ToString() + Path.GetExtension(apk));
                            Logger.Info("apk = {0}, newPath = {1}", (object)apk, (object)str1);
                            try
                            {
                                if (!ApkInstall.CreateHardLinkForFile(apk, str1))
                                {
                                    System.IO.File.Copy(apk, str1, true);
                                }
                            }
                            catch (Exception ex)
                            {
                                if (ApkInstall.IsDiskFull(ex))
                                {
                                    Logger.Info("Disk Space is full");
                                    Stats.SendMiscellaneousStatsAsyncForDMM(Stats.DMMEvent.app_install_failed.ToString(), "INSTALL_FAILED_INSUFFICIENT_STORAGE_HOST", apk, (string)null, (string)null, "Android", 0);
                                    return("INSTALL_FAILED_INSUFFICIENT_STORAGE_HOST");
                                }
                                Logger.Error("Unable to copy file" + ex.ToString());
                                num1 = 0;
                                throw new Exception("File_Not_Copied");
                            }
                            System.IO.File.SetAttributes(str1, FileAttributes.Normal);
                            string str2 = "/mnt/sdcard/windows/" + sharedFolder0Name + "/" + Path.GetFileName(str1);
                            Logger.Info("androidPath: " + str2);
                            Dictionary <string, string> data = new Dictionary <string, string>()
                            {
                                {
                                    "path",
                                    str2
                                }
                            };
                            if (!Utils.IsUIProcessAlive(vmName, "bgp"))
                            {
                                Logger.Info("Starting Frontend in hidden mode.");
                                Utils.StartHiddenFrontend(vmName, "bgp");
                            }
                            new Thread((ThreadStart)(() =>
                            {
                                if (!Utils.WaitForFrontendPingResponse(vmName))
                                {
                                    Logger.Info("Frontend not responding to ping response for 50 seconds, aborting installtion with FRONTEND_NOT_STARTING error");
                                    HTTPHandler.sApkInstallResult = "FRONTEND_NOT_STARTING";
                                    Stats.SendMiscellaneousStatsAsyncForDMM(Stats.DMMEvent.app_install_failed.ToString(), "FRONTEND_NOT_STARTING", apk, (string)null, (string)null, "Android", 0);
                                    if (HTTPHandler.sApkInstallThread == null)
                                    {
                                        return;
                                    }
                                    HTTPHandler.sApkInstallThread.Abort();
                                }
                                else
                                {
                                    Logger.Info("Frontend is running gave ping response");
                                    while (HTTPHandler.sApkInstallThread != null)
                                    {
                                        if (Utils.IsUIProcessAlive(vmName, "bgp"))
                                        {
                                            Thread.Sleep(500);
                                        }
                                        else
                                        {
                                            Logger.Info("Frontend Process Stopped, aborting Installation with FRONTEND_NOT_RUNNING error");
                                            Stats.SendMiscellaneousStatsAsyncForDMM(Stats.DMMEvent.app_install_failed.ToString(), "FRONTEND_NOT_RUNNING", apk, (string)null, (string)null, "Android", 0);
                                            HTTPHandler.sApkInstallResult = "FRONTEND_NOT_RUNNING";
                                            HTTPHandler.sApkInstallThread.Abort();
                                            break;
                                        }
                                    }
                                }
                            }))
                            {
                                IsBackground = true
                            }.Start();
                            if ((RegistryManager.Instance.Guest[vmName].ConfigSynced == 0 ? 1 : 0) != 0 && !Utils.WaitForSyncConfig(vmName))
                            {
                                Logger.Info("Config still not sycned");
                                Stats.SendMiscellaneousStatsAsyncForDMM(Stats.DMMEvent.app_install_failed.ToString(), "CONFIG_NOT_SYNCED", apk, (string)null, (string)null, "Android", 0);
                                return("CONFIG_NOT_SYNCED");
                            }
                            int retries = 180;
                            if (Oem.IsOEMDmm)
                            {
                                retries = 1;
                            }
                            if (!Utils.CheckIfGuestReady(vmName, retries))
                            {
                                return(Oem.IsOEMDmm ? "ANDROID_BOOT_FAILURE" : "GUEST_NOT_READY_YET");
                            }
                            try
                            {
                                if (string.Equals(Path.GetExtension(apk), ".xapk", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    Logger.Info("HTTPHandler: Sending /xinstall request to guest");
                                    json = HTTPUtils.SendRequestToGuest("xinstall", data, vmName, 300000, (Dictionary <string, string>)null, false, 1, 0, "bgp");
                                }
                                else
                                {
                                    Logger.Info("HTTPHandler: Sending /install request to guest");
                                    json = HTTPUtils.SendRequestToGuest("install", data, vmName, 300000, (Dictionary <string, string>)null, false, 1, 0, "bgp");
                                }
                            }
                            catch (WebException ex)
                            {
                                Logger.Error("WebException occured while installing apk.");
                                Logger.Error(ex.ToString());
                                return(ex.Status == WebExceptionStatus.Timeout ? "INSTALL_APK_TIMEOUT" : "INSTALL_APK_CONNECTION_TERMINATED");
                            }
                            Logger.Info("Install apk respnse : " + json);
                            int num2 = 20;
                            while (json.Contains("INSTALL_FAILED_INVALID_URI") && num2 > 0)
                            {
                                Logger.Info("Retrying install since INSTALL_FAILED_INVALID_URI..." + num2.ToString());
                                --num2;
                                try
                                {
                                    json = !string.Equals(Path.GetExtension(apk), ".xapk", StringComparison.InvariantCultureIgnoreCase) ? HTTPUtils.SendRequestToGuest("install", data, vmName, 180000, (Dictionary <string, string>)null, false, 1, 0, "bgp") : HTTPUtils.SendRequestToGuest("xinstall", data, vmName, 180000, (Dictionary <string, string>)null, false, 1, 0, "bgp");
                                }
                                catch
                                {
                                }
                                Thread.Sleep(1000);
                            }
                            if (!json.Contains("INSTALL_FAILED_INSUFFICIENT_STORAGE"))
                            {
                                if (!json.Contains("INSTALL_FAILED_INVALID_URI"))
                                {
                                    goto label_36;
                                }
                            }
                            num1 = 0;
                        }
                    }
                    catch (Exception ex1)
                    {
                        Logger.Error(ex1.ToString());
                        if (!ex1.Message.Equals("File_Not_Copied"))
                        {
                            if (System.IO.File.Exists(str1))
                            {
                                Logger.Info("Deleting copied apk from sharedfolder");
                                try
                                {
                                    System.IO.File.Delete(str1);
                                }
                                catch (Exception ex2)
                                {
                                    Logger.Error("Unable to delete file {0}, Error: {1}", (object)str1, (object)ex2.ToString());
                                }
                            }
                        }
                    }
                }
label_36:
                try
                {
                    if (num1 == 0)
                    {
                        Logger.Info("Sending apk");
                        json = !string.Equals(Path.GetExtension(apk), ".xapk", StringComparison.InvariantCultureIgnoreCase) ? ApkInstall.PostFileToGuest("install", apk, vmName) : ApkInstall.PostFileToGuest("xinstall", apk, vmName);
                        if (json == null)
                        {
                            Logger.Error("No response received yet.");
                            return("INSTALL_FAILED_UPLOAD_APK_ERROR");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("Exception when sending install post request");
                    Logger.Error(ex.ToString());
                    return("INSTALL_FAILED_SERVER_ERROR");
                }
                JObject jobject = JObject.Parse(json);
                ApkInstall.sReturnString = jobject["result"].ToString() == "ok" ? "SUCCESS" : jobject["reason"].ToString();
                if (System.IO.File.Exists(str1))
                {
                    try
                    {
                        System.IO.File.Delete(str1);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Unable to delete file {0}, Error: {1}", (object)str1, (object)ex.ToString());
                    }
                }
                return(ApkInstall.sReturnString);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
                return("UNKNOWN_ERROR");
            }
        }
예제 #4
0
        public static void AppInstalled(
            string name,
            string package,
            string activity,
            string img,
            string version,
            string isUpdate,
            string vmName,
            string source,
            string campaignName,
            string clientVersion,
            bool isGl3Required,
            bool isVideoPresent,
            string apkType,
            string versionName)
        {
            Logger.Info("Replacing invalid characters, if any, with whitespace");
            ApkInstall.sAppName                = Regex.Replace(name, "[\\x22\\\\\\/:*?|<>]", " ");
            ApkInstall.sPackageName            = package;
            ApkInstall.sLaunchableActivityName = activity;
            ApkInstall.sAppIcon                = img;
            ApkInstall.sVersion                = version;
            ApkInstall.sGl3Required            = isGl3Required;
            ApkInstall.sVideoPresent           = isVideoPresent;
            ApkInstall.sVersionName            = versionName;
            ApkInstall.sIsGamepadCompatible    = Utils.CheckGamepadCompatible(package);
            ApkInstall.sOriginalJson           = new JsonParser(vmName).GetAppList();
            ApkInstall.AddToJson(vmName);
            Stats.SendAppInstallStats(name, package, version, versionName, "true", isUpdate, source, vmName, campaignName, clientVersion, apkType);
            string str1 = Path.Combine(RegistryStrings.GadgetDir, string.Format("{0}.{1}.png", (object)package, (object)activity));
            string str2 = Path.Combine(RegistryStrings.GadgetDir, string.Format("{0}.png", (object)package));

            if (System.IO.File.Exists(str2))
            {
                if (!System.IO.File.Exists(str1))
                {
                    System.IO.File.Copy(str2, str1, false);
                }
            }
            else if (Oem.Instance.IsDownloadIconFromWeb)
            {
                try
                {
                    Utils.DownloadIcon(package, "", false);
                }
                catch
                {
                }
            }
            if (Oem.Instance.IsOEMWithBGPClient)
            {
                ApkInstall.InformPartner(vmName, package, isUpdate);
            }
            if (Features.IsFeatureEnabled(8192UL))
            {
                ApkInstall.CreateAppShortcut(vmName, isUpdate);
            }
            Logger.Info("InstallApk: Got AppName: {0}", (object)ApkInstall.sAppName);
            string str3    = ApkInstall.sAppName + " ";
            string message = string.Compare(isUpdate, "true", true) != 0 ? str3 + LocaleStrings.GetLocalizedString("STRING_INSTALL_SUCCESS", "") : str3 + LocaleStrings.GetLocalizedString("STRING_UPDATE_SUCCESS", "");

            try
            {
                if (Features.IsFeatureEnabled(2UL))
                {
                    if (Array.IndexOf <string>(ApkInstall.sIgnoreEvents, package) == -1)
                    {
                        SysTray.ShowInfoShort(LocaleStrings.GetLocalizedString("STRING_BLUESTACKS", ""), message, vmName, package, "0");
                    }
                    else
                    {
                        Logger.Debug("Not showing notification for: " + package);
                    }
                }
                else
                {
                    Logger.Info("Not showing install notification...");
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Failed to get ShowInstallerNotification value. err: " + ex.Message);
            }
        }