|
|
|
@ -19,29 +19,31 @@
|
|
|
|
|
|
|
|
|
|
package org.isoron.uhabits.ui;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.os.Environment;
|
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
import android.view.WindowManager;
|
|
|
|
|
|
|
|
|
|
import org.isoron.uhabits.BuildConfig;
|
|
|
|
|
import org.isoron.uhabits.HabitsApplication;
|
|
|
|
|
import org.isoron.uhabits.models.HabitList;
|
|
|
|
|
import org.isoron.uhabits.tasks.BaseTask;
|
|
|
|
|
import org.isoron.uhabits.utils.DateUtils;
|
|
|
|
|
import org.isoron.uhabits.utils.FileUtils;
|
|
|
|
|
import org.isoron.uhabits.utils.ReminderUtils;
|
|
|
|
|
import org.isoron.uhabits.widgets.WidgetManager;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileWriter;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
|
|
|
|
|
import android.content.*;
|
|
|
|
|
import android.os.*;
|
|
|
|
|
import android.support.annotation.*;
|
|
|
|
|
import android.view.*;
|
|
|
|
|
|
|
|
|
|
import org.isoron.uhabits.*;
|
|
|
|
|
import org.isoron.uhabits.models.*;
|
|
|
|
|
import org.isoron.uhabits.tasks.*;
|
|
|
|
|
import org.isoron.uhabits.utils.*;
|
|
|
|
|
import org.isoron.uhabits.widgets.*;
|
|
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.lang.Process;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
import javax.inject.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Base class for all systems class in the application.
|
|
|
|
|
* <p>
|
|
|
|
|
* Classes derived from BaseSystem are responsible for handling events and
|
|
|
|
|
* sending requests to the Android operating system. Examples include capturing
|
|
|
|
|
* a bug report, obtaining device information, or requesting runtime
|
|
|
|
|
* permissions.
|
|
|
|
|
*/
|
|
|
|
|
public class BaseSystem
|
|
|
|
|
{
|
|
|
|
|
private Context context;
|
|
|
|
@ -55,69 +57,16 @@ public class BaseSystem
|
|
|
|
|
HabitsApplication.getComponent().inject(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getLogcat() throws IOException
|
|
|
|
|
{
|
|
|
|
|
int maxNLines = 250;
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
String[] command = new String[]{"logcat", "-d"};
|
|
|
|
|
Process process = Runtime.getRuntime().exec(command);
|
|
|
|
|
|
|
|
|
|
InputStreamReader in = new InputStreamReader(process.getInputStream());
|
|
|
|
|
BufferedReader bufferedReader = new BufferedReader(in);
|
|
|
|
|
|
|
|
|
|
LinkedList<String> log = new LinkedList<>();
|
|
|
|
|
|
|
|
|
|
String line;
|
|
|
|
|
while ((line = bufferedReader.readLine()) != null)
|
|
|
|
|
{
|
|
|
|
|
log.addLast(line);
|
|
|
|
|
if (log.size() > maxNLines) log.removeFirst();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (String l : log)
|
|
|
|
|
{
|
|
|
|
|
builder.append(l);
|
|
|
|
|
builder.append('\n');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return builder.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getDeviceInfo()
|
|
|
|
|
{
|
|
|
|
|
if (context == null) return "";
|
|
|
|
|
|
|
|
|
|
StringBuilder b = new StringBuilder();
|
|
|
|
|
WindowManager wm =
|
|
|
|
|
(WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
|
|
|
|
|
|
|
|
|
b.append(
|
|
|
|
|
String.format("App Version Name: %s\n", BuildConfig.VERSION_NAME));
|
|
|
|
|
b.append(
|
|
|
|
|
String.format("App Version Code: %s\n", BuildConfig.VERSION_CODE));
|
|
|
|
|
b.append(String.format("OS Version: %s (%s)\n",
|
|
|
|
|
java.lang.System.getProperty("os.version"),
|
|
|
|
|
android.os.Build.VERSION.INCREMENTAL));
|
|
|
|
|
b.append(
|
|
|
|
|
String.format("OS API Level: %s\n", android.os.Build.VERSION.SDK));
|
|
|
|
|
b.append(String.format("Device: %s\n", android.os.Build.DEVICE));
|
|
|
|
|
b.append(
|
|
|
|
|
String.format("Model (Product): %s (%s)\n", android.os.Build.MODEL,
|
|
|
|
|
android.os.Build.PRODUCT));
|
|
|
|
|
b.append(
|
|
|
|
|
String.format("Manufacturer: %s\n", android.os.Build.MANUFACTURER));
|
|
|
|
|
b.append(String.format("Other tags: %s\n", android.os.Build.TAGS));
|
|
|
|
|
b.append(String.format("Screen Width: %s\n",
|
|
|
|
|
wm.getDefaultDisplay().getWidth()));
|
|
|
|
|
b.append(String.format("Screen Height: %s\n",
|
|
|
|
|
wm.getDefaultDisplay().getHeight()));
|
|
|
|
|
b.append(String.format("SD Card state: %s\n\n",
|
|
|
|
|
Environment.getExternalStorageState()));
|
|
|
|
|
|
|
|
|
|
return b.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Captures a bug report and saves it to a file in the SD card.
|
|
|
|
|
* <p>
|
|
|
|
|
* The contents of the file are generated by the method {@link
|
|
|
|
|
* #getBugReport()}. The file is saved in the apps's external private
|
|
|
|
|
* storage.
|
|
|
|
|
*
|
|
|
|
|
* @return the generated file.
|
|
|
|
|
* @throws IOException when I/O errors occur.
|
|
|
|
|
*/
|
|
|
|
|
@NonNull
|
|
|
|
|
public File dumpBugReportToFile() throws IOException
|
|
|
|
|
{
|
|
|
|
@ -138,6 +87,14 @@ public class BaseSystem
|
|
|
|
|
return logFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Captures and returns a bug report.
|
|
|
|
|
* <p>
|
|
|
|
|
* The bug report contains some device information and the logcat.
|
|
|
|
|
*
|
|
|
|
|
* @return a String containing the bug report.
|
|
|
|
|
* @throws IOException when any I/O error occur.
|
|
|
|
|
*/
|
|
|
|
|
@NonNull
|
|
|
|
|
public String getBugReport() throws IOException
|
|
|
|
|
{
|
|
|
|
@ -146,6 +103,9 @@ public class BaseSystem
|
|
|
|
|
return deviceInfo + "\n" + logcat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Recreates all application reminders.
|
|
|
|
|
*/
|
|
|
|
|
public void scheduleReminders()
|
|
|
|
|
{
|
|
|
|
|
new BaseTask()
|
|
|
|
@ -159,6 +119,9 @@ public class BaseSystem
|
|
|
|
|
}.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Refreshes all application widgets.
|
|
|
|
|
*/
|
|
|
|
|
public void updateWidgets()
|
|
|
|
|
{
|
|
|
|
|
new BaseTask()
|
|
|
|
@ -171,4 +134,59 @@ public class BaseSystem
|
|
|
|
|
}
|
|
|
|
|
}.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getDeviceInfo()
|
|
|
|
|
{
|
|
|
|
|
if (context == null) return "null context\n";
|
|
|
|
|
|
|
|
|
|
WindowManager wm =
|
|
|
|
|
(WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
String.format("App Version Name: %s\n", BuildConfig.VERSION_NAME) +
|
|
|
|
|
String.format("App Version Code: %s\n", BuildConfig.VERSION_CODE) +
|
|
|
|
|
String.format("OS Version: %s (%s)\n",
|
|
|
|
|
System.getProperty("os.version"), Build.VERSION.INCREMENTAL) +
|
|
|
|
|
String.format("OS API Level: %s\n", Build.VERSION.SDK) +
|
|
|
|
|
String.format("Device: %s\n", Build.DEVICE) +
|
|
|
|
|
String.format("Model (Product): %s (%s)\n", Build.MODEL,
|
|
|
|
|
Build.PRODUCT) +
|
|
|
|
|
String.format("Manufacturer: %s\n", Build.MANUFACTURER) +
|
|
|
|
|
String.format("Other tags: %s\n", Build.TAGS) +
|
|
|
|
|
String.format("Screen Width: %s\n",
|
|
|
|
|
wm.getDefaultDisplay().getWidth()) +
|
|
|
|
|
String.format("Screen Height: %s\n",
|
|
|
|
|
wm.getDefaultDisplay().getHeight()) +
|
|
|
|
|
String.format("External storage state: %s\n\n",
|
|
|
|
|
Environment.getExternalStorageState());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getLogcat() throws IOException
|
|
|
|
|
{
|
|
|
|
|
int maxLineCount = 250;
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
String[] command = new String[]{"logcat", "-d"};
|
|
|
|
|
Process process = Runtime.getRuntime().exec(command);
|
|
|
|
|
|
|
|
|
|
InputStreamReader in = new InputStreamReader(process.getInputStream());
|
|
|
|
|
BufferedReader bufferedReader = new BufferedReader(in);
|
|
|
|
|
|
|
|
|
|
LinkedList<String> log = new LinkedList<>();
|
|
|
|
|
|
|
|
|
|
String line;
|
|
|
|
|
while ((line = bufferedReader.readLine()) != null)
|
|
|
|
|
{
|
|
|
|
|
log.addLast(line);
|
|
|
|
|
if (log.size() > maxLineCount) log.removeFirst();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (String l : log)
|
|
|
|
|
{
|
|
|
|
|
builder.append(l);
|
|
|
|
|
builder.append('\n');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return builder.toString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|