Welcome to CSDN-markdown editor

Hits: 0

private void setImplLocked(int type, long when, long whenElapsed, long windowLength,
long maxWhen, long interval, PendingIntent operation, int flags,
boolean doValidate, WorkSource workSource, AlarmManager.AlarmClockInfo alarmClock,
int uid, boolean mNeedGrouping) {
Alarm a = new Alarm(type, when, whenElapsed, windowLength, maxWhen, interval,
operation, workSource, flags, alarmClock, uid, mNeedGrouping);
removeLocked(operation);
setImplLocked(a, false, doValidate);
}

private void setImplLocked(Alarm a, boolean rebatching, boolean doValidate) {
    if ((a.flags&AlarmManager.FLAG_IDLE_UNTIL) != 0) {
        // This is a special alarm that will put the system into idle until it goes off.
        // The caller has given the time they want this to happen at, however we need
        // to pull that earlier if there are existing alarms that have requested to
        // bring us out of idle.
        if (mNextWakeFromIdle != null) {
            a.when = a.whenElapsed = a.maxWhenElapsed = mNextWakeFromIdle.whenElapsed;
        }
        // Add fuzz to make the alarm go off some time before the actual desired time.
        final long nowElapsed = SystemClock.elapsedRealtime();
        final int fuzz = fuzzForDuration(a.whenElapsed-nowElapsed);
        if (fuzz > 0) {
            if (mRandom == null) {
                mRandom = new Random();
            }
            final int delta = mRandom.nextInt(fuzz);
            a.whenElapsed -= delta;
            if (false) {
                Slog.d(TAG, "Alarm when: " + a.whenElapsed);
                Slog.d(TAG, "Delta until alarm: " + (a.whenElapsed-nowElapsed));
                Slog.d(TAG, "Applied fuzz: " + fuzz);
                Slog.d(TAG, "Final delta: " + delta);
                Slog.d(TAG, "Final when: " + a.whenElapsed);
            }
            a.when = a.maxWhenElapsed = a.whenElapsed;
        }

    } else if (mPendingIdleUntil != null) {
        // We currently have an idle until alarm scheduled; if the new alarm has
        // not explicitly stated it wants to run while idle, then put it on hold.
        if ((a.flags&(AlarmManager.FLAG_ALLOW_WHILE_IDLE
                | AlarmManager.FLAG_ALLOW_WHILE_IDLE_UNRESTRICTED
                | AlarmManager.FLAG_WAKE_FROM_IDLE))
                == 0) {
            mPendingWhileIdleAlarms.add(a);
            return;
        }
    }
    if (DEBUG_BATCH) {
         Slog.d(TAG, "a.whenElapsed =" + a.whenElapsed
         + " a.needGrouping= " + a.needGrouping
         + "  a.flags= " + a.flags);
    }
    //Gionee <bug> <hanbj> <20160226> modified for CR01620828 begin
    int whichBatch = ( (a.flags&AlarmManager.FLAG_STANDALONE) != 0)
            ? -1 : attemptCoalesceLocked(a.whenElapsed, a.maxWhenElapsed);
    // M using a.needGrouping for check condition
    //int whichBatch = (a.needGrouping == false)
    //        ? -1 : attemptCoalesceLocked(a.whenElapsed, a.maxWhenElapsed);
    //Gionee <bug> <hanbj> <20160226> modified for CR01620828 end

    //Gionee <bug> <wangym> <20160217> add for CR01620828   begin
    if (DEBUG_BATCH) {
        Slog.d(TAG, " whichBatch = " + whichBatch);
    }
    //Gionee <bug> <wangym> <20160217> add for CR01465140 end
    if (whichBatch < 0) {
        Batch batch = new Batch(a);
        addBatchLocked(mAlarmBatches, batch);
    } else {
        Batch batch = mAlarmBatches.get(whichBatch);
        //Gionee <bug><huangshuiqiang> <2016-01-22> CR01627159 add  begin
        if(isSchrPowerOff(a)){
            Slog.d(GN_OFF_TAG,"----WARN:whichBatch="+whichBatch+", ADD pwroffalarm ("+show(a.when)+") to batch ="+batch);
        }
        //Gionee <bug><huangshuiqiang> <2016-01-22> CR01627159 add  end
        //Gionee <bug> <wangym> <20160217> add for CR01620828   begin
        if (DEBUG_BATCH) {
            Slog.d(TAG, " alarm = " + a + " add to " + batch);
        }
        //Gionee <bug> <wangym> <20160217> add for CR01465140 end
        if (batch.add(a)) {
            // The start time of this batch advanced, so batch ordering may
            // have just been broken.  Move it to where it now belongs.
            mAlarmBatches.remove(whichBatch);
            addBatchLocked(mAlarmBatches, batch);
        }
    }

    if (a.alarmClock != null) {
        mNextAlarmClockMayChange = true;
    }

    boolean needRebatch = false;

    if ((a.flags&AlarmManager.FLAG_IDLE_UNTIL) != 0) {
        mPendingIdleUntil = a;
        mConstants.updateAllowWhileIdleMinTimeLocked();
        needRebatch = true;
    } else if ((a.flags&AlarmManager.FLAG_WAKE_FROM_IDLE) != 0) {
        if (mNextWakeFromIdle == null || mNextWakeFromIdle.whenElapsed > a.whenElapsed) {
            mNextWakeFromIdle = a;
            // If this wake from idle is earlier than whatever was previously scheduled,
            // and we are currently idling, then we need to rebatch alarms in case the idle
            // until time needs to be updated.
            if (mPendingIdleUntil != null) {
                needRebatch = true;
            }
        }
    }

    if (!rebatching) {
        if (DEBUG_VALIDATE) {
            if (doValidate && !validateConsistencyLocked()) {
                Slog.v(TAG, "Tipping-point operation: type=" + a.type + " when=" + a.when
                        + " when(hex)=" + Long.toHexString(a.when)
                        + " whenElapsed=" + a.whenElapsed
                        + " maxWhenElapsed=" + a.maxWhenElapsed
                        + " interval=" + a.repeatInterval + " op=" + a.operation
                        + " flags=0x" + Integer.toHexString(a.flags));
                rebatchAllAlarmsLocked(false);
                needRebatch = false;
            }
        }

        if (needRebatch) {
            rebatchAllAlarmsLocked(false);
        }

        rescheduleKernelAlarmsLocked();
        updateNextAlarmClockLocked();
    }
}

Leave a Reply

Your email address will not be published.