Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (C) 2014 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.builder.internal;
public class InstallUtils {

    
Checks whether a device is compatible with a given app minSdkVersion value.

Parameters:
device the device
appMinSdkVersion the minSdkVersion of the app
logger a logger object
projectName the project name for logging
variantName the variant name for logging
Returns:
true if the device can run the app
    public static boolean checkDeviceApiLevel(
            @NonNull DeviceConnector device,
            @NonNull ApiVersion appMinSdkVersion,
            @NonNull ILogger logger,
            @NonNull String projectName,
            @NonNull String variantName) {
        int deviceApiLevel = device.getApiLevel();
        if (deviceApiLevel == 0) {
            logger.info("Skipping device '%1$s' for '%2$s:%3$s': Unknown API Level",
                    device.getName(), projectNamevariantName);
            return false;
        }
        int minSdkVersion = appMinSdkVersion.getApiLevel();
        if (appMinSdkVersion.getCodename() != null) {
            String deviceCodeName = device.getApiCodeName();
            if (deviceCodeName != null) {
                if (deviceCodeName.equals(appMinSdkVersion.getCodename())) {
                    logger.info("Skipping device '%1$s', due to different API preview '%2$s' and '%3$s'",
                            device.getName(), deviceCodeNameappMinSdkVersion.getCodename());
                    return false;
                }
            } else {
                minSdkVersion = SdkVersionInfo.getApiByBuildCode(
                        appMinSdkVersion.getCodename(), true);
                if (minSdkVersion > deviceApiLevel) {
                    logger.info("Skipping device '%s' for '%s:%s'",
                            device.getName(), projectNamevariantName);
                    return false;
                }
            }
        } else {
            if (minSdkVersion > deviceApiLevel) {
                logger.info("Skipping device '%s' for '%s:%s'",
                        device.getName(), projectNamevariantName);
                return false;
            }
        }
        return true;
    }
New to GrepCode? Check out our FAQ X