Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
fix element-hq/riot-meta#12 Device management - solve the problem of …
Browse files Browse the repository at this point in the history
…detected device names
  • Loading branch information
ylecollen committed Oct 2, 2017
1 parent 63725f1 commit 76872c5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
Binary file modified vector/libs/matrix-sdk.aar
Binary file not shown.
16 changes: 11 additions & 5 deletions vector/src/main/java/im/vector/LoginHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package im.vector;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;

import org.matrix.androidsdk.HomeServerConnectionConfig;
Expand Down Expand Up @@ -133,7 +134,7 @@ public void onMatrixError(MatrixError e) {
}
};

callLogin(hsConfig, username, phoneNumber, phoneNumberCountry, password, loginCallback);
callLogin(ctx, hsConfig, username, phoneNumber, phoneNumberCountry, password, loginCallback);
}

/**
Expand All @@ -146,20 +147,22 @@ public void onMatrixError(MatrixError e) {
* @param password
* @param callback
*/
private void callLogin(final HomeServerConnectionConfig hsConfig, final String username,
private void callLogin(final Context ctx, final HomeServerConnectionConfig hsConfig, final String username,
final String phoneNumber, final String phoneNumberCountry,
final String password, final SimpleApiCallback<Credentials> callback) {
LoginRestClient client = new LoginRestClient(hsConfig);
String deviceName = ctx.getString(R.string.login_mobile_device);

if (!TextUtils.isEmpty(username)) {
if (android.util.Patterns.EMAIL_ADDRESS.matcher(username).matches()) {
// Login with 3pid
client.loginWith3Pid(ThreePid.MEDIUM_EMAIL, username.toLowerCase(), password, callback);
client.loginWith3Pid(ThreePid.MEDIUM_EMAIL, username.toLowerCase(), password, deviceName, callback);
} else {
// Login with user
client.loginWithUser(username, password, callback);
client.loginWithUser(username, password, deviceName, callback);
}
} else if (!TextUtils.isEmpty(phoneNumber) && !TextUtils.isEmpty(phoneNumberCountry)) {
client.loginWithPhoneNumber(phoneNumber, phoneNumberCountry, password, callback);
client.loginWithPhoneNumber(phoneNumber, phoneNumberCountry, password, deviceName, callback);
}
}

Expand Down Expand Up @@ -239,6 +242,9 @@ public void register(Context ctx, final HomeServerConnectionConfig hsConfig, fin
final Context appCtx = ctx.getApplicationContext();
LoginRestClient client = new LoginRestClient(hsConfig);

// avoid dispatching the device name
params.initial_device_display_name = ctx.getString(R.string.login_mobile_device);

client.register(params, new SimpleApiCallback <Credentials> () {
@Override
public void onSuccess(Credentials credentials){
Expand Down
1 change: 1 addition & 0 deletions vector/src/main/java/im/vector/RegistrationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ public void onReject() {
*/
private void register(final Context context, final RegistrationParams params, final InternalRegistrationListener listener) {
if (getLoginRestClient() != null) {
params.initial_device_display_name = context.getString(R.string.login_mobile_device);
mLoginRestClient.register(params, new SimpleApiCallback<Credentials>() {
@Override
public void onSuccess(Credentials credentials) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private enum RegistrationState {
}

// the pusher base
private static final String mBasePusherDeviceName = Build.MODEL.trim();
private final String mBasePusherDeviceName;

// the context
private final Context mContext;
Expand All @@ -139,6 +139,7 @@ private enum RegistrationState {
*/
public GcmRegistrationManager(final Context appContext) {
mContext = appContext.getApplicationContext();
mBasePusherDeviceName = mContext.getString(R.string.login_mobile_device);

try {
PackageInfo pInfo = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
Expand Down
1 change: 1 addition & 0 deletions vector/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
<string name="login_error_unable_register">Unable to register</string>
<string name="login_error_unable_register_mail_ownership">Unable to register : email ownership failure</string>
<string name="login_error_invalid_home_server">Enter valid URL</string>
<string name="login_mobile_device">Mobile</string>

<string name="login_error_forbidden">Invalid username/password</string>
<string name="login_error_unknown_token">The access token specified was not recognised</string>
Expand Down

0 comments on commit 76872c5

Please sign in to comment.