X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fasynctasks%2FGetLogcat.java;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fasynctasks%2FGetLogcat.java;h=0000000000000000000000000000000000000000;hp=8abd75acd0c30339e1cec3d3d3e00574ab8837e4;hb=322b36f275782a06ed66b950083f28cc37f5690a;hpb=1d656c562831f535aa33903d44198dd890393f4f diff --git a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetLogcat.java b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetLogcat.java deleted file mode 100644 index 8abd75ac..00000000 --- a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetLogcat.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright © 2020-2021 Soren Stoutner . - * - * This file is part of Privacy Browser . - * - * Privacy Browser is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Privacy Browser is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Privacy Browser. If not, see . - */ - -package com.stoutner.privacybrowser.asynctasks; - -import android.app.Activity; -import android.os.AsyncTask; -import android.widget.ScrollView; -import android.widget.TextView; - -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; - -import com.stoutner.privacybrowser.R; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.lang.ref.WeakReference; - -// `Void` does not declare any parameters. `Void` does not declare progress units. `String` contains the results. -public class GetLogcat extends AsyncTask { - // Define the class variables. - private final WeakReference activityWeakReference; - private final int scrollViewYPositionInt; - - // The public constructor. - public GetLogcat(Activity activity, int scrollViewYPositionInt) { - // Populate the weak reference to the calling activity. - activityWeakReference = new WeakReference<>(activity); - - // Store the scrollview Y position. - this.scrollViewYPositionInt = scrollViewYPositionInt; - } - - @Override - protected String doInBackground(Void... parameters) { - // Get a handle for the activity. - Activity activity = activityWeakReference.get(); - - // Abort if the activity is gone. - if ((activity == null) || activity.isFinishing()) { - return ""; - } - - // Create a log string builder. - StringBuilder logStringBuilder = new StringBuilder(); - - try { - // Get the logcat. `-b all` gets all the buffers (instead of just crash, main, and system). `-v long` produces more complete information. `-d` dumps the logcat and exits. - Process process = Runtime.getRuntime().exec("logcat -b all -v long -d"); - - // Wrap the logcat in a buffered reader. - BufferedReader logBufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); - - // Create a log transfer string. - String logTransferString; - - // Use the log transfer string to copy the logcat from the buffered reader to the string builder. - while ((logTransferString = logBufferedReader.readLine()) != null) { - // Append a line. - logStringBuilder.append(logTransferString); - - // Append a line break. - logStringBuilder.append("\n"); - } - - // Close the buffered reader. - logBufferedReader.close(); - } catch (IOException exception) { - // Do nothing. - } - - // Return the logcat. - return logStringBuilder.toString(); - } - - // `onPostExecute()` operates on the UI thread. - @Override - protected void onPostExecute(String logcatString) { - // Get a handle for the activity. - Activity activity = activityWeakReference.get(); - - // Abort if the activity is gone. - if ((activity == null) || activity.isFinishing()) { - return; - } - - // Get handles for the views. - TextView logcatTextView = activity.findViewById(R.id.logcat_textview); - SwipeRefreshLayout swipeRefreshLayout = activity.findViewById(R.id.logcat_swiperefreshlayout); - ScrollView scrollView = activity.findViewById(R.id.logcat_scrollview); - - // Display the logcat. - logcatTextView.setText(logcatString); - - // Update the scroll position after the text is populated. - logcatTextView.post(() -> { - // Set the scroll position. - scrollView.setScrollY(scrollViewYPositionInt); - }); - - // Stop the swipe to refresh animation if it is displayed. - swipeRefreshLayout.setRefreshing(false); - } -} \ No newline at end of file