mirror of
https://github.com/mattintech/AndroidTestApp.git
synced 2026-07-11 16:31:53 +00:00
Compare commits
5 Commits
v0.9.5
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
| 17f28324d9 | |||
| 39cc49edc1 | |||
| 81fca84207 | |||
| 6ddc8861ac | |||
| 61431cff75 |
@@ -10,8 +10,8 @@ android {
|
|||||||
applicationId = "com.mattintech.androidtestapp"
|
applicationId = "com.mattintech.androidtestapp"
|
||||||
minSdk = 32
|
minSdk = 32
|
||||||
targetSdk = 35
|
targetSdk = 35
|
||||||
versionCode = 1
|
versionCode = 2
|
||||||
versionName = "1.0.0"
|
versionName = "1.0.1"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,35 +32,13 @@ public class BadBehaviorActivity extends AppCompatActivity {
|
|||||||
private boolean isRandomModeActive = false;
|
private boolean isRandomModeActive = false;
|
||||||
private Runnable randomCrashRunnable;
|
private Runnable randomCrashRunnable;
|
||||||
private boolean isServiceRunning = false;
|
private boolean isServiceRunning = false;
|
||||||
|
private String currentFrequency = "";
|
||||||
|
private long randomModeStartTime = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
// Set up crash handler to restart app
|
|
||||||
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
|
||||||
@Override
|
|
||||||
public void uncaughtException(Thread thread, Throwable throwable) {
|
|
||||||
// Check if we're in random mode
|
|
||||||
SharedPreferences prefs = getSharedPreferences("BadBehaviorPrefs", Context.MODE_PRIVATE);
|
|
||||||
boolean isRandomActive = prefs.getBoolean("isRandomActive", false);
|
|
||||||
|
|
||||||
// Restart the app
|
|
||||||
Intent intent;
|
|
||||||
if (isRandomActive) {
|
|
||||||
// Go directly to BadBehaviorActivity to resume random mode
|
|
||||||
intent = new Intent(getApplicationContext(), BadBehaviorActivity.class);
|
|
||||||
intent.putExtra("resumeRandomMode", true);
|
|
||||||
} else {
|
|
||||||
// Normal restart to MainActivity
|
|
||||||
intent = new Intent(getApplicationContext(), MainActivity.class);
|
|
||||||
}
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
||||||
startActivity(intent);
|
|
||||||
android.os.Process.killProcess(android.os.Process.myPid());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
binding = ActivityBadBehaviorBinding.inflate(getLayoutInflater());
|
binding = ActivityBadBehaviorBinding.inflate(getLayoutInflater());
|
||||||
setContentView(binding.getRoot());
|
setContentView(binding.getRoot());
|
||||||
|
|
||||||
@@ -81,8 +59,6 @@ public class BadBehaviorActivity extends AppCompatActivity {
|
|||||||
finish();
|
finish();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if we need to resume random mode after a crash
|
|
||||||
checkAndResumeRandomMode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupWindowInsets() {
|
private void setupWindowInsets() {
|
||||||
@@ -141,6 +117,7 @@ public class BadBehaviorActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
// Initially disable stop button
|
// Initially disable stop button
|
||||||
binding.btnStopRandom.setEnabled(false);
|
binding.btnStopRandom.setEnabled(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void triggerCrash() {
|
private void triggerCrash() {
|
||||||
@@ -298,22 +275,15 @@ public class BadBehaviorActivity extends AppCompatActivity {
|
|||||||
"• STOP battery drain tests\n" +
|
"• STOP battery drain tests\n" +
|
||||||
"• FAIL scheduled downloads\n" +
|
"• FAIL scheduled downloads\n" +
|
||||||
"• Crash the app " + frequency.toLowerCase() + "\n\n" +
|
"• Crash the app " + frequency.toLowerCase() + "\n\n" +
|
||||||
"The app will auto-restart and return to this screen.\n" +
|
"NOTE: The app will NOT auto-restart after crashes.\n" +
|
||||||
"Keep the app open for continuous testing.\n" +
|
"Random mode will stop when the app crashes.\n\n" +
|
||||||
"This mode will automatically stop after 24 hours.\n\n" +
|
|
||||||
"Are you sure you want to start random crash mode?")
|
"Are you sure you want to start random crash mode?")
|
||||||
.setPositiveButton("Start", (dialog, which) -> {
|
.setPositiveButton("Start", (dialog, which) -> {
|
||||||
Log.d(TAG, "Starting random mode with frequency: " + frequency);
|
Log.d(TAG, "Starting random mode with frequency: " + frequency);
|
||||||
|
|
||||||
// Save random mode configuration
|
|
||||||
SharedPreferences prefs = getSharedPreferences("BadBehaviorPrefs", Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
|
||||||
editor.putBoolean("isRandomActive", true);
|
|
||||||
editor.putString("frequency", frequency);
|
|
||||||
editor.putLong("startTime", System.currentTimeMillis());
|
|
||||||
editor.apply();
|
|
||||||
|
|
||||||
isRandomModeActive = true;
|
isRandomModeActive = true;
|
||||||
|
currentFrequency = frequency;
|
||||||
|
randomModeStartTime = System.currentTimeMillis();
|
||||||
binding.btnStartRandom.setEnabled(false);
|
binding.btnStartRandom.setEnabled(false);
|
||||||
binding.btnStopRandom.setEnabled(true);
|
binding.btnStopRandom.setEnabled(true);
|
||||||
binding.btnTriggerCrash.setEnabled(false);
|
binding.btnTriggerCrash.setEnabled(false);
|
||||||
@@ -373,11 +343,6 @@ public class BadBehaviorActivity extends AppCompatActivity {
|
|||||||
isRandomModeActive = false;
|
isRandomModeActive = false;
|
||||||
handler.removeCallbacks(randomCrashRunnable);
|
handler.removeCallbacks(randomCrashRunnable);
|
||||||
|
|
||||||
// Clear random mode from preferences
|
|
||||||
SharedPreferences prefs = getSharedPreferences("BadBehaviorPrefs", Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
|
||||||
editor.putBoolean("isRandomActive", false);
|
|
||||||
editor.apply();
|
|
||||||
|
|
||||||
binding.btnStartRandom.setEnabled(true);
|
binding.btnStartRandom.setEnabled(true);
|
||||||
binding.btnStopRandom.setEnabled(false);
|
binding.btnStopRandom.setEnabled(false);
|
||||||
@@ -392,12 +357,9 @@ public class BadBehaviorActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void viewScheduledCrashes() {
|
private void viewScheduledCrashes() {
|
||||||
SharedPreferences prefs = getSharedPreferences("BadBehaviorPrefs", Context.MODE_PRIVATE);
|
if (isRandomModeActive) {
|
||||||
boolean isRandomActive = prefs.getBoolean("isRandomActive", false);
|
String frequency = currentFrequency;
|
||||||
|
long startTime = randomModeStartTime;
|
||||||
if (isRandomActive && isRandomModeActive) {
|
|
||||||
String frequency = prefs.getString("frequency", "Unknown");
|
|
||||||
long startTime = prefs.getLong("startTime", 0);
|
|
||||||
|
|
||||||
StringBuilder info = new StringBuilder();
|
StringBuilder info = new StringBuilder();
|
||||||
info.append("Random Crash Mode Active\n\n");
|
info.append("Random Crash Mode Active\n\n");
|
||||||
@@ -492,49 +454,6 @@ public class BadBehaviorActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkAndResumeRandomMode() {
|
|
||||||
SharedPreferences prefs = getSharedPreferences("BadBehaviorPrefs", Context.MODE_PRIVATE);
|
|
||||||
boolean wasRandomActive = prefs.getBoolean("isRandomActive", false);
|
|
||||||
|
|
||||||
if (wasRandomActive) {
|
|
||||||
String frequency = prefs.getString("frequency", "");
|
|
||||||
long startTime = prefs.getLong("startTime", 0);
|
|
||||||
|
|
||||||
// Check if we should still be in random mode (e.g., within 24 hours)
|
|
||||||
long elapsedHours = (System.currentTimeMillis() - startTime) / (1000 * 60 * 60);
|
|
||||||
if (elapsedHours < 24 && !frequency.isEmpty()) {
|
|
||||||
Log.d(TAG, "Resuming random mode after restart: " + frequency);
|
|
||||||
|
|
||||||
// Update UI to reflect active state
|
|
||||||
isRandomModeActive = true;
|
|
||||||
binding.btnStartRandom.setEnabled(false);
|
|
||||||
binding.btnStopRandom.setEnabled(true);
|
|
||||||
binding.btnTriggerCrash.setEnabled(false);
|
|
||||||
binding.btnTriggerAnr.setEnabled(false);
|
|
||||||
|
|
||||||
// Set the spinner to the saved frequency
|
|
||||||
ArrayAdapter<String> adapter = (ArrayAdapter<String>) binding.spinnerFrequency.getAdapter();
|
|
||||||
int position = adapter.getPosition(frequency);
|
|
||||||
if (position >= 0) {
|
|
||||||
binding.spinnerFrequency.setSelection(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resume scheduling with a shorter initial delay after crash
|
|
||||||
long delayMillis = Math.min(10000, getDelayMillis(frequency)); // 10 seconds or normal delay, whichever is shorter
|
|
||||||
scheduleRandomBehavior(delayMillis);
|
|
||||||
|
|
||||||
// Show notification again
|
|
||||||
showRandomModeNotification(frequency);
|
|
||||||
|
|
||||||
Toast.makeText(this, "Random mode resumed", Toast.LENGTH_SHORT).show();
|
|
||||||
} else {
|
|
||||||
// Clear stale random mode
|
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
|
||||||
editor.putBoolean("isRandomActive", false);
|
|
||||||
editor.apply();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inner class for slow service
|
// Inner class for slow service
|
||||||
public static class SlowService extends android.app.Service {
|
public static class SlowService extends android.app.Service {
|
||||||
|
|||||||
@@ -155,7 +155,7 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="⚠️ IMPORTANT: Crashes/ANRs only occur when app is in foreground!\n• Keep this screen open for tests to work\n• Random mode: crashes only (no ANRs) for unattended testing\n• Random mode: interferes with ALL other tests\n• App auto-restarts after crashes\n• Random mode stops after 24 hours"
|
android:text="⚠️ IMPORTANT: Crashes/ANRs only occur when app is in foreground!\n• Keep this screen open for tests to work\n• Random mode: crashes only (no ANRs) for unattended testing\n• Random mode: interferes with ALL other tests\n• App will NOT auto-restart after crashes\n• Random mode stops when the app crashes"
|
||||||
android:textSize="12sp"
|
android:textSize="12sp"
|
||||||
android:textColor="@android:color/holo_red_dark"
|
android:textColor="@android:color/holo_red_dark"
|
||||||
android:layout_marginTop="8dp" />
|
android:layout_marginTop="8dp" />
|
||||||
|
|||||||
Reference in New Issue
Block a user