Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dev
Browse files Browse the repository at this point in the history
tobiasKaminsky committed Dec 22, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
2 parents 02058b6 + 5fb9115 commit 05d3716
Showing 44 changed files with 891 additions and 515 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
@@ -24,14 +24,18 @@ jobs:
run: |
if [ -z "$GITHUB_HEAD_REF" ]; then
# push
echo "branch=$GITHUB_REF_NAME" >> "$GITHUB_OUTPUT"
echo "pr=$GITHUB_RUN_ID" >> "$GITHUB_OUTPUT"
echo "repo=${{ github.repository }}" >> "$GITHUB_OUTPUT"
{
echo "branch=$GITHUB_REF_NAME"
echo "pr=$GITHUB_RUN_ID"
echo "repo=${{ github.repository }}"
} >> "$GITHUB_OUTPUT"
else
# pull request
echo "branch=$GITHUB_HEAD_REF" >> "$GITHUB_OUTPUT"
echo "pr=${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT"
echo "repo=${{ github.event.pull_request.head.repo.full_name }}" >> "$GITHUB_OUTPUT"
{
echo "branch=$GITHUB_HEAD_REF"
echo "pr=${{ github.event.pull_request.number }}"
echo "repo=${{ github.event.pull_request.head.repo.full_name }}"
} >> "$GITHUB_OUTPUT"
fi
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
@@ -49,6 +53,6 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p $HOME/.gradle
echo "org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError" > $HOME/.gradle/gradle.properties
scripts/analysis/analysis-wrapper.sh ${{ steps.get-vars.outputs.branch }} ${{ secrets.LOG_USERNAME }} ${{ secrets.LOG_PASSWORD }} $GITHUB_RUN_NUMBER ${{ steps.get-vars.outputs.pr }}
mkdir -p "$HOME/.gradle"
echo "org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError" > "$HOME/.gradle/gradle.properties"
scripts/analysis/analysis-wrapper.sh ${{ steps.get-vars.outputs.branch }} ${{ secrets.LOG_USERNAME }} ${{ secrets.LOG_PASSWORD }} "$GITHUB_RUN_NUMBER" ${{ steps.get-vars.outputs.pr }}
1 change: 1 addition & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -26,3 +26,4 @@ jobs:
Please take a look again and update the issue with new details,
otherwise the issue will be automatically closed in 2 weeks. Thank you!
exempt-all-pr-milestones: true
labels-to-remove-when-unstale: 'needs info'
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ class BackgroundJobManagerTest {
clock = mock()
whenever(clock.currentTime).thenReturn(TIMESTAMP)
whenever(clock.currentDate).thenReturn(Date(TIMESTAMP))
backgroundJobManager = BackgroundJobManagerImpl(workManager, clock)
backgroundJobManager = BackgroundJobManagerImpl(workManager, clock, mock())
}

fun assertHasRequiredTags(tags: Set<String>, jobName: String, user: User? = null) {
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ import android.Manifest
import androidx.test.rule.GrantPermissionRule
import androidx.work.WorkManager
import com.nextcloud.client.core.ClockImpl
import com.nextcloud.client.preferences.AppPreferencesImpl
import com.nextcloud.test.RetryTestRule
import com.owncloud.android.AbstractIT
import com.owncloud.android.AbstractOnServerIT
@@ -43,7 +44,8 @@ import java.io.FileInputStream

class ContactsBackupIT : AbstractOnServerIT() {
val workmanager = WorkManager.getInstance(targetContext)
private val backgroundJobManager = BackgroundJobManagerImpl(workmanager, ClockImpl())
val preferences = AppPreferencesImpl.fromContext(targetContext)
private val backgroundJobManager = BackgroundJobManagerImpl(workmanager, ClockImpl(), preferences)

@get:Rule
val writeContactsRule = GrantPermissionRule.grant(Manifest.permission.WRITE_CONTACTS)
Original file line number Diff line number Diff line change
@@ -139,12 +139,10 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
val file = getDummyFile("chunkedFile.txt")

FileUploader.uploadNewFile(
targetContext,
user,
file.absolutePath,
"/testFile.txt",
FileUploader.LOCAL_BEHAVIOUR_COPY,
null,
true,
UploadFileOperation.CREATED_BY_USER,
false,
@@ -258,12 +256,10 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
val file = getDummyFile("nonEmpty.txt")

FileUploader.uploadNewFile(
targetContext,
user,
file.absolutePath,
"/testFile.txt",
FileUploader.LOCAL_BEHAVIOUR_COPY,
null,
true,
UploadFileOperation.CREATED_BY_USER,
false,
@@ -369,12 +365,10 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
val file = getDummyFile("chunkedFile.txt")

FileUploader.uploadNewFile(
targetContext,
user,
file.absolutePath,
"/testFile.txt",
FileUploader.LOCAL_BEHAVIOUR_COPY,
null,
true,
UploadFileOperation.CREATED_BY_USER,
false,
@@ -476,12 +470,10 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
val file = getDummyFile("chunkedFile.txt")

FileUploader.uploadNewFile(
targetContext,
user,
file.absolutePath,
"/testFile.txt",
FileUploader.LOCAL_BEHAVIOUR_COPY,
null,
true,
UploadFileOperation.CREATED_BY_USER,
false,
12 changes: 12 additions & 0 deletions app/src/main/java/com/nextcloud/client/di/ComponentsModule.java
Original file line number Diff line number Diff line change
@@ -23,8 +23,11 @@
import com.nextcloud.client.documentscan.DocumentScanActivity;
import com.nextcloud.client.editimage.EditImageActivity;
import com.nextcloud.client.etm.EtmActivity;
import com.nextcloud.client.etm.pages.EtmBackgroundJobsFragment;
import com.nextcloud.client.files.downloader.FileTransferService;
import com.nextcloud.client.jobs.BackgroundJobManagerImpl;
import com.nextcloud.client.jobs.NotificationWork;
import com.nextcloud.client.jobs.TestJob;
import com.nextcloud.client.logger.ui.LogsActivity;
import com.nextcloud.client.logger.ui.LogsViewModel;
import com.nextcloud.client.media.PlayerService;
@@ -478,4 +481,13 @@ abstract class ComponentsModule {

@ContributesAndroidInjector
abstract ImageDetailFragment imageDetailFragment();

@ContributesAndroidInjector
abstract EtmBackgroundJobsFragment etmBackgroundJobsFragment();

@ContributesAndroidInjector
abstract BackgroundJobManagerImpl backgroundJobManagerImpl();

@ContributesAndroidInjector
abstract TestJob testJob();
}
Original file line number Diff line number Diff line change
@@ -36,7 +36,6 @@ import com.owncloud.android.files.services.FileUploader
import com.owncloud.android.files.services.NameCollisionPolicy
import com.owncloud.android.operations.UploadFileOperation
import com.owncloud.android.ui.helpers.FileOperationsHelper
import com.owncloud.android.utils.MimeType
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -184,16 +183,10 @@ class DocumentScanViewModel @Inject constructor(
uploadFolder + OCFile.PATH_SEPARATOR + File(it).name
}.toTypedArray()

val mimetypes = pageList.map {
MimeType.JPEG
}.toTypedArray()

FileUploader.uploadNewFile(
getApplication(),
currentAccountProvider.user,
pageList.toTypedArray(),
uploadPaths,
mimetypes,
FileUploader.LOCAL_BEHAVIOUR_DELETE,
true,
UploadFileOperation.CREATED_BY_USER,
Original file line number Diff line number Diff line change
@@ -39,7 +39,6 @@ import com.owncloud.android.files.services.FileUploader
import com.owncloud.android.files.services.NameCollisionPolicy
import com.owncloud.android.operations.UploadFileOperation
import com.owncloud.android.ui.notifications.NotificationUtils
import com.owncloud.android.utils.MimeType
import com.owncloud.android.utils.theme.ViewThemeUtils
import java.io.File
import java.security.SecureRandom
@@ -124,12 +123,10 @@ class GeneratePdfFromImagesWork(
val uploadPath = uploadFolder + OCFile.PATH_SEPARATOR + File(pdfPath).name

FileUploader.uploadNewFile(
appContext,
user,
pdfPath,
uploadPath,
FileUploader.LOCAL_BEHAVIOUR_DELETE, // MIME type will be detected from file name
MimeType.PDF,
true,
UploadFileOperation.CREATED_BY_USER,
false,
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
*/
package com.nextcloud.client.etm.pages

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
@@ -32,15 +33,23 @@ import androidx.lifecycle.Observer
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.nextcloud.client.di.Injectable
import com.nextcloud.client.etm.EtmBaseFragment
import com.nextcloud.client.jobs.BackgroundJobManagerImpl
import com.nextcloud.client.jobs.JobInfo
import com.nextcloud.client.preferences.AppPreferences
import com.owncloud.android.R
import java.text.SimpleDateFormat
import java.util.Locale
import javax.inject.Inject

class EtmBackgroundJobsFragment : EtmBaseFragment() {
class EtmBackgroundJobsFragment : EtmBaseFragment(), Injectable {

class Adapter(private val inflater: LayoutInflater) : RecyclerView.Adapter<Adapter.ViewHolder>() {
@Inject
lateinit var preferences: AppPreferences

class Adapter(private val inflater: LayoutInflater, private val preferences: AppPreferences) :
RecyclerView.Adapter<Adapter.ViewHolder>() {

class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val uuid = view.findViewById<TextView>(R.id.etm_background_job_uuid)
@@ -50,6 +59,10 @@ class EtmBackgroundJobsFragment : EtmBaseFragment() {
val started = view.findViewById<TextView>(R.id.etm_background_job_started)
val progress = view.findViewById<TextView>(R.id.etm_background_job_progress)
private val progressRow = view.findViewById<View>(R.id.etm_background_job_progress_row)
val executionCount = view.findViewById<TextView>(R.id.etm_background_execution_count)
val executionLog = view.findViewById<TextView>(R.id.etm_background_execution_logs)
private val executionLogRow = view.findViewById<View>(R.id.etm_background_execution_logs_row)
val executionTimesRow = view.findViewById<View>(R.id.etm_background_execution_times_row)

var progressEnabled: Boolean = progressRow.visibility == View.VISIBLE
get() {
@@ -63,6 +76,19 @@ class EtmBackgroundJobsFragment : EtmBaseFragment() {
View.GONE
}
}

var logsEnabled: Boolean = executionLogRow.visibility == View.VISIBLE
get() {
return executionLogRow.visibility == View.VISIBLE
}
set(value) {
field = value
executionLogRow.visibility = if (value) {
View.VISIBLE
} else {
View.GONE
}
}
}

private val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:MM:ssZ", Locale.getDefault())
@@ -74,13 +100,20 @@ class EtmBackgroundJobsFragment : EtmBaseFragment() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = inflater.inflate(R.layout.etm_background_job_list_item, parent, false)
return ViewHolder(view)
val viewHolder = ViewHolder(view)
viewHolder.logsEnabled = false
viewHolder.executionTimesRow.visibility = View.GONE
view.setOnClickListener {
viewHolder.logsEnabled = !viewHolder.logsEnabled
}
return viewHolder
}

override fun getItemCount(): Int {
return backgroundJobs.size
}

@SuppressLint("SetTextI18n")
override fun onBindViewHolder(vh: ViewHolder, position: Int) {
val info = backgroundJobs[position]
vh.uuid.text = info.id.toString()
@@ -94,6 +127,34 @@ class EtmBackgroundJobsFragment : EtmBaseFragment() {
} else {
vh.progressEnabled = false
}

val logs = preferences.readLogEntry()
val logsForThisWorker =
logs.filter { BackgroundJobManagerImpl.parseTag(it.workerClass)?.second == info.workerClass }
if (logsForThisWorker.isNotEmpty()) {
vh.executionTimesRow.visibility = View.VISIBLE
vh.executionCount.text =
"${logsForThisWorker.filter { it.started != null }.size} " +
"(${logsForThisWorker.filter { it.finished != null }.size})"
var logText = "Worker Logs\n\n" +
"*** Does NOT differentiate between immediate or periodic kinds of Work! ***\n" +
"*** Times run in 48h: Times started (Times finished) ***\n"
logsForThisWorker.forEach {
logText += "----------------------\n"
logText += "Worker ${BackgroundJobManagerImpl.parseTag(it.workerClass)?.second}\n"
logText += if (it.started == null) {
"ENDED at\n${it.finished}\nWith result: ${it.result}\n"
} else {
"STARTED at\n${it.started}\n"
}
}
vh.executionLog.text = logText
} else {
vh.executionLog.text = "Worker Logs\n\n" +
"No Entries -> Maybe logging is not implemented for Worker or it has not run yet."
vh.executionCount.text = "0"
vh.executionTimesRow.visibility = View.GONE
}
}
}

@@ -107,7 +168,7 @@ class EtmBackgroundJobsFragment : EtmBaseFragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_etm_background_jobs, container, false)
adapter = Adapter(inflater)
adapter = Adapter(inflater, preferences)
list = view.findViewById(R.id.etm_background_jobs_list)
list.layoutManager = LinearLayoutManager(context)
list.addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL))
@@ -127,22 +188,27 @@ class EtmBackgroundJobsFragment : EtmBaseFragment() {
vm.cancelAllJobs()
true
}

R.id.etm_background_jobs_prune -> {
vm.pruneJobs()
true
}

R.id.etm_background_jobs_start_test -> {
vm.startTestJob(periodic = false)
true
}

R.id.etm_background_jobs_schedule_test -> {
vm.startTestJob(periodic = true)
true
}

R.id.etm_background_jobs_cancel_test -> {
vm.cancelTestJob()
true
}

else -> super.onOptionsItemSelected(item)
}
}
Loading

0 comments on commit 05d3716

Please sign in to comment.