Closed Bug 917942 Opened 11 years ago Closed 10 years ago

Create a JS API for Sync accounts

Categories

(Firefox for Android Graveyard :: Android Sync, defect, P1)

All
Android
defect

Tracking

(firefox29 fixed, firefox30 fixed, fennec29+)

RESOLVED FIXED
Firefox 30
Tracking Status
firefox29 --- fixed
firefox30 --- fixed
fennec 29+ ---

People

(Reporter: Margaret, Assigned: rnewman)

References

Details

(Whiteboard: [qa-])

Attachments

(4 files, 1 obsolete file)

I want to re-implement the sync promo banner using the new home banner API, and to do that, I want to know in JS-land whether or not sync is set up.
Assignee: nobody → rnewman
Status: NEW → ASSIGNED
Attached patch Proposed patch. v1 (obsolete) — Splinter Review
Here, give this a shot...
Attachment #806811 - Flags: feedback?(margaret.leibovic)
Comment on attachment 806811 [details] [diff] [review]
Proposed patch. v1

Is there a reason you made this into a helper script as opposed to a jsm? I feel like this would be better as /mobile/android/modules/AccountsHelper.jsm because then it could be loaded as a standalone thing. Most of the reason we have things in lazy-loaded scripts is because they depend on other things in browser.js, so we can't actually run them independently.

This looks like it's on the right track, but it didn't work because it expects JNI to already be defined, and when I imported JNI.jsm in my add-on, I ran into this error:
TypeError: JNI.GetForThread is not a function (chrome://browser/content/AccountsHelper.js:47)" {file: "chrome://browser/content/AccountsHelper.js" line: 47}]

Here's the add-on I'm using to test, in case you're curious:
https://github.com/leibovic/promo-banner/blob/master/bootstrap.js
Attachment #806811 - Flags: feedback?(margaret.leibovic) → feedback+
Untested.
Shifted to a module. Still untested :P
Attachment #806811 - Attachment is obsolete: true
tracking-fennec: ? → -
Re-noming, we'll want this when the new sync ships, so we can only show the sync promo banner if sync isn't set up.
tracking-fennec: - → ?
This isn't just for add-ons. This would give us a less fragile way to do this in JS (encapsulating the JNI stuff behind an API).
Summary: Create a JS API to let an add-on know whether or not sync is set up → Create a JS API to know whether or not sync is set up
tracking-fennec: ? → 29+
This is more interesting, now that we have multiple Android Account types.  We now can match

(Legacy Sync)?|(Firefox Account)*

on the system.  I'm going to assert that we won't ever allow both account types at the same time (but the code here should be robust enough to handle that case) and it's unlikely that we'll allow (Firefox Account){2,} anytime soon.

That suggests returning a list of Accounts, each an object with a type.  Most callers will just query if the list is non-empty, for which we might provide a helper function.
Blocks: 958891
tracking-fennec: 29+ → ?
Hardware: ARM → All
Whiteboard: [qa?]
As part of Bug 958891, we'll want this to grow the ability to open the Sync|FxA Getting Started activity.
Summary: Create a JS API to know whether or not sync is set up → Create a JS API for Sync accounts
Whiteboard: [qa?] → [qa-]
tracking-fennec: ? → 29+
Priority: -- → P1
Comment on attachment 8377381 [details] [diff] [review]
Create a JS interface to Sync configuration.

Tested on my device.

I spent a bunch of time on the JNI approach to no avail.

N.B., this uses promises. Spinning the event loop to wait for the result (exactly as does SharedPreferences.jsm) caused stalls up to 30 seconds long on my phone, and is a terrible idea anyway, so rock on with your bad async self.
Attachment #8377381 - Flags: review?(margaret.leibovic)
N.B., this implementation depends on Bug 946344's GeckoEventResponder changes. It'll need adjustment to land on 29, or that bug will need to be uplifted.
Depends on: 946344
Blocks: 974195
Comment on attachment 8377381 [details] [diff] [review]
Create a JS interface to Sync configuration.

Review of attachment 8377381 [details] [diff] [review]:
-----------------------------------------------------------------

::: mobile/android/base/BrowserApp.java
@@ +1268,5 @@
> +                    EventDispatcher.sendResponse(message, response);
> +                } else {
> +                    response.put("error", "Unknown kind");
> +                    EventDispatcher.sendError(message, response);
> +                }

Sigh, more stuff in BrowserApp. Part of me thinks we should make a new class for this to live in, but I don't know if that should just be punted to part of a greater cleanup effort.

::: mobile/android/modules/Accounts.jsm
@@ +18,5 @@
> + *
> + * Usage:
> + *
> + *   Cu.import("resource://gre/modules/Accounts.jsm");
> + *   Accounts.anySyncAccountsExist(

This should be Accounts.anySyncAccountsExist().then(
Attachment #8377381 - Flags: review?(margaret.leibovic) → review+
Also, can we write a test for this?
With tests, no less!

https://hg.mozilla.org/integration/fx-team/rev/f51db1b6c9a6

needinfo on me for uplift.
Flags: needinfo?(rnewman)
Target Milestone: --- → Firefox 30
Pah. Tests passed locally but not remotely because the setup activity was just taking too long to launch.

(Yes, I'm one of the tiny set of people who actually runs the Robocop tests before landing.)

Commented out the failing part of the test and relanded:

https://hg.mozilla.org/integration/fx-team/rev/2af0db58021b
https://hg.mozilla.org/mozilla-central/rev/2af0db58021b
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Comment on attachment 8377381 [details] [diff] [review]
Create a JS interface to Sync configuration.

Requesting uplift. Needed for Sync promo on 29. No strings. Happily baked on m-c for a while.
Attachment #8377381 - Flags: approval-mozilla-aurora?
Flags: needinfo?(rnewman)
Attachment #8377381 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
Backed out for bustage (depends on bug 946344 IIUC). Please post a branch-specific patch for uplift here or nominate that for uplift as well.
https://hg.mozilla.org/releases/mozilla-aurora/rev/a4d31bafa9a6

https://tbpl.mozilla.org/php/getParsedLog.php?id=35149110&tree=Mozilla-Aurora
Flags: needinfo?(rnewman)
Comment on attachment 8380795 [details] [diff] [review]
Patch for uplift.

Flagging margaret to double-check that I Auroraified this correctly. Tests pass.
Attachment #8380795 - Flags: feedback?(margaret.leibovic)
Flags: needinfo?(rnewman)
Comment on attachment 8380795 [details] [diff] [review]
Patch for uplift.

Review of attachment 8380795 [details] [diff] [review]:
-----------------------------------------------------------------

::: mobile/android/modules/Accounts.jsm
@@ +52,5 @@
> +      kind: kind,
> +    }, (data, error) => {
> +      if (error) {
> +        deferred.reject(error);
> +        return;

I don't think there was an error param in the old world, so I'm not sure that this will ever get called. But I suppose that's okay, since you're handling the !data case below.
Attachment #8380795 - Flags: feedback?(margaret.leibovic) → feedback+
Thanks, Margaret!
Depends on: 977271
Product: Android Background Services → Firefox for Android
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: