Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 57c0a9a9 authored by Jeff Hamilton's avatar Jeff Hamilton Committed by Android (Google) Code Review
Browse files

Merge changes I37292676,I324a0544

* changes:
  Move the notification logic out to a listener so there can be an Activity based version of the listener as well for NFC VCARD imports.
  Fix a BroadcastReceiver leak.
parents a370c232 1167da42
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -599,17 +599,23 @@
            android:configChanges="orientation|screenSize|keyboardHidden"
            android:theme="@style/BackgroundOnly">
            <intent-filter>
                <action android:name="android.nfc.action.NDEF_DISCOVERED" />
                <action android:name="android.intent.action.VIEW" />
                <data android:mimeType="text/directory" />
                <data android:mimeType="text/vcard" />
                <data android:mimeType="text/x-vcard" />
                <data android:mimeType="text/x-vCard" />
                <data android:mimeType="text/vcard" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <activity android:name=".vcard.NfcImportVCardActivity"
            android:configChanges="orientation|screenSize|keyboardHidden"
            android:theme="@style/BackgroundOnly">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <data android:mimeType="text/directory" />
                <action android:name="android.nfc.action.NDEF_DISCOVERED" />
                <data android:mimeType="text/vcard" />
                <data android:mimeType="text/x-vcard" />
                <data android:mimeType="text/x-vCard" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
+1 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ public abstract class AccountTypeManager {
     * the available authenticators. This method can safely be called from the UI thread.
     */
    public static AccountTypeManager getInstance(Context context) {
        context = context.getApplicationContext();
        AccountTypeManager service =
                (AccountTypeManager) context.getSystemService(ACCOUNT_TYPE_SERVICE);
        if (service == null) {
+5 −14
Original line number Diff line number Diff line
@@ -72,7 +72,6 @@ public class CancelActivity extends Activity implements ServiceConnection {
    private int mJobId;
    private String mDisplayName;
    private int mType;
    private Messenger mMessenger;

    @Override
    public void onCreate(Bundle savedInstanceState) {
@@ -121,29 +120,21 @@ public class CancelActivity extends Activity implements ServiceConnection {
    }

    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
        mMessenger = new Messenger(service);
    public void onServiceConnected(ComponentName name, IBinder binder) {
        VCardService service = ((VCardService.MyBinder) binder).getService();

        boolean callFinish = false;
        try {
            final CancelRequest request = new CancelRequest(mJobId, mDisplayName);
            mMessenger.send(Message.obtain(null, VCardService.MSG_CANCEL_REQUEST, request));
            callFinish = true;
        } catch (RemoteException e) {
            Log.e(LOG_TAG, "RemoteException is thrown when trying to send request");
            showDialog(R.id.dialog_cancel_failed);
            // finish() should be called from the Dialog
            service.handleCancelRequest(request, null);
        } finally {
            unbindService(this);
        }

        if (callFinish) {
        finish();
    }
    }

    @Override
    public void onServiceDisconnected(ComponentName name) {
        mMessenger = null;
        // do nothing
    }
}
+12 −7
Original line number Diff line number Diff line
@@ -235,9 +235,11 @@ public class ExportProcessor extends ProcessorBase {
        final String tickerText =
                mService.getString(R.string.exporting_contact_list_title);
        final Notification notification =
                VCardService.constructProgressNotification(mService, VCardService.TYPE_EXPORT,
                        description, tickerText, mJobId, displayName, totalCount, currentCount);
        mNotificationManager.notify(VCardService.DEFAULT_NOTIFICATION_TAG, mJobId, notification);
                NotificationImportExportListener.constructProgressNotification(mService,
                        VCardService.TYPE_EXPORT, description, tickerText, mJobId, displayName,
                        totalCount, currentCount);
        mNotificationManager.notify(NotificationImportExportListener.DEFAULT_NOTIFICATION_TAG,
                mJobId, notification);
    }

    private void doCancelNotification() {
@@ -245,16 +247,19 @@ public class ExportProcessor extends ProcessorBase {
        final String description = mService.getString(R.string.exporting_vcard_canceled_title,
                mExportRequest.destUri.getLastPathSegment());
        final Notification notification =
                VCardService.constructCancelNotification(mService, description);
        mNotificationManager.notify(VCardService.DEFAULT_NOTIFICATION_TAG, mJobId, notification);
                NotificationImportExportListener.constructCancelNotification(mService, description);
        mNotificationManager.notify(NotificationImportExportListener.DEFAULT_NOTIFICATION_TAG,
                mJobId, notification);
    }

    private void doFinishNotification(final String title, final String description) {
        if (DEBUG) Log.d(LOG_TAG, "send finish notification: " + title + ", " + description);
        final Intent intent = new Intent(mService, PeopleActivity.class);
        final Notification notification =
                VCardService.constructFinishNotification(mService, title, description, intent);
        mNotificationManager.notify(VCardService.DEFAULT_NOTIFICATION_TAG, mJobId, notification);
                NotificationImportExportListener.constructFinishNotification(mService, title,
                        description, intent);
        mNotificationManager.notify(NotificationImportExportListener.DEFAULT_NOTIFICATION_TAG,
                mJobId, notification);
    }

    @Override
+11 −27
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ public class ExportVCardActivity extends Activity implements ServiceConnection,
     */
    private volatile boolean mProcessOngoing = true;

    private Messenger mOutgoingMessenger;
    private VCardService mService;
    private final Messenger mIncomingMessenger = new Messenger(new IncomingHandler());

    // Used temporarily when asking users to confirm the file name
@@ -138,10 +138,8 @@ public class ExportVCardActivity extends Activity implements ServiceConnection,
                }
                final ExportRequest request = new ExportRequest(mDestinationUri);
                // The connection object will call finish().
                if (trySend(Message.obtain(null, VCardService.MSG_EXPORT_REQUEST, request))) {
                    Log.i(LOG_TAG, "Successfully sent export request. Finish itself");
                    unbindAndFinish();
                }
                mService.handleExportRequest(request, new NotificationImportExportListener(
                        ExportVCardActivity.this));
            }
        }
    }
@@ -160,14 +158,16 @@ public class ExportVCardActivity extends Activity implements ServiceConnection,
            return;
        }

        if (startService(new Intent(this, VCardService.class)) == null) {
        Intent intent = new Intent(this, VCardService.class);

        if (startService(intent) == null) {
            Log.e(LOG_TAG, "Failed to start vCard service");
            mErrorReason = getString(R.string.fail_reason_unknown);
            showDialog(R.id.dialog_fail_to_export_with_reason);
            return;
        }

        if (!bindService(new Intent(this, VCardService.class), this, Context.BIND_AUTO_CREATE)) {
        if (!bindService(intent, this, Context.BIND_AUTO_CREATE)) {
            Log.e(LOG_TAG, "Failed to connect to vCard service.");
            mErrorReason = getString(R.string.fail_reason_unknown);
            showDialog(R.id.dialog_fail_to_export_with_reason);
@@ -176,14 +176,11 @@ public class ExportVCardActivity extends Activity implements ServiceConnection,
    }

    @Override
    public synchronized void onServiceConnected(ComponentName name, IBinder service) {
    public synchronized void onServiceConnected(ComponentName name, IBinder binder) {
        if (DEBUG) Log.d(LOG_TAG, "connected to service, requesting a destination file name");
        mConnected = true;
        mOutgoingMessenger = new Messenger(service);
        final Message message =
                Message.obtain(null, VCardService.MSG_REQUEST_AVAILABLE_EXPORT_DESTINATION);
        message.replyTo = mIncomingMessenger;
        trySend(message);
        mService = ((VCardService.MyBinder) binder).getService();
        mService.handleRequestAvailableExportDestination(mIncomingMessenger);
        // Wait until MSG_SET_AVAILABLE_EXPORT_DESTINATION message is available.
    }

@@ -191,7 +188,7 @@ public class ExportVCardActivity extends Activity implements ServiceConnection,
    @Override
    public synchronized void onServiceDisconnected(ComponentName name) {
        if (DEBUG) Log.d(LOG_TAG, "onServiceDisconnected()");
        mOutgoingMessenger = null;
        mService = null;
        mConnected = false;
        if (mProcessOngoing) {
            // Unexpected disconnect event.
@@ -267,19 +264,6 @@ public class ExportVCardActivity extends Activity implements ServiceConnection,
        }
    }

    private boolean trySend(Message message) {
        try {
            mOutgoingMessenger.send(message);
            return true;
        } catch (RemoteException e) {
            Log.e(LOG_TAG, "RemoteException is thrown when trying to send request");
            unbindService(this);
            mErrorReason = getString(R.string.fail_reason_unknown);
            showDialog(R.id.dialog_fail_to_export_with_reason);
            return false;
        }
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        if (DEBUG) Log.d(LOG_TAG, "ExportVCardActivity#onClick() is called");
Loading