|
| 1 | +/** |
| 2 | + * ownCloud Android client application |
| 3 | + * |
| 4 | + * @author Jesus Recio Rincon |
| 5 | + * |
| 6 | + * Copyright (C) 2026 ownCloud GmbH. |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU General Public License version 2, |
| 10 | + * as published by the Free Software Foundation. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +package com.owncloud.android.test |
| 22 | + |
| 23 | +import android.content.ContentProvider |
| 24 | +import android.content.ContentValues |
| 25 | +import android.content.Context |
| 26 | +import android.database.Cursor |
| 27 | +import android.net.Uri |
| 28 | +import android.os.Bundle |
| 29 | +import androidx.core.content.edit |
| 30 | + |
| 31 | +/** |
| 32 | + * |
| 33 | + * A ContentProvider used only in the QA flavor to allow |
| 34 | + * external test tools (E2E tests for automation) to modify |
| 35 | + * SharedPreferences at runtime. |
| 36 | + * |
| 37 | + * This provider is NOT intended for production usage. |
| 38 | + */ |
| 39 | +class TestPreferencesProvider : ContentProvider() { |
| 40 | + |
| 41 | + override fun onCreate(): Boolean = true |
| 42 | + |
| 43 | + override fun call( |
| 44 | + method: String, |
| 45 | + arg: String?, |
| 46 | + extras: Bundle? |
| 47 | + ): Bundle { |
| 48 | + |
| 49 | + val prefs = context?.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) |
| 50 | + if (method == SET_BOOLEAN) { |
| 51 | + prefs?.edit { |
| 52 | + arg?.let { setting -> |
| 53 | + extras?.let { extra -> |
| 54 | + putBoolean(setting, extra.getBoolean("value")) |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + return Bundle() |
| 60 | + } |
| 61 | + |
| 62 | + override fun query( |
| 63 | + uri: Uri, projection: Array<out String>?, |
| 64 | + selection: String?, selectionArgs: Array<out String>?, |
| 65 | + sortOrder: String? |
| 66 | + ): Cursor? = null |
| 67 | + |
| 68 | + override fun insert(uri: Uri, values: ContentValues?): Uri? = null |
| 69 | + |
| 70 | + override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 0 |
| 71 | + |
| 72 | + override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?): Int = 0 |
| 73 | + |
| 74 | + override fun getType(uri: Uri): String? = null |
| 75 | + |
| 76 | + companion object { |
| 77 | + private const val SET_BOOLEAN = "set_boolean" |
| 78 | + private const val PREFS_NAME = "com.owncloud.android_preferences" |
| 79 | + } |
| 80 | +} |
0 commit comments