Bug 1064263 - Part 1: avoid crash when Sync is partially configured. r=nalexander
--- a/mobile/android/base/overlays/service/sharemethods/SendTab.java
+++ b/mobile/android/base/overlays/service/sharemethods/SendTab.java
@@ -201,16 +201,23 @@ public class SendTab extends ShareMethod
ParcelableClientRecord record = ParcelableClientRecord.fromClientRecord(client);
records[i] = record;
validGUIDs.add(record.guid);
i++;
}
+ if (validGUIDs.isEmpty()) {
+ // Guess we'd better override. We have no clients.
+ // This does the broadcast for us.
+ setOverrideIntent(FxAccountGetStartedActivity.class);
+ return;
+ }
+
Intent uiStateIntent = getUIStateIntent();
uiStateIntent.putExtra(EXTRA_CLIENT_RECORDS, records);
broadcastUIState(uiStateIntent);
}
/**
* Record our intention to redirect the user to a different activity when they attempt to share
* with us, usually because we found something wrong with their Sync account (a need to login,
@@ -225,16 +232,17 @@ public class SendTab extends ShareMethod
Intent intent = new Intent(context, activityClass);
// Per http://stackoverflow.com/a/8992365, this triggers a known bug with
// the soft keyboard not being shown for the started activity. Why, Android, why?
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Intent uiStateIntent = getUIStateIntent();
uiStateIntent.putExtra(OVERRIDE_INTENT, intent);
+
broadcastUIState(uiStateIntent);
}
private static void registerDisplayURICommand() {
final CommandProcessor processor = CommandProcessor.getProcessor();
processor.registerCommand("displayURI", new CommandRunner(3) {
@Override
public void executeCommand(final GlobalSession session, List<String> args) {
--- a/mobile/android/base/overlays/ui/SendTabDeviceListArrayAdapter.java
+++ b/mobile/android/base/overlays/ui/SendTabDeviceListArrayAdapter.java
@@ -107,34 +107,37 @@ public class SendTabDeviceListArrayAdapt
dialog.show();
}
});
return row;
}
// The remaining states delegate to the SentTabTargetSelectedListener.
- final String listenerGUID;
-
- ParcelableClientRecord clientRecord = getItem(position);
+ final ParcelableClientRecord clientRecord = getItem(position);
if (currentState == State.LIST) {
row.setText(clientRecord.name);
row.setCompoundDrawablesWithIntrinsicBounds(getImage(clientRecord), 0, 0, 0);
- listenerGUID = clientRecord.guid;
- } else {
- listenerGUID = null;
- }
+ final String listenerGUID = clientRecord.guid;
- row.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View view) {
- listener.onSendTabTargetSelected(listenerGUID);
- }
- });
+ row.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ listener.onSendTabTargetSelected(listenerGUID);
+ }
+ });
+ } else {
+ row.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ listener.onSendTabActionSelected();
+ }
+ });
+ }
return row;
}
private static int getImage(ParcelableClientRecord record) {
if ("mobile".equals(record.type)) {
return R.drawable.sync_mobile_inactive;
}
--- a/mobile/android/base/overlays/ui/SendTabList.java
+++ b/mobile/android/base/overlays/ui/SendTabList.java
@@ -1,17 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.overlays.ui;
import static org.mozilla.gecko.overlays.ui.SendTabList.State.LIST;
import static org.mozilla.gecko.overlays.ui.SendTabList.State.LOADING;
-import static org.mozilla.gecko.overlays.ui.SendTabList.State.NONE;
import static org.mozilla.gecko.overlays.ui.SendTabList.State.SHOW_DEVICES;
import java.util.Arrays;
import org.mozilla.gecko.Assert;
import org.mozilla.gecko.R;
import org.mozilla.gecko.overlays.service.sharemethods.ParcelableClientRecord;
@@ -106,39 +105,32 @@ public class SendTabList extends ListVie
if (state == SHOW_DEVICES) {
clientListAdapter.setDialog(getDialog());
}
}
public void setSyncClients(final ParcelableClientRecord[] c) {
final ParcelableClientRecord[] clients = c == null ? new ParcelableClientRecord[0] : c;
- int size = clients.length;
- if (size == 0) {
- // Just show a button to set up Sync (or whatever).
- switchState(NONE);
- return;
- }
-
clientListAdapter.setClientRecordList(Arrays.asList(clients));
- if (size <= MAXIMUM_INLINE_ELEMENTS) {
+ if (clients.length <= MAXIMUM_INLINE_ELEMENTS) {
// Show the list of devices in-line.
switchState(LIST);
return;
}
// Just show a button to launch the list of devices to choose from.
switchState(SHOW_DEVICES);
}
/**
* Get an AlertDialog listing all devices, allowing the user to select the one they want.
* Used when more than MAXIMUM_INLINE_ELEMENTS devices are found (to avoid displaying them all
- * inline and looking crazy.
+ * inline and looking crazy).
*/
public AlertDialog getDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
final ParcelableClientRecord[] records = clientListAdapter.toArray();
final String[] dialogElements = new String[records.length];
for (int i = 0; i < records.length; i++) {
--- a/mobile/android/base/overlays/ui/SendTabTargetSelectedListener.java
+++ b/mobile/android/base/overlays/ui/SendTabTargetSelectedListener.java
@@ -10,9 +10,16 @@ package org.mozilla.gecko.overlays.ui;
*/
public interface SendTabTargetSelectedListener {
/**
* Called when a row in the SendTabList is clicked.
*
* @param targetGUID The GUID of the ClientRecord the element represents (if any, otherwise null)
*/
public void onSendTabTargetSelected(String targetGUID);
+
+ /**
+ * Called when the overall Send Tab item is clicked.
+ *
+ * This implies that the clients list was unavailable.
+ */
+ public void onSendTabActionSelected();
}
--- a/mobile/android/base/overlays/ui/ShareDialog.java
+++ b/mobile/android/base/overlays/ui/ShareDialog.java
@@ -290,24 +290,27 @@ public class ShareDialog extends LocaleA
}
/*
* Button handlers. Send intents to the background service responsible for processing requests
* on Fennec in the background. (a nice extensible mechanism for "doing stuff without properly
* launching Fennec").
*/
- public void sendTab(String targetGUID) {
- // If an override intent has been set, dispatch it.
- if (sendTabOverrideIntent != null) {
- startActivity(sendTabOverrideIntent);
- finish();
- return;
- }
+ @Override
+ public void onSendTabActionSelected() {
+ // This requires an override intent.
+ Assert.isTrue(sendTabOverrideIntent != null);
+ startActivity(sendTabOverrideIntent);
+ finish();
+ }
+
+ @Override
+ public void onSendTabTargetSelected(String targetGUID) {
// targetGUID being null with no override intent should be an impossible state.
Assert.isTrue(targetGUID != null);
Intent serviceIntent = getServiceIntent(ShareMethod.Type.SEND_TAB);
// Currently, only one extra parameter is necessary (the GUID of the target device).
Bundle extraParameters = new Bundle();
@@ -315,21 +318,16 @@ public class ShareDialog extends LocaleA
extraParameters.putStringArray(SendTab.SEND_TAB_TARGET_DEVICES, new String[] { targetGUID });
serviceIntent.putExtra(OverlayConstants.EXTRA_PARAMETERS, extraParameters);
startService(serviceIntent);
slideOut();
}
- @Override
- public void onSendTabTargetSelected(String targetGUID) {
- sendTab(targetGUID);
- }
-
public void addToReadingList() {
startService(getServiceIntent(ShareMethod.Type.ADD_TO_READING_LIST));
slideOut();
}
public void addBookmark() {
startService(getServiceIntent(ShareMethod.Type.ADD_BOOKMARK));
slideOut();