cmsdk: allow custom tiles to set the new qstile's sensitive data flag

Requires: topic:hide-qs-tiles

Change-Id: I71c85a00ae5797f1e142073b4d6a3a4c3274007b
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
This commit is contained in:
Jorge Ruesga 2015-08-15 14:31:46 +02:00 committed by Adnan Begovic
parent 0eb2999091
commit 95dadd837c
3 changed files with 52 additions and 2 deletions

View File

@ -108,6 +108,13 @@ public class CustomTile implements Parcelable {
*/
public boolean collapsePanel = true;
/**
* Indicates whether this tile has sensitive data that have to be hidden on
* secure lockscreens.
* By default {@link #sensitiveData} is false
*/
public boolean sensitiveData = false;
/**
* Unflatten the CustomTile from a parcel.
*/
@ -152,6 +159,7 @@ public class CustomTile implements Parcelable {
if (parcel.readInt() != 0) {
this.deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel);
}
this.sensitiveData = (parcel.readInt() == 1);
}
parcel.setDataPosition(startPosition + parcelableSize);
@ -210,6 +218,7 @@ public class CustomTile implements Parcelable {
if (deleteIntent != null) {
b.append("deleteIntent=" + deleteIntent.toString() + NEW_LINE);
}
b.append("sensitiveData=" + sensitiveData + NEW_LINE);
return b.toString();
}
@ -229,6 +238,7 @@ public class CustomTile implements Parcelable {
that.collapsePanel = this.collapsePanel;
that.remoteIcon = this.remoteIcon;
that.deleteIntent = this.deleteIntent;
that.sensitiveData = this.sensitiveData;
}
@Override
@ -290,20 +300,19 @@ public class CustomTile implements Parcelable {
// ==== BOYSENBERRY =====
out.writeString(resourcesPackageName);
out.writeInt(collapsePanel ? 1 : 0);
if (remoteIcon != null) {
out.writeInt(1);
remoteIcon.writeToParcel(out, 0);
} else {
out.writeInt(0);
}
if (deleteIntent != null) {
out.writeInt(1);
deleteIntent.writeToParcel(out, 0);
} else {
out.writeInt(0);
}
out.writeInt(sensitiveData ? 1 : 0);
// Go back and write size
int parcelableSize = out.dataPosition() - startPosition;
@ -908,6 +917,7 @@ public class CustomTile implements Parcelable {
private ExpandedStyle mExpandedStyle;
private boolean mCollapsePanel = true;
private PendingIntent mDeleteIntent;
private boolean mSensitiveData = false;
/**
* Constructs a new Builder with the defaults:
@ -1051,6 +1061,17 @@ public class CustomTile implements Parcelable {
return this;
}
/**
* Indicates whether this tile has sensitive data that have to be hidden
* on secure lockscreens.
* @param bool
* @return {@link cyanogenmod.app.CustomTile.Builder}
*/
public Builder hasSensitiveData(boolean bool) {
mSensitiveData = bool;
return this;
}
/**
* Create a {@link cyanogenmod.app.CustomTile} object
* @return {@link cyanogenmod.app.CustomTile}
@ -1068,6 +1089,7 @@ public class CustomTile implements Parcelable {
tile.collapsePanel = mCollapsePanel;
tile.remoteIcon = mRemoteIcon;
tile.deleteIntent = mDeleteIntent;
tile.sensitiveData = mSensitiveData;
return tile;
}
}

View File

@ -140,6 +140,15 @@ public class CustomTileBuilderTest extends AndroidTestCase {
assertEquals(collapsePanel, customTile.collapsePanel);
}
@SmallTest
public void testCustomTileBuilderSensitiveDataSet() {
boolean sensitiveData = true;
CustomTile customTile = new CustomTile.Builder(mContext)
.hasSensitiveData(sensitiveData)
.build();
assertEquals(sensitiveData, customTile.sensitiveData);
}
@MediumTest
public void testCustomTileBuilderExpandedListStyleSet() {
PendingIntent intent = PendingIntent.getActivity(mContext, 0,

View File

@ -189,6 +189,25 @@ public class CustomTileTest extends AndroidTestCase {
assertEquals(expectedCustomTile.collapsePanel, fromParcel.collapsePanel);
}
@SmallTest
public void testCustomTileSensitiveDataUnravelFromParcel() {
CustomTile expectedCustomTile = new CustomTile.Builder(mContext)
.hasSensitiveData(true)
.build();
// Write to parcel
Parcel parcel = Parcel.obtain();
expectedCustomTile.writeToParcel(parcel, 0);
// Rewind
parcel.setDataPosition(0);
// Verify data when unraveling
CustomTile fromParcel = CustomTile.CREATOR.createFromParcel(parcel);
assertEquals(expectedCustomTile.sensitiveData, fromParcel.sensitiveData);
}
@MediumTest
public void testCustomTileExpandedListStyleUnravelFromParcel() {
PendingIntent intent = PendingIntent.getActivity(mContext, 0,