Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add multi-device-setup #2493

Merged
merged 69 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
a79931b
add DcBackupProvider add receiveBackup() wrappers
r10s Mar 8, 2023
b32d853
add 'Add Another Device' item to settings
r10s Mar 9, 2023
26a1ae6
add android-ifaddrs
r10s Mar 9, 2023
c47a55b
add BackupProviderActivity
r10s Mar 9, 2023
c6cfd54
make SVG-hack reusable
r10s Mar 10, 2023
412d383
add BackupProviderFragment
r10s Mar 10, 2023
61d38c4
prepare scanning backup codes
r10s Mar 11, 2023
3ec395e
Revert "add android-ifaddrs"
r10s Mar 13, 2023
4ad021d
more logging
r10s Mar 13, 2023
c10c981
call receiveBackup() on scanning DC_QR_BACKUP
r10s Mar 14, 2023
cf571e1
Fixup for recvmmsg fallback
link2xt Mar 14, 2023
c8a889f
protect BackupProviderActivity by system secret
r10s Mar 16, 2023
eb2a9f4
show transfer progress as provided form the core; hide qr-code once s…
r10s Mar 16, 2023
1f40fec
add a permanent notification for the provider
r10s Mar 17, 2023
cb164b7
clarify what we are waiting for
r10s Mar 17, 2023
af5e4ab
add a permanent notification for the receiver
r10s Mar 17, 2023
f80e742
ask before finishing BackupProviderActivity
r10s Mar 17, 2023
e98d9ee
it is fine to cancel the abort question by tapping outside the alert
r10s Mar 17, 2023
3e0b616
remove outdated comment from 'keep screen on'
r10s Mar 17, 2023
1b9571a
add and check TRANSFER_MODE
r10s Mar 17, 2023
61596b9
rename BackupProviderActivity to BackupTransferActivity
r10s Mar 17, 2023
1b991be
use our base activity
r10s Mar 17, 2023
f5192c6
start/stop IO in base activity
r10s Mar 17, 2023
21122b9
use BackupTransferActivity also for scanning
r10s Mar 17, 2023
487a186
add BackupReceiverFragment
r10s Mar 17, 2023
731c661
show detailed transfer progress
r10s Mar 17, 2023
934ed18
show details instead of percent during preparation, for now
r10s Mar 17, 2023
f64c812
launch chatlist and remove welcome when transfer is done
r10s Mar 17, 2023
d4446b3
redirect to chatlist automatically after transfer succeeded
r10s Mar 17, 2023
da269dc
reword
r10s Mar 18, 2023
b982bdb
make log accessible from send and receive activities
r10s Mar 18, 2023
6a1d430
bump version
r10s Mar 18, 2023
e9f2413
show error if backup provider creation fails
r10s Mar 20, 2023
2a2d4d5
remove unneeded format()
r10s Mar 20, 2023
56afe08
show some context in the errors alerts, hide QR code sooner
r10s Mar 20, 2023
9bd3be8
calculate transfer percentage as specified
r10s Mar 20, 2023
317c2f1
show a 'close' instead of a 'back' button to make visually clear, thi…
r10s Mar 20, 2023
05300a9
add option to copy backup-qr-code to clipboard
r10s Mar 21, 2023
89d26ad
remove vague retry statement, core will show a detailed error soon
r10s Mar 21, 2023
f1f49d4
warn about QR codes on clipboard getting invalidated
r10s Mar 21, 2023
bdcfe0d
make basic strings translatable
r10s Mar 21, 2023
81cb8c0
add troubleshooting menu item (once help is evolved, it may be a more…
r10s Mar 21, 2023
c711798
rename to backup_transfer_fragment.xml
r10s Mar 21, 2023
00f7c16
add detailed instructions
r10s Mar 21, 2023
476ff02
move 1,2,3 layout to the .xml
r10s Mar 22, 2023
d39b373
fix layout
r10s Mar 22, 2023
0cbf081
use text size used elsewhere
r10s Mar 22, 2023
3dafc9d
do best effort to show SSID on sending device
r10s Mar 22, 2023
2e2ac6f
make SSID code reusable for receiver
r10s Mar 22, 2023
765cbeb
adapt to otherwise used font style
r10s Mar 22, 2023
b8a618b
show ssid also for receiver
r10s Mar 22, 2023
4933a45
minor refactorings
r10s Mar 22, 2023
9a36de9
make qr code subtitle translatable
r10s Mar 22, 2023
8d676a8
tune down 'same network hint' on scanning device
r10s Mar 22, 2023
3aa376d
add progress bar to provider
r10s Mar 22, 2023
87f45dd
add progress bar to receiver
r10s Mar 22, 2023
7418a5d
bump version
r10s Mar 23, 2023
5f271d8
use 'Add Second Device' wording
r10s Mar 23, 2023
46871bc
use "Exporting/Preparing/Prepared Account" wording
r10s Mar 23, 2023
37b49bc
refine abort question
r10s Mar 23, 2023
dcea54e
Update res/layout/backup_provider_fragment.xml
r10s Mar 24, 2023
8f26673
Update src/org/thoughtcrime/securesms/qr/BackupProviderFragment.java
r10s Mar 24, 2023
007dd6d
Update src/org/thoughtcrime/securesms/qr/BackupReceiverFragment.java
r10s Mar 24, 2023
2f9f6dd
Update src/org/thoughtcrime/securesms/qr/BackupTransferActivity.java
r10s Mar 24, 2023
80f2036
Update src/org/thoughtcrime/securesms/qr/BackupReceiverFragment.java
r10s Mar 24, 2023
df71751
remove string duplicate
r10s Mar 24, 2023
fe05225
refine 1,2,3
r10s Mar 24, 2023
279580e
simplify string ids
r10s Mar 24, 2023
12f94be
focus on what matters
r10s Mar 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@
android:theme="@style/TextSecure.LightTheme"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>

<activity android:name=".qr.BackupTransferActivity"
android:theme="@style/TextSecure.LightTheme"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>

<activity android:name=".preferences.ChatBackgroundActivity"
android:theme="@style/TextSecure.LightTheme"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ android {

defaultConfig {
versionCode 649
versionName "1.35.1"
versionName "1.35.3"

applicationId "com.b44t.messenger"
multiDexEnabled true
Expand Down
66 changes: 65 additions & 1 deletion jni/dc_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int sendmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
int recvmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
int flags, struct timespec *timeout)
{
if (flags != -1) {
if (flags != 0) {
Hocuri marked this conversation as resolved.
Show resolved Hide resolved
// Not supported by the fallback.
return -1;
}
Expand Down Expand Up @@ -958,6 +958,21 @@ JNIEXPORT jstring Java_com_b44t_messenger_DcContext_imexHasBackup(JNIEnv *env, j
}


JNIEXPORT jlong Java_com_b44t_messenger_DcContext_newBackupProviderCPtr(JNIEnv *env, jobject obj)
{
return (jlong)dc_backup_provider_new(get_dc_context(env, obj));
}


JNIEXPORT jboolean Java_com_b44t_messenger_DcContext_receiveBackup(JNIEnv *env, jobject obj, jstring qr)
{
CHAR_REF(qr);
jboolean ret = dc_receive_backup(get_dc_context(env, obj), qrPtr);
CHAR_UNREF(qr);
return ret;
}


JNIEXPORT jint Java_com_b44t_messenger_DcContext_addAddressBook(JNIEnv *env, jobject obj, jstring adrbook)
{
CHAR_REF(adrbook);
Expand Down Expand Up @@ -1956,6 +1971,55 @@ JNIEXPORT void Java_com_b44t_messenger_DcLot_unrefLotCPtr(JNIEnv *env, jobject o
}


/*******************************************************************************
* DcBackupProvider
******************************************************************************/


static dc_backup_provider_t* get_dc_backup_provider(JNIEnv *env, jobject obj)
{
static jfieldID fid = 0;
if (fid==0) {
jclass cls = (*env)->GetObjectClass(env, obj);
fid = (*env)->GetFieldID(env, cls, "backupProviderCPtr", "J" /*Signature, J=long*/);
}
if (fid) {
return (dc_backup_provider_t*)(*env)->GetLongField(env, obj, fid);
}
return NULL;
}


JNIEXPORT void Java_com_b44t_messenger_DcBackupProvider_unrefBackupProviderCPtr(JNIEnv *env, jobject obj)
{
dc_backup_provider_unref(get_dc_backup_provider(env, obj));
}


JNIEXPORT jstring Java_com_b44t_messenger_DcBackupProvider_getQr(JNIEnv *env, jobject obj)
{
char* temp = dc_backup_provider_get_qr(get_dc_backup_provider(env, obj));
jstring ret = JSTRING_NEW(temp);
dc_str_unref(temp);
return ret;
}


JNIEXPORT jstring Java_com_b44t_messenger_DcBackupProvider_getQrSvg(JNIEnv *env, jobject obj)
{
char* temp = dc_backup_provider_get_qr_svg(get_dc_backup_provider(env, obj));
jstring ret = JSTRING_NEW(temp);
dc_str_unref(temp);
return ret;
}


JNIEXPORT void Java_com_b44t_messenger_DcBackupProvider_waitForReceiver(JNIEnv *env, jobject obj)
{
dc_backup_provider_wait(get_dc_backup_provider(env, obj));
}


/*******************************************************************************
* DcProvider
******************************************************************************/
Expand Down
5 changes: 5 additions & 0 deletions res/drawable/ic_baseline_devices_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="?attr/pref_icon_tint"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M4,6h18L22,4L4,4c-1.1,0 -2,0.9 -2,2v11L0,17v3h14v-3L4,17L4,6zM23,8h-6c-0.55,0 -1,0.45 -1,1v10c0,0.55 0.45,1 1,1h6c0.55,0 1,-0.45 1,-1L24,9c0,-0.55 -0.45,-1 -1,-1zM22,17h-4v-7h4v7z"/>
</vector>
5 changes: 5 additions & 0 deletions res/layout/backup_provider_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/backup_provider_fragment" />
110 changes: 110 additions & 0 deletions res/layout/backup_provider_fragment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">

<org.thoughtcrime.securesms.components.emoji.EmojiTextView
android:id="@+id/status_line"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40sp"
android:gravity="center_horizontal"
android:textAlignment="center"
android:textColor="?attr/emoji_text_color"
android:textSize="20sp"
tools:text="One moment..."/>

<ProgressBar
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
/>

<LinearLayout
android:id="@+id/top_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="vertical"
android:visibility="gone">
r10s marked this conversation as resolved.
Show resolved Hide resolved

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:gravity="center_vertical"
android:text="➊"
android:textColor="?attr/emoji_text_color"
android:textSize="16sp"/> <!-- idk - using sightly larger text size moves the next text down -->
<TextView
android:id="@+id/same_network_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/multidevice_same_network_hint"
android:textColor="?attr/emoji_text_color"
android:textSize="16sp"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:gravity="center_vertical"
android:text="➋"
android:textColor="?attr/emoji_text_color"
android:textSize="16sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/multidevice_install_dc_on_other_device"
android:textColor="?attr/emoji_text_color"
android:textSize="16sp"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:gravity="center_vertical"
android:text="➌"
android:textColor="?attr/emoji_text_color"
android:textSize="16sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/multidevice_tap_scan_on_other_device"
android:textColor="?attr/emoji_text_color"
android:textSize="16sp"/>
</LinearLayout>

</LinearLayout>

<com.caverock.androidsvg.SVGImageView
android:id="@+id/qrImage"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="16dp"
android:contentDescription="@string/qrscan_title" />

</LinearLayout>
38 changes: 38 additions & 0 deletions res/layout/backup_receiver_fragment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">

<TextView
android:id="@+id/status_line"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40sp"
android:gravity="center_horizontal"
android:textAlignment="center"
android:textColor="?attr/emoji_text_color"
android:textSize="20sp"
tools:text="One moment..."/>

<ProgressBar
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
/>

<TextView
android:id="@+id/same_network_hint"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="16dp"
android:layout_weight="1"
android:gravity="bottom"
android:text="@string/multidevice_same_network_hint"
android:textColor="@color/gray50"
android:textSize="16sp"/>

</LinearLayout>
2 changes: 1 addition & 1 deletion res/layout/welcome_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
android:layout_height="wrap_content"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:text="@string/scan_invitation_code"/>
android:text="@string/qrscan_title"/>

</LinearLayout>

Expand Down
18 changes: 18 additions & 0 deletions res/menu/backup_transfer_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">

<item android:title="@string/troubleshooting"
android:id="@+id/troubleshooting"
app:showAsAction="never"/>

<item android:title="@string/menu_copy_to_clipboard"
android:id="@+id/copy"
android:visible="false"
app:showAsAction="never"/>

<item android:title="@string/pref_view_log"
android:id="@+id/view_log_button"
app:showAsAction="never"/>

</menu>
29 changes: 29 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,35 @@
<!-- the explanation is shown (1) as a modal dialog with the buttons "Cancel" and "Continue" as well as (2) as a device message -->
<string name="aeap_explanation">You changed your email address from %1$s to %2$s.\n\nIf you now send a message to a verified group, contacts there will automatically replace the old with your new address.\n\nIt\'s highly advised to set up your old email provider to forward all emails to your new email address. Otherwise you might miss messages of contacts who did not get your new address yet.</string>


<!-- Multi Device -->
<!-- "Second Device" can also be translated as "Another Device", if that is catchier in the destination language. However, make sure to use the term consistently. -->
<string name="multidevice_title">Add Second Device</string>
<string name="multidevice_same_network_hint">Make sure both devices are on the same Wi-Fi or network</string>
<string name="multidevice_install_dc_on_other_device">Install and start Delta Chat 1.36 or newer on your other device (https://get.delta.chat)</string>
<string name="multidevice_tap_scan_on_other_device">During setup, tap “Scan QR Code” and scan the code shown here</string>
r10s marked this conversation as resolved.
Show resolved Hide resolved
<!-- Shown inside a "QR code card" with very limited space; please formulate the text as short as possible therefore. The placeholder will be replaced by name and/or address eg. "Scan to set up second device for Alice (alice@example.org)" -->
<string name="multidevice_qr_subtitle">Scan to set up second device for %1$s</string>
<string name="multidevice_reveiver_title">Add as Second Device</string>
<string name="multidevice_receiver_scanning_ask">Copy the account from the other device to this device? Both devices will work independently afterwards.</string>
<!-- Shown beside progress bar, stay short -->
<string name="multidevice_exporting_account">Exporting account…</string>
<!-- Shown beside progress bar, stay short -->
<string name="multidevice_preparing_account">Preparing account…</string>
<!-- Shown beside progress bar, stay short -->
<string name="multidevice_account_prepared">Account prepared.</string>
<!-- Shown beside progress bar, stay short -->
<string name="multidevice_waiting_for_receiver">Waiting for receiver…</string>
<!-- Shown beside progress bar, stay short -->
<string name="multidevice_connecting">Connecting…</string>
r10s marked this conversation as resolved.
Show resolved Hide resolved
<!-- Shown beside progress bar, stay short -->
<string name="multidevice_receiver_connected">Receiver connected…</string>
<!-- Shown beside progress bar, stay short -->
<string name="multidevice_transferring">Transferring…</string>
<string name="multidevice_abort">Abort transfer?</string>
<string name="multidevice_abort_will_invalidate_copied_qr">This will invalidate the QR code copied to clipboard.</string>
<string name="troubleshooting">Troubleshooting</string>

<!-- Connectivity -->
<!-- Headline for the "Inbox" eg. in the "Connectivity" view -->
<string name="incoming_messages">Incoming Messages</string>
Expand Down
5 changes: 5 additions & 0 deletions res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
android:icon="@drawable/ic_brightness_6_24dp"
android:layout="@layout/preference_item" />

<Preference android:key="preference_category_multidevice"
android:title="@string/multidevice_title"
android:icon="@drawable/ic_baseline_devices_24"
android:layout="@layout/preference_item"/>

<Preference android:key="preference_category_connectivity"
android:title="@string/connectivity"
android:icon="@drawable/ic_swap_vert_24dp"
Expand Down
32 changes: 32 additions & 0 deletions src/com/b44t/messenger/DcBackupProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.b44t.messenger;

public class DcBackupProvider {

public DcBackupProvider(long backupProviderCPtr) {
this.backupProviderCPtr = backupProviderCPtr;
}

public boolean isOk() {
return backupProviderCPtr != 0;
}

@Override protected void finalize() throws Throwable {
super.finalize();
unref();
}

public void unref() {
if (backupProviderCPtr == 0) {
unrefBackupProviderCPtr();
backupProviderCPtr = 0;
}
}

public native String getQr ();
public native String getQrSvg ();
public native void waitForReceiver ();

// working with raw c-data
private long backupProviderCPtr; // CAVE: the name is referenced in the JNI
private native void unrefBackupProviderCPtr();
}
Loading