예제 #1
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            if (!Settings.IsFireTV ()) {
                Console.WriteLine ("Not starting KFTV Watcher Service, not FireTV...");
                return StartCommandResult.NotSticky;
            }

            if (timer == null) {
                activityManager = ActivityManager.FromContext (this);

                timer = new Timer (state => {

                    if (Settings.Instance.DisableHomeDetection) {
                        Console.WriteLine ("Disabled Home Detection... Not starting KFTV Watcher Service...");
                        return;
                    }

                    // Gets the topmost running task
                    var topTask = activityManager.GetRunningTasks (1).FirstOrDefault ();

                    if (topTask == null || topTask.TopActivity == null)
                        return;

                    // We can detect that the firetv home launcher was called
                    // by simply getting the top task's top activity and matching the
                    // package name and class name
                    //      Package Name: com.amazon.tv.launcher
                    //      Class Name:   com.amazon.tv.launcher.ui.HomeActivity
                    if (topTask.TopActivity.PackageName == Settings.HOME_PACKAGE_NAME
                        && topTask.TopActivity.ClassName == Settings.HOME_CLASS_NAME) {

                        var actedAgo = DateTime.UtcNow - acted;
                        // Just to be safe, we don't want to call this multiple times in a row
                        // Also there's a static flag that the firedtv app can set
                        // to allow the user to launch the firetv homescreen
                        if (actedAgo > TimeSpan.FromMilliseconds (500) && !AllowFireTVHome) {

                            //Come back to papa
                            var actIntent = new Intent(ApplicationContext, typeof(MainActivity));
                            actIntent.AddFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop);
                            StartActivity (actIntent);

                            // Set the flag
                            acted = DateTime.UtcNow;
                        }

                    } else {
                        // It wasn't a match (another task is top) so reset the flag
                        acted = DateTime.MinValue;
                    }

                }, null, Settings.Instance.HomeDetectIntervalMs, Settings.Instance.HomeDetectIntervalMs);
            }

            return StartCommandResult.Sticky;
        }
예제 #2
0
        string getRam(Context context)
        {
            StringBuilder sb = new StringBuilder();

            try {
                Android.App.ActivityManager.MemoryInfo memInfo    = new Android.App.ActivityManager.MemoryInfo();
                Android.App.ActivityManager            actManager = context.GetSystemService(Android.Content.Context.ActivityService) as Android.App.ActivityManager;
                actManager.GetMemoryInfo(memInfo);
                sb.AppendLine(getItemString("RAM:", string.Format("{0} B ({1:N1} kb / {2:N1} MB / {3:N1} GB)",
                                                                  memInfo.TotalMem,
                                                                  memInfo.TotalMem / 1024.0,
                                                                  memInfo.TotalMem / (1024.0 * 1024.0),
                                                                  memInfo.TotalMem / (1024.0 * 1024.0 * 1024.0)), NAME1POS, CONTENT1POS));
            } catch (Exception ex) {
                sb.AppendLine("Exception: " + ex.Message);
            }
            return(sb.ToString());
        }
 public Android.App.ActivityManager GetCustomActivityManager()
 {
     Android.App.ActivityManager _am = (Android.App.ActivityManager)Android.App.Application
                                       .Context.GetSystemService(Context.ActivityService);
     return(_am);
 }
 public PlatformPerformance()
 {
     _runtime = Runtime.GetRuntime();
     _activityManager = (ActivityManager)Application.Context.GetSystemService("activity");
     _memoryInfo = new ActivityManager.MemoryInfo();
 }