Closed vvb2060 closed 2 years ago
Hello @vvb2060 And thank you for getting in touch with us! I'm working on your issue. Will update this conversation once get results.
@vvb2060 , Unfortunately, I'm unable to reproduce your issue for now. It will be great if you'll have a possibility to share sample app reproducing the issue.
No need to reproduce, just follow this guide https://developer.android.com/training/articles/direct-boot to fix it.
@vvb2060 I've filed a bug on our internal dashboard. Thank you for the update.
Hi, @vvb2060! The App Center SDK doesn't support this behavior. Could you please try to check this workaround in your project before App Center start? Do it resolve your issue?
private static String TAG = "AppCenterTag";
private static String APP_CENTER_PREF_NAME = "AppCenter";
private static String APP_CENTER_DATABASE = "com.microsoft.appcenter.persistence";
private void supportDirectBootModeWorkaround(Context context) {
Context deviceContext = context;
// Get encryption status.
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
int encryptionStatus = devicePolicyManager.getStorageEncryptionStatus();
Log.d(TAG, "Current encryption status: " + encryptionStatus);
// Move data if needed.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
&& (encryptionStatus == ENCRYPTION_STATUS_ACTIVE || encryptionStatus == ENCRYPTION_STATUS_ACTIVE_PER_USER)) {
deviceContext = context.createDeviceProtectedStorageContext();
if (!deviceContext.moveSharedPreferencesFrom(context,
APP_CENTER_PREF_NAME)) {
Log.d(TAG, "Failed to migrate App Center shared preferences.");
}
if (!deviceContext.moveDatabaseFrom(context, APP_CENTER_DATABASE)) {
Log.d(TAG, "Failed to migrate App Center database.");
}
}
}
I think this workaround won't fix the problem, you need to replace the context with deviceProtectedContext in appcenter library to get sp or db. I can't help you because I can only pass in the application object to initialize, not context.
Ok, I got it. Thanks for the quick check. The App Center SDK does not support this behavior for now. I will label this issue as a feature request. Also, feel free to open contribution PRs if you already have a solution.
Why this is a feature request? Both direct boot and FBE are introduced in Android 7.0, shouldn't it be a bug that the App Center SDK doesn't support features introduced in official Android nearly 6 years ago?
When the device has been powered on but the user has not unlocked the device in Direct Boot Mode, components can't access the device encrypted storage and credential encrypted storage. To access device encrypted storage, you should use context.createDeviceProtectedStorageContext() instead of context. So it is a bug, isn't it?
The App Center SDK does not support work in this mode for now. We will start this feature as soon as possible. Contribution PRs are welcome.
My workaround
private static Application getDeApplication(Application app) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return app;
var deApp = new Application() {
@Override
public void registerActivityLifecycleCallbacks(ActivityLifecycleCallbacks callback) {
app.registerActivityLifecycleCallbacks(callback);
}
};
try {
var attach = ContextWrapper.class.getDeclaredMethod("attachBaseContext", Context.class);
attach.setAccessible(true);
attach.invoke(deApp, app.getApplicationContext().createDeviceProtectedStorageContext());
return deApp;
} catch (ReflectiveOperationException ignored) {
return app;
}
}
AppCenter.start(getDeApplication(app), "", Crashes.class);
The fix has been released! I'm closing the issue, but feel free to reopen if you face it again.
Description
Repro Steps
Please list the steps used to reproduce your issue.
AppCenter.start()
whenApplication.onCreate()
logcat -b crash
Details
https://developer.android.com/training/articles/direct-boot