OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.physicalweb; | 5 package org.chromium.chrome.browser.physicalweb; |
6 | 6 |
7 import android.content.Intent; | 7 import android.content.Intent; |
8 import android.os.Build; | 8 import android.os.Build; |
9 | 9 |
10 import org.chromium.chrome.browser.ChromeActivity; | 10 import org.chromium.chrome.browser.ChromeActivity; |
11 import org.chromium.chrome.browser.share.ShareActivity; | 11 import org.chromium.chrome.browser.share.ShareActivity; |
12 | 12 |
13 /** | 13 /** |
14 * A simple activity that allows Chrome to start the physical web sharing servic
e. | 14 * A simple activity that allows Chrome to start the physical web sharing servic
e. |
15 */ | 15 */ |
16 public class PhysicalWebShareActivity extends ShareActivity { | 16 public class PhysicalWebShareActivity extends ShareActivity { |
17 @Override | 17 @Override |
18 protected void handleShareAction(ChromeActivity triggeringActivity) { | 18 protected void handleShareAction(ChromeActivity triggeringActivity) { |
19 String url = triggeringActivity.getActivityTab().getUrl(); | 19 String url = triggeringActivity.getActivityTab().getUrl(); |
20 | 20 |
21 Intent intent = new Intent(this, PhysicalWebBroadcastService.class); | 21 if (!PhysicalWeb.sharingIsOptedIn()) { |
22 intent.putExtra(PhysicalWebBroadcastService.DISPLAY_URL_KEY, url); | 22 // This shows an interstitial for the user to opt-in for sending URL
to Google. |
23 startService(intent); | 23 Intent intent = new Intent(this, PhysicalWebShareEntryActivity.class
); |
| 24 intent.putExtra(PhysicalWebShareEntryActivity.SHARING_ENTRY_URL, url
); |
| 25 triggeringActivity.startActivity(intent); |
| 26 return; |
| 27 } |
| 28 |
| 29 PhysicalWebBroadcastService.startBroadcastService(url); |
24 } | 30 } |
25 | 31 |
26 /** | 32 /** |
27 * Returns whether we should show this sharing option in the share sheet. | 33 * Returns whether we should show this sharing option in the share sheet. |
28 * Pre-conditions for Physical Web Sharing to be enabled: | 34 * Pre-conditions for Physical Web Sharing to be enabled: |
29 * Device has hardware BLE advertising capabilities. | 35 * Device has hardware BLE advertising capabilities. |
30 * Device had Bluetooth on. | 36 * Device had Bluetooth on. |
31 * Device is Marshmallow or above. | 37 * Device is Marshmallow or above. |
32 * Device has sharing feature enabled. | 38 * Device has sharing feature enabled. |
33 * @return {@code true} if the feature should be enabled. | 39 * @return {@code true} if the feature should be enabled. |
34 */ | 40 */ |
35 public static boolean featureIsAvailable() { | 41 public static boolean featureIsAvailable() { |
36 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false; | 42 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false; |
37 return PhysicalWeb.hasBleAdvertiseCapability() && PhysicalWeb.bluetoothI
sEnabled() | 43 return PhysicalWeb.hasBleAdvertiseCapability() && PhysicalWeb.bluetoothI
sEnabled() |
38 && PhysicalWeb.sharingIsEnabled(); | 44 && PhysicalWeb.sharingIsEnabled(); |
39 } | 45 } |
40 } | 46 } |
OLD | NEW |