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

Commit a05e6c3d authored by d34d's avatar d34d Committed by Clark Scheff
Browse files

SysUI: Update external keyguard view when component changed

List for changes to the third party keyguard component and update
external keyguard view.

Change-Id: I4a4e8157f9302cece7d9edde2a82713bc0df7926
TICKET: CYNGNOS-1481
parent b8580a17
Loading
Loading
Loading
Loading
+55 −3
Original line number Diff line number Diff line
@@ -21,12 +21,15 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.app.ActivityManager;
import android.app.StatusBarManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.database.ContentObserver;
@@ -227,6 +230,7 @@ public class NotificationPanelView extends PanelView implements

    private ComponentName mThirdPartyKeyguardViewComponent;
    private KeyguardExternalView mKeyguardExternalView;
    private CmLockPatternUtils mLockPatternUtils;

    private Runnable mHeadsUpExistenceChangedRunnable = new Runnable() {
        @Override
@@ -314,9 +318,9 @@ public class NotificationPanelView extends PanelView implements
            }
        });

        CmLockPatternUtils lockPatternUtils = new CmLockPatternUtils(getContext());
        if (lockPatternUtils.isThirdPartyKeyguardEnabled()) {
            mThirdPartyKeyguardViewComponent = lockPatternUtils.getThirdPartyKeyguardComponent();
        mLockPatternUtils = new CmLockPatternUtils(getContext());
        if (mLockPatternUtils.isThirdPartyKeyguardEnabled()) {
            mThirdPartyKeyguardViewComponent = mLockPatternUtils.getThirdPartyKeyguardComponent();
        }
    }

@@ -324,12 +328,15 @@ public class NotificationPanelView extends PanelView implements
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        mSettingsObserver.observe();
        mContext.registerReceiver(mExternalKeyguardViewChangedReceiver,
                new IntentFilter(CmLockPatternUtils.ACTION_THIRD_PARTY_KEYGUARD_COMPONENT_CHANGED));
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        mSettingsObserver.unobserve();
        mContext.unregisterReceiver(mExternalKeyguardViewChangedReceiver);
    }

    @Override
@@ -1218,6 +1225,26 @@ public class NotificationPanelView extends PanelView implements
        }
    };

    private BroadcastReceiver mExternalKeyguardViewChangedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String pkgName = getSendingPackage(intent);
            if (pkgName != null) {
                PackageManager pm = context.getPackageManager();
                if (pm.checkPermission(android.Manifest.permission.ACCESS_KEYGUARD_SECURE_STORAGE,
                        pkgName) != PackageManager.PERMISSION_GRANTED) {
                    // we should not be here if the sending app does not have the proper permission,
                    // so do nothing and return.
                    return;
                }
            } else {
                // null package name?  something is not right so just return and skip doing anything
                return;
            }
            updateExternalKeyguardView();
        }
    };

    private void animateHeaderSlidingIn() {
        // If the QS is already expanded we don't need to slide in the header as it's already
        // visible.
@@ -2639,4 +2666,29 @@ public class NotificationPanelView extends PanelView implements
        }
        return null;
    }

    private void updateExternalKeyguardView() {
        ComponentName cn = mLockPatternUtils.getThirdPartyKeyguardComponent();
        // If mThirdPartyKeyguardViewComponent differs from cn, go ahead and update
        if ((cn == null && mThirdPartyKeyguardViewComponent != null) ||
                (cn != null && mThirdPartyKeyguardViewComponent == null) ||
                !mThirdPartyKeyguardViewComponent.equals(cn)) {
            mThirdPartyKeyguardViewComponent = cn;
            if (mKeyguardExternalView != null) {
                if (indexOfChild(mKeyguardExternalView) >= 0) {
                    removeView(mKeyguardExternalView);
                }
                mKeyguardExternalView.unregisterKeyguardExternalViewCallback(
                        mExternalKeyguardViewCallbacks);
                if (mThirdPartyKeyguardViewComponent != null) {
                    mKeyguardExternalView =
                            getExternalKeyguardView(mThirdPartyKeyguardViewComponent);
                    mKeyguardExternalView.registerKeyguardExternalViewCallback(
                            mExternalKeyguardViewCallbacks);
                } else {
                    mKeyguardExternalView = null;
                }
            }
        }
    }
}