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

Commit c66f16ec authored by Joe Onorato's avatar Joe Onorato Committed by Android (Google) Code Review
Browse files

Merge "Connect my plumbing to dsandler's awesome lights out mode."

parents e4e0a4bc f63b0f44
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -43,4 +43,5 @@ interface IStatusBarService
            int uid, int initialPid, String message);
    void onClearAllNotifications();
    void onNotificationClear(String pkg, String tag, int id);
    void setLightsOn(boolean on);
}
+0 −1
Original line number Diff line number Diff line
@@ -159,7 +159,6 @@
        android:layout_height="match_parent"
        android:visibility="invisible"
        android:clickable="true"
        android:onClick="toggleLightsOut"
        />
</FrameLayout>
+43 −30
Original line number Diff line number Diff line
@@ -150,15 +150,12 @@ public class TabletStatusBarService extends StatusBarService {
        mBarContents = sb.findViewById(R.id.bar_contents);
        mCurtains = sb.findViewById(R.id.lights_out);
        View systemInfo = sb.findViewById(R.id.systemInfo);
        View.OnLongClickListener toggle = new View.OnLongClickListener() {
            public boolean onLongClick(View v) {
                toggleLightsOut(v);
                return true;
            }
        };

        systemInfo.setOnLongClickListener(toggle);
        mCurtains.setOnLongClickListener(toggle);
        systemInfo.setOnLongClickListener(new SetLightsOnListener(false));

        SetLightsOnListener on = new SetLightsOnListener(true);
        mCurtains.setOnClickListener(on);
        mCurtains.setOnLongClickListener(on);

        // the more notifications icon
        mNotificationIconArea = (NotificationIconArea)sb.findViewById(R.id.notificationIcons);
@@ -492,11 +489,22 @@ public class TabletStatusBarService extends StatusBarService {
    }

    public void setLightsOn(boolean on) {
        //Slog.d(TAG, "setLightsOn on=" + on);
        if (!on) {
        if (on) {
            mCurtains.setAnimation(AnimationUtils.loadAnimation((Context)this,
                        R.anim.lights_out_out));
            mCurtains.setVisibility(View.GONE);
            mBarContents.setAnimation(AnimationUtils.loadAnimation((Context)this,
                        R.anim.status_bar_in));
            mBarContents.setVisibility(View.VISIBLE);
        } else {
            animateCollapse();
            mCurtains.setAnimation(AnimationUtils.loadAnimation((Context)this,
                        R.anim.lights_out_in));
            mCurtains.setVisibility(View.VISIBLE);
            mBarContents.setAnimation(AnimationUtils.loadAnimation((Context)this,
                        R.anim.status_bar_out));
            mBarContents.setVisibility(View.GONE);
        }
        // TODO: implement lights out mode
    }

    public void notificationIconsClicked(View v) {
@@ -738,26 +746,31 @@ public class TabletStatusBarService extends StatusBarService {
        return true;
    }

    protected void setLightsOut(boolean out) {
        if (out) {
            mCurtains.setAnimation(AnimationUtils.loadAnimation((Context)this,
                        R.anim.lights_out_in));
            mCurtains.setVisibility(View.VISIBLE);
            mBarContents.setAnimation(AnimationUtils.loadAnimation((Context)this,
                        R.anim.status_bar_out));
            mBarContents.setVisibility(View.GONE);
        } else {
            mCurtains.setAnimation(AnimationUtils.loadAnimation((Context)this,
                        R.anim.lights_out_out));
            mCurtains.setVisibility(View.GONE);
            mBarContents.setAnimation(AnimationUtils.loadAnimation((Context)this,
                        R.anim.status_bar_in));
            mBarContents.setVisibility(View.VISIBLE);
    public class SetLightsOnListener implements View.OnLongClickListener,
           View.OnClickListener {
        private boolean mOn;

        SetLightsOnListener(boolean on) {
            mOn = on;
        }

        public void onClick(View v) {
            try {
                mBarService.setLightsOn(mOn);
            } catch (RemoteException ex) {
                // system process
            }
        }

        public boolean onLongClick(View v) {
            try {
                mBarService.setLightsOn(mOn);
            } catch (RemoteException ex) {
                // system process
            }
            return true;
        }

    public void toggleLightsOut(View v) {
        setLightsOut(mCurtains.getVisibility() != View.VISIBLE);
    }
}

+38 −12
Original line number Diff line number Diff line
@@ -246,14 +246,41 @@ public class StatusBarManagerService extends IStatusBarService.Stub
        }
    }

    /**
     * This is used for the automatic version of lights-out mode.  Only call this from
     * the window manager.
     *
     * @see setLightsOn(boolean)
     */
    public void setActiveWindowIsFullscreen(boolean fullscreen) {
        // We could get away with a separate permission here, but STATUS_BAR is
        // signatureOrSystem which is probably good enough.  There is no public API
        // for this, so the question is a security issue, not an API compatibility issue.
        enforceStatusBar();

        final boolean lightsOn = !fullscreen;
        synchronized (mLock) {
            updateLightsOnLocked(!fullscreen);
        }
    }

    /**
     * This is used for the user-controlled version of lights-out mode.  Only call this from
     * the status bar itself.
     *
     * We have two different functions here, because I think we're going to want to
     * tweak the behavior when the user keeps turning lights-out mode off and the
     * app keeps trying to turn it on.  For now they can just fight it out.  Having
     * these two separte inputs will allow us to keep that change local to here.  --joeo
     */
    public void setLightsOn(boolean lightsOn) {
        enforceStatusBarService();

        synchronized (mLock) {
            updateLightsOnLocked(lightsOn);
        }
    }

    private void updateLightsOnLocked(final boolean lightsOn) {
        if (mLightsOn != lightsOn) {
            mLightsOn = lightsOn;
            mHandler.post(new Runnable() {
@@ -268,7 +295,6 @@ public class StatusBarManagerService extends IStatusBarService.Stub
                });
        }
    }
    }

    private void enforceStatusBar() {
        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,