Merge "Let low-ram devices override voice recognisers on"
diff --git a/Android.bp b/Android.bp
index 7e97e66..b76e923 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1067,6 +1067,7 @@
"core/java/android/annotation/IntDef.java",
"core/java/android/annotation/NonNull.java",
"core/java/android/annotation/SystemApi.java",
+ "core/java/android/annotation/TestApi.java",
"core/java/android/os/HwBinder.java",
"core/java/android/os/HwBlob.java",
"core/java/android/os/HwParcel.java",
@@ -1316,7 +1317,6 @@
"ext",
"framework",
"voip-common",
- "android.test.mock.impl",
],
local_sourcepaths: frameworks_base_subdirs,
installable: false,
diff --git a/api/current.txt b/api/current.txt
index 4edaf04..e2ea649 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -5245,8 +5245,8 @@
method public android.app.Notification clone();
method public int describeContents();
method public boolean getAllowSystemGeneratedContextualActions();
- method public android.app.PendingIntent getAppOverlayIntent();
method public int getBadgeIconType();
+ method public android.app.Notification.BubbleMetadata getBubbleMetadata();
method public java.lang.String getChannelId();
method public java.lang.String getGroup();
method public int getGroupAlertBehavior();
@@ -5459,6 +5459,25 @@
method public android.app.Notification.BigTextStyle setSummaryText(java.lang.CharSequence);
}
+ public static final class Notification.BubbleMetadata implements android.os.Parcelable {
+ method public int describeContents();
+ method public int getDesiredHeight();
+ method public android.graphics.drawable.Icon getIcon();
+ method public android.app.PendingIntent getIntent();
+ method public java.lang.CharSequence getTitle();
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator<android.app.Notification.BubbleMetadata> CREATOR;
+ }
+
+ public static class Notification.BubbleMetadata.Builder {
+ ctor public Notification.BubbleMetadata.Builder();
+ method public android.app.Notification.BubbleMetadata build();
+ method public android.app.Notification.BubbleMetadata.Builder setDesiredHeight(int);
+ method public android.app.Notification.BubbleMetadata.Builder setIcon(android.graphics.drawable.Icon);
+ method public android.app.Notification.BubbleMetadata.Builder setIntent(android.app.PendingIntent);
+ method public android.app.Notification.BubbleMetadata.Builder setTitle(java.lang.CharSequence);
+ }
+
public static class Notification.Builder {
ctor public Notification.Builder(android.content.Context, java.lang.String);
ctor public deprecated Notification.Builder(android.content.Context);
@@ -5478,9 +5497,9 @@
method public static android.app.Notification.Builder recoverBuilder(android.content.Context, android.app.Notification);
method public android.app.Notification.Builder setActions(android.app.Notification.Action...);
method public android.app.Notification.Builder setAllowSystemGeneratedContextualActions(boolean);
- method public android.app.Notification.Builder setAppOverlayIntent(android.app.PendingIntent);
method public android.app.Notification.Builder setAutoCancel(boolean);
method public android.app.Notification.Builder setBadgeIconType(int);
+ method public android.app.Notification.Builder setBubbleMetadata(android.app.Notification.BubbleMetadata);
method public android.app.Notification.Builder setCategory(java.lang.String);
method public android.app.Notification.Builder setChannelId(java.lang.String);
method public android.app.Notification.Builder setChronometerCountDown(boolean);
@@ -5695,8 +5714,8 @@
public final class NotificationChannel implements android.os.Parcelable {
ctor public NotificationChannel(java.lang.String, java.lang.CharSequence, int);
+ method public boolean canBubble();
method public boolean canBypassDnd();
- method public boolean canOverlayApps();
method public boolean canShowBadge();
method public int describeContents();
method public void enableLights(boolean);
@@ -5712,7 +5731,7 @@
method public android.net.Uri getSound();
method public long[] getVibrationPattern();
method public boolean hasUserSetImportance();
- method public void setAllowAppOverlay(boolean);
+ method public void setAllowBubbles(boolean);
method public void setBypassDnd(boolean);
method public void setDescription(java.lang.String);
method public void setGroup(java.lang.String);
@@ -5746,7 +5765,7 @@
public class NotificationManager {
method public java.lang.String addAutomaticZenRule(android.app.AutomaticZenRule);
- method public boolean areAppOverlaysAllowed();
+ method public boolean areBubblesAllowed();
method public boolean areNotificationsEnabled();
method public boolean canNotifyAsPackage(java.lang.String);
method public void cancel(int);
@@ -13737,6 +13756,7 @@
method public void drawTextOnPath(java.lang.String, android.graphics.Path, float, float, android.graphics.Paint);
method public void drawTextRun(char[], int, int, int, int, float, float, boolean, android.graphics.Paint);
method public void drawTextRun(java.lang.CharSequence, int, int, int, int, float, float, boolean, android.graphics.Paint);
+ method public void drawTextRun(android.graphics.text.MeasuredText, int, int, int, int, float, float, boolean, android.graphics.Paint);
method public void drawVertices(android.graphics.Canvas.VertexMode, int, float[], int, float[], int, int[], int, short[], int, int, android.graphics.Paint);
method public void enableZ();
method public boolean getClipBounds(android.graphics.Rect);
@@ -22663,6 +22683,7 @@
method public deprecated double getCarrierPhase();
method public deprecated double getCarrierPhaseUncertainty();
method public double getCn0DbHz();
+ method public int getCodeType();
method public int getConstellationType();
method public int getMultipathIndicator();
method public double getPseudorangeRateMetersPerSecond();
@@ -22678,6 +22699,7 @@
method public boolean hasCarrierFrequencyHz();
method public deprecated boolean hasCarrierPhase();
method public deprecated boolean hasCarrierPhaseUncertainty();
+ method public boolean hasCodeType();
method public boolean hasSnrInDb();
method public void writeToParcel(android.os.Parcel, int);
field public static final int ADR_STATE_CYCLE_SLIP = 4; // 0x4
@@ -22686,6 +22708,21 @@
field public static final int ADR_STATE_RESET = 2; // 0x2
field public static final int ADR_STATE_UNKNOWN = 0; // 0x0
field public static final int ADR_STATE_VALID = 1; // 0x1
+ field public static final int CODE_TYPE_A = 0; // 0x0
+ field public static final int CODE_TYPE_B = 1; // 0x1
+ field public static final int CODE_TYPE_C = 2; // 0x2
+ field public static final int CODE_TYPE_CODELESS = 13; // 0xd
+ field public static final int CODE_TYPE_I = 3; // 0x3
+ field public static final int CODE_TYPE_L = 4; // 0x4
+ field public static final int CODE_TYPE_M = 5; // 0x5
+ field public static final int CODE_TYPE_P = 6; // 0x6
+ field public static final int CODE_TYPE_Q = 7; // 0x7
+ field public static final int CODE_TYPE_S = 8; // 0x8
+ field public static final int CODE_TYPE_UNKNOWN = -1; // 0xffffffff
+ field public static final int CODE_TYPE_W = 9; // 0x9
+ field public static final int CODE_TYPE_X = 10; // 0xa
+ field public static final int CODE_TYPE_Y = 11; // 0xb
+ field public static final int CODE_TYPE_Z = 12; // 0xc
field public static final android.os.Parcelable.Creator<android.location.GnssMeasurement> CREATOR;
field public static final int MULTIPATH_INDICATOR_DETECTED = 1; // 0x1
field public static final int MULTIPATH_INDICATOR_NOT_DETECTED = 2; // 0x2
@@ -25439,6 +25476,7 @@
method public java.lang.Object setAuxEffectSendLevel(float);
method public java.lang.Object setDataSource(android.media.DataSourceDesc);
method public java.lang.Object setDisplay(android.view.SurfaceHolder);
+ method public void setDrmEventCallback(java.util.concurrent.Executor, android.media.MediaPlayer2.DrmEventCallback);
method public java.lang.Object setNextDataSource(android.media.DataSourceDesc);
method public java.lang.Object setNextDataSources(java.util.List<android.media.DataSourceDesc>);
method public java.lang.Object setPlaybackParams(android.media.PlaybackParams);
@@ -25517,6 +25555,33 @@
field public static final int SEEK_PREVIOUS_SYNC = 0; // 0x0
}
+ public static class MediaPlayer2.DrmEventCallback {
+ ctor public MediaPlayer2.DrmEventCallback();
+ method public void onDrmConfig(android.media.MediaPlayer2, android.media.DataSourceDesc, android.media.MediaDrm);
+ method public android.media.MediaPlayer2.DrmPreparationInfo onDrmInfo(android.media.MediaPlayer2, android.media.DataSourceDesc, android.media.MediaPlayer2.DrmInfo);
+ method public byte[] onDrmKeyRequest(android.media.MediaPlayer2, android.media.DataSourceDesc, android.media.MediaDrm.KeyRequest);
+ method public void onDrmPrepared(android.media.MediaPlayer2, android.media.DataSourceDesc, int, byte[]);
+ }
+
+ public static final class MediaPlayer2.DrmInfo {
+ method public java.util.Map<java.util.UUID, byte[]> getPssh();
+ method public java.util.List<java.util.UUID> getSupportedSchemes();
+ }
+
+ public static final class MediaPlayer2.DrmPreparationInfo {
+ }
+
+ public static final class MediaPlayer2.DrmPreparationInfo.Builder {
+ ctor public MediaPlayer2.DrmPreparationInfo.Builder();
+ method public android.media.MediaPlayer2.DrmPreparationInfo build();
+ method public android.media.MediaPlayer2.DrmPreparationInfo.Builder setInitData(byte[]);
+ method public android.media.MediaPlayer2.DrmPreparationInfo.Builder setKeySetId(byte[]);
+ method public android.media.MediaPlayer2.DrmPreparationInfo.Builder setKeyType(int);
+ method public android.media.MediaPlayer2.DrmPreparationInfo.Builder setMimeType(java.lang.String);
+ method public android.media.MediaPlayer2.DrmPreparationInfo.Builder setOptionalParameters(java.util.Map<java.lang.String, java.lang.String>);
+ method public android.media.MediaPlayer2.DrmPreparationInfo.Builder setUuid(java.util.UUID);
+ }
+
public static class MediaPlayer2.EventCallback {
ctor public MediaPlayer2.EventCallback();
method public void onCallCompleted(android.media.MediaPlayer2, android.media.DataSourceDesc, int, int);
@@ -25544,6 +25609,10 @@
field public static final java.lang.String WIDTH = "android.media.mediaplayer.width";
}
+ public static final class MediaPlayer2.NoDrmSchemeException extends android.media.MediaDrmException {
+ ctor public MediaPlayer2.NoDrmSchemeException(java.lang.String);
+ }
+
public static class MediaPlayer2.TrackInfo {
method public android.media.MediaFormat getFormat();
method public java.lang.String getLanguage();
@@ -29724,8 +29793,10 @@
method public java.lang.String getMacAddress();
method public int getNetworkId();
method public int getRssi();
+ method public int getRxLinkSpeedMbps();
method public java.lang.String getSSID();
method public android.net.wifi.SupplicantState getSupplicantState();
+ method public int getTxLinkSpeedMbps();
method public void writeToParcel(android.os.Parcel, int);
field public static final java.lang.String FREQUENCY_UNITS = "MHz";
field public static final java.lang.String LINK_SPEED_UNITS = "Mbps";
@@ -45078,6 +45149,7 @@
}
public class EuiccManager {
+ method public android.telephony.euicc.EuiccManager createForCardId(int);
method public void deleteSubscription(int, android.app.PendingIntent);
method public void downloadSubscription(android.telephony.euicc.DownloadableSubscription, boolean, android.app.PendingIntent);
method public java.lang.String getEid();
@@ -47080,7 +47152,7 @@
public class Linkify {
ctor public Linkify();
method public static final boolean addLinks(android.text.Spannable, int);
- method public static final boolean addLinks(android.text.Spannable, int, android.text.util.Linkify.UrlSpanFactory);
+ method public static final boolean addLinks(android.text.Spannable, int, java.util.function.Function<java.lang.String, android.text.style.URLSpan>);
method public static final boolean addLinks(android.widget.TextView, int);
method public static final void addLinks(android.widget.TextView, java.util.regex.Pattern, java.lang.String);
method public static final void addLinks(android.widget.TextView, java.util.regex.Pattern, java.lang.String, android.text.util.Linkify.MatchFilter, android.text.util.Linkify.TransformFilter);
@@ -47088,7 +47160,7 @@
method public static final boolean addLinks(android.text.Spannable, java.util.regex.Pattern, java.lang.String);
method public static final boolean addLinks(android.text.Spannable, java.util.regex.Pattern, java.lang.String, android.text.util.Linkify.MatchFilter, android.text.util.Linkify.TransformFilter);
method public static final boolean addLinks(android.text.Spannable, java.util.regex.Pattern, java.lang.String, java.lang.String[], android.text.util.Linkify.MatchFilter, android.text.util.Linkify.TransformFilter);
- method public static final boolean addLinks(android.text.Spannable, java.util.regex.Pattern, java.lang.String, java.lang.String[], android.text.util.Linkify.MatchFilter, android.text.util.Linkify.TransformFilter, android.text.util.Linkify.UrlSpanFactory);
+ method public static final boolean addLinks(android.text.Spannable, java.util.regex.Pattern, java.lang.String, java.lang.String[], android.text.util.Linkify.MatchFilter, android.text.util.Linkify.TransformFilter, java.util.function.Function<java.lang.String, android.text.style.URLSpan>);
field public static final int ALL = 15; // 0xf
field public static final int EMAIL_ADDRESSES = 2; // 0x2
field public static final deprecated int MAP_ADDRESSES = 8; // 0x8
@@ -47107,11 +47179,6 @@
method public abstract java.lang.String transformUrl(java.util.regex.Matcher, java.lang.String);
}
- public static class Linkify.UrlSpanFactory {
- ctor public Linkify.UrlSpanFactory();
- method public android.text.style.URLSpan create(java.lang.String);
- }
-
public class Rfc822Token {
ctor public Rfc822Token(java.lang.String, java.lang.String, java.lang.String);
method public java.lang.String getAddress();
@@ -53015,15 +53082,15 @@
package android.view.textclassifier {
- public final class ConversationActions implements android.os.Parcelable {
- ctor public ConversationActions(java.util.List<android.view.textclassifier.ConversationActions.ConversationAction>, java.lang.String);
+ public final class ConversationAction implements android.os.Parcelable {
method public int describeContents();
- method public java.util.List<android.view.textclassifier.ConversationActions.ConversationAction> getConversationActions();
- method public java.lang.String getId();
+ method public android.app.RemoteAction getAction();
+ method public float getConfidenceScore();
+ method public android.os.Bundle getExtras();
+ method public java.lang.CharSequence getTextReply();
+ method public java.lang.String getType();
method public void writeToParcel(android.os.Parcel, int);
- field public static final android.os.Parcelable.Creator<android.view.textclassifier.ConversationActions> CREATOR;
- field public static final java.lang.String HINT_FOR_IN_APP = "in_app";
- field public static final java.lang.String HINT_FOR_NOTIFICATION = "notification";
+ field public static final android.os.Parcelable.Creator<android.view.textclassifier.ConversationAction> CREATOR;
field public static final java.lang.String TYPE_CALL_PHONE = "call_phone";
field public static final java.lang.String TYPE_CREATE_REMINDER = "create_reminder";
field public static final java.lang.String TYPE_OPEN_URL = "open_url";
@@ -53036,24 +53103,22 @@
field public static final java.lang.String TYPE_VIEW_MAP = "view_map";
}
- public static final class ConversationActions.ConversationAction implements android.os.Parcelable {
- method public int describeContents();
- method public android.app.RemoteAction getAction();
- method public float getConfidenceScore();
- method public android.os.Bundle getExtras();
- method public java.lang.CharSequence getTextReply();
- method public java.lang.String getType();
- method public void writeToParcel(android.os.Parcel, int);
- field public static final android.os.Parcelable.Creator<android.view.textclassifier.ConversationActions.ConversationAction> CREATOR;
+ public static final class ConversationAction.Builder {
+ ctor public ConversationAction.Builder(java.lang.String);
+ method public android.view.textclassifier.ConversationAction build();
+ method public android.view.textclassifier.ConversationAction.Builder setAction(android.app.RemoteAction);
+ method public android.view.textclassifier.ConversationAction.Builder setConfidenceScore(float);
+ method public android.view.textclassifier.ConversationAction.Builder setExtras(android.os.Bundle);
+ method public android.view.textclassifier.ConversationAction.Builder setTextReply(java.lang.CharSequence);
}
- public static final class ConversationActions.ConversationAction.Builder {
- ctor public ConversationActions.ConversationAction.Builder(java.lang.String);
- method public android.view.textclassifier.ConversationActions.ConversationAction build();
- method public android.view.textclassifier.ConversationActions.ConversationAction.Builder setAction(android.app.RemoteAction);
- method public android.view.textclassifier.ConversationActions.ConversationAction.Builder setConfidenceScore(float);
- method public android.view.textclassifier.ConversationActions.ConversationAction.Builder setExtras(android.os.Bundle);
- method public android.view.textclassifier.ConversationActions.ConversationAction.Builder setTextReply(java.lang.CharSequence);
+ public final class ConversationActions implements android.os.Parcelable {
+ ctor public ConversationActions(java.util.List<android.view.textclassifier.ConversationAction>, java.lang.String);
+ method public int describeContents();
+ method public java.util.List<android.view.textclassifier.ConversationAction> getConversationActions();
+ method public java.lang.String getId();
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator<android.view.textclassifier.ConversationActions> CREATOR;
}
public static final class ConversationActions.Message implements android.os.Parcelable {
@@ -53083,9 +53148,11 @@
method public java.lang.String getConversationId();
method public java.util.List<java.lang.String> getHints();
method public int getMaxSuggestions();
- method public android.view.textclassifier.ConversationActions.TypeConfig getTypeConfig();
+ method public android.view.textclassifier.TextClassifier.EntityConfig getTypeConfig();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.view.textclassifier.ConversationActions.Request> CREATOR;
+ field public static final java.lang.String HINT_FOR_IN_APP = "in_app";
+ field public static final java.lang.String HINT_FOR_NOTIFICATION = "notification";
}
public static final class ConversationActions.Request.Builder {
@@ -53094,23 +53161,7 @@
method public android.view.textclassifier.ConversationActions.Request.Builder setConversationId(java.lang.String);
method public android.view.textclassifier.ConversationActions.Request.Builder setHints(java.util.List<java.lang.String>);
method public android.view.textclassifier.ConversationActions.Request.Builder setMaxSuggestions(int);
- method public android.view.textclassifier.ConversationActions.Request.Builder setTypeConfig(android.view.textclassifier.ConversationActions.TypeConfig);
- }
-
- public static final class ConversationActions.TypeConfig implements android.os.Parcelable {
- method public int describeContents();
- method public java.util.Collection<java.lang.String> resolveTypes(java.util.Collection<java.lang.String>);
- method public boolean shouldIncludeTypesFromTextClassifier();
- method public void writeToParcel(android.os.Parcel, int);
- field public static final android.os.Parcelable.Creator<android.view.textclassifier.ConversationActions.TypeConfig> CREATOR;
- }
-
- public static final class ConversationActions.TypeConfig.Builder {
- ctor public ConversationActions.TypeConfig.Builder();
- method public android.view.textclassifier.ConversationActions.TypeConfig build();
- method public android.view.textclassifier.ConversationActions.TypeConfig.Builder includeTypesFromTextClassifier(boolean);
- method public android.view.textclassifier.ConversationActions.TypeConfig.Builder setExcludedTypes(java.util.Collection<java.lang.String>);
- method public android.view.textclassifier.ConversationActions.TypeConfig.Builder setIncludedTypes(java.util.Collection<java.lang.String>);
+ method public android.view.textclassifier.ConversationActions.Request.Builder setTypeConfig(android.view.textclassifier.TextClassifier.EntityConfig);
}
public final class SelectionEvent implements android.os.Parcelable {
@@ -53284,16 +53335,26 @@
}
public static final class TextClassifier.EntityConfig implements android.os.Parcelable {
- method public static android.view.textclassifier.TextClassifier.EntityConfig create(java.util.Collection<java.lang.String>, java.util.Collection<java.lang.String>, java.util.Collection<java.lang.String>);
- method public static android.view.textclassifier.TextClassifier.EntityConfig createWithExplicitEntityList(java.util.Collection<java.lang.String>);
- method public static android.view.textclassifier.TextClassifier.EntityConfig createWithHints(java.util.Collection<java.lang.String>);
+ method public static deprecated android.view.textclassifier.TextClassifier.EntityConfig create(java.util.Collection<java.lang.String>, java.util.Collection<java.lang.String>, java.util.Collection<java.lang.String>);
+ method public static deprecated android.view.textclassifier.TextClassifier.EntityConfig createWithExplicitEntityList(java.util.Collection<java.lang.String>);
+ method public static deprecated android.view.textclassifier.TextClassifier.EntityConfig createWithHints(java.util.Collection<java.lang.String>);
method public int describeContents();
method public java.util.Collection<java.lang.String> getHints();
method public java.util.Collection<java.lang.String> resolveEntityListModifications(java.util.Collection<java.lang.String>);
+ method public boolean shouldIncludeTypesFromTextClassifier();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.view.textclassifier.TextClassifier.EntityConfig> CREATOR;
}
+ public static final class TextClassifier.EntityConfig.Builder {
+ ctor public TextClassifier.EntityConfig.Builder();
+ method public android.view.textclassifier.TextClassifier.EntityConfig build();
+ method public android.view.textclassifier.TextClassifier.EntityConfig.Builder includeTypesFromTextClassifier(boolean);
+ method public android.view.textclassifier.TextClassifier.EntityConfig.Builder setExcludedTypes(java.util.Collection<java.lang.String>);
+ method public android.view.textclassifier.TextClassifier.EntityConfig.Builder setHints(java.util.Collection<java.lang.String>);
+ method public android.view.textclassifier.TextClassifier.EntityConfig.Builder setIncludedTypes(java.util.Collection<java.lang.String>);
+ }
+
public final class TextClassifierEvent implements android.os.Parcelable {
method public int describeContents();
method public int[] getActionIndices();
diff --git a/api/system-current.txt b/api/system-current.txt
index 78f3471..37b5e1e 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -3908,24 +3908,24 @@
package android.net.wifi {
- public abstract class DppStatusCallback {
- ctor public DppStatusCallback();
+ public abstract class EasyConnectStatusCallback {
+ ctor public EasyConnectStatusCallback();
method public abstract void onConfiguratorSuccess(int);
method public abstract void onEnrolleeSuccess(int);
method public abstract void onFailure(int);
method public abstract void onProgress(int);
- field public static final int DPP_EVENT_FAILURE = -7; // 0xfffffff9
- field public static final int DPP_EVENT_FAILURE_AUTHENTICATION = -2; // 0xfffffffe
- field public static final int DPP_EVENT_FAILURE_BUSY = -5; // 0xfffffffb
- field public static final int DPP_EVENT_FAILURE_CONFIGURATION = -4; // 0xfffffffc
- field public static final int DPP_EVENT_FAILURE_INVALID_NETWORK = -9; // 0xfffffff7
- field public static final int DPP_EVENT_FAILURE_INVALID_URI = -1; // 0xffffffff
- field public static final int DPP_EVENT_FAILURE_NOT_COMPATIBLE = -3; // 0xfffffffd
- field public static final int DPP_EVENT_FAILURE_NOT_SUPPORTED = -8; // 0xfffffff8
- field public static final int DPP_EVENT_FAILURE_TIMEOUT = -6; // 0xfffffffa
- field public static final int DPP_EVENT_PROGRESS_AUTHENTICATION_SUCCESS = 0; // 0x0
- field public static final int DPP_EVENT_PROGRESS_RESPONSE_PENDING = 1; // 0x1
- field public static final int DPP_EVENT_SUCCESS_CONFIGURATION_SENT = 0; // 0x0
+ field public static final int EASY_CONNECT_EVENT_FAILURE = -7; // 0xfffffff9
+ field public static final int EASY_CONNECT_EVENT_FAILURE_AUTHENTICATION = -2; // 0xfffffffe
+ field public static final int EASY_CONNECT_EVENT_FAILURE_BUSY = -5; // 0xfffffffb
+ field public static final int EASY_CONNECT_EVENT_FAILURE_CONFIGURATION = -4; // 0xfffffffc
+ field public static final int EASY_CONNECT_EVENT_FAILURE_INVALID_NETWORK = -9; // 0xfffffff7
+ field public static final int EASY_CONNECT_EVENT_FAILURE_INVALID_URI = -1; // 0xffffffff
+ field public static final int EASY_CONNECT_EVENT_FAILURE_NOT_COMPATIBLE = -3; // 0xfffffffd
+ field public static final int EASY_CONNECT_EVENT_FAILURE_NOT_SUPPORTED = -8; // 0xfffffff8
+ field public static final int EASY_CONNECT_EVENT_FAILURE_TIMEOUT = -6; // 0xfffffffa
+ field public static final int EASY_CONNECT_EVENT_PROGRESS_AUTHENTICATION_SUCCESS = 0; // 0x0
+ field public static final int EASY_CONNECT_EVENT_PROGRESS_RESPONSE_PENDING = 1; // 0x1
+ field public static final int EASY_CONNECT_EVENT_SUCCESS_CONFIGURATION_SENT = 0; // 0x0
}
public deprecated class RttManager {
@@ -4156,10 +4156,10 @@
method public void save(android.net.wifi.WifiConfiguration, android.net.wifi.WifiManager.ActionListener);
method public void setDeviceMobilityState(int);
method public boolean setWifiApConfiguration(android.net.wifi.WifiConfiguration);
- method public void startDppAsConfiguratorInitiator(java.lang.String, int, int, android.os.Handler, android.net.wifi.DppStatusCallback);
- method public void startDppAsEnrolleeInitiator(java.lang.String, android.os.Handler, android.net.wifi.DppStatusCallback);
+ method public void startEasyConnectAsConfiguratorInitiator(java.lang.String, int, int, android.os.Handler, android.net.wifi.EasyConnectStatusCallback);
+ method public void startEasyConnectAsEnrolleeInitiator(java.lang.String, android.os.Handler, android.net.wifi.EasyConnectStatusCallback);
method public boolean startScan(android.os.WorkSource);
- method public void stopDppSession();
+ method public void stopEasyConnectSession();
method public void unregisterNetworkRequestMatchCallback(android.net.wifi.WifiManager.NetworkRequestMatchCallback);
field public static final int CHANGE_REASON_ADDED = 0; // 0x0
field public static final int CHANGE_REASON_CONFIG_CHANGE = 2; // 0x2
@@ -4169,8 +4169,8 @@
field public static final int DEVICE_MOBILITY_STATE_LOW_MVMT = 2; // 0x2
field public static final int DEVICE_MOBILITY_STATE_STATIONARY = 3; // 0x3
field public static final int DEVICE_MOBILITY_STATE_UNKNOWN = 0; // 0x0
- field public static final int DPP_NETWORK_ROLE_AP = 1; // 0x1
- field public static final int DPP_NETWORK_ROLE_STA = 0; // 0x0
+ field public static final int EASY_CONNECT_NETWORK_ROLE_AP = 1; // 0x1
+ field public static final int EASY_CONNECT_NETWORK_ROLE_STA = 0; // 0x0
field public static final java.lang.String EXTRA_CHANGE_REASON = "changeReason";
field public static final java.lang.String EXTRA_MULTIPLE_NETWORKS_CHANGED = "multipleChanges";
field public static final java.lang.String EXTRA_PREVIOUS_WIFI_AP_STATE = "previous_wifi_state";
@@ -4445,6 +4445,10 @@
method public abstract java.lang.Object onTransactStarted(android.os.IBinder, int);
}
+ public static class Build.VERSION {
+ field public static final java.lang.String PREVIEW_SDK_FINGERPRINT;
+ }
+
public final class ConfigUpdate {
field public static final java.lang.String ACTION_UPDATE_CARRIER_ID_DB = "android.os.action.UPDATE_CARRIER_ID_DB";
field public static final java.lang.String ACTION_UPDATE_CARRIER_PROVISIONING_URLS = "android.intent.action.UPDATE_CARRIER_PROVISIONING_URLS";
@@ -4863,6 +4867,8 @@
method public final android.os.IBinder onBind(android.content.Intent);
method public abstract int onCountPermissionApps(java.util.List<java.lang.String>, boolean, boolean);
method public abstract java.util.List<android.permission.RuntimePermissionPresentationInfo> onGetAppPermissions(java.lang.String);
+ method public abstract void onGetRuntimePermissionsBackup(android.os.UserHandle, java.io.OutputStream);
+ method public abstract java.util.List<android.permission.RuntimePermissionUsageInfo> onPermissionUsageResult(boolean, long);
method public abstract void onRevokeRuntimePermission(java.lang.String, java.lang.String);
method public abstract java.util.Map<java.lang.String, java.util.List<java.lang.String>> onRevokeRuntimePermissions(java.util.Map<java.lang.String, java.util.List<java.lang.String>>, boolean, int, java.lang.String);
field public static final java.lang.String SERVICE_INTERFACE = "android.permission.PermissionControllerService";
@@ -4891,11 +4897,12 @@
public final class RuntimePermissionUsageInfo implements android.os.Parcelable {
ctor public RuntimePermissionUsageInfo(java.lang.CharSequence, int);
method public int describeContents();
- method public java.lang.CharSequence getName();
method public int getAppAccessCount();
+ method public java.lang.CharSequence getName();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.permission.RuntimePermissionUsageInfo> CREATOR;
}
+
}
package android.permissionpresenterservice {
@@ -7251,7 +7258,6 @@
method public void callSessionInviteParticipantsRequestDelivered();
method public void callSessionInviteParticipantsRequestFailed(android.telephony.ims.ImsReasonInfo);
method public void callSessionMayHandover(int, int);
- method public void callSessionRttAudioIndicatorChanged(android.telephony.ims.ImsStreamMediaProfile);
method public void callSessionMergeComplete(android.telephony.ims.stub.ImsCallSessionImplBase);
method public void callSessionMergeFailed(android.telephony.ims.ImsReasonInfo);
method public void callSessionMergeStarted(android.telephony.ims.stub.ImsCallSessionImplBase, android.telephony.ims.ImsCallProfile);
@@ -7262,6 +7268,7 @@
method public void callSessionResumeFailed(android.telephony.ims.ImsReasonInfo);
method public void callSessionResumeReceived(android.telephony.ims.ImsCallProfile);
method public void callSessionResumed(android.telephony.ims.ImsCallProfile);
+ method public void callSessionRttAudioIndicatorChanged(android.telephony.ims.ImsStreamMediaProfile);
method public void callSessionRttMessageReceived(java.lang.String);
method public void callSessionRttModifyRequestReceived(android.telephony.ims.ImsCallProfile);
method public void callSessionRttModifyResponseReceived(int);
diff --git a/api/test-current.txt b/api/test-current.txt
index 6d40e69..71f02b9 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -421,6 +421,7 @@
public class PermissionInfo extends android.content.pm.PackageItemInfo implements android.os.Parcelable {
field public static final int PROTECTION_FLAG_DOCUMENTER = 262144; // 0x40000
+ field public static final int PROTECTION_FLAG_OEM = 16384; // 0x4000
field public static final int PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER = 65536; // 0x10000
field public static final int PROTECTION_FLAG_VENDOR_PRIVILEGED = 32768; // 0x8000
field public static final int PROTECTION_FLAG_WELLBEING = 131072; // 0x20000
@@ -500,6 +501,10 @@
package android.graphics {
+ public final class Bitmap implements android.os.Parcelable {
+ method public void eraseColor(long);
+ }
+
public final class ImageDecoder implements java.lang.AutoCloseable {
method public static android.graphics.ImageDecoder.Source createSource(android.content.res.Resources, java.io.InputStream, int);
}
@@ -623,6 +628,7 @@
method public void resetCarrierFrequencyHz();
method public deprecated void resetCarrierPhase();
method public deprecated void resetCarrierPhaseUncertainty();
+ method public void resetCodeType();
method public void resetSnrInDb();
method public void set(android.location.GnssMeasurement);
method public void setAccumulatedDeltaRangeMeters(double);
@@ -634,6 +640,7 @@
method public deprecated void setCarrierPhase(double);
method public deprecated void setCarrierPhaseUncertainty(double);
method public void setCn0DbHz(double);
+ method public void setCodeType(int);
method public void setConstellationType(int);
method public void setMultipathIndicator(int);
method public void setPseudorangeRateMetersPerSecond(double);
@@ -790,6 +797,134 @@
method public static java.io.File getStorageDirectory();
}
+ public abstract class HwBinder implements android.os.IHwBinder {
+ ctor public HwBinder();
+ method public static final void configureRpcThreadpool(long, boolean);
+ method public static void enableInstrumentation();
+ method public static final android.os.IHwBinder getService(java.lang.String, java.lang.String) throws java.util.NoSuchElementException, android.os.RemoteException;
+ method public static final android.os.IHwBinder getService(java.lang.String, java.lang.String, boolean) throws java.util.NoSuchElementException, android.os.RemoteException;
+ method public static final void joinRpcThreadpool();
+ method public abstract void onTransact(int, android.os.HwParcel, android.os.HwParcel, int) throws android.os.RemoteException;
+ method public final void registerService(java.lang.String) throws android.os.RemoteException;
+ method public final void transact(int, android.os.HwParcel, android.os.HwParcel, int) throws android.os.RemoteException;
+ }
+
+ public class HwBlob {
+ ctor public HwBlob(int);
+ method public final void copyToBoolArray(long, boolean[], int);
+ method public final void copyToDoubleArray(long, double[], int);
+ method public final void copyToFloatArray(long, float[], int);
+ method public final void copyToInt16Array(long, short[], int);
+ method public final void copyToInt32Array(long, int[], int);
+ method public final void copyToInt64Array(long, long[], int);
+ method public final void copyToInt8Array(long, byte[], int);
+ method public final boolean getBool(long);
+ method public final double getDouble(long);
+ method public final float getFloat(long);
+ method public final short getInt16(long);
+ method public final int getInt32(long);
+ method public final long getInt64(long);
+ method public final byte getInt8(long);
+ method public final java.lang.String getString(long);
+ method public final long handle();
+ method public final void putBlob(long, android.os.HwBlob);
+ method public final void putBool(long, boolean);
+ method public final void putBoolArray(long, boolean[]);
+ method public final void putDouble(long, double);
+ method public final void putDoubleArray(long, double[]);
+ method public final void putFloat(long, float);
+ method public final void putFloatArray(long, float[]);
+ method public final void putInt16(long, short);
+ method public final void putInt16Array(long, short[]);
+ method public final void putInt32(long, int);
+ method public final void putInt32Array(long, int[]);
+ method public final void putInt64(long, long);
+ method public final void putInt64Array(long, long[]);
+ method public final void putInt8(long, byte);
+ method public final void putInt8Array(long, byte[]);
+ method public final void putNativeHandle(long, android.os.NativeHandle);
+ method public final void putString(long, java.lang.String);
+ method public static java.lang.Boolean[] wrapArray(boolean[]);
+ method public static java.lang.Long[] wrapArray(long[]);
+ method public static java.lang.Byte[] wrapArray(byte[]);
+ method public static java.lang.Short[] wrapArray(short[]);
+ method public static java.lang.Integer[] wrapArray(int[]);
+ method public static java.lang.Float[] wrapArray(float[]);
+ method public static java.lang.Double[] wrapArray(double[]);
+ }
+
+ public class HwParcel {
+ ctor public HwParcel();
+ method public final void enforceInterface(java.lang.String);
+ method public final boolean readBool();
+ method public final java.util.ArrayList<java.lang.Boolean> readBoolVector();
+ method public final android.os.HwBlob readBuffer(long);
+ method public final double readDouble();
+ method public final java.util.ArrayList<java.lang.Double> readDoubleVector();
+ method public final android.os.HwBlob readEmbeddedBuffer(long, long, long, boolean);
+ method public final android.os.NativeHandle readEmbeddedNativeHandle(long, long);
+ method public final float readFloat();
+ method public final java.util.ArrayList<java.lang.Float> readFloatVector();
+ method public final short readInt16();
+ method public final java.util.ArrayList<java.lang.Short> readInt16Vector();
+ method public final int readInt32();
+ method public final java.util.ArrayList<java.lang.Integer> readInt32Vector();
+ method public final long readInt64();
+ method public final java.util.ArrayList<java.lang.Long> readInt64Vector();
+ method public final byte readInt8();
+ method public final java.util.ArrayList<java.lang.Byte> readInt8Vector();
+ method public final android.os.NativeHandle readNativeHandle();
+ method public final java.util.ArrayList<android.os.NativeHandle> readNativeHandleVector();
+ method public final java.lang.String readString();
+ method public final java.util.ArrayList<java.lang.String> readStringVector();
+ method public final android.os.IHwBinder readStrongBinder();
+ method public final void release();
+ method public final void releaseTemporaryStorage();
+ method public final void send();
+ method public final void verifySuccess();
+ method public final void writeBool(boolean);
+ method public final void writeBoolVector(java.util.ArrayList<java.lang.Boolean>);
+ method public final void writeBuffer(android.os.HwBlob);
+ method public final void writeDouble(double);
+ method public final void writeDoubleVector(java.util.ArrayList<java.lang.Double>);
+ method public final void writeFloat(float);
+ method public final void writeFloatVector(java.util.ArrayList<java.lang.Float>);
+ method public final void writeInt16(short);
+ method public final void writeInt16Vector(java.util.ArrayList<java.lang.Short>);
+ method public final void writeInt32(int);
+ method public final void writeInt32Vector(java.util.ArrayList<java.lang.Integer>);
+ method public final void writeInt64(long);
+ method public final void writeInt64Vector(java.util.ArrayList<java.lang.Long>);
+ method public final void writeInt8(byte);
+ method public final void writeInt8Vector(java.util.ArrayList<java.lang.Byte>);
+ method public final void writeInterfaceToken(java.lang.String);
+ method public final void writeNativeHandle(android.os.NativeHandle);
+ method public final void writeNativeHandleVector(java.util.ArrayList<android.os.NativeHandle>);
+ method public final void writeStatus(int);
+ method public final void writeString(java.lang.String);
+ method public final void writeStringVector(java.util.ArrayList<java.lang.String>);
+ method public final void writeStrongBinder(android.os.IHwBinder);
+ field public static final int STATUS_SUCCESS = 0; // 0x0
+ }
+
+ public static abstract class HwParcel.Status implements java.lang.annotation.Annotation {
+ }
+
+ public abstract interface IHwBinder {
+ method public abstract boolean linkToDeath(android.os.IHwBinder.DeathRecipient, long);
+ method public abstract android.os.IHwInterface queryLocalInterface(java.lang.String);
+ method public abstract void transact(int, android.os.HwParcel, android.os.HwParcel, int) throws android.os.RemoteException;
+ method public abstract boolean unlinkToDeath(android.os.IHwBinder.DeathRecipient);
+ }
+
+ public static abstract interface IHwBinder.DeathRecipient {
+ method public abstract void serviceDied(long);
+ }
+
+ public abstract interface IHwInterface {
+ method public abstract android.os.IHwBinder asBinder();
+ }
+
public class IncidentManager {
method public void reportIncident(android.os.IncidentReportArgs);
}
@@ -815,6 +950,18 @@
method public void removeSyncBarrier(int);
}
+ public final class NativeHandle implements java.io.Closeable {
+ ctor public NativeHandle();
+ ctor public NativeHandle(java.io.FileDescriptor, boolean);
+ ctor public NativeHandle(java.io.FileDescriptor[], int[], boolean);
+ method public void close() throws java.io.IOException;
+ method public android.os.NativeHandle dup() throws java.io.IOException;
+ method public java.io.FileDescriptor getFileDescriptor();
+ method public java.io.FileDescriptor[] getFileDescriptors();
+ method public int[] getInts();
+ method public boolean hasSingleFileDescriptor();
+ }
+
public final class PowerManager {
method public int getPowerSaveMode();
method public boolean setDynamicPowerSavings(boolean, int);
@@ -825,6 +972,11 @@
public class Process {
method public static final int getThreadScheduler(int) throws java.lang.IllegalArgumentException;
+ field public static final int FIRST_APP_ZYGOTE_ISOLATED_UID = 90000; // 0x15f90
+ field public static final int FIRST_ISOLATED_UID = 99000; // 0x182b8
+ field public static final int LAST_APP_ZYGOTE_ISOLATED_UID = 98999; // 0x182b7
+ field public static final int LAST_ISOLATED_UID = 99999; // 0x1869f
+ field public static final int NUM_UIDS_PER_APP_ZYGOTE = 100; // 0x64
}
public final class RemoteCallback implements android.os.Parcelable {
diff --git a/cmds/screencap/screencap.cpp b/cmds/screencap/screencap.cpp
index 8fa2980..3d74f8b 100644
--- a/cmds/screencap/screencap.cpp
+++ b/cmds/screencap/screencap.cpp
@@ -81,8 +81,7 @@
case ui::Dataspace::V0_SRGB:
return SkColorSpace::MakeSRGB();
case ui::Dataspace::DISPLAY_P3:
- return SkColorSpace::MakeRGB(
- SkColorSpace::kSRGB_RenderTargetGamma, SkColorSpace::kDCIP3_D65_Gamut);
+ return SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
default:
return nullptr;
}
diff --git a/cmds/statsd/src/anomaly/subscriber_util.cpp b/cmds/statsd/src/anomaly/subscriber_util.cpp
index 9d37cdb..ad5eae3 100644
--- a/cmds/statsd/src/anomaly/subscriber_util.cpp
+++ b/cmds/statsd/src/anomaly/subscriber_util.cpp
@@ -57,7 +57,7 @@
break;
case Subscription::SubscriberInformationCase::kPerfettoDetails:
if (!CollectPerfettoTraceAndUploadToDropbox(subscription.perfetto_details(),
- rule_id, configKey)) {
+ subscription.id(), rule_id, configKey)) {
ALOGW("Failed to generate perfetto traces.");
}
break;
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index 6267ac2f..453a0c0 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -25,6 +25,7 @@
import "frameworks/base/core/proto/android/app/settings_enums.proto";
import "frameworks/base/core/proto/android/app/job/enums.proto";
import "frameworks/base/core/proto/android/bluetooth/enums.proto";
+import "frameworks/base/core/proto/android/bluetooth/hci/enums.proto";
import "frameworks/base/core/proto/android/net/networkcapabilities.proto";
import "frameworks/base/core/proto/android/os/enums.proto";
import "frameworks/base/core/proto/android/server/connectivity/data_stall_event.proto";
@@ -181,6 +182,9 @@
DocsUISearchTypeReported docs_ui_search_type_reported = 120;
DataStallEvent data_stall_event = 121;
RescuePartyResetReported rescue_party_reset_reported = 122;
+ SignedConfigReported signed_config_reported = 123;
+ GnssNiEventReported gnss_ni_event_reported = 124;
+ BluetoothLinkLayerConnectionEvent bluetooth_link_layer_connection_event = 125;
}
// Pulled events will start at field 10000.
@@ -1314,6 +1318,90 @@
optional int32 bt_profile = 3;
}
+// Logs when there is an event affecting Bluetooth device's link layer connection.
+// - This event is triggered when there is a related HCI command or event
+// - Users of this metrics can deduce Bluetooth device's connection state from these events
+// - HCI commands are logged before the command is sent, after receiving command status, and after
+// receiving command complete
+// - HCI events are logged when they arrive
+//
+// Low level log from system/bt
+//
+// Bluetooth classic commands:
+// - CMD_CREATE_CONNECTION
+// - CMD_DISCONNECT
+// - CMD_CREATE_CONNECTION_CANCEL
+// - CMD_ACCEPT_CONNECTION_REQUEST
+// - CMD_REJECT_CONNECTION_REQUEST
+// - CMD_SETUP_ESCO_CONNECTION
+// - CMD_ACCEPT_ESCO_CONNECTION
+// - CMD_REJECT_ESCO_CONNECTION
+// - CMD_ENH_SETUP_ESCO_CONNECTION
+// - CMD_ENH_ACCEPT_ESCO_CONNECTION
+//
+// Bluetooth low energy commands:
+// - CMD_BLE_CREATE_LL_CONN [Only logged on error or when initiator filter policy is 0x00]
+// - CMD_BLE_CREATE_CONN_CANCEL [Only logged when there is an error]
+// - CMD_BLE_EXTENDED_CREATE_CONNECTION [Only logged on error or when initiator filter policy is 0x00]
+// - CMD_BLE_CLEAR_WHITE_LIST
+// - CMD_BLE_ADD_WHITE_LIST
+// - CMD_BLE_REMOVE_WHITE_LIST
+//
+// Bluetooth classic events:
+// - EVT_CONNECTION_COMP
+// - EVT_CONNECTION_REQUEST
+// - EVT_DISCONNECTION_COMP
+// - EVT_ESCO_CONNECTION_COMP
+// - EVT_ESCO_CONNECTION_CHANGED
+//
+// Bluetooth low energy meta events:
+// - BLE_EVT_CONN_COMPLETE_EVT
+// - BLE_EVT_ENHANCED_CONN_COMPLETE_EVT
+//
+// Next tag: 10
+message BluetoothLinkLayerConnectionEvent {
+ // An identifier that can be used to match events for this device.
+ // Currently, this is a salted hash of the MAC address of this Bluetooth device.
+ // Salt: Randomly generated 256 bit value
+ // Hash algorithm: HMAC-SHA256
+ // Size: 32 byte
+ // Default: null or empty if the device identifier is not known
+ optional bytes obfuscated_id = 1 [(android.os.statsd.log_mode) = MODE_BYTES];
+ // Connection handle of this connection if available
+ // Range: 0x0000 - 0x0EFF (12 bits)
+ // Default: 0xFFFF if the handle is unknown
+ optional int32 connection_handle = 2;
+ // Direction of the link
+ // Default: DIRECTION_UNKNOWN
+ optional android.bluetooth.DirectionEnum direction = 3;
+ // Type of this link
+ // Default: LINK_TYPE_UNKNOWN
+ optional android.bluetooth.LinkTypeEnum type = 4;
+
+ // Reason metadata for this link layer connection event, rules for interpretation:
+ // 1. If hci_cmd is set and valid, hci_event can be either EVT_COMMAND_STATUS or
+ // EVT_COMMAND_COMPLETE, ignore hci_ble_event in this case
+ // 2. If hci_event is set to EVT_BLE_META, look at hci_ble_event; otherwise, if hci_event is
+ // set and valid, ignore hci_ble_event
+
+ // HCI command associated with this event
+ // Default: CMD_UNKNOWN
+ optional android.bluetooth.hci.CommandEnum hci_cmd = 5;
+ // HCI event associated with this event
+ // Default: EVT_UNKNOWN
+ optional android.bluetooth.hci.EventEnum hci_event = 6;
+ // HCI BLE meta event associated with this event
+ // Default: BLE_EVT_UNKNOWN
+ optional android.bluetooth.hci.BleMetaEventEnum hci_ble_event = 7;
+ // HCI command status code if this is triggerred by hci_cmd
+ // Default: STATUS_UNKNOWN
+ optional android.bluetooth.hci.StatusEnum cmd_status = 8;
+ // HCI reason code associated with this event
+ // Default: STATUS_UNKNOWN
+ optional android.bluetooth.hci.StatusEnum reason_code = 9;
+}
+
+
/**
* Logs when something is plugged into or removed from the USB-C connector.
*
@@ -3859,3 +3947,105 @@
// The rescue level of this reset. A value of 0 indicates missing or unknown level information.
optional int32 rescue_level = 1;
}
+
+/**
+ * Logs when signed config is received from an APK, and if that config was applied successfully.
+ * Logged from:
+ * frameworks/base/services/core/java/com/android/server/signedconfig/SignedConfigService.java
+ */
+message SignedConfigReported {
+ enum Type {
+ UNKNOWN_TYPE = 0;
+ GLOBAL_SETTINGS = 1;
+ }
+ optional Type type = 1;
+
+ // The final status of the signed config received.
+ enum Status {
+ UNKNOWN_STATUS = 0;
+ APPLIED = 1;
+ BASE64_FAILURE_CONFIG = 2;
+ BASE64_FAILURE_SIGNATURE = 3;
+ SECURITY_EXCEPTION = 4;
+ INVALID_CONFIG = 5;
+ OLD_CONFIG = 6;
+ SIGNATURE_CHECK_FAILED = 7;
+ NOT_APPLICABLE = 8;
+ SIGNATURE_CHECK_FAILED_PROD_KEY_ABSENT = 9;
+ }
+ optional Status status = 2;
+
+ // The version of the signed config processed.
+ optional int32 version = 3;
+
+ // The package name that the config was extracted from.
+ optional string from_package = 4;
+
+ enum Key {
+ NO_KEY = 0;
+ DEBUG = 1;
+ PRODUCTION = 2;
+ }
+ // Which key was used to verify the config.
+ optional Key verified_with = 5;
+}
+
+/*
+ * Logs GNSS Network-Initiated (NI) location events.
+ *
+ * Logged from:
+ * frameworks/base/services/core/java/com/android/server/location/GnssLocationProvider.java
+ */
+message GnssNiEventReported {
+ // The type of GnssNiEvent.
+ enum EventType {
+ UNKNOWN = 0;
+ NI_REQUEST = 1;
+ NI_RESPONSE = 2;
+ }
+ optional EventType event_type = 1;
+
+ // An ID generated by HAL to associate NI notifications and UI responses.
+ optional int32 notification_id = 2;
+
+ // A type which distinguishes different categories of NI request, such as VOICE, UMTS_SUPL etc.
+ optional int32 ni_type = 3;
+
+ // NI requires notification.
+ optional bool need_notify = 4;
+
+ // NI requires verification.
+ optional bool need_verify = 5;
+
+ // NI requires privacy override, no notification/minimal trace.
+ optional bool privacy_override = 6;
+
+ // Timeout period to wait for user response. Set to 0 for no timeout limit. Specified in
+ // seconds.
+ optional int32 timeout = 7;
+
+ // Default response when timeout.
+ optional int32 default_response = 8;
+
+ // String representing the requester of the network inititated location request.
+ optional string requestor_id = 9;
+
+ // Notification message text string representing the service(for eg. SUPL-service) who sent the
+ // network initiated location request.
+ optional string text = 10;
+
+ // requestorId decoding scheme.
+ optional int32 requestor_id_encoding = 11;
+
+ // Notification message text decoding scheme.
+ optional int32 text_encoding = 12;
+
+ // True if SUPL ES is enabled.
+ optional bool is_supl_es_enabled = 13;
+
+ // True if GNSS location is enabled.
+ optional bool is_location_enabled = 14;
+
+ // GNSS NI responses which define the response in NI structures.
+ optional int32 user_response = 15;
+}
diff --git a/cmds/statsd/src/external/Perfetto.cpp b/cmds/statsd/src/external/Perfetto.cpp
index 42cc543..0c4c330 100644
--- a/cmds/statsd/src/external/Perfetto.cpp
+++ b/cmds/statsd/src/external/Perfetto.cpp
@@ -39,6 +39,7 @@
namespace statsd {
bool CollectPerfettoTraceAndUploadToDropbox(const PerfettoDetails& config,
+ int64_t subscription_id,
int64_t alert_id,
const ConfigKey& configKey) {
VLOG("Starting trace collection through perfetto");
@@ -48,9 +49,11 @@
return false;
}
- char alertId[20];
- char configId[20];
- char configUid[20];
+ char subscriptionId[25];
+ char alertId[25];
+ char configId[25];
+ char configUid[25];
+ snprintf(subscriptionId, sizeof(subscriptionId), "%" PRId64, subscription_id);
snprintf(alertId, sizeof(alertId), "%" PRId64, alert_id);
snprintf(configId, sizeof(configId), "%" PRId64, configKey.GetId());
snprintf(configUid, sizeof(configUid), "%d", configKey.GetUid());
@@ -94,7 +97,7 @@
execl("/system/bin/perfetto", "perfetto", "--background", "--config", "-", "--dropbox",
kDropboxTag, "--alert-id", alertId, "--config-id", configId, "--config-uid",
- configUid, nullptr);
+ configUid, "--subscription-id", subscriptionId, nullptr);
// execl() doesn't return in case of success, if we get here something
// failed.
diff --git a/cmds/statsd/src/external/Perfetto.h b/cmds/statsd/src/external/Perfetto.h
index 1e7f728..ab2c195 100644
--- a/cmds/statsd/src/external/Perfetto.h
+++ b/cmds/statsd/src/external/Perfetto.h
@@ -32,6 +32,7 @@
// This method returns immediately after passing the config and does NOT wait
// for the full duration of the trace.
bool CollectPerfettoTraceAndUploadToDropbox(const PerfettoDetails& config,
+ int64_t subscription_id,
int64_t alert_id,
const ConfigKey& configKey);
diff --git a/config/hiddenapi-greylist.txt b/config/hiddenapi-greylist.txt
index 4d3c5d1..5392a3c 100644
--- a/config/hiddenapi-greylist.txt
+++ b/config/hiddenapi-greylist.txt
@@ -1492,7 +1492,6 @@
Landroid/test/AndroidTestCase;->getTestContext()Landroid/content/Context;
Landroid/test/AndroidTestCase;->setTestContext(Landroid/content/Context;)V
Landroid/test/InstrumentationTestCase;->runMethod(Ljava/lang/reflect/Method;I)V
-Landroid/test/RepetitiveTest;->numIterations()I
Landroid/util/Singleton;-><init>()V
Landroid/util/XmlPullAttributes;-><init>(Lorg/xmlpull/v1/XmlPullParser;)V
Landroid/util/XmlPullAttributes;->mParser:Lorg/xmlpull/v1/XmlPullParser;
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 98c5a0fb..d374f1c 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -17,6 +17,7 @@
package android.app;
import static android.Manifest.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS;
+import static android.os.Process.myUid;
import static java.lang.Character.MIN_VALUE;
@@ -1025,7 +1026,7 @@
*/
@Nullable private ContentCaptureManager getContentCaptureManager() {
// ContextCapture disabled for system apps
- if (getApplicationInfo().isSystemApp()) return null;
+ if (!UserHandle.isApp(myUid())) return null;
if (mContentCaptureManager == null) {
mContentCaptureManager = getSystemService(ContentCaptureManager.class);
}
@@ -1048,9 +1049,8 @@
private void notifyContentCaptureManagerIfNeeded(@ContentCaptureNotificationType int type) {
final ContentCaptureManager cm = getContentCaptureManager();
- if (cm == null) {
- return;
- }
+ if (cm == null) return;
+
switch (type) {
case CONTENT_CAPTURE_START:
//TODO(b/111276913): decide whether the InteractionSessionId should be
diff --git a/core/java/android/app/ActivityManagerInternal.java b/core/java/android/app/ActivityManagerInternal.java
index c90e404..1f01e26 100644
--- a/core/java/android/app/ActivityManagerInternal.java
+++ b/core/java/android/app/ActivityManagerInternal.java
@@ -317,4 +317,7 @@
/** Returns true if the given uid is the app in the foreground. */
public abstract boolean isAppForeground(int uid);
+
+ /** Remove pending backup for the given userId. */
+ public abstract void clearPendingBackup(int userId);
}
diff --git a/core/java/android/app/ActivityView.java b/core/java/android/app/ActivityView.java
index 57132a7..ab8f234 100644
--- a/core/java/android/app/ActivityView.java
+++ b/core/java/android/app/ActivityView.java
@@ -16,6 +16,10 @@
package android.app;
+import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL;
+import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY;
+import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC;
+
import android.annotation.NonNull;
import android.annotation.UnsupportedAppUsage;
import android.app.ActivityManager.StackInfo;
@@ -32,7 +36,6 @@
import android.view.IWindowManager;
import android.view.InputDevice;
import android.view.MotionEvent;
-import android.view.Surface;
import android.view.SurfaceControl;
import android.view.SurfaceHolder;
import android.view.SurfaceSession;
@@ -82,7 +85,6 @@
private boolean mOpened; // Protected by mGuard.
private final SurfaceControl.Transaction mTmpTransaction = new SurfaceControl.Transaction();
- private Surface mTmpSurface = new Surface();
/** The ActivityView is only allowed to contain one task. */
private final boolean mSingleTaskInstance;
@@ -319,20 +321,20 @@
private class SurfaceCallback implements SurfaceHolder.Callback {
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
- mTmpSurface = new Surface();
if (mVirtualDisplay == null) {
initVirtualDisplay(new SurfaceSession());
if (mVirtualDisplay != null && mActivityViewCallback != null) {
mActivityViewCallback.onActivityViewReady(ActivityView.this);
}
} else {
- // TODO (b/119209373): DisplayManager determines if a VirtualDisplay is on by
- // whether it has a surface. Setting a fake surface here so DisplayManager will
- // consider this display on.
- mVirtualDisplay.setSurface(mTmpSurface);
mTmpTransaction.reparent(mRootSurfaceControl,
mSurfaceView.getSurfaceControl().getHandle()).apply();
}
+
+ if (mVirtualDisplay != null) {
+ mVirtualDisplay.setDisplayState(true);
+ }
+
updateLocation();
}
@@ -346,10 +348,8 @@
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
- mTmpSurface.release();
- mTmpSurface = null;
if (mVirtualDisplay != null) {
- mVirtualDisplay.setSurface(null);
+ mVirtualDisplay.setDisplayState(false);
}
cleanTapExcludeRegion();
}
@@ -370,15 +370,11 @@
final int height = mSurfaceView.getHeight();
final DisplayManager displayManager = mContext.getSystemService(DisplayManager.class);
- // TODO (b/119209373): DisplayManager determines if a VirtualDisplay is on by
- // whether it has a surface. Setting a fake surface here so DisplayManager will consider
- // this display on.
mVirtualDisplay = displayManager.createVirtualDisplay(
- DISPLAY_NAME + "@" + System.identityHashCode(this),
- width, height, getBaseDisplayDensity(), mTmpSurface,
- DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC
- | DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
- | DisplayManager.VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL);
+ DISPLAY_NAME + "@" + System.identityHashCode(this), width, height,
+ getBaseDisplayDensity(), null,
+ VIRTUAL_DISPLAY_FLAG_PUBLIC | VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
+ | VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL);
if (mVirtualDisplay == null) {
Log.e(TAG, "Failed to initialize ActivityView");
return;
@@ -443,11 +439,6 @@
displayReleased = false;
}
- if (mTmpSurface != null) {
- mTmpSurface.release();
- mTmpSurface = null;
- }
-
if (displayReleased && mActivityViewCallback != null) {
mActivityViewCallback.onActivityViewDestroyed(this);
}
diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl
index 347973e..fb65da1 100644
--- a/core/java/android/app/IActivityManager.aidl
+++ b/core/java/android/app/IActivityManager.aidl
@@ -317,7 +317,6 @@
*/
void requestWifiBugReport(in String shareTitle, in String shareDescription);
- void clearPendingBackup();
Intent getIntentForIntentSender(in IIntentSender sender);
// This is not public because you need to be very careful in how you
// manage your activity to make sure it is always the uid you expect.
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl
index 163be8e..199c133 100644
--- a/core/java/android/app/INotificationManager.aidl
+++ b/core/java/android/app/INotificationManager.aidl
@@ -65,9 +65,9 @@
boolean areNotificationsEnabled(String pkg);
int getPackageImportance(String pkg);
- void setAppOverlaysAllowed(String pkg, int uid, boolean allowed);
- boolean areAppOverlaysAllowed(String pkg);
- boolean areAppOverlaysAllowedForPackage(String pkg, int uid);
+ void setBubblesAllowed(String pkg, int uid, boolean allowed);
+ boolean areBubblesAllowed(String pkg);
+ boolean areBubblesAllowedForPackage(String pkg, int uid);
void createNotificationChannelGroups(String pkg, in ParceledListSlice channelGroupList);
void createNotificationChannels(String pkg, in ParceledListSlice channelsList);
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index b657a91..72819cb 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -1276,7 +1276,7 @@
private String mShortcutId;
private CharSequence mSettingsText;
- private PendingIntent mAppOverlayIntent;
+ private BubbleMetadata mBubbleMetadata;
/** @hide */
@IntDef(prefix = { "GROUP_ALERT_" }, value = {
@@ -2278,7 +2278,7 @@
mGroupAlertBehavior = parcel.readInt();
if (parcel.readInt() != 0) {
- mAppOverlayIntent = PendingIntent.CREATOR.createFromParcel(parcel);
+ mBubbleMetadata = BubbleMetadata.CREATOR.createFromParcel(parcel);
}
mAllowSystemGeneratedContextualActions = parcel.readBoolean();
@@ -2396,7 +2396,7 @@
that.mBadgeIcon = this.mBadgeIcon;
that.mSettingsText = this.mSettingsText;
that.mGroupAlertBehavior = this.mGroupAlertBehavior;
- that.mAppOverlayIntent = this.mAppOverlayIntent;
+ that.mBubbleMetadata = this.mBubbleMetadata;
that.mAllowSystemGeneratedContextualActions = this.mAllowSystemGeneratedContextualActions;
if (!heavy) {
@@ -2719,9 +2719,9 @@
parcel.writeInt(mGroupAlertBehavior);
- if (mAppOverlayIntent != null) {
+ if (mBubbleMetadata != null) {
parcel.writeInt(1);
- mAppOverlayIntent.writeToParcel(parcel, 0);
+ mBubbleMetadata.writeToParcel(parcel, 0);
} else {
parcel.writeInt(0);
}
@@ -3141,11 +3141,11 @@
}
/**
- * Returns the intent that will be used to display app content in a floating window over the
- * existing foreground activity.
+ * Returns the bubble metadata that will be used to display app content in a floating window
+ * over the existing foreground activity.
*/
- public PendingIntent getAppOverlayIntent() {
- return mAppOverlayIntent;
+ public BubbleMetadata getBubbleMetadata() {
+ return mBubbleMetadata;
}
/**
@@ -3508,19 +3508,18 @@
}
/**
- * Sets the intent that will be used to display app content in a floating window
- * over the existing foreground activity.
+ * Sets the {@link BubbleMetadata} that will be used to display app content in a floating
+ * window over the existing foreground activity.
*
- * <p>This intent will be ignored unless this notification is posted to a channel that
- * allows {@link NotificationChannel#canOverlayApps() app overlays}.</p>
+ * <p>This data will be ignored unless the notification is posted to a channel that
+ * allows {@link NotificationChannel#canBubble() bubbles}.</p>
*
- * <p>Notifications with a valid and allowed app overlay intent will be displayed as
- * floating windows outside of the notification shade on unlocked devices. When a user
- * interacts with one of these windows, this app overlay intent will be invoked and
- * displayed.</p>
+ * <b>Notifications with a valid and allowed bubble metadata will display in collapsed state
+ * outside of the notification shade on unlocked devices. When a user interacts with the
+ * collapsed state, the bubble intent will be invoked and displayed.</b>
*/
- public Builder setAppOverlayIntent(PendingIntent intent) {
- mN.mAppOverlayIntent = intent;
+ public Builder setBubbleMetadata(BubbleMetadata data) {
+ mN.mBubbleMetadata = data;
return this;
}
@@ -8422,6 +8421,186 @@
}
}
+ /**
+ * Encapsulates the information needed to display a notification as a bubble.
+ *
+ * <p>A bubble is used to display app content in a floating window over the existing
+ * foreground activity. A bubble has a collapsed state represented by an icon,
+ * {@link BubbleMetadata.Builder#setIcon(Icon)} and an expanded state which is populated
+ * via {@link BubbleMetadata.Builder#setIntent(PendingIntent)}.</p>
+ *
+ * <b>Notifications with a valid and allowed bubble will display in collapsed state
+ * outside of the notification shade on unlocked devices. When a user interacts with the
+ * collapsed bubble, the bubble intent will be invoked and displayed.</b>
+ *
+ * @see Notification.Builder#setBubbleMetadata(BubbleMetadata)
+ */
+ public static final class BubbleMetadata implements Parcelable {
+
+ private PendingIntent mPendingIntent;
+ private CharSequence mTitle;
+ private Icon mIcon;
+ private int mDesiredHeight;
+
+ private BubbleMetadata(PendingIntent intent, CharSequence title, Icon icon, int height) {
+ mPendingIntent = intent;
+ mTitle = title;
+ mIcon = icon;
+ mDesiredHeight = height;
+ }
+
+ private BubbleMetadata(Parcel in) {
+ mPendingIntent = PendingIntent.CREATOR.createFromParcel(in);
+ mTitle = in.readCharSequence();
+ mIcon = Icon.CREATOR.createFromParcel(in);
+ mDesiredHeight = in.readInt();
+ }
+
+ /**
+ * @return the pending intent used to populate the floating window for this bubble.
+ */
+ public PendingIntent getIntent() {
+ return mPendingIntent;
+ }
+
+ /**
+ * @return the title that will appear along with the app content defined by
+ * {@link #getIntent()} for this bubble.
+ */
+ public CharSequence getTitle() {
+ return mTitle;
+ }
+
+ /**
+ * @return the icon that will be displayed for this bubble when it is collapsed.
+ */
+ public Icon getIcon() {
+ return mIcon;
+ }
+
+ /**
+ * @return the ideal height for the floating window that app content defined by
+ * {@link #getIntent()} for this bubble.
+ */
+ public int getDesiredHeight() {
+ return mDesiredHeight;
+ }
+
+ public static final Parcelable.Creator<BubbleMetadata> CREATOR =
+ new Parcelable.Creator<BubbleMetadata>() {
+
+ @Override
+ public BubbleMetadata createFromParcel(Parcel source) {
+ return new BubbleMetadata(source);
+ }
+
+ @Override
+ public BubbleMetadata[] newArray(int size) {
+ return new BubbleMetadata[size];
+ }
+ };
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel out, int flags) {
+ mPendingIntent.writeToParcel(out, 0);
+ out.writeCharSequence(mTitle);
+ mIcon.writeToParcel(out, 0);
+ out.writeInt(mDesiredHeight);
+ }
+
+ /**
+ * Builder to construct a {@link BubbleMetadata} object.
+ */
+ public static class Builder {
+
+ private PendingIntent mPendingIntent;
+ private CharSequence mTitle;
+ private Icon mIcon;
+ private int mDesiredHeight;
+
+ /**
+ * Constructs a new builder object.
+ */
+ public Builder() {
+ }
+
+ /**
+ * Sets the intent that will be used when the bubble is expanded. This will display the
+ * app content in a floating window over the existing foreground activity.
+ */
+ public BubbleMetadata.Builder setIntent(PendingIntent intent) {
+ if (intent == null) {
+ throw new IllegalArgumentException("Bubble requires non-null pending intent");
+ }
+ mPendingIntent = intent;
+ return this;
+ }
+
+ /**
+ * Sets the title that will appear along with the app content for this bubble.
+ *
+ * <p>A title is required and should expect to fit on a single line and make sense when
+ * shown with the content defined by {@link #setIntent(PendingIntent)}.</p>
+ */
+ public BubbleMetadata.Builder setTitle(CharSequence title) {
+ if (TextUtils.isEmpty(title)) {
+ throw new IllegalArgumentException("Bubbles require non-null or empty title");
+ }
+ mTitle = title;
+ return this;
+ }
+
+ /**
+ * Sets the icon that will represent the bubble when it is collapsed.
+ *
+ * <p>An icon is required and should be representative of the content within the bubble.
+ * If your app produces multiple bubbles, the image should be unique for each of them.
+ * </p>
+ */
+ public BubbleMetadata.Builder setIcon(Icon icon) {
+ if (icon == null) {
+ throw new IllegalArgumentException("Bubbles require non-null icon");
+ }
+ mIcon = icon;
+ return this;
+ }
+
+ /**
+ * Sets the desired height for the app content defined by
+ * {@link #setIntent(PendingIntent)}, this height may not be respected if there is not
+ * enough space on the screen or if the provided height is too small to be useful.
+ */
+ public BubbleMetadata.Builder setDesiredHeight(int height) {
+ mDesiredHeight = Math.max(height, 0);
+ return this;
+ }
+
+ /**
+ * Creates the {@link BubbleMetadata} defined by this builder.
+ * <p>Will throw {@link IllegalStateException} if required fields have not been set
+ * on this builder.</p>
+ */
+ public BubbleMetadata build() {
+ if (mPendingIntent == null) {
+ throw new IllegalStateException("Must supply pending intent to bubble");
+ }
+ if (TextUtils.isEmpty(mTitle)) {
+ throw new IllegalStateException("Must supply a title for the bubble");
+ }
+ if (mIcon == null) {
+ throw new IllegalStateException("Must supply an icon for the bubble");
+ }
+ return new BubbleMetadata(mPendingIntent, mTitle, mIcon, mDesiredHeight);
+ }
+ }
+ }
+
+
// When adding a new Style subclass here, don't forget to update
// Builder.getNotificationStyleClass.
diff --git a/core/java/android/app/NotificationChannel.java b/core/java/android/app/NotificationChannel.java
index 950e9aa..e95d62f 100644
--- a/core/java/android/app/NotificationChannel.java
+++ b/core/java/android/app/NotificationChannel.java
@@ -85,7 +85,7 @@
private static final String ATT_FG_SERVICE_SHOWN = "fgservice";
private static final String ATT_GROUP = "group";
private static final String ATT_BLOCKABLE_SYSTEM = "blockable_system";
- private static final String ATT_ALLOW_APP_OVERLAY = "app_overlay";
+ private static final String ATT_ALLOW_BUBBLE = "allow_bubble";
private static final String DELIMITER = ",";
/**
@@ -121,7 +121,7 @@
/**
* @hide
*/
- public static final int USER_LOCKED_ALLOW_APP_OVERLAY = 0x00000100;
+ public static final int USER_LOCKED_ALLOW_BUBBLE = 0x00000100;
/**
* @hide
@@ -134,7 +134,7 @@
USER_LOCKED_VIBRATION,
USER_LOCKED_SOUND,
USER_LOCKED_SHOW_BADGE,
- USER_LOCKED_ALLOW_APP_OVERLAY
+ USER_LOCKED_ALLOW_BUBBLE
};
private static final int DEFAULT_LIGHT_COLOR = 0;
@@ -144,7 +144,7 @@
NotificationManager.IMPORTANCE_UNSPECIFIED;
private static final boolean DEFAULT_DELETED = false;
private static final boolean DEFAULT_SHOW_BADGE = true;
- private static final boolean DEFAULT_ALLOW_APP_OVERLAY = true;
+ private static final boolean DEFAULT_ALLOW_BUBBLE = true;
@UnsupportedAppUsage
private final String mId;
@@ -168,7 +168,7 @@
private AudioAttributes mAudioAttributes = Notification.AUDIO_ATTRIBUTES_DEFAULT;
// If this is a blockable system notification channel.
private boolean mBlockableSystem = false;
- private boolean mAllowAppOverlay = DEFAULT_ALLOW_APP_OVERLAY;
+ private boolean mAllowBubbles = DEFAULT_ALLOW_BUBBLE;
private boolean mImportanceLockedByOEM;
/**
@@ -231,7 +231,7 @@
mAudioAttributes = in.readInt() > 0 ? AudioAttributes.CREATOR.createFromParcel(in) : null;
mLightColor = in.readInt();
mBlockableSystem = in.readBoolean();
- mAllowAppOverlay = in.readBoolean();
+ mAllowBubbles = in.readBoolean();
mImportanceLockedByOEM = in.readBoolean();
}
@@ -285,7 +285,7 @@
}
dest.writeInt(mLightColor);
dest.writeBoolean(mBlockableSystem);
- dest.writeBoolean(mAllowAppOverlay);
+ dest.writeBoolean(mAllowBubbles);
dest.writeBoolean(mImportanceLockedByOEM);
}
@@ -480,7 +480,7 @@
/**
* Sets whether notifications posted to this channel can appear outside of the notification
- * shade, floating over other apps' content.
+ * shade, floating over other apps' content as a bubble.
*
* <p>This value will be ignored for channels that aren't allowed to pop on screen (that is,
* channels whose {@link #getImportance() importance} is <
@@ -488,10 +488,10 @@
*
* <p>Only modifiable before the channel is submitted to
* * {@link NotificationManager#createNotificationChannel(NotificationChannel)}.</p>
- * @see Notification#getAppOverlayIntent()
+ * @see Notification#getBubbleMetadata()
*/
- public void setAllowAppOverlay(boolean allowAppOverlay) {
- mAllowAppOverlay = allowAppOverlay;
+ public void setAllowBubbles(boolean allowBubbles) {
+ mAllowBubbles = allowBubbles;
}
/**
@@ -610,16 +610,16 @@
* Returns whether notifications posted to this channel can display outside of the notification
* shade, in a floating window on top of other apps.
*/
- public boolean canOverlayApps() {
- return isAppOverlayAllowed() && getImportance() >= IMPORTANCE_HIGH;
+ public boolean canBubble() {
+ return isBubbleAllowed() && getImportance() >= IMPORTANCE_HIGH;
}
/**
- * Like {@link #canOverlayApps()}, but only checks the permission, not the importance.
+ * Like {@link #canBubble()}, but only checks the permission, not the importance.
* @hide
*/
- public boolean isAppOverlayAllowed() {
- return mAllowAppOverlay;
+ public boolean isBubbleAllowed() {
+ return mAllowBubbles;
}
/**
@@ -719,7 +719,7 @@
lockFields(safeInt(parser, ATT_USER_LOCKED, 0));
setFgServiceShown(safeBool(parser, ATT_FG_SERVICE_SHOWN, false));
setBlockableSystem(safeBool(parser, ATT_BLOCKABLE_SYSTEM, false));
- setAllowAppOverlay(safeBool(parser, ATT_ALLOW_APP_OVERLAY, DEFAULT_ALLOW_APP_OVERLAY));
+ setAllowBubbles(safeBool(parser, ATT_ALLOW_BUBBLE, DEFAULT_ALLOW_BUBBLE));
}
@Nullable
@@ -838,8 +838,8 @@
if (isBlockableSystem()) {
out.attribute(null, ATT_BLOCKABLE_SYSTEM, Boolean.toString(isBlockableSystem()));
}
- if (canOverlayApps() != DEFAULT_ALLOW_APP_OVERLAY) {
- out.attribute(null, ATT_ALLOW_APP_OVERLAY, Boolean.toString(canOverlayApps()));
+ if (canBubble() != DEFAULT_ALLOW_BUBBLE) {
+ out.attribute(null, ATT_ALLOW_BUBBLE, Boolean.toString(canBubble()));
}
out.endTag(null, TAG_CHANNEL);
@@ -883,7 +883,7 @@
record.put(ATT_DELETED, Boolean.toString(isDeleted()));
record.put(ATT_GROUP, getGroup());
record.put(ATT_BLOCKABLE_SYSTEM, isBlockableSystem());
- record.put(ATT_ALLOW_APP_OVERLAY, canOverlayApps());
+ record.put(ATT_ALLOW_BUBBLE, canBubble());
return record;
}
@@ -983,7 +983,7 @@
&& mShowBadge == that.mShowBadge
&& isDeleted() == that.isDeleted()
&& isBlockableSystem() == that.isBlockableSystem()
- && mAllowAppOverlay == that.mAllowAppOverlay
+ && mAllowBubbles == that.mAllowBubbles
&& Objects.equals(getId(), that.getId())
&& Objects.equals(getName(), that.getName())
&& Objects.equals(mDesc, that.mDesc)
@@ -1000,7 +1000,7 @@
getLockscreenVisibility(), getSound(), mLights, getLightColor(),
getUserLockedFields(),
isFgServiceShown(), mVibrationEnabled, mShowBadge, isDeleted(), getGroup(),
- getAudioAttributes(), isBlockableSystem(), mAllowAppOverlay,
+ getAudioAttributes(), isBlockableSystem(), mAllowBubbles,
mImportanceLockedByOEM);
result = 31 * result + Arrays.hashCode(mVibration);
return result;
@@ -1028,7 +1028,7 @@
+ ", mGroup='" + mGroup + '\''
+ ", mAudioAttributes=" + mAudioAttributes
+ ", mBlockableSystem=" + mBlockableSystem
- + ", mAllowAppOverlay=" + mAllowAppOverlay
+ + ", mAllowBubbles=" + mAllowBubbles
+ ", mImportanceLockedByOEM=" + mImportanceLockedByOEM
+ '}';
pw.println(prefix + output);
@@ -1055,7 +1055,7 @@
+ ", mGroup='" + mGroup + '\''
+ ", mAudioAttributes=" + mAudioAttributes
+ ", mBlockableSystem=" + mBlockableSystem
- + ", mAllowAppOverlay=" + mAllowAppOverlay
+ + ", mAllowBubbles=" + mAllowBubbles
+ ", mImportanceLockedByOEM=" + mImportanceLockedByOEM
+ '}';
}
@@ -1090,7 +1090,7 @@
mAudioAttributes.writeToProto(proto, NotificationChannelProto.AUDIO_ATTRIBUTES);
}
proto.write(NotificationChannelProto.IS_BLOCKABLE_SYSTEM, mBlockableSystem);
- proto.write(NotificationChannelProto.ALLOW_APP_OVERLAY, mAllowAppOverlay);
+ proto.write(NotificationChannelProto.ALLOW_APP_OVERLAY, mAllowBubbles);
proto.end(token);
}
diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java
index aad3253..43614fe 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -1080,14 +1080,14 @@
* notification shade, floating over other apps' content.
*
* <p>This value will be ignored for notifications that are posted to channels that do not
- * allow app overlays ({@link NotificationChannel#canOverlayApps()}.
+ * allow bubbles ({@link NotificationChannel#canBubble()}.
*
- * @see Notification#getAppOverlayIntent()
+ * @see Notification#getBubbleMetadata()
*/
- public boolean areAppOverlaysAllowed() {
+ public boolean areBubblesAllowed() {
INotificationManager service = getService();
try {
- return service.areAppOverlaysAllowed(mContext.getPackageName());
+ return service.areBubblesAllowed(mContext.getPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 636a70f..b845673 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -5555,26 +5555,24 @@
}
/**
- * @deprecated This function no longer does anything; it was an old
- * approach to managing preferred activities, which has been superseded
- * by (and conflicts with) the modern activity-based preferences.
+ * @deprecated This function no longer does anything. It is the platform's
+ * responsibility to assign preferred activities and this cannot be modified
+ * directly. To determine the activities resolved by the platform, use
+ * {@link #resolveActivity} or {@link #queryIntentActivities}.
*/
@Deprecated
public abstract void addPackageToPreferred(String packageName);
/**
- * @deprecated This function no longer does anything; it was an old
- * approach to managing preferred activities, which has been superseded
- * by (and conflicts with) the modern activity-based preferences.
+ * @deprecated This function no longer does anything. It is the platform's
+ * responsibility to assign preferred activities and this cannot be modified
+ * directly. To determine the activities resolved by the platform, use
+ * {@link #resolveActivity} or {@link #queryIntentActivities}.
*/
@Deprecated
public abstract void removePackageFromPreferred(String packageName);
/**
- * @deprecated This function no longer does anything; it was an old
- * approach to managing preferred activities, which has been superseded
- * by (and conflicts with) the modern activity-based preferences.
- *
* Retrieve the list of all currently configured preferred packages. The
* first package on the list is the most preferred, the last is the least
* preferred.
@@ -5582,15 +5580,16 @@
* @param flags Additional option flags to modify the data returned.
* @return A List of PackageInfo objects, one for each preferred
* application, in order of preference.
+ *
+ * @deprecated This function no longer does anything. It is the platform's
+ * responsibility to assign preferred activities and this cannot be modified
+ * directly. To determine the activities resolved by the platform, use
+ * {@link #resolveActivity} or {@link #queryIntentActivities}.
*/
@Deprecated
public abstract List<PackageInfo> getPreferredPackages(@PackageInfoFlags int flags);
/**
- * @deprecated This is a protected API that should not have been available
- * to third party applications. It is the platform's responsibility for
- * assigning preferred activities and this cannot be directly modified.
- *
* Add a new preferred activity mapping to the system. This will be used
* to automatically select the given activity component when
* {@link Context#startActivity(Intent) Context.startActivity()} finds
@@ -5604,20 +5603,26 @@
* this preference was made.
* @param activity The component name of the activity that is to be
* preferred.
+ *
+ * @deprecated This function no longer does anything. It is the platform's
+ * responsibility to assign preferred activities and this cannot be modified
+ * directly. To determine the activities resolved by the platform, use
+ * {@link #resolveActivity} or {@link #queryIntentActivities}.
*/
@Deprecated
public abstract void addPreferredActivity(IntentFilter filter, int match,
ComponentName[] set, ComponentName activity);
/**
- * @deprecated This is a protected API that should not have been available
- * to third party applications. It is the platform's responsibility for
- * assigning preferred activities and this cannot be directly modified.
- *
* Same as {@link #addPreferredActivity(IntentFilter, int,
ComponentName[], ComponentName)}, but with a specific userId to apply the preference
to.
* @hide
+ *
+ * @deprecated This function no longer does anything. It is the platform's
+ * responsibility to assign preferred activities and this cannot be modified
+ * directly. To determine the activities resolved by the platform, use
+ * {@link #resolveActivity} or {@link #queryIntentActivities}.
*/
@Deprecated
@UnsupportedAppUsage
@@ -5627,10 +5632,6 @@
}
/**
- * @deprecated This is a protected API that should not have been available
- * to third party applications. It is the platform's responsibility for
- * assigning preferred activities and this cannot be directly modified.
- *
* Replaces an existing preferred activity mapping to the system, and if that were not present
* adds a new preferred activity. This will be used
* to automatically select the given activity component when
@@ -5645,7 +5646,13 @@
* this preference was made.
* @param activity The component name of the activity that is to be
* preferred.
+ *
* @hide
+ *
+ * @deprecated This function no longer does anything. It is the platform's
+ * responsibility to assign preferred activities and this cannot be modified
+ * directly. To determine the activities resolved by the platform, use
+ * {@link #resolveActivity} or {@link #queryIntentActivities}.
*/
@Deprecated
@UnsupportedAppUsage
@@ -5653,10 +5660,6 @@
ComponentName[] set, ComponentName activity);
/**
- * @deprecated This is a protected API that should not have been available
- * to third party applications. It is the platform's responsibility for
- * assigning preferred activities and this cannot be directly modified.
- *
* Replaces an existing preferred activity mapping to the system, and if that were not present
* adds a new preferred activity. This will be used to automatically select the given activity
* component when {@link Context#startActivity(Intent) Context.startActivity()} finds multiple
@@ -5671,6 +5674,11 @@
* @param activity The component name of the activity that is to be preferred.
*
* @hide
+ *
+ * @deprecated This function no longer does anything. It is the platform's
+ * responsibility to assign preferred activities and this cannot be modified
+ * directly. To determine the activities resolved by the platform, use
+ * {@link #resolveActivity} or {@link #queryIntentActivities}.
*/
@Deprecated
@SystemApi
@@ -5681,6 +5689,11 @@
/**
* @hide
+ *
+ * @deprecated This function no longer does anything. It is the platform's
+ * responsibility to assign preferred activities and this cannot be modified
+ * directly. To determine the activities resolved by the platform, use
+ * {@link #resolveActivity} or {@link #queryIntentActivities}.
*/
@Deprecated
@UnsupportedAppUsage
@@ -5690,10 +5703,6 @@
}
/**
- * @deprecated This function no longer does anything; it was an old
- * approach to managing preferred activities, which has been superseded
- * by (and conflicts with) the modern activity-based preferences.
- *
* Remove all preferred activity mappings, previously added with
* {@link #addPreferredActivity}, from the
* system whose activities are implemented in the given package name.
@@ -5701,15 +5710,16 @@
*
* @param packageName The name of the package whose preferred activity
* mappings are to be removed.
+ *
+ * @deprecated This function no longer does anything. It is the platform's
+ * responsibility to assign preferred activities and this cannot be modified
+ * directly. To determine the activities resolved by the platform, use
+ * {@link #resolveActivity} or {@link #queryIntentActivities}.
*/
@Deprecated
public abstract void clearPackagePreferredActivities(String packageName);
/**
- * @deprecated This function no longer does anything; it was an old
- * approach to managing preferred activities, which has been superseded
- * by (and conflicts with) the modern activity-based preferences.
- *
* Retrieve all preferred activities, previously added with
* {@link #addPreferredActivity}, that are
* currently registered with the system.
@@ -5725,6 +5735,11 @@
* @return Returns the total number of registered preferred activities
* (the number of distinct IntentFilter records, not the number of unique
* activity components) that were found.
+ *
+ * @deprecated This function no longer does anything. It is the platform's
+ * responsibility to assign preferred activities and this cannot be modified
+ * directly. To determine the activities resolved by the platform, use
+ * {@link #resolveActivity} or {@link #queryIntentActivities}.
*/
@Deprecated
public abstract int getPreferredActivities(@NonNull List<IntentFilter> outFilters,
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index 0fc50c6..1ac0ab6 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -2656,6 +2656,23 @@
}
/**
+ * Matches a given {@code targetCode} against a set of release codeNames. Target codes can
+ * either be of the form {@code [codename]}" (e.g {@code "Q"}) or of the form
+ * {@code [codename].[fingerprint]} (e.g {@code "Q.cafebc561"}).
+ */
+ private static boolean matchTargetCode(@NonNull String[] codeNames,
+ @NonNull String targetCode) {
+ final String targetCodeName;
+ final int targetCodeIdx = targetCode.indexOf('.');
+ if (targetCodeIdx == -1) {
+ targetCodeName = targetCode;
+ } else {
+ targetCodeName = targetCode.substring(0, targetCodeIdx);
+ }
+ return ArrayUtils.contains(codeNames, targetCodeName);
+ }
+
+ /**
* Computes the targetSdkVersion to use at runtime. If the package is not
* compatible with this platform, populates {@code outError[0]} with an
* error message.
@@ -2698,7 +2715,7 @@
// If it's a pre-release SDK and the codename matches this platform, it
// definitely targets this SDK.
- if (ArrayUtils.contains(platformSdkCodenames, targetCode) || forceCurrentDev) {
+ if (matchTargetCode(platformSdkCodenames, targetCode) || forceCurrentDev) {
return Build.VERSION_CODES.CUR_DEVELOPMENT;
}
@@ -2831,7 +2848,7 @@
// If it's a pre-release SDK and the codename matches this platform, we
// definitely meet the minimum SDK requirement.
- if (ArrayUtils.contains(platformSdkCodenames, minCode)) {
+ if (matchTargetCode(platformSdkCodenames, minCode)) {
return Build.VERSION_CODES.CUR_DEVELOPMENT;
}
diff --git a/core/java/android/content/pm/PermissionInfo.java b/core/java/android/content/pm/PermissionInfo.java
index bb8c92d..a3395ac 100644
--- a/core/java/android/content/pm/PermissionInfo.java
+++ b/core/java/android/content/pm/PermissionInfo.java
@@ -158,6 +158,7 @@
* @hide
*/
@SystemApi
+ @TestApi
public static final int PROTECTION_FLAG_OEM = 0x4000;
/**
diff --git a/core/java/android/content/res/AssetManager.java b/core/java/android/content/res/AssetManager.java
index f1a4db2..9e0a9ba 100644
--- a/core/java/android/content/res/AssetManager.java
+++ b/core/java/android/content/res/AssetManager.java
@@ -732,6 +732,38 @@
}
}
+ /**
+ * Enable resource resolution logging to track the steps taken to resolve the last resource
+ * entry retrieved. Stores the configuration and package names for each step.
+ *
+ * Default disabled.
+ *
+ * @param enabled Boolean indicating whether to enable or disable logging.
+ *
+ * @hide
+ */
+ public void setResourceResolutionLoggingEnabled(boolean enabled) {
+ synchronized (this) {
+ ensureValidLocked();
+ nativeSetResourceResolutionLoggingEnabled(mObject, enabled);
+ }
+ }
+
+ /**
+ * Retrieve the last resource resolution path logged.
+ *
+ * @return Formatted string containing last resource ID/name and steps taken to resolve final
+ * entry, including configuration and package names.
+ *
+ * @hide
+ */
+ public @Nullable String getLastResourceResolution() {
+ synchronized (this) {
+ ensureValidLocked();
+ return nativeGetLastResourceResolution(mObject);
+ }
+ }
+
CharSequence getPooledStringForCookie(int cookie, int id) {
// Cookies map to ApkAssets starting at 1.
return getApkAssets()[cookie - 1].getStringFromPool(id);
@@ -1383,6 +1415,8 @@
private static native @Nullable String nativeGetResourceEntryName(long ptr, @AnyRes int resid);
private static native @Nullable String[] nativeGetLocales(long ptr, boolean excludeSystem);
private static native @Nullable Configuration[] nativeGetSizeConfigurations(long ptr);
+ private static native void nativeSetResourceResolutionLoggingEnabled(long ptr, boolean enabled);
+ private static native @Nullable String nativeGetLastResourceResolution(long ptr);
// Style attribute retrieval native methods.
private static native void nativeApplyStyle(long ptr, long themePtr, @AttrRes int defStyleAttr,
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java
index 365ceac..c4b315e 100644
--- a/core/java/android/content/res/Resources.java
+++ b/core/java/android/content/res/Resources.java
@@ -2010,22 +2010,36 @@
public String getResourceTypeName(@AnyRes int resid) throws NotFoundException {
return mResourcesImpl.getResourceTypeName(resid);
}
-
+
/**
* Return the entry name for a given resource identifier.
- *
+ *
* @param resid The resource identifier whose entry name is to be
* retrieved.
- *
+ *
* @return A string holding the entry name of the resource.
- *
+ *
* @throws NotFoundException Throws NotFoundException if the given ID does not exist.
- *
+ *
* @see #getResourceName
*/
public String getResourceEntryName(@AnyRes int resid) throws NotFoundException {
return mResourcesImpl.getResourceEntryName(resid);
}
+
+ /**
+ * Return formatted log of the last retrieved resource's resolution path.
+ *
+ * @return A string holding a formatted log of the steps taken to resolve the last resource.
+ *
+ * @throws NotFoundException Throws NotFoundException if there hasn't been a resource
+ * resolved yet.
+ *
+ * @hide
+ */
+ public String getLastResourceResolution() throws NotFoundException {
+ return mResourcesImpl.getLastResourceResolution();
+ }
/**
* Parse a series of {@link android.R.styleable#Extra <extra>} tags from
diff --git a/core/java/android/content/res/ResourcesImpl.java b/core/java/android/content/res/ResourcesImpl.java
index 2ad4f62..77796d9 100644
--- a/core/java/android/content/res/ResourcesImpl.java
+++ b/core/java/android/content/res/ResourcesImpl.java
@@ -299,6 +299,13 @@
}
@NonNull
+ String getLastResourceResolution() throws NotFoundException {
+ String str = mAssets.getLastResourceResolution();
+ if (str != null) return str;
+ throw new NotFoundException("Associated AssetManager hasn't resolved a resource");
+ }
+
+ @NonNull
CharSequence getQuantityText(@PluralsRes int id, int quantity) throws NotFoundException {
PluralRules rule = getPluralRule();
CharSequence res = mAssets.getResourceBagText(id,
diff --git a/core/java/android/hardware/display/DisplayManagerGlobal.java b/core/java/android/hardware/display/DisplayManagerGlobal.java
index cda8498..7e45441 100644
--- a/core/java/android/hardware/display/DisplayManagerGlobal.java
+++ b/core/java/android/hardware/display/DisplayManagerGlobal.java
@@ -436,6 +436,7 @@
public void setVirtualDisplaySurface(IVirtualDisplayCallback token, Surface surface) {
try {
mDm.setVirtualDisplaySurface(token, surface);
+ setVirtualDisplayState(token, surface != null);
} catch (RemoteException ex) {
throw ex.rethrowFromSystemServer();
}
@@ -458,6 +459,14 @@
}
}
+ void setVirtualDisplayState(IVirtualDisplayCallback token, boolean isOn) {
+ try {
+ mDm.setVirtualDisplayState(token, isOn);
+ } catch (RemoteException ex) {
+ throw ex.rethrowFromSystemServer();
+ }
+ }
+
/**
* Gets the stable device display size, in pixels.
*/
diff --git a/core/java/android/hardware/display/IDisplayManager.aidl b/core/java/android/hardware/display/IDisplayManager.aidl
index 2d81cdf..aae8afb 100644
--- a/core/java/android/hardware/display/IDisplayManager.aidl
+++ b/core/java/android/hardware/display/IDisplayManager.aidl
@@ -82,6 +82,9 @@
// No permissions required but must be same Uid as the creator.
void releaseVirtualDisplay(in IVirtualDisplayCallback token);
+ // No permissions required but must be same Uid as the creator.
+ void setVirtualDisplayState(in IVirtualDisplayCallback token, boolean isOn);
+
// Get a stable metric for the device's display size. No permissions required.
Point getStableDisplaySize();
diff --git a/core/java/android/hardware/display/VirtualDisplay.java b/core/java/android/hardware/display/VirtualDisplay.java
index d354666..bf62c95 100644
--- a/core/java/android/hardware/display/VirtualDisplay.java
+++ b/core/java/android/hardware/display/VirtualDisplay.java
@@ -104,6 +104,18 @@
}
}
+ /**
+ * Sets the on/off state for a virtual display.
+ *
+ * @param isOn Whether the display should be on or off.
+ * @hide
+ */
+ public void setDisplayState(boolean isOn) {
+ if (mToken != null) {
+ mGlobal.setVirtualDisplayState(mToken, isOn);
+ }
+ }
+
@Override
public String toString() {
return "VirtualDisplay{display=" + mDisplay + ", token=" + mToken
diff --git a/core/java/android/hardware/hdmi/HdmiAudioSystemClient.java b/core/java/android/hardware/hdmi/HdmiAudioSystemClient.java
index d382eb9..bdd5ab6 100644
--- a/core/java/android/hardware/hdmi/HdmiAudioSystemClient.java
+++ b/core/java/android/hardware/hdmi/HdmiAudioSystemClient.java
@@ -15,10 +15,12 @@
*/
package android.hardware.hdmi;
+import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
+import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting.Visibility;
@@ -56,6 +58,21 @@
mHandler = handler == null ? new Handler(Looper.getMainLooper()) : handler;
}
+ /**
+ * Callback interface used to get the set System Audio Mode result.
+ *
+ * @hide
+ */
+ // TODO(b/110094868): unhide and add @SystemApi for Q
+ public interface SetSystemAudioModeCallback {
+ /**
+ * Called when the input was changed.
+ *
+ * @param result the result of the set System Audio Mode
+ */
+ void onComplete(int result);
+ }
+
/** @hide */
// TODO(b/110094868): unhide and add @SystemApi for Q
@Override
@@ -117,4 +134,34 @@
mPendingReportAudioStatus = true;
}
}
+
+ /**
+ * Set System Audio Mode on/off with audio system device.
+ *
+ * @param state true to set System Audio Mode on. False to set off.
+ * @param callback callback offer the setting result.
+ *
+ * @hide
+ */
+ // TODO(b/110094868): unhide and add @SystemApi for Q
+ public void setSystemAudioMode(boolean state, @NonNull SetSystemAudioModeCallback callback) {
+ // TODO(amyjojo): implement this when needed.
+ }
+
+ /**
+ * When device is switching to an audio only source, this method is called to broadcast
+ * a setSystemAudioMode on message to the HDMI CEC system without querying Active Source or
+ * TV supporting System Audio Control or not. This is to get volume control passthrough
+ * from STB even if TV does not support it.
+ *
+ * @hide
+ */
+ // TODO(b/110094868): unhide and add @SystemApi for Q
+ public void setSystemAudioModeOnForAudioOnlySource() {
+ try {
+ mService.setSystemAudioModeOnForAudioOnlySource();
+ } catch (RemoteException e) {
+ Log.d(TAG, "Failed to set System Audio Mode on for Audio Only source");
+ }
+ }
}
diff --git a/core/java/android/hardware/hdmi/HdmiControlManager.java b/core/java/android/hardware/hdmi/HdmiControlManager.java
index f5d288e..a7734f5 100644
--- a/core/java/android/hardware/hdmi/HdmiControlManager.java
+++ b/core/java/android/hardware/hdmi/HdmiControlManager.java
@@ -33,6 +33,8 @@
import android.util.ArrayMap;
import android.util.Log;
+import java.util.List;
+
/**
* The {@link HdmiControlManager} class is used to send HDMI control messages
* to attached CEC devices.
@@ -404,6 +406,72 @@
}
/**
+ * Get a snapshot of the real-time status of the remote devices.
+ *
+ * @return a list of {@link HdmiDeviceInfo} of the devices connected to the current device.
+ *
+ * TODO(b/110094868): unhide for Q
+ * @hide
+ */
+ public List<HdmiDeviceInfo> getConnectedDevicesList() {
+ try {
+ return mService.getDeviceList();
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Power off the target device.
+ *
+ * @param deviceInfo HdmiDeviceInfo of the device to be powered off
+ *
+ * TODO(b/110094868): unhide for Q
+ * @hide
+ */
+ public void powerOffRemoteDevice(HdmiDeviceInfo deviceInfo) {
+ try {
+ mService.powerOffRemoteDevice(
+ deviceInfo.getLogicalAddress(), deviceInfo.getDevicePowerStatus());
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Power on the target device.
+ *
+ * @param deviceInfo HdmiDeviceInfo of the device to be powered on
+ *
+ * TODO(b/110094868): unhide for Q
+ * @hide
+ */
+ public void powerOnRemoteDevice(HdmiDeviceInfo deviceInfo) {
+ try {
+ mService.powerOnRemoteDevice(
+ deviceInfo.getLogicalAddress(), deviceInfo.getDevicePowerStatus());
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Ask the target device to be the new Active Source.
+ *
+ * @param deviceInfo HdmiDeviceInfo of the target device
+ *
+ * TODO(b/110094868): unhide for Q
+ * @hide
+ */
+ public void askRemoteDeviceToBecomeActiveSource(HdmiDeviceInfo deviceInfo) {
+ try {
+ mService.askRemoteDeviceToBecomeActiveSource(deviceInfo.getPhysicalAddress());
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Controls standby mode of the system. It will also try to turn on/off the connected devices if
* necessary.
*
@@ -432,6 +500,19 @@
}
/**
+ * Get the physical address of the device.
+ *
+ * @hide
+ */
+ public int getPhysicalAddress() {
+ try {
+ return mService.getPhysicalAddress();
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Listener used to get hotplug event from HDMI port.
*/
public interface HotplugEventListener {
diff --git a/core/java/android/hardware/hdmi/IHdmiControlService.aidl b/core/java/android/hardware/hdmi/IHdmiControlService.aidl
index 2b8d00b..1cd9920 100644
--- a/core/java/android/hardware/hdmi/IHdmiControlService.aidl
+++ b/core/java/android/hardware/hdmi/IHdmiControlService.aidl
@@ -50,6 +50,7 @@
List<HdmiPortInfo> getPortInfo();
boolean canChangeSystemAudioMode();
boolean getSystemAudioMode();
+ int getPhysicalAddress();
void setSystemAudioMode(boolean enabled, IHdmiControlCallback callback);
void addSystemAudioModeChangeListener(IHdmiSystemAudioModeChangeListener listener);
void removeSystemAudioModeChangeListener(IHdmiSystemAudioModeChangeListener listener);
@@ -60,6 +61,9 @@
void setInputChangeListener(IHdmiInputChangeListener listener);
List<HdmiDeviceInfo> getInputDevices();
List<HdmiDeviceInfo> getDeviceList();
+ void powerOffRemoteDevice(int logicalAddress, int powerStatus);
+ void powerOnRemoteDevice(int logicalAddress, int powerStatus);
+ void askRemoteDeviceToBecomeActiveSource(int physicalAddress);
void sendVendorCommand(int deviceType, int targetAddress, in byte[] params,
boolean hasVendorId);
void addVendorCommandListener(IHdmiVendorCommandListener listener, int deviceType);
@@ -73,4 +77,5 @@
void addHdmiMhlVendorCommandListener(IHdmiMhlVendorCommandListener listener);
void setStandbyMode(boolean isStandbyModeOn);
void reportAudioStatus(int deviceType, int volume, int maxVolume, boolean isMute);
+ void setSystemAudioModeOnForAudioOnlySource();
}
diff --git a/core/java/android/net/LinkProperties.java b/core/java/android/net/LinkProperties.java
index 617125b3..c2963fd 100644
--- a/core/java/android/net/LinkProperties.java
+++ b/core/java/android/net/LinkProperties.java
@@ -191,6 +191,7 @@
}
setMtu(source.mMtu);
mTcpBufferSizes = source.mTcpBufferSizes;
+ mNat64Prefix = source.mNat64Prefix;
}
}
diff --git a/core/java/android/net/ipmemorystore/NetworkAttributes.java b/core/java/android/net/ipmemorystore/NetworkAttributes.java
index d7e5b27..b932d21 100644
--- a/core/java/android/net/ipmemorystore/NetworkAttributes.java
+++ b/core/java/android/net/ipmemorystore/NetworkAttributes.java
@@ -28,6 +28,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import java.util.StringJoiner;
/**
* A POD object to represent attributes of a single L2 network entry.
@@ -207,4 +208,52 @@
public int hashCode() {
return Objects.hash(assignedV4Address, groupHint, dnsAddresses, mtu);
}
+
+ /** Pretty print */
+ @Override
+ public String toString() {
+ final StringJoiner resultJoiner = new StringJoiner(" ", "{", "}");
+ final ArrayList<String> nullFields = new ArrayList<>();
+
+ if (null != assignedV4Address) {
+ resultJoiner.add("assignedV4Addr :");
+ resultJoiner.add(assignedV4Address.toString());
+ } else {
+ nullFields.add("assignedV4Addr");
+ }
+
+ if (null != groupHint) {
+ resultJoiner.add("groupHint :");
+ resultJoiner.add(groupHint);
+ } else {
+ nullFields.add("groupHint");
+ }
+
+ if (null != dnsAddresses) {
+ resultJoiner.add("dnsAddr : [");
+ for (final InetAddress addr : dnsAddresses) {
+ resultJoiner.add(addr.getHostAddress());
+ }
+ resultJoiner.add("]");
+ } else {
+ nullFields.add("dnsAddr");
+ }
+
+ if (null != mtu) {
+ resultJoiner.add("mtu :");
+ resultJoiner.add(mtu.toString());
+ } else {
+ nullFields.add("mtu");
+ }
+
+ if (!nullFields.isEmpty()) {
+ resultJoiner.add("; Null fields : [");
+ for (final String field : nullFields) {
+ resultJoiner.add(field);
+ }
+ resultJoiner.add("]");
+ }
+
+ return resultJoiner.toString();
+ }
}
diff --git a/core/java/android/net/ipmemorystore/SameL3NetworkResponse.java b/core/java/android/net/ipmemorystore/SameL3NetworkResponse.java
index 0cb37e9..d040dcc 100644
--- a/core/java/android/net/ipmemorystore/SameL3NetworkResponse.java
+++ b/core/java/android/net/ipmemorystore/SameL3NetworkResponse.java
@@ -128,4 +128,19 @@
public int hashCode() {
return Objects.hash(l2Key1, l2Key2, confidence);
}
+
+ @Override
+ /** Pretty print */
+ public String toString() {
+ switch (getNetworkSameness()) {
+ case NETWORK_SAME:
+ return "\"" + l2Key1 + "\" same L3 network as \"" + l2Key2 + "\"";
+ case NETWORK_DIFFERENT:
+ return "\"" + l2Key1 + "\" different L3 network from \"" + l2Key2 + "\"";
+ case NETWORK_NEVER_CONNECTED:
+ return "\"" + l2Key1 + "\" can't be tested against \"" + l2Key2 + "\"";
+ default:
+ return "Buggy sameness value ? \"" + l2Key1 + "\", \"" + l2Key2 + "\"";
+ }
+ }
}
diff --git a/core/java/android/net/ipmemorystore/Status.java b/core/java/android/net/ipmemorystore/Status.java
index 5b016ec..95e5042 100644
--- a/core/java/android/net/ipmemorystore/Status.java
+++ b/core/java/android/net/ipmemorystore/Status.java
@@ -26,6 +26,8 @@
public class Status {
public static final int SUCCESS = 0;
+ public static final int ERROR_DATABASE_CANNOT_BE_OPENED = -1;
+
public final int resultCode;
public Status(final int resultCode) {
@@ -47,4 +49,14 @@
public boolean isSuccess() {
return SUCCESS == resultCode;
}
+
+ /** Pretty print */
+ @Override
+ public String toString() {
+ switch (resultCode) {
+ case SUCCESS: return "SUCCESS";
+ case ERROR_DATABASE_CANNOT_BE_OPENED: return "DATABASE CANNOT BE OPENED";
+ default: return "Unknown value ?!";
+ }
+ }
}
diff --git a/core/java/android/net/ipmemorystore/Utils.java b/core/java/android/net/ipmemorystore/Utils.java
new file mode 100644
index 0000000..73d8c83
--- /dev/null
+++ b/core/java/android/net/ipmemorystore/Utils.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.ipmemorystore;
+
+import android.annotation.NonNull;
+
+/** {@hide} */
+public class Utils {
+ /** Pretty print */
+ public static String blobToString(final Blob blob) {
+ final StringBuilder sb = new StringBuilder("Blob : [");
+ if (blob.data.length <= 24) {
+ appendByteArray(sb, blob.data, 0, blob.data.length);
+ } else {
+ appendByteArray(sb, blob.data, 0, 16);
+ sb.append("...");
+ appendByteArray(sb, blob.data, blob.data.length - 8, blob.data.length);
+ }
+ sb.append("]");
+ return sb.toString();
+ }
+
+ // Adds the hex representation of the array between the specified indices (inclusive, exclusive)
+ private static void appendByteArray(@NonNull final StringBuilder sb, @NonNull final byte[] ar,
+ final int from, final int to) {
+ for (int i = from; i < to; ++i) {
+ sb.append(String.format("%02X", ar[i]));
+ }
+ }
+}
diff --git a/core/java/android/os/BugreportManager.java b/core/java/android/os/BugreportManager.java
index 1343d24..b15a4d3 100644
--- a/core/java/android/os/BugreportManager.java
+++ b/core/java/android/os/BugreportManager.java
@@ -114,7 +114,6 @@
}
}
-
// TODO(b/111441001) Connect up with BugreportListener methods.
private final class DumpstateListener extends IDumpstateListener.Stub
implements DeathRecipient {
@@ -130,6 +129,23 @@
}
@Override
+ public void onProgress(int progress) throws RemoteException {
+ // TODO(b/111441001): implement
+ }
+
+ @Override
+ public void onError(int errorCode) throws RemoteException {
+ // TODO(b/111441001): implement
+ }
+
+ @Override
+ public void onFinished(long durationMs, String title, String description)
+ throws RemoteException {
+ // TODO(b/111441001): implement
+ }
+
+ // Old methods; should go away
+ @Override
public void onProgressUpdated(int progress) throws RemoteException {
// TODO(b/111441001): implement
}
diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java
index 9fea873..2d61a4e 100755
--- a/core/java/android/os/Build.java
+++ b/core/java/android/os/Build.java
@@ -289,6 +289,26 @@
"ro.build.version.preview_sdk", 0);
/**
+ * The SDK fingerprint for a given prerelease SDK. This value will always be
+ * {@code REL} on production platform builds/devices.
+ *
+ * <p>When this value is not {@code REL}, it contains a string fingerprint of the API
+ * surface exposed by the preview SDK. Preview platforms with different API surfaces
+ * will have different {@code PREVIEW_SDK_FINGERPRINT}.
+ *
+ * <p>This attribute is intended for use by installers for finer grained targeting of
+ * packages. Applications targeting preview APIs should not use this field and should
+ * instead use {@code PREVIEW_SDK_INT} or use reflection or other runtime checks to
+ * detect the presence of an API or guard themselves against unexpected runtime
+ * behavior.
+ *
+ * @hide
+ */
+ @SystemApi
+ public static final String PREVIEW_SDK_FINGERPRINT = SystemProperties.get(
+ "ro.build.version.preview_sdk_fingerprint", "REL");
+
+ /**
* The current development codename, or the string "REL" if this is
* a release build.
*/
diff --git a/core/java/android/os/HwBinder.java b/core/java/android/os/HwBinder.java
index 3de3494..9e3e83e 100644
--- a/core/java/android/os/HwBinder.java
+++ b/core/java/android/os/HwBinder.java
@@ -17,6 +17,7 @@
package android.os;
import android.annotation.SystemApi;
+import android.annotation.TestApi;
import libcore.util.NativeAllocationRegistry;
@@ -24,6 +25,7 @@
/** @hide */
@SystemApi
+@TestApi
public abstract class HwBinder implements IHwBinder {
private static final String TAG = "HwBinder";
diff --git a/core/java/android/os/HwBlob.java b/core/java/android/os/HwBlob.java
index 6a5bb1c..0ec63b5 100644
--- a/core/java/android/os/HwBlob.java
+++ b/core/java/android/os/HwBlob.java
@@ -18,6 +18,7 @@
import android.annotation.NonNull;
import android.annotation.SystemApi;
+import android.annotation.TestApi;
import libcore.util.NativeAllocationRegistry;
@@ -28,6 +29,7 @@
* @hide
*/
@SystemApi
+@TestApi
public class HwBlob {
private static final String TAG = "HwBlob";
diff --git a/core/java/android/os/HwParcel.java b/core/java/android/os/HwParcel.java
index 7a51db2..7919a00 100644
--- a/core/java/android/os/HwParcel.java
+++ b/core/java/android/os/HwParcel.java
@@ -18,6 +18,7 @@
import android.annotation.IntDef;
import android.annotation.SystemApi;
+import android.annotation.TestApi;
import libcore.util.NativeAllocationRegistry;
@@ -28,6 +29,7 @@
/** @hide */
@SystemApi
+@TestApi
public class HwParcel {
private static final String TAG = "HwParcel";
diff --git a/core/java/android/os/IHwBinder.java b/core/java/android/os/IHwBinder.java
index 249eb3a..46fa6ef 100644
--- a/core/java/android/os/IHwBinder.java
+++ b/core/java/android/os/IHwBinder.java
@@ -17,9 +17,11 @@
package android.os;
import android.annotation.SystemApi;
+import android.annotation.TestApi;
/** @hide */
@SystemApi
+@TestApi
public interface IHwBinder {
/**
* Process a hwbinder transaction.
diff --git a/core/java/android/os/IHwInterface.java b/core/java/android/os/IHwInterface.java
index f9edd5b..0a5a715 100644
--- a/core/java/android/os/IHwInterface.java
+++ b/core/java/android/os/IHwInterface.java
@@ -17,8 +17,11 @@
package android.os;
import android.annotation.SystemApi;
+import android.annotation.TestApi;
+
/** @hide */
@SystemApi
+@TestApi
public interface IHwInterface {
/**
* @return the binder object that corresponds to this interface.
diff --git a/core/java/android/os/INetworkManagementService.aidl b/core/java/android/os/INetworkManagementService.aidl
index fdd7488..8ced722 100644
--- a/core/java/android/os/INetworkManagementService.aidl
+++ b/core/java/android/os/INetworkManagementService.aidl
@@ -356,16 +356,6 @@
void removeVpnUidRanges(int netId, in UidRange[] ranges);
/**
- * Start the clatd (464xlat) service on the given interface.
- */
- void startClatd(String interfaceName);
-
- /**
- * Stop the clatd (464xlat) service on the given interface.
- */
- void stopClatd(String interfaceName);
-
- /**
* Start listening for mobile activity state changes.
*/
void registerNetworkActivityListener(INetworkActivityListener listener);
diff --git a/core/java/android/os/NativeHandle.java b/core/java/android/os/NativeHandle.java
index f7ffc37..f13bf5f 100644
--- a/core/java/android/os/NativeHandle.java
+++ b/core/java/android/os/NativeHandle.java
@@ -20,6 +20,7 @@
import android.annotation.NonNull;
import android.annotation.SystemApi;
+import android.annotation.TestApi;
import android.system.ErrnoException;
import android.system.Os;
@@ -32,6 +33,7 @@
* @hide
*/
@SystemApi
+@TestApi
public final class NativeHandle implements Closeable {
// whether this object owns mFds
private boolean mOwn = false;
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index ee56e3d..760fef7 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -208,30 +208,35 @@
* First uid used for fully isolated sandboxed processes spawned from an app zygote
* @hide
*/
+ @TestApi
public static final int FIRST_APP_ZYGOTE_ISOLATED_UID = 90000;
/**
* Number of UIDs we allocate per application zygote
* @hide
*/
+ @TestApi
public static final int NUM_UIDS_PER_APP_ZYGOTE = 100;
/**
* Last uid used for fully isolated sandboxed processes spawned from an app zygote
* @hide
*/
+ @TestApi
public static final int LAST_APP_ZYGOTE_ISOLATED_UID = 98999;
/**
* First uid used for fully isolated sandboxed processes (with no permissions of their own)
* @hide
*/
+ @TestApi
public static final int FIRST_ISOLATED_UID = 99000;
/**
* Last uid used for fully isolated sandboxed processes (with no permissions of their own)
* @hide
*/
+ @TestApi
public static final int LAST_ISOLATED_UID = 99999;
/**
diff --git a/core/java/android/permission/IPermissionController.aidl b/core/java/android/permission/IPermissionController.aidl
index 7a7bd83..249b622 100644
--- a/core/java/android/permission/IPermissionController.aidl
+++ b/core/java/android/permission/IPermissionController.aidl
@@ -18,6 +18,8 @@
import android.os.RemoteCallback;
import android.os.Bundle;
+import android.os.ParcelFileDescriptor;
+import android.os.UserHandle;
/**
* Interface for system apps to communication with the permission controller.
@@ -27,6 +29,7 @@
oneway interface IPermissionController {
void revokeRuntimePermissions(in Bundle request, boolean doDryRun, int reason,
String callerPackageName, in RemoteCallback callback);
+ void getRuntimePermissionBackup(in UserHandle user, in ParcelFileDescriptor pipe);
void getAppPermissions(String packageName, in RemoteCallback callback);
void revokeRuntimePermission(String packageName, String permissionName);
void countPermissionApps(in List<String> permissionNames, boolean countOnlyGranted,
diff --git a/core/java/android/permission/PermissionControllerManager.java b/core/java/android/permission/PermissionControllerManager.java
index 0865b62..bfcca7c 100644
--- a/core/java/android/permission/PermissionControllerManager.java
+++ b/core/java/android/permission/PermissionControllerManager.java
@@ -36,10 +36,12 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
+import android.os.AsyncTask;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
+import android.os.ParcelFileDescriptor;
import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.UserHandle;
@@ -51,6 +53,11 @@
import com.android.internal.infra.AbstractRemoteService;
import com.android.internal.util.Preconditions;
+import libcore.io.IoUtils;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
@@ -58,6 +65,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
+import java.util.function.Consumer;
/**
* Interface for communicating with the permission controller.
@@ -118,6 +126,20 @@
}
/**
+ * Callback for delivering the result of {@link #getRuntimePermissionBackup}.
+ *
+ * @hide
+ */
+ public interface OnGetRuntimePermissionBackupCallback {
+ /**
+ * The result for {@link #getRuntimePermissionBackup}.
+ *
+ * @param backup The backup file
+ */
+ void onGetRuntimePermissionsBackup(@NonNull byte[] backup);
+ }
+
+ /**
* Callback for delivering the result of {@link #getAppPermissions}.
*
* @hide
@@ -219,6 +241,26 @@
}
/**
+ * Create a backup of the runtime permissions.
+ *
+ * @param user The user to be backed up
+ * @param executor Executor on which to invoke the callback
+ * @param callback Callback to receive the result
+ *
+ * @hide
+ */
+ @RequiresPermission(Manifest.permission.GET_RUNTIME_PERMISSIONS)
+ public void getRuntimePermissionBackup(@NonNull UserHandle user,
+ @NonNull @CallbackExecutor Executor executor,
+ @NonNull OnGetRuntimePermissionBackupCallback callback) {
+ checkNotNull(executor);
+ checkNotNull(callback);
+
+ sRemoteService.scheduleRequest(new PendingGetRuntimePermissionBackup(sRemoteService,
+ user, executor, callback));
+ }
+
+ /**
* Gets the runtime permissions for an app.
*
* @param packageName The package for which to query.
@@ -355,6 +397,89 @@
}
/**
+ * Task to read a large amount of data from a remote service.
+ */
+ private static class FileReaderTask<Callback extends Consumer<byte[]>>
+ extends AsyncTask<Void, Void, byte[]> {
+ private ParcelFileDescriptor mLocalPipe;
+ private ParcelFileDescriptor mRemotePipe;
+
+ private final @NonNull Callback mCallback;
+
+ FileReaderTask(@NonNull Callback callback) {
+ mCallback = callback;
+ }
+
+ @Override
+ protected void onPreExecute() {
+ ParcelFileDescriptor[] pipe;
+ try {
+ pipe = ParcelFileDescriptor.createPipe();
+ } catch (IOException e) {
+ Log.e(TAG, "Could not create pipe needed to get runtime permission backup", e);
+ return;
+ }
+
+ mLocalPipe = pipe[0];
+ mRemotePipe = pipe[1];
+ }
+
+ /**
+ * Get the file descriptor the remote service should write the data to.
+ *
+ * <p>Needs to be closed <u>locally</u> before the FileReader can finish.
+ *
+ * @return The file the data should be written to
+ */
+ ParcelFileDescriptor getRemotePipe() {
+ return mRemotePipe;
+ }
+
+ @Override
+ protected byte[] doInBackground(Void... ignored) {
+ ByteArrayOutputStream combinedBuffer = new ByteArrayOutputStream();
+
+ try (InputStream in = new ParcelFileDescriptor.AutoCloseInputStream(mLocalPipe)) {
+ byte[] buffer = new byte[16 * 1024];
+
+ while (!isCancelled()) {
+ int numRead = in.read(buffer);
+ if (numRead == -1) {
+ break;
+ }
+
+ combinedBuffer.write(buffer, 0, numRead);
+ }
+ } catch (IOException | NullPointerException e) {
+ Log.e(TAG, "Error reading runtime permission backup", e);
+ combinedBuffer.reset();
+ }
+
+ return combinedBuffer.toByteArray();
+ }
+
+ /**
+ * Interrupt the reading of the data.
+ *
+ * <p>Needs to be called when canceling this task as it might be hung.
+ */
+ void interruptRead() {
+ IoUtils.closeQuietly(mLocalPipe);
+ }
+
+ @Override
+ protected void onCancelled() {
+ onPostExecute(new byte[]{});
+ }
+
+ @Override
+ protected void onPostExecute(byte[] backup) {
+ IoUtils.closeQuietly(mLocalPipe);
+ mCallback.accept(backup);
+ }
+ }
+
+ /**
* Request for {@link #revokeRuntimePermissions}
*/
private static final class PendingRevokeRuntimePermissionRequest extends
@@ -441,6 +566,68 @@
}
/**
+ * Request for {@link #getRuntimePermissionBackup}
+ */
+ private static final class PendingGetRuntimePermissionBackup extends
+ AbstractRemoteService.PendingRequest<RemoteService, IPermissionController>
+ implements Consumer<byte[]> {
+ private final @NonNull FileReaderTask<PendingGetRuntimePermissionBackup> mBackupReader;
+ private final @NonNull Executor mExecutor;
+ private final @NonNull OnGetRuntimePermissionBackupCallback mCallback;
+ private final @NonNull UserHandle mUser;
+
+ private PendingGetRuntimePermissionBackup(@NonNull RemoteService service,
+ @NonNull UserHandle user, @NonNull @CallbackExecutor Executor executor,
+ @NonNull OnGetRuntimePermissionBackupCallback callback) {
+ super(service);
+
+ mUser = user;
+ mExecutor = executor;
+ mCallback = callback;
+
+ mBackupReader = new FileReaderTask<>(this);
+ }
+
+ @Override
+ protected void onTimeout(RemoteService remoteService) {
+ mBackupReader.cancel(true);
+ mBackupReader.interruptRead();
+ }
+
+ @Override
+ public void run() {
+ mBackupReader.execute();
+
+ ParcelFileDescriptor remotePipe = mBackupReader.getRemotePipe();
+ try {
+ getService().getServiceInterface().getRuntimePermissionBackup(mUser, remotePipe);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error getting runtime permission backup", e);
+ } finally {
+ // Remote pipe end is duped by binder call. Local copy is not needed anymore
+ IoUtils.closeQuietly(remotePipe);
+ }
+ }
+
+ /**
+ * Called when the {@link #mBackupReader} finished reading the file.
+ *
+ * @param backup The data read
+ */
+ @Override
+ public void accept(byte[] backup) {
+ long token = Binder.clearCallingIdentity();
+ try {
+ mExecutor.execute(() -> mCallback.onGetRuntimePermissionsBackup(backup));
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+
+ finish();
+ }
+ }
+
+ /**
* Request for {@link #getAppPermissions}
*/
private static final class PendingGetAppPermissionRequest extends
diff --git a/core/java/android/permission/PermissionControllerService.java b/core/java/android/permission/PermissionControllerService.java
index 75d61e6..10e8c8d 100644
--- a/core/java/android/permission/PermissionControllerService.java
+++ b/core/java/android/permission/PermissionControllerService.java
@@ -33,11 +33,16 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
+import android.os.ParcelFileDescriptor;
import android.os.RemoteCallback;
+import android.os.UserHandle;
import android.util.ArrayMap;
+import android.util.Log;
import com.android.internal.util.Preconditions;
+import java.io.IOException;
+import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -51,6 +56,7 @@
*/
@SystemApi
public abstract class PermissionControllerService extends Service {
+ private static final String LOG_TAG = PermissionControllerService.class.getSimpleName();
/**
* The {@link Intent} action that must be declared as handled by a service
@@ -83,6 +89,15 @@
@PermissionControllerManager.Reason int reason, @NonNull String callerPackageName);
/**
+ * Create a backup of the runtime permissions.
+ *
+ * @param user The user to back up
+ * @param out The stream to write the backup to
+ */
+ public abstract void onGetRuntimePermissionsBackup(@NonNull UserHandle user,
+ @NonNull OutputStream out);
+
+ /**
* Gets the runtime permissions for an app.
*
* @param packageName The package for which to query.
@@ -163,6 +178,18 @@
}
@Override
+ public void getRuntimePermissionBackup(UserHandle user, ParcelFileDescriptor pipe) {
+ checkNotNull(user);
+ checkNotNull(pipe);
+
+ enforceCallingPermission(Manifest.permission.GET_RUNTIME_PERMISSIONS, null);
+
+ mHandler.sendMessage(obtainMessage(
+ PermissionControllerService::getRuntimePermissionsBackup,
+ PermissionControllerService.this, user, pipe));
+ }
+
+ @Override
public void getAppPermissions(String packageName, RemoteCallback callback) {
checkNotNull(packageName, "packageName");
checkNotNull(callback, "callback");
@@ -237,6 +264,15 @@
callback.sendResult(result);
}
+ private void getRuntimePermissionsBackup(@NonNull UserHandle user,
+ @NonNull ParcelFileDescriptor outFile) {
+ try (OutputStream out = new ParcelFileDescriptor.AutoCloseOutputStream(outFile)) {
+ onGetRuntimePermissionsBackup(user, out);
+ } catch (IOException e) {
+ Log.e(LOG_TAG, "Could not open pipe to write backup tp", e);
+ }
+ }
+
private void getAppPermissions(@NonNull String packageName, @NonNull RemoteCallback callback) {
List<RuntimePermissionPresentationInfo> permissions = onGetAppPermissions(packageName);
if (permissions != null && !permissions.isEmpty()) {
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index ef117ea..39c4266 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -7407,6 +7407,22 @@
private static final Validator DOZE_WAKE_SCREEN_GESTURE_VALIDATOR = BOOLEAN_VALIDATOR;
/**
+ * Gesture that skips media.
+ * @hide
+ */
+ public static final String SKIP_GESTURE = "skip_gesture";
+
+ private static final Validator SKIP_GESTURE_VALIDATOR = BOOLEAN_VALIDATOR;
+
+ /**
+ * Gesture that silences sound (alarms, notification, calls).
+ * @hide
+ */
+ public static final String SILENCE_GESTURE = "silence_gesture";
+
+ private static final Validator SILENCE_GESTURE_VALIDATOR = BOOLEAN_VALIDATOR;
+
+ /**
* The current night mode that has been selected by the user. Owned
* and controlled by UiModeManagerService. Constants are as per
* UiModeManager.
@@ -8483,6 +8499,8 @@
NOTIFICATION_NEW_INTERRUPTION_MODEL,
TRUST_AGENTS_EXTEND_UNLOCK,
LOCK_SCREEN_WHEN_TRUST_LOST,
+ SKIP_GESTURE,
+ SILENCE_GESTURE,
};
/**
@@ -8650,6 +8668,8 @@
VALIDATORS.put(TRUST_AGENTS_EXTEND_UNLOCK, TRUST_AGENTS_EXTEND_UNLOCK_VALIDATOR);
VALIDATORS.put(LOCK_SCREEN_CUSTOM_CLOCK_FACE, LOCK_SCREEN_CUSTOM_CLOCK_FACE_VALIDATOR);
VALIDATORS.put(LOCK_SCREEN_WHEN_TRUST_LOST, LOCK_SCREEN_WHEN_TRUST_LOST_VALIDATOR);
+ VALIDATORS.put(SKIP_GESTURE, SKIP_GESTURE_VALIDATOR);
+ VALIDATORS.put(SILENCE_GESTURE, SILENCE_GESTURE_VALIDATOR);
}
/**
@@ -8681,10 +8701,10 @@
CLONE_TO_MANAGED_PROFILE.add(LOCATION_CHANGER);
CLONE_TO_MANAGED_PROFILE.add(LOCATION_MODE);
CLONE_TO_MANAGED_PROFILE.add(LOCATION_PROVIDERS_ALLOWED);
- CLONE_TO_MANAGED_PROFILE.add(SELECTED_INPUT_METHOD_SUBTYPE);
if (!InputMethodSystemProperty.PER_PROFILE_IME_ENABLED) {
CLONE_TO_MANAGED_PROFILE.add(DEFAULT_INPUT_METHOD);
CLONE_TO_MANAGED_PROFILE.add(ENABLED_INPUT_METHODS);
+ CLONE_TO_MANAGED_PROFILE.add(SELECTED_INPUT_METHOD_SUBTYPE);
CLONE_TO_MANAGED_PROFILE.add(SELECTED_SPELL_CHECKER);
CLONE_TO_MANAGED_PROFILE.add(SELECTED_SPELL_CHECKER_SUBTYPE);
}
@@ -9361,6 +9381,15 @@
"hdmi_system_audio_control_enabled";
/**
+ * Whether HDMI Routing Control feature is enabled. If enabled, the switch device will
+ * route to the correct input source on receiving Routing Control related messages. If
+ * disabled, you can only switch the input via controls on this device.
+ * @hide
+ */
+ public static final String HDMI_CEC_SWITCH_ENABLED =
+ "hdmi_cec_switch_enabled";
+
+ /**
* Whether TV will automatically turn on upon reception of the CEC command
* <Text View On> or <Image View On>. (0 = false, 1 = true)
*
@@ -11062,6 +11091,31 @@
/** {@hide} */
public static final String
BLUETOOTH_HEARING_AID_PRIORITY_PREFIX = "bluetooth_hearing_aid_priority_";
+ /**
+ * Enable/disable radio bug detection
+ *
+ * {@hide}
+ */
+ public static final String
+ ENABLE_RADIO_BUG_DETECTION = "enable_radio_bug_detection";
+
+ /**
+ * Count threshold of RIL wakelock timeout for radio bug detection
+ *
+ * {@hide}
+ */
+ public static final String
+ RADIO_BUG_WAKELOCK_TIMEOUT_COUNT_THRESHOLD =
+ "radio_bug_wakelock_timeout_count_threshold";
+
+ /**
+ * Count threshold of RIL system error for radio bug detection
+ *
+ * {@hide}
+ */
+ public static final String
+ RADIO_BUG_SYSTEM_ERROR_COUNT_THRESHOLD =
+ "radio_bug_system_error_count_threshold";
/**
* Activity manager specific settings.
diff --git a/core/java/android/service/autofill/augmented/AugmentedAutofillService.java b/core/java/android/service/autofill/augmented/AugmentedAutofillService.java
index 0116961..aaba85b 100644
--- a/core/java/android/service/autofill/augmented/AugmentedAutofillService.java
+++ b/core/java/android/service/autofill/augmented/AugmentedAutofillService.java
@@ -42,6 +42,7 @@
import android.view.autofill.AutofillId;
import android.view.autofill.AutofillValue;
import android.view.autofill.IAugmentedAutofillManagerClient;
+import android.view.autofill.IAutofillWindowPresenter;
import com.android.internal.annotations.GuardedBy;
@@ -95,10 +96,10 @@
}
@Override
- public void onDestroyFillWindowRequest(int sessionId) {
+ public void onDestroyAllFillWindowsRequest() {
mHandler.sendMessage(
- obtainMessage(AugmentedAutofillService::handleOnDestroyFillWindowRequest,
- AugmentedAutofillService.this, sessionId));
+ obtainMessage(AugmentedAutofillService::handleOnDestroyAllFillWindowsRequest,
+ AugmentedAutofillService.this));
}
};
@@ -185,18 +186,21 @@
new FillCallback(proxy));
}
- private void handleOnDestroyFillWindowRequest(@NonNull int sessionId) {
- AutofillProxy proxy = null;
+ private void handleOnDestroyAllFillWindowsRequest() {
if (mAutofillProxies != null) {
- proxy = mAutofillProxies.get(sessionId);
+ final int size = mAutofillProxies.size();
+ for (int i = 0; i < size; i++) {
+ final int sessionId = mAutofillProxies.keyAt(i);
+ final AutofillProxy proxy = mAutofillProxies.valueAt(i);
+ if (proxy == null) {
+ // TODO(b/111330312): this might be fine, in which case we should logv it
+ Log.w(TAG, "No proxy for session " + sessionId);
+ return;
+ }
+ proxy.destroy();
+ }
+ mAutofillProxies.clear();
}
- if (proxy == null) {
- // TODO(b/111330312): this might be fine, in which case we should logv it
- Log.w(TAG, "No proxy for session " + sessionId);
- return;
- }
- proxy.destroy();
- mAutofillProxies.remove(sessionId);
}
private void handleOnUnbind() {
@@ -350,6 +354,16 @@
}
}
+ public void requestShowFillUi(int width, int height, Rect anchorBounds,
+ IAutofillWindowPresenter presenter) throws RemoteException {
+ mClient.requestShowFillUi(mSessionId, mFocusedId, width, height, anchorBounds,
+ presenter);
+ }
+
+ public void requestHideFillUi() throws RemoteException {
+ mClient.requestHideFillUi(mSessionId, mFocusedId);
+ }
+
private void update(@NonNull AutofillId focusedId, @NonNull AutofillValue focusedValue) {
synchronized (mLock) {
// TODO(b/111330312): should we close the popupwindow if the focused id changed?
diff --git a/core/java/android/service/autofill/augmented/FillWindow.java b/core/java/android/service/autofill/augmented/FillWindow.java
index 33b88e42..51b0f01 100644
--- a/core/java/android/service/autofill/augmented/FillWindow.java
+++ b/core/java/android/service/autofill/augmented/FillWindow.java
@@ -16,22 +16,25 @@
package android.service.autofill.augmented;
import static android.service.autofill.augmented.AugmentedAutofillService.DEBUG;
+import static android.service.autofill.augmented.AugmentedAutofillService.VERBOSE;
+
+import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;
import android.annotation.LongDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.annotation.TestApi;
-import android.app.Dialog;
import android.graphics.Rect;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.RemoteException;
import android.service.autofill.augmented.AugmentedAutofillService.AutofillProxy;
import android.service.autofill.augmented.PresentationParams.Area;
import android.util.Log;
-import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
-import android.view.ViewGroup;
-import android.view.Window;
import android.view.WindowManager;
+import android.view.autofill.IAutofillWindowPresenter;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions;
@@ -71,7 +74,7 @@
/** Indicates the data being shown is a physical address */
public static final long FLAG_METADATA_ADDRESS = 0x1;
- // TODO(b/111330312): add moar flags
+ // TODO(b/111330312): add more flags
/** @hide */
@LongDef(prefix = { "FLAG" }, value = {
@@ -83,8 +86,17 @@
private final Object mLock = new Object();
private final CloseGuard mCloseGuard = CloseGuard.get();
+ private final @NonNull Handler mUiThreadHandler = new Handler(Looper.getMainLooper());
+ private final @NonNull FillWindowPresenter mFillWindowPresenter = new FillWindowPresenter();
+
@GuardedBy("mLock")
- private Dialog mDialog;
+ private WindowManager mWm;
+ @GuardedBy("mLock")
+ private View mFillView;
+ @GuardedBy("mLock")
+ private boolean mShowing;
+ @GuardedBy("mLock")
+ private Rect mBounds;
@GuardedBy("mLock")
private boolean mDestroyed;
@@ -140,51 +152,28 @@
// window instead of destroying. In fact, it might be better to allocate a full window
// initially, which is transparent (and let touches get through) everywhere but in the
// rect boundaries.
- destroy();
// TODO(b/111330312): make sure all touch events are handled, window is always closed,
// etc.
- mDialog = new Dialog(rootView.getContext()) {
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
- FillWindow.this.destroy();
+ mWm = rootView.getContext().getSystemService(WindowManager.class);
+ mFillView = rootView;
+ // Listen to the touch outside to destroy the window when typing is detected.
+ mFillView.setOnTouchListener(
+ (view, motionEvent) -> {
+ if (motionEvent.getAction() == MotionEvent.ACTION_OUTSIDE) {
+ if (VERBOSE) Log.v(TAG, "Outside touch detected, hiding the window");
+ hide();
+ }
+ return false;
}
- return false;
- }
- };
- mCloseGuard.open("destroy");
- final Window window = mDialog.getWindow();
- window.setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
- // Makes sure touch outside the dialog is received by the window behind the dialog.
- window.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
- // Makes sure the touch outside the dialog is received by the dialog to dismiss it.
- window.addFlags(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
- // Makes sure keyboard shows up.
- window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
-
- final int height = rect.bottom - rect.top;
- final int width = rect.right - rect.left;
- final WindowManager.LayoutParams windowParams = window.getAttributes();
- windowParams.gravity = Gravity.TOP | Gravity.LEFT;
- windowParams.y = rect.top + height;
- windowParams.height = height;
- windowParams.x = rect.left;
- windowParams.width = width;
-
- window.setAttributes(windowParams);
- window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
- window.setBackgroundDrawableResource(android.R.color.transparent);
-
- mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
- final ViewGroup.LayoutParams diagParams = new ViewGroup.LayoutParams(width, height);
- mDialog.setContentView(rootView, diagParams);
-
+ );
+ mShowing = false;
+ mBounds = new Rect(area.getBounds());
if (DEBUG) {
Log.d(TAG, "Created FillWindow: params= " + smartSuggestion + " view=" + rootView);
}
-
+ mDestroyed = false;
mProxy.setFillWindow(this);
return true;
}
@@ -194,36 +183,87 @@
void show() {
// TODO(b/111330312): check if updated first / throw exception
if (DEBUG) Log.d(TAG, "show()");
-
synchronized (mLock) {
checkNotDestroyedLocked();
- if (mDialog == null) {
+ if (mWm == null || mFillView == null) {
throw new IllegalStateException("update() not called yet, or already destroyed()");
}
-
- mDialog.show();
if (mProxy != null) {
+ try {
+ mProxy.requestShowFillUi(mBounds.right - mBounds.left,
+ mBounds.bottom - mBounds.top,
+ /*anchorBounds=*/ null, mFillWindowPresenter);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Error requesting to show fill window", e);
+ }
mProxy.report(AutofillProxy.REPORT_EVENT_UI_SHOWN);
}
}
}
/**
+ * Hides the window.
+ *
+ * <p>The window is not destroyed and can be shown again
+ */
+ private void hide() {
+ if (DEBUG) Log.d(TAG, "hide()");
+ synchronized (mLock) {
+ checkNotDestroyedLocked();
+ if (mWm == null || mFillView == null) {
+ throw new IllegalStateException("update() not called yet, or already destroyed()");
+ }
+ if (mProxy != null && mShowing) {
+ try {
+ mProxy.requestHideFillUi();
+ } catch (RemoteException e) {
+ Log.w(TAG, "Error requesting to hide fill window", e);
+ }
+ }
+ }
+ }
+
+ private void handleShow(WindowManager.LayoutParams p) {
+ if (DEBUG) Log.d(TAG, "handleShow()");
+ synchronized (mLock) {
+ if (mWm != null && mFillView != null) {
+ p.flags |= WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
+ if (!mShowing) {
+ mWm.addView(mFillView, p);
+ mShowing = true;
+ } else {
+ mWm.updateViewLayout(mFillView, p);
+ }
+ }
+ }
+ }
+
+ private void handleHide() {
+ if (DEBUG) Log.d(TAG, "handleHide()");
+ synchronized (mLock) {
+ if (mWm != null && mFillView != null && mShowing) {
+ mWm.removeView(mFillView);
+ mShowing = false;
+ }
+ }
+ }
+
+ /**
* Destroys the window.
*
* <p>Once destroyed, this window cannot be used anymore
*/
public void destroy() {
- if (DEBUG) Log.d(TAG, "destroy(): mDestroyed=" + mDestroyed + " mDialog=" + mDialog);
-
- synchronized (this) {
- if (mDestroyed || mDialog == null) return;
-
- mDialog.dismiss();
- mDialog = null;
- if (mProxy != null) {
- mProxy.report(AutofillProxy.REPORT_EVENT_UI_DESTROYED);
- }
+ if (DEBUG) {
+ Log.d(TAG,
+ "destroy(): mDestroyed=" + mDestroyed + " mShowing=" + mShowing + " mFillView="
+ + mFillView);
+ }
+ synchronized (mLock) {
+ if (mDestroyed) return;
+ hide();
+ mProxy.report(AutofillProxy.REPORT_EVENT_UI_DESTROYED);
+ mDestroyed = true;
mCloseGuard.close();
}
}
@@ -250,11 +290,15 @@
public void dump(@NonNull String prefix, @NonNull PrintWriter pw) {
synchronized (this) {
pw.print(prefix); pw.print("destroyed: "); pw.println(mDestroyed);
- if (mDialog != null) {
- pw.print(prefix); pw.print("dialog: ");
- pw.println(mDialog.isShowing() ? "shown" : "hidden");
- pw.print(prefix); pw.print("window: ");
- pw.println(mDialog.getWindow().getAttributes());
+ if (mFillView != null) {
+ pw.print(prefix); pw.print("fill window: ");
+ pw.println(mShowing ? "shown" : "hidden");
+ pw.print(prefix); pw.print("fill view: ");
+ pw.println(mFillView);
+ pw.print(prefix); pw.print("mBounds: ");
+ pw.println(mBounds);
+ pw.print(prefix); pw.print("mWm: ");
+ pw.println(mWm);
}
}
}
@@ -264,4 +308,19 @@
public void close() throws Exception {
destroy();
}
+
+ private final class FillWindowPresenter extends IAutofillWindowPresenter.Stub {
+ @Override
+ public void show(WindowManager.LayoutParams p, Rect transitionEpicenter,
+ boolean fitsSystemWindows, int layoutDirection) {
+ if (DEBUG) Log.d(TAG, "FillWindowPresenter.show()");
+ mUiThreadHandler.sendMessage(obtainMessage(FillWindow::handleShow, FillWindow.this, p));
+ }
+
+ @Override
+ public void hide(Rect transitionEpicenter) {
+ if (DEBUG) Log.d(TAG, "FillWindowPresenter.hide()");
+ mUiThreadHandler.sendMessage(obtainMessage(FillWindow::handleHide, FillWindow.this));
+ }
+ }
}
diff --git a/core/java/android/service/autofill/augmented/IAugmentedAutofillService.aidl b/core/java/android/service/autofill/augmented/IAugmentedAutofillService.aidl
index b3ac2da1..fb6912a 100644
--- a/core/java/android/service/autofill/augmented/IAugmentedAutofillService.aidl
+++ b/core/java/android/service/autofill/augmented/IAugmentedAutofillService.aidl
@@ -36,5 +36,5 @@
in ComponentName activityComponent, in AutofillId focusedId,
in AutofillValue focusedValue, long requestTime, in IFillCallback callback);
- void onDestroyFillWindowRequest(int sessionId);
+ void onDestroyAllFillWindowsRequest();
}
diff --git a/core/java/android/service/contentcapture/ContentCaptureService.java b/core/java/android/service/contentcapture/ContentCaptureService.java
index e5e028d..1eaa3c5 100644
--- a/core/java/android/service/contentcapture/ContentCaptureService.java
+++ b/core/java/android/service/contentcapture/ContentCaptureService.java
@@ -323,15 +323,21 @@
mSessionUids.put(sessionId, uid);
onCreateContentCaptureSession(context, new ContentCaptureSessionId(sessionId));
- final int flags = context.getFlags();
- if ((flags & ContentCaptureContext.FLAG_DISABLED_BY_FLAG_SECURE) != 0) {
- setClientState(clientReceiver, ContentCaptureSession.STATE_DISABLED_BY_FLAG_SECURE,
- mClientInterface.asBinder());
- return;
+ final int clientFlags = context.getFlags();
+ int stateFlags = 0;
+ if ((clientFlags & ContentCaptureContext.FLAG_DISABLED_BY_FLAG_SECURE) != 0) {
+ stateFlags |= ContentCaptureSession.STATE_FLAG_SECURE;
}
+ if ((clientFlags & ContentCaptureContext.FLAG_DISABLED_BY_APP) != 0) {
+ stateFlags |= ContentCaptureSession.STATE_BY_APP;
+ }
+ if (stateFlags == 0) {
+ stateFlags = ContentCaptureSession.STATE_ACTIVE;
+ } else {
+ stateFlags |= ContentCaptureSession.STATE_DISABLED;
- setClientState(clientReceiver, ContentCaptureSession.STATE_ACTIVE,
- mClientInterface.asBinder());
+ }
+ setClientState(clientReceiver, stateFlags, mClientInterface.asBinder());
}
private void handleSendEvents(int uid,
diff --git a/core/java/android/text/util/Linkify.java b/core/java/android/text/util/Linkify.java
index eef7ea2..50e7ec3 100644
--- a/core/java/android/text/util/Linkify.java
+++ b/core/java/android/text/util/Linkify.java
@@ -37,7 +37,6 @@
import com.android.i18n.phonenumbers.PhoneNumberMatch;
import com.android.i18n.phonenumbers.PhoneNumberUtil;
import com.android.i18n.phonenumbers.PhoneNumberUtil.Leniency;
-import com.android.internal.annotations.GuardedBy;
import libcore.util.EmptyArray;
@@ -49,6 +48,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.Locale;
+import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -69,7 +69,6 @@
*
* @see MatchFilter
* @see TransformFilter
- * @see UrlSpanFactory
*/
public class Linkify {
@@ -228,44 +227,6 @@
}
/**
- * Factory class to create {@link URLSpan}s. While adding spans to a {@link Spannable},
- * {@link Linkify} will call {@link UrlSpanFactory#create(String)} function to create a
- * {@link URLSpan}.
- *
- * @see #addLinks(Spannable, int, UrlSpanFactory)
- * @see #addLinks(Spannable, Pattern, String, String[], MatchFilter, TransformFilter,
- * UrlSpanFactory)
- */
- public static class UrlSpanFactory {
- private static final Object sInstanceLock = new Object();
-
- @GuardedBy("sInstanceLock")
- private static volatile UrlSpanFactory sInstance = null;
-
- private static synchronized UrlSpanFactory getInstance() {
- if (sInstance == null) {
- synchronized (sInstanceLock) {
- if (sInstance == null) {
- sInstance = new UrlSpanFactory();
- }
- }
- }
- return sInstance;
- }
-
- /**
- * Factory function that will called by {@link Linkify} in order to create a
- * {@link URLSpan}.
- *
- * @param url URL found
- * @return a URLSpan instance
- */
- public URLSpan create(final String url) {
- return new URLSpan(url);
- }
- }
-
- /**
* Scans the text of the provided Spannable and turns all occurrences
* of the link types indicated in the mask into clickable links.
* If the mask is nonzero, it also removes any existing URLSpans
@@ -277,7 +238,7 @@
*
* @return True if at least one link is found and applied.
*
- * @see #addLinks(Spannable, int, UrlSpanFactory)
+ * @see #addLinks(Spannable, int, Function)
*/
public static final boolean addLinks(@NonNull Spannable text, @LinkifyMask int mask) {
return addLinks(text, mask, null, null);
@@ -292,11 +253,11 @@
*
* @param text Spannable whose text is to be marked-up with links
* @param mask mask to define which kinds of links will be searched
- * @param urlSpanFactory factory class used to create {@link URLSpan}s
+ * @param urlSpanFactory function used to create {@link URLSpan}s
* @return True if at least one link is found and applied.
*/
public static final boolean addLinks(@NonNull Spannable text, @LinkifyMask int mask,
- @Nullable UrlSpanFactory urlSpanFactory) {
+ @Nullable Function<String, URLSpan> urlSpanFactory) {
return addLinks(text, mask, null, urlSpanFactory);
}
@@ -309,11 +270,11 @@
* @param text Spannable whose text is to be marked-up with links
* @param mask mask to define which kinds of links will be searched
* @param context Context to be used while identifying phone numbers
- * @param urlSpanFactory factory class used to create {@link URLSpan}s
+ * @param urlSpanFactory function used to create {@link URLSpan}s
* @return true if at least one link is found and applied.
*/
private static boolean addLinks(@NonNull Spannable text, @LinkifyMask int mask,
- @Nullable Context context, @Nullable UrlSpanFactory urlSpanFactory) {
+ @Nullable Context context, @Nullable Function<String, URLSpan> urlSpanFactory) {
if (text != null && containsUnsupportedCharacters(text.toString())) {
android.util.EventLog.writeEvent(0x534e4554, "116321860", -1, "");
return false;
@@ -398,7 +359,7 @@
*
* @return True if at least one link is found and applied.
*
- * @see #addLinks(Spannable, int, UrlSpanFactory)
+ * @see #addLinks(Spannable, int, Function)
*/
public static final boolean addLinks(@NonNull TextView text, @LinkifyMask int mask) {
if (mask == 0) {
@@ -512,8 +473,7 @@
* @param pattern Regex pattern to be used for finding links
* @param scheme URL scheme string (eg <code>http://</code>) to be
* prepended to the links that do not start with this scheme.
- * @see #addLinks(Spannable, Pattern, String, String[], MatchFilter, TransformFilter,
- * UrlSpanFactory)
+ * @see #addLinks(Spannable, Pattern, String, String[], MatchFilter, TransformFilter, Function)
*/
public static final boolean addLinks(@NonNull Spannable text, @NonNull Pattern pattern,
@Nullable String scheme) {
@@ -534,8 +494,7 @@
* @param transformFilter Filter to allow the client code to update the link found.
*
* @return True if at least one link is found and applied.
- * @see #addLinks(Spannable, Pattern, String, String[], MatchFilter, TransformFilter,
- * UrlSpanFactory)
+ * @see #addLinks(Spannable, Pattern, String, String[], MatchFilter, TransformFilter, Function)
*/
public static final boolean addLinks(@NonNull Spannable spannable, @NonNull Pattern pattern,
@Nullable String scheme, @Nullable MatchFilter matchFilter,
@@ -560,8 +519,7 @@
*
* @return True if at least one link is found and applied.
*
- * @see #addLinks(Spannable, Pattern, String, String[], MatchFilter, TransformFilter,
- * UrlSpanFactory)
+ * @see #addLinks(Spannable, Pattern, String, String[], MatchFilter, TransformFilter, Function)
*/
public static final boolean addLinks(@NonNull Spannable spannable, @NonNull Pattern pattern,
@Nullable String defaultScheme, @Nullable String[] schemes,
@@ -584,14 +542,14 @@
* @param matchFilter the filter that is used to allow the client code additional control
* over which pattern matches are to be converted into links.
* @param transformFilter filter to allow the client code to update the link found.
- * @param urlSpanFactory factory class used to create {@link URLSpan}s
+ * @param urlSpanFactory function used to create {@link URLSpan}s
*
* @return True if at least one link is found and applied.
*/
public static final boolean addLinks(@NonNull Spannable spannable, @NonNull Pattern pattern,
@Nullable String defaultScheme, @Nullable String[] schemes,
@Nullable MatchFilter matchFilter, @Nullable TransformFilter transformFilter,
- @Nullable UrlSpanFactory urlSpanFactory) {
+ @Nullable Function<String, URLSpan> urlSpanFactory) {
if (spannable != null && containsUnsupportedCharacters(spannable.toString())) {
android.util.EventLog.writeEvent(0x534e4554, "116321860", -1, "");
return false;
@@ -634,11 +592,11 @@
}
private static void applyLink(String url, int start, int end, Spannable text,
- @Nullable UrlSpanFactory urlSpanFactory) {
+ @Nullable Function<String, URLSpan> urlSpanFactory) {
if (urlSpanFactory == null) {
- urlSpanFactory = UrlSpanFactory.getInstance();
+ urlSpanFactory = DEFAULT_SPAN_FACTORY;
}
- final URLSpan span = urlSpanFactory.create(url);
+ final URLSpan span = urlSpanFactory.apply(url);
text.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
@@ -805,6 +763,13 @@
i++;
}
}
+
+ /**
+ * Default factory function to create {@link URLSpan}s. While adding spans to a
+ * {@link Spannable}, {@link Linkify} will call this function to create a {@link URLSpan}.
+ */
+ private static final Function<String, URLSpan> DEFAULT_SPAN_FACTORY =
+ (String string) -> new URLSpan(string);
}
class LinkSpec {
diff --git a/core/java/android/view/autofill/AutofillManager.java b/core/java/android/view/autofill/AutofillManager.java
index 93941d0..888a4c5 100644
--- a/core/java/android/view/autofill/AutofillManager.java
+++ b/core/java/android/view/autofill/AutofillManager.java
@@ -2997,5 +2997,23 @@
afm.post(() -> afm.autofill(sessionId, ids, values));
}
}
+
+ @Override
+ public void requestShowFillUi(int sessionId, AutofillId id, int width, int height,
+ Rect anchorBounds, IAutofillWindowPresenter presenter) {
+ final AutofillManager afm = mAfm.get();
+ if (afm != null) {
+ afm.post(() -> afm.requestShowFillUi(sessionId, id, width, height, anchorBounds,
+ presenter));
+ }
+ }
+
+ @Override
+ public void requestHideFillUi(int sessionId, AutofillId id) {
+ final AutofillManager afm = mAfm.get();
+ if (afm != null) {
+ afm.post(() -> afm.requestHideFillUi(id, false));
+ }
+ }
}
}
diff --git a/core/java/android/view/autofill/IAugmentedAutofillManagerClient.aidl b/core/java/android/view/autofill/IAugmentedAutofillManagerClient.aidl
index 67cd0bf..140507c 100644
--- a/core/java/android/view/autofill/IAugmentedAutofillManagerClient.aidl
+++ b/core/java/android/view/autofill/IAugmentedAutofillManagerClient.aidl
@@ -21,6 +21,7 @@
import android.graphics.Rect;
import android.view.autofill.AutofillId;
import android.view.autofill.AutofillValue;
+import android.view.autofill.IAutofillWindowPresenter;
/**
* Object running in the application process and responsible to provide the functionalities
@@ -29,6 +30,24 @@
* @hide
*/
interface IAugmentedAutofillManagerClient {
- Rect getViewCoordinates(in AutofillId id);
- void autofill(int sessionId, in List<AutofillId> ids, in List<AutofillValue> values);
+ /**
+ * Gets the coordinates of the input field view.
+ */
+ Rect getViewCoordinates(in AutofillId id);
+
+ /**
+ * Autofills the activity with the contents of the values.
+ */
+ void autofill(int sessionId, in List<AutofillId> ids, in List<AutofillValue> values);
+
+ /**
+ * Requests showing the fill UI.
+ */
+ void requestShowFillUi(int sessionId, in AutofillId id, int width, int height,
+ in Rect anchorBounds, in IAutofillWindowPresenter presenter);
+
+ /**
+ * Requests hiding the fill UI.
+ */
+ void requestHideFillUi(int sessionId, in AutofillId id);
}
diff --git a/core/java/android/view/contentcapture/ContentCaptureManager.java b/core/java/android/view/contentcapture/ContentCaptureManager.java
index ff45efd..81b2e01 100644
--- a/core/java/android/view/contentcapture/ContentCaptureManager.java
+++ b/core/java/android/view/contentcapture/ContentCaptureManager.java
@@ -29,12 +29,12 @@
import android.os.RemoteException;
import android.util.Log;
+import com.android.internal.annotations.GuardedBy;
import com.android.internal.os.IResultReceiver;
import com.android.internal.util.Preconditions;
import com.android.internal.util.SyncResultReceiver;
import java.io.PrintWriter;
-import java.util.concurrent.atomic.AtomicBoolean;
/*
* NOTE: all methods in this class should return right away, or do the real work in a handler
@@ -62,8 +62,10 @@
static final boolean VERBOSE = false;
static final boolean DEBUG = true; // STOPSHIP if not set to false
- @NonNull
- private final AtomicBoolean mDisabled = new AtomicBoolean();
+ private final Object mLock = new Object();
+
+ @GuardedBy("mLock")
+ private boolean mDisabled;
@NonNull
private final Context mContext;
@@ -71,11 +73,16 @@
@Nullable
private final IContentCaptureManager mService;
+ // Flags used for starting session.
+ @GuardedBy("mLock")
+ private int mFlags;
+
// TODO(b/119220549): use UI Thread directly (as calls are one-way) or a shared thread / handler
// held at the Application level
@NonNull
private final Handler mHandler;
+ @GuardedBy("mLock")
private MainContentCaptureSession mMainSession;
/** @hide */
@@ -114,20 +121,25 @@
@NonNull
@UiThread
public MainContentCaptureSession getMainContentCaptureSession() {
- if (mMainSession == null) {
- mMainSession = new MainContentCaptureSession(mContext, mHandler, mService,
- mDisabled);
- if (VERBOSE) {
- Log.v(TAG, "getDefaultContentCaptureSession(): created " + mMainSession);
+ synchronized (mLock) {
+ if (mMainSession == null) {
+ mMainSession = new MainContentCaptureSession(mContext, mHandler, mService,
+ mDisabled);
+ if (VERBOSE) {
+ Log.v(TAG, "getDefaultContentCaptureSession(): created " + mMainSession);
+ }
}
+ return mMainSession;
}
- return mMainSession;
}
/** @hide */
public void onActivityStarted(@NonNull IBinder applicationToken,
@NonNull ComponentName activityComponent, int flags) {
- getMainContentCaptureSession().start(applicationToken, activityComponent, flags);
+ synchronized (mLock) {
+ mFlags |= flags;
+ getMainContentCaptureSession().start(applicationToken, activityComponent, mFlags);
+ }
}
/** @hide */
@@ -173,7 +185,9 @@
* Checks whether content capture is enabled for this activity.
*/
public boolean isContentCaptureEnabled() {
- return mService != null && !mDisabled.get();
+ synchronized (mLock) {
+ return mService != null && !mDisabled;
+ }
}
/**
@@ -183,7 +197,9 @@
* it on {@link android.app.Activity#onCreate(android.os.Bundle, android.os.PersistableBundle)}.
*/
public void setContentCaptureEnabled(boolean enabled) {
- //TODO(b/111276913): implement (need to finish / disable all sessions)
+ synchronized (mLock) {
+ mFlags |= enabled ? 0 : ContentCaptureContext.FLAG_DISABLED_BY_APP;
+ }
}
/**
@@ -198,20 +214,22 @@
/** @hide */
public void dump(String prefix, PrintWriter pw) {
- pw.print(prefix); pw.println("ContentCaptureManager");
-
- pw.print(prefix); pw.print("Disabled: "); pw.println(mDisabled.get());
- pw.print(prefix); pw.print("Context: "); pw.println(mContext);
- pw.print(prefix); pw.print("User: "); pw.println(mContext.getUserId());
- if (mService != null) {
- pw.print(prefix); pw.print("Service: "); pw.println(mService);
- }
- if (mMainSession != null) {
- final String prefix2 = prefix + " ";
- pw.print(prefix); pw.println("Main session:");
- mMainSession.dump(prefix2, pw);
- } else {
- pw.print(prefix); pw.println("No sessions");
+ synchronized (mLock) {
+ pw.print(prefix); pw.println("ContentCaptureManager");
+ pw.print(prefix); pw.print("Disabled: "); pw.println(mDisabled);
+ pw.print(prefix); pw.print("Context: "); pw.println(mContext);
+ pw.print(prefix); pw.print("User: "); pw.println(mContext.getUserId());
+ if (mService != null) {
+ pw.print(prefix); pw.print("Service: "); pw.println(mService);
+ }
+ pw.print(prefix); pw.print("Flags: "); pw.println(mFlags);
+ if (mMainSession != null) {
+ final String prefix2 = prefix + " ";
+ pw.print(prefix); pw.println("Main session:");
+ mMainSession.dump(prefix2, pw);
+ } else {
+ pw.print(prefix); pw.println("No sessions");
+ }
}
}
diff --git a/core/java/android/view/contentcapture/ContentCaptureSession.java b/core/java/android/view/contentcapture/ContentCaptureSession.java
index d9a8416..2123308 100644
--- a/core/java/android/view/contentcapture/ContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/ContentCaptureSession.java
@@ -21,6 +21,7 @@
import android.annotation.CallSuper;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.util.DebugUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewStructure;
@@ -56,42 +57,58 @@
*
* @hide
*/
- public static final int STATE_UNKNOWN = 0;
+ // NOTE: not prefixed by STATE_ so it's not printed on getStateAsString()
+ public static final int UNKNWON_STATE = 0x0;
/**
* Service's startSession() was called, but server didn't confirm it was created yet.
*
* @hide
*/
- public static final int STATE_WAITING_FOR_SERVER = 1;
+ public static final int STATE_WAITING_FOR_SERVER = 0x1;
/**
* Session is active.
*
* @hide
*/
- public static final int STATE_ACTIVE = 2;
+ public static final int STATE_ACTIVE = 0x2;
/**
* Session is disabled because there is no service for this user.
*
* @hide
*/
- public static final int STATE_DISABLED_NO_SERVICE = 3;
+ public static final int STATE_DISABLED = 0x4;
/**
* Session is disabled because its id already existed on server.
*
* @hide
*/
- public static final int STATE_DISABLED_DUPLICATED_ID = 4;
+ public static final int STATE_DUPLICATED_ID = 0x8;
+
+ /**
+ * Session is disabled because service is not set for user.
+ *
+ * @hide
+ */
+ public static final int STATE_NO_SERVICE = 0x10;
/**
* Session is disabled by FLAG_SECURE
*
* @hide
*/
- public static final int STATE_DISABLED_BY_FLAG_SECURE = 5;
+ public static final int STATE_FLAG_SECURE = 0x20;
+
+ /**
+ * Session is disabled manually by the specific app.
+ *
+ * @hide
+ */
+ public static final int STATE_BY_APP = 0x40;
+
private static final int INITIAL_CHILDREN_CAPACITY = 5;
@@ -110,7 +127,7 @@
@Nullable
protected final String mId;
- private int mState = STATE_UNKNOWN;
+ private int mState = UNKNWON_STATE;
// Lazily created on demand.
private ContentCaptureSessionId mContentCaptureSessionId;
@@ -382,21 +399,7 @@
*/
@NonNull
protected static String getStateAsString(int state) {
- switch (state) {
- case STATE_UNKNOWN:
- return "UNKNOWN";
- case STATE_WAITING_FOR_SERVER:
- return "WAITING_FOR_SERVER";
- case STATE_ACTIVE:
- return "ACTIVE";
- case STATE_DISABLED_NO_SERVICE:
- return "DISABLED_NO_SERVICE";
- case STATE_DISABLED_DUPLICATED_ID:
- return "DISABLED_DUPLICATED_ID";
- case STATE_DISABLED_BY_FLAG_SECURE:
- return "DISABLED_FLAG_SECURE";
- default:
- return "INVALID:" + state;
- }
+ return state + " (" + (state == UNKNWON_STATE ? "UNKNOWN"
+ : DebugUtils.flagsToString(ContentCaptureSession.class, "STATE_", state)) + ")";
}
}
diff --git a/core/java/android/view/contentcapture/MainContentCaptureSession.java b/core/java/android/view/contentcapture/MainContentCaptureSession.java
index a29aaf0..1d9018c 100644
--- a/core/java/android/view/contentcapture/MainContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/MainContentCaptureSession.java
@@ -88,6 +88,7 @@
*/
public static final String EXTRA_BINDER = "binder";
+ // TODO(b/111276913): make sure disabled state is in sync with manager's disabled
@NonNull
private final AtomicBoolean mDisabled;
@@ -113,7 +114,7 @@
@Nullable
private DeathRecipient mDirectServiceVulture;
- private int mState = STATE_UNKNOWN;
+ private int mState = UNKNWON_STATE;
@Nullable
private IBinder mApplicationToken;
@@ -133,11 +134,11 @@
/** @hide */
protected MainContentCaptureSession(@NonNull Context context, @NonNull Handler handler,
@Nullable IContentCaptureManager systemServerInterface,
- @NonNull AtomicBoolean disabled) {
+ @NonNull boolean disabled) {
mContext = context;
mHandler = handler;
mSystemServerInterface = systemServerInterface;
- mDisabled = disabled;
+ mDisabled = new AtomicBoolean(disabled);
}
@Override
@@ -184,7 +185,7 @@
private void handleStartSession(@NonNull IBinder token, @NonNull ComponentName componentName,
int flags) {
- if (mState != STATE_UNKNOWN) {
+ if (mState != UNKNWON_STATE) {
// TODO(b/111276913): revisit this scenario
Log.w(TAG, "ignoring handleStartSession(" + token + ") while on state "
+ getStateAsString(mState));
@@ -247,17 +248,14 @@
}
}
- // TODO(b/111276913): change the resultCode to use flags so there's just one flag for
- // disabled stuff
- if (resultCode == STATE_DISABLED_NO_SERVICE || resultCode == STATE_DISABLED_DUPLICATED_ID
- || resultCode == STATE_DISABLED_BY_FLAG_SECURE) {
+ if ((mState & STATE_DISABLED) != 0) {
mDisabled.set(true);
handleResetSession(/* resetState= */ false);
} else {
mDisabled.set(false);
}
if (VERBOSE) {
- Log.v(TAG, "handleSessionStarted() result: code=" + resultCode + ", id=" + mId
+ Log.v(TAG, "handleSessionStarted() result: id=" + mId
+ ", state=" + getStateAsString(mState) + ", disabled=" + mDisabled.get()
+ ", binder=" + binder + ", events=" + (mEvents == null ? 0 : mEvents.size()));
}
@@ -407,7 +405,7 @@
// clearings out.
private void handleResetSession(boolean resetState) {
if (resetState) {
- mState = STATE_UNKNOWN;
+ mState = UNKNWON_STATE;
}
// TODO(b/122454205): must reset children (which currently is owned by superclass)
@@ -496,8 +494,7 @@
}
pw.print(prefix); pw.print("mDisabled: "); pw.println(mDisabled.get());
pw.print(prefix); pw.print("isEnabled(): "); pw.println(isContentCaptureEnabled());
- pw.print(prefix); pw.print("state: "); pw.print(mState); pw.print(" (");
- pw.print(getStateAsString(mState)); pw.println(")");
+ pw.print(prefix); pw.print("state: "); pw.println(getStateAsString(mState));
if (mApplicationToken != null) {
pw.print(prefix); pw.print("app token: "); pw.println(mApplicationToken);
}
diff --git a/core/java/android/view/textclassifier/ConversationAction.java b/core/java/android/view/textclassifier/ConversationAction.java
new file mode 100644
index 0000000..1a6e5d8
--- /dev/null
+++ b/core/java/android/view/textclassifier/ConversationAction.java
@@ -0,0 +1,266 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.view.textclassifier;
+
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
+import android.annotation.FloatRange;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.annotation.StringDef;
+import android.app.RemoteAction;
+import android.os.Bundle;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import com.android.internal.util.Preconditions;
+
+import java.lang.annotation.Retention;
+
+/** Represents the action suggested by a {@link TextClassifier} on a given conversation. */
+public final class ConversationAction implements Parcelable {
+
+ /** @hide */
+ @Retention(SOURCE)
+ @StringDef(
+ value = {
+ TYPE_VIEW_CALENDAR,
+ TYPE_VIEW_MAP,
+ TYPE_TRACK_FLIGHT,
+ TYPE_OPEN_URL,
+ TYPE_SEND_SMS,
+ TYPE_CALL_PHONE,
+ TYPE_SEND_EMAIL,
+ TYPE_TEXT_REPLY,
+ TYPE_CREATE_REMINDER,
+ TYPE_SHARE_LOCATION
+ },
+ prefix = "TYPE_")
+ public @interface ActionType {}
+
+ /**
+ * Indicates an action to view a calendar at a specified time.
+ */
+ public static final String TYPE_VIEW_CALENDAR = "view_calendar";
+ /**
+ * Indicates an action to view the map at a specified location.
+ */
+ public static final String TYPE_VIEW_MAP = "view_map";
+ /**
+ * Indicates an action to track a flight.
+ */
+ public static final String TYPE_TRACK_FLIGHT = "track_flight";
+ /**
+ * Indicates an action to open an URL.
+ */
+ public static final String TYPE_OPEN_URL = "open_url";
+ /**
+ * Indicates an action to send a SMS.
+ */
+ public static final String TYPE_SEND_SMS = "send_sms";
+ /**
+ * Indicates an action to call a phone number.
+ */
+ public static final String TYPE_CALL_PHONE = "call_phone";
+ /**
+ * Indicates an action to send an email.
+ */
+ public static final String TYPE_SEND_EMAIL = "send_email";
+ /**
+ * Indicates an action to reply with a text message.
+ */
+ public static final String TYPE_TEXT_REPLY = "text_reply";
+ /**
+ * Indicates an action to create a reminder.
+ */
+ public static final String TYPE_CREATE_REMINDER = "create_reminder";
+ /**
+ * Indicates an action to reply with a location.
+ */
+ public static final String TYPE_SHARE_LOCATION = "share_location";
+
+ public static final Creator<ConversationAction> CREATOR =
+ new Creator<ConversationAction>() {
+ @Override
+ public ConversationAction createFromParcel(Parcel in) {
+ return new ConversationAction(in);
+ }
+
+ @Override
+ public ConversationAction[] newArray(int size) {
+ return new ConversationAction[size];
+ }
+ };
+
+ @NonNull
+ @ActionType
+ private final String mType;
+ @NonNull
+ private final CharSequence mTextReply;
+ @Nullable
+ private final RemoteAction mAction;
+
+ @FloatRange(from = 0, to = 1)
+ private final float mScore;
+
+ @NonNull
+ private final Bundle mExtras;
+
+ private ConversationAction(
+ @NonNull String type,
+ @Nullable RemoteAction action,
+ @Nullable CharSequence textReply,
+ float score,
+ @NonNull Bundle extras) {
+ mType = Preconditions.checkNotNull(type);
+ mAction = action;
+ mTextReply = textReply;
+ mScore = score;
+ mExtras = Preconditions.checkNotNull(extras);
+ }
+
+ private ConversationAction(Parcel in) {
+ mType = in.readString();
+ mAction = in.readParcelable(null);
+ mTextReply = in.readCharSequence();
+ mScore = in.readFloat();
+ mExtras = in.readBundle();
+ }
+
+ @Override
+ public void writeToParcel(Parcel parcel, int flags) {
+ parcel.writeString(mType);
+ parcel.writeParcelable(mAction, flags);
+ parcel.writeCharSequence(mTextReply);
+ parcel.writeFloat(mScore);
+ parcel.writeBundle(mExtras);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ /** Returns the type of this action, for example, {@link #TYPE_VIEW_CALENDAR}. */
+ @NonNull
+ @ActionType
+ public String getType() {
+ return mType;
+ }
+
+ /**
+ * Returns a RemoteAction object, which contains the icon, label and a PendingIntent, for
+ * the specified action type.
+ */
+ @Nullable
+ public RemoteAction getAction() {
+ return mAction;
+ }
+
+ /**
+ * Returns the confidence score for the specified action. The value ranges from 0 (low
+ * confidence) to 1 (high confidence).
+ */
+ @FloatRange(from = 0, to = 1)
+ public float getConfidenceScore() {
+ return mScore;
+ }
+
+ /**
+ * Returns the text reply that could be sent as a reply to the given conversation.
+ * <p>
+ * This is only available when the type of the action is {@link #TYPE_TEXT_REPLY}.
+ */
+ @Nullable
+ public CharSequence getTextReply() {
+ return mTextReply;
+ }
+
+ /**
+ * Returns the extended data related to this conversation action.
+ *
+ * <p><b>NOTE: </b>Each call to this method returns a new bundle copy so clients should
+ * prefer to hold a reference to the returned bundle rather than frequently calling this
+ * method.
+ */
+ @NonNull
+ public Bundle getExtras() {
+ return mExtras.deepCopy();
+ }
+
+ /** Builder class to construct {@link ConversationAction}. */
+ public static final class Builder {
+ @Nullable
+ @ActionType
+ private String mType;
+ @Nullable
+ private RemoteAction mAction;
+ @Nullable
+ private CharSequence mTextReply;
+ private float mScore;
+ @Nullable
+ private Bundle mExtras;
+
+ public Builder(@NonNull @ActionType String actionType) {
+ mType = Preconditions.checkNotNull(actionType);
+ }
+
+ /**
+ * Sets an action that may be performed on the given conversation.
+ */
+ @NonNull
+ public Builder setAction(@Nullable RemoteAction action) {
+ mAction = action;
+ return this;
+ }
+
+ /**
+ * Sets a text reply that may be performed on the given conversation.
+ */
+ @NonNull
+ public Builder setTextReply(@Nullable CharSequence textReply) {
+ mTextReply = textReply;
+ return this;
+ }
+
+ /** Sets the confident score. */
+ @NonNull
+ public Builder setConfidenceScore(@FloatRange(from = 0, to = 1) float score) {
+ mScore = score;
+ return this;
+ }
+
+ /**
+ * Sets the extended data for the conversation action object.
+ */
+ @NonNull
+ public Builder setExtras(@Nullable Bundle extras) {
+ mExtras = extras;
+ return this;
+ }
+
+ /** Builds the {@link ConversationAction} object. */
+ @NonNull
+ public ConversationAction build() {
+ return new ConversationAction(
+ mType,
+ mAction,
+ mTextReply,
+ mScore,
+ mExtras == null ? Bundle.EMPTY : mExtras.deepCopy());
+ }
+ }
+}
diff --git a/core/java/android/view/textclassifier/ConversationActions.java b/core/java/android/view/textclassifier/ConversationActions.java
index 3f690f7..f7c1a26 100644
--- a/core/java/android/view/textclassifier/ConversationActions.java
+++ b/core/java/android/view/textclassifier/ConversationActions.java
@@ -17,18 +17,15 @@
import static java.lang.annotation.RetentionPolicy.SOURCE;
-import android.annotation.FloatRange;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringDef;
import android.app.Person;
-import android.app.RemoteAction;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.SpannedString;
-import android.util.ArraySet;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.Preconditions;
@@ -37,10 +34,8 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.Set;
/**
* Represents a list of actions suggested by a {@link TextClassifier} on a given conversation.
@@ -62,83 +57,6 @@
}
};
- /** @hide */
- @Retention(SOURCE)
- @StringDef(
- value = {
- TYPE_VIEW_CALENDAR,
- TYPE_VIEW_MAP,
- TYPE_TRACK_FLIGHT,
- TYPE_OPEN_URL,
- TYPE_SEND_SMS,
- TYPE_CALL_PHONE,
- TYPE_SEND_EMAIL,
- TYPE_TEXT_REPLY,
- TYPE_CREATE_REMINDER,
- TYPE_SHARE_LOCATION
- },
- prefix = "TYPE_")
- public @interface ActionType {}
-
- /**
- * Indicates an action to view a calendar at a specified time.
- */
- public static final String TYPE_VIEW_CALENDAR = "view_calendar";
- /**
- * Indicates an action to view the map at a specified location.
- */
- public static final String TYPE_VIEW_MAP = "view_map";
- /**
- * Indicates an action to track a flight.
- */
- public static final String TYPE_TRACK_FLIGHT = "track_flight";
- /**
- * Indicates an action to open an URL.
- */
- public static final String TYPE_OPEN_URL = "open_url";
- /**
- * Indicates an action to send a SMS.
- */
- public static final String TYPE_SEND_SMS = "send_sms";
- /**
- * Indicates an action to call a phone number.
- */
- public static final String TYPE_CALL_PHONE = "call_phone";
- /**
- * Indicates an action to send an email.
- */
- public static final String TYPE_SEND_EMAIL = "send_email";
- /**
- * Indicates an action to reply with a text message.
- */
- public static final String TYPE_TEXT_REPLY = "text_reply";
- /**
- * Indicates an action to create a reminder.
- */
- public static final String TYPE_CREATE_REMINDER = "create_reminder";
- /**
- * Indicates an action to reply with a location.
- */
- public static final String TYPE_SHARE_LOCATION = "share_location";
-
- /** @hide */
- @Retention(SOURCE)
- @StringDef(
- value = {
- HINT_FOR_NOTIFICATION,
- HINT_FOR_IN_APP,
- },
- prefix = "HINT_")
- public @interface Hint {}
- /**
- * To indicate the generated actions will be used within the app.
- */
- public static final String HINT_FOR_IN_APP = "in_app";
- /**
- * To indicate the generated actions will be used for notification.
- */
- public static final String HINT_FOR_NOTIFICATION = "notification";
-
private final List<ConversationAction> mConversationActions;
private final String mId;
@@ -184,182 +102,6 @@
return mId;
}
- /** Represents the action suggested by a {@link TextClassifier} on a given conversation. */
- public static final class ConversationAction implements Parcelable {
-
- public static final Creator<ConversationAction> CREATOR =
- new Creator<ConversationAction>() {
- @Override
- public ConversationAction createFromParcel(Parcel in) {
- return new ConversationAction(in);
- }
-
- @Override
- public ConversationAction[] newArray(int size) {
- return new ConversationAction[size];
- }
- };
-
- @NonNull
- @ActionType
- private final String mType;
- @NonNull
- private final CharSequence mTextReply;
- @Nullable
- private final RemoteAction mAction;
-
- @FloatRange(from = 0, to = 1)
- private final float mScore;
-
- @NonNull
- private final Bundle mExtras;
-
- private ConversationAction(
- @NonNull String type,
- @Nullable RemoteAction action,
- @Nullable CharSequence textReply,
- float score,
- @NonNull Bundle extras) {
- mType = Preconditions.checkNotNull(type);
- mAction = action;
- mTextReply = textReply;
- mScore = score;
- mExtras = Preconditions.checkNotNull(extras);
- }
-
- private ConversationAction(Parcel in) {
- mType = in.readString();
- mAction = in.readParcelable(null);
- mTextReply = in.readCharSequence();
- mScore = in.readFloat();
- mExtras = in.readBundle();
- }
-
- @Override
- public void writeToParcel(Parcel parcel, int flags) {
- parcel.writeString(mType);
- parcel.writeParcelable(mAction, flags);
- parcel.writeCharSequence(mTextReply);
- parcel.writeFloat(mScore);
- parcel.writeBundle(mExtras);
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @NonNull
- @ActionType
- /** Returns the type of this action, for example, {@link #TYPE_VIEW_CALENDAR}. */
- public String getType() {
- return mType;
- }
-
- @Nullable
- /**
- * Returns a RemoteAction object, which contains the icon, label and a PendingIntent, for
- * the specified action type.
- */
- public RemoteAction getAction() {
- return mAction;
- }
-
- /**
- * Returns the confidence score for the specified action. The value ranges from 0 (low
- * confidence) to 1 (high confidence).
- */
- @FloatRange(from = 0, to = 1)
- public float getConfidenceScore() {
- return mScore;
- }
-
- /**
- * Returns the text reply that could be sent as a reply to the given conversation.
- * <p>
- * This is only available when the type of the action is {@link #TYPE_TEXT_REPLY}.
- */
- @Nullable
- public CharSequence getTextReply() {
- return mTextReply;
- }
-
- /**
- * Returns the extended data related to this conversation action.
- *
- * <p><b>NOTE: </b>Each call to this method returns a new bundle copy so clients should
- * prefer to hold a reference to the returned bundle rather than frequently calling this
- * method.
- */
- @NonNull
- public Bundle getExtras() {
- return mExtras.deepCopy();
- }
-
- /** Builder class to construct {@link ConversationAction}. */
- public static final class Builder {
- @Nullable
- @ActionType
- private String mType;
- @Nullable
- private RemoteAction mAction;
- @Nullable
- private CharSequence mTextReply;
- private float mScore;
- @Nullable
- private Bundle mExtras;
-
- public Builder(@NonNull @ActionType String actionType) {
- mType = Preconditions.checkNotNull(actionType);
- }
-
- /**
- * Sets an action that may be performed on the given conversation.
- */
- @NonNull
- public Builder setAction(@Nullable RemoteAction action) {
- mAction = action;
- return this;
- }
-
- /**
- * Sets a text reply that may be performed on the given conversation.
- */
- @NonNull
- public Builder setTextReply(@Nullable CharSequence textReply) {
- mTextReply = textReply;
- return this;
- }
-
- /** Sets the confident score. */
- @NonNull
- public Builder setConfidenceScore(@FloatRange(from = 0, to = 1) float score) {
- mScore = score;
- return this;
- }
-
- /**
- * Sets the extended data for the conversation action object.
- */
- @NonNull
- public Builder setExtras(@Nullable Bundle extras) {
- mExtras = extras;
- return this;
- }
-
- /** Builds the {@link ConversationAction} object. */
- @NonNull
- public ConversationAction build() {
- return new ConversationAction(
- mType,
- mAction,
- mTextReply,
- mScore,
- mExtras == null ? Bundle.EMPTY : mExtras.deepCopy());
- }
- }
- }
-
/** Represents a message in the conversation. */
public static final class Message implements Parcelable {
/**
@@ -538,156 +280,36 @@
}
}
- /** Configuration object for specifying what action types to identify. */
- public static final class TypeConfig implements Parcelable {
- @NonNull
- @ActionType
- private final Set<String> mExcludedTypes;
- @NonNull
- @ActionType
- private final Set<String> mIncludedTypes;
- private final boolean mIncludeTypesFromTextClassifier;
-
- private TypeConfig(
- @NonNull Set<String> includedTypes,
- @NonNull Set<String> excludedTypes,
- boolean includeTypesFromTextClassifier) {
- mIncludedTypes = Preconditions.checkNotNull(includedTypes);
- mExcludedTypes = Preconditions.checkNotNull(excludedTypes);
- mIncludeTypesFromTextClassifier = includeTypesFromTextClassifier;
- }
-
- private TypeConfig(Parcel in) {
- mIncludedTypes = new ArraySet<>(in.createStringArrayList());
- mExcludedTypes = new ArraySet<>(in.createStringArrayList());
- mIncludeTypesFromTextClassifier = in.readByte() != 0;
- }
-
- @Override
- public void writeToParcel(Parcel parcel, int flags) {
- parcel.writeStringList(new ArrayList<>(mIncludedTypes));
- parcel.writeStringList(new ArrayList<>(mExcludedTypes));
- parcel.writeByte((byte) (mIncludeTypesFromTextClassifier ? 1 : 0));
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- public static final Creator<TypeConfig> CREATOR =
- new Creator<TypeConfig>() {
- @Override
- public TypeConfig createFromParcel(Parcel in) {
- return new TypeConfig(in);
- }
-
- @Override
- public TypeConfig[] newArray(int size) {
- return new TypeConfig[size];
- }
- };
-
- /**
- * Returns a final list of types that the text classifier should look for.
- *
- * <p>NOTE: This method is intended for use by a text classifier.
- *
- * @param defaultTypes types the text classifier thinks should be included before factoring
- * in the included/excluded types given by the client.
- */
- @NonNull
- public Collection<String> resolveTypes(@Nullable Collection<String> defaultTypes) {
- Set<String> types = new ArraySet<>();
- if (mIncludeTypesFromTextClassifier && defaultTypes != null) {
- types.addAll(defaultTypes);
- }
- types.addAll(mIncludedTypes);
- types.removeAll(mExcludedTypes);
- return Collections.unmodifiableCollection(types);
- }
-
- /**
- * Return whether the client allows the text classifier to include its own list of default
- * types. If this function returns {@code true}, the text classifier can consider specifying
- * a default list of entity types in {@link #resolveTypes(Collection)}.
- *
- * <p>NOTE: This method is intended for use by a text classifier.
- *
- * @see #resolveTypes(Collection)
- */
- public boolean shouldIncludeTypesFromTextClassifier() {
- return mIncludeTypesFromTextClassifier;
- }
-
- /** Builder class to construct the {@link TypeConfig} object. */
- public static final class Builder {
- @Nullable
- private Collection<String> mExcludedTypes;
- @Nullable
- private Collection<String> mIncludedTypes;
- private boolean mIncludeTypesFromTextClassifier = true;
-
- /**
- * Sets a collection of types that are explicitly included, for example, {@link
- * #TYPE_VIEW_CALENDAR}.
- */
- @NonNull
- public Builder setIncludedTypes(
- @Nullable @ActionType Collection<String> includedTypes) {
- mIncludedTypes = includedTypes;
- return this;
- }
-
- /**
- * Sets a collection of types that are explicitly excluded, for example, {@link
- * #TYPE_VIEW_CALENDAR}.
- */
- @NonNull
- public Builder setExcludedTypes(
- @Nullable @ActionType Collection<String> excludedTypes) {
- mExcludedTypes = excludedTypes;
- return this;
- }
-
- /**
- * Specifies whether or not to include the types suggested by the text classifier. By
- * default, it is included.
- */
- @NonNull
- public Builder includeTypesFromTextClassifier(boolean includeTypesFromTextClassifier) {
- mIncludeTypesFromTextClassifier = includeTypesFromTextClassifier;
- return this;
- }
-
- /**
- * Combines all of the options that have been set and returns a new {@link TypeConfig}
- * object.
- */
- @NonNull
- public TypeConfig build() {
- return new TypeConfig(
- mIncludedTypes == null
- ? Collections.emptySet()
- : new ArraySet<>(mIncludedTypes),
- mExcludedTypes == null
- ? Collections.emptySet()
- : new ArraySet<>(mExcludedTypes),
- mIncludeTypesFromTextClassifier);
- }
- }
- }
-
/**
* A request object for generating conversation action suggestions.
*
* @see TextClassifier#suggestConversationActions(Request)
*/
public static final class Request implements Parcelable {
+
+ /** @hide */
+ @Retention(SOURCE)
+ @StringDef(
+ value = {
+ HINT_FOR_NOTIFICATION,
+ HINT_FOR_IN_APP,
+ },
+ prefix = "HINT_")
+ public @interface Hint {}
+
+ /**
+ * To indicate the generated actions will be used within the app.
+ */
+ public static final String HINT_FOR_IN_APP = "in_app";
+ /**
+ * To indicate the generated actions will be used for notification.
+ */
+ public static final String HINT_FOR_NOTIFICATION = "notification";
+
@NonNull
private final List<Message> mConversation;
@NonNull
- private final TypeConfig mTypeConfig;
+ private final TextClassifier.EntityConfig mTypeConfig;
private final int mMaxSuggestions;
@NonNull
@Hint
@@ -699,7 +321,7 @@
private Request(
@NonNull List<Message> conversation,
- @NonNull TypeConfig typeConfig,
+ @NonNull TextClassifier.EntityConfig typeConfig,
int maxSuggestions,
String conversationId,
@Nullable @Hint List<String> hints) {
@@ -713,7 +335,7 @@
private static Request readFromParcel(Parcel in) {
List<Message> conversation = new ArrayList<>();
in.readParcelableList(conversation, null);
- TypeConfig typeConfig = in.readParcelable(null);
+ TextClassifier.EntityConfig typeConfig = in.readParcelable(null);
int maxSuggestions = in.readInt();
String conversationId = in.readString();
List<String> hints = new ArrayList<>();
@@ -760,7 +382,7 @@
/** Returns the type config. */
@NonNull
- public TypeConfig getTypeConfig() {
+ public TextClassifier.EntityConfig getTypeConfig() {
return mTypeConfig;
}
@@ -820,7 +442,7 @@
@NonNull
private List<Message> mConversation;
@Nullable
- private TypeConfig mTypeConfig;
+ private TextClassifier.EntityConfig mTypeConfig;
private int mMaxSuggestions;
@Nullable
private String mConversationId;
@@ -849,7 +471,7 @@
/** Sets the type config. */
@NonNull
- public Builder setTypeConfig(@Nullable TypeConfig typeConfig) {
+ public Builder setTypeConfig(@Nullable TextClassifier.EntityConfig typeConfig) {
mTypeConfig = typeConfig;
return this;
}
@@ -879,7 +501,9 @@
public Request build() {
return new Request(
Collections.unmodifiableList(mConversation),
- mTypeConfig == null ? new TypeConfig.Builder().build() : mTypeConfig,
+ mTypeConfig == null
+ ? new TextClassifier.EntityConfig.Builder().build()
+ : mTypeConfig,
mMaxSuggestions,
mConversationId,
mHints == null
diff --git a/core/java/android/view/textclassifier/TextClassificationConstants.java b/core/java/android/view/textclassifier/TextClassificationConstants.java
index 50801a2..ce680ec 100644
--- a/core/java/android/view/textclassifier/TextClassificationConstants.java
+++ b/core/java/android/view/textclassifier/TextClassificationConstants.java
@@ -117,15 +117,15 @@
.add(TextClassifier.TYPE_FLIGHT_NUMBER).toString();
private static final String CONVERSATION_ACTIONS_TYPES_DEFAULT_VALUES =
new StringJoiner(ENTITY_LIST_DELIMITER)
- .add(ConversationActions.TYPE_TEXT_REPLY)
- .add(ConversationActions.TYPE_CREATE_REMINDER)
- .add(ConversationActions.TYPE_CALL_PHONE)
- .add(ConversationActions.TYPE_OPEN_URL)
- .add(ConversationActions.TYPE_SEND_EMAIL)
- .add(ConversationActions.TYPE_SEND_SMS)
- .add(ConversationActions.TYPE_TRACK_FLIGHT)
- .add(ConversationActions.TYPE_VIEW_CALENDAR)
- .add(ConversationActions.TYPE_VIEW_MAP)
+ .add(ConversationAction.TYPE_TEXT_REPLY)
+ .add(ConversationAction.TYPE_CREATE_REMINDER)
+ .add(ConversationAction.TYPE_CALL_PHONE)
+ .add(ConversationAction.TYPE_OPEN_URL)
+ .add(ConversationAction.TYPE_SEND_EMAIL)
+ .add(ConversationAction.TYPE_SEND_SMS)
+ .add(ConversationAction.TYPE_TRACK_FLIGHT)
+ .add(ConversationAction.TYPE_VIEW_CALENDAR)
+ .add(ConversationAction.TYPE_VIEW_MAP)
.toString();
private final boolean mSystemTextClassifierEnabled;
diff --git a/core/java/android/view/textclassifier/TextClassifier.java b/core/java/android/view/textclassifier/TextClassifier.java
index 8709e09..5a56136 100644
--- a/core/java/android/view/textclassifier/TextClassifier.java
+++ b/core/java/android/view/textclassifier/TextClassifier.java
@@ -32,7 +32,6 @@
import android.text.util.Linkify;
import android.text.util.Linkify.LinkifyMask;
import android.util.ArrayMap;
-import android.util.ArraySet;
import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.Preconditions;
@@ -43,6 +42,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -324,7 +324,7 @@
}
/**
- * Detects the language of the specified text.
+ * Detects the language of the text in the given request.
*
* <p><strong>NOTE: </strong>Call on a worker thread.
*
@@ -403,42 +403,59 @@
default void dump(@NonNull IndentingPrintWriter printWriter) {}
/**
- * Configuration object for specifying what entities to identify.
+ * Configuration object for specifying what entity types to identify.
*
* Configs are initially based on a predefined preset, and can be modified from there.
*/
final class EntityConfig implements Parcelable {
- private final Collection<String> mHints;
- private final Collection<String> mExcludedEntityTypes;
- private final Collection<String> mIncludedEntityTypes;
- private final boolean mUseHints;
+ private final List<String> mIncludedTypes;
+ private final List<String> mExcludedTypes;
+ private final List<String> mHints;
+ private final boolean mIncludeTypesFromTextClassifier;
- private EntityConfig(boolean useHints, Collection<String> hints,
- Collection<String> includedEntityTypes, Collection<String> excludedEntityTypes) {
- mHints = hints == null
- ? Collections.EMPTY_LIST
- : Collections.unmodifiableCollection(new ArraySet<>(hints));
- mExcludedEntityTypes = excludedEntityTypes == null
- ? Collections.EMPTY_LIST : new ArraySet<>(excludedEntityTypes);
- mIncludedEntityTypes = includedEntityTypes == null
- ? Collections.EMPTY_LIST : new ArraySet<>(includedEntityTypes);
- mUseHints = useHints;
+ private EntityConfig(
+ List<String> includedEntityTypes,
+ List<String> excludedEntityTypes,
+ List<String> hints,
+ boolean includeTypesFromTextClassifier) {
+ mIncludedTypes = Preconditions.checkNotNull(includedEntityTypes);
+ mExcludedTypes = Preconditions.checkNotNull(excludedEntityTypes);
+ mHints = Preconditions.checkNotNull(hints);
+ mIncludeTypesFromTextClassifier = includeTypesFromTextClassifier;
+ }
+
+ private EntityConfig(Parcel in) {
+ mIncludedTypes = new ArrayList<>();
+ in.readStringList(mIncludedTypes);
+ mExcludedTypes = new ArrayList<>();
+ in.readStringList(mExcludedTypes);
+ List<String> tmpHints = new ArrayList<>();
+ in.readStringList(tmpHints);
+ mHints = Collections.unmodifiableList(tmpHints);
+ mIncludeTypesFromTextClassifier = in.readByte() != 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel parcel, int flags) {
+ parcel.writeStringList(mIncludedTypes);
+ parcel.writeStringList(mExcludedTypes);
+ parcel.writeStringList(mHints);
+ parcel.writeByte((byte) (mIncludeTypesFromTextClassifier ? 1 : 0));
}
/**
* Creates an EntityConfig.
*
* @param hints Hints for the TextClassifier to determine what types of entities to find.
+ *
+ * @deprecated Use {@link Builder} instead.
*/
+ @Deprecated
public static EntityConfig createWithHints(@Nullable Collection<String> hints) {
- return new EntityConfig(/* useHints */ true, hints,
- /* includedEntityTypes */null, /* excludedEntityTypes */ null);
- }
-
- // TODO: Remove once apps can build against the latest sdk.
- /** @hide */
- public static EntityConfig create(@Nullable Collection<String> hints) {
- return createWithHints(hints);
+ return new EntityConfig.Builder()
+ .includeTypesFromTextClassifier(true)
+ .setHints(hints)
+ .build();
}
/**
@@ -450,12 +467,19 @@
*
*
* Note that if an entity has been excluded, the exclusion will take precedence.
+ *
+ * @deprecated Use {@link Builder} instead.
*/
+ @Deprecated
public static EntityConfig create(@Nullable Collection<String> hints,
@Nullable Collection<String> includedEntityTypes,
@Nullable Collection<String> excludedEntityTypes) {
- return new EntityConfig(/* useHints */ true, hints,
- includedEntityTypes, excludedEntityTypes);
+ return new EntityConfig.Builder()
+ .setIncludedTypes(includedEntityTypes)
+ .setExcludedTypes(excludedEntityTypes)
+ .setHints(hints)
+ .includeTypesFromTextClassifier(true)
+ .build();
}
/**
@@ -463,34 +487,33 @@
*
* @param entityTypes Complete set of entities, e.g. {@link #TYPE_URL} to find.
*
+ * @deprecated Use {@link Builder} instead.
*/
+ @Deprecated
public static EntityConfig createWithExplicitEntityList(
@Nullable Collection<String> entityTypes) {
- return new EntityConfig(/* useHints */ false, /* hints */ null,
- /* includedEntityTypes */ entityTypes, /* excludedEntityTypes */ null);
- }
-
- // TODO: Remove once apps can build against the latest sdk.
- /** @hide */
- public static EntityConfig createWithEntityList(@Nullable Collection<String> entityTypes) {
- return createWithExplicitEntityList(entityTypes);
+ return new EntityConfig.Builder()
+ .setIncludedTypes(entityTypes)
+ .includeTypesFromTextClassifier(false)
+ .build();
}
/**
- * Returns a list of the final set of entities to find.
+ * Returns a final list of entity types to find.
*
- * @param entities Entities we think should be found before factoring in includes/excludes
+ * @param entityTypes Entity types we think should be found before factoring in
+ * includes/excludes
*
* This method is intended for use by TextClassifier implementations.
*/
public Collection<String> resolveEntityListModifications(
- @NonNull Collection<String> entities) {
- final Set<String> finalSet = new HashSet();
- if (mUseHints) {
- finalSet.addAll(entities);
+ @NonNull Collection<String> entityTypes) {
+ final Set<String> finalSet = new HashSet<>();
+ if (mIncludeTypesFromTextClassifier) {
+ finalSet.addAll(entityTypes);
}
- finalSet.addAll(mIncludedEntityTypes);
- finalSet.removeAll(mExcludedEntityTypes);
+ finalSet.addAll(mIncludedTypes);
+ finalSet.removeAll(mExcludedTypes);
return finalSet;
}
@@ -503,17 +526,22 @@
return mHints;
}
- @Override
- public int describeContents() {
- return 0;
+ /**
+ * Return whether the client allows the text classifier to include its own list of
+ * default types. If this function returns {@code true}, a default list of types suggested
+ * from a text classifier will be taking into account.
+ *
+ * <p>NOTE: This method is intended for use by a text classifier.
+ *
+ * @see #resolveEntityListModifications(Collection)
+ */
+ public boolean shouldIncludeTypesFromTextClassifier() {
+ return mIncludeTypesFromTextClassifier;
}
@Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeStringList(new ArrayList<>(mHints));
- dest.writeStringList(new ArrayList<>(mExcludedEntityTypes));
- dest.writeStringList(new ArrayList<>(mIncludedEntityTypes));
- dest.writeInt(mUseHints ? 1 : 0);
+ public int describeContents() {
+ return 0;
}
public static final Parcelable.Creator<EntityConfig> CREATOR =
@@ -529,11 +557,75 @@
}
};
- private EntityConfig(Parcel in) {
- mHints = new ArraySet<>(in.createStringArrayList());
- mExcludedEntityTypes = new ArraySet<>(in.createStringArrayList());
- mIncludedEntityTypes = new ArraySet<>(in.createStringArrayList());
- mUseHints = in.readInt() == 1;
+
+
+ /** Builder class to construct the {@link EntityConfig} object. */
+ public static final class Builder {
+ @Nullable
+ private Collection<String> mIncludedTypes;
+ @Nullable
+ private Collection<String> mExcludedTypes;
+ @Nullable
+ private Collection<String> mHints;
+ private boolean mIncludeTypesFromTextClassifier = true;
+
+ /**
+ * Sets a collection of types that are explicitly included.
+ */
+ @NonNull
+ public Builder setIncludedTypes(@Nullable Collection<String> includedTypes) {
+ mIncludedTypes = includedTypes;
+ return this;
+ }
+
+ /**
+ * Sets a collection of types that are explicitly excluded.
+ */
+ @NonNull
+ public Builder setExcludedTypes(@Nullable Collection<String> excludedTypes) {
+ mExcludedTypes = excludedTypes;
+ return this;
+ }
+
+ /**
+ * Specifies whether or not to include the types suggested by the text classifier. By
+ * default, it is included.
+ */
+ @NonNull
+ public Builder includeTypesFromTextClassifier(boolean includeTypesFromTextClassifier) {
+ mIncludeTypesFromTextClassifier = includeTypesFromTextClassifier;
+ return this;
+ }
+
+
+ /**
+ * Sets the hints for the TextClassifier to determine what types of entities to find.
+ * These hints will only be used if {@link #includeTypesFromTextClassifier} is
+ * set to be true.
+ */
+ public Builder setHints(Collection<String> hints) {
+ mHints = hints;
+ return this;
+ }
+
+ /**
+ * Combines all of the options that have been set and returns a new {@link EntityConfig}
+ * object.
+ */
+ @NonNull
+ public EntityConfig build() {
+ return new EntityConfig(
+ mIncludedTypes == null
+ ? Collections.emptyList()
+ : new ArrayList<>(mIncludedTypes),
+ mExcludedTypes == null
+ ? Collections.emptyList()
+ : new ArrayList<>(mExcludedTypes),
+ mHints == null
+ ? Collections.emptyList()
+ : Collections.unmodifiableList(new ArrayList<>(mHints)),
+ mIncludeTypesFromTextClassifier);
+ }
}
}
diff --git a/core/java/android/view/textclassifier/TextClassifierImpl.java b/core/java/android/view/textclassifier/TextClassifierImpl.java
index d5b9eb1..9ab963e 100644
--- a/core/java/android/view/textclassifier/TextClassifierImpl.java
+++ b/core/java/android/view/textclassifier/TextClassifierImpl.java
@@ -393,7 +393,7 @@
actionsImpl.suggestActions(nativeConversation, null);
Collection<String> expectedTypes = resolveActionTypesFromRequest(request);
- List<ConversationActions.ConversationAction> conversationActions = new ArrayList<>();
+ List<ConversationAction> conversationActions = new ArrayList<>();
int maxSuggestions = nativeSuggestions.length;
if (request.getMaxSuggestions() > 0) {
maxSuggestions = Math.min(request.getMaxSuggestions(), nativeSuggestions.length);
@@ -405,7 +405,7 @@
continue;
}
conversationActions.add(
- new ConversationActions.ConversationAction.Builder(actionType)
+ new ConversationAction.Builder(actionType)
.setTextReply(nativeSuggestion.getResponseText())
.setConfidenceScore(nativeSuggestion.getScore())
.build());
@@ -445,10 +445,10 @@
private Collection<String> resolveActionTypesFromRequest(ConversationActions.Request request) {
List<String> defaultActionTypes =
- request.getHints().contains(ConversationActions.HINT_FOR_NOTIFICATION)
+ request.getHints().contains(ConversationActions.Request.HINT_FOR_NOTIFICATION)
? mSettings.getNotificationConversationActionTypes()
: mSettings.getInAppConversationActionTypes();
- return request.getTypeConfig().resolveTypes(defaultActionTypes);
+ return request.getTypeConfig().resolveEntityListModifications(defaultActionTypes);
}
private AnnotatorModel getAnnotatorImpl(LocaleList localeList)
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index cc8da5c..5125f5c 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -30,6 +30,7 @@
import android.database.ContentObserver;
import android.hardware.usb.UsbManager;
import android.net.ConnectivityManager;
+import android.net.INetworkStatsService;
import android.net.NetworkStats;
import android.net.Uri;
import android.net.wifi.WifiActivityEnergyInfo;
@@ -86,7 +87,6 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.location.gnssmetrics.GnssMetrics;
-import com.android.internal.net.NetworkStatsFactory;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.FastXmlSerializer;
@@ -11012,7 +11012,6 @@
}
}
- private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory();
private final Pools.Pool<NetworkStats> mNetworkStatsPool = new Pools.SynchronizedPool<>(6);
private final Object mWifiNetworkLock = new Object();
@@ -11034,11 +11033,16 @@
private NetworkStats readNetworkStatsLocked(String[] ifaces) {
try {
if (!ArrayUtils.isEmpty(ifaces)) {
- return mNetworkStatsFactory.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces,
- NetworkStats.TAG_NONE, mNetworkStatsPool.acquire());
+ INetworkStatsService statsService = INetworkStatsService.Stub.asInterface(
+ ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
+ if (statsService != null) {
+ return statsService.getDetailedUidStats(ifaces);
+ } else {
+ Slog.e(TAG, "Failed to get networkStatsService ");
+ }
}
- } catch (IOException e) {
- Slog.e(TAG, "failed to read network stats for ifaces: " + Arrays.toString(ifaces));
+ } catch (RemoteException e) {
+ Slog.e(TAG, "failed to read network stats for ifaces: " + Arrays.toString(ifaces) + e);
}
return null;
}
diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp
index c073466..876bd4f 100755
--- a/core/jni/android/graphics/Bitmap.cpp
+++ b/core/jni/android/graphics/Bitmap.cpp
@@ -8,7 +8,6 @@
#include "SkImageInfo.h"
#include "SkColor.h"
#include "SkColorSpace.h"
-#include "SkMatrix44.h"
#include "GraphicsJNI.h"
#include "SkStream.h"
@@ -356,8 +355,8 @@
if (xyzD50 == nullptr || transferParameters == nullptr) {
colorSpace = SkColorSpace::MakeSRGB();
} else {
- SkColorSpaceTransferFn p = GraphicsJNI::getNativeTransferParameters(env, transferParameters);
- SkMatrix44 xyzMatrix = GraphicsJNI::getNativeXYZMatrix(env, xyzD50);
+ skcms_TransferFunction p = GraphicsJNI::getNativeTransferParameters(env, transferParameters);
+ skcms_Matrix3x3 xyzMatrix = GraphicsJNI::getNativeXYZMatrix(env, xyzD50);
colorSpace = SkColorSpace::MakeRGB(p, xyzMatrix);
}
@@ -549,8 +548,7 @@
if (skbitmap.colorType() == kRGBA_F16_SkColorType) {
// Convert to P3 before encoding. This matches SkAndroidCodec::computeOutputColorSpace
// for wide gamuts.
- auto cs = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
- SkColorSpace::kDCIP3_D65_Gamut);
+ auto cs = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
auto info = skbitmap.info().makeColorType(kRGBA_8888_SkColorType)
.makeColorSpace(std::move(cs));
SkBitmap p3;
@@ -568,11 +566,34 @@
return SkEncodeImage(strm.get(), skbitmap, fm, quality) ? JNI_TRUE : JNI_FALSE;
}
+static inline void bitmapErase(SkBitmap bitmap, const SkColor4f& color,
+ const sk_sp<SkColorSpace>& colorSpace) {
+ SkPaint p;
+ p.setColor4f(color, colorSpace.get());
+ p.setBlendMode(SkBlendMode::kSrc);
+ SkCanvas canvas(bitmap);
+ canvas.drawPaint(p);
+}
+
static void Bitmap_erase(JNIEnv* env, jobject, jlong bitmapHandle, jint color) {
LocalScopedBitmap bitmap(bitmapHandle);
SkBitmap skBitmap;
bitmap->getSkBitmap(&skBitmap);
- skBitmap.eraseColor(color);
+ bitmapErase(skBitmap, SkColor4f::FromColor(color), SkColorSpace::MakeSRGB());
+}
+
+static void Bitmap_eraseLong(JNIEnv* env, jobject, jlong bitmapHandle, jobject jColorSpace,
+ jfloat r, jfloat g, jfloat b, jfloat a) {
+ sk_sp<SkColorSpace> cs = GraphicsJNI::getNativeColorSpace(env, jColorSpace);
+ if (GraphicsJNI::hasException(env)) {
+ return;
+ }
+
+ LocalScopedBitmap bitmap(bitmapHandle);
+ SkBitmap skBitmap;
+ bitmap->getSkBitmap(&skBitmap);
+ SkColor4f color = SkColor4f{r, g, b, a};
+ bitmapErase(skBitmap, color, cs);
}
static jint Bitmap_rowBytes(JNIEnv* env, jobject, jlong bitmapHandle) {
@@ -910,32 +931,32 @@
SkColorSpace* colorSpace = bitmapHolder->info().colorSpace();
if (colorSpace == nullptr) return JNI_FALSE;
- SkMatrix44 xyzMatrix(SkMatrix44::kUninitialized_Constructor);
+ skcms_Matrix3x3 xyzMatrix;
if (!colorSpace->toXYZD50(&xyzMatrix)) return JNI_FALSE;
jfloat* xyz = env->GetFloatArrayElements(xyzArray, NULL);
- xyz[0] = xyzMatrix.getFloat(0, 0);
- xyz[1] = xyzMatrix.getFloat(1, 0);
- xyz[2] = xyzMatrix.getFloat(2, 0);
- xyz[3] = xyzMatrix.getFloat(0, 1);
- xyz[4] = xyzMatrix.getFloat(1, 1);
- xyz[5] = xyzMatrix.getFloat(2, 1);
- xyz[6] = xyzMatrix.getFloat(0, 2);
- xyz[7] = xyzMatrix.getFloat(1, 2);
- xyz[8] = xyzMatrix.getFloat(2, 2);
+ xyz[0] = xyzMatrix.vals[0][0];
+ xyz[1] = xyzMatrix.vals[1][0];
+ xyz[2] = xyzMatrix.vals[2][0];
+ xyz[3] = xyzMatrix.vals[0][1];
+ xyz[4] = xyzMatrix.vals[1][1];
+ xyz[5] = xyzMatrix.vals[2][1];
+ xyz[6] = xyzMatrix.vals[0][2];
+ xyz[7] = xyzMatrix.vals[1][2];
+ xyz[8] = xyzMatrix.vals[2][2];
env->ReleaseFloatArrayElements(xyzArray, xyz, 0);
- SkColorSpaceTransferFn transferParams;
+ skcms_TransferFunction transferParams;
if (!colorSpace->isNumericalTransferFn(&transferParams)) return JNI_FALSE;
jfloat* params = env->GetFloatArrayElements(paramsArray, NULL);
- params[0] = transferParams.fA;
- params[1] = transferParams.fB;
- params[2] = transferParams.fC;
- params[3] = transferParams.fD;
- params[4] = transferParams.fE;
- params[5] = transferParams.fF;
- params[6] = transferParams.fG;
+ params[0] = transferParams.a;
+ params[1] = transferParams.b;
+ params[2] = transferParams.c;
+ params[3] = transferParams.d;
+ params[4] = transferParams.e;
+ params[5] = transferParams.f;
+ params[6] = transferParams.g;
env->ReleaseFloatArrayElements(paramsArray, params, 0);
return JNI_TRUE;
@@ -1121,8 +1142,8 @@
static jobject Bitmap_wrapHardwareBufferBitmap(JNIEnv* env, jobject, jobject hardwareBuffer,
jfloatArray xyzD50, jobject transferParameters) {
- SkColorSpaceTransferFn p = GraphicsJNI::getNativeTransferParameters(env, transferParameters);
- SkMatrix44 xyzMatrix = GraphicsJNI::getNativeXYZMatrix(env, xyzD50);
+ skcms_TransferFunction p = GraphicsJNI::getNativeTransferParameters(env, transferParameters);
+ skcms_Matrix3x3 xyzMatrix = GraphicsJNI::getNativeXYZMatrix(env, xyzD50);
sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeRGB(p, xyzMatrix);
AHardwareBuffer* hwBuf = android_hardware_HardwareBuffer_getNativeHardwareBuffer(env,
hardwareBuffer);
@@ -1183,6 +1204,7 @@
{ "nativeCompress", "(JIILjava/io/OutputStream;[B)Z",
(void*)Bitmap_compress },
{ "nativeErase", "(JI)V", (void*)Bitmap_erase },
+ { "nativeErase", "(JLandroid/graphics/ColorSpace;FFFF)V", (void*)Bitmap_eraseLong },
{ "nativeRowBytes", "(J)I", (void*)Bitmap_rowBytes },
{ "nativeConfig", "(J)I", (void*)Bitmap_config },
{ "nativeHasAlpha", "(J)Z", (void*)Bitmap_hasAlpha },
diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp
index 67d0c8a..9e74b88 100644
--- a/core/jni/android/graphics/Graphics.cpp
+++ b/core/jni/android/graphics/Graphics.cpp
@@ -424,30 +424,30 @@
///////////////////////////////////////////////////////////////////////////////
-SkColorSpaceTransferFn GraphicsJNI::getNativeTransferParameters(JNIEnv* env, jobject transferParams) {
- SkColorSpaceTransferFn p;
- p.fA = (float) env->GetDoubleField(transferParams, gTransferParams_aFieldID);
- p.fB = (float) env->GetDoubleField(transferParams, gTransferParams_bFieldID);
- p.fC = (float) env->GetDoubleField(transferParams, gTransferParams_cFieldID);
- p.fD = (float) env->GetDoubleField(transferParams, gTransferParams_dFieldID);
- p.fE = (float) env->GetDoubleField(transferParams, gTransferParams_eFieldID);
- p.fF = (float) env->GetDoubleField(transferParams, gTransferParams_fFieldID);
- p.fG = (float) env->GetDoubleField(transferParams, gTransferParams_gFieldID);
+skcms_TransferFunction GraphicsJNI::getNativeTransferParameters(JNIEnv* env, jobject transferParams) {
+ skcms_TransferFunction p;
+ p.a = (float) env->GetDoubleField(transferParams, gTransferParams_aFieldID);
+ p.b = (float) env->GetDoubleField(transferParams, gTransferParams_bFieldID);
+ p.c = (float) env->GetDoubleField(transferParams, gTransferParams_cFieldID);
+ p.d = (float) env->GetDoubleField(transferParams, gTransferParams_dFieldID);
+ p.e = (float) env->GetDoubleField(transferParams, gTransferParams_eFieldID);
+ p.f = (float) env->GetDoubleField(transferParams, gTransferParams_fFieldID);
+ p.g = (float) env->GetDoubleField(transferParams, gTransferParams_gFieldID);
return p;
}
-SkMatrix44 GraphicsJNI::getNativeXYZMatrix(JNIEnv* env, jfloatArray xyzD50) {
- SkMatrix44 xyzMatrix(SkMatrix44::kIdentity_Constructor);
+skcms_Matrix3x3 GraphicsJNI::getNativeXYZMatrix(JNIEnv* env, jfloatArray xyzD50) {
+ skcms_Matrix3x3 xyzMatrix;
jfloat* array = env->GetFloatArrayElements(xyzD50, NULL);
- xyzMatrix.setFloat(0, 0, array[0]);
- xyzMatrix.setFloat(1, 0, array[1]);
- xyzMatrix.setFloat(2, 0, array[2]);
- xyzMatrix.setFloat(0, 1, array[3]);
- xyzMatrix.setFloat(1, 1, array[4]);
- xyzMatrix.setFloat(2, 1, array[5]);
- xyzMatrix.setFloat(0, 2, array[6]);
- xyzMatrix.setFloat(1, 2, array[7]);
- xyzMatrix.setFloat(2, 2, array[8]);
+ xyzMatrix.vals[0][0] = array[0];
+ xyzMatrix.vals[1][0] = array[1];
+ xyzMatrix.vals[2][0] = array[2];
+ xyzMatrix.vals[0][1] = array[3];
+ xyzMatrix.vals[1][1] = array[4];
+ xyzMatrix.vals[2][1] = array[5];
+ xyzMatrix.vals[0][2] = array[6];
+ xyzMatrix.vals[1][2] = array[7];
+ xyzMatrix.vals[2][2] = array[8];
env->ReleaseFloatArrayElements(xyzD50, array, 0);
return xyzMatrix;
}
@@ -456,12 +456,14 @@
if (colorSpace == nullptr) return nullptr;
if (!env->IsInstanceOf(colorSpace, gColorSpaceRGB_class)) {
doThrowIAE(env, "The color space must be an RGB color space");
+ return nullptr;
}
jobject transferParams = env->CallObjectMethod(colorSpace,
gColorSpaceRGB_getTransferParametersMethodID);
if (transferParams == nullptr) {
doThrowIAE(env, "The color space must use an ICC parametric transfer function");
+ return nullptr;
}
jfloatArray illuminantD50 = (jfloatArray) env->GetStaticObjectField(gColorSpace_class,
@@ -472,8 +474,8 @@
jfloatArray xyzD50 = (jfloatArray) env->CallObjectMethod(colorSpaceD50,
gColorSpaceRGB_getTransformMethodID);
- SkMatrix44 xyzMatrix = getNativeXYZMatrix(env, xyzD50);
- SkColorSpaceTransferFn transferFunction = getNativeTransferParameters(env, transferParams);
+ skcms_Matrix3x3 xyzMatrix = getNativeXYZMatrix(env, xyzD50);
+ skcms_TransferFunction transferFunction = getNativeTransferParameters(env, transferParams);
return SkColorSpace::MakeRGB(transferFunction, xyzMatrix);
}
@@ -499,30 +501,30 @@
} else if (decodeColorSpace.get() != nullptr) {
// Try to match against known RGB color spaces using the CIE XYZ D50
// conversion matrix and numerical transfer function parameters
- SkMatrix44 xyzMatrix(SkMatrix44::kUninitialized_Constructor);
+ skcms_Matrix3x3 xyzMatrix;
LOG_ALWAYS_FATAL_IF(!decodeColorSpace->toXYZD50(&xyzMatrix));
- SkColorSpaceTransferFn transferParams;
+ skcms_TransferFunction transferParams;
// We can only handle numerical transfer functions at the moment
LOG_ALWAYS_FATAL_IF(!decodeColorSpace->isNumericalTransferFn(&transferParams));
jobject params = env->NewObject(gTransferParameters_class,
gTransferParameters_constructorMethodID,
- transferParams.fA, transferParams.fB, transferParams.fC,
- transferParams.fD, transferParams.fE, transferParams.fF,
- transferParams.fG);
+ transferParams.a, transferParams.b, transferParams.c,
+ transferParams.d, transferParams.e, transferParams.f,
+ transferParams.g);
jfloatArray xyzArray = env->NewFloatArray(9);
jfloat xyz[9] = {
- xyzMatrix.getFloat(0, 0),
- xyzMatrix.getFloat(1, 0),
- xyzMatrix.getFloat(2, 0),
- xyzMatrix.getFloat(0, 1),
- xyzMatrix.getFloat(1, 1),
- xyzMatrix.getFloat(2, 1),
- xyzMatrix.getFloat(0, 2),
- xyzMatrix.getFloat(1, 2),
- xyzMatrix.getFloat(2, 2)
+ xyzMatrix.vals[0][0],
+ xyzMatrix.vals[1][0],
+ xyzMatrix.vals[2][0],
+ xyzMatrix.vals[0][1],
+ xyzMatrix.vals[1][1],
+ xyzMatrix.vals[2][1],
+ xyzMatrix.vals[0][2],
+ xyzMatrix.vals[1][2],
+ xyzMatrix.vals[2][2]
};
env->SetFloatArrayRegion(xyzArray, 0, 9, xyz);
diff --git a/core/jni/android/graphics/GraphicsJNI.h b/core/jni/android/graphics/GraphicsJNI.h
index b0bd683..699d153 100644
--- a/core/jni/android/graphics/GraphicsJNI.h
+++ b/core/jni/android/graphics/GraphicsJNI.h
@@ -10,7 +10,6 @@
#include "SkPoint.h"
#include "SkRect.h"
#include "SkColorSpace.h"
-#include "SkMatrix44.h"
#include <jni.h>
#include <hwui/Canvas.h>
#include <hwui/Bitmap.h>
@@ -101,8 +100,8 @@
int srcStride, int x, int y, int width, int height,
SkBitmap* dstBitmap);
- static SkColorSpaceTransferFn getNativeTransferParameters(JNIEnv* env, jobject transferParams);
- static SkMatrix44 getNativeXYZMatrix(JNIEnv* env, jfloatArray xyzD50);
+ static skcms_TransferFunction getNativeTransferParameters(JNIEnv* env, jobject transferParams);
+ static skcms_Matrix3x3 getNativeXYZMatrix(JNIEnv* env, jfloatArray xyzD50);
static sk_sp<SkColorSpace> getNativeColorSpace(JNIEnv* env, jobject colorSpace);
static jobject getColorSpace(JNIEnv* env, sk_sp<SkColorSpace>& decodeColorSpace,
diff --git a/core/jni/android_app_NativeActivity.cpp b/core/jni/android_app_NativeActivity.cpp
index 49a24a3..b2d3651 100644
--- a/core/jni/android_app_NativeActivity.cpp
+++ b/core/jni/android_app_NativeActivity.cpp
@@ -281,15 +281,18 @@
std::unique_ptr<NativeCode> code;
bool needs_native_bridge = false;
+ char* nativeloader_error_msg = nullptr;
void* handle = OpenNativeLibrary(env,
sdkVersion,
pathStr.c_str(),
classLoader,
libraryPath,
&needs_native_bridge,
- &g_error_msg);
+ &nativeloader_error_msg);
if (handle == nullptr) {
+ g_error_msg = nativeloader_error_msg;
+ NativeLoaderFreeErrorMessage(nativeloader_error_msg);
ALOGW("NativeActivity LoadNativeLibrary(\"%s\") failed: %s",
pathStr.c_str(),
g_error_msg.c_str());
diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp
index 7b564ae..4101c04 100644
--- a/core/jni/android_util_AssetManager.cpp
+++ b/core/jni/android_util_AssetManager.cpp
@@ -44,6 +44,8 @@
#include "androidfw/MutexGuard.h"
#include "androidfw/PosixUtils.h"
#include "androidfw/ResourceTypes.h"
+#include "androidfw/ResourceUtils.h"
+
#include "core_jni_helpers.h"
#include "jni.h"
#include "nativehelper/JNIHelp.h"
@@ -975,34 +977,7 @@
return nullptr;
}
- std::string result;
- if (name.package != nullptr) {
- result.append(name.package, name.package_len);
- }
-
- if (name.type != nullptr || name.type16 != nullptr) {
- if (!result.empty()) {
- result += ":";
- }
-
- if (name.type != nullptr) {
- result.append(name.type, name.type_len);
- } else {
- result += util::Utf16ToUtf8(StringPiece16(name.type16, name.type_len));
- }
- }
-
- if (name.entry != nullptr || name.entry16 != nullptr) {
- if (!result.empty()) {
- result += "/";
- }
-
- if (name.entry != nullptr) {
- result.append(name.entry, name.entry_len);
- } else {
- result += util::Utf16ToUtf8(StringPiece16(name.entry16, name.entry_len));
- }
- }
+ std::string result = ToFormattedResourceString(&name);
return env->NewStringUTF(result.c_str());
}
@@ -1049,6 +1024,26 @@
return nullptr;
}
+static void NativeSetResourceResolutionLoggingEnabled(JNIEnv* /*env*/,
+ jclass /*clazz*/,
+ jlong ptr,
+ jboolean enabled) {
+ ScopedLock<AssetManager2> assetmanager(AssetManagerFromLong(ptr));
+ assetmanager->SetResourceResolutionLoggingEnabled(enabled);
+}
+
+static jstring NativeGetLastResourceResolution(JNIEnv* env,
+ jclass /*clazz*/,
+ jlong ptr) {
+ ScopedLock<AssetManager2> assetmanager(AssetManagerFromLong(ptr));
+ std::string resolution = assetmanager->GetLastResourceResolution();
+ if (resolution.empty()) {
+ return nullptr;
+ } else {
+ return env->NewStringUTF(resolution.c_str());
+ }
+}
+
static jobjectArray NativeGetLocales(JNIEnv* env, jclass /*class*/, jlong ptr,
jboolean exclude_system) {
ScopedLock<AssetManager2> assetmanager(AssetManagerFromLong(ptr));
@@ -1452,6 +1447,10 @@
{"nativeGetResourcePackageName", "(JI)Ljava/lang/String;", (void*)NativeGetResourcePackageName},
{"nativeGetResourceTypeName", "(JI)Ljava/lang/String;", (void*)NativeGetResourceTypeName},
{"nativeGetResourceEntryName", "(JI)Ljava/lang/String;", (void*)NativeGetResourceEntryName},
+ {"nativeSetResourceResolutionLoggingEnabled", "(JZ)V",
+ (void*) NativeSetResourceResolutionLoggingEnabled},
+ {"nativeGetLastResourceResolution", "(J)Ljava/lang/String;",
+ (void*) NativeGetLastResourceResolution},
{"nativeGetLocales", "(JZ)[Ljava/lang/String;", (void*)NativeGetLocales},
{"nativeGetSizeConfigurations", "(J)[Landroid/content/res/Configuration;",
(void*)NativeGetSizeConfigurations},
diff --git a/core/jni/fd_utils.cpp b/core/jni/fd_utils.cpp
index bd87dcc..41e00b9 100644
--- a/core/jni/fd_utils.cpp
+++ b/core/jni/fd_utils.cpp
@@ -33,6 +33,7 @@
// Static whitelist of open paths that the zygote is allowed to keep open.
static const char* kPathWhitelist[] = {
+ "/apex/com.android.conscrypt/javalib/conscrypt.jar",
"/dev/null",
"/dev/socket/zygote",
"/dev/socket/zygote_secondary",
diff --git a/core/proto/Android.bp b/core/proto/Android.bp
new file mode 100644
index 0000000..80cc2d4
--- /dev/null
+++ b/core/proto/Android.bp
@@ -0,0 +1,27 @@
+// Copyright (C) 2018 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// C++ library for Bluetooth platform wide protobuf definitions
+cc_library_static {
+ name: "libbt-platform-protos-lite",
+ host_supported: true,
+ proto: {
+ export_proto_headers: true,
+ type: "lite",
+ },
+ srcs: [
+ "android/bluetooth/enums.proto",
+ "android/bluetooth/hci/enums.proto",
+ ],
+}
diff --git a/core/proto/android/app/settings_enums.proto b/core/proto/android/app/settings_enums.proto
index 2f2f623..49ca378 100644
--- a/core/proto/android/app/settings_enums.proto
+++ b/core/proto/android/app/settings_enums.proto
@@ -91,4 +91,10 @@
// OPEN: Settings > Apps & Notifications -> Special app access -> Financial Apps Sms Access
SETTINGS_FINANCIAL_APPS_SMS_ACCESS = 1597;
+
+ // OPEN: Settings > System > Input & Gesture > Skip songs
+ SETTINGS_GESTURE_SKIP = 1624;
+
+ // OPEN: Settings > System > Input & Gesture > Silence alerts
+ SETTINGS_GESTURE_SILENCE = 1625;
}
diff --git a/core/proto/android/bluetooth/enums.proto b/core/proto/android/bluetooth/enums.proto
index d0c9226..76c240e 100644
--- a/core/proto/android/bluetooth/enums.proto
+++ b/core/proto/android/bluetooth/enums.proto
@@ -41,3 +41,18 @@
ENABLE_DISABLE_REASON_USER_SWITCH = 8;
ENABLE_DISABLE_REASON_RESTORE_USER_SETTING = 9;
}
+
+enum DirectionEnum {
+ DIRECTION_UNKNOWN = 0;
+ DIRECTION_OUTGOING = 1;
+ DIRECTION_INCOMING = 2;
+}
+
+// First item is the default value, other values follow Bluetooth spec definition
+enum LinkTypeEnum {
+ // Link type is at most 1 byte (0xFF), thus 0xFFF must not be a valid value
+ LINK_TYPE_UNKNOWN = 0xFFF;
+ LINK_TYPE_SCO = 0x00;
+ LINK_TYPE_ACL = 0x01;
+ LINK_TYPE_ESCO = 0x02;
+}
diff --git a/core/proto/android/bluetooth/hci/enums.proto b/core/proto/android/bluetooth/hci/enums.proto
new file mode 100644
index 0000000..e1d96bb
--- /dev/null
+++ b/core/proto/android/bluetooth/hci/enums.proto
@@ -0,0 +1,519 @@
+/*
+ * Copyright 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto2";
+package android.bluetooth.hci;
+
+option java_outer_classname = "BluetoothHciProtoEnums";
+option java_multiple_files = true;
+
+// HCI command opcodes (OCF+OGF) from Bluetooth 5.0 specification Vol 2, Part E, Section 7
+// Original definition: system/bt/stack/include/hcidefs.h
+enum CommandEnum {
+ // Opcode is at most 2 bytes (0xFFFF), thus 0xFFFFF must not be a valid value
+ CMD_UNKNOWN = 0xFFFFF;
+ // Link control commands 0x0400
+ CMD_INQUIRY = 0x0401;
+ CMD_INQUIRY_CANCEL = 0x0402;
+ CMD_PERIODIC_INQUIRY_MODE = 0x0403;
+ CMD_EXIT_PERIODIC_INQUIRY_MODE = 0x0404;
+ CMD_CREATE_CONNECTION = 0x0405;
+ CMD_DISCONNECT = 0x0406;
+ CMD_ADD_SCO_CONNECTION = 0x0407; // Deprecated since Bluetooth 1.2
+ CMD_CREATE_CONNECTION_CANCEL = 0x0408;
+ CMD_ACCEPT_CONNECTION_REQUEST = 0x0409;
+ CMD_REJECT_CONNECTION_REQUEST = 0x040A;
+ CMD_LINK_KEY_REQUEST_REPLY = 0x040B;
+ CMD_LINK_KEY_REQUEST_NEG_REPLY = 0x040C;
+ CMD_PIN_CODE_REQUEST_REPLY = 0x040D;
+ CMD_PIN_CODE_REQUEST_NEG_REPLY = 0x040E;
+ CMD_CHANGE_CONN_PACKET_TYPE = 0x040F;
+ CMD_AUTHENTICATION_REQUESTED = 0x0411;
+ CMD_SET_CONN_ENCRYPTION = 0x0413;
+ CMD_CHANGE_CONN_LINK_KEY = 0x0415;
+ CMD_MASTER_LINK_KEY = 0x0417;
+ CMD_RMT_NAME_REQUEST = 0x0419;
+ CMD_RMT_NAME_REQUEST_CANCEL = 0x041A;
+ CMD_READ_RMT_FEATURES = 0x041B;
+ CMD_READ_RMT_EXT_FEATURES = 0x041C;
+ CMD_READ_RMT_VERSION_INFO = 0x041D;
+ CMD_READ_RMT_CLOCK_OFFSET = 0x041F;
+ CMD_READ_LMP_HANDLE = 0x0420;
+ CMD_SETUP_ESCO_CONNECTION = 0x0428;
+ CMD_ACCEPT_ESCO_CONNECTION = 0x0429;
+ CMD_REJECT_ESCO_CONNECTION = 0x042A;
+ CMD_IO_CAPABILITY_REQUEST_REPLY = 0x042B;
+ CMD_USER_CONF_REQUEST_REPLY = 0x042C;
+ CMD_USER_CONF_VALUE_NEG_REPLY = 0x042D;
+ CMD_USER_PASSKEY_REQ_REPLY = 0x042E;
+ CMD_USER_PASSKEY_REQ_NEG_REPLY = 0x042F;
+ CMD_REM_OOB_DATA_REQ_REPLY = 0x0430;
+ CMD_REM_OOB_DATA_REQ_NEG_REPLY = 0x0433;
+ CMD_IO_CAP_REQ_NEG_REPLY = 0x0434;
+ // BEGIN: AMP commands (not used in system/bt)
+ CMD_CREATE_PHYSICAL_LINK = 0x0435;
+ CMD_ACCEPT_PHYSICAL_LINK = 0x0436;
+ CMD_DISCONNECT_PHYSICAL_LINK = 0x0437;
+ CMD_CREATE_LOGICAL_LINK = 0x0438;
+ CMD_ACCEPT_LOGICAL_LINK = 0x0439;
+ CMD_DISCONNECT_LOGICAL_LINK = 0x043A;
+ CMD_LOGICAL_LINK_CANCEL = 0x043B;
+ CMD_FLOW_SPEC_MODIFY = 0x043C;
+ // END: AMP commands
+ CMD_ENH_SETUP_ESCO_CONNECTION = 0x043D;
+ CMD_ENH_ACCEPT_ESCO_CONNECTION = 0x043E;
+ CMD_TRUNCATED_PAGE = 0x043F;
+ CMD_TRUNCATED_PAGE_CANCEL = 0x0440;
+ CMD_SET_CLB = 0x0441;
+ CMD_RECEIVE_CLB = 0x0442;
+ CMD_START_SYNC_TRAIN = 0x0443;
+ CMD_RECEIVE_SYNC_TRAIN = 0x0444;
+ CMD_REM_OOB_EXTENDED_DATA_REQ_REPLY = 0x0445; // Not currently used in system/bt
+ // Link policy commands 0x0800
+ CMD_HOLD_MODE = 0x0801;
+ CMD_SNIFF_MODE = 0x0803;
+ CMD_EXIT_SNIFF_MODE = 0x0804;
+ CMD_PARK_MODE = 0x0805;
+ CMD_EXIT_PARK_MODE = 0x0806;
+ CMD_QOS_SETUP = 0x0807;
+ CMD_ROLE_DISCOVERY = 0x0809;
+ CMD_SWITCH_ROLE = 0x080B;
+ CMD_READ_POLICY_SETTINGS = 0x080C;
+ CMD_WRITE_POLICY_SETTINGS = 0x080D;
+ CMD_READ_DEF_POLICY_SETTINGS = 0x080E;
+ CMD_WRITE_DEF_POLICY_SETTINGS = 0x080F;
+ CMD_FLOW_SPECIFICATION = 0x0810;
+ CMD_SNIFF_SUB_RATE = 0x0811;
+ // Host controller baseband commands 0x0C00
+ CMD_SET_EVENT_MASK = 0x0C01;
+ CMD_RESET = 0x0C03;
+ CMD_SET_EVENT_FILTER = 0x0C05;
+ CMD_FLUSH = 0x0C08;
+ CMD_READ_PIN_TYPE = 0x0C09;
+ CMD_WRITE_PIN_TYPE = 0x0C0A;
+ CMD_CREATE_NEW_UNIT_KEY = 0x0C0B;
+ CMD_GET_MWS_TRANS_LAYER_CFG = 0x0C0C; // Deprecated (not used in spec)
+ CMD_READ_STORED_LINK_KEY = 0x0C0D;
+ CMD_WRITE_STORED_LINK_KEY = 0x0C11;
+ CMD_DELETE_STORED_LINK_KEY = 0x0C12;
+ CMD_CHANGE_LOCAL_NAME = 0x0C13;
+ CMD_READ_LOCAL_NAME = 0x0C14;
+ CMD_READ_CONN_ACCEPT_TOUT = 0x0C15;
+ CMD_WRITE_CONN_ACCEPT_TOUT = 0x0C16;
+ CMD_READ_PAGE_TOUT = 0x0C17;
+ CMD_WRITE_PAGE_TOUT = 0x0C18;
+ CMD_READ_SCAN_ENABLE = 0x0C19;
+ CMD_WRITE_SCAN_ENABLE = 0x0C1A;
+ CMD_READ_PAGESCAN_CFG = 0x0C1B;
+ CMD_WRITE_PAGESCAN_CFG = 0x0C1C;
+ CMD_READ_INQUIRYSCAN_CFG = 0x0C1D;
+ CMD_WRITE_INQUIRYSCAN_CFG = 0x0C1E;
+ CMD_READ_AUTHENTICATION_ENABLE = 0x0C1F;
+ CMD_WRITE_AUTHENTICATION_ENABLE = 0x0C20;
+ CMD_READ_ENCRYPTION_MODE = 0x0C21; // Deprecated
+ CMD_WRITE_ENCRYPTION_MODE = 0x0C22; // Deprecated
+ CMD_READ_CLASS_OF_DEVICE = 0x0C23;
+ CMD_WRITE_CLASS_OF_DEVICE = 0x0C24;
+ CMD_READ_VOICE_SETTINGS = 0x0C25;
+ CMD_WRITE_VOICE_SETTINGS = 0x0C26;
+ CMD_READ_AUTOMATIC_FLUSH_TIMEOUT = 0x0C27;
+ CMD_WRITE_AUTOMATIC_FLUSH_TIMEOUT = 0x0C28;
+ CMD_READ_NUM_BCAST_REXMITS = 0x0C29;
+ CMD_WRITE_NUM_BCAST_REXMITS = 0x0C2A;
+ CMD_READ_HOLD_MODE_ACTIVITY = 0x0C2B;
+ CMD_WRITE_HOLD_MODE_ACTIVITY = 0x0C2C;
+ CMD_READ_TRANSMIT_POWER_LEVEL = 0x0C2D;
+ CMD_READ_SCO_FLOW_CTRL_ENABLE = 0x0C2E;
+ CMD_WRITE_SCO_FLOW_CTRL_ENABLE = 0x0C2F;
+ CMD_SET_HC_TO_HOST_FLOW_CTRL = 0x0C31;
+ CMD_HOST_BUFFER_SIZE = 0x0C33;
+ CMD_HOST_NUM_PACKETS_DONE = 0x0C35;
+ CMD_READ_LINK_SUPER_TOUT = 0x0C36;
+ CMD_WRITE_LINK_SUPER_TOUT = 0x0C37;
+ CMD_READ_NUM_SUPPORTED_IAC = 0x0C38;
+ CMD_READ_CURRENT_IAC_LAP = 0x0C39;
+ CMD_WRITE_CURRENT_IAC_LAP = 0x0C3A;
+ CMD_READ_PAGESCAN_PERIOD_MODE = 0x0C3B; // Deprecated
+ CMD_WRITE_PAGESCAN_PERIOD_MODE = 0x0C3C; // Deprecated
+ CMD_READ_PAGESCAN_MODE = 0x0C3D; // Deprecated
+ CMD_WRITE_PAGESCAN_MODE = 0x0C3E; // Deprecated
+ CMD_SET_AFH_CHANNELS = 0x0C3F;
+ CMD_READ_INQSCAN_TYPE = 0x0C42;
+ CMD_WRITE_INQSCAN_TYPE = 0x0C43;
+ CMD_READ_INQUIRY_MODE = 0x0C44;
+ CMD_WRITE_INQUIRY_MODE = 0x0C45;
+ CMD_READ_PAGESCAN_TYPE = 0x0C46;
+ CMD_WRITE_PAGESCAN_TYPE = 0x0C47;
+ CMD_READ_AFH_ASSESSMENT_MODE = 0x0C48;
+ CMD_WRITE_AFH_ASSESSMENT_MODE = 0x0C49;
+ CMD_READ_EXT_INQ_RESPONSE = 0x0C51;
+ CMD_WRITE_EXT_INQ_RESPONSE = 0x0C52;
+ CMD_REFRESH_ENCRYPTION_KEY = 0x0C53;
+ CMD_READ_SIMPLE_PAIRING_MODE = 0x0C55;
+ CMD_WRITE_SIMPLE_PAIRING_MODE = 0x0C56;
+ CMD_READ_LOCAL_OOB_DATA = 0x0C57;
+ CMD_READ_INQ_TX_POWER_LEVEL = 0x0C58;
+ CMD_WRITE_INQ_TX_POWER_LEVEL = 0x0C59;
+ CMD_READ_ERRONEOUS_DATA_RPT = 0x0C5A;
+ CMD_WRITE_ERRONEOUS_DATA_RPT = 0x0C5B;
+ CMD_ENHANCED_FLUSH = 0x0C5F;
+ CMD_SEND_KEYPRESS_NOTIF = 0x0C60;
+ CMD_READ_LOGICAL_LINK_ACCEPT_TIMEOUT = 0x0C61;
+ CMD_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT = 0x0C62;
+ CMD_SET_EVENT_MASK_PAGE_2 = 0x0C63;
+ CMD_READ_LOCATION_DATA = 0x0C64;
+ CMD_WRITE_LOCATION_DATA = 0x0C65;
+ CMD_READ_FLOW_CONTROL_MODE = 0x0C66;
+ CMD_WRITE_FLOW_CONTROL_MODE = 0x0C67;
+ CMD_READ_ENHANCED_TX_PWR_LEVEL = 0x0C68; // Not currently used in system/bt
+ CMD_READ_BE_FLUSH_TOUT = 0x0C69;
+ CMD_WRITE_BE_FLUSH_TOUT = 0x0C6A;
+ CMD_SHORT_RANGE_MODE = 0x0C6B;
+ CMD_READ_BLE_HOST_SUPPORT = 0x0C6C;
+ CMD_WRITE_BLE_HOST_SUPPORT = 0x0C6D;
+ CMD_SET_MWS_CHANNEL_PARAMETERS = 0x0C6E;
+ CMD_SET_EXTERNAL_FRAME_CONFIGURATION = 0x0C6F;
+ CMD_SET_MWS_SIGNALING = 0x0C70;
+ CMD_SET_MWS_TRANSPORT_LAYER = 0x0C71;
+ CMD_SET_MWS_SCAN_FREQUENCY_TABLE = 0x0C72;
+ CMD_SET_MWS_PATTERN_CONFIGURATION = 0x0C73;
+ CMD_SET_RESERVED_LT_ADDR = 0x0C74;
+ CMD_DELETE_RESERVED_LT_ADDR = 0x0C75;
+ CMD_WRITE_CLB_DATA = 0x0C76;
+ CMD_READ_SYNC_TRAIN_PARAM = 0x0C77;
+ CMD_WRITE_SYNC_TRAIN_PARAM = 0x0C78;
+ CMD_READ_SECURE_CONNS_SUPPORT = 0x0C79;
+ CMD_WRITE_SECURE_CONNS_SUPPORT = 0x0C7A;
+ CMD_READ_AUTHED_PAYLOAD_TIMEOUT = 0x0C7B; // Not currently used in system/bt
+ CMD_WRITE_AUTHED_PAYLOAD_TIMEOUT = 0x0C7C; // Not currently used in system/bt
+ CMD_READ_LOCAL_OOB_EXTENDED_DATA = 0x0C7D; // Not currently used in system/bt
+ CMD_READ_EXTENDED_PAGE_TIMEOUT = 0x0C7E; // Not currently used in system/bt
+ CMD_WRITE_EXTENDED_PAGE_TIMEOUT = 0x0C7F; // Not currently used in system/bt
+ CMD_READ_EXTENDED_INQUIRY_LENGTH = 0x0C80; // Not currently used in system/bt
+ CMD_WRITE_EXTENDED_INQUIRY_LENGTH = 0x0C81; // Not currently used in system/bt
+ // Informational parameter commands 0x1000
+ CMD_READ_LOCAL_VERSION_INFO = 0x1001;
+ CMD_READ_LOCAL_SUPPORTED_CMDS = 0x1002;
+ CMD_READ_LOCAL_FEATURES = 0x1003;
+ CMD_READ_LOCAL_EXT_FEATURES = 0x1004;
+ CMD_READ_BUFFER_SIZE = 0x1005;
+ CMD_READ_COUNTRY_CODE = 0x1007; // Deprecated
+ CMD_READ_BD_ADDR = 0x1009;
+ CMD_READ_DATA_BLOCK_SIZE = 0x100A;
+ CMD_READ_LOCAL_SUPPORTED_CODECS = 0x100B;
+ // Status parameter commands 0x1400
+ CMD_READ_FAILED_CONTACT_COUNTER = 0x1401;
+ CMD_RESET_FAILED_CONTACT_COUNTER = 0x1402;
+ CMD_GET_LINK_QUALITY = 0x1403;
+ CMD_READ_RSSI = 0x1405;
+ CMD_READ_AFH_CH_MAP = 0x1406;
+ CMD_READ_CLOCK = 0x1407;
+ CMD_READ_ENCR_KEY_SIZE = 0x1408;
+ CMD_READ_LOCAL_AMP_INFO = 0x1409;
+ CMD_READ_LOCAL_AMP_ASSOC = 0x140A;
+ CMD_WRITE_REMOTE_AMP_ASSOC = 0x140B;
+ CMD_GET_MWS_TRANSPORT_CFG = 0x140C; // Not currently used in system/bt
+ CMD_SET_TRIGGERED_CLK_CAPTURE = 0x140D; // Not currently used in system/bt
+ // Testing commands 0x1800
+ CMD_READ_LOOPBACK_MODE = 0x1801;
+ CMD_WRITE_LOOPBACK_MODE = 0x1802;
+ CMD_ENABLE_DEV_UNDER_TEST_MODE = 0x1803;
+ CMD_WRITE_SIMP_PAIR_DEBUG_MODE = 0x1804;
+ CMD_ENABLE_AMP_RCVR_REPORTS = 0x1807;
+ CMD_AMP_TEST_END = 0x1808;
+ CMD_AMP_TEST = 0x1809;
+ CMD_WRITE_SECURE_CONN_TEST_MODE = 0x180A; // Not currently used in system/bt
+ // BLE commands 0x2000
+ CMD_BLE_SET_EVENT_MASK = 0x2001;
+ CMD_BLE_READ_BUFFER_SIZE = 0x2002;
+ CMD_BLE_READ_LOCAL_SPT_FEAT = 0x2003;
+ CMD_BLE_WRITE_LOCAL_SPT_FEAT = 0x2004;
+ CMD_BLE_WRITE_RANDOM_ADDR = 0x2005;
+ CMD_BLE_WRITE_ADV_PARAMS = 0x2006;
+ CMD_BLE_READ_ADV_CHNL_TX_POWER = 0x2007;
+ CMD_BLE_WRITE_ADV_DATA = 0x2008;
+ CMD_BLE_WRITE_SCAN_RSP_DATA = 0x2009;
+ CMD_BLE_WRITE_ADV_ENABLE = 0x200A;
+ CMD_BLE_WRITE_SCAN_PARAMS = 0x200B;
+ CMD_BLE_WRITE_SCAN_ENABLE = 0x200C;
+ CMD_BLE_CREATE_LL_CONN = 0x200D;
+ CMD_BLE_CREATE_CONN_CANCEL = 0x200E;
+ CMD_BLE_READ_WHITE_LIST_SIZE = 0x200F;
+ CMD_BLE_CLEAR_WHITE_LIST = 0x2010;
+ CMD_BLE_ADD_WHITE_LIST = 0x2011;
+ CMD_BLE_REMOVE_WHITE_LIST = 0x2012;
+ CMD_BLE_UPD_LL_CONN_PARAMS = 0x2013;
+ CMD_BLE_SET_HOST_CHNL_CLASS = 0x2014;
+ CMD_BLE_READ_CHNL_MAP = 0x2015;
+ CMD_BLE_READ_REMOTE_FEAT = 0x2016;
+ CMD_BLE_ENCRYPT = 0x2017;
+ CMD_BLE_RAND = 0x2018;
+ CMD_BLE_START_ENC = 0x2019;
+ CMD_BLE_LTK_REQ_REPLY = 0x201A;
+ CMD_BLE_LTK_REQ_NEG_REPLY = 0x201B;
+ CMD_BLE_READ_SUPPORTED_STATES = 0x201C;
+ CMD_BLE_RECEIVER_TEST = 0x201D;
+ CMD_BLE_TRANSMITTER_TEST = 0x201E;
+ CMD_BLE_TEST_END = 0x201F;
+ CMD_BLE_RC_PARAM_REQ_REPLY = 0x2020;
+ CMD_BLE_RC_PARAM_REQ_NEG_REPLY = 0x2021;
+ CMD_BLE_SET_DATA_LENGTH = 0x2022;
+ CMD_BLE_READ_DEFAULT_DATA_LENGTH = 0x2023;
+ CMD_BLE_WRITE_DEFAULT_DATA_LENGTH = 0x2024;
+ CMD_BLE_GENERATE_DHKEY = 0x2026; // Not currently used in system/bt
+ CMD_BLE_ADD_DEV_RESOLVING_LIST = 0x2027;
+ CMD_BLE_RM_DEV_RESOLVING_LIST = 0x2028;
+ CMD_BLE_CLEAR_RESOLVING_LIST = 0x2029;
+ CMD_BLE_READ_RESOLVING_LIST_SIZE = 0x202A;
+ CMD_BLE_READ_RESOLVABLE_ADDR_PEER = 0x202B;
+ CMD_BLE_READ_RESOLVABLE_ADDR_LOCAL = 0x202C;
+ CMD_BLE_SET_ADDR_RESOLUTION_ENABLE = 0x202D;
+ CMD_BLE_SET_RAND_PRIV_ADDR_TIMOUT = 0x202E;
+ CMD_BLE_READ_MAXIMUM_DATA_LENGTH = 0x202F;
+ CMD_BLE_READ_PHY = 0x2030;
+ CMD_BLE_SET_DEFAULT_PHY = 0x2031;
+ CMD_BLE_SET_PHY = 0x2032;
+ CMD_BLE_ENH_RECEIVER_TEST = 0x2033;
+ CMD_BLE_ENH_TRANSMITTER_TEST = 0x2034;
+ CMD_BLE_SET_EXT_ADVERTISING_RANDOM_ADDRESS = 0x2035;
+ CMD_BLE_SET_EXT_ADVERTISING_PARAM = 0x2036;
+ CMD_BLE_SET_EXT_ADVERTISING_DATA = 0x2037;
+ CMD_BLE_SET_EXT_ADVERTISING_SCAN_RESP = 0x2038;
+ CMD_BLE_SET_EXT_ADVERTISING_ENABLE = 0x2039;
+ CMD_BLE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH = 0x203A;
+ CMD_BLE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS = 0x203B;
+ CMD_BLE_REMOVE_ADVERTISING_SET = 0x203C;
+ CMD_BLE_CLEAR_ADVERTISING_SETS = 0x203D;
+ CMD_BLE_SET_PERIODIC_ADVERTISING_PARAM = 0x203E;
+ CMD_BLE_SET_PERIODIC_ADVERTISING_DATA = 0x203F;
+ CMD_BLE_SET_PERIODIC_ADVERTISING_ENABLE = 0x2040;
+ CMD_BLE_SET_EXTENDED_SCAN_PARAMETERS = 0x2041;
+ CMD_BLE_SET_EXTENDED_SCAN_ENABLE = 0x2042;
+ CMD_BLE_EXTENDED_CREATE_CONNECTION = 0x2043;
+ CMD_BLE_PERIODIC_ADVERTISING_CREATE_SYNC = 0x2044;
+ CMD_BLE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL = 0x2045;
+ CMD_BLE_PERIODIC_ADVERTISING_TERMINATE_SYNC = 0x2046;
+ CMD_BLE_ADD_DEVICE_TO_PERIODIC_ADVERTISING_LIST = 0x2047;
+ CMD_BLE_RM_DEVICE_FROM_PERIODIC_ADVERTISING_LIST = 0x2048;
+ CMD_BLE_CLEAR_PERIODIC_ADVERTISING_LIST = 0x2049;
+ CMD_BLE_READ_PERIODIC_ADVERTISING_LIST_SIZE = 0x204A;
+ CMD_BLE_READ_TRANSMIT_POWER = 0x204B;
+ CMD_BLE_READ_RF_COMPENS_POWER = 0x204C;
+ CMD_BLE_WRITE_RF_COMPENS_POWER = 0x204D;
+ CMD_BLE_SET_PRIVACY_MODE = 0x204E;
+ // Vendor specific commands 0xFC00 and above
+ // Android vendor specific commands defined in
+ // https://source.android.com/devices/bluetooth/hci_requirements#vendor-specific-capabilities
+ CMD_BLE_VENDOR_CAP = 0xFD53;
+ CMD_BLE_MULTI_ADV = 0xFD54;
+ CMD_BLE_BATCH_SCAN = 0xFD56;
+ CMD_BLE_ADV_FILTER = 0xFD57;
+ CMD_BLE_TRACK_ADV = 0xFD58;
+ CMD_BLE_ENERGY_INFO = 0xFD59;
+ CMD_BLE_EXTENDED_SCAN_PARAMS = 0xFD5A;
+ CMD_CONTROLLER_DEBUG_INFO = 0xFD5B;
+ CMD_CONTROLLER_A2DP_OPCODE = 0xFD5D;
+ CMD_BRCM_SET_ACL_PRIORITY = 0xFC57;
+ // Other vendor specific commands below here
+}
+
+// HCI event codes from the Bluetooth 5.0 specification Vol 2, Part 7, Section 7
+// Original definition: system/bt/stack/include/hcidefs.h
+enum EventEnum {
+ // Event is at most 1 byte (0xFF), thus 0xFFF must not be a valid value
+ EVT_UNKNOWN = 0xFFF;
+ EVT_INQUIRY_COMP = 0x01;
+ EVT_INQUIRY_RESULT = 0x02;
+ EVT_CONNECTION_COMP = 0x03;
+ EVT_CONNECTION_REQUEST = 0x04;
+ EVT_DISCONNECTION_COMP = 0x05;
+ EVT_AUTHENTICATION_COMP = 0x06;
+ EVT_RMT_NAME_REQUEST_COMP = 0x07;
+ EVT_ENCRYPTION_CHANGE = 0x08;
+ EVT_CHANGE_CONN_LINK_KEY = 0x09;
+ EVT_MASTER_LINK_KEY_COMP = 0x0A;
+ EVT_READ_RMT_FEATURES_COMP = 0x0B;
+ EVT_READ_RMT_VERSION_COMP = 0x0C;
+ EVT_QOS_SETUP_COMP = 0x0D;
+ EVT_COMMAND_COMPLETE = 0x0E;
+ EVT_COMMAND_STATUS = 0x0F;
+ EVT_HARDWARE_ERROR = 0x10;
+ EVT_FLUSH_OCCURED = 0x11;
+ EVT_ROLE_CHANGE = 0x12;
+ EVT_NUM_COMPL_DATA_PKTS = 0x13;
+ EVT_MODE_CHANGE = 0x14;
+ EVT_RETURN_LINK_KEYS = 0x15;
+ EVT_PIN_CODE_REQUEST = 0x16;
+ EVT_LINK_KEY_REQUEST = 0x17;
+ EVT_LINK_KEY_NOTIFICATION = 0x18;
+ EVT_LOOPBACK_COMMAND = 0x19;
+ EVT_DATA_BUF_OVERFLOW = 0x1A;
+ EVT_MAX_SLOTS_CHANGED = 0x1B;
+ EVT_READ_CLOCK_OFF_COMP = 0x1C;
+ EVT_CONN_PKT_TYPE_CHANGE = 0x1D;
+ EVT_QOS_VIOLATION = 0x1E;
+ EVT_PAGE_SCAN_MODE_CHANGE = 0x1F; // Deprecated
+ EVT_PAGE_SCAN_REP_MODE_CHNG = 0x20;
+ EVT_FLOW_SPECIFICATION_COMP = 0x21;
+ EVT_INQUIRY_RSSI_RESULT = 0x22;
+ EVT_READ_RMT_EXT_FEATURES_COMP = 0x23;
+ EVT_ESCO_CONNECTION_COMP = 0x2C;
+ EVT_ESCO_CONNECTION_CHANGED = 0x2D;
+ EVT_SNIFF_SUB_RATE = 0x2E;
+ EVT_EXTENDED_INQUIRY_RESULT = 0x2F;
+ EVT_ENCRYPTION_KEY_REFRESH_COMP = 0x30;
+ EVT_IO_CAPABILITY_REQUEST = 0x31;
+ EVT_IO_CAPABILITY_RESPONSE = 0x32;
+ EVT_USER_CONFIRMATION_REQUEST = 0x33;
+ EVT_USER_PASSKEY_REQUEST = 0x34;
+ EVT_REMOTE_OOB_DATA_REQUEST = 0x35;
+ EVT_SIMPLE_PAIRING_COMPLETE = 0x36;
+ EVT_LINK_SUPER_TOUT_CHANGED = 0x38;
+ EVT_ENHANCED_FLUSH_COMPLETE = 0x39;
+ EVT_USER_PASSKEY_NOTIFY = 0x3B;
+ EVT_KEYPRESS_NOTIFY = 0x3C;
+ EVT_RMT_HOST_SUP_FEAT_NOTIFY = 0x3D;
+ EVT_BLE_META = 0x3E;
+ EVT_PHYSICAL_LINK_COMP = 0x40;
+ EVT_CHANNEL_SELECTED = 0x41;
+ EVT_DISC_PHYSICAL_LINK_COMP = 0x42;
+ EVT_PHY_LINK_LOSS_EARLY_WARNING = 0x43;
+ EVT_PHY_LINK_RECOVERY = 0x44;
+ EVT_LOGICAL_LINK_COMP = 0x45;
+ EVT_DISC_LOGICAL_LINK_COMP = 0x46;
+ EVT_FLOW_SPEC_MODIFY_COMP = 0x47;
+ EVT_NUM_COMPL_DATA_BLOCKS = 0x48;
+ EVT_AMP_TEST_START = 0x49; // Not currently used in system/bt
+ EVT_AMP_TEST_END = 0x4A; // Not currently used in system/bt
+ EVT_AMP_RECEIVER_RPT = 0x4B; // Not currently used in system/bt
+ EVT_SHORT_RANGE_MODE_COMPLETE = 0x4C;
+ EVT_AMP_STATUS_CHANGE = 0x4D;
+ EVT_SET_TRIGGERED_CLOCK_CAPTURE = 0x4E;
+ EVT_SYNC_TRAIN_CMPL = 0x4F; // Not currently used in system/bt
+ EVT_SYNC_TRAIN_RCVD = 0x50; // Not currently used in system/bt
+ EVT_CONNLESS_SLAVE_BROADCAST_RCVD = 0x51; // Not currently used in system/bt
+ EVT_CONNLESS_SLAVE_BROADCAST_TIMEOUT = 0x52; // Not currently used in system/bt
+ EVT_TRUNCATED_PAGE_CMPL = 0x53; // Not currently used in system/bt
+ EVT_SLAVE_PAGE_RES_TIMEOUT = 0x54; // Not currently used in system/bt
+ EVT_CONNLESS_SLAVE_BROADCAST_CHNL_MAP_CHANGE = 0x55; // Not currently used in system/bt
+ EVT_INQUIRY_RES_NOTIFICATION = 0x56; // Not currently used in system/bt
+ EVT_AUTHED_PAYLOAD_TIMEOUT = 0x57; // Not currently used in system/bt
+ EVT_SAM_STATUS_CHANGE = 0x58; // Not currently used in system/bt
+}
+
+// Bluetooth low energy related meta event codes
+// from the Bluetooth 5.0 specification Vol 2, Part E, Section 7.7.65
+// Original definition: system/bt/stack/include/hcidefs.h
+enum BleMetaEventEnum {
+ // BLE meta event code is at most 1 byte (0xFF), thus 0xFFF must not be a valid value
+ BLE_EVT_UNKNOWN = 0xFFF;
+ BLE_EVT_CONN_COMPLETE_EVT = 0x01;
+ BLE_EVT_ADV_PKT_RPT_EVT = 0x02;
+ BLE_EVT_LL_CONN_PARAM_UPD_EVT = 0x03;
+ BLE_EVT_READ_REMOTE_FEAT_CMPL_EVT = 0x04;
+ BLE_EVT_LTK_REQ_EVT = 0x05;
+ BLE_EVT_RC_PARAM_REQ_EVT = 0x06;
+ BLE_EVT_DATA_LENGTH_CHANGE_EVT = 0x07;
+ BLE_EVT_READ_LOCAL_P256_PUB_KEY = 0x08; // Not currently used in system/bt
+ BLE_EVT_GEN_DHKEY_CMPL = 0x09; // Not currently used in system/bt
+ BLE_EVT_ENHANCED_CONN_COMPLETE_EVT = 0x0a;
+ BLE_EVT_DIRECT_ADV_EVT = 0x0b;
+ BLE_EVT_PHY_UPDATE_COMPLETE_EVT = 0x0c;
+ BLE_EVT_EXTENDED_ADVERTISING_REPORT_EVT = 0x0D;
+ BLE_EVT_PERIODIC_ADV_SYNC_EST_EVT = 0x0E;
+ BLE_EVT_PERIODIC_ADV_REPORT_EVT = 0x0F;
+ BLE_EVT_PERIODIC_ADV_SYNC_LOST_EVT = 0x10;
+ BLE_EVT_SCAN_TIMEOUT_EVT = 0x11;
+ BLE_EVT_ADVERTISING_SET_TERMINATED_EVT = 0x12;
+ BLE_EVT_SCAN_REQ_RX_EVT = 0x13;
+ BLE_EVT_CHNL_SELECTION_ALGORITHM = 0x14; // Not currently used in system/bt
+}
+
+// HCI status code from the Bluetooth 5.0 specification Vol 2, Part D.
+// Original definition: system/bt/stack/include/hcidefs.h
+enum StatusEnum {
+ // Status is at most 1 byte (0xFF), thus 0xFFF must not be a valid value
+ STATUS_UNKNOWN = 0xFFF;
+ STATUS_SUCCESS = 0x00;
+ STATUS_ILLEGAL_COMMAND = 0x01;
+ STATUS_NO_CONNECTION = 0x02;
+ STATUS_HW_FAILURE = 0x03;
+ STATUS_PAGE_TIMEOUT = 0x04;
+ STATUS_AUTH_FAILURE = 0x05;
+ STATUS_KEY_MISSING = 0x06;
+ STATUS_MEMORY_FULL = 0x07;
+ STATUS_CONNECTION_TOUT = 0x08;
+ STATUS_MAX_NUM_OF_CONNECTIONS = 0x09;
+ STATUS_MAX_NUM_OF_SCOS = 0x0A;
+ STATUS_CONNECTION_EXISTS = 0x0B;
+ STATUS_COMMAND_DISALLOWED = 0x0C;
+ STATUS_HOST_REJECT_RESOURCES = 0x0D;
+ STATUS_HOST_REJECT_SECURITY = 0x0E;
+ STATUS_HOST_REJECT_DEVICE = 0x0F;
+ STATUS_HOST_TIMEOUT = 0x10;
+ STATUS_UNSUPPORTED_VALUE = 0x11;
+ STATUS_ILLEGAL_PARAMETER_FMT = 0x12;
+ STATUS_PEER_USER = 0x13;
+ STATUS_PEER_LOW_RESOURCES = 0x14;
+ STATUS_PEER_POWER_OFF = 0x15;
+ STATUS_CONN_CAUSE_LOCAL_HOST = 0x16;
+ STATUS_REPEATED_ATTEMPTS = 0x17;
+ STATUS_PAIRING_NOT_ALLOWED = 0x18;
+ STATUS_UNKNOWN_LMP_PDU = 0x19;
+ STATUS_UNSUPPORTED_REM_FEATURE = 0x1A;
+ STATUS_SCO_OFFSET_REJECTED = 0x1B;
+ STATUS_SCO_INTERVAL_REJECTED = 0x1C;
+ STATUS_SCO_AIR_MODE = 0x1D;
+ STATUS_INVALID_LMP_PARAM = 0x1E;
+ STATUS_UNSPECIFIED = 0x1F;
+ STATUS_UNSUPPORTED_LMP_FEATURE = 0x20;
+ STATUS_ROLE_CHANGE_NOT_ALLOWED = 0x21;
+ STATUS_LMP_RESPONSE_TIMEOUT = 0x22;
+ STATUS_LMP_STATUS_TRANS_COLLISION = 0x23;
+ STATUS_LMP_PDU_NOT_ALLOWED = 0x24;
+ STATUS_ENCRY_MODE_NOT_ACCEPTABLE = 0x25;
+ STATUS_UNIT_KEY_USED = 0x26;
+ STATUS_QOS_NOT_SUPPORTED = 0x27;
+ STATUS_INSTANT_PASSED = 0x28;
+ STATUS_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED = 0x29;
+ STATUS_DIFF_TRANSACTION_COLLISION = 0x2A;
+ STATUS_UNDEFINED_0x2B = 0x2B; // Not used
+ STATUS_QOS_UNACCEPTABLE_PARAM = 0x2C;
+ STATUS_QOS_REJECTED = 0x2D;
+ STATUS_CHAN_CLASSIF_NOT_SUPPORTED = 0x2E;
+ STATUS_INSUFFCIENT_SECURITY = 0x2F;
+ STATUS_PARAM_OUT_OF_RANGE = 0x30;
+ STATUS_UNDEFINED_0x31 = 0x31; // Not used
+ STATUS_ROLE_SWITCH_PENDING = 0x32;
+ STATUS_UNDEFINED_0x33 = 0x33;
+ STATUS_RESERVED_SLOT_VIOLATION = 0x34;
+ STATUS_ROLE_SWITCH_FAILED = 0x35;
+ STATUS_INQ_RSP_DATA_TOO_LARGE = 0x36;
+ STATUS_SIMPLE_PAIRING_NOT_SUPPORTED = 0x37;
+ STATUS_HOST_BUSY_PAIRING = 0x38;
+ STATUS_REJ_NO_SUITABLE_CHANNEL = 0x39;
+ STATUS_CONTROLLER_BUSY = 0x3A;
+ STATUS_UNACCEPT_CONN_INTERVAL = 0x3B;
+ STATUS_ADVERTISING_TIMEOUT = 0x3C;
+ STATUS_CONN_TOUT_DUE_TO_MIC_FAILURE = 0x3D;
+ STATUS_CONN_FAILED_ESTABLISHMENT = 0x3E;
+ STATUS_MAC_CONNECTION_FAILED = 0x3F;
+ STATUS_LT_ADDR_ALREADY_IN_USE = 0x40;
+ STATUS_LT_ADDR_NOT_ALLOCATED = 0x41;
+ STATUS_CLB_NOT_ENABLED = 0x42;
+ STATUS_CLB_DATA_TOO_BIG = 0x43;
+ STATUS_OPERATION_CANCELED_BY_HOST = 0x44; // Not currently used in system/bt
+}
diff --git a/core/proto/android/providers/settings/secure.proto b/core/proto/android/providers/settings/secure.proto
index 0e052fe..9f4345d 100644
--- a/core/proto/android/providers/settings/secure.proto
+++ b/core/proto/android/providers/settings/secure.proto
@@ -525,7 +525,10 @@
}
optional Zen zen = 71;
+ optional SettingProto skip_gesture_enabled = 74 [ (android.privacy).dest = DEST_AUTOMATIC ];
+ optional SettingProto silence_gesture_enabled = 75 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
// Please insert fields in alphabetical order and group them into messages
// if possible (to avoid reaching the method limit).
- // Next tag = 74;
+ // Next tag = 76;
}
diff --git a/core/proto/android/server/jobscheduler.proto b/core/proto/android/server/jobscheduler.proto
index 0ec8c1a..7f3ea7a 100644
--- a/core/proto/android/server/jobscheduler.proto
+++ b/core/proto/android/server/jobscheduler.proto
@@ -403,18 +403,23 @@
optional bool is_charging = 1;
optional bool is_in_parole = 2;
+ // List of UIDs currently in the foreground.
+ repeated int32 foreground_uids = 3;
+
message TrackedJob {
option (.android.msg_privacy).dest = DEST_AUTOMATIC;
optional JobStatusShortInfoProto info = 1;
optional int32 source_uid = 2;
optional JobStatusDumpProto.Bucket effective_standby_bucket = 3;
- optional bool has_quota = 4;
+ // If the job started while the app was in the TOP state.
+ optional bool is_top_started_job = 4;
+ optional bool has_quota = 5;
// The amount of time that this job has remaining in its quota. This
// can be negative if the job is out of quota.
- optional int64 remaining_quota_ms = 5;
+ optional int64 remaining_quota_ms = 6;
}
- repeated TrackedJob tracked_jobs = 3;
+ repeated TrackedJob tracked_jobs = 4;
message Package {
option (.android.msg_privacy).dest = DEST_AUTOMATIC;
@@ -456,7 +461,7 @@
repeated TimingSession saved_sessions = 3;
}
- repeated PackageStats package_stats = 4;
+ repeated PackageStats package_stats = 5;
}
message StorageController {
option (.android.msg_privacy).dest = DEST_AUTOMATIC;
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 506d7f2..2f3a491 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -2269,6 +2269,11 @@
<permission android:name="android.permission.START_ANY_ACTIVITY"
android:protectionLevel="signature" />
+ <!-- Allows an application to start activities from background
+ @hide -->
+ <permission android:name="android.permission.START_ACTIVITIES_FROM_BACKGROUND"
+ android:protectionLevel="signature|privileged|vendorPrivileged|oem" />
+
<!-- @SystemApi Must be required by activities that handle the intent action
{@link Intent#ACTION_SEND_SHOW_SUSPENDED_APP_DETAILS}. This is for use by apps that
hold {@link Manifest.permission#SUSPEND_APPS} to interact with the system.
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 1feb59a..4d20fa4 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -929,9 +929,6 @@
in hardware. -->
<bool name="config_setColorTransformAccelerated">false</bool>
- <!-- Boolean indicating whether display white balance is supported. -->
- <bool name="config_displayWhiteBalanceAvailable">false</bool>
-
<!-- Control whether Night display is available. This should only be enabled on devices
that have a HWC implementation that can apply the matrix passed to setColorTransform
without impacting power, performance, and app compatibility (e.g. protected content). -->
@@ -987,6 +984,44 @@
<!-- B y-intercept --> <item>-0.198650895</item>
</string-array>
+ <!-- Boolean indicating whether display white balance is supported. -->
+ <bool name="config_displayWhiteBalanceAvailable">false</bool>
+
+ <!-- Minimum color temperature, in Kelvin, supported by display white balance. -->
+ <integer name="config_displayWhiteBalanceColorTemperatureMin">4000</integer>
+
+ <!-- Maximum color temperature, in Kelvin, supported by display white balance. -->
+ <integer name="config_displayWhiteBalanceColorTemperatureMax">8000</integer>
+
+ <!-- Default color temperature, in Kelvin, used by display white balance. -->
+ <integer name="config_displayWhiteBalanceColorTemperatureDefault">6500</integer>
+
+ <!-- The display primaries, in CIE1931 XYZ color space, for display
+ white balance to use in its calculations. -->
+ <string-array name="config_displayWhiteBalanceDisplayPrimaries">
+ <!-- Red X --> <item>0.412315</item>
+ <!-- Red Y --> <item>0.212600</item>
+ <!-- Red Z --> <item>0.019327</item>
+ <!-- Green X --> <item>0.357600</item>
+ <!-- Green Y --> <item>0.715200</item>
+ <!-- Green Z --> <item>0.119200</item>
+ <!-- Blue X --> <item>0.180500</item>
+ <!-- Blue Y --> <item>0.072200</item>
+ <!-- Blue Z --> <item>0.950633</item>
+ <!-- White X --> <item>0.950456</item>
+ <!-- White Y --> <item>1.000000</item>
+ <!-- White Z --> <item>1.089058</item>
+ </string-array>
+
+ <!-- The nominal white coordinates, in CIE1931 XYZ color space, for Display White Balance to
+ use in its calculations. AWB will adapt this white point to the target ambient white
+ point. -->
+ <string-array name="config_displayWhiteBalanceDisplayNominalWhite">
+ <!-- Nominal White X --> <item>0.950456</item>
+ <!-- Nominal White Y --> <item>1.000000</item>
+ <!-- Nominal White Z --> <item>1.089058</item>
+ </string-array>
+
<!-- Indicate available ColorDisplayController.COLOR_MODE_xxx. -->
<integer-array name="config_availableColorModes">
@@ -3661,7 +3696,7 @@
<string name="config_inputEventCompatProcessorOverrideClassName" translatable="false"></string>
<!-- Component name for the default module metadata provider on this device -->
- <string name="config_defaultModuleMetadataProvider">com.android.modulemetadata</string>
+ <string name="config_defaultModuleMetadataProvider" translatable="false">com.android.modulemetadata</string>
<!-- This is the default launcher component to use on secondary displays that support system
decorations.
@@ -3673,4 +3708,10 @@
<!-- If device supports corner radius on windows.
This should be turned off on low-end devices to improve animation performance. -->
<bool name="config_supportsRoundedCornersOnWindows">true</bool>
+
+ <!-- If the sensor that skips media is available or not. -->
+ <bool name="config_skipSensorAvailable">false</bool>
+
+ <!-- If the sensor that silences alerts is available or not. -->
+ <bool name="config_silenceSensorAvailable">false</bool>
</resources>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 010accf..daf8b44 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -3042,6 +3042,13 @@
<java-symbol type="array" name="config_nightDisplayColorTemperatureCoefficientsNative" />
<java-symbol type="array" name="config_availableColorModes" />
+ <java-symbol type="bool" name="config_displayWhiteBalanceAvailable" />
+ <java-symbol type="integer" name="config_displayWhiteBalanceColorTemperatureMin" />
+ <java-symbol type="integer" name="config_displayWhiteBalanceColorTemperatureMax" />
+ <java-symbol type="integer" name="config_displayWhiteBalanceColorTemperatureDefault" />
+ <java-symbol type="array" name="config_displayWhiteBalanceDisplayPrimaries" />
+ <java-symbol type="array" name="config_displayWhiteBalanceDisplayNominalWhite" />
+
<!-- Default first user restrictions -->
<java-symbol type="array" name="config_defaultFirstUserRestrictions" />
@@ -3529,4 +3536,7 @@
<java-symbol type="string" name="dynamic_mode_notification_title" />
<java-symbol type="string" name="dynamic_mode_notification_summary" />
<java-symbol type="drawable" name="ic_battery" />
+
+ <java-symbol type="bool" name="config_skipSensorAvailable" />
+ <java-symbol type="bool" name="config_silenceSensorAvailable" />
</resources>
diff --git a/core/tests/coretests/src/android/content/pm/PackageParserTest.java b/core/tests/coretests/src/android/content/pm/PackageParserTest.java
index 267267e..3f91a65 100644
--- a/core/tests/coretests/src/android/content/pm/PackageParserTest.java
+++ b/core/tests/coretests/src/android/content/pm/PackageParserTest.java
@@ -51,6 +51,12 @@
private static final String PRE_RELEASE = "B";
private static final String NEWER_PRE_RELEASE = "C";
+ // Codenames with a fingerprint attached to them. These may only be present in the apps
+ // declared min SDK and not as platform codenames.
+ private static final String OLDER_PRE_RELEASE_WITH_FINGERPRINT = "A.fingerprint";
+ private static final String PRE_RELEASE_WITH_FINGERPRINT = "B.fingerprint";
+ private static final String NEWER_PRE_RELEASE_WITH_FINGERPRINT = "C.fingerprint";
+
private static final String[] CODENAMES_RELEASED = { /* empty */ };
private static final String[] CODENAMES_PRE_RELEASE = { PRE_RELEASE };
@@ -68,7 +74,7 @@
isPlatformReleased ? CODENAMES_RELEASED : CODENAMES_PRE_RELEASE,
outError);
- assertEquals(result, expectedMinSdk);
+ assertEquals("Error msg: " + outError[0], expectedMinSdk, result);
if (expectedMinSdk == -1) {
assertNotNull(outError[0]);
@@ -98,6 +104,7 @@
// APP: Pre-release API 10
// DEV: Pre-release API 20
verifyComputeMinSdkVersion(OLDER_VERSION, OLDER_PRE_RELEASE, false, -1);
+ verifyComputeMinSdkVersion(OLDER_VERSION, OLDER_PRE_RELEASE_WITH_FINGERPRINT, false, -1);
// Do allow same pre-release minSdkVersion on pre-release platform,
// but overwrite the specified version with CUR_DEVELOPMENT.
@@ -105,11 +112,15 @@
// DEV: Pre-release API 20
verifyComputeMinSdkVersion(PLATFORM_VERSION, PRE_RELEASE, false,
Build.VERSION_CODES.CUR_DEVELOPMENT);
+ verifyComputeMinSdkVersion(PLATFORM_VERSION, PRE_RELEASE_WITH_FINGERPRINT, false,
+ Build.VERSION_CODES.CUR_DEVELOPMENT);
+
// Don't allow newer pre-release minSdkVersion on pre-release platform.
// APP: Pre-release API 30
// DEV: Pre-release API 20
verifyComputeMinSdkVersion(NEWER_VERSION, NEWER_PRE_RELEASE, false, -1);
+ verifyComputeMinSdkVersion(NEWER_VERSION, NEWER_PRE_RELEASE_WITH_FINGERPRINT, false, -1);
}
@Test
@@ -133,16 +144,20 @@
// APP: Pre-release API 10
// DEV: Released API 20
verifyComputeMinSdkVersion(OLDER_VERSION, OLDER_PRE_RELEASE, true, -1);
+ verifyComputeMinSdkVersion(OLDER_VERSION, OLDER_PRE_RELEASE_WITH_FINGERPRINT, true, -1);
// Don't allow same pre-release minSdkVersion on released platform.
// APP: Pre-release API 20
// DEV: Released API 20
verifyComputeMinSdkVersion(PLATFORM_VERSION, PRE_RELEASE, true, -1);
+ verifyComputeMinSdkVersion(PLATFORM_VERSION, PRE_RELEASE_WITH_FINGERPRINT, true, -1);
+
// Don't allow newer pre-release minSdkVersion on released platform.
// APP: Pre-release API 30
// DEV: Released API 20
verifyComputeMinSdkVersion(NEWER_VERSION, NEWER_PRE_RELEASE, true, -1);
+ verifyComputeMinSdkVersion(NEWER_VERSION, NEWER_PRE_RELEASE_WITH_FINGERPRINT, true, -1);
}
private void verifyComputeTargetSdkVersion(int targetSdkVersion, String targetSdkCodename,
@@ -189,6 +204,9 @@
// DEV: Pre-release API 20
verifyComputeTargetSdkVersion(OLDER_VERSION, OLDER_PRE_RELEASE, false, -1,
false /* forceCurrentDev */);
+ verifyComputeTargetSdkVersion(OLDER_VERSION, OLDER_PRE_RELEASE_WITH_FINGERPRINT, false, -1,
+ false /* forceCurrentDev */);
+
// Do allow same pre-release targetSdkVersion on pre-release platform,
// but overwrite the specified version with CUR_DEVELOPMENT.
@@ -196,18 +214,26 @@
// DEV: Pre-release API 20
verifyComputeTargetSdkVersion(PLATFORM_VERSION, PRE_RELEASE, false,
Build.VERSION_CODES.CUR_DEVELOPMENT, false /* forceCurrentDev */);
+ verifyComputeTargetSdkVersion(PLATFORM_VERSION, PRE_RELEASE_WITH_FINGERPRINT, false,
+ Build.VERSION_CODES.CUR_DEVELOPMENT, false /* forceCurrentDev */);
+
// Don't allow newer pre-release targetSdkVersion on pre-release platform.
// APP: Pre-release API 30
// DEV: Pre-release API 20
verifyComputeTargetSdkVersion(NEWER_VERSION, NEWER_PRE_RELEASE, false, -1,
false /* forceCurrentDev */);
+ verifyComputeTargetSdkVersion(NEWER_VERSION, NEWER_PRE_RELEASE_WITH_FINGERPRINT, false, -1,
+ false /* forceCurrentDev */);
+
// Force newer pre-release targetSdkVersion to current pre-release platform.
// APP: Pre-release API 30
// DEV: Pre-release API 20
verifyComputeTargetSdkVersion(NEWER_VERSION, NEWER_PRE_RELEASE, false,
Build.VERSION_CODES.CUR_DEVELOPMENT, true /* forceCurrentDev */);
+ verifyComputeTargetSdkVersion(NEWER_VERSION, NEWER_PRE_RELEASE_WITH_FINGERPRINT, false,
+ Build.VERSION_CODES.CUR_DEVELOPMENT, true /* forceCurrentDev */);
}
@Test
@@ -235,18 +261,25 @@
// DEV: Released API 20
verifyComputeTargetSdkVersion(OLDER_VERSION, OLDER_PRE_RELEASE, true, -1,
false /* forceCurrentDev */);
+ verifyComputeTargetSdkVersion(OLDER_VERSION, OLDER_PRE_RELEASE_WITH_FINGERPRINT, true, -1,
+ false /* forceCurrentDev */);
// Don't allow same pre-release targetSdkVersion on released platform.
// APP: Pre-release API 20
// DEV: Released API 20
verifyComputeTargetSdkVersion(PLATFORM_VERSION, PRE_RELEASE, true, -1,
false /* forceCurrentDev */);
+ verifyComputeTargetSdkVersion(PLATFORM_VERSION, PRE_RELEASE_WITH_FINGERPRINT, true, -1,
+ false /* forceCurrentDev */);
+
// Don't allow newer pre-release targetSdkVersion on released platform.
// APP: Pre-release API 30
// DEV: Released API 20
verifyComputeTargetSdkVersion(NEWER_VERSION, NEWER_PRE_RELEASE, true, -1,
false /* forceCurrentDev */);
+ verifyComputeTargetSdkVersion(NEWER_VERSION, NEWER_PRE_RELEASE_WITH_FINGERPRINT, true, -1,
+ false /* forceCurrentDev */);
}
/**
diff --git a/core/tests/coretests/src/android/provider/SettingsBackupTest.java b/core/tests/coretests/src/android/provider/SettingsBackupTest.java
index 1ed5ce4..df4600e 100644
--- a/core/tests/coretests/src/android/provider/SettingsBackupTest.java
+++ b/core/tests/coretests/src/android/provider/SettingsBackupTest.java
@@ -27,7 +27,6 @@
import static java.lang.reflect.Modifier.isStatic;
import android.platform.test.annotations.Presubmit;
-import android.provider.Settings.Global;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
@@ -270,6 +269,7 @@
Settings.Global.GNSS_HAL_LOCATION_REQUEST_DURATION_MILLIS,
Settings.Global.GNSS_SATELLITE_BLACKLIST,
Settings.Global.GPRS_REGISTER_CHECK_PERIOD_MS,
+ Settings.Global.HDMI_CEC_SWITCH_ENABLED,
Settings.Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED,
Settings.Global.HDMI_CONTROL_AUTO_WAKEUP_ENABLED,
Settings.Global.HDMI_CONTROL_ENABLED,
@@ -554,8 +554,10 @@
Settings.Global.APPOP_HISTORY_PARAMETERS,
Settings.Global.APPOP_HISTORY_MODE,
Settings.Global.APPOP_HISTORY_INTERVAL_MULTIPLIER,
- Settings.Global.APPOP_HISTORY_BASE_INTERVAL_MILLIS);
-
+ Settings.Global.APPOP_HISTORY_BASE_INTERVAL_MILLIS,
+ Settings.Global.ENABLE_RADIO_BUG_DETECTION,
+ Settings.Global.RADIO_BUG_WAKELOCK_TIMEOUT_COUNT_THRESHOLD,
+ Settings.Global.RADIO_BUG_SYSTEM_ERROR_COUNT_THRESHOLD);
private static final Set<String> BACKUP_BLACKLISTED_SECURE_SETTINGS =
newHashSet(
Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE,
diff --git a/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java b/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java
index 82eaf88..ec6101c 100644
--- a/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java
+++ b/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java
@@ -377,10 +377,10 @@
ConversationActions.Message.PERSON_USER_REMOTE)
.setText("Where are you?")
.build();
- ConversationActions.TypeConfig typeConfig =
- new ConversationActions.TypeConfig.Builder().includeTypesFromTextClassifier(false)
+ TextClassifier.EntityConfig typeConfig =
+ new TextClassifier.EntityConfig.Builder().includeTypesFromTextClassifier(false)
.setIncludedTypes(
- Collections.singletonList(ConversationActions.TYPE_TEXT_REPLY))
+ Collections.singletonList(ConversationAction.TYPE_TEXT_REPLY))
.build();
ConversationActions.Request request =
new ConversationActions.Request.Builder(Collections.singletonList(message))
@@ -391,10 +391,10 @@
ConversationActions conversationActions = mClassifier.suggestConversationActions(request);
assertTrue(conversationActions.getConversationActions().size() > 0);
assertTrue(conversationActions.getConversationActions().size() == 1);
- for (ConversationActions.ConversationAction conversationAction :
+ for (ConversationAction conversationAction :
conversationActions.getConversationActions()) {
assertThat(conversationAction,
- isConversationAction(ConversationActions.TYPE_TEXT_REPLY));
+ isConversationAction(ConversationAction.TYPE_TEXT_REPLY));
}
}*/
@@ -406,10 +406,10 @@
ConversationActions.Message.PERSON_USER_REMOTE)
.setText("Where are you?")
.build();
- ConversationActions.TypeConfig typeConfig =
- new ConversationActions.TypeConfig.Builder().includeTypesFromTextClassifier(false)
+ TextClassifier.EntityConfig typeConfig =
+ new TextClassifier.EntityConfig.Builder().includeTypesFromTextClassifier(false)
.setIncludedTypes(
- Collections.singletonList(ConversationActions.TYPE_TEXT_REPLY))
+ Collections.singletonList(ConversationAction.TYPE_TEXT_REPLY))
.build();
ConversationActions.Request request =
new ConversationActions.Request.Builder(Collections.singletonList(message))
@@ -418,10 +418,10 @@
ConversationActions conversationActions = mClassifier.suggestConversationActions(request);
assertTrue(conversationActions.getConversationActions().size() > 1);
- for (ConversationActions.ConversationAction conversationAction :
+ for (ConversationAction conversationAction :
conversationActions.getConversationActions()) {
assertThat(conversationAction,
- isConversationAction(ConversationActions.TYPE_TEXT_REPLY));
+ isConversationAction(ConversationAction.TYPE_TEXT_REPLY));
}
}
@@ -524,20 +524,19 @@
};
}
- private static Matcher<ConversationActions.ConversationAction> isConversationAction(
- String actionType) {
- return new BaseMatcher<ConversationActions.ConversationAction>() {
+ private static Matcher<ConversationAction> isConversationAction(String actionType) {
+ return new BaseMatcher<ConversationAction>() {
@Override
public boolean matches(Object o) {
- if (!(o instanceof ConversationActions.ConversationAction)) {
+ if (!(o instanceof ConversationAction)) {
return false;
}
- ConversationActions.ConversationAction conversationAction =
- (ConversationActions.ConversationAction) o;
+ ConversationAction conversationAction =
+ (ConversationAction) o;
if (!actionType.equals(conversationAction.getType())) {
return false;
}
- if (ConversationActions.TYPE_TEXT_REPLY.equals(actionType)) {
+ if (ConversationAction.TYPE_TEXT_REPLY.equals(actionType)) {
if (conversationAction.getTextReply() == null) {
return false;
}
diff --git a/core/tests/coretests/src/android/view/textclassifier/logging/TextClassifierEventTronLoggerTest.java b/core/tests/coretests/src/android/view/textclassifier/logging/TextClassifierEventTronLoggerTest.java
index 344f79d..0597a89 100644
--- a/core/tests/coretests/src/android/view/textclassifier/logging/TextClassifierEventTronLoggerTest.java
+++ b/core/tests/coretests/src/android/view/textclassifier/logging/TextClassifierEventTronLoggerTest.java
@@ -26,7 +26,7 @@
import android.metrics.LogMaker;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
-import android.view.textclassifier.ConversationActions;
+import android.view.textclassifier.ConversationAction;
import android.view.textclassifier.TextClassificationContext;
import android.view.textclassifier.TextClassifierEvent;
import android.view.textclassifier.TextClassifierEventTronLogger;
@@ -69,7 +69,7 @@
new TextClassifierEvent.Builder(
TextClassifierEvent.CATEGORY_CONVERSATION_ACTIONS,
TextClassifierEvent.TYPE_SMART_ACTION)
- .setEntityType(ConversationActions.TYPE_CALL_PHONE)
+ .setEntityType(ConversationAction.TYPE_CALL_PHONE)
.setEventTime(EVENT_TIME)
.setEventContext(textClassificationContext)
.build();
@@ -84,7 +84,7 @@
assertThat(logMaker.getType()).isEqualTo(
ACTION_TEXT_SELECTION_SMART_SHARE);
assertThat(logMaker.getTaggedData(FIELD_SELECTION_ENTITY_TYPE))
- .isEqualTo(ConversationActions.TYPE_CALL_PHONE);
+ .isEqualTo(ConversationAction.TYPE_CALL_PHONE);
assertThat(logMaker.getTaggedData(FIELD_TEXT_CLASSIFIER_EVENT_TIME))
.isEqualTo(EVENT_TIME);
assertThat(logMaker.getPackageName()).isEqualTo(PACKAGE_NAME);
diff --git a/core/tests/hdmitests/src/android/hardware/hdmi/HdmiAudioSystemClientTest.java b/core/tests/hdmitests/src/android/hardware/hdmi/HdmiAudioSystemClientTest.java
index 0dd9d09..28a8afe 100644
--- a/core/tests/hdmitests/src/android/hardware/hdmi/HdmiAudioSystemClientTest.java
+++ b/core/tests/hdmitests/src/android/hardware/hdmi/HdmiAudioSystemClientTest.java
@@ -318,6 +318,27 @@
mMaxVolume = maxVolume;
mIsMute = isMute;
}
+
+ @Override
+ public void setSystemAudioModeOnForAudioOnlySource() {
+ }
+
+ @Override
+ public int getPhysicalAddress() {
+ return 0x0000;
+ }
+
+ @Override
+ public void powerOffRemoteDevice(int logicalAddress, int powerStatus) {
+ }
+
+ @Override
+ public void powerOnRemoteDevice(int logicalAddress, int powerStatus) {
+ }
+
+ @Override
+ public void askRemoteDeviceToBecomeActiveSource(int physicalAddress) {
+ }
}
}
diff --git a/data/etc/Android.bp b/data/etc/Android.bp
index 0bffa38..035ee10 100644
--- a/data/etc/Android.bp
+++ b/data/etc/Android.bp
@@ -39,9 +39,38 @@
name: "privapp-permissions-platform.xml",
sub_dir: "permissions",
src: "privapp-permissions-platform.xml",
- required: [
- "privapp_whitelist_com.android.settings.intelligence",
- ]
+}
+
+prebuilt_etc {
+ name: "privapp_whitelist_com.android.carrierconfig",
+ product_specific: true,
+ sub_dir: "permissions",
+ src: "com.android.carrierconfig.xml",
+ filename_from_src: true,
+}
+
+prebuilt_etc {
+ name: "privapp_whitelist_com.android.contacts",
+ product_specific: true,
+ sub_dir: "permissions",
+ src: "com.android.contacts.xml",
+ filename_from_src: true,
+}
+
+prebuilt_etc {
+ name: "privapp_whitelist_com.android.launcher3",
+ product_specific: true,
+ sub_dir: "permissions",
+ src: "com.android.launcher3.xml",
+ filename_from_src: true,
+}
+
+prebuilt_etc {
+ name: "privapp_whitelist_com.android.provision",
+ product_specific: true,
+ sub_dir: "permissions",
+ src: "com.android.provision.xml",
+ filename_from_src: true,
}
prebuilt_etc {
@@ -54,12 +83,21 @@
prebuilt_etc {
name: "privapp_whitelist_com.android.settings.intelligence",
+ product_specific: true,
sub_dir: "permissions",
src: "com.android.settings.intelligence.xml",
filename_from_src: true,
}
prebuilt_etc {
+ name: "privapp_whitelist_com.android.storagemanager",
+ product_specific: true,
+ sub_dir: "permissions",
+ src: "com.android.storagemanager.xml",
+ filename_from_src: true,
+}
+
+prebuilt_etc {
name: "privapp_whitelist_com.android.systemui",
product_specific: true,
sub_dir: "permissions",
diff --git a/data/etc/com.android.carrierconfig.xml b/data/etc/com.android.carrierconfig.xml
new file mode 100644
index 0000000..17efb03
--- /dev/null
+++ b/data/etc/com.android.carrierconfig.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2019 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+<permissions>
+ <privapp-permissions package="com.android.carrierconfig">
+ <permission name="android.permission.READ_PRIVILEGED_PHONE_STATE"/>
+ </privapp-permissions>
+</permissions>
diff --git a/data/etc/com.android.contacts.xml b/data/etc/com.android.contacts.xml
new file mode 100644
index 0000000..78eae40
--- /dev/null
+++ b/data/etc/com.android.contacts.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2019 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+<permissions>
+ <privapp-permissions package="com.android.contacts">
+ <permission name="android.permission.GET_ACCOUNTS_PRIVILEGED"/>
+ <permission name="com.android.voicemail.permission.READ_VOICEMAIL"/>
+ </privapp-permissions>
+</permissions>
diff --git a/data/etc/com.android.launcher3.xml b/data/etc/com.android.launcher3.xml
new file mode 100644
index 0000000..337e153
--- /dev/null
+++ b/data/etc/com.android.launcher3.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2019 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+<permissions>
+ <privapp-permissions package="com.android.launcher3">
+ <permission name="android.permission.BIND_APPWIDGET"/>
+ <permission name="android.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS"/>
+ <permission name="android.permission.GET_ACCOUNTS_PRIVILEGED"/>
+ </privapp-permissions>
+</permissions>
diff --git a/data/etc/com.android.provision.xml b/data/etc/com.android.provision.xml
new file mode 100644
index 0000000..05404ef
--- /dev/null
+++ b/data/etc/com.android.provision.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2019 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+<permissions>
+ <privapp-permissions package="com.android.provision">
+ <permission name="android.permission.WRITE_SECURE_SETTINGS"/>
+ </privapp-permissions>
+</permissions>
diff --git a/data/etc/com.android.storagemanager.xml b/data/etc/com.android.storagemanager.xml
new file mode 100644
index 0000000..e85a82c
--- /dev/null
+++ b/data/etc/com.android.storagemanager.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2019 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+<permissions>
+ <privapp-permissions package="com.android.storagemanager">
+ <permission name="android.permission.DELETE_PACKAGES"/>
+ <permission name="android.permission.INTERACT_ACROSS_USERS"/>
+ <permission name="android.permission.MANAGE_USERS"/>
+ <permission name="android.permission.PACKAGE_USAGE_STATS"/>
+ <permission name="android.permission.USE_RESERVED_DISK"/>
+ <permission name="android.permission.WRITE_SECURE_SETTINGS"/>
+ </privapp-permissions>
+</permissions>
diff --git a/data/etc/com.android.systemui.xml b/data/etc/com.android.systemui.xml
index 221708b..3562a8f 100644
--- a/data/etc/com.android.systemui.xml
+++ b/data/etc/com.android.systemui.xml
@@ -44,6 +44,7 @@
<permission name="android.permission.READ_PRIVILEGED_PHONE_STATE"/>
<permission name="android.permission.REAL_GET_TASKS"/>
<permission name="android.permission.RECEIVE_MEDIA_RESOURCE_USAGE"/>
+ <permission name="android.permission.START_ACTIVITIES_FROM_BACKGROUND" />
<permission name="android.permission.START_ACTIVITY_AS_CALLER"/>
<permission name="android.permission.START_TASKS_FROM_RECENTS"/>
<permission name="android.permission.STATUS_BAR"/>
diff --git a/data/etc/platform.xml b/data/etc/platform.xml
index 4a2db0a..fb43e41 100644
--- a/data/etc/platform.xml
+++ b/data/etc/platform.xml
@@ -223,12 +223,12 @@
code to link against. -->
<library name="android.test.base"
- file="/system/framework/android.test.base.impl.jar" />
+ file="/system/framework/android.test.base.jar" />
<library name="android.test.mock"
- file="/system/framework/android.test.mock.impl.jar"
+ file="/system/framework/android.test.mock.jar"
dependency="android.test.base" />
<library name="android.test.runner"
- file="/system/framework/android.test.runner.impl.jar"
+ file="/system/framework/android.test.runner.jar"
dependency="android.test.base:android.test.mock" />
<!-- In BOOT_JARS historically, and now added to legacy applications. -->
diff --git a/data/etc/privapp-permissions-platform.xml b/data/etc/privapp-permissions-platform.xml
index 393a2a6..597d14a 100644
--- a/data/etc/privapp-permissions-platform.xml
+++ b/data/etc/privapp-permissions-platform.xml
@@ -33,10 +33,6 @@
<permission name="android.permission.CRYPT_KEEPER"/>
</privapp-permissions>
- <privapp-permissions package="com.android.carrierconfig">
- <permission name="android.permission.READ_PRIVILEGED_PHONE_STATE"/>
- </privapp-permissions>
-
<privapp-permissions package="com.android.cellbroadcastreceiver">
<permission name="android.permission.INTERACT_ACROSS_USERS"/>
<permission name="android.permission.MANAGE_USERS"/>
@@ -45,11 +41,6 @@
<permission name="android.permission.RECEIVE_EMERGENCY_BROADCAST"/>
</privapp-permissions>
- <privapp-permissions package="com.android.contacts">
- <permission name="android.permission.GET_ACCOUNTS_PRIVILEGED"/>
- <permission name="com.android.voicemail.permission.READ_VOICEMAIL"/>
- </privapp-permissions>
-
<privapp-permissions package="com.android.defcontainer">
<permission name="android.permission.ACCESS_CACHE_FILESYSTEM"/>
<permission name="android.permission.ALLOCATE_AGGRESSIVE"/>
@@ -79,12 +70,6 @@
<permission name="android.permission.WRITE_MEDIA_STORAGE"/>
</privapp-permissions>
- <privapp-permissions package="com.android.launcher3">
- <permission name="android.permission.BIND_APPWIDGET"/>
- <permission name="android.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS"/>
- <permission name="android.permission.GET_ACCOUNTS_PRIVILEGED"/>
- </privapp-permissions>
-
<privapp-permissions package="com.android.location.fused">
<permission name="android.permission.INSTALL_LOCATION_PROVIDER"/>
</privapp-permissions>
@@ -238,10 +223,6 @@
<permission name="android.permission.USE_RESERVED_DISK"/>
</privapp-permissions>
- <privapp-permissions package="com.android.provision">
- <permission name="android.permission.WRITE_SECURE_SETTINGS"/>
- </privapp-permissions>
-
<privapp-permissions package="com.android.mainline.networkstack">
<permission name="android.permission.ACCESS_NETWORK_CONDITIONS"/>
<permission name="android.permission.CHANGE_BACKGROUND_DATA_SETTING"/>
@@ -335,6 +316,7 @@
<permission name="android.permission.SET_TIME"/>
<permission name="android.permission.SET_TIME_ZONE"/>
<permission name="android.permission.SIGNAL_PERSISTENT_PROCESSES"/>
+ <permission name="android.permission.START_ACTIVITIES_FROM_BACKGROUND" />
<permission name="android.permission.START_TASKS_FROM_RECENTS" />
<permission name="android.permission.STOP_APP_SWITCHES"/>
<permission name="android.permission.SUBSTITUTE_NOTIFICATION_APP_NAME"/>
@@ -349,15 +331,6 @@
<permission name="android.permission.INTENT_FILTER_VERIFICATION_AGENT"/>
</privapp-permissions>
- <privapp-permissions package="com.android.storagemanager">
- <permission name="android.permission.DELETE_PACKAGES"/>
- <permission name="android.permission.INTERACT_ACROSS_USERS"/>
- <permission name="android.permission.MANAGE_USERS"/>
- <permission name="android.permission.PACKAGE_USAGE_STATS"/>
- <permission name="android.permission.USE_RESERVED_DISK"/>
- <permission name="android.permission.WRITE_SECURE_SETTINGS"/>
- </privapp-permissions>
-
<privapp-permissions package="com.android.tv">
<permission name="android.permission.CHANGE_HDMI_CEC_ACTIVE_SOURCE"/>
<permission name="android.permission.DVB_DEVICE"/>
diff --git a/graphics/java/android/graphics/BaseCanvas.java b/graphics/java/android/graphics/BaseCanvas.java
index ca9dc47..65aaba1 100644
--- a/graphics/java/android/graphics/BaseCanvas.java
+++ b/graphics/java/android/graphics/BaseCanvas.java
@@ -22,6 +22,7 @@
import android.annotation.Size;
import android.annotation.UnsupportedAppUsage;
import android.graphics.Canvas.VertexMode;
+import android.graphics.text.MeasuredText;
import android.text.GraphicsOperations;
import android.text.MeasuredParagraph;
import android.text.PrecomputedText;
@@ -554,14 +555,12 @@
final int paraStart = pt.getParagraphStart(paraIndex);
final MeasuredParagraph mp = pt.getMeasuredParagraph(paraIndex);
// Only support the text in the same paragraph.
- nDrawTextRun(mNativeCanvasWrapper,
- mp.getChars(),
- start - paraStart,
- end - start,
- contextStart - paraStart,
- contextEnd - contextStart,
- x, y, isRtl, paint.getNativeInstance(),
- mp.getMeasuredText().getNativePtr());
+ drawTextRun(mp.getMeasuredText(),
+ start - paraStart,
+ end - paraStart,
+ contextStart - paraStart,
+ contextEnd - paraStart,
+ x, y, isRtl, paint);
return;
}
}
@@ -576,6 +575,14 @@
}
}
+ public void drawTextRun(@NonNull MeasuredText measuredText, int start, int end,
+ int contextStart, int contextEnd, float x, float y, boolean isRtl,
+ @NonNull Paint paint) {
+ nDrawTextRun(mNativeCanvasWrapper, measuredText.getChars(), start, end - start,
+ contextStart, contextEnd - contextStart, x, y, isRtl, paint.getNativeInstance(),
+ measuredText.getNativePtr());
+ }
+
public void drawVertices(@NonNull VertexMode mode, int vertexCount, @NonNull float[] verts,
int vertOffset, @Nullable float[] texs, int texOffset, @Nullable int[] colors,
int colorOffset, @Nullable short[] indices, int indexOffset, int indexCount,
diff --git a/graphics/java/android/graphics/BaseRecordingCanvas.java b/graphics/java/android/graphics/BaseRecordingCanvas.java
index 901c211..4f60935 100644
--- a/graphics/java/android/graphics/BaseRecordingCanvas.java
+++ b/graphics/java/android/graphics/BaseRecordingCanvas.java
@@ -20,6 +20,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Size;
+import android.graphics.text.MeasuredText;
import android.text.GraphicsOperations;
import android.text.MeasuredParagraph;
import android.text.PrecomputedText;
@@ -522,14 +523,12 @@
final int paraStart = pt.getParagraphStart(paraIndex);
final MeasuredParagraph mp = pt.getMeasuredParagraph(paraIndex);
// Only support if the target is in the same paragraph.
- nDrawTextRun(mNativeCanvasWrapper,
- mp.getChars(),
+ drawTextRun(mp.getMeasuredText(),
start - paraStart,
- end - start,
+ end - paraStart,
contextStart - paraStart,
- contextEnd - contextStart,
- x, y, isRtl, paint.getNativeInstance(),
- mp.getMeasuredText().getNativePtr());
+ contextEnd - paraStart,
+ x, y, isRtl, paint);
return;
}
}
@@ -545,6 +544,15 @@
}
@Override
+ public void drawTextRun(@NonNull MeasuredText measuredText, int start, int end,
+ int contextStart, int contextEnd, float x, float y, boolean isRtl,
+ @NonNull Paint paint) {
+ nDrawTextRun(mNativeCanvasWrapper, measuredText.getChars(), start, end - start,
+ contextStart, contextEnd - contextStart, x, y, isRtl, paint.getNativeInstance(),
+ measuredText.getNativePtr());
+ }
+
+ @Override
public final void drawVertices(@NonNull VertexMode mode, int vertexCount,
@NonNull float[] verts, int vertOffset, @Nullable float[] texs, int texOffset,
@Nullable int[] colors, int colorOffset, @Nullable short[] indices, int indexOffset,
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index 790b37e..30f0bfa 100644
--- a/graphics/java/android/graphics/Bitmap.java
+++ b/graphics/java/android/graphics/Bitmap.java
@@ -18,9 +18,11 @@
import android.annotation.CheckResult;
import android.annotation.ColorInt;
+import android.annotation.ColorLong;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Size;
+import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
import android.annotation.WorkerThread;
import android.content.res.ResourcesImpl;
@@ -1780,6 +1782,30 @@
}
/**
+ * Fills the bitmap's pixels with the specified {@link Color}.
+ *
+ * @throws IllegalStateException if the bitmap is not mutable.
+ * @throws IllegalArgumentException if the color space encoded in the long
+ * is invalid or unknown.
+ *
+ * @hide pending API approval
+ */
+ @TestApi
+ public void eraseColor(@ColorLong long c) {
+ checkRecycled("Can't erase a recycled bitmap");
+ if (!isMutable()) {
+ throw new IllegalStateException("cannot erase immutable bitmaps");
+ }
+
+ ColorSpace cs = Color.colorSpace(c);
+ float r = Color.red(c);
+ float g = Color.green(c);
+ float b = Color.blue(c);
+ float a = Color.alpha(c);
+ nativeErase(mNativePtr, cs, r, g, b, a);
+ }
+
+ /**
* Returns the {@link Color} at the specified location. Throws an exception
* if x or y are out of bounds (negative or >= to the width or height
* respectively). The returned color is a non-premultiplied ARGB value in
@@ -2123,6 +2149,8 @@
int quality, OutputStream stream,
byte[] tempStorage);
private static native void nativeErase(long nativeBitmap, int color);
+ private static native void nativeErase(long nativeBitmap, ColorSpace cs,
+ float r, float g, float b, float a);
private static native int nativeRowBytes(long nativeBitmap);
private static native int nativeConfig(long nativeBitmap);
diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java
index 63a806e..8c1bae2 100644
--- a/graphics/java/android/graphics/Canvas.java
+++ b/graphics/java/android/graphics/Canvas.java
@@ -22,6 +22,7 @@
import android.annotation.Nullable;
import android.annotation.Size;
import android.annotation.UnsupportedAppUsage;
+import android.graphics.text.MeasuredText;
import android.os.Build;
import dalvik.annotation.optimization.CriticalNative;
@@ -2122,7 +2123,8 @@
* the text next to it.
* <p>
* All text outside the range {@code contextStart..contextEnd} is ignored. The text between
- * {@code start} and {@code end} will be laid out and drawn.
+ * {@code start} and {@code end} will be laid out and drawn. The context range is useful for
+ * contextual shaping, e.g. Kerning, Arabic contextural form.
* <p>
* The direction of the run is explicitly specified by {@code isRtl}. Thus, this method is
* suitable only for runs of a single direction. Alignment of the text is as determined by the
@@ -2151,6 +2153,31 @@
}
/**
+ * Draw a run of text, all in a single direction, with optional context for complex text
+ * shaping.
+ * <p>
+ * See {@link #drawTextRun(CharSequence, int, int, int, int, float, float, boolean, Paint)} for
+ * more details. This method uses a {@link MeasuredText} rather than CharSequence to represent
+ * the string.
+ *
+ * @param text the text to render
+ * @param start the start of the text to render. Data before this position can be used for
+ * shaping context.
+ * @param end the end of the text to render. Data at or after this position can be used for
+ * shaping context.
+ * @param contextStart the index of the start of the shaping context
+ * @param contextEnd the index of the end of the shaping context
+ * @param x the x position at which to draw the text
+ * @param y the y position at which to draw the text
+ * @param isRtl whether the run is in RTL direction
+ * @param paint the paint
+ */
+ public void drawTextRun(@NonNull MeasuredText text, int start, int end, int contextStart,
+ int contextEnd, float x, float y, boolean isRtl, @NonNull Paint paint) {
+ super.drawTextRun(text, start, end, contextStart, contextEnd, x, y, isRtl, paint);
+ }
+
+ /**
* Draw the array of vertices, interpreted as triangles (based on mode). The verts array is
* required, and specifies the x,y pairs for each vertex. If texs is non-null, then it is used
* to specify the coordinate in shader coordinates to use at each vertex (the paint must have a
diff --git a/graphics/java/android/graphics/ColorSpace.java b/graphics/java/android/graphics/ColorSpace.java
index 95317a4..9fa70a5 100644
--- a/graphics/java/android/graphics/ColorSpace.java
+++ b/graphics/java/android/graphics/ColorSpace.java
@@ -1661,10 +1661,12 @@
* @param rhs 3x3 matrix, as a non-null array of 9 floats
* @return A new array of 9 floats containing the result of the multiplication
* of rhs by lhs
+ *
+ * @hide
*/
@NonNull
@Size(9)
- private static float[] mul3x3(@NonNull @Size(9) float[] lhs, @NonNull @Size(9) float[] rhs) {
+ public static float[] mul3x3(@NonNull @Size(9) float[] lhs, @NonNull @Size(9) float[] rhs) {
float[] r = new float[9];
r[0] = lhs[0] * rhs[0] + lhs[3] * rhs[1] + lhs[6] * rhs[2];
r[1] = lhs[1] * rhs[0] + lhs[4] * rhs[1] + lhs[7] * rhs[2];
diff --git a/libs/androidfw/AssetManager2.cpp b/libs/androidfw/AssetManager2.cpp
index ad9ec02..3c35d9b 100644
--- a/libs/androidfw/AssetManager2.cpp
+++ b/libs/androidfw/AssetManager2.cpp
@@ -20,8 +20,9 @@
#include <algorithm>
#include <iterator>
-#include <set>
#include <map>
+#include <set>
+#include <sstream>
#include "android-base/logging.h"
#include "android-base/stringprintf.h"
@@ -372,6 +373,9 @@
uint32_t best_offset = 0u;
uint32_t type_flags = 0u;
+ Resolution::Step::Type resolution_type;
+ std::vector<Resolution::Step> resolution_steps;
+
// If desired_config is the same as the set configuration, then we can use our filtered list
// and we don't need to match the configurations, since they already matched.
const bool use_fast_path = desired_config == &configuration_;
@@ -403,8 +407,8 @@
// If the package is an overlay, then even configurations that are the same MUST be chosen.
const bool package_is_overlay = loaded_package->IsOverlay();
- const FilteredConfigGroup& filtered_group = loaded_package_impl.filtered_configs_[type_idx];
if (use_fast_path) {
+ const FilteredConfigGroup& filtered_group = loaded_package_impl.filtered_configs_[type_idx];
const std::vector<ResTable_config>& candidate_configs = filtered_group.configurations;
const size_t type_count = candidate_configs.size();
for (uint32_t i = 0; i < type_count; i++) {
@@ -412,21 +416,34 @@
// We can skip calling ResTable_config::match() because we know that all candidate
// configurations that do NOT match have been filtered-out.
- if ((best_config == nullptr || this_config.isBetterThan(*best_config, desired_config)) ||
- (package_is_overlay && this_config.compare(*best_config) == 0)) {
- // The configuration matches and is better than the previous selection.
- // Find the entry value if it exists for this configuration.
- const ResTable_type* type_chunk = filtered_group.types[i];
- const uint32_t offset = LoadedPackage::GetEntryOffset(type_chunk, local_entry_idx);
- if (offset == ResTable_type::NO_ENTRY) {
- continue;
- }
+ if (best_config == nullptr) {
+ resolution_type = Resolution::Step::Type::INITIAL;
+ } else if (this_config.isBetterThan(*best_config, desired_config)) {
+ resolution_type = Resolution::Step::Type::BETTER_MATCH;
+ } else if (package_is_overlay && this_config.compare(*best_config) == 0) {
+ resolution_type = Resolution::Step::Type::OVERLAID;
+ } else {
+ continue;
+ }
- best_cookie = cookie;
- best_package = loaded_package;
- best_type = type_chunk;
- best_config = &this_config;
- best_offset = offset;
+ // The configuration matches and is better than the previous selection.
+ // Find the entry value if it exists for this configuration.
+ const ResTable_type* type = filtered_group.types[i];
+ const uint32_t offset = LoadedPackage::GetEntryOffset(type, local_entry_idx);
+ if (offset == ResTable_type::NO_ENTRY) {
+ continue;
+ }
+
+ best_cookie = cookie;
+ best_package = loaded_package;
+ best_type = type;
+ best_config = &this_config;
+ best_offset = offset;
+
+ if (resource_resolution_logging_enabled_) {
+ resolution_steps.push_back(Resolution::Step{resolution_type,
+ this_config.toString(),
+ &loaded_package->GetPackageName()});
}
}
} else {
@@ -440,23 +457,38 @@
ResTable_config this_config;
this_config.copyFromDtoH((*iter)->config);
- if (this_config.match(*desired_config)) {
- if ((best_config == nullptr || this_config.isBetterThan(*best_config, desired_config)) ||
- (package_is_overlay && this_config.compare(*best_config) == 0)) {
- // The configuration matches and is better than the previous selection.
- // Find the entry value if it exists for this configuration.
- const uint32_t offset = LoadedPackage::GetEntryOffset(*iter, local_entry_idx);
- if (offset == ResTable_type::NO_ENTRY) {
- continue;
- }
+ if (!this_config.match(*desired_config)) {
+ continue;
+ }
- best_cookie = cookie;
- best_package = loaded_package;
- best_type = *iter;
- best_config_copy = this_config;
- best_config = &best_config_copy;
- best_offset = offset;
- }
+ if (best_config == nullptr) {
+ resolution_type = Resolution::Step::Type::INITIAL;
+ } else if (this_config.isBetterThan(*best_config, desired_config)) {
+ resolution_type = Resolution::Step::Type::BETTER_MATCH;
+ } else if (package_is_overlay && this_config.compare(*best_config) == 0) {
+ resolution_type = Resolution::Step::Type::OVERLAID;
+ } else {
+ continue;
+ }
+
+ // The configuration matches and is better than the previous selection.
+ // Find the entry value if it exists for this configuration.
+ const uint32_t offset = LoadedPackage::GetEntryOffset(*iter, local_entry_idx);
+ if (offset == ResTable_type::NO_ENTRY) {
+ continue;
+ }
+
+ best_cookie = cookie;
+ best_package = loaded_package;
+ best_type = *iter;
+ best_config_copy = this_config;
+ best_config = &best_config_copy;
+ best_offset = offset;
+
+ if (resource_resolution_logging_enabled_) {
+ resolution_steps.push_back(Resolution::Step{resolution_type,
+ this_config.toString(),
+ &loaded_package->GetPackageName()});
}
}
}
@@ -478,9 +510,95 @@
out_entry->entry_string_ref =
StringPoolRef(best_package->GetKeyStringPool(), best_entry->key.index);
out_entry->dynamic_ref_table = &package_group.dynamic_ref_table;
+
+ if (resource_resolution_logging_enabled_) {
+ last_resolution.resid = resid;
+ last_resolution.cookie = best_cookie;
+ last_resolution.steps = resolution_steps;
+
+ // Cache only the type/entry refs since that's all that's needed to build name
+ last_resolution.type_string_ref =
+ StringPoolRef(best_package->GetTypeStringPool(), best_type->id - 1);
+ last_resolution.entry_string_ref =
+ StringPoolRef(best_package->GetKeyStringPool(), best_entry->key.index);
+ }
+
return best_cookie;
}
+void AssetManager2::SetResourceResolutionLoggingEnabled(bool enabled) {
+ resource_resolution_logging_enabled_ = enabled;
+
+ if (!enabled) {
+ last_resolution.cookie = kInvalidCookie;
+ last_resolution.resid = 0;
+ last_resolution.steps.clear();
+ last_resolution.type_string_ref = StringPoolRef();
+ last_resolution.entry_string_ref = StringPoolRef();
+ }
+}
+
+std::string AssetManager2::GetLastResourceResolution() const {
+ if (!resource_resolution_logging_enabled_) {
+ LOG(ERROR) << "Must enable resource resolution logging before getting path.";
+ return std::string();
+ }
+
+ auto cookie = last_resolution.cookie;
+ if (cookie == kInvalidCookie) {
+ LOG(ERROR) << "AssetManager hasn't resolved a resource to read resolution path.";
+ return std::string();
+ }
+
+ uint32_t resid = last_resolution.resid;
+ std::vector<Resolution::Step>& steps = last_resolution.steps;
+
+ ResourceName resource_name;
+ std::string resource_name_string;
+
+ const LoadedPackage* package =
+ apk_assets_[cookie]->GetLoadedArsc()->GetPackageById(get_package_id(resid));
+
+ if (package != nullptr) {
+ ToResourceName(last_resolution.type_string_ref,
+ last_resolution.entry_string_ref,
+ package,
+ &resource_name);
+ resource_name_string = ToFormattedResourceString(&resource_name);
+ }
+
+ std::stringstream log_stream;
+ log_stream << base::StringPrintf("Resolution for 0x%08x ", resid)
+ << resource_name_string
+ << "\n\tFor config -"
+ << configuration_.toString();
+
+ std::string prefix;
+ for (Resolution::Step step : steps) {
+ switch (step.type) {
+ case Resolution::Step::Type::INITIAL:
+ prefix = "Found initial";
+ break;
+ case Resolution::Step::Type::BETTER_MATCH:
+ prefix = "Found better";
+ break;
+ case Resolution::Step::Type::OVERLAID:
+ prefix = "Overlaid";
+ break;
+ }
+
+ if (!prefix.empty()) {
+ log_stream << "\n\t" << prefix << ": " << *step.package_name;
+
+ if (!step.config_name.isEmpty()) {
+ log_stream << " -" << step.config_name;
+ }
+ }
+ }
+
+ return log_stream.str();
+}
+
bool AssetManager2::GetResourceName(uint32_t resid, ResourceName* out_name) const {
FindEntryResult entry;
ApkAssetsCookie cookie =
@@ -495,27 +613,10 @@
return false;
}
- out_name->package = package->GetPackageName().data();
- out_name->package_len = package->GetPackageName().size();
-
- out_name->type = entry.type_string_ref.string8(&out_name->type_len);
- out_name->type16 = nullptr;
- if (out_name->type == nullptr) {
- out_name->type16 = entry.type_string_ref.string16(&out_name->type_len);
- if (out_name->type16 == nullptr) {
- return false;
- }
- }
-
- out_name->entry = entry.entry_string_ref.string8(&out_name->entry_len);
- out_name->entry16 = nullptr;
- if (out_name->entry == nullptr) {
- out_name->entry16 = entry.entry_string_ref.string16(&out_name->entry_len);
- if (out_name->entry16 == nullptr) {
- return false;
- }
- }
- return true;
+ return ToResourceName(entry.type_string_ref,
+ entry.entry_string_ref,
+ package,
+ out_name);
}
bool AssetManager2::GetResourceFlags(uint32_t resid, uint32_t* out_flags) const {
diff --git a/libs/androidfw/CursorWindow.cpp b/libs/androidfw/CursorWindow.cpp
index 5694115..a99e77f 100644
--- a/libs/androidfw/CursorWindow.cpp
+++ b/libs/androidfw/CursorWindow.cpp
@@ -94,7 +94,7 @@
if (size < 0) {
result = UNKNOWN_ERROR;
} else {
- int dupAshmemFd = ::dup(ashmemFd);
+ int dupAshmemFd = ::fcntl(ashmemFd, F_DUPFD_CLOEXEC, 0);
if (dupAshmemFd < 0) {
result = -errno;
} else {
diff --git a/libs/androidfw/LoadedArsc.cpp b/libs/androidfw/LoadedArsc.cpp
index 5a26780..70ce9bc 100644
--- a/libs/androidfw/LoadedArsc.cpp
+++ b/libs/androidfw/LoadedArsc.cpp
@@ -593,7 +593,12 @@
return {};
}
- // Iterate over the overlayable policy chunks
+ std::string name;
+ util::ReadUtf16StringFromDevice(header->name, arraysize(header->name), &name);
+ std::string actor;
+ util::ReadUtf16StringFromDevice(header->actor, arraysize(header->actor), &actor);
+
+ // Iterate over the overlayable policy chunks contained within the overlayable chunk data
ChunkIterator overlayable_iter(child_chunk.data_ptr(), child_chunk.data_size());
while (overlayable_iter.HasNext()) {
const Chunk overlayable_child_chunk = overlayable_iter.Next();
@@ -613,7 +618,7 @@
return {};
}
- // Retrieve all the ids belonging to this policy
+ // Retrieve all the resource ids belonging to this policy chunk
std::unordered_set<uint32_t> ids;
const auto ids_begin =
reinterpret_cast<const ResTable_ref*>(overlayable_child_chunk.data_ptr());
@@ -622,8 +627,10 @@
ids.insert(dtohl(id_iter->ident));
}
- // Add the pairing of overlayable properties to resource ids to the package
+ // Add the pairing of overlayable properties and resource ids to the package
OverlayableInfo overlayable_info{};
+ overlayable_info.name = name;
+ overlayable_info.actor = actor;
overlayable_info.policy_flags = policy_header->policy_flags;
loaded_package->overlayable_infos_.push_back(std::make_pair(overlayable_info, ids));
break;
@@ -636,7 +643,7 @@
}
if (overlayable_iter.HadError()) {
- LOG(ERROR) << StringPrintf("Error parsing RES_TABLE_OVERLAYABLE_POLICY_TYPE: %s",
+ LOG(ERROR) << StringPrintf("Error parsing RES_TABLE_OVERLAYABLE_TYPE: %s",
overlayable_iter.GetLastError().c_str());
if (overlayable_iter.HadFatalError()) {
return {};
diff --git a/libs/androidfw/ResourceUtils.cpp b/libs/androidfw/ResourceUtils.cpp
index d63feb01..645984d 100644
--- a/libs/androidfw/ResourceUtils.cpp
+++ b/libs/androidfw/ResourceUtils.cpp
@@ -48,4 +48,65 @@
!(has_type_separator && out_type->empty());
}
+bool ToResourceName(StringPoolRef& type_string_ref,
+ StringPoolRef& entry_string_ref,
+ const LoadedPackage* package,
+ AssetManager2::ResourceName* out_name) {
+ out_name->package = package->GetPackageName().data();
+ out_name->package_len = package->GetPackageName().size();
+
+ out_name->type = type_string_ref.string8(&out_name->type_len);
+ out_name->type16 = nullptr;
+ if (out_name->type == nullptr) {
+ out_name->type16 = type_string_ref.string16(&out_name->type_len);
+ if (out_name->type16 == nullptr) {
+ return false;
+ }
+ }
+
+ out_name->entry = entry_string_ref.string8(&out_name->entry_len);
+ out_name->entry16 = nullptr;
+ if (out_name->entry == nullptr) {
+ out_name->entry16 = entry_string_ref.string16(&out_name->entry_len);
+ if (out_name->entry16 == nullptr) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+std::string ToFormattedResourceString(AssetManager2::ResourceName* resource_name) {
+ std::string result;
+ if (resource_name->package != nullptr) {
+ result.append(resource_name->package, resource_name->package_len);
+ }
+
+ if (resource_name->type != nullptr || resource_name->type16 != nullptr) {
+ if (!result.empty()) {
+ result += ":";
+ }
+
+ if (resource_name->type != nullptr) {
+ result.append(resource_name->type, resource_name->type_len);
+ } else {
+ result += util::Utf16ToUtf8(StringPiece16(resource_name->type16, resource_name->type_len));
+ }
+ }
+
+ if (resource_name->entry != nullptr || resource_name->entry16 != nullptr) {
+ if (!result.empty()) {
+ result += "/";
+ }
+
+ if (resource_name->entry != nullptr) {
+ result.append(resource_name->entry, resource_name->entry_len);
+ } else {
+ result += util::Utf16ToUtf8(StringPiece16(resource_name->entry16, resource_name->entry_len));
+ }
+ }
+
+ return result;
+}
+
} // namespace android
diff --git a/libs/androidfw/include/androidfw/AssetManager2.h b/libs/androidfw/include/androidfw/AssetManager2.h
index 0d49298..f29769b 100644
--- a/libs/androidfw/include/androidfw/AssetManager2.h
+++ b/libs/androidfw/include/androidfw/AssetManager2.h
@@ -229,6 +229,14 @@
ResTable_config* in_out_selected_config, uint32_t* in_out_flags,
uint32_t* out_last_reference) const;
+ // Enables or disables resource resolution logging. Clears stored steps when
+ // disabled.
+ void SetResourceResolutionLoggingEnabled(bool enabled);
+
+ // Returns formatted log of last resource resolution path, or empty if no
+ // resource has been resolved yet.
+ std::string GetLastResourceResolution() const;
+
// Retrieves the best matching bag/map resource with ID `resid`.
// This method will resolve all parent references for this bag and merge keys with the child.
// To iterate over the keys, use the following idiom:
@@ -346,6 +354,48 @@
// Cached set of bags. These are cached because they can inherit keys from parent bags,
// which involves some calculation.
std::unordered_map<uint32_t, util::unique_cptr<ResolvedBag>> cached_bags_;
+
+ // Whether or not to save resource resolution steps
+ bool resource_resolution_logging_enabled_ = false;
+
+ struct Resolution {
+
+ struct Step {
+
+ enum class Type {
+ INITIAL,
+ BETTER_MATCH,
+ OVERLAID
+ };
+
+ // Marks what kind of override this step was.
+ Type type;
+
+ // Built name of configuration for this step.
+ String8 config_name;
+
+ // Marks the package name of the better resource found in this step.
+ const std::string* package_name;
+ };
+
+ // Last resolved resource ID.
+ uint32_t resid;
+
+ // Last resolved resource result cookie.
+ ApkAssetsCookie cookie = kInvalidCookie;
+
+ // Last resolved resource type.
+ StringPoolRef type_string_ref;
+
+ // Last resolved resource entry.
+ StringPoolRef entry_string_ref;
+
+ // Steps taken to resolve last resource.
+ std::vector<Step> steps;
+ };
+
+ // Record of the last resolved resource's resolution path.
+ mutable Resolution last_resolution;
};
class Theme {
diff --git a/libs/androidfw/include/androidfw/LoadedArsc.h b/libs/androidfw/include/androidfw/LoadedArsc.h
index 8c5c3b7..be62f30 100644
--- a/libs/androidfw/include/androidfw/LoadedArsc.h
+++ b/libs/androidfw/include/androidfw/LoadedArsc.h
@@ -78,6 +78,8 @@
using TypeSpecPtr = util::unique_cptr<TypeSpec>;
struct OverlayableInfo {
+ std::string name;
+ std::string actor;
uint32_t policy_flags;
};
diff --git a/libs/androidfw/include/androidfw/ResourceTypes.h b/libs/androidfw/include/androidfw/ResourceTypes.h
index 9b05d1f..6b9ebd3 100644
--- a/libs/androidfw/include/androidfw/ResourceTypes.h
+++ b/libs/androidfw/include/androidfw/ResourceTypes.h
@@ -1611,6 +1611,12 @@
struct ResTable_overlayable_header
{
struct ResChunk_header header;
+
+ // The name of the overlayable set of resources that overlays target.
+ uint16_t name[256];
+
+ // The component responsible for enabling and disabling overlays targeting this chunk.
+ uint16_t actor[256];
};
/**
diff --git a/libs/androidfw/include/androidfw/ResourceUtils.h b/libs/androidfw/include/androidfw/ResourceUtils.h
index d94779b..eb6eb8e 100644
--- a/libs/androidfw/include/androidfw/ResourceUtils.h
+++ b/libs/androidfw/include/androidfw/ResourceUtils.h
@@ -17,6 +17,7 @@
#ifndef ANDROIDFW_RESOURCEUTILS_H
#define ANDROIDFW_RESOURCEUTILS_H
+#include "androidfw/AssetManager2.h"
#include "androidfw/StringPiece.h"
namespace android {
@@ -27,6 +28,17 @@
bool ExtractResourceName(const StringPiece& str, StringPiece* out_package, StringPiece* out_type,
StringPiece* out_entry);
+// Convert a type_string_ref, entry_string_ref, and package
+// to AssetManager2::ResourceName. Useful for getting
+// resource name without re-running AssetManager2::FindEntry searches.
+bool ToResourceName(StringPoolRef& type_string_ref,
+ StringPoolRef& entry_string_ref,
+ const LoadedPackage* package,
+ AssetManager2::ResourceName* out_name);
+
+// Formats a ResourceName to "package:type/entry_name".
+std::string ToFormattedResourceString(AssetManager2::ResourceName* resource_name);
+
inline uint32_t fix_package_id(uint32_t resid, uint8_t package_id) {
return (resid & 0x00ffffffu) | (static_cast<uint32_t>(package_id) << 24);
}
diff --git a/libs/androidfw/tests/AssetManager2_test.cpp b/libs/androidfw/tests/AssetManager2_test.cpp
index 5449a54..105dcd2 100644
--- a/libs/androidfw/tests/AssetManager2_test.cpp
+++ b/libs/androidfw/tests/AssetManager2_test.cpp
@@ -586,4 +586,111 @@
EXPECT_THAT(asset_dir->getFileType(2), Eq(FileType::kFileTypeDirectory));
}
+TEST_F(AssetManager2Test, GetLastPathWithoutEnablingReturnsEmpty) {
+ ResTable_config desired_config;
+
+ AssetManager2 assetmanager;
+ assetmanager.SetConfiguration(desired_config);
+ assetmanager.SetApkAssets({basic_assets_.get()});
+ assetmanager.SetResourceResolutionLoggingEnabled(false);
+
+ Res_value value;
+ ResTable_config selected_config;
+ uint32_t flags;
+
+ ApkAssetsCookie cookie =
+ assetmanager.GetResource(basic::R::string::test1, false /*may_be_bag*/,
+ 0 /*density_override*/, &value, &selected_config, &flags);
+ ASSERT_NE(kInvalidCookie, cookie);
+
+ auto result = assetmanager.GetLastResourceResolution();
+ EXPECT_EQ("", result);
+}
+
+TEST_F(AssetManager2Test, GetLastPathWithoutResolutionReturnsEmpty) {
+ ResTable_config desired_config;
+
+ AssetManager2 assetmanager;
+ assetmanager.SetConfiguration(desired_config);
+ assetmanager.SetApkAssets({basic_assets_.get()});
+
+ auto result = assetmanager.GetLastResourceResolution();
+ EXPECT_EQ("", result);
+}
+
+TEST_F(AssetManager2Test, GetLastPathWithSingleApkAssets) {
+ ResTable_config desired_config;
+ memset(&desired_config, 0, sizeof(desired_config));
+ desired_config.language[0] = 'd';
+ desired_config.language[1] = 'e';
+
+ AssetManager2 assetmanager;
+ assetmanager.SetResourceResolutionLoggingEnabled(true);
+ assetmanager.SetConfiguration(desired_config);
+ assetmanager.SetApkAssets({basic_assets_.get()});
+
+ Res_value value;
+ ResTable_config selected_config;
+ uint32_t flags;
+
+ ApkAssetsCookie cookie =
+ assetmanager.GetResource(basic::R::string::test1, false /*may_be_bag*/,
+ 0 /*density_override*/, &value, &selected_config, &flags);
+ ASSERT_NE(kInvalidCookie, cookie);
+
+ auto result = assetmanager.GetLastResourceResolution();
+ EXPECT_EQ("Resolution for 0x7f030000 com.android.basic:string/test1\n\tFor config -de\n\tFound initial: com.android.basic", result);
+}
+
+TEST_F(AssetManager2Test, GetLastPathWithMultipleApkAssets) {
+ ResTable_config desired_config;
+ memset(&desired_config, 0, sizeof(desired_config));
+ desired_config.language[0] = 'd';
+ desired_config.language[1] = 'e';
+
+ AssetManager2 assetmanager;
+ assetmanager.SetResourceResolutionLoggingEnabled(true);
+ assetmanager.SetConfiguration(desired_config);
+ assetmanager.SetApkAssets({basic_assets_.get(), basic_de_fr_assets_.get()});
+
+ Res_value value = Res_value();
+ ResTable_config selected_config;
+ uint32_t flags;
+
+ ApkAssetsCookie cookie =
+ assetmanager.GetResource(basic::R::string::test1, false /*may_be_bag*/,
+ 0 /*density_override*/, &value, &selected_config, &flags);
+ ASSERT_NE(kInvalidCookie, cookie);
+
+ auto result = assetmanager.GetLastResourceResolution();
+ EXPECT_EQ("Resolution for 0x7f030000 com.android.basic:string/test1\n\tFor config -de\n\tFound initial: com.android.basic\n\tFound better: com.android.basic -de", result);
+}
+
+TEST_F(AssetManager2Test, GetLastPathAfterDisablingReturnsEmpty) {
+ ResTable_config desired_config;
+ memset(&desired_config, 0, sizeof(desired_config));
+
+ AssetManager2 assetmanager;
+ assetmanager.SetResourceResolutionLoggingEnabled(true);
+ assetmanager.SetConfiguration(desired_config);
+ assetmanager.SetApkAssets({basic_assets_.get()});
+
+ Res_value value = Res_value();
+ ResTable_config selected_config;
+ uint32_t flags;
+
+ ApkAssetsCookie cookie =
+ assetmanager.GetResource(basic::R::string::test1, false /*may_be_bag*/,
+ 0 /*density_override*/, &value, &selected_config, &flags);
+ ASSERT_NE(kInvalidCookie, cookie);
+
+ auto resultEnabled = assetmanager.GetLastResourceResolution();
+ ASSERT_NE("", resultEnabled);
+
+ assetmanager.SetResourceResolutionLoggingEnabled(false);
+
+ auto resultDisabled = assetmanager.GetLastResourceResolution();
+ EXPECT_EQ("", resultDisabled);
+}
+
} // namespace android
diff --git a/libs/androidfw/tests/LoadedArsc_test.cpp b/libs/androidfw/tests/LoadedArsc_test.cpp
index 22d587a..2e386a0 100644
--- a/libs/androidfw/tests/LoadedArsc_test.cpp
+++ b/libs/androidfw/tests/LoadedArsc_test.cpp
@@ -294,22 +294,30 @@
info = package->GetOverlayableInfo(overlayable::R::string::overlayable1);
ASSERT_THAT(info, NotNull());
+ EXPECT_THAT(info->name, Eq("OverlayableResources1"));
+ EXPECT_THAT(info->actor, Eq("overlay://theme"));
EXPECT_THAT(info->policy_flags, Eq(ResTable_overlayable_policy_header::POLICY_PUBLIC));
info = package->GetOverlayableInfo(overlayable::R::string::overlayable2);
ASSERT_THAT(info, NotNull());
+ EXPECT_THAT(info->name, Eq("OverlayableResources1"));
+ EXPECT_THAT(info->actor, Eq("overlay://theme"));
EXPECT_THAT(info->policy_flags,
Eq(ResTable_overlayable_policy_header::POLICY_SYSTEM_PARTITION
| ResTable_overlayable_policy_header::POLICY_PRODUCT_PARTITION));
info = package->GetOverlayableInfo(overlayable::R::string::overlayable3);
ASSERT_THAT(info, NotNull());
+ EXPECT_THAT(info->name, Eq("OverlayableResources2"));
+ EXPECT_THAT(info->actor, Eq("overlay://com.android.overlayable"));
EXPECT_THAT(info->policy_flags,
Eq(ResTable_overlayable_policy_header::POLICY_VENDOR_PARTITION
| ResTable_overlayable_policy_header::POLICY_PRODUCT_SERVICES_PARTITION
| ResTable_overlayable_policy_header::POLICY_PRODUCT_PARTITION));
info = package->GetOverlayableInfo(overlayable::R::string::overlayable4);
+ EXPECT_THAT(info->name, Eq("OverlayableResources1"));
+ EXPECT_THAT(info->actor, Eq("overlay://theme"));
ASSERT_THAT(info, NotNull());
EXPECT_THAT(info->policy_flags, Eq(ResTable_overlayable_policy_header::POLICY_PUBLIC));
}
diff --git a/libs/androidfw/tests/data/overlayable/overlayable.apk b/libs/androidfw/tests/data/overlayable/overlayable.apk
index 85ab4be..8634747 100644
--- a/libs/androidfw/tests/data/overlayable/overlayable.apk
+++ b/libs/androidfw/tests/data/overlayable/overlayable.apk
Binary files differ
diff --git a/libs/androidfw/tests/data/overlayable/res/values/overlayable.xml b/libs/androidfw/tests/data/overlayable/res/values/overlayable.xml
index 11aa735..dba7b08 100644
--- a/libs/androidfw/tests/data/overlayable/res/values/overlayable.xml
+++ b/libs/androidfw/tests/data/overlayable/res/values/overlayable.xml
@@ -15,7 +15,7 @@
-->
<resources>
-<overlayable>
+<overlayable name="OverlayableResources1" actor="overlay://theme">
<!-- Any overlay can overlay the value of @string/overlayable1 -->
<item type="string" name="overlayable1" />
@@ -31,9 +31,9 @@
</policy>
</overlayable>
-<overlayable>
+<overlayable name="OverlayableResources2" actor="overlay://com.android.overlayable">
<!-- Any overlay on the product_services, vendor, or product partition can overlay the value of
- @string/overlayable3 -->
+ @string/overlayable3 -->
<policy type="product_services|vendor|product">
<item type="string" name="overlayable3" />
</policy>
diff --git a/libs/hwui/DeviceInfo.cpp b/libs/hwui/DeviceInfo.cpp
index ed167e5..56b1885 100644
--- a/libs/hwui/DeviceInfo.cpp
+++ b/libs/hwui/DeviceInfo.cpp
@@ -79,8 +79,7 @@
switch (wcgDataspace) {
case ui::Dataspace::DISPLAY_P3:
*colorGamut = SkColorSpace::Gamut::kDCIP3_D65_Gamut;
- *colorSpace = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
- SkColorSpace::Gamut::kDCIP3_D65_Gamut);
+ *colorSpace = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
break;
case ui::Dataspace::V0_SCRGB:
*colorGamut = SkColorSpace::Gamut::kSRGB_Gamut;
diff --git a/libs/hwui/WebViewFunctorManager.cpp b/libs/hwui/WebViewFunctorManager.cpp
index 9170d6d..68541b4 100644
--- a/libs/hwui/WebViewFunctorManager.cpp
+++ b/libs/hwui/WebViewFunctorManager.cpp
@@ -86,6 +86,26 @@
mCallbacks.gles.draw(mFunctor, mData, drawInfo);
}
+void WebViewFunctor::initVk(const VkFunctorInitParams& params) {
+ ATRACE_NAME("WebViewFunctor::initVk");
+ if (!mHasContext) {
+ mHasContext = true;
+ } else {
+ return;
+ }
+ mCallbacks.vk.initialize(mFunctor, mData, params);
+}
+
+void WebViewFunctor::drawVk(const VkFunctorDrawParams& params) {
+ ATRACE_NAME("WebViewFunctor::drawVk");
+ mCallbacks.vk.draw(mFunctor, mData, params);
+}
+
+void WebViewFunctor::postDrawVk() {
+ ATRACE_NAME("WebViewFunctor::postDrawVk");
+ mCallbacks.vk.postDraw(mFunctor, mData);
+}
+
void WebViewFunctor::destroyContext() {
if (mHasContext) {
mHasContext = false;
diff --git a/libs/hwui/WebViewFunctorManager.h b/libs/hwui/WebViewFunctorManager.h
index 1719ce7..2846cb1 100644
--- a/libs/hwui/WebViewFunctorManager.h
+++ b/libs/hwui/WebViewFunctorManager.h
@@ -42,6 +42,12 @@
void drawGl(const DrawGlInfo& drawInfo) const { mReference.drawGl(drawInfo); }
+ void initVk(const VkFunctorInitParams& params) { mReference.initVk(params); }
+
+ void drawVk(const VkFunctorDrawParams& params) { mReference.drawVk(params); }
+
+ void postDrawVk() { mReference.postDrawVk(); }
+
private:
friend class WebViewFunctor;
@@ -53,6 +59,9 @@
int id() const { return mFunctor; }
void sync(const WebViewSyncData& syncData) const;
void drawGl(const DrawGlInfo& drawInfo);
+ void initVk(const VkFunctorInitParams& params);
+ void drawVk(const VkFunctorDrawParams& params);
+ void postDrawVk();
void destroyContext();
sp<Handle> createHandle() {
diff --git a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp
index 6eefed9..d54275f 100644
--- a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp
+++ b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp
@@ -125,8 +125,6 @@
uirenderer::GlFunctorLifecycleListener* listener) {
FunctorDrawable* functorDrawable;
if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaVulkan) {
- // TODO(cblume) use VkFunctorDrawable instead of VkInteropFunctorDrawable here when the
- // interop is disabled/moved.
functorDrawable = mDisplayList->allocateDrawable<VkInteropFunctorDrawable>(
functor, listener, asSkCanvas());
} else {
diff --git a/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp b/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp
index 156f74a..2f8d381 100644
--- a/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp
+++ b/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp
@@ -17,6 +17,8 @@
#include "VkFunctorDrawable.h"
#include <private/hwui/DrawVkInfo.h>
+#include "renderthread/VulkanManager.h"
+#include "renderthread/RenderThread.h"
#include <GrBackendDrawableInfo.h>
#include <SkImage.h>
#include <utils/Color.h>
@@ -31,34 +33,58 @@
namespace uirenderer {
namespace skiapipeline {
-VkFunctorDrawHandler::VkFunctorDrawHandler(Functor* functor) : INHERITED(), mFunctor(functor) {}
+VkFunctorDrawHandler::VkFunctorDrawHandler(sp<WebViewFunctor::Handle> functor_handle,
+ const SkMatrix& matrix, const SkIRect& clip,
+ const SkImageInfo& image_info)
+ : INHERITED()
+ , mFunctorHandle(functor_handle)
+ , mMatrix(matrix)
+ , mClip(clip)
+ , mImageInfo(image_info) {}
VkFunctorDrawHandler::~VkFunctorDrawHandler() {
- // TODO(cblume) Fill in the DrawVkInfo parameters.
- (*mFunctor)(DrawVkInfo::kModePostComposite, nullptr);
+ mFunctorHandle->postDrawVk();
}
void VkFunctorDrawHandler::draw(const GrBackendDrawableInfo& info) {
ATRACE_CALL();
+ if (!renderthread::RenderThread::isCurrent())
+ LOG_ALWAYS_FATAL("VkFunctorDrawHandler::draw not called on render thread");
GrVkDrawableInfo vulkan_info;
if (!info.getVkDrawableInfo(&vulkan_info)) {
return;
}
+ renderthread::VulkanManager& vk_manager =
+ renderthread::RenderThread::getInstance().vulkanManager();
+ mFunctorHandle->initVk(vk_manager.getVkFunctorInitParams());
- DrawVkInfo draw_vk_info;
- // TODO(cblume) Fill in the rest of the parameters and test the actual call.
- draw_vk_info.isLayer = true;
+ SkMatrix44 mat4(mMatrix);
+ VkFunctorDrawParams params{
+ .width = mImageInfo.width(),
+ .height = mImageInfo.height(),
+ .is_layer = false, // TODO(boliu): Populate is_layer.
+ .color_space_ptr = mImageInfo.colorSpace(),
+ .clip_left = mClip.fLeft,
+ .clip_top = mClip.fTop,
+ .clip_right = mClip.fRight,
+ .clip_bottom = mClip.fBottom,
+ };
+ mat4.asColMajorf(¶ms.transform[0]);
+ params.secondary_command_buffer = vulkan_info.fSecondaryCommandBuffer;
+ params.color_attachment_index = vulkan_info.fColorAttachmentIndex;
+ params.compatible_render_pass = vulkan_info.fCompatibleRenderPass;
+ params.format = vulkan_info.fFormat;
- (*mFunctor)(DrawVkInfo::kModeComposite, &draw_vk_info);
+ mFunctorHandle->drawVk(params);
+
+ vulkan_info.fDrawBounds->offset.x = mClip.fLeft;
+ vulkan_info.fDrawBounds->offset.y = mClip.fTop;
+ vulkan_info.fDrawBounds->extent.width = mClip.fRight - mClip.fLeft;
+ vulkan_info.fDrawBounds->extent.height = mClip.fBottom - mClip.fTop;
}
VkFunctorDrawable::~VkFunctorDrawable() {
- if (auto lp = std::get_if<LegacyFunctor>(&mAnyFunctor)) {
- if (lp->listener) {
- lp->listener->onGlFunctorReleased(lp->functor);
- }
- }
}
void VkFunctorDrawable::onDraw(SkCanvas* /*canvas*/) {
@@ -67,16 +93,17 @@
}
std::unique_ptr<FunctorDrawable::GpuDrawHandler> VkFunctorDrawable::onSnapGpuDrawHandler(
- GrBackendApi backendApi, const SkMatrix& matrix) {
+ GrBackendApi backendApi, const SkMatrix& matrix, const SkIRect& clip,
+ const SkImageInfo& image_info) {
if (backendApi != GrBackendApi::kVulkan) {
return nullptr;
}
std::unique_ptr<VkFunctorDrawHandler> draw;
if (mAnyFunctor.index() == 0) {
- LOG_ALWAYS_FATAL("Not implemented");
- return nullptr;
+ return std::make_unique<VkFunctorDrawHandler>(std::get<0>(mAnyFunctor).handle, matrix, clip,
+ image_info);
} else {
- return std::make_unique<VkFunctorDrawHandler>(std::get<1>(mAnyFunctor).functor);
+ LOG_ALWAYS_FATAL("Not implemented");
}
}
diff --git a/libs/hwui/pipeline/skia/VkFunctorDrawable.h b/libs/hwui/pipeline/skia/VkFunctorDrawable.h
index d6fefc1..1a53c8f 100644
--- a/libs/hwui/pipeline/skia/VkFunctorDrawable.h
+++ b/libs/hwui/pipeline/skia/VkFunctorDrawable.h
@@ -32,15 +32,18 @@
*/
class VkFunctorDrawHandler : public FunctorDrawable::GpuDrawHandler {
public:
- explicit VkFunctorDrawHandler(Functor* functor);
+ VkFunctorDrawHandler(sp<WebViewFunctor::Handle> functor_handle, const SkMatrix& matrix,
+ const SkIRect& clip, const SkImageInfo& image_info);
~VkFunctorDrawHandler() override;
void draw(const GrBackendDrawableInfo& info) override;
private:
typedef GpuDrawHandler INHERITED;
-
- Functor* mFunctor;
+ sp<WebViewFunctor::Handle> mFunctorHandle;
+ const SkMatrix mMatrix;
+ const SkIRect mClip;
+ const SkImageInfo mImageInfo;
};
/**
@@ -57,7 +60,8 @@
// SkDrawable functions:
void onDraw(SkCanvas* canvas) override;
std::unique_ptr<FunctorDrawable::GpuDrawHandler> onSnapGpuDrawHandler(
- GrBackendApi backendApi, const SkMatrix& matrix) override;
+ GrBackendApi backendApi, const SkMatrix& matrix, const SkIRect& clip,
+ const SkImageInfo& image_info) override;
};
} // namespace skiapipeline
diff --git a/libs/hwui/private/hwui/DrawVkInfo.h b/libs/hwui/private/hwui/DrawVkInfo.h
index fd824bd..abc4dbf 100644
--- a/libs/hwui/private/hwui/DrawVkInfo.h
+++ b/libs/hwui/private/hwui/DrawVkInfo.h
@@ -17,80 +17,61 @@
#ifndef ANDROID_HWUI_DRAW_VK_INFO_H
#define ANDROID_HWUI_DRAW_VK_INFO_H
+#include <SkColorSpace.h>
#include <vulkan/vulkan.h>
namespace android {
namespace uirenderer {
-/**
- * Structure used by VulkanRenderer::callDrawVKFunction() to pass and receive data from Vulkan
- * functors.
- */
-struct DrawVkInfo {
- // Input: current width/height of destination surface
- int width;
- int height;
+struct VkFunctorInitParams {
+ VkInstance instance;
+ VkPhysicalDevice physical_device;
+ VkDevice device;
+ VkQueue queue;
+ uint32_t graphics_queue_index;
+ uint32_t instance_version;
+ const char* const* enabled_instance_extension_names;
+ uint32_t enabled_instance_extension_names_length;
+ const char* const* enabled_device_extension_names;
+ uint32_t enabled_device_extension_names_length;
+ const VkPhysicalDeviceFeatures2* device_features_2;
+};
- // Input: is the render target an FBO
- bool isLayer;
+struct VkFunctorDrawParams {
+ // Input: current width/height of destination surface.
+ int width;
+ int height;
- // Input: current transform matrix, in OpenGL format
- float transform[16];
+ // Input: is the render target a FBO
+ bool is_layer;
- // Input: WebView should do its main compositing draws into this. It cannot do anything that
- // would require stopping the render pass.
- VkCommandBuffer secondaryCommandBuffer;
+ // Input: current transform matrix
+ float transform[16];
- // Input: The main color attachment index where secondaryCommandBuffer will eventually be
- // submitted.
- uint32_t colorAttachmentIndex;
+ // Input WebView should do its main compositing draws into this. It cannot do
+ // anything that would require stopping the render pass.
+ VkCommandBuffer secondary_command_buffer;
- // Input: A render pass which will be compatible to the one which the secondaryCommandBuffer
- // will be submitted into.
- VkRenderPass compatibleRenderPass;
+ // Input: The main color attachment index where secondary_command_buffer will
+ // eventually be submitted.
+ uint32_t color_attachment_index;
- // Input: Format of the destination surface.
- VkFormat format;
+ // Input: A render pass which will be compatible to the one which the
+ // secondary_command_buffer will be submitted into.
+ VkRenderPass compatible_render_pass;
- // Input: Color space
- const SkColorSpace* colorSpaceInfo;
+ // Input: Format of the destination surface.
+ VkFormat format;
- // Input: current clip rect
- int clipLeft;
- int clipTop;
- int clipRight;
- int clipBottom;
+ // Input: Color space.
+ const SkColorSpace* color_space_ptr;
- /**
- * Values used as the "what" parameter of the functor.
- */
- enum Mode {
- // Called once at WebView start
- kModeInit,
- // Called when things need to be re-created
- kModeReInit,
- // Notifies the app that the composite functor will be called soon. This allows WebView to
- // begin work early.
- kModePreComposite,
- // Do the actual composite work
- kModeComposite,
- // This allows WebView to begin using the previously submitted objects in future work.
- kModePostComposite,
- // Invoked every time the UI thread pushes over a frame to the render thread and the owning
- // view has a dirty display list*. This is a signal to sync any data that needs to be
- // shared between the UI thread and the render thread. During this time the UI thread is
- // blocked.
- kModeSync
- };
-
- /**
- * Values used by Vulkan functors to tell the framework what to do next.
- */
- enum Status {
- // The functor is done
- kStatusDone = 0x0,
- };
-}; // struct DrawVkInfo
+ // Input: current clip rect
+ int clip_left;
+ int clip_top;
+ int clip_right;
+ int clip_bottom;
+};
} // namespace uirenderer
} // namespace android
diff --git a/libs/hwui/private/hwui/WebViewFunctor.h b/libs/hwui/private/hwui/WebViewFunctor.h
index da3d06a..96da947 100644
--- a/libs/hwui/private/hwui/WebViewFunctor.h
+++ b/libs/hwui/private/hwui/WebViewFunctor.h
@@ -19,6 +19,7 @@
#include <cutils/compiler.h>
#include <private/hwui/DrawGlInfo.h>
+#include <private/hwui/DrawVkInfo.h>
namespace android::uirenderer {
@@ -52,18 +53,12 @@
// Called on RenderThread. initialize is guaranteed to happen before this call
void (*draw)(int functor, void* data, const DrawGlInfo& params);
} gles;
- // TODO: VK support. The current DrawVkInfo is monolithic and needs to be split up for
- // what params are valid on what callbacks
struct {
// Called either the first time the functor is used or the first time it's used after
// a call to onContextDestroyed.
- // void (*initialize)(int functor, const InitParams& params);
- // void (*frameStart)(int functor, /* todo: what params are actually needed for this to
- // be useful? Is this useful? */)
- // void (*draw)(int functor, const CompositeParams& params /* todo: rename - composite
- // almost always means something else, and we aren't compositing */);
- // void (*frameEnd)(int functor, const PostCompositeParams& params /* todo: same as
- // CompositeParams - rename */);
+ void (*initialize)(int functor, void* data, const VkFunctorInitParams& params);
+ void (*draw)(int functor, void* data, const VkFunctorDrawParams& params);
+ void (*postDraw)(int functor, void*);
} vk;
};
};
diff --git a/libs/hwui/renderthread/RenderThread.cpp b/libs/hwui/renderthread/RenderThread.cpp
index c06fadd..8bef359 100644
--- a/libs/hwui/renderthread/RenderThread.cpp
+++ b/libs/hwui/renderthread/RenderThread.cpp
@@ -171,6 +171,9 @@
mRenderState = new RenderState(*this);
mVkManager = new VulkanManager(*this);
mCacheManager = new CacheManager(mDisplayInfo);
+ if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaVulkan) {
+ mVkManager->initialize();
+ }
}
void RenderThread::requireGlContext() {
diff --git a/libs/hwui/renderthread/RenderThread.h b/libs/hwui/renderthread/RenderThread.h
index 5272227..1ef83fb 100644
--- a/libs/hwui/renderthread/RenderThread.h
+++ b/libs/hwui/renderthread/RenderThread.h
@@ -47,6 +47,10 @@
class RenderState;
class TestUtils;
+namespace skiapipeline {
+class VkFunctorDrawHandler;
+}
+
namespace renderthread {
class CanvasContext;
@@ -124,6 +128,7 @@
friend class DummyVsyncSource;
friend class android::uirenderer::TestUtils;
friend class android::uirenderer::WebViewFunctor;
+ friend class android::uirenderer::skiapipeline::VkFunctorDrawHandler;
RenderThread();
virtual ~RenderThread();
diff --git a/libs/hwui/renderthread/VulkanManager.cpp b/libs/hwui/renderthread/VulkanManager.cpp
index aa7a141..6c540f6 100644
--- a/libs/hwui/renderthread/VulkanManager.cpp
+++ b/libs/hwui/renderthread/VulkanManager.cpp
@@ -34,6 +34,23 @@
namespace uirenderer {
namespace renderthread {
+static void free_features_extensions_structs(const VkPhysicalDeviceFeatures2& features) {
+ // All Vulkan structs that could be part of the features chain will start with the
+ // structure type followed by the pNext pointer. We cast to the CommonVulkanHeader
+ // so we can get access to the pNext for the next struct.
+ struct CommonVulkanHeader {
+ VkStructureType sType;
+ void* pNext;
+ };
+
+ void* pNext = features.pNext;
+ while (pNext) {
+ void* current = pNext;
+ pNext = static_cast<CommonVulkanHeader*>(current)->pNext;
+ free(current);
+ }
+}
+
#define GET_PROC(F) m##F = (PFN_vk##F)vkGetInstanceProcAddr(VK_NULL_HANDLE, "vk" #F)
#define GET_INST_PROC(F) m##F = (PFN_vk##F)vkGetInstanceProcAddr(mInstance, "vk" #F)
#define GET_DEV_PROC(F) m##F = (PFN_vk##F)vkGetDeviceProcAddr(mDevice, "vk" #F)
@@ -66,6 +83,11 @@
mDevice = VK_NULL_HANDLE;
mPhysicalDevice = VK_NULL_HANDLE;
mInstance = VK_NULL_HANDLE;
+ mInstanceVersion = 0u;
+ mInstanceExtensions.clear();
+ mDeviceExtensions.clear();
+ free_features_extensions_structs(mPhysicalDeviceFeatures2);
+ mPhysicalDeviceFeatures2 = {};
}
bool VulkanManager::setupDevice(GrVkExtensions& grExtensions, VkPhysicalDeviceFeatures2& features) {
@@ -81,7 +103,6 @@
VK_MAKE_VERSION(1, 1, 0), // apiVersion
};
- std::vector<const char*> instanceExtensions;
{
GET_PROC(EnumerateInstanceExtensionProperties);
@@ -99,7 +120,7 @@
bool hasKHRSurfaceExtension = false;
bool hasKHRAndroidSurfaceExtension = false;
for (uint32_t i = 0; i < extensionCount; ++i) {
- instanceExtensions.push_back(extensions[i].extensionName);
+ mInstanceExtensions.push_back(extensions[i].extensionName);
if (!strcmp(extensions[i].extensionName, VK_KHR_SURFACE_EXTENSION_NAME)) {
hasKHRSurfaceExtension = true;
}
@@ -120,8 +141,8 @@
&app_info, // pApplicationInfo
0, // enabledLayerNameCount
nullptr, // ppEnabledLayerNames
- (uint32_t) instanceExtensions.size(), // enabledExtensionNameCount
- instanceExtensions.data(), // ppEnabledExtensionNames
+ (uint32_t) mInstanceExtensions.size(), // enabledExtensionNameCount
+ mInstanceExtensions.data(), // ppEnabledExtensionNames
};
GET_PROC(CreateInstance);
@@ -201,7 +222,6 @@
// presentation with any native window. So just use the first one.
mPresentQueueIndex = 0;
- std::vector<const char*> deviceExtensions;
{
uint32_t extensionCount = 0;
err = mEnumerateDeviceExtensionProperties(mPhysicalDevice, nullptr, &extensionCount,
@@ -220,7 +240,7 @@
}
bool hasKHRSwapchainExtension = false;
for (uint32_t i = 0; i < extensionCount; ++i) {
- deviceExtensions.push_back(extensions[i].extensionName);
+ mDeviceExtensions.push_back(extensions[i].extensionName);
if (!strcmp(extensions[i].extensionName, VK_KHR_SWAPCHAIN_EXTENSION_NAME)) {
hasKHRSwapchainExtension = true;
}
@@ -237,8 +257,8 @@
}
return vkGetInstanceProcAddr(instance, proc_name);
};
- grExtensions.init(getProc, mInstance, mPhysicalDevice, instanceExtensions.size(),
- instanceExtensions.data(), deviceExtensions.size(), deviceExtensions.data());
+ grExtensions.init(getProc, mInstance, mPhysicalDevice, mInstanceExtensions.size(),
+ mInstanceExtensions.data(), mDeviceExtensions.size(), mDeviceExtensions.data());
if (!grExtensions.hasExtension(VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME, 1)) {
this->destroy();
@@ -308,8 +328,8 @@
queueInfo, // pQueueCreateInfos
0, // layerCount
nullptr, // ppEnabledLayerNames
- (uint32_t) deviceExtensions.size(), // extensionCount
- deviceExtensions.data(), // ppEnabledExtensionNames
+ (uint32_t) mDeviceExtensions.size(), // extensionCount
+ mDeviceExtensions.data(), // ppEnabledExtensionNames
nullptr, // ppEnabledFeatures
};
@@ -351,36 +371,17 @@
return true;
}
-static void free_features_extensions_structs(const VkPhysicalDeviceFeatures2& features) {
- // All Vulkan structs that could be part of the features chain will start with the
- // structure type followed by the pNext pointer. We cast to the CommonVulkanHeader
- // so we can get access to the pNext for the next struct.
- struct CommonVulkanHeader {
- VkStructureType sType;
- void* pNext;
- };
-
- void* pNext = features.pNext;
- while (pNext) {
- void* current = pNext;
- pNext = static_cast<CommonVulkanHeader*>(current)->pNext;
- free(current);
- }
-}
-
void VulkanManager::initialize() {
if (mDevice != VK_NULL_HANDLE) {
return;
}
GET_PROC(EnumerateInstanceVersion);
- uint32_t instanceVersion = 0;
- LOG_ALWAYS_FATAL_IF(mEnumerateInstanceVersion(&instanceVersion));
- LOG_ALWAYS_FATAL_IF(instanceVersion < VK_MAKE_VERSION(1, 1, 0));
+ LOG_ALWAYS_FATAL_IF(mEnumerateInstanceVersion(&mInstanceVersion));
+ LOG_ALWAYS_FATAL_IF(mInstanceVersion < VK_MAKE_VERSION(1, 1, 0));
GrVkExtensions extensions;
- VkPhysicalDeviceFeatures2 features;
- LOG_ALWAYS_FATAL_IF(!this->setupDevice(extensions, features));
+ LOG_ALWAYS_FATAL_IF(!this->setupDevice(extensions, mPhysicalDeviceFeatures2));
mGetDeviceQueue(mDevice, mGraphicsQueueIndex, 0, &mGraphicsQueue);
@@ -397,9 +398,9 @@
backendContext.fDevice = mDevice;
backendContext.fQueue = mGraphicsQueue;
backendContext.fGraphicsQueueIndex = mGraphicsQueueIndex;
- backendContext.fInstanceVersion = instanceVersion;
+ backendContext.fInstanceVersion = mInstanceVersion;
backendContext.fVkExtensions = &extensions;
- backendContext.fDeviceFeatures2 = &features;
+ backendContext.fDeviceFeatures2 = &mPhysicalDeviceFeatures2;
backendContext.fGetProc = std::move(getProc);
// create the command pool for the command buffers
@@ -433,13 +434,29 @@
LOG_ALWAYS_FATAL_IF(!grContext.get());
mRenderThread.setGrContext(grContext);
- free_features_extensions_structs(features);
-
if (Properties::enablePartialUpdates && Properties::useBufferAge) {
mSwapBehavior = SwapBehavior::BufferAge;
}
}
+VkFunctorInitParams VulkanManager::getVkFunctorInitParams() const {
+ return VkFunctorInitParams{
+ .instance = mInstance,
+ .physical_device = mPhysicalDevice,
+ .device = mDevice,
+ .queue = mGraphicsQueue,
+ .graphics_queue_index = mGraphicsQueueIndex,
+ .instance_version = mInstanceVersion,
+ .enabled_instance_extension_names = mInstanceExtensions.data(),
+ .enabled_instance_extension_names_length =
+ static_cast<uint32_t>(mInstanceExtensions.size()),
+ .enabled_device_extension_names = mDeviceExtensions.data(),
+ .enabled_device_extension_names_length =
+ static_cast<uint32_t>(mDeviceExtensions.size()),
+ .device_features_2 = &mPhysicalDeviceFeatures2,
+ };
+}
+
// Returns the next BackbufferInfo to use for the next draw. The function will make sure all
// previous uses have finished before returning.
VulkanSurface::BackbufferInfo* VulkanManager::getAvailableBackbuffer(VulkanSurface* surface) {
diff --git a/libs/hwui/renderthread/VulkanManager.h b/libs/hwui/renderthread/VulkanManager.h
index 9eb942c..105ee09 100644
--- a/libs/hwui/renderthread/VulkanManager.h
+++ b/libs/hwui/renderthread/VulkanManager.h
@@ -132,6 +132,9 @@
// Creates a fence that is signaled, when all the pending Vulkan commands are flushed.
status_t createReleaseFence(sp<Fence>& nativeFence);
+ // Returned pointers are owned by VulkanManager.
+ VkFunctorInitParams getVkFunctorInitParams() const;
+
private:
friend class RenderThread;
@@ -234,6 +237,12 @@
VkCommandBuffer mDummyCB = VK_NULL_HANDLE;
+ // Variables saved to populate VkFunctorInitParams.
+ uint32_t mInstanceVersion = 0u;
+ std::vector<const char*> mInstanceExtensions;
+ std::vector<const char*> mDeviceExtensions;
+ VkPhysicalDeviceFeatures2 mPhysicalDeviceFeatures2{};
+
enum class SwapBehavior {
Discard,
BufferAge,
diff --git a/libs/hwui/tests/unit/SkiaCanvasTests.cpp b/libs/hwui/tests/unit/SkiaCanvasTests.cpp
index f3a7648..f6178af 100644
--- a/libs/hwui/tests/unit/SkiaCanvasTests.cpp
+++ b/libs/hwui/tests/unit/SkiaCanvasTests.cpp
@@ -44,8 +44,8 @@
}
TEST(SkiaCanvas, colorSpaceXform) {
- sk_sp<SkColorSpace> adobe = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
- SkColorSpace::kAdobeRGB_Gamut);
+ sk_sp<SkColorSpace> adobe = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB,
+ SkNamedGamut::kAdobeRGB);
SkImageInfo adobeInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kOpaque_SkAlphaType, adobe);
sk_sp<Bitmap> adobeBitmap = Bitmap::allocateHeapBitmap(adobeInfo);
diff --git a/libs/hwui/utils/Color.cpp b/libs/hwui/utils/Color.cpp
index dc347f6..4415a59 100644
--- a/libs/hwui/utils/Color.cpp
+++ b/libs/hwui/utils/Color.cpp
@@ -25,38 +25,6 @@
namespace android {
namespace uirenderer {
-static inline bool almostEqual(float a, float b) {
- return std::abs(a - b) < 1e-2f;
-}
-
-bool transferFunctionCloseToSRGB(const SkColorSpace* colorSpace) {
- if (colorSpace == nullptr) return true;
- if (colorSpace->isSRGB()) return true;
-
- SkColorSpaceTransferFn transferFunction;
- if (colorSpace->isNumericalTransferFn(&transferFunction)) {
- // sRGB transfer function params:
- const float sRGBParamA = 1 / 1.055f;
- const float sRGBParamB = 0.055f / 1.055f;
- const float sRGBParamC = 1 / 12.92f;
- const float sRGBParamD = 0.04045f;
- const float sRGBParamE = 0.0f;
- const float sRGBParamF = 0.0f;
- const float sRGBParamG = 2.4f;
-
- // This comparison will catch Display P3
- return almostEqual(sRGBParamA, transferFunction.fA) &&
- almostEqual(sRGBParamB, transferFunction.fB) &&
- almostEqual(sRGBParamC, transferFunction.fC) &&
- almostEqual(sRGBParamD, transferFunction.fD) &&
- almostEqual(sRGBParamE, transferFunction.fE) &&
- almostEqual(sRGBParamF, transferFunction.fF) &&
- almostEqual(sRGBParamG, transferFunction.fG);
- }
-
- return false;
-}
-
android::PixelFormat ColorTypeToPixelFormat(SkColorType colorType) {
switch (colorType) {
case kRGBA_8888_SkColorType:
@@ -79,19 +47,19 @@
sk_sp<SkColorSpace> DataSpaceToColorSpace(android_dataspace dataspace) {
- SkColorSpace::Gamut gamut;
+ skcms_Matrix3x3 gamut;
switch (dataspace & HAL_DATASPACE_STANDARD_MASK) {
case HAL_DATASPACE_STANDARD_BT709:
- gamut = SkColorSpace::kSRGB_Gamut;
+ gamut = SkNamedGamut::kSRGB;
break;
case HAL_DATASPACE_STANDARD_BT2020:
- gamut = SkColorSpace::kRec2020_Gamut;
+ gamut = SkNamedGamut::kRec2020;
break;
case HAL_DATASPACE_STANDARD_DCI_P3:
- gamut = SkColorSpace::kDCIP3_D65_Gamut;
+ gamut = SkNamedGamut::kDCIP3;
break;
case HAL_DATASPACE_STANDARD_ADOBE_RGB:
- gamut = SkColorSpace::kAdobeRGB_Gamut;
+ gamut = SkNamedGamut::kAdobeRGB;
break;
case HAL_DATASPACE_STANDARD_UNSPECIFIED:
return nullptr;
@@ -109,9 +77,9 @@
switch (dataspace & HAL_DATASPACE_TRANSFER_MASK) {
case HAL_DATASPACE_TRANSFER_LINEAR:
- return SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, gamut);
+ return SkColorSpace::MakeRGB(SkNamedTransferFn::kLinear, gamut);
case HAL_DATASPACE_TRANSFER_SRGB:
- return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, gamut);
+ return SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, gamut);
case HAL_DATASPACE_TRANSFER_GAMMA2_2:
return SkColorSpace::MakeRGB({2.2f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, gamut);
case HAL_DATASPACE_TRANSFER_GAMMA2_6:
diff --git a/libs/hwui/utils/Color.h b/libs/hwui/utils/Color.h
index 4473ce6..3880252 100644
--- a/libs/hwui/utils/Color.h
+++ b/libs/hwui/utils/Color.h
@@ -111,11 +111,6 @@
#endif
}
-// Returns whether the specified color space's transfer function can be
-// approximated with the native sRGB transfer function. This method
-// returns true for sRGB, gamma 2.2 and Display P3 for instance
-bool transferFunctionCloseToSRGB(const SkColorSpace* colorSpace);
-
android::PixelFormat ColorTypeToPixelFormat(SkColorType colorType);
ANDROID_API sk_sp<SkColorSpace> DataSpaceToColorSpace(android_dataspace dataspace);
diff --git a/location/java/android/location/GnssMeasurement.java b/location/java/android/location/GnssMeasurement.java
index f179bc3..602cc3e 100644
--- a/location/java/android/location/GnssMeasurement.java
+++ b/location/java/android/location/GnssMeasurement.java
@@ -48,6 +48,7 @@
private int mMultipathIndicator;
private double mSnrInDb;
private double mAutomaticGainControlLevelInDb;
+ private int mCodeType;
// The following enumerations must be in sync with the values declared in gps.h
@@ -58,6 +59,7 @@
private static final int HAS_CARRIER_PHASE = (1<<11);
private static final int HAS_CARRIER_PHASE_UNCERTAINTY = (1<<12);
private static final int HAS_AUTOMATIC_GAIN_CONTROL = (1<<13);
+ private static final int HAS_CODE_TYPE = (1 << 14);
/**
* The status of the multipath indicator.
@@ -202,6 +204,104 @@
public static final int ADR_STATE_HALF_CYCLE_REPORTED = (1<<4);
/**
+ * GNSS measurement code type.
+ * @hide
+ */
+ @IntDef(prefix = { "CODE_TYPE_" }, value = {
+ CODE_TYPE_UNKNOWN, CODE_TYPE_A, CODE_TYPE_B, CODE_TYPE_C, CODE_TYPE_I, CODE_TYPE_L,
+ CODE_TYPE_M, CODE_TYPE_P, CODE_TYPE_Q, CODE_TYPE_S, CODE_TYPE_W, CODE_TYPE_X,
+ CODE_TYPE_Y, CODE_TYPE_Z, CODE_TYPE_CODELESS
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface CodeType {}
+
+ /** The GNSS Measurement's code type is unknown. */
+ public static final int CODE_TYPE_UNKNOWN = -1;
+
+ /**
+ * The GNSS Measurement's code type is one of the following: GALILEO E1A, GALILEO E6A, IRNSS
+ * L5A, IRNSS SA.
+ */
+ public static final int CODE_TYPE_A = 0;
+
+ /**
+ * The GNSS Measurement's code type is one of the following: GALILEO E1B, GALILEO E6B, IRNSS
+ * L5B, IRNSS SB.
+ */
+ public static final int CODE_TYPE_B = 1;
+
+ /**
+ * The GNSS Measurement's code type is one of the following: GPS L1 C/A, GPS L2 C/A, GLONASS G1
+ * C/A, GLONASS G2 C/A, GALILEO E1C, GALILEO E6C, SBAS L1 C/A, QZSS L1 C/A, IRNSS L5C.
+ */
+ public static final int CODE_TYPE_C = 2;
+
+ /**
+ * The GNSS Measurement's code type is one of the following: GPS L5 I, GLONASS G3 I, GALILEO E5a
+ * I, GALILEO E5b I, GALILEO E5a+b I, SBAS L5 I, QZSS L5 I, BDS B1 I, BDS B2 I, BDS B3 I.
+ */
+ public static final int CODE_TYPE_I = 3;
+
+ /**
+ * The GNSS Measurement's code type is one of the following: GPS L1C (P), GPS L2C (L), QZSS L1C
+ * (P), QZSS L2C (L), LEX(6) L.
+ */
+ public static final int CODE_TYPE_L = 4;
+
+ /**
+ * The GNSS Measurement's code type is one of the following: GPS L1M, GPS L2M.
+ */
+ public static final int CODE_TYPE_M = 5;
+
+ /**
+ * The GNSS Measurement's code type is one of the following: GPS L1P, GPS L2P, GLONASS G1P,
+ * GLONASS G2P.
+ */
+ public static final int CODE_TYPE_P = 6;
+
+ /**
+ * The GNSS Measurement's code type is one of the following: GPS L5 Q, GLONASS G3 Q, GALILEO E5a
+ * Q, GALILEO E5b Q, GALILEO E5a+b Q, SBAS L5 Q, QZSS L5 Q, BDS B1 Q, BDS B2 Q, BDS B3 Q.
+ */
+ public static final int CODE_TYPE_Q = 7;
+
+ /**
+ * The GNSS Measurement's code type is one of the following: GPS L1C (D), GPS L2C (M), QZSS L1C
+ * (D), QZSS L2C (M), LEX(6) S.
+ */
+ public static final int CODE_TYPE_S = 8;
+
+ /**
+ * The GNSS Measurement's code type is one of the following: GPS L1 Z-tracking, GPS L2
+ * Z-tracking.
+ */
+ public static final int CODE_TYPE_W = 9;
+
+ /**
+ * The GNSS Measurement's code type is one of the following: GPS L1C (D+P), GPS L2C (M+L), GPS
+ * L5 (I+Q), GLONASS G3 (I+Q), GALILEO E1 (B+C), GALILEO E5a (I+Q), GALILEO E5b (I+Q), GALILEO
+ * E5a+b(I+Q), GALILEO E6 (B+C), SBAS L5 (I+Q), QZSS L1C (D+P), QZSS L2C (M+L), QZSS L5 (I+Q),
+ * LEX(6) (S+L), BDS B1 (I+Q), BDS B2 (I+Q), BDS B3 (I+Q), IRNSS L5 (B+C).
+ */
+ public static final int CODE_TYPE_X = 10;
+
+ /**
+ * The GNSS Measurement's code type is one of the following: GPS L1Y, GPS L2Y.
+ */
+ public static final int CODE_TYPE_Y = 11;
+
+ /**
+ * The GNSS Measurement's code type is one of the following: GALILEO E1 (A+B+C), GALILEO E6
+ * (A+B+C), QZSS L1-SAIF.
+ */
+ public static final int CODE_TYPE_Z = 12;
+
+ /**
+ * The GNSS Measurement's code type is one of the following: GPS L1 codeless, GPS L2 codeless.
+ */
+ public static final int CODE_TYPE_CODELESS = 13;
+
+ /**
* All the 'Accumulated Delta Range' flags.
* @hide
*/
@@ -248,6 +348,7 @@
mMultipathIndicator = measurement.mMultipathIndicator;
mSnrInDb = measurement.mSnrInDb;
mAutomaticGainControlLevelInDb = measurement.mAutomaticGainControlLevelInDb;
+ mCodeType = measurement.mCodeType;
}
/**
@@ -967,7 +1068,7 @@
* <p>For internal and logging use only.
*/
private String getMultipathIndicatorString() {
- switch(mMultipathIndicator) {
+ switch (mMultipathIndicator) {
case MULTIPATH_INDICATOR_UNKNOWN:
return "Unknown";
case MULTIPATH_INDICATOR_DETECTED:
@@ -1063,6 +1164,89 @@
mAutomaticGainControlLevelInDb = Double.NaN;
}
+ /**
+ * Returns {@code true} if {@link #getCodeType()} is available,
+ * {@code false} otherwise.
+ */
+ public boolean hasCodeType() {
+ return isFlagSet(HAS_CODE_TYPE);
+ }
+
+ /**
+ * Gets the GNSS measurement's code type.
+ *
+ * <p>Similar to the Attribute field described in Rinex 3.03, e.g., in Tables 4-10, and Table
+ * A2 at the Rinex 3.03 Update 1 Document.
+ */
+ @CodeType
+ public int getCodeType() {
+ return mCodeType;
+ }
+
+ /**
+ * Sets the GNSS measurement's code type.
+ *
+ * @hide
+ */
+ @TestApi
+ public void setCodeType(@CodeType int codeType) {
+ setFlag(HAS_CODE_TYPE);
+ mCodeType = codeType;
+ }
+
+ /**
+ * Resets the GNSS measurement's code type.
+ *
+ * @hide
+ */
+ @TestApi
+ public void resetCodeType() {
+ resetFlag(HAS_CODE_TYPE);
+ mCodeType = CODE_TYPE_UNKNOWN;
+ }
+
+ /**
+ * Gets a string representation of the 'code type'.
+ *
+ * <p>For internal and logging use only.
+ */
+ private String getCodeTypeString() {
+ switch (mCodeType) {
+ case CODE_TYPE_UNKNOWN:
+ return "CODE_TYPE_UNKNOWN";
+ case CODE_TYPE_A:
+ return "CODE_TYPE_A";
+ case CODE_TYPE_B:
+ return "CODE_TYPE_B";
+ case CODE_TYPE_C:
+ return "CODE_TYPE_C";
+ case CODE_TYPE_I:
+ return "CODE_TYPE_I";
+ case CODE_TYPE_L:
+ return "CODE_TYPE_L";
+ case CODE_TYPE_M:
+ return "CODE_TYPE_M";
+ case CODE_TYPE_P:
+ return "CODE_TYPE_P";
+ case CODE_TYPE_Q:
+ return "CODE_TYPE_Q";
+ case CODE_TYPE_S:
+ return "CODE_TYPE_S";
+ case CODE_TYPE_W:
+ return "CODE_TYPE_W";
+ case CODE_TYPE_X:
+ return "CODE_TYPE_X";
+ case CODE_TYPE_Y:
+ return "CODE_TYPE_Y";
+ case CODE_TYPE_Z:
+ return "CODE_TYPE_Z";
+ case CODE_TYPE_CODELESS:
+ return "CODE_TYPE_CODELESS";
+ default:
+ return "<Invalid: " + mCodeType + ">";
+ }
+ }
+
public static final Creator<GnssMeasurement> CREATOR = new Creator<GnssMeasurement>() {
@Override
public GnssMeasurement createFromParcel(Parcel parcel) {
@@ -1088,6 +1272,7 @@
gnssMeasurement.mMultipathIndicator = parcel.readInt();
gnssMeasurement.mSnrInDb = parcel.readDouble();
gnssMeasurement.mAutomaticGainControlLevelInDb = parcel.readDouble();
+ gnssMeasurement.mCodeType = parcel.readInt();
return gnssMeasurement;
}
@@ -1120,6 +1305,7 @@
parcel.writeInt(mMultipathIndicator);
parcel.writeDouble(mSnrInDb);
parcel.writeDouble(mAutomaticGainControlLevelInDb);
+ parcel.writeInt(mCodeType);
}
@Override
@@ -1191,9 +1377,13 @@
"SnrInDb",
hasSnrInDb() ? mSnrInDb : null));
builder.append(String.format(
- format,
- "AgcLevelDb",
- hasAutomaticGainControlLevelDb() ? mAutomaticGainControlLevelInDb : null));
+ format,
+ "AgcLevelDb",
+ hasAutomaticGainControlLevelDb() ? mAutomaticGainControlLevelInDb : null));
+ builder.append(String.format(
+ format,
+ "CodeType",
+ hasCodeType() ? getCodeTypeString() : null));
return builder.toString();
}
@@ -1218,6 +1408,7 @@
setMultipathIndicator(MULTIPATH_INDICATOR_UNKNOWN);
resetSnrInDb();
resetAutomaticGainControlLevel();
+ resetCodeType();
}
private void setFlag(int flag) {
diff --git a/media/java/android/media/AudioFormat.java b/media/java/android/media/AudioFormat.java
index 793aa27..5516086 100644
--- a/media/java/android/media/AudioFormat.java
+++ b/media/java/android/media/AudioFormat.java
@@ -17,6 +17,7 @@
package android.media;
import android.annotation.IntDef;
+import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
@@ -816,7 +817,7 @@
*
* @return The audio frame size in bytes corresponding to the encoding and the channel mask.
*/
- public int getFrameSizeInBytes() {
+ public @IntRange(from = 1) int getFrameSizeInBytes() {
return mFrameSizeInBytes;
}
diff --git a/media/java/android/media/MediaPlayer2.java b/media/java/android/media/MediaPlayer2.java
index df96994..aa79c41 100644
--- a/media/java/android/media/MediaPlayer2.java
+++ b/media/java/android/media/MediaPlayer2.java
@@ -60,6 +60,7 @@
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
@@ -67,6 +68,7 @@
import java.util.Map;
import java.util.Queue;
import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
@@ -399,8 +401,7 @@
clearSourceInfos();
// Modular DRM clean up
- mOnDrmConfigHelper = null;
- synchronized (mDrmEventCbLock) {
+ synchronized (mDrmEventCallbackLock) {
mDrmEventCallbackRecords.clear();
}
@@ -775,7 +776,7 @@
}
boolean hasError = false;
for (DataSourceDesc dsd : dsds) {
- if (dsd != null) {
+ if (dsd == null) {
hasError = true;
continue;
}
@@ -2889,7 +2890,7 @@
}
private void sendDrmEvent(final DrmEventNotifier notifier) {
- synchronized (mDrmEventCbLock) {
+ synchronized (mDrmEventCallbackLock) {
try {
for (Pair<Executor, DrmEventCallback> cb : mDrmEventCallbackRecords) {
cb.first.execute(() -> notifier.notify(cb.second));
@@ -2901,12 +2902,28 @@
}
}
+ private <T> T sendDrmEventWait(final DrmEventNotifier<T> notifier)
+ throws InterruptedException, ExecutionException {
+ synchronized (mDrmEventCallbackLock) {
+ mDrmEventCallbackRecords.get(0);
+ for (Pair<Executor, DrmEventCallback> cb : mDrmEventCallbackRecords) {
+ CompletableFuture<T> ret = new CompletableFuture<>();
+ cb.first.execute(() -> ret.complete(notifier.notifyWait(cb.second)));
+ return ret.get();
+ }
+ }
+ return null;
+ }
+
private interface EventNotifier {
void notify(EventCallback callback);
}
- private interface DrmEventNotifier {
- void notify(DrmEventCallback callback);
+ private interface DrmEventNotifier<T> {
+ default void notify(DrmEventCallback callback) { }
+ default T notifyWait(DrmEventCallback callback) {
+ return null;
+ }
}
/* Do not change these values without updating their counterparts
@@ -3351,73 +3368,209 @@
// Modular DRM begin
/**
- * Interface definition of a callback to be invoked when the app
- * can do DRM configuration (get/set properties) before the session
- * is opened. This facilitates configuration of the properties, like
- * 'securityLevel', which has to be set after DRM scheme creation but
- * before the DRM session is opened.
+ * An immutable structure per {@link DataSourceDesc} with settings required to initiate a DRM
+ * protected playback session.
*
- * The only allowed DRM calls in this listener are
- * {@link MediaPlayer2#getDrmPropertyString(DataSourceDesc, String)}
- * and {@link MediaPlayer2#setDrmPropertyString(DataSourceDesc, String, String)}.
- * @hide
+ * @see DrmPreparationInfo.Builder
*/
- public interface OnDrmConfigHelper {
+ public static final class DrmPreparationInfo {
+
/**
- * Called to give the app the opportunity to configure DRM before the session is created
- *
- * @param mp the {@code MediaPlayer2} associated with this callback
- * @param dsd the DataSourceDesc of this data source
+ * Mutable builder to create a {@link MediaPlayer2.DrmPreparationInfo} object.
*/
- public void onDrmConfig(MediaPlayer2 mp, DataSourceDesc dsd);
- }
+ public static final class Builder {
- /**
- * Register a callback to be invoked for configuration of the DRM object before
- * the session is created.
- * The callback will be invoked synchronously during the execution
- * of {@link #prepareDrm}.
- *
- * @param listener the callback that will be run
- * @hide
- */
- // This is a synchronous call.
- public void setOnDrmConfigHelper(OnDrmConfigHelper listener) {
- mOnDrmConfigHelper = listener;
- }
+ private UUID mUUID;
+ private byte[] mKeySetId;
+ private byte[] mInitData;
+ private String mMimeType;
+ private int mKeyType;
+ private Map<String, String> mOptionalParameters;
- private OnDrmConfigHelper mOnDrmConfigHelper;
+ /**
+ * Set UUID of the crypto scheme selected to decrypt content. An UUID can be retrieved from
+ * the source listening to {@link MediaPlayer2.DrmEventCallback#onDrmInfo}.
+ *
+ * @param uuid of selected crypto scheme
+ * @return this
+ */
+ public Builder setUuid(@NonNull UUID uuid) {
+ this.mUUID = uuid;
+ return this;
+ }
+
+ /**
+ * Set identifier of a persisted offline key obtained from
+ * {@link MediaPlayer2.DrmEventCallback#onDrmPrepared(MediaPlayer2, DataSourceDesc, int, byte[])}.
+ *
+ * A {@code keySetId} can be used to restore persisted offline keys into a new playback
+ * session of a DRM protected data source. When {@code keySetId} is set, {@code initData},
+ * {@code mimeType}, {@code keyType}, {@code optionalParameters} are ignored.
+ *
+ * @param keySetId identifier of a persisted offline key
+ * @return this
+ */
+ public Builder setKeySetId(@Nullable byte[] keySetId) {
+ this.mKeySetId = keySetId;
+ return this;
+ }
+
+ /**
+ * Set container-specific DRM initialization data. Its meaning is interpreted based on
+ * {@code mimeType}. For example, it could contain the content ID, key ID or other data
+ * obtained from the content metadata that is required to generate a
+ * {@link MediaDrm.KeyRequest}.
+ *
+ * @param initData container-specific DRM initialization data
+ * @return this
+ */
+ public Builder setInitData(@Nullable byte[] initData) {
+ this.mInitData = initData;
+ return this;
+ }
+
+ /**
+ * Set mime type of the content
+ *
+ * @param mimeType mime type to the content
+ * @return this
+ */
+ public Builder setMimeType(@Nullable String mimeType) {
+ this.mMimeType = mimeType;
+ return this;
+ }
+
+ /**
+ * Set type of the key request. The request may be to acquire keys
+ * for streaming, {@link MediaDrm#KEY_TYPE_STREAMING}, or for offline content,
+ * {@link MediaDrm#KEY_TYPE_OFFLINE}. Releasing previously acquired keys
+ * ({@link MediaDrm#KEY_TYPE_RELEASE}) is not allowed.
+ *
+ * @param keyType type of the key request
+ * @return this
+ */
+ public Builder setKeyType(@MediaPlayer2.MediaDrmKeyType int keyType) {
+ this.mKeyType = keyType;
+ return this;
+ }
+
+ /**
+ * Set optional parameters to be included in a {@link MediaDrm.KeyRequest} message sent to
+ * the license server.
+ *
+ * @param optionalParameters optional parameters to be included in a key request
+ * @return this
+ */
+ public Builder setOptionalParameters(
+ @Nullable Map<String, String> optionalParameters) {
+ this.mOptionalParameters = optionalParameters;
+ return this;
+ }
+
+ /**
+ * @return an immutable {@link MediaPlayer2.DrmPreparationInfo} representing the settings of this builder
+ */
+ public MediaPlayer2.DrmPreparationInfo build() {
+ return new MediaPlayer2.DrmPreparationInfo(mUUID, mKeySetId, mInitData, mMimeType, mKeyType,
+ mOptionalParameters);
+ }
+
+ }
+
+ private final UUID mUUID;
+ private final byte[] mKeySetId;
+ private final byte[] mInitData;
+ private final String mMimeType;
+ private final int mKeyType;
+ private final Map<String, String> mOptionalParameters;
+
+ private DrmPreparationInfo(UUID mUUID, byte[] mKeySetId, byte[] mInitData, String mMimeType,
+ int mKeyType, Map<String, String> optionalParameters) {
+ this.mUUID = mUUID;
+ this.mKeySetId = mKeySetId;
+ this.mInitData = mInitData;
+ this.mMimeType = mMimeType;
+ this.mKeyType = mKeyType;
+ this.mOptionalParameters = optionalParameters;
+ }
+
+ }
/**
* Interface definition for callbacks to be invoked when the player has the corresponding
* DRM events.
- * @hide
*/
public static class DrmEventCallback {
/**
- * Called to indicate DRM info is available
+ * Called to indicate DRM info is available. Return a {@link DrmPreparationInfo} object that
+ * bundles DRM initialization parameters.
*
* @param mp the {@code MediaPlayer2} associated with this callback
- * @param dsd the DataSourceDesc of this data source
- * @param drmInfo DRM info of the source including PSSH, and subset
- * of crypto schemes supported by this device
+ * @param dsd the {@link DataSourceDesc} of this data source
+ * @param drmInfo DRM info of the source including PSSH, and subset of crypto schemes
+ * supported by this device
+ * @return a {@link DrmPreparationInfo} object to initialize DRM playback, or null to skip
+ * DRM initialization
*/
- public void onDrmInfo(MediaPlayer2 mp, DataSourceDesc dsd, DrmInfo drmInfo) { }
+ public DrmPreparationInfo onDrmInfo(MediaPlayer2 mp, DataSourceDesc dsd, DrmInfo drmInfo) {
+ return null;
+ }
/**
- * Called to notify the client that {@link MediaPlayer2#prepareDrm(DataSourceDesc, UUID)}
- * is finished and ready for key request/response.
+ * Called to notify the client that {@code mp} is ready to decrypt DRM protected data source
+ * {@code dsd}
*
* @param mp the {@code MediaPlayer2} associated with this callback
- * @param dsd the DataSourceDesc of this data source
+ * @param dsd the {@link DataSourceDesc} of this data source
* @param status the result of DRM preparation.
+ * @param keySetId optional identifier that can be used to restore DRM playback initiated
+ * with a {@link MediaDrm#KEY_TYPE_OFFLINE} key request.
+ *
+ * @see DrmPreparationInfo.Builder#setKeySetId(byte[])
*/
- public void onDrmPrepared(
- MediaPlayer2 mp, DataSourceDesc dsd, @PrepareDrmStatusCode int status) { }
+ public void onDrmPrepared(@NonNull MediaPlayer2 mp, @NonNull DataSourceDesc dsd,
+ @PrepareDrmStatusCode int status, @Nullable byte[] keySetId) { }
+
+ /**
+ * Called to give the app the opportunity to configure DRM before the session is created.
+ *
+ * This facilitates configuration of the properties, like 'securityLevel', which
+ * has to be set after DRM scheme creation but before the DRM session is opened.
+ *
+ * The only allowed DRM calls in this listener are
+ * {@link MediaDrm#getPropertyString(String)},
+ * {@link MediaDrm#getPropertyByteArray(String)},
+ * {@link MediaDrm#setPropertyString(String, String)},
+ * {@link MediaDrm#setPropertyByteArray(String, byte[])},
+ * {@link MediaDrm#setOnExpirationUpdateListener},
+ * and {@link MediaDrm#setOnKeyStatusChangeListener}.
+ *
+ * @param mp the {@code MediaPlayer2} associated with this callback
+ * @param dsd the {@link DataSourceDesc} of this data source
+ * @param drm handle to get/set DRM properties and listeners for this data source
+ */
+ public void onDrmConfig(@NonNull MediaPlayer2 mp, @NonNull DataSourceDesc dsd,
+ @NonNull MediaDrm drm) { }
+
+ /**
+ * Called to indicate the DRM session for {@code dsd} is ready for key request/response
+ *
+ * @param mp the {@code MediaPlayer2} associated with this callback
+ * @param dsd the {@link DataSourceDesc} of this data source
+ * @param request a {@link MediaDrm.KeyRequest} prepared using the
+ * {@link DrmPreparationInfo} returned from
+ * {@link #onDrmInfo(MediaPlayer2, DataSourceDesc, DrmInfo)}
+ * @return the response to {@code request} (from license server)
+ */
+ public byte[] onDrmKeyRequest(@NonNull MediaPlayer2 mp, @NonNull DataSourceDesc dsd,
+ @NonNull MediaDrm.KeyRequest request) {
+ return null;
+ }
+
}
- private final Object mDrmEventCbLock = new Object();
- private ArrayList<Pair<Executor, DrmEventCallback>> mDrmEventCallbackRecords =
+ private final Object mDrmEventCallbackLock = new Object();
+ private List<Pair<Executor, DrmEventCallback>> mDrmEventCallbackRecords =
new ArrayList<Pair<Executor, DrmEventCallback>>();
/**
@@ -3425,10 +3578,9 @@
*
* @param eventCallback the callback that will be run
* @param executor the executor through which the callback should be invoked
- * @hide
*/
// This is a synchronous call.
- public void registerDrmEventCallback(@NonNull @CallbackExecutor Executor executor,
+ public void setDrmEventCallback(@NonNull @CallbackExecutor Executor executor,
@NonNull DrmEventCallback eventCallback) {
if (eventCallback == null) {
throw new IllegalArgumentException("Illegal null EventCallback");
@@ -3437,8 +3589,9 @@
throw new IllegalArgumentException(
"Illegal null Executor for the EventCallback");
}
- synchronized (mDrmEventCbLock) {
- mDrmEventCallbackRecords.add(new Pair(executor, eventCallback));
+ synchronized (mDrmEventCallbackLock) {
+ mDrmEventCallbackRecords = Collections.singletonList(
+ new Pair<Executor, DrmEventCallback>(executor, eventCallback));
}
}
@@ -3450,7 +3603,7 @@
*/
// This is a synchronous call.
public void unregisterDrmEventCallback(DrmEventCallback eventCallback) {
- synchronized (mDrmEventCbLock) {
+ synchronized (mDrmEventCallbackLock) {
for (Pair<Executor, DrmEventCallback> cb : mDrmEventCallbackRecords) {
if (cb.second == eventCallback) {
mDrmEventCallbackRecords.remove(cb);
@@ -3564,7 +3717,7 @@
/**
* Prepares the DRM for the given data source
* <p>
- * If {@link OnDrmConfigHelper} is registered, it will be called during
+ * If {@link DrmEventCallback} is registered, it will be called during
* preparation to allow configuration of the DRM properties before opening the
* DRM session. It should be used only for a series of
* {@link #getDrmPropertyString(DataSourceDesc, String)} and
@@ -3587,8 +3740,7 @@
* @param dsd The DRM protected data source
*
* @param uuid The UUID of the crypto scheme. If not known beforehand, it can be retrieved
- * from the source through {@link #getDrmInfo(DataSourceDesc)} or registering a
- * {@link DrmEventCallback#onDrmInfo}.
+ * from the source listening to {@link DrmEventCallback#onDrmInfo}.
*
* @return a token which can be used to cancel the operation later with {@link #cancelCommand}.
* @hide
@@ -3661,8 +3813,8 @@
sendDrmEvent(new DrmEventNotifier() {
@Override
public void notify(DrmEventCallback callback) {
- callback.onDrmPrepared(
- MediaPlayer2.this, dsd, prepareDrmStatus);
+ callback.onDrmPrepared(MediaPlayer2.this, dsd, prepareDrmStatus,
+ /* TODO: keySetId */ null);
}
});
@@ -3876,7 +4028,6 @@
/**
* Encapsulates the DRM properties of the source.
- * @hide
*/
public static final class DrmInfo {
private Map<UUID, byte[]> mMapPssh;
@@ -4013,10 +4164,8 @@
}; // DrmInfo
/**
- * Thrown when a DRM method is called before preparing a DRM scheme through
- * {@link MediaPlayer2#prepareDrm(DataSourceDesc, UUID)}.
+ * Thrown when a DRM method is called when there is no active DRM session.
* Extends MediaDrm.MediaDrmException
- * @hide
*/
public static final class NoDrmSchemeException extends MediaDrmException {
public NoDrmSchemeException(String detailMessage) {
@@ -4291,9 +4440,9 @@
}
void prepare(UUID uuid) throws UnsupportedSchemeException,
- ResourceBusyException, NotProvisionedException {
- final OnDrmConfigHelper onDrmConfigHelper = mOnDrmConfigHelper;
- Log.v(TAG, "prepareDrm: uuid: " + uuid + " mOnDrmConfigHelper: " + onDrmConfigHelper);
+ ResourceBusyException, NotProvisionedException, InterruptedException,
+ ExecutionException {
+ Log.v(TAG, "prepareDrm: uuid: " + uuid);
synchronized (this) {
if (mActiveDrmUUID != null) {
@@ -4334,9 +4483,13 @@
} // synchronized
// call the callback outside the lock
- if (onDrmConfigHelper != null) {
- onDrmConfigHelper.onDrmConfig(MediaPlayer2.this, mDSD);
- }
+ sendDrmEventWait(new DrmEventNotifier<Void>() {
+ @Override
+ public Void notifyWait(DrmEventCallback callback) {
+ callback.onDrmConfig(MediaPlayer2.this, mDSD, mDrmObj);
+ return null;
+ }
+ });
synchronized (this) {
mDrmConfigAllowed = false;
@@ -4506,7 +4659,7 @@
@Override
public void notify(DrmEventCallback callback) {
callback.onDrmPrepared(
- MediaPlayer2.this, mDSD, finalStatus);
+ MediaPlayer2.this, mDSD, finalStatus, /* TODO: keySetId */ null);
}
});
diff --git a/media/jni/Android.bp b/media/jni/Android.bp
index d6b6339..452c6e1 100644
--- a/media/jni/Android.bp
+++ b/media/jni/Android.bp
@@ -34,7 +34,6 @@
"libutils",
"libbinder",
"libmedia",
- "libmediaextractor",
"libmedia_omx",
"libmediametrics",
"libmediadrm",
@@ -125,12 +124,12 @@
"libcutils",
"libmedia_helper",
"libmedia_player2_util",
- "libmediaextractor",
"libmediaplayer2",
"libmediaplayer2-protos",
"libmediandk_utils",
"libmediautils",
"libprotobuf-cpp-lite",
+ "libstagefright",
"libstagefright_esds",
"libstagefright_foundation",
"libstagefright_httplive",
diff --git a/native/android/Android.bp b/native/android/Android.bp
index fdcfc44..73d4c45 100644
--- a/native/android/Android.bp
+++ b/native/android/Android.bp
@@ -49,6 +49,7 @@
"sharedmem.cpp",
"storage_manager.cpp",
"surface_texture.cpp",
+ "surface_control.cpp",
"system_fonts.cpp",
"trace.cpp",
],
diff --git a/native/android/libandroid.map.txt b/native/android/libandroid.map.txt
index 537aed4..8be8eda 100644
--- a/native/android/libandroid.map.txt
+++ b/native/android/libandroid.map.txt
@@ -205,6 +205,9 @@
AStorageManager_mountObb;
AStorageManager_new;
AStorageManager_unmountObb;
+ ASurfaceControl_create; # introduced=29
+ ASurfaceControl_createFromWindow; # introduced=29
+ ASurfaceControl_destroy; # introduced=29
ASurfaceTexture_acquireANativeWindow; # introduced=28
ASurfaceTexture_attachToGLContext; # introduced=28
ASurfaceTexture_detachFromGLContext; # introduced=28
@@ -213,6 +216,16 @@
ASurfaceTexture_getTransformMatrix; # introduced=28
ASurfaceTexture_release; # introduced=28
ASurfaceTexture_updateTexImage; # introduced=28
+ ASurfaceTransaction_apply; # introduced=29
+ ASurfaceTransaction_create; # introduced=29
+ ASurfaceTransaction_delete; # introduced=29
+ ASurfaceTransaction_setBuffer; # introduced=29
+ ASurfaceTransaction_setBufferTransparency; # introduced=29
+ ASurfaceTransaction_setDamageRegion; # introduced=29
+ ASurfaceTransaction_setGeometry; # introduced=29
+ ASurfaceTransaction_setOnComplete; # introduced=29
+ ASurfaceTransaction_setVisibility; # introduced=29
+ ASurfaceTransaction_setZOrder; # introduced=29
ASystemFontIterator_open; # introduced=29
ASystemFontIterator_close; # introduced=29
ASystemFontIterator_next; # introduced=29
diff --git a/native/android/surface_control.cpp b/native/android/surface_control.cpp
new file mode 100644
index 0000000..ead5b0b
--- /dev/null
+++ b/native/android/surface_control.cpp
@@ -0,0 +1,232 @@
+/*
+ * Copyright 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <android/native_window.h>
+#include <android/surface_control.h>
+
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+#include <gui/SurfaceControl.h>
+
+using namespace android;
+
+using Transaction = SurfaceComposerClient::Transaction;
+
+#define CHECK_NOT_NULL(name) \
+ LOG_ALWAYS_FATAL_IF(name == nullptr, "nullptr passed as " #name " argument");
+
+#define CHECK_VALID_RECT(name) \
+ LOG_ALWAYS_FATAL_IF(!static_cast<const Rect&>(name).isValid(), \
+ "invalid arg passed as " #name " argument");
+
+Transaction* ASurfaceTransaction_to_Transaction(ASurfaceTransaction* aSurfaceTransaction) {
+ return reinterpret_cast<Transaction*>(aSurfaceTransaction);
+}
+
+SurfaceControl* ASurfaceControl_to_SurfaceControl(ASurfaceControl* aSurfaceControl) {
+ return reinterpret_cast<SurfaceControl*>(aSurfaceControl);
+}
+
+void SurfaceControl_acquire(SurfaceControl* surfaceControl) {
+ // incStrong/decStrong token must be the same, doesn't matter what it is
+ surfaceControl->incStrong((void*)SurfaceControl_acquire);
+}
+
+void SurfaceControl_release(SurfaceControl* surfaceControl) {
+ // incStrong/decStrong token must be the same, doesn't matter what it is
+ surfaceControl->decStrong((void*)SurfaceControl_acquire);
+}
+
+ASurfaceControl* ASurfaceControl_createFromWindow(ANativeWindow* window, const char* debug_name) {
+ CHECK_NOT_NULL(window);
+ CHECK_NOT_NULL(debug_name);
+
+ sp<SurfaceComposerClient> client = new SurfaceComposerClient();
+ if (client->initCheck() != NO_ERROR) {
+ return nullptr;
+ }
+
+ uint32_t flags = ISurfaceComposerClient::eFXSurfaceBufferState;
+ sp<SurfaceControl> surfaceControl =
+ client->createWithSurfaceParent(String8(debug_name), 0 /* width */, 0 /* height */,
+ // Format is only relevant for buffer queue layers.
+ PIXEL_FORMAT_UNKNOWN /* format */, flags,
+ static_cast<Surface*>(window));
+ if (!surfaceControl) {
+ return nullptr;
+ }
+
+ SurfaceControl_acquire(surfaceControl.get());
+ return reinterpret_cast<ASurfaceControl*>(surfaceControl.get());
+}
+
+ASurfaceControl* ASurfaceControl_create(ASurfaceControl* parent, const char* debug_name) {
+ CHECK_NOT_NULL(parent);
+ CHECK_NOT_NULL(debug_name);
+
+ SurfaceComposerClient* client = ASurfaceControl_to_SurfaceControl(parent)->getClient().get();
+
+ SurfaceControl* surfaceControlParent = ASurfaceControl_to_SurfaceControl(parent);
+
+ uint32_t flags = ISurfaceComposerClient::eFXSurfaceBufferState;
+ sp<SurfaceControl> surfaceControl =
+ client->createSurface(String8(debug_name), 0 /* width */, 0 /* height */,
+ // Format is only relevant for buffer queue layers.
+ PIXEL_FORMAT_UNKNOWN /* format */, flags,
+ surfaceControlParent);
+ if (!surfaceControl) {
+ return nullptr;
+ }
+
+ SurfaceControl_acquire(surfaceControl.get());
+ return reinterpret_cast<ASurfaceControl*>(surfaceControl.get());
+}
+
+void ASurfaceControl_destroy(ASurfaceControl* aSurfaceControl) {
+ sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
+
+ Transaction().reparent(surfaceControl, nullptr).apply();
+ SurfaceControl_release(surfaceControl.get());
+}
+
+ASurfaceTransaction* ASurfaceTransaction_create() {
+ Transaction* transaction = new Transaction;
+ return reinterpret_cast<ASurfaceTransaction*>(transaction);
+}
+
+void ASurfaceTransaction_delete(ASurfaceTransaction* aSurfaceTransaction) {
+ Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
+ delete transaction;
+}
+
+void ASurfaceTransaction_apply(ASurfaceTransaction* aSurfaceTransaction) {
+ CHECK_NOT_NULL(aSurfaceTransaction);
+
+ Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
+
+ transaction->apply();
+}
+
+void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* aSurfaceTransaction, void* context,
+ ASurfaceTransaction_OnComplete func) {
+ CHECK_NOT_NULL(aSurfaceTransaction);
+ CHECK_NOT_NULL(context);
+ CHECK_NOT_NULL(func);
+
+ TransactionCompletedCallbackTakesContext callback = [func](void* callback_context,
+ const TransactionStats& stats) {
+ int fence = (stats.presentFence) ? stats.presentFence->dup() : -1;
+ (*func)(callback_context, fence);
+ };
+
+ Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
+
+ transaction->addTransactionCompletedCallback(callback, context);
+}
+
+void ASurfaceTransaction_setVisibility(ASurfaceTransaction* aSurfaceTransaction, ASurfaceControl* aSurfaceControl,
+ int8_t visibility) {
+ CHECK_NOT_NULL(aSurfaceTransaction);
+ CHECK_NOT_NULL(aSurfaceControl);
+
+ sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
+ Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
+
+ switch (visibility) {
+ case ASURFACE_TRANSACTION_VISIBILITY_SHOW:
+ transaction->show(surfaceControl);
+ break;
+ case ASURFACE_TRANSACTION_VISIBILITY_HIDE:
+ transaction->hide(surfaceControl);
+ break;
+ default:
+ LOG_ALWAYS_FATAL("invalid visibility %d", visibility);
+ }
+}
+
+void ASurfaceTransaction_setZOrder(ASurfaceTransaction* aSurfaceTransaction, ASurfaceControl* aSurfaceControl,
+ int32_t z_order) {
+ CHECK_NOT_NULL(aSurfaceTransaction);
+ CHECK_NOT_NULL(aSurfaceControl);
+
+ sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
+ Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
+
+ transaction->setLayer(surfaceControl, z_order);
+}
+
+void ASurfaceTransaction_setBuffer(ASurfaceTransaction* aSurfaceTransaction, ASurfaceControl* aSurfaceControl,
+ AHardwareBuffer* buffer, int fence_fd) {
+ CHECK_NOT_NULL(aSurfaceTransaction);
+ CHECK_NOT_NULL(aSurfaceControl);
+
+ sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
+ Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
+
+ sp<GraphicBuffer> graphic_buffer(reinterpret_cast<GraphicBuffer*>(buffer));
+
+ transaction->setBuffer(surfaceControl, graphic_buffer);
+ if (fence_fd != -1) {
+ sp<Fence> fence = new Fence(fence_fd);
+ transaction->setAcquireFence(surfaceControl, fence);
+ }
+}
+
+void ASurfaceTransaction_setGeometry(ASurfaceTransaction* aSurfaceTransaction,
+ ASurfaceControl* aSurfaceControl, const ARect& source,
+ const ARect& destination, int32_t transform) {
+ CHECK_NOT_NULL(aSurfaceTransaction);
+ CHECK_NOT_NULL(aSurfaceControl);
+ CHECK_VALID_RECT(source);
+ CHECK_VALID_RECT(destination);
+
+ sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
+ Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
+
+ transaction->setCrop(surfaceControl, static_cast<const Rect&>(source));
+ transaction->setFrame(surfaceControl, static_cast<const Rect&>(destination));
+ transaction->setTransform(surfaceControl, transform);
+}
+
+void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* aSurfaceTransaction,
+ ASurfaceControl* aSurfaceControl,
+ int8_t transparency) {
+ CHECK_NOT_NULL(aSurfaceTransaction);
+ CHECK_NOT_NULL(aSurfaceControl);
+
+ sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
+ Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
+
+ uint32_t flags = (transparency == ASURFACE_TRANSACTION_TRANSPARENCY_OPAQUE) ?
+ layer_state_t::eLayerOpaque : 0;
+ transaction->setFlags(surfaceControl, flags, layer_state_t::eLayerOpaque);
+}
+
+void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* aSurfaceTransaction, ASurfaceControl* aSurfaceControl,
+ const ARect rects[], uint32_t count) {
+ CHECK_NOT_NULL(aSurfaceTransaction);
+ CHECK_NOT_NULL(aSurfaceControl);
+
+ sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
+ Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
+
+ Region region;
+ for (uint32_t i = 0; i < count; ++i) {
+ region.merge(static_cast<const Rect&>(rects[i]));
+ }
+
+ transaction->setSurfaceDamageRegion(surfaceControl, region);
+}
diff --git a/native/webview/plat_support/draw_fn.h b/native/webview/plat_support/draw_fn.h
index bb2ee9b..0490e65 100644
--- a/native/webview/plat_support/draw_fn.h
+++ b/native/webview/plat_support/draw_fn.h
@@ -74,7 +74,10 @@
VkQueue queue;
uint32_t graphics_queue_index;
uint32_t instance_version;
- const char* const* enabled_extension_names;
+ const char* const* enabled_instance_extension_names;
+ uint32_t enabled_instance_extension_names_length;
+ const char* const* enabled_device_extension_names;
+ uint32_t enabled_device_extension_names_length;
// Only one of device_features and device_features_2 should be non-null.
// If both are null then no features are enabled.
VkPhysicalDeviceFeatures* device_features;
@@ -128,15 +131,13 @@
struct AwDrawFn_PostDrawVkParams {
int version;
-
- // Input: Fence for the composite command buffer to signal it has finished its
- // work on the GPU.
- int fd;
};
// Called on render thread while UI thread is blocked. Called for both GL and
// VK.
-typedef void AwDrawFn_OnSync(int functor, void* data, AwDrawFn_OnSyncParams* params);
+typedef void AwDrawFn_OnSync(int functor,
+ void* data,
+ AwDrawFn_OnSyncParams* params);
// Called on render thread when either the context is destroyed _or_ when the
// functor's last reference goes away. Will always be called with an active
@@ -150,17 +151,24 @@
typedef void AwDrawFn_OnDestroyed(int functor, void* data);
// Only called for GL.
-typedef void AwDrawFn_DrawGL(int functor, void* data, AwDrawFn_DrawGLParams* params);
+typedef void AwDrawFn_DrawGL(int functor,
+ void* data,
+ AwDrawFn_DrawGLParams* params);
// Initialize vulkan state. Needs to be called again after any
// OnContextDestroyed. Only called for Vulkan.
-typedef void AwDrawFn_InitVk(int functor, void* data, AwDrawFn_InitVkParams* params);
+typedef void AwDrawFn_InitVk(int functor,
+ void* data,
+ AwDrawFn_InitVkParams* params);
// Only called for Vulkan.
-typedef void AwDrawFn_DrawVk(int functor, void* data, AwDrawFn_DrawVkParams* params);
+typedef void AwDrawFn_DrawVk(int functor,
+ void* data,
+ AwDrawFn_DrawVkParams* params);
// Only called for Vulkan.
-typedef void AwDrawFn_PostDrawVk(int functor, void* data,
+typedef void AwDrawFn_PostDrawVk(int functor,
+ void* data,
AwDrawFn_PostDrawVkParams* params);
struct AwDrawFnFunctorCallbacks {
@@ -183,7 +191,8 @@
typedef AwDrawFnRenderMode AwDrawFn_QueryRenderMode(void);
// Create a functor. |functor_callbacks| should be valid until OnDestroyed.
-typedef int AwDrawFn_CreateFunctor(void* data, AwDrawFnFunctorCallbacks* functor_callbacks);
+typedef int AwDrawFn_CreateFunctor(void* data,
+ AwDrawFnFunctorCallbacks* functor_callbacks);
// May be called on any thread to signal that the functor should be destroyed.
// The functor will receive an onDestroyed when the last usage of it is
diff --git a/native/webview/plat_support/draw_functor.cpp b/native/webview/plat_support/draw_functor.cpp
index 6c1ceab..b97bbc3 100644
--- a/native/webview/plat_support/draw_functor.cpp
+++ b/native/webview/plat_support/draw_functor.cpp
@@ -74,6 +74,79 @@
support->callbacks.draw_gl(functor, support->data, ¶ms);
}
+void initializeVk(int functor, void* data,
+ const uirenderer::VkFunctorInitParams& init_vk_params) {
+ SupportData* support = static_cast<SupportData*>(data);
+ VkPhysicalDeviceFeatures2 device_features_2;
+ if (init_vk_params.device_features_2)
+ device_features_2 = *init_vk_params.device_features_2;
+
+ AwDrawFn_InitVkParams params{
+ .version = kAwDrawFnVersion,
+ .instance = init_vk_params.instance,
+ .physical_device = init_vk_params.physical_device,
+ .device = init_vk_params.device,
+ .queue = init_vk_params.queue,
+ .graphics_queue_index = init_vk_params.graphics_queue_index,
+ .instance_version = init_vk_params.instance_version,
+ .enabled_instance_extension_names =
+ init_vk_params.enabled_instance_extension_names,
+ .enabled_instance_extension_names_length =
+ init_vk_params.enabled_instance_extension_names_length,
+ .enabled_device_extension_names =
+ init_vk_params.enabled_device_extension_names,
+ .enabled_device_extension_names_length =
+ init_vk_params.enabled_device_extension_names_length,
+ .device_features = nullptr,
+ .device_features_2 =
+ init_vk_params.device_features_2 ? &device_features_2 : nullptr,
+ };
+ support->callbacks.init_vk(functor, support->data, ¶ms);
+}
+
+void drawVk(int functor, void* data, const uirenderer::VkFunctorDrawParams& draw_vk_params) {
+ SupportData* support = static_cast<SupportData*>(data);
+ float gabcdef[7];
+ draw_vk_params.color_space_ptr->transferFn(gabcdef);
+ AwDrawFn_DrawVkParams params{
+ .version = kAwDrawFnVersion,
+ .width = draw_vk_params.width,
+ .height = draw_vk_params.height,
+ .is_layer = draw_vk_params.is_layer,
+ .secondary_command_buffer = draw_vk_params.secondary_command_buffer,
+ .color_attachment_index = draw_vk_params.color_attachment_index,
+ .compatible_render_pass = draw_vk_params.compatible_render_pass,
+ .format = draw_vk_params.format,
+ .transfer_function_g = gabcdef[0],
+ .transfer_function_a = gabcdef[1],
+ .transfer_function_b = gabcdef[2],
+ .transfer_function_c = gabcdef[3],
+ .transfer_function_d = gabcdef[4],
+ .transfer_function_e = gabcdef[5],
+ .transfer_function_f = gabcdef[6],
+ .clip_left = draw_vk_params.clip_left,
+ .clip_top = draw_vk_params.clip_top,
+ .clip_right = draw_vk_params.clip_right,
+ .clip_bottom = draw_vk_params.clip_bottom,
+ };
+ COMPILE_ASSERT(sizeof(params.color_space_toXYZD50) == sizeof(skcms_Matrix3x3),
+ gamut_transform_size_mismatch);
+ draw_vk_params.color_space_ptr->toXYZD50(
+ reinterpret_cast<skcms_Matrix3x3*>(¶ms.color_space_toXYZD50));
+ COMPILE_ASSERT(NELEM(params.transform) == NELEM(draw_vk_params.transform),
+ mismatched_transform_matrix_sizes);
+ for (int i = 0; i < NELEM(params.transform); ++i) {
+ params.transform[i] = draw_vk_params.transform[i];
+ }
+ support->callbacks.draw_vk(functor, support->data, ¶ms);
+}
+
+void postDrawVk(int functor, void* data) {
+ SupportData* support = static_cast<SupportData*>(data);
+ AwDrawFn_PostDrawVkParams params{.version = kAwDrawFnVersion};
+ support->callbacks.post_draw_vk(functor, support->data, ¶ms);
+}
+
int CreateFunctor(void* data, AwDrawFnFunctorCallbacks* functor_callbacks) {
static bool callbacks_initialized = false;
static uirenderer::WebViewFunctorCallbacks webview_functor_callbacks = {
@@ -82,9 +155,19 @@
.onDestroyed = &onDestroyed,
};
if (!callbacks_initialized) {
- // Under uirenderer::RenderMode::Vulkan, whether gles or vk union should
- // be populated should match whether the vk-gl interop is used.
- webview_functor_callbacks.gles.draw = &draw_gl;
+ switch (uirenderer::WebViewFunctor_queryPlatformRenderMode()) {
+ case uirenderer::RenderMode::OpenGL_ES:
+ webview_functor_callbacks.gles.draw = &draw_gl;
+ break;
+ case uirenderer::RenderMode::Vulkan:
+ webview_functor_callbacks.vk.initialize = &initializeVk;
+ webview_functor_callbacks.vk.draw = &drawVk;
+ webview_functor_callbacks.vk.postDraw = &postDrawVk;
+ // TODO(boliu): Remove this once SkiaRecordingCanvas::drawWebViewFunctor
+ // no longer uses GL interop.
+ webview_functor_callbacks.gles.draw = &draw_gl;
+ break;
+ }
callbacks_initialized = true;
}
SupportData* support = new SupportData{
diff --git a/packages/ExtServices/src/android/ext/services/notification/SmartActionsHelper.java b/packages/ExtServices/src/android/ext/services/notification/SmartActionsHelper.java
index a9d8f62..95df5f2 100644
--- a/packages/ExtServices/src/android/ext/services/notification/SmartActionsHelper.java
+++ b/packages/ExtServices/src/android/ext/services/notification/SmartActionsHelper.java
@@ -27,6 +27,7 @@
import android.service.notification.NotificationAssistantService;
import android.text.TextUtils;
import android.util.LruCache;
+import android.view.textclassifier.ConversationAction;
import android.view.textclassifier.ConversationActions;
import android.view.textclassifier.TextClassification;
import android.view.textclassifier.TextClassificationContext;
@@ -65,13 +66,13 @@
private static final int MAX_MESSAGES_TO_EXTRACT = 5;
private static final int MAX_RESULT_ID_TO_CACHE = 20;
- private static final ConversationActions.TypeConfig TYPE_CONFIG =
- new ConversationActions.TypeConfig.Builder().setIncludedTypes(
- Collections.singletonList(ConversationActions.TYPE_TEXT_REPLY))
+ private static final TextClassifier.EntityConfig TYPE_CONFIG =
+ new TextClassifier.EntityConfig.Builder().setIncludedTypes(
+ Collections.singletonList(ConversationAction.TYPE_TEXT_REPLY))
.includeTypesFromTextClassifier(false)
.build();
private static final List<String> HINTS =
- Collections.singletonList(ConversationActions.HINT_FOR_NOTIFICATION);
+ Collections.singletonList(ConversationActions.Request.HINT_FOR_NOTIFICATION);
private Context mContext;
@Nullable
@@ -137,7 +138,7 @@
ConversationActions conversationActionsResult =
mTextClassifier.suggestConversationActions(request);
- List<ConversationActions.ConversationAction> conversationActions =
+ List<ConversationAction> conversationActions =
conversationActionsResult.getConversationActions();
ArrayList<CharSequence> replies = conversationActions.stream()
.map(conversationAction -> conversationAction.getTextReply())
@@ -193,7 +194,7 @@
}
TextClassifierEvent textClassifierEvent =
createTextClassifierEventBuilder(TextClassifierEvent.TYPE_SMART_ACTION, resultId)
- .setEntityType(ConversationActions.TYPE_TEXT_REPLY)
+ .setEntityType(ConversationAction.TYPE_TEXT_REPLY)
.build();
mTextClassifier.onTextClassifierEvent(textClassifierEvent);
}
diff --git a/packages/ExtServices/tests/src/android/ext/services/notification/SmartActionHelperTest.java b/packages/ExtServices/tests/src/android/ext/services/notification/SmartActionHelperTest.java
index 7d74788..7b7ce3d 100644
--- a/packages/ExtServices/tests/src/android/ext/services/notification/SmartActionHelperTest.java
+++ b/packages/ExtServices/tests/src/android/ext/services/notification/SmartActionHelperTest.java
@@ -32,6 +32,7 @@
import android.service.notification.StatusBarNotification;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
+import android.view.textclassifier.ConversationAction;
import android.view.textclassifier.ConversationActions;
import android.view.textclassifier.TextClassificationManager;
import android.view.textclassifier.TextClassifier;
@@ -65,9 +66,10 @@
private static final String NOTIFICATION_KEY = "key";
private static final String RESULT_ID = "id";
- private static final ConversationActions.ConversationAction REPLY_ACTION =
- new ConversationActions.ConversationAction.Builder(
- ConversationActions.TYPE_TEXT_REPLY).setTextReply("Home").build();
+ private static final ConversationAction REPLY_ACTION =
+ new ConversationAction.Builder(ConversationAction.TYPE_TEXT_REPLY)
+ .setTextReply("Home")
+ .build();
private SmartActionsHelper mSmartActionsHelper;
private Context mContext;
diff --git a/packages/NetworkStack/AndroidManifest.xml b/packages/NetworkStack/AndroidManifest.xml
index 0b0f1ec..7f8bb93 100644
--- a/packages/NetworkStack/AndroidManifest.xml
+++ b/packages/NetworkStack/AndroidManifest.xml
@@ -20,6 +20,7 @@
package="com.android.mainline.networkstack"
android:sharedUserId="android.uid.networkstack">
<uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CONNECTIVITY_INTERNAL" />
diff --git a/packages/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java b/packages/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java
index 94ea1b9..4077d93 100644
--- a/packages/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java
+++ b/packages/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java
@@ -545,7 +545,9 @@
return HANDLED;
case CMD_FORCE_REEVALUATION:
case CMD_CAPTIVE_PORTAL_RECHECK:
- log("Forcing reevaluation for UID " + message.arg1);
+ final int dnsCount = mDnsStallDetector.getConsecutiveTimeoutCount();
+ validationLog("Forcing reevaluation for UID " + message.arg1
+ + ". Dns signal count: " + dnsCount);
mUidResponsibleForReeval = message.arg1;
transitionTo(mEvaluatingState);
return HANDLED;
diff --git a/packages/SettingsLib/res/values/strings.xml b/packages/SettingsLib/res/values/strings.xml
index 03c6205..9e89b89 100644
--- a/packages/SettingsLib/res/values/strings.xml
+++ b/packages/SettingsLib/res/values/strings.xml
@@ -99,8 +99,12 @@
<string name="connected_via_network_scorer_default">Automatically connected via network rating provider</string>
<!-- Status message of Wi-Fi when it is connected by Passpoint configuration. [CHAR LIMIT=NONE] -->
<string name="connected_via_passpoint">Connected via %1$s</string>
+ <!-- Status message of Wi-Fi when it is connected by Passpoint configuration. [CHAR LIMIT=NONE] -->
+ <string name="ssid_by_passpoint_provider"><xliff:g id="ssid" example="Cafe Wifi">%1$s</xliff:g> by <xliff:g id="passpointProvider" example="Passpoint Provider">%2$s</xliff:g></string>
<!-- Status message of Wi-Fi when network has matching passpoint credentials. [CHAR LIMIT=NONE] -->
<string name="available_via_passpoint">Available via %1$s</string>
+ <!-- Status message of OSU Provider network when not connected. [CHAR LIMIT=NONE] -->
+ <string name="tap_to_set_up">Tap to set up</string>
<!-- Package name for Settings app-->
<string name="settings_package" translatable="false">com.android.settings</string>
<!-- Package name for Certinstaller app-->
diff --git a/packages/SettingsLib/src/com/android/settingslib/Utils.java b/packages/SettingsLib/src/com/android/settingslib/Utils.java
index 595aeb3..c751c39 100644
--- a/packages/SettingsLib/src/com/android/settingslib/Utils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/Utils.java
@@ -38,8 +38,8 @@
private static final String CURRENT_MODE_KEY = "CURRENT_MODE";
private static final String NEW_MODE_KEY = "NEW_MODE";
@VisibleForTesting
- static final String STORAGE_MANAGER_SHOW_OPT_IN_PROPERTY =
- "ro.storage_manager.show_opt_in";
+ static final String STORAGE_MANAGER_ENABLED_PROPERTY =
+ "ro.storage_manager.enabled";
private static Signature[] sSystemSignature;
private static String sPermissionControllerPackageName;
@@ -373,8 +373,7 @@
public static boolean isStorageManagerEnabled(Context context) {
boolean isDefaultOn;
try {
- // Turn off by default if the opt-in was shown.
- isDefaultOn = !SystemProperties.getBoolean(STORAGE_MANAGER_SHOW_OPT_IN_PROPERTY, true);
+ isDefaultOn = SystemProperties.getBoolean(STORAGE_MANAGER_ENABLED_PROPERTY, false);
} catch (Resources.NotFoundException e) {
isDefaultOn = false;
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java b/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
index af5a24f..a97931a 100644
--- a/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
+++ b/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
@@ -41,6 +41,7 @@
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiNetworkScoreCache;
+import android.net.wifi.hotspot2.OsuProvider;
import android.net.wifi.hotspot2.PasspointConfiguration;
import android.os.Bundle;
import android.os.Parcelable;
@@ -182,6 +183,10 @@
public static final int UNREACHABLE_RSSI = Integer.MIN_VALUE;
+ public static final String KEY_PREFIX_AP = "AP:";
+ public static final String KEY_PREFIX_FQDN = "FQDN:";
+ public static final String KEY_PREFIX_OSU = "OSU:";
+
private final Context mContext;
private String ssid;
@@ -204,9 +209,6 @@
@Speed private int mSpeed = Speed.NONE;
private boolean mIsScoredNetworkMetered = false;
- // used to co-relate internal vs returned accesspoint.
- int mId;
-
/**
* Information associated with the {@link PasspointConfiguration}. Only maintaining
* the relevant info to preserve spaces.
@@ -215,6 +217,8 @@
private String mProviderFriendlyName;
private boolean mIsCarrierAp = false;
+
+ private OsuProvider mOsuProvider;
/**
* The EAP type {@link WifiEnterpriseConfig.Eap} associated with this AP if it is a carrier AP.
*/
@@ -280,14 +284,18 @@
// Calculate required fields
updateKey();
updateRssi();
-
- mId = sLastId.incrementAndGet();
}
+ /**
+ * Creates an AccessPoint with only a WifiConfiguration. This is used for the saved networks
+ * page.
+ *
+ * Passpoint Credential AccessPoints should be created with this.
+ * Make sure to call setScanResults after constructing with this.
+ */
public AccessPoint(Context context, WifiConfiguration config) {
mContext = context;
loadConfig(config);
- mId = sLastId.incrementAndGet();
}
/**
@@ -298,7 +306,19 @@
mContext = context;
mFqdn = config.getHomeSp().getFqdn();
mProviderFriendlyName = config.getHomeSp().getFriendlyName();
- mId = sLastId.incrementAndGet();
+ }
+
+ /**
+ * Initialize an AccessPoint object for a Passpoint OSU Provider.
+ * Make sure to call setScanResults after constructing with this.
+ */
+ public AccessPoint(Context context, OsuProvider provider) {
+ mContext = context;
+ mOsuProvider = provider;
+ mRssi = 1;
+ // TODO: This placeholder SSID is here to avoid null pointer exceptions.
+ ssid = "<OsuProvider AP SSID goes here>";
+ updateKey();
}
AccessPoint(Context context, Collection<ScanResult> results) {
@@ -324,8 +344,6 @@
mIsCarrierAp = firstResult.isCarrierAp;
mCarrierApEapType = firstResult.carrierApEapType;
mCarrierName = firstResult.carrierName;
-
- mId = sLastId.incrementAndGet();
}
@VisibleForTesting void loadConfig(WifiConfiguration config) {
@@ -344,14 +362,19 @@
StringBuilder builder = new StringBuilder();
if (isPasspoint()) {
- builder.append(mConfig.FQDN);
- } else if (TextUtils.isEmpty(getSsidStr())) {
- builder.append(getBssid());
- } else {
- builder.append(getSsidStr());
+ builder.append(KEY_PREFIX_FQDN).append(mConfig.FQDN);
+ } else if (isOsuProvider()) {
+ builder.append(KEY_PREFIX_OSU).append(mOsuProvider.getOsuSsid());
+ builder.append(',').append(mOsuProvider.getServerUri());
+ } else { // Non-Passpoint AP
+ builder.append(KEY_PREFIX_AP);
+ if (TextUtils.isEmpty(getSsidStr())) {
+ builder.append(getBssid());
+ } else {
+ builder.append(getSsidStr());
+ }
+ builder.append(',').append(getSecurity());
}
-
- builder.append(',').append(getSecurity());
mKey = builder.toString();
}
@@ -396,8 +419,8 @@
return difference;
}
- // Sort by ssid.
- difference = getSsidStr().compareToIgnoreCase(other.getSsidStr());
+ // Sort by title.
+ difference = getTitle().compareToIgnoreCase(other.getTitle());
if (difference != 0) {
return difference;
}
@@ -595,6 +618,7 @@
public static String getKey(ScanResult result) {
StringBuilder builder = new StringBuilder();
+ builder.append(KEY_PREFIX_AP);
if (TextUtils.isEmpty(result.SSID)) {
builder.append(result.BSSID);
} else {
@@ -609,14 +633,17 @@
StringBuilder builder = new StringBuilder();
if (config.isPasspoint()) {
- builder.append(config.FQDN);
- } else if (TextUtils.isEmpty(config.SSID)) {
- builder.append(config.BSSID);
+ builder.append(KEY_PREFIX_FQDN).append(config.FQDN);
} else {
- builder.append(removeDoubleQuotes(config.SSID));
+ builder.append(KEY_PREFIX_AP);
+ if (TextUtils.isEmpty(config.SSID)) {
+ builder.append(config.BSSID);
+ } else {
+ builder.append(removeDoubleQuotes(config.SSID));
+ }
+ builder.append(',').append(getSecurity(config));
}
- builder.append(',').append(getSecurity(config));
return builder.toString();
}
@@ -839,91 +866,97 @@
public String getTitle() {
if (isPasspoint()) {
return mConfig.providerFriendlyName;
+ } else if (isOsuProvider()) {
+ return mOsuProvider.getFriendlyName();
} else {
return getSsidStr();
}
}
public String getSummary() {
- return getSettingsSummary(mConfig);
+ return getSettingsSummary();
}
public String getSettingsSummary() {
- return getSettingsSummary(mConfig);
- }
-
- private String getSettingsSummary(WifiConfiguration config) {
// Update to new summary
StringBuilder summary = new StringBuilder();
- if (isActive() && config != null && config.isPasspoint()) {
- // This is the active connection on passpoint
- summary.append(getSummary(mContext, getDetailedState(),
- false, config.providerFriendlyName));
- } else if (isActive() && config != null && getDetailedState() == DetailedState.CONNECTED
- && mIsCarrierAp) {
- summary.append(String.format(mContext.getString(R.string.connected_via_carrier), mCarrierName));
- } else if (isActive()) {
- // This is the active connection on non-passpoint network
- summary.append(getSummary(mContext, getDetailedState(),
- mInfo != null && mInfo.isEphemeral()));
- } else if (config != null && config.isPasspoint()
- && config.getNetworkSelectionStatus().isNetworkEnabled()) {
- String format = mContext.getString(R.string.available_via_passpoint);
- summary.append(String.format(format, config.providerFriendlyName));
- } else if (config != null && config.hasNoInternetAccess()) {
- int messageID = config.getNetworkSelectionStatus().isNetworkPermanentlyDisabled()
- ? R.string.wifi_no_internet_no_reconnect
- : R.string.wifi_no_internet;
- summary.append(mContext.getString(messageID));
- } else if (config != null && !config.getNetworkSelectionStatus().isNetworkEnabled()) {
- WifiConfiguration.NetworkSelectionStatus networkStatus =
- config.getNetworkSelectionStatus();
- switch (networkStatus.getNetworkSelectionDisableReason()) {
- case WifiConfiguration.NetworkSelectionStatus.DISABLED_AUTHENTICATION_FAILURE:
- summary.append(mContext.getString(R.string.wifi_disabled_password_failure));
- break;
- case WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD:
- summary.append(mContext.getString(R.string.wifi_check_password_try_again));
- break;
- case WifiConfiguration.NetworkSelectionStatus.DISABLED_DHCP_FAILURE:
- case WifiConfiguration.NetworkSelectionStatus.DISABLED_DNS_FAILURE:
- summary.append(mContext.getString(R.string.wifi_disabled_network_failure));
- break;
- case WifiConfiguration.NetworkSelectionStatus.DISABLED_ASSOCIATION_REJECTION:
- summary.append(mContext.getString(R.string.wifi_disabled_generic));
- break;
+ if (isActive()) {
+ if (isPasspoint()) {
+ // This is the active connection on passpoint
+ summary.append(getSummary(mContext, ssid, getDetailedState(),
+ false, mConfig.providerFriendlyName));
+ } else if (mConfig != null && getDetailedState() == DetailedState.CONNECTED
+ && mIsCarrierAp) {
+ // This is the active connection on a carrier AP
+ summary.append(String.format(mContext.getString(R.string.connected_via_carrier),
+ mCarrierName));
+ } else {
+ // This is the active connection on non-passpoint network
+ summary.append(getSummary(mContext, getDetailedState(),
+ mInfo != null && mInfo.isEphemeral()));
}
- } else if (config != null && config.getNetworkSelectionStatus().isNotRecommended()) {
- summary.append(mContext.getString(R.string.wifi_disabled_by_recommendation_provider));
- } else if (mIsCarrierAp) {
- summary.append(String.format(mContext.getString(R.string.available_via_carrier), mCarrierName));
- } else if (!isReachable()) { // Wifi out of range
- summary.append(mContext.getString(R.string.wifi_not_in_range));
- } else { // In range, not disabled.
- if (config != null) { // Is saved network
- // Last attempt to connect to this failed. Show reason why
- switch (config.recentFailure.getAssociationStatus()) {
- case WifiConfiguration.RecentFailure.STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
- summary.append(mContext.getString(
- R.string.wifi_ap_unable_to_handle_new_sta));
+ } else { // not active
+ if (mConfig != null && mConfig.hasNoInternetAccess()) {
+ int messageID = mConfig.getNetworkSelectionStatus().isNetworkPermanentlyDisabled()
+ ? R.string.wifi_no_internet_no_reconnect
+ : R.string.wifi_no_internet;
+ summary.append(mContext.getString(messageID));
+ } else if (mConfig != null && !mConfig.getNetworkSelectionStatus().isNetworkEnabled()) {
+ WifiConfiguration.NetworkSelectionStatus networkStatus =
+ mConfig.getNetworkSelectionStatus();
+ switch (networkStatus.getNetworkSelectionDisableReason()) {
+ case WifiConfiguration.NetworkSelectionStatus.DISABLED_AUTHENTICATION_FAILURE:
+ summary.append(mContext.getString(R.string.wifi_disabled_password_failure));
break;
- default:
- // "Saved"
- summary.append(mContext.getString(R.string.wifi_remembered));
+ case WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD:
+ summary.append(mContext.getString(R.string.wifi_check_password_try_again));
break;
+ case WifiConfiguration.NetworkSelectionStatus.DISABLED_DHCP_FAILURE:
+ case WifiConfiguration.NetworkSelectionStatus.DISABLED_DNS_FAILURE:
+ summary.append(mContext.getString(R.string.wifi_disabled_network_failure));
+ break;
+ case WifiConfiguration.NetworkSelectionStatus.DISABLED_ASSOCIATION_REJECTION:
+ summary.append(mContext.getString(R.string.wifi_disabled_generic));
+ break;
+ }
+ } else if (mConfig != null && mConfig.getNetworkSelectionStatus().isNotRecommended()) {
+ summary.append(mContext.getString(
+ R.string.wifi_disabled_by_recommendation_provider));
+ } else if (mIsCarrierAp) {
+ summary.append(String.format(mContext.getString(
+ R.string.available_via_carrier), mCarrierName));
+ } else if (isOsuProvider()) {
+ summary.append(mContext.getString(R.string.tap_to_set_up));
+ } else if (!isReachable()) { // Wifi out of range
+ summary.append(mContext.getString(R.string.wifi_not_in_range));
+ } else { // In range, not disabled.
+ if (mConfig != null) { // Is saved network
+ // Last attempt to connect to this failed. Show reason why
+ switch (mConfig.recentFailure.getAssociationStatus()) {
+ case WifiConfiguration.RecentFailure.STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
+ summary.append(mContext.getString(
+ R.string.wifi_ap_unable_to_handle_new_sta));
+ break;
+ default:
+ // "Saved"
+ summary.append(mContext.getString(R.string.wifi_remembered));
+ break;
+ }
}
}
}
+
+
if (isVerboseLoggingEnabled()) {
- summary.append(WifiUtils.buildLoggingSummary(this, config));
+ summary.append(WifiUtils.buildLoggingSummary(this, mConfig));
}
- if (config != null && (WifiUtils.isMeteredOverridden(config) || config.meteredHint)) {
+ if (mConfig != null && (WifiUtils.isMeteredOverridden(mConfig) || mConfig.meteredHint)) {
return mContext.getResources().getString(
R.string.preference_summary_default_combination,
- WifiUtils.getMeteredLabel(mContext, config),
+ WifiUtils.getMeteredLabel(mContext, mConfig),
summary.toString());
}
@@ -976,6 +1009,13 @@
}
/**
+ * Return true if this AccessPoint represents an OSU Provider.
+ */
+ public boolean isOsuProvider() {
+ return mOsuProvider != null;
+ }
+
+ /**
* Return whether the given {@link WifiInfo} is for this access point.
* If the current AP does not have a network Id then the config is used to
* match based on SSID and security.
@@ -1065,8 +1105,8 @@
void setScanResults(Collection<ScanResult> scanResults) {
// Validate scan results are for current AP only by matching SSID/BSSID
- // Passpoint R1 networks are not bound to a specific SSID/BSSID, so skip this for passpoint.
- if (!isPasspoint()) {
+ // Passpoint networks are not bound to a specific SSID/BSSID, so skip this for passpoint.
+ if (!isPasspoint() && !isOsuProvider()) {
String key = getKey();
for (ScanResult result : scanResults) {
String scanResultKey = AccessPoint.getKey(result);
@@ -1119,7 +1159,17 @@
}
}
- /** Attempt to update the AccessPoint and return true if an update occurred. */
+ /**
+ * Attempt to update the AccessPoint with the current connection info.
+ * This is used to set an AccessPoint to the active one if the connection info matches, or
+ * conversely to set an AccessPoint to inactive if the connection info does not match. The RSSI
+ * is also updated upon a match. Listeners will be notified if an update occurred.
+ *
+ * This is called in {@link WifiTracker#updateAccessPoints} as well as in callbacks for handling
+ * NETWORK_STATE_CHANGED_ACTION, RSSI_CHANGED_ACTION, and onCapabilitiesChanged in WifiTracker.
+ *
+ * Returns true if an update occurred.
+ */
public boolean update(
@Nullable WifiConfiguration config, WifiInfo info, NetworkInfo networkInfo) {
@@ -1246,11 +1296,11 @@
public static String getSummary(Context context, String ssid, DetailedState state,
boolean isEphemeral, String passpointProvider) {
- if (state == DetailedState.CONNECTED && ssid == null) {
- if (TextUtils.isEmpty(passpointProvider) == false) {
+ if (state == DetailedState.CONNECTED) {
+ if (!TextUtils.isEmpty(passpointProvider)) {
// Special case for connected + passpoint networks.
- String format = context.getString(R.string.connected_via_passpoint);
- return String.format(format, passpointProvider);
+ String format = context.getString(R.string.ssid_by_passpoint_provider);
+ return String.format(format, ssid, passpointProvider);
} else if (isEphemeral) {
// Special case for connected + ephemeral networks.
final NetworkScoreManager networkScoreManager = context.getSystemService(
diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
index 79a7240..6d28891 100644
--- a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
+++ b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
@@ -35,6 +35,7 @@
import android.net.wifi.WifiManager;
import android.net.wifi.WifiNetworkScoreCache;
import android.net.wifi.WifiNetworkScoreCache.CacheListener;
+import android.net.wifi.hotspot2.OsuProvider;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
@@ -584,7 +585,7 @@
Map<Integer, List<ScanResult>>> pairing : passpointConfigsAndScans) {
WifiConfiguration config = pairing.first;
- // TODO: Prioritize home networks before roaming networks
+ // TODO(b/118705403): Prioritize home networks before roaming networks
List<ScanResult> scanResults = new ArrayList<>();
List<ScanResult> homeScans =
@@ -618,6 +619,23 @@
}
}
+ // Add Passpoint OSU Provider AccessPoints
+ // TODO(b/118705403): filter out OSU Providers which we already have credentials from.
+ Map<OsuProvider, List<ScanResult>> providersAndScans =
+ mWifiManager.getMatchingOsuProviders(cachedScanResults);
+ for (OsuProvider provider : providersAndScans.keySet()) {
+ AccessPoint accessPointOsu = new AccessPoint(mContext, provider);
+ // TODO(b/118705403): accessPointOsu.setScanResults(Matching ScanResult with best
+ // RSSI)
+ // TODO(b/118705403): Figure out if we would need to update an OSU AP (this will be
+ // used if we need to display it at the top of the picker as the "active" AP).
+ // Otherwise, OSU APs should ignore attempts to update the active connection
+ // info.
+ // accessPointOsu.update(connectionConfig, mLastInfo, mLastNetworkInfo);
+ accessPoints.add(accessPointOsu);
+ }
+
+
// If there were no scan results, create an AP for the currently connected network (if
// it exists).
if (accessPoints.isEmpty() && connectionConfig != null) {
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java
index 86f0438..92ebe44 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java
@@ -17,7 +17,7 @@
import static android.Manifest.permission.WRITE_SECURE_SETTINGS;
-import static com.android.settingslib.Utils.STORAGE_MANAGER_SHOW_OPT_IN_PROPERTY;
+import static com.android.settingslib.Utils.STORAGE_MANAGER_ENABLED_PROPERTY;
import static com.google.common.truth.Truth.assertThat;
@@ -159,7 +159,7 @@
@Test
public void testIsStorageManagerEnabled_UsesSystemProperties() {
- SystemProperties.set(STORAGE_MANAGER_SHOW_OPT_IN_PROPERTY, "false");
+ SystemProperties.set(STORAGE_MANAGER_ENABLED_PROPERTY, "true");
assertThat(Utils.isStorageManagerEnabled(mContext)).isTrue();
}
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
index bcf37ff..18bdb20 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
@@ -2363,6 +2363,14 @@
SecureSettingsProto.Zen.SETTINGS_SUGGESTION_VIEWED);
p.end(zenToken);
+ dumpSetting(s, p,
+ Settings.Secure.SKIP_GESTURE,
+ SecureSettingsProto.SKIP_GESTURE_ENABLED);
+
+ dumpSetting(s, p,
+ Settings.Secure.SILENCE_GESTURE,
+ SecureSettingsProto.SILENCE_GESTURE_ENABLED);
+
// Please insert new settings using the same order as in SecureSettingsProto.
p.end(token);
diff --git a/packages/Shell/AndroidManifest.xml b/packages/Shell/AndroidManifest.xml
index fa95bf2..9b775e0 100644
--- a/packages/Shell/AndroidManifest.xml
+++ b/packages/Shell/AndroidManifest.xml
@@ -129,6 +129,7 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.MANAGE_ACTIVITY_STACKS" />
<uses-permission android:name="android.permission.START_TASKS_FROM_RECENTS" />
+ <uses-permission android:name="android.permission.START_ACTIVITIES_FROM_BACKGROUND" />
<uses-permission android:name="android.permission.ACTIVITY_EMBEDDING" />
<uses-permission android:name="android.permission.CONNECTIVITY_INTERNAL" />
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" />
diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java
index 2530abc..afb9781 100644
--- a/packages/Shell/src/com/android/shell/BugreportProgressService.java
+++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java
@@ -56,6 +56,7 @@
import android.accounts.Account;
import android.accounts.AccountManager;
import android.annotation.MainThread;
+import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Notification;
@@ -799,6 +800,18 @@
Log.wtf(TAG, "Missing " + EXTRA_BUGREPORT + " on intent " + intent);
return;
}
+ final int max = intent.getIntExtra(EXTRA_MAX, -1);
+ final File screenshotFile = getFileExtra(intent, EXTRA_SCREENSHOT);
+ final String shareTitle = intent.getStringExtra(EXTRA_TITLE);
+ final String shareDescription = intent.getStringExtra(EXTRA_DESCRIPTION);
+ onBugreportFinished(id, bugreportFile, screenshotFile, shareTitle, shareDescription, max);
+ }
+
+ /**
+ * Wraps up bugreport generation and triggers a notification to share the bugreport.
+ */
+ private void onBugreportFinished(int id, File bugreportFile, @Nullable File screenshotFile,
+ String shareTitle, String shareDescription, int max) {
mInfoDialog.onBugreportFinished();
BugreportInfo info = getInfo(id);
if (info == null) {
@@ -809,22 +822,17 @@
}
info.renameScreenshots(mScreenshotsDir);
info.bugreportFile = bugreportFile;
+ if (screenshotFile != null) {
+ info.addScreenshot(screenshotFile);
+ }
- final int max = intent.getIntExtra(EXTRA_MAX, -1);
if (max != -1) {
MetricsLogger.histogram(this, "dumpstate_duration", max);
info.max = max;
}
- final File screenshot = getFileExtra(intent, EXTRA_SCREENSHOT);
- if (screenshot != null) {
- info.addScreenshot(screenshot);
- }
-
- final String shareTitle = intent.getStringExtra(EXTRA_TITLE);
if (!TextUtils.isEmpty(shareTitle)) {
info.title = shareTitle;
- final String shareDescription = intent.getStringExtra(EXTRA_DESCRIPTION);
if (!TextUtils.isEmpty(shareDescription)) {
info.shareDescription= shareDescription;
}
@@ -1944,6 +1952,23 @@
}
@Override
+ public void onProgress(int progress) throws RemoteException {
+ // TODO(b/111441001): change max argument?
+ updateProgressInfo(progress, CAPPED_MAX);
+ }
+
+ @Override
+ public void onError(int errorCode) throws RemoteException {
+ // TODO(b/111441001): implement
+ }
+
+ @Override
+ public void onFinished(long durationMs, String title, String description)
+ throws RemoteException {
+ // TODO(b/111441001): implement
+ }
+
+ @Override
public void onProgressUpdated(int progress) throws RemoteException {
/*
* Checks whether the progress changed in a way that should be displayed to the user:
@@ -1964,21 +1989,7 @@
}
if (newPercentage > oldPercentage) {
- if (DEBUG) {
- if (progress != info.progress) {
- Log.v(TAG, "Updating progress for PID " + info.pid + "(id: " + info.id
- + ") from " + info.progress + " to " + progress);
- }
- if (max != info.max) {
- Log.v(TAG, "Updating max progress for PID " + info.pid + "(id: " + info.id
- + ") from " + info.max + " to " + max);
- }
- }
- info.progress = progress;
- info.max = max;
- info.lastUpdate = System.currentTimeMillis();
-
- updateProgress(info);
+ updateProgressInfo(progress, max);
}
}
@@ -2000,5 +2011,23 @@
public void dump(String prefix, PrintWriter pw) {
pw.print(prefix); pw.print("token: "); pw.println(token);
}
+
+ private void updateProgressInfo(int progress, int max) {
+ if (DEBUG) {
+ if (progress != info.progress) {
+ Log.v(TAG, "Updating progress for PID " + info.pid + "(id: " + info.id
+ + ") from " + info.progress + " to " + progress);
+ }
+ if (max != info.max) {
+ Log.v(TAG, "Updating max progress for PID " + info.pid + "(id: " + info.id
+ + ") from " + info.max + " to " + max);
+ }
+ }
+ info.progress = progress;
+ info.max = max;
+ info.lastUpdate = System.currentTimeMillis();
+
+ updateProgress(info);
+ }
}
}
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
index 1c1a140..b4f2711 100644
--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -87,6 +87,7 @@
<uses-permission android:name="android.permission.STOP_APP_SWITCHES" />
<uses-permission android:name="android.permission.SET_SCREEN_COMPATIBILITY" />
<uses-permission android:name="android.permission.START_ANY_ACTIVITY" />
+ <uses-permission android:name="android.permission.START_ACTIVITIES_FROM_BACKGROUND" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<uses-permission android:name="android.permission.GET_TOP_ACTIVITY_INFO" />
diff --git a/packages/SystemUI/res-keyguard/drawable/bubble_hour_hand.xml b/packages/SystemUI/res-keyguard/drawable/bubble_hour_hand.xml
new file mode 100644
index 0000000..d3c3a51
--- /dev/null
+++ b/packages/SystemUI/res-keyguard/drawable/bubble_hour_hand.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:height="200dp"
+ android:width="200dp"
+ android:viewportHeight="100"
+ android:viewportWidth="100">
+ <path
+ android:fillColor="#000000"
+ android:pathData="M50.082,14.199m-13.985,0a13.985,13.985 0,1 1,27.97 0a13.985,13.985 0,1 1,-27.97 0"/>
+</vector>
diff --git a/packages/SystemUI/res-keyguard/drawable/bubble_minute_hand.xml b/packages/SystemUI/res-keyguard/drawable/bubble_minute_hand.xml
new file mode 100644
index 0000000..a4417fb
--- /dev/null
+++ b/packages/SystemUI/res-keyguard/drawable/bubble_minute_hand.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:height="200dp"
+ android:width="200dp"
+ android:viewportHeight="100"
+ android:viewportWidth="100" >
+ <path
+ android:fillColor="#000000"
+ android:pathData="M50.082,0.025L50.082,0.025A13.985,15.63 0,0 1,64.067 15.656L64.067,49.029A13.985,15.63 0,0 1,50.082 64.659L50.082,64.659A13.985,15.63 0,0 1,36.097 49.029L36.097,15.656A13.985,15.63 0,0 1,50.082 0.025z"/>
+</vector>
diff --git a/packages/SystemUI/res-keyguard/layout/bubble_clock.xml b/packages/SystemUI/res-keyguard/layout/bubble_clock.xml
new file mode 100644
index 0000000..0d72657
--- /dev/null
+++ b/packages/SystemUI/res-keyguard/layout/bubble_clock.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<com.android.keyguard.clock.ClockLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ >
+ <TextClock
+ android:id="@+id/digital_clock"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:letterSpacing="0.03"
+ android:singleLine="true"
+ style="@style/widget_big"
+ android:format12Hour="@string/keyguard_widget_12_hours_format"
+ android:format24Hour="@string/keyguard_widget_24_hours_format"
+ />
+ <com.android.keyguard.clock.ImageClock
+ android:id="@+id/analog_clock"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ >
+ <ImageView
+ android:id="@+id/minute_hand"
+ android:layout_width="300dp"
+ android:layout_height="300dp"
+ android:src="@drawable/bubble_minute_hand"
+ android:tint="@color/bubbleMinuteHandColor"
+ />
+ <ImageView
+ android:id="@+id/hour_hand"
+ android:layout_width="300dp"
+ android:layout_height="300dp"
+ android:src="@drawable/bubble_hour_hand"
+ android:tint="@color/bubbleHourHandColor"
+ />
+ </com.android.keyguard.clock.ImageClock>
+</com.android.keyguard.clock.ClockLayout>
diff --git a/packages/SystemUI/res-keyguard/layout/digital_clock.xml b/packages/SystemUI/res-keyguard/layout/digital_clock.xml
new file mode 100644
index 0000000..cf4a573
--- /dev/null
+++ b/packages/SystemUI/res-keyguard/layout/digital_clock.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<FrameLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_alignParentTop="true">
+ <TextClock
+ android:id="@+id/lock_screen_clock"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:letterSpacing="0.03"
+ android:singleLine="true"
+ style="@style/widget_big"
+ android:format12Hour="@string/keyguard_widget_12_hours_format"
+ android:format24Hour="@string/keyguard_widget_24_hours_format" />
+ />
+</FrameLayout>
+
diff --git a/packages/SystemUI/res-keyguard/values/colors.xml b/packages/SystemUI/res-keyguard/values/colors.xml
new file mode 100644
index 0000000..7a849eb
--- /dev/null
+++ b/packages/SystemUI/res-keyguard/values/colors.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<resources>
+ <!-- Default color for hour hand of Bubble clock. -->
+ <color name="bubbleHourHandColor">#C97343</color>
+ <!-- Default color for minute hand of Bubble clock. -->
+ <color name="bubbleMinuteHandColor">#F5C983</color>
+</resources>
diff --git a/packages/SystemUI/res/layout/ongoing_privacy_dialog_item.xml b/packages/SystemUI/res/layout/ongoing_privacy_dialog_item.xml
index ecfbfb4..c8e0845 100644
--- a/packages/SystemUI/res/layout/ongoing_privacy_dialog_item.xml
+++ b/packages/SystemUI/res/layout/ongoing_privacy_dialog_item.xml
@@ -25,12 +25,18 @@
android:focusable="true"
android:layout_gravity="center_vertical">
- <ImageView
- android:id="@+id/app_icon"
+ <FrameLayout
android:layout_height="@dimen/ongoing_appops_dialog_app_icon_size"
android:layout_width="@dimen/ongoing_appops_dialog_app_icon_size"
- android:layout_gravity="start|center_vertical"
- />
+ android:layout_gravity="start|center_vertical">
+
+ <ImageView
+ android:id="@+id/app_icon"
+ android:layout_height="@dimen/ongoing_appops_dialog_app_icon_size"
+ android:layout_width="@dimen/ongoing_appops_dialog_app_icon_size"
+ android:layout_gravity="center"
+ />
+ </FrameLayout>
<TextView
android:id="@+id/app_name"
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index ef16bca..5a00b45 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -952,6 +952,8 @@
<dimen name="ongoing_appops_dialog_icon_margin">8dp</dimen>
<!-- Height and width of Application icons in Ongoing App Ops dialog -->
<dimen name="ongoing_appops_dialog_app_icon_size">32dp</dimen>
+ <!-- Height and width of Plus sign in Ongoing App Ops dialog -->
+ <dimen name="ongoing_appops_dialog_app_plus_size">24dp</dimen>
<!-- Height of line in Ongoing App Ops dialog-->
<dimen name="ongoing_appops_dialog_line_height">48dp</dimen>
<!-- Side margin of title in Ongoing App Ops dialog -->
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginInstanceManager.java b/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginInstanceManager.java
index 523720d5..1a684a0 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginInstanceManager.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginInstanceManager.java
@@ -323,7 +323,7 @@
return null;
}
// Create our own ClassLoader so we can use our own code as the parent.
- ClassLoader classLoader = mManager.getClassLoader(info.sourceDir, info.packageName);
+ ClassLoader classLoader = mManager.getClassLoader(info);
Context pluginContext = new PluginContextWrapper(
mContext.createApplicationContext(info, 0), classLoader);
Class<?> pluginClass = Class.forName(cls, true, classLoader);
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginManagerImpl.java b/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginManagerImpl.java
index da143f9..7139708 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginManagerImpl.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginManagerImpl.java
@@ -14,6 +14,7 @@
package com.android.systemui.shared.plugins;
+import android.app.LoadedApk;
import android.app.Notification;
import android.app.Notification.Action;
import android.app.NotificationManager;
@@ -44,15 +45,17 @@
import com.android.systemui.plugins.Plugin;
import com.android.systemui.plugins.PluginListener;
import com.android.systemui.plugins.annotations.ProvidesInterface;
-import com.android.systemui.shared.plugins.PluginInstanceManager.PluginContextWrapper;
import com.android.systemui.shared.plugins.PluginInstanceManager.PluginInfo;
import dalvik.system.PathClassLoader;
+import java.io.File;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.Thread.UncaughtExceptionHandler;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import java.util.Map;
/**
* @see Plugin
@@ -117,6 +120,7 @@
return mPluginEnabler;
}
+ // TODO(mankoff): This appears to be only called from tests. Remove?
public <T extends Plugin> T getOneShotPlugin(Class<T> cls) {
ProvidesInterface info = cls.getDeclaredAnnotation(ProvidesInterface.class);
if (info == null) {
@@ -282,17 +286,25 @@
}
}
- public ClassLoader getClassLoader(String sourceDir, String pkg) {
- if (!isDebuggable && !mWhitelistedPlugins.contains(pkg)) {
- Log.w(TAG, "Cannot get class loader for non-whitelisted plugin. Src:" + sourceDir +
- ", pkg: " + pkg);
+ /** Returns class loader specific for the given plugin. */
+ public ClassLoader getClassLoader(ApplicationInfo appInfo) {
+ if (!isDebuggable && !mWhitelistedPlugins.contains(appInfo.packageName)) {
+ Log.w(TAG, "Cannot get class loader for non-whitelisted plugin. Src:"
+ + appInfo.sourceDir + ", pkg: " + appInfo.packageName);
return null;
}
- if (mClassLoaders.containsKey(pkg)) {
- return mClassLoaders.get(pkg);
+ if (mClassLoaders.containsKey(appInfo.packageName)) {
+ return mClassLoaders.get(appInfo.packageName);
}
- ClassLoader classLoader = new PathClassLoader(sourceDir, getParentClassLoader());
- mClassLoaders.put(pkg, classLoader);
+
+ List<String> zipPaths = new ArrayList<>();
+ List<String> libPaths = new ArrayList<>();
+ LoadedApk.makePaths(null, true, appInfo, zipPaths, libPaths);
+ ClassLoader classLoader = new PathClassLoader(
+ TextUtils.join(File.pathSeparator, zipPaths),
+ TextUtils.join(File.pathSeparator, libPaths),
+ getParentClassLoader());
+ mClassLoaders.put(appInfo.packageName, classLoader);
return classLoader;
}
@@ -309,11 +321,6 @@
return mParentClassLoader;
}
- public Context getContext(ApplicationInfo info, String pkg) throws NameNotFoundException {
- ClassLoader classLoader = getClassLoader(info.sourceDir, pkg);
- return new PluginContextWrapper(mContext.createApplicationContext(info, 0), classLoader);
- }
-
public <T> boolean dependsOn(Plugin p, Class<T> cls) {
for (int i = 0; i < mPluginMap.size(); i++) {
if (mPluginMap.valueAt(i).dependsOn(p, cls)) {
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputView.java
index 41e9eba..a055950 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputView.java
@@ -46,6 +46,7 @@
protected View mEcaView;
protected boolean mEnableHaptics;
private boolean mDismissing;
+ protected boolean mResumed;
private CountDownTimer mCountdownTimer = null;
// To avoid accidental lockout due to events while the device in in the pocket, ignore
@@ -263,6 +264,8 @@
@Override
public void onPause() {
+ mResumed = false;
+
if (mCountdownTimer != null) {
mCountdownTimer.cancel();
mCountdownTimer = null;
@@ -276,6 +279,7 @@
@Override
public void onResume(int reason) {
+ mResumed = true;
}
@Override
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java
index 3cfd6a9..0ec0bf0 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java
@@ -1,9 +1,15 @@
package com.android.keyguard;
+import android.content.ContentResolver;
import android.content.Context;
+import android.database.ContentObserver;
import android.graphics.Paint;
import android.graphics.Paint.Style;
+import android.os.Handler;
+import android.os.Looper;
+import android.provider.Settings;
import android.util.AttributeSet;
+import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
@@ -12,6 +18,7 @@
import androidx.annotation.VisibleForTesting;
+import com.android.keyguard.clock.BubbleClockController;
import com.android.systemui.Dependency;
import com.android.systemui.plugins.ClockPlugin;
import com.android.systemui.statusbar.StatusBarState;
@@ -19,13 +26,19 @@
import com.android.systemui.statusbar.policy.ExtensionController;
import com.android.systemui.statusbar.policy.ExtensionController.Extension;
+import java.util.Objects;
import java.util.TimeZone;
import java.util.function.Consumer;
+import java.util.function.Supplier;
/**
* Switch to show plugin clock when plugin is connected, otherwise it will show default clock.
*/
public class KeyguardClockSwitch extends RelativeLayout {
+
+ private LayoutInflater mLayoutInflater;
+
+ private final ContentResolver mContentResolver;
/**
* Optional/alternative clock injected via plugin.
*/
@@ -79,12 +92,25 @@
}
};
+ private final ContentObserver mContentObserver =
+ new ContentObserver(new Handler(Looper.getMainLooper())) {
+ @Override
+ public void onChange(boolean selfChange) {
+ super.onChange(selfChange);
+ if (mClockExtension != null) {
+ mClockExtension.reload();
+ }
+ }
+ };
+
public KeyguardClockSwitch(Context context) {
this(context, null);
}
public KeyguardClockSwitch(Context context, AttributeSet attrs) {
super(context, attrs);
+ mLayoutInflater = LayoutInflater.from(context);
+ mContentResolver = context.getContentResolver();
}
/**
@@ -108,7 +134,22 @@
mClockExtension = Dependency.get(ExtensionController.class).newExtension(ClockPlugin.class)
.withPlugin(ClockPlugin.class)
.withCallback(mClockPluginConsumer)
+ // Using withDefault even though this isn't the default as a workaround.
+ // ExtensionBulider doesn't provide the ability to supply a ClockPlugin
+ // instance based off of the value of a setting. Since multiple "default"
+ // can be provided, using a supplier that changes the settings value.
+ // A null return will cause Extension#reload to look at the next "default"
+ // supplier.
+ .withDefault(
+ new SettingsGattedSupplier(
+ mContentResolver,
+ Settings.Secure.LOCK_SCREEN_CUSTOM_CLOCK_FACE,
+ BubbleClockController.class.getName(),
+ () -> BubbleClockController.build(mLayoutInflater)))
.build();
+ mContentResolver.registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_CUSTOM_CLOCK_FACE),
+ false, mContentObserver);
Dependency.get(StatusBarStateController.class).addCallback(mStateListener);
}
@@ -116,6 +157,7 @@
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
mClockExtension.destroy();
+ mContentResolver.unregisterContentObserver(mContentObserver);
Dependency.get(StatusBarStateController.class).removeCallback(mStateListener);
}
@@ -269,4 +311,44 @@
StatusBarStateController.StateListener getStateListener() {
return mStateListener;
}
+
+ /**
+ * Supplier that only gets an instance when a settings value matches expected value.
+ */
+ private static class SettingsGattedSupplier implements Supplier<ClockPlugin> {
+
+ private final ContentResolver mContentResolver;
+ private final String mKey;
+ private final String mValue;
+ private final Supplier<ClockPlugin> mSupplier;
+
+ /**
+ * Constructs a supplier that changes secure setting key against value.
+ *
+ * @param contentResolver Used to look up settings value.
+ * @param key Settings key.
+ * @param value If the setting matches this values that get supplies a ClockPlugin
+ * instance.
+ * @param supplier Supplier of ClockPlugin instance, only used if the setting
+ * matches value.
+ */
+ SettingsGattedSupplier(ContentResolver contentResolver, String key, String value,
+ Supplier<ClockPlugin> supplier) {
+ mContentResolver = contentResolver;
+ mKey = key;
+ mValue = value;
+ mSupplier = supplier;
+ }
+
+ /**
+ * Returns null if the settings value doesn't match the expected value.
+ *
+ * A null return causes Extension#reload to skip this supplier and move to the next.
+ */
+ @Override
+ public ClockPlugin get() {
+ final String currentValue = Settings.Secure.getString(mContentResolver, mKey);
+ return Objects.equals(currentValue, mValue) ? mSupplier.get() : null;
+ }
+ }
}
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java
index 41afa9a..3296c10 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java
@@ -81,6 +81,11 @@
protected void resetState() {
mSecurityMessageDisplay.setMessage("");
final boolean wasDisabled = mPasswordEntry.isEnabled();
+ // Don't set enabled password entry & showSoftInput when PasswordEntry is invisible or in
+ // pausing stage.
+ if (!mResumed || !mPasswordEntry.isVisibleToUser()) {
+ return;
+ }
setPasswordEntryEnabled(true);
setPasswordEntryInputEnabled(true);
if (wasDisabled) {
diff --git a/packages/SystemUI/src/com/android/keyguard/clock/BubbleClockController.java b/packages/SystemUI/src/com/android/keyguard/clock/BubbleClockController.java
new file mode 100644
index 0000000..db6127f
--- /dev/null
+++ b/packages/SystemUI/src/com/android/keyguard/clock/BubbleClockController.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.keyguard.clock;
+
+import android.graphics.Paint.Style;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.TextClock;
+
+import com.android.keyguard.R;
+import com.android.systemui.plugins.ClockPlugin;
+
+import java.util.TimeZone;
+
+/**
+ * Controller for Bubble clock that can appear on lock screen and AOD.
+ */
+public class BubbleClockController implements ClockPlugin {
+
+ /**
+ * Custom clock shown on AOD screen and behind stack scroller on lock.
+ */
+ private View mView;
+ private TextClock mDigitalClock;
+ private ImageClock mAnalogClock;
+
+ /**
+ * Small clock shown on lock screen above stack scroller.
+ */
+ private View mLockClockContainer;
+ private TextClock mLockClock;
+
+ /**
+ * Controller for transition to dark state.
+ */
+ private CrossFadeDarkController mDarkController;
+
+ private BubbleClockController() { }
+
+ /**
+ * Create a BubbleClockController instance.
+ *
+ * @param layoutInflater Inflater used to inflate custom clock views.
+ */
+ public static BubbleClockController build(LayoutInflater layoutInflater) {
+ BubbleClockController controller = new BubbleClockController();
+ controller.createViews(layoutInflater);
+ return controller;
+ }
+
+ private void createViews(LayoutInflater layoutInflater) {
+ mView = layoutInflater.inflate(R.layout.bubble_clock, null);
+ mDigitalClock = (TextClock) mView.findViewById(R.id.digital_clock);
+ mAnalogClock = (ImageClock) mView.findViewById(R.id.analog_clock);
+
+ mLockClockContainer = layoutInflater.inflate(R.layout.digital_clock, null);
+ mLockClock = (TextClock) mLockClockContainer.findViewById(R.id.lock_screen_clock);
+ mLockClock.setVisibility(View.GONE);
+
+ mDarkController = new CrossFadeDarkController(mDigitalClock, mLockClock);
+ }
+
+ @Override
+ public View getView() {
+ return mLockClockContainer;
+ }
+
+ @Override
+ public View getBigClockView() {
+ return mView;
+ }
+
+ @Override
+ public void setStyle(Style style) {}
+
+ @Override
+ public void setTextColor(int color) {
+ mLockClock.setTextColor(color);
+ mDigitalClock.setTextColor(color);
+ }
+
+ @Override
+ public void dozeTimeTick() {
+ mAnalogClock.onTimeChanged();
+ }
+
+ @Override
+ public void setDarkAmount(float darkAmount) {
+ mDarkController.setDarkAmount(darkAmount);
+ }
+
+ @Override
+ public void onTimeZoneChanged(TimeZone timeZone) {
+ mAnalogClock.onTimeZoneChanged(timeZone);
+ }
+
+ @Override
+ public boolean shouldShowStatusArea() {
+ return false;
+ }
+}
diff --git a/packages/SystemUI/src/com/android/keyguard/clock/ClockLayout.java b/packages/SystemUI/src/com/android/keyguard/clock/ClockLayout.java
new file mode 100644
index 0000000..5aa5668
--- /dev/null
+++ b/packages/SystemUI/src/com/android/keyguard/clock/ClockLayout.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.keyguard.clock;
+
+import static com.android.systemui.doze.util.BurnInHelperKt.getBurnInOffset;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.FrameLayout;
+
+import com.android.keyguard.R;
+
+/**
+ * Positions clock faces (analog, digital, typographic) and handles pixel shifting
+ * to prevent screen burn-in.
+ */
+public class ClockLayout extends FrameLayout {
+
+ /**
+ * Clock face views.
+ */
+ private View mDigitalClock;
+ private View mAnalogClock;
+
+ /**
+ * Pixel shifting amplitidues used to prevent screen burn-in.
+ */
+ private int mBurnInPreventionOffsetX;
+ private int mBurnInPreventionOffsetY;
+
+ public ClockLayout(Context context) {
+ this(context, null);
+ }
+
+ public ClockLayout(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public ClockLayout(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+ mDigitalClock = findViewById(R.id.digital_clock);
+ mAnalogClock = findViewById(R.id.analog_clock);
+
+ // Get pixel shifting X, Y amplitudes from resources.
+ Resources resources = getResources();
+ mBurnInPreventionOffsetX = resources.getDimensionPixelSize(
+ R.dimen.burn_in_prevention_offset_x);
+ mBurnInPreventionOffsetY = resources.getDimensionPixelSize(
+ R.dimen.burn_in_prevention_offset_y);
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ super.onLayout(changed, left, top, right, bottom);
+
+ final float offsetX = getBurnInOffset(mBurnInPreventionOffsetX, true);
+ final float offsetY = getBurnInOffset(mBurnInPreventionOffsetY, false);
+
+ // Put digital clock in two left corner of the screen.
+ if (mDigitalClock != null) {
+ mDigitalClock.setX(0.1f * getWidth() + offsetX);
+ mDigitalClock.setY(0.1f * getHeight() + offsetY);
+ }
+
+ // Put the analog clock in the middle of the screen.
+ if (mAnalogClock != null) {
+ mAnalogClock.setX(Math.max(0f, 0.5f * (getWidth() - mAnalogClock.getWidth()))
+ + offsetX);
+ mAnalogClock.setY(Math.max(0f, 0.5f * (getHeight() - mAnalogClock.getHeight()))
+ + offsetY);
+ }
+ }
+}
diff --git a/packages/SystemUI/src/com/android/keyguard/clock/CrossFadeDarkController.java b/packages/SystemUI/src/com/android/keyguard/clock/CrossFadeDarkController.java
new file mode 100644
index 0000000..3c3f475
--- /dev/null
+++ b/packages/SystemUI/src/com/android/keyguard/clock/CrossFadeDarkController.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.keyguard.clock;
+
+import android.view.View;
+
+/**
+ * Controls transition to dark state by cross fading between views.
+ */
+final class CrossFadeDarkController {
+
+ private final View mFadeInView;
+ private final View mFadeOutView;
+
+ /**
+ * Creates a new controller that fades between views.
+ *
+ * @param fadeInView View to fade in when transitioning to AOD.
+ * @param fadeOutView View to fade out when transitioning to AOD.
+ */
+ CrossFadeDarkController(View fadeInView, View fadeOutView) {
+ mFadeInView = fadeInView;
+ mFadeOutView = fadeOutView;
+ }
+
+ /**
+ * Sets the amount the system has transitioned to the dark state.
+ *
+ * @param darkAmount Amount of transition to dark state: 1f for AOD and 0f for lock screen.
+ */
+ void setDarkAmount(float darkAmount) {
+ mFadeInView.setAlpha(Math.max(0f, 2f * darkAmount - 1f));
+ if (darkAmount == 0f) {
+ mFadeInView.setVisibility(View.GONE);
+ } else {
+ if (mFadeInView.getVisibility() == View.GONE) {
+ mFadeInView.setVisibility(View.VISIBLE);
+ }
+ }
+ mFadeOutView.setAlpha(Math.max(0f, 1f - 2f * darkAmount));
+ if (darkAmount == 1f) {
+ mFadeOutView.setVisibility(View.GONE);
+ } else {
+ if (mFadeOutView.getVisibility() == View.GONE) {
+ mFadeOutView.setVisibility(View.VISIBLE);
+ }
+ }
+ }
+}
diff --git a/packages/SystemUI/src/com/android/keyguard/clock/ImageClock.java b/packages/SystemUI/src/com/android/keyguard/clock/ImageClock.java
new file mode 100644
index 0000000..2c709e0
--- /dev/null
+++ b/packages/SystemUI/src/com/android/keyguard/clock/ImageClock.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.keyguard.clock;
+
+import android.content.Context;
+import android.text.format.DateFormat;
+import android.util.AttributeSet;
+import android.widget.FrameLayout;
+import android.widget.ImageView;
+
+import com.android.keyguard.R;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+/**
+ * Clock composed of two images that rotate with the time.
+ *
+ * The images are the clock hands. ImageClock expects two child ImageViews
+ * with ids hour_hand and minute_hand.
+ */
+public class ImageClock extends FrameLayout {
+
+ private ImageView mHourHand;
+ private ImageView mMinuteHand;
+ private Calendar mTime;
+ private String mDescFormat;
+ private TimeZone mTimeZone;
+
+ public ImageClock(Context context) {
+ this(context, null);
+ }
+
+ public ImageClock(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public ImageClock(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ mTime = Calendar.getInstance();
+ mDescFormat = ((SimpleDateFormat) DateFormat.getTimeFormat(context)).toLocalizedPattern();
+ }
+
+ /**
+ * Call when the time changes to update the rotation of the clock hands.
+ */
+ public void onTimeChanged() {
+ mTime.setTimeInMillis(System.currentTimeMillis());
+ final float hourAngle = mTime.get(Calendar.HOUR) * 30f;
+ mHourHand.setRotation(hourAngle);
+ final float minuteAngle = mTime.get(Calendar.MINUTE) * 6f;
+ mMinuteHand.setRotation(minuteAngle);
+ setContentDescription(DateFormat.format(mDescFormat, mTime));
+ invalidate();
+ }
+
+ /**
+ * Call when the time zone has changed to update clock hands.
+ *
+ * @param timeZone The updated time zone that will be used.
+ */
+ public void onTimeZoneChanged(TimeZone timeZone) {
+ mTimeZone = timeZone;
+ mTime.setTimeZone(timeZone);
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+ mHourHand = findViewById(R.id.hour_hand);
+ mMinuteHand = findViewById(R.id.minute_hand);
+ }
+
+ @Override
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ mTime = Calendar.getInstance(mTimeZone != null ? mTimeZone : TimeZone.getDefault());
+ onTimeChanged();
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java
index d7bf77d..957d772 100644
--- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java
+++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java
@@ -284,8 +284,9 @@
@Nullable
private PendingIntent getAppOverlayIntent(NotificationEntry notif) {
Notification notification = notif.notification.getNotification();
- if (canLaunchInActivityView(notification.getAppOverlayIntent())) {
- return notification.getAppOverlayIntent();
+ if (canLaunchInActivityView(notification.getBubbleMetadata() != null
+ ? notification.getBubbleMetadata().getIntent() : null)) {
+ return notification.getBubbleMetadata().getIntent();
} else if (shouldUseContentIntent(mContext)
&& canLaunchInActivityView(notification.contentIntent)) {
Log.d(TAG, "[addBubble " + notif.key
@@ -446,15 +447,16 @@
StatusBarNotification n = entry.notification;
boolean canAppOverlay = false;
try {
- canAppOverlay = mNotificationManagerService.areAppOverlaysAllowedForPackage(
+ canAppOverlay = mNotificationManagerService.areBubblesAllowedForPackage(
n.getPackageName(), n.getUid());
} catch (RemoteException e) {
Log.w(TAG, "Error calling NoMan to determine if app can overlay", e);
}
boolean canChannelOverlay = mNotificationEntryManager.getNotificationData().getChannel(
- entry.key).canOverlayApps();
- boolean hasOverlayIntent = n.getNotification().getAppOverlayIntent() != null;
+ entry.key).canBubble();
+ boolean hasOverlayIntent = n.getNotification().getBubbleMetadata() != null
+ && n.getNotification().getBubbleMetadata().getIntent() != null;
return hasOverlayIntent && canChannelOverlay && canAppOverlay;
}
diff --git a/packages/SystemUI/src/com/android/systemui/privacy/OngoingPrivacyDialog.kt b/packages/SystemUI/src/com/android/systemui/privacy/OngoingPrivacyDialog.kt
index 6ed1eba..77e25e3 100644
--- a/packages/SystemUI/src/com/android/systemui/privacy/OngoingPrivacyDialog.kt
+++ b/packages/SystemUI/src/com/android/systemui/privacy/OngoingPrivacyDialog.kt
@@ -20,6 +20,7 @@
import android.content.DialogInterface
import android.content.Intent
import android.content.res.ColorStateList
+import android.util.IconDrawableFactory
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
@@ -37,11 +38,22 @@
private val iconSize = context.resources.getDimensionPixelSize(
R.dimen.ongoing_appops_dialog_icon_size)
+ private val plusSize = context.resources.getDimensionPixelSize(
+ R.dimen.ongoing_appops_dialog_app_plus_size)
private val iconColor = context.resources.getColor(
com.android.internal.R.color.text_color_primary, context.theme)
+ private val plusColor: Int
private val iconMargin = context.resources.getDimensionPixelSize(
R.dimen.ongoing_appops_dialog_icon_margin)
private val MAX_ITEMS = context.resources.getInteger(R.integer.ongoing_appops_dialog_max_apps)
+ private val iconFactory = IconDrawableFactory.newInstance(context, true)
+
+ init {
+ val a = context.theme.obtainStyledAttributes(
+ intArrayOf(com.android.internal.R.attr.colorAccent))
+ plusColor = a.getColor(0, 0)
+ a.recycle()
+ }
fun createDialog(): Dialog {
val builder = AlertDialog.Builder(context).apply {
@@ -87,9 +99,15 @@
numItems - MAX_ITEMS
)
val overflowPlus = overflow.findViewById(R.id.app_icon) as ImageView
+ val lp = overflowPlus.layoutParams.apply {
+ height = plusSize
+ width = plusSize
+ }
+ overflowPlus.layoutParams = lp
overflowPlus.apply {
- imageTintList = ColorStateList.valueOf(iconColor)
- setImageDrawable(context.getDrawable(R.drawable.plus))
+ val plus = context.getDrawable(R.drawable.plus)
+ imageTintList = ColorStateList.valueOf(plusColor)
+ setImageDrawable(plus)
}
}
@@ -114,7 +132,7 @@
}
app.icon.let {
- appIcon.setImageDrawable(it)
+ appIcon.setImageDrawable(iconFactory.getShadowedIcon(it))
}
appName.text = app.applicationName
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java
index 9422101..f79ad71 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java
@@ -541,7 +541,8 @@
@VisibleForTesting
void doUpdateMobileControllers() {
- List<SubscriptionInfo> subscriptions = mSubscriptionManager.getActiveSubscriptionInfoList();
+ List<SubscriptionInfo> subscriptions = mSubscriptionManager
+ .getActiveSubscriptionInfoList(true);
if (subscriptions == null) {
subscriptions = Collections.emptyList();
}
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/clock/BubbleClockControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/clock/BubbleClockControllerTest.java
new file mode 100644
index 0000000..9e946fa
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/keyguard/clock/BubbleClockControllerTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.keyguard.clock;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.test.suitebuilder.annotation.SmallTest;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper.RunWithLooper;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import com.android.systemui.SysuiTestCase;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper
+public final class BubbleClockControllerTest extends SysuiTestCase {
+
+ private BubbleClockController mClockController;
+
+ @Before
+ public void setUp() {
+ LayoutInflater layoutInflater = LayoutInflater.from(getContext());
+ mClockController = BubbleClockController.build(layoutInflater);
+ }
+
+ @Test
+ public void setDarkAmount_fadeIn() {
+ ViewGroup smallClockFrame = (ViewGroup) mClockController.getView();
+ View smallClock = smallClockFrame.getChildAt(0);
+ // WHEN dark amount is set to AOD
+ mClockController.setDarkAmount(1f);
+ // THEN small clock should not be shown.
+ assertThat(smallClock.getVisibility()).isEqualTo(View.GONE);
+ }
+
+ @Test
+ public void setTextColor_setDigitalClock() {
+ ViewGroup smallClock = (ViewGroup) mClockController.getView();
+ // WHEN text color is set
+ mClockController.setTextColor(42);
+ // THEN child of small clock should have text color set.
+ TextView digitalClock = (TextView) smallClock.getChildAt(0);
+ assertThat(digitalClock.getCurrentTextColor()).isEqualTo(42);
+ }
+}
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/clock/CrossFadeDarkControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/clock/CrossFadeDarkControllerTest.java
new file mode 100644
index 0000000..fd7657f
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/keyguard/clock/CrossFadeDarkControllerTest.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.keyguard.clock;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.test.suitebuilder.annotation.SmallTest;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper.RunWithLooper;
+import android.view.View;
+import android.widget.TextView;
+
+import com.android.systemui.SysuiTestCase;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidTestingRunner.class)
+@RunWithLooper
+public final class CrossFadeDarkControllerTest extends SysuiTestCase {
+
+ private View mViewFadeIn;
+ private View mViewFadeOut;
+ private CrossFadeDarkController mDarkController;
+
+ @Before
+ public void setUp() {
+ mViewFadeIn = new TextView(getContext());
+ mViewFadeIn.setVisibility(View.VISIBLE);
+ mViewFadeIn.setAlpha(1f);
+ mViewFadeOut = new TextView(getContext());
+ mViewFadeOut.setVisibility(View.VISIBLE);
+ mViewFadeOut.setAlpha(1f);
+
+ mDarkController = new CrossFadeDarkController(mViewFadeIn, mViewFadeOut);
+ }
+
+ @Test
+ public void setDarkAmount_fadeIn() {
+ // WHEN dark amount corresponds to AOD
+ mDarkController.setDarkAmount(1f);
+ // THEN fade in view should be faded in and fade out view faded out.
+ assertThat(mViewFadeIn.getAlpha()).isEqualTo(1f);
+ assertThat(mViewFadeIn.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(mViewFadeOut.getAlpha()).isEqualTo(0f);
+ assertThat(mViewFadeOut.getVisibility()).isEqualTo(View.GONE);
+ }
+
+ @Test
+ public void setDarkAmount_fadeOut() {
+ // WHEN dark amount corresponds to lock screen
+ mDarkController.setDarkAmount(0f);
+ // THEN fade out view should bed faded out and fade in view faded in.
+ assertThat(mViewFadeIn.getAlpha()).isEqualTo(0f);
+ assertThat(mViewFadeIn.getVisibility()).isEqualTo(View.GONE);
+ assertThat(mViewFadeOut.getAlpha()).isEqualTo(1f);
+ assertThat(mViewFadeOut.getVisibility()).isEqualTo(View.VISIBLE);
+ }
+
+ @Test
+ public void setDarkAmount_partialFadeIn() {
+ // WHEN dark amount corresponds to a partial transition
+ mDarkController.setDarkAmount(0.9f);
+ // THEN views should have intermediate alpha value.
+ assertThat(mViewFadeIn.getAlpha()).isGreaterThan(0f);
+ assertThat(mViewFadeIn.getAlpha()).isLessThan(1f);
+ assertThat(mViewFadeIn.getVisibility()).isEqualTo(View.VISIBLE);
+ }
+
+ @Test
+ public void setDarkAmount_partialFadeOut() {
+ // WHEN dark amount corresponds to a partial transition
+ mDarkController.setDarkAmount(0.1f);
+ // THEN views should have intermediate alpha value.
+ assertThat(mViewFadeOut.getAlpha()).isGreaterThan(0f);
+ assertThat(mViewFadeOut.getAlpha()).isLessThan(1f);
+ assertThat(mViewFadeOut.getVisibility()).isEqualTo(View.VISIBLE);
+ }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceManagerTest.java
index 4583770..3415c72 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceManagerTest.java
@@ -91,7 +91,7 @@
mMockPm = mock(PackageManager.class);
mMockListener = mock(PluginListener.class);
mMockManager = mock(PluginManagerImpl.class);
- when(mMockManager.getClassLoader(any(), any())).thenReturn(getClass().getClassLoader());
+ when(mMockManager.getClassLoader(any())).thenReturn(getClass().getClassLoader());
mMockEnabler = mock(PluginEnabler.class);
when(mMockManager.getPluginEnabler()).thenReturn(mMockEnabler);
mMockVersionInfo = mock(VersionInfo.class);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginManagerTest.java
index 76e68f1..536c043 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginManagerTest.java
@@ -25,6 +25,7 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.test.suitebuilder.annotation.SmallTest;
@@ -135,9 +136,13 @@
});
resetExceptionHandler();
+ String sourceDir = "myPlugin";
+ ApplicationInfo applicationInfo = new ApplicationInfo();
+ applicationInfo.sourceDir = sourceDir;
+ applicationInfo.packageName = WHITELISTED_PACKAGE;
mPluginManager.addPluginListener("myAction", mMockListener, TestPlugin.class);
- assertNull(mPluginManager.getOneShotPlugin("myPlugin", TestPlugin.class));
- assertNull(mPluginManager.getClassLoader("myPlugin", WHITELISTED_PACKAGE));
+ assertNull(mPluginManager.getOneShotPlugin(sourceDir, TestPlugin.class));
+ assertNull(mPluginManager.getClassLoader(applicationInfo));
}
@Test
@@ -152,9 +157,16 @@
});
resetExceptionHandler();
+ String sourceDir = "myPlugin";
+ ApplicationInfo whiteListedApplicationInfo = new ApplicationInfo();
+ whiteListedApplicationInfo.sourceDir = sourceDir;
+ whiteListedApplicationInfo.packageName = WHITELISTED_PACKAGE;
+ ApplicationInfo invalidApplicationInfo = new ApplicationInfo();
+ invalidApplicationInfo.sourceDir = sourceDir;
+ invalidApplicationInfo.packageName = "com.android.invalidpackage";
mPluginManager.addPluginListener("myAction", mMockListener, TestPlugin.class);
- assertNotNull(mPluginManager.getClassLoader("myPlugin", WHITELISTED_PACKAGE));
- assertNull(mPluginManager.getClassLoader("myPlugin", "com.android.invalidpackage"));
+ assertNotNull(mPluginManager.getClassLoader(whiteListedApplicationInfo));
+ assertNull(mPluginManager.getClassLoader(invalidApplicationInfo));
}
@Test
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java
index 2b13f86..8952594 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java
@@ -27,6 +27,7 @@
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
+import android.graphics.drawable.Icon;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
import android.support.test.InstrumentationRegistry;
@@ -220,8 +221,7 @@
notificationBuilder.setGroup(groupKey);
}
if (isBubble) {
- PendingIntent bubbleIntent = PendingIntent.getActivity(mContext, 0, new Intent(), 0);
- notificationBuilder.setAppOverlayIntent(bubbleIntent);
+ notificationBuilder.setBubbleMetadata(makeBubbleMetadata());
}
return notificationBuilder.build();
}
@@ -282,4 +282,14 @@
mGroupManager.onEntryAdded(entry);
return row;
}
+
+ private Notification.BubbleMetadata makeBubbleMetadata() {
+ PendingIntent bubbleIntent = PendingIntent.getActivity(mContext, 0, new Intent(), 0);
+ return new Notification.BubbleMetadata.Builder()
+ .setIntent(bubbleIntent)
+ .setTitle("bubble title")
+ .setIcon(Icon.createWithResource(mContext, 1))
+ .setDesiredHeight(314)
+ .build();
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerBaseTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerBaseTest.java
index fdbf090..c1f8885 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerBaseTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerBaseTest.java
@@ -182,6 +182,7 @@
subs.add(subscription);
}
when(mMockSm.getActiveSubscriptionInfoList()).thenReturn(subs);
+ when(mMockSm.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(subs);
mNetworkController.doUpdateMobileControllers();
}
diff --git a/packages/WallpaperCropper/Android.mk b/packages/WallpaperCropper/Android.mk
index 848f2bd..2fa1dde 100644
--- a/packages/WallpaperCropper/Android.mk
+++ b/packages/WallpaperCropper/Android.mk
@@ -8,6 +8,7 @@
LOCAL_PACKAGE_NAME := WallpaperCropper
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_CERTIFICATE := platform
+LOCAL_PRODUCT_MODULE := true
LOCAL_PRIVILEGED_MODULE := true
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
diff --git a/packages/WallpaperCropper/CleanSpec.mk b/packages/WallpaperCropper/CleanSpec.mk
new file mode 100644
index 0000000..e6d8d5a
--- /dev/null
+++ b/packages/WallpaperCropper/CleanSpec.mk
@@ -0,0 +1,50 @@
+# Copyright (C) 2019 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# If you don't need to do a full clean build but would like to touch
+# a file or delete some intermediate files, add a clean step to the end
+# of the list. These steps will only be run once, if they haven't been
+# run before.
+#
+# E.g.:
+# $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
+# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
+#
+# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
+# files that are missing or have been moved.
+#
+# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
+# Use $(OUT_DIR) to refer to the "out" directory.
+#
+# If you need to re-do something that's already mentioned, just copy
+# the command and add it to the bottom of the list. E.g., if a change
+# that you made last week required touching a file and a change you
+# made today requires touching the same file, just copy the old
+# touch step and add it to the end of the list.
+#
+# ************************************************
+# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
+# ************************************************
+
+# For example:
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
+#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
+#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/priv-app/WallpaperCropper)
+
+# ************************************************
+# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
+# ************************************************
diff --git a/proto/src/metrics_constants/metrics_constants.proto b/proto/src/metrics_constants/metrics_constants.proto
index 44edb56..bb5d288 100644
--- a/proto/src/metrics_constants/metrics_constants.proto
+++ b/proto/src/metrics_constants/metrics_constants.proto
@@ -6803,6 +6803,15 @@
ACTION_NFC_PAYMENT_ALWAYS_SETTING = 1623;
// ---- End Q Constants, all Q constants go above this line ----
+ // OPEN: Settings > System > Input & Gesture > Skip song gesture
+ // OS: Q
+ SETTINGS_GESTURE_SKIP_SONG = 1624;
+
+ // OPEN: Settings > System > Input & Gesture > Silence gesture
+ // OS: Q
+ SETTINGS_GESTURE_SILENCE = 1625;
+
+ // ---- End Q Constants, all Q constants go above this line ----
// Add new aosp constants above this line.
// END OF AOSP CONSTANTS
}
diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java
index 24fd7b9..ec6d20d 100644
--- a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java
+++ b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java
@@ -701,6 +701,11 @@
public void onBackKeyPressed() {
if (sDebug) Slog.d(TAG, "onBackKeyPressed()");
mUi.hideAll(null);
+ synchronized (mLock) {
+ final AutofillManagerServiceImpl service =
+ getServiceForUserLocked(UserHandle.getCallingUserId());
+ service.onBackKeyPressed();
+ }
}
@Override
diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java
index a6bb049..d037b08 100644
--- a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java
+++ b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java
@@ -187,6 +187,15 @@
}
@GuardedBy("mLock")
+ void onBackKeyPressed() {
+ final RemoteAugmentedAutofillService remoteService =
+ getRemoteAugmentedAutofillServiceLocked();
+ if (remoteService != null) {
+ remoteService.onDestroyAutofillWindowsRequest();
+ }
+ }
+
+ @GuardedBy("mLock")
@Override // from PerUserSystemService
protected boolean updateLocked(boolean disabled) {
destroySessionsLocked();
diff --git a/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java b/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java
index a8ff9b0..5d8d8fa 100644
--- a/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java
+++ b/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java
@@ -109,8 +109,8 @@
/**
* Called by {@link Session} when it's time to destroy all augmented autofill requests.
*/
- public void onDestroyAutofillWindowsRequest(int sessionId) {
- scheduleAsyncRequest((s) -> s.onDestroyFillWindowRequest(sessionId));
+ public void onDestroyAutofillWindowsRequest() {
+ scheduleAsyncRequest((s) -> s.onDestroyAllFillWindowsRequest());
}
// TODO(b/111330312): inline into PendingAutofillRequest if it doesn't have any other subclass
diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java
index cf4963c..a5ef21a 100644
--- a/services/autofill/java/com/android/server/autofill/Session.java
+++ b/services/autofill/java/com/android/server/autofill/Session.java
@@ -2619,7 +2619,7 @@
currentValue);
if (mAugmentedAutofillDestroyer == null) {
- mAugmentedAutofillDestroyer = () -> remoteService.onDestroyAutofillWindowsRequest(id);
+ mAugmentedAutofillDestroyer = () -> remoteService.onDestroyAutofillWindowsRequest();
}
return mAugmentedAutofillDestroyer;
}
diff --git a/services/backup/java/com/android/server/backup/UserBackupManagerService.java b/services/backup/java/com/android/server/backup/UserBackupManagerService.java
index 0412b0f..3a8966a 100644
--- a/services/backup/java/com/android/server/backup/UserBackupManagerService.java
+++ b/services/backup/java/com/android/server/backup/UserBackupManagerService.java
@@ -249,11 +249,11 @@
private final TransportManager mTransportManager;
private final HandlerThread mUserBackupThread;
- private Context mContext;
- private PackageManager mPackageManager;
- private IPackageManager mPackageManagerBinder;
- private IActivityManager mActivityManager;
- private ActivityManagerInternal mActivityManagerInternal;
+ private final Context mContext;
+ private final PackageManager mPackageManager;
+ private final IPackageManager mPackageManagerBinder;
+ private final IActivityManager mActivityManager;
+ private final ActivityManagerInternal mActivityManagerInternal;
private PowerManager mPowerManager;
private final AlarmManager mAlarmManager;
private final IStorageManager mStorageManager;
@@ -1466,11 +1466,7 @@
}
}
if (agent == null) {
- try {
- mActivityManager.clearPendingBackup();
- } catch (RemoteException e) {
- // can't happen - ActivityManager is local
- }
+ mActivityManagerInternal.clearPendingBackup(mUserId);
}
return agent;
}
diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java
index 09aa421..01778cd 100644
--- a/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java
+++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java
@@ -17,6 +17,9 @@
package com.android.server.contentcapture;
import static android.service.contentcapture.ContentCaptureService.setClientState;
+import static android.view.contentcapture.ContentCaptureSession.STATE_DISABLED;
+import static android.view.contentcapture.ContentCaptureSession.STATE_DUPLICATED_ID;
+import static android.view.contentcapture.ContentCaptureSession.STATE_NO_SERVICE;
import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_CONTENT;
import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_DATA;
@@ -39,7 +42,6 @@
import android.service.contentcapture.SnapshotData;
import android.util.ArrayMap;
import android.util.Slog;
-import android.view.contentcapture.ContentCaptureSession;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.os.IResultReceiver;
@@ -165,7 +167,7 @@
if (!isEnabledLocked()) {
// TODO: it would be better to split in differet reasons, like
// STATE_DISABLED_NO_SERVICE and STATE_DISABLED_BY_DEVICE_POLICY
- setClientState(clientReceiver, ContentCaptureSession.STATE_DISABLED_NO_SERVICE,
+ setClientState(clientReceiver, STATE_DISABLED | STATE_NO_SERVICE,
/* binder= */ null);
return;
}
@@ -184,7 +186,7 @@
if (existingSession != null) {
Slog.w(TAG, "startSession(id=" + existingSession + ", token=" + activityToken
+ ": ignoring because it already exists for " + existingSession.mActivityToken);
- setClientState(clientReceiver, ContentCaptureSession.STATE_DISABLED_DUPLICATED_ID,
+ setClientState(clientReceiver, STATE_DISABLED | STATE_DUPLICATED_ID,
/* binder=*/ null);
return;
}
@@ -197,8 +199,7 @@
// TODO(b/119613670): log metrics
Slog.w(TAG, "startSession(id=" + existingSession + ", token=" + activityToken
+ ": ignoring because service is not set");
- // TODO(b/111276913): use a new disabled state?
- setClientState(clientReceiver, ContentCaptureSession.STATE_DISABLED_NO_SERVICE,
+ setClientState(clientReceiver, STATE_DISABLED | STATE_NO_SERVICE,
/* binder= */ null);
return;
}
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index d0666b9..d6f3e2b 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -4879,7 +4879,7 @@
final NetworkCapabilities nc = new NetworkCapabilities(networkCapabilities);
final NetworkAgentInfo nai = new NetworkAgentInfo(messenger, new AsyncChannel(),
new Network(reserveNetId()), new NetworkInfo(networkInfo), lp, nc, currentScore,
- mContext, mTrackerHandler, new NetworkMisc(networkMisc), this);
+ mContext, mTrackerHandler, new NetworkMisc(networkMisc), this, mNetd, mNMS);
// Make sure the network capabilities reflect what the agent info says.
nai.networkCapabilities = mixInCapabilities(nai, nc);
final String extraInfo = networkInfo.getExtraInfo();
diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java
index 869d564..312b83c 100644
--- a/services/core/java/com/android/server/LocationManagerService.java
+++ b/services/core/java/com/android/server/LocationManagerService.java
@@ -1041,12 +1041,13 @@
@Override
public void onSetProperties(ProviderProperties properties) {
- // move calls coming from below LMS onto a different thread to avoid deadlock
- runInternal(() -> {
- synchronized (mLock) {
- mProperties = properties;
- }
- });
+ // because this does not invoke any other methods which might result in calling back
+ // into the location provider, it is safe to run this on the calling thread. it is also
+ // currently necessary to run this on the calling thread to ensure that property changes
+ // are publicly visibly immediately, ie for mock providers which are created.
+ synchronized (mLock) {
+ mProperties = properties;
+ }
}
@GuardedBy("mLock")
diff --git a/services/core/java/com/android/server/NetworkManagementService.java b/services/core/java/com/android/server/NetworkManagementService.java
index b0ca2df..aed0684 100644
--- a/services/core/java/com/android/server/NetworkManagementService.java
+++ b/services/core/java/com/android/server/NetworkManagementService.java
@@ -17,13 +17,11 @@
package com.android.server;
import static android.Manifest.permission.CONNECTIVITY_INTERNAL;
-import static android.Manifest.permission.DUMP;
import static android.Manifest.permission.NETWORK_SETTINGS;
import static android.Manifest.permission.NETWORK_STACK;
import static android.Manifest.permission.SHUTDOWN;
import static android.net.NetworkPolicyManager.FIREWALL_CHAIN_DOZABLE;
import static android.net.NetworkPolicyManager.FIREWALL_CHAIN_NAME_DOZABLE;
-import static android.net.NetworkPolicyManager.FIREWALL_CHAIN_NAME_NONE;
import static android.net.NetworkPolicyManager.FIREWALL_CHAIN_NAME_POWERSAVE;
import static android.net.NetworkPolicyManager.FIREWALL_CHAIN_NAME_STANDBY;
import static android.net.NetworkPolicyManager.FIREWALL_CHAIN_NONE;
@@ -40,6 +38,7 @@
import static android.net.NetworkStats.TAG_NONE;
import static android.net.NetworkStats.UID_ALL;
import static android.net.TrafficStats.UID_TETHERING;
+
import static com.android.server.NetworkManagementService.NetdResponseCode.ClatdStatusResult;
import static com.android.server.NetworkManagementService.NetdResponseCode.InterfaceGetCfgResult;
import static com.android.server.NetworkManagementService.NetdResponseCode.InterfaceListResult;
@@ -53,11 +52,9 @@
import android.annotation.NonNull;
import android.app.ActivityManager;
-import android.content.ContentResolver;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.INetd;
-import android.net.TetherStatsParcel;
import android.net.INetworkManagementEventObserver;
import android.net.ITetheringStatsProvider;
import android.net.InterfaceConfiguration;
@@ -69,18 +66,15 @@
import android.net.NetworkStats;
import android.net.NetworkUtils;
import android.net.RouteInfo;
+import android.net.TetherStatsParcel;
import android.net.UidRange;
-import android.net.UidRangeParcel;
import android.net.util.NetdService;
-import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.os.BatteryStats;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.INetworkActivityListener;
import android.os.INetworkManagementService;
-import android.os.PersistableBundle;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteCallbackList;
@@ -91,12 +85,7 @@
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.Trace;
-import android.provider.Settings;
import android.telephony.DataConnectionRealTimeInfo;
-import android.telephony.PhoneStateListener;
-import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
-import android.text.TextUtils;
import android.util.Log;
import android.util.Slog;
import android.util.SparseBooleanArray;
@@ -110,13 +99,11 @@
import com.android.internal.util.DumpUtils;
import com.android.internal.util.HexDump;
import com.android.internal.util.Preconditions;
-import com.android.server.NativeDaemonConnector.Command;
-import com.android.server.NativeDaemonConnector.SensitiveArg;
+
import com.google.android.collect.Maps;
import java.io.BufferedReader;
import java.io.DataInputStream;
-import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
@@ -124,15 +111,11 @@
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.InterfaceAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.StringTokenizer;
import java.util.concurrent.CountDownLatch;
/**
@@ -2153,28 +2136,6 @@
}
@Override
- public void startClatd(String interfaceName) throws IllegalStateException {
- mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
- try {
- mNetdService.clatdStart(interfaceName);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new IllegalStateException(e);
- }
- }
-
- @Override
- public void stopClatd(String interfaceName) throws IllegalStateException {
- mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
- try {
- mNetdService.clatdStop(interfaceName);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new IllegalStateException(e);
- }
- }
-
- @Override
public void registerNetworkActivityListener(INetworkActivityListener listener) {
mNetworkActivityListeners.register(listener);
}
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 3b08a00..d292783 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -32,6 +32,7 @@
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.pm.ApplicationInfo.HIDDEN_API_ENFORCEMENT_DEFAULT;
import static android.content.pm.PackageManager.GET_PROVIDERS;
+import static android.content.pm.PackageManager.MATCH_ALL;
import static android.content.pm.PackageManager.MATCH_ANY_USER;
import static android.content.pm.PackageManager.MATCH_DEBUG_TRIAGED_MISSING;
import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE;
@@ -318,7 +319,6 @@
import com.android.internal.util.function.QuadFunction;
import com.android.internal.util.function.TriFunction;
import com.android.server.AlarmManagerInternal;
-import com.android.server.appop.AppOpsService;
import com.android.server.AttributeCache;
import com.android.server.DeviceIdleController;
import com.android.server.DisplayThread;
@@ -337,6 +337,7 @@
import com.android.server.Watchdog;
import com.android.server.am.ActivityManagerServiceDumpProcessesProto.UidObserverRegistrationProto;
import com.android.server.am.MemoryStatUtil.MemoryStat;
+import com.android.server.appop.AppOpsService;
import com.android.server.firewall.IntentFirewall;
import com.android.server.job.JobSchedulerInternal;
import com.android.server.pm.Installer;
@@ -658,9 +659,47 @@
/**
* When an app has restrictions on the other apps that can have associations with it,
- * it appears here with a set of the allowed apps.
+ * it appears here with a set of the allowed apps and also track debuggability of the app.
*/
- ArrayMap<String, ArraySet<String>> mAllowedAssociations;
+ ArrayMap<String, PackageAssociationInfo> mAllowedAssociations;
+
+ /**
+ * Tracks association information for a particular package along with debuggability.
+ * <p> Associations for a package A are allowed to package B if B is part of the
+ * allowed associations for A or if A is debuggable.
+ */
+ private final class PackageAssociationInfo {
+ private final String mSourcePackage;
+ private final ArraySet<String> mAllowedPackageAssociations;
+ private boolean mIsDebuggable;
+
+ PackageAssociationInfo(String sourcePackage, ArraySet<String> allowedPackages,
+ boolean isDebuggable) {
+ mSourcePackage = sourcePackage;
+ mAllowedPackageAssociations = allowedPackages;
+ mIsDebuggable = isDebuggable;
+ }
+
+ /**
+ * Returns true if {@code mSourcePackage} is allowed association with
+ * {@code targetPackage}.
+ */
+ boolean isPackageAssociationAllowed(String targetPackage) {
+ return mIsDebuggable || mAllowedPackageAssociations.contains(targetPackage);
+ }
+
+ boolean isDebuggable() {
+ return mIsDebuggable;
+ }
+
+ void setDebuggable(boolean isDebuggable) {
+ mIsDebuggable = isDebuggable;
+ }
+
+ ArraySet<String> getAllowedPackageAssociations() {
+ return mAllowedPackageAssociations;
+ }
+ }
/**
* All of the processes we currently have running organized by pid.
@@ -920,8 +959,8 @@
/**
* Backup/restore process management
*/
- String mBackupAppName = null;
- BackupRecord mBackupTarget = null;
+ @GuardedBy("this")
+ final SparseArray<BackupRecord> mBackupTargets = new SparseArray<>();
final ProviderMap mProviderMap;
@@ -2392,12 +2431,10 @@
* If it does not, give it an empty set.
*/
void requireAllowedAssociationsLocked(String packageName) {
- if (mAllowedAssociations == null) {
- mAllowedAssociations = new ArrayMap<>(
- SystemConfig.getInstance().getAllowedAssociations());
- }
+ ensureAllowedAssociations();
if (mAllowedAssociations.get(packageName) == null) {
- mAllowedAssociations.put(packageName, new ArraySet<>());
+ mAllowedAssociations.put(packageName, new PackageAssociationInfo(packageName,
+ new ArraySet<>(), /* isDebuggable = */ false));
}
}
@@ -2408,10 +2445,7 @@
* association is implicitly allowed.
*/
boolean validateAssociationAllowedLocked(String pkg1, int uid1, String pkg2, int uid2) {
- if (mAllowedAssociations == null) {
- mAllowedAssociations = new ArrayMap<>(
- SystemConfig.getInstance().getAllowedAssociations());
- }
+ ensureAllowedAssociations();
// Interactions with the system uid are always allowed, since that is the core system
// that everyone needs to be able to interact with. Also allow reflexive associations
// within the same uid.
@@ -2419,24 +2453,57 @@
|| UserHandle.getAppId(uid2) == SYSTEM_UID) {
return true;
}
- // We won't allow this association if either pkg1 or pkg2 has a limit on the
- // associations that are allowed with it, and the other package is not explicitly
- // specified as one of those associations.
- ArraySet<String> pkgs = mAllowedAssociations.get(pkg1);
- if (pkgs != null) {
- if (!pkgs.contains(pkg2)) {
- return false;
- }
+
+ // Check for association on both source and target packages.
+ PackageAssociationInfo pai = mAllowedAssociations.get(pkg1);
+ if (pai != null && !pai.isPackageAssociationAllowed(pkg2)) {
+ return false;
}
- pkgs = mAllowedAssociations.get(pkg2);
- if (pkgs != null) {
- return pkgs.contains(pkg1);
+ pai = mAllowedAssociations.get(pkg2);
+ if (pai != null && !pai.isPackageAssociationAllowed(pkg1)) {
+ return false;
}
// If no explicit associations are provided in the manifest, then assume the app is
// allowed associations with any package.
return true;
}
+ /** Sets up allowed associations for system prebuilt packages from system config (if needed). */
+ private void ensureAllowedAssociations() {
+ if (mAllowedAssociations == null) {
+ ArrayMap<String, ArraySet<String>> allowedAssociations =
+ SystemConfig.getInstance().getAllowedAssociations();
+ mAllowedAssociations = new ArrayMap<>(allowedAssociations.size());
+ PackageManagerInternal pm = getPackageManagerInternalLocked();
+ for (int i = 0; i < allowedAssociations.size(); i++) {
+ final String pkg = allowedAssociations.keyAt(i);
+ final ArraySet<String> asc = allowedAssociations.valueAt(i);
+
+ // Query latest debuggable flag from package-manager.
+ boolean isDebuggable = false;
+ try {
+ ApplicationInfo ai = AppGlobals.getPackageManager()
+ .getApplicationInfo(pkg, MATCH_ALL, 0);
+ if (ai != null) {
+ isDebuggable = (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
+ }
+ } catch (RemoteException e) {
+ /* ignore */
+ }
+ mAllowedAssociations.put(pkg, new PackageAssociationInfo(pkg, asc, isDebuggable));
+ }
+ }
+ }
+
+ /** Updates allowed associations for app info (specifically, based on debuggability). */
+ private void updateAssociationForApp(ApplicationInfo appInfo) {
+ ensureAllowedAssociations();
+ PackageAssociationInfo pai = mAllowedAssociations.get(appInfo.packageName);
+ if (pai != null) {
+ pai.setDebuggable((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0);
+ }
+ }
+
@Override
public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
throws RemoteException {
@@ -4365,6 +4432,7 @@
mProcessList.removeProcessLocked(app, false, true, "timeout publishing content providers");
}
+ @GuardedBy("this")
private final void processStartTimedOutLocked(ProcessRecord app) {
final int pid = app.pid;
boolean gone = mPidsSelfLocked.removeIfNoThread(pid);
@@ -4385,7 +4453,8 @@
mBatteryStatsService.removeIsolatedUid(app.uid, app.info.uid);
}
removeLruProcessLocked(app);
- if (mBackupTarget != null && mBackupTarget.app.pid == pid) {
+ final BackupRecord backupTarget = mBackupTargets.get(app.userId);
+ if (backupTarget != null && backupTarget.app.pid == pid) {
Slog.w(TAG, "Unattached app died before backup, skipping");
mHandler.post(new Runnable() {
@Override
@@ -4393,7 +4462,7 @@
try {
IBackupManager bm = IBackupManager.Stub.asInterface(
ServiceManager.getService(Context.BACKUP_SERVICE));
- bm.agentDisconnected(app.info.packageName);
+ bm.agentDisconnectedForUser(app.userId, app.info.packageName);
} catch (RemoteException e) {
// Can't happen; the backup manager is local
}
@@ -4516,6 +4585,7 @@
if (DEBUG_ALL) Slog.v(
TAG, "New app record " + app
+ " thread=" + thread.asBinder() + " pid=" + pid);
+ final BackupRecord backupTarget = mBackupTargets.get(app.userId);
try {
int testMode = ApplicationThreadConstants.DEBUG_OFF;
if (mDebugApp != null && mDebugApp.equals(processName)) {
@@ -4537,11 +4607,11 @@
// If the app is being launched for restore or full backup, set it up specially
boolean isRestrictedBackupMode = false;
- if (mBackupTarget != null && mBackupAppName.equals(processName)) {
- isRestrictedBackupMode = mBackupTarget.appInfo.uid >= FIRST_APPLICATION_UID
- && ((mBackupTarget.backupMode == BackupRecord.RESTORE)
- || (mBackupTarget.backupMode == BackupRecord.RESTORE_FULL)
- || (mBackupTarget.backupMode == BackupRecord.BACKUP_FULL));
+ if (backupTarget != null && backupTarget.appInfo.packageName.equals(processName)) {
+ isRestrictedBackupMode = backupTarget.appInfo.uid >= FIRST_APPLICATION_UID
+ && ((backupTarget.backupMode == BackupRecord.RESTORE)
+ || (backupTarget.backupMode == BackupRecord.RESTORE_FULL)
+ || (backupTarget.backupMode == BackupRecord.BACKUP_FULL));
}
final ActiveInstrumentation instr = app.getActiveInstrumentation();
@@ -4749,15 +4819,15 @@
}
// Check whether the next backup agent is in this process...
- if (!badApp && mBackupTarget != null && mBackupTarget.app == app) {
+ if (!badApp && backupTarget != null && backupTarget.app == app) {
if (DEBUG_BACKUP) Slog.v(TAG_BACKUP,
"New app is backup target, launching agent for " + app);
- notifyPackageUse(mBackupTarget.appInfo.packageName,
+ notifyPackageUse(backupTarget.appInfo.packageName,
PackageManager.NOTIFY_PACKAGE_USE_BACKUP);
try {
- thread.scheduleCreateBackupAgent(mBackupTarget.appInfo,
- compatibilityInfoForPackage(mBackupTarget.appInfo),
- mBackupTarget.backupMode);
+ thread.scheduleCreateBackupAgent(backupTarget.appInfo,
+ compatibilityInfoForPackage(backupTarget.appInfo),
+ backupTarget.backupMode);
} catch (Exception e) {
Slog.wtf(TAG, "Exception thrown creating backup agent in " + app, e);
badApp = true;
@@ -10907,14 +10977,14 @@
void dumpAllowedAssociationsLocked(FileDescriptor fd, PrintWriter pw, String[] args,
int opti, boolean dumpAll, String dumpPackage) {
boolean needSep = false;
- boolean printedAnything = false;
pw.println("ACTIVITY MANAGER ALLOWED ASSOCIATION STATE (dumpsys activity allowed-associations)");
boolean printed = false;
if (mAllowedAssociations != null) {
for (int i = 0; i < mAllowedAssociations.size(); i++) {
final String pkg = mAllowedAssociations.keyAt(i);
- final ArraySet<String> asc = mAllowedAssociations.valueAt(i);
+ final ArraySet<String> asc =
+ mAllowedAssociations.valueAt(i).getAllowedPackageAssociations();
boolean printedHeader = false;
for (int j = 0; j < asc.size(); j++) {
if (dumpPackage == null || pkg.equals(dumpPackage)
@@ -10923,7 +10993,6 @@
pw.println(" Allowed associations (by restricted package):");
printed = true;
needSep = true;
- printedAnything = true;
}
if (!printedHeader) {
pw.print(" * ");
@@ -10935,6 +11004,9 @@
pw.println(asc.valueAt(j));
}
}
+ if (mAllowedAssociations.valueAt(i).isDebuggable()) {
+ pw.println(" (debuggable)");
+ }
}
}
if (!printed) {
@@ -13224,16 +13296,17 @@
app.receivers.clear();
// If the app is undergoing backup, tell the backup manager about it
- if (mBackupTarget != null && app.pid == mBackupTarget.app.pid) {
+ final BackupRecord backupTarget = mBackupTargets.get(app.userId);
+ if (backupTarget != null && app.pid == backupTarget.app.pid) {
if (DEBUG_BACKUP || DEBUG_CLEANUP) Slog.d(TAG_CLEANUP, "App "
- + mBackupTarget.appInfo + " died during backup");
+ + backupTarget.appInfo + " died during backup");
mHandler.post(new Runnable() {
@Override
public void run(){
try {
IBackupManager bm = IBackupManager.Stub.asInterface(
ServiceManager.getService(Context.BACKUP_SERVICE));
- bm.agentDisconnected(app.info.packageName);
+ bm.agentDisconnectedForUser(app.userId, app.info.packageName);
} catch (RemoteException e) {
// can't happen; backup manager is local
}
@@ -13573,7 +13646,11 @@
// instantiated. The backup agent will invoke backupAgentCreated() on the
// activity manager to announce its creation.
public boolean bindBackupAgent(String packageName, int backupMode, int userId) {
- if (DEBUG_BACKUP) Slog.v(TAG, "bindBackupAgent: app=" + packageName + " mode=" + backupMode);
+ if (DEBUG_BACKUP) {
+ Slog.v(TAG, "bindBackupAgent: app=" + packageName + " mode="
+ + backupMode + " userId=" + userId + " callingUid = " + Binder.getCallingUid()
+ + " uid = " + Process.myUid());
+ }
enforceCallingPermission("android.permission.CONFIRM_FULL_BACKUP", "bindBackupAgent");
IPackageManager pm = AppGlobals.getPackageManager();
@@ -13625,10 +13702,10 @@
proc.inFullBackup = true;
}
r.app = proc;
- oldBackupUid = mBackupTarget != null ? mBackupTarget.appInfo.uid : -1;
+ final BackupRecord backupTarget = mBackupTargets.get(userId);
+ oldBackupUid = backupTarget != null ? backupTarget.appInfo.uid : -1;
newBackupUid = proc.inFullBackup ? r.appInfo.uid : -1;
- mBackupTarget = r;
- mBackupAppName = app.packageName;
+ mBackupTargets.put(userId, r);
// Try not to kill the process during backup
updateOomAdjLocked(proc, true);
@@ -13663,14 +13740,14 @@
return true;
}
- @Override
- public void clearPendingBackup() {
- if (DEBUG_BACKUP) Slog.v(TAG_BACKUP, "clearPendingBackup");
- enforceCallingPermission("android.permission.BACKUP", "clearPendingBackup");
+ private void clearPendingBackup(int userId) {
+ if (DEBUG_BACKUP) {
+ Slog.v(TAG_BACKUP, "clearPendingBackup: userId = " + userId + " callingUid = "
+ + Binder.getCallingUid() + " uid = " + Process.myUid());
+ }
synchronized (this) {
- mBackupTarget = null;
- mBackupAppName = null;
+ mBackupTargets.delete(userId);
}
JobSchedulerInternal js = LocalServices.getService(JobSchedulerInternal.class);
@@ -13678,12 +13755,19 @@
}
// A backup agent has just come up
+ @Override
public void backupAgentCreated(String agentPackageName, IBinder agent) {
- if (DEBUG_BACKUP) Slog.v(TAG_BACKUP, "backupAgentCreated: " + agentPackageName
- + " = " + agent);
+ final int callingUserId = UserHandle.getCallingUserId();
+ if (DEBUG_BACKUP) {
+ Slog.v(TAG_BACKUP, "backupAgentCreated: " + agentPackageName + " = " + agent
+ + " callingUserId = " + callingUserId + " callingUid = "
+ + Binder.getCallingUid() + " uid = " + Process.myUid());
+ }
synchronized(this) {
- if (!agentPackageName.equals(mBackupAppName)) {
+ final BackupRecord backupTarget = mBackupTargets.get(callingUserId);
+ String backupAppName = backupTarget == null ? null : backupTarget.appInfo.packageName;
+ if (!agentPackageName.equals(backupAppName)) {
Slog.e(TAG, "Backup agent created for " + agentPackageName + " but not requested!");
return;
}
@@ -13693,7 +13777,7 @@
try {
IBackupManager bm = IBackupManager.Stub.asInterface(
ServiceManager.getService(Context.BACKUP_SERVICE));
- bm.agentConnected(agentPackageName, agent);
+ bm.agentConnectedForUser(callingUserId, agentPackageName, agent);
} catch (RemoteException e) {
// can't happen; the backup manager service is local
} catch (Exception e) {
@@ -13706,7 +13790,12 @@
// done with this agent
public void unbindBackupAgent(ApplicationInfo appInfo) {
- if (DEBUG_BACKUP) Slog.v(TAG_BACKUP, "unbindBackupAgent: " + appInfo);
+ if (DEBUG_BACKUP) {
+ Slog.v(TAG_BACKUP, "unbindBackupAgent: " + appInfo + " appInfo.uid = "
+ + appInfo.uid + " callingUid = " + Binder.getCallingUid() + " uid = "
+ + Process.myUid());
+ }
+
enforceCallingPermission("android.permission.CONFIRM_FULL_BACKUP", "unbindBackupAgent");
if (appInfo == null) {
Slog.w(TAG, "unbind backup agent for null app");
@@ -13715,24 +13804,27 @@
int oldBackupUid;
+ final int userId = UserHandle.getUserId(appInfo.uid);
synchronized(this) {
+ final BackupRecord backupTarget = mBackupTargets.get(userId);
+ String backupAppName = backupTarget == null ? null : backupTarget.appInfo.packageName;
try {
- if (mBackupAppName == null) {
+ if (backupAppName == null) {
Slog.w(TAG, "Unbinding backup agent with no active backup");
return;
}
- if (!mBackupAppName.equals(appInfo.packageName)) {
+ if (!backupAppName.equals(appInfo.packageName)) {
Slog.e(TAG, "Unbind of " + appInfo + " but is not the current backup target");
return;
}
// Not backing this app up any more; reset its OOM adjustment
- final ProcessRecord proc = mBackupTarget.app;
+ final ProcessRecord proc = backupTarget.app;
updateOomAdjLocked(proc, true);
proc.inFullBackup = false;
- oldBackupUid = mBackupTarget != null ? mBackupTarget.appInfo.uid : -1;
+ oldBackupUid = backupTarget != null ? backupTarget.appInfo.uid : -1;
// If the app crashed during backup, 'thread' will be null here
if (proc.thread != null) {
@@ -13745,8 +13837,7 @@
}
}
} finally {
- mBackupTarget = null;
- mBackupAppName = null;
+ mBackupTargets.delete(userId);
}
}
@@ -14497,6 +14588,7 @@
+ " ssp=" + ssp + " data=" + data);
return ActivityManager.BROADCAST_SUCCESS;
}
+ updateAssociationForApp(aInfo);
mAtmInternal.onPackageReplaced(aInfo);
mServices.updateServiceApplicationInfoLocked(aInfo);
sendPackageBroadcastLocked(ApplicationThreadConstants.PACKAGE_REPLACED,
@@ -17771,6 +17863,11 @@
public boolean isAppForeground(int uid) {
return ActivityManagerService.this.isAppForeground(uid);
}
+
+ @Override
+ public void clearPendingBackup(int userId) {
+ ActivityManagerService.this.clearPendingBackup(userId);
+ }
}
long inputDispatchingTimedOut(int pid, final boolean aboveSystem, String reason) {
diff --git a/services/core/java/com/android/server/am/OomAdjuster.java b/services/core/java/com/android/server/am/OomAdjuster.java
index cb4cac9..1f9362e 100644
--- a/services/core/java/com/android/server/am/OomAdjuster.java
+++ b/services/core/java/com/android/server/am/OomAdjuster.java
@@ -1024,7 +1024,8 @@
app.hasStartedServices = false;
app.adjSeq = mAdjSeq;
- if (mService.mBackupTarget != null && app == mService.mBackupTarget.app) {
+ final BackupRecord backupTarget = mService.mBackupTargets.get(app.userId);
+ if (backupTarget != null && app == backupTarget.app) {
// If possible we want to avoid killing apps while they're being backed up
if (adj > ProcessList.BACKUP_APP_ADJ) {
if (DEBUG_BACKUP) Slog.v(TAG_BACKUP, "oom BACKUP_APP_ADJ for " + app);
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index d704a3e..9a4ca1f 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -7824,8 +7824,10 @@
/** see AudioPolicy.setUidDeviceAffinity() */
public int setUidDeviceAffinity(IAudioPolicyCallback pcb, int uid,
- @NonNull int[] deviceTypes,
- @NonNull String[] deviceAddresses) {
+ @NonNull int[] deviceTypes, @NonNull String[] deviceAddresses) {
+ if (DEBUG_AP) {
+ Log.d(TAG, "setUidDeviceAffinity for " + pcb.asBinder() + " uid:" + uid);
+ }
synchronized (mAudioPolicies) {
final AudioPolicyProxy app =
checkUpdateForPolicy(pcb, "Cannot change device affinity in audio policy");
@@ -7835,21 +7837,23 @@
if (!app.hasMixRoutedToDevices(deviceTypes, deviceAddresses)) {
return AudioManager.ERROR;
}
+ return app.setUidDeviceAffinities(uid, deviceTypes, deviceAddresses);
}
- return AudioManager.SUCCESS;
}
/** see AudioPolicy.removeUidDeviceAffinity() */
public int removeUidDeviceAffinity(IAudioPolicyCallback pcb, int uid) {
+ if (DEBUG_AP) {
+ Log.d(TAG, "removeUidDeviceAffinity for " + pcb.asBinder() + " uid:" + uid);
+ }
synchronized (mAudioPolicies) {
final AudioPolicyProxy app =
checkUpdateForPolicy(pcb, "Cannot remove device affinity in audio policy");
if (app == null) {
return AudioManager.ERROR;
}
-
+ return app.removeUidDeviceAffinities(uid);
}
- return AudioManager.SUCCESS;
}
public int setFocusPropertiesForPolicy(int duckingBehavior, IAudioPolicyCallback pcb) {
@@ -8160,27 +8164,41 @@
Binder.restoreCallingIdentity(identity);
}
- void setUidDeviceAffinities(int uid, @NonNull int[] types, @NonNull String[] addresses) {
+ int setUidDeviceAffinities(int uid, @NonNull int[] types, @NonNull String[] addresses) {
final Integer Uid = new Integer(uid);
+ int res;
if (mUidDeviceAffinities.remove(Uid) != null) {
final long identity = Binder.clearCallingIdentity();
- AudioSystem.removeUidDeviceAffinities(uid);
+ res = AudioSystem.removeUidDeviceAffinities(uid);
Binder.restoreCallingIdentity(identity);
+ if (res != AudioSystem.SUCCESS) {
+ Log.e(TAG, "AudioSystem. removeUidDeviceAffinities(" + uid + ") failed, "
+ + " cannot call AudioSystem.setUidDeviceAffinities");
+ return AudioManager.ERROR;
+ }
}
final long identity = Binder.clearCallingIdentity();
- final int res = AudioSystem.setUidDeviceAffinities(uid, types, addresses);
+ res = AudioSystem.setUidDeviceAffinities(uid, types, addresses);
Binder.restoreCallingIdentity(identity);
if (res == AudioSystem.SUCCESS) {
mUidDeviceAffinities.put(Uid, new AudioDeviceArray(types, addresses));
+ return AudioManager.SUCCESS;
}
+ Log.e(TAG, "AudioSystem. setUidDeviceAffinities(" + uid + ") failed");
+ return AudioManager.ERROR;
}
- void removeUidDeviceAffinities(int uid, @NonNull int[] types, @NonNull String[] addresses) {
+ int removeUidDeviceAffinities(int uid) {
if (mUidDeviceAffinities.remove(new Integer(uid)) != null) {
final long identity = Binder.clearCallingIdentity();
- AudioSystem.removeUidDeviceAffinities(uid);
+ final int res = AudioSystem.removeUidDeviceAffinities(uid);
Binder.restoreCallingIdentity(identity);
+ if (res == AudioSystem.SUCCESS) {
+ return AudioManager.SUCCESS;
+ }
}
+ Log.e(TAG, "AudioSystem. removeUidDeviceAffinities failed");
+ return AudioManager.ERROR;
}
};
diff --git a/services/core/java/com/android/server/connectivity/Nat464Xlat.java b/services/core/java/com/android/server/connectivity/Nat464Xlat.java
index 6596d27..9d9b1cf 100644
--- a/services/core/java/com/android/server/connectivity/Nat464Xlat.java
+++ b/services/core/java/com/android/server/connectivity/Nat464Xlat.java
@@ -16,8 +16,9 @@
package com.android.server.connectivity;
-import android.net.InterfaceConfiguration;
import android.net.ConnectivityManager;
+import android.net.INetd;
+import android.net.InterfaceConfiguration;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.NetworkInfo;
@@ -59,6 +60,7 @@
NetworkInfo.State.SUSPENDED,
};
+ private final INetd mNetd;
private final INetworkManagementService mNMService;
// The network we're running on, and its type.
@@ -76,7 +78,8 @@
private String mIface;
private State mState = State.IDLE;
- public Nat464Xlat(INetworkManagementService nmService, NetworkAgentInfo nai) {
+ public Nat464Xlat(NetworkAgentInfo nai, INetd netd, INetworkManagementService nmService) {
+ mNetd = netd;
mNMService = nmService;
mNetwork = nai;
}
@@ -140,7 +143,7 @@
return;
}
try {
- mNMService.startClatd(baseIface);
+ mNetd.clatdStart(baseIface);
} catch(RemoteException|IllegalStateException e) {
Slog.e(TAG, "Error starting clatd on " + baseIface, e);
}
@@ -162,7 +165,7 @@
*/
private void enterStoppingState() {
try {
- mNMService.stopClatd(mBaseIface);
+ mNetd.clatdStop(mBaseIface);
} catch(RemoteException|IllegalStateException e) {
Slog.e(TAG, "Error stopping clatd on " + mBaseIface, e);
}
@@ -204,7 +207,7 @@
Slog.e(TAG, "startClat: Can't start clat on null interface");
return;
}
- // TODO: should we only do this if mNMService.startClatd() succeeds?
+ // TODO: should we only do this if mNetd.clatdStart() succeeds?
Slog.i(TAG, "Starting clatd on " + baseIface);
enterStartingState(baseIface);
}
diff --git a/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java b/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java
index 54c89aa..9ea73fb 100644
--- a/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java
+++ b/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java
@@ -17,6 +17,7 @@
package com.android.server.connectivity;
import android.content.Context;
+import android.net.INetd;
import android.net.INetworkMonitor;
import android.net.LinkProperties;
import android.net.Network;
@@ -239,12 +240,15 @@
private static final String TAG = ConnectivityService.class.getSimpleName();
private static final boolean VDBG = false;
private final ConnectivityService mConnService;
+ private final INetd mNetd;
+ private final INetworkManagementService mNMS;
private final Context mContext;
private final Handler mHandler;
public NetworkAgentInfo(Messenger messenger, AsyncChannel ac, Network net, NetworkInfo info,
LinkProperties lp, NetworkCapabilities nc, int score, Context context, Handler handler,
- NetworkMisc misc, ConnectivityService connService) {
+ NetworkMisc misc, ConnectivityService connService, INetd netd,
+ INetworkManagementService nms) {
this.messenger = messenger;
asyncChannel = ac;
network = net;
@@ -253,6 +257,8 @@
networkCapabilities = nc;
currentScore = score;
mConnService = connService;
+ mNetd = netd;
+ mNMS = nms;
mContext = context;
mHandler = handler;
networkMisc = misc;
@@ -587,18 +593,18 @@
public void updateClat(INetworkManagementService netd) {
if (Nat464Xlat.requiresClat(this)) {
- maybeStartClat(netd);
+ maybeStartClat();
} else {
maybeStopClat();
}
}
/** Ensure clat has started for this network. */
- public void maybeStartClat(INetworkManagementService netd) {
+ public void maybeStartClat() {
if (clatd != null && clatd.isStarted()) {
return;
}
- clatd = new Nat464Xlat(netd, this);
+ clatd = new Nat464Xlat(this, mNetd, mNMS);
clatd.start();
}
diff --git a/services/core/java/com/android/server/content/SyncLogger.java b/services/core/java/com/android/server/content/SyncLogger.java
index 5cbe5b9..fc20ef20 100644
--- a/services/core/java/com/android/server/content/SyncLogger.java
+++ b/services/core/java/com/android/server/content/SyncLogger.java
@@ -16,6 +16,7 @@
package com.android.server.content;
+import android.accounts.Account;
import android.app.job.JobParameters;
import android.os.Build;
import android.os.Environment;
@@ -31,6 +32,8 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.IntPair;
import com.android.server.IoThread;
+import com.android.server.content.SyncManager.ActiveSyncContext;
+import com.android.server.content.SyncStorageEngine.EndPoint;
import libcore.io.IoUtils;
@@ -309,4 +312,20 @@
}
}
}
+
+ static String logSafe(Account account) {
+ return account == null ? "[null]" : account.toSafeString();
+ }
+
+ static String logSafe(EndPoint endPoint) {
+ return endPoint == null ? "[null]" : endPoint.toSafeString();
+ }
+
+ static String logSafe(SyncOperation operation) {
+ return operation == null ? "[null]" : operation.toSafeString();
+ }
+
+ static String logSafe(ActiveSyncContext asc) {
+ return asc == null ? "[null]" : asc.toSafeString();
+ }
}
diff --git a/services/core/java/com/android/server/content/SyncManager.java b/services/core/java/com/android/server/content/SyncManager.java
index 8b93e04..7096477 100644
--- a/services/core/java/com/android/server/content/SyncManager.java
+++ b/services/core/java/com/android/server/content/SyncManager.java
@@ -16,6 +16,8 @@
package com.android.server.content;
+import static com.android.server.content.SyncLogger.logSafe;
+
import android.accounts.Account;
import android.accounts.AccountAndUser;
import android.accounts.AccountManager;
@@ -1140,7 +1142,7 @@
/* ignore - local call */
}
if (checkAccountAccess && !canAccessAccount(account, owningPackage, owningUid)) {
- Log.w(TAG, "Access to " + account + " denied for package "
+ Log.w(TAG, "Access to " + logSafe(account) + " denied for package "
+ owningPackage + " in UID " + syncAdapterInfo.uid);
return AuthorityInfo.SYNCABLE_NO_ACCOUNT_ACCESS;
}
@@ -1474,7 +1476,8 @@
if (!syncOperation.ignoreBackoff()) {
Pair<Long, Long> backoff = mSyncStorageEngine.getBackoff(syncOperation.target);
if (backoff == null) {
- Slog.e(TAG, "Couldn't find backoff values for " + syncOperation.target);
+ Slog.e(TAG, "Couldn't find backoff values for "
+ + logSafe(syncOperation.target));
backoff = new Pair<Long, Long>(SyncStorageEngine.NOT_IN_BACKOFF_MODE,
SyncStorageEngine.NOT_IN_BACKOFF_MODE);
}
@@ -1745,8 +1748,8 @@
scheduleSyncOperationH(operation);
} else {
// Otherwise do not reschedule.
- Log.d(TAG, "not retrying sync operation because the error is a hard error: "
- + operation);
+ Log.e(TAG, "not retrying sync operation because the error is a hard error: "
+ + logSafe(operation));
}
}
@@ -1881,11 +1884,12 @@
sendSyncFinishedOrCanceledMessage(this, result);
}
- public void toString(StringBuilder sb) {
+ public void toString(StringBuilder sb, boolean logSafe) {
sb.append("startTime ").append(mStartTime)
.append(", mTimeoutStartTime ").append(mTimeoutStartTime)
.append(", mHistoryRowId ").append(mHistoryRowId)
- .append(", syncOperation ").append(mSyncOperation);
+ .append(", syncOperation ").append(
+ logSafe ? logSafe(mSyncOperation) : mSyncOperation);
}
public void onServiceConnected(ComponentName name, IBinder service) {
@@ -1947,7 +1951,13 @@
public String toString() {
StringBuilder sb = new StringBuilder();
- toString(sb);
+ toString(sb, false);
+ return sb.toString();
+ }
+
+ public String toSafeString() {
+ StringBuilder sb = new StringBuilder();
+ toString(sb, true);
return sb.toString();
}
@@ -2036,7 +2046,7 @@
int count = 0;
for (SyncOperation op: pendingSyncs) {
if (!op.isPeriodic) {
- pw.println(op.dump(null, false, buckets));
+ pw.println(op.dump(null, false, buckets, /*logSafe=*/ false));
count++;
}
}
@@ -2053,7 +2063,7 @@
int count = 0;
for (SyncOperation op: pendingSyncs) {
if (op.isPeriodic) {
- pw.println(op.dump(null, false, buckets));
+ pw.println(op.dump(null, false, buckets, /*logSafe=*/ false));
count++;
}
}
@@ -2186,7 +2196,7 @@
sb.setLength(0);
pw.print(formatDurationHMS(sb, durationInSeconds));
pw.print(" - ");
- pw.print(activeSyncContext.mSyncOperation.dump(pm, false, buckets));
+ pw.print(activeSyncContext.mSyncOperation.dump(pm, false, buckets, /*logSafe=*/ false));
pw.println();
}
pw.println();
@@ -2974,7 +2984,7 @@
case SyncHandler.MESSAGE_CANCEL:
SyncStorageEngine.EndPoint endpoint = (SyncStorageEngine.EndPoint) msg.obj;
Bundle extras = msg.peekData();
- if (Log.isLoggable(TAG, Log.DEBUG)) {
+ if (isLoggable) {
Log.d(TAG, "handleSyncHandlerMessage: MESSAGE_CANCEL: "
+ endpoint + " bundle: " + extras);
}
@@ -2985,9 +2995,11 @@
SyncFinishedOrCancelledMessagePayload payload =
(SyncFinishedOrCancelledMessagePayload) msg.obj;
if (!isSyncStillActiveH(payload.activeSyncContext)) {
- Log.d(TAG, "handleSyncHandlerMessage: dropping since the "
- + "sync is no longer active: "
- + payload.activeSyncContext);
+ if (isLoggable) {
+ Log.d(TAG, "handleSyncHandlerMessage: dropping since the "
+ + "sync is no longer active: "
+ + payload.activeSyncContext);
+ }
break;
}
if (isLoggable) {
@@ -3002,7 +3014,7 @@
case SyncHandler.MESSAGE_SERVICE_CONNECTED: {
ServiceConnectionData msgData = (ServiceConnectionData) msg.obj;
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ if (isLoggable) {
Log.d(TAG, "handleSyncHandlerMessage: MESSAGE_SERVICE_CONNECTED: "
+ msgData.activeSyncContext);
}
@@ -3018,7 +3030,7 @@
case SyncHandler.MESSAGE_SERVICE_DISCONNECTED: {
final ActiveSyncContext currentSyncContext =
((ServiceConnectionData) msg.obj).activeSyncContext;
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ if (isLoggable) {
Log.d(TAG, "handleSyncHandlerMessage: MESSAGE_SERVICE_DISCONNECTED: "
+ currentSyncContext);
}
@@ -3053,7 +3065,7 @@
case SyncHandler.MESSAGE_MONITOR_SYNC:
ActiveSyncContext monitoredSyncContext = (ActiveSyncContext) msg.obj;
- if (Log.isLoggable(TAG, Log.DEBUG)) {
+ if (isLoggable) {
Log.d(TAG, "handleSyncHandlerMessage: MESSAGE_MONITOR_SYNC: " +
monitoredSyncContext.mSyncOperation.target);
}
@@ -3061,7 +3073,7 @@
if (isSyncNotUsingNetworkH(monitoredSyncContext)) {
Log.w(TAG, String.format(
"Detected sync making no progress for %s. cancelling.",
- monitoredSyncContext));
+ logSafe(monitoredSyncContext)));
SyncJobService.callJobFinished(
monitoredSyncContext.mSyncOperation.jobId, false,
"no network activity");
@@ -3558,7 +3570,8 @@
} catch (RuntimeException exc) {
mLogger.log("Sync failed with RuntimeException: ", exc.toString());
closeActiveSyncContext(activeSyncContext);
- Slog.e(TAG, "Caught RuntimeException while starting the sync " + syncOperation, exc);
+ Slog.e(TAG, "Caught RuntimeException while starting the sync "
+ + logSafe(syncOperation), exc);
}
}
@@ -3658,7 +3671,8 @@
reschedulePeriodicSyncH(syncOperation);
}
} else {
- Log.w(TAG, "failed sync operation " + syncOperation + ", " + syncResult);
+ Log.w(TAG, "failed sync operation "
+ + logSafe(syncOperation) + ", " + syncResult);
syncOperation.retries++;
if (syncOperation.retries > mConstants.getMaxRetriesWithAppStandbyExemption()) {
@@ -4042,11 +4056,6 @@
getJobScheduler().cancel(op.jobId);
}
- private void wtfWithLog(String message) {
- Slog.wtf(TAG, message);
- mLogger.log("WTF: ", message);
- }
-
public void resetTodayStats() {
mSyncStorageEngine.resetTodayStats(/*force=*/ true);
}
diff --git a/services/core/java/com/android/server/content/SyncOperation.java b/services/core/java/com/android/server/content/SyncOperation.java
index 25edf40..2abc2e6 100644
--- a/services/core/java/com/android/server/content/SyncOperation.java
+++ b/services/core/java/com/android/server/content/SyncOperation.java
@@ -363,14 +363,19 @@
@Override
public String toString() {
- return dump(null, true, null);
+ return dump(null, true, null, false);
}
- String dump(PackageManager pm, boolean shorter, SyncAdapterStateFetcher appStates) {
+ public String toSafeString() {
+ return dump(null, true, null, true);
+ }
+
+ String dump(PackageManager pm, boolean shorter, SyncAdapterStateFetcher appStates,
+ boolean logSafe) {
StringBuilder sb = new StringBuilder();
sb.append("JobId=").append(jobId)
.append(" ")
- .append(target.account.name)
+ .append(logSafe ? "***" : target.account.name)
.append("/")
.append(target.account.type)
.append(" u")
diff --git a/services/core/java/com/android/server/content/SyncStorageEngine.java b/services/core/java/com/android/server/content/SyncStorageEngine.java
index bfd1791..6b441a0 100644
--- a/services/core/java/com/android/server/content/SyncStorageEngine.java
+++ b/services/core/java/com/android/server/content/SyncStorageEngine.java
@@ -16,6 +16,8 @@
package com.android.server.content;
+import static com.android.server.content.SyncLogger.logSafe;
+
import android.accounts.Account;
import android.accounts.AccountAndUser;
import android.accounts.AccountManager;
@@ -225,6 +227,15 @@
sb.append(":u" + userId);
return sb.toString();
}
+
+ public String toSafeString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(account == null ? "ALL ACCS" : logSafe(account))
+ .append("/")
+ .append(provider == null ? "ALL PDRS" : provider);
+ sb.append(":u" + userId);
+ return sb.toString();
+ }
}
public static class AuthorityInfo {
@@ -1861,8 +1872,8 @@
}
} else {
- Slog.w(TAG, "Failure adding authority: account="
- + accountName + " auth=" + authorityName
+ Slog.w(TAG, "Failure adding authority:"
+ + " auth=" + authorityName
+ " enabled=" + enabled
+ " syncable=" + syncable);
}
diff --git a/services/core/java/com/android/server/display/ColorDisplayService.java b/services/core/java/com/android/server/display/ColorDisplayService.java
index b332c47..2fe17d8 100644
--- a/services/core/java/com/android/server/display/ColorDisplayService.java
+++ b/services/core/java/com/android/server/display/ColorDisplayService.java
@@ -34,8 +34,10 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
+import android.content.res.Resources;
import android.database.ContentObserver;
import android.hardware.display.ColorDisplayManager;
+import android.graphics.ColorSpace;
import android.hardware.display.IColorDisplayManager;
import android.net.Uri;
import android.opengl.Matrix;
@@ -59,6 +61,7 @@
import com.android.server.twilight.TwilightManager;
import com.android.server.twilight.TwilightState;
+import java.io.PrintWriter;
import java.time.DateTimeException;
import java.time.Instant;
import java.time.LocalDateTime;
@@ -148,26 +151,204 @@
};
private final TintController mDisplayWhiteBalanceTintController = new TintController() {
+ // Three chromaticity coordinates per color: X, Y, and Z
+ private final int NUM_VALUES_PER_PRIMARY = 3;
+ // Four colors: red, green, blue, and white
+ private final int NUM_DISPLAY_PRIMARIES_VALS = 4 * NUM_VALUES_PER_PRIMARY;
+ private final Object mLock = new Object();
+ private int mTemperatureMin;
+ private int mTemperatureMax;
+ private int mTemperatureDefault;
+ private float[] mDisplayNominalWhiteXYZ = new float[NUM_VALUES_PER_PRIMARY];
+ private ColorSpace.Rgb mDisplayColorSpaceRGB;
+ private float[] mChromaticAdaptationMatrix;
+ private int mCurrentColorTemperature;
+ private float[] mCurrentColorTemperatureXYZ;
+ private boolean mSetUp = false;
private float[] mMatrixDisplayWhiteBalance = new float[16];
@Override
public void setUp(Context context, boolean needsLinear) {
+ mSetUp = false;
+
+ final Resources res = getContext().getResources();
+ final String[] displayPrimariesValues = res.getStringArray(
+ R.array.config_displayWhiteBalanceDisplayPrimaries);
+ final String[] nominalWhiteValues = res.getStringArray(
+ R.array.config_displayWhiteBalanceDisplayNominalWhite);
+
+ if (displayPrimariesValues.length != NUM_DISPLAY_PRIMARIES_VALS) {
+ Slog.e(TAG, "Unexpected display white balance primaries resource length " +
+ displayPrimariesValues.length);
+ return;
+ }
+
+ if (nominalWhiteValues.length != NUM_VALUES_PER_PRIMARY) {
+ Slog.e(TAG, "Unexpected display white balance nominal white resource length " +
+ nominalWhiteValues.length);
+ return;
+ }
+
+ float[] displayRedGreenBlueXYZ =
+ new float[NUM_DISPLAY_PRIMARIES_VALS - NUM_VALUES_PER_PRIMARY];
+ float[] displayWhiteXYZ = new float[NUM_VALUES_PER_PRIMARY];
+ for (int i = 0; i < displayRedGreenBlueXYZ.length; i++) {
+ displayRedGreenBlueXYZ[i] = Float.parseFloat(displayPrimariesValues[i]);
+ }
+ for (int i = 0; i < displayWhiteXYZ.length; i++) {
+ displayWhiteXYZ[i] = Float.parseFloat(
+ displayPrimariesValues[displayRedGreenBlueXYZ.length + i]);
+ }
+
+ final ColorSpace.Rgb displayColorSpaceRGB = new ColorSpace.Rgb(
+ "Display Color Space",
+ displayRedGreenBlueXYZ,
+ displayWhiteXYZ,
+ 2.2f // gamma, unused for display white balance
+ );
+
+ float[] displayNominalWhiteXYZ = new float[NUM_VALUES_PER_PRIMARY];
+ for (int i = 0; i < nominalWhiteValues.length; i++) {
+ displayNominalWhiteXYZ[i] = Float.parseFloat(nominalWhiteValues[i]);
+ }
+
+ final int colorTemperatureMin = res.getInteger(
+ R.integer.config_displayWhiteBalanceColorTemperatureMin);
+ if (colorTemperatureMin <= 0) {
+ Slog.e(TAG, "display white balance minimum temperature must be greater than 0");
+ return;
+ }
+
+ final int colorTemperatureMax = res.getInteger(
+ R.integer.config_displayWhiteBalanceColorTemperatureMax);
+ if (colorTemperatureMax < colorTemperatureMin) {
+ Slog.e(TAG, "display white balance max temp must be greater or equal to min");
+ return;
+ }
+
+ final int colorTemperature = res.getInteger(
+ R.integer.config_displayWhiteBalanceColorTemperatureDefault);
+
+ synchronized (mLock) {
+ mDisplayColorSpaceRGB = displayColorSpaceRGB;
+ mDisplayNominalWhiteXYZ = displayNominalWhiteXYZ;
+ mTemperatureMin = colorTemperatureMin;
+ mTemperatureMax = colorTemperatureMax;
+ mTemperatureDefault = colorTemperature;
+ mSetUp = true;
+ }
+
+ setMatrix(mTemperatureDefault);
}
@Override
public float[] getMatrix() {
- return isActivated() ? mMatrixDisplayWhiteBalance : MATRIX_IDENTITY;
+ return mSetUp && isActivated() ? mMatrixDisplayWhiteBalance : MATRIX_IDENTITY;
}
@Override
public void setMatrix(int cct) {
+ if (!mSetUp) {
+ Slog.w(TAG, "Can't set display white balance temperature: uninitialized");
+ return;
+ }
+
+ if (cct < mTemperatureMin) {
+ Slog.w(TAG, "Requested display color temperature is below allowed minimum");
+ cct = mTemperatureMin;
+ } else if (cct > mTemperatureMax) {
+ Slog.w(TAG, "Requested display color temperature is above allowed maximum");
+ cct = mTemperatureMax;
+ }
+
+ Slog.d(TAG, "setDisplayWhiteBalanceTemperatureMatrix: cct = " + cct);
+
+ synchronized (mLock) {
+ mCurrentColorTemperature = cct;
+
+ // Adapt the display's nominal white point to match the requested CCT value
+ mCurrentColorTemperatureXYZ = ColorSpace.cctToIlluminantdXyz(cct);
+
+ mChromaticAdaptationMatrix =
+ ColorSpace.chromaticAdaptation(ColorSpace.Adaptation.BRADFORD,
+ mDisplayNominalWhiteXYZ, mCurrentColorTemperatureXYZ);
+
+ // Convert the adaptation matrix to RGB space
+ float[] result = ColorSpace.mul3x3(mChromaticAdaptationMatrix,
+ mDisplayColorSpaceRGB.getTransform());
+ result = ColorSpace.mul3x3(mDisplayColorSpaceRGB.getInverseTransform(), result);
+
+ // Normalize the transform matrix to peak white value in RGB space
+ final float adaptedMaxR = result[0] + result[3] + result[6];
+ final float adaptedMaxG = result[1] + result[4] + result[7];
+ final float adaptedMaxB = result[2] + result[5] + result[8];
+ final float denum = Math.max(Math.max(adaptedMaxR, adaptedMaxG), adaptedMaxB);
+ for (int i = 0; i < result.length; i++) {
+ result[i] /= denum;
+ }
+
+ Matrix.setIdentityM(mMatrixDisplayWhiteBalance, 0);
+ java.lang.System.arraycopy(result, 0, mMatrixDisplayWhiteBalance, 0, 3);
+ java.lang.System.arraycopy(result, 3, mMatrixDisplayWhiteBalance, 4, 3);
+ java.lang.System.arraycopy(result, 6, mMatrixDisplayWhiteBalance, 8, 3);
+ }
}
@Override
public int getLevel() {
return LEVEL_COLOR_MATRIX_DISPLAY_WHITE_BALANCE;
}
+
+ /**
+ * Format a given matrix into a string.
+ *
+ * @param matrix the matrix to format
+ * @param cols number of columns in the matrix
+ */
+ private String matrixToString(float[] matrix, int cols) {
+ if (matrix == null || cols <= 0) {
+ Slog.e(TAG, "Invalid arguments when formatting matrix to string");
+ return "";
+ }
+
+ StringBuilder sb = new StringBuilder("");
+ for (int i = 0; i < matrix.length; i++) {
+ if (i % cols == 0) {
+ sb.append("\n ");
+ }
+ sb.append(String.format("%9.6f ", matrix[i]));
+ }
+ return sb.toString();
+ }
+
+ @Override
+ public void dump(PrintWriter pw) {
+ synchronized (mLock) {
+ pw.println("ColorDisplayService");
+ pw.println(" mSetUp = " + mSetUp);
+
+ if (!mSetUp) {
+ return;
+ }
+
+ pw.println(" isActivated = " + isActivated());
+ pw.println(" mTemperatureMin = " + mTemperatureMin);
+ pw.println(" mTemperatureMax = " + mTemperatureMax);
+ pw.println(" mTemperatureDefault = " + mTemperatureDefault);
+ pw.println(" mCurrentColorTemperature = " + mCurrentColorTemperature);
+ pw.println(" mCurrentColorTemperatureXYZ = " +
+ matrixToString(mCurrentColorTemperatureXYZ, 3));
+ pw.println(" mDisplayColorSpaceRGB RGB-to-XYZ = " +
+ matrixToString(mDisplayColorSpaceRGB.getTransform(), 3));
+ pw.println(" mChromaticAdaptationMatrix = " +
+ matrixToString(mChromaticAdaptationMatrix, 3));
+ pw.println(" mDisplayColorSpaceRGB XYZ-to-RGB = " +
+ matrixToString(mDisplayColorSpaceRGB.getInverseTransform(), 3));
+ pw.println(" mMatrixDisplayWhiteBalance = " +
+ matrixToString(mMatrixDisplayWhiteBalance, 4));
+ }
+ }
};
private final TintController mGlobalSaturationTintController = new TintController() {
@@ -230,8 +411,6 @@
private NightDisplayAutoMode mNightDisplayAutoMode;
- private Integer mDisplayWhiteBalanceColorTemperature;
-
public ColorDisplayService(Context context) {
super(context);
mHandler = new TintHandler(Looper.getMainLooper());
@@ -363,7 +542,7 @@
onAccessibilityTransformChanged();
break;
case Secure.DISPLAY_WHITE_BALANCE_ENABLED:
- onDisplayWhiteBalanceEnabled(isDisplayWhiteBalanceSettingEnabled());
+ updateDisplayWhiteBalanceStatus();
break;
}
}
@@ -416,14 +595,9 @@
if (ColorDisplayManager.isDisplayWhiteBalanceAvailable(getContext())) {
// Prepare the display white balance transform matrix.
- mDisplayWhiteBalanceTintController
- .setUp(getContext(), DisplayTransformManager.needsLinearColorMatrix());
- if (mDisplayWhiteBalanceColorTemperature != null) {
- mDisplayWhiteBalanceTintController
- .setMatrix(mDisplayWhiteBalanceColorTemperature);
- }
+ mDisplayWhiteBalanceTintController.setUp(getContext(), true /* needsLinear */);
- onDisplayWhiteBalanceEnabled(isDisplayWhiteBalanceSettingEnabled());
+ updateDisplayWhiteBalanceStatus();
}
}
@@ -460,6 +634,8 @@
mNightDisplayAutoMode.onActivated(activated);
}
+ updateDisplayWhiteBalanceStatus();
+
applyTint(mNightDisplayTintController, false);
}
}
@@ -516,11 +692,7 @@
.setUp(getContext(), DisplayTransformManager.needsLinearColorMatrix(mode));
mNightDisplayTintController.setMatrix(mNightDisplayController.getColorTemperature());
- mDisplayWhiteBalanceTintController
- .setUp(getContext(), DisplayTransformManager.needsLinearColorMatrix(mode));
- if (mDisplayWhiteBalanceColorTemperature != null) {
- mDisplayWhiteBalanceTintController.setMatrix(mDisplayWhiteBalanceColorTemperature);
- }
+ updateDisplayWhiteBalanceStatus();
final DisplayTransformManager dtm = getLocalService(DisplayTransformManager.class);
dtm.setColorMode(mode, mNightDisplayTintController.getMatrix());
@@ -611,10 +783,15 @@
return ldt.isBefore(compareTime) ? ldt.plusDays(1) : ldt;
}
- private void onDisplayWhiteBalanceEnabled(boolean enabled) {
- mDisplayWhiteBalanceTintController.setActivated(enabled);
- if (mDisplayWhiteBalanceListener != null) {
- mDisplayWhiteBalanceListener.onDisplayWhiteBalanceStatusChanged(enabled);
+ private void updateDisplayWhiteBalanceStatus() {
+ boolean oldActivated = mDisplayWhiteBalanceTintController.isActivated();
+ mDisplayWhiteBalanceTintController.setActivated(isDisplayWhiteBalanceSettingEnabled() &&
+ !mNightDisplayTintController.isActivated() &&
+ DisplayTransformManager.needsLinearColorMatrix());
+ boolean activated = mDisplayWhiteBalanceTintController.isActivated();
+
+ if (mDisplayWhiteBalanceListener != null && oldActivated != activated) {
+ mDisplayWhiteBalanceListener.onDisplayWhiteBalanceStatusChanged(activated);
}
}
@@ -896,6 +1073,12 @@
}
/**
+ * Dump debug information.
+ */
+ public void dump(PrintWriter pw) {
+ }
+
+ /**
* Set up any constants needed for computing the matrix.
*/
public abstract void setUp(Context context, boolean needsLinear);
@@ -929,11 +1112,10 @@
*/
public boolean setDisplayWhiteBalanceColorTemperature(int cct) {
// Update the transform matrix even if it can't be applied.
- mDisplayWhiteBalanceColorTemperature = cct;
mDisplayWhiteBalanceTintController.setMatrix(cct);
if (mDisplayWhiteBalanceTintController.isActivated()) {
- applyTint(mDisplayWhiteBalanceTintController, true);
+ applyTint(mDisplayWhiteBalanceTintController, false);
return true;
}
return false;
@@ -946,6 +1128,10 @@
mDisplayWhiteBalanceListener = listener;
return mDisplayWhiteBalanceTintController.isActivated();
}
+
+ public void dump(PrintWriter pw) {
+ mDisplayWhiteBalanceTintController.dump(pw);
+ }
}
/**
diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java
index 4a17c65..cb3f91b 100644
--- a/services/core/java/com/android/server/display/DisplayManagerService.java
+++ b/services/core/java/com/android/server/display/DisplayManagerService.java
@@ -95,6 +95,7 @@
import com.android.server.UiThread;
import com.android.server.wm.SurfaceAnimationThread;
import com.android.server.wm.WindowManagerInternal;
+import com.android.server.display.ColorDisplayService.ColorDisplayServiceInternal;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -791,6 +792,16 @@
}
}
+ private void setVirtualDisplayStateInternal(IBinder appToken, boolean isOn) {
+ synchronized (mSyncRoot) {
+ if (mVirtualDisplayAdapter == null) {
+ return;
+ }
+
+ mVirtualDisplayAdapter.setVirtualDisplayStateLocked(appToken, isOn);
+ }
+ }
+
private void registerDefaultDisplayAdapters() {
// Register default display adapters.
synchronized (mSyncRoot) {
@@ -1459,6 +1470,13 @@
pw.println();
mPersistentDataStore.dump(pw);
+
+ final ColorDisplayServiceInternal cds = LocalServices.getService(
+ ColorDisplayServiceInternal.class);
+ if (cds != null) {
+ pw.println();
+ cds.dump(pw);
+ }
}
}
@@ -1922,6 +1940,16 @@
}
@Override // Binder call
+ public void setVirtualDisplayState(IVirtualDisplayCallback callback, boolean isOn) {
+ final long token = Binder.clearCallingIdentity();
+ try {
+ setVirtualDisplayStateInternal(callback.asBinder(), isOn);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ @Override // Binder call
public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
diff --git a/services/core/java/com/android/server/display/VirtualDisplayAdapter.java b/services/core/java/com/android/server/display/VirtualDisplayAdapter.java
index 5aa585f..1ca8dd3 100644
--- a/services/core/java/com/android/server/display/VirtualDisplayAdapter.java
+++ b/services/core/java/com/android/server/display/VirtualDisplayAdapter.java
@@ -147,6 +147,13 @@
return device;
}
+ void setVirtualDisplayStateLocked(IBinder appToken, boolean isOn) {
+ VirtualDisplayDevice device = mVirtualDisplayDevices.get(appToken);
+ if (device != null) {
+ device.setDisplayState(isOn);
+ }
+ }
+
/**
* Returns the next unique index for the uniqueIdPrefix
*/
@@ -206,6 +213,7 @@
private int mPendingChanges;
private int mUniqueIndex;
private Display.Mode mMode;
+ private boolean mIsDisplayOn;
public VirtualDisplayDevice(IBinder displayToken, IBinder appToken,
int ownerUid, String ownerPackageName,
@@ -226,6 +234,7 @@
mDisplayState = Display.STATE_UNKNOWN;
mPendingChanges |= PENDING_SURFACE_CHANGE;
mUniqueIndex = uniqueIndex;
+ mIsDisplayOn = surface != null;
}
@Override
@@ -304,6 +313,14 @@
}
}
+ void setDisplayState(boolean isOn) {
+ if (mIsDisplayOn != isOn) {
+ mIsDisplayOn = isOn;
+ mInfo = null;
+ sendDisplayDeviceEventLocked(this, DISPLAY_DEVICE_EVENT_CHANGED);
+ }
+ }
+
public void stopLocked() {
setSurfaceLocked(null);
mStopped = true;
@@ -375,7 +392,9 @@
mInfo.type = Display.TYPE_VIRTUAL;
mInfo.touch = ((mFlags & VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH) == 0) ?
DisplayDeviceInfo.TOUCH_NONE : DisplayDeviceInfo.TOUCH_VIRTUAL;
- mInfo.state = mSurface != null ? Display.STATE_ON : Display.STATE_OFF;
+
+ mInfo.state = mIsDisplayOn ? Display.STATE_ON : Display.STATE_OFF;
+
mInfo.ownerUid = mOwnerUid;
mInfo.ownerPackageName = mOwnerPackageName;
}
diff --git a/services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java b/services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java
index ba21b78..d137580 100755
--- a/services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java
+++ b/services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java
@@ -16,6 +16,7 @@
package com.android.server.hdmi;
+import android.hardware.hdmi.HdmiControlManager;
import android.hardware.hdmi.HdmiDeviceInfo;
import android.util.Slog;
@@ -51,6 +52,10 @@
private static final int STATE_WAITING_FOR_OSD_NAME = 3;
// State in which the action is waiting for gathering vendor id of non-local devices.
private static final int STATE_WAITING_FOR_VENDOR_ID = 4;
+ // State in which the action is waiting for devices to be ready.
+ private static final int STATE_WAITING_FOR_DEVICES = 5;
+ // State in which the action is waiting for gathering power status of non-local devices.
+ private static final int STATE_WAITING_FOR_POWER = 6;
/**
* Interface used to report result of device discovery.
@@ -72,6 +77,7 @@
private int mPhysicalAddress = Constants.INVALID_PHYSICAL_ADDRESS;
private int mPortId = Constants.INVALID_PORT_ID;
private int mVendorId = Constants.UNKNOWN_VENDOR_ID;
+ private int mPowerStatus = HdmiControlManager.POWER_STATUS_UNKNOWN;
private String mDisplayName = "";
private int mDeviceType = HdmiDeviceInfo.DEVICE_INACTIVE;
@@ -81,7 +87,7 @@
private HdmiDeviceInfo toHdmiDeviceInfo() {
return new HdmiDeviceInfo(mLogicalAddress, mPhysicalAddress, mPortId, mDeviceType,
- mVendorId, mDisplayName);
+ mVendorId, mDisplayName, mPowerStatus);
}
}
@@ -89,7 +95,20 @@
private final DeviceDiscoveryCallback mCallback;
private int mProcessedDeviceCount = 0;
private int mTimeoutRetry = 0;
- private boolean mIsTvDevice = source().mService.isTvDevice();
+ private boolean mIsTvDevice = localDevice().mService.isTvDevice();
+ private final int mDelayPeriod;
+
+ /**
+ * Constructor.
+ *
+ * @param source an instance of {@link HdmiCecLocalDevice}.
+ * @param delay delay action for this period between query Physical Address and polling
+ */
+ DeviceDiscoveryAction(HdmiCecLocalDevice source, DeviceDiscoveryCallback callback, int delay) {
+ super(source);
+ mCallback = Preconditions.checkNotNull(callback);
+ mDelayPeriod = delay;
+ }
/**
* Constructor.
@@ -97,8 +116,7 @@
* @param source an instance of {@link HdmiCecLocalDevice}.
*/
DeviceDiscoveryAction(HdmiCecLocalDevice source, DeviceDiscoveryCallback callback) {
- super(source);
- mCallback = Preconditions.checkNotNull(callback);
+ this(source, callback, 0);
}
@Override
@@ -117,7 +135,11 @@
Slog.v(TAG, "Device detected: " + ackedAddress);
allocateDevices(ackedAddress);
- startPhysicalAddressStage();
+ if (mDelayPeriod > 0) {
+ startToDelayAction();
+ } else {
+ startPhysicalAddressStage();
+ }
}
}, Constants.POLL_ITERATION_REVERSE_ORDER
| Constants.POLL_STRATEGY_REMOTES_DEVICES, HdmiConfig.DEVICE_POLLING_RETRY);
@@ -131,6 +153,13 @@
}
}
+ private void startToDelayAction() {
+ Slog.v(TAG, "Waiting for connected devices to be ready");
+ mState = STATE_WAITING_FOR_DEVICES;
+
+ checkAndProceedStage();
+ }
+
private void startPhysicalAddressStage() {
Slog.v(TAG, "Start [Physical Address Stage]:" + mDevices.size());
mProcessedDeviceCount = 0;
@@ -159,6 +188,11 @@
addTimer(mState, HdmiConfig.TIMEOUT_MS);
}
+ private void delayActionWithTimePeriod(int timeDelay) {
+ mActionTimer.clearTimerMessage();
+ addTimer(mState, timeDelay);
+ }
+
private void startOsdNameStage() {
Slog.v(TAG, "Start [Osd Name Stage]:" + mDevices.size());
mProcessedDeviceCount = 0;
@@ -207,6 +241,29 @@
addTimer(mState, HdmiConfig.TIMEOUT_MS);
}
+ private void startPowerStatusStage() {
+ Slog.v(TAG, "Start [Power Status Stage]:" + mDevices.size());
+ mProcessedDeviceCount = 0;
+ mState = STATE_WAITING_FOR_POWER;
+
+ checkAndProceedStage();
+ }
+
+ private void queryPowerStatus(int address) {
+ if (!verifyValidLogicalAddress(address)) {
+ checkAndProceedStage();
+ return;
+ }
+
+ mActionTimer.clearTimerMessage();
+
+ if (mayProcessMessageIfCached(address, Constants.MESSAGE_REPORT_POWER_STATUS)) {
+ return;
+ }
+ sendCommand(HdmiCecMessageBuilder.buildGiveDevicePowerStatus(getSourceAddress(), address));
+ addTimer(mState, HdmiConfig.TIMEOUT_MS);
+ }
+
private boolean mayProcessMessageIfCached(int address, int opcode) {
HdmiCecMessage message = getCecMessageCache().getMessage(address, opcode);
if (message != null) {
@@ -245,6 +302,16 @@
return true;
}
return false;
+ case STATE_WAITING_FOR_POWER:
+ if (cmd.getOpcode() == Constants.MESSAGE_REPORT_POWER_STATUS) {
+ handleReportPowerStatus(cmd);
+ return true;
+ } else if ((cmd.getOpcode() == Constants.MESSAGE_FEATURE_ABORT)
+ && ((cmd.getParams()[0] & 0xFF) == Constants.MESSAGE_REPORT_POWER_STATUS)) {
+ handleReportPowerStatus(cmd);
+ return true;
+ }
+ return false;
case STATE_WAITING_FOR_DEVICE_POLLING:
// Fall through.
default:
@@ -329,6 +396,26 @@
checkAndProceedStage();
}
+ private void handleReportPowerStatus(HdmiCecMessage cmd) {
+ Preconditions.checkState(mProcessedDeviceCount < mDevices.size());
+
+ DeviceInfo current = mDevices.get(mProcessedDeviceCount);
+ if (current.mLogicalAddress != cmd.getSource()) {
+ Slog.w(TAG, "Unmatched address[expected:" + current.mLogicalAddress + ", actual:"
+ + cmd.getSource());
+ return;
+ }
+
+ if (cmd.getOpcode() != Constants.MESSAGE_FEATURE_ABORT) {
+ byte[] params = cmd.getParams();
+ int powerStatus = params[0] & 0xFF;
+ current.mPowerStatus = powerStatus;
+ }
+
+ increaseProcessedDeviceCount();
+ checkAndProceedStage();
+ }
+
private void increaseProcessedDeviceCount() {
mProcessedDeviceCount++;
mTimeoutRetry = 0;
@@ -372,6 +459,9 @@
startVendorIdStage();
return;
case STATE_WAITING_FOR_VENDOR_ID:
+ startPowerStatusStage();
+ return;
+ case STATE_WAITING_FOR_POWER:
wrapUpAndFinish();
return;
default:
@@ -385,6 +475,9 @@
private void sendQueryCommand() {
int address = mDevices.get(mProcessedDeviceCount).mLogicalAddress;
switch (mState) {
+ case STATE_WAITING_FOR_DEVICES:
+ delayActionWithTimePeriod(mDelayPeriod);
+ return;
case STATE_WAITING_FOR_PHYSICAL_ADDRESS:
queryPhysicalAddress(address);
return;
@@ -394,6 +487,9 @@
case STATE_WAITING_FOR_VENDOR_ID:
queryVendorId(address);
return;
+ case STATE_WAITING_FOR_POWER:
+ queryPowerStatus(address);
+ return;
default:
return;
}
@@ -405,13 +501,21 @@
return;
}
+ if (mState == STATE_WAITING_FOR_DEVICES) {
+ startPhysicalAddressStage();
+ return;
+ }
if (++mTimeoutRetry < HdmiConfig.TIMEOUT_RETRY) {
sendQueryCommand();
return;
}
mTimeoutRetry = 0;
Slog.v(TAG, "Timeout[State=" + mState + ", Processed=" + mProcessedDeviceCount);
- removeDevice(mProcessedDeviceCount);
+ if (mState != STATE_WAITING_FOR_POWER) {
+ removeDevice(mProcessedDeviceCount);
+ } else {
+ increaseProcessedDeviceCount();
+ }
checkAndProceedStage();
}
}
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecController.java b/services/core/java/com/android/server/hdmi/HdmiCecController.java
index e777ce8..86be585 100644
--- a/services/core/java/com/android/server/hdmi/HdmiCecController.java
+++ b/services/core/java/com/android/server/hdmi/HdmiCecController.java
@@ -77,7 +77,7 @@
private static final int NUM_LOGICAL_ADDRESS = 16;
- private static final int MAX_CEC_MESSAGE_HISTORY = 20;
+ private static final int MAX_CEC_MESSAGE_HISTORY = 200;
// Predicate for whether the given logical address is remote device's one or not.
private final Predicate<Integer> mRemoteDeviceAddressPredicate = new Predicate<Integer>() {
@@ -682,7 +682,7 @@
void dump(final IndentingPrintWriter pw) {
for (int i = 0; i < mLocalDevices.size(); ++i) {
- pw.println("HdmiCecLocalDevice #" + i + ":");
+ pw.println("HdmiCecLocalDevice #" + mLocalDevices.keyAt(i) + ":");
pw.increaseIndent();
mLocalDevices.valueAt(i).dump(pw);
pw.decreaseIndent();
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceAudioSystem.java b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceAudioSystem.java
index 0e4e334..1029a0d 100644
--- a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceAudioSystem.java
+++ b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceAudioSystem.java
@@ -26,22 +26,30 @@
import android.hardware.hdmi.HdmiPortInfo;
import android.hardware.hdmi.IHdmiControlCallback;
import android.media.AudioDeviceInfo;
+import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioSystem;
import android.media.tv.TvContract;
import android.os.SystemProperties;
+import android.provider.Settings.Global;
import android.util.Slog;
import android.util.SparseArray;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.util.IndentingPrintWriter;
import com.android.server.hdmi.Constants.AudioCodec;
import com.android.server.hdmi.DeviceDiscoveryAction.DeviceDiscoveryCallback;
import com.android.server.hdmi.HdmiAnnotations.ServiceThreadOnly;
import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
+import java.util.stream.Collectors;
+
/**
* Represent a logical device of type {@link HdmiDeviceInfo#DEVICE_AUDIO_SYSTEM} residing in Android
@@ -77,23 +85,24 @@
// processing.
private final HashMap<Integer, String> mTvInputs = new HashMap<>();
+ // Copy of mDeviceInfos to guarantee thread-safety.
+ @GuardedBy("mLock")
+ private List<HdmiDeviceInfo> mSafeAllDeviceInfos = Collections.emptyList();
+
// Map-like container of all cec devices.
// device id is used as key of container.
private final SparseArray<HdmiDeviceInfo> mDeviceInfos = new SparseArray<>();
protected HdmiCecLocalDeviceAudioSystem(HdmiControlService service) {
super(service, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM);
- mSystemAudioControlFeatureEnabled = true;
- // TODO(amyjojo) make System Audio Control controllable by users
- /*mSystemAudioControlFeatureEnabled =
- mService.readBooleanSetting(Global.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED, true);*/
- // TODO(amyjojo): make the map ro property.
- mTvInputs.put(Constants.CEC_SWITCH_HDMI1,
- "com.droidlogic.tvinput/.services.Hdmi1InputService/HW5");
- mTvInputs.put(Constants.CEC_SWITCH_HDMI2,
- "com.droidlogic.tvinput/.services.Hdmi2InputService/HW6");
- mTvInputs.put(Constants.CEC_SWITCH_HDMI3,
- "com.droidlogic.tvinput/.services.Hdmi3InputService/HW7");
+ mRoutingControlFeatureEnabled =
+ mService.readBooleanSetting(Global.HDMI_CEC_SWITCH_ENABLED, false);
+ mSystemAudioControlFeatureEnabled =
+ mService.readBooleanSetting(Global.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED, true);
+ // TODO(amyjojo): Maintain a portId to TvinputId map.
+ mTvInputs.put(2, "com.droidlogic.tvinput/.services.Hdmi1InputService/HW5");
+ mTvInputs.put(4, "com.droidlogic.tvinput/.services.Hdmi2InputService/HW6");
+ mTvInputs.put(1, "com.droidlogic.tvinput/.services.Hdmi3InputService/HW7");
}
/**
@@ -167,6 +176,7 @@
removeDeviceInfo(deviceInfo.getId());
}
mDeviceInfos.append(deviceInfo.getId(), deviceInfo);
+ updateSafeDeviceInfoList();
return oldDeviceInfo;
}
@@ -184,6 +194,7 @@
if (deviceInfo != null) {
mDeviceInfos.remove(id);
}
+ updateSafeDeviceInfoList();
return deviceInfo;
}
@@ -200,6 +211,24 @@
return mDeviceInfos.get(HdmiDeviceInfo.idForCecDevice(logicalAddress));
}
+ @ServiceThreadOnly
+ private void updateSafeDeviceInfoList() {
+ assertRunOnServiceThread();
+ List<HdmiDeviceInfo> copiedDevices = HdmiUtils.sparseArrayToList(mDeviceInfos);
+ synchronized (mLock) {
+ mSafeAllDeviceInfos = copiedDevices;
+ }
+ }
+
+ @GuardedBy("mLock")
+ List<HdmiDeviceInfo> getSafeCecDevicesLocked() {
+ ArrayList<HdmiDeviceInfo> infoList = new ArrayList<>();
+ for (HdmiDeviceInfo info : mSafeAllDeviceInfos) {
+ infoList.add(info);
+ }
+ return infoList;
+ }
+
private void invokeDeviceEventListener(HdmiDeviceInfo info, int status) {
mService.invokeDeviceEventListeners(info, status);
}
@@ -267,7 +296,7 @@
int systemAudioOnPowerOnProp, boolean lastSystemAudioControlStatus) {
if ((systemAudioOnPowerOnProp == ALWAYS_SYSTEM_AUDIO_CONTROL_ON_POWER_ON)
|| ((systemAudioOnPowerOnProp == USE_LAST_STATE_SYSTEM_AUDIO_CONTROL_ON_POWER_ON)
- && lastSystemAudioControlStatus)) {
+ && lastSystemAudioControlStatus && isSystemAudioControlFeatureEnabled())) {
addAndStartAction(new SystemAudioInitiationActionFromAvr(this));
}
}
@@ -400,8 +429,11 @@
@ServiceThreadOnly
protected boolean handleGiveAudioStatus(HdmiCecMessage message) {
assertRunOnServiceThread();
-
- reportAudioStatus(message);
+ if (isSystemAudioControlFeatureEnabled()) {
+ reportAudioStatus(message.getSource());
+ } else {
+ mService.maySendFeatureAbortCommand(message, Constants.ABORT_REFUSED);
+ }
return true;
}
@@ -478,14 +510,91 @@
private byte[] getSupportedShortAudioDescriptors(
AudioDeviceInfo deviceInfo, @AudioCodec int[] audioFormatCodes) {
- // TODO(b/80297701) implement
- return new byte[] {};
+ ArrayList<byte[]> sads = new ArrayList<>(audioFormatCodes.length);
+ for (@AudioCodec int audioFormatCode : audioFormatCodes) {
+ byte[] sad = getSupportedShortAudioDescriptor(deviceInfo, audioFormatCode);
+ if (sad != null) {
+ if (sad.length == 3) {
+
+ sads.add(sad);
+ } else {
+ HdmiLogger.warning(
+ "Dropping Short Audio Descriptor with length %d for requested codec %x",
+ sad.length, audioFormatCode);
+ }
+ }
+ }
+ // Short Audio Descriptors are always 3 bytes long.
+ byte[] bytes = new byte[sads.size() * 3];
+ int index = 0;
+ for (byte[] sad : sads) {
+ System.arraycopy(sad, 0, bytes, index, 3);
+ index += 3;
+ }
+ return bytes;
+ }
+
+ /**
+ * Returns a 3 byte short audio descriptor as described in CEC 1.4 table 29 or null if the
+ * audioFormatCode is not supported.
+ */
+ @Nullable
+ private byte[] getSupportedShortAudioDescriptor(
+ AudioDeviceInfo deviceInfo, @AudioCodec int audioFormatCode) {
+ switch (audioFormatCode) {
+ case Constants.AUDIO_CODEC_NONE: {
+ return null;
+ }
+ case Constants.AUDIO_CODEC_LPCM: {
+ return getLpcmShortAudioDescriptor(deviceInfo);
+ }
+ // TODO(b/80297701): implement the rest of the codecs
+ case Constants.AUDIO_CODEC_DD:
+ case Constants.AUDIO_CODEC_MPEG1:
+ case Constants.AUDIO_CODEC_MP3:
+ case Constants.AUDIO_CODEC_MPEG2:
+ case Constants.AUDIO_CODEC_AAC:
+ case Constants.AUDIO_CODEC_DTS:
+ case Constants.AUDIO_CODEC_ATRAC:
+ case Constants.AUDIO_CODEC_ONEBITAUDIO:
+ case Constants.AUDIO_CODEC_DDP:
+ case Constants.AUDIO_CODEC_DTSHD:
+ case Constants.AUDIO_CODEC_TRUEHD:
+ case Constants.AUDIO_CODEC_DST:
+ case Constants.AUDIO_CODEC_WMAPRO:
+ default: {
+ return null;
+ }
+ }
+ }
+
+ @Nullable
+ private byte[] getLpcmShortAudioDescriptor(AudioDeviceInfo deviceInfo) {
+ // TODO(b/80297701): implement
+ return null;
}
@Nullable
private AudioDeviceInfo getSystemAudioDeviceInfo() {
- // TODO(b/80297701) implement
- // Get the audio device used for system audio mode.
+ AudioManager audioManager = mService.getContext().getSystemService(AudioManager.class);
+ if (audioManager == null) {
+ HdmiLogger.error(
+ "Error getting system audio device because AudioManager not available.");
+ return null;
+ }
+ AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS);
+ HdmiLogger.debug("Found %d audio input devices", devices.length);
+ for (AudioDeviceInfo device : devices) {
+ HdmiLogger.debug("%s at port %s", device.getProductName(), device.getPort());
+ HdmiLogger.debug("Supported encodings are %s",
+ Arrays.stream(device.getEncodings()).mapToObj(
+ AudioFormat::toLogFriendlyEncoding
+ ).collect(Collectors.joining(", ")));
+ // TODO(b/80297701) use the actual device type that system audio mode is connected to.
+ if (device.getType() == AudioDeviceInfo.TYPE_HDMI_ARC) {
+ return device;
+ }
+ }
return null;
}
@@ -583,17 +692,20 @@
.setWiredDeviceConnectionState(AudioSystem.DEVICE_IN_HDMI, enabled ? 1 : 0, "", "");
}
- private void reportAudioStatus(HdmiCecMessage message) {
+ void reportAudioStatus(int source) {
assertRunOnServiceThread();
int volume = mService.getAudioManager().getStreamVolume(AudioManager.STREAM_MUSIC);
boolean mute = mService.getAudioManager().isStreamMute(AudioManager.STREAM_MUSIC);
int maxVolume = mService.getAudioManager().getStreamMaxVolume(AudioManager.STREAM_MUSIC);
+ int minVolume = mService.getAudioManager().getStreamMinVolume(AudioManager.STREAM_MUSIC);
int scaledVolume = VolumeControlAction.scaleToCecVolume(volume, maxVolume);
+ HdmiLogger.debug("Reporting volume %i (%i-%i) as CEC volume %i", volume,
+ minVolume, maxVolume, scaledVolume);
mService.sendCecCommand(
HdmiCecMessageBuilder.buildReportAudioStatus(
- mAddress, message.getSource(), scaledVolume, mute));
+ mAddress, source, scaledVolume, mute));
}
/**
@@ -633,7 +745,7 @@
*/
private void setSystemAudioMode(boolean newSystemAudioMode) {
int targetPhysicalAddress = getActiveSource().physicalAddress;
- int port = getLocalPortFromPhysicalAddress(targetPhysicalAddress);
+ int port = mService.pathToPortId(targetPhysicalAddress);
if (newSystemAudioMode && port >= 0) {
switchToAudioInput();
}
@@ -641,16 +753,18 @@
// PROPERTY_SYSTEM_AUDIO_MODE_MUTING_ENABLE is false when device never needs to be muted.
boolean currentMuteStatus =
mService.getAudioManager().isStreamMute(AudioManager.STREAM_MUSIC);
- if (SystemProperties.getBoolean(
- Constants.PROPERTY_SYSTEM_AUDIO_MODE_MUTING_ENABLE, true)
- && currentMuteStatus == newSystemAudioMode) {
- mService.getAudioManager()
- .adjustStreamVolume(
- AudioManager.STREAM_MUSIC,
- newSystemAudioMode
- ? AudioManager.ADJUST_UNMUTE
- : AudioManager.ADJUST_MUTE,
- 0);
+ if (currentMuteStatus == newSystemAudioMode) {
+ if (SystemProperties.getBoolean(
+ Constants.PROPERTY_SYSTEM_AUDIO_MODE_MUTING_ENABLE, true)
+ || newSystemAudioMode) {
+ mService.getAudioManager()
+ .adjustStreamVolume(
+ AudioManager.STREAM_MUSIC,
+ newSystemAudioMode
+ ? AudioManager.ADJUST_UNMUTE
+ : AudioManager.ADJUST_MUTE,
+ 0);
+ }
}
updateAudioManagerForSystemAudio(newSystemAudioMode);
synchronized (mLock) {
@@ -688,6 +802,13 @@
HdmiLogger.debug("[A]UpdateSystemAudio mode[on=%b] output=[%X]", on, device);
}
+ void onSystemAduioControlFeatureSupportChanged(boolean enabled) {
+ setSystemAudioControlFeatureEnabled(enabled);
+ if (enabled) {
+ addAndStartAction(new SystemAudioInitiationActionFromAvr(this));
+ }
+ }
+
@ServiceThreadOnly
void setSystemAudioControlFeatureEnabled(boolean enabled) {
assertRunOnServiceThread();
@@ -697,6 +818,14 @@
}
@ServiceThreadOnly
+ void setRoutingControlFeatureEnables(boolean enabled) {
+ assertRunOnServiceThread();
+ synchronized (mLock) {
+ mRoutingControlFeatureEnabled = enabled;
+ }
+ }
+
+ @ServiceThreadOnly
void doManualPortSwitching(int portId, IHdmiControlCallback callback) {
assertRunOnServiceThread();
// TODO: validate port ID
@@ -817,7 +946,7 @@
@Override
protected void switchInputOnReceivingNewActivePath(int physicalAddress) {
- int port = getLocalPortFromPhysicalAddress(physicalAddress);
+ int port = mService.pathToPortId(physicalAddress);
if (isSystemAudioActivated() && port < 0) {
// If system audio mode is on and the new active source is not under the current device,
// Will switch to ARC input.
@@ -831,6 +960,10 @@
}
protected void routeToInputFromPortId(int portId) {
+ if (!isRoutingControlFeatureEnabled()) {
+ HdmiLogger.debug("Routing Control Feature is not enabled.");
+ return;
+ }
if (mArcIntentUsed) {
routeToTvInputFromPortId(portId);
} else {
@@ -885,7 +1018,7 @@
@Override
protected void handleRoutingChangeAndInformation(int physicalAddress, HdmiCecMessage message) {
- int port = getLocalPortFromPhysicalAddress(physicalAddress);
+ int port = mService.pathToPortId(physicalAddress);
// Routing change or information sent from switches under the current device can be ignored.
if (port > 0) {
return;
@@ -954,6 +1087,10 @@
@ServiceThreadOnly
private void launchDeviceDiscovery() {
assertRunOnServiceThread();
+ if (hasAction(DeviceDiscoveryAction.class)) {
+ Slog.i(TAG, "Device Discovery Action is in progress. Restarting.");
+ removeAction(DeviceDiscoveryAction.class);
+ }
DeviceDiscoveryAction action = new DeviceDiscoveryAction(this,
new DeviceDiscoveryCallback() {
@Override
@@ -977,5 +1114,25 @@
invokeDeviceEventListener(info, HdmiControlManager.DEVICE_EVENT_REMOVE_DEVICE);
}
mDeviceInfos.clear();
+ updateSafeDeviceInfoList();
}
+
+ @Override
+ protected void dump(IndentingPrintWriter pw) {
+ pw.println("HdmiCecLocalDeviceAudioSystem:");
+ pw.increaseIndent();
+ pw.println("mSystemAudioActivated: " + mSystemAudioActivated);
+ pw.println("isRoutingFeatureEnabled " + isRoutingControlFeatureEnabled());
+ pw.println("mSystemAudioControlFeatureEnabled: " + mSystemAudioControlFeatureEnabled);
+ pw.println("mTvSystemAudioModeSupport: " + mTvSystemAudioModeSupport);
+ pw.println("mArcEstablished: " + mArcEstablished);
+ pw.println("mArcIntentUsed: " + mArcIntentUsed);
+ pw.println("mRoutingPort: " + getRoutingPort());
+ pw.println("mLocalActivePort: " + getLocalActivePort());
+ HdmiUtils.dumpMap(pw, "mTvInputs:", mTvInputs);
+ HdmiUtils.dumpSparseArray(pw, "mDeviceInfos:", mDeviceInfos);
+ pw.decreaseIndent();
+ super.dump(pw);
+ }
+
}
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceSource.java b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceSource.java
index a95f7f1..83c2fe1 100644
--- a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceSource.java
+++ b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceSource.java
@@ -66,6 +66,10 @@
@LocalActivePort
protected int mLocalActivePort = Constants.CEC_SWITCH_HOME;
+ // Whether the Routing Coutrol feature is enabled or not. False by default.
+ @GuardedBy("mLock")
+ protected boolean mRoutingControlFeatureEnabled;
+
protected HdmiCecLocalDeviceSource(HdmiControlService service, int deviceType) {
super(service, deviceType);
}
@@ -123,7 +127,9 @@
}
setIsActiveSource(physicalAddress == mService.getPhysicalAddress());
updateDevicePowerStatus(logicalAddress, HdmiControlManager.POWER_STATUS_ON);
- switchInputOnReceivingNewActivePath(physicalAddress);
+ if (isRoutingControlFeatureEnabled()) {
+ switchInputOnReceivingNewActivePath(physicalAddress);
+ }
return true;
}
@@ -153,6 +159,10 @@
@ServiceThreadOnly
protected boolean handleRoutingChange(HdmiCecMessage message) {
assertRunOnServiceThread();
+ if (!isRoutingControlFeatureEnabled()) {
+ mService.maySendFeatureAbortCommand(message, Constants.ABORT_REFUSED);
+ return true;
+ }
int newPath = HdmiUtils.twoBytesToInt(message.getParams(), 2);
// if the current device is a pure playback device
if (!mIsSwitchDevice
@@ -168,6 +178,10 @@
@ServiceThreadOnly
protected boolean handleRoutingInformation(HdmiCecMessage message) {
assertRunOnServiceThread();
+ if (!isRoutingControlFeatureEnabled()) {
+ mService.maySendFeatureAbortCommand(message, Constants.ABORT_REFUSED);
+ return true;
+ }
int physicalAddress = HdmiUtils.twoBytesToInt(message.getParams());
// if the current device is a pure playback device
if (!mIsSwitchDevice
@@ -279,6 +293,12 @@
}
}
+ boolean isRoutingControlFeatureEnabled() {
+ synchronized (mLock) {
+ return mRoutingControlFeatureEnabled;
+ }
+ }
+
// Check if the device is trying to switch to the same input that is active right now.
// This can help avoid redundant port switching.
protected boolean isSwitchingToTheSameInput(@LocalActivePort int activePort) {
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecMessage.java b/services/core/java/com/android/server/hdmi/HdmiCecMessage.java
index c005615..f8b3962 100644
--- a/services/core/java/com/android/server/hdmi/HdmiCecMessage.java
+++ b/services/core/java/com/android/server/hdmi/HdmiCecMessage.java
@@ -17,6 +17,7 @@
package com.android.server.hdmi;
import android.annotation.Nullable;
+
import libcore.util.EmptyArray;
import java.util.Arrays;
@@ -111,12 +112,11 @@
@Override
public String toString() {
StringBuffer s = new StringBuffer();
- s.append(String.format("<%s> src: %d, dst: %d",
- opcodeToString(mOpcode), mSource, mDestination));
+ s.append(String.format("<%s> %X%X:%02X",
+ opcodeToString(mOpcode), mSource, mDestination, mOpcode));
if (mParams.length > 0) {
- s.append(", params:");
for (byte data : mParams) {
- s.append(String.format(" %02X", data));
+ s.append(String.format(":%02X", data));
}
}
return s.toString();
@@ -133,7 +133,7 @@
case Constants.MESSAGE_TUNER_STEP_DECREMENT:
return "Tuner Step Decrement";
case Constants.MESSAGE_TUNER_DEVICE_STATUS:
- return "Tuner Device Staus";
+ return "Tuner Device Status";
case Constants.MESSAGE_GIVE_TUNER_DEVICE_STATUS:
return "Give Tuner Device Status";
case Constants.MESSAGE_RECORD_ON:
@@ -207,7 +207,7 @@
case Constants.MESSAGE_DEVICE_VENDOR_ID:
return "Device Vendor Id";
case Constants.MESSAGE_VENDOR_COMMAND:
- return "Vendor Commandn";
+ return "Vendor Command";
case Constants.MESSAGE_VENDOR_REMOTE_BUTTON_DOWN:
return "Vendor Remote Button Down";
case Constants.MESSAGE_VENDOR_REMOTE_BUTTON_UP:
@@ -215,7 +215,7 @@
case Constants.MESSAGE_GIVE_DEVICE_VENDOR_ID:
return "Give Device Vendor Id";
case Constants.MESSAGE_MENU_REQUEST:
- return "Menu REquest";
+ return "Menu Request";
case Constants.MESSAGE_MENU_STATUS:
return "Menu Status";
case Constants.MESSAGE_GIVE_DEVICE_POWER_STATUS:
@@ -247,7 +247,7 @@
case Constants.MESSAGE_SET_EXTERNAL_TIMER:
return "Set External Timer";
case Constants.MESSAGE_REPORT_SHORT_AUDIO_DESCRIPTOR:
- return "Repot Short Audio Descriptor";
+ return "Report Short Audio Descriptor";
case Constants.MESSAGE_REQUEST_SHORT_AUDIO_DESCRIPTOR:
return "Request Short Audio Descriptor";
case Constants.MESSAGE_INITIATE_ARC:
diff --git a/services/core/java/com/android/server/hdmi/HdmiControlService.java b/services/core/java/com/android/server/hdmi/HdmiControlService.java
index 2d6e762..d390d86 100644
--- a/services/core/java/com/android/server/hdmi/HdmiControlService.java
+++ b/services/core/java/com/android/server/hdmi/HdmiControlService.java
@@ -20,12 +20,14 @@
import static android.hardware.hdmi.HdmiControlManager.DEVICE_EVENT_REMOVE_DEVICE;
import static com.android.internal.os.RoSystemProperties.PROPERTY_HDMI_IS_DEVICE_HDMI_CEC_SWITCH;
+import static com.android.server.hdmi.Constants.ADDR_UNREGISTERED;
import static com.android.server.hdmi.Constants.DISABLED;
import static com.android.server.hdmi.Constants.ENABLED;
import static com.android.server.hdmi.Constants.OPTION_MHL_ENABLE;
import static com.android.server.hdmi.Constants.OPTION_MHL_INPUT_SWITCHING;
import static com.android.server.hdmi.Constants.OPTION_MHL_POWER_CHARGE;
import static com.android.server.hdmi.Constants.OPTION_MHL_SERVICE_CONTROL;
+import static com.android.server.power.ShutdownThread.SHUTDOWN_ACTION_PROPERTY;
import android.annotation.Nullable;
import android.content.BroadcastReceiver;
@@ -184,9 +186,10 @@
@Override
public void onReceive(Context context, Intent intent) {
assertRunOnServiceThread();
+ boolean isReboot = SystemProperties.get(SHUTDOWN_ACTION_PROPERTY).contains("1");
switch (intent.getAction()) {
case Intent.ACTION_SCREEN_OFF:
- if (isPowerOnOrTransient()) {
+ if (isPowerOnOrTransient() && !isReboot) {
onStandby(STANDBY_SCREEN_OFF);
}
break;
@@ -202,7 +205,7 @@
}
break;
case Intent.ACTION_SHUTDOWN:
- if (isPowerOnOrTransient()) {
+ if (isPowerOnOrTransient() && !isReboot) {
onStandby(STANDBY_SHUTDOWN);
}
break;
@@ -345,6 +348,10 @@
@Nullable
private Looper mIoLooper;
+ // Thread safe physical address
+ @GuardedBy("mLock")
+ private int mPhysicalAddress = Constants.INVALID_PHYSICAL_ADDRESS;
+
// Last input port before switching to the MHL port. Should switch back to this port
// when the mobile device sends the request one touch play with off.
// Gets invalidated if we go to other port/input.
@@ -564,7 +571,8 @@
Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED,
Global.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED,
Global.MHL_INPUT_SWITCHING_ENABLED,
- Global.MHL_POWER_CHARGE_ENABLED
+ Global.MHL_POWER_CHARGE_ENABLED,
+ Global.HDMI_CEC_SWITCH_ENABLED
};
for (String s : settings) {
resolver.registerContentObserver(Global.getUriFor(s), false, mSettingsObserver,
@@ -605,6 +613,14 @@
if (isTvDeviceEnabled()) {
tv().setSystemAudioControlFeatureEnabled(enabled);
}
+ if (isAudioSystemDevice()) {
+ audioSystem().onSystemAduioControlFeatureSupportChanged(enabled);
+ }
+ break;
+ case Global.HDMI_CEC_SWITCH_ENABLED:
+ if (isAudioSystemDevice()) {
+ audioSystem().setRoutingControlFeatureEnables(enabled);
+ }
break;
case Global.MHL_INPUT_SWITCHING_ENABLED:
setMhlInputChangeEnabled(enabled);
@@ -734,6 +750,10 @@
assertRunOnServiceThread();
HdmiPortInfo[] cecPortInfo = null;
+ synchronized (mLock) {
+ mPhysicalAddress = getPhysicalAddress();
+ }
+
// CEC HAL provides majority of the info while MHL does only MHL support flag for
// each port. Return empty array if CEC HAL didn't provide the info.
if (mCecController != null) {
@@ -1532,6 +1552,14 @@
}
@Override
+ public int getPhysicalAddress() {
+ enforceAccessPermission();
+ synchronized (mLock) {
+ return mPhysicalAddress;
+ }
+ }
+
+ @Override
public void setSystemAudioMode(final boolean enabled, final IHdmiControlCallback callback) {
enforceAccessPermission();
runOnServiceThread(new Runnable() {
@@ -1588,14 +1616,65 @@
public List<HdmiDeviceInfo> getDeviceList() {
enforceAccessPermission();
HdmiCecLocalDeviceTv tv = tv();
- synchronized (mLock) {
- return (tv == null)
+ if (tv != null) {
+ synchronized (mLock) {
+ return tv.getSafeCecDevicesLocked();
+ }
+ } else {
+ HdmiCecLocalDeviceAudioSystem audioSystem = audioSystem();
+ synchronized (mLock) {
+ return (audioSystem == null)
? Collections.<HdmiDeviceInfo>emptyList()
- : tv.getSafeCecDevicesLocked();
+ : audioSystem.getSafeCecDevicesLocked();
+ }
}
}
@Override
+ public void powerOffRemoteDevice(int logicalAddress, int powerStatus) {
+ enforceAccessPermission();
+ runOnServiceThread(new Runnable() {
+ @Override
+ public void run() {
+ if (powerStatus == HdmiControlManager.POWER_STATUS_ON
+ || powerStatus == HdmiControlManager.POWER_STATUS_TRANSIENT_TO_ON) {
+ sendCecCommand(HdmiCecMessageBuilder.buildStandby(
+ getRemoteControlSourceAddress(), logicalAddress));
+ } else {
+ Slog.w(TAG, "Device " + logicalAddress + " is already off " + powerStatus);
+ }
+ }
+ });
+ }
+
+ @Override
+ public void powerOnRemoteDevice(int logicalAddress, int powerStatus) {
+ // TODO(amyjojo): implement the method
+ }
+
+ @Override
+ // TODO(AMYJOJO): add a result callback
+ public void askRemoteDeviceToBecomeActiveSource(int physicalAddress) {
+ enforceAccessPermission();
+ runOnServiceThread(new Runnable() {
+ @Override
+ public void run() {
+ HdmiCecMessage setStreamPath = HdmiCecMessageBuilder.buildSetStreamPath(
+ getRemoteControlSourceAddress(), physicalAddress);
+ if (pathToPortId(physicalAddress) != Constants.INVALID_PORT_ID) {
+ if (getSwitchDevice() != null) {
+ getSwitchDevice().handleSetStreamPath(setStreamPath);
+ } else {
+ Slog.e(TAG, "Can't get the correct local device to handle routing.");
+ }
+ } else {
+ sendCecCommand(setStreamPath);
+ }
+ }
+ });
+ }
+
+ @Override
public void setSystemAudioVolume(final int oldIndex, final int newIndex,
final int maxIndex) {
enforceAccessPermission();
@@ -1834,14 +1913,28 @@
Slog.w(TAG, "audio system is not in system audio mode");
return;
}
- int scaledVolume = VolumeControlAction.scaleToCecVolume(volume, maxVolume);
+ audioSystem().reportAudioStatus(Constants.ADDR_TV);
+ }
+ });
+ }
- sendCecCommand(HdmiCecMessageBuilder
- .buildReportAudioStatus(
- device.getDeviceInfo().getLogicalAddress(),
- Constants.ADDR_TV,
- scaledVolume,
- isMute));
+ @Override
+ public void setSystemAudioModeOnForAudioOnlySource() {
+ enforceAccessPermission();
+ runOnServiceThread(new Runnable() {
+ @Override
+ public void run() {
+ if (!isAudioSystemDevice()) {
+ Slog.e(TAG, "Not an audio system device. Won't set system audio mode on");
+ return;
+ }
+ if (!audioSystem().checkSupportAndSetSystemAudioMode(true)) {
+ Slog.e(TAG, "System Audio Mode is not supported.");
+ return;
+ }
+ sendCecCommand(
+ HdmiCecMessageBuilder.buildSetSystemAudioMode(
+ audioSystem().mAddress, Constants.ADDR_BROADCAST, true));
}
});
}
@@ -1851,30 +1944,54 @@
if (!DumpUtils.checkDumpPermission(getContext(), TAG, writer)) return;
final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
- pw.println("mHdmiControlEnabled: " + mHdmiControlEnabled);
pw.println("mProhibitMode: " + mProhibitMode);
- if (mCecController != null) {
- pw.println("mCecController: ");
- pw.increaseIndent();
- mCecController.dump(pw);
- pw.decreaseIndent();
- }
+ pw.println("mPowerStatus: " + mPowerStatus);
+
+ // System settings
+ pw.println("System_settings:");
+ pw.increaseIndent();
+ pw.println("mHdmiControlEnabled: " + mHdmiControlEnabled);
+ pw.println("mMhlInputChangeEnabled: " + mMhlInputChangeEnabled);
+ pw.decreaseIndent();
pw.println("mMhlController: ");
pw.increaseIndent();
mMhlController.dump(pw);
pw.decreaseIndent();
- pw.println("mPortInfo: ");
- pw.increaseIndent();
- for (HdmiPortInfo hdmiPortInfo : mPortInfo) {
- pw.println("- " + hdmiPortInfo);
+ HdmiUtils.dumpIterable(pw, "mPortInfo:", mPortInfo);
+ if (mCecController != null) {
+ pw.println("mCecController: ");
+ pw.increaseIndent();
+ mCecController.dump(pw);
+ pw.decreaseIndent();
}
- pw.decreaseIndent();
- pw.println("mPowerStatus: " + mPowerStatus);
}
}
+ // Get the source address to send out commands to devices connected to the current device
+ // when other services interact with HdmiControlService.
+ private int getRemoteControlSourceAddress() {
+ if (isAudioSystemDevice()) {
+ return audioSystem().getDeviceInfo().getLogicalAddress();
+ } else if (isPlaybackDevice()) {
+ return playback().getDeviceInfo().getLogicalAddress();
+ }
+ return ADDR_UNREGISTERED;
+ }
+
+ // Get the switch device to do CEC routing control
+ @Nullable
+ private HdmiCecLocalDeviceSource getSwitchDevice() {
+ if (isAudioSystemDevice()) {
+ return audioSystem();
+ }
+ if (isPlaybackDevice()) {
+ return playback();
+ }
+ return null;
+ }
+
@ServiceThreadOnly
private void oneTouchPlay(final IHdmiControlCallback callback) {
assertRunOnServiceThread();
diff --git a/services/core/java/com/android/server/hdmi/HdmiUtils.java b/services/core/java/com/android/server/hdmi/HdmiUtils.java
index 2a8117f..2110682 100644
--- a/services/core/java/com/android/server/hdmi/HdmiUtils.java
+++ b/services/core/java/com/android/server/hdmi/HdmiUtils.java
@@ -20,9 +20,13 @@
import android.util.Slog;
import android.util.SparseArray;
+import com.android.internal.util.IndentingPrintWriter;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
+
/**
* Various utilities to handle HDMI CEC messages.
@@ -317,4 +321,74 @@
info.getPhysicalAddress(), info.getPortId(), info.getDeviceType(),
info.getVendorId(), info.getDisplayName(), newPowerStatus);
}
+
+ /**
+ * Dump a {@link SparseArray} to the print writer.
+ *
+ * <p>The dump is formatted:
+ * <pre>
+ * name:
+ * key = value
+ * key = value
+ * ...
+ * </pre>
+ */
+ static <T> void dumpSparseArray(IndentingPrintWriter pw, String name,
+ SparseArray<T> sparseArray) {
+ printWithTrailingColon(pw, name);
+ pw.increaseIndent();
+ int size = sparseArray.size();
+ for (int i = 0; i < size; i++) {
+ int key = sparseArray.keyAt(i);
+ T value = sparseArray.get(key);
+ pw.printPair(Integer.toString(key), value);
+ pw.println();
+ }
+ pw.decreaseIndent();
+ }
+
+ private static void printWithTrailingColon(IndentingPrintWriter pw, String name) {
+ pw.println(name.endsWith(":") ? name : name.concat(":"));
+ }
+
+ /**
+ * Dump a {@link Map} to the print writer.
+ *
+ * <p>The dump is formatted:
+ * <pre>
+ * name:
+ * key = value
+ * key = value
+ * ...
+ * </pre>
+ */
+ static <K, V> void dumpMap(IndentingPrintWriter pw, String name, Map<K, V> map) {
+ printWithTrailingColon(pw, name);
+ pw.increaseIndent();
+ for (Map.Entry<K, V> entry: map.entrySet()) {
+ pw.printPair(entry.getKey().toString(), entry.getValue());
+ pw.println();
+ }
+ pw.decreaseIndent();
+ }
+
+ /**
+ * Dump a {@link Map} to the print writer.
+ *
+ * <p>The dump is formatted:
+ * <pre>
+ * name:
+ * value
+ * value
+ * ...
+ * </pre>
+ */
+ static <T> void dumpIterable(IndentingPrintWriter pw, String name, Iterable<T> values) {
+ printWithTrailingColon(pw, name);
+ pw.increaseIndent();
+ for (T value : values) {
+ pw.println(value);
+ }
+ pw.decreaseIndent();
+ }
}
diff --git a/services/core/java/com/android/server/hdmi/OneTouchPlayAction.java b/services/core/java/com/android/server/hdmi/OneTouchPlayAction.java
index 41bf01f..d665efe 100644
--- a/services/core/java/com/android/server/hdmi/OneTouchPlayAction.java
+++ b/services/core/java/com/android/server/hdmi/OneTouchPlayAction.java
@@ -92,6 +92,9 @@
if (source.mService.audioSystem() != null) {
source = source.mService.audioSystem();
}
+ if (source.getLocalActivePort() != Constants.CEC_SWITCH_HOME) {
+ source.switchInputOnReceivingNewActivePath(getSourceAddress());
+ }
source.setRoutingPort(Constants.CEC_SWITCH_HOME);
source.setLocalActivePort(Constants.CEC_SWITCH_HOME);
}
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index 5fa3f52..7ff6a2f 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -89,6 +89,7 @@
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
+import android.os.UserManagerInternal;
import android.provider.Settings;
import android.service.vr.IVrManager;
import android.service.vr.IVrStateCallbacks;
@@ -309,6 +310,7 @@
private final HardKeyboardListener mHardKeyboardListener;
private final AppOpsManager mAppOpsManager;
private final UserManager mUserManager;
+ private final UserManagerInternal mUserManagerInternal;
// All known input methods. mMethodMap also serves as the global
// lock for this class.
@@ -1405,6 +1407,7 @@
}, true /*asyncHandler*/);
mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
mUserManager = mContext.getSystemService(UserManager.class);
+ mUserManagerInternal = LocalServices.getService(UserManagerInternal.class);
mHardKeyboardListener = new HardKeyboardListener();
mHasFeature = context.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_INPUT_METHODS);
@@ -1489,7 +1492,7 @@
// If the system is not ready or the device is not yed unlocked by the user, then we use
// copy-on-write settings.
final boolean useCopyOnWriteSettings =
- !mSystemReady || !mUserManager.isUserUnlockingOrUnlocked(newUserId);
+ !mSystemReady || !mUserManagerInternal.isUserUnlockingOrUnlocked(newUserId);
mSettings.switchCurrentUser(newUserId, useCopyOnWriteSettings);
updateCurrentProfileIds();
// Additional subtypes should be reset when the user is changed
@@ -1562,7 +1565,7 @@
mLastSystemLocales = mRes.getConfiguration().getLocales();
final int currentUserId = mSettings.getCurrentUserId();
mSettings.switchCurrentUser(currentUserId,
- !mUserManager.isUserUnlockingOrUnlocked(currentUserId));
+ !mUserManagerInternal.isUserUnlockingOrUnlocked(currentUserId));
mKeyguardManager = mContext.getSystemService(KeyguardManager.class);
mNotificationManager = mContext.getSystemService(NotificationManager.class);
mStatusBar = statusBar;
diff --git a/services/core/java/com/android/server/job/controllers/QuotaController.java b/services/core/java/com/android/server/job/controllers/QuotaController.java
index ac2dbdf..c16d1b4 100644
--- a/services/core/java/com/android/server/job/controllers/QuotaController.java
+++ b/services/core/java/com/android/server/job/controllers/QuotaController.java
@@ -26,7 +26,10 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
+import android.app.ActivityManager;
+import android.app.ActivityManagerInternal;
import android.app.AlarmManager;
+import android.app.IUidObserver;
import android.app.usage.UsageStatsManagerInternal;
import android.app.usage.UsageStatsManagerInternal.AppIdleStateChangeListener;
import android.content.BroadcastReceiver;
@@ -38,12 +41,14 @@
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
+import android.os.RemoteException;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
+import android.util.SparseBooleanArray;
import android.util.proto.ProtoOutputStream;
import com.android.internal.annotations.VisibleForTesting;
@@ -69,6 +74,11 @@
* bucket, it will be eligible to run. When a job's bucket changes, its new quota is immediately
* applied to it.
*
+ * Jobs are throttled while an app is not in a foreground state. All jobs are allowed to run
+ * freely when an app enters the foreground state and are restricted when the app leaves the
+ * foreground state. However, jobs that are started while the app is in the TOP state are not
+ * restricted regardless of the app's state change.
+ *
* Test: atest com.android.server.job.controllers.QuotaControllerTest
*/
public final class QuotaController extends StateController {
@@ -97,6 +107,12 @@
data.put(packageName, obj);
}
+ public void clear() {
+ for (int i = 0; i < mData.size(); ++i) {
+ mData.valueAt(i).clear();
+ }
+ }
+
/** Removes all the data for the user, if there was any. */
public void delete(int userId) {
mData.delete(userId);
@@ -119,6 +135,11 @@
return null;
}
+ /** @see SparseArray#indexOfKey */
+ public int indexOfKey(int userId) {
+ return mData.indexOfKey(userId);
+ }
+
/** Returns the userId at the given index. */
public int keyAt(int index) {
return mData.keyAt(index);
@@ -294,6 +315,17 @@
/** Cached calculation results for each app, with the standby buckets as the array indices. */
private final UserPackageMap<ExecutionStats[]> mExecutionStatsCache = new UserPackageMap<>();
+ /** List of UIDs currently in the foreground. */
+ private final SparseBooleanArray mForegroundUids = new SparseBooleanArray();
+
+ /**
+ * List of jobs that started while the UID was in the TOP state. There will be no more than
+ * 16 ({@link JobSchedulerService.MAX_JOB_CONTEXTS_COUNT}) running at once, so an ArraySet is
+ * fine.
+ */
+ private final ArraySet<JobStatus> mTopStartedJobs = new ArraySet<>();
+
+ private final ActivityManagerInternal mActivityManagerInternal;
private final AlarmManager mAlarmManager;
private final ChargingTracker mChargeTracker;
private final Handler mHandler;
@@ -343,6 +375,29 @@
}
};
+ private final IUidObserver mUidObserver = new IUidObserver.Stub() {
+ @Override
+ public void onUidStateChanged(int uid, int procState, long procStateSeq) {
+ mHandler.obtainMessage(MSG_UID_PROCESS_STATE_CHANGED, uid, procState).sendToTarget();
+ }
+
+ @Override
+ public void onUidGone(int uid, boolean disabled) {
+ }
+
+ @Override
+ public void onUidActive(int uid) {
+ }
+
+ @Override
+ public void onUidIdle(int uid, boolean disabled) {
+ }
+
+ @Override
+ public void onUidCachedChanged(int uid, boolean cached) {
+ }
+ };
+
/**
* The rolling window size for each standby bucket. Within each window, an app will have 10
* minutes to run its jobs.
@@ -363,12 +418,15 @@
private static final int MSG_CLEAN_UP_SESSIONS = 1;
/** Check if a package is now within its quota. */
private static final int MSG_CHECK_PACKAGE = 2;
+ /** Process state for a UID has changed. */
+ private static final int MSG_UID_PROCESS_STATE_CHANGED = 3;
public QuotaController(JobSchedulerService service) {
super(service);
mHandler = new QcHandler(mContext.getMainLooper());
mChargeTracker = new ChargingTracker();
mChargeTracker.startTracking();
+ mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
// Set up the app standby bucketing tracker
@@ -376,6 +434,14 @@
UsageStatsManagerInternal.class);
usageStats.addAppIdleStateChangeListener(new StandbyTracker());
+ try {
+ ActivityManager.getService().registerUidObserver(mUidObserver,
+ ActivityManager.UID_OBSERVER_PROCSTATE,
+ ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE, null);
+ } catch (RemoteException e) {
+ // ignored; both services live in system_server
+ }
+
onConstantsUpdatedLocked();
}
@@ -399,11 +465,15 @@
if (DEBUG) Slog.d(TAG, "Prepping for " + jobStatus.toShortString());
final int userId = jobStatus.getSourceUserId();
final String packageName = jobStatus.getSourcePackageName();
+ final int uid = jobStatus.getSourceUid();
Timer timer = mPkgTimers.get(userId, packageName);
if (timer == null) {
- timer = new Timer(userId, packageName);
+ timer = new Timer(uid, userId, packageName);
mPkgTimers.add(userId, packageName, timer);
}
+ if (mActivityManagerInternal.getUidProcessState(uid) == ActivityManager.PROCESS_STATE_TOP) {
+ mTopStartedJobs.add(jobStatus);
+ }
timer.startTrackingJob(jobStatus);
}
@@ -421,6 +491,7 @@
if (jobs != null) {
jobs.remove(jobStatus);
}
+ mTopStartedJobs.remove(jobStatus);
}
}
@@ -511,6 +582,7 @@
mInQuotaAlarmListeners.delete(userId, packageName);
}
mExecutionStatsCache.delete(userId, packageName);
+ mForegroundUids.delete(uid);
}
@Override
@@ -522,6 +594,20 @@
mExecutionStatsCache.delete(userId);
}
+ private boolean isUidInForeground(int uid) {
+ if (UserHandle.isCore(uid)) {
+ return true;
+ }
+ synchronized (mLock) {
+ return mForegroundUids.get(uid);
+ }
+ }
+
+ /** @return true if the job was started while the app was in the TOP state. */
+ private boolean isTopStartedJob(@NonNull final JobStatus jobStatus) {
+ return mTopStartedJobs.contains(jobStatus);
+ }
+
/**
* Returns an appropriate standby bucket for the job, taking into account any standby
* exemptions.
@@ -537,9 +623,15 @@
private boolean isWithinQuotaLocked(@NonNull final JobStatus jobStatus) {
final int standbyBucket = getEffectiveStandbyBucket(jobStatus);
- // Jobs for the active app should always be able to run.
- return jobStatus.uidActive || isWithinQuotaLocked(
- jobStatus.getSourceUserId(), jobStatus.getSourcePackageName(), standbyBucket);
+ Timer timer = mPkgTimers.get(jobStatus.getSourceUserId(), jobStatus.getSourcePackageName());
+ // A job is within quota if one of the following is true:
+ // 1. it was started while the app was in the TOP state
+ // 2. the app is currently in the foreground
+ // 3. the app overall is within its quota
+ return isTopStartedJob(jobStatus)
+ || isUidInForeground(jobStatus.getSourceUid())
+ || isWithinQuotaLocked(
+ jobStatus.getSourceUserId(), jobStatus.getSourcePackageName(), standbyBucket);
}
private boolean isWithinQuotaLocked(final int userId, @NonNull final String packageName,
@@ -800,7 +892,7 @@
final boolean isCharging = mChargeTracker.isCharging();
if (DEBUG) Slog.d(TAG, "handleNewChargingStateLocked: " + isCharging);
// Deal with Timers first.
- mPkgTimers.forEach((t) -> t.onChargingChanged(nowElapsed, isCharging));
+ mPkgTimers.forEach((t) -> t.onStateChanged(nowElapsed, isCharging));
// Now update jobs.
maybeUpdateAllConstraintsLocked();
}
@@ -837,10 +929,15 @@
boolean changed = false;
for (int i = jobs.size() - 1; i >= 0; --i) {
final JobStatus js = jobs.valueAt(i);
- if (js.uidActive) {
- // Jobs for the active app should always be able to run.
+ if (isTopStartedJob(js)) {
+ // Job was started while the app was in the TOP state so we should allow it to
+ // finish.
changed |= js.setQuotaConstraintSatisfied(true);
- } else if (realStandbyBucket == getEffectiveStandbyBucket(js)) {
+ } else if (realStandbyBucket != ACTIVE_INDEX
+ && realStandbyBucket == getEffectiveStandbyBucket(js)) {
+ // An app in the ACTIVE bucket may be out of quota while the job could be in quota
+ // for some reason. Therefore, avoid setting the real value here and check each job
+ // individually.
changed |= js.setQuotaConstraintSatisfied(realInQuota);
} else {
// This job is somehow exempted. Need to determine its own quota status.
@@ -854,7 +951,7 @@
maybeScheduleStartAlarmLocked(userId, packageName, realStandbyBucket);
} else {
QcAlarmListener alarmListener = mInQuotaAlarmListeners.get(userId, packageName);
- if (alarmListener != null) {
+ if (alarmListener != null && alarmListener.isWaiting()) {
mAlarmManager.cancel(alarmListener);
// Set the trigger time to 0 so that the alarm doesn't think it's still waiting.
alarmListener.setTriggerTime(0);
@@ -863,6 +960,56 @@
return changed;
}
+ private class UidConstraintUpdater implements Consumer<JobStatus> {
+ private final UserPackageMap<Integer> mToScheduleStartAlarms = new UserPackageMap<>();
+ public boolean wasJobChanged;
+
+ @Override
+ public void accept(JobStatus jobStatus) {
+ wasJobChanged |= jobStatus.setQuotaConstraintSatisfied(isWithinQuotaLocked(jobStatus));
+ final int userId = jobStatus.getSourceUserId();
+ final String packageName = jobStatus.getSourcePackageName();
+ final int realStandbyBucket = jobStatus.getStandbyBucket();
+ if (isWithinQuotaLocked(userId, packageName, realStandbyBucket)) {
+ QcAlarmListener alarmListener = mInQuotaAlarmListeners.get(userId, packageName);
+ if (alarmListener != null && alarmListener.isWaiting()) {
+ mAlarmManager.cancel(alarmListener);
+ // Set the trigger time to 0 so that the alarm doesn't think it's still waiting.
+ alarmListener.setTriggerTime(0);
+ }
+ } else {
+ mToScheduleStartAlarms.add(userId, packageName, realStandbyBucket);
+ }
+ }
+
+ void postProcess() {
+ for (int u = 0; u < mToScheduleStartAlarms.numUsers(); ++u) {
+ final int userId = mToScheduleStartAlarms.keyAt(u);
+ for (int p = 0; p < mToScheduleStartAlarms.numPackagesForUser(userId); ++p) {
+ final String packageName = mToScheduleStartAlarms.keyAt(u, p);
+ final int standbyBucket = mToScheduleStartAlarms.get(userId, packageName);
+ maybeScheduleStartAlarmLocked(userId, packageName, standbyBucket);
+ }
+ }
+ }
+
+ void reset() {
+ wasJobChanged = false;
+ mToScheduleStartAlarms.clear();
+ }
+ }
+
+ private final UidConstraintUpdater mUpdateUidConstraints = new UidConstraintUpdater();
+
+ private boolean maybeUpdateConstraintForUidLocked(final int uid) {
+ mService.getJobStore().forEachJobForSourceUid(uid, mUpdateUidConstraints);
+
+ mUpdateUidConstraints.postProcess();
+ boolean changed = mUpdateUidConstraints.wasJobChanged;
+ mUpdateUidConstraints.reset();
+ return changed;
+ }
+
/**
* Maybe schedule a non-wakeup alarm for the next time this package will have quota to run
* again. This should only be called if the package is already out of quota.
@@ -1052,6 +1199,7 @@
private final class Timer {
private final Package mPkg;
+ private final int mUid;
// List of jobs currently running for this app that started when the app wasn't in the
// foreground.
@@ -1059,16 +1207,18 @@
private long mStartTimeElapsed;
private int mBgJobCount;
- Timer(int userId, String packageName) {
+ Timer(int uid, int userId, String packageName) {
mPkg = new Package(userId, packageName);
+ mUid = uid;
}
void startTrackingJob(@NonNull JobStatus jobStatus) {
- if (jobStatus.uidActive) {
- // We intentionally don't pay attention to fg state changes after a job has started.
+ if (isTopStartedJob(jobStatus)) {
+ // We intentionally don't pay attention to fg state changes after a TOP job has
+ // started.
if (DEBUG) {
Slog.v(TAG,
- "Timer ignoring " + jobStatus.toShortString() + " because uidActive");
+ "Timer ignoring " + jobStatus.toShortString() + " because isTop");
}
return;
}
@@ -1076,7 +1226,7 @@
synchronized (mLock) {
// Always track jobs, even when charging.
mRunningBgJobs.add(jobStatus);
- if (!mChargeTracker.isCharging()) {
+ if (shouldTrackLocked()) {
mBgJobCount++;
if (mRunningBgJobs.size() == 1) {
// Started tracking the first job.
@@ -1142,6 +1292,10 @@
}
}
+ boolean isRunning(JobStatus jobStatus) {
+ return mRunningBgJobs.contains(jobStatus);
+ }
+
long getCurrentDuration(long nowElapsed) {
synchronized (mLock) {
return !isActive() ? 0 : nowElapsed - mStartTimeElapsed;
@@ -1154,17 +1308,21 @@
}
}
- void onChargingChanged(long nowElapsed, boolean isCharging) {
+ private boolean shouldTrackLocked() {
+ return !mChargeTracker.isCharging() && !mForegroundUids.get(mUid);
+ }
+
+ void onStateChanged(long nowElapsed, boolean isQuotaFree) {
synchronized (mLock) {
- if (isCharging) {
+ if (isQuotaFree) {
emitSessionLocked(nowElapsed);
- } else {
+ } else if (shouldTrackLocked()) {
// Start timing from unplug.
if (mRunningBgJobs.size() > 0) {
mStartTimeElapsed = nowElapsed;
// NOTE: this does have the unfortunate consequence that if the device is
- // repeatedly plugged in and unplugged, the job count for a package may be
- // artificially high.
+ // repeatedly plugged in and unplugged, or an app changes foreground state
+ // very frequently, the job count for a package may be artificially high.
mBgJobCount = mRunningBgJobs.size();
// Starting the timer means that all cached execution stats are now
// incorrect.
@@ -1371,6 +1529,38 @@
}
break;
}
+ case MSG_UID_PROCESS_STATE_CHANGED: {
+ final int uid = msg.arg1;
+ final int procState = msg.arg2;
+ final int userId = UserHandle.getUserId(uid);
+ final long nowElapsed = sElapsedRealtimeClock.millis();
+
+ synchronized (mLock) {
+ boolean isQuotaFree;
+ if (procState <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) {
+ mForegroundUids.put(uid, true);
+ isQuotaFree = true;
+ } else {
+ mForegroundUids.delete(uid);
+ isQuotaFree = false;
+ }
+ // Update Timers first.
+ final int userIndex = mPkgTimers.indexOfKey(userId);
+ if (userIndex != -1) {
+ final int numPkgs = mPkgTimers.numPackagesForUser(userId);
+ for (int p = 0; p < numPkgs; ++p) {
+ Timer t = mPkgTimers.valueAt(userIndex, p);
+ if (t != null) {
+ t.onStateChanged(nowElapsed, isQuotaFree);
+ }
+ }
+ }
+ if (maybeUpdateConstraintForUidLocked(uid)) {
+ mStateChangedListener.onControllerStateChanged();
+ }
+ }
+ break;
+ }
}
}
}
@@ -1420,6 +1610,12 @@
@VisibleForTesting
@NonNull
+ SparseBooleanArray getForegroundUids() {
+ return mForegroundUids;
+ }
+
+ @VisibleForTesting
+ @NonNull
Handler getHandler() {
return mHandler;
}
@@ -1450,6 +1646,10 @@
pw.println("In parole: " + mInParole);
pw.println();
+ pw.print("Foreground UIDs: ");
+ pw.println(mForegroundUids.toString());
+ pw.println();
+
mTrackedJobs.forEach((jobs) -> {
for (int j = 0; j < jobs.size(); j++) {
final JobStatus js = jobs.valueAt(j);
@@ -1460,6 +1660,9 @@
js.printUniqueId(pw);
pw.print(" from ");
UserHandle.formatUid(pw, js.getSourceUid());
+ if (mTopStartedJobs.contains(js)) {
+ pw.print(" (TOP)");
+ }
pw.println();
pw.increaseIndent();
@@ -1511,6 +1714,11 @@
proto.write(StateControllerProto.QuotaController.IS_CHARGING, mChargeTracker.isCharging());
proto.write(StateControllerProto.QuotaController.IS_IN_PAROLE, mInParole);
+ for (int i = 0; i < mForegroundUids.size(); ++i) {
+ proto.write(StateControllerProto.QuotaController.FOREGROUND_UIDS,
+ mForegroundUids.keyAt(i));
+ }
+
mTrackedJobs.forEach((jobs) -> {
for (int j = 0; j < jobs.size(); j++) {
final JobStatus js = jobs.valueAt(j);
@@ -1526,6 +1734,8 @@
proto.write(
StateControllerProto.QuotaController.TrackedJob.EFFECTIVE_STANDBY_BUCKET,
getEffectiveStandbyBucket(js));
+ proto.write(StateControllerProto.QuotaController.TrackedJob.IS_TOP_STARTED_JOB,
+ mTopStartedJobs.contains(js));
proto.write(StateControllerProto.QuotaController.TrackedJob.HAS_QUOTA,
js.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
proto.write(StateControllerProto.QuotaController.TrackedJob.REMAINING_QUOTA_MS,
diff --git a/services/core/java/com/android/server/location/GnssLocationProvider.java b/services/core/java/com/android/server/location/GnssLocationProvider.java
index 269767a..dfb98c3 100644
--- a/services/core/java/com/android/server/location/GnssLocationProvider.java
+++ b/services/core/java/com/android/server/location/GnssLocationProvider.java
@@ -64,6 +64,7 @@
import android.telephony.gsm.GsmCellLocation;
import android.text.TextUtils;
import android.util.Log;
+import android.util.StatsLog;
import com.android.internal.app.IBatteryStats;
import com.android.internal.location.GpsNetInitiatedHandler;
@@ -1704,6 +1705,24 @@
", response: " + userResponse);
}
native_send_ni_response(notificationId, userResponse);
+
+ StatsLog.write(StatsLog.GNSS_NI_EVENT_REPORTED,
+ StatsLog.GNSS_NI_EVENT_REPORTED__EVENT_TYPE__NI_RESPONSE,
+ notificationId,
+ /* niType= */ 0,
+ /* needNotify= */ false,
+ /* needVerify= */ false,
+ /* privacyOverride= */ false,
+ /* timeout= */ 0,
+ /* defaultResponse= */ 0,
+ /* requestorId= */ null,
+ /* text= */ null,
+ /* requestorIdEncoding= */ 0,
+ /* textEncoding= */ 0,
+ mSuplEsEnabled,
+ mEnabled,
+ userResponse);
+
return true;
}
};
@@ -1753,6 +1772,22 @@
notification.textEncoding = textEncoding;
mNIHandler.handleNiNotification(notification);
+ StatsLog.write(StatsLog.GNSS_NI_EVENT_REPORTED,
+ StatsLog.GNSS_NI_EVENT_REPORTED__EVENT_TYPE__NI_REQUEST,
+ notification.notificationId,
+ notification.niType,
+ notification.needNotify,
+ notification.needVerify,
+ notification.privacyOverride,
+ notification.timeout,
+ notification.defaultResponse,
+ notification.requestorId,
+ notification.text,
+ notification.requestorIdEncoding,
+ notification.textEncoding,
+ mSuplEsEnabled,
+ mEnabled,
+ /* userResponse= */ 0);
}
/**
diff --git a/services/core/java/com/android/server/location/MockProvider.java b/services/core/java/com/android/server/location/MockProvider.java
index 86bc9f3..fe91c63 100644
--- a/services/core/java/com/android/server/location/MockProvider.java
+++ b/services/core/java/com/android/server/location/MockProvider.java
@@ -52,7 +52,6 @@
mExtras = null;
setProperties(properties);
- setEnabled(true);
}
/** Sets the enabled state of this mock provider. */
diff --git a/services/core/java/com/android/server/media/MediaSessionRecord.java b/services/core/java/com/android/server/media/MediaSessionRecord.java
index d611a17..7fffe8e 100644
--- a/services/core/java/com/android/server/media/MediaSessionRecord.java
+++ b/services/core/java/com/android/server/media/MediaSessionRecord.java
@@ -80,7 +80,7 @@
private final ControllerStub mController;
private final SessionStub mSession;
private final SessionCb mSessionCb;
- private final MediaSessionService mService;
+ private final MediaSessionService.ServiceImpl mService;
private final Context mContext;
private final Object mLock = new Object();
@@ -120,7 +120,8 @@
private String mMetadataDescription;
public MediaSessionRecord(int ownerPid, int ownerUid, int userId, String ownerPackageName,
- SessionCallbackLink cb, String tag, MediaSessionService service, Looper handlerLooper) {
+ SessionCallbackLink cb, String tag, MediaSessionService.ServiceImpl service,
+ Looper handlerLooper) {
mOwnerPid = ownerPid;
mOwnerUid = ownerUid;
mUserId = userId;
diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java
index ba7b87e..d20ed8c 100644
--- a/services/core/java/com/android/server/media/MediaSessionService.java
+++ b/services/core/java/com/android/server/media/MediaSessionService.java
@@ -16,79 +16,15 @@
package com.android.server.media;
-import static android.os.UserHandle.USER_ALL;
-
-import android.annotation.Nullable;
-import android.app.ActivityManager;
-import android.app.INotificationManager;
-import android.app.KeyguardManager;
-import android.app.PendingIntent;
-import android.app.PendingIntent.CanceledException;
-import android.content.ActivityNotFoundException;
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.ContentResolver;
import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.pm.ServiceInfo;
-import android.content.pm.UserInfo;
-import android.database.ContentObserver;
-import android.media.AudioManager;
-import android.media.AudioManagerInternal;
-import android.media.AudioPlaybackConfiguration;
-import android.media.AudioSystem;
-import android.media.IAudioService;
-import android.media.IRemoteVolumeController;
-import android.media.MediaController2;
-import android.media.Session2CommandGroup;
import android.media.Session2Token;
-import android.media.session.IActiveSessionsListener;
-import android.media.session.ICallback;
-import android.media.session.IOnMediaKeyListener;
-import android.media.session.IOnVolumeKeyLongPressListener;
-import android.media.session.ISession;
-import android.media.session.ISession2TokensListener;
-import android.media.session.ISessionManager;
-import android.media.session.MediaSession;
-import android.media.session.MediaSessionManager;
-import android.media.session.SessionCallbackLink;
-import android.net.Uri;
-import android.os.Binder;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.HandlerExecutor;
import android.os.IBinder;
-import android.os.Message;
-import android.os.PowerManager;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.ResultReceiver;
-import android.os.ServiceManager;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.provider.Settings;
-import android.speech.RecognizerIntent;
-import android.text.TextUtils;
import android.util.Log;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.util.SparseIntArray;
-import android.view.KeyEvent;
-import android.view.ViewConfiguration;
-import com.android.internal.annotations.GuardedBy;
-import com.android.internal.util.DumpUtils;
-import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.Watchdog;
import com.android.server.Watchdog.Monitor;
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.util.ArrayList;
import java.util.List;
/**
@@ -97,2040 +33,124 @@
public class MediaSessionService extends SystemService implements Monitor {
private static final String TAG = "MediaSessionService";
static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
- // Leave log for key event always.
- private static final boolean DEBUG_KEY_EVENT = true;
- private static final int WAKELOCK_TIMEOUT = 5000;
- private static final int MEDIA_KEY_LISTENER_TIMEOUT = 1000;
-
- private final SessionManagerImpl mSessionManagerImpl;
- private final MessageHandler mHandler = new MessageHandler();
- private final PowerManager.WakeLock mMediaEventWakeLock;
- private final int mLongPressTimeout;
- private final INotificationManager mNotificationManager;
- private final Object mLock = new Object();
- // Keeps the full user id for each user.
- @GuardedBy("mLock")
- private final SparseIntArray mFullUserIds = new SparseIntArray();
- @GuardedBy("mLock")
- private final SparseArray<FullUserRecord> mUserRecords = new SparseArray<FullUserRecord>();
- @GuardedBy("mLock")
- private final ArrayList<SessionsListenerRecord> mSessionsListeners
- = new ArrayList<SessionsListenerRecord>();
- // Map user id as index to list of Session2Tokens
- // TODO: Keep session2 info in MediaSessionStack for prioritizing both session1 and session2 in
- // one place.
- @GuardedBy("mLock")
- private final SparseArray<List<Session2Token>> mSession2TokensPerUser = new SparseArray<>();
- @GuardedBy("mLock")
- private final List<Session2TokensListenerRecord> mSession2TokensListenerRecords =
- new ArrayList<>();
-
- private KeyguardManager mKeyguardManager;
- private IAudioService mAudioService;
- private AudioManagerInternal mAudioManagerInternal;
- private ActivityManager mActivityManager;
- private ContentResolver mContentResolver;
- private SettingsObserver mSettingsObserver;
- private boolean mHasFeatureLeanback;
-
- // The FullUserRecord of the current users. (i.e. The foreground user that isn't a profile)
- // It's always not null after the MediaSessionService is started.
- private FullUserRecord mCurrentFullUserRecord;
- private MediaSessionRecord mGlobalPrioritySession;
- private AudioPlayerStateMonitor mAudioPlayerStateMonitor;
-
- // Used to notify system UI when remote volume was changed. TODO find a
- // better way to handle this.
- private IRemoteVolumeController mRvc;
+ private final ServiceImpl mImpl;
public MediaSessionService(Context context) {
super(context);
- mSessionManagerImpl = new SessionManagerImpl();
- PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
- mMediaEventWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "handleMediaEvent");
- mLongPressTimeout = ViewConfiguration.getLongPressTimeout();
- mNotificationManager = INotificationManager.Stub.asInterface(
- ServiceManager.getService(Context.NOTIFICATION_SERVICE));
+ mImpl = new MediaSessionServiceImpl(context);
}
@Override
public void onStart() {
- publishBinderService(Context.MEDIA_SESSION_SERVICE, mSessionManagerImpl);
+ publishBinderService(Context.MEDIA_SESSION_SERVICE, mImpl.getServiceBinder());
Watchdog.getInstance().addMonitor(this);
- mKeyguardManager =
- (KeyguardManager) getContext().getSystemService(Context.KEYGUARD_SERVICE);
- mAudioService = getAudioService();
- mAudioManagerInternal = LocalServices.getService(AudioManagerInternal.class);
- mActivityManager =
- (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
- mAudioPlayerStateMonitor = AudioPlayerStateMonitor.getInstance();
- mAudioPlayerStateMonitor.registerListener(
- (config, isRemoved) -> {
- if (isRemoved || !config.isActive() || config.getPlayerType()
- == AudioPlaybackConfiguration.PLAYER_TYPE_JAM_SOUNDPOOL) {
- return;
- }
- synchronized (mLock) {
- FullUserRecord user = getFullUserRecordLocked(
- UserHandle.getUserId(config.getClientUid()));
- if (user != null) {
- user.mPriorityStack.updateMediaButtonSessionIfNeeded();
- }
- }
- }, null /* handler */);
- mAudioPlayerStateMonitor.registerSelfIntoAudioServiceIfNeeded(mAudioService);
- mContentResolver = getContext().getContentResolver();
- mSettingsObserver = new SettingsObserver();
- mSettingsObserver.observe();
- mHasFeatureLeanback = getContext().getPackageManager().hasSystemFeature(
- PackageManager.FEATURE_LEANBACK);
- updateUser();
+ mImpl.onStart();
}
- private IAudioService getAudioService() {
- IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
- return IAudioService.Stub.asInterface(b);
+ @Override
+ public void onStartUser(int userId) {
+ mImpl.onStartUser(userId);
}
- private boolean isGlobalPriorityActiveLocked() {
- return mGlobalPrioritySession != null && mGlobalPrioritySession.isActive();
+ @Override
+ public void onSwitchUser(int userId) {
+ mImpl.onSwitchUser(userId);
}
+ // Called when the user with the userId is removed.
+ @Override
+ public void onStopUser(int userId) {
+ mImpl.onStopUser(userId);
+ }
+
+ @Override
+ public void monitor() {
+ mImpl.monitor();
+ }
+
+ /**
+ * Updates session.
+ */
public void updateSession(MediaSessionRecord record) {
- synchronized (mLock) {
- FullUserRecord user = getFullUserRecordLocked(record.getUserId());
- if (user == null) {
- Log.w(TAG, "Unknown session updated. Ignoring.");
- return;
- }
- if ((record.getFlags() & MediaSession.FLAG_EXCLUSIVE_GLOBAL_PRIORITY) != 0) {
- if (DEBUG_KEY_EVENT) {
- Log.d(TAG, "Global priority session is updated, active=" + record.isActive());
- }
- user.pushAddressedPlayerChangedLocked();
- } else {
- if (!user.mPriorityStack.contains(record)) {
- Log.w(TAG, "Unknown session updated. Ignoring.");
- return;
- }
- user.mPriorityStack.onSessionStateChange(record);
- }
- mHandler.postSessionsChanged(record.getUserId());
- }
+ mImpl.updateSession(record);
}
+ /**
+ * Sets global priority session.
+ */
public void setGlobalPrioritySession(MediaSessionRecord record) {
- synchronized (mLock) {
- FullUserRecord user = getFullUserRecordLocked(record.getUserId());
- if (mGlobalPrioritySession != record) {
- Log.d(TAG, "Global priority session is changed from " + mGlobalPrioritySession
- + " to " + record);
- mGlobalPrioritySession = record;
- if (user != null && user.mPriorityStack.contains(record)) {
- // Handle the global priority session separately.
- // Otherwise, it can be the media button session regardless of the active state
- // because it or other system components might have been the lastly played media
- // app.
- user.mPriorityStack.removeSession(record);
- }
- }
- }
- }
-
- private List<MediaSessionRecord> getActiveSessionsLocked(int userId) {
- List<MediaSessionRecord> records = new ArrayList<>();
- if (userId == USER_ALL) {
- int size = mUserRecords.size();
- for (int i = 0; i < size; i++) {
- records.addAll(mUserRecords.valueAt(i).mPriorityStack.getActiveSessions(userId));
- }
- } else {
- FullUserRecord user = getFullUserRecordLocked(userId);
- if (user == null) {
- Log.w(TAG, "getSessions failed. Unknown user " + userId);
- return records;
- }
- records.addAll(user.mPriorityStack.getActiveSessions(userId));
- }
-
- // Return global priority session at the first whenever it's asked.
- if (isGlobalPriorityActiveLocked()
- && (userId == USER_ALL || userId == mGlobalPrioritySession.getUserId())) {
- records.add(0, mGlobalPrioritySession);
- }
- return records;
+ mImpl.setGlobalPrioritySession(record);
}
List<Session2Token> getSession2TokensLocked(int userId) {
- List<Session2Token> list = new ArrayList<>();
- if (userId == USER_ALL) {
- for (int i = 0; i < mSession2TokensPerUser.size(); i++) {
- list.addAll(mSession2TokensPerUser.valueAt(i));
- }
- } else {
- list.addAll(mSession2TokensPerUser.get(userId));
- }
- return list;
+ return mImpl.getSession2TokensLocked(userId);
}
/**
* Tells the system UI that volume has changed on an active remote session.
*/
public void notifyRemoteVolumeChanged(int flags, MediaSessionRecord session) {
- if (mRvc == null || !session.isActive()) {
- return;
- }
- try {
- mRvc.remoteVolumeChanged(session.getControllerBinder(), flags);
- } catch (Exception e) {
- Log.wtf(TAG, "Error sending volume change to system UI.", e);
- }
+ mImpl.notifyRemoteVolumeChanged(flags, session);
}
+ /**
+ * Called when session playstate is changed.
+ */
public void onSessionPlaystateChanged(MediaSessionRecord record, int oldState, int newState) {
- synchronized (mLock) {
- FullUserRecord user = getFullUserRecordLocked(record.getUserId());
- if (user == null || !user.mPriorityStack.contains(record)) {
- Log.d(TAG, "Unknown session changed playback state. Ignoring.");
- return;
- }
- user.mPriorityStack.onPlaystateChanged(record, oldState, newState);
- }
+ mImpl.onSessionPlaystateChanged(record, oldState, newState);
}
+ /**
+ * Called when session playback type is changed.
+ */
public void onSessionPlaybackTypeChanged(MediaSessionRecord record) {
- synchronized (mLock) {
- FullUserRecord user = getFullUserRecordLocked(record.getUserId());
- if (user == null || !user.mPriorityStack.contains(record)) {
- Log.d(TAG, "Unknown session changed playback type. Ignoring.");
- return;
- }
- pushRemoteVolumeUpdateLocked(record.getUserId());
- }
- }
-
- @Override
- public void onStartUser(int userId) {
- if (DEBUG) Log.d(TAG, "onStartUser: " + userId);
- updateUser();
- }
-
- @Override
- public void onSwitchUser(int userId) {
- if (DEBUG) Log.d(TAG, "onSwitchUser: " + userId);
- updateUser();
- }
-
- // Called when the user with the userId is removed.
- @Override
- public void onStopUser(int userId) {
- if (DEBUG) Log.d(TAG, "onStopUser: " + userId);
- synchronized (mLock) {
- // TODO: Also handle removing user in updateUser() because adding/switching user is
- // handled in updateUser().
- FullUserRecord user = getFullUserRecordLocked(userId);
- if (user != null) {
- if (user.mFullUserId == userId) {
- user.destroySessionsForUserLocked(USER_ALL);
- mUserRecords.remove(userId);
- } else {
- user.destroySessionsForUserLocked(userId);
- }
- }
- mSession2TokensPerUser.remove(userId);
- updateUser();
- }
- }
-
- @Override
- public void monitor() {
- synchronized (mLock) {
- // Check for deadlock
- }
+ mImpl.onSessionPlaybackTypeChanged(record);
}
protected void enforcePhoneStatePermission(int pid, int uid) {
- if (getContext().checkPermission(android.Manifest.permission.MODIFY_PHONE_STATE, pid, uid)
- != PackageManager.PERMISSION_GRANTED) {
- throw new SecurityException("Must hold the MODIFY_PHONE_STATE permission.");
- }
+ mImpl.enforcePhoneStatePermission(pid, uid);
}
void sessionDied(MediaSessionRecord session) {
- synchronized (mLock) {
- destroySessionLocked(session);
- }
+ mImpl.sessionDied(session);
}
void destroySession(MediaSessionRecord session) {
- synchronized (mLock) {
- destroySessionLocked(session);
- }
- }
-
- private void updateUser() {
- synchronized (mLock) {
- UserManager manager = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
- mFullUserIds.clear();
- List<UserInfo> allUsers = manager.getUsers();
- if (allUsers != null) {
- for (UserInfo userInfo : allUsers) {
- if (userInfo.isManagedProfile()) {
- mFullUserIds.put(userInfo.id, userInfo.profileGroupId);
- } else {
- mFullUserIds.put(userInfo.id, userInfo.id);
- if (mUserRecords.get(userInfo.id) == null) {
- mUserRecords.put(userInfo.id, new FullUserRecord(userInfo.id));
- }
- }
- if (mSession2TokensPerUser.get(userInfo.id) == null) {
- mSession2TokensPerUser.put(userInfo.id, new ArrayList<>());
- }
- }
- }
- // Ensure that the current full user exists.
- int currentFullUserId = ActivityManager.getCurrentUser();
- mCurrentFullUserRecord = mUserRecords.get(currentFullUserId);
- if (mCurrentFullUserRecord == null) {
- Log.w(TAG, "Cannot find FullUserInfo for the current user " + currentFullUserId);
- mCurrentFullUserRecord = new FullUserRecord(currentFullUserId);
- mUserRecords.put(currentFullUserId, mCurrentFullUserRecord);
- if (mSession2TokensPerUser.get(currentFullUserId) == null) {
- mSession2TokensPerUser.put(currentFullUserId, new ArrayList<>());
- }
- }
- mFullUserIds.put(currentFullUserId, currentFullUserId);
- }
- }
-
- private void updateActiveSessionListeners() {
- synchronized (mLock) {
- for (int i = mSessionsListeners.size() - 1; i >= 0; i--) {
- SessionsListenerRecord listener = mSessionsListeners.get(i);
- try {
- enforceMediaPermissions(listener.componentName, listener.pid, listener.uid,
- listener.userId);
- } catch (SecurityException e) {
- Log.i(TAG, "ActiveSessionsListener " + listener.componentName
- + " is no longer authorized. Disconnecting.");
- mSessionsListeners.remove(i);
- try {
- listener.listener
- .onActiveSessionsChanged(new ArrayList<MediaSession.Token>());
- } catch (Exception e1) {
- // ignore
- }
- }
- }
- }
- }
-
- /*
- * When a session is removed several things need to happen.
- * 1. We need to remove it from the relevant user.
- * 2. We need to remove it from the priority stack.
- * 3. We need to remove it from all sessions.
- * 4. If this is the system priority session we need to clear it.
- * 5. We need to unlink to death from the cb binder
- * 6. We need to tell the session to do any final cleanup (onDestroy)
- */
- private void destroySessionLocked(MediaSessionRecord session) {
- if (DEBUG) {
- Log.d(TAG, "Destroying " + session);
- }
- FullUserRecord user = getFullUserRecordLocked(session.getUserId());
- if (mGlobalPrioritySession == session) {
- mGlobalPrioritySession = null;
- if (session.isActive() && user != null) {
- user.pushAddressedPlayerChangedLocked();
- }
- } else {
- if (user != null) {
- user.mPriorityStack.removeSession(session);
- }
- }
-
- try {
- session.getCallback().getBinder().unlinkToDeath(session, 0);
- } catch (Exception e) {
- // ignore exceptions while destroying a session.
- }
- session.onDestroy();
- mHandler.postSessionsChanged(session.getUserId());
- }
-
- private void enforcePackageName(String packageName, int uid) {
- if (TextUtils.isEmpty(packageName)) {
- throw new IllegalArgumentException("packageName may not be empty");
- }
- String[] packages = getContext().getPackageManager().getPackagesForUid(uid);
- final int packageCount = packages.length;
- for (int i = 0; i < packageCount; i++) {
- if (packageName.equals(packages[i])) {
- return;
- }
- }
- throw new IllegalArgumentException("packageName is not owned by the calling process");
- }
-
- /**
- * Checks a caller's authorization to register an IRemoteControlDisplay.
- * Authorization is granted if one of the following is true:
- * <ul>
- * <li>the caller has android.Manifest.permission.MEDIA_CONTENT_CONTROL
- * permission</li>
- * <li>the caller's listener is one of the enabled notification listeners
- * for the caller's user</li>
- * </ul>
- */
- private void enforceMediaPermissions(ComponentName compName, int pid, int uid,
- int resolvedUserId) {
- if (isCurrentVolumeController(pid, uid)) return;
- if (getContext()
- .checkPermission(android.Manifest.permission.MEDIA_CONTENT_CONTROL, pid, uid)
- != PackageManager.PERMISSION_GRANTED
- && !isEnabledNotificationListener(compName, UserHandle.getUserId(uid),
- resolvedUserId)) {
- throw new SecurityException("Missing permission to control media.");
- }
- }
-
- private boolean isCurrentVolumeController(int pid, int uid) {
- return getContext().checkPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
- pid, uid) == PackageManager.PERMISSION_GRANTED;
- }
-
- private void enforceSystemUiPermission(String action, int pid, int uid) {
- if (!isCurrentVolumeController(pid, uid)) {
- throw new SecurityException("Only system ui may " + action);
- }
- }
-
- /**
- * This checks if the component is an enabled notification listener for the
- * specified user. Enabled components may only operate on behalf of the user
- * they're running as.
- *
- * @param compName The component that is enabled.
- * @param userId The user id of the caller.
- * @param forUserId The user id they're making the request on behalf of.
- * @return True if the component is enabled, false otherwise
- */
- private boolean isEnabledNotificationListener(ComponentName compName, int userId,
- int forUserId) {
- if (userId != forUserId) {
- // You may not access another user's content as an enabled listener.
- return false;
- }
- if (DEBUG) {
- Log.d(TAG, "Checking if enabled notification listener " + compName);
- }
- if (compName != null) {
- try {
- return mNotificationManager.isNotificationListenerAccessGrantedForUser(
- compName, userId);
- } catch(RemoteException e) {
- Log.w(TAG, "Dead NotificationManager in isEnabledNotificationListener", e);
- }
- }
- return false;
- }
-
- private MediaSessionRecord createSessionInternal(int callerPid, int callerUid, int userId,
- String callerPackageName, SessionCallbackLink cb, String tag) throws RemoteException {
- synchronized (mLock) {
- return createSessionLocked(callerPid, callerUid, userId, callerPackageName, cb, tag);
- }
- }
-
- /*
- * When a session is created the following things need to happen.
- * 1. Its callback binder needs a link to death
- * 2. It needs to be added to all sessions.
- * 3. It needs to be added to the priority stack.
- * 4. It needs to be added to the relevant user record.
- */
- private MediaSessionRecord createSessionLocked(int callerPid, int callerUid, int userId,
- String callerPackageName, SessionCallbackLink cb, String tag) {
- FullUserRecord user = getFullUserRecordLocked(userId);
- if (user == null) {
- Log.wtf(TAG, "Request from invalid user: " + userId);
- throw new RuntimeException("Session request from invalid user.");
- }
-
- final MediaSessionRecord session = new MediaSessionRecord(callerPid, callerUid, userId,
- callerPackageName, cb, tag, this, mHandler.getLooper());
- try {
- cb.getBinder().linkToDeath(session, 0);
- } catch (RemoteException e) {
- throw new RuntimeException("Media Session owner died prematurely.", e);
- }
-
- user.mPriorityStack.addSession(session);
- mHandler.postSessionsChanged(userId);
-
- if (DEBUG) {
- Log.d(TAG, "Created session for " + callerPackageName + " with tag " + tag);
- }
- return session;
- }
-
- private int findIndexOfSessionsListenerLocked(IActiveSessionsListener listener) {
- for (int i = mSessionsListeners.size() - 1; i >= 0; i--) {
- if (mSessionsListeners.get(i).listener.asBinder() == listener.asBinder()) {
- return i;
- }
- }
- return -1;
- }
-
- private int findIndexOfSession2TokensListenerLocked(ISession2TokensListener listener) {
- for (int i = mSession2TokensListenerRecords.size() - 1; i >= 0; i--) {
- if (mSession2TokensListenerRecords.get(i).listener.asBinder() == listener.asBinder()) {
- return i;
- }
- }
- return -1;
- }
-
-
- private void pushSessionsChanged(int userId) {
- synchronized (mLock) {
- FullUserRecord user = getFullUserRecordLocked(userId);
- if (user == null) {
- Log.w(TAG, "pushSessionsChanged failed. No user with id=" + userId);
- return;
- }
- List<MediaSessionRecord> records = getActiveSessionsLocked(userId);
- int size = records.size();
- ArrayList<MediaSession.Token> tokens = new ArrayList<MediaSession.Token>();
- for (int i = 0; i < size; i++) {
- tokens.add(new MediaSession.Token(records.get(i).getControllerBinder()));
- }
- pushRemoteVolumeUpdateLocked(userId);
- for (int i = mSessionsListeners.size() - 1; i >= 0; i--) {
- SessionsListenerRecord record = mSessionsListeners.get(i);
- if (record.userId == USER_ALL || record.userId == userId) {
- try {
- record.listener.onActiveSessionsChanged(tokens);
- } catch (RemoteException e) {
- Log.w(TAG, "Dead ActiveSessionsListener in pushSessionsChanged, removing",
- e);
- mSessionsListeners.remove(i);
- }
- }
- }
- }
- }
-
- private void pushRemoteVolumeUpdateLocked(int userId) {
- if (mRvc != null) {
- try {
- FullUserRecord user = getFullUserRecordLocked(userId);
- if (user == null) {
- Log.w(TAG, "pushRemoteVolumeUpdateLocked failed. No user with id=" + userId);
- return;
- }
- MediaSessionRecord record = user.mPriorityStack.getDefaultRemoteSession(userId);
- mRvc.updateRemoteController(record == null ? null : record.getControllerBinder());
- } catch (RemoteException e) {
- Log.wtf(TAG, "Error sending default remote volume to sys ui.", e);
- }
- }
+ mImpl.destroySession(session);
}
void pushSession2TokensChangedLocked(int userId) {
- List<Session2Token> allSession2Tokens = getSession2TokensLocked(USER_ALL);
- List<Session2Token> session2Tokens = getSession2TokensLocked(userId);
-
- for (int i = mSession2TokensListenerRecords.size() - 1; i >= 0; i--) {
- Session2TokensListenerRecord listenerRecord = mSession2TokensListenerRecords.get(i);
- try {
- if (listenerRecord.userId == USER_ALL) {
- listenerRecord.listener.onSession2TokensChanged(allSession2Tokens);
- } else if (listenerRecord.userId == userId) {
- listenerRecord.listener.onSession2TokensChanged(session2Tokens);
- }
- } catch (RemoteException e) {
- Log.w(TAG, "Failed to notify Session2Token change. Removing listener.", e);
- mSession2TokensListenerRecords.remove(i);
- }
- }
+ mImpl.pushSession2TokensChangedLocked(userId);
}
/**
- * Called when the media button receiver for the {@param record} is changed.
- *
- * @param record the media session whose media button receiver is updated.
+ * Called when media button receiver changed.
*/
public void onMediaButtonReceiverChanged(MediaSessionRecord record) {
- synchronized (mLock) {
- FullUserRecord user = getFullUserRecordLocked(record.getUserId());
- MediaSessionRecord mediaButtonSession =
- user.mPriorityStack.getMediaButtonSession();
- if (record == mediaButtonSession) {
- user.rememberMediaButtonReceiverLocked(mediaButtonSession);
- }
- }
+ mImpl.onMediaButtonReceiverChanged(record);
}
- private String getCallingPackageName(int uid) {
- String[] packages = getContext().getPackageManager().getPackagesForUid(uid);
- if (packages != null && packages.length > 0) {
- return packages[0];
- }
- return "";
- }
-
- private void dispatchVolumeKeyLongPressLocked(KeyEvent keyEvent) {
- if (mCurrentFullUserRecord.mOnVolumeKeyLongPressListener == null) {
- return;
- }
- try {
- mCurrentFullUserRecord.mOnVolumeKeyLongPressListener.onVolumeKeyLongPress(keyEvent);
- } catch (RemoteException e) {
- Log.w(TAG, "Failed to send " + keyEvent + " to volume key long-press listener");
- }
- }
-
- private FullUserRecord getFullUserRecordLocked(int userId) {
- int fullUserId = mFullUserIds.get(userId, -1);
- if (fullUserId < 0) {
- return null;
- }
- return mUserRecords.get(fullUserId);
- }
-
- /**
- * Information about a full user and its corresponding managed profiles.
- *
- * <p>Since the full user runs together with its managed profiles, a user wouldn't differentiate
- * them when he/she presses a media/volume button. So keeping media sessions for them in one
- * place makes more sense and increases the readability.</p>
- * <p>The contents of this object is guarded by {@link #mLock}.
- */
- final class FullUserRecord implements MediaSessionStack.OnMediaButtonSessionChangedListener {
- public static final int COMPONENT_TYPE_INVALID = 0;
- public static final int COMPONENT_TYPE_BROADCAST = 1;
- public static final int COMPONENT_TYPE_ACTIVITY = 2;
- public static final int COMPONENT_TYPE_SERVICE = 3;
- private static final String COMPONENT_NAME_USER_ID_DELIM = ",";
-
- private final int mFullUserId;
- private final MediaSessionStack mPriorityStack;
- private PendingIntent mLastMediaButtonReceiver;
- private ComponentName mRestoredMediaButtonReceiver;
- private int mRestoredMediaButtonReceiverComponentType;
- private int mRestoredMediaButtonReceiverUserId;
-
- private IOnVolumeKeyLongPressListener mOnVolumeKeyLongPressListener;
- private int mOnVolumeKeyLongPressListenerUid;
- private KeyEvent mInitialDownVolumeKeyEvent;
- private int mInitialDownVolumeStream;
- private boolean mInitialDownMusicOnly;
-
- private IOnMediaKeyListener mOnMediaKeyListener;
- private int mOnMediaKeyListenerUid;
- private ICallback mCallback;
-
- public FullUserRecord(int fullUserId) {
- mFullUserId = fullUserId;
- mPriorityStack = new MediaSessionStack(mAudioPlayerStateMonitor, this);
- // Restore the remembered media button receiver before the boot.
- String mediaButtonReceiverInfo = Settings.Secure.getStringForUser(mContentResolver,
- Settings.System.MEDIA_BUTTON_RECEIVER, mFullUserId);
- if (mediaButtonReceiverInfo == null) {
- return;
- }
- String[] tokens = mediaButtonReceiverInfo.split(COMPONENT_NAME_USER_ID_DELIM);
- if (tokens == null || (tokens.length != 2 && tokens.length != 3)) {
- return;
- }
- mRestoredMediaButtonReceiver = ComponentName.unflattenFromString(tokens[0]);
- mRestoredMediaButtonReceiverUserId = Integer.parseInt(tokens[1]);
- if (tokens.length == 3) {
- mRestoredMediaButtonReceiverComponentType = Integer.parseInt(tokens[2]);
- } else {
- mRestoredMediaButtonReceiverComponentType =
- getComponentType(mRestoredMediaButtonReceiver);
- }
- }
-
- public void destroySessionsForUserLocked(int userId) {
- List<MediaSessionRecord> sessions = mPriorityStack.getPriorityList(false, userId);
- for (MediaSessionRecord session : sessions) {
- MediaSessionService.this.destroySessionLocked(session);
- }
- }
-
- public void dumpLocked(PrintWriter pw, String prefix) {
- pw.print(prefix + "Record for full_user=" + mFullUserId);
- // Dump managed profile user ids associated with this user.
- int size = mFullUserIds.size();
- for (int i = 0; i < size; i++) {
- if (mFullUserIds.keyAt(i) != mFullUserIds.valueAt(i)
- && mFullUserIds.valueAt(i) == mFullUserId) {
- pw.print(", profile_user=" + mFullUserIds.keyAt(i));
- }
- }
- pw.println();
- String indent = prefix + " ";
- pw.println(indent + "Volume key long-press listener: " + mOnVolumeKeyLongPressListener);
- pw.println(indent + "Volume key long-press listener package: " +
- getCallingPackageName(mOnVolumeKeyLongPressListenerUid));
- pw.println(indent + "Media key listener: " + mOnMediaKeyListener);
- pw.println(indent + "Media key listener package: " +
- getCallingPackageName(mOnMediaKeyListenerUid));
- pw.println(indent + "Callback: " + mCallback);
- pw.println(indent + "Last MediaButtonReceiver: " + mLastMediaButtonReceiver);
- pw.println(indent + "Restored MediaButtonReceiver: " + mRestoredMediaButtonReceiver);
- pw.println(indent + "Restored MediaButtonReceiverComponentType: "
- + mRestoredMediaButtonReceiverComponentType);
- mPriorityStack.dump(pw, indent);
- pw.println(indent + "Session2Tokens:");
- for (int i = 0; i < mSession2TokensPerUser.size(); i++) {
- List<Session2Token> list = mSession2TokensPerUser.valueAt(i);
- if (list == null || list.size() == 0) {
- continue;
- }
- for (Session2Token token : list) {
- pw.println(indent + " " + token);
- }
- }
- }
-
- @Override
- public void onMediaButtonSessionChanged(MediaSessionRecord oldMediaButtonSession,
- MediaSessionRecord newMediaButtonSession) {
- if (DEBUG_KEY_EVENT) {
- Log.d(TAG, "Media button session is changed to " + newMediaButtonSession);
- }
- synchronized (mLock) {
- if (oldMediaButtonSession != null) {
- mHandler.postSessionsChanged(oldMediaButtonSession.getUserId());
- }
- if (newMediaButtonSession != null) {
- rememberMediaButtonReceiverLocked(newMediaButtonSession);
- mHandler.postSessionsChanged(newMediaButtonSession.getUserId());
- }
- pushAddressedPlayerChangedLocked();
- }
- }
-
- // Remember media button receiver and keep it in the persistent storage.
- public void rememberMediaButtonReceiverLocked(MediaSessionRecord record) {
- PendingIntent receiver = record.getMediaButtonReceiver();
- mLastMediaButtonReceiver = receiver;
- mRestoredMediaButtonReceiver = null;
- mRestoredMediaButtonReceiverComponentType = COMPONENT_TYPE_INVALID;
-
- String mediaButtonReceiverInfo = "";
- if (receiver != null) {
- ComponentName component = receiver.getIntent().getComponent();
- if (component != null
- && record.getPackageName().equals(component.getPackageName())) {
- String componentName = component.flattenToString();
- int componentType = getComponentType(component);
- mediaButtonReceiverInfo = String.join(COMPONENT_NAME_USER_ID_DELIM,
- componentName, String.valueOf(record.getUserId()),
- String.valueOf(componentType));
- }
- }
- Settings.Secure.putStringForUser(mContentResolver,
- Settings.System.MEDIA_BUTTON_RECEIVER, mediaButtonReceiverInfo,
- mFullUserId);
- }
-
- private void pushAddressedPlayerChangedLocked() {
- if (mCallback == null) {
- return;
- }
- try {
- MediaSessionRecord mediaButtonSession = getMediaButtonSessionLocked();
- if (mediaButtonSession != null) {
- mCallback.onAddressedPlayerChangedToMediaSession(
- new MediaSession.Token(mediaButtonSession.getControllerBinder()));
- } else if (mCurrentFullUserRecord.mLastMediaButtonReceiver != null) {
- mCallback.onAddressedPlayerChangedToMediaButtonReceiver(
- mCurrentFullUserRecord.mLastMediaButtonReceiver
- .getIntent().getComponent());
- } else if (mCurrentFullUserRecord.mRestoredMediaButtonReceiver != null) {
- mCallback.onAddressedPlayerChangedToMediaButtonReceiver(
- mCurrentFullUserRecord.mRestoredMediaButtonReceiver);
- }
- } catch (RemoteException e) {
- Log.w(TAG, "Failed to pushAddressedPlayerChangedLocked", e);
- }
- }
-
- private MediaSessionRecord getMediaButtonSessionLocked() {
- return isGlobalPriorityActiveLocked()
- ? mGlobalPrioritySession : mPriorityStack.getMediaButtonSession();
- }
-
- private int getComponentType(@Nullable ComponentName componentName) {
- if (componentName == null) {
- return COMPONENT_TYPE_INVALID;
- }
- PackageManager pm = getContext().getPackageManager();
- try {
- ActivityInfo activityInfo = pm.getActivityInfo(componentName,
- PackageManager.MATCH_DIRECT_BOOT_AWARE
- | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
- | PackageManager.GET_ACTIVITIES);
- if (activityInfo != null) {
- return COMPONENT_TYPE_ACTIVITY;
- }
- } catch (NameNotFoundException e) {
- }
- try {
- ServiceInfo serviceInfo = pm.getServiceInfo(componentName,
- PackageManager.MATCH_DIRECT_BOOT_AWARE
- | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
- | PackageManager.GET_SERVICES);
- if (serviceInfo != null) {
- return COMPONENT_TYPE_SERVICE;
- }
- } catch (NameNotFoundException e) {
- }
- // Pick legacy behavior for BroadcastReceiver or unknown.
- return COMPONENT_TYPE_BROADCAST;
- }
- }
-
- final class SessionsListenerRecord implements IBinder.DeathRecipient {
- public final IActiveSessionsListener listener;
- public final ComponentName componentName;
- public final int userId;
- public final int pid;
- public final int uid;
-
- public SessionsListenerRecord(IActiveSessionsListener listener,
- ComponentName componentName,
- int userId, int pid, int uid) {
- this.listener = listener;
- this.componentName = componentName;
- this.userId = userId;
- this.pid = pid;
- this.uid = uid;
- }
-
- @Override
- public void binderDied() {
- synchronized (mLock) {
- mSessionsListeners.remove(this);
- }
- }
- }
-
- final class Session2TokensListenerRecord implements IBinder.DeathRecipient {
- public final ISession2TokensListener listener;
- public final int userId;
-
- Session2TokensListenerRecord(ISession2TokensListener listener,
- int userId) {
- this.listener = listener;
- this.userId = userId;
- }
-
- @Override
- public void binderDied() {
- synchronized (mLock) {
- mSession2TokensListenerRecords.remove(this);
- }
- }
- }
-
- final class SettingsObserver extends ContentObserver {
- private final Uri mSecureSettingsUri = Settings.Secure.getUriFor(
- Settings.Secure.ENABLED_NOTIFICATION_LISTENERS);
-
- private SettingsObserver() {
- super(null);
- }
-
- private void observe() {
- mContentResolver.registerContentObserver(mSecureSettingsUri,
- false, this, USER_ALL);
- }
-
- @Override
- public void onChange(boolean selfChange, Uri uri) {
- updateActiveSessionListeners();
- }
- }
-
- class SessionManagerImpl extends ISessionManager.Stub {
- private static final String EXTRA_WAKELOCK_ACQUIRED =
- "android.media.AudioService.WAKELOCK_ACQUIRED";
- private static final int WAKELOCK_RELEASE_ON_FINISHED = 1980; // magic number
-
- private boolean mVoiceButtonDown = false;
- private boolean mVoiceButtonHandled = false;
-
- @Override
- public ISession createSession(String packageName, SessionCallbackLink cb, String tag,
- int userId) throws RemoteException {
- final int pid = Binder.getCallingPid();
- final int uid = Binder.getCallingUid();
- final long token = Binder.clearCallingIdentity();
- try {
- enforcePackageName(packageName, uid);
- int resolvedUserId = ActivityManager.handleIncomingUser(pid, uid, userId,
- false /* allowAll */, true /* requireFull */, "createSession", packageName);
- if (cb == null) {
- throw new IllegalArgumentException("Controller callback cannot be null");
- }
- return createSessionInternal(pid, uid, resolvedUserId, packageName, cb, tag)
- .getSessionBinder();
- } finally {
- Binder.restoreCallingIdentity(token);
- }
- }
-
- @Override
- public void notifySession2Created(Session2Token sessionToken) throws RemoteException {
- final int pid = Binder.getCallingPid();
- final int uid = Binder.getCallingUid();
- final long token = Binder.clearCallingIdentity();
- try {
- if (DEBUG) {
- Log.d(TAG, "Session2 is created " + sessionToken);
- }
- if (uid != sessionToken.getUid()) {
- throw new SecurityException("Unexpected Session2Token's UID, expected=" + uid
- + " but actually=" + sessionToken.getUid());
- }
- Controller2Callback callback = new Controller2Callback(sessionToken);
- // Note: It's safe not to keep controller here because it wouldn't be GC'ed until
- // it's closed.
- // TODO: Keep controller as well for better readability
- // because the GC behavior isn't straightforward.
- MediaController2 controller = new MediaController2(getContext(), sessionToken,
- new HandlerExecutor(mHandler), callback);
- } finally {
- Binder.restoreCallingIdentity(token);
- }
- }
-
- @Override
- public List<IBinder> getSessions(ComponentName componentName, int userId) {
- final int pid = Binder.getCallingPid();
- final int uid = Binder.getCallingUid();
- final long token = Binder.clearCallingIdentity();
-
- try {
- int resolvedUserId = verifySessionsRequest(componentName, userId, pid, uid);
- ArrayList<IBinder> binders = new ArrayList<IBinder>();
- synchronized (mLock) {
- List<MediaSessionRecord> records = getActiveSessionsLocked(resolvedUserId);
- for (MediaSessionRecord record : records) {
- binders.add(record.getControllerBinder().asBinder());
- }
- }
- return binders;
- } finally {
- Binder.restoreCallingIdentity(token);
- }
- }
-
- @Override
- public List<Session2Token> getSession2Tokens(int userId) {
- final int pid = Binder.getCallingPid();
- final int uid = Binder.getCallingUid();
- final long token = Binder.clearCallingIdentity();
-
- try {
- // Check that they can make calls on behalf of the user and
- // get the final user id
- int resolvedUserId = ActivityManager.handleIncomingUser(pid, uid, userId,
- true /* allowAll */, true /* requireFull */, "getSession2Tokens",
- null /* optional packageName */);
- List<Session2Token> result;
- synchronized (mLock) {
- result = getSession2TokensLocked(resolvedUserId);
- }
- return result;
- } finally {
- Binder.restoreCallingIdentity(token);
- }
- }
-
- @Override
- public void addSessionsListener(IActiveSessionsListener listener,
- ComponentName componentName, int userId) throws RemoteException {
- final int pid = Binder.getCallingPid();
- final int uid = Binder.getCallingUid();
- final long token = Binder.clearCallingIdentity();
-
- try {
- int resolvedUserId = verifySessionsRequest(componentName, userId, pid, uid);
- synchronized (mLock) {
- int index = findIndexOfSessionsListenerLocked(listener);
- if (index != -1) {
- Log.w(TAG, "ActiveSessionsListener is already added, ignoring");
- return;
- }
- SessionsListenerRecord record = new SessionsListenerRecord(listener,
- componentName, resolvedUserId, pid, uid);
- try {
- listener.asBinder().linkToDeath(record, 0);
- } catch (RemoteException e) {
- Log.e(TAG, "ActiveSessionsListener is dead, ignoring it", e);
- return;
- }
- mSessionsListeners.add(record);
- }
- } finally {
- Binder.restoreCallingIdentity(token);
- }
- }
-
- @Override
- public void removeSessionsListener(IActiveSessionsListener listener)
- throws RemoteException {
- synchronized (mLock) {
- int index = findIndexOfSessionsListenerLocked(listener);
- if (index != -1) {
- SessionsListenerRecord record = mSessionsListeners.remove(index);
- try {
- record.listener.asBinder().unlinkToDeath(record, 0);
- } catch (Exception e) {
- // ignore exceptions, the record is being removed
- }
- }
- }
- }
-
- @Override
- public void addSession2TokensListener(ISession2TokensListener listener,
- int userId) {
- final int pid = Binder.getCallingPid();
- final int uid = Binder.getCallingUid();
- final long token = Binder.clearCallingIdentity();
-
- try {
- // Check that they can make calls on behalf of the user and get the final user id.
- int resolvedUserId = ActivityManager.handleIncomingUser(pid, uid, userId,
- true /* allowAll */, true /* requireFull */, "addSession2TokensListener",
- null /* optional packageName */);
- synchronized (mLock) {
- int index = findIndexOfSession2TokensListenerLocked(listener);
- if (index >= 0) {
- Log.w(TAG, "addSession2TokensListener is already added, ignoring");
- return;
- }
- mSession2TokensListenerRecords.add(
- new Session2TokensListenerRecord(listener, resolvedUserId));
- }
- } finally {
- Binder.restoreCallingIdentity(token);
- }
- }
-
- @Override
- public void removeSession2TokensListener(ISession2TokensListener listener) {
- final int pid = Binder.getCallingPid();
- final int uid = Binder.getCallingUid();
- final long token = Binder.clearCallingIdentity();
-
- try {
- synchronized (mLock) {
- int index = findIndexOfSession2TokensListenerLocked(listener);
- if (index >= 0) {
- Session2TokensListenerRecord listenerRecord =
- mSession2TokensListenerRecords.remove(index);
- try {
- listenerRecord.listener.asBinder().unlinkToDeath(listenerRecord, 0);
- } catch (Exception e) {
- // Ignore exception.
- }
- }
- }
- } finally {
- Binder.restoreCallingIdentity(token);
- }
- }
-
- /**
- * Handles the dispatching of the media button events to one of the
- * registered listeners, or if there was none, broadcast an
- * ACTION_MEDIA_BUTTON intent to the rest of the system.
- *
- * @param packageName The caller package
- * @param asSystemService {@code true} if the event sent to the session as if it was come
- * from the system service instead of the app process. This helps sessions to
- * distinguish between the key injection by the app and key events from the
- * hardware devices. Should be used only when the volume key events aren't handled
- * by foreground activity. {@code false} otherwise to tell session about the real
- * caller.
- * @param keyEvent a non-null KeyEvent whose key code is one of the
- * supported media buttons
- * @param needWakeLock true if a PARTIAL_WAKE_LOCK needs to be held
- * while this key event is dispatched.
- */
- @Override
- public void dispatchMediaKeyEvent(String packageName, boolean asSystemService,
- KeyEvent keyEvent, boolean needWakeLock) {
- if (keyEvent == null || !KeyEvent.isMediaSessionKey(keyEvent.getKeyCode())) {
- Log.w(TAG, "Attempted to dispatch null or non-media key event.");
- return;
- }
-
- final int pid = Binder.getCallingPid();
- final int uid = Binder.getCallingUid();
- final long token = Binder.clearCallingIdentity();
- try {
- if (DEBUG) {
- Log.d(TAG, "dispatchMediaKeyEvent, pkg=" + packageName + " pid=" + pid
- + ", uid=" + uid + ", asSystem=" + asSystemService + ", event="
- + keyEvent);
- }
- if (!isUserSetupComplete()) {
- // Global media key handling can have the side-effect of starting new
- // activities which is undesirable while setup is in progress.
- Slog.i(TAG, "Not dispatching media key event because user "
- + "setup is in progress.");
- return;
- }
-
- synchronized (mLock) {
- boolean isGlobalPriorityActive = isGlobalPriorityActiveLocked();
- if (isGlobalPriorityActive && uid != Process.SYSTEM_UID) {
- // Prevent dispatching key event through reflection while the global
- // priority session is active.
- Slog.i(TAG, "Only the system can dispatch media key event "
- + "to the global priority session.");
- return;
- }
- if (!isGlobalPriorityActive) {
- if (mCurrentFullUserRecord.mOnMediaKeyListener != null) {
- if (DEBUG_KEY_EVENT) {
- Log.d(TAG, "Send " + keyEvent + " to the media key listener");
- }
- try {
- mCurrentFullUserRecord.mOnMediaKeyListener.onMediaKey(keyEvent,
- new MediaKeyListenerResultReceiver(packageName, pid, uid,
- asSystemService, keyEvent, needWakeLock));
- return;
- } catch (RemoteException e) {
- Log.w(TAG, "Failed to send " + keyEvent
- + " to the media key listener");
- }
- }
- }
- if (!isGlobalPriorityActive && isVoiceKey(keyEvent.getKeyCode())) {
- handleVoiceKeyEventLocked(packageName, pid, uid, asSystemService, keyEvent,
- needWakeLock);
- } else {
- dispatchMediaKeyEventLocked(packageName, pid, uid, asSystemService,
- keyEvent, needWakeLock);
- }
- }
- } finally {
- Binder.restoreCallingIdentity(token);
- }
- }
-
- @Override
- public void setCallback(ICallback callback) {
- final int pid = Binder.getCallingPid();
- final int uid = Binder.getCallingUid();
- final long token = Binder.clearCallingIdentity();
- try {
- if (!UserHandle.isSameApp(uid, Process.BLUETOOTH_UID)) {
- throw new SecurityException("Only Bluetooth service processes can set"
- + " Callback");
- }
- synchronized (mLock) {
- int userId = UserHandle.getUserId(uid);
- FullUserRecord user = getFullUserRecordLocked(userId);
- if (user == null || user.mFullUserId != userId) {
- Log.w(TAG, "Only the full user can set the callback"
- + ", userId=" + userId);
- return;
- }
- user.mCallback = callback;
- Log.d(TAG, "The callback " + user.mCallback
- + " is set by " + getCallingPackageName(uid));
- if (user.mCallback == null) {
- return;
- }
- try {
- user.mCallback.asBinder().linkToDeath(
- new IBinder.DeathRecipient() {
- @Override
- public void binderDied() {
- synchronized (mLock) {
- user.mCallback = null;
- }
- }
- }, 0);
- user.pushAddressedPlayerChangedLocked();
- } catch (RemoteException e) {
- Log.w(TAG, "Failed to set callback", e);
- user.mCallback = null;
- }
- }
- } finally {
- Binder.restoreCallingIdentity(token);
- }
- }
-
- @Override
- public void setOnVolumeKeyLongPressListener(IOnVolumeKeyLongPressListener listener) {
- final int pid = Binder.getCallingPid();
- final int uid = Binder.getCallingUid();
- final long token = Binder.clearCallingIdentity();
- try {
- // Enforce SET_VOLUME_KEY_LONG_PRESS_LISTENER permission.
- if (getContext().checkPermission(
- android.Manifest.permission.SET_VOLUME_KEY_LONG_PRESS_LISTENER, pid, uid)
- != PackageManager.PERMISSION_GRANTED) {
- throw new SecurityException("Must hold the SET_VOLUME_KEY_LONG_PRESS_LISTENER" +
- " permission.");
- }
-
- synchronized (mLock) {
- int userId = UserHandle.getUserId(uid);
- FullUserRecord user = getFullUserRecordLocked(userId);
- if (user == null || user.mFullUserId != userId) {
- Log.w(TAG, "Only the full user can set the volume key long-press listener"
- + ", userId=" + userId);
- return;
- }
- if (user.mOnVolumeKeyLongPressListener != null &&
- user.mOnVolumeKeyLongPressListenerUid != uid) {
- Log.w(TAG, "The volume key long-press listener cannot be reset"
- + " by another app , mOnVolumeKeyLongPressListener="
- + user.mOnVolumeKeyLongPressListenerUid
- + ", uid=" + uid);
- return;
- }
-
- user.mOnVolumeKeyLongPressListener = listener;
- user.mOnVolumeKeyLongPressListenerUid = uid;
-
- Log.d(TAG, "The volume key long-press listener "
- + listener + " is set by " + getCallingPackageName(uid));
-
- if (user.mOnVolumeKeyLongPressListener != null) {
- try {
- user.mOnVolumeKeyLongPressListener.asBinder().linkToDeath(
- new IBinder.DeathRecipient() {
- @Override
- public void binderDied() {
- synchronized (mLock) {
- user.mOnVolumeKeyLongPressListener = null;
- }
- }
- }, 0);
- } catch (RemoteException e) {
- Log.w(TAG, "Failed to set death recipient "
- + user.mOnVolumeKeyLongPressListener);
- user.mOnVolumeKeyLongPressListener = null;
- }
- }
- }
- } finally {
- Binder.restoreCallingIdentity(token);
- }
- }
-
- @Override
- public void setOnMediaKeyListener(IOnMediaKeyListener listener) {
- final int pid = Binder.getCallingPid();
- final int uid = Binder.getCallingUid();
- final long token = Binder.clearCallingIdentity();
- try {
- // Enforce SET_MEDIA_KEY_LISTENER permission.
- if (getContext().checkPermission(
- android.Manifest.permission.SET_MEDIA_KEY_LISTENER, pid, uid)
- != PackageManager.PERMISSION_GRANTED) {
- throw new SecurityException("Must hold the SET_MEDIA_KEY_LISTENER" +
- " permission.");
- }
-
- synchronized (mLock) {
- int userId = UserHandle.getUserId(uid);
- FullUserRecord user = getFullUserRecordLocked(userId);
- if (user == null || user.mFullUserId != userId) {
- Log.w(TAG, "Only the full user can set the media key listener"
- + ", userId=" + userId);
- return;
- }
- if (user.mOnMediaKeyListener != null && user.mOnMediaKeyListenerUid != uid) {
- Log.w(TAG, "The media key listener cannot be reset by another app. "
- + ", mOnMediaKeyListenerUid=" + user.mOnMediaKeyListenerUid
- + ", uid=" + uid);
- return;
- }
-
- user.mOnMediaKeyListener = listener;
- user.mOnMediaKeyListenerUid = uid;
-
- Log.d(TAG, "The media key listener " + user.mOnMediaKeyListener
- + " is set by " + getCallingPackageName(uid));
-
- if (user.mOnMediaKeyListener != null) {
- try {
- user.mOnMediaKeyListener.asBinder().linkToDeath(
- new IBinder.DeathRecipient() {
- @Override
- public void binderDied() {
- synchronized (mLock) {
- user.mOnMediaKeyListener = null;
- }
- }
- }, 0);
- } catch (RemoteException e) {
- Log.w(TAG, "Failed to set death recipient " + user.mOnMediaKeyListener);
- user.mOnMediaKeyListener = null;
- }
- }
- }
- } finally {
- Binder.restoreCallingIdentity(token);
- }
- }
-
- /**
- * Handles the dispatching of the volume button events to one of the
- * registered listeners. If there's a volume key long-press listener and
- * there's no active global priority session, long-pressess will be sent to the
- * long-press listener instead of adjusting volume.
- *
- * @param packageName The caller's package name, obtained by Context#getPackageName()
- * @param opPackageName The caller's op package name, obtained by Context#getOpPackageName()
- * @param asSystemService {@code true} if the event sent to the session as if it was come
- * from the system service instead of the app process. This helps sessions to
- * distinguish between the key injection by the app and key events from the
- * hardware devices. Should be used only when the volume key events aren't handled
- * by foreground activity. {@code false} otherwise to tell session about the real
- * caller.
- * @param keyEvent a non-null KeyEvent whose key code is one of the
- * {@link KeyEvent#KEYCODE_VOLUME_UP},
- * {@link KeyEvent#KEYCODE_VOLUME_DOWN},
- * or {@link KeyEvent#KEYCODE_VOLUME_MUTE}.
- * @param stream stream type to adjust volume.
- * @param musicOnly true if both UI nor haptic feedback aren't needed when adjust volume.
- */
- @Override
- public void dispatchVolumeKeyEvent(String packageName, String opPackageName,
- boolean asSystemService, KeyEvent keyEvent, int stream, boolean musicOnly) {
- if (keyEvent == null ||
- (keyEvent.getKeyCode() != KeyEvent.KEYCODE_VOLUME_UP
- && keyEvent.getKeyCode() != KeyEvent.KEYCODE_VOLUME_DOWN
- && keyEvent.getKeyCode() != KeyEvent.KEYCODE_VOLUME_MUTE)) {
- Log.w(TAG, "Attempted to dispatch null or non-volume key event.");
- return;
- }
-
- final int pid = Binder.getCallingPid();
- final int uid = Binder.getCallingUid();
- final long token = Binder.clearCallingIdentity();
-
- if (DEBUG_KEY_EVENT) {
- Log.d(TAG, "dispatchVolumeKeyEvent, pkg=" + packageName + ", pid=" + pid + ", uid="
- + uid + ", asSystem=" + asSystemService + ", event=" + keyEvent);
- }
-
- try {
- synchronized (mLock) {
- if (isGlobalPriorityActiveLocked()
- || mCurrentFullUserRecord.mOnVolumeKeyLongPressListener == null) {
- dispatchVolumeKeyEventLocked(packageName, opPackageName, pid, uid,
- asSystemService, keyEvent, stream, musicOnly);
- } else {
- // TODO: Consider the case when both volume up and down keys are pressed
- // at the same time.
- if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
- if (keyEvent.getRepeatCount() == 0) {
- // Keeps the copy of the KeyEvent because it can be reused.
- mCurrentFullUserRecord.mInitialDownVolumeKeyEvent =
- KeyEvent.obtain(keyEvent);
- mCurrentFullUserRecord.mInitialDownVolumeStream = stream;
- mCurrentFullUserRecord.mInitialDownMusicOnly = musicOnly;
- mHandler.sendMessageDelayed(
- mHandler.obtainMessage(
- MessageHandler.MSG_VOLUME_INITIAL_DOWN,
- mCurrentFullUserRecord.mFullUserId, 0),
- mLongPressTimeout);
- }
- if (keyEvent.getRepeatCount() > 0 || keyEvent.isLongPress()) {
- mHandler.removeMessages(MessageHandler.MSG_VOLUME_INITIAL_DOWN);
- if (mCurrentFullUserRecord.mInitialDownVolumeKeyEvent != null) {
- dispatchVolumeKeyLongPressLocked(
- mCurrentFullUserRecord.mInitialDownVolumeKeyEvent);
- // Mark that the key is already handled.
- mCurrentFullUserRecord.mInitialDownVolumeKeyEvent = null;
- }
- dispatchVolumeKeyLongPressLocked(keyEvent);
- }
- } else { // if up
- mHandler.removeMessages(MessageHandler.MSG_VOLUME_INITIAL_DOWN);
- if (mCurrentFullUserRecord.mInitialDownVolumeKeyEvent != null
- && mCurrentFullUserRecord.mInitialDownVolumeKeyEvent
- .getDownTime() == keyEvent.getDownTime()) {
- // Short-press. Should change volume.
- dispatchVolumeKeyEventLocked(packageName, opPackageName, pid, uid,
- asSystemService,
- mCurrentFullUserRecord.mInitialDownVolumeKeyEvent,
- mCurrentFullUserRecord.mInitialDownVolumeStream,
- mCurrentFullUserRecord.mInitialDownMusicOnly);
- dispatchVolumeKeyEventLocked(packageName, opPackageName, pid, uid,
- asSystemService, keyEvent, stream, musicOnly);
- } else {
- dispatchVolumeKeyLongPressLocked(keyEvent);
- }
- }
- }
- }
- } finally {
- Binder.restoreCallingIdentity(token);
- }
- }
-
- private void dispatchVolumeKeyEventLocked(String packageName, String opPackageName, int pid,
- int uid, boolean asSystemService, KeyEvent keyEvent, int stream,
- boolean musicOnly) {
- boolean down = keyEvent.getAction() == KeyEvent.ACTION_DOWN;
- boolean up = keyEvent.getAction() == KeyEvent.ACTION_UP;
- int direction = 0;
- boolean isMute = false;
- switch (keyEvent.getKeyCode()) {
- case KeyEvent.KEYCODE_VOLUME_UP:
- direction = AudioManager.ADJUST_RAISE;
- break;
- case KeyEvent.KEYCODE_VOLUME_DOWN:
- direction = AudioManager.ADJUST_LOWER;
- break;
- case KeyEvent.KEYCODE_VOLUME_MUTE:
- isMute = true;
- break;
- }
- if (down || up) {
- int flags = AudioManager.FLAG_FROM_KEY;
- if (musicOnly) {
- // This flag is used when the screen is off to only affect active media.
- flags |= AudioManager.FLAG_ACTIVE_MEDIA_ONLY;
- } else {
- // These flags are consistent with the home screen
- if (up) {
- flags |= AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_VIBRATE;
- } else {
- flags |= AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_VIBRATE;
- }
- }
- if (direction != 0) {
- // If this is action up we want to send a beep for non-music events
- if (up) {
- direction = 0;
- }
- dispatchAdjustVolumeLocked(packageName, opPackageName, pid, uid,
- asSystemService, stream, direction, flags);
- } else if (isMute) {
- if (down && keyEvent.getRepeatCount() == 0) {
- dispatchAdjustVolumeLocked(packageName, opPackageName, pid, uid,
- asSystemService, stream, AudioManager.ADJUST_TOGGLE_MUTE, flags);
- }
- }
- }
- }
-
- @Override
- public void dispatchAdjustVolume(String packageName, String opPackageName,
- int suggestedStream, int delta, int flags) {
- final int pid = Binder.getCallingPid();
- final int uid = Binder.getCallingUid();
- final long token = Binder.clearCallingIdentity();
- try {
- synchronized (mLock) {
- dispatchAdjustVolumeLocked(packageName, opPackageName, pid, uid, false,
- suggestedStream, delta, flags);
- }
- } finally {
- Binder.restoreCallingIdentity(token);
- }
- }
-
- @Override
- public void setRemoteVolumeController(IRemoteVolumeController rvc) {
- final int pid = Binder.getCallingPid();
- final int uid = Binder.getCallingUid();
- final long token = Binder.clearCallingIdentity();
- try {
- enforceSystemUiPermission("listen for volume changes", pid, uid);
- mRvc = rvc;
- } finally {
- Binder.restoreCallingIdentity(token);
- }
- }
-
- @Override
- public boolean isGlobalPriorityActive() {
- synchronized (mLock) {
- return isGlobalPriorityActiveLocked();
- }
- }
-
- @Override
- public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
- if (!DumpUtils.checkDumpPermission(getContext(), TAG, pw)) return;
-
- pw.println("MEDIA SESSION SERVICE (dumpsys media_session)");
- pw.println();
-
- synchronized (mLock) {
- pw.println(mSessionsListeners.size() + " sessions listeners.");
- pw.println("Global priority session is " + mGlobalPrioritySession);
- if (mGlobalPrioritySession != null) {
- mGlobalPrioritySession.dump(pw, " ");
- }
- pw.println("User Records:");
- int count = mUserRecords.size();
- for (int i = 0; i < count; i++) {
- mUserRecords.valueAt(i).dumpLocked(pw, "");
- }
- mAudioPlayerStateMonitor.dump(getContext(), pw, "");
- }
- }
-
- /**
- * Returns if the controller's package is trusted (i.e. has either MEDIA_CONTENT_CONTROL
- * permission or an enabled notification listener)
- *
- * @param controllerPackageName package name of the controller app
- * @param controllerPid pid of the controller app
- * @param controllerUid uid of the controller app
- */
- @Override
- public boolean isTrusted(String controllerPackageName, int controllerPid, int controllerUid)
- throws RemoteException {
- final int uid = Binder.getCallingUid();
- final long token = Binder.clearCallingIdentity();
- try {
- // Don't perform sanity check between controllerPackageName and controllerUid.
- // When an (activity|service) runs on the another apps process by specifying
- // android:process in the AndroidManifest.xml, then PID and UID would have the
- // running process' information instead of the (activity|service) that has created
- // MediaController.
- // Note that we can use Context#getOpPackageName() instead of
- // Context#getPackageName() for getting package name that matches with the PID/UID,
- // but it doesn't tell which package has created the MediaController, so useless.
- return hasMediaControlPermission(UserHandle.getUserId(uid), controllerPackageName,
- controllerPid, controllerUid);
- } finally {
- Binder.restoreCallingIdentity(token);
- }
- }
-
- // For MediaSession
- private int verifySessionsRequest(ComponentName componentName, int userId, final int pid,
- final int uid) {
- String packageName = null;
- if (componentName != null) {
- // If they gave us a component name verify they own the
- // package
- packageName = componentName.getPackageName();
- enforcePackageName(packageName, uid);
- }
- // Check that they can make calls on behalf of the user and
- // get the final user id
- int resolvedUserId = ActivityManager.handleIncomingUser(pid, uid, userId,
- true /* allowAll */, true /* requireFull */, "getSessions", packageName);
- // Check if they have the permissions or their component is
- // enabled for the user they're calling from.
- enforceMediaPermissions(componentName, pid, uid, resolvedUserId);
- return resolvedUserId;
- }
-
- private boolean hasMediaControlPermission(int resolvedUserId, String packageName,
- int pid, int uid) throws RemoteException {
- // Allow API calls from the System UI
- if (isCurrentVolumeController(pid, uid)) {
- return true;
- }
-
- // Check if it's system server or has MEDIA_CONTENT_CONTROL.
- // Note that system server doesn't have MEDIA_CONTENT_CONTROL, so we need extra
- // check here.
- if (uid == Process.SYSTEM_UID || getContext().checkPermission(
- android.Manifest.permission.MEDIA_CONTENT_CONTROL, pid, uid)
- == PackageManager.PERMISSION_GRANTED) {
- return true;
- } else if (DEBUG) {
- Log.d(TAG, packageName + " (uid=" + uid + ") hasn't granted MEDIA_CONTENT_CONTROL");
- }
-
- // You may not access another user's content as an enabled listener.
- final int userId = UserHandle.getUserId(uid);
- if (resolvedUserId != userId) {
- return false;
- }
-
- // TODO(jaewan): (Post-P) Propose NotificationManager#hasEnabledNotificationListener(
- // String pkgName) to notification team for optimization
- final List<ComponentName> enabledNotificationListeners =
- mNotificationManager.getEnabledNotificationListeners(userId);
- if (enabledNotificationListeners != null) {
- for (int i = 0; i < enabledNotificationListeners.size(); i++) {
- if (TextUtils.equals(packageName,
- enabledNotificationListeners.get(i).getPackageName())) {
- return true;
- }
- }
- }
- if (DEBUG) {
- Log.d(TAG, packageName + " (uid=" + uid + ") doesn't have an enabled "
- + "notification listener");
- }
- return false;
- }
-
- private void dispatchAdjustVolumeLocked(String packageName, String opPackageName, int pid,
- int uid, boolean asSystemService, int suggestedStream, int direction, int flags) {
- MediaSessionRecord session = isGlobalPriorityActiveLocked() ? mGlobalPrioritySession
- : mCurrentFullUserRecord.mPriorityStack.getDefaultVolumeSession();
-
- boolean preferSuggestedStream = false;
- if (isValidLocalStreamType(suggestedStream)
- && AudioSystem.isStreamActive(suggestedStream, 0)) {
- preferSuggestedStream = true;
- }
- if (DEBUG_KEY_EVENT) {
- Log.d(TAG, "Adjusting " + session + " by " + direction + ". flags="
- + flags + ", suggestedStream=" + suggestedStream
- + ", preferSuggestedStream=" + preferSuggestedStream);
- }
- if (session == null || preferSuggestedStream) {
- if ((flags & AudioManager.FLAG_ACTIVE_MEDIA_ONLY) != 0
- && !AudioSystem.isStreamActive(AudioManager.STREAM_MUSIC, 0)) {
- if (DEBUG) {
- Log.d(TAG, "No active session to adjust, skipping media only volume event");
- }
- return;
- }
-
- // Execute mAudioService.adjustSuggestedStreamVolume() on
- // handler thread of MediaSessionService.
- // This will release the MediaSessionService.mLock sooner and avoid
- // a potential deadlock between MediaSessionService.mLock and
- // ActivityManagerService lock.
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- final String callingOpPackageName;
- final int callingUid;
- if (asSystemService) {
- callingOpPackageName = getContext().getOpPackageName();
- callingUid = Process.myUid();
- } else {
- callingOpPackageName = opPackageName;
- callingUid = uid;
- }
- try {
- mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(suggestedStream,
- direction, flags, callingOpPackageName, callingUid);
- } catch (SecurityException | IllegalArgumentException e) {
- Log.e(TAG, "Cannot adjust volume: direction=" + direction
- + ", suggestedStream=" + suggestedStream + ", flags=" + flags
- + ", packageName=" + packageName + ", uid=" + uid
- + ", asSystemService=" + asSystemService, e);
- }
- }
- });
- } else {
- session.adjustVolume(packageName, opPackageName, pid, uid, null, asSystemService,
- direction, flags, true);
- }
- }
-
- private void handleVoiceKeyEventLocked(String packageName, int pid, int uid,
- boolean asSystemService, KeyEvent keyEvent, boolean needWakeLock) {
- int action = keyEvent.getAction();
- boolean isLongPress = (keyEvent.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0;
- if (action == KeyEvent.ACTION_DOWN) {
- if (keyEvent.getRepeatCount() == 0) {
- mVoiceButtonDown = true;
- mVoiceButtonHandled = false;
- } else if (mVoiceButtonDown && !mVoiceButtonHandled && isLongPress) {
- mVoiceButtonHandled = true;
- startVoiceInput(needWakeLock);
- }
- } else if (action == KeyEvent.ACTION_UP) {
- if (mVoiceButtonDown) {
- mVoiceButtonDown = false;
- if (!mVoiceButtonHandled && !keyEvent.isCanceled()) {
- // Resend the down then send this event through
- KeyEvent downEvent = KeyEvent.changeAction(keyEvent, KeyEvent.ACTION_DOWN);
- dispatchMediaKeyEventLocked(packageName, pid, uid, asSystemService,
- downEvent, needWakeLock);
- dispatchMediaKeyEventLocked(packageName, pid, uid, asSystemService,
- keyEvent, needWakeLock);
- }
- }
- }
- }
-
- private void dispatchMediaKeyEventLocked(String packageName, int pid, int uid,
- boolean asSystemService, KeyEvent keyEvent, boolean needWakeLock) {
- MediaSessionRecord session = mCurrentFullUserRecord.getMediaButtonSessionLocked();
- if (session != null) {
- if (DEBUG_KEY_EVENT) {
- Log.d(TAG, "Sending " + keyEvent + " to " + session);
- }
- if (needWakeLock) {
- mKeyEventReceiver.aquireWakeLockLocked();
- }
- // If we don't need a wakelock use -1 as the id so we won't release it later.
- session.sendMediaButton(packageName, pid, uid, asSystemService, keyEvent,
- needWakeLock ? mKeyEventReceiver.mLastTimeoutId : -1,
- mKeyEventReceiver);
- if (mCurrentFullUserRecord.mCallback != null) {
- try {
- mCurrentFullUserRecord.mCallback.onMediaKeyEventDispatchedToMediaSession(
- keyEvent, new MediaSession.Token(session.getControllerBinder()));
- } catch (RemoteException e) {
- Log.w(TAG, "Failed to send callback", e);
- }
- }
- } else if (mCurrentFullUserRecord.mLastMediaButtonReceiver != null
- || mCurrentFullUserRecord.mRestoredMediaButtonReceiver != null) {
- if (needWakeLock) {
- mKeyEventReceiver.aquireWakeLockLocked();
- }
- Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
- mediaButtonIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
- mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
- // TODO: Find a way to also send PID/UID in secure way.
- String callerPackageName =
- (asSystemService) ? getContext().getPackageName() : packageName;
- mediaButtonIntent.putExtra(Intent.EXTRA_PACKAGE_NAME, callerPackageName);
- try {
- if (mCurrentFullUserRecord.mLastMediaButtonReceiver != null) {
- PendingIntent receiver = mCurrentFullUserRecord.mLastMediaButtonReceiver;
- if (DEBUG_KEY_EVENT) {
- Log.d(TAG, "Sending " + keyEvent
- + " to the last known PendingIntent " + receiver);
- }
- receiver.send(getContext(),
- needWakeLock ? mKeyEventReceiver.mLastTimeoutId : -1,
- mediaButtonIntent, mKeyEventReceiver, mHandler);
- if (mCurrentFullUserRecord.mCallback != null) {
- ComponentName componentName = mCurrentFullUserRecord
- .mLastMediaButtonReceiver.getIntent().getComponent();
- if (componentName != null) {
- mCurrentFullUserRecord.mCallback
- .onMediaKeyEventDispatchedToMediaButtonReceiver(
- keyEvent, componentName);
- }
- }
- } else {
- ComponentName receiver =
- mCurrentFullUserRecord.mRestoredMediaButtonReceiver;
- int componentType = mCurrentFullUserRecord
- .mRestoredMediaButtonReceiverComponentType;
- UserHandle userHandle = UserHandle.of(mCurrentFullUserRecord
- .mRestoredMediaButtonReceiverUserId);
- if (DEBUG_KEY_EVENT) {
- Log.d(TAG, "Sending " + keyEvent + " to the restored intent "
- + receiver + ", type=" + componentType);
- }
- mediaButtonIntent.setComponent(receiver);
- try {
- switch (componentType) {
- case FullUserRecord.COMPONENT_TYPE_ACTIVITY:
- getContext().startActivityAsUser(mediaButtonIntent, userHandle);
- break;
- case FullUserRecord.COMPONENT_TYPE_SERVICE:
- getContext().startForegroundServiceAsUser(mediaButtonIntent,
- userHandle);
- break;
- default:
- // Legacy behavior for other cases.
- getContext().sendBroadcastAsUser(mediaButtonIntent, userHandle);
- }
- } catch (Exception e) {
- Log.w(TAG, "Error sending media button to the restored intent "
- + receiver + ", type=" + componentType, e);
- }
- if (mCurrentFullUserRecord.mCallback != null) {
- mCurrentFullUserRecord.mCallback
- .onMediaKeyEventDispatchedToMediaButtonReceiver(
- keyEvent, receiver);
- }
- }
- } catch (CanceledException e) {
- Log.i(TAG, "Error sending key event to media button receiver "
- + mCurrentFullUserRecord.mLastMediaButtonReceiver, e);
- } catch (RemoteException e) {
- Log.w(TAG, "Failed to send callback", e);
- }
- }
- }
-
- private void startVoiceInput(boolean needWakeLock) {
- Intent voiceIntent = null;
- // select which type of search to launch:
- // - screen on and device unlocked: action is ACTION_WEB_SEARCH
- // - device locked or screen off: action is
- // ACTION_VOICE_SEARCH_HANDS_FREE
- // with EXTRA_SECURE set to true if the device is securely locked
- PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
- boolean isLocked = mKeyguardManager != null && mKeyguardManager.isKeyguardLocked();
- if (!isLocked && pm.isScreenOn()) {
- voiceIntent = new Intent(android.speech.RecognizerIntent.ACTION_WEB_SEARCH);
- Log.i(TAG, "voice-based interactions: about to use ACTION_WEB_SEARCH");
- } else {
- voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
- voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE,
- isLocked && mKeyguardManager.isKeyguardSecure());
- Log.i(TAG, "voice-based interactions: about to use ACTION_VOICE_SEARCH_HANDS_FREE");
- }
- // start the search activity
- if (needWakeLock) {
- mMediaEventWakeLock.acquire();
- }
- try {
- if (voiceIntent != null) {
- voiceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
- | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
- if (DEBUG) Log.d(TAG, "voiceIntent: " + voiceIntent);
- getContext().startActivityAsUser(voiceIntent, UserHandle.CURRENT);
- }
- } catch (ActivityNotFoundException e) {
- Log.w(TAG, "No activity for search: " + e);
- } finally {
- if (needWakeLock) {
- mMediaEventWakeLock.release();
- }
- }
- }
-
- private boolean isVoiceKey(int keyCode) {
- return keyCode == KeyEvent.KEYCODE_HEADSETHOOK
- || (!mHasFeatureLeanback && keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
- }
-
- private boolean isUserSetupComplete() {
- return Settings.Secure.getIntForUser(getContext().getContentResolver(),
- Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
- }
-
- // we only handle public stream types, which are 0-5
- private boolean isValidLocalStreamType(int streamType) {
- return streamType >= AudioManager.STREAM_VOICE_CALL
- && streamType <= AudioManager.STREAM_NOTIFICATION;
- }
-
- private class MediaKeyListenerResultReceiver extends ResultReceiver implements Runnable {
- private final String mPackageName;
- private final int mPid;
- private final int mUid;
- private final boolean mAsSystemService;
- private final KeyEvent mKeyEvent;
- private final boolean mNeedWakeLock;
- private boolean mHandled;
-
- private MediaKeyListenerResultReceiver(String packageName, int pid, int uid,
- boolean asSystemService, KeyEvent keyEvent, boolean needWakeLock) {
- super(mHandler);
- mHandler.postDelayed(this, MEDIA_KEY_LISTENER_TIMEOUT);
- mPackageName = packageName;
- mPid = pid;
- mUid = uid;
- mAsSystemService = asSystemService;
- mKeyEvent = keyEvent;
- mNeedWakeLock = needWakeLock;
- }
-
- @Override
- public void run() {
- Log.d(TAG, "The media key listener is timed-out for " + mKeyEvent);
- dispatchMediaKeyEvent();
- }
-
- @Override
- protected void onReceiveResult(int resultCode, Bundle resultData) {
- if (resultCode == MediaSessionManager.RESULT_MEDIA_KEY_HANDLED) {
- mHandled = true;
- mHandler.removeCallbacks(this);
- return;
- }
- dispatchMediaKeyEvent();
- }
-
- private void dispatchMediaKeyEvent() {
- if (mHandled) {
- return;
- }
- mHandled = true;
- mHandler.removeCallbacks(this);
- synchronized (mLock) {
- if (!isGlobalPriorityActiveLocked()
- && isVoiceKey(mKeyEvent.getKeyCode())) {
- handleVoiceKeyEventLocked(mPackageName, mPid, mUid, mAsSystemService,
- mKeyEvent, mNeedWakeLock);
- } else {
- dispatchMediaKeyEventLocked(mPackageName, mPid, mUid, mAsSystemService,
- mKeyEvent, mNeedWakeLock);
- }
- }
- }
- }
-
- private KeyEventWakeLockReceiver mKeyEventReceiver = new KeyEventWakeLockReceiver(mHandler);
-
- class KeyEventWakeLockReceiver extends ResultReceiver implements Runnable,
- PendingIntent.OnFinished {
- private final Handler mHandler;
- private int mRefCount = 0;
- private int mLastTimeoutId = 0;
-
- public KeyEventWakeLockReceiver(Handler handler) {
- super(handler);
- mHandler = handler;
- }
-
- public void onTimeout() {
- synchronized (mLock) {
- if (mRefCount == 0) {
- // We've already released it, so just return
- return;
- }
- mLastTimeoutId++;
- mRefCount = 0;
- releaseWakeLockLocked();
- }
- }
-
- public void aquireWakeLockLocked() {
- if (mRefCount == 0) {
- mMediaEventWakeLock.acquire();
- }
- mRefCount++;
- mHandler.removeCallbacks(this);
- mHandler.postDelayed(this, WAKELOCK_TIMEOUT);
-
- }
-
- @Override
- public void run() {
- onTimeout();
- }
-
- @Override
- protected void onReceiveResult(int resultCode, Bundle resultData) {
- if (resultCode < mLastTimeoutId) {
- // Ignore results from calls that were before the last
- // timeout, just in case.
- return;
- } else {
- synchronized (mLock) {
- if (mRefCount > 0) {
- mRefCount--;
- if (mRefCount == 0) {
- releaseWakeLockLocked();
- }
- }
- }
- }
- }
-
- private void releaseWakeLockLocked() {
- mMediaEventWakeLock.release();
- mHandler.removeCallbacks(this);
- }
-
- @Override
- public void onSendFinished(PendingIntent pendingIntent, Intent intent, int resultCode,
- String resultData, Bundle resultExtras) {
- onReceiveResult(resultCode, null);
- }
- };
-
- BroadcastReceiver mKeyEventDone = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent == null) {
- return;
- }
- Bundle extras = intent.getExtras();
- if (extras == null) {
- return;
- }
- synchronized (mLock) {
- if (extras.containsKey(EXTRA_WAKELOCK_ACQUIRED)
- && mMediaEventWakeLock.isHeld()) {
- mMediaEventWakeLock.release();
- }
- }
- }
- };
- }
-
- final class MessageHandler extends Handler {
- private static final int MSG_SESSIONS_CHANGED = 1;
- private static final int MSG_VOLUME_INITIAL_DOWN = 2;
- private final SparseArray<Integer> mIntegerCache = new SparseArray<>();
-
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case MSG_SESSIONS_CHANGED:
- pushSessionsChanged((int) msg.obj);
- break;
- case MSG_VOLUME_INITIAL_DOWN:
- synchronized (mLock) {
- FullUserRecord user = mUserRecords.get((int) msg.arg1);
- if (user != null && user.mInitialDownVolumeKeyEvent != null) {
- dispatchVolumeKeyLongPressLocked(user.mInitialDownVolumeKeyEvent);
- // Mark that the key is already handled.
- user.mInitialDownVolumeKeyEvent = null;
- }
- }
- break;
- }
- }
-
- public void postSessionsChanged(int userId) {
- // Use object instead of the arguments when posting message to remove pending requests.
- Integer userIdInteger = mIntegerCache.get(userId);
- if (userIdInteger == null) {
- userIdInteger = Integer.valueOf(userId);
- mIntegerCache.put(userId, userIdInteger);
- }
- removeMessages(MSG_SESSIONS_CHANGED, userIdInteger);
- obtainMessage(MSG_SESSIONS_CHANGED, userIdInteger).sendToTarget();
- }
- }
-
- private class Controller2Callback extends MediaController2.ControllerCallback {
- private final Session2Token mToken;
-
- Controller2Callback(Session2Token token) {
- mToken = token;
- }
-
- @Override
- public void onConnected(MediaController2 controller, Session2CommandGroup allowedCommands) {
- synchronized (mLock) {
- int userId = UserHandle.getUserId(mToken.getUid());
- mSession2TokensPerUser.get(userId).add(mToken);
- pushSession2TokensChangedLocked(userId);
- }
- }
-
- @Override
- public void onDisconnected(MediaController2 controller) {
- synchronized (mLock) {
- int userId = UserHandle.getUserId(mToken.getUid());
- mSession2TokensPerUser.get(userId).remove(mToken);
- pushSession2TokensChangedLocked(userId);
- }
- }
+ abstract static class ServiceImpl {
+ public abstract void onStart();
+ public abstract void notifyRemoteVolumeChanged(int flags, MediaSessionRecord session);
+ public abstract void onSessionPlaystateChanged(
+ MediaSessionRecord record, int oldState, int newState);
+ public abstract void onSessionPlaybackTypeChanged(MediaSessionRecord record);
+ public abstract void onStartUser(int userId);
+ public abstract void onSwitchUser(int userId);
+ public abstract void monitor();
+ public abstract void onMediaButtonReceiverChanged(MediaSessionRecord record);
+ protected abstract void enforcePhoneStatePermission(int pid, int uid);
+ abstract void updateSession(MediaSessionRecord record);
+ abstract void setGlobalPrioritySession(MediaSessionRecord record);
+ abstract List<Session2Token> getSession2TokensLocked(int userId);
+ abstract void onStopUser(int userId);
+ abstract void sessionDied(MediaSessionRecord session);
+ abstract void destroySession(MediaSessionRecord session);
+ abstract void pushSession2TokensChangedLocked(int userId);
+ abstract Context getContext();
+ abstract IBinder getServiceBinder();
}
}
diff --git a/services/core/java/com/android/server/media/MediaSessionServiceImpl.java b/services/core/java/com/android/server/media/MediaSessionServiceImpl.java
new file mode 100644
index 0000000..f374c6d
--- /dev/null
+++ b/services/core/java/com/android/server/media/MediaSessionServiceImpl.java
@@ -0,0 +1,2142 @@
+/*
+ * Copyright 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.media;
+
+import static android.os.UserHandle.USER_ALL;
+
+import android.annotation.Nullable;
+import android.app.ActivityManager;
+import android.app.INotificationManager;
+import android.app.KeyguardManager;
+import android.app.PendingIntent;
+import android.app.PendingIntent.CanceledException;
+import android.content.ActivityNotFoundException;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ServiceInfo;
+import android.content.pm.UserInfo;
+import android.database.ContentObserver;
+import android.media.AudioManager;
+import android.media.AudioManagerInternal;
+import android.media.AudioPlaybackConfiguration;
+import android.media.AudioSystem;
+import android.media.IAudioService;
+import android.media.IRemoteVolumeController;
+import android.media.MediaController2;
+import android.media.Session2CommandGroup;
+import android.media.Session2Token;
+import android.media.session.IActiveSessionsListener;
+import android.media.session.ICallback;
+import android.media.session.IOnMediaKeyListener;
+import android.media.session.IOnVolumeKeyLongPressListener;
+import android.media.session.ISession;
+import android.media.session.ISession2TokensListener;
+import android.media.session.ISessionManager;
+import android.media.session.MediaSession;
+import android.media.session.MediaSessionManager;
+import android.media.session.SessionCallbackLink;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.HandlerExecutor;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.PowerManager;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.ResultReceiver;
+import android.os.ServiceManager;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.provider.Settings;
+import android.speech.RecognizerIntent;
+import android.text.TextUtils;
+import android.util.Log;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.util.SparseIntArray;
+import android.view.KeyEvent;
+import android.view.ViewConfiguration;
+
+import com.android.internal.annotations.GuardedBy;
+import com.android.internal.util.DumpUtils;
+import com.android.server.LocalServices;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * System implementation of MediaSessionManager
+ */
+public class MediaSessionServiceImpl extends MediaSessionService.ServiceImpl {
+ private static final String TAG = "MediaSessionService";
+ static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+ // Leave log for key event always.
+ private static final boolean DEBUG_KEY_EVENT = true;
+
+ private static final int WAKELOCK_TIMEOUT = 5000;
+ private static final int MEDIA_KEY_LISTENER_TIMEOUT = 1000;
+
+ private final Context mContext;
+ private final SessionManagerImpl mSessionManagerImpl;
+ private final MessageHandler mHandler = new MessageHandler();
+ private final PowerManager.WakeLock mMediaEventWakeLock;
+ private final int mLongPressTimeout;
+ private final INotificationManager mNotificationManager;
+ private final Object mLock = new Object();
+ // Keeps the full user id for each user.
+ @GuardedBy("mLock")
+ private final SparseIntArray mFullUserIds = new SparseIntArray();
+ @GuardedBy("mLock")
+ private final SparseArray<FullUserRecord> mUserRecords = new SparseArray<FullUserRecord>();
+ @GuardedBy("mLock")
+ private final ArrayList<SessionsListenerRecord> mSessionsListeners =
+ new ArrayList<SessionsListenerRecord>();
+ // Map user id as index to list of Session2Tokens
+ // TODO: Keep session2 info in MediaSessionStack for prioritizing both session1 and session2 in
+ // one place.
+ @GuardedBy("mLock")
+ private final SparseArray<List<Session2Token>> mSession2TokensPerUser = new SparseArray<>();
+ @GuardedBy("mLock")
+ private final List<Session2TokensListenerRecord> mSession2TokensListenerRecords =
+ new ArrayList<>();
+
+ private KeyguardManager mKeyguardManager;
+ private IAudioService mAudioService;
+ private AudioManagerInternal mAudioManagerInternal;
+ private ActivityManager mActivityManager;
+ private ContentResolver mContentResolver;
+ private SettingsObserver mSettingsObserver;
+ private boolean mHasFeatureLeanback;
+
+ // The FullUserRecord of the current users. (i.e. The foreground user that isn't a profile)
+ // It's always not null after the MediaSessionService is started.
+ private FullUserRecord mCurrentFullUserRecord;
+ private MediaSessionRecord mGlobalPrioritySession;
+ private AudioPlayerStateMonitor mAudioPlayerStateMonitor;
+
+ // Used to notify system UI when remote volume was changed. TODO find a
+ // better way to handle this.
+ private IRemoteVolumeController mRvc;
+
+ public MediaSessionServiceImpl(Context context) {
+ mContext = context;
+ mSessionManagerImpl = new SessionManagerImpl();
+ PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
+ mMediaEventWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "handleMediaEvent");
+ mLongPressTimeout = ViewConfiguration.getLongPressTimeout();
+ mNotificationManager = INotificationManager.Stub.asInterface(
+ ServiceManager.getService(Context.NOTIFICATION_SERVICE));
+ }
+
+ Context getContext() {
+ return mContext;
+ }
+
+ IBinder getServiceBinder() {
+ return mSessionManagerImpl;
+ }
+
+ @Override
+ public void onStart() {
+ mKeyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
+ mAudioService = getAudioService();
+ mAudioManagerInternal = LocalServices.getService(AudioManagerInternal.class);
+ mActivityManager =
+ (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
+ mAudioPlayerStateMonitor = AudioPlayerStateMonitor.getInstance();
+ mAudioPlayerStateMonitor.registerListener(
+ (config, isRemoved) -> {
+ if (isRemoved || !config.isActive() || config.getPlayerType()
+ == AudioPlaybackConfiguration.PLAYER_TYPE_JAM_SOUNDPOOL) {
+ return;
+ }
+ synchronized (mLock) {
+ FullUserRecord user = getFullUserRecordLocked(
+ UserHandle.getUserId(config.getClientUid()));
+ if (user != null) {
+ user.mPriorityStack.updateMediaButtonSessionIfNeeded();
+ }
+ }
+ }, null /* handler */);
+ mAudioPlayerStateMonitor.registerSelfIntoAudioServiceIfNeeded(mAudioService);
+ mContentResolver = mContext.getContentResolver();
+ mSettingsObserver = new SettingsObserver();
+ mSettingsObserver.observe();
+ mHasFeatureLeanback = mContext.getPackageManager().hasSystemFeature(
+ PackageManager.FEATURE_LEANBACK);
+
+ updateUser();
+ }
+
+ private IAudioService getAudioService() {
+ IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
+ return IAudioService.Stub.asInterface(b);
+ }
+
+ private boolean isGlobalPriorityActiveLocked() {
+ return mGlobalPrioritySession != null && mGlobalPrioritySession.isActive();
+ }
+
+ @Override
+ public void updateSession(MediaSessionRecord record) {
+ synchronized (mLock) {
+ FullUserRecord user = getFullUserRecordLocked(record.getUserId());
+ if (user == null) {
+ Log.w(TAG, "Unknown session updated. Ignoring.");
+ return;
+ }
+ if ((record.getFlags() & MediaSession.FLAG_EXCLUSIVE_GLOBAL_PRIORITY) != 0) {
+ if (DEBUG_KEY_EVENT) {
+ Log.d(TAG, "Global priority session is updated, active=" + record.isActive());
+ }
+ user.pushAddressedPlayerChangedLocked();
+ } else {
+ if (!user.mPriorityStack.contains(record)) {
+ Log.w(TAG, "Unknown session updated. Ignoring.");
+ return;
+ }
+ user.mPriorityStack.onSessionStateChange(record);
+ }
+ mHandler.postSessionsChanged(record.getUserId());
+ }
+ }
+
+ @Override
+ public void setGlobalPrioritySession(MediaSessionRecord record) {
+ synchronized (mLock) {
+ FullUserRecord user = getFullUserRecordLocked(record.getUserId());
+ if (mGlobalPrioritySession != record) {
+ Log.d(TAG, "Global priority session is changed from " + mGlobalPrioritySession
+ + " to " + record);
+ mGlobalPrioritySession = record;
+ if (user != null && user.mPriorityStack.contains(record)) {
+ // Handle the global priority session separately.
+ // Otherwise, it can be the media button session regardless of the active state
+ // because it or other system components might have been the lastly played media
+ // app.
+ user.mPriorityStack.removeSession(record);
+ }
+ }
+ }
+ }
+
+ private List<MediaSessionRecord> getActiveSessionsLocked(int userId) {
+ List<MediaSessionRecord> records = new ArrayList<>();
+ if (userId == USER_ALL) {
+ int size = mUserRecords.size();
+ for (int i = 0; i < size; i++) {
+ records.addAll(mUserRecords.valueAt(i).mPriorityStack.getActiveSessions(userId));
+ }
+ } else {
+ FullUserRecord user = getFullUserRecordLocked(userId);
+ if (user == null) {
+ Log.w(TAG, "getSessions failed. Unknown user " + userId);
+ return records;
+ }
+ records.addAll(user.mPriorityStack.getActiveSessions(userId));
+ }
+
+ // Return global priority session at the first whenever it's asked.
+ if (isGlobalPriorityActiveLocked()
+ && (userId == USER_ALL || userId == mGlobalPrioritySession.getUserId())) {
+ records.add(0, mGlobalPrioritySession);
+ }
+ return records;
+ }
+
+ List<Session2Token> getSession2TokensLocked(int userId) {
+ List<Session2Token> list = new ArrayList<>();
+ if (userId == USER_ALL) {
+ for (int i = 0; i < mSession2TokensPerUser.size(); i++) {
+ list.addAll(mSession2TokensPerUser.valueAt(i));
+ }
+ } else {
+ list.addAll(mSession2TokensPerUser.get(userId));
+ }
+ return list;
+ }
+
+ /**
+ * Tells the system UI that volume has changed on an active remote session.
+ */
+ public void notifyRemoteVolumeChanged(int flags, MediaSessionRecord session) {
+ if (mRvc == null || !session.isActive()) {
+ return;
+ }
+ try {
+ mRvc.remoteVolumeChanged(session.getControllerBinder(), flags);
+ } catch (Exception e) {
+ Log.wtf(TAG, "Error sending volume change to system UI.", e);
+ }
+ }
+
+ @Override
+ public void onSessionPlaystateChanged(MediaSessionRecord record, int oldState, int newState) {
+ synchronized (mLock) {
+ FullUserRecord user = getFullUserRecordLocked(record.getUserId());
+ if (user == null || !user.mPriorityStack.contains(record)) {
+ Log.d(TAG, "Unknown session changed playback state. Ignoring.");
+ return;
+ }
+ user.mPriorityStack.onPlaystateChanged(record, oldState, newState);
+ }
+ }
+
+ @Override
+ public void onSessionPlaybackTypeChanged(MediaSessionRecord record) {
+ synchronized (mLock) {
+ FullUserRecord user = getFullUserRecordLocked(record.getUserId());
+ if (user == null || !user.mPriorityStack.contains(record)) {
+ Log.d(TAG, "Unknown session changed playback type. Ignoring.");
+ return;
+ }
+ pushRemoteVolumeUpdateLocked(record.getUserId());
+ }
+ }
+
+ @Override
+ public void onStartUser(int userId) {
+ if (DEBUG) Log.d(TAG, "onStartUser: " + userId);
+ updateUser();
+ }
+
+ @Override
+ public void onSwitchUser(int userId) {
+ if (DEBUG) Log.d(TAG, "onSwitchUser: " + userId);
+ updateUser();
+ }
+
+ // Called when the user with the userId is removed.
+ @Override
+ public void onStopUser(int userId) {
+ if (DEBUG) Log.d(TAG, "onStopUser: " + userId);
+ synchronized (mLock) {
+ // TODO: Also handle removing user in updateUser() because adding/switching user is
+ // handled in updateUser().
+ FullUserRecord user = getFullUserRecordLocked(userId);
+ if (user != null) {
+ if (user.mFullUserId == userId) {
+ user.destroySessionsForUserLocked(USER_ALL);
+ mUserRecords.remove(userId);
+ } else {
+ user.destroySessionsForUserLocked(userId);
+ }
+ }
+ mSession2TokensPerUser.remove(userId);
+ updateUser();
+ }
+ }
+
+ @Override
+ public void monitor() {
+ synchronized (mLock) {
+ // Check for deadlock
+ }
+ }
+
+ protected void enforcePhoneStatePermission(int pid, int uid) {
+ if (mContext.checkPermission(android.Manifest.permission.MODIFY_PHONE_STATE, pid, uid)
+ != PackageManager.PERMISSION_GRANTED) {
+ throw new SecurityException("Must hold the MODIFY_PHONE_STATE permission.");
+ }
+ }
+
+ void sessionDied(MediaSessionRecord session) {
+ synchronized (mLock) {
+ destroySessionLocked(session);
+ }
+ }
+
+ void destroySession(MediaSessionRecord session) {
+ synchronized (mLock) {
+ destroySessionLocked(session);
+ }
+ }
+
+ private void updateUser() {
+ synchronized (mLock) {
+ UserManager manager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
+ mFullUserIds.clear();
+ List<UserInfo> allUsers = manager.getUsers();
+ if (allUsers != null) {
+ for (UserInfo userInfo : allUsers) {
+ if (userInfo.isManagedProfile()) {
+ mFullUserIds.put(userInfo.id, userInfo.profileGroupId);
+ } else {
+ mFullUserIds.put(userInfo.id, userInfo.id);
+ if (mUserRecords.get(userInfo.id) == null) {
+ mUserRecords.put(userInfo.id, new FullUserRecord(userInfo.id));
+ }
+ }
+ if (mSession2TokensPerUser.get(userInfo.id) == null) {
+ mSession2TokensPerUser.put(userInfo.id, new ArrayList<>());
+ }
+ }
+ }
+ // Ensure that the current full user exists.
+ int currentFullUserId = ActivityManager.getCurrentUser();
+ mCurrentFullUserRecord = mUserRecords.get(currentFullUserId);
+ if (mCurrentFullUserRecord == null) {
+ Log.w(TAG, "Cannot find FullUserInfo for the current user " + currentFullUserId);
+ mCurrentFullUserRecord = new FullUserRecord(currentFullUserId);
+ mUserRecords.put(currentFullUserId, mCurrentFullUserRecord);
+ if (mSession2TokensPerUser.get(currentFullUserId) == null) {
+ mSession2TokensPerUser.put(currentFullUserId, new ArrayList<>());
+ }
+ }
+ mFullUserIds.put(currentFullUserId, currentFullUserId);
+ }
+ }
+
+ private void updateActiveSessionListeners() {
+ synchronized (mLock) {
+ for (int i = mSessionsListeners.size() - 1; i >= 0; i--) {
+ SessionsListenerRecord listener = mSessionsListeners.get(i);
+ try {
+ enforceMediaPermissions(listener.componentName, listener.pid, listener.uid,
+ listener.userId);
+ } catch (SecurityException e) {
+ Log.i(TAG, "ActiveSessionsListener " + listener.componentName
+ + " is no longer authorized. Disconnecting.");
+ mSessionsListeners.remove(i);
+ try {
+ listener.listener
+ .onActiveSessionsChanged(new ArrayList<MediaSession.Token>());
+ } catch (Exception e1) {
+ // ignore
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ * When a session is removed several things need to happen.
+ * 1. We need to remove it from the relevant user.
+ * 2. We need to remove it from the priority stack.
+ * 3. We need to remove it from all sessions.
+ * 4. If this is the system priority session we need to clear it.
+ * 5. We need to unlink to death from the cb binder
+ * 6. We need to tell the session to do any final cleanup (onDestroy)
+ */
+ private void destroySessionLocked(MediaSessionRecord session) {
+ if (DEBUG) {
+ Log.d(TAG, "Destroying " + session);
+ }
+ FullUserRecord user = getFullUserRecordLocked(session.getUserId());
+ if (mGlobalPrioritySession == session) {
+ mGlobalPrioritySession = null;
+ if (session.isActive() && user != null) {
+ user.pushAddressedPlayerChangedLocked();
+ }
+ } else {
+ if (user != null) {
+ user.mPriorityStack.removeSession(session);
+ }
+ }
+
+ try {
+ session.getCallback().getBinder().unlinkToDeath(session, 0);
+ } catch (Exception e) {
+ // ignore exceptions while destroying a session.
+ }
+ session.onDestroy();
+ mHandler.postSessionsChanged(session.getUserId());
+ }
+
+ private void enforcePackageName(String packageName, int uid) {
+ if (TextUtils.isEmpty(packageName)) {
+ throw new IllegalArgumentException("packageName may not be empty");
+ }
+ String[] packages = mContext.getPackageManager().getPackagesForUid(uid);
+ final int packageCount = packages.length;
+ for (int i = 0; i < packageCount; i++) {
+ if (packageName.equals(packages[i])) {
+ return;
+ }
+ }
+ throw new IllegalArgumentException("packageName is not owned by the calling process");
+ }
+
+ /**
+ * Checks a caller's authorization to register an IRemoteControlDisplay.
+ * Authorization is granted if one of the following is true:
+ * <ul>
+ * <li>the caller has android.Manifest.permission.MEDIA_CONTENT_CONTROL
+ * permission</li>
+ * <li>the caller's listener is one of the enabled notification listeners
+ * for the caller's user</li>
+ * </ul>
+ */
+ private void enforceMediaPermissions(ComponentName compName, int pid, int uid,
+ int resolvedUserId) {
+ if (isCurrentVolumeController(pid, uid)) return;
+ if (mContext
+ .checkPermission(android.Manifest.permission.MEDIA_CONTENT_CONTROL, pid, uid)
+ != PackageManager.PERMISSION_GRANTED
+ && !isEnabledNotificationListener(compName, UserHandle.getUserId(uid),
+ resolvedUserId)) {
+ throw new SecurityException("Missing permission to control media.");
+ }
+ }
+
+ private boolean isCurrentVolumeController(int pid, int uid) {
+ return mContext.checkPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
+ pid, uid) == PackageManager.PERMISSION_GRANTED;
+ }
+
+ private void enforceSystemUiPermission(String action, int pid, int uid) {
+ if (!isCurrentVolumeController(pid, uid)) {
+ throw new SecurityException("Only system ui may " + action);
+ }
+ }
+
+ /**
+ * This checks if the component is an enabled notification listener for the
+ * specified user. Enabled components may only operate on behalf of the user
+ * they're running as.
+ *
+ * @param compName The component that is enabled.
+ * @param userId The user id of the caller.
+ * @param forUserId The user id they're making the request on behalf of.
+ * @return True if the component is enabled, false otherwise
+ */
+ private boolean isEnabledNotificationListener(ComponentName compName, int userId,
+ int forUserId) {
+ if (userId != forUserId) {
+ // You may not access another user's content as an enabled listener.
+ return false;
+ }
+ if (DEBUG) {
+ Log.d(TAG, "Checking if enabled notification listener " + compName);
+ }
+ if (compName != null) {
+ try {
+ return mNotificationManager.isNotificationListenerAccessGrantedForUser(
+ compName, userId);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Dead NotificationManager in isEnabledNotificationListener", e);
+ }
+ }
+ return false;
+ }
+
+ private MediaSessionRecord createSessionInternal(int callerPid, int callerUid, int userId,
+ String callerPackageName, SessionCallbackLink cb, String tag) throws RemoteException {
+ synchronized (mLock) {
+ return createSessionLocked(callerPid, callerUid, userId, callerPackageName, cb, tag);
+ }
+ }
+
+ /*
+ * When a session is created the following things need to happen.
+ * 1. Its callback binder needs a link to death
+ * 2. It needs to be added to all sessions.
+ * 3. It needs to be added to the priority stack.
+ * 4. It needs to be added to the relevant user record.
+ */
+ private MediaSessionRecord createSessionLocked(int callerPid, int callerUid, int userId,
+ String callerPackageName, SessionCallbackLink cb, String tag) {
+ FullUserRecord user = getFullUserRecordLocked(userId);
+ if (user == null) {
+ Log.wtf(TAG, "Request from invalid user: " + userId);
+ throw new RuntimeException("Session request from invalid user.");
+ }
+
+ final MediaSessionRecord session = new MediaSessionRecord(callerPid, callerUid, userId,
+ callerPackageName, cb, tag, this, mHandler.getLooper());
+ try {
+ cb.getBinder().linkToDeath(session, 0);
+ } catch (RemoteException e) {
+ throw new RuntimeException("Media Session owner died prematurely.", e);
+ }
+
+ user.mPriorityStack.addSession(session);
+ mHandler.postSessionsChanged(userId);
+
+ if (DEBUG) {
+ Log.d(TAG, "Created session for " + callerPackageName + " with tag " + tag);
+ }
+ return session;
+ }
+
+ private int findIndexOfSessionsListenerLocked(IActiveSessionsListener listener) {
+ for (int i = mSessionsListeners.size() - 1; i >= 0; i--) {
+ if (mSessionsListeners.get(i).listener.asBinder() == listener.asBinder()) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ private int findIndexOfSession2TokensListenerLocked(ISession2TokensListener listener) {
+ for (int i = mSession2TokensListenerRecords.size() - 1; i >= 0; i--) {
+ if (mSession2TokensListenerRecords.get(i).listener.asBinder() == listener.asBinder()) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+
+ private void pushSessionsChanged(int userId) {
+ synchronized (mLock) {
+ FullUserRecord user = getFullUserRecordLocked(userId);
+ if (user == null) {
+ Log.w(TAG, "pushSessionsChanged failed. No user with id=" + userId);
+ return;
+ }
+ List<MediaSessionRecord> records = getActiveSessionsLocked(userId);
+ int size = records.size();
+ ArrayList<MediaSession.Token> tokens = new ArrayList<MediaSession.Token>();
+ for (int i = 0; i < size; i++) {
+ tokens.add(new MediaSession.Token(records.get(i).getControllerBinder()));
+ }
+ pushRemoteVolumeUpdateLocked(userId);
+ for (int i = mSessionsListeners.size() - 1; i >= 0; i--) {
+ SessionsListenerRecord record = mSessionsListeners.get(i);
+ if (record.userId == USER_ALL || record.userId == userId) {
+ try {
+ record.listener.onActiveSessionsChanged(tokens);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Dead ActiveSessionsListener in pushSessionsChanged, removing",
+ e);
+ mSessionsListeners.remove(i);
+ }
+ }
+ }
+ }
+ }
+
+ private void pushRemoteVolumeUpdateLocked(int userId) {
+ if (mRvc != null) {
+ try {
+ FullUserRecord user = getFullUserRecordLocked(userId);
+ if (user == null) {
+ Log.w(TAG, "pushRemoteVolumeUpdateLocked failed. No user with id=" + userId);
+ return;
+ }
+ MediaSessionRecord record = user.mPriorityStack.getDefaultRemoteSession(userId);
+ mRvc.updateRemoteController(record == null ? null : record.getControllerBinder());
+ } catch (RemoteException e) {
+ Log.wtf(TAG, "Error sending default remote volume to sys ui.", e);
+ }
+ }
+ }
+
+ void pushSession2TokensChangedLocked(int userId) {
+ List<Session2Token> allSession2Tokens = getSession2TokensLocked(USER_ALL);
+ List<Session2Token> session2Tokens = getSession2TokensLocked(userId);
+
+ for (int i = mSession2TokensListenerRecords.size() - 1; i >= 0; i--) {
+ Session2TokensListenerRecord listenerRecord = mSession2TokensListenerRecords.get(i);
+ try {
+ if (listenerRecord.userId == USER_ALL) {
+ listenerRecord.listener.onSession2TokensChanged(allSession2Tokens);
+ } else if (listenerRecord.userId == userId) {
+ listenerRecord.listener.onSession2TokensChanged(session2Tokens);
+ }
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed to notify Session2Token change. Removing listener.", e);
+ mSession2TokensListenerRecords.remove(i);
+ }
+ }
+ }
+
+ /**
+ * Called when the media button receiver for the {@code record} is changed.
+ *
+ * @param record the media session whose media button receiver is updated.
+ */
+ public void onMediaButtonReceiverChanged(MediaSessionRecord record) {
+ synchronized (mLock) {
+ FullUserRecord user = getFullUserRecordLocked(record.getUserId());
+ MediaSessionRecord mediaButtonSession =
+ user.mPriorityStack.getMediaButtonSession();
+ if (record == mediaButtonSession) {
+ user.rememberMediaButtonReceiverLocked(mediaButtonSession);
+ }
+ }
+ }
+
+ private String getCallingPackageName(int uid) {
+ String[] packages = mContext.getPackageManager().getPackagesForUid(uid);
+ if (packages != null && packages.length > 0) {
+ return packages[0];
+ }
+ return "";
+ }
+
+ private void dispatchVolumeKeyLongPressLocked(KeyEvent keyEvent) {
+ if (mCurrentFullUserRecord.mOnVolumeKeyLongPressListener == null) {
+ return;
+ }
+ try {
+ mCurrentFullUserRecord.mOnVolumeKeyLongPressListener.onVolumeKeyLongPress(keyEvent);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed to send " + keyEvent + " to volume key long-press listener");
+ }
+ }
+
+ private FullUserRecord getFullUserRecordLocked(int userId) {
+ int fullUserId = mFullUserIds.get(userId, -1);
+ if (fullUserId < 0) {
+ return null;
+ }
+ return mUserRecords.get(fullUserId);
+ }
+
+ /**
+ * Information about a full user and its corresponding managed profiles.
+ *
+ * <p>Since the full user runs together with its managed profiles, a user wouldn't differentiate
+ * them when he/she presses a media/volume button. So keeping media sessions for them in one
+ * place makes more sense and increases the readability.</p>
+ * <p>The contents of this object is guarded by {@link #mLock}.
+ */
+ final class FullUserRecord implements MediaSessionStack.OnMediaButtonSessionChangedListener {
+ public static final int COMPONENT_TYPE_INVALID = 0;
+ public static final int COMPONENT_TYPE_BROADCAST = 1;
+ public static final int COMPONENT_TYPE_ACTIVITY = 2;
+ public static final int COMPONENT_TYPE_SERVICE = 3;
+ private static final String COMPONENT_NAME_USER_ID_DELIM = ",";
+
+ private final int mFullUserId;
+ private final MediaSessionStack mPriorityStack;
+ private PendingIntent mLastMediaButtonReceiver;
+ private ComponentName mRestoredMediaButtonReceiver;
+ private int mRestoredMediaButtonReceiverComponentType;
+ private int mRestoredMediaButtonReceiverUserId;
+
+ private IOnVolumeKeyLongPressListener mOnVolumeKeyLongPressListener;
+ private int mOnVolumeKeyLongPressListenerUid;
+ private KeyEvent mInitialDownVolumeKeyEvent;
+ private int mInitialDownVolumeStream;
+ private boolean mInitialDownMusicOnly;
+
+ private IOnMediaKeyListener mOnMediaKeyListener;
+ private int mOnMediaKeyListenerUid;
+ private ICallback mCallback;
+
+ FullUserRecord(int fullUserId) {
+ mFullUserId = fullUserId;
+ mPriorityStack = new MediaSessionStack(mAudioPlayerStateMonitor, this);
+ // Restore the remembered media button receiver before the boot.
+ String mediaButtonReceiverInfo = Settings.Secure.getStringForUser(mContentResolver,
+ Settings.System.MEDIA_BUTTON_RECEIVER, mFullUserId);
+ if (mediaButtonReceiverInfo == null) {
+ return;
+ }
+ String[] tokens = mediaButtonReceiverInfo.split(COMPONENT_NAME_USER_ID_DELIM);
+ if (tokens == null || (tokens.length != 2 && tokens.length != 3)) {
+ return;
+ }
+ mRestoredMediaButtonReceiver = ComponentName.unflattenFromString(tokens[0]);
+ mRestoredMediaButtonReceiverUserId = Integer.parseInt(tokens[1]);
+ if (tokens.length == 3) {
+ mRestoredMediaButtonReceiverComponentType = Integer.parseInt(tokens[2]);
+ } else {
+ mRestoredMediaButtonReceiverComponentType =
+ getComponentType(mRestoredMediaButtonReceiver);
+ }
+ }
+
+ public void destroySessionsForUserLocked(int userId) {
+ List<MediaSessionRecord> sessions = mPriorityStack.getPriorityList(false, userId);
+ for (MediaSessionRecord session : sessions) {
+ MediaSessionServiceImpl.this.destroySessionLocked(session);
+ }
+ }
+
+ public void dumpLocked(PrintWriter pw, String prefix) {
+ pw.print(prefix + "Record for full_user=" + mFullUserId);
+ // Dump managed profile user ids associated with this user.
+ int size = mFullUserIds.size();
+ for (int i = 0; i < size; i++) {
+ if (mFullUserIds.keyAt(i) != mFullUserIds.valueAt(i)
+ && mFullUserIds.valueAt(i) == mFullUserId) {
+ pw.print(", profile_user=" + mFullUserIds.keyAt(i));
+ }
+ }
+ pw.println();
+ String indent = prefix + " ";
+ pw.println(indent + "Volume key long-press listener: " + mOnVolumeKeyLongPressListener);
+ pw.println(indent + "Volume key long-press listener package: "
+ + getCallingPackageName(mOnVolumeKeyLongPressListenerUid));
+ pw.println(indent + "Media key listener: " + mOnMediaKeyListener);
+ pw.println(indent + "Media key listener package: "
+ + getCallingPackageName(mOnMediaKeyListenerUid));
+ pw.println(indent + "Callback: " + mCallback);
+ pw.println(indent + "Last MediaButtonReceiver: " + mLastMediaButtonReceiver);
+ pw.println(indent + "Restored MediaButtonReceiver: " + mRestoredMediaButtonReceiver);
+ pw.println(indent + "Restored MediaButtonReceiverComponentType: "
+ + mRestoredMediaButtonReceiverComponentType);
+ mPriorityStack.dump(pw, indent);
+ pw.println(indent + "Session2Tokens:");
+ for (int i = 0; i < mSession2TokensPerUser.size(); i++) {
+ List<Session2Token> list = mSession2TokensPerUser.valueAt(i);
+ if (list == null || list.size() == 0) {
+ continue;
+ }
+ for (Session2Token token : list) {
+ pw.println(indent + " " + token);
+ }
+ }
+ }
+
+ @Override
+ public void onMediaButtonSessionChanged(MediaSessionRecord oldMediaButtonSession,
+ MediaSessionRecord newMediaButtonSession) {
+ if (DEBUG_KEY_EVENT) {
+ Log.d(TAG, "Media button session is changed to " + newMediaButtonSession);
+ }
+ synchronized (mLock) {
+ if (oldMediaButtonSession != null) {
+ mHandler.postSessionsChanged(oldMediaButtonSession.getUserId());
+ }
+ if (newMediaButtonSession != null) {
+ rememberMediaButtonReceiverLocked(newMediaButtonSession);
+ mHandler.postSessionsChanged(newMediaButtonSession.getUserId());
+ }
+ pushAddressedPlayerChangedLocked();
+ }
+ }
+
+ // Remember media button receiver and keep it in the persistent storage.
+ public void rememberMediaButtonReceiverLocked(MediaSessionRecord record) {
+ PendingIntent receiver = record.getMediaButtonReceiver();
+ mLastMediaButtonReceiver = receiver;
+ mRestoredMediaButtonReceiver = null;
+ mRestoredMediaButtonReceiverComponentType = COMPONENT_TYPE_INVALID;
+
+ String mediaButtonReceiverInfo = "";
+ if (receiver != null) {
+ ComponentName component = receiver.getIntent().getComponent();
+ if (component != null
+ && record.getPackageName().equals(component.getPackageName())) {
+ String componentName = component.flattenToString();
+ int componentType = getComponentType(component);
+ mediaButtonReceiverInfo = String.join(COMPONENT_NAME_USER_ID_DELIM,
+ componentName, String.valueOf(record.getUserId()),
+ String.valueOf(componentType));
+ }
+ }
+ Settings.Secure.putStringForUser(mContentResolver,
+ Settings.System.MEDIA_BUTTON_RECEIVER, mediaButtonReceiverInfo,
+ mFullUserId);
+ }
+
+ private void pushAddressedPlayerChangedLocked() {
+ if (mCallback == null) {
+ return;
+ }
+ try {
+ MediaSessionRecord mediaButtonSession = getMediaButtonSessionLocked();
+ if (mediaButtonSession != null) {
+ mCallback.onAddressedPlayerChangedToMediaSession(
+ new MediaSession.Token(mediaButtonSession.getControllerBinder()));
+ } else if (mCurrentFullUserRecord.mLastMediaButtonReceiver != null) {
+ mCallback.onAddressedPlayerChangedToMediaButtonReceiver(
+ mCurrentFullUserRecord.mLastMediaButtonReceiver
+ .getIntent().getComponent());
+ } else if (mCurrentFullUserRecord.mRestoredMediaButtonReceiver != null) {
+ mCallback.onAddressedPlayerChangedToMediaButtonReceiver(
+ mCurrentFullUserRecord.mRestoredMediaButtonReceiver);
+ }
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed to pushAddressedPlayerChangedLocked", e);
+ }
+ }
+
+ private MediaSessionRecord getMediaButtonSessionLocked() {
+ return isGlobalPriorityActiveLocked()
+ ? mGlobalPrioritySession : mPriorityStack.getMediaButtonSession();
+ }
+
+ private int getComponentType(@Nullable ComponentName componentName) {
+ if (componentName == null) {
+ return COMPONENT_TYPE_INVALID;
+ }
+ PackageManager pm = mContext.getPackageManager();
+ try {
+ ActivityInfo activityInfo = pm.getActivityInfo(componentName,
+ PackageManager.MATCH_DIRECT_BOOT_AWARE
+ | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
+ | PackageManager.GET_ACTIVITIES);
+ if (activityInfo != null) {
+ return COMPONENT_TYPE_ACTIVITY;
+ }
+ } catch (NameNotFoundException e) {
+ }
+ try {
+ ServiceInfo serviceInfo = pm.getServiceInfo(componentName,
+ PackageManager.MATCH_DIRECT_BOOT_AWARE
+ | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
+ | PackageManager.GET_SERVICES);
+ if (serviceInfo != null) {
+ return COMPONENT_TYPE_SERVICE;
+ }
+ } catch (NameNotFoundException e) {
+ }
+ // Pick legacy behavior for BroadcastReceiver or unknown.
+ return COMPONENT_TYPE_BROADCAST;
+ }
+ }
+
+ final class SessionsListenerRecord implements IBinder.DeathRecipient {
+ public final IActiveSessionsListener listener;
+ public final ComponentName componentName;
+ public final int userId;
+ public final int pid;
+ public final int uid;
+
+ SessionsListenerRecord(IActiveSessionsListener listener,
+ ComponentName componentName,
+ int userId, int pid, int uid) {
+ this.listener = listener;
+ this.componentName = componentName;
+ this.userId = userId;
+ this.pid = pid;
+ this.uid = uid;
+ }
+
+ @Override
+ public void binderDied() {
+ synchronized (mLock) {
+ mSessionsListeners.remove(this);
+ }
+ }
+ }
+
+ final class Session2TokensListenerRecord implements IBinder.DeathRecipient {
+ public final ISession2TokensListener listener;
+ public final int userId;
+
+ Session2TokensListenerRecord(ISession2TokensListener listener,
+ int userId) {
+ this.listener = listener;
+ this.userId = userId;
+ }
+
+ @Override
+ public void binderDied() {
+ synchronized (mLock) {
+ mSession2TokensListenerRecords.remove(this);
+ }
+ }
+ }
+
+ final class SettingsObserver extends ContentObserver {
+ private final Uri mSecureSettingsUri = Settings.Secure.getUriFor(
+ Settings.Secure.ENABLED_NOTIFICATION_LISTENERS);
+
+ private SettingsObserver() {
+ super(null);
+ }
+
+ private void observe() {
+ mContentResolver.registerContentObserver(mSecureSettingsUri,
+ false, this, USER_ALL);
+ }
+
+ @Override
+ public void onChange(boolean selfChange, Uri uri) {
+ updateActiveSessionListeners();
+ }
+ }
+
+ class SessionManagerImpl extends ISessionManager.Stub {
+ private static final String EXTRA_WAKELOCK_ACQUIRED =
+ "android.media.AudioService.WAKELOCK_ACQUIRED";
+ private static final int WAKELOCK_RELEASE_ON_FINISHED = 1980; // magic number
+
+ private boolean mVoiceButtonDown = false;
+ private boolean mVoiceButtonHandled = false;
+
+ @Override
+ public ISession createSession(String packageName, SessionCallbackLink cb, String tag,
+ int userId) throws RemoteException {
+ final int pid = Binder.getCallingPid();
+ final int uid = Binder.getCallingUid();
+ final long token = Binder.clearCallingIdentity();
+ try {
+ enforcePackageName(packageName, uid);
+ int resolvedUserId = ActivityManager.handleIncomingUser(pid, uid, userId,
+ false /* allowAll */, true /* requireFull */, "createSession", packageName);
+ if (cb == null) {
+ throw new IllegalArgumentException("Controller callback cannot be null");
+ }
+ return createSessionInternal(pid, uid, resolvedUserId, packageName, cb, tag)
+ .getSessionBinder();
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ @Override
+ public void notifySession2Created(Session2Token sessionToken) throws RemoteException {
+ final int pid = Binder.getCallingPid();
+ final int uid = Binder.getCallingUid();
+ final long token = Binder.clearCallingIdentity();
+ try {
+ if (DEBUG) {
+ Log.d(TAG, "Session2 is created " + sessionToken);
+ }
+ if (uid != sessionToken.getUid()) {
+ throw new SecurityException("Unexpected Session2Token's UID, expected=" + uid
+ + " but actually=" + sessionToken.getUid());
+ }
+ Controller2Callback callback = new Controller2Callback(sessionToken);
+ // Note: It's safe not to keep controller here because it wouldn't be GC'ed until
+ // it's closed.
+ // TODO: Keep controller as well for better readability
+ // because the GC behavior isn't straightforward.
+ MediaController2 controller = new MediaController2(mContext, sessionToken,
+ new HandlerExecutor(mHandler), callback);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ @Override
+ public List<IBinder> getSessions(ComponentName componentName, int userId) {
+ final int pid = Binder.getCallingPid();
+ final int uid = Binder.getCallingUid();
+ final long token = Binder.clearCallingIdentity();
+
+ try {
+ int resolvedUserId = verifySessionsRequest(componentName, userId, pid, uid);
+ ArrayList<IBinder> binders = new ArrayList<IBinder>();
+ synchronized (mLock) {
+ List<MediaSessionRecord> records = getActiveSessionsLocked(resolvedUserId);
+ for (MediaSessionRecord record : records) {
+ binders.add(record.getControllerBinder().asBinder());
+ }
+ }
+ return binders;
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ @Override
+ public List<Session2Token> getSession2Tokens(int userId) {
+ final int pid = Binder.getCallingPid();
+ final int uid = Binder.getCallingUid();
+ final long token = Binder.clearCallingIdentity();
+
+ try {
+ // Check that they can make calls on behalf of the user and
+ // get the final user id
+ int resolvedUserId = ActivityManager.handleIncomingUser(pid, uid, userId,
+ true /* allowAll */, true /* requireFull */, "getSession2Tokens",
+ null /* optional packageName */);
+ List<Session2Token> result;
+ synchronized (mLock) {
+ result = getSession2TokensLocked(resolvedUserId);
+ }
+ return result;
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ @Override
+ public void addSessionsListener(IActiveSessionsListener listener,
+ ComponentName componentName, int userId) throws RemoteException {
+ final int pid = Binder.getCallingPid();
+ final int uid = Binder.getCallingUid();
+ final long token = Binder.clearCallingIdentity();
+
+ try {
+ int resolvedUserId = verifySessionsRequest(componentName, userId, pid, uid);
+ synchronized (mLock) {
+ int index = findIndexOfSessionsListenerLocked(listener);
+ if (index != -1) {
+ Log.w(TAG, "ActiveSessionsListener is already added, ignoring");
+ return;
+ }
+ SessionsListenerRecord record = new SessionsListenerRecord(listener,
+ componentName, resolvedUserId, pid, uid);
+ try {
+ listener.asBinder().linkToDeath(record, 0);
+ } catch (RemoteException e) {
+ Log.e(TAG, "ActiveSessionsListener is dead, ignoring it", e);
+ return;
+ }
+ mSessionsListeners.add(record);
+ }
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ @Override
+ public void removeSessionsListener(IActiveSessionsListener listener)
+ throws RemoteException {
+ synchronized (mLock) {
+ int index = findIndexOfSessionsListenerLocked(listener);
+ if (index != -1) {
+ SessionsListenerRecord record = mSessionsListeners.remove(index);
+ try {
+ record.listener.asBinder().unlinkToDeath(record, 0);
+ } catch (Exception e) {
+ // ignore exceptions, the record is being removed
+ }
+ }
+ }
+ }
+
+ @Override
+ public void addSession2TokensListener(ISession2TokensListener listener,
+ int userId) {
+ final int pid = Binder.getCallingPid();
+ final int uid = Binder.getCallingUid();
+ final long token = Binder.clearCallingIdentity();
+
+ try {
+ // Check that they can make calls on behalf of the user and get the final user id.
+ int resolvedUserId = ActivityManager.handleIncomingUser(pid, uid, userId,
+ true /* allowAll */, true /* requireFull */, "addSession2TokensListener",
+ null /* optional packageName */);
+ synchronized (mLock) {
+ int index = findIndexOfSession2TokensListenerLocked(listener);
+ if (index >= 0) {
+ Log.w(TAG, "addSession2TokensListener is already added, ignoring");
+ return;
+ }
+ mSession2TokensListenerRecords.add(
+ new Session2TokensListenerRecord(listener, resolvedUserId));
+ }
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ @Override
+ public void removeSession2TokensListener(ISession2TokensListener listener) {
+ final int pid = Binder.getCallingPid();
+ final int uid = Binder.getCallingUid();
+ final long token = Binder.clearCallingIdentity();
+
+ try {
+ synchronized (mLock) {
+ int index = findIndexOfSession2TokensListenerLocked(listener);
+ if (index >= 0) {
+ Session2TokensListenerRecord listenerRecord =
+ mSession2TokensListenerRecords.remove(index);
+ try {
+ listenerRecord.listener.asBinder().unlinkToDeath(listenerRecord, 0);
+ } catch (Exception e) {
+ // Ignore exception.
+ }
+ }
+ }
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ /**
+ * Handles the dispatching of the media button events to one of the
+ * registered listeners, or if there was none, broadcast an
+ * ACTION_MEDIA_BUTTON intent to the rest of the system.
+ *
+ * @param packageName The caller package
+ * @param asSystemService {@code true} if the event sent to the session as if it was come
+ * from the system service instead of the app process. This helps sessions to
+ * distinguish between the key injection by the app and key events from the
+ * hardware devices. Should be used only when the volume key events aren't handled
+ * by foreground activity. {@code false} otherwise to tell session about the real
+ * caller.
+ * @param keyEvent a non-null KeyEvent whose key code is one of the
+ * supported media buttons
+ * @param needWakeLock true if a PARTIAL_WAKE_LOCK needs to be held
+ * while this key event is dispatched.
+ */
+ @Override
+ public void dispatchMediaKeyEvent(String packageName, boolean asSystemService,
+ KeyEvent keyEvent, boolean needWakeLock) {
+ if (keyEvent == null || !KeyEvent.isMediaSessionKey(keyEvent.getKeyCode())) {
+ Log.w(TAG, "Attempted to dispatch null or non-media key event.");
+ return;
+ }
+
+ final int pid = Binder.getCallingPid();
+ final int uid = Binder.getCallingUid();
+ final long token = Binder.clearCallingIdentity();
+ try {
+ if (DEBUG) {
+ Log.d(TAG, "dispatchMediaKeyEvent, pkg=" + packageName + " pid=" + pid
+ + ", uid=" + uid + ", asSystem=" + asSystemService + ", event="
+ + keyEvent);
+ }
+ if (!isUserSetupComplete()) {
+ // Global media key handling can have the side-effect of starting new
+ // activities which is undesirable while setup is in progress.
+ Slog.i(TAG, "Not dispatching media key event because user "
+ + "setup is in progress.");
+ return;
+ }
+
+ synchronized (mLock) {
+ boolean isGlobalPriorityActive = isGlobalPriorityActiveLocked();
+ if (isGlobalPriorityActive && uid != Process.SYSTEM_UID) {
+ // Prevent dispatching key event through reflection while the global
+ // priority session is active.
+ Slog.i(TAG, "Only the system can dispatch media key event "
+ + "to the global priority session.");
+ return;
+ }
+ if (!isGlobalPriorityActive) {
+ if (mCurrentFullUserRecord.mOnMediaKeyListener != null) {
+ if (DEBUG_KEY_EVENT) {
+ Log.d(TAG, "Send " + keyEvent + " to the media key listener");
+ }
+ try {
+ mCurrentFullUserRecord.mOnMediaKeyListener.onMediaKey(keyEvent,
+ new MediaKeyListenerResultReceiver(packageName, pid, uid,
+ asSystemService, keyEvent, needWakeLock));
+ return;
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed to send " + keyEvent
+ + " to the media key listener");
+ }
+ }
+ }
+ if (!isGlobalPriorityActive && isVoiceKey(keyEvent.getKeyCode())) {
+ handleVoiceKeyEventLocked(packageName, pid, uid, asSystemService, keyEvent,
+ needWakeLock);
+ } else {
+ dispatchMediaKeyEventLocked(packageName, pid, uid, asSystemService,
+ keyEvent, needWakeLock);
+ }
+ }
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ @Override
+ public void setCallback(ICallback callback) {
+ final int pid = Binder.getCallingPid();
+ final int uid = Binder.getCallingUid();
+ final long token = Binder.clearCallingIdentity();
+ try {
+ if (!UserHandle.isSameApp(uid, Process.BLUETOOTH_UID)) {
+ throw new SecurityException("Only Bluetooth service processes can set"
+ + " Callback");
+ }
+ synchronized (mLock) {
+ int userId = UserHandle.getUserId(uid);
+ FullUserRecord user = getFullUserRecordLocked(userId);
+ if (user == null || user.mFullUserId != userId) {
+ Log.w(TAG, "Only the full user can set the callback"
+ + ", userId=" + userId);
+ return;
+ }
+ user.mCallback = callback;
+ Log.d(TAG, "The callback " + user.mCallback
+ + " is set by " + getCallingPackageName(uid));
+ if (user.mCallback == null) {
+ return;
+ }
+ try {
+ user.mCallback.asBinder().linkToDeath(
+ new IBinder.DeathRecipient() {
+ @Override
+ public void binderDied() {
+ synchronized (mLock) {
+ user.mCallback = null;
+ }
+ }
+ }, 0);
+ user.pushAddressedPlayerChangedLocked();
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed to set callback", e);
+ user.mCallback = null;
+ }
+ }
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ @Override
+ public void setOnVolumeKeyLongPressListener(IOnVolumeKeyLongPressListener listener) {
+ final int pid = Binder.getCallingPid();
+ final int uid = Binder.getCallingUid();
+ final long token = Binder.clearCallingIdentity();
+ try {
+ // Enforce SET_VOLUME_KEY_LONG_PRESS_LISTENER permission.
+ if (mContext.checkPermission(
+ android.Manifest.permission.SET_VOLUME_KEY_LONG_PRESS_LISTENER, pid, uid)
+ != PackageManager.PERMISSION_GRANTED) {
+ throw new SecurityException("Must hold the SET_VOLUME_KEY_LONG_PRESS_LISTENER"
+ + " permission.");
+ }
+
+ synchronized (mLock) {
+ int userId = UserHandle.getUserId(uid);
+ FullUserRecord user = getFullUserRecordLocked(userId);
+ if (user == null || user.mFullUserId != userId) {
+ Log.w(TAG, "Only the full user can set the volume key long-press listener"
+ + ", userId=" + userId);
+ return;
+ }
+ if (user.mOnVolumeKeyLongPressListener != null
+ && user.mOnVolumeKeyLongPressListenerUid != uid) {
+ Log.w(TAG, "The volume key long-press listener cannot be reset"
+ + " by another app , mOnVolumeKeyLongPressListener="
+ + user.mOnVolumeKeyLongPressListenerUid
+ + ", uid=" + uid);
+ return;
+ }
+
+ user.mOnVolumeKeyLongPressListener = listener;
+ user.mOnVolumeKeyLongPressListenerUid = uid;
+
+ Log.d(TAG, "The volume key long-press listener "
+ + listener + " is set by " + getCallingPackageName(uid));
+
+ if (user.mOnVolumeKeyLongPressListener != null) {
+ try {
+ user.mOnVolumeKeyLongPressListener.asBinder().linkToDeath(
+ new IBinder.DeathRecipient() {
+ @Override
+ public void binderDied() {
+ synchronized (mLock) {
+ user.mOnVolumeKeyLongPressListener = null;
+ }
+ }
+ }, 0);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed to set death recipient "
+ + user.mOnVolumeKeyLongPressListener);
+ user.mOnVolumeKeyLongPressListener = null;
+ }
+ }
+ }
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ @Override
+ public void setOnMediaKeyListener(IOnMediaKeyListener listener) {
+ final int pid = Binder.getCallingPid();
+ final int uid = Binder.getCallingUid();
+ final long token = Binder.clearCallingIdentity();
+ try {
+ // Enforce SET_MEDIA_KEY_LISTENER permission.
+ if (mContext.checkPermission(
+ android.Manifest.permission.SET_MEDIA_KEY_LISTENER, pid, uid)
+ != PackageManager.PERMISSION_GRANTED) {
+ throw new SecurityException("Must hold the SET_MEDIA_KEY_LISTENER permission.");
+ }
+
+ synchronized (mLock) {
+ int userId = UserHandle.getUserId(uid);
+ FullUserRecord user = getFullUserRecordLocked(userId);
+ if (user == null || user.mFullUserId != userId) {
+ Log.w(TAG, "Only the full user can set the media key listener"
+ + ", userId=" + userId);
+ return;
+ }
+ if (user.mOnMediaKeyListener != null && user.mOnMediaKeyListenerUid != uid) {
+ Log.w(TAG, "The media key listener cannot be reset by another app. "
+ + ", mOnMediaKeyListenerUid=" + user.mOnMediaKeyListenerUid
+ + ", uid=" + uid);
+ return;
+ }
+
+ user.mOnMediaKeyListener = listener;
+ user.mOnMediaKeyListenerUid = uid;
+
+ Log.d(TAG, "The media key listener " + user.mOnMediaKeyListener
+ + " is set by " + getCallingPackageName(uid));
+
+ if (user.mOnMediaKeyListener != null) {
+ try {
+ user.mOnMediaKeyListener.asBinder().linkToDeath(
+ new IBinder.DeathRecipient() {
+ @Override
+ public void binderDied() {
+ synchronized (mLock) {
+ user.mOnMediaKeyListener = null;
+ }
+ }
+ }, 0);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed to set death recipient " + user.mOnMediaKeyListener);
+ user.mOnMediaKeyListener = null;
+ }
+ }
+ }
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ /**
+ * Handles the dispatching of the volume button events to one of the
+ * registered listeners. If there's a volume key long-press listener and
+ * there's no active global priority session, long-pressess will be sent to the
+ * long-press listener instead of adjusting volume.
+ *
+ * @param packageName The caller's package name, obtained by Context#getPackageName()
+ * @param opPackageName The caller's op package name, obtained by Context#getOpPackageName()
+ * @param asSystemService {@code true} if the event sent to the session as if it was come
+ * from the system service instead of the app process. This helps sessions to
+ * distinguish between the key injection by the app and key events from the
+ * hardware devices. Should be used only when the volume key events aren't handled
+ * by foreground activity. {@code false} otherwise to tell session about the real
+ * caller.
+ * @param keyEvent a non-null KeyEvent whose key code is one of the
+ * {@link KeyEvent#KEYCODE_VOLUME_UP},
+ * {@link KeyEvent#KEYCODE_VOLUME_DOWN},
+ * or {@link KeyEvent#KEYCODE_VOLUME_MUTE}.
+ * @param stream stream type to adjust volume.
+ * @param musicOnly true if both UI nor haptic feedback aren't needed when adjust volume.
+ */
+ @Override
+ public void dispatchVolumeKeyEvent(String packageName, String opPackageName,
+ boolean asSystemService, KeyEvent keyEvent, int stream, boolean musicOnly) {
+ if (keyEvent == null
+ || (keyEvent.getKeyCode() != KeyEvent.KEYCODE_VOLUME_UP
+ && keyEvent.getKeyCode() != KeyEvent.KEYCODE_VOLUME_DOWN
+ && keyEvent.getKeyCode() != KeyEvent.KEYCODE_VOLUME_MUTE)) {
+ Log.w(TAG, "Attempted to dispatch null or non-volume key event.");
+ return;
+ }
+
+ final int pid = Binder.getCallingPid();
+ final int uid = Binder.getCallingUid();
+ final long token = Binder.clearCallingIdentity();
+
+ if (DEBUG_KEY_EVENT) {
+ Log.d(TAG, "dispatchVolumeKeyEvent, pkg=" + packageName + ", pid=" + pid + ", uid="
+ + uid + ", asSystem=" + asSystemService + ", event=" + keyEvent);
+ }
+
+ try {
+ synchronized (mLock) {
+ if (isGlobalPriorityActiveLocked()
+ || mCurrentFullUserRecord.mOnVolumeKeyLongPressListener == null) {
+ dispatchVolumeKeyEventLocked(packageName, opPackageName, pid, uid,
+ asSystemService, keyEvent, stream, musicOnly);
+ } else {
+ // TODO: Consider the case when both volume up and down keys are pressed
+ // at the same time.
+ if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
+ if (keyEvent.getRepeatCount() == 0) {
+ // Keeps the copy of the KeyEvent because it can be reused.
+ mCurrentFullUserRecord.mInitialDownVolumeKeyEvent =
+ KeyEvent.obtain(keyEvent);
+ mCurrentFullUserRecord.mInitialDownVolumeStream = stream;
+ mCurrentFullUserRecord.mInitialDownMusicOnly = musicOnly;
+ mHandler.sendMessageDelayed(
+ mHandler.obtainMessage(
+ MessageHandler.MSG_VOLUME_INITIAL_DOWN,
+ mCurrentFullUserRecord.mFullUserId, 0),
+ mLongPressTimeout);
+ }
+ if (keyEvent.getRepeatCount() > 0 || keyEvent.isLongPress()) {
+ mHandler.removeMessages(MessageHandler.MSG_VOLUME_INITIAL_DOWN);
+ if (mCurrentFullUserRecord.mInitialDownVolumeKeyEvent != null) {
+ dispatchVolumeKeyLongPressLocked(
+ mCurrentFullUserRecord.mInitialDownVolumeKeyEvent);
+ // Mark that the key is already handled.
+ mCurrentFullUserRecord.mInitialDownVolumeKeyEvent = null;
+ }
+ dispatchVolumeKeyLongPressLocked(keyEvent);
+ }
+ } else { // if up
+ mHandler.removeMessages(MessageHandler.MSG_VOLUME_INITIAL_DOWN);
+ if (mCurrentFullUserRecord.mInitialDownVolumeKeyEvent != null
+ && mCurrentFullUserRecord.mInitialDownVolumeKeyEvent
+ .getDownTime() == keyEvent.getDownTime()) {
+ // Short-press. Should change volume.
+ dispatchVolumeKeyEventLocked(packageName, opPackageName, pid, uid,
+ asSystemService,
+ mCurrentFullUserRecord.mInitialDownVolumeKeyEvent,
+ mCurrentFullUserRecord.mInitialDownVolumeStream,
+ mCurrentFullUserRecord.mInitialDownMusicOnly);
+ dispatchVolumeKeyEventLocked(packageName, opPackageName, pid, uid,
+ asSystemService, keyEvent, stream, musicOnly);
+ } else {
+ dispatchVolumeKeyLongPressLocked(keyEvent);
+ }
+ }
+ }
+ }
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ private void dispatchVolumeKeyEventLocked(String packageName, String opPackageName, int pid,
+ int uid, boolean asSystemService, KeyEvent keyEvent, int stream,
+ boolean musicOnly) {
+ boolean down = keyEvent.getAction() == KeyEvent.ACTION_DOWN;
+ boolean up = keyEvent.getAction() == KeyEvent.ACTION_UP;
+ int direction = 0;
+ boolean isMute = false;
+ switch (keyEvent.getKeyCode()) {
+ case KeyEvent.KEYCODE_VOLUME_UP:
+ direction = AudioManager.ADJUST_RAISE;
+ break;
+ case KeyEvent.KEYCODE_VOLUME_DOWN:
+ direction = AudioManager.ADJUST_LOWER;
+ break;
+ case KeyEvent.KEYCODE_VOLUME_MUTE:
+ isMute = true;
+ break;
+ }
+ if (down || up) {
+ int flags = AudioManager.FLAG_FROM_KEY;
+ if (musicOnly) {
+ // This flag is used when the screen is off to only affect active media.
+ flags |= AudioManager.FLAG_ACTIVE_MEDIA_ONLY;
+ } else {
+ // These flags are consistent with the home screen
+ if (up) {
+ flags |= AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_VIBRATE;
+ } else {
+ flags |= AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_VIBRATE;
+ }
+ }
+ if (direction != 0) {
+ // If this is action up we want to send a beep for non-music events
+ if (up) {
+ direction = 0;
+ }
+ dispatchAdjustVolumeLocked(packageName, opPackageName, pid, uid,
+ asSystemService, stream, direction, flags);
+ } else if (isMute) {
+ if (down && keyEvent.getRepeatCount() == 0) {
+ dispatchAdjustVolumeLocked(packageName, opPackageName, pid, uid,
+ asSystemService, stream, AudioManager.ADJUST_TOGGLE_MUTE, flags);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void dispatchAdjustVolume(String packageName, String opPackageName,
+ int suggestedStream, int delta, int flags) {
+ final int pid = Binder.getCallingPid();
+ final int uid = Binder.getCallingUid();
+ final long token = Binder.clearCallingIdentity();
+ try {
+ synchronized (mLock) {
+ dispatchAdjustVolumeLocked(packageName, opPackageName, pid, uid, false,
+ suggestedStream, delta, flags);
+ }
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ @Override
+ public void setRemoteVolumeController(IRemoteVolumeController rvc) {
+ final int pid = Binder.getCallingPid();
+ final int uid = Binder.getCallingUid();
+ final long token = Binder.clearCallingIdentity();
+ try {
+ enforceSystemUiPermission("listen for volume changes", pid, uid);
+ mRvc = rvc;
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ @Override
+ public boolean isGlobalPriorityActive() {
+ synchronized (mLock) {
+ return isGlobalPriorityActiveLocked();
+ }
+ }
+
+ @Override
+ public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
+ if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
+
+ pw.println("MEDIA SESSION SERVICE (dumpsys media_session)");
+ pw.println();
+
+ synchronized (mLock) {
+ pw.println(mSessionsListeners.size() + " sessions listeners.");
+ pw.println("Global priority session is " + mGlobalPrioritySession);
+ if (mGlobalPrioritySession != null) {
+ mGlobalPrioritySession.dump(pw, " ");
+ }
+ pw.println("User Records:");
+ int count = mUserRecords.size();
+ for (int i = 0; i < count; i++) {
+ mUserRecords.valueAt(i).dumpLocked(pw, "");
+ }
+ mAudioPlayerStateMonitor.dump(mContext, pw, "");
+ }
+ }
+
+ /**
+ * Returns if the controller's package is trusted (i.e. has either MEDIA_CONTENT_CONTROL
+ * permission or an enabled notification listener)
+ *
+ * @param controllerPackageName package name of the controller app
+ * @param controllerPid pid of the controller app
+ * @param controllerUid uid of the controller app
+ */
+ @Override
+ public boolean isTrusted(String controllerPackageName, int controllerPid, int controllerUid)
+ throws RemoteException {
+ final int uid = Binder.getCallingUid();
+ final long token = Binder.clearCallingIdentity();
+ try {
+ // Don't perform sanity check between controllerPackageName and controllerUid.
+ // When an (activity|service) runs on the another apps process by specifying
+ // android:process in the AndroidManifest.xml, then PID and UID would have the
+ // running process' information instead of the (activity|service) that has created
+ // MediaController.
+ // Note that we can use Context#getOpPackageName() instead of
+ // Context#getPackageName() for getting package name that matches with the PID/UID,
+ // but it doesn't tell which package has created the MediaController, so useless.
+ return hasMediaControlPermission(UserHandle.getUserId(uid), controllerPackageName,
+ controllerPid, controllerUid);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ // For MediaSession
+ private int verifySessionsRequest(ComponentName componentName, int userId, final int pid,
+ final int uid) {
+ String packageName = null;
+ if (componentName != null) {
+ // If they gave us a component name verify they own the
+ // package
+ packageName = componentName.getPackageName();
+ enforcePackageName(packageName, uid);
+ }
+ // Check that they can make calls on behalf of the user and
+ // get the final user id
+ int resolvedUserId = ActivityManager.handleIncomingUser(pid, uid, userId,
+ true /* allowAll */, true /* requireFull */, "getSessions", packageName);
+ // Check if they have the permissions or their component is
+ // enabled for the user they're calling from.
+ enforceMediaPermissions(componentName, pid, uid, resolvedUserId);
+ return resolvedUserId;
+ }
+
+ private boolean hasMediaControlPermission(int resolvedUserId, String packageName,
+ int pid, int uid) throws RemoteException {
+ // Allow API calls from the System UI
+ if (isCurrentVolumeController(pid, uid)) {
+ return true;
+ }
+
+ // Check if it's system server or has MEDIA_CONTENT_CONTROL.
+ // Note that system server doesn't have MEDIA_CONTENT_CONTROL, so we need extra
+ // check here.
+ if (uid == Process.SYSTEM_UID || mContext.checkPermission(
+ android.Manifest.permission.MEDIA_CONTENT_CONTROL, pid, uid)
+ == PackageManager.PERMISSION_GRANTED) {
+ return true;
+ } else if (DEBUG) {
+ Log.d(TAG, packageName + " (uid=" + uid + ") hasn't granted MEDIA_CONTENT_CONTROL");
+ }
+
+ // You may not access another user's content as an enabled listener.
+ final int userId = UserHandle.getUserId(uid);
+ if (resolvedUserId != userId) {
+ return false;
+ }
+
+ // TODO(jaewan): (Post-P) Propose NotificationManager#hasEnabledNotificationListener(
+ // String pkgName) to notification team for optimization
+ final List<ComponentName> enabledNotificationListeners =
+ mNotificationManager.getEnabledNotificationListeners(userId);
+ if (enabledNotificationListeners != null) {
+ for (int i = 0; i < enabledNotificationListeners.size(); i++) {
+ if (TextUtils.equals(packageName,
+ enabledNotificationListeners.get(i).getPackageName())) {
+ return true;
+ }
+ }
+ }
+ if (DEBUG) {
+ Log.d(TAG, packageName + " (uid=" + uid + ") doesn't have an enabled "
+ + "notification listener");
+ }
+ return false;
+ }
+
+ private void dispatchAdjustVolumeLocked(String packageName, String opPackageName, int pid,
+ int uid, boolean asSystemService, int suggestedStream, int direction, int flags) {
+ MediaSessionRecord session = isGlobalPriorityActiveLocked() ? mGlobalPrioritySession
+ : mCurrentFullUserRecord.mPriorityStack.getDefaultVolumeSession();
+
+ boolean preferSuggestedStream = false;
+ if (isValidLocalStreamType(suggestedStream)
+ && AudioSystem.isStreamActive(suggestedStream, 0)) {
+ preferSuggestedStream = true;
+ }
+ if (DEBUG_KEY_EVENT) {
+ Log.d(TAG, "Adjusting " + session + " by " + direction + ". flags="
+ + flags + ", suggestedStream=" + suggestedStream
+ + ", preferSuggestedStream=" + preferSuggestedStream);
+ }
+ if (session == null || preferSuggestedStream) {
+ if ((flags & AudioManager.FLAG_ACTIVE_MEDIA_ONLY) != 0
+ && !AudioSystem.isStreamActive(AudioManager.STREAM_MUSIC, 0)) {
+ if (DEBUG) {
+ Log.d(TAG, "No active session to adjust, skipping media only volume event");
+ }
+ return;
+ }
+
+ // Execute mAudioService.adjustSuggestedStreamVolume() on
+ // handler thread of MediaSessionService.
+ // This will release the MediaSessionService.mLock sooner and avoid
+ // a potential deadlock between MediaSessionService.mLock and
+ // ActivityManagerService lock.
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ final String callingOpPackageName;
+ final int callingUid;
+ if (asSystemService) {
+ callingOpPackageName = mContext.getOpPackageName();
+ callingUid = Process.myUid();
+ } else {
+ callingOpPackageName = opPackageName;
+ callingUid = uid;
+ }
+ try {
+ mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(suggestedStream,
+ direction, flags, callingOpPackageName, callingUid);
+ } catch (SecurityException | IllegalArgumentException e) {
+ Log.e(TAG, "Cannot adjust volume: direction=" + direction
+ + ", suggestedStream=" + suggestedStream + ", flags=" + flags
+ + ", packageName=" + packageName + ", uid=" + uid
+ + ", asSystemService=" + asSystemService, e);
+ }
+ }
+ });
+ } else {
+ session.adjustVolume(packageName, opPackageName, pid, uid, null, asSystemService,
+ direction, flags, true);
+ }
+ }
+
+ private void handleVoiceKeyEventLocked(String packageName, int pid, int uid,
+ boolean asSystemService, KeyEvent keyEvent, boolean needWakeLock) {
+ int action = keyEvent.getAction();
+ boolean isLongPress = (keyEvent.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0;
+ if (action == KeyEvent.ACTION_DOWN) {
+ if (keyEvent.getRepeatCount() == 0) {
+ mVoiceButtonDown = true;
+ mVoiceButtonHandled = false;
+ } else if (mVoiceButtonDown && !mVoiceButtonHandled && isLongPress) {
+ mVoiceButtonHandled = true;
+ startVoiceInput(needWakeLock);
+ }
+ } else if (action == KeyEvent.ACTION_UP) {
+ if (mVoiceButtonDown) {
+ mVoiceButtonDown = false;
+ if (!mVoiceButtonHandled && !keyEvent.isCanceled()) {
+ // Resend the down then send this event through
+ KeyEvent downEvent = KeyEvent.changeAction(keyEvent, KeyEvent.ACTION_DOWN);
+ dispatchMediaKeyEventLocked(packageName, pid, uid, asSystemService,
+ downEvent, needWakeLock);
+ dispatchMediaKeyEventLocked(packageName, pid, uid, asSystemService,
+ keyEvent, needWakeLock);
+ }
+ }
+ }
+ }
+
+ private void dispatchMediaKeyEventLocked(String packageName, int pid, int uid,
+ boolean asSystemService, KeyEvent keyEvent, boolean needWakeLock) {
+ MediaSessionRecord session = mCurrentFullUserRecord.getMediaButtonSessionLocked();
+ if (session != null) {
+ if (DEBUG_KEY_EVENT) {
+ Log.d(TAG, "Sending " + keyEvent + " to " + session);
+ }
+ if (needWakeLock) {
+ mKeyEventReceiver.aquireWakeLockLocked();
+ }
+ // If we don't need a wakelock use -1 as the id so we won't release it later.
+ session.sendMediaButton(packageName, pid, uid, asSystemService, keyEvent,
+ needWakeLock ? mKeyEventReceiver.mLastTimeoutId : -1,
+ mKeyEventReceiver);
+ if (mCurrentFullUserRecord.mCallback != null) {
+ try {
+ mCurrentFullUserRecord.mCallback.onMediaKeyEventDispatchedToMediaSession(
+ keyEvent, new MediaSession.Token(session.getControllerBinder()));
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed to send callback", e);
+ }
+ }
+ } else if (mCurrentFullUserRecord.mLastMediaButtonReceiver != null
+ || mCurrentFullUserRecord.mRestoredMediaButtonReceiver != null) {
+ if (needWakeLock) {
+ mKeyEventReceiver.aquireWakeLockLocked();
+ }
+ Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
+ mediaButtonIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
+ mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
+ // TODO: Find a way to also send PID/UID in secure way.
+ String callerPackageName =
+ (asSystemService) ? mContext.getPackageName() : packageName;
+ mediaButtonIntent.putExtra(Intent.EXTRA_PACKAGE_NAME, callerPackageName);
+ try {
+ if (mCurrentFullUserRecord.mLastMediaButtonReceiver != null) {
+ PendingIntent receiver = mCurrentFullUserRecord.mLastMediaButtonReceiver;
+ if (DEBUG_KEY_EVENT) {
+ Log.d(TAG, "Sending " + keyEvent
+ + " to the last known PendingIntent " + receiver);
+ }
+ receiver.send(mContext,
+ needWakeLock ? mKeyEventReceiver.mLastTimeoutId : -1,
+ mediaButtonIntent, mKeyEventReceiver, mHandler);
+ if (mCurrentFullUserRecord.mCallback != null) {
+ ComponentName componentName = mCurrentFullUserRecord
+ .mLastMediaButtonReceiver.getIntent().getComponent();
+ if (componentName != null) {
+ mCurrentFullUserRecord.mCallback
+ .onMediaKeyEventDispatchedToMediaButtonReceiver(
+ keyEvent, componentName);
+ }
+ }
+ } else {
+ ComponentName receiver =
+ mCurrentFullUserRecord.mRestoredMediaButtonReceiver;
+ int componentType = mCurrentFullUserRecord
+ .mRestoredMediaButtonReceiverComponentType;
+ UserHandle userHandle = UserHandle.of(mCurrentFullUserRecord
+ .mRestoredMediaButtonReceiverUserId);
+ if (DEBUG_KEY_EVENT) {
+ Log.d(TAG, "Sending " + keyEvent + " to the restored intent "
+ + receiver + ", type=" + componentType);
+ }
+ mediaButtonIntent.setComponent(receiver);
+ try {
+ switch (componentType) {
+ case FullUserRecord.COMPONENT_TYPE_ACTIVITY:
+ mContext.startActivityAsUser(mediaButtonIntent, userHandle);
+ break;
+ case FullUserRecord.COMPONENT_TYPE_SERVICE:
+ mContext.startForegroundServiceAsUser(mediaButtonIntent,
+ userHandle);
+ break;
+ default:
+ // Legacy behavior for other cases.
+ mContext.sendBroadcastAsUser(mediaButtonIntent, userHandle);
+ }
+ } catch (Exception e) {
+ Log.w(TAG, "Error sending media button to the restored intent "
+ + receiver + ", type=" + componentType, e);
+ }
+ if (mCurrentFullUserRecord.mCallback != null) {
+ mCurrentFullUserRecord.mCallback
+ .onMediaKeyEventDispatchedToMediaButtonReceiver(
+ keyEvent, receiver);
+ }
+ }
+ } catch (CanceledException e) {
+ Log.i(TAG, "Error sending key event to media button receiver "
+ + mCurrentFullUserRecord.mLastMediaButtonReceiver, e);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed to send callback", e);
+ }
+ }
+ }
+
+ private void startVoiceInput(boolean needWakeLock) {
+ Intent voiceIntent = null;
+ // select which type of search to launch:
+ // - screen on and device unlocked: action is ACTION_WEB_SEARCH
+ // - device locked or screen off: action is
+ // ACTION_VOICE_SEARCH_HANDS_FREE
+ // with EXTRA_SECURE set to true if the device is securely locked
+ PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
+ boolean isLocked = mKeyguardManager != null && mKeyguardManager.isKeyguardLocked();
+ if (!isLocked && pm.isScreenOn()) {
+ voiceIntent = new Intent(android.speech.RecognizerIntent.ACTION_WEB_SEARCH);
+ Log.i(TAG, "voice-based interactions: about to use ACTION_WEB_SEARCH");
+ } else {
+ voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
+ voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE,
+ isLocked && mKeyguardManager.isKeyguardSecure());
+ Log.i(TAG, "voice-based interactions: about to use ACTION_VOICE_SEARCH_HANDS_FREE");
+ }
+ // start the search activity
+ if (needWakeLock) {
+ mMediaEventWakeLock.acquire();
+ }
+ try {
+ if (voiceIntent != null) {
+ voiceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+ | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
+ if (DEBUG) Log.d(TAG, "voiceIntent: " + voiceIntent);
+ mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT);
+ }
+ } catch (ActivityNotFoundException e) {
+ Log.w(TAG, "No activity for search: " + e);
+ } finally {
+ if (needWakeLock) {
+ mMediaEventWakeLock.release();
+ }
+ }
+ }
+
+ private boolean isVoiceKey(int keyCode) {
+ return keyCode == KeyEvent.KEYCODE_HEADSETHOOK
+ || (!mHasFeatureLeanback && keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
+ }
+
+ private boolean isUserSetupComplete() {
+ return Settings.Secure.getIntForUser(mContext.getContentResolver(),
+ Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
+ }
+
+ // we only handle public stream types, which are 0-5
+ private boolean isValidLocalStreamType(int streamType) {
+ return streamType >= AudioManager.STREAM_VOICE_CALL
+ && streamType <= AudioManager.STREAM_NOTIFICATION;
+ }
+
+ private class MediaKeyListenerResultReceiver extends ResultReceiver implements Runnable {
+ private final String mPackageName;
+ private final int mPid;
+ private final int mUid;
+ private final boolean mAsSystemService;
+ private final KeyEvent mKeyEvent;
+ private final boolean mNeedWakeLock;
+ private boolean mHandled;
+
+ private MediaKeyListenerResultReceiver(String packageName, int pid, int uid,
+ boolean asSystemService, KeyEvent keyEvent, boolean needWakeLock) {
+ super(mHandler);
+ mHandler.postDelayed(this, MEDIA_KEY_LISTENER_TIMEOUT);
+ mPackageName = packageName;
+ mPid = pid;
+ mUid = uid;
+ mAsSystemService = asSystemService;
+ mKeyEvent = keyEvent;
+ mNeedWakeLock = needWakeLock;
+ }
+
+ @Override
+ public void run() {
+ Log.d(TAG, "The media key listener is timed-out for " + mKeyEvent);
+ dispatchMediaKeyEvent();
+ }
+
+ @Override
+ protected void onReceiveResult(int resultCode, Bundle resultData) {
+ if (resultCode == MediaSessionManager.RESULT_MEDIA_KEY_HANDLED) {
+ mHandled = true;
+ mHandler.removeCallbacks(this);
+ return;
+ }
+ dispatchMediaKeyEvent();
+ }
+
+ private void dispatchMediaKeyEvent() {
+ if (mHandled) {
+ return;
+ }
+ mHandled = true;
+ mHandler.removeCallbacks(this);
+ synchronized (mLock) {
+ if (!isGlobalPriorityActiveLocked()
+ && isVoiceKey(mKeyEvent.getKeyCode())) {
+ handleVoiceKeyEventLocked(mPackageName, mPid, mUid, mAsSystemService,
+ mKeyEvent, mNeedWakeLock);
+ } else {
+ dispatchMediaKeyEventLocked(mPackageName, mPid, mUid, mAsSystemService,
+ mKeyEvent, mNeedWakeLock);
+ }
+ }
+ }
+ }
+
+ private KeyEventWakeLockReceiver mKeyEventReceiver = new KeyEventWakeLockReceiver(mHandler);
+
+ class KeyEventWakeLockReceiver extends ResultReceiver implements Runnable,
+ PendingIntent.OnFinished {
+ private final Handler mHandler;
+ private int mRefCount = 0;
+ private int mLastTimeoutId = 0;
+
+ KeyEventWakeLockReceiver(Handler handler) {
+ super(handler);
+ mHandler = handler;
+ }
+
+ public void onTimeout() {
+ synchronized (mLock) {
+ if (mRefCount == 0) {
+ // We've already released it, so just return
+ return;
+ }
+ mLastTimeoutId++;
+ mRefCount = 0;
+ releaseWakeLockLocked();
+ }
+ }
+
+ public void aquireWakeLockLocked() {
+ if (mRefCount == 0) {
+ mMediaEventWakeLock.acquire();
+ }
+ mRefCount++;
+ mHandler.removeCallbacks(this);
+ mHandler.postDelayed(this, WAKELOCK_TIMEOUT);
+
+ }
+
+ @Override
+ public void run() {
+ onTimeout();
+ }
+
+ @Override
+ protected void onReceiveResult(int resultCode, Bundle resultData) {
+ if (resultCode < mLastTimeoutId) {
+ // Ignore results from calls that were before the last
+ // timeout, just in case.
+ return;
+ } else {
+ synchronized (mLock) {
+ if (mRefCount > 0) {
+ mRefCount--;
+ if (mRefCount == 0) {
+ releaseWakeLockLocked();
+ }
+ }
+ }
+ }
+ }
+
+ private void releaseWakeLockLocked() {
+ mMediaEventWakeLock.release();
+ mHandler.removeCallbacks(this);
+ }
+
+ @Override
+ public void onSendFinished(PendingIntent pendingIntent, Intent intent, int resultCode,
+ String resultData, Bundle resultExtras) {
+ onReceiveResult(resultCode, null);
+ }
+ };
+
+ BroadcastReceiver mKeyEventDone = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent == null) {
+ return;
+ }
+ Bundle extras = intent.getExtras();
+ if (extras == null) {
+ return;
+ }
+ synchronized (mLock) {
+ if (extras.containsKey(EXTRA_WAKELOCK_ACQUIRED)
+ && mMediaEventWakeLock.isHeld()) {
+ mMediaEventWakeLock.release();
+ }
+ }
+ }
+ };
+ }
+
+ final class MessageHandler extends Handler {
+ private static final int MSG_SESSIONS_CHANGED = 1;
+ private static final int MSG_VOLUME_INITIAL_DOWN = 2;
+ private final SparseArray<Integer> mIntegerCache = new SparseArray<>();
+
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case MSG_SESSIONS_CHANGED:
+ pushSessionsChanged((int) msg.obj);
+ break;
+ case MSG_VOLUME_INITIAL_DOWN:
+ synchronized (mLock) {
+ FullUserRecord user = mUserRecords.get((int) msg.arg1);
+ if (user != null && user.mInitialDownVolumeKeyEvent != null) {
+ dispatchVolumeKeyLongPressLocked(user.mInitialDownVolumeKeyEvent);
+ // Mark that the key is already handled.
+ user.mInitialDownVolumeKeyEvent = null;
+ }
+ }
+ break;
+ }
+ }
+
+ public void postSessionsChanged(int userId) {
+ // Use object instead of the arguments when posting message to remove pending requests.
+ Integer userIdInteger = mIntegerCache.get(userId);
+ if (userIdInteger == null) {
+ userIdInteger = Integer.valueOf(userId);
+ mIntegerCache.put(userId, userIdInteger);
+ }
+ removeMessages(MSG_SESSIONS_CHANGED, userIdInteger);
+ obtainMessage(MSG_SESSIONS_CHANGED, userIdInteger).sendToTarget();
+ }
+ }
+
+ private class Controller2Callback extends MediaController2.ControllerCallback {
+ private final Session2Token mToken;
+
+ Controller2Callback(Session2Token token) {
+ mToken = token;
+ }
+
+ @Override
+ public void onConnected(MediaController2 controller, Session2CommandGroup allowedCommands) {
+ synchronized (mLock) {
+ int userId = UserHandle.getUserId(mToken.getUid());
+ mSession2TokensPerUser.get(userId).add(mToken);
+ pushSession2TokensChangedLocked(userId);
+ }
+ }
+
+ @Override
+ public void onDisconnected(MediaController2 controller) {
+ synchronized (mLock) {
+ int userId = UserHandle.getUserId(mToken.getUid());
+ mSession2TokensPerUser.get(userId).remove(mToken);
+ pushSession2TokensChangedLocked(userId);
+ }
+ }
+ }
+}
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 20eebe7..7323e93 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -2311,22 +2311,22 @@
}
@Override
- public boolean areAppOverlaysAllowed(String pkg) {
- return areAppOverlaysAllowedForPackage(pkg, Binder.getCallingUid());
+ public boolean areBubblesAllowed(String pkg) {
+ return areBubblesAllowedForPackage(pkg, Binder.getCallingUid());
}
@Override
- public boolean areAppOverlaysAllowedForPackage(String pkg, int uid) {
- enforceSystemOrSystemUIOrSamePackage("Caller not system or systemui or same package",
- pkg);
- return mPreferencesHelper.areAppOverlaysAllowed(pkg, uid);
+ public boolean areBubblesAllowedForPackage(String pkg, int uid) {
+ enforceSystemOrSystemUIOrSamePackage(pkg,
+ "Caller not system or systemui or same package");
+ return mPreferencesHelper.areBubblessAllowed(pkg, uid);
}
@Override
- public void setAppOverlaysAllowed(String pkg, int uid, boolean allowed) {
+ public void setBubblesAllowed(String pkg, int uid, boolean allowed) {
checkCallerIsSystem();
- mPreferencesHelper.setAppOverlaysAllowed(pkg, uid, allowed);
+ mPreferencesHelper.setBubblesAllowed(pkg, uid, allowed);
handleSavePolicyFile();
}
diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java
index 28f6972..7a21aa2 100644
--- a/services/core/java/com/android/server/notification/PreferencesHelper.java
+++ b/services/core/java/com/android/server/notification/PreferencesHelper.java
@@ -81,7 +81,7 @@
private static final String ATT_NAME = "name";
private static final String ATT_UID = "uid";
private static final String ATT_ID = "id";
- private static final String ATT_APP_OVERLAY = "overlay";
+ private static final String ATT_ALLOW_BUBBLE = "allow_bubble";
private static final String ATT_PRIORITY = "priority";
private static final String ATT_VISIBILITY = "visibility";
private static final String ATT_IMPORTANCE = "importance";
@@ -94,8 +94,9 @@
private static final int DEFAULT_VISIBILITY = NotificationManager.VISIBILITY_NO_OVERRIDE;
private static final int DEFAULT_IMPORTANCE = NotificationManager.IMPORTANCE_UNSPECIFIED;
private static final boolean DEFAULT_SHOW_BADGE = true;
- private static final boolean DEFAULT_ALLOW_APP_OVERLAY = true;
+ private static final boolean DEFAULT_ALLOW_BUBBLE = true;
private static final boolean DEFAULT_OEM_LOCKED_IMPORTANCE = false;
+
/**
* Default value for what fields are user locked. See {@link LockableAppFields} for all lockable
* fields.
@@ -108,7 +109,7 @@
@IntDef({LockableAppFields.USER_LOCKED_IMPORTANCE})
public @interface LockableAppFields {
int USER_LOCKED_IMPORTANCE = 0x00000001;
- int USER_LOCKED_APP_OVERLAY = 0x00000002;
+ int USER_LOCKED_BUBBLE = 0x00000002;
}
// pkg|uid => PackagePreferences
@@ -176,7 +177,7 @@
XmlUtils.readBooleanAttribute(
parser, ATT_SHOW_BADGE, DEFAULT_SHOW_BADGE),
XmlUtils.readBooleanAttribute(
- parser, ATT_APP_OVERLAY, DEFAULT_ALLOW_APP_OVERLAY));
+ parser, ATT_ALLOW_BUBBLE, DEFAULT_ALLOW_BUBBLE));
r.importance = XmlUtils.readIntAttribute(
parser, ATT_IMPORTANCE, DEFAULT_IMPORTANCE);
r.priority = XmlUtils.readIntAttribute(
@@ -272,11 +273,11 @@
private PackagePreferences getOrCreatePackagePreferences(String pkg, int uid) {
return getOrCreatePackagePreferences(pkg, uid,
DEFAULT_IMPORTANCE, DEFAULT_PRIORITY, DEFAULT_VISIBILITY, DEFAULT_SHOW_BADGE,
- DEFAULT_ALLOW_APP_OVERLAY);
+ DEFAULT_ALLOW_BUBBLE);
}
private PackagePreferences getOrCreatePackagePreferences(String pkg, int uid, int importance,
- int priority, int visibility, boolean showBadge, boolean allowAppOverlay) {
+ int priority, int visibility, boolean showBadge, boolean allowBubble) {
final String key = packagePreferencesKey(pkg, uid);
synchronized (mPackagePreferences) {
PackagePreferences
@@ -290,7 +291,7 @@
r.priority = priority;
r.visibility = visibility;
r.showBadge = showBadge;
- r.appOverlay = allowAppOverlay;
+ r.allowBubble = allowBubble;
try {
createDefaultChannelIfNeeded(r);
@@ -392,7 +393,7 @@
|| r.channels.size() > 0
|| r.groups.size() > 0
|| r.delegate != null
- || r.appOverlay != DEFAULT_ALLOW_APP_OVERLAY;
+ || r.allowBubble != DEFAULT_ALLOW_BUBBLE;
if (hasNonDefaultSettings) {
out.startTag(null, TAG_PACKAGE);
out.attribute(null, ATT_NAME, r.pkg);
@@ -405,8 +406,8 @@
if (r.visibility != DEFAULT_VISIBILITY) {
out.attribute(null, ATT_VISIBILITY, Integer.toString(r.visibility));
}
- if (r.appOverlay != DEFAULT_ALLOW_APP_OVERLAY) {
- out.attribute(null, ATT_APP_OVERLAY, Boolean.toString(r.appOverlay));
+ if (r.allowBubble != DEFAULT_ALLOW_BUBBLE) {
+ out.attribute(null, ATT_ALLOW_BUBBLE, Boolean.toString(r.allowBubble));
}
out.attribute(null, ATT_SHOW_BADGE, Boolean.toString(r.showBadge));
out.attribute(null, ATT_APP_USER_LOCKED_FIELDS,
@@ -452,14 +453,28 @@
out.endTag(null, TAG_RANKING);
}
- public void setAppOverlaysAllowed(String pkg, int uid, boolean allowed) {
+ /**
+ * Sets whether bubbles are allowed.
+ *
+ * @param pkg the package to allow or not allow bubbles for.
+ * @param uid the uid to allow or not allow bubbles for.
+ * @param allowed whether bubbles are allowed.
+ */
+ public void setBubblesAllowed(String pkg, int uid, boolean allowed) {
PackagePreferences p = getOrCreatePackagePreferences(pkg, uid);
- p.appOverlay = allowed;
- p.lockedAppFields = p.lockedAppFields | LockableAppFields.USER_LOCKED_APP_OVERLAY;
+ p.allowBubble = allowed;
+ p.lockedAppFields = p.lockedAppFields | LockableAppFields.USER_LOCKED_BUBBLE;
}
- public boolean areAppOverlaysAllowed(String pkg, int uid) {
- return getOrCreatePackagePreferences(pkg, uid).appOverlay;
+ /**
+ * Whether bubbles are allowed.
+ *
+ * @param pkg the package to check if bubbles are allowed for
+ * @param uid the uid to check if bubbles are allowed for.
+ * @return whether bubbles are allowed.
+ */
+ public boolean areBubblessAllowed(String pkg, int uid) {
+ return getOrCreatePackagePreferences(pkg, uid).allowBubble;
}
public int getAppLockedFields(String pkg, int uid) {
@@ -1232,8 +1247,8 @@
if (original.canShowBadge() != update.canShowBadge()) {
update.lockFields(NotificationChannel.USER_LOCKED_SHOW_BADGE);
}
- if (original.isAppOverlayAllowed() != update.isAppOverlayAllowed()) {
- update.lockFields(NotificationChannel.USER_LOCKED_ALLOW_APP_OVERLAY);
+ if (original.isBubbleAllowed() != update.isBubbleAllowed()) {
+ update.lockFields(NotificationChannel.USER_LOCKED_ALLOW_BUBBLE);
}
}
@@ -1654,7 +1669,7 @@
int priority = DEFAULT_PRIORITY;
int visibility = DEFAULT_VISIBILITY;
boolean showBadge = DEFAULT_SHOW_BADGE;
- boolean appOverlay = DEFAULT_ALLOW_APP_OVERLAY;
+ boolean allowBubble = DEFAULT_ALLOW_BUBBLE;
int lockedAppFields = DEFAULT_LOCKED_APP_FIELDS;
boolean oemLockedImportance = DEFAULT_OEM_LOCKED_IMPORTANCE;
List<String> futureOemLockedChannels = new ArrayList<>();
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index d1a67bb..6932390 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -239,6 +239,7 @@
import android.os.storage.StorageManagerInternal;
import android.os.storage.VolumeInfo;
import android.os.storage.VolumeRecord;
+import android.permission.PermissionControllerManager;
import android.provider.MediaStore;
import android.provider.Settings.Global;
import android.provider.Settings.Secure;
@@ -317,7 +318,6 @@
import com.android.server.pm.permission.PermissionManagerInternal.PermissionCallback;
import com.android.server.pm.permission.PermissionManagerService;
import com.android.server.pm.permission.PermissionsState;
-import com.android.server.pm.permission.PermissionsState.PermissionState;
import com.android.server.security.VerityUtils;
import com.android.server.storage.DeviceStorageMonitorInternal;
import com.android.server.wm.ActivityTaskManagerInternal;
@@ -370,6 +370,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Predicate;
@@ -443,6 +444,8 @@
private static final boolean ENABLE_FREE_CACHE_V2 =
SystemProperties.getBoolean("fw.free_cache_v2", true);
+ private static final long BACKUP_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(60);
+
private static final int RADIO_UID = Process.PHONE_UID;
private static final int LOG_UID = Process.LOG_UID;
private static final int NFC_UID = Process.NFC_UID;
@@ -13774,14 +13777,15 @@
IBackupManager bm = IBackupManager.Stub.asInterface(
ServiceManager.getService(Context.BACKUP_SERVICE));
if (bm != null) {
+ int userId = args.user.getIdentifier();
if (DEBUG_INSTALL) {
- Log.v(TAG, "token " + token + " to BM for possible restore");
+ Log.v(TAG, "token " + token + " to BM for possible restore for user " + userId);
}
Trace.asyncTraceBegin(TRACE_TAG_PACKAGE_MANAGER, "restore", token);
try {
- // TODO: http://b/22388012
- if (bm.isBackupServiceActive(UserHandle.USER_SYSTEM)) {
- bm.restoreAtInstall(res.pkg.applicationInfo.packageName, token);
+ if (bm.isBackupServiceActive(userId)) {
+ bm.restoreAtInstallForUser(
+ userId, res.pkg.applicationInfo.packageName, token);
} else {
doRestore = false;
}
@@ -19572,28 +19576,32 @@
throw new SecurityException("Only the system may call getPermissionGrantBackup()");
}
- ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
- try {
- final XmlSerializer serializer = new FastXmlSerializer();
- serializer.setOutput(dataStream, StandardCharsets.UTF_8.name());
- serializer.startDocument(null, true);
- serializer.startTag(null, TAG_PERMISSION_BACKUP);
+ AtomicReference<byte[]> backup = new AtomicReference<>();
+ mContext.getSystemService(PermissionControllerManager.class).getRuntimePermissionBackup(
+ UserHandle.of(userId), mContext.getMainExecutor(), (b) -> {
+ synchronized (backup) {
+ backup.set(b);
+ backup.notifyAll();
+ }
+ });
- synchronized (mPackages) {
- serializeRuntimePermissionGrantsLPr(serializer, userId);
- }
+ long start = System.currentTimeMillis();
+ synchronized (backup) {
+ while (backup.get() == null) {
+ long timeLeft = start + BACKUP_TIMEOUT_MILLIS - System.currentTimeMillis();
+ if (timeLeft <= 0) {
+ return null;
+ }
- serializer.endTag(null, TAG_PERMISSION_BACKUP);
- serializer.endDocument();
- serializer.flush();
- } catch (Exception e) {
- if (DEBUG_BACKUP) {
- Slog.e(TAG, "Unable to write default apps for backup", e);
+ try {
+ backup.wait(timeLeft);
+ } catch (InterruptedException ignored) {
+ return null;
+ }
}
- return null;
}
- return dataStream.toByteArray();
+ return backup.get();
}
@Override
@@ -19619,66 +19627,6 @@
}
@GuardedBy("mPackages")
- private void serializeRuntimePermissionGrantsLPr(XmlSerializer serializer, final int userId)
- throws IOException {
- serializer.startTag(null, TAG_ALL_GRANTS);
-
- final int N = mSettings.mPackages.size();
- for (int i = 0; i < N; i++) {
- final PackageSetting ps = mSettings.mPackages.valueAt(i);
- boolean pkgGrantsKnown = false;
-
- PermissionsState packagePerms = ps.getPermissionsState();
-
- for (PermissionState state : packagePerms.getRuntimePermissionStates(userId)) {
- final int grantFlags = state.getFlags();
- // only look at grants that are not system/policy fixed
- if ((grantFlags & SYSTEM_RUNTIME_GRANT_MASK) == 0) {
- final boolean isGranted = state.isGranted();
- // And only back up the user-twiddled state bits
- if (isGranted || (grantFlags & USER_RUNTIME_GRANT_MASK) != 0) {
- final String packageName = mSettings.mPackages.keyAt(i);
- if (!pkgGrantsKnown) {
- serializer.startTag(null, TAG_GRANT);
- serializer.attribute(null, ATTR_PACKAGE_NAME, packageName);
- pkgGrantsKnown = true;
- }
-
- final boolean userSet =
- (grantFlags & FLAG_PERMISSION_USER_SET) != 0;
- final boolean userFixed =
- (grantFlags & FLAG_PERMISSION_USER_FIXED) != 0;
- final boolean revoke =
- (grantFlags & FLAG_PERMISSION_REVOKE_ON_UPGRADE) != 0;
-
- serializer.startTag(null, TAG_PERMISSION);
- serializer.attribute(null, ATTR_PERMISSION_NAME, state.getName());
- if (isGranted) {
- serializer.attribute(null, ATTR_IS_GRANTED, "true");
- }
- if (userSet) {
- serializer.attribute(null, ATTR_USER_SET, "true");
- }
- if (userFixed) {
- serializer.attribute(null, ATTR_USER_FIXED, "true");
- }
- if (revoke) {
- serializer.attribute(null, ATTR_REVOKE_ON_UPGRADE, "true");
- }
- serializer.endTag(null, TAG_PERMISSION);
- }
- }
- }
-
- if (pkgGrantsKnown) {
- serializer.endTag(null, TAG_GRANT);
- }
- }
-
- serializer.endTag(null, TAG_ALL_GRANTS);
- }
-
- @GuardedBy("mPackages")
private void processRestoredPermissionGrantsLPr(XmlPullParser parser, int userId)
throws XmlPullParserException, IOException {
String pkgName = null;
diff --git a/services/core/java/com/android/server/pm/StagingManager.java b/services/core/java/com/android/server/pm/StagingManager.java
index ac05ee8..bd14223 100644
--- a/services/core/java/com/android/server/pm/StagingManager.java
+++ b/services/core/java/com/android/server/pm/StagingManager.java
@@ -130,7 +130,7 @@
ServiceManager.getService("apexservice"));
boolean success;
try {
- success = apex.submitStagedSession(sessionId, apexInfoList);
+ success = apex.submitStagedSession(sessionId, new int[0], apexInfoList);
} catch (RemoteException re) {
Slog.e(TAG, "Unable to contact apexservice", re);
return false;
diff --git a/services/core/java/com/android/server/pm/dex/DexLogger.java b/services/core/java/com/android/server/pm/dex/DexLogger.java
index 68a755b..78fa82c 100644
--- a/services/core/java/com/android/server/pm/dex/DexLogger.java
+++ b/services/core/java/com/android/server/pm/dex/DexLogger.java
@@ -28,7 +28,6 @@
import android.util.Slog;
import android.util.SparseArray;
-import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.pm.Installer;
import com.android.server.pm.Installer.InstallerException;
@@ -53,21 +52,18 @@
private final IPackageManager mPackageManager;
private final PackageDynamicCodeLoading mPackageDynamicCodeLoading;
- private final Object mInstallLock;
- @GuardedBy("mInstallLock")
private final Installer mInstaller;
- public DexLogger(IPackageManager pms, Installer installer, Object installLock) {
- this(pms, installer, installLock, new PackageDynamicCodeLoading());
+ public DexLogger(IPackageManager pms, Installer installer) {
+ this(pms, installer, new PackageDynamicCodeLoading());
}
@VisibleForTesting
- DexLogger(IPackageManager pms, Installer installer, Object installLock,
+ DexLogger(IPackageManager pms, Installer installer,
PackageDynamicCodeLoading packageDynamicCodeLoading) {
mPackageManager = pms;
mPackageDynamicCodeLoading = packageDynamicCodeLoading;
mInstaller = installer;
- mInstallLock = installLock;
}
public Set<String> getAllPackagesWithDynamicCodeLoading() {
@@ -131,14 +127,16 @@
}
byte[] hash = null;
- synchronized (mInstallLock) {
- try {
- hash = mInstaller.hashSecondaryDexFile(filePath, packageName, appInfo.uid,
- appInfo.volumeUuid, storageFlags);
- } catch (InstallerException e) {
- Slog.e(TAG, "Got InstallerException when hashing file " + filePath
- + ": " + e.getMessage());
- }
+ try {
+ // Note that we do not take the install lock here. Hashing should never interfere
+ // with app update/compilation/removal. We may get anomalous results if a file
+ // changes while we hash it, but that can happen anyway and is harmless for our
+ // purposes.
+ hash = mInstaller.hashSecondaryDexFile(filePath, packageName, appInfo.uid,
+ appInfo.volumeUuid, storageFlags);
+ } catch (InstallerException e) {
+ Slog.e(TAG, "Got InstallerException when hashing file " + filePath
+ + ": " + e.getMessage());
}
String fileName = new File(filePath).getName();
diff --git a/services/core/java/com/android/server/pm/dex/DexManager.java b/services/core/java/com/android/server/pm/dex/DexManager.java
index e57d9d7..b546836 100644
--- a/services/core/java/com/android/server/pm/dex/DexManager.java
+++ b/services/core/java/com/android/server/pm/dex/DexManager.java
@@ -129,7 +129,7 @@
mPackageDexOptimizer = pdo;
mInstaller = installer;
mInstallLock = installLock;
- mDexLogger = new DexLogger(pms, installer, installLock);
+ mDexLogger = new DexLogger(pms, installer);
}
public DexLogger getDexLogger() {
diff --git a/services/core/java/com/android/server/role/RoleUserState.java b/services/core/java/com/android/server/role/RoleUserState.java
index 69e1449..02dcc49 100644
--- a/services/core/java/com/android/server/role/RoleUserState.java
+++ b/services/core/java/com/android/server/role/RoleUserState.java
@@ -193,14 +193,18 @@
*
* @param roleName the name of the role to query for
*
- * @return the set of role holders. {@code null} should not be returned and indicates an issue.
+ * @return the set of role holders, or {@code null} if and only if the role is not found
*/
@Nullable
public ArraySet<String> getRoleHolders(@NonNull String roleName) {
synchronized (mLock) {
throwIfDestroyedLocked();
- return new ArraySet<>(mRoles.get(roleName));
+ ArraySet<String> packageNames = mRoles.get(roleName);
+ if (packageNames == null) {
+ return null;
+ }
+ return new ArraySet<>(packageNames);
}
}
@@ -268,8 +272,7 @@
* @param roleName the name of the role to add the holder to
* @param packageName the package name of the new holder
*
- * @return {@code false} only if the set of role holders is null, which should not happen and
- * indicates an issue.
+ * @return {@code false} if and only if the role is not found
*/
@CheckResult
public boolean addRoleHolder(@NonNull String roleName, @NonNull String packageName) {
@@ -302,8 +305,7 @@
* @param roleName the name of the role to remove the holder from
* @param packageName the package name of the holder to remove
*
- * @return {@code false} only if the set of role holders is null, which should not happen and
- * indicates an issue.
+ * @return {@code false} if and only if the role is not found
*/
@CheckResult
public boolean removeRoleHolder(@NonNull String roleName, @NonNull String packageName) {
diff --git a/services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java b/services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java
index 8021265..d12f7ed 100644
--- a/services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java
+++ b/services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java
@@ -977,6 +977,8 @@
ensureRollbackDataLoadedLocked();
mAvailableRollbacks.add(data);
}
+
+ scheduleExpiration(ROLLBACK_LIFETIME_DURATION_MILLIS);
} catch (IOException e) {
Log.e(TAG, "Unable to enable rollback", e);
removeFile(data.backupDir);
diff --git a/services/core/java/com/android/server/signedconfig/GlobalSettingsConfigApplicator.java b/services/core/java/com/android/server/signedconfig/GlobalSettingsConfigApplicator.java
index 438c303..d77cf90 100644
--- a/services/core/java/com/android/server/signedconfig/GlobalSettingsConfigApplicator.java
+++ b/services/core/java/com/android/server/signedconfig/GlobalSettingsConfigApplicator.java
@@ -23,6 +23,7 @@
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Slog;
+import android.util.StatsLog;
import java.security.GeneralSecurityException;
import java.util.Arrays;
@@ -66,12 +67,14 @@
private final Context mContext;
private final String mSourcePackage;
+ private final SignedConfigEvent mEvent;
private final SignatureVerifier mVerifier;
- GlobalSettingsConfigApplicator(Context context, String sourcePackage) {
+ GlobalSettingsConfigApplicator(Context context, String sourcePackage, SignedConfigEvent event) {
mContext = context;
mSourcePackage = sourcePackage;
- mVerifier = new SignatureVerifier();
+ mEvent = event;
+ mVerifier = new SignatureVerifier(mEvent);
}
private boolean checkSignature(String data, String signature) {
@@ -79,6 +82,7 @@
return mVerifier.verifySignature(data, signature);
} catch (GeneralSecurityException e) {
Slog.e(TAG, "Failed to verify signature", e);
+ mEvent.status = StatsLog.SIGNED_CONFIG_REPORTED__STATUS__SECURITY_EXCEPTION;
return false;
}
}
@@ -109,14 +113,17 @@
SignedConfig config;
try {
config = SignedConfig.parse(configStr, ALLOWED_KEYS, KEY_VALUE_MAPPERS);
+ mEvent.version = config.version;
} catch (InvalidConfigException e) {
Slog.e(TAG, "Failed to parse global settings from package " + mSourcePackage, e);
+ mEvent.status = StatsLog.SIGNED_CONFIG_REPORTED__STATUS__INVALID_CONFIG;
return;
}
int currentVersion = getCurrentConfigVersion();
if (currentVersion >= config.version) {
Slog.i(TAG, "Global settings from package " + mSourcePackage
+ " is older than existing: " + config.version + "<=" + currentVersion);
+ mEvent.status = StatsLog.SIGNED_CONFIG_REPORTED__STATUS__OLD_CONFIG;
return;
}
// We have new config!
@@ -126,10 +133,12 @@
config.getMatchingConfig(Build.VERSION.SDK_INT);
if (matchedConfig == null) {
Slog.i(TAG, "Settings is not applicable to current SDK version; ignoring");
+ mEvent.status = StatsLog.SIGNED_CONFIG_REPORTED__STATUS__NOT_APPLICABLE;
return;
}
Slog.i(TAG, "Updating global settings to version " + config.version);
updateCurrentConfig(config.version, matchedConfig.values);
+ mEvent.status = StatsLog.SIGNED_CONFIG_REPORTED__STATUS__APPLIED;
}
}
diff --git a/services/core/java/com/android/server/signedconfig/SignatureVerifier.java b/services/core/java/com/android/server/signedconfig/SignatureVerifier.java
index 944db84..56db32a 100644
--- a/services/core/java/com/android/server/signedconfig/SignatureVerifier.java
+++ b/services/core/java/com/android/server/signedconfig/SignatureVerifier.java
@@ -18,6 +18,7 @@
import android.os.Build;
import android.util.Slog;
+import android.util.StatsLog;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
@@ -42,11 +43,18 @@
private static final String DEBUG_KEY =
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEaAn2XVifsLTHg616nTsOMVmlhBoECGbTEBTKKvdd2hO60"
+ "pj1pnU8SMkhYfaNxZuKgw9LNvOwlFwStboIYeZ3lQ==";
+ private static final String PROD_KEY =
+ "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE+lky6wKyGL6lE1VrD0YTMHwb0Xwc+tzC8MvnrzVxodvTp"
+ + "VY/jV7V+Zktcx+pry43XPABFRXtbhTo+qykhyBA1g==";
+ private final SignedConfigEvent mEvent;
private final PublicKey mDebugKey;
+ private final PublicKey mProdKey;
- public SignatureVerifier() {
- mDebugKey = createKey(DEBUG_KEY);
+ public SignatureVerifier(SignedConfigEvent event) {
+ mEvent = event;
+ mDebugKey = Build.IS_DEBUGGABLE ? createKey(DEBUG_KEY) : null;
+ mProdKey = createKey(PROD_KEY);
}
private static PublicKey createKey(String base64) {
@@ -67,6 +75,14 @@
}
}
+ private boolean verifyWithPublicKey(PublicKey key, byte[] data, byte[] signature)
+ throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
+ Signature verifier = Signature.getInstance("SHA256withECDSA");
+ verifier.initVerify(key);
+ verifier.update(data);
+ return verifier.verify(signature);
+ }
+
/**
* Verify a signature for signed config.
*
@@ -80,6 +96,7 @@
try {
signature = Base64.getDecoder().decode(base64Signature);
} catch (IllegalArgumentException e) {
+ mEvent.status = StatsLog.SIGNED_CONFIG_REPORTED__STATUS__BASE64_FAILURE_SIGNATURE;
Slog.e(TAG, "Failed to base64 decode signature");
return false;
}
@@ -89,11 +106,9 @@
if (Build.IS_DEBUGGABLE) {
if (mDebugKey != null) {
if (DBG) Slog.w(TAG, "Trying to verify signature using debug key");
- Signature verifier = Signature.getInstance("SHA256withECDSA");
- verifier.initVerify(mDebugKey);
- verifier.update(data);
- if (verifier.verify(signature)) {
+ if (verifyWithPublicKey(mDebugKey, data, signature)) {
Slog.i(TAG, "Verified config using debug key");
+ mEvent.verifiedWith = StatsLog.SIGNED_CONFIG_REPORTED__VERIFIED_WITH__DEBUG;
return true;
} else {
if (DBG) Slog.i(TAG, "Config verification failed using debug key");
@@ -102,8 +117,20 @@
Slog.w(TAG, "Debuggable build, but have no debug key");
}
}
- // TODO verify production key.
- Slog.w(TAG, "NO PRODUCTION KEY YET, FAILING VERIFICATION");
- return false;
+ if (mProdKey == null) {
+ Slog.e(TAG, "No prod key; construction failed?");
+ mEvent.status =
+ StatsLog.SIGNED_CONFIG_REPORTED__STATUS__SIGNATURE_CHECK_FAILED_PROD_KEY_ABSENT;
+ return false;
+ }
+ if (verifyWithPublicKey(mProdKey, data, signature)) {
+ Slog.i(TAG, "Verified config using production key");
+ mEvent.verifiedWith = StatsLog.SIGNED_CONFIG_REPORTED__VERIFIED_WITH__PRODUCTION;
+ return true;
+ } else {
+ if (DBG) Slog.i(TAG, "Verification failed using production key");
+ mEvent.status = StatsLog.SIGNED_CONFIG_REPORTED__STATUS__SIGNATURE_CHECK_FAILED;
+ return false;
+ }
}
}
diff --git a/services/core/java/com/android/server/signedconfig/SignedConfigEvent.java b/services/core/java/com/android/server/signedconfig/SignedConfigEvent.java
new file mode 100644
index 0000000..2f2062c
--- /dev/null
+++ b/services/core/java/com/android/server/signedconfig/SignedConfigEvent.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.server.signedconfig;
+
+import android.util.StatsLog;
+
+/**
+ * Helper class to allow a SignedConfigReported event to be built up in stages.
+ */
+public class SignedConfigEvent {
+
+ public int type = StatsLog.SIGNED_CONFIG_REPORTED__TYPE__UNKNOWN_TYPE;
+ public int status = StatsLog.SIGNED_CONFIG_REPORTED__STATUS__UNKNOWN_STATUS;
+ public int version = 0;
+ public String fromPackage = null;
+ public int verifiedWith = StatsLog.SIGNED_CONFIG_REPORTED__VERIFIED_WITH__NO_KEY;
+
+ /**
+ * Write this event to statslog.
+ */
+ public void send() {
+ StatsLog.write(StatsLog.SIGNED_CONFIG_REPORTED,
+ type, status, version, fromPackage, verifiedWith);
+ }
+
+}
diff --git a/services/core/java/com/android/server/signedconfig/SignedConfigService.java b/services/core/java/com/android/server/signedconfig/SignedConfigService.java
index 6bcee14..dc39542 100644
--- a/services/core/java/com/android/server/signedconfig/SignedConfigService.java
+++ b/services/core/java/com/android/server/signedconfig/SignedConfigService.java
@@ -26,6 +26,7 @@
import android.net.Uri;
import android.os.Bundle;
import android.util.Slog;
+import android.util.StatsLog;
import com.android.server.LocalServices;
@@ -82,21 +83,30 @@
}
if (metaData.containsKey(KEY_GLOBAL_SETTINGS)
&& metaData.containsKey(KEY_GLOBAL_SETTINGS_SIGNATURE)) {
- String config = metaData.getString(KEY_GLOBAL_SETTINGS);
- String signature = metaData.getString(KEY_GLOBAL_SETTINGS_SIGNATURE);
+ SignedConfigEvent event = new SignedConfigEvent();
try {
- // Base64 encoding is standard (not URL safe) encoding: RFC4648
- config = new String(Base64.getDecoder().decode(config), StandardCharsets.UTF_8);
- } catch (IllegalArgumentException iae) {
- Slog.e(TAG, "Failed to base64 decode global settings config from " + packageName);
- return;
+ event.type = StatsLog.SIGNED_CONFIG_REPORTED__TYPE__GLOBAL_SETTINGS;
+ event.fromPackage = packageName;
+ String config = metaData.getString(KEY_GLOBAL_SETTINGS);
+ String signature = metaData.getString(KEY_GLOBAL_SETTINGS_SIGNATURE);
+ try {
+ // Base64 encoding is standard (not URL safe) encoding: RFC4648
+ config = new String(Base64.getDecoder().decode(config), StandardCharsets.UTF_8);
+ } catch (IllegalArgumentException iae) {
+ Slog.e(TAG, "Failed to base64 decode global settings config from "
+ + packageName);
+ event.status = StatsLog.SIGNED_CONFIG_REPORTED__STATUS__BASE64_FAILURE_CONFIG;
+ return;
+ }
+ if (DBG) {
+ Slog.d(TAG, "Got global settings config: " + config);
+ Slog.d(TAG, "Got global settings signature: " + signature);
+ }
+ new GlobalSettingsConfigApplicator(mContext, packageName, event).applyConfig(
+ config, signature);
+ } finally {
+ event.send();
}
- if (DBG) {
- Slog.d(TAG, "Got global settings config: " + config);
- Slog.d(TAG, "Got global settings signature: " + signature);
- }
- new GlobalSettingsConfigApplicator(mContext, packageName).applyConfig(
- config, signature);
} else {
if (DBG) Slog.d(TAG, "Package has no global settings config/signature.");
}
diff --git a/services/core/java/com/android/server/stats/StatsCompanionService.java b/services/core/java/com/android/server/stats/StatsCompanionService.java
index 30aa528..4e71a05 100644
--- a/services/core/java/com/android/server/stats/StatsCompanionService.java
+++ b/services/core/java/com/android/server/stats/StatsCompanionService.java
@@ -43,6 +43,7 @@
import android.content.pm.UserInfo;
import android.hardware.fingerprint.FingerprintManager;
import android.net.ConnectivityManager;
+import android.net.INetworkStatsService;
import android.net.Network;
import android.net.NetworkRequest;
import android.net.NetworkStats;
@@ -90,7 +91,6 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.app.procstats.IProcessStats;
import com.android.internal.app.procstats.ProcessStats;
-import com.android.internal.net.NetworkStatsFactory;
import com.android.internal.os.BatterySipper;
import com.android.internal.os.BatteryStatsHelper;
import com.android.internal.os.BinderCallsStats.ExportedCallStat;
@@ -210,6 +210,7 @@
private final Context mContext;
private final AlarmManager mAlarmManager;
+ private final INetworkStatsService mNetworkStatsService;
@GuardedBy("sStatsdLock")
private static IStatsManager sStatsd;
private static final Object sStatsdLock = new Object();
@@ -257,6 +258,8 @@
super();
mContext = context;
mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
+ mNetworkStatsService = INetworkStatsService.Stub.asInterface(
+ ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
mBaseDir.mkdirs();
mAppUpdateReceiver = new AppUpdateReceiver();
mUserUpdateReceiver = new BroadcastReceiver() {
@@ -788,14 +791,14 @@
if (ifaces.length == 0) {
return;
}
- NetworkStatsFactory nsf = new NetworkStatsFactory();
+ if (mNetworkStatsService == null) {
+ Slog.e(TAG, "NetworkStats Service is not available!");
+ return;
+ }
// Combine all the metrics per Uid into one record.
- NetworkStats stats =
- nsf.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces, NetworkStats.TAG_NONE,
- null)
- .groupedByUid();
+ NetworkStats stats = mNetworkStatsService.getDetailedUidStats(ifaces).groupedByUid();
addNetworkStats(tagId, pulledData, stats, false);
- } catch (java.io.IOException e) {
+ } catch (RemoteException e) {
Slog.e(TAG, "Pulling netstats for wifi bytes has error", e);
} finally {
Binder.restoreCallingIdentity(token);
@@ -812,12 +815,14 @@
if (ifaces.length == 0) {
return;
}
- NetworkStatsFactory nsf = new NetworkStatsFactory();
+ if (mNetworkStatsService == null) {
+ Slog.e(TAG, "NetworkStats Service is not available!");
+ return;
+ }
NetworkStats stats = rollupNetworkStatsByFGBG(
- nsf.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces, NetworkStats.TAG_NONE,
- null));
+ mNetworkStatsService.getDetailedUidStats(ifaces));
addNetworkStats(tagId, pulledData, stats, true);
- } catch (java.io.IOException e) {
+ } catch (RemoteException e) {
Slog.e(TAG, "Pulling netstats for wifi bytes w/ fg/bg has error", e);
} finally {
Binder.restoreCallingIdentity(token);
@@ -834,14 +839,14 @@
if (ifaces.length == 0) {
return;
}
- NetworkStatsFactory nsf = new NetworkStatsFactory();
+ if (mNetworkStatsService == null) {
+ Slog.e(TAG, "NetworkStats Service is not available!");
+ return;
+ }
// Combine all the metrics per Uid into one record.
- NetworkStats stats =
- nsf.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces, NetworkStats.TAG_NONE,
- null)
- .groupedByUid();
+ NetworkStats stats = mNetworkStatsService.getDetailedUidStats(ifaces).groupedByUid();
addNetworkStats(tagId, pulledData, stats, false);
- } catch (java.io.IOException e) {
+ } catch (RemoteException e) {
Slog.e(TAG, "Pulling netstats for mobile bytes has error", e);
} finally {
Binder.restoreCallingIdentity(token);
@@ -874,12 +879,14 @@
if (ifaces.length == 0) {
return;
}
- NetworkStatsFactory nsf = new NetworkStatsFactory();
+ if (mNetworkStatsService == null) {
+ Slog.e(TAG, "NetworkStats Service is not available!");
+ return;
+ }
NetworkStats stats = rollupNetworkStatsByFGBG(
- nsf.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces, NetworkStats.TAG_NONE,
- null));
+ mNetworkStatsService.getDetailedUidStats(ifaces));
addNetworkStats(tagId, pulledData, stats, true);
- } catch (java.io.IOException e) {
+ } catch (RemoteException e) {
Slog.e(TAG, "Pulling netstats for mobile bytes w/ fg/bg has error", e);
} finally {
Binder.restoreCallingIdentity(token);
@@ -2058,6 +2065,17 @@
mContext.unregisterReceiver(mShutdownEventReceiver);
cancelAnomalyAlarm();
cancelPullingAlarm();
+
+ BinderCallsStatsService.Internal binderStats =
+ LocalServices.getService(BinderCallsStatsService.Internal.class);
+ if (binderStats != null) {
+ binderStats.reset();
+ }
+
+ LooperStats looperStats = LocalServices.getService(LooperStats.class);
+ if (looperStats != null) {
+ looperStats.reset();
+ }
}
@Override
diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java
index a207354..916baa0 100644
--- a/services/core/java/com/android/server/wm/ActivityStarter.java
+++ b/services/core/java/com/android/server/wm/ActivityStarter.java
@@ -16,6 +16,7 @@
package com.android.server.wm;
+import static android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND;
import static android.app.Activity.RESULT_CANCELED;
import static android.app.ActivityManager.START_ABORTED;
import static android.app.ActivityManager.START_CANCELED;
@@ -50,6 +51,7 @@
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE;
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK;
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP;
+import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;
@@ -745,8 +747,9 @@
// not sure if we need to create START_ABORTED_BACKGROUND so for now piggybacking
// on START_ABORTED
if (!abort) {
- abort |= shouldAbortBackgroundActivityStart(callingUid, callingPackage, realCallingUid,
- callerApp, originatingPendingIntent, allowBackgroundActivityStart);
+ abort |= shouldAbortBackgroundActivityStart(callingUid, callingPid, callingPackage,
+ realCallingUid, callerApp, originatingPendingIntent,
+ allowBackgroundActivityStart, intent);
}
// Merge the two options bundles, while realCallerOptions takes precedence.
@@ -893,9 +896,10 @@
true /* doResume */, checkedOptions, inTask, outActivity);
}
- private boolean shouldAbortBackgroundActivityStart(int callingUid, final String callingPackage,
- int realCallingUid, WindowProcessController callerApp,
- PendingIntentRecord originatingPendingIntent, boolean allowBackgroundActivityStart) {
+ private boolean shouldAbortBackgroundActivityStart(int callingUid, int callingPid,
+ final String callingPackage, int realCallingUid, WindowProcessController callerApp,
+ PendingIntentRecord originatingPendingIntent, boolean allowBackgroundActivityStart,
+ Intent intent) {
if (mService.isBackgroundActivityStartsEnabled()) {
return false;
}
@@ -908,19 +912,24 @@
return false;
}
// don't abort if the callingUid is in the foreground or is a persistent system process
- if (isUidForeground(callingUid) || isUidPersistentSystemProcess(callingUid)) {
+ final boolean isCallingUidForeground = isUidForeground(callingUid);
+ final boolean isCallingUidPersistentSystemProcess = isUidPersistentSystemProcess(
+ callingUid);
+ if (isCallingUidForeground || isCallingUidPersistentSystemProcess) {
return false;
}
// take realCallingUid into consideration
+ final boolean isRealCallingUidForeground = isUidForeground(realCallingUid);
+ final boolean isRealCallingUidPersistentSystemProcess = isUidPersistentSystemProcess(
+ realCallingUid);
if (realCallingUid != callingUid) {
// don't abort if the realCallingUid is in the foreground and callingUid isn't
- if (isUidForeground(realCallingUid)) {
+ if (isRealCallingUidForeground) {
return false;
}
// if the realCallingUid is a persistent system process, abort if the IntentSender
// wasn't whitelisted to start an activity
- if (isUidPersistentSystemProcess(realCallingUid) && (originatingPendingIntent != null)
- && allowBackgroundActivityStart) {
+ if (isRealCallingUidPersistentSystemProcess && allowBackgroundActivityStart) {
return false;
}
}
@@ -928,11 +937,28 @@
if (callerApp != null && callerApp.areBackgroundActivityStartsAllowed()) {
return false;
}
+ // don't abort if the callingUid has START_ACTIVITIES_FROM_BACKGROUND permission
+ if (mService.checkPermission(START_ACTIVITIES_FROM_BACKGROUND, callingPid, callingUid)
+ == PERMISSION_GRANTED) {
+ return false;
+ }
// don't abort if the caller has the same uid as the recents component
if (mSupervisor.mRecentTasks.isCallerRecents(callingUid)) {
return false;
}
// anything that has fallen through will currently be aborted
+ Slog.w(TAG, "Blocking background activity start [callingPackage: " + callingPackage
+ + "; callingUid: " + callingUid
+ + "; isCallingUidForeground: " + isCallingUidForeground
+ + "; isCallingUidPersistentSystemProcess: " + isCallingUidPersistentSystemProcess
+ + "; realCallingUid: " + realCallingUid
+ + "; isRealCallingUidForeground: " + isRealCallingUidForeground
+ + "; isRealCallingUidPersistentSystemProcess: "
+ + isRealCallingUidPersistentSystemProcess
+ + "; originatingPendingIntent: " + originatingPendingIntent
+ + "; isBgStartWhitelisted: " + allowBackgroundActivityStart
+ + "; intent: " + intent
+ + "]");
// TODO: remove this toast after feature development is done
mService.mUiHandler.post(() -> {
Toast.makeText(mService.mContext,
diff --git a/services/core/java/com/android/server/wm/KeyguardController.java b/services/core/java/com/android/server/wm/KeyguardController.java
index 5f56fe5..177f244 100644
--- a/services/core/java/com/android/server/wm/KeyguardController.java
+++ b/services/core/java/com/android/server/wm/KeyguardController.java
@@ -462,22 +462,19 @@
mOccluded = false;
mDismissingKeyguardActivity = null;
- // Only the top activity of the focused stack on each display may control it's
- // occluded state.
- final ActivityStack focusedStack = display.getFocusedStack();
- if (focusedStack != null) {
- final ActivityRecord topDismissing =
- focusedStack.getTopDismissingKeyguardActivity();
- mOccluded = focusedStack.topActivityOccludesKeyguard() || (topDismissing != null
- && focusedStack.topRunningActivityLocked() == topDismissing
- && controller.canShowWhileOccluded(
+ final ActivityStack stack = getStackForControllingOccluding(display);
+ if (stack != null) {
+ final ActivityRecord topDismissing = stack.getTopDismissingKeyguardActivity();
+ mOccluded = stack.topActivityOccludesKeyguard() || (topDismissing != null
+ && stack.topRunningActivityLocked() == topDismissing
+ && controller.canShowWhileOccluded(
true /* dismissKeyguard */,
false /* showWhenLocked */));
- if (focusedStack.getTopDismissingKeyguardActivity() != null) {
- mDismissingKeyguardActivity = focusedStack.getTopDismissingKeyguardActivity();
+ if (stack.getTopDismissingKeyguardActivity() != null) {
+ mDismissingKeyguardActivity = stack.getTopDismissingKeyguardActivity();
}
- mOccluded |= controller.mWindowManager.isShowingDream();
}
+ mOccluded |= controller.mWindowManager.isShowingDream();
// TODO(b/113840485): Handle app transition for individual display, and apply occluded
// state change to secondary displays.
@@ -492,6 +489,23 @@
}
}
+ /**
+ * Gets the stack used to check the occluded state.
+ * <p>
+ * Only the top non-pinned activity of the focusable stack on each display can control its
+ * occlusion state.
+ */
+ private ActivityStack getStackForControllingOccluding(ActivityDisplay display) {
+ for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
+ final ActivityStack stack = display.getChildAt(stackNdx);
+ if (stack != null && stack.isFocusableAndVisible()
+ && !stack.inPinnedWindowingMode()) {
+ return stack;
+ }
+ }
+ return null;
+ }
+
void dumpStatus(PrintWriter pw, String prefix) {
final StringBuilder sb = new StringBuilder();
sb.append(prefix);
diff --git a/services/core/java/com/android/server/wm/TaskRecord.java b/services/core/java/com/android/server/wm/TaskRecord.java
index 4a553cf..e944858 100644
--- a/services/core/java/com/android/server/wm/TaskRecord.java
+++ b/services/core/java/com/android/server/wm/TaskRecord.java
@@ -1278,28 +1278,28 @@
}
/**
- * Checks if the root activity requires a particular orientation (either by override or
+ * Checks if the top activity requires a particular orientation (either by override or
* activityInfo) and returns that. Otherwise, this returns ORIENTATION_UNDEFINED.
*/
- private int getRootActivityRequestedOrientation() {
- ActivityRecord root = getRootActivity();
+ private int getTopActivityRequestedOrientation() {
+ ActivityRecord top = getTopActivity();
if (getRequestedOverrideConfiguration().orientation != ORIENTATION_UNDEFINED
- || root == null) {
+ || top == null) {
return getRequestedOverrideConfiguration().orientation;
}
- int rootScreenOrientation = root.getOrientation();
- if (rootScreenOrientation == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
+ int screenOrientation = top.getOrientation();
+ if (screenOrientation == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
// NOSENSOR means the display's "natural" orientation, so return that.
ActivityDisplay display = mStack != null ? mStack.getDisplay() : null;
if (display != null && display.mDisplayContent != null) {
return mStack.getDisplay().mDisplayContent.getNaturalOrientation();
}
- } else if (rootScreenOrientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
+ } else if (screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
// LOCKED means the activity's orientation remains unchanged, so return existing value.
- return root.getConfiguration().orientation;
- } else if (ActivityInfo.isFixedOrientationLandscape(rootScreenOrientation)) {
+ return top.getConfiguration().orientation;
+ } else if (ActivityInfo.isFixedOrientationLandscape(screenOrientation)) {
return ORIENTATION_LANDSCAPE;
- } else if (ActivityInfo.isFixedOrientationPortrait(rootScreenOrientation)) {
+ } else if (ActivityInfo.isFixedOrientationPortrait(screenOrientation)) {
return ORIENTATION_PORTRAIT;
}
return ORIENTATION_UNDEFINED;
@@ -2196,9 +2196,9 @@
// In FULLSCREEN mode, always start with empty bounds to indicate "fill parent"
outOverrideBounds.setEmpty();
- // If the task or its root activity require a different orientation, make it fit the
+ // If the task or its top activity requires a different orientation, make it fit the
// available bounds by scaling down its bounds.
- int forcedOrientation = getRootActivityRequestedOrientation();
+ int forcedOrientation = getTopActivityRequestedOrientation();
if (forcedOrientation != ORIENTATION_UNDEFINED
&& forcedOrientation != newParentConfig.orientation) {
final Rect parentBounds = newParentConfig.windowConfiguration.getBounds();
diff --git a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp
index b290bc5..bce944d 100644
--- a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp
+++ b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp
@@ -856,7 +856,7 @@
Return<void> GnssMeasurementCallback::gnssMeasurementCb_2_0(
const IGnssMeasurementCallback_V2_0::GnssData& data) {
- // TODO(b/119571122): implement gnssMeasurementCb_2_0
+ translateAndSetGnssData(data);
return Void();
}
@@ -894,9 +894,8 @@
return data.measurementCount;
}
-template<>
-size_t GnssMeasurementCallback::getMeasurementCount<IGnssMeasurementCallback_V1_1::GnssData>
- (const IGnssMeasurementCallback_V1_1::GnssData& data) {
+template<class T>
+size_t GnssMeasurementCallback::getMeasurementCount(const T& data) {
return data.measurements.size();
}
@@ -958,6 +957,17 @@
ADR_STATE_HALF_CYCLE_REPORTED));
}
+// Preallocate object as: JavaObject object(env, "android/location/GnssMeasurement");
+template<>
+void GnssMeasurementCallback::translateSingleGnssMeasurement
+ <IGnssMeasurementCallback_V2_0::GnssMeasurement>(
+ const IGnssMeasurementCallback_V2_0::GnssMeasurement* measurement_V2_0,
+ JavaObject& object) {
+ translateSingleGnssMeasurement(&(measurement_V2_0->v1_1), object);
+
+ SET(CodeType, (static_cast<int32_t>(measurement_V2_0->codeType)));
+}
+
jobject GnssMeasurementCallback::translateGnssClock(
JNIEnv* env, const IGnssMeasurementCallback_V1_0::GnssClock* clock) {
JavaObject object(env, "android/location/GnssClock");
diff --git a/services/ipmemorystore/java/com/android/server/net/ipmemorystore/IpMemoryStoreDatabase.java b/services/ipmemorystore/java/com/android/server/net/ipmemorystore/IpMemoryStoreDatabase.java
new file mode 100644
index 0000000..eaab650
--- /dev/null
+++ b/services/ipmemorystore/java/com/android/server/net/ipmemorystore/IpMemoryStoreDatabase.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.net.ipmemorystore;
+
+import android.annotation.NonNull;
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+
+/**
+ * Encapsulating class for using the SQLite database backing the memory store.
+ *
+ * This class groups together the contracts and the SQLite helper used to
+ * use the database.
+ *
+ * @hide
+ */
+public class IpMemoryStoreDatabase {
+ /**
+ * Contract class for the Network Attributes table.
+ */
+ public static class NetworkAttributesContract {
+ public static final String TABLENAME = "NetworkAttributes";
+
+ public static final String COLNAME_L2KEY = "l2Key";
+ public static final String COLTYPE_L2KEY = "TEXT NOT NULL";
+
+ public static final String COLNAME_EXPIRYDATE = "expiryDate";
+ // Milliseconds since the Epoch, in true Java style
+ public static final String COLTYPE_EXPIRYDATE = "BIGINT";
+
+ public static final String COLNAME_ASSIGNEDV4ADDRESS = "assignedV4Address";
+ public static final String COLTYPE_ASSIGNEDV4ADDRESS = "INTEGER";
+
+ // Please note that the group hint is only a *hint*, hence its name. The client can offer
+ // this information to nudge the grouping in the decision it thinks is right, but it can't
+ // decide for the memory store what is the same L3 network.
+ public static final String COLNAME_GROUPHINT = "groupHint";
+ public static final String COLTYPE_GROUPHINT = "TEXT";
+
+ public static final String COLNAME_DNSADDRESSES = "dnsAddresses";
+ // Stored in marshalled form as is
+ public static final String COLTYPE_DNSADDRESSES = "BLOB";
+
+ public static final String COLNAME_MTU = "mtu";
+ public static final String COLTYPE_MTU = "INTEGER";
+
+ public static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS "
+ + TABLENAME + " ("
+ + COLNAME_L2KEY + " " + COLTYPE_L2KEY + " PRIMARY KEY NOT NULL, "
+ + COLNAME_EXPIRYDATE + " " + COLTYPE_EXPIRYDATE + ", "
+ + COLNAME_ASSIGNEDV4ADDRESS + " " + COLTYPE_ASSIGNEDV4ADDRESS + ", "
+ + COLNAME_GROUPHINT + " " + COLTYPE_GROUPHINT + ", "
+ + COLNAME_DNSADDRESSES + " " + COLTYPE_DNSADDRESSES + ", "
+ + COLNAME_MTU + " " + COLTYPE_MTU + ")";
+ public static final String DROP_TABLE = "DROP TABLE IF EXISTS " + TABLENAME;
+ }
+
+ /**
+ * Contract class for the Private Data table.
+ */
+ public static class PrivateDataContract {
+ public static final String TABLENAME = "PrivateData";
+
+ public static final String COLNAME_L2KEY = "l2Key";
+ public static final String COLTYPE_L2KEY = "TEXT NOT NULL";
+
+ public static final String COLNAME_CLIENT = "client";
+ public static final String COLTYPE_CLIENT = "TEXT NOT NULL";
+
+ public static final String COLNAME_DATANAME = "dataName";
+ public static final String COLTYPE_DATANAME = "TEXT NOT NULL";
+
+ public static final String COLNAME_DATA = "data";
+ public static final String COLTYPE_DATA = "BLOB NOT NULL";
+
+ public static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS "
+ + TABLENAME + " ("
+ + COLNAME_L2KEY + " " + COLTYPE_L2KEY + ", "
+ + COLNAME_CLIENT + " " + COLTYPE_CLIENT + ", "
+ + COLNAME_DATANAME + " " + COLTYPE_DATANAME + ", "
+ + COLNAME_DATA + " " + COLTYPE_DATA + ", "
+ + "PRIMARY KEY ("
+ + COLNAME_L2KEY + ", "
+ + COLNAME_CLIENT + ", "
+ + COLNAME_DATANAME + "))";
+ public static final String DROP_TABLE = "DROP TABLE IF EXISTS " + TABLENAME;
+ }
+
+ // To save memory when the DB is not used, close it after 30s of inactivity. This is
+ // determined manually based on what feels right.
+ private static final long IDLE_CONNECTION_TIMEOUT_MS = 30_000;
+
+ /** The SQLite DB helper */
+ public static class DbHelper extends SQLiteOpenHelper {
+ // Update this whenever changing the schema.
+ private static final int SCHEMA_VERSION = 1;
+ private static final String DATABASE_FILENAME = "IpMemoryStore.db";
+
+ public DbHelper(@NonNull final Context context) {
+ super(context, DATABASE_FILENAME, null, SCHEMA_VERSION);
+ setIdleConnectionTimeout(IDLE_CONNECTION_TIMEOUT_MS);
+ }
+
+ /** Called when the database is created */
+ public void onCreate(@NonNull final SQLiteDatabase db) {
+ db.execSQL(NetworkAttributesContract.CREATE_TABLE);
+ db.execSQL(PrivateDataContract.CREATE_TABLE);
+ }
+
+ /** Called when the database is upgraded */
+ public void onUpgrade(@NonNull final SQLiteDatabase db, final int oldVersion,
+ final int newVersion) {
+ // No upgrade supported yet.
+ db.execSQL(NetworkAttributesContract.DROP_TABLE);
+ db.execSQL(PrivateDataContract.DROP_TABLE);
+ onCreate(db);
+ }
+
+ /** Called when the database is downgraded */
+ public void onDowngrade(@NonNull final SQLiteDatabase db, final int oldVersion,
+ final int newVersion) {
+ // Downgrades always nuke all data and recreate an empty table.
+ db.execSQL(NetworkAttributesContract.DROP_TABLE);
+ db.execSQL(PrivateDataContract.DROP_TABLE);
+ onCreate(db);
+ }
+ }
+}
diff --git a/services/ipmemorystore/java/com/android/server/net/ipmemorystore/IpMemoryStoreService.java b/services/ipmemorystore/java/com/android/server/net/ipmemorystore/IpMemoryStoreService.java
index c9759bf..55a72190 100644
--- a/services/ipmemorystore/java/com/android/server/net/ipmemorystore/IpMemoryStoreService.java
+++ b/services/ipmemorystore/java/com/android/server/net/ipmemorystore/IpMemoryStoreService.java
@@ -19,6 +19,8 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
+import android.database.SQLException;
+import android.database.sqlite.SQLiteDatabase;
import android.net.IIpMemoryStore;
import android.net.ipmemorystore.Blob;
import android.net.ipmemorystore.IOnBlobRetrievedListener;
@@ -27,6 +29,10 @@
import android.net.ipmemorystore.IOnSameNetworkResponseListener;
import android.net.ipmemorystore.IOnStatusListener;
import android.net.ipmemorystore.NetworkAttributesParcelable;
+import android.util.Log;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
/**
* Implementation for the IP memory store.
@@ -37,10 +43,75 @@
* @hide
*/
public class IpMemoryStoreService extends IIpMemoryStore.Stub {
- final Context mContext;
+ private static final String TAG = IpMemoryStoreService.class.getSimpleName();
+ private static final int MAX_CONCURRENT_THREADS = 4;
+ @NonNull
+ final Context mContext;
+ @Nullable
+ final SQLiteDatabase mDb;
+ @NonNull
+ final ExecutorService mExecutor;
+
+ /**
+ * Construct an IpMemoryStoreService object.
+ * This constructor will block on disk access to open the database.
+ * @param context the context to access storage with.
+ */
public IpMemoryStoreService(@NonNull final Context context) {
+ // Note that constructing the service will access the disk and block
+ // for some time, but it should make no difference to the clients. Because
+ // the interface is one-way, clients fire and forget requests, and the callback
+ // will get called eventually in any case, and the framework will wait for the
+ // service to be created to deliver subsequent requests.
+ // Avoiding this would mean the mDb member can't be final, which means the service would
+ // have to test for nullity, care for failure, and allow for a wait at every single access,
+ // which would make the code a lot more complex and require all methods to possibly block.
mContext = context;
+ SQLiteDatabase db;
+ final IpMemoryStoreDatabase.DbHelper helper = new IpMemoryStoreDatabase.DbHelper(context);
+ try {
+ db = helper.getWritableDatabase();
+ if (null == db) Log.e(TAG, "Unexpected null return of getWriteableDatabase");
+ } catch (final SQLException e) {
+ Log.e(TAG, "Can't open the Ip Memory Store database", e);
+ db = null;
+ } catch (final Exception e) {
+ Log.wtf(TAG, "Impossible exception Ip Memory Store database", e);
+ db = null;
+ }
+ mDb = db;
+ // The work-stealing thread pool executor will spawn threads as needed up to
+ // the max only when there is no free thread available. This generally behaves
+ // exactly like one would expect it intuitively :
+ // - When work arrives, it will spawn a new thread iff there are no available threads
+ // - When there is no work to do it will shutdown threads after a while (the while
+ // being equal to 2 seconds (not configurable) when max threads are spun up and
+ // twice as much for every one less thread)
+ // - When all threads are busy the work is enqueued and waits for any worker
+ // to become available.
+ // Because the stealing pool is made for very heavily parallel execution of
+ // small tasks that spawn others, it creates a queue per thread that in this
+ // case is overhead. However, the three behaviors above make it a superior
+ // choice to cached or fixedThreadPoolExecutor, neither of which can actually
+ // enqueue a task waiting for a thread to be free. This can probably be solved
+ // with judicious subclassing of ThreadPoolExecutor, but that's a lot of dangerous
+ // complexity for little benefit in this case.
+ mExecutor = Executors.newWorkStealingPool(MAX_CONCURRENT_THREADS);
+ }
+
+ /**
+ * Shutdown the memory store service, cancelling running tasks and dropping queued tasks.
+ *
+ * This is provided to give a way to clean up, and is meant to be available in case of an
+ * emergency shutdown.
+ */
+ public void shutdown() {
+ // By contrast with ExecutorService#shutdown, ExecutorService#shutdownNow tries
+ // to cancel the existing tasks, and does not wait for completion. It does not
+ // guarantee the threads can be terminated in any given amount of time.
+ mExecutor.shutdownNow();
+ if (mDb != null) mDb.close();
}
/**
@@ -61,7 +132,7 @@
public void storeNetworkAttributes(@NonNull final String l2Key,
@NonNull final NetworkAttributesParcelable attributes,
@Nullable final IOnStatusListener listener) {
- // TODO : implement this
+ // TODO : implement this.
}
/**
@@ -79,7 +150,7 @@
public void storeBlob(@NonNull final String l2Key, @NonNull final String clientId,
@NonNull final String name, @NonNull final Blob data,
@Nullable final IOnStatusListener listener) {
- // TODO : implement this
+ // TODO : implement this.
}
/**
@@ -99,7 +170,7 @@
@Override
public void findL2Key(@NonNull final NetworkAttributesParcelable attributes,
@NonNull final IOnL2KeyResponseListener listener) {
- // TODO : implement this
+ // TODO : implement this.
}
/**
@@ -114,7 +185,7 @@
@Override
public void isSameNetwork(@NonNull final String l2Key1, @NonNull final String l2Key2,
@NonNull final IOnSameNetworkResponseListener listener) {
- // TODO : implement this
+ // TODO : implement this.
}
/**
diff --git a/services/ipmemorystore/java/com/android/server/net/ipmemorystore/RelevanceUtils.java b/services/ipmemorystore/java/com/android/server/net/ipmemorystore/RelevanceUtils.java
new file mode 100644
index 0000000..aa45400
--- /dev/null
+++ b/services/ipmemorystore/java/com/android/server/net/ipmemorystore/RelevanceUtils.java
@@ -0,0 +1,307 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.net.ipmemorystore;
+
+import com.android.internal.annotations.VisibleForTesting;
+
+/**
+ * A class containing the logic around the relevance value for
+ * IP Memory Store.
+ *
+ * @hide
+ */
+public class RelevanceUtils {
+ /**
+ * The relevance is a decaying value that gets lower and lower until it
+ * reaches 0 after some time passes. It follows an exponential decay law,
+ * dropping slowly at first then faster and faster, because a network is
+ * likely to be visited again if it was visited not long ago, and the longer
+ * it hasn't been visited the more likely it is that it won't be visited
+ * again. For example, a network visited on holiday should stay fresh for
+ * the duration of the holiday and persist for a while, but after the venue
+ * hasn't been visited for a while it should quickly be discarded. What
+ * should accelerate forgetting the network is extended periods without
+ * visits, so that occasional venues get discarded but regular visits keep
+ * the network relevant, even if the visits are infrequent.
+ *
+ * This function must be stable by iteration, meaning that adjusting the same value
+ * for different dates iteratively multiple times should give the same result.
+ * Formally, if f is the decay function that associates a relevance x at a date d1
+ * to the value at ulterior date d3, then for any date d2 between d1 and d3 :
+ * f(x, d3 - d1) = f(f(x, d3 - d2), d2 - d1). Intuitively, this property simply
+ * means it should be the same to compute and store back the value after two months,
+ * or to do it once after one month, store it back, and do it again after another
+ * months has passed.
+ * The pair of the relevance and date define the entire curve, so any pair
+ * of values on the curve will define the same curve. Setting one of them to a
+ * constant, so as not to have to store it, means the other one will always suffice
+ * to describe the curve. For example, only storing the date for a known, constant
+ * value of the relevance is an efficient way of remembering this information (and
+ * to compare relevances together, as f is monotonically decreasing).
+ *
+ *** Choosing the function :
+ * Functions of the kind described above are standard exponential decay functions
+ * like the ones that govern atomic decay where the value at any given date can be
+ * computed uniformly from the value at a previous date and the time elapsed since
+ * that date. It is simple to picture this kind of function as one where after a
+ * given period of time called the half-life, the relevance value will have been
+ * halved. Decay of this kind is expressed in function of the previous value by
+ * functions like
+ * f(x, t) = x * F ^ (t / L)
+ * ...where x is the value, t is the elapsed time, L is the half-life (or more
+ * generally the F-th-life) and F the decay factor (typically 0.5, hence why L is
+ * usually called the half-life). The ^ symbol here is used for exponentiation.
+ * Or, starting at a given M for t = 0 :
+ * f(t) = M * F ^ (t / L)
+ *
+ * Because a line in the store needs to become irrelevant at some point but
+ * this class of functions never go to 0, a minimum cutoff has to be chosen to
+ * represent irrelevance. The simpler way of doing this is to simply add this
+ * minimum cutoff to the computation before and removing it after.
+ * Thus the function becomes :
+ * f(x, t) = ((x + K) * F ^ (t / L)) - K
+ * ...where K is the minimum cutoff, L the half-life, and F the factor between
+ * the original x and x after its half-life. Strictly speaking using the word
+ * "half-life" implies that F = 0.5, but the relation works for any value of F.
+ *
+ * It is easy enough to check that this function satisfies the stability
+ * relation that was given above for any value of F, L and K, which become
+ * parameters that can be defined at will.
+ *
+ * relevance
+ * 1.0 |
+ * |\
+ * | \
+ * | \ (this graph rendered with L = 75 days and K = 1/40)
+ * 0.75| ',
+ * | \
+ * | '.
+ * | \.
+ * | \
+ * 0.5 | '\
+ * | ''.
+ * | ''.
+ * | ''.
+ * 0.25| '''..
+ * | '''..
+ * | ''''....
+ * | '''''..........
+ * 0 +-------------------------------------------------------''''''''''----
+ * 0 50 100 150 200 250 300 350 400 days
+ *
+ *** Choosing the parameters
+ * The maximum M is an arbitrary parameter that simply scales the curve.
+ * The tradeoff for M is pretty simple : if the relevance is going to be an
+ * integer, the bigger M is the more precision there is in the relevance.
+ * However, values of M that are easy for humans to read are preferable to
+ * help debugging, and a suitably low value may be enough to ensure there
+ * won't be integer overflows in intermediate computations.
+ * A value of 1_000_000 probably is plenty for precision, while still in the
+ * low range of what ints can represent.
+ *
+ * F and L are parameters to be chosen arbitrarily and have an impact on how
+ * fast the relevance will be decaying at first, keeping in mind that
+ * the 400 days value and the cap stay the same. In simpler words, F and L
+ * define the steepness of the curve.
+ * To keep things simple (and familiar) F is arbitrarily chosen to be 0.5, and
+ * L is set to 200 days visually to achieve the desired effect. Refer to the
+ * illustration above to get a feel of how that feels.
+ *
+ * Moreover, the memory store works on an assumption that the relevance should
+ * be capped, and that an entry with capped relevance should decay in 400 days.
+ * This is on premises that the networks a device will need to remember the
+ * longest should be networks visited about once a year.
+ * For this reason, the relevance is at the maximum M 400 days before expiry :
+ * f(M, 400 days) = 0
+ * From replacing this with the value of the function, K can then be derived
+ * from the values of M, F and L :
+ * (M + K) * F ^ (t / L) - K = 0
+ * K = M * F ^ (400 days / L) / (1 - F ^ (400 days / L))
+ * Replacing with actual values this gives :
+ * K = 1_000_000 * 0.5 ^ (400 / 200) / (1 - 0.5 ^ (400 / 200))
+ * = 1_000_000 / 3 ≈ 333_333.3
+ * This ensures the function has the desired profile, the desired value at
+ * cap, and the desired value at expiry.
+ *
+ *** Useful relations
+ * Let's define the expiry time for any given relevance x as the interval of
+ * time such as :
+ * f(x, expiry) = 0
+ * which can be rewritten
+ * ((x + K) * F ^ (expiry / L)) = K
+ * ...giving an expression of the expiry in function of the relevance x as
+ * expiry = L * logF(K / (x + K))
+ * Conversely the relevance x can be expressed in function of the expiry as
+ * x = K / F ^ (expiry / L) - K
+ * These relations are useful in utility functions.
+ *
+ *** Bumping things up
+ * The last issue therefore is to decide how to bump up the relevance. The
+ * simple approach is to simply lift up the curve a little bit by a constant
+ * normalized amount, delaying the time of expiry. For example increasing
+ * the relevance by an amount I gives :
+ * x2 = x1 + I
+ * x2 and x1 correspond to two different expiry times expiry2 and expiry1,
+ * and replacing x1 and x2 in the relation above with their expression in
+ * function of the expiry comes :
+ * K / F ^ (expiry2 / L) - K = K / F ^ (expiry1 / L) - K + I
+ * which resolves to :
+ * expiry2 = L * logF(K / (I + K / F ^ (expiry1 / L)))
+ *
+ * In this implementation, the bump is defined as 1/25th of the cap for
+ * the relevance. This means a network will be remembered for the maximum
+ * period of 400 days if connected 25 times in succession not accounting
+ * for decay. Of course decay actually happens so it will take more than 25
+ * connections for any given network to actually reach the cap, but because
+ * decay is slow at first, it is a good estimate of how fast cap happens.
+ *
+ * Specifically, it gives the following four results :
+ * - A network that a device connects to once hits irrelevance about 32.7 days after
+ * it was first registered if never connected again.
+ * - A network that a device connects to once a day at a fixed hour will hit the cap
+ * on the 27th connection.
+ * - A network that a device connects to once a week at a fixed hour will hit the cap
+ * on the 57th connection.
+ * - A network that a device connects to every day for 7 straight days then never again
+ * expires 144 days after the last connection.
+ * These metrics tend to match pretty well the requirements.
+ */
+
+ // TODO : make these constants configurable at runtime. Don't forget to build it so that
+ // changes will wipe the database, migrate the values, or otherwise make sure the relevance
+ // values are still meaningful.
+
+ // How long, in milliseconds, is a capped relevance valid for, or in other
+ // words how many milliseconds after its relevance was set to RELEVANCE_CAP does
+ // any given line expire. 400 days.
+ @VisibleForTesting
+ public static final long CAPPED_RELEVANCE_LIFETIME_MS = 400L * 24 * 60 * 60 * 1000;
+
+ // The constant that represents a normalized 1.0 value for the relevance. In other words,
+ // the cap for the relevance. This is referred to as M in the explanation above.
+ @VisibleForTesting
+ public static final int CAPPED_RELEVANCE = 1_000_000;
+
+ // The decay factor. After a half-life, the relevance will have decayed by this value.
+ // This is referred to as F in the explanation above.
+ private static final double DECAY_FACTOR = 0.5;
+
+ // The half-life. After this time, the relevance will have decayed by a factor DECAY_FACTOR.
+ // This is referred to as L in the explanation above.
+ private static final long HALF_LIFE_MS = 200L * 24 * 60 * 60 * 1000;
+
+ // The value of the frame change. This is referred to as K in the explanation above.
+ private static final double IRRELEVANCE_FLOOR =
+ CAPPED_RELEVANCE * powF((double) CAPPED_RELEVANCE_LIFETIME_MS / HALF_LIFE_MS)
+ / (1 - powF((double) CAPPED_RELEVANCE_LIFETIME_MS / HALF_LIFE_MS));
+
+ // How much to bump the relevance by every time a line is written to.
+ @VisibleForTesting
+ public static final int RELEVANCE_BUMP = CAPPED_RELEVANCE / 25;
+
+ // Java doesn't include a function for the logarithm in an arbitrary base, so implement it
+ private static final double LOG_DECAY_FACTOR = Math.log(DECAY_FACTOR);
+ private static double logF(final double value) {
+ return Math.log(value) / LOG_DECAY_FACTOR;
+ }
+
+ // Utility function to get a power of the decay factor, to simplify the code.
+ private static double powF(final double value) {
+ return Math.pow(DECAY_FACTOR, value);
+ }
+
+ /**
+ * Compute the value of the relevance now given an expiry date.
+ *
+ * @param expiry the date at which the column in the database expires.
+ * @return the adjusted value of the relevance for this moment in time.
+ */
+ public static int computeRelevanceForNow(final long expiry) {
+ return computeRelevanceForTargetDate(expiry, System.currentTimeMillis());
+ }
+
+ /**
+ * Compute the value of the relevance at a given date from an expiry date.
+ *
+ * Because relevance decays with time, a relevance in the past corresponds to
+ * a different relevance later.
+ *
+ * Relevance is always a positive value. 0 means not relevant at all.
+ *
+ * See the explanation at the top of this file to get the justification for this
+ * computation.
+ *
+ * @param expiry the date at which the column in the database expires.
+ * @param target the target date to adjust the relevance to.
+ * @return the adjusted value of the relevance for the target moment.
+ */
+ public static int computeRelevanceForTargetDate(final long expiry, final long target) {
+ final long delay = expiry - target;
+ if (delay >= CAPPED_RELEVANCE_LIFETIME_MS) return CAPPED_RELEVANCE;
+ if (delay <= 0) return 0;
+ return (int) (IRRELEVANCE_FLOOR / powF((float) delay / HALF_LIFE_MS) - IRRELEVANCE_FLOOR);
+ }
+
+ /**
+ * Compute the expiry duration adjusted up for a new fresh write.
+ *
+ * Every time data is written to the memory store for a given line, the
+ * relevance is bumped up by a certain amount, which will boost the priority
+ * of this line for computation of group attributes, and delay (possibly
+ * indefinitely, if the line is accessed regularly) forgetting the data stored
+ * in that line.
+ * As opposed to bumpExpiryDate, this function uses a duration from now to expiry.
+ *
+ * See the explanation at the top of this file for a justification of this computation.
+ *
+ * @param oldExpiryDuration the old expiry duration in milliseconds from now.
+ * @return the expiry duration representing a bumped up relevance value.
+ */
+ public static long bumpExpiryDuration(final long oldExpiryDuration) {
+ // L * logF(K / (I + K / F ^ (expiry1 / L))), as documented above
+ final double divisionFactor = powF(((double) oldExpiryDuration) / HALF_LIFE_MS);
+ final double oldRelevance = IRRELEVANCE_FLOOR / divisionFactor;
+ final long newDuration =
+ (long) (HALF_LIFE_MS * logF(IRRELEVANCE_FLOOR / (RELEVANCE_BUMP + oldRelevance)));
+ return Math.min(newDuration, CAPPED_RELEVANCE_LIFETIME_MS);
+ }
+
+ /**
+ * Compute the new expiry date adjusted up for a new fresh write.
+ *
+ * Every time data is written to the memory store for a given line, the
+ * relevance is bumped up by a certain amount, which will boost the priority
+ * of this line for computation of group attributes, and delay (possibly
+ * indefinitely, if the line is accessed regularly) forgetting the data stored
+ * in that line.
+ * As opposed to bumpExpiryDuration, this function takes the old timestamp and returns the
+ * new timestamp.
+ *
+ * {@see bumpExpiryDuration}, and keep in mind that the bump depends on when this is called,
+ * because the relevance decays exponentially, therefore bumping up a high relevance (for a
+ * date far in the future) is less potent than bumping up a low relevance (for a date in
+ * a close future).
+ *
+ * @param oldExpiryDate the old date of expiration.
+ * @return the new expiration date after the relevance bump.
+ */
+ public static long bumpExpiryDate(final long oldExpiryDate) {
+ final long now = System.currentTimeMillis();
+ final long newDuration = bumpExpiryDuration(oldExpiryDate - now);
+ return now + newDuration;
+ }
+}
diff --git a/services/tests/mockingservicestests/src/com/android/server/AppStateTrackerTest.java b/services/tests/mockingservicestests/src/com/android/server/AppStateTrackerTest.java
index c8e6782..4a48468 100644
--- a/services/tests/mockingservicestests/src/com/android/server/AppStateTrackerTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/AppStateTrackerTest.java
@@ -85,6 +85,7 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
+import androidx.test.filters.FlakyTest;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
@@ -793,6 +794,7 @@
}
@Test
+ @FlakyTest(bugId = 114098433)
public void testAllListeners() throws Exception {
final AppStateTrackerTestable instance = newInstance();
callStart(instance);
diff --git a/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java b/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java
index f1cd0cd..57ee6dc 100644
--- a/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java
@@ -33,6 +33,7 @@
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
@@ -43,7 +44,12 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import android.app.ActivityManager;
+import android.app.ActivityManagerInternal;
import android.app.AlarmManager;
+import android.app.AppGlobals;
+import android.app.IActivityManager;
+import android.app.IUidObserver;
import android.app.job.JobInfo;
import android.app.usage.UsageStatsManager;
import android.app.usage.UsageStatsManagerInternal;
@@ -56,13 +62,16 @@
import android.os.BatteryManagerInternal;
import android.os.Handler;
import android.os.Looper;
+import android.os.RemoteException;
import android.os.SystemClock;
+import android.util.SparseBooleanArray;
import androidx.test.runner.AndroidJUnit4;
import com.android.server.LocalServices;
import com.android.server.job.JobSchedulerService;
import com.android.server.job.JobSchedulerService.Constants;
+import com.android.server.job.JobStore;
import com.android.server.job.controllers.QuotaController.ExecutionStats;
import com.android.server.job.controllers.QuotaController.TimingSession;
@@ -96,9 +105,13 @@
private BroadcastReceiver mChargingReceiver;
private Constants mConstants;
private QuotaController mQuotaController;
+ private int mSourceUid;
+ private IUidObserver mUidObserver;
private MockitoSession mMockingSession;
@Mock
+ private ActivityManagerInternal mActivityMangerInternal;
+ @Mock
private AlarmManager mAlarmManager;
@Mock
private Context mContext;
@@ -107,6 +120,8 @@
@Mock
private UsageStatsManagerInternal mUsageStatsManager;
+ private JobStore mJobStore;
+
@Before
public void setUp() {
mMockingSession = mockitoSession()
@@ -123,8 +138,17 @@
when(mJobSchedulerService.getLock()).thenReturn(mJobSchedulerService);
when(mJobSchedulerService.getConstants()).thenReturn(mConstants);
// Called in QuotaController constructor.
+ IActivityManager activityManager = ActivityManager.getService();
+ spyOn(activityManager);
+ try {
+ doNothing().when(activityManager).registerUidObserver(any(), anyInt(), anyInt(), any());
+ } catch (RemoteException e) {
+ fail("registerUidObserver threw exception: " + e.getMessage());
+ }
when(mContext.getMainLooper()).thenReturn(Looper.getMainLooper());
when(mContext.getSystemService(Context.ALARM_SERVICE)).thenReturn(mAlarmManager);
+ doReturn(mActivityMangerInternal)
+ .when(() -> LocalServices.getService(ActivityManagerInternal.class));
doReturn(mock(BatteryManagerInternal.class))
.when(() -> LocalServices.getService(BatteryManagerInternal.class));
doReturn(mUsageStatsManager)
@@ -132,6 +156,9 @@
// Used in JobStatus.
doReturn(mock(PackageManagerInternal.class))
.when(() -> LocalServices.getService(PackageManagerInternal.class));
+ // Used in QuotaController.Handler.
+ mJobStore = JobStore.initAndGetForTesting(mContext, mContext.getFilesDir());
+ when(mJobSchedulerService.getJobStore()).thenReturn(mJobStore);
// Freeze the clocks at 24 hours after this moment in time. Several tests create sessions
// in the past, and QuotaController sometimes floors values at 0, so if the test time
@@ -150,10 +177,23 @@
// Capture the listeners.
ArgumentCaptor<BroadcastReceiver> receiverCaptor =
ArgumentCaptor.forClass(BroadcastReceiver.class);
+ ArgumentCaptor<IUidObserver> uidObserverCaptor =
+ ArgumentCaptor.forClass(IUidObserver.class);
mQuotaController = new QuotaController(mJobSchedulerService);
verify(mContext).registerReceiver(receiverCaptor.capture(), any());
mChargingReceiver = receiverCaptor.getValue();
+ try {
+ verify(activityManager).registerUidObserver(
+ uidObserverCaptor.capture(),
+ eq(ActivityManager.UID_OBSERVER_PROCSTATE),
+ eq(ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE),
+ any());
+ mUidObserver = uidObserverCaptor.getValue();
+ mSourceUid = AppGlobals.getPackageManager().getPackageUid(SOURCE_PACKAGE, 0, 0);
+ } catch (RemoteException e) {
+ fail(e.getMessage());
+ }
}
@After
@@ -182,6 +222,25 @@
mChargingReceiver.onReceive(mContext, intent);
}
+ private void setProcessState(int procState) {
+ try {
+ doReturn(procState).when(mActivityMangerInternal).getUidProcessState(mSourceUid);
+ SparseBooleanArray foregroundUids = mQuotaController.getForegroundUids();
+ spyOn(foregroundUids);
+ mUidObserver.onUidStateChanged(mSourceUid, procState, 0);
+ if (procState <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) {
+ verify(foregroundUids, timeout(SECOND_IN_MILLIS).times(1))
+ .put(eq(mSourceUid), eq(true));
+ assertTrue(foregroundUids.get(mSourceUid));
+ } else {
+ verify(foregroundUids, timeout(SECOND_IN_MILLIS).times(1)).delete(eq(mSourceUid));
+ assertFalse(foregroundUids.get(mSourceUid));
+ }
+ } catch (RemoteException e) {
+ fail("registerUidObserver threw exception: " + e.getMessage());
+ }
+ }
+
private void setStandbyBucket(int bucketIndex) {
int bucket;
switch (bucketIndex) {
@@ -204,9 +263,18 @@
anyLong())).thenReturn(bucket);
}
- private void setStandbyBucket(int bucketIndex, JobStatus job) {
+ private void setStandbyBucket(int bucketIndex, JobStatus... jobs) {
setStandbyBucket(bucketIndex);
- job.setStandbyBucket(bucketIndex);
+ for (JobStatus job : jobs) {
+ job.setStandbyBucket(bucketIndex);
+ }
+ }
+
+ private void trackJobs(JobStatus... jobs) {
+ for (JobStatus job : jobs) {
+ mJobStore.add(job);
+ mQuotaController.maybeStartTrackingJobLocked(job, null);
+ }
}
private JobStatus createJobStatus(String testTag, int jobId) {
@@ -214,8 +282,11 @@
new ComponentName(mContext, "TestQuotaJobService"))
.setMinimumLatency(Math.abs(jobId) + 1)
.build();
- return JobStatus.createFromJobInfo(
+ JobStatus js = JobStatus.createFromJobInfo(
jobInfo, CALLING_UID, SOURCE_PACKAGE, SOURCE_USER_ID, testTag);
+ // Make sure tests aren't passing just because the default bucket is likely ACTIVE.
+ js.setStandbyBucket(FREQUENT_INDEX);
+ return js;
}
private TimingSession createTimingSession(long start, long duration, int count) {
@@ -709,6 +780,7 @@
verify(mAlarmManager, never()).set(anyInt(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any());
JobStatus jobStatus = createJobStatus("testMaybeScheduleStartAlarmLocked_Active", 1);
+ setStandbyBucket(standbyBucket, jobStatus);
mQuotaController.maybeStartTrackingJobLocked(jobStatus, null);
mQuotaController.prepareForExecutionLocked(jobStatus);
advanceElapsedClock(5 * MINUTE_IN_MILLIS);
@@ -1339,19 +1411,23 @@
setDischarging();
JobStatus jobStatus = createJobStatus("testTimerTracking_AllForeground", 1);
- jobStatus.uidActive = true;
+ setProcessState(ActivityManager.PROCESS_STATE_TOP);
mQuotaController.maybeStartTrackingJobLocked(jobStatus, null);
assertNull(mQuotaController.getTimingSessions(SOURCE_USER_ID, SOURCE_PACKAGE));
mQuotaController.prepareForExecutionLocked(jobStatus);
advanceElapsedClock(5 * SECOND_IN_MILLIS);
+ // Change to a state that should still be considered foreground.
+ setProcessState(ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE);
+ advanceElapsedClock(5 * SECOND_IN_MILLIS);
mQuotaController.maybeStopTrackingJobLocked(jobStatus, null, false);
assertNull(mQuotaController.getTimingSessions(SOURCE_USER_ID, SOURCE_PACKAGE));
}
/**
- * Tests that Timers properly track overlapping foreground and background jobs.
+ * Tests that Timers properly track sessions when switching between foreground and background
+ * states.
*/
@Test
public void testTimerTracking_ForegroundAndBackground() {
@@ -1360,7 +1436,6 @@
JobStatus jobBg1 = createJobStatus("testTimerTracking_ForegroundAndBackground", 1);
JobStatus jobBg2 = createJobStatus("testTimerTracking_ForegroundAndBackground", 2);
JobStatus jobFg3 = createJobStatus("testTimerTracking_ForegroundAndBackground", 3);
- jobFg3.uidActive = true;
mQuotaController.maybeStartTrackingJobLocked(jobBg1, null);
mQuotaController.maybeStartTrackingJobLocked(jobBg2, null);
mQuotaController.maybeStartTrackingJobLocked(jobFg3, null);
@@ -1368,6 +1443,7 @@
List<TimingSession> expected = new ArrayList<>();
// UID starts out inactive.
+ setProcessState(ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND);
long start = JobSchedulerService.sElapsedRealtimeClock.millis();
mQuotaController.prepareForExecutionLocked(jobBg1);
advanceElapsedClock(10 * SECOND_IN_MILLIS);
@@ -1379,48 +1455,223 @@
// Bg job starts while inactive, spans an entire active session, and ends after the
// active session.
- // Fg job starts after the bg job and ends before the bg job.
- // Entire bg job duration should be counted since it started before active session. However,
- // count should only be 1 since Timer shouldn't count fg jobs.
+ // App switching to foreground state then fg job starts.
+ // App remains in foreground state after coming to foreground, so there should only be one
+ // session.
start = JobSchedulerService.sElapsedRealtimeClock.millis();
mQuotaController.maybeStartTrackingJobLocked(jobBg2, null);
mQuotaController.prepareForExecutionLocked(jobBg2);
advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ expected.add(createTimingSession(start, 10 * SECOND_IN_MILLIS, 1));
+ setProcessState(ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE);
mQuotaController.prepareForExecutionLocked(jobFg3);
advanceElapsedClock(10 * SECOND_IN_MILLIS);
mQuotaController.maybeStopTrackingJobLocked(jobFg3, null, false);
advanceElapsedClock(10 * SECOND_IN_MILLIS);
mQuotaController.maybeStopTrackingJobLocked(jobBg2, null, false);
- expected.add(createTimingSession(start, 30 * SECOND_IN_MILLIS, 1));
assertEquals(expected, mQuotaController.getTimingSessions(SOURCE_USER_ID, SOURCE_PACKAGE));
advanceElapsedClock(SECOND_IN_MILLIS);
// Bg job 1 starts, then fg job starts. Bg job 1 job ends. Shortly after, uid goes
// "inactive" and then bg job 2 starts. Then fg job ends.
- // This should result in two TimingSessions with a count of one each.
+ // This should result in two TimingSessions:
+ // * The first should have a count of 1
+ // * The second should have a count of 2 since it will include both jobs
start = JobSchedulerService.sElapsedRealtimeClock.millis();
mQuotaController.maybeStartTrackingJobLocked(jobBg1, null);
mQuotaController.maybeStartTrackingJobLocked(jobBg2, null);
mQuotaController.maybeStartTrackingJobLocked(jobFg3, null);
+ setProcessState(ActivityManager.PROCESS_STATE_LAST_ACTIVITY);
mQuotaController.prepareForExecutionLocked(jobBg1);
advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ expected.add(createTimingSession(start, 10 * SECOND_IN_MILLIS, 1));
+ setProcessState(ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE);
mQuotaController.prepareForExecutionLocked(jobFg3);
advanceElapsedClock(10 * SECOND_IN_MILLIS);
mQuotaController.maybeStopTrackingJobLocked(jobBg1, jobBg1, true);
- expected.add(createTimingSession(start, 20 * SECOND_IN_MILLIS, 1));
advanceElapsedClock(10 * SECOND_IN_MILLIS); // UID "inactive" now
start = JobSchedulerService.sElapsedRealtimeClock.millis();
+ setProcessState(ActivityManager.PROCESS_STATE_TOP_SLEEPING);
mQuotaController.prepareForExecutionLocked(jobBg2);
advanceElapsedClock(10 * SECOND_IN_MILLIS);
mQuotaController.maybeStopTrackingJobLocked(jobFg3, null, false);
advanceElapsedClock(10 * SECOND_IN_MILLIS);
mQuotaController.maybeStopTrackingJobLocked(jobBg2, null, false);
- expected.add(createTimingSession(start, 20 * SECOND_IN_MILLIS, 1));
+ expected.add(createTimingSession(start, 20 * SECOND_IN_MILLIS, 2));
assertEquals(expected, mQuotaController.getTimingSessions(SOURCE_USER_ID, SOURCE_PACKAGE));
}
/**
+ * Tests that Timers properly track overlapping top and background jobs.
+ */
+ @Test
+ public void testTimerTracking_TopAndNonTop() {
+ setDischarging();
+
+ JobStatus jobBg1 = createJobStatus("testTimerTracking_TopAndNonTop", 1);
+ JobStatus jobBg2 = createJobStatus("testTimerTracking_TopAndNonTop", 2);
+ JobStatus jobFg1 = createJobStatus("testTimerTracking_TopAndNonTop", 3);
+ JobStatus jobTop = createJobStatus("testTimerTracking_TopAndNonTop", 4);
+ mQuotaController.maybeStartTrackingJobLocked(jobBg1, null);
+ mQuotaController.maybeStartTrackingJobLocked(jobBg2, null);
+ mQuotaController.maybeStartTrackingJobLocked(jobFg1, null);
+ mQuotaController.maybeStartTrackingJobLocked(jobTop, null);
+ assertNull(mQuotaController.getTimingSessions(SOURCE_USER_ID, SOURCE_PACKAGE));
+ List<TimingSession> expected = new ArrayList<>();
+
+ // UID starts out inactive.
+ setProcessState(ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND);
+ long start = JobSchedulerService.sElapsedRealtimeClock.millis();
+ mQuotaController.prepareForExecutionLocked(jobBg1);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ mQuotaController.maybeStopTrackingJobLocked(jobBg1, jobBg1, true);
+ expected.add(createTimingSession(start, 10 * SECOND_IN_MILLIS, 1));
+ assertEquals(expected, mQuotaController.getTimingSessions(SOURCE_USER_ID, SOURCE_PACKAGE));
+
+ advanceElapsedClock(SECOND_IN_MILLIS);
+
+ // Bg job starts while inactive, spans an entire active session, and ends after the
+ // active session.
+ // App switching to top state then fg job starts.
+ // App remains in top state after coming to top, so there should only be one
+ // session.
+ start = JobSchedulerService.sElapsedRealtimeClock.millis();
+ mQuotaController.maybeStartTrackingJobLocked(jobBg2, null);
+ mQuotaController.prepareForExecutionLocked(jobBg2);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ expected.add(createTimingSession(start, 10 * SECOND_IN_MILLIS, 1));
+ setProcessState(ActivityManager.PROCESS_STATE_TOP);
+ mQuotaController.prepareForExecutionLocked(jobTop);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ mQuotaController.maybeStopTrackingJobLocked(jobTop, null, false);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ mQuotaController.maybeStopTrackingJobLocked(jobBg2, null, false);
+ assertEquals(expected, mQuotaController.getTimingSessions(SOURCE_USER_ID, SOURCE_PACKAGE));
+
+ advanceElapsedClock(SECOND_IN_MILLIS);
+
+ // Bg job 1 starts, then top job starts. Bg job 1 job ends. Then app goes to
+ // foreground_service and a new job starts. Shortly after, uid goes
+ // "inactive" and then bg job 2 starts. Then top job ends, followed by bg and fg jobs.
+ // This should result in two TimingSessions:
+ // * The first should have a count of 1
+ // * The second should have a count of 2, which accounts for the bg2 and fg, but not top
+ // jobs.
+ start = JobSchedulerService.sElapsedRealtimeClock.millis();
+ mQuotaController.maybeStartTrackingJobLocked(jobBg1, null);
+ mQuotaController.maybeStartTrackingJobLocked(jobBg2, null);
+ mQuotaController.maybeStartTrackingJobLocked(jobTop, null);
+ setProcessState(ActivityManager.PROCESS_STATE_LAST_ACTIVITY);
+ mQuotaController.prepareForExecutionLocked(jobBg1);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ expected.add(createTimingSession(start, 10 * SECOND_IN_MILLIS, 1));
+ setProcessState(ActivityManager.PROCESS_STATE_TOP);
+ mQuotaController.prepareForExecutionLocked(jobTop);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ mQuotaController.maybeStopTrackingJobLocked(jobBg1, jobBg1, true);
+ advanceElapsedClock(5 * SECOND_IN_MILLIS);
+ setProcessState(ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE);
+ mQuotaController.prepareForExecutionLocked(jobFg1);
+ advanceElapsedClock(5 * SECOND_IN_MILLIS);
+ setProcessState(ActivityManager.PROCESS_STATE_TOP);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS); // UID "inactive" now
+ start = JobSchedulerService.sElapsedRealtimeClock.millis();
+ setProcessState(ActivityManager.PROCESS_STATE_TOP_SLEEPING);
+ mQuotaController.prepareForExecutionLocked(jobBg2);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ mQuotaController.maybeStopTrackingJobLocked(jobTop, null, false);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ mQuotaController.maybeStopTrackingJobLocked(jobBg2, null, false);
+ mQuotaController.maybeStopTrackingJobLocked(jobFg1, null, false);
+ expected.add(createTimingSession(start, 20 * SECOND_IN_MILLIS, 2));
+ assertEquals(expected, mQuotaController.getTimingSessions(SOURCE_USER_ID, SOURCE_PACKAGE));
+ }
+
+ /**
+ * Tests that TOP jobs aren't stopped when an app runs out of quota.
+ */
+ @Test
+ public void testTracking_OutOfQuota_ForegroundAndBackground() {
+ setDischarging();
+
+ JobStatus jobBg = createJobStatus("testTracking_OutOfQuota_ForegroundAndBackground", 1);
+ JobStatus jobTop = createJobStatus("testTracking_OutOfQuota_ForegroundAndBackground", 2);
+ trackJobs(jobBg, jobTop);
+ setStandbyBucket(WORKING_INDEX, jobTop, jobBg); // 2 hour window
+ // Now the package only has 20 seconds to run.
+ final long remainingTimeMs = 20 * SECOND_IN_MILLIS;
+ mQuotaController.saveTimingSession(SOURCE_USER_ID, SOURCE_PACKAGE,
+ createTimingSession(
+ JobSchedulerService.sElapsedRealtimeClock.millis() - HOUR_IN_MILLIS,
+ 10 * MINUTE_IN_MILLIS - remainingTimeMs, 1));
+
+ InOrder inOrder = inOrder(mJobSchedulerService);
+
+ // UID starts out inactive.
+ setProcessState(ActivityManager.PROCESS_STATE_SERVICE);
+ // Start the job.
+ mQuotaController.prepareForExecutionLocked(jobBg);
+ advanceElapsedClock(remainingTimeMs / 2);
+ // New job starts after UID is in the foreground. Since the app is now in the foreground, it
+ // should continue to have remainingTimeMs / 2 time remaining.
+ setProcessState(ActivityManager.PROCESS_STATE_TOP);
+ mQuotaController.prepareForExecutionLocked(jobTop);
+ advanceElapsedClock(remainingTimeMs);
+
+ // Wait for some extra time to allow for job processing.
+ inOrder.verify(mJobSchedulerService,
+ timeout(remainingTimeMs + 2 * SECOND_IN_MILLIS).times(0))
+ .onControllerStateChanged();
+ assertEquals(remainingTimeMs / 2, mQuotaController.getRemainingExecutionTimeLocked(jobBg));
+ assertEquals(remainingTimeMs / 2, mQuotaController.getRemainingExecutionTimeLocked(jobTop));
+ // Go to a background state.
+ setProcessState(ActivityManager.PROCESS_STATE_TOP_SLEEPING);
+ advanceElapsedClock(remainingTimeMs / 2 + 1);
+ inOrder.verify(mJobSchedulerService,
+ timeout(remainingTimeMs / 2 + 2 * SECOND_IN_MILLIS).times(1))
+ .onControllerStateChanged();
+ // Top job should still be allowed to run.
+ assertFalse(jobBg.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+ assertTrue(jobTop.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+
+ // New jobs to run.
+ JobStatus jobBg2 = createJobStatus("testTracking_OutOfQuota_ForegroundAndBackground", 3);
+ JobStatus jobTop2 = createJobStatus("testTracking_OutOfQuota_ForegroundAndBackground", 4);
+ JobStatus jobFg = createJobStatus("testTracking_OutOfQuota_ForegroundAndBackground", 5);
+ setStandbyBucket(WORKING_INDEX, jobBg2, jobTop2, jobFg);
+
+ advanceElapsedClock(20 * SECOND_IN_MILLIS);
+ setProcessState(ActivityManager.PROCESS_STATE_TOP);
+ inOrder.verify(mJobSchedulerService, timeout(SECOND_IN_MILLIS).times(1))
+ .onControllerStateChanged();
+ trackJobs(jobFg, jobTop);
+ mQuotaController.prepareForExecutionLocked(jobTop);
+ assertTrue(jobTop.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+ assertTrue(jobFg.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+ assertTrue(jobBg.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+
+ // App still in foreground so everything should be in quota.
+ advanceElapsedClock(20 * SECOND_IN_MILLIS);
+ setProcessState(ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE);
+ assertTrue(jobTop.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+ assertTrue(jobFg.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+ assertTrue(jobBg.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+
+ advanceElapsedClock(20 * SECOND_IN_MILLIS);
+ setProcessState(ActivityManager.PROCESS_STATE_SERVICE);
+ inOrder.verify(mJobSchedulerService, timeout(SECOND_IN_MILLIS).times(1))
+ .onControllerStateChanged();
+ // App is now in background and out of quota. Fg should now change to out of quota since it
+ // wasn't started. Top should remain in quota since it started when the app was in TOP.
+ assertTrue(jobTop.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+ assertFalse(jobFg.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+ assertFalse(jobBg.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+ trackJobs(jobBg2);
+ assertFalse(jobBg2.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+ }
+
+ /**
* Tests that a job is properly updated and JobSchedulerService is notified when a job reaches
* its quota.
*/
diff --git a/services/tests/servicestests/src/com/android/server/pm/dex/DexLoggerTests.java b/services/tests/servicestests/src/com/android/server/pm/dex/DexLoggerTests.java
index 3b6b48b..f817e8e 100644
--- a/services/tests/servicestests/src/com/android/server/pm/dex/DexLoggerTests.java
+++ b/services/tests/servicestests/src/com/android/server/pm/dex/DexLoggerTests.java
@@ -77,7 +77,6 @@
@Mock IPackageManager mPM;
@Mock Installer mInstaller;
- private final Object mInstallLock = new Object();
private PackageDynamicCodeLoading mPackageDynamicCodeLoading;
private DexLogger mDexLogger;
@@ -103,7 +102,7 @@
};
// For test purposes capture log messages as well as sending to the event log.
- mDexLogger = new DexLogger(mPM, mInstaller, mInstallLock, mPackageDynamicCodeLoading) {
+ mDexLogger = new DexLogger(mPM, mInstaller, mPackageDynamicCodeLoading) {
@Override
void writeDclEvent(int uid, String message) {
super.writeDclEvent(uid, message);
diff --git a/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java b/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
index 41d5691..8171469 100644
--- a/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
+++ b/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
@@ -61,6 +61,7 @@
import android.view.Display;
import androidx.test.InstrumentationRegistry;
+import androidx.test.filters.FlakyTest;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
@@ -416,6 +417,7 @@
}
@Test
+ @FlakyTest(bugId = 119774928)
public void testEnabledState() throws Exception {
TestParoleListener paroleListener = new TestParoleListener();
mController.addListener(paroleListener);
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index 83c1c76..94b21af 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -3511,9 +3511,9 @@
}
@Test
- public void testAppOverlay() throws Exception {
- mBinderService.setAppOverlaysAllowed(PKG, mUid, false);
- assertFalse(mBinderService.areAppOverlaysAllowedForPackage(PKG, mUid));
+ public void testBubble() throws Exception {
+ mBinderService.setBubblesAllowed(PKG, mUid, false);
+ assertFalse(mBinderService.areBubblesAllowedForPackage(PKG, mUid));
}
@Test
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java
index 0fcfea7..24a1f8c 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java
@@ -809,7 +809,7 @@
channel.setBypassDnd(true);
channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
channel.setShowBadge(true);
- channel.setAllowAppOverlay(false);
+ channel.setAllowBubbles(false);
int lockMask = 0;
for (int i = 0; i < NotificationChannel.LOCKABLE_FIELDS.length; i++) {
lockMask |= NotificationChannel.LOCKABLE_FIELDS[i];
@@ -826,7 +826,7 @@
assertFalse(savedChannel.canBypassDnd());
assertFalse(Notification.VISIBILITY_SECRET == savedChannel.getLockscreenVisibility());
assertEquals(channel.canShowBadge(), savedChannel.canShowBadge());
- assertEquals(channel.canOverlayApps(), savedChannel.canOverlayApps());
+ assertEquals(channel.canBubble(), savedChannel.canBubble());
verify(mHandler, never()).requestSort();
}
@@ -840,7 +840,7 @@
channel.setBypassDnd(true);
channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
channel.setShowBadge(true);
- channel.setAllowAppOverlay(false);
+ channel.setAllowBubbles(false);
int lockMask = 0;
for (int i = 0; i < NotificationChannel.LOCKABLE_FIELDS.length; i++) {
lockMask |= NotificationChannel.LOCKABLE_FIELDS[i];
@@ -857,7 +857,7 @@
assertFalse(savedChannel.canBypassDnd());
assertFalse(Notification.VISIBILITY_SECRET == savedChannel.getLockscreenVisibility());
assertEquals(channel.canShowBadge(), savedChannel.canShowBadge());
- assertEquals(channel.canOverlayApps(), savedChannel.canOverlayApps());
+ assertEquals(channel.canBubble(), savedChannel.canBubble());
}
@Test
@@ -969,16 +969,16 @@
}
@Test
- public void testLockFields_appOverlay() {
+ public void testLockFields_allowBubble() {
mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, getChannel(), true, false);
assertEquals(0,
mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, getChannel().getId(), false)
.getUserLockedFields());
final NotificationChannel update = getChannel();
- update.setAllowAppOverlay(false);
+ update.setAllowBubbles(false);
mHelper.updateNotificationChannel(PKG_N_MR1, UID_N_MR1, update, true);
- assertEquals(NotificationChannel.USER_LOCKED_ALLOW_APP_OVERLAY,
+ assertEquals(NotificationChannel.USER_LOCKED_ALLOW_BUBBLE,
mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, update.getId(), false)
.getUserLockedFields());
}
@@ -2161,30 +2161,30 @@
}
@Test
- public void testAllowAppOverlay_defaults() throws Exception {
- assertTrue(mHelper.areAppOverlaysAllowed(PKG_O, UID_O));
+ public void testAllowBubbles_defaults() throws Exception {
+ assertTrue(mHelper.areBubblessAllowed(PKG_O, UID_O));
ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false);
mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper);
loadStreamXml(baos, false);
- assertTrue(mHelper.areAppOverlaysAllowed(PKG_O, UID_O));
+ assertTrue(mHelper.areBubblessAllowed(PKG_O, UID_O));
assertEquals(0, mHelper.getAppLockedFields(PKG_O, UID_O));
}
@Test
- public void testAllowAppOverlay_xml() throws Exception {
- mHelper.setAppOverlaysAllowed(PKG_O, UID_O, false);
- assertFalse(mHelper.areAppOverlaysAllowed(PKG_O, UID_O));
- assertEquals(PreferencesHelper.LockableAppFields.USER_LOCKED_APP_OVERLAY,
+ public void testAllowBubbles_xml() throws Exception {
+ mHelper.setBubblesAllowed(PKG_O, UID_O, false);
+ assertFalse(mHelper.areBubblessAllowed(PKG_O, UID_O));
+ assertEquals(PreferencesHelper.LockableAppFields.USER_LOCKED_BUBBLE,
mHelper.getAppLockedFields(PKG_O, UID_O));
ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false);
mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper);
loadStreamXml(baos, false);
- assertFalse(mHelper.areAppOverlaysAllowed(PKG_O, UID_O));
- assertEquals(PreferencesHelper.LockableAppFields.USER_LOCKED_APP_OVERLAY,
+ assertFalse(mHelper.areBubblessAllowed(PKG_O, UID_O));
+ assertEquals(PreferencesHelper.LockableAppFields.USER_LOCKED_BUBBLE,
mHelper.getAppLockedFields(PKG_O, UID_O));
}
@@ -2290,14 +2290,14 @@
mHelper.lockChannelsForOEM(new String[] {PKG_O});
NotificationChannel update = new NotificationChannel("a", "a", IMPORTANCE_NONE);
- update.setAllowAppOverlay(false);
+ update.setAllowBubbles(false);
mHelper.updateNotificationChannel(PKG_O, UID_O, update, true);
assertEquals(IMPORTANCE_HIGH,
mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false).getImportance());
assertEquals(false,
- mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false).canOverlayApps());
+ mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false).canBubble());
mHelper.updateNotificationChannel(PKG_O, UID_O, update, true);
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java b/services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java
index fa42289..51bebbb 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AppTransitionTests.java
@@ -39,7 +39,9 @@
import androidx.test.filters.SmallTest;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
/**
@@ -52,15 +54,34 @@
@Presubmit
public class AppTransitionTests extends WindowTestsBase {
+ private static RootWindowContainer sOriginalRootWindowContainer;
+
private DisplayContent mDc;
+ @BeforeClass
+ public static void setUpRootWindowContainerMock() {
+ final WindowManagerService wm = WmServiceUtils.getWindowManagerService();
+ // For unit test, we don't need to test performSurfacePlacement to prevent some abnormal
+ // interaction with surfaceflinger native side.
+ sOriginalRootWindowContainer = wm.mRoot;
+ // Creating spied mock of RootWindowContainer shouldn't be done in @Before, since it will
+ // create unnecessary nested spied objects chain, because WindowManagerService object under
+ // test is a single instance shared among all tests that extend WindowTestsBase class.
+ // Instead it should be done once before running all tests in this test class.
+ wm.mRoot = spy(wm.mRoot);
+ doNothing().when(wm.mRoot).performSurfacePlacement(anyBoolean());
+ }
+
+ @AfterClass
+ public static void tearDownRootWindowContainerMock() {
+ final WindowManagerService wm = WmServiceUtils.getWindowManagerService();
+ wm.mRoot = sOriginalRootWindowContainer;
+ sOriginalRootWindowContainer = null;
+ }
+
@Before
public void setUp() throws Exception {
mDc = mWm.getDefaultDisplayContentLocked();
- // For unit test, we don't need to test performSurfacePlacement to prevent some
- // abnormal interaction with surfaceflinger native side.
- mWm.mRoot = spy(mWm.mRoot);
- doNothing().when(mWm.mRoot).performSurfacePlacement(anyBoolean());
}
@Test
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskRecordTests.java
index 8a98cbe..cdb578d 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskRecordTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskRecordTests.java
@@ -217,12 +217,17 @@
info.logicalHeight = fullScreenBounds.height();
ActivityDisplay display = addNewActivityDisplayAt(info, POSITION_TOP);
assertTrue(mRootActivityContainer.getActivityDisplay(display.mDisplayId) != null);
+ // Override display orientation. Normally this is available via DisplayContent, but DC
+ // is mocked-out.
+ display.getRequestedOverrideConfiguration().orientation =
+ Configuration.ORIENTATION_LANDSCAPE;
+ display.onRequestedOverrideConfigurationChanged(
+ display.getRequestedOverrideConfiguration());
ActivityStack stack = new StackBuilder(mRootActivityContainer)
.setWindowingMode(WINDOWING_MODE_FULLSCREEN).setDisplay(display).build();
TaskRecord task = stack.getChildAt(0);
- ActivityRecord root = task.getRootActivity();
- ActivityRecord top = new ActivityBuilder(mService).setTask(task).setStack(stack).build();
- assertEquals(root, task.getRootActivity());
+ ActivityRecord root = task.getTopActivity();
+ assertEquals(root, task.getTopActivity());
assertEquals(fullScreenBounds, task.getBounds());
@@ -233,16 +238,22 @@
assertTrue(task.getBounds().width() < task.getBounds().height());
assertEquals(fullScreenBounds.height(), task.getBounds().height());
- // Setting non-root app has no effect
- setActivityRequestedOrientation(root, SCREEN_ORIENTATION_LANDSCAPE);
- assertTrue(task.getBounds().width() < task.getBounds().height());
+ // Top activity gets used
+ ActivityRecord top = new ActivityBuilder(mService).setTask(task).setStack(stack).build();
+ assertEquals(top, task.getTopActivity());
+ setActivityRequestedOrientation(top, SCREEN_ORIENTATION_LANDSCAPE);
+ assertTrue(task.getBounds().width() > task.getBounds().height());
+ assertEquals(task.getBounds().width(), fullScreenBounds.width());
// Setting app to unspecified restores
- setActivityRequestedOrientation(root, SCREEN_ORIENTATION_UNSPECIFIED);
+ setActivityRequestedOrientation(top, SCREEN_ORIENTATION_UNSPECIFIED);
assertEquals(fullScreenBounds, task.getBounds());
// Setting app to fixed landscape and changing display
- setActivityRequestedOrientation(root, SCREEN_ORIENTATION_LANDSCAPE);
+ setActivityRequestedOrientation(top, SCREEN_ORIENTATION_LANDSCAPE);
+ // simulate display orientation changing (normally done via DisplayContent)
+ display.getRequestedOverrideConfiguration().orientation =
+ Configuration.ORIENTATION_PORTRAIT;
display.setBounds(fullScreenBoundsPort);
assertTrue(task.getBounds().width() > task.getBounds().height());
assertEquals(fullScreenBoundsPort.width(), task.getBounds().width());
diff --git a/services/usb/java/com/android/server/usb/UsbHostManager.java b/services/usb/java/com/android/server/usb/UsbHostManager.java
index 904d55e..00c7548 100644
--- a/services/usb/java/com/android/server/usb/UsbHostManager.java
+++ b/services/usb/java/com/android/server/usb/UsbHostManager.java
@@ -418,12 +418,10 @@
parser.getRawDescriptors());
// Stats collection
- if (parser.hasAudioInterface()) {
- StatsLog.write(StatsLog.USB_DEVICE_ATTACHED, newDevice.getVendorId(),
- newDevice.getProductId(), parser.hasAudioInterface(),
- parser.hasHIDInterface(), parser.hasStorageInterface(),
- StatsLog.USB_DEVICE_ATTACHED__STATE__STATE_CONNECTED, 0);
- }
+ StatsLog.write(StatsLog.USB_DEVICE_ATTACHED, newDevice.getVendorId(),
+ newDevice.getProductId(), parser.hasAudioInterface(),
+ parser.hasHIDInterface(), parser.hasStorageInterface(),
+ StatsLog.USB_DEVICE_ATTACHED__STATE__STATE_CONNECTED, 0);
}
}
@@ -455,14 +453,12 @@
if (current != null) {
UsbDescriptorParser parser = new UsbDescriptorParser(deviceAddress,
current.mDescriptors);
- if (parser.hasAudioInterface()) {
// Stats collection
- StatsLog.write(StatsLog.USB_DEVICE_ATTACHED, device.getVendorId(),
- device.getProductId(), parser.hasAudioInterface(),
- parser.hasHIDInterface(), parser.hasStorageInterface(),
- StatsLog.USB_DEVICE_ATTACHED__STATE__STATE_DISCONNECTED,
- System.currentTimeMillis() - current.mTimestamp);
- }
+ StatsLog.write(StatsLog.USB_DEVICE_ATTACHED, device.getVendorId(),
+ device.getProductId(), parser.hasAudioInterface(),
+ parser.hasHIDInterface(), parser.hasStorageInterface(),
+ StatsLog.USB_DEVICE_ATTACHED__STATE__STATE_DISCONNECTED,
+ System.currentTimeMillis() - current.mTimestamp);
}
} else {
Slog.d(TAG, "Removed device at " + deviceAddress + " was already gone");
diff --git a/startop/view_compiler/apk_layout_compiler.cc b/startop/view_compiler/apk_layout_compiler.cc
index e95041b..09cdbd5 100644
--- a/startop/view_compiler/apk_layout_compiler.cc
+++ b/startop/view_compiler/apk_layout_compiler.cc
@@ -79,9 +79,9 @@
return visitor.can_compile();
}
-void CompileApkLayouts(const std::string& filename, CompilationTarget target,
- std::ostream& target_out) {
- auto assets = android::ApkAssets::Load(filename);
+namespace {
+void CompileApkAssetsLayouts(const std::unique_ptr<const android::ApkAssets>& assets,
+ CompilationTarget target, std::ostream& target_out) {
android::AssetManager2 resources;
resources.SetApkAssets({assets.get()});
@@ -155,5 +155,20 @@
target_out.write(image.ptr<const char>(), image.size());
}
}
+} // namespace
+
+void CompileApkLayouts(const std::string& filename, CompilationTarget target,
+ std::ostream& target_out) {
+ auto assets = android::ApkAssets::Load(filename);
+ CompileApkAssetsLayouts(assets, target, target_out);
+}
+
+void CompileApkLayoutsFd(android::base::unique_fd fd, CompilationTarget target,
+ std::ostream& target_out) {
+ constexpr const char* friendly_name{"viewcompiler assets"};
+ auto assets = android::ApkAssets::LoadFromFd(
+ std::move(fd), friendly_name, /*system=*/false, /*force_shared_lib=*/false);
+ CompileApkAssetsLayouts(assets, target, target_out);
+}
} // namespace startop
diff --git a/startop/view_compiler/apk_layout_compiler.h b/startop/view_compiler/apk_layout_compiler.h
index c85ddd6..03bd545 100644
--- a/startop/view_compiler/apk_layout_compiler.h
+++ b/startop/view_compiler/apk_layout_compiler.h
@@ -19,12 +19,16 @@
#include <string>
+#include "android-base/unique_fd.h"
+
namespace startop {
enum class CompilationTarget { kJavaLanguage, kDex };
void CompileApkLayouts(const std::string& filename, CompilationTarget target,
std::ostream& target_out);
+void CompileApkLayoutsFd(android::base::unique_fd fd, CompilationTarget target,
+ std::ostream& target_out);
} // namespace startop
diff --git a/startop/view_compiler/main.cc b/startop/view_compiler/main.cc
index 871a421..11ecde2 100644
--- a/startop/view_compiler/main.cc
+++ b/startop/view_compiler/main.cc
@@ -49,6 +49,7 @@
DEFINE_bool(apk, false, "Compile layouts in an APK");
DEFINE_bool(dex, false, "Generate a DEX file instead of Java");
+DEFINE_int32(infd, -1, "Read input from the given file descriptor");
DEFINE_string(out, kStdoutFilename, "Where to write the generated class");
DEFINE_string(package, "", "The package name for the generated class (required)");
@@ -95,7 +96,7 @@
int main(int argc, char** argv) {
constexpr size_t kProgramName = 0;
constexpr size_t kFileNameParam = 1;
- constexpr size_t kNumRequiredArgs = 2;
+ constexpr size_t kNumRequiredArgs = 1;
gflags::SetUsageMessage(
"Compile XML layout files into equivalent Java language code\n"
@@ -104,12 +105,11 @@
gflags::ParseCommandLineFlags(&argc, &argv, /*remove_flags*/ true);
gflags::CommandLineFlagInfo cmd = gflags::GetCommandLineFlagInfoOrDie("package");
- if (argc != kNumRequiredArgs || cmd.is_default) {
+ if (argc < kNumRequiredArgs || cmd.is_default) {
gflags::ShowUsageWithFlags(argv[kProgramName]);
return 1;
}
- const char* const filename = argv[kFileNameParam];
const bool is_stdout = FLAGS_out == kStdoutFilename;
std::ofstream outfile;
@@ -118,13 +118,23 @@
}
if (FLAGS_apk) {
- startop::CompileApkLayouts(
- filename,
- FLAGS_dex ? startop::CompilationTarget::kDex : startop::CompilationTarget::kJavaLanguage,
- is_stdout ? std::cout : outfile);
+ const startop::CompilationTarget target =
+ FLAGS_dex ? startop::CompilationTarget::kDex : startop::CompilationTarget::kJavaLanguage;
+ if (FLAGS_infd >= 0) {
+ startop::CompileApkLayoutsFd(
+ android::base::unique_fd{FLAGS_infd}, target, is_stdout ? std::cout : outfile);
+ } else {
+ if (argc < 2) {
+ gflags::ShowUsageWithFlags(argv[kProgramName]);
+ return 1;
+ }
+ const char* const filename = argv[kFileNameParam];
+ startop::CompileApkLayouts(filename, target, is_stdout ? std::cout : outfile);
+ }
return 0;
}
+ const char* const filename = argv[kFileNameParam];
const string layout_name = startop::util::FindLayoutNameFromFilename(filename);
XMLDocument xml;
diff --git a/telephony/java/android/telephony/AvailableNetworkInfo.java b/telephony/java/android/telephony/AvailableNetworkInfo.java
index fe07370..4da79b3 100644
--- a/telephony/java/android/telephony/AvailableNetworkInfo.java
+++ b/telephony/java/android/telephony/AvailableNetworkInfo.java
@@ -110,6 +110,7 @@
private AvailableNetworkInfo(Parcel in) {
mSubId = in.readInt();
mPriority = in.readInt();
+ mMccMncs = new ArrayList<>();
in.readStringList(mMccMncs);
}
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index babeb7b..3311218 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -9963,7 +9963,7 @@
boolean ret = false;
try {
IOns iOpportunisticNetworkService = getIOns();
- if (iOpportunisticNetworkService != null) {
+ if (iOpportunisticNetworkService != null && availableNetworks != null) {
ret = iOpportunisticNetworkService.updateAvailableNetworks(availableNetworks,
pkgForDebug);
}
diff --git a/telephony/java/android/telephony/euicc/EuiccManager.java b/telephony/java/android/telephony/euicc/EuiccManager.java
index cc9befe..42a788d 100644
--- a/telephony/java/android/telephony/euicc/EuiccManager.java
+++ b/telephony/java/android/telephony/euicc/EuiccManager.java
@@ -30,6 +30,7 @@
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.telephony.TelephonyManager;
import com.android.internal.telephony.euicc.IEuiccController;
@@ -40,7 +41,11 @@
* EuiccManager is the application interface to eUICCs, or eSIMs/embedded SIMs.
*
* <p>You do not instantiate this class directly; instead, you retrieve an instance through
- * {@link Context#getSystemService(String)} and {@link Context#EUICC_SERVICE}.
+ * {@link Context#getSystemService(String)} and {@link Context#EUICC_SERVICE}. This instance will be
+ * created using the default eUICC.
+ *
+ * <p>On a device with multiple eUICCs, you may want to create multiple EuiccManagers. To do this
+ * you can call {@link #createForCardId}.
*
* <p>See {@link #isEnabled} before attempting to use these APIs.
*/
@@ -318,10 +323,29 @@
public static final int EUICC_OTA_STATUS_UNAVAILABLE = 5;
private final Context mContext;
+ private final int mCardId;
/** @hide */
public EuiccManager(Context context) {
mContext = context;
+ TelephonyManager tm = (TelephonyManager)
+ context.getSystemService(Context.TELEPHONY_SERVICE);
+ mCardId = tm.getCardIdForDefaultEuicc();
+ }
+
+ /** @hide */
+ private EuiccManager(Context context, int cardId) {
+ mContext = context;
+ mCardId = cardId;
+ }
+
+ /**
+ * Create a new EuiccManager object pinned to the given card ID.
+ *
+ * @return an EuiccManager that uses the given card ID for all calls.
+ */
+ public EuiccManager createForCardId(int cardId) {
+ return new EuiccManager(mContext, cardId);
}
/**
@@ -344,7 +368,8 @@
* Returns the EID identifying the eUICC hardware.
*
* <p>Requires that the calling app has carrier privileges on the active subscription on the
- * eUICC.
+ * current eUICC. A calling app with carrier privileges for one eUICC may not necessarily have
+ * access to the EID of another eUICC.
*
* @return the EID. May be null if {@link #isEnabled()} is false or the eUICC is not ready.
*/
@@ -354,7 +379,7 @@
return null;
}
try {
- return getIEuiccController().getEid();
+ return getIEuiccController().getEid(mCardId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -377,7 +402,7 @@
return EUICC_OTA_STATUS_UNAVAILABLE;
}
try {
- return getIEuiccController().getOtaStatus();
+ return getIEuiccController().getOtaStatus(mCardId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -387,10 +412,10 @@
* Attempt to download the given {@link DownloadableSubscription}.
*
* <p>Requires the {@code android.Manifest.permission#WRITE_EMBEDDED_SUBSCRIPTIONS} permission,
- * or the calling app must be authorized to manage both the currently-active subscription and
- * the subscription to be downloaded according to the subscription metadata. Without the former,
- * an {@link #EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR} will be returned in the callback
- * intent to prompt the user to accept the download.
+ * or the calling app must be authorized to manage both the currently-active subscription on the
+ * current eUICC and the subscription to be downloaded according to the subscription metadata.
+ * Without the former, an {@link #EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR} will be
+ * returned in the callback intent to prompt the user to accept the download.
*
* @param subscription the subscription to download.
* @param switchAfterDownload if true, the profile will be activated upon successful download.
@@ -404,7 +429,7 @@
return;
}
try {
- getIEuiccController().downloadSubscription(subscription, switchAfterDownload,
+ getIEuiccController().downloadSubscription(mCardId, subscription, switchAfterDownload,
mContext.getOpPackageName(), null /* resolvedBundle */, callbackIntent);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
@@ -471,7 +496,7 @@
return;
}
try {
- getIEuiccController().continueOperation(resolutionIntent, resolutionExtras);
+ getIEuiccController().continueOperation(mCardId, resolutionIntent, resolutionExtras);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -503,8 +528,8 @@
return;
}
try {
- getIEuiccController().getDownloadableSubscriptionMetadata(
- subscription, mContext.getOpPackageName(), callbackIntent);
+ getIEuiccController().getDownloadableSubscriptionMetadata(mCardId, subscription,
+ mContext.getOpPackageName(), callbackIntent);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -533,7 +558,7 @@
return;
}
try {
- getIEuiccController().getDefaultDownloadableSubscriptionList(
+ getIEuiccController().getDefaultDownloadableSubscriptionList(mCardId,
mContext.getOpPackageName(), callbackIntent);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
@@ -552,7 +577,7 @@
return null;
}
try {
- return getIEuiccController().getEuiccInfo();
+ return getIEuiccController().getEuiccInfo(mCardId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -578,7 +603,7 @@
return;
}
try {
- getIEuiccController().deleteSubscription(
+ getIEuiccController().deleteSubscription(mCardId,
subscriptionId, mContext.getOpPackageName(), callbackIntent);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
@@ -606,7 +631,7 @@
return;
}
try {
- getIEuiccController().switchToSubscription(
+ getIEuiccController().switchToSubscription(mCardId,
subscriptionId, mContext.getOpPackageName(), callbackIntent);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
@@ -632,7 +657,7 @@
return;
}
try {
- getIEuiccController().updateSubscriptionNickname(
+ getIEuiccController().updateSubscriptionNickname(mCardId,
subscriptionId, nickname, mContext.getOpPackageName(), callbackIntent);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
@@ -656,7 +681,7 @@
return;
}
try {
- getIEuiccController().eraseSubscriptions(callbackIntent);
+ getIEuiccController().eraseSubscriptions(mCardId, callbackIntent);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -686,7 +711,7 @@
return;
}
try {
- getIEuiccController().retainSubscriptionsForFactoryReset(callbackIntent);
+ getIEuiccController().retainSubscriptionsForFactoryReset(mCardId, callbackIntent);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/telephony/java/com/android/internal/telephony/DctConstants.java b/telephony/java/com/android/internal/telephony/DctConstants.java
index 96f7a1b..3408291 100644
--- a/telephony/java/com/android/internal/telephony/DctConstants.java
+++ b/telephony/java/com/android/internal/telephony/DctConstants.java
@@ -92,6 +92,7 @@
public static final int EVENT_DATA_RECONNECT = BASE + 47;
public static final int EVENT_ROAMING_SETTING_CHANGE = BASE + 48;
public static final int EVENT_DATA_SERVICE_BINDING_CHANGED = BASE + 49;
+ public static final int EVENT_DEVICE_PROVISIONED_CHANGE = BASE + 50;
/***** Constants *****/
diff --git a/telephony/java/com/android/internal/telephony/TelephonyIntents.java b/telephony/java/com/android/internal/telephony/TelephonyIntents.java
index 2a648bd..8523554 100644
--- a/telephony/java/com/android/internal/telephony/TelephonyIntents.java
+++ b/telephony/java/com/android/internal/telephony/TelephonyIntents.java
@@ -501,4 +501,18 @@
*/
public static final String ACTION_LINE1_NUMBER_ERROR_DETECTED =
"com.android.internal.telephony.ACTION_LINE1_NUMBER_ERROR_DETECTED";
+
+ /**
+ * Broadcast action to notify radio bug.
+ *
+ * Requires the READ_PRIVILEGED_PHONE_STATE permission.
+ *
+ * @hide
+ */
+ public static final String ACTION_REPORT_RADIO_BUG =
+ "com.android.internal.telephony.ACTION_REPORT_RADIO_BUG";
+
+ // ACTION_REPORT_RADIO_BUG extra keys
+ public static final String EXTRA_SLOT_ID = "slotId";
+ public static final String EXTRA_RADIO_BUG_TYPE = "radioBugType";
}
diff --git a/telephony/java/com/android/internal/telephony/euicc/IEuiccController.aidl b/telephony/java/com/android/internal/telephony/euicc/IEuiccController.aidl
index dd40d56..14a36c8 100644
--- a/telephony/java/com/android/internal/telephony/euicc/IEuiccController.aidl
+++ b/telephony/java/com/android/internal/telephony/euicc/IEuiccController.aidl
@@ -24,22 +24,25 @@
/** @hide */
interface IEuiccController {
- oneway void continueOperation(in Intent resolutionIntent, in Bundle resolutionExtras);
- oneway void getDownloadableSubscriptionMetadata(in DownloadableSubscription subscription,
+ oneway void continueOperation(int cardId, in Intent resolutionIntent,
+ in Bundle resolutionExtras);
+ oneway void getDownloadableSubscriptionMetadata(int cardId,
+ in DownloadableSubscription subscription,
String callingPackage, in PendingIntent callbackIntent);
- oneway void getDefaultDownloadableSubscriptionList(
+ oneway void getDefaultDownloadableSubscriptionList(int cardId,
String callingPackage, in PendingIntent callbackIntent);
- String getEid();
- int getOtaStatus();
- oneway void downloadSubscription(in DownloadableSubscription subscription,
- boolean switchAfterDownload, String callingPackage, in Bundle resolvedBundle, in PendingIntent callbackIntent);
- EuiccInfo getEuiccInfo();
- oneway void deleteSubscription(int subscriptionId, String callingPackage,
+ String getEid(int cardId);
+ int getOtaStatus(int cardId);
+ oneway void downloadSubscription(int cardId, in DownloadableSubscription subscription,
+ boolean switchAfterDownload, String callingPackage, in Bundle resolvedBundle,
in PendingIntent callbackIntent);
- oneway void switchToSubscription(int subscriptionId, String callingPackage,
+ EuiccInfo getEuiccInfo(int cardId);
+ oneway void deleteSubscription(int cardId, int subscriptionId, String callingPackage,
in PendingIntent callbackIntent);
- oneway void updateSubscriptionNickname(int subscriptionId, String nickname,
+ oneway void switchToSubscription(int cardId, int subscriptionId, String callingPackage,
+ in PendingIntent callbackIntent);
+ oneway void updateSubscriptionNickname(int cardId, int subscriptionId, String nickname,
String callingPackage, in PendingIntent callbackIntent);
- oneway void eraseSubscriptions(in PendingIntent callbackIntent);
- oneway void retainSubscriptionsForFactoryReset(in PendingIntent callbackIntent);
-}
\ No newline at end of file
+ oneway void eraseSubscriptions(int cardId, in PendingIntent callbackIntent);
+ oneway void retainSubscriptionsForFactoryReset(int cardId, in PendingIntent callbackIntent);
+}
diff --git a/test-base/api/current.txt b/test-base/api/current.txt
index 7ebd6aa..91fcca5 100644
--- a/test-base/api/current.txt
+++ b/test-base/api/current.txt
@@ -48,6 +48,9 @@
method public abstract void startTiming(boolean);
}
+ public abstract deprecated class RepetitiveTest implements java.lang.annotation.Annotation {
+ }
+
public abstract deprecated class UiThreadTest implements java.lang.annotation.Annotation {
}
diff --git a/test-base/src/android/test/RepetitiveTest.java b/test-base/src/android/test/RepetitiveTest.java
index 6a7130e..13e89d2 100644
--- a/test-base/src/android/test/RepetitiveTest.java
+++ b/test-base/src/android/test/RepetitiveTest.java
@@ -26,8 +26,10 @@
* When the annotation is present, the test method is executed the number of times specified by
* numIterations and defaults to 1.
*
- * {@hide} Not needed for public API.
+ * @deprecated New tests should be written using the
+ * <a href="{@docRoot}tools/testing-support-library/index.html">Android Testing Support Library</a>.
*/
+@Deprecated
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface RepetitiveTest {
@@ -37,4 +39,4 @@
* @return The total number of iterations, the default is 1.
*/
int numIterations() default 1;
-}
\ No newline at end of file
+}
diff --git a/test-legacy/Android.bp b/test-legacy/Android.bp
index 833c714..a69f422 100644
--- a/test-legacy/Android.bp
+++ b/test-legacy/Android.bp
@@ -25,7 +25,7 @@
static_libs: [
"android.test.base-minus-junit",
"android.test.runner-minus-junit",
- "android.test.mock.impl",
+ "android.test.mock_static",
],
no_framework_libs: true,
diff --git a/test-mock/Android.bp b/test-mock/Android.bp
index e1d6e01..43b765d 100644
--- a/test-mock/Android.bp
+++ b/test-mock/Android.bp
@@ -30,3 +30,19 @@
srcs_lib_whitelist_pkgs: ["android"],
compile_dex: true,
}
+
+// Build the android.test.mock_static library
+// ==========================================
+// This is only intended for inclusion in the legacy-android-test.
+// Must not be used elewhere.
+java_library_static {
+ name: "android.test.mock_static",
+
+ java_version: "1.8",
+ srcs: ["src/**/*.java"],
+
+ no_framework_libs: true,
+ libs: [
+ "framework",
+ ],
+}
diff --git a/tests/PackageWatchdog/Android.mk b/tests/PackageWatchdog/Android.mk
index b53f27d..1c1c2a4 100644
--- a/tests/PackageWatchdog/Android.mk
+++ b/tests/PackageWatchdog/Android.mk
@@ -23,7 +23,7 @@
junit \
frameworks-base-testutils \
android-support-test \
- services
+ services.core
LOCAL_JAVA_LIBRARIES := \
android.test.runner
diff --git a/tests/net/java/android/net/LinkPropertiesTest.java b/tests/net/java/android/net/LinkPropertiesTest.java
index 932fee0..299fbef 100644
--- a/tests/net/java/android/net/LinkPropertiesTest.java
+++ b/tests/net/java/android/net/LinkPropertiesTest.java
@@ -849,6 +849,18 @@
assertEquals(new ArraySet<>(expectRemoved), (new ArraySet<>(result.removed)));
}
+ private void assertParcelingIsLossless(LinkProperties source) {
+ Parcel p = Parcel.obtain();
+ source.writeToParcel(p, /* flags */ 0);
+ p.setDataPosition(0);
+ final byte[] marshalled = p.marshall();
+ p = Parcel.obtain();
+ p.unmarshall(marshalled, 0, marshalled.length);
+ p.setDataPosition(0);
+ LinkProperties dest = LinkProperties.CREATOR.createFromParcel(p);
+ assertEquals(source, dest);
+ }
+
@Test
public void testLinkPropertiesParcelable() throws Exception {
LinkProperties source = new LinkProperties();
@@ -870,15 +882,12 @@
source.setNat64Prefix(new IpPrefix("2001:db8:1:2:64:64::/96"));
- Parcel p = Parcel.obtain();
- source.writeToParcel(p, /* flags */ 0);
- p.setDataPosition(0);
- final byte[] marshalled = p.marshall();
- p = Parcel.obtain();
- p.unmarshall(marshalled, 0, marshalled.length);
- p.setDataPosition(0);
- LinkProperties dest = LinkProperties.CREATOR.createFromParcel(p);
+ assertParcelingIsLossless(source);
+ }
- assertEquals(source, dest);
+ @Test
+ public void testParcelUninitialized() throws Exception {
+ LinkProperties empty = new LinkProperties();
+ assertParcelingIsLossless(empty);
}
}
diff --git a/tests/net/java/com/android/server/ConnectivityServiceTest.java b/tests/net/java/com/android/server/ConnectivityServiceTest.java
index bf39644..2a92a7d 100644
--- a/tests/net/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/net/java/com/android/server/ConnectivityServiceTest.java
@@ -4683,7 +4683,7 @@
mCellNetworkAgent.sendLinkProperties(cellLp);
mCellNetworkAgent.connect(true);
networkCallback.expectAvailableThenValidatedCallbacks(mCellNetworkAgent);
- verify(mNetworkManagementService, times(1)).startClatd(MOBILE_IFNAME);
+ verify(mMockNetd, times(1)).clatdStart(MOBILE_IFNAME);
Nat464Xlat clat = mService.getNat464Xlat(mCellNetworkAgent);
// Clat iface up, expect stack link updated.
@@ -4710,7 +4710,7 @@
mCellNetworkAgent.sendLinkProperties(cellLp);
waitForIdle();
networkCallback.expectCallback(CallbackState.LINK_PROPERTIES, mCellNetworkAgent);
- verify(mNetworkManagementService, times(1)).stopClatd(MOBILE_IFNAME);
+ verify(mMockNetd, times(1)).clatdStop(MOBILE_IFNAME);
// Clat iface removed, expect linkproperties revert to original one
clat.interfaceRemoved(CLAT_PREFIX + MOBILE_IFNAME);
diff --git a/tests/net/java/com/android/server/connectivity/LingerMonitorTest.java b/tests/net/java/com/android/server/connectivity/LingerMonitorTest.java
index 4c52d81..9578ded 100644
--- a/tests/net/java/com/android/server/connectivity/LingerMonitorTest.java
+++ b/tests/net/java/com/android/server/connectivity/LingerMonitorTest.java
@@ -32,11 +32,13 @@
import android.content.Context;
import android.content.res.Resources;
import android.net.ConnectivityManager;
+import android.net.INetd;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkMisc;
import android.net.NetworkStack;
+import android.os.INetworkManagementService;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.text.format.DateUtils;
@@ -66,6 +68,8 @@
LingerMonitor mMonitor;
@Mock ConnectivityService mConnService;
+ @Mock INetd mNetd;
+ @Mock INetworkManagementService mNMS;
@Mock Context mCtx;
@Mock NetworkMisc mMisc;
@Mock NetworkNotificationManager mNotifier;
@@ -352,7 +356,7 @@
caps.addCapability(0);
caps.addTransportType(transport);
NetworkAgentInfo nai = new NetworkAgentInfo(null, null, new Network(netId), info, null,
- caps, 50, mCtx, null, mMisc, mConnService);
+ caps, 50, mCtx, null, mMisc, mConnService, mNetd, mNMS);
nai.everValidated = true;
return nai;
}
diff --git a/tests/net/java/com/android/server/connectivity/Nat464XlatTest.java b/tests/net/java/com/android/server/connectivity/Nat464XlatTest.java
index bf42412..07b1d05 100644
--- a/tests/net/java/com/android/server/connectivity/Nat464XlatTest.java
+++ b/tests/net/java/com/android/server/connectivity/Nat464XlatTest.java
@@ -17,9 +17,7 @@
package com.android.server.connectivity;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.any;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -27,6 +25,7 @@
import static org.mockito.Mockito.when;
import android.net.ConnectivityManager;
+import android.net.INetd;
import android.net.InterfaceConfiguration;
import android.net.LinkAddress;
import android.net.LinkProperties;
@@ -57,6 +56,7 @@
@Mock ConnectivityService mConnectivity;
@Mock NetworkMisc mMisc;
+ @Mock INetd mNetd;
@Mock INetworkManagementService mNms;
@Mock InterfaceConfiguration mConfig;
@Mock NetworkAgentInfo mNai;
@@ -65,7 +65,7 @@
Handler mHandler;
Nat464Xlat makeNat464Xlat() {
- return new Nat464Xlat(mNms, mNai);
+ return new Nat464Xlat(mNai, mNetd, mNms);
}
@Before
@@ -129,7 +129,7 @@
nat.start();
verify(mNms).registerObserver(eq(nat));
- verify(mNms).startClatd(eq(BASE_IFACE));
+ verify(mNetd).clatdStart(eq(BASE_IFACE));
// Stacked interface up notification arrives.
nat.interfaceLinkStateChanged(STACKED_IFACE, true);
@@ -144,7 +144,7 @@
// ConnectivityService stops clat (Network disconnects, IPv4 addr appears, ...).
nat.stop();
- verify(mNms).stopClatd(eq(BASE_IFACE));
+ verify(mNetd).clatdStop(eq(BASE_IFACE));
// Stacked interface removed notification arrives.
nat.interfaceRemoved(STACKED_IFACE);
@@ -156,7 +156,7 @@
assertFalse(c.getValue().getAllInterfaceNames().contains(STACKED_IFACE));
assertIdle(nat);
- verifyNoMoreInteractions(mNms, mConnectivity);
+ verifyNoMoreInteractions(mNetd, mNms, mConnectivity);
}
@Test
@@ -168,7 +168,7 @@
nat.start();
verify(mNms).registerObserver(eq(nat));
- verify(mNms).startClatd(eq(BASE_IFACE));
+ verify(mNetd).clatdStart(eq(BASE_IFACE));
// Stacked interface up notification arrives.
nat.interfaceLinkStateChanged(STACKED_IFACE, true);
@@ -185,7 +185,7 @@
mLooper.dispatchNext();
verify(mNms).unregisterObserver(eq(nat));
- verify(mNms).stopClatd(eq(BASE_IFACE));
+ verify(mNetd).clatdStop(eq(BASE_IFACE));
verify(mConnectivity, times(2)).handleUpdateLinkProperties(eq(mNai), c.capture());
assertTrue(c.getValue().getStackedLinks().isEmpty());
assertFalse(c.getValue().getAllInterfaceNames().contains(STACKED_IFACE));
@@ -194,7 +194,7 @@
// ConnectivityService stops clat: no-op.
nat.stop();
- verifyNoMoreInteractions(mNms, mConnectivity);
+ verifyNoMoreInteractions(mNetd, mNms, mConnectivity);
}
@Test
@@ -205,13 +205,13 @@
nat.start();
verify(mNms).registerObserver(eq(nat));
- verify(mNms).startClatd(eq(BASE_IFACE));
+ verify(mNetd).clatdStart(eq(BASE_IFACE));
// ConnectivityService immediately stops clat (Network disconnects, IPv4 addr appears, ...)
nat.stop();
verify(mNms).unregisterObserver(eq(nat));
- verify(mNms).stopClatd(eq(BASE_IFACE));
+ verify(mNetd).clatdStop(eq(BASE_IFACE));
assertIdle(nat);
// In-flight interface up notification arrives: no-op
@@ -225,7 +225,7 @@
assertIdle(nat);
- verifyNoMoreInteractions(mNms, mConnectivity);
+ verifyNoMoreInteractions(mNetd, mNms, mConnectivity);
}
@Test
@@ -236,16 +236,16 @@
nat.start();
verify(mNms).registerObserver(eq(nat));
- verify(mNms).startClatd(eq(BASE_IFACE));
+ verify(mNetd).clatdStart(eq(BASE_IFACE));
// ConnectivityService immediately stops clat (Network disconnects, IPv4 addr appears, ...)
nat.stop();
verify(mNms).unregisterObserver(eq(nat));
- verify(mNms).stopClatd(eq(BASE_IFACE));
+ verify(mNetd).clatdStop(eq(BASE_IFACE));
assertIdle(nat);
- verifyNoMoreInteractions(mNms, mConnectivity);
+ verifyNoMoreInteractions(mNetd, mNms, mConnectivity);
}
static void assertIdle(Nat464Xlat nat) {
diff --git a/tests/net/java/com/android/server/net/ipmemorystore/IpMemoryStoreServiceTest.java b/tests/net/java/com/android/server/net/ipmemorystore/IpMemoryStoreServiceTest.java
index 859a54d..e63c3b0 100644
--- a/tests/net/java/com/android/server/net/ipmemorystore/IpMemoryStoreServiceTest.java
+++ b/tests/net/java/com/android/server/net/ipmemorystore/IpMemoryStoreServiceTest.java
@@ -16,6 +16,9 @@
package com.android.server.net.ipmemorystore;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doReturn;
+
import android.content.Context;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
@@ -26,6 +29,8 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.io.File;
+
/** Unit tests for {@link IpMemoryStoreServiceTest}. */
@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -36,6 +41,7 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ doReturn(new File("/tmp/test.db")).when(mMockContext).getDatabasePath(anyString());
}
@Test
diff --git a/tests/net/java/com/android/server/net/ipmemorystore/RelevanceUtilsTests.java b/tests/net/java/com/android/server/net/ipmemorystore/RelevanceUtilsTests.java
new file mode 100644
index 0000000..8d367e2
--- /dev/null
+++ b/tests/net/java/com/android/server/net/ipmemorystore/RelevanceUtilsTests.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.net.ipmemorystore;
+
+import static com.android.server.net.ipmemorystore.RelevanceUtils.CAPPED_RELEVANCE;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/** Unit tests for {@link RelevanceUtils}. */
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class RelevanceUtilsTests {
+ @Test
+ public void testComputeRelevanceForTargetDate() {
+ final long dayInMillis = 24L * 60 * 60 * 1000;
+ final long base = 1_000_000L; // any given point in time
+ // Relevance when the network expires in 1000 years must be capped
+ assertEquals(CAPPED_RELEVANCE, RelevanceUtils.computeRelevanceForTargetDate(
+ base + 1000L * dayInMillis, base));
+ // Relevance when expiry is before the date must be 0
+ assertEquals(0, RelevanceUtils.computeRelevanceForTargetDate(base - 1, base));
+ // Make sure the relevance for a given target date is higher if the expiry is further
+ // in the future
+ assertTrue(RelevanceUtils.computeRelevanceForTargetDate(base + 100 * dayInMillis, base)
+ < RelevanceUtils.computeRelevanceForTargetDate(base + 150 * dayInMillis, base));
+
+ // Make sure the relevance falls slower as the expiry is closing in. This is to ensure
+ // the decay is indeed logarithmic.
+ final int relevanceAtExpiry = RelevanceUtils.computeRelevanceForTargetDate(base, base);
+ final int relevance50DaysBeforeExpiry =
+ RelevanceUtils.computeRelevanceForTargetDate(base + 50 * dayInMillis, base);
+ final int relevance100DaysBeforeExpiry =
+ RelevanceUtils.computeRelevanceForTargetDate(base + 100 * dayInMillis, base);
+ final int relevance150DaysBeforeExpiry =
+ RelevanceUtils.computeRelevanceForTargetDate(base + 150 * dayInMillis, base);
+ assertEquals(0, relevanceAtExpiry);
+ assertTrue(relevance50DaysBeforeExpiry - relevanceAtExpiry
+ < relevance100DaysBeforeExpiry - relevance50DaysBeforeExpiry);
+ assertTrue(relevance100DaysBeforeExpiry - relevance50DaysBeforeExpiry
+ < relevance150DaysBeforeExpiry - relevance100DaysBeforeExpiry);
+ }
+
+ @Test
+ public void testIncreaseRelevance() {
+ long expiry = System.currentTimeMillis();
+
+ final long firstBump = RelevanceUtils.bumpExpiryDate(expiry);
+ // Though a few milliseconds might have elapsed, the first bump should push the duration
+ // to days in the future, so unless this test takes literal days between these two lines,
+ // this should always pass.
+ assertTrue(firstBump > expiry);
+
+ expiry = 0;
+ long lastDifference = Long.MAX_VALUE;
+ // The relevance should be capped in at most this many steps. Otherwise, fail.
+ final int steps = 1000;
+ for (int i = 0; i < steps; ++i) {
+ final long newExpiry = RelevanceUtils.bumpExpiryDuration(expiry);
+ if (newExpiry == expiry) {
+ // The relevance should be capped. Make sure it is, then exit without failure.
+ assertEquals(newExpiry, RelevanceUtils.CAPPED_RELEVANCE_LIFETIME_MS);
+ return;
+ }
+ // Make sure the new expiry is further in the future than last time.
+ assertTrue(newExpiry > expiry);
+ // Also check that it was not bumped as much as the last bump, because the
+ // decay must be exponential.
+ assertTrue(newExpiry - expiry < lastDifference);
+ lastDifference = newExpiry - expiry;
+ expiry = newExpiry;
+ }
+ fail("Relevance failed to go to the maximum value after " + steps + " bumps");
+ }
+
+ @Test
+ public void testContinuity() {
+ final long expiry = System.currentTimeMillis();
+
+ // Relevance at expiry and after expiry should be the cap.
+ final int relevanceBeforeMaxLifetime = RelevanceUtils.computeRelevanceForTargetDate(expiry,
+ expiry - (RelevanceUtils.CAPPED_RELEVANCE_LIFETIME_MS + 1_000_000));
+ assertEquals(relevanceBeforeMaxLifetime, CAPPED_RELEVANCE);
+ final int relevanceForMaxLifetime = RelevanceUtils.computeRelevanceForTargetDate(expiry,
+ expiry - RelevanceUtils.CAPPED_RELEVANCE_LIFETIME_MS);
+ assertEquals(relevanceForMaxLifetime, CAPPED_RELEVANCE);
+
+ // If the max relevance is reached at the cap lifetime, one millisecond less than this
+ // should be very close. Strictly speaking this is a bit brittle, but it should be
+ // good enough for the purposes of the memory store.
+ final int relevanceForOneMillisecLessThanCap = RelevanceUtils.computeRelevanceForTargetDate(
+ expiry, expiry - RelevanceUtils.CAPPED_RELEVANCE_LIFETIME_MS + 1);
+ assertTrue(relevanceForOneMillisecLessThanCap <= CAPPED_RELEVANCE);
+ assertTrue(relevanceForOneMillisecLessThanCap >= CAPPED_RELEVANCE - 10);
+
+ // Likewise the relevance one millisecond before expiry should be very close to 0. It's
+ // fine if it rounds down to 0.
+ final int relevanceOneMillisecBeforeExpiry = RelevanceUtils.computeRelevanceForTargetDate(
+ expiry, expiry - 1);
+ assertTrue(relevanceOneMillisecBeforeExpiry <= 10);
+ assertTrue(relevanceOneMillisecBeforeExpiry >= 0);
+
+ final int relevanceAtExpiry = RelevanceUtils.computeRelevanceForTargetDate(expiry, expiry);
+ assertEquals(relevanceAtExpiry, 0);
+ final int relevanceAfterExpiry = RelevanceUtils.computeRelevanceForTargetDate(expiry,
+ expiry + 1_000_000);
+ assertEquals(relevanceAfterExpiry, 0);
+ }
+
+ // testIncreaseRelevance makes sure bumping the expiry continuously always yields a
+ // monotonically increasing date as a side effect, but this tests that the relevance (as
+ // opposed to the expiry date) increases monotonically with increasing periods.
+ @Test
+ public void testMonotonicity() {
+ // Hopefully the relevance is granular enough to give a different value for every one
+ // of this number of steps.
+ final int steps = 40;
+ final long expiry = System.currentTimeMillis();
+
+ int lastRelevance = -1;
+ for (int i = 0; i < steps; ++i) {
+ final long date = expiry - i * (RelevanceUtils.CAPPED_RELEVANCE_LIFETIME_MS / steps);
+ final int relevance = RelevanceUtils.computeRelevanceForTargetDate(expiry, date);
+ assertTrue(relevance > lastRelevance);
+ lastRelevance = relevance;
+ }
+ }
+}
diff --git a/tools/aapt2/Android.bp b/tools/aapt2/Android.bp
index 0580df6..7783e10 100644
--- a/tools/aapt2/Android.bp
+++ b/tools/aapt2/Android.bp
@@ -115,6 +115,7 @@
"optimize/MultiApkGenerator.cpp",
"optimize/ResourceDeduper.cpp",
"optimize/ResourceFilter.cpp",
+ "optimize/ResourcePathShortener.cpp",
"optimize/VersionCollapser.cpp",
"process/SymbolTable.cpp",
"split/TableSplitter.cpp",
diff --git a/tools/aapt2/LoadedApk.cpp b/tools/aapt2/LoadedApk.cpp
index b353ff0..45719ef 100644
--- a/tools/aapt2/LoadedApk.cpp
+++ b/tools/aapt2/LoadedApk.cpp
@@ -223,8 +223,17 @@
io::IFile* file = iterator->Next();
std::string path = file->GetSource().path;
+ std::string output_path = path;
+ bool is_resource = path.find("res/") == 0;
+ if (is_resource) {
+ auto it = options.shortened_path_map.find(path);
+ if (it != options.shortened_path_map.end()) {
+ output_path = it->second;
+ }
+ }
+
// Skip resources that are not referenced if requested.
- if (path.find("res/") == 0 && referenced_resources.find(path) == referenced_resources.end()) {
+ if (is_resource && referenced_resources.find(output_path) == referenced_resources.end()) {
if (context->IsVerbose()) {
context->GetDiagnostics()->Note(DiagMessage()
<< "Removing resource '" << path << "' from APK.");
@@ -283,7 +292,8 @@
return false;
}
} else {
- if (!io::CopyFileToArchivePreserveCompression(context, file, path, writer)) {
+ if (!io::CopyFileToArchivePreserveCompression(
+ context, file, output_path, writer)) {
return false;
}
}
diff --git a/tools/aapt2/cmd/Optimize.cpp b/tools/aapt2/cmd/Optimize.cpp
index 328b0be..2e6af18 100644
--- a/tools/aapt2/cmd/Optimize.cpp
+++ b/tools/aapt2/cmd/Optimize.cpp
@@ -41,6 +41,7 @@
#include "optimize/MultiApkGenerator.h"
#include "optimize/ResourceDeduper.h"
#include "optimize/ResourceFilter.h"
+#include "optimize/ResourcePathShortener.h"
#include "optimize/VersionCollapser.h"
#include "split/TableSplitter.h"
#include "util/Files.h"
@@ -52,6 +53,7 @@
using ::android::ResTable_config;
using ::android::StringPiece;
using ::android::base::ReadFileToString;
+using ::android::base::WriteStringToFile;
using ::android::base::StringAppendF;
using ::android::base::StringPrintf;
@@ -143,6 +145,21 @@
return 1;
}
+ if (options_.shorten_resource_paths) {
+ ResourcePathShortener shortener(options_.table_flattener_options.shortened_path_map);
+ if (!shortener.Consume(context_, apk->GetResourceTable())) {
+ context_->GetDiagnostics()->Error(DiagMessage() << "failed shortening resource paths");
+ return 1;
+ }
+ if (options_.shortened_paths_map_path
+ && !WriteShortenedPathsMap(options_.table_flattener_options.shortened_path_map,
+ options_.shortened_paths_map_path.value())) {
+ context_->GetDiagnostics()->Error(DiagMessage()
+ << "failed to write shortened resource paths to file");
+ return 1;
+ }
+ }
+
// Adjust the SplitConstraints so that their SDK version is stripped if it is less than or
// equal to the minSdk.
options_.split_constraints =
@@ -264,6 +281,15 @@
ArchiveEntry::kAlign, writer);
}
+ bool WriteShortenedPathsMap(const std::map<std::string, std::string> &path_map,
+ const std::string &file_path) {
+ std::stringstream ss;
+ for (auto it = path_map.cbegin(); it != path_map.cend(); ++it) {
+ ss << it->first << " -> " << it->second << "\n";
+ }
+ return WriteStringToFile(ss.str(), file_path);
+ }
+
OptimizeOptions options_;
OptimizeContext* context_;
};
diff --git a/tools/aapt2/cmd/Optimize.h b/tools/aapt2/cmd/Optimize.h
index d07305b..7f4a3ed 100644
--- a/tools/aapt2/cmd/Optimize.h
+++ b/tools/aapt2/cmd/Optimize.h
@@ -55,6 +55,12 @@
// Set of artifacts to keep when generating multi-APK splits. If the list is empty, all artifacts
// are kept and will be written as output.
std::unordered_set<std::string> kept_artifacts;
+
+ // Whether or not to shorten resource paths in the APK.
+ bool shorten_resource_paths;
+
+ // Path to the output map of original resource paths to shortened paths.
+ Maybe<std::string> shortened_paths_map_path;
};
class OptimizeCommand : public Command {
@@ -101,6 +107,12 @@
AddOptionalSwitch("--enable-resource-obfuscation",
"Enables obfuscation of key string pool to single value",
&options_.table_flattener_options.collapse_key_stringpool);
+ AddOptionalSwitch("--enable-resource-path-shortening",
+ "Enables shortening of the path of the resources inside the APK.",
+ &options_.shorten_resource_paths);
+ AddOptionalFlag("--resource-path-shortening-map",
+ "Path to output the map of old resource paths to shortened paths.",
+ &options_.shortened_paths_map_path);
AddOptionalSwitch("-v", "Enables verbose logging", &verbose_);
}
@@ -109,6 +121,9 @@
private:
OptimizeOptions options_;
+ bool WriteObfuscatedPathsMap(const std::map<std::string, std::string> &path_map,
+ const std::string &file_path);
+
Maybe<std::string> config_path_;
Maybe<std::string> whitelist_path_;
Maybe<std::string> resources_config_path_;
@@ -122,4 +137,4 @@
}// namespace aapt
-#endif //AAPT2_OPTIMIZE_H
\ No newline at end of file
+#endif //AAPT2_OPTIMIZE_H
diff --git a/tools/aapt2/format/binary/BinaryResourceParser.cpp b/tools/aapt2/format/binary/BinaryResourceParser.cpp
index c496ff0..7d4c6f3 100644
--- a/tools/aapt2/format/binary/BinaryResourceParser.cpp
+++ b/tools/aapt2/format/binary/BinaryResourceParser.cpp
@@ -42,6 +42,19 @@
namespace {
+static std::u16string strcpy16_dtoh(const char16_t* src, size_t len) {
+ size_t utf16_len = strnlen16(src, len);
+ if (utf16_len == 0) {
+ return {};
+ }
+ std::u16string dst;
+ dst.resize(utf16_len);
+ for (size_t i = 0; i < utf16_len; i++) {
+ dst[i] = util::DeviceToHost16(src[i]);
+ }
+ return dst;
+}
+
// Visitor that converts a reference's resource ID to a resource name, given a mapping from
// resource ID to resource name.
class ReferenceIdToNameVisitor : public DescendingValueVisitor {
@@ -176,12 +189,8 @@
}
// Extract the package name.
- size_t len = strnlen16((const char16_t*)package_header->name, arraysize(package_header->name));
- std::u16string package_name;
- package_name.resize(len);
- for (size_t i = 0; i < len; i++) {
- package_name[i] = util::DeviceToHost16(package_header->name[i]);
- }
+ std::u16string package_name = strcpy16_dtoh((const char16_t*)package_header->name,
+ arraysize(package_header->name));
ResourceTablePackage* package =
table_->CreatePackage(util::Utf16ToUtf8(package_name), static_cast<uint8_t>(package_id));
@@ -435,6 +444,11 @@
}
auto overlayable = std::make_shared<Overlayable>();
+ overlayable->name = util::Utf16ToUtf8(strcpy16_dtoh((const char16_t*)header->name,
+ arraysize(header->name)));
+ overlayable->actor = util::Utf16ToUtf8(strcpy16_dtoh((const char16_t*)header->actor,
+ arraysize(header->name)));
+ overlayable->source = source_.WithLine(0);
ResChunkPullParser parser(GetChunkData(chunk),
GetChunkDataLen(chunk));
diff --git a/tools/aapt2/format/binary/TableFlattener.cpp b/tools/aapt2/format/binary/TableFlattener.cpp
index 931d57b..c4ecbaf 100644
--- a/tools/aapt2/format/binary/TableFlattener.cpp
+++ b/tools/aapt2/format/binary/TableFlattener.cpp
@@ -217,9 +217,10 @@
size_t entry_count_ = 0;
};
-struct PolicyChunk {
- uint32_t policy_flags;
- std::set<ResourceId> ids;
+struct OverlayableChunk {
+ std::string actor;
+ Source source;
+ std::map<OverlayableItem::PolicyFlags, std::set<ResourceId>> policy_ids;
};
class PackageFlattener {
@@ -421,8 +422,9 @@
return sorted_entries;
}
- void FlattenOverlayable(BigBuffer* buffer) {
- std::vector<PolicyChunk> policies;
+ bool FlattenOverlayable(BigBuffer* buffer) {
+ std::set<ResourceId> seen_ids;
+ std::map<std::string, OverlayableChunk> overlayable_chunks;
CHECK(bool(package_->id)) << "package must have an ID set when flattening <overlayable>";
for (auto& type : package_->types) {
@@ -433,79 +435,119 @@
continue;
}
- OverlayableItem& overlayable = entry->overlayable_item.value();
- uint32_t policy_flags = OverlayableItem::Policy::kNone;
- if (overlayable.policies & OverlayableItem::Policy::kPublic) {
- policy_flags |= ResTable_overlayable_policy_header::POLICY_PUBLIC;
- }
- if (overlayable.policies & OverlayableItem::Policy::kSystem) {
- policy_flags |= ResTable_overlayable_policy_header::POLICY_SYSTEM_PARTITION;
- }
- if (overlayable.policies & OverlayableItem::Policy::kVendor) {
- policy_flags |= ResTable_overlayable_policy_header::POLICY_VENDOR_PARTITION;
- }
- if (overlayable.policies & OverlayableItem::Policy::kProduct) {
- policy_flags |= ResTable_overlayable_policy_header::POLICY_PRODUCT_PARTITION;
- }
- if (overlayable.policies & OverlayableItem::Policy::kProductServices) {
- policy_flags |= ResTable_overlayable_policy_header::POLICY_PRODUCT_SERVICES_PARTITION;
+ OverlayableItem& item = entry->overlayable_item.value();
+
+ // Resource ids should only appear once in the resource table
+ ResourceId id = android::make_resid(package_->id.value(), type->id.value(),
+ entry->id.value());
+ CHECK(seen_ids.find(id) == seen_ids.end())
+ << "multiple overlayable definitions found for resource "
+ << ResourceName(package_->name, type->type, entry->name).to_string();
+ seen_ids.insert(id);
+
+ // Find the overlayable chunk with the specified name
+ OverlayableChunk* overlayable_chunk = nullptr;
+ auto iter = overlayable_chunks.find(item.overlayable->name);
+ if (iter == overlayable_chunks.end()) {
+ OverlayableChunk chunk{item.overlayable->actor, item.overlayable->source};
+ overlayable_chunk =
+ &overlayable_chunks.insert({item.overlayable->name, chunk}).first->second;
+ } else {
+ OverlayableChunk& chunk = iter->second;
+ if (!(chunk.source == item.overlayable->source)) {
+ // The name of an overlayable set of resources must be unique
+ context_->GetDiagnostics()->Error(DiagMessage(item.overlayable->source)
+ << "duplicate overlayable name"
+ << item.overlayable->name << "'");
+ context_->GetDiagnostics()->Error(DiagMessage(chunk.source)
+ << "previous declaration here");
+ return false;
+ }
+
+ CHECK(chunk.actor == item.overlayable->actor);
+ overlayable_chunk = &chunk;
}
- if (overlayable.policies == OverlayableItem::Policy::kNone) {
+ uint32_t policy_flags = 0;
+ if (item.policies == OverlayableItem::Policy::kNone) {
// Encode overlayable entries defined without a policy as publicly overlayable
policy_flags |= ResTable_overlayable_policy_header::POLICY_PUBLIC;
- }
-
- // Find the overlayable policy chunk with the same policies as the entry
- PolicyChunk* policy_chunk = nullptr;
- for (PolicyChunk& policy : policies) {
- if (policy.policy_flags == policy_flags) {
- policy_chunk = &policy;
- break;
+ } else {
+ if (item.policies & OverlayableItem::Policy::kPublic) {
+ policy_flags |= ResTable_overlayable_policy_header::POLICY_PUBLIC;
+ }
+ if (item.policies & OverlayableItem::Policy::kSystem) {
+ policy_flags |= ResTable_overlayable_policy_header::POLICY_SYSTEM_PARTITION;
+ }
+ if (item.policies & OverlayableItem::Policy::kVendor) {
+ policy_flags |= ResTable_overlayable_policy_header::POLICY_VENDOR_PARTITION;
+ }
+ if (item.policies & OverlayableItem::Policy::kProduct) {
+ policy_flags |= ResTable_overlayable_policy_header::POLICY_PRODUCT_PARTITION;
+ }
+ if (item.policies & OverlayableItem::Policy::kProductServices) {
+ policy_flags |= ResTable_overlayable_policy_header::POLICY_PRODUCT_SERVICES_PARTITION;
}
}
- // Create a new policy chunk if an existing one with the same policy cannot be found
- if (policy_chunk == nullptr) {
- PolicyChunk p;
- p.policy_flags = policy_flags;
- policies.push_back(p);
- policy_chunk = &policies.back();
+ auto policy = overlayable_chunk->policy_ids.find(policy_flags);
+ if (policy != overlayable_chunk->policy_ids.end()) {
+ policy->second.insert(id);
+ } else {
+ overlayable_chunk->policy_ids.insert(
+ std::make_pair(policy_flags, std::set<ResourceId>{id}));
}
-
- policy_chunk->ids.insert(android::make_resid(package_->id.value(), type->id.value(),
- entry->id.value()));
}
}
- if (policies.empty()) {
- // Only write the overlayable chunk if the APK has overlayable entries
- return;
- }
+ for (auto& overlayable_pair : overlayable_chunks) {
+ std::string name = overlayable_pair.first;
+ OverlayableChunk& overlayable = overlayable_pair.second;
- ChunkWriter writer(buffer);
- writer.StartChunk<ResTable_overlayable_header>(RES_TABLE_OVERLAYABLE_TYPE);
-
- // Write each policy block for the overlayable
- for (PolicyChunk& policy : policies) {
- ChunkWriter policy_writer(buffer);
- ResTable_overlayable_policy_header* policy_type =
- policy_writer.StartChunk<ResTable_overlayable_policy_header>(
- RES_TABLE_OVERLAYABLE_POLICY_TYPE);
- policy_type->policy_flags = util::HostToDevice32(policy.policy_flags);
- policy_type->entry_count = util::HostToDevice32(static_cast<uint32_t>(policy.ids.size()));
-
- // Write the ids after the policy header
- ResTable_ref* id_block = policy_writer.NextBlock<ResTable_ref>(policy.ids.size());
- for (const ResourceId& id : policy.ids) {
- id_block->ident = util::HostToDevice32(id.id);
- id_block++;
+ // Write the header of the overlayable chunk
+ ChunkWriter overlayable_writer(buffer);
+ auto* overlayable_type =
+ overlayable_writer.StartChunk<ResTable_overlayable_header>(RES_TABLE_OVERLAYABLE_TYPE);
+ if (name.size() >= arraysize(overlayable_type->name)) {
+ diag_->Error(DiagMessage() << "overlayable name '" << name
+ << "' exceeds maximum length ("
+ << arraysize(overlayable_type->name)
+ << " utf16 characters)");
+ return false;
}
+ strcpy16_htod(overlayable_type->name, arraysize(overlayable_type->name),
+ util::Utf8ToUtf16(name));
- policy_writer.Finish();
+ if (overlayable.actor.size() >= arraysize(overlayable_type->actor)) {
+ diag_->Error(DiagMessage() << "overlayable name '" << overlayable.actor
+ << "' exceeds maximum length ("
+ << arraysize(overlayable_type->actor)
+ << " utf16 characters)");
+ return false;
+ }
+ strcpy16_htod(overlayable_type->actor, arraysize(overlayable_type->actor),
+ util::Utf8ToUtf16(overlayable.actor));
+
+ // Write each policy block for the overlayable
+ for (auto& policy_ids : overlayable.policy_ids) {
+ ChunkWriter policy_writer(buffer);
+ auto* policy_type = policy_writer.StartChunk<ResTable_overlayable_policy_header>(
+ RES_TABLE_OVERLAYABLE_POLICY_TYPE);
+ policy_type->policy_flags = util::HostToDevice32(static_cast<uint32_t>(policy_ids.first));
+ policy_type->entry_count = util::HostToDevice32(static_cast<uint32_t>(
+ policy_ids.second.size()));
+ // Write the ids after the policy header
+ auto* id_block = policy_writer.NextBlock<ResTable_ref>(policy_ids.second.size());
+ for (const ResourceId& id : policy_ids.second) {
+ id_block->ident = util::HostToDevice32(id.id);
+ id_block++;
+ }
+ policy_writer.Finish();
+ }
+ overlayable_writer.Finish();
}
- writer.Finish();
+ return true;
}
bool FlattenTypeSpec(ResourceTableType* type, std::vector<ResourceEntry*>* sorted_entries,
diff --git a/tools/aapt2/format/binary/TableFlattener.h b/tools/aapt2/format/binary/TableFlattener.h
index 635cb21..71330e3 100644
--- a/tools/aapt2/format/binary/TableFlattener.h
+++ b/tools/aapt2/format/binary/TableFlattener.h
@@ -46,6 +46,9 @@
// When true, sort the entries in the values string pool by priority and configuration.
bool sort_stringpool_entries = true;
+
+ // Map from original resource paths to shortened resource paths.
+ std::map<std::string, std::string> shortened_path_map;
};
class TableFlattener : public IResourceTableConsumer {
diff --git a/tools/aapt2/format/binary/TableFlattener_test.cpp b/tools/aapt2/format/binary/TableFlattener_test.cpp
index a5fb6fd..18fecf6 100644
--- a/tools/aapt2/format/binary/TableFlattener_test.cpp
+++ b/tools/aapt2/format/binary/TableFlattener_test.cpp
@@ -657,36 +657,36 @@
TEST_F(TableFlattenerTest, FlattenMultipleOverlayablePolicies) {
auto overlayable = std::make_shared<Overlayable>("TestName", "overlay://theme");
std::string name_zero = "com.app.test:integer/overlayable_zero_item";
- OverlayableItem overlayable_zero_item(overlayable);
- overlayable_zero_item.policies |= OverlayableItem::Policy::kProduct;
- overlayable_zero_item.policies |= OverlayableItem::Policy::kSystem;
- overlayable_zero_item.policies |= OverlayableItem::Policy::kProductServices;
+ OverlayableItem overlayable_item_zero(overlayable);
+ overlayable_item_zero.policies |= OverlayableItem::Policy::kProduct;
+ overlayable_item_zero.policies |= OverlayableItem::Policy::kSystem;
+ overlayable_item_zero.policies |= OverlayableItem::Policy::kProductServices;
std::string name_one = "com.app.test:integer/overlayable_one_item";
- OverlayableItem overlayable_one_item(overlayable);
- overlayable_one_item.policies |= OverlayableItem::Policy::kPublic;
- overlayable_one_item.policies |= OverlayableItem::Policy::kProductServices;
+ OverlayableItem overlayable_item_one(overlayable);
+ overlayable_item_one.policies |= OverlayableItem::Policy::kPublic;
+ overlayable_item_one.policies |= OverlayableItem::Policy::kProductServices;
std::string name_two = "com.app.test:integer/overlayable_two_item";
- OverlayableItem overlayable_two_item(overlayable);
- overlayable_two_item.policies |= OverlayableItem::Policy::kProduct;
- overlayable_two_item.policies |= OverlayableItem::Policy::kSystem;
- overlayable_two_item.policies |= OverlayableItem::Policy::kVendor;
+ OverlayableItem overlayable_item_two(overlayable);
+ overlayable_item_two.policies |= OverlayableItem::Policy::kProduct;
+ overlayable_item_two.policies |= OverlayableItem::Policy::kSystem;
+ overlayable_item_two.policies |= OverlayableItem::Policy::kVendor;
std::string name_three = "com.app.test:integer/overlayable_three_item";
- OverlayableItem overlayable_three_item(overlayable);
+ OverlayableItem overlayable_item_three(overlayable);
std::unique_ptr<ResourceTable> table =
test::ResourceTableBuilder()
.SetPackageId("com.app.test", 0x7f)
.AddSimple(name_zero, ResourceId(0x7f020000))
- .SetOverlayable(name_zero, overlayable_zero_item)
+ .SetOverlayable(name_zero, overlayable_item_zero)
.AddSimple(name_one, ResourceId(0x7f020001))
- .SetOverlayable(name_one, overlayable_one_item)
+ .SetOverlayable(name_one, overlayable_item_one)
.AddSimple(name_two, ResourceId(0x7f020002))
- .SetOverlayable(name_two, overlayable_two_item)
+ .SetOverlayable(name_two, overlayable_item_two)
.AddSimple(name_three, ResourceId(0x7f020003))
- .SetOverlayable(name_three, overlayable_three_item)
+ .SetOverlayable(name_three, overlayable_item_three)
.Build();
ResourceTable output_table;
@@ -724,6 +724,84 @@
ASSERT_TRUE(search_result.value().entry->overlayable_item);
overlayable_item = search_result.value().entry->overlayable_item.value();
EXPECT_EQ(overlayable_item.policies, OverlayableItem::Policy::kPublic);
+ EXPECT_EQ(overlayable_item.overlayable->name, "TestName");
+ EXPECT_EQ(overlayable_item.overlayable->actor, "overlay://theme");
+ EXPECT_EQ(overlayable_item.policies, OverlayableItem::Policy::kPublic);
+}
+
+TEST_F(TableFlattenerTest, FlattenMultipleOverlayable) {
+ auto group = std::make_shared<Overlayable>("TestName", "overlay://theme");
+ std::string name_zero = "com.app.test:integer/overlayable_zero";
+ OverlayableItem overlayable_item_zero(group);
+ overlayable_item_zero.policies |= OverlayableItem::Policy::kProduct;
+ overlayable_item_zero.policies |= OverlayableItem::Policy::kSystem;
+ overlayable_item_zero.policies |= OverlayableItem::Policy::kProductServices;
+
+ auto group_one = std::make_shared<Overlayable>("OtherName", "overlay://customization");
+ std::string name_one = "com.app.test:integer/overlayable_one";
+ OverlayableItem overlayable_item_one(group_one);
+ overlayable_item_one.policies |= OverlayableItem::Policy::kPublic;
+ overlayable_item_one.policies |= OverlayableItem::Policy::kProductServices;
+
+ std::string name_two = "com.app.test:integer/overlayable_two";
+ OverlayableItem overlayable_item_two(group);
+ overlayable_item_two.policies |= OverlayableItem::Policy::kProduct;
+ overlayable_item_two.policies |= OverlayableItem::Policy::kSystem;
+ overlayable_item_two.policies |= OverlayableItem::Policy::kVendor;
+
+ std::string name_three = "com.app.test:integer/overlayable_three";
+ OverlayableItem overlayable_item_three(group_one);
+ std::unique_ptr<ResourceTable> table =
+ test::ResourceTableBuilder()
+ .SetPackageId("com.app.test", 0x7f)
+ .AddSimple(name_zero, ResourceId(0x7f020000))
+ .SetOverlayable(name_zero, overlayable_item_zero)
+ .AddSimple(name_one, ResourceId(0x7f020001))
+ .SetOverlayable(name_one, overlayable_item_one)
+ .AddSimple(name_two, ResourceId(0x7f020002))
+ .SetOverlayable(name_two, overlayable_item_two)
+ .AddSimple(name_three, ResourceId(0x7f020003))
+ .SetOverlayable(name_three, overlayable_item_three)
+ .Build();
+ ResourceTable output_table;
+ ASSERT_TRUE(Flatten(context_.get(), {}, table.get(), &output_table));
+ auto search_result = output_table.FindResource(test::ParseNameOrDie(name_zero));
+ ASSERT_TRUE(search_result);
+ ASSERT_THAT(search_result.value().entry, NotNull());
+ ASSERT_TRUE(search_result.value().entry->overlayable_item);
+ OverlayableItem& result_overlayable = search_result.value().entry->overlayable_item.value();
+ EXPECT_EQ(result_overlayable.overlayable->name, "TestName");
+ EXPECT_EQ(result_overlayable.overlayable->actor, "overlay://theme");
+ EXPECT_EQ(result_overlayable.policies, OverlayableItem::Policy::kSystem
+ | OverlayableItem::Policy::kProduct
+ | OverlayableItem::Policy::kProductServices);
+ search_result = output_table.FindResource(test::ParseNameOrDie(name_one));
+ ASSERT_TRUE(search_result);
+ ASSERT_THAT(search_result.value().entry, NotNull());
+ ASSERT_TRUE(search_result.value().entry->overlayable_item);
+ result_overlayable = search_result.value().entry->overlayable_item.value();
+ EXPECT_EQ(result_overlayable.overlayable->name, "OtherName");
+ EXPECT_EQ(result_overlayable.overlayable->actor, "overlay://customization");
+ EXPECT_EQ(result_overlayable.policies, OverlayableItem::Policy::kPublic
+ | OverlayableItem::Policy::kProductServices);
+ search_result = output_table.FindResource(test::ParseNameOrDie(name_two));
+ ASSERT_TRUE(search_result);
+ ASSERT_THAT(search_result.value().entry, NotNull());
+ ASSERT_TRUE(search_result.value().entry->overlayable_item);
+ result_overlayable = search_result.value().entry->overlayable_item.value();
+ EXPECT_EQ(result_overlayable.overlayable->name, "TestName");
+ EXPECT_EQ(result_overlayable.overlayable->actor, "overlay://theme");
+ EXPECT_EQ(result_overlayable.policies, OverlayableItem::Policy::kSystem
+ | OverlayableItem::Policy::kProduct
+ | OverlayableItem::Policy::kVendor);
+ search_result = output_table.FindResource(test::ParseNameOrDie(name_three));
+ ASSERT_TRUE(search_result);
+ ASSERT_THAT(search_result.value().entry, NotNull());
+ ASSERT_TRUE(search_result.value().entry->overlayable_item);
+ result_overlayable = search_result.value().entry->overlayable_item.value();
+ EXPECT_EQ(result_overlayable.overlayable->name, "OtherName");
+ EXPECT_EQ(result_overlayable.overlayable->actor, "overlay://customization");
+ EXPECT_EQ(result_overlayable.policies, OverlayableItem::Policy::kPublic);
}
} // namespace aapt
diff --git a/tools/aapt2/optimize/ResourcePathShortener.cpp b/tools/aapt2/optimize/ResourcePathShortener.cpp
new file mode 100644
index 0000000..c5df3dd
--- /dev/null
+++ b/tools/aapt2/optimize/ResourcePathShortener.cpp
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "optimize/ResourcePathShortener.h"
+
+#include <math.h>
+#include <unordered_set>
+
+#include "androidfw/StringPiece.h"
+
+#include "ResourceTable.h"
+#include "ValueVisitor.h"
+
+
+static const std::string base64_chars =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789-_";
+
+namespace aapt {
+
+ResourcePathShortener::ResourcePathShortener(
+ std::map<std::string, std::string>& path_map_out)
+ : path_map_(path_map_out) {
+}
+
+std::string ShortenFileName(const android::StringPiece& file_path, int output_length) {
+ std::size_t hash_num = std::hash<android::StringPiece>{}(file_path);
+ std::string result = "";
+ // Convert to (modified) base64 so that it is a proper file path.
+ for (int i = 0; i < output_length; i++) {
+ uint8_t sextet = hash_num & 0x3f;
+ hash_num >>= 6;
+ result += base64_chars[sextet];
+ }
+ return result;
+}
+
+
+// Calculate the optimal hash length such that an average of 10% of resources
+// collide in their shortened path.
+// Reference: http://matt.might.net/articles/counting-hash-collisions/
+int OptimalShortenedLength(int num_resources) {
+ int num_chars = 2;
+ double N = 64*64; // hash space when hash is 2 chars long
+ double max_collisions = num_resources * 0.1;
+ while (num_resources - N + N * pow((N - 1) / N, num_resources) > max_collisions) {
+ N *= 64;
+ num_chars++;
+ }
+ return num_chars;
+}
+
+std::string GetShortenedPath(const android::StringPiece& shortened_filename,
+ const android::StringPiece& extension, int collision_count) {
+ std::string shortened_path = "res/" + shortened_filename.to_string();
+ if (collision_count > 0) {
+ shortened_path += std::to_string(collision_count);
+ }
+ shortened_path += extension;
+ return shortened_path;
+}
+
+bool ResourcePathShortener::Consume(IAaptContext* context, ResourceTable* table) {
+ // used to detect collisions
+ std::unordered_set<std::string> shortened_paths;
+ std::unordered_set<FileReference*> file_refs;
+ for (auto& package : table->packages) {
+ for (auto& type : package->types) {
+ for (auto& entry : type->entries) {
+ for (auto& config_value : entry->values) {
+ FileReference* file_ref = ValueCast<FileReference>(config_value->value.get());
+ if (file_ref) {
+ file_refs.insert(file_ref);
+ }
+ }
+ }
+ }
+ }
+ int num_chars = OptimalShortenedLength(file_refs.size());
+ for (auto& file_ref : file_refs) {
+ android::StringPiece res_subdir, actual_filename, extension;
+ util::ExtractResFilePathParts(*file_ref->path, &res_subdir, &actual_filename, &extension);
+
+ std::string shortened_filename = ShortenFileName(*file_ref->path, num_chars);
+ int collision_count = 0;
+ std::string shortened_path = GetShortenedPath(shortened_filename, extension, collision_count);
+ while (shortened_paths.find(shortened_path) != shortened_paths.end()) {
+ collision_count++;
+ shortened_path = GetShortenedPath(shortened_filename, extension, collision_count);
+ }
+ shortened_paths.insert(shortened_path);
+ path_map_.insert({*file_ref->path, shortened_path});
+ file_ref->path = table->string_pool.MakeRef(shortened_path, file_ref->path.GetContext());
+ }
+ return true;
+}
+
+} // namespace aapt
diff --git a/tools/aapt2/optimize/ResourcePathShortener.h b/tools/aapt2/optimize/ResourcePathShortener.h
new file mode 100644
index 0000000..f1074ef
--- /dev/null
+++ b/tools/aapt2/optimize/ResourcePathShortener.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AAPT_OPTIMIZE_RESOURCEPATHSHORTENER_H
+#define AAPT_OPTIMIZE_RESOURCEPATHSHORTENER_H
+
+#include <map>
+
+#include "android-base/macros.h"
+
+#include "process/IResourceTableConsumer.h"
+
+namespace aapt {
+
+class ResourceTable;
+
+// Maps resources in the apk to shortened paths.
+class ResourcePathShortener : public IResourceTableConsumer {
+ public:
+ explicit ResourcePathShortener(std::map<std::string, std::string>& path_map_out);
+
+ bool Consume(IAaptContext* context, ResourceTable* table) override;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ResourcePathShortener);
+ std::map<std::string, std::string>& path_map_;
+};
+
+} // namespace aapt
+
+#endif // AAPT_OPTIMIZE_RESOURCEPATHSHORTENER_H
diff --git a/tools/aapt2/optimize/ResourcePathShortener_test.cpp b/tools/aapt2/optimize/ResourcePathShortener_test.cpp
new file mode 100644
index 0000000..88cadc7
--- /dev/null
+++ b/tools/aapt2/optimize/ResourcePathShortener_test.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "optimize/ResourcePathShortener.h"
+
+#include "ResourceTable.h"
+#include "test/Test.h"
+
+using ::aapt::test::GetValue;
+using ::testing::Not;
+using ::testing::NotNull;
+using ::testing::Eq;
+
+namespace aapt {
+
+TEST(ResourcePathShortenerTest, FileRefPathsChangedInResourceTable) {
+ std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build();
+
+ std::unique_ptr<ResourceTable> table =
+ test::ResourceTableBuilder()
+ .AddFileReference("android:drawable/xmlfile", "res/drawables/xmlfile.xml")
+ .AddFileReference("android:drawable/xmlfile2", "res/drawables/xmlfile2.xml")
+ .AddString("android:string/string", "res/should/still/be/the/same.png")
+ .Build();
+
+ std::map<std::string, std::string> path_map;
+ ASSERT_TRUE(ResourcePathShortener(path_map).Consume(context.get(), table.get()));
+
+ // Expect that the path map is populated
+ ASSERT_THAT(path_map.find("res/drawables/xmlfile.xml"), Not(Eq(path_map.end())));
+ ASSERT_THAT(path_map.find("res/drawables/xmlfile2.xml"), Not(Eq(path_map.end())));
+
+ // The file paths were changed
+ EXPECT_THAT(path_map.at("res/drawables/xmlfile.xml"), Not(Eq("res/drawables/xmlfile.xml")));
+ EXPECT_THAT(path_map.at("res/drawables/xmlfile2.xml"), Not(Eq("res/drawables/xmlfile2.xml")));
+
+ // Different file paths should remain different
+ EXPECT_THAT(path_map["res/drawables/xmlfile.xml"],
+ Not(Eq(path_map["res/drawables/xmlfile2.xml"])));
+
+ FileReference* ref =
+ GetValue<FileReference>(table.get(), "android:drawable/xmlfile");
+ ASSERT_THAT(ref, NotNull());
+ // The map correctly points to the new location of the file
+ EXPECT_THAT(path_map["res/drawables/xmlfile.xml"], Eq(*ref->path));
+
+ // Strings should not be affected, only file paths
+ EXPECT_THAT(
+ *GetValue<String>(table.get(), "android:string/string")->value,
+ Eq("res/should/still/be/the/same.png"));
+ EXPECT_THAT(path_map.find("res/should/still/be/the/same.png"), Eq(path_map.end()));
+}
+
+} // namespace aapt
diff --git a/tools/apilint/apilint.py b/tools/apilint/apilint.py
index acf1f1e..d1fe43e 100644
--- a/tools/apilint/apilint.py
+++ b/tools/apilint/apilint.py
@@ -297,7 +297,7 @@
class V2LineParser(object):
__slots__ = ["tokenized", "current", "len"]
- MODIFIERS = set("public protected internal private abstract default static final transient volatile synchronized".split())
+ MODIFIERS = set("public protected internal private abstract default static final transient volatile synchronized native operator sealed strictfp infix inline suspend vararg".split())
JAVA_LANG_TYPES = set("AbstractMethodError AbstractStringBuilder Appendable ArithmeticException ArrayIndexOutOfBoundsException ArrayStoreException AssertionError AutoCloseable Boolean BootstrapMethodError Byte Character CharSequence Class ClassCastException ClassCircularityError ClassFormatError ClassLoader ClassNotFoundException Cloneable CloneNotSupportedException Comparable Compiler Deprecated Double Enum EnumConstantNotPresentException Error Exception ExceptionInInitializerError Float FunctionalInterface IllegalAccessError IllegalAccessException IllegalArgumentException IllegalMonitorStateException IllegalStateException IllegalThreadStateException IncompatibleClassChangeError IndexOutOfBoundsException InheritableThreadLocal InstantiationError InstantiationException Integer InternalError InterruptedException Iterable LinkageError Long Math NegativeArraySizeException NoClassDefFoundError NoSuchFieldError NoSuchFieldException NoSuchMethodError NoSuchMethodException NullPointerException Number NumberFormatException Object OutOfMemoryError Override Package package-info.java Process ProcessBuilder ProcessEnvironment ProcessImpl Readable ReflectiveOperationException Runnable Runtime RuntimeException RuntimePermission SafeVarargs SecurityException SecurityManager Short StackOverflowError StackTraceElement StrictMath String StringBuffer StringBuilder StringIndexOutOfBoundsException SuppressWarnings System Thread ThreadDeath ThreadGroup ThreadLocal Throwable TypeNotPresentException UNIXProcess UnknownError UnsatisfiedLinkError UnsupportedClassVersionError UnsupportedOperationException VerifyError VirtualMachineError Void".split())
def __init__(self, raw):
@@ -355,7 +355,7 @@
self.parse_eof()
def parse_into_field(self, field):
- kind = self.parse_token("field")
+ kind = self.parse_one_of("field", "property")
field.split = [kind]
annotations = self.parse_annotations()
if "@Deprecated" in annotations:
@@ -442,13 +442,19 @@
return None
def parse_type(self):
+ self.parse_annotations()
type = self.parse_token()
+ if type[-1] == '.':
+ self.parse_annotations()
+ type += self.parse_token()
if type in V2LineParser.JAVA_LANG_TYPES:
type = "java.lang." + type
self.parse_matching_paren("<", ">")
while True:
t = self.lookahead()
- if t == "[]":
+ if t == "@":
+ self.parse_annotation()
+ elif t == "[]":
type += self.parse_token()
elif self.parse_kotlin_nullability() is not None:
pass # discard nullability for now
@@ -478,17 +484,23 @@
self.parse_token(",")
def parse_arg(self):
+ self.parse_if("vararg") # kotlin vararg
self.parse_annotations()
type = self.parse_arg_type()
l = self.lookahead()
if l != "," and l != ")":
- self.parse_token() # kotlin argument name
+ if self.lookahead() != '=':
+ self.parse_token() # kotlin argument name
if self.parse_if('='): # kotlin default value
- (self.parse_matching_paren('(', ')') or
- self.parse_matching_paren('{', '}') or
- self.parse_token() and self.parse_matching_paren('(', ')'))
+ self.parse_expression()
return type
+ def parse_expression(self):
+ while not self.lookahead() in [')', ',', ';']:
+ (self.parse_matching_paren('(', ')') or
+ self.parse_matching_paren('{', '}') or
+ self.parse_token())
+
def parse_throws(self):
ret = []
if self.parse_if("throws"):
@@ -516,7 +528,7 @@
def parse_annotation_default(self):
if self.parse_if("default"):
- self.parse_value()
+ self.parse_expression()
def parse_value(self):
if self.lookahead() == "{":
@@ -599,7 +611,7 @@
clazz.ctors.append(Method(clazz, line, raw, blame, sig_format=sig_format))
elif raw.startswith(" method"):
clazz.methods.append(Method(clazz, line, raw, blame, sig_format=sig_format))
- elif raw.startswith(" field"):
+ elif raw.startswith(" field") or raw.startswith(" property"):
clazz.fields.append(Field(clazz, line, raw, blame, sig_format=sig_format))
elif raw.startswith(" }") and clazz:
yield clazz
@@ -942,7 +954,7 @@
else:
error(clazz, f, "F2", "Bare fields must be marked final, or add accessors if mutable")
- if not "static" in f.split:
+ if "static" not in f.split and "property" not in f.split:
if not re.match("[a-z]([a-zA-Z]+)?", f.name):
error(clazz, f, "S1", "Non-static fields must be named using myField style")
@@ -1650,7 +1662,7 @@
binary.add(op)
for m in clazz.methods:
- if 'static' in m.split:
+ if 'static' in m.split or 'operator' in m.split:
continue
# https://kotlinlang.org/docs/reference/operator-overloading.html#unary-prefix-operators
diff --git a/tools/apilint/apilint_test.py b/tools/apilint/apilint_test.py
index 081e98d..fde61a9 100644
--- a/tools/apilint/apilint_test.py
+++ b/tools/apilint/apilint_test.py
@@ -225,11 +225,12 @@
self.assertEquals('pkg.SuppressLint', cls.fullname)
def test_parse_method(self):
- m = self._method("method @Deprecated public static <T> Class<T>[][] name("
+ m = self._method("method @Deprecated public static native <T> Class<T>[][] name("
+ "Class<T[]>[][], Class<T[][][]>[][]...) throws Exception, T;")
self.assertTrue('static' in m.split)
self.assertTrue('public' in m.split)
self.assertTrue('method' in m.split)
+ self.assertTrue('native' in m.split)
self.assertTrue('deprecated' in m.split)
self.assertEquals('java.lang.Class[][]', m.typ)
self.assertEquals('name', m.name)
@@ -248,6 +249,7 @@
self._method('method abstract String category() default "";', cls=cls)
self._method('method abstract boolean deepExport() default false;', cls=cls)
self._method('method abstract ViewDebug.FlagToString[] flagMapping() default {};', cls=cls)
+ self._method('method abstract ViewDebug.FlagToString[] flagMapping() default (double)java.lang.Float.NEGATIVE_INFINITY;', cls=cls)
def test_parse_string_field(self):
f = self._field('field @Deprecated public final String SOME_NAME = "value";')
@@ -286,5 +288,44 @@
self._method("method <T> T name(T a = 1, T b = A(1), Lambda f = { false }, N? n = null, "
+ """double c = (1/0), float d = 1.0f, String s = "heyo", char c = 'a');""")
+ def test_kotlin_operator(self):
+ self._method('method public operator void unaryPlus(androidx.navigation.NavDestination);')
+ self._method('method public static operator androidx.navigation.NavDestination get(androidx.navigation.NavGraph, @IdRes int id);')
+ self._method('method public static operator <T> T get(androidx.navigation.NavigatorProvider, kotlin.reflect.KClass<T> clazz);')
+
+ def test_kotlin_property(self):
+ self._field('property public VM value;')
+ self._field('property public final String? action;')
+
+ def test_kotlin_varargs(self):
+ self._method('method public void error(int p = "42", Integer int2 = "null", int p1 = "42", vararg String args);')
+
+ def test_kotlin_default_values(self):
+ self._method('method public void foo(String! = null, String! = "Hello World", int = 42);')
+ self._method('method void method(String, String firstArg = "hello", int secondArg = "42", String thirdArg = "world");')
+ self._method('method void method(String, String firstArg = "hello", int secondArg = "42");')
+ self._method('method void method(String, String firstArg = "hello");')
+ self._method('method void edit(android.Type, boolean commit = false, Function1<? super Editor,kotlin.Unit> action);')
+ self._method('method <K, V> LruCache<K,V> lruCache(int maxSize, Function2<? super K,? super V,java.lang.Integer> sizeOf = { _, _ -> 1 }, Function1<? extends V> create = { (V)null }, Function4<kotlin.Unit> onEntryRemoved = { _, _, _, _ -> });')
+ self._method('method android.Bitmap? drawToBitmap(android.View, android.Config config = android.graphics.Bitmap.Config.ARGB_8888);')
+ self._method('method void emptyLambda(Function0<kotlin.Unit> sizeOf = {});')
+ self._method('method void method1(int p = 42, Integer? int2 = null, int p1 = 42, String str = "hello world", java.lang.String... args);')
+ self._method('method void method2(int p, int int2 = (2 * int) * some.other.pkg.Constants.Misc.SIZE);')
+ self._method('method void method3(String str, int p, int int2 = double(int) + str.length);')
+ self._method('method void print(test.pkg.Foo foo = test.pkg.Foo());')
+
+ def test_type_use_annotation(self):
+ self._method('method public static int codePointAt(char @NonNull [], int);')
+ self._method('method @NonNull public java.util.Set<java.util.Map.@NonNull Entry<K,V>> entrySet();')
+
+ m = self._method('method @NonNull public java.lang.annotation.@NonNull Annotation @NonNull [] getAnnotations();')
+ self.assertEquals('java.lang.annotation.Annotation[]', m.typ)
+
+ m = self._method('method @NonNull public abstract java.lang.annotation.@NonNull Annotation @NonNull [] @NonNull [] getParameterAnnotations();')
+ self.assertEquals('java.lang.annotation.Annotation[][]', m.typ)
+
+ m = self._method('method @NonNull public @NonNull String @NonNull [] split(@NonNull String, int);')
+ self.assertEquals('java.lang.String[]', m.typ)
+
if __name__ == "__main__":
unittest.main()
diff --git a/tools/signedconfig/prod_public.pem b/tools/signedconfig/prod_public.pem
new file mode 100644
index 0000000..8c10215
--- /dev/null
+++ b/tools/signedconfig/prod_public.pem
@@ -0,0 +1,5 @@
+-----BEGIN PUBLIC KEY-----
+MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE+lky6wKyGL6lE1VrD0YTMHwb0Xwc
++tzC8MvnrzVxodvTpVY/jV7V+Zktcx+pry43XPABFRXtbhTo+qykhyBA1g==
+-----END PUBLIC KEY-----
+
diff --git a/tools/signedconfig/verify_b64.sh b/tools/signedconfig/verify_b64.sh
index 8e1f58c..a4ac6a8 100755
--- a/tools/signedconfig/verify_b64.sh
+++ b/tools/signedconfig/verify_b64.sh
@@ -7,4 +7,30 @@
# The arg values can be taken from the debug log for SignedConfigService when verbose logging is
# enabled.
-openssl dgst -sha256 -verify $(dirname $0)/debug_public.pem -signature <(echo $2 | base64 -d) <(echo $1 | base64 -d)
+function verify() {
+ D=${1}
+ S=${2}
+ K=${3}
+ echo Trying ${K}
+ openssl dgst -sha256 -verify $(dirname $0)/${K} -signature <(echo ${S} | base64 -d) <(echo ${D} | base64 -d)
+}
+
+
+PROD_KEY_NAME=prod_public.pem
+DEBUG_KEY_NAME=debug_public.pem
+SIGNATURE="$2"
+DATA="$1"
+
+echo DATA: ${DATA}
+echo SIGNATURE: ${SIGNATURE}
+
+if verify "${DATA}" "${SIGNATURE}" "${PROD_KEY_NAME}"; then
+ echo Verified with ${PROD_KEY_NAME}
+ exit 0
+fi
+
+if verify "${DATA}" "${SIGNATURE}" "${DEBUG_KEY_NAME}"; then
+ echo Verified with ${DEBUG_KEY_NAME}
+ exit 0
+fi
+exit 1
diff --git a/wifi/java/android/net/wifi/DppStatusCallback.java b/wifi/java/android/net/wifi/DppStatusCallback.java
deleted file mode 100644
index fa2ab30..0000000
--- a/wifi/java/android/net/wifi/DppStatusCallback.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.net.wifi;
-
-import android.annotation.IntDef;
-import android.annotation.SystemApi;
-import android.os.Handler;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-/**
- * DPP Status Callback. Use this callback to get status updates (success, failure, progress)
- * from the DPP operation started with {@link WifiManager#startDppAsConfiguratorInitiator(String,
- * int, int, Handler, DppStatusCallback)} or {@link WifiManager#startDppAsEnrolleeInitiator(String,
- * Handler, DppStatusCallback)}
- * @hide
- */
-@SystemApi
-public abstract class DppStatusCallback {
- /**
- * DPP Success event: Configuration sent (Configurator mode).
- */
- public static final int DPP_EVENT_SUCCESS_CONFIGURATION_SENT = 0;
-
- /** @hide */
- @IntDef(prefix = { "DPP_EVENT_SUCCESS_" }, value = {
- DPP_EVENT_SUCCESS_CONFIGURATION_SENT,
- })
- @Retention(RetentionPolicy.SOURCE)
- public @interface DppSuccessStatusCode {}
-
- /**
- * DPP Progress event: Initial authentication with peer succeeded.
- */
- public static final int DPP_EVENT_PROGRESS_AUTHENTICATION_SUCCESS = 0;
-
- /**
- * DPP Progress event: Peer requires more time to process bootstrapping.
- */
- public static final int DPP_EVENT_PROGRESS_RESPONSE_PENDING = 1;
-
- /** @hide */
- @IntDef(prefix = { "DPP_EVENT_PROGRESS_" }, value = {
- DPP_EVENT_PROGRESS_AUTHENTICATION_SUCCESS,
- DPP_EVENT_PROGRESS_RESPONSE_PENDING,
- })
- @Retention(RetentionPolicy.SOURCE)
- public @interface DppProgressStatusCode {}
-
- /**
- * DPP Failure event: Scanned QR code is either not a DPP URI, or the DPP URI has errors.
- */
- public static final int DPP_EVENT_FAILURE_INVALID_URI = -1;
-
- /**
- * DPP Failure event: Bootstrapping/Authentication initialization process failure.
- */
- public static final int DPP_EVENT_FAILURE_AUTHENTICATION = -2;
-
- /**
- * DPP Failure event: Both devices are implementing the same role and are incompatible.
- */
- public static final int DPP_EVENT_FAILURE_NOT_COMPATIBLE = -3;
-
- /**
- * DPP Failure event: Configuration process has failed due to malformed message.
- */
- public static final int DPP_EVENT_FAILURE_CONFIGURATION = -4;
-
- /**
- * DPP Failure event: DPP request while in another DPP exchange.
- */
- public static final int DPP_EVENT_FAILURE_BUSY = -5;
-
- /**
- * DPP Failure event: No response from the peer.
- */
- public static final int DPP_EVENT_FAILURE_TIMEOUT = -6;
-
- /**
- * DPP Failure event: General protocol failure.
- */
- public static final int DPP_EVENT_FAILURE = -7;
-
- /**
- * DPP Failure event: Feature or option is not supported.
- */
- public static final int DPP_EVENT_FAILURE_NOT_SUPPORTED = -8;
-
- /**
- * DPP Failure event: Invalid network provided to DPP configurator.
- * Network must either be WPA3-Personal (SAE) or WPA2-Personal (PSK).
- */
- public static final int DPP_EVENT_FAILURE_INVALID_NETWORK = -9;
-
-
- /** @hide */
- @IntDef(prefix = {"DPP_EVENT_FAILURE_"}, value = {
- DPP_EVENT_FAILURE_INVALID_URI,
- DPP_EVENT_FAILURE_AUTHENTICATION,
- DPP_EVENT_FAILURE_NOT_COMPATIBLE,
- DPP_EVENT_FAILURE_CONFIGURATION,
- DPP_EVENT_FAILURE_BUSY,
- DPP_EVENT_FAILURE_TIMEOUT,
- DPP_EVENT_FAILURE,
- DPP_EVENT_FAILURE_NOT_SUPPORTED,
- DPP_EVENT_FAILURE_INVALID_NETWORK,
- })
- @Retention(RetentionPolicy.SOURCE)
- public @interface DppFailureStatusCode {
- }
-
- /**
- * Called when local DPP Enrollee successfully receives a new Wi-Fi configuration from the
- * peer DPP configurator. This callback marks the successful end of the DPP current DPP
- * session, and no further callbacks will be called. This callback is the successful outcome
- * of a DPP flow starting with {@link WifiManager#startDppAsEnrolleeInitiator(String, Handler,
- * DppStatusCallback)}.
- *
- * @param newNetworkId New Wi-Fi configuration with a network ID received from the configurator
- */
- public abstract void onEnrolleeSuccess(int newNetworkId);
-
- /**
- * Called when a DPP success event takes place, except for when configuration is received from
- * an external Configurator. The callback onSuccessConfigReceived will be used in this case.
- * This callback marks the successful end of the current DPP session, and no further
- * callbacks will be called. This callback is the successful outcome of a DPP flow starting with
- * {@link WifiManager#startDppAsConfiguratorInitiator(String, int, int, Handler,
- * DppStatusCallback)}.
- *
- * @param code DPP success status code.
- */
- public abstract void onConfiguratorSuccess(@DppSuccessStatusCode int code);
-
- /**
- * Called when a DPP Failure event takes place. This callback marks the unsuccessful end of the
- * current DPP session, and no further callbacks will be called.
- *
- * @param code DPP failure status code.
- */
- public abstract void onFailure(@DppFailureStatusCode int code);
-
- /**
- * Called when DPP events that indicate progress take place. Can be used by UI elements
- * to show progress.
- *
- * @param code DPP progress status code.
- */
- public abstract void onProgress(@DppProgressStatusCode int code);
-}
diff --git a/wifi/java/android/net/wifi/EasyConnectStatusCallback.java b/wifi/java/android/net/wifi/EasyConnectStatusCallback.java
new file mode 100644
index 0000000..3b4a6cd
--- /dev/null
+++ b/wifi/java/android/net/wifi/EasyConnectStatusCallback.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi;
+
+import android.annotation.IntDef;
+import android.annotation.SystemApi;
+import android.os.Handler;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Easy Connect (DPP) Status Callback. Use this callback to get status updates (success, failure,
+ * progress) from the Easy Connect operation started with
+ * {@link WifiManager#startEasyConnectAsConfiguratorInitiator(String,
+ * int, int, Handler, EasyConnectStatusCallback)} or
+ * {@link WifiManager#startEasyConnectAsEnrolleeInitiator(String,
+ * Handler, EasyConnectStatusCallback)}
+ *
+ * @hide
+ */
+@SystemApi
+public abstract class EasyConnectStatusCallback {
+ /**
+ * Easy Connect Success event: Configuration sent (Configurator mode).
+ */
+ public static final int EASY_CONNECT_EVENT_SUCCESS_CONFIGURATION_SENT = 0;
+
+ /** @hide */
+ @IntDef(prefix = {"EASY_CONNECT_EVENT_SUCCESS_"}, value = {
+ EASY_CONNECT_EVENT_SUCCESS_CONFIGURATION_SENT,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface EasyConnectSuccessStatusCode {
+ }
+
+ /**
+ * Easy Connect Progress event: Initial authentication with peer succeeded.
+ */
+ public static final int EASY_CONNECT_EVENT_PROGRESS_AUTHENTICATION_SUCCESS = 0;
+
+ /**
+ * Easy Connect Progress event: Peer requires more time to process bootstrapping.
+ */
+ public static final int EASY_CONNECT_EVENT_PROGRESS_RESPONSE_PENDING = 1;
+
+ /** @hide */
+ @IntDef(prefix = {"EASY_CONNECT_EVENT_PROGRESS_"}, value = {
+ EASY_CONNECT_EVENT_PROGRESS_AUTHENTICATION_SUCCESS,
+ EASY_CONNECT_EVENT_PROGRESS_RESPONSE_PENDING,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface EasyConnectProgressStatusCode {
+ }
+
+ /**
+ * Easy Connect Failure event: Scanned QR code is either not a Easy Connect URI, or the Easy
+ * Connect URI has errors.
+ */
+ public static final int EASY_CONNECT_EVENT_FAILURE_INVALID_URI = -1;
+
+ /**
+ * Easy Connect Failure event: Bootstrapping/Authentication initialization process failure.
+ */
+ public static final int EASY_CONNECT_EVENT_FAILURE_AUTHENTICATION = -2;
+
+ /**
+ * Easy Connect Failure event: Both devices are implementing the same role and are incompatible.
+ */
+ public static final int EASY_CONNECT_EVENT_FAILURE_NOT_COMPATIBLE = -3;
+
+ /**
+ * Easy Connect Failure event: Configuration process has failed due to malformed message.
+ */
+ public static final int EASY_CONNECT_EVENT_FAILURE_CONFIGURATION = -4;
+
+ /**
+ * Easy Connect Failure event: Easy Connect request while in another Easy Connect exchange.
+ */
+ public static final int EASY_CONNECT_EVENT_FAILURE_BUSY = -5;
+
+ /**
+ * Easy Connect Failure event: No response from the peer.
+ */
+ public static final int EASY_CONNECT_EVENT_FAILURE_TIMEOUT = -6;
+
+ /**
+ * Easy Connect Failure event: General protocol failure.
+ */
+ public static final int EASY_CONNECT_EVENT_FAILURE = -7;
+
+ /**
+ * Easy Connect Failure event: Feature or option is not supported.
+ */
+ public static final int EASY_CONNECT_EVENT_FAILURE_NOT_SUPPORTED = -8;
+
+ /**
+ * Easy Connect Failure event: Invalid network provided to Easy Connect configurator.
+ * Network must either be WPA3-Personal (SAE) or WPA2-Personal (PSK).
+ */
+ public static final int EASY_CONNECT_EVENT_FAILURE_INVALID_NETWORK = -9;
+
+
+ /** @hide */
+ @IntDef(prefix = {"EASY_CONNECT_EVENT_FAILURE_"}, value = {
+ EASY_CONNECT_EVENT_FAILURE_INVALID_URI,
+ EASY_CONNECT_EVENT_FAILURE_AUTHENTICATION,
+ EASY_CONNECT_EVENT_FAILURE_NOT_COMPATIBLE,
+ EASY_CONNECT_EVENT_FAILURE_CONFIGURATION,
+ EASY_CONNECT_EVENT_FAILURE_BUSY,
+ EASY_CONNECT_EVENT_FAILURE_TIMEOUT,
+ EASY_CONNECT_EVENT_FAILURE,
+ EASY_CONNECT_EVENT_FAILURE_NOT_SUPPORTED,
+ EASY_CONNECT_EVENT_FAILURE_INVALID_NETWORK,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface EasyConnectFailureStatusCode {
+ }
+
+ /**
+ * Called when local Easy Connect Enrollee successfully receives a new Wi-Fi configuration from
+ * the
+ * peer Easy Connect configurator. This callback marks the successful end of the Easy Connect
+ * current Easy Connect
+ * session, and no further callbacks will be called. This callback is the successful outcome
+ * of a Easy Connect flow starting with
+ * {@link WifiManager#startEasyConnectAsEnrolleeInitiator(String,
+ * Handler,
+ * EasyConnectStatusCallback)}.
+ *
+ * @param newNetworkId New Wi-Fi configuration with a network ID received from the configurator
+ */
+ public abstract void onEnrolleeSuccess(int newNetworkId);
+
+ /**
+ * Called when a Easy Connect success event takes place, except for when configuration is
+ * received from
+ * an external Configurator. The callback onSuccessConfigReceived will be used in this case.
+ * This callback marks the successful end of the current Easy Connect session, and no further
+ * callbacks will be called. This callback is the successful outcome of a Easy Connect flow
+ * starting with
+ * {@link WifiManager#startEasyConnectAsConfiguratorInitiator(String, int, int, Handler,
+ * EasyConnectStatusCallback)}.
+ *
+ * @param code Easy Connect success status code.
+ */
+ public abstract void onConfiguratorSuccess(@EasyConnectSuccessStatusCode int code);
+
+ /**
+ * Called when a Easy Connect Failure event takes place. This callback marks the unsuccessful
+ * end of the
+ * current Easy Connect session, and no further callbacks will be called.
+ *
+ * @param code Easy Connect failure status code.
+ */
+ public abstract void onFailure(@EasyConnectFailureStatusCode int code);
+
+ /**
+ * Called when Easy Connect events that indicate progress take place. Can be used by UI elements
+ * to show progress.
+ *
+ * @param code Easy Connect progress status code.
+ */
+ public abstract void onProgress(@EasyConnectProgressStatusCode int code);
+}
diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java
index 28dd9b4..85871fe 100644
--- a/wifi/java/android/net/wifi/WifiConfiguration.java
+++ b/wifi/java/android/net/wifi/WifiConfiguration.java
@@ -1886,6 +1886,7 @@
if (creatorName != null) sbuf.append(" cname=" + creatorName);
if (lastUpdateUid != 0) sbuf.append(" luid=" + lastUpdateUid);
if (lastUpdateName != null) sbuf.append(" lname=" + lastUpdateName);
+ if (updateIdentifier != null) sbuf.append(" updateIdentifier=" + updateIdentifier);
sbuf.append(" lcuid=" + lastConnectUid);
sbuf.append(" userApproved=" + userApprovedAsString(userApproved));
sbuf.append(" noInternetAccessExpected=" + noInternetAccessExpected);
@@ -2281,6 +2282,7 @@
mRandomizedMacAddress = source.mRandomizedMacAddress;
macRandomizationSetting = source.macRandomizationSetting;
requirePMF = source.requirePMF;
+ updateIdentifier = source.updateIdentifier;
}
}
diff --git a/wifi/java/android/net/wifi/WifiInfo.java b/wifi/java/android/net/wifi/WifiInfo.java
index af5ad51..840af5d 100644
--- a/wifi/java/android/net/wifi/WifiInfo.java
+++ b/wifi/java/android/net/wifi/WifiInfo.java
@@ -93,12 +93,22 @@
private int mRssi;
/**
- * Link speed in Mbps
+ * The unit in which links speeds are expressed.
*/
public static final String LINK_SPEED_UNITS = "Mbps";
private int mLinkSpeed;
/**
+ * Tx(transmit) Link speed in Mbps
+ */
+ private int mTxLinkSpeed;
+
+ /**
+ * Rx(receive) Link speed in Mbps
+ */
+ private int mRxLinkSpeed;
+
+ /**
* Frequency in MHz
*/
public static final String FREQUENCY_UNITS = "MHz";
@@ -192,6 +202,8 @@
setNetworkId(-1);
setRssi(INVALID_RSSI);
setLinkSpeed(-1);
+ setTxLinkSpeedMbps(-1);
+ setRxLinkSpeedMbps(-1);
setFrequency(-1);
setMeteredHint(false);
setEphemeral(false);
@@ -219,6 +231,8 @@
mNetworkId = source.mNetworkId;
mRssi = source.mRssi;
mLinkSpeed = source.mLinkSpeed;
+ mTxLinkSpeed = source.mTxLinkSpeed;
+ mRxLinkSpeed = source.mRxLinkSpeed;
mFrequency = source.mFrequency;
mIpAddress = source.mIpAddress;
mMacAddress = source.mMacAddress;
@@ -313,7 +327,7 @@
/**
* Returns the current link speed in {@link #LINK_SPEED_UNITS}.
- * @return the link speed.
+ * @return the link speed or -1 if there is no valid value.
* @see #LINK_SPEED_UNITS
*/
public int getLinkSpeed() {
@@ -323,7 +337,39 @@
/** @hide */
@UnsupportedAppUsage
public void setLinkSpeed(int linkSpeed) {
- this.mLinkSpeed = linkSpeed;
+ mLinkSpeed = linkSpeed;
+ }
+
+ /**
+ * Returns the current transmit link speed in Mbps.
+ * @return the Tx link speed or -1 if there is no valid value.
+ */
+ public int getTxLinkSpeedMbps() {
+ return mTxLinkSpeed;
+ }
+
+ /**
+ * Update the last transmitted packet bit rate in Mbps.
+ * @hide
+ */
+ public void setTxLinkSpeedMbps(int txLinkSpeed) {
+ mTxLinkSpeed = txLinkSpeed;
+ }
+
+ /**
+ * Returns the current receive link speed in Mbps.
+ * @return the Rx link speed or -1 if there is no valid value.
+ */
+ public int getRxLinkSpeedMbps() {
+ return mRxLinkSpeed;
+ }
+
+ /**
+ * Update the last received packet bit rate in Mbps.
+ * @hide
+ */
+ public void setRxLinkSpeedMbps(int rxLinkSpeed) {
+ mRxLinkSpeed = rxLinkSpeed;
}
/**
@@ -529,17 +575,19 @@
StringBuffer sb = new StringBuffer();
String none = "<none>";
- sb.append("SSID: ").append(mWifiSsid == null ? WifiSsid.NONE : mWifiSsid).
- append(", BSSID: ").append(mBSSID == null ? none : mBSSID).
- append(", MAC: ").append(mMacAddress == null ? none : mMacAddress).
- append(", Supplicant state: ").
- append(mSupplicantState == null ? none : mSupplicantState).
- append(", RSSI: ").append(mRssi).
- append(", Link speed: ").append(mLinkSpeed).append(LINK_SPEED_UNITS).
- append(", Frequency: ").append(mFrequency).append(FREQUENCY_UNITS).
- append(", Net ID: ").append(mNetworkId).
- append(", Metered hint: ").append(mMeteredHint).
- append(", score: ").append(Integer.toString(score));
+ sb.append("SSID: ").append(mWifiSsid == null ? WifiSsid.NONE : mWifiSsid)
+ .append(", BSSID: ").append(mBSSID == null ? none : mBSSID)
+ .append(", MAC: ").append(mMacAddress == null ? none : mMacAddress)
+ .append(", Supplicant state: ")
+ .append(mSupplicantState == null ? none : mSupplicantState)
+ .append(", RSSI: ").append(mRssi)
+ .append(", Link speed: ").append(mLinkSpeed).append(LINK_SPEED_UNITS)
+ .append(", Tx Link speed: ").append(mTxLinkSpeed).append(LINK_SPEED_UNITS)
+ .append(", Rx Link speed: ").append(mRxLinkSpeed).append(LINK_SPEED_UNITS)
+ .append(", Frequency: ").append(mFrequency).append(FREQUENCY_UNITS)
+ .append(", Net ID: ").append(mNetworkId)
+ .append(", Metered hint: ").append(mMeteredHint)
+ .append(", score: ").append(Integer.toString(score));
return sb.toString();
}
@@ -553,6 +601,8 @@
dest.writeInt(mNetworkId);
dest.writeInt(mRssi);
dest.writeInt(mLinkSpeed);
+ dest.writeInt(mTxLinkSpeed);
+ dest.writeInt(mRxLinkSpeed);
dest.writeInt(mFrequency);
if (mIpAddress != null) {
dest.writeByte((byte)1);
@@ -593,6 +643,8 @@
info.setNetworkId(in.readInt());
info.setRssi(in.readInt());
info.setLinkSpeed(in.readInt());
+ info.setTxLinkSpeedMbps(in.readInt());
+ info.setRxLinkSpeedMbps(in.readInt());
info.setFrequency(in.readInt());
if (in.readByte() == 1) {
try {
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index 517bf3b..559f4ad 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -4586,93 +4586,100 @@
}
}
- /* DPP - Device Provisioning Protocol AKA "Easy Connect" */
+ /* Easy Connect - AKA Device Provisioning Protocol (DPP) */
/**
- * DPP Network role: Station.
+ * Easy Connect Network role: Station.
+ *
* @hide
*/
@SystemApi
- public static final int DPP_NETWORK_ROLE_STA = 0;
+ public static final int EASY_CONNECT_NETWORK_ROLE_STA = 0;
/**
- * DPP Network role: Access Point.
+ * Easy Connect Network role: Access Point.
+ *
* @hide
*/
@SystemApi
- public static final int DPP_NETWORK_ROLE_AP = 1;
+ public static final int EASY_CONNECT_NETWORK_ROLE_AP = 1;
/** @hide */
- @IntDef(prefix = {"DPP_NETWORK_ROLE_"}, value = {
- DPP_NETWORK_ROLE_STA,
- DPP_NETWORK_ROLE_AP,
+ @IntDef(prefix = {"EASY_CONNECT_NETWORK_ROLE_"}, value = {
+ EASY_CONNECT_NETWORK_ROLE_STA,
+ EASY_CONNECT_NETWORK_ROLE_AP,
})
@Retention(RetentionPolicy.SOURCE)
- public @interface DppNetworkRole {}
+ public @interface EasyConnectNetworkRole {
+ }
/**
- * Start DPP in Configurator-Initiator role. The current device will initiate DPP bootstrapping
- * with a peer, and configure the peer with the SSID and password of the specified network using
- * the DPP protocol on an encrypted link.
+ * Start Easy Connect (DPP) in Configurator-Initiator role. The current device will initiate
+ * Easy Connect bootstrapping with a peer, and configure the peer with the SSID and password of
+ * the specified network using the Easy Connect protocol on an encrypted link.
*
- * @param enrolleeUri URI of the Enrollee obtained separately (e.g. QR code scanning)
- * @param selectedNetworkId Selected network ID to be sent to the peer
+ * @param enrolleeUri URI of the Enrollee obtained separately (e.g. QR code scanning)
+ * @param selectedNetworkId Selected network ID to be sent to the peer
* @param enrolleeNetworkRole The network role of the enrollee
- * @param callback Callback for status updates
- * @param handler The handler on whose thread to execute the callbacks. Null for main thread.
+ * @param callback Callback for status updates
+ * @param handler The handler on whose thread to execute the callbacks. Null for
+ * main thread.
* @hide
*/
@SystemApi
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_SETUP_WIZARD})
- public void startDppAsConfiguratorInitiator(@NonNull String enrolleeUri,
- int selectedNetworkId, @DppNetworkRole int enrolleeNetworkRole,
- @Nullable Handler handler, @NonNull DppStatusCallback callback) {
+ public void startEasyConnectAsConfiguratorInitiator(@NonNull String enrolleeUri,
+ int selectedNetworkId, @EasyConnectNetworkRole int enrolleeNetworkRole,
+ @Nullable Handler handler, @NonNull EasyConnectStatusCallback callback) {
Looper looper = (handler == null) ? Looper.getMainLooper() : handler.getLooper();
Binder binder = new Binder();
try {
mService.startDppAsConfiguratorInitiator(binder, enrolleeUri, selectedNetworkId,
- enrolleeNetworkRole, new DppCallbackProxy(looper, callback));
+ enrolleeNetworkRole, new EasyConnectCallbackProxy(looper, callback));
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
- * Start DPP in Enrollee-Initiator role. The current device will initiate DPP bootstrapping
- * with a peer, and receive the SSID and password from the peer configurator.
+ * Start Easy Connect (DPP) in Enrollee-Initiator role. The current device will initiate Easy
+ * Connect bootstrapping with a peer, and receive the SSID and password from the peer
+ * configurator.
*
* @param configuratorUri URI of the Configurator obtained separately (e.g. QR code scanning)
- * @param callback Callback for status updates
- * @param handler The handler on whose thread to execute the callbacks. Null for main thread.
+ * @param callback Callback for status updates
+ * @param handler The handler on whose thread to execute the callbacks. Null for main
+ * thread.
* @hide
*/
@SystemApi
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_SETUP_WIZARD})
- public void startDppAsEnrolleeInitiator(@NonNull String configuratorUri,
- @Nullable Handler handler, @NonNull DppStatusCallback callback) {
+ public void startEasyConnectAsEnrolleeInitiator(@NonNull String configuratorUri,
+ @Nullable Handler handler, @NonNull EasyConnectStatusCallback callback) {
Looper looper = (handler == null) ? Looper.getMainLooper() : handler.getLooper();
Binder binder = new Binder();
try {
mService.startDppAsEnrolleeInitiator(binder, configuratorUri,
- new DppCallbackProxy(looper, callback));
+ new EasyConnectCallbackProxy(looper, callback));
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
- * Stop or abort a current DPP session.
+ * Stop or abort a current Easy Connect (DPP) session.
+ *
* @hide
*/
@SystemApi
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_SETUP_WIZARD})
- public void stopDppSession() {
+ public void stopEasyConnectSession() {
try {
/* Request lower layers to stop/abort and clear resources */
mService.stopDppSession();
@@ -4682,48 +4689,50 @@
}
/**
- * Helper class to support DPP callbacks
+ * Helper class to support Easy Connect (DPP) callbacks
+ *
* @hide
*/
@SystemApi
- private static class DppCallbackProxy extends IDppCallback.Stub {
+ private static class EasyConnectCallbackProxy extends IDppCallback.Stub {
private final Handler mHandler;
- private final DppStatusCallback mDppStatusCallback;
+ private final EasyConnectStatusCallback mEasyConnectStatusCallback;
- DppCallbackProxy(Looper looper, DppStatusCallback dppStatusCallback) {
+ EasyConnectCallbackProxy(Looper looper,
+ EasyConnectStatusCallback easyConnectStatusCallback) {
mHandler = new Handler(looper);
- mDppStatusCallback = dppStatusCallback;
+ mEasyConnectStatusCallback = easyConnectStatusCallback;
}
@Override
public void onSuccessConfigReceived(int newNetworkId) {
- Log.d(TAG, "DPP onSuccessConfigReceived callback");
+ Log.d(TAG, "Easy Connect onSuccessConfigReceived callback");
mHandler.post(() -> {
- mDppStatusCallback.onEnrolleeSuccess(newNetworkId);
+ mEasyConnectStatusCallback.onEnrolleeSuccess(newNetworkId);
});
}
@Override
public void onSuccess(int status) {
- Log.d(TAG, "DPP onSuccess callback");
+ Log.d(TAG, "Easy Connect onSuccess callback");
mHandler.post(() -> {
- mDppStatusCallback.onConfiguratorSuccess(status);
+ mEasyConnectStatusCallback.onConfiguratorSuccess(status);
});
}
@Override
public void onFailure(int status) {
- Log.d(TAG, "DPP onFailure callback");
+ Log.d(TAG, "Easy Connect onFailure callback");
mHandler.post(() -> {
- mDppStatusCallback.onFailure(status);
+ mEasyConnectStatusCallback.onFailure(status);
});
}
@Override
public void onProgress(int status) {
- Log.d(TAG, "DPP onProgress callback");
+ Log.d(TAG, "Easy Connect onProgress callback");
mHandler.post(() -> {
- mDppStatusCallback.onProgress(status);
+ mEasyConnectStatusCallback.onProgress(status);
});
}
}
diff --git a/wifi/tests/src/android/net/wifi/WifiConfigurationTest.java b/wifi/tests/src/android/net/wifi/WifiConfigurationTest.java
index c744f18..7bff68a 100644
--- a/wifi/tests/src/android/net/wifi/WifiConfigurationTest.java
+++ b/wifi/tests/src/android/net/wifi/WifiConfigurationTest.java
@@ -59,6 +59,7 @@
WifiConfiguration config = new WifiConfiguration();
config.setPasspointManagementObjectTree(cookie);
config.trusted = false;
+ config.updateIdentifier = "1234";
MacAddress macBeforeParcel = config.getOrCreateRandomizedMacAddress();
Parcel parcelW = Parcel.obtain();
config.writeToParcel(parcelW, 0);
@@ -73,6 +74,7 @@
// lacking a useful config.equals, check two fields near the end.
assertEquals(cookie, reconfig.getMoTree());
assertEquals(macBeforeParcel, reconfig.getOrCreateRandomizedMacAddress());
+ assertEquals(config.updateIdentifier, reconfig.updateIdentifier);
assertFalse(reconfig.trusted);
Parcel parcelWW = Parcel.obtain();
@@ -251,6 +253,18 @@
}
/**
+ * Verifies that updateIdentifier should be copied for copy constructor.
+ */
+ @Test
+ public void testUpdateIdentifierForCopyConstructor() {
+ WifiConfiguration config = new WifiConfiguration();
+ config.updateIdentifier = "1234";
+ WifiConfiguration copyConfig = new WifiConfiguration(config);
+
+ assertEquals(config.updateIdentifier, copyConfig.updateIdentifier);
+ }
+
+ /**
* Verifies that the serialization/de-serialization for softap config works.
*/
@Test