cmsdk: customtiles: allow load resources from external packages
Saved the context passed to CustomTile.Builder in other to differenciate from the context used to publish the tile. This allow to load resources (icons) from other packages Change-Id: I8e40bc59a66f371f3a02f0182e25c6e9eca73c63 Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
This commit is contained in:
parent
6b9dbb295d
commit
08a3470a78
|
@ -27,8 +27,8 @@ import android.os.IBinder;
|
|||
import android.os.IInterface;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Log;
|
||||
import android.util.Slog;
|
||||
|
||||
|
@ -166,9 +166,14 @@ public class CMStatusBarManagerService extends SystemService {
|
|||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Obtain the resources package name
|
||||
String resPkg = customTile.getResourcesPackageName();
|
||||
if (TextUtils.isEmpty(resPkg)) {
|
||||
resPkg = pkg;
|
||||
}
|
||||
|
||||
final StatusBarPanelCustomTile sbc = new StatusBarPanelCustomTile(
|
||||
pkg, opPkg, id, tag, callingUid, callingPid, customTile,
|
||||
user);
|
||||
pkg, resPkg, opPkg, id, tag, callingUid, callingPid, customTile, user);
|
||||
ExternalQuickSettingsRecord r = new ExternalQuickSettingsRecord(sbc);
|
||||
ExternalQuickSettingsRecord old = mCustomTileByKey.get(sbc.getKey());
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@ import java.util.ArrayList;
|
|||
*/
|
||||
public class CustomTile implements Parcelable {
|
||||
|
||||
private String resourcesPackageName = "";
|
||||
|
||||
/**
|
||||
* An optional intent to execute when the custom tile entry is clicked. If
|
||||
* this is an activity, it must include the
|
||||
|
@ -83,6 +85,7 @@ public class CustomTile implements Parcelable {
|
|||
* Unflatten the CustomTile from a parcel.
|
||||
*/
|
||||
public CustomTile(Parcel parcel) {
|
||||
resourcesPackageName = parcel.readString();
|
||||
if (parcel.readInt() != 0) {
|
||||
this.onClick = PendingIntent.CREATOR.createFromParcel(parcel);
|
||||
}
|
||||
|
@ -113,6 +116,11 @@ public class CustomTile implements Parcelable {
|
|||
// Empty constructor
|
||||
}
|
||||
|
||||
/** @hide **/
|
||||
public String getResourcesPackageName() {
|
||||
return resourcesPackageName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomTile clone() {
|
||||
CustomTile that = new CustomTile();
|
||||
|
@ -124,6 +132,7 @@ public class CustomTile implements Parcelable {
|
|||
public String toString() {
|
||||
StringBuilder b = new StringBuilder();
|
||||
String NEW_LINE = System.getProperty("line.separator");
|
||||
b.append("resourcesPackageName=" + resourcesPackageName + NEW_LINE);
|
||||
if (onClickUri != null) {
|
||||
b.append("onClickUri=" + onClickUri.toString() + NEW_LINE);
|
||||
}
|
||||
|
@ -151,6 +160,7 @@ public class CustomTile implements Parcelable {
|
|||
* @hide
|
||||
*/
|
||||
public void cloneInto(CustomTile that) {
|
||||
that.resourcesPackageName = this.resourcesPackageName;
|
||||
that.onClick = this.onClick;
|
||||
that.onSettingsClick = this.onSettingsClick;
|
||||
that.onClickUri = this.onClickUri;
|
||||
|
@ -167,6 +177,7 @@ public class CustomTile implements Parcelable {
|
|||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeString(resourcesPackageName);
|
||||
if (onClick != null) {
|
||||
out.writeInt(1);
|
||||
onClick.writeToParcel(out, 0);
|
||||
|
@ -734,6 +745,7 @@ public class CustomTile implements Parcelable {
|
|||
*/
|
||||
public CustomTile build() {
|
||||
CustomTile tile = new CustomTile();
|
||||
tile.resourcesPackageName = mContext.getPackageName();
|
||||
tile.onClick = mOnClick;
|
||||
tile.onSettingsClick = mOnSettingsClick;
|
||||
tile.onClickUri = mOnClickUri;
|
||||
|
|
|
@ -32,25 +32,27 @@ public class StatusBarPanelCustomTile implements Parcelable {
|
|||
private final String key;
|
||||
|
||||
private final int uid;
|
||||
private final String resPkg;
|
||||
private final String opPkg;
|
||||
private final int initialPid;
|
||||
private final CustomTile customTile;
|
||||
private final UserHandle user;
|
||||
private final long postTime;
|
||||
|
||||
public StatusBarPanelCustomTile(String pkg, String opPkg, int id, String tag, int uid,
|
||||
int initialPid, CustomTile customTile, UserHandle user) {
|
||||
this(pkg, opPkg, id, tag, uid, initialPid, customTile, user,
|
||||
public StatusBarPanelCustomTile(String pkg, String resPkg, String opPkg, int id, String tag,
|
||||
int uid, int initialPid, CustomTile customTile, UserHandle user) {
|
||||
this(pkg, resPkg, opPkg, id, tag, uid, initialPid, customTile, user,
|
||||
System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public StatusBarPanelCustomTile(String pkg, String opPkg, int id, String tag, int uid,
|
||||
int initialPid, CustomTile customTile, UserHandle user,
|
||||
public StatusBarPanelCustomTile(String pkg, String resPkg, String opPkg, int id, String tag,
|
||||
int uid, int initialPid, CustomTile customTile, UserHandle user,
|
||||
long postTime) {
|
||||
if (pkg == null) throw new NullPointerException();
|
||||
if (customTile == null) throw new NullPointerException();
|
||||
|
||||
this.pkg = pkg;
|
||||
this.resPkg = resPkg;
|
||||
this.opPkg = opPkg;
|
||||
this.id = id;
|
||||
this.tag = tag;
|
||||
|
@ -65,6 +67,7 @@ public class StatusBarPanelCustomTile implements Parcelable {
|
|||
|
||||
public StatusBarPanelCustomTile(Parcel in) {
|
||||
this.pkg = in.readString();
|
||||
this.resPkg = in.readString();
|
||||
this.opPkg = in.readString();
|
||||
this.id = in.readInt();
|
||||
if (in.readInt() != 0) {
|
||||
|
@ -113,6 +116,7 @@ public class StatusBarPanelCustomTile implements Parcelable {
|
|||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeString(this.pkg);
|
||||
out.writeString(this.resPkg);
|
||||
out.writeString(this.opPkg);
|
||||
out.writeInt(this.id);
|
||||
if (this.tag != null) {
|
||||
|
@ -130,7 +134,7 @@ public class StatusBarPanelCustomTile implements Parcelable {
|
|||
|
||||
@Override
|
||||
public StatusBarPanelCustomTile clone() {
|
||||
return new StatusBarPanelCustomTile(this.pkg, this.opPkg,
|
||||
return new StatusBarPanelCustomTile(this.pkg, this.resPkg, this.opPkg,
|
||||
this.id, this.tag, this.uid, this.initialPid,
|
||||
this.customTile.clone(), this.user, this.postTime);
|
||||
}
|
||||
|
@ -169,6 +173,11 @@ public class StatusBarPanelCustomTile implements Parcelable {
|
|||
return uid;
|
||||
}
|
||||
|
||||
/** The package used for load resources from. @hide */
|
||||
public String getResPkg() {
|
||||
return resPkg;
|
||||
}
|
||||
|
||||
/** The package used for AppOps tracking. @hide */
|
||||
public String getOpPkg() {
|
||||
return opPkg;
|
||||
|
|
Loading…
Reference in New Issue