Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasKaminsky committed Nov 23, 2023
2 parents 0844fe8 + 6d0566f commit 7cc7086
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -241,7 +240,6 @@ class FileDisplayActivityIT : AbstractOnServerIT() {

// browse into folder
onView(withId(R.id.list_root))
.perform(scrollTo())
.perform(closeSoftKeyboard())
.perform(
RecyclerViewActions.actionOnItemAtPosition<OCFileListItemViewHolder>(
Expand Down
6 changes: 3 additions & 3 deletions app/src/androidTest/java/com/owncloud/android/UploadIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -497,16 +497,16 @@ 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;
}
}

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) {
Expand Down
15 changes: 11 additions & 4 deletions app/src/main/java/com/nextcloud/android/sso/InputStreamBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,20 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);

Expand All @@ -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
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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());
}
}
}
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,46 @@
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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()
}
}
}

0 comments on commit 7cc7086

Please sign in to comment.