method public void onStopListening();
method public void onTileAdded();
method public void onTileRemoved();
+ method public final void showDialog(android.app.Dialog);
field public static final java.lang.String ACTION_QS_TILE = "android.service.quicksettings.action.QS_TILE";
}
method public void onStopListening();
method public void onTileAdded();
method public void onTileRemoved();
+ method public final void showDialog(android.app.Dialog);
field public static final java.lang.String ACTION_QS_TILE = "android.service.quicksettings.action.QS_TILE";
}
method public void onStopListening();
method public void onTileAdded();
method public void onTileRemoved();
+ method public final void showDialog(android.app.Dialog);
field public static final java.lang.String ACTION_QS_TILE = "android.service.quicksettings.action.QS_TILE";
}
*/
interface IQSService {
void updateQsTile(in Tile tile);
+ void onShowDialog(in Tile tile);
}
void onTileRemoved();
void onStartListening();
void onStopListening();
- void onClick();
+ void onClick(IBinder wtoken);
}
}
}
+ /**
+ * @hide
+ * Notifies the IQSService that this tile is showing a dialog.
+ */
+ void onShowDialog() {
+ try {
+ mService.onShowDialog(this);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Couldn't onShowDialog");
+ }
+ }
+
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeStrongInterface(mService);
*/
package android.service.quicksettings;
+import android.app.Dialog;
import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
+import android.view.WindowManager;
/**
* A QSTileService provides the user a tile that can be added to Quick Settings.
* android:icon="@drawable/my_default_icon_label"
* android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
* <intent-filter>
- * <action android:name="android.intent.action.QS_TILE" />
+ * <action android:name="android.service.quicksettings.action.QS_TILE" />
* </intent-filter>
* </service>}
* </pre>
private boolean mListening = false;
private Tile mTile;
+ private IBinder mToken;
/**
* Called when the user adds this tile to Quick Settings.
}
/**
+ * Used to show a dialog.
+ *
+ * This will collapse the Quick Settings panel and show the dialog.
+ *
+ * @param dialog Dialog to show.
+ */
+ public final void showDialog(Dialog dialog) {
+ dialog.getWindow().getAttributes().token = mToken;
+ dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_QS_DIALOG);
+ dialog.show();
+ getQsTile().onShowDialog();
+ }
+
+ /**
* Gets the {@link Tile} for this service.
* <p/>
* This tile may be used to get or set the current state for this
}
@Override
- public void onClick() throws RemoteException {
- mHandler.sendEmptyMessage(H.MSG_TILE_CLICKED);
+ public void onClick(IBinder wtoken) throws RemoteException {
+ mHandler.obtainMessage(H.MSG_TILE_CLICKED, wtoken).sendToTarget();
}
};
}
case MSG_TILE_REMOVED:
TileService.this.onTileAdded();
break;
- case MSG_START_LISTENING:
+ case MSG_STOP_LISTENING:
if (mListening) {
mListening = false;
TileService.this.onStopListening();
}
break;
- case MSG_STOP_LISTENING:
+ case MSG_START_LISTENING:
if (!mListening) {
mListening = true;
TileService.this.onStartListening();
}
break;
case MSG_TILE_CLICKED:
+ mToken = (IBinder) msg.obj;
TileService.this.onClick();
break;
}
@ViewDebug.IntToString(from = TYPE_VOICE_INTERACTION, to = "TYPE_VOICE_INTERACTION"),
@ViewDebug.IntToString(from = TYPE_VOICE_INTERACTION_STARTING, to = "TYPE_VOICE_INTERACTION_STARTING"),
@ViewDebug.IntToString(from = TYPE_DOCK_DIVIDER, to = "TYPE_DOCK_DIVIDER"),
+ @ViewDebug.IntToString(from = TYPE_QS_DIALOG, to = "TYPE_QS_DIALOG"),
})
public int type;
public static final int TYPE_DOCK_DIVIDER = FIRST_SYSTEM_WINDOW+34;
/**
+ * Window type: like {@link #TYPE_APPLICATION_ATTACHED_DIALOG}, but used
+ * by Quick Settings Tiles.
+ * @hide
+ */
+ public static final int TYPE_QS_DIALOG = FIRST_SYSTEM_WINDOW+35;
+
+ /**
* End of types of system windows.
*/
public static final int LAST_SYSTEM_WINDOW = 2999;
}
@Override
- public void onClick() {
+ public void onClick(IBinder token) {
try {
- mService.onClick();
+ mService.onClick(token);
} catch (Exception e) {
Log.d(TAG, "Caught exception from QSTileService", e);
}
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.graphics.drawable.Drawable;
+import android.os.Binder;
import android.os.IBinder;
+import android.os.RemoteException;
import android.os.UserHandle;
import android.service.quicksettings.IQSTileService;
import android.service.quicksettings.Tile;
import android.util.Log;
-
+import android.view.IWindowManager;
+import android.view.WindowManager;
+import android.view.WindowManagerGlobal;
import com.android.internal.logging.MetricsLogger;
import com.android.systemui.qs.QSTile;
import com.android.systemui.qs.QSTileServiceWrapper;
public class CustomTile extends QSTile<QSTile.State> {
public static final String PREFIX = "custom(";
+ private static final boolean DEBUG = false;
+
// We don't want to thrash binding and unbinding if the user opens and closes the panel a lot.
// So instead we have a period of waiting.
private static final long UNBIND_DELAY = 30000;
private final ComponentName mComponent;
private final Tile mTile;
+ private final IWindowManager mWindowManager;
+ private final IBinder mToken = new Binder();
private QSTileServiceWrapper mService;
private boolean mListening;
private boolean mBound;
+ private boolean mIsTokenGranted;
+ private boolean mIsShowingDialog;
private CustomTile(QSTileHost host, String action) {
super(host);
+ mWindowManager = WindowManagerGlobal.getWindowManagerService();
mComponent = ComponentName.unflattenFromString(action);
mTile = new Tile(mComponent, host);
try {
}
public void updateState(Tile tile) {
- Log.d("TileService", "Setting state " + tile.getLabel());
mTile.setIcon(tile.getIcon());
mTile.setLabel(tile.getLabel());
mTile.setContentDescription(tile.getContentDescription());
}
+ public void onDialogShown() {
+ mIsShowingDialog = true;
+ }
+
@Override
public void setListening(boolean listening) {
if (mListening == listening) return;
if (mService!= null) {
mService.onStopListening();
}
+ if (mIsTokenGranted && !mIsShowingDialog) {
+ try {
+ if (DEBUG) Log.d(TAG, "Removing token");
+ mWindowManager.removeWindowToken(mToken);
+ } catch (RemoteException e) {
+ }
+ mIsTokenGranted = false;
+ }
+ mIsShowingDialog = false;
mHandler.postDelayed(mUnbind, UNBIND_DELAY);
}
}
-
+
@Override
protected void handleDestroy() {
super.handleDestroy();
mHandler.removeCallbacks(mUnbind);
+ if (mIsTokenGranted) {
+ try {
+ if (DEBUG) Log.d(TAG, "Removing token");
+ mWindowManager.removeWindowToken(mToken);
+ } catch (RemoteException e) {
+ }
+ }
mUnbind.run();
}
@Override
protected void handleClick() {
if (mService != null) {
- mService.onClick();
+ try {
+ if (DEBUG) Log.d(TAG, "Adding token");
+ mWindowManager.addWindowToken(mToken, WindowManager.LayoutParams.TYPE_QS_DIALOG);
+ mIsTokenGranted = true;
+ } catch (RemoteException e) {
+ }
+ mService.onClick(mToken);
} else {
Log.e(TAG, "Click with no service " + getTileSpec());
}
verifyCaller(tile.getComponentName().getPackageName());
CustomTile customTile = getTileForComponent(tile.getComponentName());
if (customTile != null) {
- Log.d("TileService", "Got tile update for " + tile.getComponentName());
customTile.updateState(tile);
customTile.refreshState();
}
}
+ @Override
+ public void onShowDialog(Tile tile) throws RemoteException {
+ verifyCaller(tile.getComponentName().getPackageName());
+ CustomTile customTile = getTileForComponent(tile.getComponentName());
+ if (customTile != null) {
+ customTile.onDialogShown();
+ collapsePanels();
+ }
+ }
+
private void verifyCaller(String packageName) {
try {
int uid = mContext.getPackageManager().getPackageUid(packageName,
import android.view.KeyCharacterMap.FallbackAction;
import android.view.KeyEvent;
import android.view.MotionEvent;
-
-import com.android.internal.logging.MetricsLogger;
-import com.android.internal.policy.PhoneWindow;
import android.view.Surface;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import com.android.internal.R;
+import com.android.internal.logging.MetricsLogger;
+import com.android.internal.policy.PhoneWindow;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.util.ScreenShapeHelper;
import com.android.internal.widget.PointerLocationView;
case TYPE_PRIVATE_PRESENTATION:
case TYPE_VOICE_INTERACTION:
case TYPE_ACCESSIBILITY_OVERLAY:
+ case TYPE_QS_DIALOG:
// The window manager will check these.
break;
case TYPE_PHONE:
return 2;
case TYPE_DOCK_DIVIDER:
return 2;
+ case TYPE_QS_DIALOG:
+ return 2;
case TYPE_PHONE:
return 3;
case TYPE_SEARCH_BAR:
case WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG:
case WindowManager.LayoutParams.TYPE_SYSTEM_ERROR:
case WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY:
+ case WindowManager.LayoutParams.TYPE_QS_DIALOG:
case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL: {
Rect magnifiedRegionBounds = mTempRect2;
mMagnifedViewport.getMagnifiedFrameInContentCoordsLocked(
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION;
+import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG;
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION;
import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
+ attrs.token + ". Aborting.");
return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
}
+ if (type == TYPE_QS_DIALOG) {
+ Slog.w(TAG, "Attempted to add QS dialog window with unknown token "
+ + attrs.token + ". Aborting.");
+ return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
+ }
if (type == TYPE_ACCESSIBILITY_OVERLAY) {
Slog.w(TAG, "Attempted to add Accessibility overlay window with unknown token "
+ attrs.token + ". Aborting.");