Search in sources :

Example 21 with GuardedBy

use of com.android.internal.annotations.GuardedBy in project android_frameworks_base by ResurrectionRemix.

the class ApfFilter method installNewProgramLocked.

/**
     * Generate and install a new filter program.
     */
@GuardedBy("this")
@VisibleForTesting
void installNewProgramLocked() {
    purgeExpiredRasLocked();
    ArrayList<Ra> rasToFilter = new ArrayList<>();
    final byte[] program;
    long programMinLifetime = Long.MAX_VALUE;
    try {
        // Step 1: Determine how many RA filters we can fit in the program.
        ApfGenerator gen = beginProgramLocked();
        for (Ra ra : mRas) {
            ra.generateFilterLocked(gen);
            // Stop if we get too big.
            if (gen.programLengthOverEstimate() > mApfCapabilities.maximumApfProgramSize)
                break;
            rasToFilter.add(ra);
        }
        // Step 2: Actually generate the program
        gen = beginProgramLocked();
        for (Ra ra : rasToFilter) {
            programMinLifetime = Math.min(programMinLifetime, ra.generateFilterLocked(gen));
        }
        // Execution will reach the end of the program if no filters match, which will pass the
        // packet to the AP.
        program = gen.generate();
    } catch (IllegalInstructionException e) {
        Log.e(TAG, "Program failed to generate: ", e);
        return;
    }
    mLastTimeInstalledProgram = curTime();
    mLastInstalledProgramMinLifetime = programMinLifetime;
    mLastInstalledProgram = program;
    mNumProgramUpdates++;
    if (VDBG) {
        hexDump("Installing filter: ", program, program.length);
    }
    mIpManagerCallback.installPacketFilter(program);
    int flags = ApfProgramEvent.flagsFor(mIPv4Address != null, mMulticastFilter);
    mMetricsLog.log(new ApfProgramEvent(programMinLifetime, rasToFilter.size(), mRas.size(), program.length, flags));
}
Also used : IllegalInstructionException(android.net.apf.ApfGenerator.IllegalInstructionException) ApfGenerator(android.net.apf.ApfGenerator) ArrayList(java.util.ArrayList) ApfProgramEvent(android.net.metrics.ApfProgramEvent) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) GuardedBy(com.android.internal.annotations.GuardedBy)

Example 22 with GuardedBy

use of com.android.internal.annotations.GuardedBy in project android_frameworks_base by ResurrectionRemix.

the class UserManagerService method computeEffectiveUserRestrictionsLR.

@GuardedBy("mRestrictionsLock")
private Bundle computeEffectiveUserRestrictionsLR(int userId) {
    final Bundle baseRestrictions = UserRestrictionsUtils.nonNull(mBaseUserRestrictions.get(userId));
    final Bundle global = mDevicePolicyGlobalUserRestrictions;
    final Bundle local = mDevicePolicyLocalUserRestrictions.get(userId);
    if (UserRestrictionsUtils.isEmpty(global) && UserRestrictionsUtils.isEmpty(local)) {
        // Common case first.
        return baseRestrictions;
    }
    final Bundle effective = UserRestrictionsUtils.clone(baseRestrictions);
    UserRestrictionsUtils.merge(effective, global);
    UserRestrictionsUtils.merge(effective, local);
    return effective;
}
Also used : Bundle(android.os.Bundle) PersistableBundle(android.os.PersistableBundle) GuardedBy(com.android.internal.annotations.GuardedBy)

Example 23 with GuardedBy

use of com.android.internal.annotations.GuardedBy in project android_frameworks_base by crdroidandroid.

the class UserManagerService method updateUserRestrictionsInternalLR.

/**
     * Optionally updating user restrictions, calculate the effective user restrictions and also
     * propagate to other services and system settings.
     *
     * @param newRestrictions User restrictions to set.
     *      If null, will not update user restrictions and only does the propagation.
     * @param userId target user ID.
     */
@GuardedBy("mRestrictionsLock")
private void updateUserRestrictionsInternalLR(@Nullable Bundle newRestrictions, int userId) {
    final Bundle prevAppliedRestrictions = UserRestrictionsUtils.nonNull(mAppliedUserRestrictions.get(userId));
    // Update base restrictions.
    if (newRestrictions != null) {
        // If newRestrictions == the current one, it's probably a bug.
        final Bundle prevBaseRestrictions = mBaseUserRestrictions.get(userId);
        Preconditions.checkState(prevBaseRestrictions != newRestrictions);
        Preconditions.checkState(mCachedEffectiveUserRestrictions.get(userId) != newRestrictions);
        if (!UserRestrictionsUtils.areEqual(prevBaseRestrictions, newRestrictions)) {
            mBaseUserRestrictions.put(userId, newRestrictions);
            scheduleWriteUser(getUserDataNoChecks(userId));
        }
    }
    final Bundle effective = computeEffectiveUserRestrictionsLR(userId);
    mCachedEffectiveUserRestrictions.put(userId, effective);
    // Apply the new restrictions.
    if (DBG) {
        debug("Applying user restrictions: userId=" + userId + " new=" + effective + " prev=" + prevAppliedRestrictions);
    }
    if (mAppOpsService != null) {
        // We skip it until system-ready.
        mHandler.post(new Runnable() {

            @Override
            public void run() {
                try {
                    mAppOpsService.setUserRestrictions(effective, mUserRestriconToken, userId);
                } catch (RemoteException e) {
                    Log.w(LOG_TAG, "Unable to notify AppOpsService of UserRestrictions");
                }
            }
        });
    }
    propagateUserRestrictionsLR(userId, effective, prevAppliedRestrictions);
    mAppliedUserRestrictions.put(userId, new Bundle(effective));
}
Also used : Bundle(android.os.Bundle) PersistableBundle(android.os.PersistableBundle) RemoteException(android.os.RemoteException) GuardedBy(com.android.internal.annotations.GuardedBy)

Aggregations

GuardedBy (com.android.internal.annotations.GuardedBy)23 ApfGenerator (android.net.apf.ApfGenerator)8 Bundle (android.os.Bundle)8 PersistableBundle (android.os.PersistableBundle)8 IOException (java.io.IOException)7 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)5 AtomicFile (android.util.AtomicFile)5 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)5 IllegalInstructionException (android.net.apf.ApfGenerator.IllegalInstructionException)4 ApfProgramEvent (android.net.metrics.ApfProgramEvent)4 RemoteException (android.os.RemoteException)4 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)4 ZygoteProcess (android.os.ZygoteProcess)1 BufferedWriter (java.io.BufferedWriter)1 DataInputStream (java.io.DataInputStream)1 TimeoutException (java.util.concurrent.TimeoutException)1