android.content.Context#createDeviceProtectedStorageContext ( )源码实例Demo

下面列出了android.content.Context#createDeviceProtectedStorageContext ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: security-samples   文件: AlarmStorage.java
public AlarmStorage(Context context) {
    Context storageContext;
    if (BuildCompat.isAtLeastN()) {
        // All N devices have split storage areas, but we may need to
        // move the existing preferences to the new device protected
        // storage area, which is where the data lives from now on.
        final Context deviceContext = context.createDeviceProtectedStorageContext();
        if (!deviceContext.moveSharedPreferencesFrom(context,
                ALARM_PREFERENCES_NAME)) {
            Log.w(TAG, "Failed to migrate shared preferences.");
        }
        storageContext = deviceContext;
    } else {
        storageContext = context;
    }
    mSharedPreferences = storageContext
            .getSharedPreferences(ALARM_PREFERENCES_NAME, Context.MODE_PRIVATE);
}
 
源代码2 项目: libsu   文件: BusyBoxInstaller.java
@Override
public boolean onInit(@NonNull Context context, @NonNull Shell shell) {
    Context de = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
            ? context.createDeviceProtectedStorageContext() : context;

    File lib = new File(de.getApplicationInfo().nativeLibraryDir, "libbusybox.so");
    File bbPath = new File(de.getFilesDir().getParentFile(), "busybox");
    File bb = new File(bbPath, "busybox");

    bbPath.mkdir();
    shell.newJob().add(
            "rm -f " + bbPath + "/*",
            "ln -sf " + lib + " " + bb,
            bb + " --install -s " + bbPath,
            "export PATH=" + bbPath + ":$PATH"
    ).exec();

    return true;
}
 
源代码3 项目: android-DirectBoot   文件: AlarmStorage.java
public AlarmStorage(Context context) {
    Context storageContext;
    if (BuildCompat.isAtLeastN()) {
        // All N devices have split storage areas, but we may need to
        // move the existing preferences to the new device protected
        // storage area, which is where the data lives from now on.
        final Context deviceContext = context.createDeviceProtectedStorageContext();
        if (!deviceContext.moveSharedPreferencesFrom(context,
                ALARM_PREFERENCES_NAME)) {
            Log.w(TAG, "Failed to migrate shared preferences.");
        }
        storageContext = deviceContext;
    } else {
        storageContext = context;
    }
    mSharedPreferences = storageContext
            .getSharedPreferences(ALARM_PREFERENCES_NAME, Context.MODE_PRIVATE);
}
 
源代码4 项目: android_9.0.0_r45   文件: FullBackup.java
BackupScheme(Context context) {
    mFullBackupContent = context.getApplicationInfo().fullBackupContent;
    mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
    mPackageManager = context.getPackageManager();
    mPackageName = context.getPackageName();

    // System apps have control over where their default storage context
    // is pointed, so we're always explicit when building paths.
    final Context ceContext = context.createCredentialProtectedStorageContext();
    FILES_DIR = ceContext.getFilesDir();
    DATABASE_DIR = ceContext.getDatabasePath("foo").getParentFile();
    ROOT_DIR = ceContext.getDataDir();
    SHAREDPREF_DIR = ceContext.getSharedPreferencesPath("foo").getParentFile();
    CACHE_DIR = ceContext.getCacheDir();
    NOBACKUP_DIR = ceContext.getNoBackupFilesDir();

    final Context deContext = context.createDeviceProtectedStorageContext();
    DEVICE_FILES_DIR = deContext.getFilesDir();
    DEVICE_DATABASE_DIR = deContext.getDatabasePath("foo").getParentFile();
    DEVICE_ROOT_DIR = deContext.getDataDir();
    DEVICE_SHAREDPREF_DIR = deContext.getSharedPreferencesPath("foo").getParentFile();
    DEVICE_CACHE_DIR = deContext.getCacheDir();
    DEVICE_NOBACKUP_DIR = deContext.getNoBackupFilesDir();

    if (android.os.Process.myUid() != Process.SYSTEM_UID) {
        EXTERNAL_DIR = context.getExternalFilesDir(null);
    } else {
        EXTERNAL_DIR = null;
    }
}
 
源代码5 项目: capillary   文件: Utils.java
/**
 * Creates a storage context that is protected by device-specific credentials.
 *
 * <p>This method only has an effect on API levels 24 and above.
 */
Context getDeviceProtectedStorageContext(Context context) {
  if (VERSION.SDK_INT >= VERSION_CODES.N) {
    return context.createDeviceProtectedStorageContext();
  }
  return context;
}
 
public static byte[] loadPasswordResetTokenFromPreference(Context context) {
    Context directBootContext = context.createDeviceProtectedStorageContext();
    SharedPreferences settings = directBootContext.getSharedPreferences(PREFS_NAME, 0);
    String tokenString = settings.getString(TOKEN_NAME, null);
    if (tokenString != null) {
        return Base64.getDecoder().decode(tokenString.getBytes(StandardCharsets.UTF_8));
    } else {
        return null;
    }
}
 
源代码7 项目: LocationReportEnabler   文件: PropUtil.java
public static SharedPreferences getProtecredSharedPreferences(Context context) {
    SharedPreferences preferences;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        Context protectedContext = context.createDeviceProtectedStorageContext();
        preferences = protectedContext.getSharedPreferences(PropUtil.PREFERENCE_NAME, Context.MODE_PRIVATE);
    }
    else {
        preferences = context.getSharedPreferences(PropUtil.PREFERENCE_NAME, Context.MODE_PRIVATE);
    }
    return preferences;
}
 
源代码8 项目: XMiTools   文件: ContextUtils.java
@RequiresApi(api = Build.VERSION_CODES.N)
public static Context getProtectedContext(Context context) {
    return context.isDeviceProtectedStorage() ? context
            : context.createDeviceProtectedStorageContext();
}
 
源代码9 项目: pandora   文件: SharedPrefDriver.java
public SharedPrefDriver(Context context) {
    this.context = context;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        DPStorageContext = context.createDeviceProtectedStorageContext();
    }
}
 
源代码10 项目: capillary   文件: Utils.java
private static Context getDeviceProtectedStorageContext(Context context) {
  if (VERSION.SDK_INT >= VERSION_CODES.N) {
    return context.createDeviceProtectedStorageContext();
  }
  return context;
}
 
 方法所在类
 同类方法