Loading java/src/com/android/inputmethod/latin/LatinIME.java +21 −51 Original line number Original line Diff line number Diff line Loading @@ -60,6 +60,7 @@ import android.view.Window; import android.view.WindowManager; import android.view.WindowManager; import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype; import android.widget.ImageButton; import android.widget.ImageButton; Loading Loading @@ -140,6 +141,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private static final int MAX_SPACESLIDE_CHARS = 32; private static final int MAX_SPACESLIDE_CHARS = 32; private static final String KEY_STT_KEYBOARD = "foundation.e.stt/.MurenaWhisperInputService"; /** /** * A broadcast intent action to hide the software keyboard. * A broadcast intent action to hide the software keyboard. */ */ Loading Loading @@ -868,8 +871,22 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mIsHardwareAcceleratedDrawingEnabled); mIsHardwareAcceleratedDrawingEnabled); } } public void switchToSttIme() { private boolean isSttKeyboardActivated() { switchInputMethod("foundation.e.stt/.MurenaWhisperInputService"); InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); List<InputMethodInfo> enabledImeList = inputMethodManager.getEnabledInputMethodList(); for (InputMethodInfo inputMethodInfo : enabledImeList) { if (inputMethodInfo.getId().equals(KEY_STT_KEYBOARD)) { return true; } } Log.e(TAG, "The targeted keyboard is not activated : " + KEY_STT_KEYBOARD); return false; } private void switchToSttIme() { if (isSttKeyboardActivated()) { switchInputMethod(KEY_STT_KEYBOARD); } } } @Override @Override Loading @@ -885,13 +902,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen floatingButton = view.findViewById(R.id.floating_button); floatingButton = view.findViewById(R.id.floating_button); if (floatingButton != null) { if (floatingButton != null) { //if (isSetupWizardFinished() && (accountIsPremium(getApplicationContext()) || accountIsPremiumFromIME())) { if (shouldShowFloatingButton()) { if (shouldShowFloatingButton()) { floatingButton.setVisibility(View.VISIBLE); floatingButton.setVisibility(View.VISIBLE); floatingButton.setOnClickListener(new View.OnClickListener() { floatingButton.setOnClickListener(new View.OnClickListener() { @Override @Override public void onClick(View v) { public void onClick(View v) { //switchToNextInputMethod(); switchToSttIme(); switchToSttIme(); } } }); }); Loading @@ -902,64 +917,19 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } private boolean shouldShowFloatingButton() { private boolean shouldShowFloatingButton() { Log.d(TAG, ">>>shouldShowFloatingButton"); return accountIsPremium(getApplicationContext()) && isSttKeyboardActivated(); return true; } private void switchToNextInputMethod() { final IBinder token = getWindow().getWindow().getAttributes().token; InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); if (inputMethodManager != null) { inputMethodManager.switchToNextInputMethod(token, false); } } private boolean isSetupWizardFinished() { ContentResolver contentResolver = mDisplayContext.getContentResolver(); boolean isDeviceProvisioned = android.provider.Settings.Global.getInt(contentResolver, android.provider.Settings.Global.DEVICE_PROVISIONED, 0) == 1; Log.d(TAG, ">>>isDeviceProvisioned=" + isDeviceProvisioned); return isDeviceProvisioned; } private boolean accountIsPremiumFromIME() { try { final Context secureContext = createPackageContext( "com.android.inputmethod.latin", Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY ); Log.d(TAG, "Secur context: " + secureContext); return accountIsPremium(secureContext); } catch (PackageManager.NameNotFoundException e) { Log.wtf(TAG, "Error createPackageContext()", e); return accountIsPremium(this); } } } private boolean accountIsPremium(Context context) { private boolean accountIsPremium(Context context) { if(ContextCompat.checkSelfPermission(context, android.Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) { Log.e(TAG, "Missing permission"); return false; } AccountManager accountManager = AccountManager.get(context); AccountManager accountManager = AccountManager.get(context); Log.d(TAG, "AccountManager: " + accountManager); Account[] accountList = accountManager.getAccountsByType("e.foundation.webdav.eelo"); Account[] accountList = accountManager.getAccountsByType("e.foundation.webdav.eelo"); Log.d(TAG, "Nb: " + accountList.length); for (Account account : accountList) { for (Account account : accountList) { Log.d(TAG, "Account: " + account.name); String groupData = accountManager.getUserData(account, "group"); String groupData = accountManager.getUserData(account, "group"); Log.d(TAG, "Group: " + groupData); if (groupData != null && groupData.contains("premium")) { if ("premium".equals(groupData)) { Log.d(TAG, "Premium"); return true; return true; } } } } Log.d(TAG, "No premium user"); return false; return false; } } Loading Loading
java/src/com/android/inputmethod/latin/LatinIME.java +21 −51 Original line number Original line Diff line number Diff line Loading @@ -60,6 +60,7 @@ import android.view.Window; import android.view.WindowManager; import android.view.WindowManager; import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype; import android.widget.ImageButton; import android.widget.ImageButton; Loading Loading @@ -140,6 +141,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private static final int MAX_SPACESLIDE_CHARS = 32; private static final int MAX_SPACESLIDE_CHARS = 32; private static final String KEY_STT_KEYBOARD = "foundation.e.stt/.MurenaWhisperInputService"; /** /** * A broadcast intent action to hide the software keyboard. * A broadcast intent action to hide the software keyboard. */ */ Loading Loading @@ -868,8 +871,22 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mIsHardwareAcceleratedDrawingEnabled); mIsHardwareAcceleratedDrawingEnabled); } } public void switchToSttIme() { private boolean isSttKeyboardActivated() { switchInputMethod("foundation.e.stt/.MurenaWhisperInputService"); InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); List<InputMethodInfo> enabledImeList = inputMethodManager.getEnabledInputMethodList(); for (InputMethodInfo inputMethodInfo : enabledImeList) { if (inputMethodInfo.getId().equals(KEY_STT_KEYBOARD)) { return true; } } Log.e(TAG, "The targeted keyboard is not activated : " + KEY_STT_KEYBOARD); return false; } private void switchToSttIme() { if (isSttKeyboardActivated()) { switchInputMethod(KEY_STT_KEYBOARD); } } } @Override @Override Loading @@ -885,13 +902,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen floatingButton = view.findViewById(R.id.floating_button); floatingButton = view.findViewById(R.id.floating_button); if (floatingButton != null) { if (floatingButton != null) { //if (isSetupWizardFinished() && (accountIsPremium(getApplicationContext()) || accountIsPremiumFromIME())) { if (shouldShowFloatingButton()) { if (shouldShowFloatingButton()) { floatingButton.setVisibility(View.VISIBLE); floatingButton.setVisibility(View.VISIBLE); floatingButton.setOnClickListener(new View.OnClickListener() { floatingButton.setOnClickListener(new View.OnClickListener() { @Override @Override public void onClick(View v) { public void onClick(View v) { //switchToNextInputMethod(); switchToSttIme(); switchToSttIme(); } } }); }); Loading @@ -902,64 +917,19 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } private boolean shouldShowFloatingButton() { private boolean shouldShowFloatingButton() { Log.d(TAG, ">>>shouldShowFloatingButton"); return accountIsPremium(getApplicationContext()) && isSttKeyboardActivated(); return true; } private void switchToNextInputMethod() { final IBinder token = getWindow().getWindow().getAttributes().token; InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); if (inputMethodManager != null) { inputMethodManager.switchToNextInputMethod(token, false); } } private boolean isSetupWizardFinished() { ContentResolver contentResolver = mDisplayContext.getContentResolver(); boolean isDeviceProvisioned = android.provider.Settings.Global.getInt(contentResolver, android.provider.Settings.Global.DEVICE_PROVISIONED, 0) == 1; Log.d(TAG, ">>>isDeviceProvisioned=" + isDeviceProvisioned); return isDeviceProvisioned; } private boolean accountIsPremiumFromIME() { try { final Context secureContext = createPackageContext( "com.android.inputmethod.latin", Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY ); Log.d(TAG, "Secur context: " + secureContext); return accountIsPremium(secureContext); } catch (PackageManager.NameNotFoundException e) { Log.wtf(TAG, "Error createPackageContext()", e); return accountIsPremium(this); } } } private boolean accountIsPremium(Context context) { private boolean accountIsPremium(Context context) { if(ContextCompat.checkSelfPermission(context, android.Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) { Log.e(TAG, "Missing permission"); return false; } AccountManager accountManager = AccountManager.get(context); AccountManager accountManager = AccountManager.get(context); Log.d(TAG, "AccountManager: " + accountManager); Account[] accountList = accountManager.getAccountsByType("e.foundation.webdav.eelo"); Account[] accountList = accountManager.getAccountsByType("e.foundation.webdav.eelo"); Log.d(TAG, "Nb: " + accountList.length); for (Account account : accountList) { for (Account account : accountList) { Log.d(TAG, "Account: " + account.name); String groupData = accountManager.getUserData(account, "group"); String groupData = accountManager.getUserData(account, "group"); Log.d(TAG, "Group: " + groupData); if (groupData != null && groupData.contains("premium")) { if ("premium".equals(groupData)) { Log.d(TAG, "Premium"); return true; return true; } } } } Log.d(TAG, "No premium user"); return false; return false; } } Loading