Java Code Examples for com.android.internal.util.Preconditions#checkArrayElementsInRange()

The following examples show how to use com.android.internal.util.Preconditions#checkArrayElementsInRange() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrightnessMappingStrategy.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public SimpleMappingStrategy(float[] lux, int[] brightness, float maxGamma) {
    Preconditions.checkArgument(lux.length != 0 && brightness.length != 0,
            "Lux and brightness arrays must not be empty!");
    Preconditions.checkArgument(lux.length == brightness.length,
            "Lux and brightness arrays must be the same length!");
    Preconditions.checkArrayElementsInRange(lux, 0, Float.MAX_VALUE, "lux");
    Preconditions.checkArrayElementsInRange(brightness,
            0, Integer.MAX_VALUE, "brightness");

    final int N = brightness.length;
    mLux = new float[N];
    mBrightness = new float[N];
    for (int i = 0; i < N; i++) {
        mLux[i] = lux[i];
        mBrightness[i] = normalizeAbsoluteBrightness(brightness[i]);
    }

    mMaxGamma = maxGamma;
    mAutoBrightnessAdjustment = 0;
    mUserLux = -1;
    mUserBrightness = -1;
    if (DEBUG) {
        PLOG.start("simple mapping strategy");
    }
    computeSpline();
}
 
Example 2
Source File: AmbientBrightnessDayStats.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize day stats from the given state
 *
 * @param localDate        The date for which stats are being tracked
 * @param bucketBoundaries Bucket boundaries used from creating the buckets from
 * @param stats            Time spent in each of the buckets (in seconds)
 * @hide
 */
public AmbientBrightnessDayStats(@NonNull LocalDate localDate,
        @NonNull float[] bucketBoundaries, float[] stats) {
    Preconditions.checkNotNull(localDate);
    Preconditions.checkNotNull(bucketBoundaries);
    Preconditions.checkArrayElementsInRange(bucketBoundaries, 0, Float.MAX_VALUE,
            "bucketBoundaries");
    if (bucketBoundaries.length < 1) {
        throw new IllegalArgumentException("Bucket boundaries must contain at least 1 value");
    }
    checkSorted(bucketBoundaries);
    if (stats == null) {
        stats = new float[bucketBoundaries.length];
    } else {
        Preconditions.checkArrayElementsInRange(stats, 0, Float.MAX_VALUE, "stats");
        if (bucketBoundaries.length != stats.length) {
            throw new IllegalArgumentException(
                    "Bucket boundaries and stats must be of same size.");
        }
    }
    mLocalDate = localDate;
    mBucketBoundaries = bucketBoundaries;
    mStats = stats;
}
 
Example 3
Source File: BrightnessConfiguration.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the control points for the brightness curve.
 *
 * Brightness curves must have strictly increasing ambient brightness values in lux and
 * monotonically increasing display brightness values in nits. In addition, the initial
 * control point must be 0 lux.
 *
 * @throws IllegalArgumentException if the initial control point is not at 0 lux.
 * @throws IllegalArgumentException if the lux levels are not strictly increasing.
 * @throws IllegalArgumentException if the nit levels are not monotonically increasing.
 *
 * STOPSHIP remove when app has stopped using this.
 * @hide
 */
public Builder setCurve(float[] lux, float[] nits) {
    Preconditions.checkNotNull(lux);
    Preconditions.checkNotNull(nits);
    if (lux.length == 0 || nits.length == 0) {
        throw new IllegalArgumentException("Lux and nits arrays must not be empty");
    }
    if (lux.length != nits.length) {
        throw new IllegalArgumentException("Lux and nits arrays must be the same length");
    }
    if (lux[0] != 0) {
        throw new IllegalArgumentException("Initial control point must be for 0 lux");
    }
    Preconditions.checkArrayElementsInRange(lux, 0, Float.MAX_VALUE, "lux");
    Preconditions.checkArrayElementsInRange(nits, 0, Float.MAX_VALUE, "nits");
    checkMonotonic(lux, true/*strictly increasing*/, "lux");
    checkMonotonic(nits, false /*strictly increasing*/, "nits");
    mCurveLux = lux;
    mCurveNits = nits;
    return this;
}
 
Example 4
Source File: BrightnessMappingStrategy.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public PhysicalMappingStrategy(BrightnessConfiguration config, float[] nits,
                               int[] backlight, float maxGamma) {
    Preconditions.checkArgument(nits.length != 0 && backlight.length != 0,
            "Nits and backlight arrays must not be empty!");
    Preconditions.checkArgument(nits.length == backlight.length,
            "Nits and backlight arrays must be the same length!");
    Preconditions.checkNotNull(config);
    Preconditions.checkArrayElementsInRange(nits, 0, Float.MAX_VALUE, "nits");
    Preconditions.checkArrayElementsInRange(backlight,
            PowerManager.BRIGHTNESS_OFF, PowerManager.BRIGHTNESS_ON, "backlight");

    mMaxGamma = maxGamma;
    mAutoBrightnessAdjustment = 0;
    mUserLux = -1;
    mUserBrightness = -1;

    // Setup the backlight spline
    final int N = nits.length;
    float[] normalizedBacklight = new float[N];
    for (int i = 0; i < N; i++) {
        normalizedBacklight[i] = normalizeAbsoluteBrightness(backlight[i]);
    }

    mNitsToBacklightSpline = Spline.createSpline(nits, normalizedBacklight);
    mBacklightToNitsSpline = Spline.createSpline(normalizedBacklight, nits);

    mDefaultConfig = config;
    if (DEBUG) {
        PLOG.start("physical mapping strategy");
    }
    mConfig = config;
    computeSpline();
}
 
Example 5
Source File: AppOpsService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void startWatchingActive(int[] ops, IAppOpsActiveCallback callback) {
    int watchedUid = -1;
    final int callingUid = Binder.getCallingUid();
    final int callingPid = Binder.getCallingPid();
    if (mContext.checkCallingOrSelfPermission(Manifest.permission.WATCH_APPOPS)
            != PackageManager.PERMISSION_GRANTED) {
        watchedUid = callingUid;
    }
    if (ops != null) {
        Preconditions.checkArrayElementsInRange(ops, 0,
                AppOpsManager._NUM_OP - 1, "Invalid op code in: " + Arrays.toString(ops));
    }
    if (callback == null) {
        return;
    }
    synchronized (this) {
        SparseArray<ActiveCallback> callbacks = mActiveWatchers.get(callback.asBinder());
        if (callbacks == null) {
            callbacks = new SparseArray<>();
            mActiveWatchers.put(callback.asBinder(), callbacks);
        }
        final ActiveCallback activeCallback = new ActiveCallback(callback, watchedUid,
                callingUid, callingPid);
        for (int op : ops) {
            callbacks.put(op, activeCallback);
        }
    }
}