|
11 | 11 | * SPDX-FileCopyrightText: 2014 Jorge Antonio Diaz-Benito Soriano <jorge.diazbenitosoriano@gmail.com> |
12 | 12 | * SPDX-FileCopyrightText: 2014-2016 Juan Carlos González Cabrero <malkomich@gmail.com> |
13 | 13 | * SPDX-FileCopyrightText: 2014 jabarros <jabarros@solidgear.es> |
| 14 | + * SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com> |
14 | 15 | * SPDX-License-Identifier: MIT |
15 | 16 | */ |
16 | 17 | package com.owncloud.android.lib.common.operations; |
17 | 18 |
|
18 | 19 | import android.accounts.Account; |
19 | 20 | import android.accounts.AccountsException; |
| 21 | +import android.content.Context; |
20 | 22 | import android.os.Build; |
21 | 23 | import android.system.ErrnoException; |
22 | 24 | import android.system.OsConstants; |
23 | 25 |
|
| 26 | +import androidx.annotation.NonNull; |
| 27 | + |
24 | 28 | import com.nextcloud.common.OkHttpMethodBase; |
| 29 | +import com.owncloud.android.lib.R; |
25 | 30 | import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; |
26 | 31 | import com.owncloud.android.lib.common.network.CertificateCombinedException; |
27 | 32 | import com.owncloud.android.lib.common.utils.Log_OC; |
@@ -576,6 +581,8 @@ private CertificateCombinedException getCertificateCombinedException(Exception e |
576 | 581 | return result; |
577 | 582 | } |
578 | 583 |
|
| 584 | + // use getLogMessage(Context) |
| 585 | + @Deprecated |
579 | 586 | public String getLogMessage() { |
580 | 587 |
|
581 | 588 | if (mException != null) { |
@@ -670,6 +677,100 @@ public String getLogMessage() { |
670 | 677 |
|
671 | 678 | } |
672 | 679 |
|
| 680 | + public String getLogMessage(@NonNull Context context) { |
| 681 | + |
| 682 | + if (mException != null) { |
| 683 | + if (mException instanceof OperationCancelledException) { |
| 684 | + return context.getString(R.string.operation_cancelled); |
| 685 | + |
| 686 | + } else if (mException instanceof SocketException) { |
| 687 | + return context.getString(R.string.socket_exception); |
| 688 | + |
| 689 | + } else if (mException instanceof SocketTimeoutException) { |
| 690 | + return context.getString(R.string.socket_timeout_exception); |
| 691 | + |
| 692 | + } else if (mException instanceof ConnectTimeoutException) { |
| 693 | + return context.getString(R.string.connect_timeout_exception); |
| 694 | + |
| 695 | + } else if (mException instanceof MalformedURLException) { |
| 696 | + return context.getString(R.string.malformed_url_exception); |
| 697 | + |
| 698 | + } else if (mException instanceof UnknownHostException) { |
| 699 | + return context.getString(R.string.unknown_host_exception); |
| 700 | + |
| 701 | + } else if (mException instanceof CertificateCombinedException) { |
| 702 | + if (((CertificateCombinedException) mException).isRecoverable()) { |
| 703 | + return context.getString(R.string.ssl_recoverable_exception); |
| 704 | + } else { |
| 705 | + return context.getString(R.string.ssl_exception); |
| 706 | + } |
| 707 | + |
| 708 | + } else if (mException instanceof SSLException) { |
| 709 | + return context.getString(R.string.ssl_exception); |
| 710 | + |
| 711 | + } else if (mException instanceof DavException) { |
| 712 | + return context.getString(R.string.unexpected_webdav_exception); |
| 713 | + |
| 714 | + } else if (mException instanceof HttpException) { |
| 715 | + return context.getString(R.string.http_violation); |
| 716 | + |
| 717 | + } else if (mException instanceof IOException) { |
| 718 | + return context.getString(R.string.unrecovered_transport_exception); |
| 719 | + |
| 720 | + } else if (mException instanceof AccountNotFoundException) { |
| 721 | + Account failedAccount = ((AccountNotFoundException) mException).getFailedAccount(); |
| 722 | + return mException.getMessage() + " (" + |
| 723 | + (failedAccount != null ? failedAccount.name : "NULL") + ")"; |
| 724 | + |
| 725 | + } else if (mException instanceof AccountsException) { |
| 726 | + return context.getString(R.string.exception_using_account); |
| 727 | + |
| 728 | + } else if (mException instanceof JSONException) { |
| 729 | + return context.getString(R.string.json_exception); |
| 730 | + |
| 731 | + } else { |
| 732 | + return context.getString(R.string.unexpected_exception); |
| 733 | + } |
| 734 | + } |
| 735 | + |
| 736 | + if (mCode == ResultCode.INSTANCE_NOT_CONFIGURED) { |
| 737 | + return context.getString(R.string.instance_not_configured); |
| 738 | + |
| 739 | + } else if (mCode == ResultCode.NO_NETWORK_CONNECTION) { |
| 740 | + return context.getString(R.string.no_network_connection); |
| 741 | + |
| 742 | + } else if (mCode == ResultCode.BAD_OC_VERSION) { |
| 743 | + return context.getString(R.string.bad_oc_version); |
| 744 | + |
| 745 | + } else if (mCode == ResultCode.LOCAL_STORAGE_FULL) { |
| 746 | + return context.getString(R.string.local_storage_full); |
| 747 | + |
| 748 | + } else if (mCode == ResultCode.LOCAL_STORAGE_NOT_MOVED) { |
| 749 | + return context.getString(R.string.local_storage_not_moved); |
| 750 | + |
| 751 | + } else if (mCode == ResultCode.ACCOUNT_NOT_NEW) { |
| 752 | + return context.getString(R.string.account_not_new); |
| 753 | + |
| 754 | + } else if (mCode == ResultCode.ACCOUNT_NOT_THE_SAME) { |
| 755 | + return context.getString(R.string.account_not_the_same); |
| 756 | + |
| 757 | + } else if (mCode == ResultCode.INVALID_CHARACTER_IN_NAME) { |
| 758 | + return context.getString(R.string.invalid_character_in_name); |
| 759 | + |
| 760 | + } else if (mCode == ResultCode.FILE_NOT_FOUND) { |
| 761 | + return context.getString(R.string.file_not_found); |
| 762 | + |
| 763 | + } else if (mCode == ResultCode.SYNC_CONFLICT) { |
| 764 | + return context.getString(R.string.sync_conflict); |
| 765 | + |
| 766 | + } else if (mCode == ResultCode.LOCKED) { |
| 767 | + return context.getString(R.string.file_locked); |
| 768 | + } |
| 769 | + |
| 770 | + return context.getString(R.string.operation_finished_http_code, mHttpCode, isSuccess() ? "success" : "fail"); |
| 771 | + } |
| 772 | + |
| 773 | + |
673 | 774 | public boolean isServerFail() { |
674 | 775 | return (mHttpCode >= HttpStatus.SC_INTERNAL_SERVER_ERROR); |
675 | 776 | } |
|
0 commit comments