谷歌輸入法設定隱藏
阿新 • • 發佈:2019-01-03
由於我們產品沒有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,這樣既不影響系統穩定。也解決機器設定返回不了問題