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

Commit 38328494 authored by DvTonder's avatar DvTonder
Browse files

Framework: Forward port Power widget fixes and fix disabling

This commit fixes the ability to disable/hide the power widget on CM10.1, hide
the widget by default and forward ports a few other related fixes:

Author: Danesh
1) Notification Widgets : Fix vibration
The initial value of the array determines how long till the vibration starts,
and second value determines how long to leave it on till.

Since config_virtualKeyVibePattern is in an overlay and we cannot rely on its consitency,
we check the length of the array, and based on it execute the appropriate vibration.

2) NotificationPowerWidget : Snap widgets
Snap widgets in place, rather than allowing partial widgets

3) Framework Track Control : Switch from broadcast to audio service
Ordered broadcast is unreliable. Switch to using the Audio Service's
dispatchMediaKeyWithWakeLockToAudioService as it sends the event to the correct receiver.

4) AutoRotateButton : Minor cleanup
Use setRotationLock to avoid code duplication and staying consistent with framework

Change-Id: I0b5d1853781a7e6541a4a6283e13f8072d9972b3
parent b085023a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@
            android:layout_width="match_parent"
            android:layout_height="@dimen/notification_panel_widget_height"
            android:layout_marginTop="2dip"
            android:visibility="gone"
        />

        <TextView
+5 −4
Original line number Diff line number Diff line
@@ -512,6 +512,7 @@ public class PhoneStatusBar extends BaseStatusBar {
                    View.STATUS_BAR_DISABLE_CLOCK);
        }

        // Load the Power widget views and set the listeners
        mPowerWidget = (PowerWidget)mStatusBarWindow.findViewById(R.id.exp_power_stat);
        mPowerWidget.setGlobalButtonOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
@@ -529,8 +530,6 @@ public class PhoneStatusBar extends BaseStatusBar {
        });

        mTicker = new MyTicker(context, mStatusBarView);


        TickerView tickerView = (TickerView)mStatusBarView.findViewById(R.id.tickerText);
        tickerView.mTicker = mTicker;

@@ -665,6 +664,7 @@ public class PhoneStatusBar extends BaseStatusBar {
        resetUserSetupObserver();

        mPowerWidget.setupWidget();
        mPowerWidget.updateVisibility();

        return mStatusBarView;
    }
@@ -1514,7 +1514,8 @@ public class PhoneStatusBar extends BaseStatusBar {
        if (mNotificationButtonAnim != null) mNotificationButtonAnim.cancel();
        if (mClearButtonAnim != null) mClearButtonAnim.cancel();

        mPowerWidget.setVisibility(View.VISIBLE);
        // Only show the Power widget if it should be shown
        mPowerWidget.updateVisibility();

        mScrollView.setVisibility(View.VISIBLE);
        mScrollViewAnim = start(
@@ -1663,7 +1664,7 @@ public class PhoneStatusBar extends BaseStatusBar {

            mScrollView.setScaleX(1f);
            mScrollView.setVisibility(View.VISIBLE);
            mPowerWidget.setVisibility(View.VISIBLE);
            mPowerWidget.updateVisibility();
            mSettingsButton.setAlpha(1f);
            mSettingsButton.setVisibility(View.VISIBLE);
            mNotificationPanel.setVisibility(View.GONE);
+5 −27
Original line number Diff line number Diff line
package com.android.systemui.statusbar.powerwidget;

import com.android.systemui.R;

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings;
import android.util.Log;
import android.view.IWindowManager;

import com.android.internal.view.RotationPolicy;
import com.android.systemui.R;

import java.util.ArrayList;
import java.util.List;
@@ -40,7 +36,7 @@ public class AutoRotateButton extends PowerButton {

    @Override
    protected void toggleState(Context context) {
        setAutoRotation(!getAutoRotation(context));
        RotationPolicy.setRotationLock(context, getAutoRotation(context));
    }

    @Override
@@ -58,25 +54,7 @@ public class AutoRotateButton extends PowerButton {
    }

    private boolean getAutoRotation(Context context) {
        ContentResolver cr = context.getContentResolver();
        return Settings.System.getInt(cr, Settings.System.ACCELEROMETER_ROTATION, 0) != 0;
        return !RotationPolicy.isRotationLocked(context);
    }

    private void setAutoRotation(final boolean autorotate) {
        AsyncTask.execute(new Runnable() {
                public void run() {
                    try {
                        IWindowManager wm = IWindowManager.Stub.asInterface(
                                ServiceManager.getService(Context.WINDOW_SERVICE));
                        if (autorotate) {
                            wm.thawRotation();
                        } else {
                            wm.freezeRotation(-1);
                        }
                    } catch (RemoteException exc) {
                        Log.w(TAG, "Unable to save auto-rotate setting");
                    }
                }
            });
    }
}
+30 −13
Original line number Diff line number Diff line
package com.android.systemui.statusbar.powerwidget;

import com.android.systemui.R;

import android.app.ActivityManagerNative;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.media.IAudioService;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;

public abstract class MediaKeyEventButton extends PowerButton {
    private static final String TAG = "MediaKeyEventButton";

    private AudioManager mAM = null;
    private IAudioService mAS = null;

    protected void sendMediaKeyEvent(Context context, int code) {
        long eventtime = SystemClock.uptimeMillis();
        KeyEvent key = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, code, 0);
        dispatchMediaKeyWithWakeLockToAudioService(key);
        dispatchMediaKeyWithWakeLockToAudioService(KeyEvent.changeAction(key, KeyEvent.ACTION_UP));
    }

        Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
        KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, code, 0);
        downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
        context.sendOrderedBroadcast(downIntent, null);
    void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
        if (ActivityManagerNative.isSystemReady()) {
            IAudioService audioService = getAudioService();
            if (audioService != null) {
                try {
                    audioService.dispatchMediaKeyEventUnderWakelock(event);
                } catch (RemoteException e) {
                    Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e);
                }
            }
        }
    }

        Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
        KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, code, 0);
        upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
        context.sendOrderedBroadcast(upIntent, null);
    IAudioService getAudioService() {
        if (mAS == null) {
            mAS = IAudioService.Stub.asInterface(
                    ServiceManager.checkService(Context.AUDIO_SERVICE));
            if (mAS == null) {
                Log.w(TAG, "Unable to find IAudioService interface.");
            }
        }
        return mAS;
    }

    protected AudioManager getAudioManager(Context context) {
+7 −1
Original line number Diff line number Diff line
@@ -143,8 +143,14 @@ public abstract class PowerButton {
    private View.OnClickListener mClickListener = new View.OnClickListener() {
        public void onClick(View v) {
            if (mHapticFeedback && mClickPattern != null) {
                if (mClickPattern.length == 1) {
                    // One-shot vibration
                    mVibrator.vibrate(mClickPattern[0]);
                } else {
                    // Pattern vibration
                    mVibrator.vibrate(mClickPattern, -1);
                }
            }
            toggleState(v.getContext());
            update(v.getContext());

Loading