Example code, illustrating the usage of the Secure App ROM with asset packs
  • 26 Dec 2024
  • 1 Minute à lire
  • Sombre
    Lumière
  • PDF

Example code, illustrating the usage of the Secure App ROM with asset packs

  • Sombre
    Lumière
  • PDF

The content is currently unavailable in French. You are viewing the default English version.
Résumé de l’article

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.


Cet article vous a-t-il été utile ?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.
ESC

Ozzy, facilitant la découverte de connaissances grâce à l’intelligence conversationnelle