This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1852 from vector-im/add_google_url_link_detection
Add google url link detection
- Loading branch information
Showing
5 changed files
with
212 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
vector/src/main/java/im/vector/receiver/VectorReferrerReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
} | ||
} |