| Index: chrome/android/java/src/org/chromium/chrome/browser/gsa/GSAServiceClient.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/gsa/GSAServiceClient.java b/chrome/android/java/src/org/chromium/chrome/browser/gsa/GSAServiceClient.java
|
| index e11d384295ed43e289fe6b187eafdcfb48e0d374..df66bbfb72ecbf7f450026541974b64bf99a6ecc 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/gsa/GSAServiceClient.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/gsa/GSAServiceClient.java
|
| @@ -5,14 +5,11 @@
|
| package org.chromium.chrome.browser.gsa;
|
|
|
| import android.annotation.SuppressLint;
|
| -import android.app.ActivityManager;
|
| import android.content.ComponentName;
|
| import android.content.Context;
|
| import android.content.Intent;
|
| import android.content.ServiceConnection;
|
| -import android.os.AsyncTask;
|
| import android.os.Bundle;
|
| -import android.os.Debug;
|
| import android.os.Handler;
|
| import android.os.IBinder;
|
| import android.os.Message;
|
| @@ -22,15 +19,10 @@ import android.os.StrictMode;
|
| import android.util.Log;
|
|
|
| import org.chromium.base.Callback;
|
| -import org.chromium.base.ContextUtils;
|
| -import org.chromium.base.TraceEvent;
|
| -import org.chromium.base.VisibleForTesting;
|
| import org.chromium.base.annotations.SuppressFBWarnings;
|
| import org.chromium.base.metrics.RecordHistogram;
|
| import org.chromium.chrome.browser.AppHooks;
|
|
|
| -import java.util.List;
|
| -
|
| /**
|
| * A simple client that connects and talks to the GSAService using Messages.
|
| */
|
| @@ -41,8 +33,7 @@ public class GSAServiceClient {
|
| * Constants for gsa communication. These should not change without corresponding changes on the
|
| * service side in GSA.
|
| */
|
| - @VisibleForTesting
|
| - static final String GSA_SERVICE = "com.google.android.ssb.action.SSB_SERVICE";
|
| + private static final String GSA_SERVICE = "com.google.android.ssb.action.SSB_SERVICE";
|
| public static final int REQUEST_REGISTER_CLIENT = 2;
|
| public static final int RESPONSE_UPDATE_SSB = 3;
|
|
|
| @@ -52,16 +43,12 @@ public class GSAServiceClient {
|
| public static final String KEY_GSA_SUPPORTS_BROADCAST =
|
| "ssb_service:chrome_holds_account_update_permission";
|
|
|
| - @VisibleForTesting
|
| - static final int INVALID_PSS = -1;
|
| -
|
| static final String ACCOUNT_CHANGE_HISTOGRAM = "Search.GsaAccountChangeNotificationSource";
|
| // For the histogram above. Append-only.
|
| static final int ACCOUNT_CHANGE_SOURCE_SERVICE = 0;
|
| static final int ACCOUNT_CHANGE_SOURCE_BROADCAST = 1;
|
| static final int ACCOUNT_CHANGE_SOURCE_COUNT = 2;
|
|
|
| - private static boolean sHasRecordedPss;
|
| /** Messenger to handle incoming messages from the service */
|
| private final Messenger mMessenger;
|
| private final IncomingHandler mHandler;
|
| @@ -72,7 +59,6 @@ public class GSAServiceClient {
|
|
|
| /** Messenger for communicating with service. */
|
| private Messenger mService;
|
| - private ComponentName mComponentName;
|
|
|
| /**
|
| * Handler of incoming messages from service.
|
| @@ -92,77 +78,9 @@ public class GSAServiceClient {
|
| String account = mGsaHelper.getGSAAccountFromState(bundle.getByteArray(KEY_GSA_STATE));
|
| RecordHistogram.recordEnumeratedHistogram(ACCOUNT_CHANGE_HISTOGRAM,
|
| ACCOUNT_CHANGE_SOURCE_SERVICE, ACCOUNT_CHANGE_SOURCE_COUNT);
|
| - GSAState.getInstance(mContext.getApplicationContext()).setGsaAccount(account);
|
| - if (sHasRecordedPss) {
|
| - if (mOnMessageReceived != null) mOnMessageReceived.onResult(bundle);
|
| - return;
|
| - }
|
| -
|
| - // Getting the PSS for the GSA service process can be long, don't block the UI thread on
|
| - // that. Also, don't process the callback before the PSS is known, since the callback
|
| - // can lead to a service disconnect, which can lead to the framework killing the
|
| - // process. Hence an AsyncTask (long operation), and processing the callback in
|
| - // onPostExecute() (don't disconnect before).
|
| - sHasRecordedPss = true;
|
| - new AsyncTask<Void, Void, Integer>() {
|
| - @Override
|
| - protected Integer doInBackground(Void... params) {
|
| - TraceEvent.begin("GSAServiceClient.getPssForservice");
|
| - try {
|
| - // Looking for the service process is done by component name, which is
|
| - // inefficient. We really want the PID, which is only accessible from within
|
| - // a Binder transaction. Since the service connection is Messenger-based,
|
| - // the calls are not processed from a Binder thread. The alternatives are:
|
| - // 1. Override methods in the framework to append the calling PID to the
|
| - // Message.
|
| - // 2. Usse msg.callingUid to narrow down the search.
|
| - //
|
| - // (1) is dirty (and brittle), and (2) only works on L+, and still requires
|
| - // to get the full list of services from ActivityManager.
|
| - return getPssForService(mComponentName);
|
| - } finally {
|
| - TraceEvent.end("GSAServiceClient.getPssForservice");
|
| - }
|
| - }
|
| -
|
| - @Override
|
| - protected void onPostExecute(Integer pssInKB) {
|
| - if (pssInKB != INVALID_PSS) {
|
| - RecordHistogram.recordMemoryKBHistogram(
|
| - "Search.GsaProcessMemoryPss", pssInKB);
|
| - }
|
| - if (mOnMessageReceived != null) mOnMessageReceived.onResult(bundle);
|
| - }
|
| - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Get the PSS used by the process hosting a service.
|
| - *
|
| - * @param packageName Package name of the service to search for.
|
| - * @return the PSS in kB of the process hosting a service, or INVALID_PSS.
|
| - */
|
| - @VisibleForTesting
|
| - static int getPssForService(ComponentName componentName) {
|
| - if (componentName == null) return INVALID_PSS;
|
| - Context context = ContextUtils.getApplicationContext();
|
| - ActivityManager activityManager =
|
| - (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
| - List<ActivityManager.RunningServiceInfo> services =
|
| - activityManager.getRunningServices(1000);
|
| - if (services == null) return INVALID_PSS;
|
| - int pid = -1;
|
| - for (ActivityManager.RunningServiceInfo info : services) {
|
| - if (componentName.equals(info.service)) {
|
| - pid = info.pid;
|
| - break;
|
| - }
|
| + GSAState.getInstance(mContext).setGsaAccount(account);
|
| + if (mOnMessageReceived != null) mOnMessageReceived.onResult(bundle);
|
| }
|
| - if (pid == -1) return INVALID_PSS;
|
| - Debug.MemoryInfo infos[] = activityManager.getProcessMemoryInfo(new int[] {pid});
|
| - if (infos == null || infos.length == 0) return INVALID_PSS;
|
| - return infos[0].getTotalPss();
|
| }
|
|
|
| /**
|
| @@ -236,7 +154,6 @@ public class GSAServiceClient {
|
| if (mContext == null) return;
|
|
|
| mService = new Messenger(service);
|
| - mComponentName = name;
|
| try {
|
| Message registerClientMessage = Message.obtain(
|
| null, REQUEST_REGISTER_CLIENT);
|
|
|