Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Nov 20, 2023
2 parents c20bf62 + 326d229 commit f61a70a
Show file tree
Hide file tree
Showing 17 changed files with 553 additions and 464 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
with:
swap-size-gb: 10
- name: Initialize CodeQL
uses: github/codeql-action/init@689fdc5193eeb735ecb2e52e819e3382876f93f4 # v2.22.6
uses: github/codeql-action/init@66b90a5db151a8042fa97405c6cf843bbe433f7b # v2.22.7
with:
languages: ${{ matrix.language }}
- name: Set up JDK 17
Expand All @@ -46,4 +46,4 @@ jobs:
echo "org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError" > "$HOME/.gradle/gradle.properties"
./gradlew assembleDebug
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@689fdc5193eeb735ecb2e52e819e3382876f93f4 # v2.22.6
uses: github/codeql-action/analyze@66b90a5db151a8042fa97405c6cf843bbe433f7b # v2.22.7
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@689fdc5193eeb735ecb2e52e819e3382876f93f4 # v2.22.6
uses: github/codeql-action/upload-sarif@66b90a5db151a8042fa97405c6cf843bbe433f7b # v2.22.7
with:
sarif_file: results.sarif
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ android {

defaultConfig {
minSdkVersion 24
targetSdkVersion 33
compileSdk 33
targetSdkVersion 34
compileSdk 34

buildConfigField 'boolean', 'CI', ciBuild.toString()
buildConfigField 'boolean', 'RUNTIME_PERF_ANALYSIS', perfAnalysis.toString()
Expand Down Expand Up @@ -246,7 +246,7 @@ dependencies {
implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.5' // remove after entire switch to lib v2
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.9.0'
implementation 'com.google.android.material:material:1.10.0'
implementation 'com.jakewharton:disklrucache:2.0.2'
implementation "androidx.appcompat:appcompat:$appCompatVersion"
implementation 'androidx.webkit:webkit:1.7.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class ActivitiesActivityIT : AbstractIT() {
sut.dismissSnackbar()
}

shortSleep()
longSleep()
waitForIdleSync()

screenshot(sut)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ abstract class NextcloudDatabase : RoomDatabase() {
INSTANCE = Room
.databaseBuilder(context, NextcloudDatabase::class.java, ProviderMeta.DB_NAME)
.allowMainThreadQueries()
.addLegacyMigrations(clock)
.addLegacyMigrations(clock, context)
.addMigrations(RoomMigration())
.addMigrations(Migration67to68())
.addMigrations(Migration70to71())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package com.nextcloud.client.database.migrations

import android.content.Context
import androidx.room.RoomDatabase
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
Expand All @@ -36,12 +37,13 @@ private const val MIN_SUPPORTED_DB_VERSION = 24
class LegacyMigration(
private val from: Int,
private val to: Int,
private val clock: Clock
private val clock: Clock,
private val context: Context
) : Migration(from, to) {

override fun migrate(database: SupportSQLiteDatabase) {
LegacyMigrationHelper(clock)
.onUpgrade(database, from, to)
LegacyMigrationHelper(clock, context)
.tryUpgrade(database, from, to)
}
}

Expand All @@ -52,10 +54,11 @@ class LegacyMigration(
*/
@Suppress("ForEachOnRange")
fun RoomDatabase.Builder<NextcloudDatabase>.addLegacyMigrations(
clock: Clock
clock: Clock,
context: Context
): RoomDatabase.Builder<NextcloudDatabase> {
(MIN_SUPPORTED_DB_VERSION until NextcloudDatabase.FIRST_ROOM_DB_VERSION - 1)
.map { from -> LegacyMigration(from, from + 1, clock) }
.map { from -> LegacyMigration(from, from + 1, clock, context) }
.forEach { migration -> this.addMigrations(migration) }
return this
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package com.nextcloud.client.database.migrations;

import android.app.ActivityManager;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
Expand All @@ -31,11 +32,11 @@
import com.owncloud.android.db.ProviderMeta;
import com.owncloud.android.files.services.NameCollisionPolicy;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.providers.FileContentProvider;

import java.util.Locale;

import androidx.sqlite.db.SupportSQLiteDatabase;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

public class LegacyMigrationHelper {

Expand All @@ -52,12 +53,29 @@ public class LegacyMigrationHelper {
private static final String UPGRADE_VERSION_MSG = "OUT of the ADD in onUpgrade; oldVersion == %d, newVersion == %d";

private final Clock clock;
private final Context context;

public LegacyMigrationHelper(Clock clock) {
public LegacyMigrationHelper(Clock clock, Context context) {
this.clock = clock;
this.context = context;
}

public void onUpgrade(SupportSQLiteDatabase db, int oldVersion, int newVersion) {
public void tryUpgrade(SupportSQLiteDatabase db, int oldVersion, int newVersion) {
try {
upgrade(db, oldVersion, newVersion);
} catch (Throwable t) {
Log_OC.i(TAG, "Migration upgrade failed due to " + t);
clearStorage();
}
}

@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
private void clearStorage() {
context.getCacheDir().delete();
((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).clearApplicationUserData();
}

private void upgrade(SupportSQLiteDatabase db, int oldVersion, int newVersion) {
Log_OC.i(TAG, "Entering in onUpgrade");
boolean upgraded = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import javax.inject.Inject;

import androidx.activity.OnBackPressedCallback;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
Expand Down Expand Up @@ -115,6 +116,8 @@ protected void onCreate(Bundle savedInstanceState) {
}
transaction.commit();
}

getOnBackPressedDispatcher().addCallback(this, onBackPressedCallback);
}

@Override
Expand All @@ -137,12 +140,14 @@ public void onTransferStateChanged(OCFile file, boolean downloading, boolean upl
// not needed
}

@Override
public void onBackPressed() {
if (getSupportFragmentManager().findFragmentByTag(BackupListFragment.TAG) != null) {
getSupportFragmentManager().popBackStack(BACKUP_TO_LIST, FragmentManager.POP_BACK_STACK_INCLUSIVE);
} else {
finish();
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
if (getSupportFragmentManager().findFragmentByTag(BackupListFragment.TAG) != null) {
getSupportFragmentManager().popBackStack(BACKUP_TO_LIST, FragmentManager.POP_BACK_STACK_INCLUSIVE);
} else {
finish();
}
}
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2507,8 +2507,7 @@ private void openFile(User user, String fileId) {
setUser(user);

if (fileId == null) {
dismissLoadingDialog();
DisplayUtils.showSnackMessage(this, getString(R.string.error_retrieving_file));
onFileRequestError(null);
return;
}

Expand All @@ -2529,8 +2528,7 @@ private void openFileByPath(User user, String filepath) {
setUser(user);

if (filepath == null) {
dismissLoadingDialog();
DisplayUtils.showSnackMessage(this, getString(R.string.error_retrieving_file));
onFileRequestError(null);
return;
}

Expand All @@ -2544,8 +2542,7 @@ private void openFileByPath(User user, String filepath) {
try {
client = clientFactory.create(user);
} catch (ClientFactory.CreationException e) {
dismissLoadingDialog();
DisplayUtils.showSnackMessage(this, getString(R.string.error_retrieving_file));
onFileRequestError(null);
return;
}

Expand All @@ -2554,9 +2551,17 @@ private void openFileByPath(User user, String filepath) {
client,
storageManager,
user);
asyncRunner.postQuickTask(getRemoteFileTask, this::onFileRequestResult, null);
asyncRunner.postQuickTask(getRemoteFileTask, this::onFileRequestResult, this::onFileRequestError);
}

private Unit onFileRequestError(Throwable throwable) {
dismissLoadingDialog();
DisplayUtils.showSnackMessage(this, getString(R.string.error_retrieving_file));
Log_OC.e(TAG, "Requesting file from remote failed!", throwable);
return null;
}


private Unit onFileRequestResult(GetRemoteFileTask.Result result) {
dismissLoadingDialog();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import android.view.ActionMode
import android.view.Menu
import android.view.MenuItem
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.google.android.material.button.MaterialButton
import com.nextcloud.client.di.Injectable
Expand Down Expand Up @@ -125,9 +126,33 @@ open class FolderPickerActivity :

// sets message for empty list of folders
setBackgroundText()

handleOnBackPressed()

Log_OC.d(TAG, "onCreate() end")
}

private fun handleOnBackPressed() {
onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
val listOfFiles = listOfFilesFragment
if (listOfFiles != null) {
// should never be null, indeed
val levelsUp = listOfFiles.onBrowseUp()
if (levelsUp == 0) {
finish()
return
}
file = listOfFiles.currentFile
updateUiElements()
}
}
}
)
}

override fun onActionModeStarted(mode: ActionMode) {
super.onActionModeStarted(mode)
if (account != null) {
Expand Down Expand Up @@ -321,20 +346,6 @@ open class FolderPickerActivity :
}
}

override fun onBackPressed() {
val listOfFiles = listOfFilesFragment
if (listOfFiles != null) {
// should never be null, indeed
val levelsUp = listOfFiles.onBrowseUp()
if (levelsUp == 0) {
finish()
return
}
file = listOfFiles.currentFile
updateUiElements()
}
}

private fun updateUiElements() {
toggleChooseEnabled()
updateNavigationElementsInActionBar()
Expand Down
Loading

0 comments on commit f61a70a

Please sign in to comment.