mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-19 08:20:15 +00:00
Fix dictionary persistence with Direct Boot
Trigger app restart when credential-encrypted storage is unlocked, to refresh dictionary from credential encrypted storage. This fixes an issue where learned dictionary and frequencies are reset after device restart.
This commit is contained in:
parent
cf45b5b907
commit
1fed180950
2 changed files with 32 additions and 0 deletions
|
@ -32,6 +32,7 @@ import android.os.Build;
|
||||||
import android.os.Debug;
|
import android.os.Debug;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.os.Process;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.PrintWriterPrinter;
|
import android.util.PrintWriterPrinter;
|
||||||
|
@ -186,6 +187,24 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
}
|
}
|
||||||
final HideSoftInputReceiver mHideSoftInputReceiver = new HideSoftInputReceiver(this);
|
final HideSoftInputReceiver mHideSoftInputReceiver = new HideSoftInputReceiver(this);
|
||||||
|
|
||||||
|
final static class RestartAfterDeviceUnlockReceiver extends BroadcastReceiver {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
final String action = intent.getAction();
|
||||||
|
// Restart the keyboard if credential encrypted storage is unlocked. This reloads the
|
||||||
|
// dictionary and other data from credential-encrypted storage (with the onCreate()
|
||||||
|
// method).
|
||||||
|
if (Intent.ACTION_USER_UNLOCKED.equals(action)) {
|
||||||
|
final int myPid = Process.myPid();
|
||||||
|
Log.i(TAG, "Killing my process: pid=" + myPid);
|
||||||
|
Process.killProcess(myPid);
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Unexpected intent " + intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final RestartAfterDeviceUnlockReceiver mRestartAfterDeviceUnlockReceiver = new RestartAfterDeviceUnlockReceiver();
|
||||||
|
|
||||||
private AlertDialog mOptionsDialog;
|
private AlertDialog mOptionsDialog;
|
||||||
|
|
||||||
private final boolean mIsHardwareAcceleratedDrawingEnabled;
|
private final boolean mIsHardwareAcceleratedDrawingEnabled;
|
||||||
|
@ -625,6 +644,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
registerReceiver(mHideSoftInputReceiver, hideSoftInputFilter, PERMISSION_HIDE_SOFT_INPUT,
|
registerReceiver(mHideSoftInputReceiver, hideSoftInputFilter, PERMISSION_HIDE_SOFT_INPUT,
|
||||||
null /* scheduler */);
|
null /* scheduler */);
|
||||||
|
|
||||||
|
final IntentFilter restartAfterUnlockFilter = new IntentFilter();
|
||||||
|
restartAfterUnlockFilter.addAction(Intent.ACTION_USER_UNLOCKED);
|
||||||
|
registerReceiver(mRestartAfterDeviceUnlockReceiver, restartAfterUnlockFilter);
|
||||||
|
|
||||||
StatsUtils.onCreate(mSettings.getCurrent(), mRichImm);
|
StatsUtils.onCreate(mSettings.getCurrent(), mRichImm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -733,6 +756,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
unregisterReceiver(mRingerModeChangeReceiver);
|
unregisterReceiver(mRingerModeChangeReceiver);
|
||||||
unregisterReceiver(mDictionaryPackInstallReceiver);
|
unregisterReceiver(mDictionaryPackInstallReceiver);
|
||||||
unregisterReceiver(mDictionaryDumpBroadcastReceiver);
|
unregisterReceiver(mDictionaryDumpBroadcastReceiver);
|
||||||
|
unregisterReceiver(mRestartAfterDeviceUnlockReceiver);
|
||||||
mStatsUtilsManager.onDestroy(this /* context */);
|
mStatsUtilsManager.onDestroy(this /* context */);
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
@ -742,6 +766,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
unregisterReceiver(mDictionaryPackInstallReceiver);
|
unregisterReceiver(mDictionaryPackInstallReceiver);
|
||||||
unregisterReceiver(mDictionaryDumpBroadcastReceiver);
|
unregisterReceiver(mDictionaryDumpBroadcastReceiver);
|
||||||
unregisterReceiver(mRingerModeChangeReceiver);
|
unregisterReceiver(mRingerModeChangeReceiver);
|
||||||
|
unregisterReceiver(mRestartAfterDeviceUnlockReceiver);
|
||||||
mInputLogic.recycle();
|
mInputLogic.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,14 +18,20 @@ package org.dslul.openboard.inputmethod.latin.utils;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Build;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
|
|
||||||
public final class DeviceProtectedUtils {
|
public final class DeviceProtectedUtils {
|
||||||
|
|
||||||
static final String TAG = DeviceProtectedUtils.class.getSimpleName();
|
static final String TAG = DeviceProtectedUtils.class.getSimpleName();
|
||||||
|
|
||||||
public static SharedPreferences getSharedPreferences(final Context context) {
|
public static SharedPreferences getSharedPreferences(final Context context) {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
||||||
|
return PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
}
|
||||||
Context deviceProtectedContext = getDeviceProtectedContext(context);
|
Context deviceProtectedContext = getDeviceProtectedContext(context);
|
||||||
SharedPreferences deviceProtectedPreferences = PreferenceManager.getDefaultSharedPreferences(deviceProtectedContext);
|
SharedPreferences deviceProtectedPreferences = PreferenceManager.getDefaultSharedPreferences(deviceProtectedContext);
|
||||||
if (deviceProtectedPreferences.getAll().isEmpty()) {
|
if (deviceProtectedPreferences.getAll().isEmpty()) {
|
||||||
|
@ -35,6 +41,7 @@ public final class DeviceProtectedUtils {
|
||||||
return deviceProtectedPreferences;
|
return deviceProtectedPreferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||||
private static Context getDeviceProtectedContext(final Context context) {
|
private static Context getDeviceProtectedContext(final Context context) {
|
||||||
return context.isDeviceProtectedStorage()
|
return context.isDeviceProtectedStorage()
|
||||||
? context : context.createDeviceProtectedStorageContext();
|
? context : context.createDeviceProtectedStorageContext();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue