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));
}
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();
}
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);
}
}
}
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);
}
}
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;
}
Aggregations