版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lb5761311/article/details/84247044
由于我们产品没有Android底部三个导航键,并且开机之后就启动我们自己的app,一旦进入输入法设置之后就无法退出当前界面。只能重新启动机器,这是一个很操蛋的bug,
之前有测试的同学告诉我。我上一个版本没有设置这个选项,通过查询log得知,我之前版本是没有做user_setup_complete 初始化设置。
有两种解决办法。
第一中就是直接系统第一次开机的时候不设置
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);
这样可能会引起其他问题,因为系统很多源码都会获取
Settings.Secure.USER_SETUP_COMPLETE 是否 =1
据我所知 framework很多源码都会调用这个属性,如果为0 会引起系统某些未知bug,
第二种方法
Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE);
我们已知输入法是通过上面的方法获取当前USER_SETUP_COMPLETE 的值,为 1代表已经初始化, 为0 未初始化。
所以可以在 getInt中判断 当前正在调用本方法的app名字。如果是谷歌输入法,就默认返回 0 ,
文件
frameworks/base/core/java/android/provider/Settings.java
public static final class Secure extends NameValueTable {
****
public static String getStringForUser(ContentResolver resolver, String name,
int userHandle) {
//add
String Pname = resolver.getPackageName();
Log.e(TAG,"user getInt package name is " + Pname);
Log.e(TAG,"user getInt name name is " + name);
//add end
if(name.equals("USER_SETUP_COMPLETE")&&(Pname.equals("com.google.android.inputmethod.pinyin"))){
return "0";
}
if (MOVED_TO_GLOBAL.contains(name)) {
Log.w(TAG, "Setting " + name + " has moved from android.provider.Settings.Secure"
+ " to android.provider.Settings.Global.");
return Global.getStringForUser(resolver, name, userHandle);
}
if (MOVED_TO_LOCK_SETTINGS.contains(name)) {
synchronized (Secure.class) {
if (sLockSettings == null) {
sLockSettings = ILockSettings.Stub.asInterface(
(IBinder) ServiceManager.getService("lock_settings"));
sIsSystemProcess = Process.myUid() == Process.SYSTEM_UID;
}
}
if (sLockSettings != null && !sIsSystemProcess) {
// No context; use the ActivityThread's context as an approximation for
// determining the target API level.
Application application = ActivityThread.currentApplication();
boolean isPreMnc = application != null
&& application.getApplicationInfo() != null
&& application.getApplicationInfo().targetSdkVersion
<= VERSION_CODES.LOLLIPOP_MR1;
if (isPreMnc) {
try {
return sLockSettings.getString(name, "0", userHandle);
} catch (RemoteException re) {
// Fall through
}
} else {
throw new SecurityException("Settings.Secure." + name
+ " is deprecated and no longer accessible."
+ " See API documentation for potential replacements.");
}
}
}
return sNameValueCache.getStringForUser(resolver, name, userHandle);
}
}
String Pname = resolver.getPackageName();
是获取调用者的app的包名。
if(name.equals("USER_SETUP_COMPLETE")&&(Pname.equals("com.google.android.inputmethod.pinyin"))){
return "0";
}
对比要获取的属性名字和调用者的app包名。一致就返回为0,这样既不影响系统稳定。也解决机器设置返回不了问题