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

Commit f99acf71 authored by Sean Liu's avatar Sean Liu Committed by Android (Google) Code Review
Browse files

Merge "Avoid leaking ServiceConnection"

parents fb729464 cca57302
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ public class ExportVCardActivity extends Activity implements ServiceConnection,
                    Log.d(LOG_TAG, "create document cancelled or no data returned");
                }
            }
            unbindAndFinish();
            finish();
        }
    }

@@ -161,7 +161,7 @@ public class ExportVCardActivity extends Activity implements ServiceConnection,
        startActivityForResult(getCreateDocIntent(), REQUEST_CREATE_DOCUMENT);
    }

    // Use synchronized since we don't want to call unbindAndFinish() just after this call.
    // Use synchronized since we don't want to call finish() just after this call.
    @Override
    public synchronized void onServiceDisconnected(ComponentName name) {
        if (DEBUG) Log.d(LOG_TAG, "onServiceDisconnected()");
@@ -202,14 +202,14 @@ public class ExportVCardActivity extends Activity implements ServiceConnection,
    @Override
    public void onClick(DialogInterface dialog, int which) {
        if (DEBUG) Log.d(LOG_TAG, "ExportVCardActivity#onClick() is called");
        unbindAndFinish();
        finish();
    }

    @Override
    public void onCancel(DialogInterface dialog) {
        if (DEBUG) Log.d(LOG_TAG, "ExportVCardActivity#onCancel() is called");
        mProcessOngoing = false;
        unbindAndFinish();
        finish();
    }

    @Override
@@ -218,6 +218,15 @@ public class ExportVCardActivity extends Activity implements ServiceConnection,
        super.unbindService(conn);
    }

    @Override
    protected void onDestroy() {
        if (mConnected) {
            unbindService(this);
            mConnected = false;
        }
        super.onDestroy();
    }

    /**
     * Returns the display name for the given openable Uri or null if it could not be resolved. */
    static String getOpenableUriDisplayName(Context context, Uri uri) {
@@ -234,12 +243,4 @@ public class ExportVCardActivity extends Activity implements ServiceConnection,
        }
        return null;
    }

    protected synchronized void unbindAndFinish() {
        if (mConnected) {
            unbindService(this);
            mConnected = false;
        }
        finish();
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ public class ShareVCardActivity extends ExportVCardActivity {
            file.createNewFile();
        } catch (IOException e) {
            Log.e(LOG_TAG, "Failed to create .vcf file, because: " + e);
            unbindAndFinish();
            finish();
            return;
        }

@@ -63,7 +63,7 @@ public class ShareVCardActivity extends ExportVCardActivity {
        // The connection object will call finish().
        mService.handleExportRequest(request, new NotificationImportExportListener(
                ShareVCardActivity.this));
        unbindAndFinish();
        finish();
    }

    /**