Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
feat: Add Project OneTrust in the Profile screen
Browse files Browse the repository at this point in the history
Added a new privacy section in the user profile screen above the
help section. Tapping each option in the privacy section opens
a webview for the corresponding option.

Fixes: LEARNER-9200
  • Loading branch information
HamzaIsrar12 authored and omerhabib26 committed Jan 16, 2023
1 parent 297d17a commit 2b4008c
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 12 deletions.
73 changes: 72 additions & 1 deletion OpenEdXMobile/res/layout/fragment_account.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,77 @@
android:background="@color/neutralXLight" />
</LinearLayout>

<LinearLayout
android:id="@+id/container_privacy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/selectable_rounded_box_overlay"
android:orientation="vertical"
android:paddingTop="@dimen/edx_default_margin"
android:visibility="gone"
tools:visibility="visible">

<TextView
style="@style/profile_field_heading"
android:paddingBottom="@dimen/edx_quarter_margin"
android:text="@string/label_privacy" />

<TextView
android:id="@+id/tv_privacy_policy"
style="@style/profile_field_title"
android:layout_width="match_parent"
android:background="@drawable/selectable_rounded_box_overlay"
android:gravity="center_vertical"
android:paddingStart="@dimen/edx_default_margin"
android:paddingTop="@dimen/edx_quarter_margin"
android:paddingEnd="@dimen/edx_default_margin"
android:paddingBottom="@dimen/edx_quarter_margin"
android:text="@string/label_privacy_policy"
android:visibility="gone"
app:drawableEndCompat="@drawable/ic_chevron_right"
app:drawableTint="@color/primaryBaseColor"
tools:visibility="visible" />

<TextView
android:id="@+id/tv_cookie_policy"
style="@style/profile_field_title"
android:layout_width="match_parent"
android:background="@drawable/selectable_rounded_box_overlay"
android:gravity="center_vertical"
android:paddingStart="@dimen/edx_default_margin"
android:paddingTop="@dimen/edx_quarter_margin"
android:paddingEnd="@dimen/edx_default_margin"
android:paddingBottom="@dimen/edx_quarter_margin"
android:text="@string/label_cookie_policy"
android:visibility="gone"
app:drawableEndCompat="@drawable/ic_chevron_right"
app:drawableTint="@color/primaryBaseColor"
tools:visibility="visible" />

<TextView
android:id="@+id/tv_data_consent_policy"
style="@style/profile_field_title"
android:layout_width="match_parent"
android:background="@drawable/selectable_rounded_box_overlay"
android:gravity="center_vertical"
android:paddingStart="@dimen/edx_default_margin"
android:paddingTop="@dimen/edx_quarter_margin"
android:paddingEnd="@dimen/edx_default_margin"
android:paddingBottom="@dimen/edx_quarter_margin"
android:text="@string/label_do_not_sell_my_personal_data"
android:visibility="gone"
app:drawableEndCompat="@drawable/ic_chevron_right"
app:drawableTint="@color/primaryBaseColor"
tools:visibility="visible" />

<View
android:layout_width="match_parent"
android:layout_height="@dimen/edx_line"
android:layout_marginTop="@dimen/widget_margin"
android:background="@color/neutralXLight" />

</LinearLayout>

<TextView
android:id="@+id/tv_help"
style="@style/profile_field_heading"
Expand Down Expand Up @@ -325,8 +396,8 @@
style="@style/profile_field_description"
android:layout_marginTop="@dimen/edx_default_margin"
android:layout_marginBottom="@dimen/edx_default_margin"
android:lineHeight="@dimen/edx_margin"
android:textSize="@dimen/edx_xx_small"
app:lineHeight="@dimen/edx_margin"
tools:text="Version X.X.X" />

<LinearLayout
Expand Down
9 changes: 8 additions & 1 deletion OpenEdXMobile/res/values/profile_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@
<string name="description_delete_account">Follow the instructions on the next screen to delete your account and all related data.</string>
<!-- Label of App Version -->
<string name="label_app_version">Version</string>

<!-- Heading of Privacy Fields -->
<string name="label_privacy">Privacy</string>
<!-- Label of Privacy Policy Button -->
<string name="label_privacy_policy">Privacy policy</string>
<!-- Label of Cookie Policy Button -->
<string name="label_cookie_policy">Cookie policy</string>
<!-- Label of Data Consent Button -->
<string name="label_do_not_sell_my_personal_data">Do not sell my personal data</string>
<!-- Logout button label -->
<string name="logout">Logout</string>
<!-- Profile screen version -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,13 +884,16 @@ interface Values {
// Profile Page Screen Events
String SCREEN_NAVIGATION = "edx.bi.app.navigation.screen";
String PERSONAL_INFORMATION_CLICKED = "edx.bi.app.profile.personal_info.clicked";
String FAQ_CLICKED = "eedx.bi.app.profile.faq.clicked";
String FAQ_CLICKED = "edx.bi.app.profile.faq.clicked";
String WIFI_ON = "edx.bi.app.profile.wifi.switch.on";
String WIFI_OFF = "edx.bi.app.profile.wifi.switch.off";
String WIFI_ALLOW = "edx.bi.app.profile.wifi.allow";
String WIFI_DONT_ALLOW = "edx.bi.app.profile.wifi.dont_allow";
String EMAIL_SUPPORT_CLICKED = "edx.bi.app.profile.email_support.clicked";
String DELETE_ACCOUNT_CLICKED = "edx.bi.app.profile.delete_account.clicked";
String PRIVACY_POLICY_CLICKED = "edx.bi.app.profile.privacy_policy.clicked";
String COOKIE_POLICY_CLICKED = "edx.bi.app.profile.cookie_policy.clicked";
String DO_NOT_SELL_DATA_CLICKED = "edx.bi.app.profile.do_not_sell_data.clicked";
// Video Download Quality
String PROFILE_VIDEO_DOWNLOAD_QUALITY_CLICKED = "edx.bi.app.profile.video_download_quality.clicked";
String COURSE_VIDEOS_VIDEO_DOWNLOAD_QUALITY_CLICKED = "edx.bi.app.course_videos.video_download_quality.clicked";
Expand Down Expand Up @@ -1097,6 +1100,9 @@ interface Events {
String WIFI_DONT_ALLOW = "Wifi Dont Allow";
String EMAIL_SUPPORT_CLICKED = "Email Support Clicked";
String DELETE_ACCOUNT_CLICKED = "Profile: Delete Account Clicked";
String PRIVACY_POLICY_CLICKED = "Privacy Policy Clicked";
String COOKIE_POLICY_CLICKED = "Cookie Policy Clicked";
String DO_NOT_SELL_DATA_CLICKED = "Do Not Sell Data Clicked";
// Video Download Quality
String PROFILE_VIDEO_DOWNLOAD_QUALITY_CLICKED = "Profile: Video Download Quality Clicked";
String COURSE_VIDEOS_VIDEO_DOWNLOAD_QUALITY_CLICKED = "Course Videos: Video Download Quality Clicked";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void clear() {
pref.put(PrefManager.Key.AUTH_JSON, null);
pref.put(PrefManager.Key.VIDEO_QUALITY, VideoQuality.AUTO.ordinal());
pref.put(PrefManager.Key.PROFILE_IMAGE, null);
EdxCookieManager.getSharedInstance(MainApplication.instance()).clearWebWiewCookie();
EdxCookieManager.getSharedInstance(MainApplication.instance()).clearAllCookies();
}

public void saveSocialLoginToken(@NonNull String accessToken, @NonNull String backend) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public class EdxCookieManager {
* The cookie to set for the course upsell revenue workflow to work on mobile end.
*/
private static final String REV_934_COOKIE = "REV_934=mobile; expires=Tue, 31 Dec 2021 12:00:20 GMT; domain=.edx.org;";
/**
* The cookie is set to retain its value after session refresh.
*/
private static final String DATA_CONSENT_COOKIE = "edx_do_not_sell=true; domain=.edx.org;";

private long authSessionCookieExpiration = -1;

Expand All @@ -64,19 +68,31 @@ public static synchronized EdxCookieManager getSharedInstance(@NonNull final Con
return instance;
}

public void clearWebWiewCookie() {
CookieManager.getInstance().removeAllCookie();
public void clearAllCookies() {
CookieManager.getInstance().removeAllCookies(null);
authSessionCookieExpiration = -1;
}

/**
* Clears all session cookies but retain the required cookies if available
*/
public void clearAndRetainCookies() {
String cookie = CookieManager.getInstance().getCookie(config.getApiHostURL());
clearAllCookies();
// The `edx_do_not_sell` cookie relates to the Data Sell Consent Policy and we should retain
// it if we are only refreshing the session cookies
if (cookie != null && cookie.contains("edx_do_not_sell"))
setDataConsentCookie();
}

public synchronized void tryToRefreshSessionCookie() {
if (loginCall == null || loginCall.isCanceled()) {
loginCall = loginService.login();
loginCall.enqueue(new Callback<RequestBody>() {
loginCall.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull final Call<RequestBody> call,
@NonNull final Response<RequestBody> response) {
clearWebWiewCookie();
clearAndRetainCookies();
final CookieManager cookieManager = CookieManager.getInstance();
for (Cookie cookie : Cookie.parseAll(
call.request().url(), response.headers())) {
Expand All @@ -101,11 +117,24 @@ public boolean isSessionCookieMissingOrExpired() {
return authSessionCookieExpiration < System.currentTimeMillis();
}

/**
* Ensures all cookies currently accessible through the getCookie API are written to persistent
* storage. The flush() call will block the caller until it is done and may perform I/O.
*/
public void retainSessionCookies() {
CookieManager.getInstance().flush();
}

/**
* Set a special cookie so that the server knows that the request for the course upsell
* revenue workflow is coming from mobile end.
*/
public void setMobileCookie() {
CookieManager.getInstance().setCookie(config.getApiHostURL(), REV_934_COOKIE);
}

private void setDataConsentCookie() {
CookieManager.getInstance().setCookie(config.getApiHostURL(), DATA_CONSENT_COOKIE);
retainSessionCookies();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import org.edx.mobile.R
* This enum defines the URL type of Agreement
*/
enum class AgreementUrlType {
EULA, TOS, PRIVACY_POLICY;
EULA, TOS, PRIVACY_POLICY, COOKIE_POLICY, DATA_CONSENT;

/**
* @return The string resource's ID if it's a valid enum inside [AgreementUrlType].
*/
fun getStringResId(): Int {
fun getStringResId(): Int? {
return when (this) {
EULA -> R.string.eula_file_link
TOS -> R.string.terms_file_link
PRIVACY_POLICY -> R.string.privacy_file_link
COOKIE_POLICY -> null
DATA_CONSENT -> null
}
}
}
10 changes: 10 additions & 0 deletions OpenEdXMobile/src/main/java/org/edx/mobile/util/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,12 @@ public static class AgreementUrlsConfig {
@SerializedName("PRIVACY_POLICY_URL")
private String privacyPolicyUrl;

@SerializedName("COOKIE_POLICY_URL")
private String cookiePolicyUrl;

@SerializedName("DATA_SELL_CONSENT_URL")
private String dataConsentUrl;

@SerializedName("SUPPORTED_LANGUAGES")
private ArrayList<String> supportedLanguages;

Expand All @@ -469,6 +475,10 @@ public String getAgreementUrl(@NonNull AgreementUrlType urlType) {
return eulaUrl;
case PRIVACY_POLICY:
return privacyPolicyUrl;
case COOKIE_POLICY:
return cookiePolicyUrl;
case DATA_CONSENT:
return dataConsentUrl;
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class ConfigUtil {
urlType: AgreementUrlType
): String? {
if (config == null || TextUtils.isEmpty(config.getAgreementUrl(urlType))) {
return context.resources.getString(urlType.getStringResId())
return urlType.getStringResId()?.let { context.resources.getString(it) }
}
if (config.supportedLanguages != null && config.supportedLanguages.isNotEmpty()) {
val currentLocal = LocaleUtils.getCurrentDeviceLanguage(context)
Expand Down
68 changes: 68 additions & 0 deletions OpenEdXMobile/src/main/java/org/edx/mobile/view/AccountFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.edx.mobile.deeplink.ScreenDef
import org.edx.mobile.event.AccountDataLoadedEvent
import org.edx.mobile.event.MediaStatusChangeEvent
import org.edx.mobile.event.ProfilePhotoUpdatedEvent
import org.edx.mobile.extenstion.isVisible
import org.edx.mobile.extenstion.setVisibility
import org.edx.mobile.model.user.Account
import org.edx.mobile.model.video.VideoQuality
Expand Down Expand Up @@ -99,6 +100,7 @@ class AccountFragment : BaseFragment() {
updateWifiSwitch()
updateSDCardSwitch()
initHelpFields()
initPrivacyFields()

val iapEnabled =
environment.appFeaturesPrefs.isIAPEnabled(loginPrefs.isOddUserId)
Expand Down Expand Up @@ -325,6 +327,72 @@ class AccountFragment : BaseFragment() {
}
}

private fun initPrivacyFields() {
ConfigUtil.getAgreementUrl(
this.requireContext(),
config.agreementUrlsConfig,
AgreementUrlType.PRIVACY_POLICY
)?.let { privacyPolicyUrl ->
binding.tvPrivacyPolicy.setVisibility(true)
binding.tvPrivacyPolicy.setOnClickListener {
environment.router.showAuthenticatedWebViewActivity(
this.requireContext(),
privacyPolicyUrl,
getString(R.string.label_privacy_policy),
false
)
trackEvent(
Analytics.Events.PRIVACY_POLICY_CLICKED,
Analytics.Values.PRIVACY_POLICY_CLICKED
)
}
}

ConfigUtil.getAgreementUrl(
this.requireContext(),
config.agreementUrlsConfig,
AgreementUrlType.COOKIE_POLICY
)?.let { cookiePolicyUrl ->
binding.tvCookiePolicy.setVisibility(true)
binding.tvCookiePolicy.setOnClickListener {
environment.router.showAuthenticatedWebViewActivity(
this.requireContext(),
cookiePolicyUrl,
getString(R.string.label_cookie_policy),
false
)
trackEvent(
Analytics.Events.COOKIE_POLICY_CLICKED,
Analytics.Values.COOKIE_POLICY_CLICKED
)
}
}

ConfigUtil.getAgreementUrl(
this.requireContext(),
config.agreementUrlsConfig,
AgreementUrlType.DATA_CONSENT
)?.let { dataConsentUrl ->
binding.tvDataConsentPolicy.setVisibility(true)
binding.tvDataConsentPolicy.setOnClickListener {
environment.router.showAuthenticatedWebViewActivity(
this.requireContext(),
dataConsentUrl,
getString(R.string.label_do_not_sell_my_personal_data),
false
)
trackEvent(
Analytics.Events.DO_NOT_SELL_DATA_CLICKED,
Analytics.Values.DO_NOT_SELL_DATA_CLICKED
)
}
}

val isContainerVisible = binding.tvPrivacyPolicy.isVisible()
|| binding.tvCookiePolicy.isVisible() || binding.tvDataConsentPolicy.isVisible()
binding.containerPrivacy.setVisibility(isContainerVisible)
}

private fun updateWifiSwitch() {
val wifiPrefManager = PrefManager(requireContext(), PrefManager.Pref.WIFI)
binding.switchWifi.setOnCheckedChangeListener(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

// Clear cookies before loading so that social sharing buttons are not displayed inside web view
EdxCookieManager.getSharedInstance(getContext()).clearWebWiewCookie();
EdxCookieManager.getSharedInstance(getContext()).clearAndRetainCookies();

webview.loadUrl(courseData.getCertificateURL());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public void onPageFinished(WebView view, String url) {
} else {
hideLoadingProgress();
}
EdxCookieManager.getSharedInstance(getContext()).retainSessionCookies();
super.onPageFinished(view, url);
}
};
Expand Down

0 comments on commit 2b4008c

Please sign in to comment.