mirror of https://github.com/tasks/tasks
Additional debug info in application logs
parent
f4e0d519d7
commit
bbac4da7d0
@ -1,77 +0,0 @@
|
||||
package org.tasks.preferences;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Build;
|
||||
import android.speech.RecognizerIntent;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
|
||||
import org.tasks.BuildConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class Device {
|
||||
|
||||
private final Context context;
|
||||
|
||||
@Inject
|
||||
public Device(@ApplicationContext Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public boolean hasCamera() {
|
||||
return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
|
||||
}
|
||||
|
||||
public boolean hasMicrophone() {
|
||||
return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MICROPHONE);
|
||||
}
|
||||
|
||||
public boolean voiceInputAvailable() {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
List<ResolveInfo> activities =
|
||||
pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
|
||||
return (activities.size() != 0);
|
||||
}
|
||||
|
||||
public String getDebugInfo() {
|
||||
try {
|
||||
return Joiner.on("\n")
|
||||
.join(
|
||||
asList(
|
||||
"",
|
||||
"----------",
|
||||
"Tasks: "
|
||||
+ BuildConfig.VERSION_NAME
|
||||
+ " ("
|
||||
+ BuildConfig.FLAVOR
|
||||
+ " build "
|
||||
+ BuildConfig.VERSION_CODE
|
||||
+ ")",
|
||||
"Android: " + Build.VERSION.RELEASE + " (" + Build.DISPLAY + ")",
|
||||
"Locale: " + java.util.Locale.getDefault(),
|
||||
"Model: " + Build.MANUFACTURER + " " + Build.MODEL,
|
||||
"Product: " + Build.PRODUCT + " (" + Build.DEVICE + ")",
|
||||
"Kernel: "
|
||||
+ System.getProperty("os.version")
|
||||
+ " ("
|
||||
+ Build.VERSION.INCREMENTAL
|
||||
+ ")",
|
||||
"----------",
|
||||
""));
|
||||
} catch (Exception e) {
|
||||
Timber.e(e);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
package org.tasks.preferences
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.speech.RecognizerIntent
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import org.tasks.BuildConfig
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
|
||||
class Device @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
private val permissionChecker: PermissionChecker,
|
||||
) {
|
||||
@SuppressLint("UnsupportedChromeOsCameraSystemFeature")
|
||||
fun hasCamera() = context.packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)
|
||||
|
||||
fun hasMicrophone() = context.packageManager.hasSystemFeature(PackageManager.FEATURE_MICROPHONE)
|
||||
|
||||
fun voiceInputAvailable(): Boolean {
|
||||
val pm = context.packageManager
|
||||
val activities =
|
||||
pm.queryIntentActivities(Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0)
|
||||
return (activities.size != 0)
|
||||
}
|
||||
|
||||
val debugInfo: String
|
||||
get() = """
|
||||
----------
|
||||
Tasks: ${BuildConfig.VERSION_NAME} (${BuildConfig.FLAVOR} build ${BuildConfig.VERSION_CODE})
|
||||
Android: ${Build.VERSION.RELEASE} (${Build.DISPLAY})
|
||||
Locale: ${Locale.getDefault()}
|
||||
Model: ${Build.MANUFACTURER} ${Build.MODEL}
|
||||
Product: ${Build.PRODUCT} (${Build.DEVICE})
|
||||
Kernel: ${System.getProperty("os.version")} (${Build.VERSION.INCREMENTAL})
|
||||
----------
|
||||
notifications: ${permissionChecker.hasNotificationPermission()}
|
||||
reminders: ${permissionChecker.hasAlarmsAndRemindersPermission()}
|
||||
background location: ${permissionChecker.canAccessBackgroundLocation()}
|
||||
foreground location: ${permissionChecker.canAccessForegroundLocation()}
|
||||
calendar: ${permissionChecker.canAccessCalendars()}
|
||||
----------
|
||||
""".trimIndent()
|
||||
}
|
||||
Loading…
Reference in New Issue