From 4435c200ede08bb8e38e781f5bbc7a63fc54d9d4 Mon Sep 17 00:00:00 2001 From: Tad Date: Tue, 4 Apr 2023 12:50:09 -0400 Subject: [PATCH] 15.1+: vCard 4.0 support from GrapheneOS https://github.com/GrapheneOS/platform_packages_apps_Contacts/commit/8fbeedd0023c8c007459b528b40204da31f7bfc9 Fixes https://github.com/Divested-Mobile/DivestOS-Build/issues/202 Signed-off-by: Tad --- .../0005-vCard-Four.patch | 160 ++++++++++++++++++ Scripts/LineageOS-16.0/Patch.sh | 1 + Scripts/LineageOS-17.1/Patch.sh | 1 + Scripts/LineageOS-18.1/Patch.sh | 1 + Scripts/LineageOS-19.1/Patch.sh | 1 + Scripts/LineageOS-20.0/Patch.sh | 1 + 6 files changed, 165 insertions(+) create mode 100644 Patches/Common/android_packages_apps_Contacts/0005-vCard-Four.patch diff --git a/Patches/Common/android_packages_apps_Contacts/0005-vCard-Four.patch b/Patches/Common/android_packages_apps_Contacts/0005-vCard-Four.patch new file mode 100644 index 00000000..c036f5a7 --- /dev/null +++ b/Patches/Common/android_packages_apps_Contacts/0005-vCard-Four.patch @@ -0,0 +1,160 @@ +From 8fbeedd0023c8c007459b528b40204da31f7bfc9 Mon Sep 17 00:00:00 2001 +From: June +Date: Sat, 19 Feb 2022 06:53:03 +0000 +Subject: [PATCH] Add basic support for vCard 4.0 + +Signed-off-by: June +--- + .../contacts/vcard/ImportProcessor.java | 14 +++++--- + .../contacts/vcard/ImportVCardActivity.java | 34 +++++++++++++++++-- + .../vcard/NfcImportVCardActivity.java | 18 ++++++++-- + 3 files changed, 57 insertions(+), 9 deletions(-) + +diff --git a/src/com/android/contacts/vcard/ImportProcessor.java b/src/com/android/contacts/vcard/ImportProcessor.java +index c6fcccb8c2..8eff2cc963 100644 +--- a/src/com/android/contacts/vcard/ImportProcessor.java ++++ b/src/com/android/contacts/vcard/ImportProcessor.java +@@ -30,6 +30,7 @@ + import com.android.vcard.VCardParser; + import com.android.vcard.VCardParser_V21; + import com.android.vcard.VCardParser_V30; ++import com.android.vcard.VCardParser_V40; + import com.android.vcard.exception.VCardException; + import com.android.vcard.exception.VCardNotSupportedException; + import com.android.vcard.exception.VCardVersionException; +@@ -135,7 +136,8 @@ private void runInternal() { + */ + possibleVCardVersions = new int[] { + ImportVCardActivity.VCARD_VERSION_V21, +- ImportVCardActivity.VCARD_VERSION_V30 ++ ImportVCardActivity.VCARD_VERSION_V30, ++ ImportVCardActivity.VCARD_VERSION_V40 + }; + } else { + possibleVCardVersions = new int[] { +@@ -231,9 +233,13 @@ private boolean readOneVCard(InputStream is, int vcardType, String charset, + // In the worst case, a user may call cancel() just before creating + // mVCardParser. + synchronized (this) { +- mVCardParser = (vcardVersion == ImportVCardActivity.VCARD_VERSION_V30 ? +- new VCardParser_V30(vcardType) : +- new VCardParser_V21(vcardType)); ++ if (vcardVersion == ImportVCardActivity.VCARD_VERSION_V30) { ++ mVCardParser = new VCardParser_V30(vcardType); ++ } else if (vcardVersion == ImportVCardActivity.VCARD_VERSION_V40) { ++ mVCardParser = new VCardParser_V40(vcardType); ++ } else { ++ mVCardParser = new VCardParser_V21(vcardType); ++ } + if (isCancelled()) { + Log.i(LOG_TAG, "ImportProcessor already recieves cancel request, so " + + "send cancel request to vCard parser too."); +diff --git a/src/com/android/contacts/vcard/ImportVCardActivity.java b/src/com/android/contacts/vcard/ImportVCardActivity.java +index 38367c40f9..71203d4ac1 100644 +--- a/src/com/android/contacts/vcard/ImportVCardActivity.java ++++ b/src/com/android/contacts/vcard/ImportVCardActivity.java +@@ -49,6 +49,7 @@ + import com.android.vcard.VCardParser; + import com.android.vcard.VCardParser_V21; + import com.android.vcard.VCardParser_V30; ++import com.android.vcard.VCardParser_V40; + import com.android.vcard.VCardSourceDetector; + import com.android.vcard.exception.VCardException; + import com.android.vcard.exception.VCardNestedException; +@@ -83,6 +84,7 @@ public class ImportVCardActivity extends Activity implements ImportVCardDialogFr + /* package */ final static int VCARD_VERSION_AUTO_DETECT = 0; + /* package */ final static int VCARD_VERSION_V21 = 1; + /* package */ final static int VCARD_VERSION_V30 = 2; ++ /* package */ final static int VCARD_VERSION_V40 = 3; + + private static final int REQUEST_OPEN_DOCUMENT = 100; + +@@ -321,6 +323,7 @@ private ImportRequest constructImportRequest(final byte[] data, + int vcardVersion = VCARD_VERSION_V21; + try { + boolean shouldUseV30 = false; ++ boolean shouldUseV40 = false; + InputStream is; + if (data != null) { + is = new ByteArrayInputStream(data); +@@ -354,7 +357,28 @@ private ImportRequest constructImportRequest(final byte[] data, + mVCardParser.addInterpreter(detector); + mVCardParser.parse(is); + } catch (VCardVersionException e2) { +- throw new VCardException("vCard with unspported version."); ++ try { ++ is.close(); ++ } catch (IOException e) { ++ } ++ ++ shouldUseV30 = false; ++ shouldUseV40 = true; ++ if (data != null) { ++ is = new ByteArrayInputStream(data); ++ } else { ++ is = resolver.openInputStream(localDataUri); ++ } ++ mVCardParser = new VCardParser_V40(); ++ try { ++ counter = new VCardEntryCounter(); ++ detector = new VCardSourceDetector(); ++ mVCardParser.addInterpreter(counter); ++ mVCardParser.addInterpreter(detector); ++ mVCardParser.parse(is); ++ } catch (VCardVersionException e3) { ++ throw new VCardException("vCard with unspported version."); ++ } + } + } finally { + if (is != null) { +@@ -365,7 +389,13 @@ private ImportRequest constructImportRequest(final byte[] data, + } + } + +- vcardVersion = shouldUseV30 ? VCARD_VERSION_V30 : VCARD_VERSION_V21; ++ if (shouldUseV30) { ++ vcardVersion = VCARD_VERSION_V30; ++ } else if (shouldUseV40) { ++ vcardVersion = VCARD_VERSION_V40; ++ } else { ++ vcardVersion = VCARD_VERSION_V21; ++ } + } catch (VCardNestedException e) { + Log.w(LOG_TAG, "Nested Exception is found (it may be false-positive)."); + // Go through without throwing the Exception, as we may be able to detect the +diff --git a/src/com/android/contacts/vcard/NfcImportVCardActivity.java b/src/com/android/contacts/vcard/NfcImportVCardActivity.java +index 88fa760356..f41e564463 100644 +--- a/src/com/android/contacts/vcard/NfcImportVCardActivity.java ++++ b/src/com/android/contacts/vcard/NfcImportVCardActivity.java +@@ -46,6 +46,7 @@ + import com.android.vcard.VCardParser; + import com.android.vcard.VCardParser_V21; + import com.android.vcard.VCardParser_V30; ++import com.android.vcard.VCardParser_V40; + import com.android.vcard.VCardSourceDetector; + import com.android.vcard.exception.VCardException; + import com.android.vcard.exception.VCardNestedException; +@@ -126,9 +127,20 @@ public void onPostExecute(ImportRequest request) { + parser.addInterpreter(detector); + parser.parse(is); + } catch (VCardVersionException e2) { +- FeedbackHelper.sendFeedback(this, TAG, "vcard with unsupported version", e2); +- showFailureNotification(R.string.fail_reason_not_supported); +- return null; ++ is.reset(); ++ vcardVersion = ImportVCardActivity.VCARD_VERSION_V40; ++ parser = new VCardParser_V40(); ++ try { ++ counter = new VCardEntryCounter(); ++ detector = new VCardSourceDetector(); ++ parser.addInterpreter(counter); ++ parser.addInterpreter(detector); ++ parser.parse(is); ++ } catch (VCardVersionException e3) { ++ FeedbackHelper.sendFeedback(this, TAG, "vcard with unsupported version", e2); ++ showFailureNotification(R.string.fail_reason_not_supported); ++ return null; ++ } + } + } finally { + try { diff --git a/Scripts/LineageOS-16.0/Patch.sh b/Scripts/LineageOS-16.0/Patch.sh index 5c90597d..b17b763d 100644 --- a/Scripts/LineageOS-16.0/Patch.sh +++ b/Scripts/LineageOS-16.0/Patch.sh @@ -264,6 +264,7 @@ if enterAndClear "packages/apps/Contacts"; then applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0001-No_Google_Links.patch"; #Remove Privacy Policy and Terms of Service links (GrapheneOS) applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0003-Skip_Accounts.patch"; #Don't prompt to add account when creating a contact (CalyxOS) applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0004-No_GMaps.patch"; #Use common intent for directions instead of Google Maps URL (GrapheneOS) +applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0005-vCard-Four.patch"; #Add basic support for vCard 4.0 (GrapheneOS) fi; if enterAndClear "packages/apps/Dialer"; then diff --git a/Scripts/LineageOS-17.1/Patch.sh b/Scripts/LineageOS-17.1/Patch.sh index 4a17805f..2bdc1152 100644 --- a/Scripts/LineageOS-17.1/Patch.sh +++ b/Scripts/LineageOS-17.1/Patch.sh @@ -290,6 +290,7 @@ applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0001-No_Google_Li applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0002-No_Google_Backup.patch"; #Backups are not sent to Google (GrapheneOS) applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0003-Skip_Accounts.patch"; #Don't prompt to add account when creating a contact (CalyxOS) applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0004-No_GMaps.patch"; #Use common intent for directions instead of Google Maps URL (GrapheneOS) +applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0005-vCard-Four.patch"; #Add basic support for vCard 4.0 (GrapheneOS) fi; if enterAndClear "packages/apps/Dialer"; then diff --git a/Scripts/LineageOS-18.1/Patch.sh b/Scripts/LineageOS-18.1/Patch.sh index 89b7e744..f3cad7b9 100644 --- a/Scripts/LineageOS-18.1/Patch.sh +++ b/Scripts/LineageOS-18.1/Patch.sh @@ -282,6 +282,7 @@ applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0001-No_Google_Li applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0002-No_Google_Backup.patch"; #Backups are not sent to Google (GrapheneOS) applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0003-Skip_Accounts.patch"; #Don't prompt to add account when creating a contact (CalyxOS) applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0004-No_GMaps.patch"; #Use common intent for directions instead of Google Maps URL (GrapheneOS) +applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0005-vCard-Four.patch"; #Add basic support for vCard 4.0 (GrapheneOS) fi; if enterAndClear "packages/apps/Dialer"; then diff --git a/Scripts/LineageOS-19.1/Patch.sh b/Scripts/LineageOS-19.1/Patch.sh index 9e5a7ff1..2121af30 100644 --- a/Scripts/LineageOS-19.1/Patch.sh +++ b/Scripts/LineageOS-19.1/Patch.sh @@ -268,6 +268,7 @@ applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0001-No_Google_Li applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0002-No_Google_Backup.patch"; #Backups are not sent to Google (GrapheneOS) applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0003-Skip_Accounts.patch"; #Don't prompt to add account when creating a contact (CalyxOS) applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0004-No_GMaps.patch"; #Use common intent for directions instead of Google Maps URL (GrapheneOS) +applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0005-vCard-Four.patch"; #Add basic support for vCard 4.0 (GrapheneOS) fi; if enterAndClear "packages/apps/Dialer"; then diff --git a/Scripts/LineageOS-20.0/Patch.sh b/Scripts/LineageOS-20.0/Patch.sh index 2cd9c214..73e6f564 100644 --- a/Scripts/LineageOS-20.0/Patch.sh +++ b/Scripts/LineageOS-20.0/Patch.sh @@ -274,6 +274,7 @@ applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0001-No_Google_Li applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0002-No_Google_Backup.patch"; #Backups are not sent to Google (GrapheneOS) applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0003-Skip_Accounts.patch"; #Don't prompt to add account when creating a contact (CalyxOS) applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0004-No_GMaps.patch"; #Use common intent for directions instead of Google Maps URL (GrapheneOS) +applyPatch "$DOS_PATCHES_COMMON/android_packages_apps_Contacts/0005-vCard-Four.patch"; #Add basic support for vCard 4.0 (GrapheneOS) fi; if enterAndClear "packages/apps/Dialer"; then