Skip to content

Commit

Permalink
Add ability to send log files (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Epictek authored Nov 12, 2024
1 parent 7034d2a commit e25a949
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
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 Down Expand Up @@ -33,6 +35,7 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.FileProvider;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.documentfile.provider.DocumentFile;

Expand All @@ -54,15 +57,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 @@ -375,6 +383,60 @@ public void onStopTrackingTouch(SeekBar seekBar) {
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>

0 comments on commit e25a949

Please sign in to comment.