Exemple #1
0
 internal static void StartTimer(string vmName, string packageName)
 {
     AppUsageTimer.StopTimer();
     AppUsageTimer.sLastAppPackage = packageName;
     AppUsageTimer.sLastVMName     = vmName;
     AppUsageTimer.sStopwatch.Reset();
     AppUsageTimer.sStopwatch.Start();
 }
Exemple #2
0
 internal static long GetTotalTimeForPackageAfterReset(string packageName)
 {
     try
     {
         long packageAcrossInstances = AppUsageTimer.GetTotalTimeForPackageAcrossInstances(packageName);
         return(packageAcrossInstances < 0L ? 0L : packageAcrossInstances);
     }
     catch (Exception ex)
     {
         Logger.Error("Exception in GetTotalTimeForPackageAfterReset. Err : " + ex.ToString());
     }
     return(0);
 }
Exemple #3
0
 private static void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
 {
     if (e.Reason == SessionSwitchReason.SessionLock)
     {
         AppUsageTimer.StopTimer();
     }
     else
     {
         if (e.Reason != SessionSwitchReason.SessionUnlock)
         {
             return;
         }
         AppUsageTimer.StartTimerAfterResume();
     }
 }
Exemple #4
0
 private static void StartTimerAfterResume()
 {
     try
     {
         if (!BlueStacksUIUtils.DictWindows.ContainsKey(AppUsageTimer.sLastVMName))
         {
             return;
         }
         MainWindow dictWindow = BlueStacksUIUtils.DictWindows[AppUsageTimer.sLastVMName];
         if (dictWindow == null || dictWindow.mTopBar.mAppTabButtons.SelectedTab == null)
         {
             return;
         }
         AppUsageTimer.StartTimer(AppUsageTimer.sLastVMName, dictWindow.mTopBar.mAppTabButtons.SelectedTab.TabKey);
     }
     catch (Exception ex)
     {
         Logger.Error("Exception in starting timer after sleep. Err : " + ex.ToString());
     }
 }
 internal static void HandleUsageNotification(JObject resJson, string vmName)
 {
     try
     {
         string result           = "";
         string jsonObjectString = JSONUtils.GetJSONObjectString(AppUsageTimer.GetRealtimeDictionary());
         JObject.Parse(resJson["bluestacks_notification"][(object)"payload"].ToString()).AssignStringIfContains("handler", ref result);
         string url = WebHelper.GetServerHost() + "/v2/" + result;
         Dictionary <string, string> dictionary = new Dictionary <string, string>()
         {
             ["oem"]         = "bgp",
             ["client_ver"]  = RegistryManager.Instance.ClientVersion,
             ["engine_ver"]  = RegistryManager.Instance.Version,
             ["guid"]        = RegistryManager.Instance.UserGuid,
             ["locale"]      = RegistryManager.Instance.UserSelectedLocale,
             ["partner"]     = RegistryManager.Instance.Partner,
             ["campaignMD5"] = RegistryManager.Instance.CampaignMD5
         };
         if (!string.IsNullOrEmpty(RegistryManager.Instance.RegisteredEmail))
         {
             dictionary["email"] = RegistryManager.Instance.RegisteredEmail;
         }
         dictionary["usage_data"] = jsonObjectString;
         if (!dictionary.ContainsKey("current_app"))
         {
             dictionary.Add("current_app", BlueStacksUIUtils.DictWindows[vmName].mTopBar.mAppTabButtons.SelectedTab.PackageName);
         }
         else
         {
             dictionary["current_app"] = BlueStacksUIUtils.DictWindows[vmName].mTopBar.mAppTabButtons.SelectedTab.PackageName;
         }
         Dictionary <string, string> data = dictionary;
         string empty = string.Empty;
         Logger.Info("real time app usage response:" + BstHttpClient.Post(url, data, (Dictionary <string, string>)null, false, empty, 0, 1, 0, false, "bgp"));
     }
     catch (Exception ex)
     {
         Logger.Error("Exception in handling usage notification" + ex.ToString());
     }
 }
 private static void HandleDeferredNotification(GenericNotificationItem genericItem)
 {
     PromotionManager.sDeferredNotificationsList.Add(genericItem, AppUsageTimer.GetTotalTimeForPackageAfterReset(genericItem.DeferredApp.ToLower(CultureInfo.InvariantCulture)));
 }
Exemple #7
0
 internal static void SaveData()
 {
     AppUsageTimer.StopTimer();
     RegistryManager.Instance.AInfo = AppUsageTimer.EncryptString(JsonConvert.SerializeObject((object)AppUsageTimer.sDictAppUsageInfo));
 }
        public static void Main(string[] args)
        {
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            App.InitExceptionAndLogging();
            ProcessUtils.LogParentProcessDetails();
            if (args != null)
            {
                App.ParseWebMagnetArgs(ref args);
                Opt.Instance.Parse(args);
            }
            string path = Path.Combine(Path.Combine(Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory.Trim('\\')).FullName, "Engine"), "Oem.cfg");

            Oem.CurrentOemFilePath = System.IO.File.Exists(path) ? path : Path.Combine(RegistryManager.Instance.EngineDataDir, "Oem.cfg");
            PortableInstaller.CheckAndRunPortableInstaller();
            if (!RegistryManager.Instance.Guest.ContainsKey(Opt.Instance.vmname))
            {
                Opt.Instance.vmname = "Android";
            }
            BlueStacks.Common.Strings.CurrentDefaultVmName = Opt.Instance.vmname;
            if (Opt.Instance.mergeCfg)
            {
                KMManager.MergeConfig(Opt.Instance.newPDPath);
                Environment.Exit(0);
            }
            string mBSTProcessIdentifier = "Bluestacks/" + RegistryManager.Instance.ClientVersion;

            if (!string.Join(string.Empty, args).Contains(mBSTProcessIdentifier))
            {
                Logger.Info("BOOT_STAGE: Client starting");
                if (Oem.IsOEMDmm)
                {
                    Logger.Info("checking DMMGamePlayer process");
                    if (!ProcessUtils.FindProcessByName("DMMGamePlayer") && !ProcessUtils.FindProcessByName("dmmemulatorsandboxlauncher"))
                    {
                        Logger.Info("DMM game player not running, so exiting");
                        Environment.Exit(0);
                    }
                }
                RegistryManager.ClientThemeName = RegistryManager.Instance.GetClientThemeNameFromRegistry();
                if (Oem.IsOEMDmm || !BlueStacksUpdater.CheckIfDownloadedFileExist())
                {
                    App app = new App();
                    app.Startup     += new StartupEventHandler(App.Application_Startup);
                    app.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                    app.InitializeComponent();
                    App.CheckIfAlreadyRunning();
                    RegistryManager.Instance.ClientLaunchParams = Opt.Instance.Json;
                    App.defaultResolution = new Fraction((long)RegistryManager.Instance.Guest[BlueStacks.Common.Strings.CurrentDefaultVmName].GuestWidth, (long)RegistryManager.Instance.Guest[BlueStacks.Common.Strings.CurrentDefaultVmName].GuestHeight);
                    SystemEvents.DisplaySettingsChanged += new EventHandler(App.HandleDisplaySettingsChanged);
                    BGPHelper.InitHttpServerAsync();
                    BlueStacksUIUtils.RunInstance(BlueStacks.Common.Strings.CurrentDefaultVmName, Opt.Instance.h, Opt.Instance.Json);
                    AppUsageTimer.SessionEventHandler();
                    if (!Oem.IsOEMDmm)
                    {
                        PromotionManager.ReloadPromotionsAsync();
                        GrmManager.UpdateGrmAsync((IEnumerable <string>)null);
                        GuidanceCloudInfoManager.Instance.AppsGuidanceCloudInfoRefresh();
                    }
                    if (!FeatureManager.Instance.IsHtmlHome)
                    {
                        BlueStacksUIUtils.DictWindows[BlueStacks.Common.Strings.CurrentDefaultVmName].CreateFirebaseBrowserControl();
                    }
                    MemoryManager.TrimMemory(true);
                    app.Run();
                }
                else
                {
                    BlueStacksUpdater.HandleUpgrade(RegistryManager.Instance.DownloadedUpdateFile);
                }
            }
            else
            {
                CefHelper.InitCef(args, mBSTProcessIdentifier);
            }
            AppUsageTimer.DetachSessionEventHandler();
            CefRuntime.Shutdown();
            App.ExitApplication();
        }