/** * Stores <code>user</code> as the active user. * * @param user The user to be stored as active. */ public static void saveActiveUser(@NotNull String user) { Preferences prefs = getPrefs(); prefs.put(ACTIVE_USER, user); flushPrefs(prefs); }
private static void addUser(String user) { Preferences prefs = getPrefs(); String allUsersString = prefs.get(USERS, null); if (allUsersString == null) { prefs.put(USERS, user); return; } List<String> allUsers = new ArrayList<String>(); Splitter splitter = Splitter.on(DELIMITER).omitEmptyStrings(); for (String scope : splitter.split(allUsersString)) { allUsers.add(scope); } if (allUsers.contains(user)) { return; } Joiner joiner = Joiner.on(DELIMITER); prefs.put(USERS, joiner.join(allUsersString, user)); flushPrefs(prefs); }
/** * Stores the specified preference of the active user to display only the icon in the login panel. * * @param logoutOnExit the preference of the active user to display only the icon in the login * panel. */ public static void saveIconOnlyPref(boolean logoutOnExit) { Preferences prefs = getPrefs(); prefs.putBoolean(getCustomUserKey(ICON_ONLY_KEY), logoutOnExit); flushPrefs(prefs); }
/** * Stores the specified preference of the active user to logout on closing Android Studio. * * @param logoutOnExit the preference of the active user to logout on closing Android Studio. */ public static void saveLogoutOnExitPref(boolean logoutOnExit) { Preferences prefs = getPrefs(); prefs.putBoolean(getCustomUserKey(LOGOUT_ON_EXIT_KEY), logoutOnExit); flushPrefs(prefs); }
/** Clears the persistently stored active user. */ public static void removeActiveUser() { Preferences prefs = getPrefs(); prefs.remove(ACTIVE_USER); flushPrefs(prefs); }
/** Clears all persistently stored users. There is no active user after this. */ public static void removeAllUsers() { Preferences prefs = getPrefs(); prefs.remove(USERS); prefs.remove(ACTIVE_USER); flushPrefs(prefs); }
/** * Stores the specified {@link OAuthData} object for the active user persistently. * * @param credentials the specified {@code Credentials object} */ public static void saveOAuthData(OAuthData credentials) { String userEmail = credentials.getStoredEmail(); if (userEmail != null) { Preferences prefs = getPrefs(); prefs.put( getCustomUserKey(OAUTH_DATA_REFRESH_TOKEN_KEY, userEmail), credentials.getRefreshToken()); // we save the scopes so that if the user updates the plugin and the // scopes change, we can force the plugin to log out. Joiner joiner = Joiner.on(DELIMITER); prefs.put( getCustomUserKey(OAUTH_SCOPES_KEY, userEmail), joiner.join(credentials.getStoredScopes())); prefs.put(getCustomUserKey(OAUTH_DATA_EMAIL_KEY, userEmail), userEmail); addUser(credentials.getStoredEmail()); flushPrefs(prefs); } }
/** Clears the persistently stored {@link OAuthData} object for the active user, if any. */ public static void clearStoredOAuthData() { CredentialedUser activeUser = Services.getLoginService().getActiveUser(); if (activeUser == null) { return; } Preferences prefs = getPrefs(); prefs.remove(getCustomUserKey(OAUTH_DATA_REFRESH_TOKEN_KEY)); prefs.remove(getCustomUserKey(OAUTH_DATA_EMAIL_KEY)); prefs.remove(getCustomUserKey(OAUTH_SCOPES_KEY)); removeUser(prefs, activeUser.getEmail()); flushPrefs(prefs); }