Skip to content

FIX #327: SendWorker now works in the separate process service. - #329

Closed
romansl wants to merge 1 commit into
ACRA:masterfrom
romansl:master
Closed

FIX #327: SendWorker now works in the separate process service.#329
romansl wants to merge 1 commit into
ACRA:masterfrom
romansl:master

Conversation

@romansl

@romansl romansl commented Nov 23, 2015

Copy link
Copy Markdown
Contributor

This is a basic implementation.

Possible improvements:

  • Show notification while send task in progress (prevents from rare system-initiated process kill).
  • Merge SendService and SendWorker.
  • Self-stop SendService after delay.
  • Subscribe to "Internet availabale" broadcast and start SendService.

@william-ferguson-au

Copy link
Copy Markdown
Member

Will wait until 4.70 is released before merging this.

@xmenxwk

xmenxwk commented Dec 2, 2015

Copy link
Copy Markdown

Very good but showing notification is something I would avoid.

@andryr

andryr commented Dec 23, 2015

Copy link
Copy Markdown

If a crash occurs on startup (eg in Application.onCreate()) it will enter in a infinite loop because of the Service.

@william-ferguson-au

Copy link
Copy Markdown
Member

@andryr how does having the service cause an infinite loop?

@romansl

romansl commented Dec 24, 2015

Copy link
Copy Markdown
Contributor Author

Each process has its own Application instance.

@william-ferguson-au

Copy link
Copy Markdown
Member

@romansl are you answering my question to @andryr ?

@romansl

romansl commented Dec 24, 2015

Copy link
Copy Markdown
Contributor Author

My solution for this problem:

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        if (!getPackageName().equals(getAppNameByPID(android.os.Process.myPid()))) {
            return;
        }

        ACRA.init(this);
        ACRA.getErrorReporter().setReportSender(new HockeySender());

        // other initializations...
    }

    private String getAppNameByPID(int pid){
        ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

        for(ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()){
            if(processInfo.pid == pid){
                return processInfo.processName;
            }
        }

        return "";
    }
}

@romansl

romansl commented Dec 24, 2015

Copy link
Copy Markdown
Contributor Author

May be this check should be iside ACRA.init().

@william-ferguson-au

Copy link
Copy Markdown
Member

There are some problems with this implementation that need to be addressed.

Storing the ReportSender class instead of instance in ErrorReporter means that

  • ReportSender cannot be configured (there are definitely users who do this).
  • ReportSender must have a no arg constructor

Options are

  • enforce a no-arg constructor for ReportSender and disallow config, breaking N installs.
  • introduce ReportSenderFactory whose create method takes AppContext. Store the factory instead of ReportSender.
  • ?

I'm leaning towards the Factory. It's a bigger change in API but that will make people better aware of the change in requirements for a bespoke ReportSender.

Thoughts?

@william-ferguson-au

Copy link
Copy Markdown
Member

Closed in favour of #344

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants