Skip to content

Commit

Permalink
get consent for EEA ad requests
Browse files Browse the repository at this point in the history
  • Loading branch information
felixb committed May 22, 2018
1 parent 265aeb7 commit 062b755
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changes

## 1.7.3
* GDPR compliance

## 1.7.2
* bug fixes

Expand Down
2 changes: 1 addition & 1 deletion PRIVACY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SMSdroid Privacy Policy

This Privacy Policy was last modified on 19.09.2015.
This Privacy Policy was last modified on 22.05.2018.

ub0r.de / Felix Bechstein ("us", "we", or "our") operates the SMSdroid App (the "App").
This page informs you of our policies regarding the collection,
Expand Down
11 changes: 6 additions & 5 deletions SMSdroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ repositories {
}

android {
compileSdkVersion 25
compileSdkVersion 26
buildToolsVersion '27.0.3'

defaultConfig {
minSdkVersion 14
targetSdkVersion 25
targetSdkVersion 26
versionCode 141720000
versionName "1.7.2"
}
Expand Down Expand Up @@ -67,9 +67,10 @@ android {
}

dependencies {
implementation 'com.android.support:support-v4:25.4.0'
implementation 'com.android.support:appcompat-v7:25.4.0'
implementation 'com.google.android.gms:play-services-ads:10.2.6'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.google.android.gms:play-services-ads:15.0.1'
implementation 'de.ub0r.android.lib:lib:1.1.1'
implementation 'de.ub0r.android.logg0r:logg0r:2.0.0'
implementation 'com.google.android.ads.consent:consent-library:1.0.1'
}
126 changes: 126 additions & 0 deletions SMSdroid/src/main/java/de/ub0r/android/smsdroid/ConsentManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package de.ub0r.android.smsdroid;

import android.app.Activity;
import android.content.Intent;

import com.google.ads.consent.ConsentForm;
import com.google.ads.consent.ConsentFormListener;
import com.google.ads.consent.ConsentInfoUpdateListener;
import com.google.ads.consent.ConsentInformation;
import com.google.ads.consent.ConsentStatus;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Calendar;

import de.ub0r.android.lib.DonationHelper;
import de.ub0r.android.logg0r.Log;

public class ConsentManager {

private static final String TAG = "ConsentManager";
private static final String ADMOB_PUBLISHER_ID = "pub-1948477123608376";
private static final String PRIVACY_URL = "https://github.com/felixb/smsdroid/blob/master/PRIVACY.md";

private final Activity mActivity;
private ConsentForm mForm;

public ConsentManager(final Activity activity) {
mActivity = activity;

}

public void updateConsent() {
if (!DonationHelper.hideAds(mActivity)) {
ConsentInformation consentInformation = ConsentInformation.getInstance(mActivity);
String[] publisherIds = {ADMOB_PUBLISHER_ID};
consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener() {
@Override
public void onConsentInfoUpdated(final ConsentStatus consentStatus) {
Log.i(TAG, "updated consent status: ", consentStatus.toString());
checkConsentForAds();
}

@Override
public void onFailedToUpdateConsentInfo(final String errorDescription) {
Log.e(TAG, "failed to update consent info: ", errorDescription);
}
});
}
}

public boolean showAds() {
return !DonationHelper.hideAds(mActivity) && checkConsentForAds();
}

private boolean checkConsentForAds() {
final ConsentInformation consentInformation = ConsentInformation.getInstance(mActivity);
if (!consentInformation.isRequestLocationInEeaOrUnknown()) {
// user is outside EEA
Log.d(TAG, "User is outseide EEA");
return true;
}

final Calendar now = Calendar.getInstance();
final Calendar gdprDeadline = Calendar.getInstance();
gdprDeadline.set(2018, 5, 25, 0, 0, 0);

if (now.before(gdprDeadline)) {
Log.d(TAG, "Before GDPR deadline");
return true;
}

if (ConsentStatus.UNKNOWN.equals(consentInformation.getConsentStatus())) {
Log.d(TAG, "Need to ask for consent");
// we need to ask for consent
askForConsent();
return false;
}

return true;
}

private void askForConsent() {
URL privacyUrl = null;
try {
privacyUrl = new URL(PRIVACY_URL);
} catch (MalformedURLException e) {
Log.e(TAG, "Error parsing privacy url", e);
mActivity.finish();
}
mForm = new ConsentForm.Builder(mActivity, privacyUrl)
.withListener(new ConsentFormListener() {
@Override
public void onConsentFormLoaded() {
Log.d(TAG, "onConsentFormLoaded");
mForm.show();
}

@Override
public void onConsentFormOpened() {
Log.d(TAG, "onConsentFormOpened");
}

@Override
public void onConsentFormClosed(final ConsentStatus consentStatus, final Boolean userPrefersAdFree) {
Log.d(TAG, "onConsentFormClosed(", consentStatus, userPrefersAdFree, ")");
if (userPrefersAdFree) {
Intent i = new Intent(Intent.ACTION_VIEW, DonationHelper.DONATOR_URI);
mActivity.startActivity(i);
} else if (ConsentStatus.UNKNOWN.equals(consentStatus)) {
mActivity.finish();
}
}

@Override
public void onConsentFormError(final String errorDescription) {
Log.e(TAG, "error showing consent form: ", errorDescription);
}
})
.withPersonalizedAdsOption()
.withAdFreeOption()
.build();
mForm.load();
mForm.show();
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
* Copyright (C) 2009-2015 Felix Bechstein
*
*
* This file is part of SMSdroid.
*
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
*
* You should have received a copy of the GNU General Public License along with
* this program; If not, see <http://www.gnu.org/licenses/>.
*/
Expand Down Expand Up @@ -282,6 +282,8 @@ public void onCreate(final Bundle savedInstanceState) {
setContentView(R.layout.conversationlist);
}

new ConsentManager(this).updateConsent();

// debug info
showRows(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

import de.ub0r.android.lib.DonationHelper;
import de.ub0r.android.lib.Utils;
import de.ub0r.android.lib.apis.Contact;
import de.ub0r.android.lib.apis.ContactsWrapper;
Expand Down Expand Up @@ -285,9 +284,11 @@ public final void onCreate(final Bundle savedInstanceState) {
longItemClickDialog[WHICH_VIEW_DETAILS] = getString(R.string.view_details_);
longItemClickDialog[WHICH_DELETE] = getString(R.string.delete_message_);

mAdView = (AdView) findViewById(R.id.ads);
mAdView = findViewById(R.id.ads);
mAdView.setVisibility(View.GONE);
if (!DonationHelper.hideAds(this)) {
ConsentManager cm = new ConsentManager(this);
cm.updateConsent();
if (cm.showAds()) {
mAdView.loadAd(new AdRequest.Builder().build());
mAdView.setAdListener(new AdListener() {
@Override
Expand Down

0 comments on commit 062b755

Please sign in to comment.