Merge "Fix QS FBE-ness" into nyc-dev

This commit is contained in:
Jason Monk
2016-03-18 18:41:38 +00:00
committed by Android (Google) Code Review
7 changed files with 66 additions and 12 deletions

View File

@@ -34,4 +34,5 @@ interface IQSService {
void startUnlockAndRun(in Tile tile);
void onDialogHidden(in Tile tile);
void onStartSuccessful(in Tile tile);
}

View File

@@ -37,8 +37,6 @@ public final class Tile implements Parcelable {
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
* 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.
@@ -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,
* cast is casting).
* cast is casting). This is the default state.
*/
public static final int STATE_ACTIVE = 2;

View File

@@ -17,6 +17,7 @@ package com.android.systemui.qs.customize;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.GridLayoutManager.SpanSizeLookup;
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 Handler mHandler = new Handler();
private final List<TileInfo> mTiles = new ArrayList<>();
private final ItemTouchHelper mItemTouchHelper;
private int mDividerIndex;
@@ -262,7 +264,12 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
mCurrentDrag = (Holder) viewHolder;
mCurrentDrag.startDrag();
}
notifyItemChanged(mDividerIndex);
mHandler.post(new Runnable() {
@Override
public void run() {
notifyItemChanged(mDividerIndex);
}
});
}
@Override

View File

@@ -75,7 +75,8 @@ public class CustomTile extends QSTile<QSTile.State> {
mUser = ActivityManager.getCurrentUser();
try {
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
.createWithResource(mComponent.getPackageName(), info.icon));
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() {
return mUser;
}
@@ -211,11 +223,15 @@ public class CustomTile extends QSTile<QSTile.State> {
@Override
protected void handleUpdateState(State state, Object arg) {
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);
state.icon = new DrawableIcon(drawable);
state.label = mTile.getLabel();
if (mTile.getState() == Tile.STATE_UNAVAILABLE) {
if (tileState == Tile.STATE_UNAVAILABLE) {
state.label = new SpannableStringBuilder().append(state.label,
new ForegroundColorSpan(color),
SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);

View File

@@ -249,6 +249,8 @@ public class TileLifecycleManager extends BroadcastReceiver implements
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
filter.addDataScheme("package");
mContext.registerReceiverAsUser(this, mUser, filter, null, mHandler);
filter = new IntentFilter(Intent.ACTION_USER_UNLOCKED);
mContext.registerReceiverAsUser(this, mUser, filter, null, mHandler);
mReceiverRegistered = true;
}
@@ -261,10 +263,12 @@ public class TileLifecycleManager extends BroadcastReceiver implements
@Override
public void onReceive(Context context, Intent intent) {
if (DEBUG) Log.d(TAG, "onReceive: " + intent);
Uri data = intent.getData();
String pkgName = data.getEncodedSchemeSpecificPart();
if (!Objects.equal(pkgName, mIntent.getComponent().getPackageName())) {
return;
if (!Intent.ACTION_USER_UNLOCKED.equals(intent.getAction())) {
Uri data = intent.getData();
String pkgName = data.getEncodedSchemeSpecificPart();
if (!Objects.equal(pkgName, mIntent.getComponent().getPackageName())) {
return;
}
}
stopPackageListening();
if (mBound) {

View File

@@ -53,6 +53,9 @@ public class TileServiceManager {
private long mLastUpdate;
private int mType;
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) {
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() {
if (mBound) {
Log.e(TAG, "Service already bound");
return;
}
mPendingBind = true;
mBound = true;
mJustBound = true;
mHandler.postDelayed(mJustBoundOver, MIN_BIND_TIME);

View File

@@ -182,13 +182,29 @@ public class TileServices extends IQSService.Stub {
CustomTile customTile = getTileForComponent(componentName);
if (customTile != null) {
synchronized (mServices) {
mServices.get(customTile).setLastUpdate(System.currentTimeMillis());
final TileServiceManager tileServiceManager = mServices.get(customTile);
tileServiceManager.clearPendingBind();
tileServiceManager.setLastUpdate(System.currentTimeMillis());
}
customTile.updateState(tile);
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
public void onShowDialog(Tile tile) {
ComponentName componentName = tile.getComponentName();