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

Commit 64348d10 authored by Lucas Dupin's avatar Lucas Dupin Committed by Android (Google) Code Review
Browse files

Merge "Avoid binder call when binding Slice"

parents eaff01c0 a0d5119c
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Trace;
import android.provider.Settings;
import android.text.Layout;
import android.text.TextUtils;
@@ -148,6 +149,7 @@ public class KeyguardSliceView extends LinearLayout implements View.OnClickListe
    }

    private void showSlice() {
        Trace.beginSection("KeyguardSliceView#showSlice");
        if (mPulsing || mSlice == null) {
            mTitle.setVisibility(GONE);
            mRow.setVisibility(GONE);
@@ -236,6 +238,7 @@ public class KeyguardSliceView extends LinearLayout implements View.OnClickListe
        if (mContentChangeListener != null) {
            mContentChangeListener.run();
        }
        Trace.endSection();
    }

    public void setPulsing(boolean pulsing, boolean animate) {
@@ -383,8 +386,23 @@ public class KeyguardSliceView extends LinearLayout implements View.OnClickListe
    }

    public void refresh() {
        Slice slice = SliceViewManager.getInstance(getContext()).bindSlice(mKeyguardSliceUri);
        Slice slice;
        Trace.beginSection("KeyguardSliceView#refresh");
        // We can optimize performance and avoid binder calls when we know that we're bound
        // to a Slice on the same process.
        if (KeyguardSliceProvider.KEYGUARD_SLICE_URI.equals(mKeyguardSliceUri.toString())) {
            KeyguardSliceProvider instance = KeyguardSliceProvider.getAttachedInstance();
            if (instance != null) {
                slice = instance.onBindSlice(mKeyguardSliceUri);
            } else {
                Log.w(TAG, "Keyguard slice not bound yet?");
                slice = null;
            }
        } else {
            slice = SliceViewManager.getInstance(getContext()).bindSlice(mKeyguardSliceUri);
        }
        onChanged(slice);
        Trace.endSection();
    }

    public static class Row extends LinearLayout {
+15 −5
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.icu.text.DateFormat;
import android.icu.text.DisplayContext;
import android.net.Uri;
import android.os.Handler;
import android.os.Trace;
import android.provider.Settings;
import android.service.notification.ZenModeConfig;
import android.text.TextUtils;
@@ -72,6 +73,8 @@ public class KeyguardSliceProvider extends SliceProvider implements
    @VisibleForTesting
    static final int ALARM_VISIBILITY_HOURS = 12;

    private static KeyguardSliceProvider sInstance;

    protected final Uri mSliceUri;
    protected final Uri mDateUri;
    protected final Uri mAlarmUri;
@@ -89,6 +92,7 @@ public class KeyguardSliceProvider extends SliceProvider implements
    protected AlarmManager mAlarmManager;
    protected ContentResolver mContentResolver;
    private AlarmManager.AlarmClockInfo mNextAlarmInfo;
    private PendingIntent mPendingIntent;

    /**
     * Receiver responsible for time ticking and updating the date format.
@@ -117,6 +121,10 @@ public class KeyguardSliceProvider extends SliceProvider implements
        this(new Handler());
    }

    public static KeyguardSliceProvider getAttachedInstance() {
        return KeyguardSliceProvider.sInstance;
    }

    @VisibleForTesting
    KeyguardSliceProvider(Handler handler) {
        mHandler = handler;
@@ -128,23 +136,24 @@ public class KeyguardSliceProvider extends SliceProvider implements

    @Override
    public Slice onBindSlice(Uri sliceUri) {
        Trace.beginSection("KeyguardSliceProvider#onBindSlice");
        ListBuilder builder = new ListBuilder(getContext(), mSliceUri, ListBuilder.INFINITY);
        builder.addRow(new RowBuilder(mDateUri).setTitle(mLastText));
        addNextAlarm(builder);
        addZenMode(builder);
        addPrimaryAction(builder);
        return builder.build();
        Slice slice = builder.build();
        Trace.endSection();
        return slice;
    }

    protected void addPrimaryAction(ListBuilder builder) {
        // Add simple action because API requires it; Keyguard handles presenting
        // its own slices so this action + icon are actually never used.
        PendingIntent pi = PendingIntent.getActivity(getContext(), 0, new Intent(), 0);
        IconCompat icon = IconCompat.createWithResource(getContext(),
                R.drawable.ic_access_alarms_big);
        SliceAction action = SliceAction.createDeeplink(pi, icon,
        SliceAction action = SliceAction.createDeeplink(mPendingIntent, icon,
                ListBuilder.ICON_IMAGE, mLastText);

        RowBuilder primaryActionRow = new RowBuilder(Uri.parse(KEYGUARD_ACTION_URI))
                .setPrimaryAction(action);
        builder.addRow(primaryActionRow);
@@ -154,7 +163,6 @@ public class KeyguardSliceProvider extends SliceProvider implements
        if (TextUtils.isEmpty(mNextAlarm)) {
            return;
        }

        IconCompat alarmIcon = IconCompat.createWithResource(getContext(),
                R.drawable.ic_access_alarms_big);
        RowBuilder alarmRowBuilder = new RowBuilder(mAlarmUri)
@@ -198,6 +206,8 @@ public class KeyguardSliceProvider extends SliceProvider implements
        mZenModeController = new ZenModeControllerImpl(getContext(), mHandler);
        mZenModeController.addCallback(this);
        mDatePattern = getContext().getString(R.string.system_ui_aod_date_pattern);
        mPendingIntent = PendingIntent.getActivity(getContext(), 0, new Intent(), 0);
        KeyguardSliceProvider.sInstance = this;
        registerClockUpdate();
        updateClock();
        return true;