Commit b6b047db authored by Egor Pasko's avatar Egor Pasko Committed by Chromium LUCI CQ

base/android: eliminate JELLYBEAN-specific code

Seems that Cronet may be still supporting ICS, but these removed parts
should not be needed to Cronet.

Bug: 1041930
Change-Id: I3ae0cd53ab410401d6318d9f2ac8f6ba6145f25f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2633054
Commit-Queue: Egor Pasko <pasko@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846228}
parent 3d1f4a4d
......@@ -4,9 +4,7 @@
package org.chromium.base;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.provider.Settings;
import androidx.annotation.Nullable;
......@@ -75,15 +73,11 @@ public final class CommandLineInitUtil {
@Nullable Supplier<Boolean> shouldUseDebugFlags) {
if (shouldUseDebugFlags != null && shouldUseDebugFlags.get()) return true;
Context context = ContextUtils.getApplicationContext();
String debugApp = Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1
? getDebugAppPreJBMR1(context)
: getDebugAppJBMR1(context);
// Check isDebugAndroid() last to get full code coverage when using userdebug devices.
return context.getPackageName().equals(debugApp) || BuildInfo.isDebugAndroid();
return context.getPackageName().equals(getDebugApp(context)) || BuildInfo.isDebugAndroid();
}
@SuppressLint("NewApi")
private static String getDebugAppJBMR1(Context context) {
private static String getDebugApp(Context context) {
boolean adbEnabled = Settings.Global.getInt(context.getContentResolver(),
Settings.Global.ADB_ENABLED, 0) == 1;
if (adbEnabled) {
......@@ -92,15 +86,4 @@ public final class CommandLineInitUtil {
}
return null;
}
@SuppressWarnings("deprecation")
private static String getDebugAppPreJBMR1(Context context) {
boolean adbEnabled = Settings.System.getInt(context.getContentResolver(),
Settings.System.ADB_ENABLED, 0) == 1;
if (adbEnabled) {
return Settings.System.getString(context.getContentResolver(),
Settings.System.DEBUG_APP);
}
return null;
}
}
......@@ -4,8 +4,6 @@
package org.chromium.base;
import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Process;
import android.os.StrictMode;
import android.os.SystemClock;
......@@ -60,19 +58,9 @@ public class EarlyTraceEvent {
mIsToplevel = isToplevel;
mName = name;
mThreadId = Process.myTid();
mTimeNanos = elapsedRealtimeNanos();
mTimeNanos = SystemClock.elapsedRealtimeNanos();
mThreadTimeMillis = SystemClock.currentThreadTimeMillis();
}
@VisibleForTesting
@SuppressLint("NewApi")
static long elapsedRealtimeNanos() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return SystemClock.elapsedRealtimeNanos();
} else {
return SystemClock.elapsedRealtime() * 1000000;
}
}
}
@VisibleForTesting
......@@ -86,7 +74,7 @@ public class EarlyTraceEvent {
mName = name;
mId = id;
mIsStart = isStart;
mTimestampNanos = Event.elapsedRealtimeNanos();
mTimestampNanos = SystemClock.elapsedRealtimeNanos();
}
}
......@@ -295,7 +283,7 @@ public class EarlyTraceEvent {
private static long getOffsetNanos() {
long nativeNowNanos = TimeUtilsJni.get().getTimeTicksNowUs() * 1000;
long javaNowNanos = Event.elapsedRealtimeNanos();
long javaNowNanos = SystemClock.elapsedRealtimeNanos();
return nativeNowNanos - javaNowNanos;
}
......
......@@ -4,7 +4,6 @@
package org.chromium.base;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
......@@ -70,11 +69,9 @@ public class JavaHandlerThread {
JavaHandlerThreadJni.get().onLooperStopped(nativeThread);
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
// When we can, signal that new tasks queued up won't be run.
// Signal that new tasks queued up won't be run.
mThread.getLooper().quitSafely();
}
}
@CalledByNative
private void joinThread() {
......
......@@ -156,12 +156,8 @@ public class SysUtils {
public static boolean hasCamera(final Context context) {
final PackageManager pm = context.getPackageManager();
// JellyBean support.
boolean hasCamera = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
hasCamera |= pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
}
return hasCamera;
return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)
|| pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
}
@TargetApi(Build.VERSION_CODES.KITKAT)
......
......@@ -7,7 +7,6 @@ package org.chromium.base.memory;
import android.app.ActivityManager;
import android.content.ComponentCallbacks2;
import android.content.res.Configuration;
import android.os.Build;
import android.os.SystemClock;
import androidx.annotation.VisibleForTesting;
......@@ -243,7 +242,7 @@ public class MemoryPressureMonitor {
* Returns null if the pressure couldn't be determined.
*/
private static @MemoryPressureLevel Integer getCurrentMemoryPressure() {
long startNanos = elapsedRealtimeNanos();
long startNanos = SystemClock.elapsedRealtimeNanos();
try {
ActivityManager.RunningAppProcessInfo processInfo =
new ActivityManager.RunningAppProcessInfo();
......@@ -266,19 +265,12 @@ public class MemoryPressureMonitor {
private static int elapsedDurationSample(long startNanos) {
// We're using Count1MHistogram, so we need to calculate duration in microseconds
long durationUs = TimeUnit.NANOSECONDS.toMicros(elapsedRealtimeNanos() - startNanos);
long durationUs =
TimeUnit.NANOSECONDS.toMicros(SystemClock.elapsedRealtimeNanos() - startNanos);
// record() takes int, so we need to clamp.
return (int) Math.min(durationUs, Integer.MAX_VALUE);
}
private static long elapsedRealtimeNanos() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return SystemClock.elapsedRealtimeNanos();
} else {
return SystemClock.elapsedRealtime() * 1000000;
}
}
/**
* Maps ComponentCallbacks2.TRIM_* value to MemoryPressureLevel.
* Returns null if |level| couldn't be mapped and should be ignored.
......
......@@ -57,11 +57,11 @@ public class EarlyTraceEventTest {
public void testCanRecordEvent() {
EarlyTraceEvent.enable();
long myThreadId = Process.myTid();
long beforeNanos = Event.elapsedRealtimeNanos();
long beforeNanos = SystemClock.elapsedRealtimeNanos();
long beforeThreadMillis = SystemClock.currentThreadTimeMillis();
EarlyTraceEvent.begin(EVENT_NAME, false /*isToplevel*/);
EarlyTraceEvent.end(EVENT_NAME, false /*isToplevel*/);
long afterNanos = Event.elapsedRealtimeNanos();
long afterNanos = SystemClock.elapsedRealtimeNanos();
long afterThreadMillis = SystemClock.currentThreadTimeMillis();
List<Event> matchingEvents = getMatchingCompletedEvents(EVENT_NAME);
......@@ -85,10 +85,10 @@ public class EarlyTraceEventTest {
@Feature({"Android-AppBase"})
public void testCanRecordAsyncEvent() {
EarlyTraceEvent.enable();
long beforeNanos = Event.elapsedRealtimeNanos();
long beforeNanos = SystemClock.elapsedRealtimeNanos();
EarlyTraceEvent.startAsync(EVENT_NAME, EVENT_ID);
EarlyTraceEvent.finishAsync(EVENT_NAME, EVENT_ID);
long afterNanos = Event.elapsedRealtimeNanos();
long afterNanos = SystemClock.elapsedRealtimeNanos();
List<AsyncEvent> matchingEvents = new ArrayList<AsyncEvent>();
for (AsyncEvent evt : EarlyTraceEvent.sAsyncEvents) {
......@@ -114,11 +114,11 @@ public class EarlyTraceEventTest {
public void testCanRecordEventUsingTryWith() {
EarlyTraceEvent.enable();
long myThreadId = Process.myTid();
long beforeNanos = Event.elapsedRealtimeNanos();
long beforeNanos = SystemClock.elapsedRealtimeNanos();
try (TraceEvent e = TraceEvent.scoped(EVENT_NAME)) {
// Required comment to pass presubmit checks.
}
long afterNanos = Event.elapsedRealtimeNanos();
long afterNanos = SystemClock.elapsedRealtimeNanos();
List<Event> matchingEvents = getMatchingCompletedEvents(EVENT_NAME);
Assert.assertEquals(2, matchingEvents.size());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment