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

Commit b030476d authored by Jim Miller's avatar Jim Miller
Browse files

Fix 6021938: Improved target support in lock screen

This adds the ability to enable or disable target icons based on the drawable
resource of the target.

It also fixes a bug where we'd show the camera while displaying
the PIN/PUK unlock screen or when it's disabled by DevicePolicyAdmin.

Minor simplification and cleanup KeyguardUpdateMonitor callbacks.

Change-Id: I33fad56a2203bc8b7bcd0300c20478711a56713a
parent 5571ffdd
Loading
Loading
Loading
Loading
+40 −8
Original line number Diff line number Diff line
@@ -164,9 +164,10 @@ public class MultiWaveView extends View {
        mFeedbackCount = a.getInt(R.styleable.MultiWaveView_feedbackCount,
                mFeedbackCount);
        mHandleDrawable = new TargetDrawable(res,
                a.getDrawable(R.styleable.MultiWaveView_handleDrawable));
                a.peekValue(R.styleable.MultiWaveView_handleDrawable).resourceId);
        mTapRadius = mHandleDrawable.getWidth()/2;
        mOuterRing = new TargetDrawable(res, a.getDrawable(R.styleable.MultiWaveView_waveDrawable));
        mOuterRing = new TargetDrawable(res,
                a.peekValue(R.styleable.MultiWaveView_waveDrawable).resourceId);

        // Read chevron animation drawables
        final int chevrons[] = { R.styleable.MultiWaveView_leftChevronDrawable,
@@ -174,11 +175,12 @@ public class MultiWaveView extends View {
                R.styleable.MultiWaveView_topChevronDrawable,
                R.styleable.MultiWaveView_bottomChevronDrawable
        };

        for (int chevron : chevrons) {
            Drawable chevronDrawable = a.getDrawable(chevron);
            TypedValue typedValue = a.peekValue(chevron);
            for (int i = 0; i < mFeedbackCount; i++) {
                mChevronDrawables.add(
                    chevronDrawable != null ? new TargetDrawable(res, chevronDrawable) : null);
                    typedValue != null ? new TargetDrawable(res, typedValue.resourceId) : null);
            }
        }

@@ -519,8 +521,8 @@ public class MultiWaveView extends View {
        int count = array.length();
        ArrayList<TargetDrawable> targetDrawables = new ArrayList<TargetDrawable>(count);
        for (int i = 0; i < count; i++) {
            Drawable drawable = array.getDrawable(i);
            targetDrawables.add(new TargetDrawable(res, drawable));
            TypedValue value = array.peekValue(i);
            targetDrawables.add(new TargetDrawable(res, value != null ? value.resourceId : 0));
        }
        array.recycle();
        mTargetResourceId = resourceId;
@@ -723,7 +725,7 @@ public class MultiWaveView extends View {
                    float dx = limitX - target.getX();
                    float dy = limitY - target.getY();
                    float dist2 = dx*dx + dy*dy;
                    if (target.isValid() && dist2 < hitRadius2 && dist2 < best) {
                    if (target.isEnabled() && dist2 < hitRadius2 && dist2 < best) {
                        activeTarget = i;
                        best = dist2;
                    }
@@ -968,4 +970,34 @@ public class MultiWaveView extends View {
        array.recycle();
        return targetContentDescriptions;
    }

    public int getResourceIdForTarget(int index) {
        final TargetDrawable drawable = mTargetDrawables.get(index);
        return drawable == null ? 0 : drawable.getResourceId();
    }

    public void setEnableTarget(int resourceId, boolean enabled) {
        for (int i = 0; i < mTargetDrawables.size(); i++) {
            final TargetDrawable target = mTargetDrawables.get(i);
            if (target.getResourceId() == resourceId) {
                target.setEnabled(enabled);
                break; // should never be more than one match
            }
        }
    }

    /**
     * Gets the position of a target in the array that matches the given resource.
     * @param resourceId
     * @return the index or -1 if not found
     */
    public int getTargetPosition(int resourceId) {
        for (int i = 0; i < mTargetDrawables.size(); i++) {
            final TargetDrawable target = mTargetDrawables.get(i);
            if (target.getResourceId() == resourceId) {
                return i; // should never be more than one match
            }
        }
        return -1;
    }
}
+15 −7
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ public class TargetDrawable {
    private float mScaleY = 1.0f;
    private float mAlpha = 1.0f;
    private Drawable mDrawable;
    private boolean mEnabled = true;
    private int mResourceId;

    /* package */ static class DrawableWithAlpha extends Drawable {
        private float mAlpha = 1.0f;
@@ -72,10 +74,8 @@ public class TargetDrawable {
    }

    public TargetDrawable(Resources res, int resId) {
        this(res, resId == 0 ? null : res.getDrawable(resId));
    }

    public TargetDrawable(Resources res, Drawable drawable) {
        mResourceId = resId;
        Drawable drawable = resId == 0 ? null : res.getDrawable(resId);
        // Mutate the drawable so we can animate shared drawable properties.
        mDrawable = drawable != null ? drawable.mutate() : null;
        resizeDrawables();
@@ -122,8 +122,8 @@ public class TargetDrawable {
     *
     * @return
     */
    public boolean isValid() {
        return mDrawable != null;
    public boolean isEnabled() {
        return mDrawable != null && mEnabled;
    }

    /**
@@ -205,7 +205,7 @@ public class TargetDrawable {
    }

    public void draw(Canvas canvas) {
        if (mDrawable == null) {
        if (mDrawable == null || !mEnabled) {
            return;
        }
        canvas.save(Canvas.MATRIX_SAVE_FLAG);
@@ -216,4 +216,12 @@ public class TargetDrawable {
        mDrawable.draw(canvas);
        canvas.restore();
    }

    public void setEnabled(boolean enabled) {
        mEnabled  = enabled;
    }

    public int getResourceId() {
        return mResourceId;
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -974,6 +974,9 @@
  <java-symbol type="drawable" name="unlock_halo" />
  <java-symbol type="drawable" name="unlock_ring" />
  <java-symbol type="drawable" name="unlock_wave" />
  <java-symbol type="drawable" name="ic_lockscreen_camera" />
  <java-symbol type="drawable" name="ic_lockscreen_silent" />
  <java-symbol type="drawable" name="ic_lockscreen_unlock" />

  <java-symbol type="layout" name="action_bar_home" />
  <java-symbol type="layout" name="action_bar_title_item" />
+6 −14
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.internal.telephony.IccCard.State;
import com.android.internal.widget.DigitalClock;
import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.TransportControlView;
import com.android.internal.policy.impl.KeyguardUpdateMonitor.InfoCallbackImpl;
import com.android.internal.policy.impl.KeyguardUpdateMonitor.SimStateCallback;

import java.util.ArrayList;
@@ -625,9 +626,9 @@ class KeyguardStatusViewManager implements OnClickListener {
        }
    }

    private KeyguardUpdateMonitor.InfoCallback mInfoCallback
            = new KeyguardUpdateMonitor.InfoCallback() {
    private InfoCallbackImpl mInfoCallback = new InfoCallbackImpl() {

        @Override
        public void onRefreshBatteryInfo(boolean showBatteryInfo, boolean pluggedIn,
                int batteryLevel) {
            mShowingBatteryInfo = showBatteryInfo;
@@ -637,33 +638,24 @@ class KeyguardStatusViewManager implements OnClickListener {
            update(BATTERY_INFO, getAltTextMessage(tmpIcon));
        }

        @Override
        public void onTimeChanged() {
            refreshDate();
        }

        @Override
        public void onRefreshCarrierInfo(CharSequence plmn, CharSequence spn) {
            mPlmn = plmn;
            mSpn = spn;
            updateCarrierStateWithSimStatus(mSimState);
        }

        public void onRingerModeChanged(int state) {

        }

        @Override
        public void onPhoneStateChanged(int phoneState) {
            mPhoneState = phoneState;
            updateEmergencyCallButtonState(phoneState);
        }

        /** {@inheritDoc} */
        public void onClockVisibilityChanged() {
            // ignored
        }

        public void onDeviceProvisioned() {
            // ignored
        }
    };

    private SimStateCallback mSimStateCallback = new SimStateCallback() {
+55 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.policy.impl;

import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -103,6 +104,7 @@ public class KeyguardUpdateMonitor {
    private static final int MSG_PHONE_STATE_CHANGED = 306;
    private static final int MSG_CLOCK_VISIBILITY_CHANGED = 307;
    private static final int MSG_DEVICE_PROVISIONED = 308;
    protected static final int MSG_DPM_STATE_CHANGED = 309;

    /**
     * When we receive a
@@ -204,6 +206,9 @@ public class KeyguardUpdateMonitor {
                    case MSG_DEVICE_PROVISIONED:
                        handleDeviceProvisioned();
                        break;
                    case MSG_DPM_STATE_CHANGED:
                        handleDevicePolicyManagerStateChanged();
                        break;
                }
            }
        };
@@ -262,6 +267,7 @@ public class KeyguardUpdateMonitor {
        filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
        filter.addAction(SPN_STRINGS_UPDATED_ACTION);
        filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
        filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
        context.registerReceiver(new BroadcastReceiver() {

            public void onReceive(Context context, Intent intent) {
@@ -293,11 +299,20 @@ public class KeyguardUpdateMonitor {
                } else if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) {
                    String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
                    mHandler.sendMessage(mHandler.obtainMessage(MSG_PHONE_STATE_CHANGED, state));
                } else if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
                        .equals(action)) {
                    mHandler.sendMessage(mHandler.obtainMessage(MSG_DPM_STATE_CHANGED));
                }
            }
        }, filter);
    }

    protected void handleDevicePolicyManagerStateChanged() {
        for (int i = 0; i < mInfoCallbacks.size(); i++) {
            mInfoCallbacks.get(i).onDevicePolicyManagerStateChanged();
        }
    }

    protected void handleDeviceProvisioned() {
        for (int i = 0; i < mInfoCallbacks.size(); i++) {
            mInfoCallbacks.get(i).onDeviceProvisioned();
@@ -521,6 +536,40 @@ public class KeyguardUpdateMonitor {
         * Called when the device becomes provisioned
         */
        void onDeviceProvisioned();

        /**
         * Called when the device policy changes.
         * See {@link DevicePolicyManager#ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED}
         */
        void onDevicePolicyManagerStateChanged();
    }

    // Simple class that allows methods to easily be overwritten
    public static class InfoCallbackImpl implements InfoCallback {
        public void onRefreshBatteryInfo(boolean showBatteryInfo, boolean pluggedIn,
                int batteryLevel) {
        }

        public void onTimeChanged() {
        }

        public void onRefreshCarrierInfo(CharSequence plmn, CharSequence spn) {
        }

        public void onRingerModeChanged(int state) {
        }

        public void onPhoneStateChanged(int phoneState) {
        }

        public void onClockVisibilityChanged() {
        }

        public void onDeviceProvisioned() {
        }

        public void onDevicePolicyManagerStateChanged() {
        }
    }

    /**
@@ -653,4 +702,10 @@ public class KeyguardUpdateMonitor {
    public boolean getMaxFaceUnlockAttemptsReached() {
        return mFailedFaceUnlockAttempts >= FAILED_FACE_UNLOCK_ATTEMPTS_BEFORE_BACKUP;
    }

    public boolean isSimLocked() {
        return mSimState == IccCard.State.PIN_REQUIRED
            || mSimState == IccCard.State.PUK_REQUIRED
            || mSimState == IccCard.State.PERM_DISABLED;
    }
}
Loading