A question aimed at Android 4.0.x preferably.
I want to detect immediately, or after a few seconds, any change made to Lock SIM card
in Settings > Security > Set up SIM card lock
.
I tried 3 methods:
1) access read-only com.android.settings
shared preferences.
Context settings = getApplicationContext().createPackageContext("com.android.settings", Context.CONTEXT_IGNORE_SECURITY);
SharedPreferences prefSettings = settings.getSharedPreferences("com.android.settings_preferences", MODE_WORLD_READABLE);
Map<String, ?> allSettings = prefSettings.getAll();
for(String s : allSettings.keySet()){
//do somthing like String value=allSettings.get(s).toString());
}
There is a warning in logcat: "Attempt to read preferences file /data/data/com.android.settings/shared_prefs/com.android.settings_preferences.xml without permission". The map returned by getAll()
is empty.
2) ITelephony.isSimPinEnabled()
always returns false, even when the SIM PIN is enabled and set. So it appears changing the setting has absolutely nothing to do with this interface. I was thinking of polling the interface but this is no good either.
3) creating a ContentObserver
observing Settings.Secure
is not working here. Actually, reading the content of settings.db
with sqlite shows there isn't any record modified when changing this setting. This was also confirmed by the following code:
try {
int lockPattern = android.provider.Settings.Secure.getInt(getContentResolver(), android.provider.Settings.Secure.LOCK_PATTERN_ENABLED);
// check lock Pattern: 0=disabled, 1=enabled
} catch (SettingNotFoundException e) {
e.printStackTrace(); // on run, we reach this line.
}
The only thing I am sure is that modifying the SIM PIN enabled
setting rewrites com.android.settings preferences.xml file as shown below:
$adb shell cat
/data/data/com.android.settings/shared_prefs/com.android.settings_preferences.xml
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<boolean name="sim_toggle" value="true" />
<string name="sim_pin"></string>
</map>
The tag affected by the change is sim_toggle
.
Does anyone have an idea? What am I doing wrong here?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…