diff options
| author | 2016-03-11 11:33:36 -0500 | |
|---|---|---|
| committer | 2016-03-18 14:31:42 -0400 | |
| commit | 1c2fea8df7054d1bc23945c38460a123ce453c4a (patch) | |
| tree | 02e622c2cc4110587fd64af72d80b858518b8941 | |
| parent | 2c83702aa218cbcc51d8726575c78691fc57a53b (diff) | |
Fix QS FBE-ness
- Get service info for encryption-unaware apps
- SysUI assumes tiles in unavailable state when waiting for
binding
- Attempt rebind after unlock is complete
- Fix random crash that was making testing hard
Bug: 26940789
Bug: 27556723
Change-Id: I0b3600d35d4c74bb0d6c47a34a7d267bb9731bc4
7 files changed, 66 insertions, 12 deletions
diff --git a/core/java/android/service/quicksettings/IQSService.aidl b/core/java/android/service/quicksettings/IQSService.aidl index 1d9050557dd1..5434e2ef5e2f 100644 --- a/core/java/android/service/quicksettings/IQSService.aidl +++ b/core/java/android/service/quicksettings/IQSService.aidl @@ -34,4 +34,5 @@ interface IQSService { void startUnlockAndRun(in Tile tile); void onDialogHidden(in Tile tile); + void onStartSuccessful(in Tile tile); } diff --git a/core/java/android/service/quicksettings/Tile.java b/core/java/android/service/quicksettings/Tile.java index 85f1955e8ebd..3d7d53ea67e8 100644 --- a/core/java/android/service/quicksettings/Tile.java +++ b/core/java/android/service/quicksettings/Tile.java @@ -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; diff --git a/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java b/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java index 57db3a6acba2..03c2a0bc505a 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java @@ -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 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 db686a83f5e5..9156f3a6f726 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java @@ -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); diff --git a/packages/SystemUI/src/com/android/systemui/qs/external/TileLifecycleManager.java b/packages/SystemUI/src/com/android/systemui/qs/external/TileLifecycleManager.java index 2aad16108f50..8910d44e6488 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/external/TileLifecycleManager.java +++ b/packages/SystemUI/src/com/android/systemui/qs/external/TileLifecycleManager.java @@ -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) { diff --git a/packages/SystemUI/src/com/android/systemui/qs/external/TileServiceManager.java b/packages/SystemUI/src/com/android/systemui/qs/external/TileServiceManager.java index 5cf1e215c871..664ddd6f00a0 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/external/TileServiceManager.java +++ b/packages/SystemUI/src/com/android/systemui/qs/external/TileServiceManager.java @@ -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); diff --git a/packages/SystemUI/src/com/android/systemui/qs/external/TileServices.java b/packages/SystemUI/src/com/android/systemui/qs/external/TileServices.java index bfa4a32119c8..5bb2a3588acf 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/external/TileServices.java +++ b/packages/SystemUI/src/com/android/systemui/qs/external/TileServices.java @@ -182,7 +182,9 @@ 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(); @@ -190,6 +192,20 @@ public class TileServices extends IQSService.Stub { } @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(); verifyCaller(componentName.getPackageName()); |