Merge "Fix QS FBE-ness" into nyc-dev
am: 1ce2abc
* commit '1ce2abcf6d0a34e49a0c5fc5198c9c5a07a022b4':
Fix QS FBE-ness
This commit is contained in:
@@ -34,4 +34,5 @@ interface IQSService {
|
|||||||
void startUnlockAndRun(in Tile tile);
|
void startUnlockAndRun(in Tile tile);
|
||||||
|
|
||||||
void onDialogHidden(in Tile tile);
|
void onDialogHidden(in Tile tile);
|
||||||
|
void onStartSuccessful(in Tile tile);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ public final class Tile implements Parcelable {
|
|||||||
private static final String TAG = "Tile";
|
private static final String TAG = "Tile";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the default state of any tile, until updated by the {@link TileService}.
|
|
||||||
* <p>
|
|
||||||
* An unavailable state indicates that for some reason this tile is not currently
|
* An unavailable state indicates that for some reason this tile is not currently
|
||||||
* available to the user for some reason, and will have no click action. The tile's
|
* available to the user for some reason, and will have no click action. The tile's
|
||||||
* icon will be tinted differently to reflect this state.
|
* icon will be tinted differently to reflect this state.
|
||||||
@@ -57,7 +55,7 @@ public final class Tile implements Parcelable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This represents a tile that is currently active. (e.g. wifi is connected, bluetooth is on,
|
* This represents a tile that is currently active. (e.g. wifi is connected, bluetooth is on,
|
||||||
* cast is casting).
|
* cast is casting). This is the default state.
|
||||||
*/
|
*/
|
||||||
public static final int STATE_ACTIVE = 2;
|
public static final int STATE_ACTIVE = 2;
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ package com.android.systemui.qs.customize;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.os.Handler;
|
||||||
import android.support.v4.view.ViewCompat;
|
import android.support.v4.view.ViewCompat;
|
||||||
import android.support.v7.widget.GridLayoutManager.SpanSizeLookup;
|
import android.support.v7.widget.GridLayoutManager.SpanSizeLookup;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
@@ -51,6 +52,7 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
|
|||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
|
private final Handler mHandler = new Handler();
|
||||||
private final List<TileInfo> mTiles = new ArrayList<>();
|
private final List<TileInfo> mTiles = new ArrayList<>();
|
||||||
private final ItemTouchHelper mItemTouchHelper;
|
private final ItemTouchHelper mItemTouchHelper;
|
||||||
private int mDividerIndex;
|
private int mDividerIndex;
|
||||||
@@ -262,7 +264,12 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
|
|||||||
mCurrentDrag = (Holder) viewHolder;
|
mCurrentDrag = (Holder) viewHolder;
|
||||||
mCurrentDrag.startDrag();
|
mCurrentDrag.startDrag();
|
||||||
}
|
}
|
||||||
notifyItemChanged(mDividerIndex);
|
mHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
notifyItemChanged(mDividerIndex);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -75,7 +75,8 @@ public class CustomTile extends QSTile<QSTile.State> {
|
|||||||
mUser = ActivityManager.getCurrentUser();
|
mUser = ActivityManager.getCurrentUser();
|
||||||
try {
|
try {
|
||||||
PackageManager pm = mContext.getPackageManager();
|
PackageManager pm = mContext.getPackageManager();
|
||||||
ServiceInfo info = pm.getServiceInfo(mComponent, 0);
|
ServiceInfo info = pm.getServiceInfo(mComponent,
|
||||||
|
PackageManager.MATCH_ENCRYPTION_AWARE_AND_UNAWARE);
|
||||||
mTile.setIcon(android.graphics.drawable.Icon
|
mTile.setIcon(android.graphics.drawable.Icon
|
||||||
.createWithResource(mComponent.getPackageName(), info.icon));
|
.createWithResource(mComponent.getPackageName(), info.icon));
|
||||||
mTile.setLabel(info.loadLabel(pm));
|
mTile.setLabel(info.loadLabel(pm));
|
||||||
@@ -88,6 +89,17 @@ public class CustomTile extends QSTile<QSTile.State> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
try {
|
||||||
|
ServiceInfo info = mContext.getPackageManager().getServiceInfo(mComponent,
|
||||||
|
PackageManager.MATCH_ENCRYPTION_AWARE_AND_UNAWARE);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getUser() {
|
public int getUser() {
|
||||||
return mUser;
|
return mUser;
|
||||||
}
|
}
|
||||||
@@ -211,11 +223,15 @@ public class CustomTile extends QSTile<QSTile.State> {
|
|||||||
@Override
|
@Override
|
||||||
protected void handleUpdateState(State state, Object arg) {
|
protected void handleUpdateState(State state, Object arg) {
|
||||||
Drawable drawable = mTile.getIcon().loadDrawable(mContext);
|
Drawable drawable = mTile.getIcon().loadDrawable(mContext);
|
||||||
int color = mContext.getColor(getColor(mTile.getState()));
|
int tileState = mTile.getState();
|
||||||
|
if (mServiceManager.hasPendingBind()) {
|
||||||
|
tileState = Tile.STATE_UNAVAILABLE;
|
||||||
|
}
|
||||||
|
int color = mContext.getColor(getColor(tileState));
|
||||||
drawable.setTint(color);
|
drawable.setTint(color);
|
||||||
state.icon = new DrawableIcon(drawable);
|
state.icon = new DrawableIcon(drawable);
|
||||||
state.label = mTile.getLabel();
|
state.label = mTile.getLabel();
|
||||||
if (mTile.getState() == Tile.STATE_UNAVAILABLE) {
|
if (tileState == Tile.STATE_UNAVAILABLE) {
|
||||||
state.label = new SpannableStringBuilder().append(state.label,
|
state.label = new SpannableStringBuilder().append(state.label,
|
||||||
new ForegroundColorSpan(color),
|
new ForegroundColorSpan(color),
|
||||||
SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
|
SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
|
||||||
|
|||||||
@@ -249,6 +249,8 @@ public class TileLifecycleManager extends BroadcastReceiver implements
|
|||||||
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
|
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
|
||||||
filter.addDataScheme("package");
|
filter.addDataScheme("package");
|
||||||
mContext.registerReceiverAsUser(this, mUser, filter, null, mHandler);
|
mContext.registerReceiverAsUser(this, mUser, filter, null, mHandler);
|
||||||
|
filter = new IntentFilter(Intent.ACTION_USER_UNLOCKED);
|
||||||
|
mContext.registerReceiverAsUser(this, mUser, filter, null, mHandler);
|
||||||
mReceiverRegistered = true;
|
mReceiverRegistered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,10 +263,12 @@ public class TileLifecycleManager extends BroadcastReceiver implements
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (DEBUG) Log.d(TAG, "onReceive: " + intent);
|
if (DEBUG) Log.d(TAG, "onReceive: " + intent);
|
||||||
Uri data = intent.getData();
|
if (!Intent.ACTION_USER_UNLOCKED.equals(intent.getAction())) {
|
||||||
String pkgName = data.getEncodedSchemeSpecificPart();
|
Uri data = intent.getData();
|
||||||
if (!Objects.equal(pkgName, mIntent.getComponent().getPackageName())) {
|
String pkgName = data.getEncodedSchemeSpecificPart();
|
||||||
return;
|
if (!Objects.equal(pkgName, mIntent.getComponent().getPackageName())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
stopPackageListening();
|
stopPackageListening();
|
||||||
if (mBound) {
|
if (mBound) {
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ public class TileServiceManager {
|
|||||||
private long mLastUpdate;
|
private long mLastUpdate;
|
||||||
private int mType;
|
private int mType;
|
||||||
private boolean mShowingDialog;
|
private boolean mShowingDialog;
|
||||||
|
// Whether we have a pending bind going out to the service without a response yet.
|
||||||
|
// This defaults to true to ensure tiles start out unavailable.
|
||||||
|
private boolean mPendingBind = true;
|
||||||
|
|
||||||
TileServiceManager(TileServices tileServices, Handler handler, ComponentName component) {
|
TileServiceManager(TileServices tileServices, Handler handler, ComponentName component) {
|
||||||
this(tileServices, handler, new TileLifecycleManager(handler,
|
this(tileServices, handler, new TileLifecycleManager(handler,
|
||||||
@@ -132,11 +135,20 @@ public class TileServiceManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasPendingBind() {
|
||||||
|
return mPendingBind;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearPendingBind() {
|
||||||
|
mPendingBind = false;
|
||||||
|
}
|
||||||
|
|
||||||
private void bindService() {
|
private void bindService() {
|
||||||
if (mBound) {
|
if (mBound) {
|
||||||
Log.e(TAG, "Service already bound");
|
Log.e(TAG, "Service already bound");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
mPendingBind = true;
|
||||||
mBound = true;
|
mBound = true;
|
||||||
mJustBound = true;
|
mJustBound = true;
|
||||||
mHandler.postDelayed(mJustBoundOver, MIN_BIND_TIME);
|
mHandler.postDelayed(mJustBoundOver, MIN_BIND_TIME);
|
||||||
|
|||||||
@@ -182,13 +182,29 @@ public class TileServices extends IQSService.Stub {
|
|||||||
CustomTile customTile = getTileForComponent(componentName);
|
CustomTile customTile = getTileForComponent(componentName);
|
||||||
if (customTile != null) {
|
if (customTile != null) {
|
||||||
synchronized (mServices) {
|
synchronized (mServices) {
|
||||||
mServices.get(customTile).setLastUpdate(System.currentTimeMillis());
|
final TileServiceManager tileServiceManager = mServices.get(customTile);
|
||||||
|
tileServiceManager.clearPendingBind();
|
||||||
|
tileServiceManager.setLastUpdate(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
customTile.updateState(tile);
|
customTile.updateState(tile);
|
||||||
customTile.refreshState();
|
customTile.refreshState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartSuccessful(Tile tile) {
|
||||||
|
ComponentName componentName = tile.getComponentName();
|
||||||
|
verifyCaller(componentName.getPackageName());
|
||||||
|
CustomTile customTile = getTileForComponent(componentName);
|
||||||
|
if (customTile != null) {
|
||||||
|
synchronized (mServices) {
|
||||||
|
final TileServiceManager tileServiceManager = mServices.get(customTile);
|
||||||
|
tileServiceManager.clearPendingBind();
|
||||||
|
}
|
||||||
|
customTile.refreshState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onShowDialog(Tile tile) {
|
public void onShowDialog(Tile tile) {
|
||||||
ComponentName componentName = tile.getComponentName();
|
ComponentName componentName = tile.getComponentName();
|
||||||
|
|||||||
Reference in New Issue
Block a user