检测&QUOT的变化

检测&QUOT的变化

本文介绍了检测&QUOT的变化;锁定SIM卡"在设置/安全/设置SIM卡锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

针对Android的4.0.x的preferably一个问题。

我要立即检测,或几秒钟后,所做的任何更改为锁定SIM卡设置>安全>设置SIM卡锁

我试过3种方法:

1)访问只读 com.android.settings 共享preferences。

 上下文设置= getApplicationContext()createPackageContext(com.android.settings,Context.CONTEXT_IGNORE_SECURITY)。
共享preferences prefSettings = settings.getShared preferences(com.android.settings_ preferences,MODE_WORLD_READABLE);

地图<字符串,> allSettings = prefSettings.getAll();
对于(字符串S:allSettings.keySet()){
    //像字符串值做财产以后= allSettings.get(S)的ToString());
}
 

有一个在logcat中警告:尝试读取preferences文件/data/data/com.android.settings/shared_$p$pfs/com.android.settings_$p$pferences.xml擅自 。通过 GETALL()返回的映射为空。

2) ITelephony.isSimPinEnabled()总是返回false,即使在SIM PIN启用并设定。所以会出现更改设置有绝对无关,与此接口。我想查询的接口,但是这是没有不太妙。

3)创建一个 ContentObserver 观察 Settings.Secure 是不是在这里工作。其实,读 settings.db 与sqlite的内容显示没有更改此设置时,修改后的任何记录。这也证实了以下code:

 尝试{
    INT lockPattern = android.provider.Settings.Secure.getInt(getContentResolver(),android.provider.Settings.Secure.LOCK_PATTERN_ENABLED);
    //检查锁定模式:0 =禁用,1 =启用
}赶上(SettingNotFoundException E){
    e.printStackTrace(); //上来看,我们达到这条线。
}
 

我可以肯定的唯一的事情就是修改 SIM卡PIN启用设置重写com.android.settings preferences.xml文件,如下所示:

 < XML版本=1.0编码=UTF-8独立='是'&GT?;
<地图>
<布尔名=sim_toggle值=真/>
<字符串名称=sim_pin>< /串>
< /图>
 

受变化的标记是 sim_toggle

有没有人有一个想法?我在做什么错在这里?

解决方案

不得不实施办法FINDE出来,如果​​SimPin今天启用。该ITelephony.isSimPinEnabled()总是返回false对我也是。没有尝试你所描述的其他方法。

我找到了一种方法来获得当前设置:

  • 首先,你需要找到一个proxyPhone对象,这可怎么做都可以在这里看到:Can一个telephony.Phone对象通过SDK进行实例化?

  • 然后你可以检索IccCard-对象,并在此执行方法getIccLockEnabled。

code:

 对象proxyPhone = PhoneUtil.getProxyPhoneInstance(本);

  类<>手机=的Class.forName(com.android.internal.telephony.Phone);
  方法getIccCardMethod = phone.getDeclaredMethod(getIccCard);
  对象iccCard = getIccCardMethod.invoke(proxyPhone);
  类<> iccCardClass =的Class.forName(com.android.internal.telephony.IccCard);

  方法getIccLockEnabled = iccCardClass.getDeclaredMethod(getIccLockEnabled);
  布尔isIccLockEnabled =(布尔)getIccLockEnabled.invoke(iccCard);
 

对我的作品在Android 2.3(+?),但中提到的其他线程,你必须运行此code为手机用户/作为电话的过程。

真的有点失望,没有公共API / deviceAdmin-API为这一点。可以想像,公司的需要,以确保他们聘用过的员工保持SIM PIN启用(盗窃的情况下)。

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:

<?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?

解决方案

Had to implement a way to finde out if the SimPin is Enabled today.The ITelephony.isSimPinEnabled() always returned false for me, too. Didn't try the other methods you described.

I found a way to get the current setting:

Code:

  Object proxyPhone = PhoneUtil.getProxyPhoneInstance(this);

  Class<?> phone = Class.forName("com.android.internal.telephony.Phone");
  Method getIccCardMethod = phone.getDeclaredMethod("getIccCard");
  Object iccCard = getIccCardMethod.invoke(proxyPhone);
  Class<?> iccCardClass = Class.forName("com.android.internal.telephony.IccCard");

  Method getIccLockEnabled = iccCardClass.getDeclaredMethod("getIccLockEnabled");
  Boolean isIccLockEnabled = (Boolean) getIccLockEnabled.invoke(iccCard);

works for me on Android 2.3(+?), but as mentioned in the other thread you have to run this code as phone-user/as phone-process.

Really kinda disappointed that there is no public api / deviceAdmin-Api for this. Could imagine that companys want to ensure that their employes keep the sim pin enabled (case of theft).

这篇关于检测&QUOT的变化;锁定SIM卡&QUOT;在设置/安全/设置SIM卡锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 14:41