Skip to content

Commit

Permalink
Remove KitKat code in //components
Browse files Browse the repository at this point in the history
Bug: 1041930
Change-Id: I0cab3e0712e7188bafe53bb3e828f78c259f94c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2298941
Commit-Queue: Yaron Friedman <yfriedman@chromium.org>
Auto-Submit: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Yaron Friedman <yfriedman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#788601}
  • Loading branch information
agrieve authored and Commit Bot committed Jul 15, 2020
1 parent fff5b65 commit 1cdf850
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/
public interface NotificationManagerProxy {
// Implemented by NotificationManagerCompat and thus available on all API levels.
// Note that on < Kitkat, this always returns true.
boolean areNotificationsEnabled();

void cancel(int id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.VectorDrawable;
import android.os.Build;

import androidx.annotation.DrawableRes;
import androidx.appcompat.content.res.AppCompatResources;
Expand Down Expand Up @@ -95,10 +94,6 @@ private boolean updateTintColor() {
@RemovableInRelease
private static boolean isVectorDrawable(Context context, @DrawableRes int drawableId) {
Drawable drawable = AppCompatResources.getDrawable(context, drawableId);
if (drawable instanceof VectorDrawableCompat) return true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return drawable instanceof VectorDrawable;
}
return false;
return drawable instanceof VectorDrawableCompat || drawable instanceof VectorDrawable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.text.TextUtils;

import org.chromium.base.BuildInfo;
Expand All @@ -34,9 +33,6 @@ private PackagePaths() {}
*/
@CalledByNative
public static String[] makePackagePaths(String arch) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return new String[] {"", ""};
}
try {
PackageManager pm = ContextUtils.getApplicationContext().getPackageManager();
PackageInfo pi = pm.getPackageInfo(BuildInfo.getInstance().packageName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Build;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -57,9 +56,6 @@ public void setSystemUiVisibility(boolean enterFullscreen) {
} else {
mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}

int systemUiVisibility = decor.getSystemUiVisibility();
int flags = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.os.StrictMode;
import android.os.SystemClock;
import android.provider.Browser;
Expand Down Expand Up @@ -1494,8 +1493,6 @@ private static void forcePdfViewerAsIntentHandlerIfNeeded(Intent intent) {
* capable activities. If the intent is pdf type, return the platform pdf viewer if
* it is available so user don't need to choose it from Intent picker.
*
* Note this function is slow on Android versions less than Lollipop.
*
* @param intent Intent to open.
* @param allowSelfOpen Whether chrome itself is allowed to open the intent.
* @return true if the intent can be resolved, or false otherwise.
Expand Down Expand Up @@ -1712,7 +1709,6 @@ public static ArrayList<String> getSpecializedHandlersWithFilter(List<ResolveInf

@VisibleForTesting
protected String getDefaultSmsPackageNameFromSystem() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return null;
return Telephony.Sms.getDefaultSmsPackage(ContextUtils.getApplicationContext());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.DisableIf;
import org.chromium.components.external_intents.ExternalNavigationHandler.OverrideUrlLoadingResult;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.WebContents;
Expand All @@ -53,8 +52,6 @@
*/
@RunWith(BaseJUnit4ClassRunner.class)
// clang-format off
@DisableIf.Build(message = "Flaky on K - see https://crbug.com/851444",
sdk_is_less_than = Build.VERSION_CODES.LOLLIPOP)
@Batch(Batch.UNIT_TESTS)
public class ExternalNavigationHandlerTest {
// clang-format on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

package org.chromium.components.gcm_driver;

import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.IntDef;
Expand Down Expand Up @@ -129,7 +127,6 @@ public GCMMessage(String senderId, Bundle extras) {
* been created through {@link #toBundle}.
*/
@Nullable
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static GCMMessage createFromBundle(Bundle bundle) {
return create(bundle, new BundleReader());
}
Expand Down Expand Up @@ -263,7 +260,6 @@ public static String peekSenderId(JSONObject jsonObject) {
* for purposes of scheduling a job. Only methods available in BaseBundle may be used here,
* as it may have to be converted to a PersistableBundle.
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Bundle toBundle() {
return serialize(new BundleWriter());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

import android.os.Build;
import android.os.Bundle;

import org.json.JSONException;
Expand All @@ -17,7 +16,6 @@
import org.robolectric.annotation.Config;

import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.base.test.util.MinAndroidSdkLevel;

/**
* Unit tests for GCMMessage.
Expand Down Expand Up @@ -109,7 +107,6 @@ public void testFiltersExtraBundle() {
* because it depends on PersistableBundle.
*/
@Test
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
public void testSerializationToPersistableBundle() {
Bundle extras = new Bundle();

Expand Down Expand Up @@ -141,7 +138,6 @@ public void testSerializationToPersistableBundle() {
* on PersistableBundle.
*/
@Test
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
public void testRawDataSerializationBehaviour() {
Bundle extras = new Bundle();
extras.putString("subtype", "MyAppId");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
// found in the LICENSE file.
package org.chromium.components.minidump_uploader;

import android.annotation.TargetApi;
import android.app.job.JobInfo;
import android.app.job.JobParameters;
import android.app.job.JobScheduler;
import android.app.job.JobService;
import android.content.Context;
import android.os.Build;
import android.os.PersistableBundle;

import org.chromium.base.ContextUtils;
Expand All @@ -18,7 +16,6 @@
/**
* Class that interacts with the Android JobScheduler to upload Minidumps at appropriate times.
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public abstract class MinidumpUploadJobService extends JobService {
private static final String TAG = "MinidumpJobService";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.text.TextUtils;

import com.google.android.play.core.splitinstall.SplitInstallManager;
Expand All @@ -34,17 +33,14 @@ public static void updateCrashKeys() {
// Get modules that are fully installed as split APKs (excluding base which is always
// installed). Tree set to have ordered and, thus, deterministic results.
Set<String> fullyInstalledModules = new TreeSet<>();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Split APKs are only supported on Android L+.
try {
PackageManager pm = context.getPackageManager();
PackageInfo packageInfo = pm.getPackageInfo(BuildInfo.getInstance().packageName, 0);
if (packageInfo.splitNames != null) {
fullyInstalledModules.addAll(Arrays.asList(packageInfo.splitNames));
}
} catch (NameNotFoundException e) {
throw new RuntimeException(e);
try {
PackageManager pm = context.getPackageManager();
PackageInfo packageInfo = pm.getPackageInfo(BuildInfo.getInstance().packageName, 0);
if (packageInfo.splitNames != null) {
fullyInstalledModules.addAll(Arrays.asList(packageInfo.splitNames));
}
} catch (NameNotFoundException e) {
throw new RuntimeException(e);
}

// Create temporary split install manager to retrieve both fully installed and emulated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

package org.chromium.policy;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.os.UserManager;
Expand All @@ -25,17 +23,11 @@ public AppRestrictionsProvider(Context context) {
super(context);

// getApplicationRestrictions method of UserManager was introduced in JELLY_BEAN_MR2.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
} else {
mUserManager = null;
}
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
}

@Override
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
protected Bundle getApplicationRestrictions(String packageName) {
if (mUserManager == null) return new Bundle();
try {
long startTime = SystemClock.elapsedRealtime();
Bundle bundle = mUserManager.getApplicationRestrictions(packageName);
Expand All @@ -57,10 +49,7 @@ protected Bundle getApplicationRestrictions(String packageName) {
}

@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected String getRestrictionChangeIntentAction() {
// Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED was introduced in LOLLIPOP.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return null;
return Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

package org.chromium.policy;

import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.VisibleForTesting;
Expand Down Expand Up @@ -65,46 +63,44 @@ public void setPolicy(String key, Object value) {
mNativePolicyConverter, PolicyConverter.this, key, (String[]) value);
return;
}
// App restrictions can only contain bundles and bundle arrays on Android M, however our
// version of Robolectric only supports Lollipop, and allowing this on LOLLIPOP doesn't
// cause problems.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (value instanceof Bundle) {
Bundle bundle = (Bundle) value;
// JNI can't take a Bundle argument without a lot of extra work, but the native code
// already accepts arbitrary JSON strings, so convert to JSON.
try {
PolicyConverterJni.get().setPolicyString(mNativePolicyConverter,
PolicyConverter.this, key, convertBundleToJson(bundle).toString());
} catch (JSONException e) {
// Chrome requires all policies to be expressible as JSON, so this can't be a
// valid policy.
Log.w(TAG, "Invalid bundle in app restrictions " + bundle.toString()
+ " for key " + key);
}
return;
// App restrictions can only contain bundles and bundle arrays on Android M, but
// allowing this on LOLLIPOP doesn't cause problems.
if (value instanceof Bundle) {
Bundle bundle = (Bundle) value;
// JNI can't take a Bundle argument without a lot of extra work, but the native code
// already accepts arbitrary JSON strings, so convert to JSON.
try {
PolicyConverterJni.get().setPolicyString(mNativePolicyConverter,
PolicyConverter.this, key, convertBundleToJson(bundle).toString());
} catch (JSONException e) {
// Chrome requires all policies to be expressible as JSON, so this can't be a
// valid policy.
Log.w(TAG,
"Invalid bundle in app restrictions " + bundle.toString() + " for key "
+ key);
}
if (value instanceof Bundle[]) {
Bundle[] bundleArray = (Bundle[]) value;
// JNI can't take a Bundle[] argument without a lot of extra work, but the native
// code already accepts arbitrary JSON strings, so convert to JSON.
try {
PolicyConverterJni.get().setPolicyString(mNativePolicyConverter,
PolicyConverter.this, key,
convertBundleArrayToJson(bundleArray).toString());
} catch (JSONException e) {
// Chrome requires all policies to be expressible as JSON, so this can't be a
// valid policy.
Log.w(TAG, "Invalid bundle array in app restrictions "
+ Arrays.toString(bundleArray) + " for key " + key);
}
return;
return;
}
if (value instanceof Bundle[]) {
Bundle[] bundleArray = (Bundle[]) value;
// JNI can't take a Bundle[] argument without a lot of extra work, but the native
// code already accepts arbitrary JSON strings, so convert to JSON.
try {
PolicyConverterJni.get().setPolicyString(mNativePolicyConverter,
PolicyConverter.this, key,
convertBundleArrayToJson(bundleArray).toString());
} catch (JSONException e) {
// Chrome requires all policies to be expressible as JSON, so this can't be a
// valid policy.
Log.w(TAG,
"Invalid bundle array in app restrictions " + Arrays.toString(bundleArray)
+ " for key " + key);
}
return;
}
assert false : "Invalid setting " + value + " for key " + key;
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private JSONObject convertBundleToJson(Bundle bundle) throws JSONException {
JSONObject json = new JSONObject();
Set<String> keys = bundle.keySet();
Expand All @@ -117,7 +113,6 @@ private JSONObject convertBundleToJson(Bundle bundle) throws JSONException {
return json;
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private JSONArray convertBundleArrayToJson(Bundle[] bundleArray) throws JSONException {
JSONArray json = new JSONArray();
for (Bundle bundle : bundleArray) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AuthenticatorDescription;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
Expand Down Expand Up @@ -335,7 +334,6 @@ private void updateAccountRestrictionPatterns() {
new UpdateAccountRestrictionPatternsTask().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void subscribeToAppRestrictionChanges() {
IntentFilter filter = new IntentFilter(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED);
BroadcastReceiver receiver = new BroadcastReceiver() {
Expand Down Expand Up @@ -386,7 +384,6 @@ private static PatternMatcher[] getAccountRestrictionPatterns() {
}
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static String[] getAccountRestrictionPatternPostJellyBeanMr2() {
// This method uses AppRestrictions directly, rather than using the Policy interface,
// because it must be callable in contexts in which the native library hasn't been loaded.
Expand Down

0 comments on commit 1cdf850

Please sign in to comment.