Authenticated Cloud Endpoint Failure at Android Client Endpoint

I have an application in production that receives a significant amount of force / close when calling an authenticated Cloud endpoint. The most significant message is "java.lang.IllegalArgumentException: service not registered: com.google.android.gms.internal.es@4481e6a8 " . Logic works correctly 95% of the time. The failure stack trace is as follows:

java.lang.RuntimeException: An error occurred while doing doInBackground () in android.os.AsyncTask $ 3.done (AsyncTask.java:200) in java.util.concurrent.FutureTask $ Sync.innerSetException (FutureTask.java:273) in java .util.concurrent.FutureTask.setException (FutureTask.java:124) in java.util.concurrent.FutureTask $ Sync.innerRun (FutureTask.java:307) in java.util.concurrent.FutureTask.run (FutureTask.java:137 ) in java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1068) in java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.javahaps61) on java.lang.Thread.run (Thread.java: 1096) Called: java.lang.IllegalArgumentException: Service not registered: com.google.android.gms.internal.es@4481e6a8 at android.app.ActivityThread $ PackageInfo.forgetServiceDispatcher (ActivityThread.java:1074) in android.app.ContextImpl.unbindService (ContextImpl.java:886) in android.content.ContextWrapper.unbindService (ContextWrapper.javahaps52) in com.google.android.gms.auth.GoogleAuthUtil.java.lang.String getToken (android.content.Context, java.lang.String, java.lang.String) (Unknown Source) in java.util.concurrent.FutureTask $ Sync.innerRun (FutureTask.java.305) in java.util.concurrent.FutureTask $ Sync.innerRun (FutureTask.java.305) in java.util.concurrent.FutureTask $ Sync.innerRun (FutureTask.java.305) in java .util.concurrent.FutureTask $ Sync.innerRun (FutureTask.java.305) at com.google.android.gms.auth.GoogleAuthUtil.java.lang.String getToken (android.content.Context, java.lang.String, java .lang.String) (Unknown Source) in java.util.concurrent.FutureTask $ Sync.innerRun (FutureTask.java.305) in java.util.concurrent.FutureTask $ Sync.innerRun (FutureTask.java.305) in java. util.concurrent.FutureTask $ Sync.innerRun (FutureTask.java.305) at java.util.concurrent.FutureTask $ Sync.innerRun (FutureTask.java.305) at com.google.api.client.googleapis.extensions.android. gms.auth.GoogleAccountCredential .java.lang.String getToken () (SourceFile: 192) at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential $ RequestHandler.void interception (com.google.api.client.http. HttpRequest) (SourceFile: 217) at com.google.api.client.http.HttpRequest.com.google.api.client.http.HttpResponse execute () (SourceFile: 836) in com.google.api.client.googleapis. services.AbstractGoogleClientRequest.com.google.api.client.http.HttpResponse executeUnparsed (boolean) (SourceFile: 412) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.com.google.apipse.clienthcl.htt.client.cli executeUnparsed () (SourceFile: 345) in com.google.api.client.googleapis.services.AbstractGoogleClientRequest.java.lang.Object execute () (SourceFile: 463) in com.jdub.empiretracker.EmpireTrackerActivity $ QueryMarketgoetsogle QuarkMgoetets .api.services.marketendpoint.model.Market doInBackground (com.google.api.services.marketendpoint.model.Market []) (SourceFile: 355) in com.jdub.empiretracker. EmpireTrackerActivity $ QueryMarketStats.java.lang.Object doInBackground (java.lang.Object []) (SourceFile: 1) at android.os.AsyncTask $ 2.call (AsyncTask.java:185) in java.util.concurrent.FutureTask $ Sync .innerRun (FutureTask.java:305) ... 4 more

My implementation is very consistent with Google samples. For example, my Android activity uses AsyncTask to make a call as follows:

private class QueryMarketStats extends AsyncTask<com.google.api.services.marketendpoint.model.Market, com.google.api.services.marketendpoint.model.Market, com.google.api.services.marketendpoint.model.Market> { /* (non-Javadoc) * @see android.os.AsyncTask#doInBackground(Params[]) */ @Override protected com.google.api.services.marketendpoint.model.Market doInBackground(com.google.api.services.marketendpoint.model.Market...markets) { com.google.api.services.marketendpoint.model.Market result = null; try { result = service.market().latest(state.getServerID()).execute(); } catch (SSLException e) { PrimeDataStore(); Log.d("app", e.getMessage(), e); } catch (GoogleAuthIOException e) { Log.d("app", e.getMessage(), e); } catch (IOException e) { Log.d("app", e.getMessage(), e); } return result; } /* (non-Javadoc) * @see android.os.AsyncTask#onPostExecute(java.lang.Object) */ @Override protected void onPostExecute(com.google.api.services.marketendpoint.model.Market result) { // Process result... } } 

Line indicating an error: result = service.market (). last (state.getServerID ()). execute ();

I checked the parameter for getServerID () returns a valid value. My theory at the moment is that Google Play Services cannot provide an account that is still authenticated. Although I could not reproduce, I believe that a problem may occur when the application goes to sleep. Therefore, I confirmed my onResume () logic as follows:

  @Override protected void onResume() { super.onResume(); checkPlayServices(); isInFront = true; } 

What else could cause this intermittent failure? Is this a known issue?

+4
source share
1 answer

Instead of a better alternative, I catch the exception and start the attempt with success. Any intermittent problem leads to the fact that the service is not registered at the point in time when the endpoint is called, future calls to the service are working correctly.

Bypass code

 @Override protected com.google.api.services.marketendpoint.model.Market doInBackground(com.google.api.services.marketendpoint.model.Market...markets) { com.google.api.services.marketendpoint.model.Market result = null; try { result = service.market().latest(state.getServerID()).execute(); } catch (SSLException e) { PrimeDataStore(); Log(e); } catch (GoogleAuthIOException e) { Log(e); } catch (IOException e) { Log(e); } catch (IllegalArgumentException e) { // This caused a lot of intermittent force/closes. Log(e); } return result; } @Override protected void onPostExecute(com.google.api.services.marketendpoint.model.Market result) { DismissProgressDialogIfPresent(); com.google.api.services.marketendpoint.model.Market m = (com.google.api.services.marketendpoint.model.Market) result; if( m == null) { // Verify the current activity is active if( isInFront ) { // Present a retry/cancel dialog AlertDialog.Builder builder = new AlertDialog.Builder(EmpireTrackerActivity.this); builder.setMessage("An error was encountered retrieving the latest market data.\n\nPlease verify you are connected to the Internet."); builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); m_ProgressDlg = ProgressDialog.show(EmpireTrackerActivity.this, "Please wait...", "Retrieving data ...", true); new QueryMarketStats().execute(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); } return; } // Process newly posted data state.setMarketObj(m); state.setIsInitialized(true); state.WriteFile(EmpireTrackerActivity.this); super.onPostExecute(result); } 

}

+2
source

Source: https://habr.com/ru/post/1485308/


All Articles