Search in sources :

Example 6 with VisibleForTesting

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

the class NetworkScoreService method refreshRecommendationRequestTimeoutMs.

@VisibleForTesting
public void refreshRecommendationRequestTimeoutMs() {
    final ContentResolver cr = mContext.getContentResolver();
    long timeoutMs = Settings.Global.getLong(cr, Global.NETWORK_RECOMMENDATION_REQUEST_TIMEOUT_MS, -1L);
    if (timeoutMs < 0) {
        timeoutMs = TimedRemoteCaller.DEFAULT_CALL_TIMEOUT_MILLIS;
    }
    if (DBG)
        Log.d(TAG, "Updating the recommendation request timeout to " + timeoutMs + " ms");
    mRecommendationRequestTimeoutMs = timeoutMs;
    mReqRecommendationCallerRef.set(new RequestRecommendationCaller(timeoutMs));
}
Also used : ContentResolver(android.content.ContentResolver) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 7 with VisibleForTesting

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

the class AccountManagerService method getPreNDatabaseName.

@VisibleForTesting
String getPreNDatabaseName(int userId) {
    File systemDir = Environment.getDataSystemDirectory();
    File databaseFile = new File(Environment.getUserSystemDirectory(userId), PRE_N_DATABASE_NAME);
    if (userId == 0) {
        // Migrate old file, if it exists, to the new location.
        // Make sure the new file doesn't already exist. A dummy file could have been
        // accidentally created in the old location, causing the new one to become corrupted
        // as well.
        File oldFile = new File(systemDir, PRE_N_DATABASE_NAME);
        if (oldFile.exists() && !databaseFile.exists()) {
            // Check for use directory; create if it doesn't exist, else renameTo will fail
            File userDir = Environment.getUserSystemDirectory(userId);
            if (!userDir.exists()) {
                if (!userDir.mkdirs()) {
                    throw new IllegalStateException("User dir cannot be created: " + userDir);
                }
            }
            if (!oldFile.renameTo(databaseFile)) {
                throw new IllegalStateException("User dir cannot be migrated: " + databaseFile);
            }
        }
    }
    return databaseFile.getPath();
}
Also used : File(java.io.File) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 8 with VisibleForTesting

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

the class TaskPersister method writePersistedTaskIdsForUser.

@VisibleForTesting
void writePersistedTaskIdsForUser(@NonNull SparseBooleanArray taskIds, int userId) {
    if (userId < 0) {
        return;
    }
    final File persistedTaskIdsFile = getUserPersistedTaskIdsFile(userId);
    synchronized (mIoLock) {
        BufferedWriter writer = null;
        try {
            writer = new BufferedWriter(new FileWriter(persistedTaskIdsFile));
            for (int i = 0; i < taskIds.size(); i++) {
                if (taskIds.valueAt(i)) {
                    writer.write(String.valueOf(taskIds.keyAt(i)));
                    writer.newLine();
                }
            }
        } catch (Exception e) {
            Slog.e(TAG, "Error while writing taskIds file for user " + userId, e);
        } finally {
            IoUtils.closeQuietly(writer);
        }
    }
}
Also used : FileWriter(java.io.FileWriter) AtomicFile(android.util.AtomicFile) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) BufferedWriter(java.io.BufferedWriter) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 9 with VisibleForTesting

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

the class Vpn method updateAlwaysOnNotificationInternal.

@VisibleForTesting
protected void updateAlwaysOnNotificationInternal(boolean visible) {
    final UserHandle user = UserHandle.of(mUserHandle);
    final long token = Binder.clearCallingIdentity();
    try {
        final NotificationManager notificationManager = NotificationManager.from(mContext);
        if (!visible) {
            notificationManager.cancelAsUser(TAG, 0, user);
            return;
        }
        final Intent intent = new Intent(Settings.ACTION_VPN_SETTINGS);
        final PendingIntent configIntent = PendingIntent.getActivityAsUser(mContext, /* request */
        0, intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT, null, user);
        final Notification.Builder builder = new Notification.Builder(mContext).setDefaults(0).setSmallIcon(R.drawable.vpn_connected).setContentTitle(mContext.getString(R.string.vpn_lockdown_disconnected)).setContentText(mContext.getString(R.string.vpn_lockdown_config)).setContentIntent(configIntent).setCategory(Notification.CATEGORY_SYSTEM).setPriority(Notification.PRIORITY_LOW).setVisibility(Notification.VISIBILITY_PUBLIC).setOngoing(true).setColor(mContext.getColor(R.color.system_notification_accent_color));
        notificationManager.notifyAsUser(TAG, 0, builder.build(), user);
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
Also used : NotificationManager(android.app.NotificationManager) UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 10 with VisibleForTesting

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

the class Vpn method createUserAndRestrictedProfilesRanges.

/**
     * Creates a {@link Set} of non-intersecting {@link UidRange} objects including all UIDs
     * associated with one user, and any restricted profiles attached to that user.
     *
     * <p>If one of {@param allowedApplications} or {@param disallowedApplications} is provided,
     * the UID ranges will match the app whitelist or blacklist specified there. Otherwise, all UIDs
     * in each user and profile will be included.
     *
     * @param userHandle The userId to create UID ranges for along with any of its restricted
     *                   profiles.
     * @param allowedApplications (optional) whitelist of applications to include.
     * @param disallowedApplications (optional) blacklist of applications to exclude.
     */
@VisibleForTesting
Set<UidRange> createUserAndRestrictedProfilesRanges(@UserIdInt int userHandle, @Nullable List<String> allowedApplications, @Nullable List<String> disallowedApplications) {
    final Set<UidRange> ranges = new ArraySet<>();
    // Assign the top-level user to the set of ranges
    addUserToRanges(ranges, userHandle, allowedApplications, disallowedApplications);
    // If the user can have restricted profiles, assign all its restricted profiles too
    if (canHaveRestrictedProfile(userHandle)) {
        final long token = Binder.clearCallingIdentity();
        List<UserInfo> users;
        try {
            users = UserManager.get(mContext).getUsers(true);
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        for (UserInfo user : users) {
            if (user.isRestricted() && (user.restrictedProfileParentId == userHandle)) {
                addUserToRanges(ranges, user.id, allowedApplications, disallowedApplications);
            }
        }
    }
    return ranges;
}
Also used : ArraySet(android.util.ArraySet) UidRange(android.net.UidRange) UserInfo(android.content.pm.UserInfo) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.android.internal.annotations.VisibleForTesting)141 ArrayList (java.util.ArrayList)39 IOException (java.io.IOException)26 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)18 ComponentName (android.content.ComponentName)15 File (java.io.File)14 RemoteException (android.os.RemoteException)13 ArraySet (android.util.ArraySet)10 AtomicFile (android.util.AtomicFile)10 FileInputStream (java.io.FileInputStream)10 Locale (java.util.Locale)10 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)9 FileNotFoundException (java.io.FileNotFoundException)9 Notification (android.app.Notification)6 ErrnoException (android.system.ErrnoException)6 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)6 FileOutputStream (java.io.FileOutputStream)6 XmlSerializer (org.xmlpull.v1.XmlSerializer)6 ITransientNotification (android.app.ITransientNotification)5 UserInfo (android.content.pm.UserInfo)5