Skip to content

Commit

Permalink
# Modified layout for deeplink activity
Browse files Browse the repository at this point in the history
# Added a webview bug (URL redirection) due to weak host validation in deeplink activity
  • Loading branch information
banditAkshay committed Oct 23, 2023
1 parent 2aa92cd commit 33329ca
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 38 deletions.
66 changes: 37 additions & 29 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.READ_CONTACTS" />

<permission android:name="com.BugBazaar.permission.contacts" android:protectionLevel="signature"/>

<permission
android:name="com.BugBazaar.permission.contacts"
android:protectionLevel="signature" />

<queries>
<intent>
Expand All @@ -34,12 +35,21 @@
android:testOnly="true"
android:theme="@style/Theme.BugBazaar"
android:usesCleartextTraffic="true"
tools:ignore="CustomPermissionTypo"
tools:replace="android:fullBackupContent"
tools:targetApi="31"
tools:ignore="CustomPermissionTypo">
tools:targetApi="31">
<activity
android:name=".ui.payment.OrderHistory"
android:name=".ui.RASPSettings"
android:exported="false" />
<activity
android:name=".ui.addresses.Address"
android:exported="true" />
<activity
android:name=".ui.Wallet"
android:exported="true" />
<activity
android:name=".ui.myorders.OrderHistoryActivity"
android:exported="true" />
<activity
android:name=".ui.payment.OrderSummary"
android:exported="true" />
Expand Down Expand Up @@ -71,8 +81,8 @@
<provider
android:name=".provider.MyContactsProvider"
android:authorities="com.bugbazaar.mycontacts"
android:permission="com.BugBazaar.permission.contact"
android:exported="true" />
android:exported="true"
android:permission="com.BugBazaar.permission.contact" />

<activity
android:name=".ui.DetailedProductActivity"
Expand All @@ -84,16 +94,9 @@
android:name=".ui.NavigationDrawer_Dashboard"
android:exported="true">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.MAIN" />

<data
android:host="bugbazaar"
android:pathPrefix="/dashboard"
android:scheme="bb" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
Expand All @@ -114,37 +117,42 @@
<activity
android:name=".ui.Signin"
android:clearTaskOnLaunch="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
android:exported="true" />
<activity
android:name=".ui.Deeplink"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="bb"

<data
android:host="bugbazaar"
android:path="/cart/add"
android:scheme="bb" />
<data
android:host="bugbazaar"
android:path="/offers"
android:scheme="bb" />
<data
android:host="bugbazaar"
android:path="/cart/add"/>
android:path="/web"
android:scheme="bb" />
</intent-filter>
</activity>

<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />

<service
android:name=".MyFirebaseInstanceIDService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>

</application>

</manifest>
68 changes: 59 additions & 9 deletions app/src/main/java/com/BugBazaar/ui/Deeplink.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,81 @@
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.BugBazaar.R;

import java.util.List;

public class Deeplink extends AppCompatActivity {
//private List<Product> products;
WebView webView;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
setContentView(R.layout.activity_deep_link);
Intent intent = getIntent();
Uri deeplink = intent.getData();
if (deeplink != null) {

// Deep link handling for item
if (deeplink != null && "/cart/add".equals(deeplink.getPath())) {
// Get the item parameter value from the URI
String fetched_item = deeplink.getQueryParameter("item");
Log.d("Item fetched from deep link:", fetched_item);
if (fetched_item != null) {
Log.d("Item fetched from deep link:", fetched_item);

//Start NavigationDrawer_Dashboard to populate the product list
Intent intentA = new Intent(this, NavigationDrawer_Dashboard.class);
intentA.putExtra("fetched_item", fetched_item);
startActivity(intentA);
}
}

//Start NavigationDrawer_Dashboard to populate the product list
Intent intentA = new Intent(this, NavigationDrawer_Dashboard.class);
intentA.putExtra("fetched_item", fetched_item);
startActivity(intentA);
// Deep link handling for msg
if (deeplink != null && "/offers".equals(deeplink.getPath())) {
String message = deeplink.getQueryParameter("msg");
if (message != null) {
// Display the message, e.g., in a TextView
TextView toolbarTitle = findViewById(R.id.toolbarTitle);
toolbarTitle.setText("Offers");
TextView messageTextView = findViewById(R.id.messageTextView);
messageTextView.setText(message);
} else {
TextView toolbarTitle = findViewById(R.id.toolbarTitle);
toolbarTitle.setText("Offers");
TextView messageTextView = findViewById(R.id.messageTextView);
messageTextView.setText("Coming Soon...............!");
}
}

}
// Deep link handling for url
if (deeplink != null && "/web".equals(deeplink.getPath())) {
String webViewUrl = deeplink.getQueryParameter("url");
// Check if the "url" parameter contains "payatu.com"
if (webViewUrl != null && webViewUrl.contains("payatu.com")) {
TextView toolbarTitle = findViewById(R.id.toolbarTitle);
toolbarTitle.setText("BugBazaar");
webView = findViewById(R.id.deeplink_view);
setupwebview(webView);
this.webView.loadUrl(webViewUrl);
}
}
}
//Code to handle back button - Redirect to home page on back pressed
public void onBackButtonClick (View view){
// onBackPressed(); // Navigate back to the previous activity
Intent backtohome = new Intent(this, NavigationDrawer_Dashboard.class);
startActivity(backtohome);
}
private void setupwebview (WebView webView){
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
}
}
34 changes: 34 additions & 0 deletions app/src/main/res/layout/activity_deep_link.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/nav_toolbar_sub"
android:layout_height="wrap_content"
android:layout_width="match_parent"></include>
<TextView
android:id="@+id/messageTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:layout_marginTop="24dp"
android:text="This page is under construction"
android:textColor="#000" />
<WebView
android:id="@+id/deeplink_view"
android:layout_width="match_parent"
android:layout_height="675dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/include"
app:layout_constraintVertical_bias="0.0">

</WebView>
</LinearLayout>

0 comments on commit 33329ca

Please sign in to comment.