[DESCRIPTION]
有时候在SettingsProvider中的变量会变掉,但user并没有操作它,或许是被某个3rd的apk修改,我们可以通过以下方式定位到是谁修改了变量。
[SOLUTION]
以下以Settings.Global.WIFI_SLEEP_POLICY为例,对应的value是wifi_sleep_policy,其他变量请具体配置对应value:
1:修改Settings.java (alps\frameworks\base\core\java\android\provider) 中
在class Secure 内部类的
public static boolean putStringForUser(ContentResolver resolver, String name, String value,
int userHandle) {
的后面添加
if(name.equals(Settings.Global.WIFI_SLEEP_POLICY)){ //add begin
Log.d(TAG,"@@## name = "+ name+ "value = "+value,new Exception("Settings"));
} //add end
2:修改
ContentResolver.java (alps\frameworks\base\core\java\android\content)中
在
public final Uri insert(Uri url, ContentValues values)
{
后添加
if(values.containsKey("wifi_sleep_policy")){//add begin
Log.d("Settings","@@##@@ url = "+ url+", values = "+ values,new Exception("Settings"));
}//add end
在
public final int update(Uri uri, ContentValues values, String where,
String[] selectionArgs) {
后添加
if(values.containsKey("wifi_sleep_policy")){//add begin
Log.d("Settings","@@## url = "+ uri+", values = "+ values,new Exception("Settings"));
}//add end
3、复制问题并提供main_log,通过对应的callstack可以找到是谁操作了变量。