本文整理汇总了Java中com.securepreferences.SecurePreferences类的典型用法代码示例。如果您正苦于以下问题:Java SecurePreferences类的具体用法?Java SecurePreferences怎么用?Java SecurePreferences使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SecurePreferences类属于com.securepreferences包,在下文中一共展示了SecurePreferences类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: restartSelf
import com.securepreferences.SecurePreferences; //导入依赖的package包/类
public void restartSelf ()
{
LoggerUtil.logToFile(LoggerUtil.Level.WARNING, TAG, "restartSelf", getPackageName() + " SERVICE WILL RESTART");
this.stopSelf();
SecurePreferences securePrefs = MainService.getSecurePreferences(this);
boolean stopped = securePrefs.getBoolean(PreferenceKeys.Miscellaneous.STOPPED_SERVICE, false);
// If this MMC app is yeilding to another MMC app, it will stop when safe, but not restart
if (Global.isServiceYeilded(this))
stopped = true;
if (stopped) // if service is supposed to remain stopped, dont restart
return;
Intent restartService = new Intent(getApplicationContext(),
this.getClass());
restartService.setPackage(getPackageName());
PendingIntent restartServicePI = PendingIntent.getService(
getApplicationContext(), 1, restartService,
PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmService = (AlarmManager)getApplicationContext().getSystemService(Context.ALARM_SERVICE);
alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() +10000, restartServicePI);
System.exit(0);
}
示例2: onReceive
import com.securepreferences.SecurePreferences; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
// if(intent.getAction().equals(Intent.ACTION_SEND) ) {
LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, "BootListener", "ACTION_BOOT_COMPLETED", "");
boolean startOnBoot = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREFERENCE_KEY_START_ON_BOOT, true);
boolean isAuthorized = ReportManager.getInstance(context.getApplicationContext()).isAuthorized();
SecurePreferences securePrefs = MainService.getSecurePreferences(context);
boolean bStoppedService = securePrefs.getBoolean(PreferenceKeys.Miscellaneous.STOPPED_SERVICE, false);
String yeilded = PreferenceManager.getDefaultSharedPreferences(context).getString(PreferenceKeys.Miscellaneous.YEILDED_SERVICE, null);
if (Global.isServiceYeilded(context))
bStoppedService = true;
LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, "BootListener", "startOnBoot=" + startOnBoot + ",isAuthorized=" + isAuthorized + ",bStoppedService=" + bStoppedService, "");
if (!bStoppedService)
if(isAuthorized && startOnBoot && !bStoppedService) {
LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, "BootListener", "startService=" + startOnBoot, "");
Intent bgServiceIntent = new Intent(context, MainService.class);
context.startService(bgServiceIntent);
}
}
}
示例3: isAuthorized
import com.securepreferences.SecurePreferences; //导入依赖的package包/类
public boolean isAuthorized() {
boolean authorized = false;
int userId = Global.getUserID(mContext);
if (mApiKey != null && mApiKey.length() > 10 && userId > 0)
authorized = true;
// Unless user signed himself out
SecurePreferences prefs = PreferenceKeys.getSecurePreferences(mContext);
if (prefs.getBoolean(PreferenceKeys.Miscellaneous.SIGNED_OUT, false) == true)
authorized = false;
if (authorized == true && Global.isOnline() && Looper.myLooper() != Looper.getMainLooper())
{
URL request = RequestServerGet.getURL(mHost, mApiKey, null, "user", null);
try {
HttpURLConnection connection = (HttpURLConnection) request.openConnection();
connection.connect();
if (connection.getResponseCode() == 401)
return false;
}
catch (Exception e) {
LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "isAuthorized", "exception", e);
}
}
return authorized; // && mApiKey.length() > 10);
}
示例4: setupSettings
import com.securepreferences.SecurePreferences; //导入依赖的package包/类
/**
* Initializes the encrypted user settings, with all needed default values.
* @param _context Application context.
* @param _password Application password.
* @param _username Username inside chat.
* @param _publicKeyString PublicKey for encryption.
* @param _privateKeyString PrivateKey for decryption.
*/
public static void setupSettings(Context _context, String _password, String _username,
String _publicKeyString, String _privateKeyString) {
SharedPreferences setupPreferences = new SecurePreferences(_context, _password,
PREF_UNENCRYPTED_NAME);
// add values
SharedPreferences.Editor setupEditor = setupPreferences.edit();
setupEditor.putString(Settings.PREF_USER_NAME, _username);
setupEditor.putString(Settings.PREF_PUB_KEY, _publicKeyString);
setupEditor.putString(Settings.PREF_PRIVATE_KEY, _privateKeyString);
setupEditor.commit();
Log.d(LOG_TAG, "Username: " + setupPreferences.getString(Settings.PREF_USER_NAME, null));
Log.d(LOG_TAG, "Private: " + setupPreferences.getString(Settings.PREF_PRIVATE_KEY, null));
Log.d(LOG_TAG, "Username: " + setupPreferences.getString(Settings.PREF_PUB_KEY, null));
}
示例5: unlockSettings
import com.securepreferences.SecurePreferences; //导入依赖的package包/类
/**
* Checks if the handed password is valid for unlocking the encrypted settings.
* @param _context Application context.
* @param _password Entered password.
* @return True, if correct.
*/
public static boolean unlockSettings(Context _context, String _password) {
// try to open locked settings and ask for a value
SharedPreferences settings = new SecurePreferences(_context, _password,
PREF_UNENCRYPTED_NAME);
if(settings.getString(Settings.PREF_USER_NAME, "default") == null) {
// value not available, password has to be invalid
return false;
}
else {
// valid password, create an instance
singleInstance = new Settings(settings, _password);
return true;
}
}
示例6: getLoginDataFromDatabase
import com.securepreferences.SecurePreferences; //导入依赖的package包/类
public void getLoginDataFromDatabase() {
// get universityId from shared preferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
long universityId = prefs.getLong(Constants.PREF_KEY_UNIVERSITY_ID, -1);
long ruleId = prefs.getLong(Constants.PREF_KEY_RULE_ID, -1);
// get university name from database
University university = daoSession.getUniversityDao().queryBuilder()
.where(UniversityDao.Properties.UniversityId.eq(universityId))
.unique();
String universityName = university != null ? university.getName() : "";
// get username from shared preferences
SecurePreferences securePrefs = getSecurePreferences();
String username = securePrefs.getString(Constants.PREF_KEY_USERNAME, "");
LoginDataEvent loginDataEvent = new LoginDataEvent(username, universityId, ruleId, universityName);
EventBus.getDefault().post(loginDataEvent);
}
示例7: deletePreferences
import com.securepreferences.SecurePreferences; //导入依赖的package包/类
/**
* Deletes all normal and secure preferences and restores default values afterwards.
*/
public void deletePreferences() {
// remove username and password
SharedPreferences securePrefs = getSecurePreferences();
SecurePreferences.Editor secureEditor = (SecurePreferences.Editor) securePrefs.edit();
secureEditor.remove(Constants.PREF_KEY_USERNAME);
secureEditor.remove(Constants.PREF_KEY_PASSWORD);
secureEditor.commit();
// clear normal preferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
editor.clear();
editor.apply();
// restore default preferences
PreferenceManager.setDefaultValues(context, R.xml.settings, true);
// cancel possible active alarms
ScrapeAlarmManager scrapeAlarmManager = new ScrapeAlarmManager(context);
scrapeAlarmManager.cancelAlarm();
}
示例8: AppPreferences
import com.securepreferences.SecurePreferences; //导入依赖的package包/类
public AppPreferences(Context context) {
this.sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
this.secureSharedPreferences = new SecurePreferences(context, null, "moticons");
this.editor = sharedPreferences.edit();
this.secureEditor = secureSharedPreferences.edit();
this.context = context;
}
示例9: changePassword
import com.securepreferences.SecurePreferences; //导入依赖的package包/类
/**
* Updates the current application password with a new password, if the old one is correct.
* @param _context Application context calling the method.
* @param _oldPassword Current application password.
* @param _newPassword New application password.
* @return True, if the update was successfully.
*/
public static boolean changePassword(Context _context, String _oldPassword, String _newPassword) {
SecurePreferences securePrefs = new SecurePreferences(_context, _oldPassword,
PREF_UNENCRYPTED_NAME);
try {
securePrefs.handlePasswordChange(_newPassword, _context);
} catch(GeneralSecurityException e) {
e.printStackTrace();
return false;
}
return true;
}
示例10: setPreferences
import com.securepreferences.SecurePreferences; //导入依赖的package包/类
/**
* Fetches all needed settings from the SharedPreferences-object.
* Extracts saved settings and inserts them into the input-views.
*/
private void setPreferences() {
// get SharedPreferences
//this.settings = getSharedPreferences(PREF_ID, 0);
this.settings = new SecurePreferences(getApplicationContext(), "userpassword", null);
// parse settings
this.userName = settings.getString(Settings.PREF_USER_NAME, "Benutzername");
// insert settings
this.userNameInput.setText(this.userName);
//@todo include all settings
}
示例11: PlanYourExchangeModule
import com.securepreferences.SecurePreferences; //导入依赖的package包/类
public PlanYourExchangeModule(PlanYourExchangeApplication planYourExchangeApplication) {
try {
// -- Initialize properties Reader
this.propertyReader = new PropertyReader(planYourExchangeApplication);
// -- Initialize Google Analytics
this.googleAnalytics = GoogleAnalytics.getInstance(planYourExchangeApplication);
googleAnalytics.setLocalDispatchPeriod(DISPATCH_PERIOD_IN_SECONDS);
this.tracker = googleAnalytics.newTracker(propertyReader.getProperty("AnalyticsId"));
tracker.enableExceptionReporting(true);
tracker.enableAdvertisingIdCollection(true);
tracker.enableAutoActivityTracking(true);
// -- Initialize Rest Service Api
ServerService serverService = new ServerService(propertyReader.getProperty("service.url"),
propertyReader.getProperty("service.userName"),
propertyReader.getProperty("service.password"),
new SecurePreferences(planYourExchangeApplication));
this.serverApi = serverService.serverApi;
// -- Initialize UserLocation Based Api
} catch (Exception e) {
Log.e(TAG, planYourExchangeApplication.getResources().getString(R.string.app_init_error), e);
android.os.Process.killProcess(android.os.Process.myPid());
}
this.locationService = new LocationService(planYourExchangeApplication, serverApi);
this.pageFlowContext = new PageFlowContext();
}
示例12: getSecurePreferences
import com.securepreferences.SecurePreferences; //导入依赖的package包/类
@Override
public SharedPreferences getSecurePreferences() {
if (securePreferences == null) {
this.securePreferences = new SecurePreferences(mContext, PREFERENCE_SECURE_PWD, PREFERENCE_SECURE);
}
return securePreferences;
}
示例13: saveLoginData
import com.securepreferences.SecurePreferences; //导入依赖的package包/类
/**
* Saves username and password in secure preferences.
*/
private void saveLoginData(String username, String password) {
SharedPreferences prefs = getSecurePreferences();
SecurePreferences.Editor editor = (SecurePreferences.Editor) prefs.edit();
editor.putString(Constants.PREF_KEY_USERNAME, username);
editor.putString(Constants.PREF_KEY_PASSWORD, password);
editor.apply();
}
示例14: getPrefsEncrypted
import com.securepreferences.SecurePreferences; //导入依赖的package包/类
private SecurePreferences getPrefsEncrypted(){
securePrefs = new SecurePreferences(context, encryptionPassword, encryptedSharedPrefsName);
return securePrefs;
}
示例15: getSecurePreferences
import com.securepreferences.SecurePreferences; //导入依赖的package包/类
public static com.securepreferences.SecurePreferences getSecurePreferences (Context context)
{
if (securePrefs == null)
securePrefs = new com.securepreferences.SecurePreferences(context);
return securePrefs;
}