Hi,
I'm trying to update the font using updateFontFamily() API from system settings app. But I'm facing issue of fs-verity not enabled for the .ttf file. How I can overcome this problem. Please suggest me some things.
Error -
"
Failed to update font family
com.android.server.graphics.fonts.FontManagerService$SystemFontException: Font validation failed. Fs-verity is not enabled: /data/fonts/files/~~3BZl2w6MwZwCHwDXhcVTUQ==/Chococooky.ttf
at com.android.server.graphics.fonts.UpdatableFontDir.validateFontFile(UpdatableFontDir.java:539)
at com.android.server.graphics.fonts.UpdatableFontDir.installFontFile(UpdatableFontDir.java:406)
at com.android.server.graphics.fonts.UpdatableFontDir.update(UpdatableFontDir.java:277)
at com.android.server.graphics.fonts.FontManagerService.update(FontManagerService.java:300)
at com.android.server.graphics.fonts.FontManagerService.updateFontFamily(FontManagerService.java:90)
at com.android.internal.graphics.fonts.IFontManager$Stub.onTransact(IFontManager.java:120)
at android.os.Binder.execTransactInternal(Binder.java:1339)
at android.os.Binder.execTransact(Binder.java:1275) "
Code I'm using here is
{
apkname = mFontListAdapter.mFontPackageNames.elementAt(mClickedItem).toString();
ApplicationInfo appInfo = mFontListAdapter.mPackageManager.getApplicationInfo(apkname, PackageManager.GET_META_DATA);
appInfo.publicSourceDir = appInfo.sourceDir;
Resources res = mFontListAdapter.mPackageManager.getResourcesForApplication(appInfo);
AssetManager assetManager = res.getAssets();
String fontName = tpf.getDroidName();
String fontFilePath = FontListAdapter.FONT_DIRECTORY + tpf.getFileName();
Log.d(FF.TAG, "Asset font path: " + fontFilePath);
Log.d(FF.TAG, "Asset font name: " + fontName);
InputStream in = assetManager.open(FontListAdapter.FONT_DIRECTORY + tpf.getFileName());
err_filecopy = fontWriter.copyFontFile(fontDir, in, tpf.getDroidName());
String fontFileName = fontDir + "/" + tpf.getDroidName();
Log.d(FF.TAG, "Font file name wiht path: " + fontFileName);
ParcelFileDescriptor yourFontFd = null;
FontManager fm = getContext().getSystemService(FontManager.class);
String fontFamilyToUpdate = "sans-serif";
//Open the font file with ParcelFileDescriptor
try {
yourFontFd = ParcelFileDescriptor.open(new File(fontFileName), ParcelFileDescriptor.MODE_READ_ONLY);
}
catch (Exception ex)
{
Log.d(FF.TAG, "DEEWANSHU ParcelFileDescriptor.open() fails.");
ex.printStackTrace();
}
if(yourFontFd == null)
{
Log.d(FF.TAG, " yourFontFd is null.");
}
// Retrieve the signature for the font
byte[] signature = null;
Log.d(FF.TAG, "apkname: " + apkname);
signature = getCert(apkname);
if(signature == null)
{
Log.d(FF.TAG, " signature getCert() fails" );
}
// Create font style and family
FontStyle style = new FontStyle(FontStyle.FONT_WEIGHT_NORMAL, FontStyle.FONT_SLANT_UPRIGHT);
FontFamilyUpdateRequest.Font font = new FontFamilyUpdateRequest.Font.Builder(fontName, style).build();
List<FontFamilyUpdateRequest.Font> fonts = Arrays.asList(font);
FontFamilyUpdateRequest.FontFamily family = new FontFamilyUpdateRequest.FontFamily.Builder(fontFamilyToUpdate, fonts).build();
// Update the font family with the file update request and font family
fm.updateFontFamily(new FontFamilyUpdateRequest.Builder()
.addFontFileUpdateRequest(new FontFileUpdateRequest(yourFontFd, signature))
.addFontFamily(family)
.build(), fm.getFontConfig().getConfigVersion());
Log.d(FF.TAG, "Font family updated successfully.");
if (yourFontFd != null) {
try {
yourFontFd.close();
} catch (Exception e) {
Log.e(FF.TAG, "Failed to close ParcelFileDescriptor: " + e.getMessage());
}
}
in.close();
return true;
}
I'm trying to update the font using updateFontFamily() API from system settings app. But I'm facing issue of fs-verity not enabled for the .ttf file. How I can overcome this problem. Please suggest me some things.
Error -
"
Failed to update font family
com.android.server.graphics.fonts.FontManagerService$SystemFontException: Font validation failed. Fs-verity is not enabled: /data/fonts/files/~~3BZl2w6MwZwCHwDXhcVTUQ==/Chococooky.ttf
at com.android.server.graphics.fonts.UpdatableFontDir.validateFontFile(UpdatableFontDir.java:539)
at com.android.server.graphics.fonts.UpdatableFontDir.installFontFile(UpdatableFontDir.java:406)
at com.android.server.graphics.fonts.UpdatableFontDir.update(UpdatableFontDir.java:277)
at com.android.server.graphics.fonts.FontManagerService.update(FontManagerService.java:300)
at com.android.server.graphics.fonts.FontManagerService.updateFontFamily(FontManagerService.java:90)
at com.android.internal.graphics.fonts.IFontManager$Stub.onTransact(IFontManager.java:120)
at android.os.Binder.execTransactInternal(Binder.java:1339)
at android.os.Binder.execTransact(Binder.java:1275) "
Code I'm using here is
{
apkname = mFontListAdapter.mFontPackageNames.elementAt(mClickedItem).toString();
ApplicationInfo appInfo = mFontListAdapter.mPackageManager.getApplicationInfo(apkname, PackageManager.GET_META_DATA);
appInfo.publicSourceDir = appInfo.sourceDir;
Resources res = mFontListAdapter.mPackageManager.getResourcesForApplication(appInfo);
AssetManager assetManager = res.getAssets();
String fontName = tpf.getDroidName();
String fontFilePath = FontListAdapter.FONT_DIRECTORY + tpf.getFileName();
Log.d(FF.TAG, "Asset font path: " + fontFilePath);
Log.d(FF.TAG, "Asset font name: " + fontName);
InputStream in = assetManager.open(FontListAdapter.FONT_DIRECTORY + tpf.getFileName());
err_filecopy = fontWriter.copyFontFile(fontDir, in, tpf.getDroidName());
String fontFileName = fontDir + "/" + tpf.getDroidName();
Log.d(FF.TAG, "Font file name wiht path: " + fontFileName);
ParcelFileDescriptor yourFontFd = null;
FontManager fm = getContext().getSystemService(FontManager.class);
String fontFamilyToUpdate = "sans-serif";
//Open the font file with ParcelFileDescriptor
try {
yourFontFd = ParcelFileDescriptor.open(new File(fontFileName), ParcelFileDescriptor.MODE_READ_ONLY);
}
catch (Exception ex)
{
Log.d(FF.TAG, "DEEWANSHU ParcelFileDescriptor.open() fails.");
ex.printStackTrace();
}
if(yourFontFd == null)
{
Log.d(FF.TAG, " yourFontFd is null.");
}
// Retrieve the signature for the font
byte[] signature = null;
Log.d(FF.TAG, "apkname: " + apkname);
signature = getCert(apkname);
if(signature == null)
{
Log.d(FF.TAG, " signature getCert() fails" );
}
// Create font style and family
FontStyle style = new FontStyle(FontStyle.FONT_WEIGHT_NORMAL, FontStyle.FONT_SLANT_UPRIGHT);
FontFamilyUpdateRequest.Font font = new FontFamilyUpdateRequest.Font.Builder(fontName, style).build();
List<FontFamilyUpdateRequest.Font> fonts = Arrays.asList(font);
FontFamilyUpdateRequest.FontFamily family = new FontFamilyUpdateRequest.FontFamily.Builder(fontFamilyToUpdate, fonts).build();
// Update the font family with the file update request and font family
fm.updateFontFamily(new FontFamilyUpdateRequest.Builder()
.addFontFileUpdateRequest(new FontFileUpdateRequest(yourFontFd, signature))
.addFontFamily(family)
.build(), fm.getFontConfig().getConfigVersion());
Log.d(FF.TAG, "Font family updated successfully.");
if (yourFontFd != null) {
try {
yourFontFd.close();
} catch (Exception e) {
Log.e(FF.TAG, "Failed to close ParcelFileDescriptor: " + e.getMessage());
}
}
in.close();
return true;
}