Пример #1
0
        private static void StartLogCollection(int errorCode, string errorReason, string apkPath)
        {
            Logger.Info("starting the logging of apk installation failure");
            Process process = new Process();

            process.StartInfo.FileName = Path.Combine(RegistryStrings.InstallDir, "HD-LogCollector.exe");
            string apkNameFromPath = HDApkInstaller.GetApkNameFromPath(apkPath);
            string str             = "-apk " + errorCode.ToString() + " " + HDApkInstaller.AddQuotes(errorReason) + " " + HDApkInstaller.AddQuotes(apkNameFromPath);

            Logger.Info("The arguments being passed to log collector is :{0}", (object)str);
            process.StartInfo.Arguments = str;
            process.Start();
        }
Пример #2
0
 private static void InitExceptionHandlers()
 {
     Application.ThreadException += (ThreadExceptionEventHandler)((obj, evt) =>
     {
         HDApkInstaller.StartLogCollection(-1, "Unhandled Exception:", "");
         Logger.Error("HDApkInstaller: Unhandled Exception:");
         Logger.Error(evt.Exception.ToString());
         Environment.Exit(-1);
     });
     Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
     AppDomain.CurrentDomain.UnhandledException += (UnhandledExceptionEventHandler)((obj, evt) =>
     {
         HDApkInstaller.StartLogCollection(-1, "Unhandled Exception:", "");
         Logger.Error("HDApkInstaller: Unhandled Exception:");
         Logger.Error(evt.ExceptionObject.ToString());
         Environment.Exit(-1);
     });
 }
Пример #3
0
 private static void HandleAlreadyRunning()
 {
     if (!ProcessUtils.CheckAlreadyRunningAndTakeLock(BlueStacks.Common.Strings.GetHDApkInstallerLockName(BlueStacks.Common.Strings.CurrentDefaultVmName), out HDApkInstaller.s_HDApkInstallerLock))
     {
         return;
     }
     Logger.Info("ApkInstaller already running");
     if (Oem.Instance.IsMessageBoxToBeDisplayed)
     {
         string         stacksApkHandlerTitle = Oem.Instance.BlueStacksApkHandlerTitle;
         HDApkInstaller hdApkInstaller        = new HDApkInstaller((string)null, "");
         hdApkInstaller.Show();
         int num = (int)MessageBox.Show((IWin32Window)hdApkInstaller, LocaleStrings.GetLocalizedString("STRING_APKINSTALLER_ALREADY_RUNNING", ""), stacksApkHandlerTitle, MessageBoxButtons.OK, MessageBoxIcon.Hand);
         hdApkInstaller.Close();
     }
     Logger.Info("HD-ApkHandler already running");
     if (Features.IsFeatureEnabled(8589934592UL))
     {
         HDApkInstaller.StartLogCollection(2, "PROCESS_ALREADY_RUNNING", "");
     }
     Environment.Exit(2);
 }
Пример #4
0
        public static void Main(string[] args)
        {
            Logger.InitUserLog();
            string runningProcName;

            if (ProcessUtils.IsAnyInstallerProcesRunning(out runningProcName) && !string.IsNullOrEmpty(runningProcName))
            {
                Logger.Info(runningProcName + " process is running. Exiting BlueStacks Apk Handler");
                Environment.Exit(-1);
            }
            LocaleStrings.InitLocalization((string)null, "Android", false);
            HDApkInstaller.InitExceptionHandlers();
            args = Utils.AddVmNameInArgsIfNotPresent(args);
            HDApkInstaller.Opt opt = new HDApkInstaller.Opt();
            opt.Parse(args);
            HDApkInstaller.s_IsSilent = opt.s;
            string location = Assembly.GetEntryAssembly().Location;

            Logger.Info("the exe path is " + location);
            Directory.GetParent(location).ToString();
            BlueStacks.Common.Strings.CurrentDefaultVmName = opt.vmname;
            Logger.Info("the installvm is {0}", (object)BlueStacks.Common.Strings.CurrentDefaultVmName);
            HDApkInstaller.HandleAlreadyRunning();
            Logger.Info("IsAdministrator: {0}", (object)SystemUtils.IsAdministrator());
            Logger.Debug("pkg name = " + opt.p);
            Logger.Debug("app name = " + opt.name);
            Logger.Debug("silentmode = " + opt.s.ToString());
            Logger.Debug("apk = " + opt.apk);
            Logger.Debug("uninstallmode = " + opt.u.ToString());
            Logger.Debug("vm name =" + BlueStacks.Common.Strings.CurrentDefaultVmName);
            HDApkInstaller.sApkHandlerLaunchTime = DateTime.Now;
            Application.EnableVisualStyles();
            ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(HDApkInstaller.ValidateRemoteCertificate);
            HDApkInstaller.s_AppName    = opt.name;
            HDApkInstaller.s_AppPackage = opt.p;
            HDApkInstaller.s_ApkPath    = opt.apk;
            if (!string.IsNullOrEmpty(HDApkInstaller.s_ApkPath) && !Path.IsPathRooted(HDApkInstaller.s_ApkPath))
            {
                HDApkInstaller.s_ApkPath = Path.Combine(Directory.GetCurrentDirectory(), HDApkInstaller.s_ApkPath);
            }
            if (!((IEnumerable <string>)RegistryManager.Instance.VmList).Contains <string>(BlueStacks.Common.Strings.CurrentDefaultVmName))
            {
                Logger.Info("VM: " + BlueStacks.Common.Strings.CurrentDefaultVmName + " does not exist");
                Environment.Exit(-8);
            }
            if (!opt.u)
            {
                Logger.Debug("in Install mode");
                if (args.Length >= 1 && HDApkInstaller.s_ApkPath.Equals(""))
                {
                    Logger.Debug("ApkHandler called with older types of arguments");
                    HDApkInstaller.s_ApkPath = args[0];
                    if (!string.IsNullOrEmpty(HDApkInstaller.s_ApkPath) && !Path.IsPathRooted(HDApkInstaller.s_ApkPath))
                    {
                        HDApkInstaller.s_ApkPath = Path.Combine(Directory.GetCurrentDirectory(), HDApkInstaller.s_ApkPath);
                    }
                    if (!opt.s && args.Length == 2)
                    {
                        HDApkInstaller.s_IsSilent = args[1].Equals("silent");
                    }
                }
                if (!System.IO.File.Exists(HDApkInstaller.s_ApkPath))
                {
                    Logger.Info("Exiting with exit code {0}", (object)15);
                    if (Features.IsFeatureEnabled(8589934592UL))
                    {
                        HDApkInstaller.StartLogCollection(15, "File not found", HDApkInstaller.GetApkNameFromPath(HDApkInstaller.s_ApkPath));
                    }
                    Environment.Exit(15);
                }
                HDApkInstaller hdApkInstaller = new HDApkInstaller(HDApkInstaller.s_ApkPath, BlueStacks.Common.Strings.CurrentDefaultVmName);
                if (HDApkInstaller.s_IsSilent)
                {
                    return;
                }
                Application.Run((Form)hdApkInstaller);
            }
            else
            {
                try
                {
                    HDApkInstaller.s_AgentPort = RegistryManager.Instance.AgentServerPort;
                    JsonParser jsonParser = new JsonParser(BlueStacks.Common.Strings.CurrentDefaultVmName);
                    if (HDApkInstaller.s_AppPackage != "")
                    {
                        jsonParser.GetAppInfoFromPackageName(HDApkInstaller.s_AppPackage, out HDApkInstaller.s_AppName, out HDApkInstaller.s_AppIcon, out HDApkInstaller.unUsed, out HDApkInstaller.unUsed);
                    }
                    else if (HDApkInstaller.s_AppName != "")
                    {
                        jsonParser.GetAppInfoFromAppName(HDApkInstaller.s_AppName, out HDApkInstaller.s_AppPackage, out HDApkInstaller.s_AppIcon, out HDApkInstaller.unUsed);
                        HDApkInstaller.CleanUpUninstallEntry();
                    }
                    if (string.IsNullOrEmpty(HDApkInstaller.s_AppPackage))
                    {
                        Logger.Error("PackageName can not be null for uninstalling an app");
                    }
                    else
                    {
                        int exitCode = 0;
                        if (jsonParser.IsPackageNameSystemApp(HDApkInstaller.s_AppPackage))
                        {
                            int num = (int)MessageBox.Show("Uninstalling a pre-bundled app is not supported.", string.Format("{0} Error", (object)BlueStacks.Common.Strings.ProductDisplayName), MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        }
                        else
                        {
                            HDApkInstaller.data.Clear();
                            HDApkInstaller.data.Add("package", HDApkInstaller.s_AppPackage);
                            HDApkInstaller.data.Add("name", HDApkInstaller.s_AppName);
                            exitCode = !(JArray.Parse(HTTPUtils.SendRequestToAgent("uninstall", HDApkInstaller.data, BlueStacks.Common.Strings.CurrentDefaultVmName, 0, (Dictionary <string, string>)null, false, 10, 500, "bgp", true))[0] as JObject)["success"].ToObject <bool>() ? 1 : 0;
                        }
                        Environment.Exit(exitCode);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("Got Exception");
                    Logger.Error(ex.ToString());
                    HDApkInstaller.CleanUpUninstallEntry();
                }
            }
        }
Пример #5
0
        private void InstallApk(object apk, string vmName)
        {
            string apkPath = (string)apk;

            HDApkInstaller.s_InstallDir = RegistryStrings.InstallDir;
            Logger.Info("HDApkInstaller: Installing {0}", (object)apkPath);
            Dictionary <string, string> data = new Dictionary <string, string>();

            data.Add("path", apkPath);
            Dictionary <string, string> headers = new Dictionary <string, string>();

            if (!vmName.Equals("Android"))
            {
                Logger.Info("the vmname is not Android");
                headers.Add("vmid", vmName.Split('_')[1]);
            }
            string json = "";

            try
            {
                if (!ProcessUtils.IsLockInUse("Global\\BlueStacks_HDAgent_Lockbgp"))
                {
                    Process process = new Process();
                    process.StartInfo.UseShellExecute = false;
                    process.StartInfo.CreateNoWindow  = true;
                    process.StartInfo.FileName        = Path.Combine(HDApkInstaller.s_InstallDir, "HD-Agent.exe");
                    Logger.Info("Utils: Starting Agent");
                    process.Start();
                    if (!Utils.WaitForAgentPingResponse(vmName, "bgp"))
                    {
                        Logger.Info("Exiting with exit code {0}", (object)11);
                        if (Features.IsFeatureEnabled(8589934592UL))
                        {
                            HDApkInstaller.StartLogCollection(11, "Agent or agent-server not running", apkPath);
                        }
                        Environment.Exit(11);
                    }
                }
                json = HTTPUtils.SendRequestToAgent("install", data, vmName, 600000, headers, false, 1, 0, "bgp", true);
            }
            catch (WebException ex)
            {
                this.ReleaseApkInstallThread(vmName);
                Logger.Error("WebException in install request");
                Logger.Error(ex.ToString());
                Logger.Error("WebException Response", (object)ex.Response);
                Logger.Info("Exiting with exit code {0}", (object)9);
                if (Features.IsFeatureEnabled(8589934592UL))
                {
                    HDApkInstaller.StartLogCollection(9, string.Format("status = {0}, error = {1}", (object)ex.Status, (object)ex.Message), apkPath);
                }
                Environment.Exit(9);
            }
            catch (Exception ex)
            {
                this.ReleaseApkInstallThread(vmName);
                Logger.Error("Exception in install request");
                Logger.Error(ex.ToString());
                Logger.Info("Exiting with exit code {0}", (object)8);
                if (Features.IsFeatureEnabled(8589934592UL))
                {
                    HDApkInstaller.StartLogCollection(8, ex.Message, apkPath);
                }
                Environment.Exit(8);
            }
            string errorReason = string.Empty;
            int    num1        = 0;

            try
            {
                JObject jobject = JObject.Parse(JArray.Parse(json)[0].ToString());
                errorReason = jobject["reason"].ToString().Trim().ToUpper();
                num1        = jobject["errorCode"].ToObject <int>();
            }
            catch
            {
                Logger.Error("HDApkInstaller: Failed to recognize Installer Codes : " + errorReason);
                if (Features.IsFeatureEnabled(8589934592UL))
                {
                    HDApkInstaller.StartLogCollection(5, errorReason, apkPath);
                }
                Logger.Info("Exiting with exit code {0}", (object)5);
                Environment.Exit(5);
            }
            if (num1 == 18)
            {
                Logger.Error("HDApkInstaller: Installation failed, disk space insufficient in host");
                Logger.Info("Exiting with exit code {0}", (object)18);
                Environment.Exit(num1);
            }
            if (num1 == 0)
            {
                Logger.Info("HDApkInstaller: Installation Successful");
                string str = "Apk " + LocaleStrings.GetLocalizedString("STRING_INSTALL_SUCCESS", "");
                Logger.Info("HDApkInstaller: Exit with code 0");
                Environment.Exit(0);
            }
            else
            {
                Logger.Info("HDApkInstaller: Installation Failed");
                Logger.Info("HDApkInstaller: Got Error: {0}", (object)errorReason);
                if (!HDApkInstaller.s_IsSilent)
                {
                    string empty = string.Empty;
                    int    num2  = (int)MessageBox.Show(num1 != 7 ? "Apk " + LocaleStrings.GetLocalizedString("STRING_INSTALL_FAIL", "") + ": " + errorReason : "Apk " + LocaleStrings.GetLocalizedString("STRING_INSTALL_FAIL", "") + ": " + LocaleStrings.GetLocalizedString("STRING_APKINSTALLER_ALREADY_RUNNING", ""), this.Text, MessageBoxButtons.OK, MessageBoxIcon.None);
                }
                if (Features.IsFeatureEnabled(8589934592UL))
                {
                    HDApkInstaller.StartLogCollection(num1, errorReason, apkPath);
                    if (num1 == 10)
                    {
                        int exitCode = -1;
                        try
                        {
                            Utils.AddMessagingSupport(out HDApkInstaller.sOemWindowMapper);
                            Utils.NotifyBootFailureToParentWindow(HDApkInstaller.sOemWindowMapper[Oem.Instance.OEM][0], HDApkInstaller.sOemWindowMapper[Oem.Instance.OEM][1], exitCode, vmName);
                        }
                        catch (Exception ex)
                        {
                            Logger.Error("caught exception in checking reason for android boot failure ex : {0}", (object)ex.ToString());
                        }
                    }
                }
                Logger.Info("Exiting with exit code {0}", (object)num1);
                Environment.Exit(num1);
            }
        }