Merge "QS custom tiles - better handling of invalid icons" into nyc-dev
This commit is contained in:
@@ -144,14 +144,18 @@ public class TileQueryHelper {
|
|||||||
String packageName = info.serviceInfo.packageName;
|
String packageName = info.serviceInfo.packageName;
|
||||||
ComponentName componentName = new ComponentName(packageName, info.serviceInfo.name);
|
ComponentName componentName = new ComponentName(packageName, info.serviceInfo.name);
|
||||||
String spec = CustomTile.toSpec(componentName);
|
String spec = CustomTile.toSpec(componentName);
|
||||||
|
if (info.serviceInfo.icon == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Drawable icon = info.serviceInfo.loadIcon(pm);
|
Drawable icon = info.serviceInfo.loadIcon(pm);
|
||||||
if (!permission.BIND_QUICK_SETTINGS_TILE.equals(info.serviceInfo.permission)) {
|
if (!permission.BIND_QUICK_SETTINGS_TILE.equals(info.serviceInfo.permission)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (icon != null) {
|
if (icon == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
icon.mutate();
|
icon.mutate();
|
||||||
icon.setTint(mContext.getColor(android.R.color.white));
|
icon.setTint(mContext.getColor(android.R.color.white));
|
||||||
}
|
|
||||||
CharSequence label = info.serviceInfo.loadLabel(pm);
|
CharSequence label = info.serviceInfo.loadLabel(pm);
|
||||||
final CharSequence appLabel = info.serviceInfo.applicationInfo.loadLabel(pm);
|
final CharSequence appLabel = info.serviceInfo.applicationInfo.loadLabel(pm);
|
||||||
addTile(spec, icon, label != null ? label.toString() : "null", appLabel, mContext);
|
addTile(spec, icon, label != null ? label.toString() : "null", appLabel, mContext);
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import android.util.Log;
|
|||||||
import android.view.IWindowManager;
|
import android.view.IWindowManager;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.WindowManagerGlobal;
|
import android.view.WindowManagerGlobal;
|
||||||
|
|
||||||
import com.android.internal.logging.MetricsLogger;
|
import com.android.internal.logging.MetricsLogger;
|
||||||
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||||
import com.android.systemui.R;
|
import com.android.systemui.R;
|
||||||
@@ -59,6 +58,7 @@ public class CustomTile extends QSTile<QSTile.State> {
|
|||||||
private final IQSTileService mService;
|
private final IQSTileService mService;
|
||||||
private final TileServiceManager mServiceManager;
|
private final TileServiceManager mServiceManager;
|
||||||
private final int mUser;
|
private final int mUser;
|
||||||
|
private final android.graphics.drawable.Icon mDefaultIcon;
|
||||||
|
|
||||||
private boolean mListening;
|
private boolean mListening;
|
||||||
private boolean mBound;
|
private boolean mBound;
|
||||||
@@ -73,15 +73,19 @@ public class CustomTile extends QSTile<QSTile.State> {
|
|||||||
mService = mServiceManager.getTileService();
|
mService = mServiceManager.getTileService();
|
||||||
mTile = new Tile(mComponent);
|
mTile = new Tile(mComponent);
|
||||||
mUser = ActivityManager.getCurrentUser();
|
mUser = ActivityManager.getCurrentUser();
|
||||||
|
android.graphics.drawable.Icon defaultIcon;
|
||||||
try {
|
try {
|
||||||
PackageManager pm = mContext.getPackageManager();
|
PackageManager pm = mContext.getPackageManager();
|
||||||
ServiceInfo info = pm.getServiceInfo(mComponent,
|
ServiceInfo info = pm.getServiceInfo(mComponent,
|
||||||
PackageManager.MATCH_ENCRYPTION_AWARE_AND_UNAWARE);
|
PackageManager.MATCH_ENCRYPTION_AWARE_AND_UNAWARE);
|
||||||
mTile.setIcon(android.graphics.drawable.Icon
|
defaultIcon = info.icon != 0 ? android.graphics.drawable.Icon
|
||||||
.createWithResource(mComponent.getPackageName(), info.icon));
|
.createWithResource(mComponent.getPackageName(), info.icon) : null;
|
||||||
|
mTile.setIcon(defaultIcon);
|
||||||
mTile.setLabel(info.loadLabel(pm));
|
mTile.setLabel(info.loadLabel(pm));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
defaultIcon = null;
|
||||||
}
|
}
|
||||||
|
mDefaultIcon = defaultIcon;
|
||||||
try {
|
try {
|
||||||
mService.setQSTile(mTile);
|
mService.setQSTile(mTile);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
@@ -91,13 +95,7 @@ public class CustomTile extends QSTile<QSTile.State> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
try {
|
return mDefaultIcon != null;
|
||||||
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() {
|
||||||
@@ -227,11 +225,18 @@ 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);
|
|
||||||
int tileState = mTile.getState();
|
int tileState = mTile.getState();
|
||||||
if (mServiceManager.hasPendingBind()) {
|
if (mServiceManager.hasPendingBind()) {
|
||||||
tileState = Tile.STATE_UNAVAILABLE;
|
tileState = Tile.STATE_UNAVAILABLE;
|
||||||
}
|
}
|
||||||
|
Drawable drawable;
|
||||||
|
try {
|
||||||
|
drawable = mTile.getIcon().loadDrawable(mContext);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.w(TAG, "Invalid icon, forcing into unavailable state");
|
||||||
|
tileState = Tile.STATE_UNAVAILABLE;
|
||||||
|
drawable = mDefaultIcon.loadDrawable(mContext);
|
||||||
|
}
|
||||||
int color = mContext.getColor(getColor(tileState));
|
int color = mContext.getColor(getColor(tileState));
|
||||||
drawable.setTint(color);
|
drawable.setTint(color);
|
||||||
state.icon = new DrawableIcon(drawable);
|
state.icon = new DrawableIcon(drawable);
|
||||||
|
|||||||
Reference in New Issue
Block a user