Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e6e7a483 authored by Frank Preel's avatar Frank Preel
Browse files

Merge remote-tracking branch 'origin/1111-a14-espri-v3' into 1111-a14-espri-v3

parents ad8c8c04 07abdb3a
Loading
Loading
Loading
Loading
+17 −6
Original line number Diff line number Diff line
@@ -877,14 +877,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
            mSuggestionStripView.setListener(this, view);
        }

        Context secureContext = createPackageContext(
            "com.android.inputmethod.latin",
            Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY
            );

        ImageButton floatingButton = view.findViewById(R.id.floating_button);
        if (floatingButton != null) {
            if (isSetupWizardFinished() && (accountIsPremium(getApplicationContext()) || accountIsPremium(secureContext))) {
            if (isSetupWizardFinished() && (accountIsPremium(getApplicationContext()) || accountIsPremiumFromIME())) {
                floatingButton.setVisibility(View.VISIBLE);
                floatingButton.setOnClickListener(new View.OnClickListener() {
                    @Override
@@ -914,6 +909,22 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
        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, "Contexte sécurisé créé avec succès: " + secureContext);
            return accountIsPremium(secureContext);
        } catch (PackageManager.NameNotFoundException e) {
            // Cas gravissime, impossible réellement en théorie dans ton cas précis
            Log.wtf(TAG, "Erreur CRITIQUE: Le package LatinIME n'est pas trouvé par createPackageContext()", e);
            // Logique de secours absolue: repli sur contexte initial même si restreint, mieux que rien
            return accountIsPremium(this);
        }
    }

    private boolean accountIsPremium(Context context) {
        if(ContextCompat.checkSelfPermission(context, android.Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
            Log.e(TAG, "Missing permission");