Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to send log files #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true">
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>

<activity
android:name=".VideoActivity"
Expand Down
62 changes: 62 additions & 0 deletions app/src/main/java/com/openipc/pixelpilot/VideoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.hardware.usb.UsbManager;
Expand All @@ -30,6 +32,7 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.FileProvider;
import androidx.documentfile.provider.DocumentFile;

import com.github.mikephil.charting.charts.PieChart;
Expand All @@ -50,15 +53,20 @@
import com.openipc.wfbngrtl8812.WfbNGStatsChanged;
import com.openipc.wfbngrtl8812.WfbNgLink;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
Expand Down Expand Up @@ -237,6 +245,60 @@ protected void onCreate(Bundle savedInstanceState) {
return false;
});

SubMenu help = popup.getMenu().addSubMenu("Help");
MenuItem logs = help.add("Send Logs");
logs.setOnMenuItemClickListener(item -> {
try {
Process process = Runtime.getRuntime().exec("logcat -d");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));

String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File logFile = new File(getExternalFilesDir(null), "pixelpilot_log_" + timeStamp + ".txt");
FileWriter fileWriter = new FileWriter(logFile);

String versionName = "";
long versionCode = 0;

try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
versionName = packageInfo.versionName;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
versionCode = packageInfo.getLongVersionCode();
} else {
versionCode = packageInfo.versionCode;
}
} catch (PackageManager.NameNotFoundException e) {
}

fileWriter.append("Device Model: " + Build.MODEL + "\n" +
"Manufacturer: " + Build.MANUFACTURER + "\n" +
"OS Version: " + Build.VERSION.RELEASE + "\n" +
"SDK Version: " + Build.VERSION.SDK_INT + "\n" +
"App Version Name: " + versionName + "\n" +
"App Version Code: " + versionCode + "\n");

String line;

while ((line = bufferedReader.readLine()) != null) {
fileWriter.append(line).append("\n");
}
fileWriter.flush();
fileWriter.close();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
Uri fileUri = FileProvider.getUriForFile(this, getPackageName() + ".provider", logFile);
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
sendIntent.setType("text/plain");
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Intent shareIntent = Intent.createChooser(sendIntent, null);
startActivity(shareIntent);

} catch (IOException e) {
Log.e(TAG, "ShareLog: ", e);
}
return true;
});

popup.show();
});

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/xml/file_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="log_files" path="." />
</paths>