Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.Process;
import android.view.View;
import android.view.ViewTreeObserver;
Expand Down Expand Up @@ -564,42 +563,15 @@ public static boolean isAnyAppProcessInForeground(Context appContext) {
}
if (appProcess.processName.equals(appProcessName)
|| appProcess.processName.startsWith(allowedAppProcessNamePrefix)) {
boolean isAppInForeground = true;

// For the case when the app is in foreground and the device transitions to sleep mode,
// the importance of the process is set to IMPORTANCE_TOP_SLEEPING. However, this
// importance level was introduced in M. Pre M, the process importance is not changed to
// IMPORTANCE_TOP_SLEEPING when the display turns off. So we need to rely also on the
// state of the display to decide if any app process is really visible.
if (Build.VERSION.SDK_INT < 23 /* M */) {
isAppInForeground = isScreenOn(appContext);
}

if (isAppInForeground) {
return true;
}
// Returns true if the process with `IMPORTANCE_FOREGROUND` matches current process.
return true;
}
}
}

return false;
}

/**
* Returns whether the device screen is on.
*
* @param appContext The application's context.
*/
public static boolean isScreenOn(Context appContext) {
PowerManager powerManager = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE);
if (powerManager == null) {
return true;
}
return (Build.VERSION.SDK_INT >= 20 /* KITKAT_WATCH */)
? powerManager.isInteractive()
: powerManager.isScreenOn();
}

/**
* We use StartFromBackgroundRunnable to detect if app is started from background or foreground.
* If app is started from background, we do not generate AppStart trace. This runnable is posted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,7 @@ public void setFixedLengthStreamingMode(final int contentLength) {
}

public void setFixedLengthStreamingMode(final long contentLength) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
httpUrlConnection.setFixedLengthStreamingMode(contentLength);
}
httpUrlConnection.setFixedLengthStreamingMode(contentLength);
}

public void setIfModifiedSince(final long ifmodifiedsince) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@ public void onDraw() {
* placeholder.
*/
private static boolean isAliveAndAttached(View view) {
return view.getViewTreeObserver().isAlive() && isAttachedToWindow(view);
}

/** Backport {@link View#isAttachedToWindow()} which is API 19+ only. */
private static boolean isAttachedToWindow(View view) {
if (Build.VERSION.SDK_INT >= 19) {
return view.isAttachedToWindow();
}
return view.getWindowToken() != null;
return view.getViewTreeObserver().isAlive() && view.isAttachedToWindow();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.NANOSECONDS;

import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemClock;
Expand Down Expand Up @@ -72,10 +71,7 @@ private static long wallClockMicros() {
* @return wall-clock time in microseconds.
*/
private static long elapsedRealtimeMicros() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return NANOSECONDS.toMicros(SystemClock.elapsedRealtimeNanos());
}
return MILLISECONDS.toMicros(SystemClock.elapsedRealtime());
return NANOSECONDS.toMicros(SystemClock.elapsedRealtimeNanos());
}

// TODO: make all constructors private, use public static factory methods, per Effective Java
Expand Down