diff --git a/app/src/androidTest/java/com/nextcloud/client/FileDisplayActivityIT.kt b/app/src/androidTest/java/com/nextcloud/client/FileDisplayActivityIT.kt index 73b985d8eeff..8beb926824e9 100644 --- a/app/src/androidTest/java/com/nextcloud/client/FileDisplayActivityIT.kt +++ b/app/src/androidTest/java/com/nextcloud/client/FileDisplayActivityIT.kt @@ -26,7 +26,6 @@ import androidx.test.espresso.Espresso import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.action.ViewActions.closeSoftKeyboard -import androidx.test.espresso.action.ViewActions.scrollTo import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.contrib.DrawerActions import androidx.test.espresso.contrib.NavigationViewActions @@ -241,7 +240,6 @@ class FileDisplayActivityIT : AbstractOnServerIT() { // browse into folder onView(withId(R.id.list_root)) - .perform(scrollTo()) .perform(closeSoftKeyboard()) .perform( RecyclerViewActions.actionOnItemAtPosition( diff --git a/app/src/androidTest/java/com/owncloud/android/UploadIT.java b/app/src/androidTest/java/com/owncloud/android/UploadIT.java index 7b86de769169..f9e23bf498c4 100644 --- a/app/src/androidTest/java/com/owncloud/android/UploadIT.java +++ b/app/src/androidTest/java/com/owncloud/android/UploadIT.java @@ -460,7 +460,7 @@ public void testMetadata() throws IOException, AccountUtils.AccountNotFoundExcep testOnlyOnServer(NextcloudVersion.nextcloud_27); File file = getFile("gps.jpg"); - String remotePath = "/gps.jpg"; + String remotePath = "/metadata.jpg"; OCUpload ocUpload = new OCUpload(file.getAbsolutePath(), remotePath, account.name); assertTrue( @@ -497,7 +497,7 @@ public void testMetadata() throws IOException, AccountUtils.AccountNotFoundExcep OCFile ocFile = null; for (OCFile f : files) { - if (f.getFileName().equals("gps.jpg")) { + if (f.getFileName().equals("metadata.jpg")) { ocFile = f; break; } @@ -505,8 +505,8 @@ public void testMetadata() throws IOException, AccountUtils.AccountNotFoundExcep assertNotNull(ocFile); assertEquals(remotePath, ocFile.getRemotePath()); - assertEquals(new ImageDimension(300f, 200f), ocFile.getImageDimension()); assertEquals(new GeoLocation(64, -46), ocFile.getGeoLocation()); + assertEquals(new ImageDimension(300f, 200f), ocFile.getImageDimension()); } private void verifyStoragePath(OCFile file) { diff --git a/app/src/main/java/com/nextcloud/android/sso/InputStreamBinder.java b/app/src/main/java/com/nextcloud/android/sso/InputStreamBinder.java index fa8a8edf3cdf..55002bffbd2d 100644 --- a/app/src/main/java/com/nextcloud/android/sso/InputStreamBinder.java +++ b/app/src/main/java/com/nextcloud/android/sso/InputStreamBinder.java @@ -457,16 +457,23 @@ private Response processRequestV2(final NextcloudRequest request, final InputStr } private boolean isValid(NextcloudRequest request) { - String callingPackageName = context.getPackageManager().getNameForUid(Binder.getCallingUid()); + String[] callingPackageNames = context.getPackageManager().getPackagesForUid(Binder.getCallingUid()); SharedPreferences sharedPreferences = context.getSharedPreferences(SSO_SHARED_PREFERENCE, Context.MODE_PRIVATE); - String hash = sharedPreferences.getString(callingPackageName + DELIMITER + request.getAccountName(), ""); - return validateToken(hash, request.getToken()); + for (String callingPackageName : callingPackageNames) { + String hash = sharedPreferences.getString(callingPackageName + DELIMITER + request.getAccountName(), ""); + if (hash.isEmpty()) + continue; + if (validateToken(hash, request.getToken())) { + return true; + } + } + return false; } private boolean validateToken(String hash, String token) { - if (hash.isEmpty() || !hash.contains("$")) { + if (!hash.contains("$")) { throw new IllegalStateException(EXCEPTION_INVALID_TOKEN); } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/CopyToClipboardActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/CopyToClipboardActivity.kt similarity index 65% rename from app/src/main/java/com/owncloud/android/ui/activity/CopyToClipboardActivity.java rename to app/src/main/java/com/owncloud/android/ui/activity/CopyToClipboardActivity.kt index 16bdab55a069..197a0b97a3cd 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/CopyToClipboardActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/CopyToClipboardActivity.kt @@ -18,26 +18,20 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +package com.owncloud.android.ui.activity -package com.owncloud.android.ui.activity; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; - -import com.owncloud.android.utils.ClipboardUtil; +import android.app.Activity +import android.content.Intent +import android.os.Bundle +import com.owncloud.android.utils.ClipboardUtil /** * Activity copying the text of the received Intent into the system clipboard. */ -public class CopyToClipboardActivity extends Activity { - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - ClipboardUtil.copyToClipboard(this, getIntent().getCharSequenceExtra(Intent.EXTRA_TEXT).toString()); - - finish(); +class CopyToClipboardActivity : Activity() { + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + ClipboardUtil.copyToClipboard(this, intent.getCharSequenceExtra(Intent.EXTRA_TEXT).toString()) + finish() } } diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java index f299a1470eab..f1c71f112f07 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java @@ -91,7 +91,6 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda private static final String ARG_FILE = "FILE"; private static final String ARG_USER = "USER"; - public static final int PERMISSION_EDITING_ALLOWED = 17; private OCFile file; private User user; @@ -128,8 +127,8 @@ public void onCreate(@Nullable Bundle savedInstanceState) { } else { Bundle arguments = getArguments(); if (arguments != null) { - file = getArguments().getParcelable(ARG_FILE); - user = getArguments().getParcelable(ARG_USER); + file = arguments.getParcelable(ARG_FILE); + user = arguments.getParcelable(ARG_USER); } } @@ -159,12 +158,11 @@ public void onActivityCreated(Bundle savedInstanceState) { @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { binding = FileDetailsSharingFragmentBinding.inflate(inflater, container, false); - View view = binding.getRoot(); fileOperationsHelper = fileActivity.getFileOperationsHelper(); fileDataStorageManager = fileActivity.getStorageManager(); - AccountManager accountManager = AccountManager.get(getContext()); + AccountManager accountManager = AccountManager.get(requireContext()); String userId = accountManager.getUserData(user.toPlatformAccount(), com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID); @@ -175,13 +173,14 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, user, viewThemeUtils, file.isEncrypted())); - binding.sharesList.setLayoutManager(new LinearLayoutManager(getContext())); + + binding.sharesList.setLayoutManager(new LinearLayoutManager(requireContext())); binding.pickContactEmailBtn.setOnClickListener(v -> checkContactPermission()); setupView(); - return view; + return binding.getRoot(); } @Override @@ -229,9 +228,7 @@ private void setupView() { private void disableSearchView(View view) { view.setEnabled(false); - if (view instanceof ViewGroup) { - ViewGroup viewGroup = (ViewGroup) view; - + if (view instanceof ViewGroup viewGroup) { for (int i = 0; i < viewGroup.getChildCount(); i++) { disableSearchView(viewGroup.getChildAt(i)); } @@ -315,7 +312,7 @@ public void copyLink(OCShare share) { if (TextUtils.isEmpty(share.getShareLink())) { fileOperationsHelper.getFileWithLink(file, viewThemeUtils); } else { - ClipboardUtil.copyToClipboard(getActivity(), share.getShareLink()); + ClipboardUtil.copyToClipboard(requireActivity(), share.getShareLink()); } } } @@ -555,7 +552,7 @@ private boolean isReshareForbidden(OCShare share) { @VisibleForTesting public void search(String query) { - SearchView searchView = getView().findViewById(R.id.searchView); + SearchView searchView = requireView().findViewById(R.id.searchView); searchView.setQuery(query, true); } diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailsSharingProcessFragment.kt b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailsSharingProcessFragment.kt index 43036e056011..4c6d72573fac 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailsSharingProcessFragment.kt +++ b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailsSharingProcessFragment.kt @@ -545,7 +545,7 @@ class FileDetailsSharingProcessFragment : ) // copy the share link if available if (!TextUtils.isEmpty(share?.shareLink)) { - ClipboardUtil.copyToClipboard(activity, share?.shareLink) + ClipboardUtil.copyToClipboard(requireActivity(), share?.shareLink) } } diff --git a/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.java b/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt similarity index 51% rename from app/src/main/java/com/owncloud/android/utils/ClipboardUtil.java rename to app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt index 8c6f62756773..073122765321 100644 --- a/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.java +++ b/app/src/main/java/com/owncloud/android/utils/ClipboardUtil.kt @@ -17,51 +17,46 @@ * You should have received a copy of the GNU Affero General Public * License along with this program. If not, see . */ +package com.owncloud.android.utils -package com.owncloud.android.utils; - -import android.app.Activity; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.text.TextUtils; -import android.widget.Toast; - -import com.owncloud.android.R; -import com.owncloud.android.lib.common.utils.Log_OC; +import android.app.Activity +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.text.TextUtils +import android.widget.Toast +import com.owncloud.android.R +import com.owncloud.android.lib.common.utils.Log_OC /** * Helper implementation to copy a string into the system clipboard. */ -public final class ClipboardUtil { - private static final String TAG = ClipboardUtil.class.getName(); - - private ClipboardUtil() { - } +object ClipboardUtil { + private val TAG = ClipboardUtil::class.java.name - public static void copyToClipboard(Activity activity, String text) { - copyToClipboard(activity, text, true); - } - - public static void copyToClipboard(Activity activity, String text, boolean showToast) { + @JvmStatic + @JvmOverloads + @Suppress("TooGenericExceptionCaught") + fun copyToClipboard(activity: Activity, text: String?, showToast: Boolean = true) { if (!TextUtils.isEmpty(text)) { try { - ClipData clip = ClipData.newPlainText( - activity.getString( - R.string.clipboard_label, activity.getString(R.string.app_name)), - text - ); - ((ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(clip); - + val clip = ClipData.newPlainText( + activity.getString( + R.string.clipboard_label, + activity.getString(R.string.app_name) + ), + text + ) + (activity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).setPrimaryClip(clip) if (showToast) { - Toast.makeText(activity, R.string.clipboard_text_copied, Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, R.string.clipboard_text_copied, Toast.LENGTH_SHORT).show() } - } catch (Exception e) { - Toast.makeText(activity, R.string.clipboard_unexpected_error, Toast.LENGTH_SHORT).show(); - Log_OC.e(TAG, "Exception caught while copying to clipboard", e); + } catch (e: Exception) { + Toast.makeText(activity, R.string.clipboard_unexpected_error, Toast.LENGTH_SHORT).show() + Log_OC.e(TAG, "Exception caught while copying to clipboard", e) } } else { - Toast.makeText(activity, R.string.clipboard_no_text_to_copy, Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, R.string.clipboard_no_text_to_copy, Toast.LENGTH_SHORT).show() } } }