Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Unified Diff: Application/src/main/java/org/chromium/customtabsclient/MainActivity.java

Issue 2626633002: Log the process importance. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Application/src/main/java/org/chromium/customtabsclient/MainActivity.java
diff --git a/Application/src/main/java/org/chromium/customtabsclient/MainActivity.java b/Application/src/main/java/org/chromium/customtabsclient/MainActivity.java
index 35d563cf9401e080c5ef13238e45ffc734b5b449..3869244cee572333caeea51e034c1c504bc72027 100644
--- a/Application/src/main/java/org/chromium/customtabsclient/MainActivity.java
+++ b/Application/src/main/java/org/chromium/customtabsclient/MainActivity.java
@@ -15,6 +15,7 @@
package org.chromium.customtabsclient;
import android.app.Activity;
+import android.app.ActivityManager;
import android.app.ActivityOptions;
import android.app.PendingIntent;
import android.content.Intent;
@@ -26,6 +27,8 @@ import android.graphics.Color;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
import android.support.customtabs.CustomTabsCallback;
import android.support.customtabs.CustomTabsClient;
import android.support.customtabs.CustomTabsIntent;
@@ -70,6 +73,33 @@ public class MainActivity extends Activity implements OnClickListener, ServiceCo
private Button mLaunchButton;
private MediaPlayer mMediaPlayer;
+ /**
+ * Once per second, asks the framework for the process importance, and logs any change.
+ */
+ private Runnable mLogImportance = new Runnable() {
+ private int mPreviousImportance = -1;
+ private boolean mPreviousServiceInUse = false;
+ private Handler mHandler = new Handler(Looper.getMainLooper());
+
+ @Override
+ public void run() {
+ ActivityManager.RunningAppProcessInfo state =
+ new ActivityManager.RunningAppProcessInfo();
+ ActivityManager.getMyMemoryState(state);
+ int importance = state.importance;
+ boolean serviceInUse = state.importanceReasonCode
+ == ActivityManager.RunningAppProcessInfo.REASON_SERVICE_IN_USE;
+ if (importance != mPreviousImportance || serviceInUse != mPreviousServiceInUse) {
+ mPreviousImportance = importance;
+ mPreviousServiceInUse = serviceInUse;
+ String message = "New importance = " + importance;
+ if (serviceInUse) message += " (Reason: Service in use)";
+ Log.w(TAG, message);
+ }
+ mHandler.postDelayed(this, 1000);
+ }
+ };
+
private static class NavigationCallback extends CustomTabsCallback {
@Override
public void onNavigationEvent(int navigationEvent, Bundle extras) {
@@ -146,6 +176,8 @@ public class MainActivity extends Activity implements OnClickListener, ServiceCo
mPackageNameToBind = null;
}
});
+
+ mLogImportance.run();
}
@Override
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698