Search in sources :

Example 1 with GuardedBy

use of com.android.internal.annotations.GuardedBy in project platform_frameworks_base by android.

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)

Example 2 with GuardedBy

use of com.android.internal.annotations.GuardedBy in project platform_frameworks_base by android.

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 3 with GuardedBy

use of com.android.internal.annotations.GuardedBy in project platform_frameworks_base by android.

the class WebViewZygote method connectToZygoteIfNeededLocked.

@GuardedBy("sLock")
private static void connectToZygoteIfNeededLocked() {
    if (sZygote != null)
        return;
    if (sPackage == null) {
        Log.e(LOGTAG, "Cannot connect to zygote, no package specified");
        return;
    }
    final String serviceName = getServiceNameLocked();
    if (!SystemService.isRunning(serviceName)) {
        Log.e(LOGTAG, serviceName + " is not running");
        return;
    }
    try {
        sZygote = new ZygoteProcess("webview_zygote", null);
        // All the work below is usually done by LoadedApk, but the zygote can't talk to
        // PackageManager or construct a LoadedApk since it's single-threaded pre-fork, so
        // doesn't have an ActivityThread and can't use Binder.
        // Instead, figure out the paths here, in the system server where we have access to
        // the package manager. Reuse the logic from LoadedApk to determine the correct
        // paths and pass them to the zygote as strings.
        final List<String> zipPaths = new ArrayList<>(10);
        final List<String> libPaths = new ArrayList<>(10);
        LoadedApk.makePaths(null, false, sPackage.applicationInfo, zipPaths, libPaths);
        final String librarySearchPath = TextUtils.join(File.pathSeparator, libPaths);
        final String zip = (zipPaths.size() == 1) ? zipPaths.get(0) : TextUtils.join(File.pathSeparator, zipPaths);
        Log.d(LOGTAG, "Preloading package " + zip + " " + librarySearchPath);
        sZygote.preloadPackageForAbi(zip, librarySearchPath, Build.SUPPORTED_ABIS[0]);
    } catch (Exception e) {
        Log.e(LOGTAG, "Error connecting to " + serviceName, e);
        sZygote = null;
    }
}
Also used : ZygoteProcess(android.os.ZygoteProcess) ArrayList(java.util.ArrayList) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) GuardedBy(com.android.internal.annotations.GuardedBy)

Example 4 with GuardedBy

use of com.android.internal.annotations.GuardedBy in project platform_frameworks_base by android.

the class ZygoteProcess method zygoteSendArgsAndGetResult.

/**
     * Sends an argument list to the zygote process, which starts a new child
     * and returns the child's pid. Please note: the present implementation
     * replaces newlines in the argument list with spaces.
     *
     * @throws ZygoteStartFailedEx if process start failed for any reason
     */
@GuardedBy("mLock")
private static Process.ProcessStartResult zygoteSendArgsAndGetResult(ZygoteState zygoteState, ArrayList<String> args) throws ZygoteStartFailedEx {
    try {
        // Throw early if any of the arguments are malformed. This means we can
        // avoid writing a partial response to the zygote.
        int sz = args.size();
        for (int i = 0; i < sz; i++) {
            if (args.get(i).indexOf('\n') >= 0) {
                throw new ZygoteStartFailedEx("embedded newlines not allowed");
            }
        }
        /**
             * See com.android.internal.os.SystemZygoteInit.readArgumentList()
             * Presently the wire format to the zygote process is:
             * a) a count of arguments (argc, in essence)
             * b) a number of newline-separated argument strings equal to count
             *
             * After the zygote process reads these it will write the pid of
             * the child or -1 on failure, followed by boolean to
             * indicate whether a wrapper process was used.
             */
        final BufferedWriter writer = zygoteState.writer;
        final DataInputStream inputStream = zygoteState.inputStream;
        writer.write(Integer.toString(args.size()));
        writer.newLine();
        for (int i = 0; i < sz; i++) {
            String arg = args.get(i);
            writer.write(arg);
            writer.newLine();
        }
        writer.flush();
        // Should there be a timeout on this?
        Process.ProcessStartResult result = new Process.ProcessStartResult();
        // Always read the entire result from the input stream to avoid leaving
        // bytes in the stream for future process starts to accidentally stumble
        // upon.
        result.pid = inputStream.readInt();
        result.usingWrapper = inputStream.readBoolean();
        if (result.pid < 0) {
            throw new ZygoteStartFailedEx("fork() failed");
        }
        return result;
    } catch (IOException ex) {
        zygoteState.close();
        throw new ZygoteStartFailedEx(ex);
    }
}
Also used : IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) BufferedWriter(java.io.BufferedWriter) GuardedBy(com.android.internal.annotations.GuardedBy)

Example 5 with GuardedBy

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

the class RegisteredServicesCache method findOrCreateUserLocked.

@GuardedBy("mServicesLock")
private UserServices<V> findOrCreateUserLocked(int userId, boolean loadFromFileIfNew) {
    UserServices<V> services = mUserServices.get(userId);
    if (services == null) {
        services = new UserServices<V>();
        mUserServices.put(userId, services);
        if (loadFromFileIfNew && mSerializerAndParser != null) {
            // Check if user exists and try loading data from file
            // clear existing data if there was an error during migration
            UserInfo user = getUser(userId);
            if (user != null) {
                AtomicFile file = createFileForUser(user.id);
                if (file.getBaseFile().exists()) {
                    if (DEBUG) {
                        Slog.i(TAG, String.format("Loading u%s data from %s", user.id, file));
                    }
                    InputStream is = null;
                    try {
                        is = file.openRead();
                        readPersistentServicesLocked(is);
                    } catch (Exception e) {
                        Log.w(TAG, "Error reading persistent services for user " + user.id, e);
                    } finally {
                        IoUtils.closeQuietly(is);
                    }
                }
            }
        }
    }
    return services;
}
Also used : AtomicFile(android.util.AtomicFile) InputStream(java.io.InputStream) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) 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