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

Power saving crash #14002

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/
package com.nextcloud.client;

import android.app.Activity;
import android.content.Intent;
import android.os.Looper;

import com.nextcloud.client.preferences.SubFolderRule;
import com.owncloud.android.AbstractIT;
Expand All @@ -25,6 +25,7 @@

import java.util.Objects;

import androidx.appcompat.app.AlertDialog;
import androidx.test.espresso.intent.rule.IntentsTestRule;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
Expand Down Expand Up @@ -78,4 +79,24 @@ public void testSyncedFolderDialog() {

screenshot(Objects.requireNonNull(sut.requireDialog().getWindow()).getDecorView());
}

@Test
@ScreenshotTest
public void showPowerCheckDialog() {
if (Looper.myLooper() == null) {
Looper.prepare();
}

Intent intent = new Intent(targetContext, SyncedFoldersActivity.class);
SyncedFoldersActivity activity = activityRule.launchActivity(intent);

AlertDialog sut = activity.buildPowerCheckDialog();

activity.runOnUiThread(sut::show);

getInstrumentation().waitForIdleSync();
shortSleep();

screenshot(Objects.requireNonNull(sut.getWindow()).getDecorView());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.text.TextUtils
import android.view.Menu
import android.view.MenuItem
import android.view.View
import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AlertDialog
import androidx.drawerlayout.widget.DrawerLayout
import androidx.lifecycle.Lifecycle
Expand All @@ -31,7 +32,6 @@ import com.nextcloud.client.di.Injectable
import com.nextcloud.client.jobs.MediaFoldersDetectionWork
import com.nextcloud.client.jobs.NotificationWork
import com.nextcloud.client.jobs.upload.FileUploadWorker
import com.nextcloud.client.preferences.AppPreferences
import com.nextcloud.client.preferences.SubFolderRule
import com.nextcloud.utils.extensions.getParcelableArgument
import com.nextcloud.utils.extensions.isDialogFragmentReady
Expand All @@ -56,7 +56,6 @@ import com.owncloud.android.ui.dialog.SyncedFolderPreferencesDialogFragment.OnSy
import com.owncloud.android.ui.dialog.parcel.SyncedFolderParcelable
import com.owncloud.android.utils.PermissionUtil
import com.owncloud.android.utils.SyncedFolderUtils
import com.owncloud.android.utils.theme.ViewThemeUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -135,18 +134,12 @@ class SyncedFoldersActivity :
}
}

@Inject
lateinit var preferences: AppPreferences

@Inject
lateinit var powerManagementService: PowerManagementService

@Inject
lateinit var clock: Clock

@Inject
lateinit var viewThemeUtils: ViewThemeUtils

@Inject
lateinit var syncedFolderProvider: SyncedFolderProvider

Expand Down Expand Up @@ -221,16 +214,20 @@ class SyncedFoldersActivity :
return true
}

private fun showPowerCheckDialog() {
fun buildPowerCheckDialog(): AlertDialog {
val builder = MaterialAlertDialogBuilder(this)
.setView(R.id.root_layout)
.setPositiveButton(R.string.common_ok) { dialog, _ -> dialog.dismiss() }
.setTitle(R.string.autoupload_disable_power_save_check)
.setMessage(getString(R.string.power_save_check_dialog_message))

viewThemeUtils.dialog.colorMaterialAlertDialogBackground(this, builder)

builder.create().show()
return builder.create()
}

@VisibleForTesting
fun showPowerCheckDialog() {
buildPowerCheckDialog().show()
}

/**
Expand Down Expand Up @@ -636,6 +633,7 @@ class SyncedFoldersActivity :
binding.emptyList.emptyListIcon.visibility = View.VISIBLE
}

@Deprecated("Deprecated in Java")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == SyncedFolderPreferencesDialogFragment.REQUEST_CODE__SELECT_REMOTE_FOLDER &&
resultCode == RESULT_OK && dialogFragment != null
Expand Down
Loading