public CrashDumper(Context aContext, int aNotificationIconResource, Helper aHelper, OptionPageCrashDumper aOptionPage) { iContext = aContext; iNotificationIconResource = aNotificationIconResource; iHelper = aHelper; iOptionPage = aOptionPage; }
private void StartStack() { iUserLogListener = new AndroidUserLogListener(); UserLog.AddListener(iUserLogListener); iTraceListener = new AndroidTraceListener(); Trace.AddListener(iTraceListener); iWifiManager = (WifiManager)GetSystemService(Context.WifiService); if (iWifiManager != null) { iWifiLock = iWifiManager.CreateWifiLock("myWifiLock"); iWifiLock.Acquire(); iMulticastLock = iWifiManager.CreateMulticastLock("myMcastlock"); iMulticastLock.Acquire(); } iHelper = new Helper(new string[0] { }); OptionPageCrashDumper optionCrashDumper = new OptionPageCrashDumper("Crash Logs"); iHelper.AddOptionPage(optionCrashDumper); iWifiListener = new WifiListener(this, iHelper); iWifiListener.Refresh(this.ApplicationContext); iHelper.ProcessOptionsFileAndCommandLine(); iHelper.Stack.SetStack(this); iCrashLogDumper = new CrashDumper(this.ApplicationContext, Resource.Drawable.Icon, iHelper, optionCrashDumper); iHelper.AddCrashLogDumper(iCrashLogDumper); iEventServer = new EventServerUpnp(); iListenerNotify = new SsdpListenerMulticast(); iHouse = new House(iListenerNotify, iEventServer, new ModelFactory()); iHouse.EventRoomAdded += RoomAdded; iHouse.EventRoomRemoved += RoomRemoved; iLibrary = new Library(iListenerNotify); iLibrary.EventMediaServerAdded += LibraryAdded; iLibrary.EventMediaServerRemoved += LibraryRemoved; iRescanTimer = new System.Timers.Timer(kRescanTimeoutMilliseconds); iRescanTimer.Elapsed += (d, e) => { if (iHelper.Stack.Status.State == EStackState.eOk) { try { if (iHouse != null) { iHouse.Rescan(); } if (iLibrary != null) { iLibrary.Rescan(); } } catch (Exception ex) { UserLog.WriteLine("Error caught on rescan: " + ex); } } }; iHelper.Stack.Start(); }
protected override void OnCreate(Bundle bundle) { try { base.OnCreate(bundle); // this activity is running in a new process, cannot parcel an existing helper without making Helper an IParcelable, // so we create a new one to obtain the crash dump option Helper helper = new Helper(new string[] { }); OptionPageCrashDumper optionPage = new OptionPageCrashDumper("Crash Logs"); helper.AddOptionPage(optionPage); helper.ProcessOptionsFileAndCommandLine(); // also need to set up log listeners again for same reason UserLog.AddListener(new AndroidUserLogListener()); Trace.AddListener(new AndroidTraceListener()); // cancel crash notification NotificationManager notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); notificationManager.Cancel((int)ENotificationType.SystemCrash); string crashLog = Intent.GetStringExtra(CrashDumper.kCrashLogData); // log to adb logcat UserLog.WriteLine("CrashDump: " + crashLog); // setup activity UI //TODO: i18n this.Title = string.Format("{0} has quit unexpectedly.", helper.Product); LinearLayout rootLayout = new LinearLayout(this); rootLayout.Orientation = Orientation.Vertical; LinearLayout messagePanel = new LinearLayout(this); messagePanel.Orientation = Orientation.Horizontal; LinearLayout.LayoutParams layoutParamsImg = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent); layoutParamsImg.SetMargins(5, 5, 5, 5); ImageView image = new ImageView(this); image.SetImageResource(Intent.GetIntExtra(CrashDumper.kCrashLogImage, 0)); messagePanel.AddView(image, layoutParamsImg); LinearLayout.LayoutParams layoutParamsMessage = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent); layoutParamsMessage.SetMargins(5, 5, 5, 5); TextView message = new TextView(this); message.Text = string.Format("{0} encountered a problem and had to close. We are sorry for the inconvenience", helper.Product); messagePanel.AddView(message, layoutParamsMessage); rootLayout.AddView(messagePanel); LinearLayout.LayoutParams layoutParamsMessage2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent); layoutParamsMessage2.SetMargins(5, 5, 5, 5); TextView message2 = new TextView(this); message2.Text = "Please submit a crash report to Linn to help us fix this problem for future versions."; rootLayout.AddView(message2, layoutParamsMessage2); RelativeLayout buttonsPanel = new RelativeLayout(this); buttonsPanel.Id = 1; // need an id for relative layout references // don't send button RelativeLayout.LayoutParams dontSendButtonLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WrapContent, RelativeLayout.LayoutParams.WrapContent); dontSendButtonLayoutParams.SetMargins(5, 5, 5, 5); dontSendButtonLayoutParams.AddRule(LayoutRules.AlignParentTop, buttonsPanel.Id); dontSendButtonLayoutParams.AddRule(LayoutRules.AlignParentRight, buttonsPanel.Id); Button dontSendButton = new Button(this); dontSendButton.Text = "Don't Send"; dontSendButton.Id = 2; // need an id for relative layout references buttonsPanel.AddView(dontSendButton, dontSendButtonLayoutParams); // send button RelativeLayout.LayoutParams sendButtonLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WrapContent, RelativeLayout.LayoutParams.WrapContent); sendButtonLayoutParams.SetMargins(5, 5, 5, 5); sendButtonLayoutParams.AddRule(LayoutRules.AlignParentTop, buttonsPanel.Id); sendButtonLayoutParams.AddRule(LayoutRules.LeftOf, dontSendButton.Id); Button sendButton = new Button(this); sendButton.Text = "Send"; buttonsPanel.AddView(sendButton, sendButtonLayoutParams); // auto send checkbox RelativeLayout.LayoutParams autoSendLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WrapContent, RelativeLayout.LayoutParams.WrapContent); autoSendLayoutParams.SetMargins(5, 5, 5, 5); autoSendLayoutParams.AddRule(LayoutRules.Below, dontSendButton.Id); autoSendLayoutParams.AddRule(LayoutRules.AlignParentRight, buttonsPanel.Id); CheckBox autoSend = new CheckBox(this); autoSend.Checked = optionPage.AutoSend; autoSend.Text = "Automatically send crash reports in future"; buttonsPanel.AddView(autoSend, autoSendLayoutParams); // details button RelativeLayout.LayoutParams detailsButtonLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WrapContent, RelativeLayout.LayoutParams.WrapContent); detailsButtonLayoutParams.SetMargins(5, 5, 5, 5); detailsButtonLayoutParams.AddRule(LayoutRules.AlignParentTop, buttonsPanel.Id); detailsButtonLayoutParams.AddRule(LayoutRules.AlignParentLeft, buttonsPanel.Id); Button detailsButton = new Button(this); detailsButton.Text = "Show Details..."; buttonsPanel.AddView(detailsButton, detailsButtonLayoutParams); // scrolling textbox for crash details ScrollView scrollView = new ScrollView(this); scrollView.Visibility = ViewStates.Invisible; TextView text = new TextView(this); text.Text = crashLog; scrollView.AddView(text); rootLayout.AddView(buttonsPanel); rootLayout.AddView(scrollView); SetContentView(rootLayout); sendButton.Click += (sender, args) => { CrashDumper.Send(crashLog, helper.Product, helper.Version, helper.Title); Finish(); }; dontSendButton.Click += (sender, args) => { Finish(); }; autoSend.CheckedChange += (sender, args) => { optionPage.AutoSend = autoSend.Checked; }; detailsButton.Click += (sender, args) => { if (scrollView.Visibility == ViewStates.Invisible) { detailsButton.Text = "Hide Details..."; scrollView.Visibility = ViewStates.Visible; } else { detailsButton.Text = "Show Details..."; scrollView.Visibility = ViewStates.Invisible; } }; } catch (Exception ex) { UserLog.WriteLine("CrashReportActivity.OnCreate:: " + ex); } }
private void InitialiseStack() { iEventCreated.WaitOne(); iEventLock = new object(); iUserLogListener = new AndroidUserLogListener(); UserLog.AddListener(iUserLogListener); iTraceListener = new AndroidTraceListener(); Trace.AddListener(iTraceListener); iInvoker = new Invoker(this.ApplicationContext); iResourceManager = new AndroidResourceManager(this.Resources); iIconResolver = new IconResolver(iResourceManager); iLayoutInflater = (LayoutInflater)GetSystemService(Context.LayoutInflaterService); iHelperKinsky = new HelperKinsky(new string[2] { "-t", kTraceLevel }, Invoker); Android.Runtime.AndroidEnvironment.UnhandledExceptionRaiser += UnhandledExceptionRaiser; // name the crash dumper section general and add other UI options OptionPageCrashDumper generalOptions = new OptionPageCrashDumper("General"); iOptionExtendedTrackInfo = new OptionBool("trackinfo", "Extended track info", "Show extended track information for the current track", true); generalOptions.Add(iOptionExtendedTrackInfo); iOptionEnableRocker = new OptionBool("rocker", "Button controls", "Enable button controls for controlling volume and seeking", false); generalOptions.Add(iOptionEnableRocker); iOptionGroupTracks = new OptionBool("groupplaylist", "Group playlist tracks", "Grouping tracks by album within the playlist window", true); generalOptions.Add(iOptionGroupTracks); iOptionAutoLock = new OptionEnum("autolock", "Prevent auto-lock", "When to prevent auto-lock"); iOptionAutoLock.AddDefault(kAutoLockNever); iOptionAutoLock.Add(kAutoLockCharging); iOptionAutoLock.Add(kAutoLockAlways); generalOptions.Add(iOptionAutoLock); iOptionAutoLock.EventValueChanged += OptionAutoLock_EventValueChangedHandler; iHelperKinsky.AddOptionPage(generalOptions); iHelperKinsky.SetStackExtender(this); iCrashLogDumper = new CrashDumper(this.ApplicationContext, Resource.Drawable.Icon, iHelperKinsky, generalOptions); iHelperKinsky.AddCrashLogDumper(iCrashLogDumper); iOptionInsertMode = new OptionInsertMode(); iHelperKinsky.AddOption(iOptionInsertMode); iViewMaster = new ViewMaster(); iHttpServer = new HttpServer(HttpServer.kPortKinskyDroid); iHttpClient = new HttpClient(); iLibrary = new MediaProviderLibrary(iHelperKinsky); iSharedPlaylists = new SharedPlaylists(iHelperKinsky); iLocalPlaylists = new LocalPlaylists(iHelperKinsky, false); PluginManager pluginManager = new PluginManager(iHelperKinsky, iHttpClient, new MediaProviderSupport(iHttpServer)); iLocator = new ContentDirectoryLocator(pluginManager, new AppRestartHandler()); OptionBool optionSharedPlaylists = iLocator.Add(SharedPlaylists.kRootId, iSharedPlaylists); OptionBool optionLocalPlaylists = iLocator.Add(LocalPlaylists.kRootId, iLocalPlaylists); iLocator.Add(MediaProviderLibrary.kLibraryId, iLibrary); iHelperKinsky.AddOptionPage(iLocator.OptionPage); iSaveSupport = new SaveSupport(iHelperKinsky, iSharedPlaylists, optionSharedPlaylists, iLocalPlaylists, optionLocalPlaylists); iPlaySupport = new PlaySupport(); iHelperKinsky.ProcessOptionsFileAndCommandLine(); Linn.Kinsky.Model model = new Linn.Kinsky.Model(iViewMaster, iPlaySupport); iMediator = new Mediator(iHelperKinsky, model); iAndroidViewMaster = new AndroidViewMaster(this, iViewMaster, iInvoker, iResourceManager, iSaveSupport, iIconResolver, iOptionGroupTracks, iOptionExtendedTrackInfo, IsTabletView ? kMaxImageCacheSizeTablet : kMaxImageCacheSizePhone); iStackWatchdog = new System.Threading.Timer(StackWatchdogExpired); iPowerListener = new PowerStateListener(this.ApplicationContext); iPowerListener.EventPowerStateChanged += EventPowerStateChangedHandler; iIsCharging = PowerStateListener.IsConnected(this.ApplicationContext); iRescanTimer = new System.Threading.Timer((e) => { Rescan(); }); iRescanTimer.Change(Timeout.Infinite, Timeout.Infinite); SetAutoLock(); EventLowMemory += EventLowMemoryHandler; iInitialised = true; StartStack(); }