Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4315)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebShareActivity.java

Issue 2719493003: Add PhysicalWebBroadcastService (Closed)
Patch Set: Fixing nits Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebShareActivity.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebShareActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebShareActivity.java
index 5fe13a3583fad9cb49531491e2635c90823778b5..0261a1d93c503260a47d99ab475f7c197f62e1a5 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebShareActivity.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebShareActivity.java
@@ -4,15 +4,20 @@
package org.chromium.chrome.browser.physicalweb;
+import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
+import org.chromium.base.ApplicationStatus;
+import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.share.ShareHelper;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.util.IntentUtils;
+import java.lang.ref.WeakReference;
+import java.util.List;
/**
* A simple activity that allows Chrome to start the physical web sharing service.
*/
@@ -35,10 +40,43 @@ public class PhysicalWebShareActivity extends AppCompatActivity {
}
private void handleShareAction() {
- // TODO(iankc): implement sharing
+ ChromeActivity openPage = getTriggeringActivity();
+ if (openPage == null) return;
+ String url = openPage.getActivityTab().getUrl();
+
+ Intent intent = new Intent(this, PhysicalWebBroadcastService.class);
+ intent.putExtra(PhysicalWebBroadcastService.DISPLAY_URL_KEY, url);
+ startService(intent);
}
+ /**
+ * Pre-conditions for Physical Web Sharing to be enabled:
+ * Device has hardware BLE advertising capabilities.
+ * Device is Marshmallow or above.
+ * Device has sharing feature enabled.
+ */
public static boolean sharingIsEnabled(Tab currentTab) {
return PhysicalWeb.sharingIsEnabled() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
}
+
+ /**
+ * Returns the ChromeActivity that called the share intent picker.
+ */
+ protected ChromeActivity getTriggeringActivity() {
cco3 2017/03/02 19:01:08 Since we don't have an abstract class, could we tu
+ int triggeringTaskId =
+ IntentUtils.safeGetIntExtra(getIntent(), ShareHelper.EXTRA_TASK_ID, 0);
+ List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities();
+ ChromeActivity triggeringActivity = null;
+ for (int i = 0; i < activities.size(); i++) {
+ Activity activity = activities.get(i).get();
+ if (activity == null) continue;
+
+ // Since the share intent is triggered without NEW_TASK or NEW_DOCUMENT, the task ID
+ // of this activity will match that of the triggering activity.
+ if (activity.getTaskId() == triggeringTaskId && activity instanceof ChromeActivity) {
+ return (ChromeActivity) activity;
+ }
+ }
+ return null;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698