implement really hacky workaround for another crash on Samsung devices with Android 9
This commit is contained in:
@@ -48,6 +48,8 @@ namespace keepass2android
|
|||||||
public const String KeyEntry = "entry";
|
public const String KeyEntry = "entry";
|
||||||
public const String KeyMode = "mode";
|
public const String KeyMode = "mode";
|
||||||
|
|
||||||
|
public const int RequestCodeActivateRealSearch = 12366;
|
||||||
|
|
||||||
static readonly Dictionary<int /*resource id*/, int /*prio*/> bottomBarElementsPriority = new Dictionary<int, int>()
|
static readonly Dictionary<int /*resource id*/, int /*prio*/> bottomBarElementsPriority = new Dictionary<int, int>()
|
||||||
{
|
{
|
||||||
{ Resource.Id.cancel_insert_element, 20 },
|
{ Resource.Id.cancel_insert_element, 20 },
|
||||||
@@ -171,6 +173,13 @@ namespace keepass2android
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (RequestCodeActivateRealSearch == requestCode)
|
||||||
|
{
|
||||||
|
hasCalledOtherActivity = true;
|
||||||
|
SetSearchItemVisibility();
|
||||||
|
ActivateSearchView();
|
||||||
|
}
|
||||||
|
|
||||||
if ((GroupEditActivity.RequestCodeGroupEdit == requestCode) && (resultCode == Result.Ok))
|
if ((GroupEditActivity.RequestCodeGroupEdit == requestCode) && (resultCode == Result.Ok))
|
||||||
{
|
{
|
||||||
String groupName = data.Extras.GetString(GroupEditActivity.KeyName);
|
String groupName = data.Extras.GetString(GroupEditActivity.KeyName);
|
||||||
@@ -240,6 +249,9 @@ namespace keepass2android
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool hasCalledOtherActivity = false;
|
||||||
|
private IMenuItem searchItem;
|
||||||
|
private IMenuItem searchItemDummy;
|
||||||
|
|
||||||
protected override void OnResume()
|
protected override void OnResume()
|
||||||
{
|
{
|
||||||
@@ -257,7 +269,7 @@ namespace keepass2android
|
|||||||
|
|
||||||
RefreshIfDirty();
|
RefreshIfDirty();
|
||||||
|
|
||||||
|
SetSearchItemVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateInfotexts()
|
private void UpdateInfotexts()
|
||||||
@@ -359,6 +371,12 @@ namespace keepass2android
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnStop()
|
||||||
|
{
|
||||||
|
base.OnStop();
|
||||||
|
hasCalledOtherActivity = false;
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateAndroid8NotificationInfo(bool hideForever = false)
|
private void UpdateAndroid8NotificationInfo(bool hideForever = false)
|
||||||
{
|
{
|
||||||
const string prefsKey = "DidShowAndroid8NotificationInfo";
|
const string prefsKey = "DidShowAndroid8NotificationInfo";
|
||||||
@@ -427,6 +445,7 @@ namespace keepass2android
|
|||||||
|
|
||||||
SetContentView(ContentResourceId);
|
SetContentView(ContentResourceId);
|
||||||
|
|
||||||
|
|
||||||
if (FindViewById(Resource.Id.enable_autofill) != null)
|
if (FindViewById(Resource.Id.enable_autofill) != null)
|
||||||
{
|
{
|
||||||
FindViewById(Resource.Id.enable_autofill).Click += (sender, args) =>
|
FindViewById(Resource.Id.enable_autofill).Click += (sender, args) =>
|
||||||
@@ -502,7 +521,7 @@ namespace keepass2android
|
|||||||
FindViewById(Resource.Id.info_dont_show_child_db_again).Click += (sender, args) =>
|
FindViewById(Resource.Id.info_dont_show_child_db_again).Click += (sender, args) =>
|
||||||
{
|
{
|
||||||
_prefs.Edit().PutBoolean(childdb_ignore_prefskey + App.Kp2a.CurrentDb.CurrentFingerprintPrefKey, true).Commit();
|
_prefs.Edit().PutBoolean(childdb_ignore_prefskey + App.Kp2a.CurrentDb.CurrentFingerprintPrefKey, true).Commit();
|
||||||
UpdateAutofillInfo();
|
UpdateChildDbInfo();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -870,23 +889,34 @@ namespace keepass2android
|
|||||||
MenuInflater inflater = MenuInflater;
|
MenuInflater inflater = MenuInflater;
|
||||||
inflater.Inflate(Resource.Menu.group, menu);
|
inflater.Inflate(Resource.Menu.group, menu);
|
||||||
var searchManager = (SearchManager)GetSystemService(Context.SearchService);
|
var searchManager = (SearchManager)GetSystemService(Context.SearchService);
|
||||||
IMenuItem searchItem = menu.FindItem(Resource.Id.menu_search);
|
|
||||||
|
/*This is the start of a pretty hacky workaround to avoid a crash on Samsung devices with Android 9.
|
||||||
|
* The crash stacktrace is pretty unspecific (see https://stackoverflow.com/questions/54530604/app-crash-but-no-app-specific-code-in-stack-trace)
|
||||||
|
* It points to InputMethodService.java which seems to be modified by Samsung. Hard to tell what's going on.
|
||||||
|
* The problem only occurs, if our own keyboard is activated.
|
||||||
|
* Users found that the crash does not appear if another activity was launched and closed before activating search view.
|
||||||
|
* That's what we do as a workaround: We display another search menu option in case a crash would occur. When that search option is clicked,
|
||||||
|
* we launch an activity which immediately finished. In the activity result, we can activate the search view safely.
|
||||||
|
* If anybody reading this has a better idea, please let me know :-)
|
||||||
|
*/
|
||||||
|
searchItem = menu.FindItem(Resource.Id.menu_search);
|
||||||
|
searchItemDummy = menu.FindItem(Resource.Id.menu_search_dummy);
|
||||||
|
SetSearchItemVisibility();
|
||||||
|
|
||||||
|
|
||||||
var view = searchItem.ActionView;
|
var view = searchItem.ActionView;
|
||||||
|
|
||||||
searchView = view.JavaCast<Android.Support.V7.Widget.SearchView>();
|
searchView = view.JavaCast<Android.Support.V7.Widget.SearchView>();
|
||||||
|
|
||||||
searchView.SetSearchableInfo(searchManager.GetSearchableInfo(ComponentName));
|
searchView.SetSearchableInfo(searchManager.GetSearchableInfo(ComponentName));
|
||||||
searchView.SetOnSuggestionListener(new SuggestionListener(searchView.SuggestionsAdapter, this, searchItem));
|
/*searchView.SetOnSuggestionListener(new SuggestionListener(searchView.SuggestionsAdapter, this, searchItem));
|
||||||
searchView.SetOnQueryTextListener(new OnQueryTextListener(this));
|
searchView.SetOnQueryTextListener(new OnQueryTextListener(this));
|
||||||
|
*/
|
||||||
if (_prefs.GetBoolean("ActivateSearchView", false) && AppTask.CanActivateSearchViewOnStart)
|
if (_prefs.GetBoolean("ActivateSearchView", false) && AppTask.CanActivateSearchViewOnStart)
|
||||||
{
|
{
|
||||||
|
|
||||||
//need to use PostDelayed, otherwise the menu_lock item completely disappears
|
//need to use PostDelayed, otherwise the menu_lock item completely disappears
|
||||||
searchView.PostDelayed(() =>
|
searchView.PostDelayed(ActivateSearchView, 500);
|
||||||
{
|
|
||||||
searchView.Iconified = false;
|
|
||||||
AppTask.CanActivateSearchViewOnStart = false;
|
|
||||||
}, 500);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionBar.LayoutParams lparams = new ActionBar.LayoutParams(ActionBar.LayoutParams.MatchParent,
|
ActionBar.LayoutParams lparams = new ActionBar.LayoutParams(ActionBar.LayoutParams.MatchParent,
|
||||||
@@ -907,6 +937,44 @@ namespace keepass2android
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetSearchItemVisibility()
|
||||||
|
{
|
||||||
|
if ((searchItem == null) || (searchItemDummy == null))
|
||||||
|
return;
|
||||||
|
if (Build.Manufacturer.ToLowerInvariant() == "samsung" && ((int) Build.VERSION.SdkInt >= 28) && (IsKp2aKeyboardActive()) && !hasCalledOtherActivity)
|
||||||
|
{
|
||||||
|
searchItem.SetVisible(false);
|
||||||
|
searchItemDummy.SetVisible(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
searchItem.SetVisible(true);
|
||||||
|
searchItemDummy.SetVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string Kp2aInputMethodName
|
||||||
|
{
|
||||||
|
get { return PackageName + "/keepass2android.softkeyboard.KP2AKeyboard"; }
|
||||||
|
}
|
||||||
|
private bool IsKp2aKeyboardActive()
|
||||||
|
{
|
||||||
|
string currentIme = Android.Provider.Settings.Secure.GetString(
|
||||||
|
ContentResolver,
|
||||||
|
Android.Provider.Settings.Secure.DefaultInputMethod);
|
||||||
|
|
||||||
|
return Kp2aInputMethodName == currentIme;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ActivateSearchView()
|
||||||
|
{
|
||||||
|
|
||||||
|
searchView.Iconified = false;
|
||||||
|
AppTask.CanActivateSearchViewOnStart = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateOfflineModeMenu()
|
private void UpdateOfflineModeMenu()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -966,7 +1034,13 @@ namespace keepass2android
|
|||||||
case Resource.Id.menu_lock:
|
case Resource.Id.menu_lock:
|
||||||
App.Kp2a.Lock();
|
App.Kp2a.Lock();
|
||||||
return true;
|
return true;
|
||||||
|
case Resource.Id.menu_search_dummy:
|
||||||
|
StartActivityForResult(typeof(CloseImmediatelyActivity), RequestCodeActivateRealSearch);
|
||||||
|
OverridePendingTransition(0, 0);
|
||||||
|
hasCalledOtherActivity = true;
|
||||||
|
//TODO transition?
|
||||||
|
|
||||||
|
return true;
|
||||||
case Resource.Id.menu_search:
|
case Resource.Id.menu_search:
|
||||||
case Resource.Id.menu_search_advanced:
|
case Resource.Id.menu_search_advanced:
|
||||||
OnSearchRequested();
|
OnSearchRequested();
|
||||||
|
|||||||
@@ -23,6 +23,11 @@
|
|||||||
app:showAsAction="ifRoom"
|
app:showAsAction="ifRoom"
|
||||||
app:actionViewClass="android.support.v7.widget.SearchView"
|
app:actionViewClass="android.support.v7.widget.SearchView"
|
||||||
/>
|
/>
|
||||||
|
<item android:id="@+id/menu_search_dummy"
|
||||||
|
android:icon="@drawable/ic_menu_search"
|
||||||
|
android:title="@string/menu_search"
|
||||||
|
app:showAsAction="ifRoom"
|
||||||
|
/>
|
||||||
<item android:id="@+id/menu_search_advanced"
|
<item android:id="@+id/menu_search_advanced"
|
||||||
android:icon="@drawable/ic_menu_search"
|
android:icon="@drawable/ic_menu_search"
|
||||||
android:title="@string/menu_search_advanced"
|
android:title="@string/menu_search_advanced"
|
||||||
|
|||||||
@@ -177,6 +177,7 @@
|
|||||||
<Compile Include="addons\CsvStreamReaderEx.cs" />
|
<Compile Include="addons\CsvStreamReaderEx.cs" />
|
||||||
<Compile Include="AutoOpenEdit.cs" />
|
<Compile Include="AutoOpenEdit.cs" />
|
||||||
<Compile Include="ChallengeXCKey.cs" />
|
<Compile Include="ChallengeXCKey.cs" />
|
||||||
|
<Compile Include="CloseImmediatelyActivity.cs" />
|
||||||
<Compile Include="ConfigureChildDatabasesActivity.cs" />
|
<Compile Include="ConfigureChildDatabasesActivity.cs" />
|
||||||
<Compile Include="DisableAutofillForQueryActivity.cs" />
|
<Compile Include="DisableAutofillForQueryActivity.cs" />
|
||||||
<Compile Include="EntryActivityClasses\ViewImagePopupItem.cs" />
|
<Compile Include="EntryActivityClasses\ViewImagePopupItem.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user