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

Commit

Permalink
Merge pull request #1852 from vector-im/add_google_url_link_detection
Browse files Browse the repository at this point in the history
Add google url link detection
  • Loading branch information
ylecollen authored Jan 5, 2018
2 parents bd16763 + 682c565 commit 2d810c0
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 48 deletions.
113 changes: 69 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,70 +43,95 @@ How to build JitsiMeet libs:
Recompile the provided aar files until we have gradle
======================================================

- generate olm-sdk.aar
generate olm-sdk.aar
--------------------

clone the repository http://git.matrix.org/git/olm.git/
open the android project in /android
build it
copy /android/olm-sdk/build/outputs/aarvector/libs/olm-sdk.aar to riot-android/vector/libs/.
- clone the repository http://git.matrix.org/git/olm.git/
- open the android project in /android
- build it
- copy /android/olm-sdk/build/outputs/aarvector/libs/olm-sdk.aar to riot-android/vector/libs/.

- generate matrix-sdk.aar
generate matrix-sdk.aar
----------------------

clone the repository https://github.com/matrix-org/matrix-android-sdk
open the project with android studio
build it
copy /matrix-android-sdk/matrix-sdk/build/outputs/aar/matrix-sdk-debug-....aar to riot-android/vector/libs/matrix-sdk.aar
- clone the repository https://github.com/matrix-org/matrix-android-sdk
- open the project with android studio
- build it
- copy /matrix-android-sdk/matrix-sdk/build/outputs/aar/matrix-sdk-debug-....aar to riot-android/vector/libs/matrix-sdk.aar

- generate the other aar files
generate the other aar files
----------------------------

see the section "Jitsi integration"
- see the section "Jitsi integration"

- compile the matrix SDK with the Riot-android project
compile the matrix SDK with the Riot-android project
----------------------------------------------------

in riot-android/settings.gradle, uncomment //include.. and //project..
in riot-android/vector/build.gradle, comment compile(name: 'matrix-sdk', ext: 'aar') and uncomment compile project(':matrix-sdk')
- in riot-android/settings.gradle, uncomment //include.. and //project..
- in riot-android/vector/build.gradle, comment compile(name: 'matrix-sdk', ext: 'aar') and uncomment compile project(':matrix-sdk')

Make your own flavour
=====================

Let says your application is named MyRiot : You have to create your own flavour.

- Modify riot-android/vector/build.gradle
Modify riot-android/vector/build.gradle
---------------------------------------

In "productFlavors" section, duplicate "app" group if you plan to use GCM/FCM or "appfdroid" if don't.

for example, with GCM, it would give
appmyriot {
applicationId "im.myriot"
// use the version name
versionCode rootProject.ext.versionCodeProp
versionName rootProject.ext.versionNameProp
resValue "string", "allow_gcm_use", "true"
resValue "string", "allow_ga_use", "true"
resValue "string", "short_flavor_description", "G"
resValue "string", "flavor_description", "GooglePlay"
}

if you use GCM, duplicate appCompile at the end of this file and replace appCompile by appmyriotCompile.
if you don't, update the "if (!getGradle().getStartParameter().getTaskRequests().toString().contains("fdroid"))" to include your flavor.

- Create your flavour directory

Copy riot-android/vector/src/app or appfroid if you use GCM or you don’t.
Rename it to appmyriot.
If you use GCM, you will need to generate your own google-services.json.

- Customise your flavour

Open riot-android/vector/src/appmyriot/AndroidManifest.xml
Comment the provider section.
Change the application name to myRiot with "android:label="myRiot""
Any other field can be customised by adding the resources in this directory classpath.
Open Android studio, select your flavour.
Build and run the app : you made your first Riot app.

```
appmyriot {
applicationId "im.myriot"
// use the version name
versionCode rootProject.ext.versionCodeProp
versionName rootProject.ext.versionNameProp
resValue "string", "allow_gcm_use", "true"
resValue "string", "allow_ga_use", "true"
resValue "string", "short_flavor_description", "G"
resValue "string", "flavor_description", "GooglePlay"
}
```

- if you use GCM, duplicate appCompile at the end of this file and replace appCompile by appmyriotCompile.
- if you don't, update the "if (!getGradle().getStartParameter().getTaskRequests().toString().contains("fdroid"))" to include your flavor.

Create your flavour directory
-----------------------------

- Copy riot-android/vector/src/app or appfroid if you use GCM or you don’t.
- Rename it to appmyriot.
- If you use GCM, you will need to generate your own google-services.json.

Customise your flavour
----------------------

- Open riot-android/vector/src/appmyriot/AndroidManifest.xml
- Comment the provider section.
- Change the application name to myRiot with "android:label="myRiot""
- Any other field can be customised by adding the resources in this directory classpath.
- Open Android studio, select your flavour.
- Build and run the app : you made your first Riot app.

You will need to manage your own provider because "im.vector" is already used (look at VectorContentProvider to manage it).

Customise your application settings with a custom google play link
===================================================================

It is possible to set some default values to Riot with some extra parameters to the google play link.

- Use the https://developers.google.com/analytics/devguides/collection/android/v4/campaigns URL generator (at the bottom)
- Set "Campaign Source"
- Set "Campaign Content" with the extra parameters (e.g. is=http://my__is.org&hs=http://my_hs.org)
- Generate the customised link

Supported extra parameters
-------------------------
- is : identidy server URL
- hs : home server URL

FAQ
===

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ buildscript {

// global properties used in sub modules
ext {
versionCodeProp = 70701
versionCodeProp = 70704
versionNameProp = "0.7.07"
versionBuild = System.getenv("BUILD_NUMBER") as Integer ?: 0
buildNumberProp = "${versionBuild}"
Expand Down
10 changes: 10 additions & 0 deletions vector/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,16 @@

<receiver android:name="im.vector.receiver.DismissNotificationReceiver"/>

<receiver
android:name="im.vector.receiver.VectorReferrerReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>


<!-- Shared items -->
<activity
android:name=".activity.VectorSharedFilesActivity"
Expand Down
17 changes: 14 additions & 3 deletions vector/src/main/java/im/vector/activity/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,23 @@ public void afterTextChanged(Editable s) {
mHandler = new Handler(getMainLooper());
}

/**
* The server URLs have been updated from a receiver
*/
public void onServerUrlsUpdate() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
mHomeServerText.setText(preferences.getString(HOME_SERVER_URL_PREF, getResources().getString(R.string.default_hs_server_url)));
mIdentityServerText.setText(preferences.getString(IDENTITY_SERVER_URL_PREF, getResources().getString(R.string.default_identity_server_url)));

mHomeserverConnectionConfig = null;
checkFlows();
}

/**
* @return the home server Url according to custom HS checkbox
*/
private String getHomeServerUrl() {
String url = getResources().getString(R.string.default_hs_server_url);
String url = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this).getString(HOME_SERVER_URL_PREF, getResources().getString(R.string.default_hs_server_url));

if (mUseCustomHomeServersCheckbox.isChecked()) {
url = mHomeServerText.getText().toString().trim();
Expand All @@ -640,7 +652,7 @@ private String getHomeServerUrl() {
* @return the identity server URL according to custom HS checkbox
*/
private String getIdentityServerUrl() {
String url = getResources().getString(R.string.default_identity_server_url);
String url = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this).getString(IDENTITY_SERVER_URL_PREF, getResources().getString(R.string.default_hs_server_url));

if (mUseCustomHomeServersCheckbox.isChecked()) {
url = mIdentityServerText.getText().toString().trim();
Expand Down Expand Up @@ -1858,7 +1870,6 @@ private void refreshDisplay() {
threePidLayout.setVisibility((mMode == MODE_ACCOUNT_CREATION_THREE_PID) ? View.VISIBLE : View.GONE);

boolean isLoginMode = mMode == MODE_LOGIN;
boolean isForgetPasswordMode = (mMode == MODE_FORGOT_PASSWORD) || (mMode == MODE_FORGOT_PASSWORD_WAITING_VALIDATION);

mButtonsView.setVisibility(View.VISIBLE);

Expand Down
118 changes: 118 additions & 0 deletions vector/src/main/java/im/vector/receiver/VectorReferrerReceiver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright 2017 Vector Creation Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package im.vector.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.preference.TwoStatePreference;
import android.text.TextUtils;

import org.matrix.androidsdk.util.Log;

import java.net.URLDecoder;

import im.vector.VectorApp;
import im.vector.activity.CommonActivityUtils;
import im.vector.activity.LoginActivity;
import im.vector.util.PreferencesManager;

public class VectorReferrerReceiver extends BroadcastReceiver {
private static final String LOG_TAG = VectorReferrerReceiver.class.getSimpleName();

private static final String INSTALL_REFERRER_ACTION = "com.android.vending.INSTALL_REFERRER";
private static final String KEY_REFERRER = "referrer";

private static final String KEY_HS = "hs";
private static final String KEY_IS = "is";

private static final String UTM_SOURCE = "utm_source";
private static final String UTM_CONTENT = "utm_content";

@Override
public void onReceive(Context context, Intent intent) {
if (null == intent) {
Log.e(LOG_TAG, "No intent");
return;
}

Log.d(LOG_TAG, "## onReceive() : " + intent.getAction());
if (TextUtils.equals(intent.getAction(), INSTALL_REFERRER_ACTION)) {

Bundle extras = intent.getExtras();
if (null == extras) {
Log.e(LOG_TAG, "No extra");
return;
}

String hs = null;
String is = null;

try {
String referrer = (String) extras.get(KEY_REFERRER);

Log.d(LOG_TAG, "## onReceive() : referrer " + referrer);

if (!TextUtils.isEmpty(referrer)) {
Uri dummyUri = Uri.parse("https://dummy?" + URLDecoder.decode(referrer, "utf-8"));

String utm_source = dummyUri.getQueryParameter(UTM_SOURCE);
String utm_content = dummyUri.getQueryParameter(UTM_CONTENT);

Log.d(LOG_TAG, "## onReceive() : utm_source " + utm_source + " -- utm_content " + utm_content);

if (null != utm_content) {
dummyUri = Uri.parse("https://dummy?" + URLDecoder.decode(utm_content, "utf-8"));

hs = dummyUri.getQueryParameter(KEY_HS);
is = dummyUri.getQueryParameter(KEY_IS);
}
}
} catch (Throwable t) {
Log.e(LOG_TAG, "## onReceive() : failed " + t.getMessage());
}

Log.d(LOG_TAG, "## onReceive() : HS " + hs);
Log.d(LOG_TAG, "## onReceive() : IS " + is);


if (!TextUtils.isEmpty(hs) || !TextUtils.isEmpty(is)) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = preferences.edit();

if (!TextUtils.isEmpty(hs)) {
editor.putString(LoginActivity.HOME_SERVER_URL_PREF, hs);
}

if (!TextUtils.isEmpty(is)) {
editor.putString(LoginActivity.IDENTITY_SERVER_URL_PREF, is);
}

editor.commit();

if ((null != VectorApp.getCurrentActivity()) && (VectorApp.getCurrentActivity() instanceof LoginActivity)) {
Log.d(LOG_TAG, "## onReceive() : warn loginactivity");
((LoginActivity)VectorApp.getCurrentActivity()).onServerUrlsUpdate();
}
}
}
}
}

0 comments on commit 2d810c0

Please sign in to comment.