diff --git a/core/java/android/service/quicksettings/IQSService.aidl b/core/java/android/service/quicksettings/IQSService.aidl index d03ff93be5cee..7b690eaad96c1 100644 --- a/core/java/android/service/quicksettings/IQSService.aidl +++ b/core/java/android/service/quicksettings/IQSService.aidl @@ -15,6 +15,7 @@ */ package android.service.quicksettings; +import android.app.PendingIntent; import android.content.ComponentName; import android.graphics.drawable.Icon; import android.service.quicksettings.Tile; @@ -29,10 +30,10 @@ interface IQSService { String contentDescription); void onShowDialog(in IBinder tile); void onStartActivity(in IBinder tile); + void startActivity(in IBinder tile, in PendingIntent pendingIntent); boolean isLocked(); boolean isSecure(); void startUnlockAndRun(in IBinder tile); - void onDialogHidden(in IBinder tile); void onStartSuccessful(in IBinder tile); } diff --git a/core/java/android/service/quicksettings/Tile.java b/core/java/android/service/quicksettings/Tile.java index 40c0ac00a5a9a..d60b225e695ab 100644 --- a/core/java/android/service/quicksettings/Tile.java +++ b/core/java/android/service/quicksettings/Tile.java @@ -16,6 +16,7 @@ package android.service.quicksettings; import android.annotation.Nullable; +import android.app.PendingIntent; import android.graphics.drawable.Icon; import android.os.IBinder; import android.os.Parcel; @@ -66,6 +67,7 @@ public final class Tile implements Parcelable { private CharSequence mSubtitle; private CharSequence mContentDescription; private CharSequence mStateDescription; + private PendingIntent mPendingIntent; // Default to inactive until clients of the new API can update. private int mState = STATE_INACTIVE; @@ -223,6 +225,34 @@ public final class Tile implements Parcelable { } } + /** + * Gets the Activity {@link PendingIntent} to be launched when the tile is clicked. + * @hide + */ + @Nullable + public PendingIntent getActivityLaunchForClick() { + return mPendingIntent; + } + + /** + * Sets an Activity {@link PendingIntent} to be launched when the tile is clicked. + * + * The last value set here will be launched when the user clicks in the tile, instead of + * forwarding the `onClick` message to the {@link TileService}. Set to {@code null} to handle + * the `onClick` in the `TileService` + * (This is the default behavior if this method is never called.) + * @param pendingIntent a PendingIntent for an activity to be launched onclick, or {@code null} + * to handle the clicks in the `TileService`. + * @hide + */ + public void setActivityLaunchForClick(@Nullable PendingIntent pendingIntent) { + if (pendingIntent != null && !pendingIntent.isActivity()) { + throw new IllegalArgumentException(); + } else { + mPendingIntent = pendingIntent; + } + } + @Override public void writeToParcel(Parcel dest, int flags) { if (mIcon != null) { @@ -231,6 +261,12 @@ public final class Tile implements Parcelable { } else { dest.writeByte((byte) 0); } + if (mPendingIntent != null) { + dest.writeByte((byte) 1); + mPendingIntent.writeToParcel(dest, flags); + } else { + dest.writeByte((byte) 0); + } dest.writeInt(mState); TextUtils.writeToParcel(mLabel, dest, flags); TextUtils.writeToParcel(mSubtitle, dest, flags); @@ -244,6 +280,11 @@ public final class Tile implements Parcelable { } else { mIcon = null; } + if (source.readByte() != 0) { + mPendingIntent = PendingIntent.CREATOR.createFromParcel(source); + } else { + mPendingIntent = null; + } mState = source.readInt(); mLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); mSubtitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); diff --git a/core/java/android/service/quicksettings/TileService.java b/core/java/android/service/quicksettings/TileService.java index 85502197ea7ed..506b3b81eb9ad 100644 --- a/core/java/android/service/quicksettings/TileService.java +++ b/core/java/android/service/quicksettings/TileService.java @@ -20,6 +20,7 @@ import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SystemApi; import android.annotation.TestApi; import android.app.Dialog; +import android.app.PendingIntent; import android.app.Service; import android.app.StatusBarManager; import android.content.ComponentName; @@ -335,6 +336,20 @@ public class TileService extends Service { } } + /** + * Starts an {@link android.app.Activity}. + * Will collapse Quick Settings after launching. + * + * @param pendingIntent A PendingIntent for an Activity to be launched immediately. + * @hide + */ + public void startActivityAndCollapse(PendingIntent pendingIntent) { + try { + mService.startActivity(mTileToken, pendingIntent); + } catch (RemoteException e) { + } + } + /** * Gets the {@link Tile} for this service. *
diff --git a/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java b/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java index c4386ab9a3df1..cfda9fd6cb964 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java @@ -18,6 +18,7 @@ package com.android.systemui.qs.external; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG; +import android.app.PendingIntent; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -51,6 +52,7 @@ import androidx.annotation.WorkerThread; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; +import com.android.systemui.animation.ActivityLaunchAnimator; import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.plugins.ActivityStarter; @@ -92,6 +94,8 @@ public class CustomTile extends QSTileImpl
* It will return {@code true} before initialization, so tiles are not destroyed prematurely.
*/
@Override
@@ -262,6 +266,7 @@ public class CustomTile extends QSTileImpl