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

Commit b0838b26 authored by Joey's avatar Joey Committed by Luca Stefani
Browse files

Trebuchet: only allow hidden apps when no secure keyguard is set



Change-Id: I670a61ff3fee4d7c7d9623ce8810790f1b25224a
Signed-off-by: default avatarJoey <joey@lineageos.org>
parent 4447a63d
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -24,10 +24,7 @@ public class LineageUtils {
     *                        device security or if lock screen is unlocked
     */
    public static void showLockScreen(Context context, String title, Runnable successRunnable) {
        final KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(
                Context.KEYGUARD_SERVICE);

        if (keyguardManager.isKeyguardSecure()) {
        if (hasSecureKeyguard(context)) {
            final BiometricPrompt.AuthenticationCallback authenticationCallback =
                    new BiometricPrompt.AuthenticationCallback() {
                        @Override
@@ -45,6 +42,8 @@ public class LineageUtils {
            final BiometricPrompt.Builder builder = new BiometricPrompt.Builder(context)
                    .setTitle(title);

            final KeyguardManager keyguardManager = context.getSystemService(KeyguardManager.class);

            if (keyguardManager.isDeviceSecure()) {
                builder.setDeviceCredentialAllowed(true);
            }
@@ -55,11 +54,19 @@ public class LineageUtils {
                    runnable -> handler.post(runnable),
                    authenticationCallback);
        } else {
            // Notify the user a secure keyguard is required for protected apps,
            // but allow to set hidden apps
            Toast.makeText(context, R.string.trust_apps_no_lock_error, Toast.LENGTH_LONG)
                .show();
            successRunnable.run();
        }
    }

    public static boolean hasSecureKeyguard(Context context) {
        final KeyguardManager keyguardManager = context.getSystemService(KeyguardManager.class);
        return keyguardManager != null && keyguardManager.isKeyguardSecure();
    }

    public static boolean hasPackageInstalled(Context context, String pkgName) {
        try {
            ApplicationInfo ai = context.getPackageManager().getApplicationInfo(pkgName, 0);
+3 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.lineage.LineageUtils;
import com.android.launcher3.lineage.trust.db.TrustComponent;
import com.android.launcher3.lineage.trust.db.TrustDatabaseHelper;

@@ -74,7 +75,8 @@ public class TrustAppsActivity extends Activity implements
        mLoadingView.setVisibility(View.VISIBLE);
        mProgressBar = findViewById(R.id.hidden_apps_progress_bar);

        mAdapter = new TrustAppsAdapter(this);
        final boolean hasSecureKeyguard = LineageUtils.hasSecureKeyguard(this);
        mAdapter = new TrustAppsAdapter(this, hasSecureKeyguard);
        mDbHelper = TrustDatabaseHelper.getInstance(this);

        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
+7 −3
Original line number Diff line number Diff line
@@ -38,9 +38,11 @@ import java.util.List;
class TrustAppsAdapter extends RecyclerView.Adapter<TrustAppsAdapter.ViewHolder> {
    private List<TrustComponent> mList = new ArrayList<>();
    private Listener mListener;
    private boolean mHasSecureKeyguard;

    TrustAppsAdapter(Listener listener) {
    TrustAppsAdapter(Listener listener, boolean hasSecureKeyguard) {
        mListener = listener;
        mHasSecureKeyguard = hasSecureKeyguard;
    }

    public void update(List<TrustComponent> list) {
@@ -58,7 +60,7 @@ class TrustAppsAdapter extends RecyclerView.Adapter<TrustAppsAdapter.ViewHolder>

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        viewHolder.bind(mList.get(i));
        viewHolder.bind(mList.get(i), mHasSecureKeyguard);
    }

    @Override
@@ -87,7 +89,7 @@ class TrustAppsAdapter extends RecyclerView.Adapter<TrustAppsAdapter.ViewHolder>
            mProtectedView = itemView.findViewById(R.id.item_protected_app_switch);
        }

        void bind(TrustComponent component) {
        void bind(TrustComponent component, boolean hasSecureKeyguard) {
            mIconView.setImageDrawable(component.getIcon());
            mLabelView.setText(component.getLabel());

@@ -96,6 +98,8 @@ class TrustAppsAdapter extends RecyclerView.Adapter<TrustAppsAdapter.ViewHolder>
            mProtectedView.setImageResource(component.isProtected() ?
                    R.drawable.ic_protected_locked : R.drawable.ic_protected_unlocked);

            mProtectedView.setVisibility(hasSecureKeyguard ? View.VISIBLE : View.GONE);

            mHiddenView.setOnClickListener(v -> {
                component.invertVisibility();