mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2024-11-25 00:33:24 +01:00
Avoid crashing in direct-boot mode
The settings activity can't open in direct-boot mode. The emoji pane opens without the "last used" data.
This commit is contained in:
parent
f1ce6abe5a
commit
ef34303c7e
@ -8,7 +8,7 @@
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.view.im" android:resource="@xml/method"/>
|
||||
</service>
|
||||
<activity android:name="juloo.keyboard2.SettingsActivity" android:icon="@drawable/ic_launcher" android:label="@string/settings_activity_label" android:theme="@style/android:Theme.DeviceDefault" android:exported="true">
|
||||
<activity android:name="juloo.keyboard2.SettingsActivity" android:icon="@drawable/ic_launcher" android:label="@string/settings_activity_label" android:theme="@style/android:Theme.DeviceDefault" android:exported="true" android:directBootAware="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
</intent-filter>
|
||||
|
@ -83,7 +83,9 @@ public class EmojiGridView extends GridView
|
||||
|
||||
private void saveLastUsed()
|
||||
{
|
||||
SharedPreferences.Editor edit = emojiSharedPreferences().edit();
|
||||
SharedPreferences.Editor edit;
|
||||
try { edit = emojiSharedPreferences().edit(); }
|
||||
catch (Exception _e) { return; }
|
||||
HashSet<String> set = new HashSet<String>();
|
||||
for (Emoji emoji : _lastUsed.keySet())
|
||||
set.add(String.valueOf(_lastUsed.get(emoji)) + "-" + emoji.name());
|
||||
@ -93,15 +95,18 @@ public class EmojiGridView extends GridView
|
||||
|
||||
private void loadLastUsed()
|
||||
{
|
||||
SharedPreferences prefs = emojiSharedPreferences();
|
||||
Set<String> lastUseSet = prefs.getStringSet(LAST_USE_PREF, null);
|
||||
_lastUsed = new HashMap<Emoji, Integer>();
|
||||
SharedPreferences prefs;
|
||||
// Storage might not be available (eg. the device is locked), avoid
|
||||
// crashing.
|
||||
try { prefs = emojiSharedPreferences(); }
|
||||
catch (Exception _e) { return; }
|
||||
Set<String> lastUseSet = prefs.getStringSet(LAST_USE_PREF, null);
|
||||
if (lastUseSet != null)
|
||||
for (String emojiData : lastUseSet)
|
||||
{
|
||||
String[] data = emojiData.split("-", 2);
|
||||
Emoji emoji;
|
||||
|
||||
if (data.length != 2)
|
||||
continue ;
|
||||
emoji = Emoji.getEmojiByName(data[1]);
|
||||
|
@ -14,9 +14,13 @@ public class SettingsActivity extends PreferenceActivity
|
||||
{
|
||||
detectSystemTheme();
|
||||
super.onCreate(savedInstanceState);
|
||||
SharedPreferences prefs;
|
||||
// The preferences can't be read when in direct-boot mode. Avoid crashing
|
||||
// and don't allow changing the settings.
|
||||
try { prefs = PreferenceManager.getDefaultSharedPreferences(this); }
|
||||
catch (Exception _e) { fallbackEncrypted(); return; }
|
||||
addPreferencesFromResource(R.xml.settings);
|
||||
PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.registerOnSharedPreferenceChangeListener(this.new OnPreferencesChange());
|
||||
prefs.registerOnSharedPreferenceChangeListener(this.new OnPreferencesChange());
|
||||
}
|
||||
|
||||
/** The default theme is [Theme.DeviceDefault], which is dark. Detect if the
|
||||
@ -31,6 +35,12 @@ public class SettingsActivity extends PreferenceActivity
|
||||
}
|
||||
}
|
||||
|
||||
void fallbackEncrypted()
|
||||
{
|
||||
// Can't communicate with the user here.
|
||||
finish();
|
||||
}
|
||||
|
||||
/** See DirectBootAwarePreferences. */
|
||||
class OnPreferencesChange implements SharedPreferences.OnSharedPreferenceChangeListener
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user