- 26 Dec 2024
- 1 Minute à lire
- SombreLumière
- PDF
Example code, illustrating the usage of the Secure App ROM with asset packs
- Mis à jour le 26 Dec 2024
- 1 Minute à lire
- SombreLumière
- PDF
Function retrieving data from the Secure App ROM with a SecureApp ROM entry in an on-demand asset pack.
package com.example.sar; import java.io.IOException; import java.io.InputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import android.content.Context; import com.google.android.play.core.assetpacks.AssetPackLocation; import com.google.android.play.core.assetpacks.AssetPackManager; import com.google.android.play.core.assetpacks.AssetPackManagerFactory; import no.promon.shield.storage.rom.SecureAppRom; public class SARExampleAssetPack { private static final String KEY = "secret/Text"; private static final String ASSET_PACK = "OnDemandAssetPack"; String getSecretTextFromOnDemandAssetPack(Context context) throws IOException { AssetPackManager manager = AssetPackManagerFactory.getInstance(context); // Query the AssetPackManager for the status of `ASSET_PACK`. AssetPackLocation packLocation = manager.getPackLocation(ASSET_PACK); if (packLocation == null) { // The asset pack is not downloaded, download asset pack. ... } else { // Supply the asset pack location to the SecureAppRom instance. InputStream is = SecureAppRom.getInstance(context) .open(packLocation.assetsPath(), KEY); // Read the stream BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder text = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { text.append(line); } return text.toString(); } } } ...
This function first queries the AssetPackManager to get the location of the on-demand asset pack. If packLocation is null the asset pack is not installed and must be downloaded before we can open the Secure App ROM entry.
If we get an AssetPackLocation back we can proceed and open the SecureAppRom Entry by calling SecureAppRom.getInstance() to get a SecureAppRom instance and then opens an InputStream for the file <AssetPackDownloadPathInFileSystem>/assets/sarom/secret/Text by calling SecureAppRom.open(packLocation.assetsPath(), "secret/Text"), then read the content from the input stream as a text file.