Java Code Examples for androidx.core.content.ContextCompat#createDeviceProtectedStorageContext()
The following examples show how to use
androidx.core.content.ContextCompat#createDeviceProtectedStorageContext() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PreferenceManager.java From MaterialPreference with Apache License 2.0 | 6 votes |
/** * Gets a {@link SharedPreferences} instance that preferences managed by this will * use. * * @return a {@link SharedPreferences} instance pointing to the file that contain the values of * preferences that are managed by this PreferenceManager. If * a {@link PreferenceDataStore} has been set, this method returns {@code null}. */ public SharedPreferences getSharedPreferences() { if (getPreferenceDataStore() != null) { return null; } if (mSharedPreferences == null) { final Context storageContext; switch (mStorage) { case STORAGE_DEVICE_PROTECTED: storageContext = ContextCompat.createDeviceProtectedStorageContext(mContext); break; default: storageContext = mContext; break; } mSharedPreferences = storageContext.getSharedPreferences(mSharedPreferencesName, mSharedPreferencesMode); } return mSharedPreferences; }
Example 2
Source File: PrefFileManager.java From MinMinGuard with GNU General Public License v3.0 | 6 votes |
private PrefFileManager(Context context) { mContext = Build.VERSION.SDK_INT >= 24 && !ContextCompat.isDeviceProtectedStorage(context) ? ContextCompat.createDeviceProtectedStorageContext(context) : context; mFileObserver = new FileObserver(mContext.getFilesDir().getParentFile() + "/shared_prefs", FileObserver.ATTRIB) { @Override public void onEvent(int event, String path) { if ((event & FileObserver.ATTRIB) != 0) onFileAttributesChanged(path); } }; mFileObserver.startWatching(); }
Example 3
Source File: AppDetailDialogFragment.java From MinMinGuard with GNU General Public License v3.0 | 6 votes |
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle args = getArguments(); appName = args.getString("appName"); pkgName = args.getString("pkgName"); adNetworks = args.getString("adNetworks"); blockNum = args.getInt("blockNum"); Context ctx = ContextCompat.createDeviceProtectedStorageContext(getActivity()); if (ctx == null) ctx = getActivity(); mPref = ctx.getSharedPreferences(Common.MOD_PREFS, Context.MODE_PRIVATE); }
Example 4
Source File: AppsAdapter.java From MinMinGuard with GNU General Public License v3.0 | 6 votes |
public AppsAdapter(Context context, ArrayList<AppDetails> list, MainFragment.FragmentMode mode) { super(); mContext = context; appList = list; Context ctx = ContextCompat.createDeviceProtectedStorageContext(context); if (ctx == null) ctx = context; mPref = ctx.getSharedPreferences(Common.MOD_PREFS, Context.MODE_PRIVATE); helper = new DaoMaster.DevOpenHelper(context, "mmg", null); db = helper.getWritableDatabase(); daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); appDataDao = daoSession.getAppDataDao(); mMode = mode; mAppDataMap = new HashMap<>(); }
Example 5
Source File: SharedPreferencesUtils.java From talkback with Apache License 2.0 | 5 votes |
/** * Gets the appropriate SharedPreferences depending on the device capabilities. On systems that * support device-protected storage (Android N or later with compatible device), returns * SharedPreferences backed by device-protected storage. Otherwise, returns SharedPreferences * backed by a standard credential-protected storage context. */ public static SharedPreferences getSharedPreferences(Context context) { Context deContext = ContextCompat.createDeviceProtectedStorageContext(context); if (deContext != null) { return PreferenceManager.getDefaultSharedPreferences(deContext); } else { return PreferenceManager.getDefaultSharedPreferences(context); } }
Example 6
Source File: SharedPreferencesUtils.java From talkback with Apache License 2.0 | 5 votes |
/** * Move existing preferences file from credential protected storage to device protected storage. * This is used to migrate data between storage locations after an Android upgrade from * Build.VERSION < N to Build.VERSION >= N. */ public static void migrateSharedPreferences(Context context) { if (BuildVersionUtils.isAtLeastN()) { Context deContext = ContextCompat.createDeviceProtectedStorageContext(context); deContext.moveSharedPreferencesFrom( context, PreferenceManager.getDefaultSharedPreferencesName(context)); } }
Example 7
Source File: AndroidTestOrchestrator.java From android-test with Apache License 2.0 | 5 votes |
private OutputStream getOutputStream() { try { Context context = getContext(); // Support for directBootMode if (Build.VERSION.SDK_INT >= 24) { context = ContextCompat.createDeviceProtectedStorageContext(context); } return context.openFileOutput(getOutputFile(), 0); } catch (FileNotFoundException e) { throw new RuntimeException("Could not open stream for output"); } }
Example 8
Source File: DataCollectionConfigStorage.java From firebase-android-sdk with Apache License 2.0 | 4 votes |
private static Context directBootSafe(Context applicationContext) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { return applicationContext; } return ContextCompat.createDeviceProtectedStorageContext(applicationContext); }