Merge "Add IMEI_NOT_ACCEPTED disconnect cause"
diff --git a/Android.mk b/Android.mk
index c0bb724..5dfa58a 100644
--- a/Android.mk
+++ b/Android.mk
@@ -45,6 +45,7 @@
core/java/android/app/admin/SecurityLogTags.logtags \
core/java/android/content/EventLogTags.logtags \
core/java/android/speech/tts/EventLogTags.logtags \
+ core/java/android/net/EventLogTags.logtags \
core/java/android/webkit/EventLogTags.logtags \
core/java/com/android/internal/logging/EventLogTags.logtags \
@@ -124,6 +125,8 @@
core/java/android/bluetooth/IBluetoothSap.aidl \
core/java/android/bluetooth/IBluetoothStateChangeCallback.aidl \
core/java/android/bluetooth/IBluetoothHeadsetClient.aidl \
+ core/java/android/bluetooth/IBluetoothInputHost.aidl \
+ core/java/android/bluetooth/IBluetoothHidDeviceCallback.aidl \
core/java/android/bluetooth/IBluetoothGatt.aidl \
core/java/android/bluetooth/IBluetoothGattCallback.aidl \
core/java/android/bluetooth/IBluetoothGattServerCallback.aidl \
@@ -477,6 +480,7 @@
LOCAL_SRC_FILES += \
../../system/netd/server/binder/android/net/INetd.aidl \
+ ../native/cmds/installd/binder/android/os/IInstalld.aidl \
LOCAL_AIDL_INCLUDES += system/update_engine/binder_bindings
@@ -502,7 +506,7 @@
LOCAL_ADDITIONAL_DEPENDENCIES := $(framework_res_R_stamp)
LOCAL_NO_STANDARD_LIBRARIES := true
-LOCAL_JAVA_LIBRARIES := core-oj core-libart conscrypt okhttp legacy-test bouncycastle ext
+LOCAL_JAVA_LIBRARIES := core-oj core-libart conscrypt okhttp bouncycastle ext
LOCAL_STATIC_JAVA_LIBRARIES := framework-protos
LOCAL_MODULE := framework
@@ -729,6 +733,7 @@
# Search through the base framework dirs for these packages.
# The result will be relative to frameworks/base.
fwbase_dirs_to_document := \
+ legacy-test/src \
test-runner/src \
$(patsubst $(LOCAL_PATH)/%,%, \
$(wildcard \
@@ -741,9 +746,6 @@
# include definition of libcore_to_document
include libcore/Docs.mk
-# include definition of junit_to_document
-include external/junit/Common.mk
-
non_base_dirs := \
../opt/telephony/src/java/android/provider \
../opt/telephony/src/java/android/telephony \
@@ -784,8 +786,7 @@
# Common sources for doc check and api check
common_src_files := \
$(call find-other-html-files, $(html_dirs)) \
- $(addprefix ../../, $(libcore_to_document)) \
- $(addprefix ../../external/junit/, $(junit_to_document))
+ $(addprefix ../../, $(libcore_to_document))
# These are relative to frameworks/base
framework_docs_LOCAL_SRC_FILES := \
diff --git a/api/current.txt b/api/current.txt
index 2788f36..86b2119 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -6447,6 +6447,7 @@
public static class NetworkStats.Bucket {
ctor public NetworkStats.Bucket();
method public long getEndTimeStamp();
+ method public int getMetered();
method public int getRoaming();
method public long getRxBytes();
method public long getRxPackets();
@@ -6456,6 +6457,9 @@
method public long getTxBytes();
method public long getTxPackets();
method public int getUid();
+ field public static final int METERED_ALL = -1; // 0xffffffff
+ field public static final int METERED_NO = 1; // 0x1
+ field public static final int METERED_YES = 2; // 0x2
field public static final int ROAMING_ALL = -1; // 0xffffffff
field public static final int ROAMING_NO = 1; // 0x1
field public static final int ROAMING_YES = 2; // 0x2
@@ -14946,6 +14950,10 @@
field public static final int CONTROL = 1; // 0x1
field public static final int CR = 2; // 0x2
field public static final int EXTEND = 3; // 0x3
+ field public static final int E_BASE = 13; // 0xd
+ field public static final int E_BASE_GAZ = 14; // 0xe
+ field public static final int E_MODIFIER = 15; // 0xf
+ field public static final int GLUE_AFTER_ZWJ = 16; // 0x10
field public static final int L = 4; // 0x4
field public static final int LF = 5; // 0x5
field public static final int LV = 6; // 0x6
@@ -14956,6 +14964,7 @@
field public static final int SPACING_MARK = 10; // 0xa
field public static final int T = 8; // 0x8
field public static final int V = 9; // 0x9
+ field public static final int ZWJ = 17; // 0x11
}
public static abstract interface UCharacter.HangulSyllableType {
@@ -14968,6 +14977,9 @@
}
public static abstract interface UCharacter.JoiningGroup {
+ field public static final int AFRICAN_FEH = 86; // 0x56
+ field public static final int AFRICAN_NOON = 87; // 0x57
+ field public static final int AFRICAN_QAF = 88; // 0x58
field public static final int AIN = 1; // 0x1
field public static final int ALAPH = 2; // 0x2
field public static final int ALEF = 3; // 0x3
@@ -15081,6 +15093,8 @@
field public static final int CONDITIONAL_JAPANESE_STARTER = 37; // 0x25
field public static final int CONTINGENT_BREAK = 7; // 0x7
field public static final int EXCLAMATION = 11; // 0xb
+ field public static final int E_BASE = 40; // 0x28
+ field public static final int E_MODIFIER = 41; // 0x29
field public static final int GLUE = 12; // 0xc
field public static final int H2 = 31; // 0x1f
field public static final int H3 = 32; // 0x20
@@ -15107,6 +15121,7 @@
field public static final int SURROGATE = 25; // 0x19
field public static final int UNKNOWN = 0; // 0x0
field public static final int WORD_JOINER = 30; // 0x1e
+ field public static final int ZWJ = 42; // 0x2a
field public static final int ZWSPACE = 28; // 0x1c
}
@@ -15140,6 +15155,8 @@
method public int getID();
method public static android.icu.lang.UCharacter.UnicodeBlock getInstance(int);
method public static android.icu.lang.UCharacter.UnicodeBlock of(int);
+ field public static final android.icu.lang.UCharacter.UnicodeBlock ADLAM;
+ field public static final int ADLAM_ID = 263; // 0x107
field public static final android.icu.lang.UCharacter.UnicodeBlock AEGEAN_NUMBERS;
field public static final int AEGEAN_NUMBERS_ID = 119; // 0x77
field public static final android.icu.lang.UCharacter.UnicodeBlock AHOM;
@@ -15188,6 +15205,8 @@
field public static final int BATAK_ID = 199; // 0xc7
field public static final android.icu.lang.UCharacter.UnicodeBlock BENGALI;
field public static final int BENGALI_ID = 16; // 0x10
+ field public static final android.icu.lang.UCharacter.UnicodeBlock BHAIKSUKI;
+ field public static final int BHAIKSUKI_ID = 264; // 0x108
field public static final android.icu.lang.UCharacter.UnicodeBlock BLOCK_ELEMENTS;
field public static final int BLOCK_ELEMENTS_ID = 53; // 0x35
field public static final android.icu.lang.UCharacter.UnicodeBlock BOPOMOFO;
@@ -15277,6 +15296,8 @@
field public static final int CYRILLIC_EXTENDED_A_ID = 158; // 0x9e
field public static final android.icu.lang.UCharacter.UnicodeBlock CYRILLIC_EXTENDED_B;
field public static final int CYRILLIC_EXTENDED_B_ID = 160; // 0xa0
+ field public static final android.icu.lang.UCharacter.UnicodeBlock CYRILLIC_EXTENDED_C;
+ field public static final int CYRILLIC_EXTENDED_C_ID = 265; // 0x109
field public static final int CYRILLIC_ID = 9; // 0x9
field public static final android.icu.lang.UCharacter.UnicodeBlock CYRILLIC_SUPPLEMENT;
field public static final android.icu.lang.UCharacter.UnicodeBlock CYRILLIC_SUPPLEMENTARY;
@@ -15330,6 +15351,8 @@
field public static final int GEORGIAN_SUPPLEMENT_ID = 135; // 0x87
field public static final android.icu.lang.UCharacter.UnicodeBlock GLAGOLITIC;
field public static final int GLAGOLITIC_ID = 136; // 0x88
+ field public static final android.icu.lang.UCharacter.UnicodeBlock GLAGOLITIC_SUPPLEMENT;
+ field public static final int GLAGOLITIC_SUPPLEMENT_ID = 266; // 0x10a
field public static final android.icu.lang.UCharacter.UnicodeBlock GOTHIC;
field public static final int GOTHIC_ID = 89; // 0x59
field public static final android.icu.lang.UCharacter.UnicodeBlock GRANTHA;
@@ -15368,6 +15391,8 @@
field public static final int HIRAGANA_ID = 62; // 0x3e
field public static final android.icu.lang.UCharacter.UnicodeBlock IDEOGRAPHIC_DESCRIPTION_CHARACTERS;
field public static final int IDEOGRAPHIC_DESCRIPTION_CHARACTERS_ID = 60; // 0x3c
+ field public static final android.icu.lang.UCharacter.UnicodeBlock IDEOGRAPHIC_SYMBOLS_AND_PUNCTUATION;
+ field public static final int IDEOGRAPHIC_SYMBOLS_AND_PUNCTUATION_ID = 267; // 0x10b
field public static final android.icu.lang.UCharacter.UnicodeBlock IMPERIAL_ARAMAIC;
field public static final int IMPERIAL_ARAMAIC_ID = 186; // 0xba
field public static final android.icu.lang.UCharacter.UnicodeBlock INSCRIPTIONAL_PAHLAVI;
@@ -15452,6 +15477,8 @@
field public static final int MANDAIC_ID = 198; // 0xc6
field public static final android.icu.lang.UCharacter.UnicodeBlock MANICHAEAN;
field public static final int MANICHAEAN_ID = 234; // 0xea
+ field public static final android.icu.lang.UCharacter.UnicodeBlock MARCHEN;
+ field public static final int MARCHEN_ID = 268; // 0x10c
field public static final android.icu.lang.UCharacter.UnicodeBlock MATHEMATICAL_ALPHANUMERIC_SYMBOLS;
field public static final int MATHEMATICAL_ALPHANUMERIC_SYMBOLS_ID = 93; // 0x5d
field public static final android.icu.lang.UCharacter.UnicodeBlock MATHEMATICAL_OPERATORS;
@@ -15486,6 +15513,8 @@
field public static final int MODI_ID = 236; // 0xec
field public static final android.icu.lang.UCharacter.UnicodeBlock MONGOLIAN;
field public static final int MONGOLIAN_ID = 37; // 0x25
+ field public static final android.icu.lang.UCharacter.UnicodeBlock MONGOLIAN_SUPPLEMENT;
+ field public static final int MONGOLIAN_SUPPLEMENT_ID = 269; // 0x10d
field public static final android.icu.lang.UCharacter.UnicodeBlock MRO;
field public static final int MRO_ID = 237; // 0xed
field public static final android.icu.lang.UCharacter.UnicodeBlock MULTANI;
@@ -15500,6 +15529,8 @@
field public static final int MYANMAR_ID = 28; // 0x1c
field public static final android.icu.lang.UCharacter.UnicodeBlock NABATAEAN;
field public static final int NABATAEAN_ID = 239; // 0xef
+ field public static final android.icu.lang.UCharacter.UnicodeBlock NEWA;
+ field public static final int NEWA_ID = 270; // 0x10e
field public static final android.icu.lang.UCharacter.UnicodeBlock NEW_TAI_LUE;
field public static final int NEW_TAI_LUE_ID = 139; // 0x8b
field public static final android.icu.lang.UCharacter.UnicodeBlock NKO;
@@ -15531,6 +15562,8 @@
field public static final int ORIYA_ID = 19; // 0x13
field public static final android.icu.lang.UCharacter.UnicodeBlock ORNAMENTAL_DINGBATS;
field public static final int ORNAMENTAL_DINGBATS_ID = 242; // 0xf2
+ field public static final android.icu.lang.UCharacter.UnicodeBlock OSAGE;
+ field public static final int OSAGE_ID = 271; // 0x10f
field public static final android.icu.lang.UCharacter.UnicodeBlock OSMANYA;
field public static final int OSMANYA_ID = 122; // 0x7a
field public static final android.icu.lang.UCharacter.UnicodeBlock PAHAWH_HMONG;
@@ -15633,6 +15666,10 @@
field public static final int TAKRI_ID = 220; // 0xdc
field public static final android.icu.lang.UCharacter.UnicodeBlock TAMIL;
field public static final int TAMIL_ID = 20; // 0x14
+ field public static final android.icu.lang.UCharacter.UnicodeBlock TANGUT;
+ field public static final android.icu.lang.UCharacter.UnicodeBlock TANGUT_COMPONENTS;
+ field public static final int TANGUT_COMPONENTS_ID = 273; // 0x111
+ field public static final int TANGUT_ID = 272; // 0x110
field public static final android.icu.lang.UCharacter.UnicodeBlock TELUGU;
field public static final int TELUGU_ID = 21; // 0x15
field public static final android.icu.lang.UCharacter.UnicodeBlock THAANA;
@@ -15679,7 +15716,11 @@
field public static final int DOUBLE_QUOTE = 16; // 0x10
field public static final int EXTEND = 9; // 0x9
field public static final int EXTENDNUMLET = 7; // 0x7
+ field public static final int E_BASE = 17; // 0x11
+ field public static final int E_BASE_GAZ = 18; // 0x12
+ field public static final int E_MODIFIER = 19; // 0x13
field public static final int FORMAT = 2; // 0x2
+ field public static final int GLUE_AFTER_ZWJ = 20; // 0x14
field public static final int HEBREW_LETTER = 14; // 0xe
field public static final int KATAKANA = 3; // 0x3
field public static final int LF = 10; // 0xa
@@ -15691,6 +15732,7 @@
field public static final int OTHER = 0; // 0x0
field public static final int REGIONAL_INDICATOR = 13; // 0xd
field public static final int SINGLE_QUOTE = 15; // 0xf
+ field public static final int ZWJ = 21; // 0x15
}
public final class UCharacterCategory implements android.icu.lang.UCharacterEnums.ECharacterCategory {
@@ -15909,6 +15951,7 @@
method public static final boolean hasScript(int, int);
method public static final boolean isCased(int);
method public static final boolean isRightToLeft(int);
+ field public static final int ADLAM = 167; // 0xa7
field public static final int AFAKA = 147; // 0x93
field public static final int AHOM = 161; // 0xa1
field public static final int ANATOLIAN_HIEROGLYPHS = 156; // 0x9c
@@ -15920,6 +15963,7 @@
field public static final int BASSA_VAH = 134; // 0x86
field public static final int BATAK = 63; // 0x3f
field public static final int BENGALI = 4; // 0x4
+ field public static final int BHAIKSUKI = 168; // 0xa8
field public static final int BLISSYMBOLS = 64; // 0x40
field public static final int BOOK_PAHLAVI = 124; // 0x7c
field public static final int BOPOMOFO = 5; // 0x5
@@ -15958,6 +16002,7 @@
field public static final int HAN = 17; // 0x11
field public static final int HANGUL = 18; // 0x12
field public static final int HANUNOO = 43; // 0x2b
+ field public static final int HAN_WITH_BOPOMOFO = 172; // 0xac
field public static final int HARAPPAN_INDUS = 77; // 0x4d
field public static final int HATRAN = 162; // 0xa2
field public static final int HEBREW = 19; // 0x13
@@ -15968,6 +16013,7 @@
field public static final int INSCRIPTIONAL_PAHLAVI = 122; // 0x7a
field public static final int INSCRIPTIONAL_PARTHIAN = 125; // 0x7d
field public static final int INVALID_CODE = -1; // 0xffffffff
+ field public static final int JAMO = 173; // 0xad
field public static final int JAPANESE = 105; // 0x69
field public static final int JAVANESE = 78; // 0x4e
field public static final int JURCHEN = 148; // 0x94
@@ -16001,6 +16047,7 @@
field public static final int MANDAEAN = 84; // 0x54
field public static final int MANDAIC = 84; // 0x54
field public static final int MANICHAEAN = 121; // 0x79
+ field public static final int MARCHEN = 169; // 0xa9
field public static final int MATHEMATICAL_NOTATION = 128; // 0x80
field public static final int MAYAN_HIEROGLYPHS = 85; // 0x55
field public static final int MEITEI_MAYEK = 115; // 0x73
@@ -16017,6 +16064,7 @@
field public static final int MYANMAR = 28; // 0x1c
field public static final int NABATAEAN = 143; // 0x8f
field public static final int NAKHI_GEBA = 132; // 0x84
+ field public static final int NEWA = 170; // 0xaa
field public static final int NEW_TAI_LUE = 59; // 0x3b
field public static final int NKO = 87; // 0x57
field public static final int NUSHU = 150; // 0x96
@@ -16031,6 +16079,7 @@
field public static final int OL_CHIKI = 109; // 0x6d
field public static final int ORIYA = 31; // 0x1f
field public static final int ORKHON = 88; // 0x58
+ field public static final int OSAGE = 171; // 0xab
field public static final int OSMANYA = 50; // 0x32
field public static final int PAHAWH_HMONG = 75; // 0x4b
field public static final int PALMYRENE = 144; // 0x90
@@ -16056,6 +16105,7 @@
field public static final int SUNDANESE = 113; // 0x71
field public static final int SYLOTI_NAGRI = 58; // 0x3a
field public static final int SYMBOLS = 129; // 0x81
+ field public static final int SYMBOLS_EMOJI = 174; // 0xae
field public static final int SYRIAC = 34; // 0x22
field public static final int TAGALOG = 42; // 0x2a
field public static final int TAGBANWA = 45; // 0x2d
@@ -16582,6 +16632,8 @@
method public static final android.icu.text.DateFormat.BooleanAttribute[] values();
enum_constant public static final android.icu.text.DateFormat.BooleanAttribute PARSE_ALLOW_NUMERIC;
enum_constant public static final android.icu.text.DateFormat.BooleanAttribute PARSE_ALLOW_WHITESPACE;
+ enum_constant public static final android.icu.text.DateFormat.BooleanAttribute PARSE_MULTIPLE_PATTERNS_FOR_MATCH;
+ enum_constant public static final android.icu.text.DateFormat.BooleanAttribute PARSE_PARTIAL_LITERAL_MATCH;
}
public static class DateFormat.Field extends java.text.Format.Field {
@@ -17266,6 +17318,7 @@
field public static final int PERCENTSTYLE = 2; // 0x2
field public static final int PLURALCURRENCYSTYLE = 6; // 0x6
field public static final int SCIENTIFICSTYLE = 3; // 0x3
+ field public static final int STANDARDCURRENCYSTYLE = 9; // 0x9
}
public static class NumberFormat.Field extends java.text.Format.Field {
@@ -18060,7 +18113,7 @@
field public static final int AM_PM = 9; // 0x9
field public static final int APRIL = 3; // 0x3
field public static final int AUGUST = 7; // 0x7
- field protected static final int BASE_FIELD_COUNT = 23; // 0x17
+ field protected static final deprecated int BASE_FIELD_COUNT = 23; // 0x17
field public static final int DATE = 5; // 0x5
field public static final int DAY_OF_MONTH = 5; // 0x5
field public static final int DAY_OF_WEEK = 7; // 0x7
@@ -18088,7 +18141,7 @@
field public static final int MARCH = 2; // 0x2
field protected static final int MAXIMUM = 3; // 0x3
field protected static final java.util.Date MAX_DATE;
- field protected static final int MAX_FIELD_COUNT = 32; // 0x20
+ field protected static final deprecated int MAX_FIELD_COUNT = 32; // 0x20
field protected static final int MAX_JULIAN = 2130706432; // 0x7f000000
field protected static final long MAX_MILLIS = 183882168921600000L; // 0x28d47dbbf19b000L
field public static final int MAY = 4; // 0x4
@@ -18408,6 +18461,7 @@
field public static final android.icu.util.MeasureUnit CELSIUS;
field public static final android.icu.util.MeasureUnit CENTILITER;
field public static final android.icu.util.MeasureUnit CENTIMETER;
+ field public static final android.icu.util.MeasureUnit CENTURY;
field public static final android.icu.util.MeasureUnit CUBIC_CENTIMETER;
field public static final android.icu.util.MeasureUnit CUBIC_FOOT;
field public static final android.icu.util.MeasureUnit CUBIC_INCH;
@@ -18416,6 +18470,7 @@
field public static final android.icu.util.MeasureUnit CUBIC_MILE;
field public static final android.icu.util.MeasureUnit CUBIC_YARD;
field public static final android.icu.util.MeasureUnit CUP;
+ field public static final android.icu.util.MeasureUnit CUP_METRIC;
field public static final android.icu.util.TimeUnit DAY;
field public static final android.icu.util.MeasureUnit DECILITER;
field public static final android.icu.util.MeasureUnit DECIMETER;
@@ -18427,6 +18482,7 @@
field public static final android.icu.util.MeasureUnit FOOT;
field public static final android.icu.util.MeasureUnit FURLONG;
field public static final android.icu.util.MeasureUnit GALLON;
+ field public static final android.icu.util.MeasureUnit GENERIC_TEMPERATURE;
field public static final android.icu.util.MeasureUnit GIGABIT;
field public static final android.icu.util.MeasureUnit GIGABYTE;
field public static final android.icu.util.MeasureUnit GIGAHERTZ;
@@ -18454,8 +18510,10 @@
field public static final android.icu.util.MeasureUnit KILOMETER_PER_HOUR;
field public static final android.icu.util.MeasureUnit KILOWATT;
field public static final android.icu.util.MeasureUnit KILOWATT_HOUR;
+ field public static final android.icu.util.MeasureUnit KNOT;
field public static final android.icu.util.MeasureUnit LIGHT_YEAR;
field public static final android.icu.util.MeasureUnit LITER;
+ field public static final android.icu.util.MeasureUnit LITER_PER_100KILOMETERS;
field public static final android.icu.util.MeasureUnit LITER_PER_KILOMETER;
field public static final android.icu.util.MeasureUnit LUX;
field public static final android.icu.util.MeasureUnit MEGABIT;
@@ -18473,6 +18531,7 @@
field public static final android.icu.util.MeasureUnit MILE;
field public static final android.icu.util.MeasureUnit MILE_PER_GALLON;
field public static final android.icu.util.MeasureUnit MILE_PER_HOUR;
+ field public static final android.icu.util.MeasureUnit MILE_SCANDINAVIAN;
field public static final android.icu.util.MeasureUnit MILLIAMPERE;
field public static final android.icu.util.MeasureUnit MILLIBAR;
field public static final android.icu.util.MeasureUnit MILLIGRAM;
@@ -18492,10 +18551,12 @@
field public static final android.icu.util.MeasureUnit PARSEC;
field public static final android.icu.util.MeasureUnit PICOMETER;
field public static final android.icu.util.MeasureUnit PINT;
+ field public static final android.icu.util.MeasureUnit PINT_METRIC;
field public static final android.icu.util.MeasureUnit POUND;
field public static final android.icu.util.MeasureUnit POUND_PER_SQUARE_INCH;
field public static final android.icu.util.MeasureUnit QUART;
field public static final android.icu.util.MeasureUnit RADIAN;
+ field public static final android.icu.util.MeasureUnit REVOLUTION_ANGLE;
field public static final android.icu.util.TimeUnit SECOND;
field public static final android.icu.util.MeasureUnit SQUARE_CENTIMETER;
field public static final android.icu.util.MeasureUnit SQUARE_FOOT;
@@ -18807,6 +18868,7 @@
field public static final android.icu.util.VersionInfo UNICODE_6_3;
field public static final android.icu.util.VersionInfo UNICODE_7_0;
field public static final android.icu.util.VersionInfo UNICODE_8_0;
+ field public static final android.icu.util.VersionInfo UNICODE_9_0;
}
}
@@ -36870,6 +36932,7 @@
field public static final java.lang.String KEY_SHOW_CDMA_CHOICES_BOOL = "show_cdma_choices_bool";
field public static final java.lang.String KEY_SHOW_ICCID_IN_SIM_STATUS_BOOL = "show_iccid_in_sim_status_bool";
field public static final java.lang.String KEY_SHOW_ONSCREEN_DIAL_BUTTON_BOOL = "show_onscreen_dial_button_bool";
+ field public static final java.lang.String KEY_SIMPLIFIED_NETWORK_SETTINGS_BOOL = "simplified_network_settings_bool";
field public static final java.lang.String KEY_SIM_NETWORK_UNLOCK_ALLOW_DISMISS_BOOL = "sim_network_unlock_allow_dismiss_bool";
field public static final java.lang.String KEY_SUPPORT_CONFERENCE_CALL_BOOL = "support_conference_call_bool";
field public static final java.lang.String KEY_SUPPORT_PAUSE_IMS_VIDEO_CALLS_BOOL = "support_pause_ims_video_calls_bool";
@@ -37407,6 +37470,7 @@
method public java.lang.String getSimOperatorName();
method public java.lang.String getSimSerialNumber();
method public int getSimState();
+ method public int getSimState(int);
method public java.lang.String getSubscriberId();
method public java.lang.String getVoiceMailAlphaTag();
method public java.lang.String getVoiceMailNumber();
@@ -37489,7 +37553,11 @@
field public static final int PHONE_TYPE_NONE = 0; // 0x0
field public static final int PHONE_TYPE_SIP = 3; // 0x3
field public static final int SIM_STATE_ABSENT = 1; // 0x1
+ field public static final int SIM_STATE_CARD_IO_ERROR = 8; // 0x8
+ field public static final int SIM_STATE_CARD_RESTRICTED = 9; // 0x9
field public static final int SIM_STATE_NETWORK_LOCKED = 4; // 0x4
+ field public static final int SIM_STATE_NOT_READY = 6; // 0x6
+ field public static final int SIM_STATE_PERM_DISABLED = 7; // 0x7
field public static final int SIM_STATE_PIN_REQUIRED = 2; // 0x2
field public static final int SIM_STATE_PUK_REQUIRED = 3; // 0x3
field public static final int SIM_STATE_READY = 5; // 0x5
@@ -59296,6 +59364,10 @@
ctor public Locale(java.lang.String, java.lang.String);
ctor public Locale(java.lang.String);
method public java.lang.Object clone();
+ method public static java.util.List<java.util.Locale> filter(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.util.Locale>, java.util.Locale.FilteringMode);
+ method public static java.util.List<java.util.Locale> filter(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.util.Locale>);
+ method public static java.util.List<java.lang.String> filterTags(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.lang.String>, java.util.Locale.FilteringMode);
+ method public static java.util.List<java.lang.String> filterTags(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.lang.String>);
method public static java.util.Locale forLanguageTag(java.lang.String);
method public static java.util.Locale[] getAvailableLocales();
method public java.lang.String getCountry();
@@ -59324,6 +59396,8 @@
method public java.lang.String getUnicodeLocaleType(java.lang.String);
method public java.lang.String getVariant();
method public boolean hasExtensions();
+ method public static java.util.Locale lookup(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.util.Locale>);
+ method public static java.lang.String lookupTag(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.lang.String>);
method public static synchronized void setDefault(java.util.Locale);
method public static synchronized void setDefault(java.util.Locale.Category, java.util.Locale);
method public java.util.Locale stripExtensions();
@@ -59379,6 +59453,28 @@
enum_constant public static final java.util.Locale.Category FORMAT;
}
+ public static final class Locale.FilteringMode extends java.lang.Enum {
+ method public static java.util.Locale.FilteringMode valueOf(java.lang.String);
+ method public static final java.util.Locale.FilteringMode[] values();
+ enum_constant public static final java.util.Locale.FilteringMode AUTOSELECT_FILTERING;
+ enum_constant public static final java.util.Locale.FilteringMode EXTENDED_FILTERING;
+ enum_constant public static final java.util.Locale.FilteringMode IGNORE_EXTENDED_RANGES;
+ enum_constant public static final java.util.Locale.FilteringMode MAP_EXTENDED_RANGES;
+ enum_constant public static final java.util.Locale.FilteringMode REJECT_EXTENDED_RANGES;
+ }
+
+ public static final class Locale.LanguageRange {
+ ctor public Locale.LanguageRange(java.lang.String);
+ ctor public Locale.LanguageRange(java.lang.String, double);
+ method public java.lang.String getRange();
+ method public double getWeight();
+ method public static java.util.List<java.util.Locale.LanguageRange> mapEquivalents(java.util.List<java.util.Locale.LanguageRange>, java.util.Map<java.lang.String, java.util.List<java.lang.String>>);
+ method public static java.util.List<java.util.Locale.LanguageRange> parse(java.lang.String);
+ method public static java.util.List<java.util.Locale.LanguageRange> parse(java.lang.String, java.util.Map<java.lang.String, java.util.List<java.lang.String>>);
+ field public static final double MAX_WEIGHT = 1.0;
+ field public static final double MIN_WEIGHT = 0.0;
+ }
+
public class LongSummaryStatistics implements java.util.function.IntConsumer java.util.function.LongConsumer {
ctor public LongSummaryStatistics();
method public void accept(int);
@@ -62045,13 +62141,13 @@
ctor public Attributes.Name(java.lang.String);
field public static final java.util.jar.Attributes.Name CLASS_PATH;
field public static final java.util.jar.Attributes.Name CONTENT_TYPE;
- field public static final java.util.jar.Attributes.Name EXTENSION_INSTALLATION;
+ field public static final deprecated java.util.jar.Attributes.Name EXTENSION_INSTALLATION;
field public static final java.util.jar.Attributes.Name EXTENSION_LIST;
field public static final java.util.jar.Attributes.Name EXTENSION_NAME;
field public static final java.util.jar.Attributes.Name IMPLEMENTATION_TITLE;
- field public static final java.util.jar.Attributes.Name IMPLEMENTATION_URL;
+ field public static final deprecated java.util.jar.Attributes.Name IMPLEMENTATION_URL;
field public static final java.util.jar.Attributes.Name IMPLEMENTATION_VENDOR;
- field public static final java.util.jar.Attributes.Name IMPLEMENTATION_VENDOR_ID;
+ field public static final deprecated java.util.jar.Attributes.Name IMPLEMENTATION_VENDOR_ID;
field public static final java.util.jar.Attributes.Name IMPLEMENTATION_VERSION;
field public static final java.util.jar.Attributes.Name MAIN_CLASS;
field public static final java.util.jar.Attributes.Name MANIFEST_VERSION;
@@ -62118,11 +62214,11 @@
}
public static abstract interface Pack200.Packer {
- method public abstract void addPropertyChangeListener(java.beans.PropertyChangeListener);
+ method public default deprecated void addPropertyChangeListener(java.beans.PropertyChangeListener);
method public abstract void pack(java.util.jar.JarFile, java.io.OutputStream) throws java.io.IOException;
method public abstract void pack(java.util.jar.JarInputStream, java.io.OutputStream) throws java.io.IOException;
method public abstract java.util.SortedMap<java.lang.String, java.lang.String> properties();
- method public abstract void removePropertyChangeListener(java.beans.PropertyChangeListener);
+ method public default deprecated void removePropertyChangeListener(java.beans.PropertyChangeListener);
field public static final java.lang.String CLASS_ATTRIBUTE_PFX = "pack.class.attribute.";
field public static final java.lang.String CODE_ATTRIBUTE_PFX = "pack.code.attribute.";
field public static final java.lang.String DEFLATE_HINT = "pack.deflate.hint";
@@ -62145,9 +62241,9 @@
}
public static abstract interface Pack200.Unpacker {
- method public abstract void addPropertyChangeListener(java.beans.PropertyChangeListener);
+ method public default deprecated void addPropertyChangeListener(java.beans.PropertyChangeListener);
method public abstract java.util.SortedMap<java.lang.String, java.lang.String> properties();
- method public abstract void removePropertyChangeListener(java.beans.PropertyChangeListener);
+ method public default deprecated void removePropertyChangeListener(java.beans.PropertyChangeListener);
method public abstract void unpack(java.io.InputStream, java.util.jar.JarOutputStream) throws java.io.IOException;
method public abstract void unpack(java.io.File, java.util.jar.JarOutputStream) throws java.io.IOException;
field public static final java.lang.String DEFLATE_HINT = "unpack.deflate.hint";
diff --git a/api/system-current.txt b/api/system-current.txt
index 74b1af3..b2f2a3c 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -6739,6 +6739,7 @@
public static class NetworkStats.Bucket {
ctor public NetworkStats.Bucket();
method public long getEndTimeStamp();
+ method public int getMetered();
method public int getRoaming();
method public long getRxBytes();
method public long getRxPackets();
@@ -6748,6 +6749,9 @@
method public long getTxBytes();
method public long getTxPackets();
method public int getUid();
+ field public static final int METERED_ALL = -1; // 0xffffffff
+ field public static final int METERED_NO = 1; // 0x1
+ field public static final int METERED_YES = 2; // 0x2
field public static final int ROAMING_ALL = -1; // 0xffffffff
field public static final int ROAMING_NO = 1; // 0x1
field public static final int ROAMING_YES = 2; // 0x2
@@ -16156,6 +16160,10 @@
field public static final int CONTROL = 1; // 0x1
field public static final int CR = 2; // 0x2
field public static final int EXTEND = 3; // 0x3
+ field public static final int E_BASE = 13; // 0xd
+ field public static final int E_BASE_GAZ = 14; // 0xe
+ field public static final int E_MODIFIER = 15; // 0xf
+ field public static final int GLUE_AFTER_ZWJ = 16; // 0x10
field public static final int L = 4; // 0x4
field public static final int LF = 5; // 0x5
field public static final int LV = 6; // 0x6
@@ -16166,6 +16174,7 @@
field public static final int SPACING_MARK = 10; // 0xa
field public static final int T = 8; // 0x8
field public static final int V = 9; // 0x9
+ field public static final int ZWJ = 17; // 0x11
}
public static abstract interface UCharacter.HangulSyllableType {
@@ -16178,6 +16187,9 @@
}
public static abstract interface UCharacter.JoiningGroup {
+ field public static final int AFRICAN_FEH = 86; // 0x56
+ field public static final int AFRICAN_NOON = 87; // 0x57
+ field public static final int AFRICAN_QAF = 88; // 0x58
field public static final int AIN = 1; // 0x1
field public static final int ALAPH = 2; // 0x2
field public static final int ALEF = 3; // 0x3
@@ -16291,6 +16303,8 @@
field public static final int CONDITIONAL_JAPANESE_STARTER = 37; // 0x25
field public static final int CONTINGENT_BREAK = 7; // 0x7
field public static final int EXCLAMATION = 11; // 0xb
+ field public static final int E_BASE = 40; // 0x28
+ field public static final int E_MODIFIER = 41; // 0x29
field public static final int GLUE = 12; // 0xc
field public static final int H2 = 31; // 0x1f
field public static final int H3 = 32; // 0x20
@@ -16317,6 +16331,7 @@
field public static final int SURROGATE = 25; // 0x19
field public static final int UNKNOWN = 0; // 0x0
field public static final int WORD_JOINER = 30; // 0x1e
+ field public static final int ZWJ = 42; // 0x2a
field public static final int ZWSPACE = 28; // 0x1c
}
@@ -16350,6 +16365,8 @@
method public int getID();
method public static android.icu.lang.UCharacter.UnicodeBlock getInstance(int);
method public static android.icu.lang.UCharacter.UnicodeBlock of(int);
+ field public static final android.icu.lang.UCharacter.UnicodeBlock ADLAM;
+ field public static final int ADLAM_ID = 263; // 0x107
field public static final android.icu.lang.UCharacter.UnicodeBlock AEGEAN_NUMBERS;
field public static final int AEGEAN_NUMBERS_ID = 119; // 0x77
field public static final android.icu.lang.UCharacter.UnicodeBlock AHOM;
@@ -16398,6 +16415,8 @@
field public static final int BATAK_ID = 199; // 0xc7
field public static final android.icu.lang.UCharacter.UnicodeBlock BENGALI;
field public static final int BENGALI_ID = 16; // 0x10
+ field public static final android.icu.lang.UCharacter.UnicodeBlock BHAIKSUKI;
+ field public static final int BHAIKSUKI_ID = 264; // 0x108
field public static final android.icu.lang.UCharacter.UnicodeBlock BLOCK_ELEMENTS;
field public static final int BLOCK_ELEMENTS_ID = 53; // 0x35
field public static final android.icu.lang.UCharacter.UnicodeBlock BOPOMOFO;
@@ -16487,6 +16506,8 @@
field public static final int CYRILLIC_EXTENDED_A_ID = 158; // 0x9e
field public static final android.icu.lang.UCharacter.UnicodeBlock CYRILLIC_EXTENDED_B;
field public static final int CYRILLIC_EXTENDED_B_ID = 160; // 0xa0
+ field public static final android.icu.lang.UCharacter.UnicodeBlock CYRILLIC_EXTENDED_C;
+ field public static final int CYRILLIC_EXTENDED_C_ID = 265; // 0x109
field public static final int CYRILLIC_ID = 9; // 0x9
field public static final android.icu.lang.UCharacter.UnicodeBlock CYRILLIC_SUPPLEMENT;
field public static final android.icu.lang.UCharacter.UnicodeBlock CYRILLIC_SUPPLEMENTARY;
@@ -16540,6 +16561,8 @@
field public static final int GEORGIAN_SUPPLEMENT_ID = 135; // 0x87
field public static final android.icu.lang.UCharacter.UnicodeBlock GLAGOLITIC;
field public static final int GLAGOLITIC_ID = 136; // 0x88
+ field public static final android.icu.lang.UCharacter.UnicodeBlock GLAGOLITIC_SUPPLEMENT;
+ field public static final int GLAGOLITIC_SUPPLEMENT_ID = 266; // 0x10a
field public static final android.icu.lang.UCharacter.UnicodeBlock GOTHIC;
field public static final int GOTHIC_ID = 89; // 0x59
field public static final android.icu.lang.UCharacter.UnicodeBlock GRANTHA;
@@ -16578,6 +16601,8 @@
field public static final int HIRAGANA_ID = 62; // 0x3e
field public static final android.icu.lang.UCharacter.UnicodeBlock IDEOGRAPHIC_DESCRIPTION_CHARACTERS;
field public static final int IDEOGRAPHIC_DESCRIPTION_CHARACTERS_ID = 60; // 0x3c
+ field public static final android.icu.lang.UCharacter.UnicodeBlock IDEOGRAPHIC_SYMBOLS_AND_PUNCTUATION;
+ field public static final int IDEOGRAPHIC_SYMBOLS_AND_PUNCTUATION_ID = 267; // 0x10b
field public static final android.icu.lang.UCharacter.UnicodeBlock IMPERIAL_ARAMAIC;
field public static final int IMPERIAL_ARAMAIC_ID = 186; // 0xba
field public static final android.icu.lang.UCharacter.UnicodeBlock INSCRIPTIONAL_PAHLAVI;
@@ -16662,6 +16687,8 @@
field public static final int MANDAIC_ID = 198; // 0xc6
field public static final android.icu.lang.UCharacter.UnicodeBlock MANICHAEAN;
field public static final int MANICHAEAN_ID = 234; // 0xea
+ field public static final android.icu.lang.UCharacter.UnicodeBlock MARCHEN;
+ field public static final int MARCHEN_ID = 268; // 0x10c
field public static final android.icu.lang.UCharacter.UnicodeBlock MATHEMATICAL_ALPHANUMERIC_SYMBOLS;
field public static final int MATHEMATICAL_ALPHANUMERIC_SYMBOLS_ID = 93; // 0x5d
field public static final android.icu.lang.UCharacter.UnicodeBlock MATHEMATICAL_OPERATORS;
@@ -16696,6 +16723,8 @@
field public static final int MODI_ID = 236; // 0xec
field public static final android.icu.lang.UCharacter.UnicodeBlock MONGOLIAN;
field public static final int MONGOLIAN_ID = 37; // 0x25
+ field public static final android.icu.lang.UCharacter.UnicodeBlock MONGOLIAN_SUPPLEMENT;
+ field public static final int MONGOLIAN_SUPPLEMENT_ID = 269; // 0x10d
field public static final android.icu.lang.UCharacter.UnicodeBlock MRO;
field public static final int MRO_ID = 237; // 0xed
field public static final android.icu.lang.UCharacter.UnicodeBlock MULTANI;
@@ -16710,6 +16739,8 @@
field public static final int MYANMAR_ID = 28; // 0x1c
field public static final android.icu.lang.UCharacter.UnicodeBlock NABATAEAN;
field public static final int NABATAEAN_ID = 239; // 0xef
+ field public static final android.icu.lang.UCharacter.UnicodeBlock NEWA;
+ field public static final int NEWA_ID = 270; // 0x10e
field public static final android.icu.lang.UCharacter.UnicodeBlock NEW_TAI_LUE;
field public static final int NEW_TAI_LUE_ID = 139; // 0x8b
field public static final android.icu.lang.UCharacter.UnicodeBlock NKO;
@@ -16741,6 +16772,8 @@
field public static final int ORIYA_ID = 19; // 0x13
field public static final android.icu.lang.UCharacter.UnicodeBlock ORNAMENTAL_DINGBATS;
field public static final int ORNAMENTAL_DINGBATS_ID = 242; // 0xf2
+ field public static final android.icu.lang.UCharacter.UnicodeBlock OSAGE;
+ field public static final int OSAGE_ID = 271; // 0x10f
field public static final android.icu.lang.UCharacter.UnicodeBlock OSMANYA;
field public static final int OSMANYA_ID = 122; // 0x7a
field public static final android.icu.lang.UCharacter.UnicodeBlock PAHAWH_HMONG;
@@ -16843,6 +16876,10 @@
field public static final int TAKRI_ID = 220; // 0xdc
field public static final android.icu.lang.UCharacter.UnicodeBlock TAMIL;
field public static final int TAMIL_ID = 20; // 0x14
+ field public static final android.icu.lang.UCharacter.UnicodeBlock TANGUT;
+ field public static final android.icu.lang.UCharacter.UnicodeBlock TANGUT_COMPONENTS;
+ field public static final int TANGUT_COMPONENTS_ID = 273; // 0x111
+ field public static final int TANGUT_ID = 272; // 0x110
field public static final android.icu.lang.UCharacter.UnicodeBlock TELUGU;
field public static final int TELUGU_ID = 21; // 0x15
field public static final android.icu.lang.UCharacter.UnicodeBlock THAANA;
@@ -16889,7 +16926,11 @@
field public static final int DOUBLE_QUOTE = 16; // 0x10
field public static final int EXTEND = 9; // 0x9
field public static final int EXTENDNUMLET = 7; // 0x7
+ field public static final int E_BASE = 17; // 0x11
+ field public static final int E_BASE_GAZ = 18; // 0x12
+ field public static final int E_MODIFIER = 19; // 0x13
field public static final int FORMAT = 2; // 0x2
+ field public static final int GLUE_AFTER_ZWJ = 20; // 0x14
field public static final int HEBREW_LETTER = 14; // 0xe
field public static final int KATAKANA = 3; // 0x3
field public static final int LF = 10; // 0xa
@@ -16901,6 +16942,7 @@
field public static final int OTHER = 0; // 0x0
field public static final int REGIONAL_INDICATOR = 13; // 0xd
field public static final int SINGLE_QUOTE = 15; // 0xf
+ field public static final int ZWJ = 21; // 0x15
}
public final class UCharacterCategory implements android.icu.lang.UCharacterEnums.ECharacterCategory {
@@ -17119,6 +17161,7 @@
method public static final boolean hasScript(int, int);
method public static final boolean isCased(int);
method public static final boolean isRightToLeft(int);
+ field public static final int ADLAM = 167; // 0xa7
field public static final int AFAKA = 147; // 0x93
field public static final int AHOM = 161; // 0xa1
field public static final int ANATOLIAN_HIEROGLYPHS = 156; // 0x9c
@@ -17130,6 +17173,7 @@
field public static final int BASSA_VAH = 134; // 0x86
field public static final int BATAK = 63; // 0x3f
field public static final int BENGALI = 4; // 0x4
+ field public static final int BHAIKSUKI = 168; // 0xa8
field public static final int BLISSYMBOLS = 64; // 0x40
field public static final int BOOK_PAHLAVI = 124; // 0x7c
field public static final int BOPOMOFO = 5; // 0x5
@@ -17168,6 +17212,7 @@
field public static final int HAN = 17; // 0x11
field public static final int HANGUL = 18; // 0x12
field public static final int HANUNOO = 43; // 0x2b
+ field public static final int HAN_WITH_BOPOMOFO = 172; // 0xac
field public static final int HARAPPAN_INDUS = 77; // 0x4d
field public static final int HATRAN = 162; // 0xa2
field public static final int HEBREW = 19; // 0x13
@@ -17178,6 +17223,7 @@
field public static final int INSCRIPTIONAL_PAHLAVI = 122; // 0x7a
field public static final int INSCRIPTIONAL_PARTHIAN = 125; // 0x7d
field public static final int INVALID_CODE = -1; // 0xffffffff
+ field public static final int JAMO = 173; // 0xad
field public static final int JAPANESE = 105; // 0x69
field public static final int JAVANESE = 78; // 0x4e
field public static final int JURCHEN = 148; // 0x94
@@ -17211,6 +17257,7 @@
field public static final int MANDAEAN = 84; // 0x54
field public static final int MANDAIC = 84; // 0x54
field public static final int MANICHAEAN = 121; // 0x79
+ field public static final int MARCHEN = 169; // 0xa9
field public static final int MATHEMATICAL_NOTATION = 128; // 0x80
field public static final int MAYAN_HIEROGLYPHS = 85; // 0x55
field public static final int MEITEI_MAYEK = 115; // 0x73
@@ -17227,6 +17274,7 @@
field public static final int MYANMAR = 28; // 0x1c
field public static final int NABATAEAN = 143; // 0x8f
field public static final int NAKHI_GEBA = 132; // 0x84
+ field public static final int NEWA = 170; // 0xaa
field public static final int NEW_TAI_LUE = 59; // 0x3b
field public static final int NKO = 87; // 0x57
field public static final int NUSHU = 150; // 0x96
@@ -17241,6 +17289,7 @@
field public static final int OL_CHIKI = 109; // 0x6d
field public static final int ORIYA = 31; // 0x1f
field public static final int ORKHON = 88; // 0x58
+ field public static final int OSAGE = 171; // 0xab
field public static final int OSMANYA = 50; // 0x32
field public static final int PAHAWH_HMONG = 75; // 0x4b
field public static final int PALMYRENE = 144; // 0x90
@@ -17266,6 +17315,7 @@
field public static final int SUNDANESE = 113; // 0x71
field public static final int SYLOTI_NAGRI = 58; // 0x3a
field public static final int SYMBOLS = 129; // 0x81
+ field public static final int SYMBOLS_EMOJI = 174; // 0xae
field public static final int SYRIAC = 34; // 0x22
field public static final int TAGALOG = 42; // 0x2a
field public static final int TAGBANWA = 45; // 0x2d
@@ -17792,6 +17842,8 @@
method public static final android.icu.text.DateFormat.BooleanAttribute[] values();
enum_constant public static final android.icu.text.DateFormat.BooleanAttribute PARSE_ALLOW_NUMERIC;
enum_constant public static final android.icu.text.DateFormat.BooleanAttribute PARSE_ALLOW_WHITESPACE;
+ enum_constant public static final android.icu.text.DateFormat.BooleanAttribute PARSE_MULTIPLE_PATTERNS_FOR_MATCH;
+ enum_constant public static final android.icu.text.DateFormat.BooleanAttribute PARSE_PARTIAL_LITERAL_MATCH;
}
public static class DateFormat.Field extends java.text.Format.Field {
@@ -18476,6 +18528,7 @@
field public static final int PERCENTSTYLE = 2; // 0x2
field public static final int PLURALCURRENCYSTYLE = 6; // 0x6
field public static final int SCIENTIFICSTYLE = 3; // 0x3
+ field public static final int STANDARDCURRENCYSTYLE = 9; // 0x9
}
public static class NumberFormat.Field extends java.text.Format.Field {
@@ -19270,7 +19323,7 @@
field public static final int AM_PM = 9; // 0x9
field public static final int APRIL = 3; // 0x3
field public static final int AUGUST = 7; // 0x7
- field protected static final int BASE_FIELD_COUNT = 23; // 0x17
+ field protected static final deprecated int BASE_FIELD_COUNT = 23; // 0x17
field public static final int DATE = 5; // 0x5
field public static final int DAY_OF_MONTH = 5; // 0x5
field public static final int DAY_OF_WEEK = 7; // 0x7
@@ -19298,7 +19351,7 @@
field public static final int MARCH = 2; // 0x2
field protected static final int MAXIMUM = 3; // 0x3
field protected static final java.util.Date MAX_DATE;
- field protected static final int MAX_FIELD_COUNT = 32; // 0x20
+ field protected static final deprecated int MAX_FIELD_COUNT = 32; // 0x20
field protected static final int MAX_JULIAN = 2130706432; // 0x7f000000
field protected static final long MAX_MILLIS = 183882168921600000L; // 0x28d47dbbf19b000L
field public static final int MAY = 4; // 0x4
@@ -19618,6 +19671,7 @@
field public static final android.icu.util.MeasureUnit CELSIUS;
field public static final android.icu.util.MeasureUnit CENTILITER;
field public static final android.icu.util.MeasureUnit CENTIMETER;
+ field public static final android.icu.util.MeasureUnit CENTURY;
field public static final android.icu.util.MeasureUnit CUBIC_CENTIMETER;
field public static final android.icu.util.MeasureUnit CUBIC_FOOT;
field public static final android.icu.util.MeasureUnit CUBIC_INCH;
@@ -19626,6 +19680,7 @@
field public static final android.icu.util.MeasureUnit CUBIC_MILE;
field public static final android.icu.util.MeasureUnit CUBIC_YARD;
field public static final android.icu.util.MeasureUnit CUP;
+ field public static final android.icu.util.MeasureUnit CUP_METRIC;
field public static final android.icu.util.TimeUnit DAY;
field public static final android.icu.util.MeasureUnit DECILITER;
field public static final android.icu.util.MeasureUnit DECIMETER;
@@ -19637,6 +19692,7 @@
field public static final android.icu.util.MeasureUnit FOOT;
field public static final android.icu.util.MeasureUnit FURLONG;
field public static final android.icu.util.MeasureUnit GALLON;
+ field public static final android.icu.util.MeasureUnit GENERIC_TEMPERATURE;
field public static final android.icu.util.MeasureUnit GIGABIT;
field public static final android.icu.util.MeasureUnit GIGABYTE;
field public static final android.icu.util.MeasureUnit GIGAHERTZ;
@@ -19664,8 +19720,10 @@
field public static final android.icu.util.MeasureUnit KILOMETER_PER_HOUR;
field public static final android.icu.util.MeasureUnit KILOWATT;
field public static final android.icu.util.MeasureUnit KILOWATT_HOUR;
+ field public static final android.icu.util.MeasureUnit KNOT;
field public static final android.icu.util.MeasureUnit LIGHT_YEAR;
field public static final android.icu.util.MeasureUnit LITER;
+ field public static final android.icu.util.MeasureUnit LITER_PER_100KILOMETERS;
field public static final android.icu.util.MeasureUnit LITER_PER_KILOMETER;
field public static final android.icu.util.MeasureUnit LUX;
field public static final android.icu.util.MeasureUnit MEGABIT;
@@ -19683,6 +19741,7 @@
field public static final android.icu.util.MeasureUnit MILE;
field public static final android.icu.util.MeasureUnit MILE_PER_GALLON;
field public static final android.icu.util.MeasureUnit MILE_PER_HOUR;
+ field public static final android.icu.util.MeasureUnit MILE_SCANDINAVIAN;
field public static final android.icu.util.MeasureUnit MILLIAMPERE;
field public static final android.icu.util.MeasureUnit MILLIBAR;
field public static final android.icu.util.MeasureUnit MILLIGRAM;
@@ -19702,10 +19761,12 @@
field public static final android.icu.util.MeasureUnit PARSEC;
field public static final android.icu.util.MeasureUnit PICOMETER;
field public static final android.icu.util.MeasureUnit PINT;
+ field public static final android.icu.util.MeasureUnit PINT_METRIC;
field public static final android.icu.util.MeasureUnit POUND;
field public static final android.icu.util.MeasureUnit POUND_PER_SQUARE_INCH;
field public static final android.icu.util.MeasureUnit QUART;
field public static final android.icu.util.MeasureUnit RADIAN;
+ field public static final android.icu.util.MeasureUnit REVOLUTION_ANGLE;
field public static final android.icu.util.TimeUnit SECOND;
field public static final android.icu.util.MeasureUnit SQUARE_CENTIMETER;
field public static final android.icu.util.MeasureUnit SQUARE_FOOT;
@@ -20017,6 +20078,7 @@
field public static final android.icu.util.VersionInfo UNICODE_6_3;
field public static final android.icu.util.VersionInfo UNICODE_7_0;
field public static final android.icu.util.VersionInfo UNICODE_8_0;
+ field public static final android.icu.util.VersionInfo UNICODE_9_0;
}
}
@@ -25605,11 +25667,16 @@
public abstract class NetworkRecommendationProvider {
ctor public NetworkRecommendationProvider(android.os.Handler);
method public final android.os.IBinder getBinder();
- method public abstract android.net.RecommendationResult onRequestRecommendation(android.net.RecommendationRequest);
+ method public abstract void onRequestRecommendation(android.net.RecommendationRequest, android.net.NetworkRecommendationProvider.ResultCallback);
+ method public abstract void onRequestScores(android.net.NetworkKey[]);
field public static final java.lang.String EXTRA_RECOMMENDATION_RESULT = "android.net.extra.RECOMMENDATION_RESULT";
field public static final java.lang.String EXTRA_SEQUENCE = "android.net.extra.SEQUENCE";
}
+ public static class NetworkRecommendationProvider.ResultCallback {
+ method public void onResult(android.net.RecommendationResult);
+ }
+
public class NetworkRequest implements android.os.Parcelable {
method public int describeContents();
method public void writeToParcel(android.os.Parcel, int);
@@ -25694,9 +25761,11 @@
}
public final class RecommendationResult implements android.os.Parcelable {
- ctor public RecommendationResult(android.net.wifi.WifiConfiguration);
+ method public static android.net.RecommendationResult createConnectRecommendation(android.net.wifi.WifiConfiguration);
+ method public static android.net.RecommendationResult createDoNotConnectRecommendation();
method public int describeContents();
method public android.net.wifi.WifiConfiguration getWifiConfiguration();
+ method public boolean hasRecommendation();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.net.RecommendationResult> CREATOR;
}
@@ -25757,8 +25826,9 @@
ctor public ScoredNetwork(android.net.NetworkKey, android.net.RssiCurve, boolean, android.os.Bundle);
method public int describeContents();
method public void writeToParcel(android.os.Parcel, int);
+ field public static final java.lang.String ATTRIBUTES_KEY_HAS_CAPTIVE_PORTAL = "android.net.attributes.key.HAS_CAPTIVE_PORTAL";
+ field public static final java.lang.String ATTRIBUTES_KEY_RANKING_SCORE_OFFSET = "android.net.attributes.key.RANKING_SCORE_OFFSET";
field public static final android.os.Parcelable.Creator<android.net.ScoredNetwork> CREATOR;
- field public static final java.lang.String EXTRA_HAS_CAPTIVE_PORTAL = "android.net.extra.HAS_CAPTIVE_PORTAL";
field public final android.os.Bundle attributes;
field public final boolean meteredHint;
field public final android.net.NetworkKey networkKey;
@@ -26745,6 +26815,7 @@
field public int level;
field public java.lang.CharSequence operatorFriendlyName;
field public long timestamp;
+ field public boolean untrusted;
field public java.lang.CharSequence venueName;
}
@@ -26788,6 +26859,7 @@
field public boolean hiddenSSID;
field public java.lang.String lastUpdateName;
field public int lastUpdateUid;
+ field public boolean meteredHint;
field public int networkId;
field public int numAssociation;
field public int numScorerOverride;
@@ -39993,6 +40065,7 @@
field public static final java.lang.String KEY_SHOW_CDMA_CHOICES_BOOL = "show_cdma_choices_bool";
field public static final java.lang.String KEY_SHOW_ICCID_IN_SIM_STATUS_BOOL = "show_iccid_in_sim_status_bool";
field public static final java.lang.String KEY_SHOW_ONSCREEN_DIAL_BUTTON_BOOL = "show_onscreen_dial_button_bool";
+ field public static final java.lang.String KEY_SIMPLIFIED_NETWORK_SETTINGS_BOOL = "simplified_network_settings_bool";
field public static final java.lang.String KEY_SIM_NETWORK_UNLOCK_ALLOW_DISMISS_BOOL = "sim_network_unlock_allow_dismiss_bool";
field public static final java.lang.String KEY_SUPPORT_CONFERENCE_CALL_BOOL = "support_conference_call_bool";
field public static final java.lang.String KEY_SUPPORT_PAUSE_IMS_VIDEO_CALLS_BOOL = "support_pause_ims_video_calls_bool";
@@ -40568,6 +40641,7 @@
method public java.lang.String getSimOperatorName();
method public java.lang.String getSimSerialNumber();
method public int getSimState();
+ method public int getSimState(int);
method public java.lang.String getSubscriberId();
method public java.util.List<android.telephony.TelephonyHistogram> getTelephonyHistograms();
method public java.lang.String getVoiceMailAlphaTag();
@@ -40681,7 +40755,11 @@
field public static final int SIM_ACTIVATION_RESULT_IN_PROGRESS = 2; // 0x2
field public static final int SIM_ACTIVATION_RESULT_NOT_SUPPORTED = 1; // 0x1
field public static final int SIM_STATE_ABSENT = 1; // 0x1
+ field public static final int SIM_STATE_CARD_IO_ERROR = 8; // 0x8
+ field public static final int SIM_STATE_CARD_RESTRICTED = 9; // 0x9
field public static final int SIM_STATE_NETWORK_LOCKED = 4; // 0x4
+ field public static final int SIM_STATE_NOT_READY = 6; // 0x6
+ field public static final int SIM_STATE_PERM_DISABLED = 7; // 0x7
field public static final int SIM_STATE_PIN_REQUIRED = 2; // 0x2
field public static final int SIM_STATE_PUK_REQUIRED = 3; // 0x3
field public static final int SIM_STATE_READY = 5; // 0x5
@@ -62857,6 +62935,10 @@
ctor public Locale(java.lang.String, java.lang.String);
ctor public Locale(java.lang.String);
method public java.lang.Object clone();
+ method public static java.util.List<java.util.Locale> filter(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.util.Locale>, java.util.Locale.FilteringMode);
+ method public static java.util.List<java.util.Locale> filter(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.util.Locale>);
+ method public static java.util.List<java.lang.String> filterTags(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.lang.String>, java.util.Locale.FilteringMode);
+ method public static java.util.List<java.lang.String> filterTags(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.lang.String>);
method public static java.util.Locale forLanguageTag(java.lang.String);
method public static java.util.Locale[] getAvailableLocales();
method public java.lang.String getCountry();
@@ -62885,6 +62967,8 @@
method public java.lang.String getUnicodeLocaleType(java.lang.String);
method public java.lang.String getVariant();
method public boolean hasExtensions();
+ method public static java.util.Locale lookup(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.util.Locale>);
+ method public static java.lang.String lookupTag(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.lang.String>);
method public static synchronized void setDefault(java.util.Locale);
method public static synchronized void setDefault(java.util.Locale.Category, java.util.Locale);
method public java.util.Locale stripExtensions();
@@ -62940,6 +63024,28 @@
enum_constant public static final java.util.Locale.Category FORMAT;
}
+ public static final class Locale.FilteringMode extends java.lang.Enum {
+ method public static java.util.Locale.FilteringMode valueOf(java.lang.String);
+ method public static final java.util.Locale.FilteringMode[] values();
+ enum_constant public static final java.util.Locale.FilteringMode AUTOSELECT_FILTERING;
+ enum_constant public static final java.util.Locale.FilteringMode EXTENDED_FILTERING;
+ enum_constant public static final java.util.Locale.FilteringMode IGNORE_EXTENDED_RANGES;
+ enum_constant public static final java.util.Locale.FilteringMode MAP_EXTENDED_RANGES;
+ enum_constant public static final java.util.Locale.FilteringMode REJECT_EXTENDED_RANGES;
+ }
+
+ public static final class Locale.LanguageRange {
+ ctor public Locale.LanguageRange(java.lang.String);
+ ctor public Locale.LanguageRange(java.lang.String, double);
+ method public java.lang.String getRange();
+ method public double getWeight();
+ method public static java.util.List<java.util.Locale.LanguageRange> mapEquivalents(java.util.List<java.util.Locale.LanguageRange>, java.util.Map<java.lang.String, java.util.List<java.lang.String>>);
+ method public static java.util.List<java.util.Locale.LanguageRange> parse(java.lang.String);
+ method public static java.util.List<java.util.Locale.LanguageRange> parse(java.lang.String, java.util.Map<java.lang.String, java.util.List<java.lang.String>>);
+ field public static final double MAX_WEIGHT = 1.0;
+ field public static final double MIN_WEIGHT = 0.0;
+ }
+
public class LongSummaryStatistics implements java.util.function.IntConsumer java.util.function.LongConsumer {
ctor public LongSummaryStatistics();
method public void accept(int);
@@ -65606,13 +65712,13 @@
ctor public Attributes.Name(java.lang.String);
field public static final java.util.jar.Attributes.Name CLASS_PATH;
field public static final java.util.jar.Attributes.Name CONTENT_TYPE;
- field public static final java.util.jar.Attributes.Name EXTENSION_INSTALLATION;
+ field public static final deprecated java.util.jar.Attributes.Name EXTENSION_INSTALLATION;
field public static final java.util.jar.Attributes.Name EXTENSION_LIST;
field public static final java.util.jar.Attributes.Name EXTENSION_NAME;
field public static final java.util.jar.Attributes.Name IMPLEMENTATION_TITLE;
- field public static final java.util.jar.Attributes.Name IMPLEMENTATION_URL;
+ field public static final deprecated java.util.jar.Attributes.Name IMPLEMENTATION_URL;
field public static final java.util.jar.Attributes.Name IMPLEMENTATION_VENDOR;
- field public static final java.util.jar.Attributes.Name IMPLEMENTATION_VENDOR_ID;
+ field public static final deprecated java.util.jar.Attributes.Name IMPLEMENTATION_VENDOR_ID;
field public static final java.util.jar.Attributes.Name IMPLEMENTATION_VERSION;
field public static final java.util.jar.Attributes.Name MAIN_CLASS;
field public static final java.util.jar.Attributes.Name MANIFEST_VERSION;
@@ -65679,11 +65785,11 @@
}
public static abstract interface Pack200.Packer {
- method public abstract void addPropertyChangeListener(java.beans.PropertyChangeListener);
+ method public default deprecated void addPropertyChangeListener(java.beans.PropertyChangeListener);
method public abstract void pack(java.util.jar.JarFile, java.io.OutputStream) throws java.io.IOException;
method public abstract void pack(java.util.jar.JarInputStream, java.io.OutputStream) throws java.io.IOException;
method public abstract java.util.SortedMap<java.lang.String, java.lang.String> properties();
- method public abstract void removePropertyChangeListener(java.beans.PropertyChangeListener);
+ method public default deprecated void removePropertyChangeListener(java.beans.PropertyChangeListener);
field public static final java.lang.String CLASS_ATTRIBUTE_PFX = "pack.class.attribute.";
field public static final java.lang.String CODE_ATTRIBUTE_PFX = "pack.code.attribute.";
field public static final java.lang.String DEFLATE_HINT = "pack.deflate.hint";
@@ -65706,9 +65812,9 @@
}
public static abstract interface Pack200.Unpacker {
- method public abstract void addPropertyChangeListener(java.beans.PropertyChangeListener);
+ method public default deprecated void addPropertyChangeListener(java.beans.PropertyChangeListener);
method public abstract java.util.SortedMap<java.lang.String, java.lang.String> properties();
- method public abstract void removePropertyChangeListener(java.beans.PropertyChangeListener);
+ method public default deprecated void removePropertyChangeListener(java.beans.PropertyChangeListener);
method public abstract void unpack(java.io.InputStream, java.util.jar.JarOutputStream) throws java.io.IOException;
method public abstract void unpack(java.io.File, java.util.jar.JarOutputStream) throws java.io.IOException;
field public static final java.lang.String DEFLATE_HINT = "unpack.deflate.hint";
diff --git a/api/test-current.txt b/api/test-current.txt
index 8e3d4ef..e3a395b 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -6456,6 +6456,7 @@
public static class NetworkStats.Bucket {
ctor public NetworkStats.Bucket();
method public long getEndTimeStamp();
+ method public int getMetered();
method public int getRoaming();
method public long getRxBytes();
method public long getRxPackets();
@@ -6465,6 +6466,9 @@
method public long getTxBytes();
method public long getTxPackets();
method public int getUid();
+ field public static final int METERED_ALL = -1; // 0xffffffff
+ field public static final int METERED_NO = 1; // 0x1
+ field public static final int METERED_YES = 2; // 0x2
field public static final int ROAMING_ALL = -1; // 0xffffffff
field public static final int ROAMING_NO = 1; // 0x1
field public static final int ROAMING_YES = 2; // 0x2
@@ -14963,6 +14967,10 @@
field public static final int CONTROL = 1; // 0x1
field public static final int CR = 2; // 0x2
field public static final int EXTEND = 3; // 0x3
+ field public static final int E_BASE = 13; // 0xd
+ field public static final int E_BASE_GAZ = 14; // 0xe
+ field public static final int E_MODIFIER = 15; // 0xf
+ field public static final int GLUE_AFTER_ZWJ = 16; // 0x10
field public static final int L = 4; // 0x4
field public static final int LF = 5; // 0x5
field public static final int LV = 6; // 0x6
@@ -14973,6 +14981,7 @@
field public static final int SPACING_MARK = 10; // 0xa
field public static final int T = 8; // 0x8
field public static final int V = 9; // 0x9
+ field public static final int ZWJ = 17; // 0x11
}
public static abstract interface UCharacter.HangulSyllableType {
@@ -14985,6 +14994,9 @@
}
public static abstract interface UCharacter.JoiningGroup {
+ field public static final int AFRICAN_FEH = 86; // 0x56
+ field public static final int AFRICAN_NOON = 87; // 0x57
+ field public static final int AFRICAN_QAF = 88; // 0x58
field public static final int AIN = 1; // 0x1
field public static final int ALAPH = 2; // 0x2
field public static final int ALEF = 3; // 0x3
@@ -15098,6 +15110,8 @@
field public static final int CONDITIONAL_JAPANESE_STARTER = 37; // 0x25
field public static final int CONTINGENT_BREAK = 7; // 0x7
field public static final int EXCLAMATION = 11; // 0xb
+ field public static final int E_BASE = 40; // 0x28
+ field public static final int E_MODIFIER = 41; // 0x29
field public static final int GLUE = 12; // 0xc
field public static final int H2 = 31; // 0x1f
field public static final int H3 = 32; // 0x20
@@ -15124,6 +15138,7 @@
field public static final int SURROGATE = 25; // 0x19
field public static final int UNKNOWN = 0; // 0x0
field public static final int WORD_JOINER = 30; // 0x1e
+ field public static final int ZWJ = 42; // 0x2a
field public static final int ZWSPACE = 28; // 0x1c
}
@@ -15157,6 +15172,8 @@
method public int getID();
method public static android.icu.lang.UCharacter.UnicodeBlock getInstance(int);
method public static android.icu.lang.UCharacter.UnicodeBlock of(int);
+ field public static final android.icu.lang.UCharacter.UnicodeBlock ADLAM;
+ field public static final int ADLAM_ID = 263; // 0x107
field public static final android.icu.lang.UCharacter.UnicodeBlock AEGEAN_NUMBERS;
field public static final int AEGEAN_NUMBERS_ID = 119; // 0x77
field public static final android.icu.lang.UCharacter.UnicodeBlock AHOM;
@@ -15205,6 +15222,8 @@
field public static final int BATAK_ID = 199; // 0xc7
field public static final android.icu.lang.UCharacter.UnicodeBlock BENGALI;
field public static final int BENGALI_ID = 16; // 0x10
+ field public static final android.icu.lang.UCharacter.UnicodeBlock BHAIKSUKI;
+ field public static final int BHAIKSUKI_ID = 264; // 0x108
field public static final android.icu.lang.UCharacter.UnicodeBlock BLOCK_ELEMENTS;
field public static final int BLOCK_ELEMENTS_ID = 53; // 0x35
field public static final android.icu.lang.UCharacter.UnicodeBlock BOPOMOFO;
@@ -15294,6 +15313,8 @@
field public static final int CYRILLIC_EXTENDED_A_ID = 158; // 0x9e
field public static final android.icu.lang.UCharacter.UnicodeBlock CYRILLIC_EXTENDED_B;
field public static final int CYRILLIC_EXTENDED_B_ID = 160; // 0xa0
+ field public static final android.icu.lang.UCharacter.UnicodeBlock CYRILLIC_EXTENDED_C;
+ field public static final int CYRILLIC_EXTENDED_C_ID = 265; // 0x109
field public static final int CYRILLIC_ID = 9; // 0x9
field public static final android.icu.lang.UCharacter.UnicodeBlock CYRILLIC_SUPPLEMENT;
field public static final android.icu.lang.UCharacter.UnicodeBlock CYRILLIC_SUPPLEMENTARY;
@@ -15347,6 +15368,8 @@
field public static final int GEORGIAN_SUPPLEMENT_ID = 135; // 0x87
field public static final android.icu.lang.UCharacter.UnicodeBlock GLAGOLITIC;
field public static final int GLAGOLITIC_ID = 136; // 0x88
+ field public static final android.icu.lang.UCharacter.UnicodeBlock GLAGOLITIC_SUPPLEMENT;
+ field public static final int GLAGOLITIC_SUPPLEMENT_ID = 266; // 0x10a
field public static final android.icu.lang.UCharacter.UnicodeBlock GOTHIC;
field public static final int GOTHIC_ID = 89; // 0x59
field public static final android.icu.lang.UCharacter.UnicodeBlock GRANTHA;
@@ -15385,6 +15408,8 @@
field public static final int HIRAGANA_ID = 62; // 0x3e
field public static final android.icu.lang.UCharacter.UnicodeBlock IDEOGRAPHIC_DESCRIPTION_CHARACTERS;
field public static final int IDEOGRAPHIC_DESCRIPTION_CHARACTERS_ID = 60; // 0x3c
+ field public static final android.icu.lang.UCharacter.UnicodeBlock IDEOGRAPHIC_SYMBOLS_AND_PUNCTUATION;
+ field public static final int IDEOGRAPHIC_SYMBOLS_AND_PUNCTUATION_ID = 267; // 0x10b
field public static final android.icu.lang.UCharacter.UnicodeBlock IMPERIAL_ARAMAIC;
field public static final int IMPERIAL_ARAMAIC_ID = 186; // 0xba
field public static final android.icu.lang.UCharacter.UnicodeBlock INSCRIPTIONAL_PAHLAVI;
@@ -15469,6 +15494,8 @@
field public static final int MANDAIC_ID = 198; // 0xc6
field public static final android.icu.lang.UCharacter.UnicodeBlock MANICHAEAN;
field public static final int MANICHAEAN_ID = 234; // 0xea
+ field public static final android.icu.lang.UCharacter.UnicodeBlock MARCHEN;
+ field public static final int MARCHEN_ID = 268; // 0x10c
field public static final android.icu.lang.UCharacter.UnicodeBlock MATHEMATICAL_ALPHANUMERIC_SYMBOLS;
field public static final int MATHEMATICAL_ALPHANUMERIC_SYMBOLS_ID = 93; // 0x5d
field public static final android.icu.lang.UCharacter.UnicodeBlock MATHEMATICAL_OPERATORS;
@@ -15503,6 +15530,8 @@
field public static final int MODI_ID = 236; // 0xec
field public static final android.icu.lang.UCharacter.UnicodeBlock MONGOLIAN;
field public static final int MONGOLIAN_ID = 37; // 0x25
+ field public static final android.icu.lang.UCharacter.UnicodeBlock MONGOLIAN_SUPPLEMENT;
+ field public static final int MONGOLIAN_SUPPLEMENT_ID = 269; // 0x10d
field public static final android.icu.lang.UCharacter.UnicodeBlock MRO;
field public static final int MRO_ID = 237; // 0xed
field public static final android.icu.lang.UCharacter.UnicodeBlock MULTANI;
@@ -15517,6 +15546,8 @@
field public static final int MYANMAR_ID = 28; // 0x1c
field public static final android.icu.lang.UCharacter.UnicodeBlock NABATAEAN;
field public static final int NABATAEAN_ID = 239; // 0xef
+ field public static final android.icu.lang.UCharacter.UnicodeBlock NEWA;
+ field public static final int NEWA_ID = 270; // 0x10e
field public static final android.icu.lang.UCharacter.UnicodeBlock NEW_TAI_LUE;
field public static final int NEW_TAI_LUE_ID = 139; // 0x8b
field public static final android.icu.lang.UCharacter.UnicodeBlock NKO;
@@ -15548,6 +15579,8 @@
field public static final int ORIYA_ID = 19; // 0x13
field public static final android.icu.lang.UCharacter.UnicodeBlock ORNAMENTAL_DINGBATS;
field public static final int ORNAMENTAL_DINGBATS_ID = 242; // 0xf2
+ field public static final android.icu.lang.UCharacter.UnicodeBlock OSAGE;
+ field public static final int OSAGE_ID = 271; // 0x10f
field public static final android.icu.lang.UCharacter.UnicodeBlock OSMANYA;
field public static final int OSMANYA_ID = 122; // 0x7a
field public static final android.icu.lang.UCharacter.UnicodeBlock PAHAWH_HMONG;
@@ -15650,6 +15683,10 @@
field public static final int TAKRI_ID = 220; // 0xdc
field public static final android.icu.lang.UCharacter.UnicodeBlock TAMIL;
field public static final int TAMIL_ID = 20; // 0x14
+ field public static final android.icu.lang.UCharacter.UnicodeBlock TANGUT;
+ field public static final android.icu.lang.UCharacter.UnicodeBlock TANGUT_COMPONENTS;
+ field public static final int TANGUT_COMPONENTS_ID = 273; // 0x111
+ field public static final int TANGUT_ID = 272; // 0x110
field public static final android.icu.lang.UCharacter.UnicodeBlock TELUGU;
field public static final int TELUGU_ID = 21; // 0x15
field public static final android.icu.lang.UCharacter.UnicodeBlock THAANA;
@@ -15696,7 +15733,11 @@
field public static final int DOUBLE_QUOTE = 16; // 0x10
field public static final int EXTEND = 9; // 0x9
field public static final int EXTENDNUMLET = 7; // 0x7
+ field public static final int E_BASE = 17; // 0x11
+ field public static final int E_BASE_GAZ = 18; // 0x12
+ field public static final int E_MODIFIER = 19; // 0x13
field public static final int FORMAT = 2; // 0x2
+ field public static final int GLUE_AFTER_ZWJ = 20; // 0x14
field public static final int HEBREW_LETTER = 14; // 0xe
field public static final int KATAKANA = 3; // 0x3
field public static final int LF = 10; // 0xa
@@ -15708,6 +15749,7 @@
field public static final int OTHER = 0; // 0x0
field public static final int REGIONAL_INDICATOR = 13; // 0xd
field public static final int SINGLE_QUOTE = 15; // 0xf
+ field public static final int ZWJ = 21; // 0x15
}
public final class UCharacterCategory implements android.icu.lang.UCharacterEnums.ECharacterCategory {
@@ -15926,6 +15968,7 @@
method public static final boolean hasScript(int, int);
method public static final boolean isCased(int);
method public static final boolean isRightToLeft(int);
+ field public static final int ADLAM = 167; // 0xa7
field public static final int AFAKA = 147; // 0x93
field public static final int AHOM = 161; // 0xa1
field public static final int ANATOLIAN_HIEROGLYPHS = 156; // 0x9c
@@ -15937,6 +15980,7 @@
field public static final int BASSA_VAH = 134; // 0x86
field public static final int BATAK = 63; // 0x3f
field public static final int BENGALI = 4; // 0x4
+ field public static final int BHAIKSUKI = 168; // 0xa8
field public static final int BLISSYMBOLS = 64; // 0x40
field public static final int BOOK_PAHLAVI = 124; // 0x7c
field public static final int BOPOMOFO = 5; // 0x5
@@ -15975,6 +16019,7 @@
field public static final int HAN = 17; // 0x11
field public static final int HANGUL = 18; // 0x12
field public static final int HANUNOO = 43; // 0x2b
+ field public static final int HAN_WITH_BOPOMOFO = 172; // 0xac
field public static final int HARAPPAN_INDUS = 77; // 0x4d
field public static final int HATRAN = 162; // 0xa2
field public static final int HEBREW = 19; // 0x13
@@ -15985,6 +16030,7 @@
field public static final int INSCRIPTIONAL_PAHLAVI = 122; // 0x7a
field public static final int INSCRIPTIONAL_PARTHIAN = 125; // 0x7d
field public static final int INVALID_CODE = -1; // 0xffffffff
+ field public static final int JAMO = 173; // 0xad
field public static final int JAPANESE = 105; // 0x69
field public static final int JAVANESE = 78; // 0x4e
field public static final int JURCHEN = 148; // 0x94
@@ -16018,6 +16064,7 @@
field public static final int MANDAEAN = 84; // 0x54
field public static final int MANDAIC = 84; // 0x54
field public static final int MANICHAEAN = 121; // 0x79
+ field public static final int MARCHEN = 169; // 0xa9
field public static final int MATHEMATICAL_NOTATION = 128; // 0x80
field public static final int MAYAN_HIEROGLYPHS = 85; // 0x55
field public static final int MEITEI_MAYEK = 115; // 0x73
@@ -16034,6 +16081,7 @@
field public static final int MYANMAR = 28; // 0x1c
field public static final int NABATAEAN = 143; // 0x8f
field public static final int NAKHI_GEBA = 132; // 0x84
+ field public static final int NEWA = 170; // 0xaa
field public static final int NEW_TAI_LUE = 59; // 0x3b
field public static final int NKO = 87; // 0x57
field public static final int NUSHU = 150; // 0x96
@@ -16048,6 +16096,7 @@
field public static final int OL_CHIKI = 109; // 0x6d
field public static final int ORIYA = 31; // 0x1f
field public static final int ORKHON = 88; // 0x58
+ field public static final int OSAGE = 171; // 0xab
field public static final int OSMANYA = 50; // 0x32
field public static final int PAHAWH_HMONG = 75; // 0x4b
field public static final int PALMYRENE = 144; // 0x90
@@ -16073,6 +16122,7 @@
field public static final int SUNDANESE = 113; // 0x71
field public static final int SYLOTI_NAGRI = 58; // 0x3a
field public static final int SYMBOLS = 129; // 0x81
+ field public static final int SYMBOLS_EMOJI = 174; // 0xae
field public static final int SYRIAC = 34; // 0x22
field public static final int TAGALOG = 42; // 0x2a
field public static final int TAGBANWA = 45; // 0x2d
@@ -16599,6 +16649,8 @@
method public static final android.icu.text.DateFormat.BooleanAttribute[] values();
enum_constant public static final android.icu.text.DateFormat.BooleanAttribute PARSE_ALLOW_NUMERIC;
enum_constant public static final android.icu.text.DateFormat.BooleanAttribute PARSE_ALLOW_WHITESPACE;
+ enum_constant public static final android.icu.text.DateFormat.BooleanAttribute PARSE_MULTIPLE_PATTERNS_FOR_MATCH;
+ enum_constant public static final android.icu.text.DateFormat.BooleanAttribute PARSE_PARTIAL_LITERAL_MATCH;
}
public static class DateFormat.Field extends java.text.Format.Field {
@@ -17283,6 +17335,7 @@
field public static final int PERCENTSTYLE = 2; // 0x2
field public static final int PLURALCURRENCYSTYLE = 6; // 0x6
field public static final int SCIENTIFICSTYLE = 3; // 0x3
+ field public static final int STANDARDCURRENCYSTYLE = 9; // 0x9
}
public static class NumberFormat.Field extends java.text.Format.Field {
@@ -18077,7 +18130,7 @@
field public static final int AM_PM = 9; // 0x9
field public static final int APRIL = 3; // 0x3
field public static final int AUGUST = 7; // 0x7
- field protected static final int BASE_FIELD_COUNT = 23; // 0x17
+ field protected static final deprecated int BASE_FIELD_COUNT = 23; // 0x17
field public static final int DATE = 5; // 0x5
field public static final int DAY_OF_MONTH = 5; // 0x5
field public static final int DAY_OF_WEEK = 7; // 0x7
@@ -18105,7 +18158,7 @@
field public static final int MARCH = 2; // 0x2
field protected static final int MAXIMUM = 3; // 0x3
field protected static final java.util.Date MAX_DATE;
- field protected static final int MAX_FIELD_COUNT = 32; // 0x20
+ field protected static final deprecated int MAX_FIELD_COUNT = 32; // 0x20
field protected static final int MAX_JULIAN = 2130706432; // 0x7f000000
field protected static final long MAX_MILLIS = 183882168921600000L; // 0x28d47dbbf19b000L
field public static final int MAY = 4; // 0x4
@@ -18425,6 +18478,7 @@
field public static final android.icu.util.MeasureUnit CELSIUS;
field public static final android.icu.util.MeasureUnit CENTILITER;
field public static final android.icu.util.MeasureUnit CENTIMETER;
+ field public static final android.icu.util.MeasureUnit CENTURY;
field public static final android.icu.util.MeasureUnit CUBIC_CENTIMETER;
field public static final android.icu.util.MeasureUnit CUBIC_FOOT;
field public static final android.icu.util.MeasureUnit CUBIC_INCH;
@@ -18433,6 +18487,7 @@
field public static final android.icu.util.MeasureUnit CUBIC_MILE;
field public static final android.icu.util.MeasureUnit CUBIC_YARD;
field public static final android.icu.util.MeasureUnit CUP;
+ field public static final android.icu.util.MeasureUnit CUP_METRIC;
field public static final android.icu.util.TimeUnit DAY;
field public static final android.icu.util.MeasureUnit DECILITER;
field public static final android.icu.util.MeasureUnit DECIMETER;
@@ -18444,6 +18499,7 @@
field public static final android.icu.util.MeasureUnit FOOT;
field public static final android.icu.util.MeasureUnit FURLONG;
field public static final android.icu.util.MeasureUnit GALLON;
+ field public static final android.icu.util.MeasureUnit GENERIC_TEMPERATURE;
field public static final android.icu.util.MeasureUnit GIGABIT;
field public static final android.icu.util.MeasureUnit GIGABYTE;
field public static final android.icu.util.MeasureUnit GIGAHERTZ;
@@ -18471,8 +18527,10 @@
field public static final android.icu.util.MeasureUnit KILOMETER_PER_HOUR;
field public static final android.icu.util.MeasureUnit KILOWATT;
field public static final android.icu.util.MeasureUnit KILOWATT_HOUR;
+ field public static final android.icu.util.MeasureUnit KNOT;
field public static final android.icu.util.MeasureUnit LIGHT_YEAR;
field public static final android.icu.util.MeasureUnit LITER;
+ field public static final android.icu.util.MeasureUnit LITER_PER_100KILOMETERS;
field public static final android.icu.util.MeasureUnit LITER_PER_KILOMETER;
field public static final android.icu.util.MeasureUnit LUX;
field public static final android.icu.util.MeasureUnit MEGABIT;
@@ -18490,6 +18548,7 @@
field public static final android.icu.util.MeasureUnit MILE;
field public static final android.icu.util.MeasureUnit MILE_PER_GALLON;
field public static final android.icu.util.MeasureUnit MILE_PER_HOUR;
+ field public static final android.icu.util.MeasureUnit MILE_SCANDINAVIAN;
field public static final android.icu.util.MeasureUnit MILLIAMPERE;
field public static final android.icu.util.MeasureUnit MILLIBAR;
field public static final android.icu.util.MeasureUnit MILLIGRAM;
@@ -18509,10 +18568,12 @@
field public static final android.icu.util.MeasureUnit PARSEC;
field public static final android.icu.util.MeasureUnit PICOMETER;
field public static final android.icu.util.MeasureUnit PINT;
+ field public static final android.icu.util.MeasureUnit PINT_METRIC;
field public static final android.icu.util.MeasureUnit POUND;
field public static final android.icu.util.MeasureUnit POUND_PER_SQUARE_INCH;
field public static final android.icu.util.MeasureUnit QUART;
field public static final android.icu.util.MeasureUnit RADIAN;
+ field public static final android.icu.util.MeasureUnit REVOLUTION_ANGLE;
field public static final android.icu.util.TimeUnit SECOND;
field public static final android.icu.util.MeasureUnit SQUARE_CENTIMETER;
field public static final android.icu.util.MeasureUnit SQUARE_FOOT;
@@ -18824,6 +18885,7 @@
field public static final android.icu.util.VersionInfo UNICODE_6_3;
field public static final android.icu.util.VersionInfo UNICODE_7_0;
field public static final android.icu.util.VersionInfo UNICODE_8_0;
+ field public static final android.icu.util.VersionInfo UNICODE_9_0;
}
}
@@ -36952,6 +37014,7 @@
field public static final java.lang.String KEY_SHOW_CDMA_CHOICES_BOOL = "show_cdma_choices_bool";
field public static final java.lang.String KEY_SHOW_ICCID_IN_SIM_STATUS_BOOL = "show_iccid_in_sim_status_bool";
field public static final java.lang.String KEY_SHOW_ONSCREEN_DIAL_BUTTON_BOOL = "show_onscreen_dial_button_bool";
+ field public static final java.lang.String KEY_SIMPLIFIED_NETWORK_SETTINGS_BOOL = "simplified_network_settings_bool";
field public static final java.lang.String KEY_SIM_NETWORK_UNLOCK_ALLOW_DISMISS_BOOL = "sim_network_unlock_allow_dismiss_bool";
field public static final java.lang.String KEY_SUPPORT_CONFERENCE_CALL_BOOL = "support_conference_call_bool";
field public static final java.lang.String KEY_SUPPORT_PAUSE_IMS_VIDEO_CALLS_BOOL = "support_pause_ims_video_calls_bool";
@@ -37489,6 +37552,7 @@
method public java.lang.String getSimOperatorName();
method public java.lang.String getSimSerialNumber();
method public int getSimState();
+ method public int getSimState(int);
method public java.lang.String getSubscriberId();
method public java.lang.String getVoiceMailAlphaTag();
method public java.lang.String getVoiceMailNumber();
@@ -37571,7 +37635,11 @@
field public static final int PHONE_TYPE_NONE = 0; // 0x0
field public static final int PHONE_TYPE_SIP = 3; // 0x3
field public static final int SIM_STATE_ABSENT = 1; // 0x1
+ field public static final int SIM_STATE_CARD_IO_ERROR = 8; // 0x8
+ field public static final int SIM_STATE_CARD_RESTRICTED = 9; // 0x9
field public static final int SIM_STATE_NETWORK_LOCKED = 4; // 0x4
+ field public static final int SIM_STATE_NOT_READY = 6; // 0x6
+ field public static final int SIM_STATE_PERM_DISABLED = 7; // 0x7
field public static final int SIM_STATE_PIN_REQUIRED = 2; // 0x2
field public static final int SIM_STATE_PUK_REQUIRED = 3; // 0x3
field public static final int SIM_STATE_READY = 5; // 0x5
@@ -59387,6 +59455,10 @@
ctor public Locale(java.lang.String, java.lang.String);
ctor public Locale(java.lang.String);
method public java.lang.Object clone();
+ method public static java.util.List<java.util.Locale> filter(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.util.Locale>, java.util.Locale.FilteringMode);
+ method public static java.util.List<java.util.Locale> filter(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.util.Locale>);
+ method public static java.util.List<java.lang.String> filterTags(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.lang.String>, java.util.Locale.FilteringMode);
+ method public static java.util.List<java.lang.String> filterTags(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.lang.String>);
method public static java.util.Locale forLanguageTag(java.lang.String);
method public static java.util.Locale[] getAvailableLocales();
method public java.lang.String getCountry();
@@ -59415,6 +59487,8 @@
method public java.lang.String getUnicodeLocaleType(java.lang.String);
method public java.lang.String getVariant();
method public boolean hasExtensions();
+ method public static java.util.Locale lookup(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.util.Locale>);
+ method public static java.lang.String lookupTag(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.lang.String>);
method public static synchronized void setDefault(java.util.Locale);
method public static synchronized void setDefault(java.util.Locale.Category, java.util.Locale);
method public java.util.Locale stripExtensions();
@@ -59470,6 +59544,28 @@
enum_constant public static final java.util.Locale.Category FORMAT;
}
+ public static final class Locale.FilteringMode extends java.lang.Enum {
+ method public static java.util.Locale.FilteringMode valueOf(java.lang.String);
+ method public static final java.util.Locale.FilteringMode[] values();
+ enum_constant public static final java.util.Locale.FilteringMode AUTOSELECT_FILTERING;
+ enum_constant public static final java.util.Locale.FilteringMode EXTENDED_FILTERING;
+ enum_constant public static final java.util.Locale.FilteringMode IGNORE_EXTENDED_RANGES;
+ enum_constant public static final java.util.Locale.FilteringMode MAP_EXTENDED_RANGES;
+ enum_constant public static final java.util.Locale.FilteringMode REJECT_EXTENDED_RANGES;
+ }
+
+ public static final class Locale.LanguageRange {
+ ctor public Locale.LanguageRange(java.lang.String);
+ ctor public Locale.LanguageRange(java.lang.String, double);
+ method public java.lang.String getRange();
+ method public double getWeight();
+ method public static java.util.List<java.util.Locale.LanguageRange> mapEquivalents(java.util.List<java.util.Locale.LanguageRange>, java.util.Map<java.lang.String, java.util.List<java.lang.String>>);
+ method public static java.util.List<java.util.Locale.LanguageRange> parse(java.lang.String);
+ method public static java.util.List<java.util.Locale.LanguageRange> parse(java.lang.String, java.util.Map<java.lang.String, java.util.List<java.lang.String>>);
+ field public static final double MAX_WEIGHT = 1.0;
+ field public static final double MIN_WEIGHT = 0.0;
+ }
+
public class LongSummaryStatistics implements java.util.function.IntConsumer java.util.function.LongConsumer {
ctor public LongSummaryStatistics();
method public void accept(int);
@@ -62136,13 +62232,13 @@
ctor public Attributes.Name(java.lang.String);
field public static final java.util.jar.Attributes.Name CLASS_PATH;
field public static final java.util.jar.Attributes.Name CONTENT_TYPE;
- field public static final java.util.jar.Attributes.Name EXTENSION_INSTALLATION;
+ field public static final deprecated java.util.jar.Attributes.Name EXTENSION_INSTALLATION;
field public static final java.util.jar.Attributes.Name EXTENSION_LIST;
field public static final java.util.jar.Attributes.Name EXTENSION_NAME;
field public static final java.util.jar.Attributes.Name IMPLEMENTATION_TITLE;
- field public static final java.util.jar.Attributes.Name IMPLEMENTATION_URL;
+ field public static final deprecated java.util.jar.Attributes.Name IMPLEMENTATION_URL;
field public static final java.util.jar.Attributes.Name IMPLEMENTATION_VENDOR;
- field public static final java.util.jar.Attributes.Name IMPLEMENTATION_VENDOR_ID;
+ field public static final deprecated java.util.jar.Attributes.Name IMPLEMENTATION_VENDOR_ID;
field public static final java.util.jar.Attributes.Name IMPLEMENTATION_VERSION;
field public static final java.util.jar.Attributes.Name MAIN_CLASS;
field public static final java.util.jar.Attributes.Name MANIFEST_VERSION;
@@ -62209,11 +62305,11 @@
}
public static abstract interface Pack200.Packer {
- method public abstract void addPropertyChangeListener(java.beans.PropertyChangeListener);
+ method public default deprecated void addPropertyChangeListener(java.beans.PropertyChangeListener);
method public abstract void pack(java.util.jar.JarFile, java.io.OutputStream) throws java.io.IOException;
method public abstract void pack(java.util.jar.JarInputStream, java.io.OutputStream) throws java.io.IOException;
method public abstract java.util.SortedMap<java.lang.String, java.lang.String> properties();
- method public abstract void removePropertyChangeListener(java.beans.PropertyChangeListener);
+ method public default deprecated void removePropertyChangeListener(java.beans.PropertyChangeListener);
field public static final java.lang.String CLASS_ATTRIBUTE_PFX = "pack.class.attribute.";
field public static final java.lang.String CODE_ATTRIBUTE_PFX = "pack.code.attribute.";
field public static final java.lang.String DEFLATE_HINT = "pack.deflate.hint";
@@ -62236,9 +62332,9 @@
}
public static abstract interface Pack200.Unpacker {
- method public abstract void addPropertyChangeListener(java.beans.PropertyChangeListener);
+ method public default deprecated void addPropertyChangeListener(java.beans.PropertyChangeListener);
method public abstract java.util.SortedMap<java.lang.String, java.lang.String> properties();
- method public abstract void removePropertyChangeListener(java.beans.PropertyChangeListener);
+ method public default deprecated void removePropertyChangeListener(java.beans.PropertyChangeListener);
method public abstract void unpack(java.io.InputStream, java.util.jar.JarOutputStream) throws java.io.IOException;
method public abstract void unpack(java.io.File, java.util.jar.JarOutputStream) throws java.io.IOException;
field public static final java.lang.String DEFLATE_HINT = "unpack.deflate.hint";
diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java
index 9ea16a7..afe9651 100644
--- a/core/java/android/app/LoadedApk.java
+++ b/core/java/android/app/LoadedApk.java
@@ -51,6 +51,7 @@
import android.view.Display;
import android.view.DisplayAdjustments;
+import dalvik.system.BaseDexClassLoader;
import dalvik.system.VMRuntime;
import java.io.File;
@@ -600,6 +601,40 @@
VMRuntime.registerAppInfo(profileFile.getPath(), mApplicationInfo.dataDir,
codePaths.toArray(new String[codePaths.size()]), foreignDexProfilesFile.getPath());
+
+ // Setup the reporter to notify package manager of any relevant dex loads.
+ // At this point the primary apk is loaded and will not be reported.
+ // Anything loaded from now on will be tracked as a potential secondary
+ // or foreign dex file. The goal is to enable:
+ // 1) monitoring and compilation of secondary dex file
+ // 2) track foreign dex file usage (used to determined the
+ // compilation filter of apks).
+ if (BaseDexClassLoader.getReporter() != DexLoadReporter.INSTANCE) {
+ // Set the dex load reporter if not already set.
+ // Note that during the app's life cycle different LoadedApks may be
+ // created and loaded (e.g. if two different apps share the same runtime).
+ BaseDexClassLoader.setReporter(DexLoadReporter.INSTANCE);
+ }
+ }
+
+ private static class DexLoadReporter implements BaseDexClassLoader.Reporter {
+ private static final DexLoadReporter INSTANCE = new DexLoadReporter();
+
+ private DexLoadReporter() {}
+
+ @Override
+ public void report(List<String> dexPaths) {
+ if (dexPaths.isEmpty()) {
+ return;
+ }
+ String packageName = ActivityThread.currentPackageName();
+ try {
+ ActivityThread.getPackageManager().notifyDexLoad(
+ packageName, dexPaths, VMRuntime.getRuntime().vmInstructionSet());
+ } catch (RemoteException re) {
+ Slog.e(TAG, "Failed to notify PM about dex load for package " + packageName, re);
+ }
+ }
}
/**
diff --git a/core/java/android/app/usage/NetworkStats.java b/core/java/android/app/usage/NetworkStats.java
index 226aa8f..3670b91 100644
--- a/core/java/android/app/usage/NetworkStats.java
+++ b/core/java/android/app/usage/NetworkStats.java
@@ -164,6 +164,29 @@
public static final int UID_TETHERING = TrafficStats.UID_TETHERING;
/** @hide */
+ @IntDef({METERED_ALL, METERED_NO, METERED_YES})
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface Metered {}
+
+ /**
+ * Combined usage across all metered states. Covers metered and unmetered usage.
+ */
+ public static final int METERED_ALL = -1;
+
+ /**
+ * Usage that occurs on an unmetered network.
+ */
+ public static final int METERED_NO = 0x1;
+
+ /**
+ * Usage that occurs on a metered network.
+ *
+ * <p>A network is classified as metered when the user is sensitive to heavy data usage on
+ * that connection.
+ */
+ public static final int METERED_YES = 0x2;
+
+ /** @hide */
@IntDef({ROAMING_ALL, ROAMING_NO, ROAMING_YES})
@Retention(RetentionPolicy.SOURCE)
public @interface Roaming {}
@@ -200,6 +223,7 @@
private int mUid;
private int mTag;
private int mState;
+ private int mMetered;
private int mRoaming;
private long mBeginTimeStamp;
private long mEndTimeStamp;
@@ -232,6 +256,15 @@
return tag;
}
+ private static @Metered int convertMetered(int metered) {
+ switch (metered) {
+ case android.net.NetworkStats.METERED_ALL : return METERED_ALL;
+ case android.net.NetworkStats.METERED_NO: return METERED_NO;
+ case android.net.NetworkStats.METERED_YES: return METERED_YES;
+ }
+ return 0;
+ }
+
private static @Roaming int convertRoaming(int roaming) {
switch (roaming) {
case android.net.NetworkStats.ROAMING_ALL : return ROAMING_ALL;
@@ -279,6 +312,21 @@
}
/**
+ * Metered state. One of the following values:<p/>
+ * <ul>
+ * <li>{@link #METERED_ALL}</li>
+ * <li>{@link #METERED_NO}</li>
+ * <li>{@link #METERED_YES}</li>
+ * </ul>
+ * <p>A network is classified as metered when the user is sensitive to heavy data usage on
+ * that connection. Apps may warn before using these networks for large downloads. The
+ * metered state can be set by the user within data usage network restrictions.
+ */
+ public @Metered int getMetered() {
+ return mMetered;
+ }
+
+ /**
* Roaming state. One of the following values:<p/>
* <ul>
* <li>{@link #ROAMING_ALL}</li>
@@ -491,6 +539,7 @@
bucketOut.mUid = Bucket.convertUid(mRecycledSummaryEntry.uid);
bucketOut.mTag = Bucket.convertTag(mRecycledSummaryEntry.tag);
bucketOut.mState = Bucket.convertState(mRecycledSummaryEntry.set);
+ bucketOut.mMetered = Bucket.convertMetered(mRecycledSummaryEntry.metered);
bucketOut.mRoaming = Bucket.convertRoaming(mRecycledSummaryEntry.roaming);
bucketOut.mBeginTimeStamp = mStartTimeStamp;
bucketOut.mEndTimeStamp = mEndTimeStamp;
@@ -539,6 +588,7 @@
bucketOut.mUid = Bucket.convertUid(getUid());
bucketOut.mTag = Bucket.convertTag(mTag);
bucketOut.mState = Bucket.STATE_ALL;
+ bucketOut.mMetered = Bucket.METERED_ALL;
bucketOut.mRoaming = Bucket.ROAMING_ALL;
bucketOut.mBeginTimeStamp = mRecycledHistoryEntry.bucketStart;
bucketOut.mEndTimeStamp = mRecycledHistoryEntry.bucketStart +
diff --git a/core/java/android/app/usage/NetworkStatsManager.java b/core/java/android/app/usage/NetworkStatsManager.java
index 7961a72..840413a 100644
--- a/core/java/android/app/usage/NetworkStatsManager.java
+++ b/core/java/android/app/usage/NetworkStatsManager.java
@@ -51,16 +51,17 @@
* {@link #querySummaryForUser} <p />
* {@link #querySummary} <p />
* These queries aggregate network usage across the whole interval. Therefore there will be only one
- * bucket for a particular key and state and roaming combination. In case of the user-wide and
- * device-wide summaries a single bucket containing the totalised network usage is returned.
+ * bucket for a particular key, state, metered and roaming combination. In case of the user-wide
+ * and device-wide summaries a single bucket containing the totalised network usage is returned.
* <h3>
* History queries
* </h3>
* {@link #queryDetailsForUid} <p />
* {@link #queryDetails} <p />
- * These queries do not aggregate over time but do aggregate over state and roaming. Therefore there
- * can be multiple buckets for a particular key but all Bucket's state is going to be
- * {@link NetworkStats.Bucket#STATE_ALL} and all Bucket's roaming is going to be
+ * These queries do not aggregate over time but do aggregate over state, metered and roaming.
+ * Therefore there can be multiple buckets for a particular key but all Bucket's state is going to
+ * be {@link NetworkStats.Bucket#STATE_ALL}, all Bucket's metered is going to be
+ * {@link NetworkStats.Bucket#METERED_ALL}, and all Bucket's roaming is going to be
* {@link NetworkStats.Bucket#ROAMING_ALL}.
* <p />
* <b>NOTE:</b> Calling {@link #querySummaryForDevice} or accessing stats for apps other than the
@@ -103,10 +104,11 @@
/**
* Query network usage statistics summaries. Result is summarised data usage for the whole
- * device. Result is a single Bucket aggregated over time, state, uid, tag and roaming. This
- * means the bucket's start and end timestamp are going to be the same as the 'startTime' and
- * 'endTime' parameters. State is going to be {@link NetworkStats.Bucket#STATE_ALL}, uid
- * {@link NetworkStats.Bucket#UID_ALL}, tag {@link NetworkStats.Bucket#TAG_NONE}
+ * device. Result is a single Bucket aggregated over time, state, uid, tag, metered, and
+ * roaming. This means the bucket's start and end timestamp are going to be the same as the
+ * 'startTime' and 'endTime' parameters. State is going to be
+ * {@link NetworkStats.Bucket#STATE_ALL}, uid {@link NetworkStats.Bucket#UID_ALL},
+ * tag {@link NetworkStats.Bucket#TAG_NONE}, metered {@link NetworkStats.Bucket#METERED_ALL},
* and roaming {@link NetworkStats.Bucket#ROAMING_ALL}.
*
* @param networkType As defined in {@link ConnectivityManager}, e.g.
@@ -142,8 +144,10 @@
* Query network usage statistics summaries. Result is summarised data usage for all uids
* belonging to calling user. Result is a single Bucket aggregated over time, state and uid.
* This means the bucket's start and end timestamp are going to be the same as the 'startTime'
- * and 'endTime' parameters, state is going to be {@link NetworkStats.Bucket#STATE_ALL} and uid
- * {@link NetworkStats.Bucket#UID_ALL}.
+ * and 'endTime' parameters. State is going to be {@link NetworkStats.Bucket#STATE_ALL},
+ * uid {@link NetworkStats.Bucket#UID_ALL}, tag {@link NetworkStats.Bucket#TAG_NONE},
+ * metered {@link NetworkStats.Bucket#METERED_ALL}, and roaming
+ * {@link NetworkStats.Bucket#ROAMING_ALL}.
*
* @param networkType As defined in {@link ConnectivityManager}, e.g.
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
@@ -177,9 +181,10 @@
/**
* Query network usage statistics summaries. Result filtered to include only uids belonging to
* calling user. Result is aggregated over time, hence all buckets will have the same start and
- * end timestamps. Not aggregated over state or uid. This means buckets' start and end
- * timestamps are going to be the same as the 'startTime' and 'endTime' parameters.
- * State and uid are going to vary, and tag is going to be the same.
+ * end timestamps. State is going to be {@link NetworkStats.Bucket#STATE_ALL},
+ * uid {@link NetworkStats.Bucket#UID_ALL}, tag {@link NetworkStats.Bucket#TAG_NONE},
+ * metered {@link NetworkStats.Bucket#METERED_ALL}, and roaming
+ * {@link NetworkStats.Bucket#ROAMING_ALL}.
*
* @param networkType As defined in {@link ConnectivityManager}, e.g.
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
@@ -262,10 +267,12 @@
/**
* Query network usage statistics details. Result filtered to include only uids belonging to
- * calling user. Result is aggregated over state but not aggregated over time or uid. This means
- * buckets' start and end timestamps are going to be between 'startTime' and 'endTime'
- * parameters. State is going to be {@link NetworkStats.Bucket#STATE_ALL}, uid will vary,
- * tag {@link NetworkStats.Bucket#TAG_NONE} and roaming is going to be
+ * calling user. Result is aggregated over state but not aggregated over time, uid, tag,
+ * metered, nor roaming. This means buckets' start and end timestamps are going to be between
+ * 'startTime' and 'endTime' parameters. State is going to be
+ * {@link NetworkStats.Bucket#STATE_ALL}, uid will vary,
+ * tag {@link NetworkStats.Bucket#TAG_NONE}, metered is going to be
+ * {@link NetworkStats.Bucket#METERED_ALL}, and roaming is going to be
* {@link NetworkStats.Bucket#ROAMING_ALL}.
* <p>Only includes buckets that atomically occur in the inclusive time range. Doesn't
* interpolate across partial buckets. Since bucket length is in the order of hours, this
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index d419d03..f9be3a1 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -23,6 +23,7 @@
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
+import android.app.ActivityThread;
import android.bluetooth.le.BluetoothLeAdvertiser;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
@@ -200,6 +201,23 @@
public static final int STATE_BLE_TURNING_OFF = 16;
/**
+ * Human-readable string helper for AdapterState
+ * @hide
+ */
+ public static String nameForState(@AdapterState int state) {
+ switch(state) {
+ case STATE_OFF: return "OFF";
+ case STATE_TURNING_ON: return "TURNING_ON";
+ case STATE_ON: return "ON";
+ case STATE_TURNING_OFF: return "TURNING_OFF";
+ case STATE_BLE_TURNING_ON: return "BLE_TURNING_ON";
+ case STATE_BLE_ON: return "BLE_ON";
+ case STATE_BLE_TURNING_OFF: return "BLE_TURNING_OFF";
+ default: return "?!?!? (" + state + ")";
+ }
+ }
+
+ /**
* Activity Action: Show a system activity that requests discoverable mode.
* This activity will also request the user to turn on Bluetooth if it
* is not currently enabled.
@@ -255,6 +273,29 @@
"android.bluetooth.adapter.action.REQUEST_ENABLE";
/**
+ * Activity Action: Show a system activity that allows the user to turn off
+ * Bluetooth. This is used only if permission review is enabled which is for
+ * apps targeting API less than 23 require a permission review before any of
+ * the app's components can run.
+ * <p>This system activity will return once Bluetooth has completed turning
+ * off, or the user has decided not to turn Bluetooth off.
+ * <p>Notification of the result of this activity is posted using the
+ * {@link android.app.Activity#onActivityResult} callback. The
+ * <code>resultCode</code>
+ * will be {@link android.app.Activity#RESULT_OK} if Bluetooth has been
+ * turned off or {@link android.app.Activity#RESULT_CANCELED} if the user
+ * has rejected the request or an error has occurred.
+ * <p>Applications can also listen for {@link #ACTION_STATE_CHANGED}
+ * for global notification whenever Bluetooth is turned on or off.
+ * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
+ *
+ * @hide
+ */
+ @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
+ public static final String ACTION_REQUEST_DISABLE =
+ "android.bluetooth.adapter.action.REQUEST_DISABLE";
+
+ /**
* Activity Action: Show a system activity that allows user to enable BLE scans even when
* Bluetooth is turned off.<p>
*
@@ -634,42 +675,12 @@
@SystemApi
public boolean isLeEnabled() {
final int state = getLeState();
- if (state == BluetoothAdapter.STATE_ON) {
- if (DBG) Log.d (TAG, "STATE_ON");
- } else if (state == BluetoothAdapter.STATE_BLE_ON) {
- if (DBG) Log.d (TAG, "STATE_BLE_ON");
- } else {
- if (DBG) Log.d (TAG, "STATE_OFF");
- return false;
- }
- return true;
+ if (DBG) Log.d(TAG, "isLeEnabled(): " + BluetoothAdapter.nameForState(state));
+ return (state == BluetoothAdapter.STATE_ON || state == BluetoothAdapter.STATE_BLE_ON);
}
/**
- * Performs action based on user action to turn BT ON
- * or OFF if BT is in BLE_ON state
- */
- private void notifyUserAction(boolean enable) {
- try {
- mServiceLock.readLock().lock();
- if (mService == null) {
- Log.e(TAG, "mService is null");
- return;
- }
- if (enable) {
- mService.onLeServiceUp(); //NA:TODO implementation pending
- } else {
- mService.onBrEdrDown(); //NA:TODO implementation pending
- }
- } catch (RemoteException e) {
- Log.e(TAG, "", e);
- } finally {
- mServiceLock.readLock().unlock();
- }
- }
-
- /**
- * Turns off Bluetooth LE which was earlier turned on by calling EnableBLE().
+ * Turns off Bluetooth LE which was earlier turned on by calling enableBLE().
*
* <p> If the internal Adapter state is STATE_BLE_ON, this would trigger the transition
* to STATE_OFF and completely shut-down Bluetooth
@@ -699,61 +710,50 @@
if (!isBleScanAlwaysAvailable()) return false;
int state = getLeState();
- if (state == BluetoothAdapter.STATE_ON) {
- if (DBG) Log.d (TAG, "STATE_ON: shouldn't disable");
+ if (state == BluetoothAdapter.STATE_ON || state == BluetoothAdapter.STATE_BLE_ON) {
+ String packageName = ActivityThread.currentPackageName();
+ if (DBG) Log.d (TAG, "disableBLE(): de-registering " + packageName);
try {
- mManagerService.updateBleAppCount(mToken, false);
+ mManagerService.updateBleAppCount(mToken, false, packageName);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
return true;
-
- } else if (state == BluetoothAdapter.STATE_BLE_ON) {
- if (DBG) Log.d (TAG, "STATE_BLE_ON");
- int bleAppCnt = 0;
- try {
- bleAppCnt = mManagerService.updateBleAppCount(mToken, false);
- } catch (RemoteException e) {
- Log.e(TAG, "", e);
- }
- if (bleAppCnt == 0) {
- // Disable only if there are no other clients
- notifyUserAction(false);
- }
- return true;
}
- if (DBG) Log.d (TAG, "STATE_OFF: Already disabled");
+ if (DBG) Log.d (TAG, "disableBLE(): Already disabled");
return false;
}
/**
- * Special Applications who want to only turn on Bluetooth Low Energy (BLE) would
- * EnableBLE, EnableBLE brings-up Bluetooth so that application can access
- * only LE related feature (Bluetooth GATT layers interfaces using the respective class)
- * EnableBLE in turn registers the existance of a special App which wants to
- * turn on Bluetooth Low enrgy part without making it visible at the settings UI
- * as Bluetooth ON.
- * <p>Invoking EnableBLE when Bluetooth is already in ON state, would just registers
- * the existance of special Application and doesn't do anything to current BT state.
- * when user turn OFF Bluetooth from UI, if there is an existance of special app, Bluetooth
- * would stay in BLE_ON state so that LE features are still acessible to the special
- * Applications.
+ * Applications who want to only use Bluetooth Low Energy (BLE) can call enableBLE.
*
- * <p>This is an asynchronous call: it will return immediately, and
+ * enableBLE registers the existence of an app using only LE functions.
+ *
+ * enableBLE may enable Bluetooth to an LE only mode so that an app can use
+ * LE related features (BluetoothGatt or BluetoothGattServer classes)
+ *
+ * If the user disables Bluetooth while an app is registered to use LE only features,
+ * Bluetooth will remain on in LE only mode for the app.
+ *
+ * When Bluetooth is in LE only mode, it is not shown as ON to the UI.
+ *
+ * <p>This is an asynchronous call: it returns immediately, and
* clients should listen for {@link #ACTION_BLE_STATE_CHANGED}
- * to be notified of subsequent adapter state changes. If this call returns
- * true, then the adapter state will immediately transition from {@link
- * #STATE_OFF} to {@link #STATE_BLE_TURNING_ON}, and some time
- * later transition to either {@link #STATE_OFF} or {@link
- * #STATE_BLE_ON}. If this call returns false then there was an
- * immediate problem that will prevent the adapter from being turned on -
- * such as Airplane mode, or the adapter is already turned on.
- * (@link #ACTION_BLE_STATE_CHANGED) returns the Bluetooth Adapter's various
+ * to be notified of adapter state changes.
+ *
+ * If this call returns * true, then the adapter state is either in a mode where
+ * LE is available, or will transition from {@link #STATE_OFF} to {@link #STATE_BLE_TURNING_ON},
+ * and some time later transition to either {@link #STATE_OFF} or {@link #STATE_BLE_ON}.
+ *
+ * If this call returns false then there was an immediate problem that prevents the
+ * adapter from being turned on - such as Airplane mode.
+ *
+ * {@link #ACTION_BLE_STATE_CHANGED} returns the Bluetooth Adapter's various
* states, It includes all the classic Bluetooth Adapter states along with
* internal BLE only states
*
- * @return true to indicate Bluetooth LE start-up has begun, or false on
+ * @return true to indicate Bluetooth LE will be available, or false on
* immediate error
* @hide
*/
@@ -762,13 +762,14 @@
if (!isBleScanAlwaysAvailable()) return false;
try {
- mManagerService.updateBleAppCount(mToken, true);
+ String packageName = ActivityThread.currentPackageName();
+ mManagerService.updateBleAppCount(mToken, true, packageName);
if (isLeEnabled()) {
if (DBG) Log.d(TAG, "enableBLE(): Bluetooth already enabled");
return true;
}
if (DBG) Log.d(TAG, "enableBLE(): Calling enable");
- return mManagerService.enable();
+ return mManagerService.enable(packageName);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -807,10 +808,10 @@
if (state == BluetoothAdapter.STATE_BLE_ON
|| state == BluetoothAdapter.STATE_BLE_TURNING_ON
|| state == BluetoothAdapter.STATE_BLE_TURNING_OFF) {
- if (VDBG) Log.d(TAG, "Consider internal state as OFF");
+ if (VDBG) Log.d(TAG, "Consider " + BluetoothAdapter.nameForState(state) + " state as OFF");
state = BluetoothAdapter.STATE_OFF;
}
- if (VDBG) Log.d(TAG, "" + hashCode() + ": getState(). Returning " + state);
+ if (VDBG) Log.d(TAG, "" + hashCode() + ": getState(). Returning " + BluetoothAdapter.nameForState(state));
return state;
}
@@ -847,12 +848,12 @@
mServiceLock.readLock().unlock();
}
- if (VDBG) Log.d(TAG,"getLeState() returning " + state);
+ if (VDBG) Log.d(TAG,"getLeState() returning " + BluetoothAdapter.nameForState(state));
return state;
}
boolean getLeAccess() {
- if(getLeState() == STATE_ON)
+ if (getLeState() == STATE_ON)
return true;
else if (getLeState() == STATE_BLE_ON)
@@ -890,12 +891,12 @@
*/
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
public boolean enable() {
- if (isEnabled() == true) {
- if (DBG) Log.d(TAG, "enable(): BT is already enabled..!");
+ if (isEnabled()) {
+ if (DBG) Log.d(TAG, "enable(): BT already enabled!");
return true;
}
try {
- return mManagerService.enable();
+ return mManagerService.enable(ActivityThread.currentPackageName());
} catch (RemoteException e) {Log.e(TAG, "", e);}
return false;
}
@@ -927,7 +928,7 @@
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
public boolean disable() {
try {
- return mManagerService.disable(true);
+ return mManagerService.disable(ActivityThread.currentPackageName(), true);
} catch (RemoteException e) {Log.e(TAG, "", e);}
return false;
}
@@ -945,7 +946,7 @@
public boolean disable(boolean persist) {
try {
- return mManagerService.disable(persist);
+ return mManagerService.disable(ActivityThread.currentPackageName(), persist);
} catch (RemoteException e) {Log.e(TAG, "", e);}
return false;
}
@@ -1494,8 +1495,9 @@
}
}
}
- } catch (RemoteException e) {Log.e(TAG, "getSupportedProfiles:", e);}
-
+ } catch (RemoteException e) {
+ Log.e(TAG, "getSupportedProfiles:", e);
+ }
return supportedProfiles;
}
@@ -1846,34 +1848,6 @@
* @hide
*/
public Pair<byte[], byte[]> readOutOfBandData() {
- if (getState() != STATE_ON) return null;
- //TODO(BT
- /*
- try {
- byte[] hash;
- byte[] randomizer;
-
- byte[] ret = null;
- mServiceLock.readLock().lock();
- if (mService != null) mService.readOutOfBandData();
-
- if (ret == null || ret.length != 32) return null;
-
- hash = Arrays.copyOfRange(ret, 0, 16);
- randomizer = Arrays.copyOfRange(ret, 16, 32);
-
- if (DBG) {
- Log.d(TAG, "readOutOfBandData:" + Arrays.toString(hash) +
- ":" + Arrays.toString(randomizer));
- }
- return new Pair<byte[], byte[]>(hash, randomizer);
-
- } catch (RemoteException e) {
- Log.e(TAG, "", e);
- } finally {
- mServiceLock.readLock().unlock();
- }
- */
return null;
}
@@ -1933,6 +1907,9 @@
} else if (profile == BluetoothProfile.MAP_CLIENT) {
BluetoothMapClient mapClient = new BluetoothMapClient(context, listener);
return true;
+ } else if (profile == BluetoothProfile.INPUT_HOST) {
+ BluetoothInputHost iHost = new BluetoothInputHost(context, listener);
+ return true;
} else {
return false;
}
@@ -2009,6 +1986,10 @@
BluetoothMapClient mapClient = (BluetoothMapClient)proxy;
mapClient.close();
break;
+ case BluetoothProfile.INPUT_HOST:
+ BluetoothInputHost iHost = (BluetoothInputHost) proxy;
+ iHost.close();
+ break;
}
}
@@ -2027,7 +2008,7 @@
if (cb != null) {
cb.onBluetoothServiceUp(bluetoothService);
} else {
- Log.d(TAG, "onBluetoothServiceUp: cb is null!!!");
+ Log.d(TAG, "onBluetoothServiceUp: cb is null!");
}
} catch (Exception e) {
Log.e(TAG,"",e);
@@ -2055,7 +2036,7 @@
if (cb != null) {
cb.onBluetoothServiceDown();
} else {
- Log.d(TAG, "onBluetoothServiceDown: cb is null!!!");
+ Log.d(TAG, "onBluetoothServiceDown: cb is null!");
}
} catch (Exception e) {
Log.e(TAG,"",e);
@@ -2065,7 +2046,7 @@
}
public void onBrEdrDown() {
- if (VDBG) Log.i(TAG, "on QBrEdrDown: ");
+ if (VDBG) Log.i(TAG, "onBrEdrDown: " + mService);
}
};
@@ -2076,11 +2057,11 @@
*/
public boolean enableNoAutoConnect() {
if (isEnabled() == true){
- if (DBG) Log.d(TAG, "enableNoAutoConnect(): BT is already enabled..!");
+ if (DBG) Log.d(TAG, "enableNoAutoConnect(): BT already enabled!");
return true;
}
try {
- return mManagerService.enableNoAutoConnect();
+ return mManagerService.enableNoAutoConnect(ActivityThread.currentPackageName());
} catch (RemoteException e) {Log.e(TAG, "", e);}
return false;
}
@@ -2116,22 +2097,6 @@
*/
public boolean changeApplicationBluetoothState(boolean on,
BluetoothStateChangeCallback callback) {
- if (callback == null) return false;
-
- //TODO(BT)
- /*
- try {
- mServiceLock.readLock().lock();
- if (mService != null) {
- return mService.changeApplicationBluetoothState(on, new
- StateChangeCallbackWrapper(callback), new Binder());
- }
- } catch (RemoteException e) {
- Log.e(TAG, "changeBluetoothState", e);
- } finally {
- mServiceLock.readLock().unlock();
- }
- */
return false;
}
diff --git a/core/java/android/bluetooth/BluetoothHidDeviceAppConfiguration.aidl b/core/java/android/bluetooth/BluetoothHidDeviceAppConfiguration.aidl
new file mode 100644
index 0000000..283a717
--- /dev/null
+++ b/core/java/android/bluetooth/BluetoothHidDeviceAppConfiguration.aidl
@@ -0,0 +1,19 @@
+/*
+** Copyright 2016, 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.bluetooth;
+
+parcelable BluetoothHidDeviceAppConfiguration;
diff --git a/core/java/android/bluetooth/BluetoothHidDeviceAppConfiguration.java b/core/java/android/bluetooth/BluetoothHidDeviceAppConfiguration.java
new file mode 100644
index 0000000..05ba64e
--- /dev/null
+++ b/core/java/android/bluetooth/BluetoothHidDeviceAppConfiguration.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2016 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.bluetooth;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.Random;
+
+/** @hide */
+public final class BluetoothHidDeviceAppConfiguration implements Parcelable {
+ private final long mHash;
+
+ BluetoothHidDeviceAppConfiguration() {
+ Random rnd = new Random();
+ mHash = rnd.nextLong();
+ }
+
+ BluetoothHidDeviceAppConfiguration(long hash) {
+ mHash = hash;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof BluetoothHidDeviceAppConfiguration) {
+ BluetoothHidDeviceAppConfiguration config = (BluetoothHidDeviceAppConfiguration) o;
+ return mHash == config.mHash;
+ }
+ return false;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ public static final Parcelable.Creator<BluetoothHidDeviceAppConfiguration> CREATOR =
+ new Parcelable.Creator<BluetoothHidDeviceAppConfiguration>() {
+
+ @Override
+ public BluetoothHidDeviceAppConfiguration createFromParcel(Parcel in) {
+ long hash = in.readLong();
+ return new BluetoothHidDeviceAppConfiguration(hash);
+ }
+
+ @Override
+ public BluetoothHidDeviceAppConfiguration[] newArray(int size) {
+ return new BluetoothHidDeviceAppConfiguration[size];
+ }
+ };
+
+ @Override
+ public void writeToParcel(Parcel out, int flags) {
+ out.writeLong(mHash);
+ }
+}
diff --git a/core/java/android/bluetooth/BluetoothHidDeviceAppQosSettings.aidl b/core/java/android/bluetooth/BluetoothHidDeviceAppQosSettings.aidl
new file mode 100644
index 0000000..14f9114
--- /dev/null
+++ b/core/java/android/bluetooth/BluetoothHidDeviceAppQosSettings.aidl
@@ -0,0 +1,19 @@
+/*
+** Copyright 2016, 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.bluetooth;
+
+parcelable BluetoothHidDeviceAppQosSettings;
diff --git a/core/java/android/bluetooth/BluetoothHidDeviceAppQosSettings.java b/core/java/android/bluetooth/BluetoothHidDeviceAppQosSettings.java
new file mode 100644
index 0000000..0d6530c
--- /dev/null
+++ b/core/java/android/bluetooth/BluetoothHidDeviceAppQosSettings.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2016 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.bluetooth;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.Random;
+
+/** @hide */
+public final class BluetoothHidDeviceAppQosSettings implements Parcelable {
+
+ final public int serviceType;
+ final public int tokenRate;
+ final public int tokenBucketSize;
+ final public int peakBandwidth;
+ final public int latency;
+ final public int delayVariation;
+
+ final static public int SERVICE_NO_TRAFFIC = 0x00;
+ final static public int SERVICE_BEST_EFFORT = 0x01;
+ final static public int SERVICE_GUARANTEED = 0x02;
+
+ final static public int MAX = (int) 0xffffffff;
+
+ public BluetoothHidDeviceAppQosSettings(int serviceType, int tokenRate, int tokenBucketSize,
+ int peakBandwidth,
+ int latency, int delayVariation) {
+ this.serviceType = serviceType;
+ this.tokenRate = tokenRate;
+ this.tokenBucketSize = tokenBucketSize;
+ this.peakBandwidth = peakBandwidth;
+ this.latency = latency;
+ this.delayVariation = delayVariation;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof BluetoothHidDeviceAppQosSettings) {
+ BluetoothHidDeviceAppQosSettings qos = (BluetoothHidDeviceAppQosSettings) o;
+ return false;
+ }
+ return false;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ public static final Parcelable.Creator<BluetoothHidDeviceAppQosSettings> CREATOR =
+ new Parcelable.Creator<BluetoothHidDeviceAppQosSettings>() {
+
+ @Override
+ public BluetoothHidDeviceAppQosSettings createFromParcel(Parcel in) {
+
+ return new BluetoothHidDeviceAppQosSettings(in.readInt(), in.readInt(), in.readInt(),
+ in.readInt(),
+ in.readInt(), in.readInt());
+ }
+
+ @Override
+ public BluetoothHidDeviceAppQosSettings[] newArray(int size) {
+ return new BluetoothHidDeviceAppQosSettings[size];
+ }
+ };
+
+ @Override
+ public void writeToParcel(Parcel out, int flags) {
+ out.writeInt(serviceType);
+ out.writeInt(tokenRate);
+ out.writeInt(tokenBucketSize);
+ out.writeInt(peakBandwidth);
+ out.writeInt(latency);
+ out.writeInt(delayVariation);
+ }
+
+ public int[] toArray() {
+ return new int[] {
+ serviceType, tokenRate, tokenBucketSize, peakBandwidth, latency, delayVariation
+ };
+ }
+}
diff --git a/core/java/android/bluetooth/BluetoothHidDeviceAppSdpSettings.aidl b/core/java/android/bluetooth/BluetoothHidDeviceAppSdpSettings.aidl
new file mode 100644
index 0000000..87dd10e
--- /dev/null
+++ b/core/java/android/bluetooth/BluetoothHidDeviceAppSdpSettings.aidl
@@ -0,0 +1,19 @@
+/*
+** Copyright 2016, 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.bluetooth;
+
+parcelable BluetoothHidDeviceAppSdpSettings;
diff --git a/core/java/android/bluetooth/BluetoothHidDeviceAppSdpSettings.java b/core/java/android/bluetooth/BluetoothHidDeviceAppSdpSettings.java
new file mode 100644
index 0000000..f9a2245
--- /dev/null
+++ b/core/java/android/bluetooth/BluetoothHidDeviceAppSdpSettings.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2016 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.bluetooth;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.Random;
+
+/** @hide */
+public final class BluetoothHidDeviceAppSdpSettings implements Parcelable {
+
+ final public String name;
+ final public String description;
+ final public String provider;
+ final public byte subclass;
+ final public byte[] descriptors;
+
+ public BluetoothHidDeviceAppSdpSettings(String name, String description, String provider,
+ byte subclass, byte[] descriptors) {
+ this.name = name;
+ this.description = description;
+ this.provider = provider;
+ this.subclass = subclass;
+ this.descriptors = descriptors.clone();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof BluetoothHidDeviceAppSdpSettings) {
+ BluetoothHidDeviceAppSdpSettings sdp = (BluetoothHidDeviceAppSdpSettings) o;
+ return false;
+ }
+ return false;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ public static final Parcelable.Creator<BluetoothHidDeviceAppSdpSettings> CREATOR =
+ new Parcelable.Creator<BluetoothHidDeviceAppSdpSettings>() {
+
+ @Override
+ public BluetoothHidDeviceAppSdpSettings createFromParcel(Parcel in) {
+
+ return new BluetoothHidDeviceAppSdpSettings(in.readString(), in.readString(),
+ in.readString(), in.readByte(), in.createByteArray());
+ }
+
+ @Override
+ public BluetoothHidDeviceAppSdpSettings[] newArray(int size) {
+ return new BluetoothHidDeviceAppSdpSettings[size];
+ }
+ };
+
+ @Override
+ public void writeToParcel(Parcel out, int flags) {
+ out.writeString(name);
+ out.writeString(description);
+ out.writeString(provider);
+ out.writeByte(subclass);
+ out.writeByteArray(descriptors);
+ }
+}
diff --git a/core/java/android/bluetooth/BluetoothHidDeviceCallback.java b/core/java/android/bluetooth/BluetoothHidDeviceCallback.java
new file mode 100644
index 0000000..0f0e050
--- /dev/null
+++ b/core/java/android/bluetooth/BluetoothHidDeviceCallback.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2016 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.bluetooth;
+
+import android.util.Log;
+
+/** @hide */
+public abstract class BluetoothHidDeviceCallback {
+
+ private static final String TAG = BluetoothHidDeviceCallback.class.getSimpleName();
+
+ /**
+ * Callback called when application registration state changes. Usually it's
+ * called due to either
+ * {@link BluetoothHidDevice#registerApp(String, String, String, byte, byte[],
+ * BluetoothHidDeviceCallback)}
+ * or
+ * {@link BluetoothHidDevice#unregisterApp(BluetoothHidDeviceAppConfiguration)}
+ * , but can be also unsolicited in case e.g. Bluetooth was turned off in
+ * which case application is unregistered automatically.
+ *
+ * @param pluggedDevice {@link BluetoothDevice} object which represents host
+ * that currently has Virtual Cable established with device. Only
+ * valid when application is registered, can be <code>null</code>
+ * .
+ * @param config {@link BluetoothHidDeviceAppConfiguration} object which
+ * represents token required to unregister application using
+ * {@link BluetoothHidDevice#unregisterApp(BluetoothHidDeviceAppConfiguration)}
+ * .
+ * @param registered <code>true</code> if application is registered,
+ * <code>false</code> otherwise.
+ */
+ public void onAppStatusChanged(BluetoothDevice pluggedDevice,
+ BluetoothHidDeviceAppConfiguration config, boolean registered) {
+ Log.d(TAG, "onAppStatusChanged: pluggedDevice=" + (pluggedDevice == null ?
+ null : pluggedDevice.toString()) + " registered=" + registered);
+ }
+
+ /**
+ * Callback called when connection state with remote host was changed.
+ * Application can assume than Virtual Cable is established when called with
+ * {@link BluetoothProfile#STATE_CONNECTED} <code>state</code>.
+ *
+ * @param device {@link BluetoothDevice} object representing host device
+ * which connection state was changed.
+ * @param state Connection state as defined in {@link BluetoothProfile}.
+ */
+ public void onConnectionStateChanged(BluetoothDevice device, int state) {
+ Log.d(TAG, "onConnectionStateChanged: device=" + device.toString() + " state=" + state);
+ }
+
+ /**
+ * Callback called when GET_REPORT is received from remote host. Should be
+ * replied by application using
+ * {@link BluetoothHidDevice#replyReport(byte, byte, byte[])}.
+ *
+ * @param type Requested Report Type.
+ * @param id Requested Report Id, can be 0 if no Report Id are defined in
+ * descriptor.
+ * @param bufferSize Requested buffer size, application shall respond with
+ * at least given number of bytes.
+ */
+ public void onGetReport(byte type, byte id, int bufferSize) {
+ Log.d(TAG, "onGetReport: type=" + type + " id=" + id + " bufferSize=" + bufferSize);
+ }
+
+ /**
+ * Callback called when SET_REPORT is received from remote host. In case
+ * received data are invalid, application shall respond with
+ * {@link BluetoothHidDevice#reportError()}.
+ *
+ * @param type Report Type.
+ * @param id Report Id.
+ * @param data Report data.
+ */
+ public void onSetReport(byte type, byte id, byte[] data) {
+ Log.d(TAG, "onSetReport: type=" + type + " id=" + id);
+ }
+
+ /**
+ * Callback called when SET_PROTOCOL is received from remote host.
+ * Application shall use this information to send only reports valid for
+ * given protocol mode. By default,
+ * {@link BluetoothHidDevice#PROTOCOL_REPORT_MODE} shall be assumed.
+ *
+ * @param protocol Protocol Mode.
+ */
+ public void onSetProtocol(byte protocol) {
+ Log.d(TAG, "onSetProtocol: protocol=" + protocol);
+ }
+
+ /**
+ * Callback called when report data is received over interrupt channel.
+ * Report Type is assumed to be
+ * {@link BluetoothHidDevice#REPORT_TYPE_OUTPUT}.
+ *
+ * @param reportId Report Id.
+ * @param data Report data.
+ */
+ public void onIntrData(byte reportId, byte[] data) {
+ Log.d(TAG, "onIntrData: reportId=" + reportId);
+ }
+
+ /**
+ * Callback called when Virtual Cable is removed. This can be either due to
+ * {@link BluetoothHidDevice#unplug()} or request from remote side. After
+ * this callback is received connection will be disconnected automatically.
+ */
+ public void onVirtualCableUnplug() {
+ Log.d(TAG, "onVirtualCableUnplug");
+ }
+}
diff --git a/core/java/android/bluetooth/BluetoothInputHost.java b/core/java/android/bluetooth/BluetoothInputHost.java
new file mode 100644
index 0000000..129fe7e
--- /dev/null
+++ b/core/java/android/bluetooth/BluetoothInputHost.java
@@ -0,0 +1,521 @@
+/*
+ * Copyright (C) 2016 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.bluetooth;
+
+import android.annotation.SdkConstant;
+import android.annotation.SdkConstant.SdkConstantType;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.util.Log;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @hide
+ */
+public final class BluetoothInputHost implements BluetoothProfile {
+
+ private static final String TAG = BluetoothInputHost.class.getSimpleName();
+
+ /**
+ * Intent used to broadcast the change in connection state of the Input
+ * Host profile.
+ *
+ * <p>This intent will have 3 extras:
+ * <ul>
+ * <li> {@link #EXTRA_STATE} - The current state of the profile. </li>
+ * <li> {@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile.</li>
+ * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li>
+ * </ul>
+ *
+ * <p>{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of
+ * {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING},
+ * {@link #STATE_CONNECTED}, {@link #STATE_DISCONNECTING}.
+ *
+ * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to
+ * receive.
+ */
+ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+ public static final String ACTION_CONNECTION_STATE_CHANGED =
+ "android.bluetooth.inputhost.profile.action.CONNECTION_STATE_CHANGED";
+
+ /**
+ * Constants representing device subclass.
+ *
+ * @see #registerApp(String, String, String, byte, byte[],
+ * BluetoothHidDeviceCallback)
+ */
+ public static final byte SUBCLASS1_NONE = (byte) 0x00;
+ public static final byte SUBCLASS1_KEYBOARD = (byte) 0x40;
+ public static final byte SUBCLASS1_MOUSE = (byte) 0x80;
+ public static final byte SUBCLASS1_COMBO = (byte) 0xC0;
+
+ public static final byte SUBCLASS2_UNCATEGORIZED = (byte) 0x00;
+ public static final byte SUBCLASS2_JOYSTICK = (byte) 0x01;
+ public static final byte SUBCLASS2_GAMEPAD = (byte) 0x02;
+ public static final byte SUBCLASS2_REMOTE_CONTROL = (byte) 0x03;
+ public static final byte SUBCLASS2_SENSING_DEVICE = (byte) 0x04;
+ public static final byte SUBCLASS2_DIGITIZER_TABLED = (byte) 0x05;
+ public static final byte SUBCLASS2_CARD_READER = (byte) 0x06;
+
+ /**
+ * Constants representing report types.
+ *
+ * @see BluetoothHidDeviceCallback#onGetReport(byte, byte, int)
+ * @see BluetoothHidDeviceCallback#onSetReport(byte, byte, byte[])
+ * @see BluetoothHidDeviceCallback#onIntrData(byte, byte[])
+ */
+ public static final byte REPORT_TYPE_INPUT = (byte) 1;
+ public static final byte REPORT_TYPE_OUTPUT = (byte) 2;
+ public static final byte REPORT_TYPE_FEATURE = (byte) 3;
+
+ /**
+ * Constants representing error response for Set Report.
+ *
+ * @see BluetoothHidDeviceCallback#onSetReport(byte, byte, byte[])
+ */
+ public static final byte ERROR_RSP_SUCCESS = (byte) 0;
+ public static final byte ERROR_RSP_NOT_READY = (byte) 1;
+ public static final byte ERROR_RSP_INVALID_RPT_ID = (byte) 2;
+ public static final byte ERROR_RSP_UNSUPPORTED_REQ = (byte) 3;
+ public static final byte ERROR_RSP_INVALID_PARAM = (byte) 4;
+ public static final byte ERROR_RSP_UNKNOWN = (byte) 14;
+
+ /**
+ * Constants representing protocol mode used set by host. Default is always
+ * {@link #PROTOCOL_REPORT_MODE} unless notified otherwise.
+ *
+ * @see BluetoothHidDeviceCallback#onSetProtocol(byte)
+ */
+ public static final byte PROTOCOL_BOOT_MODE = (byte) 0;
+ public static final byte PROTOCOL_REPORT_MODE = (byte) 1;
+
+ private Context mContext;
+
+ private ServiceListener mServiceListener;
+
+ private IBluetoothInputHost mService;
+
+ private BluetoothAdapter mAdapter;
+
+ private static class BluetoothHidDeviceCallbackWrapper extends IBluetoothHidDeviceCallback.Stub {
+
+ private BluetoothHidDeviceCallback mCallback;
+
+ public BluetoothHidDeviceCallbackWrapper(BluetoothHidDeviceCallback callback) {
+ mCallback = callback;
+ }
+
+ @Override
+ public void onAppStatusChanged(BluetoothDevice pluggedDevice,
+ BluetoothHidDeviceAppConfiguration config, boolean registered) {
+ mCallback.onAppStatusChanged(pluggedDevice, config, registered);
+ }
+
+ @Override
+ public void onConnectionStateChanged(BluetoothDevice device, int state) {
+ mCallback.onConnectionStateChanged(device, state);
+ }
+
+ @Override
+ public void onGetReport(byte type, byte id, int bufferSize) {
+ mCallback.onGetReport(type, id, bufferSize);
+ }
+
+ @Override
+ public void onSetReport(byte type, byte id, byte[] data) {
+ mCallback.onSetReport(type, id, data);
+ }
+
+ @Override
+ public void onSetProtocol(byte protocol) {
+ mCallback.onSetProtocol(protocol);
+ }
+
+ @Override
+ public void onIntrData(byte reportId, byte[] data) {
+ mCallback.onIntrData(reportId, data);
+ }
+
+ @Override
+ public void onVirtualCableUnplug() {
+ mCallback.onVirtualCableUnplug();
+ }
+ }
+
+ final private IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
+ new IBluetoothStateChangeCallback.Stub() {
+
+ public void onBluetoothStateChange(boolean up) {
+ Log.d(TAG, "onBluetoothStateChange: up=" + up);
+ synchronized (mConnection) {
+ if (!up) {
+ Log.d(TAG,"Unbinding service...");
+ if (mService != null) {
+ mService = null;
+ try {
+ mContext.unbindService(mConnection);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG,"onBluetoothStateChange: could not unbind service:", e);
+ }
+ }
+ } else {
+ try {
+ if (mService == null) {
+ Log.d(TAG,"Binding HID Device service...");
+ doBind();
+ }
+ } catch (IllegalStateException e) {
+ Log.e(TAG,"onBluetoothStateChange: could not bind to HID Dev service: ", e);
+ } catch (SecurityException e) {
+ Log.e(TAG,"onBluetoothStateChange: could not bind to HID Dev service: ", e);
+ }
+ }
+ }
+ }
+ };
+
+ private ServiceConnection mConnection = new ServiceConnection() {
+
+ public void onServiceConnected(ComponentName className, IBinder service) {
+ Log.d(TAG, "onServiceConnected()");
+
+ mService = IBluetoothInputHost.Stub.asInterface(service);
+
+ if (mServiceListener != null) {
+ mServiceListener.onServiceConnected(BluetoothProfile.INPUT_HOST,
+ BluetoothInputHost.this);
+ }
+ }
+
+ public void onServiceDisconnected(ComponentName className) {
+ Log.d(TAG, "onServiceDisconnected()");
+
+ mService = null;
+
+ if (mServiceListener != null) {
+ mServiceListener.onServiceDisconnected(BluetoothProfile.INPUT_HOST);
+ }
+ }
+ };
+
+ BluetoothInputHost(Context context, ServiceListener listener) {
+ Log.v(TAG, "BluetoothInputHost");
+
+ mContext = context;
+ mServiceListener = listener;
+ mAdapter = BluetoothAdapter.getDefaultAdapter();
+
+ IBluetoothManager mgr = mAdapter.getBluetoothManager();
+ if (mgr != null) {
+ try {
+ mgr.registerStateChangeCallback(mBluetoothStateChangeCallback);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+
+ doBind();
+ }
+
+ boolean doBind() {
+ Intent intent = new Intent(IBluetoothInputHost.class.getName());
+ ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
+ intent.setComponent(comp);
+ if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
+ android.os.Process.myUserHandle())) {
+ Log.e(TAG, "Could not bind to Bluetooth HID Device Service with " + intent);
+ return false;
+ }
+ Log.d(TAG, "Bound to HID Device Service");
+ return true;
+ }
+
+ void close() {
+ Log.v(TAG, "close()");
+
+ IBluetoothManager mgr = mAdapter.getBluetoothManager();
+ if (mgr != null) {
+ try {
+ mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+
+ synchronized (mConnection) {
+ if (mService != null) {
+ mService = null;
+ try {
+ mContext.unbindService(mConnection);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG,"close: could not unbind HID Dev service: ", e);
+ }
+ }
+ }
+
+ mServiceListener = null;
+ }
+
+ @Override
+ public List<BluetoothDevice> getConnectedDevices() {
+ Log.v(TAG, "getConnectedDevices()");
+ return null;
+ }
+
+ @Override
+ public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
+ Log.v(TAG, "getDevicesMatchingConnectionStates(): states=" + Arrays.toString(states));
+ return null;
+ }
+
+ @Override
+ public int getConnectionState(BluetoothDevice device) {
+ Log.v(TAG, "getConnectionState(): device=" + device.getAddress());
+
+ return STATE_DISCONNECTED;
+ }
+
+ /**
+ * Registers application to be used for HID device. Connections to HID
+ * Device are only possible when application is registered. Only one
+ * application can be registered at time. When no longer used, application
+ * should be unregistered using
+ * {@link #unregisterApp(BluetoothHidDeviceAppConfiguration)}.
+ *
+ * @param sdp {@link BluetoothHidDeviceAppSdpSettings} object of
+ * HID Device SDP record.
+ * @param inQos {@link BluetoothHidDeviceAppQosSettings} object of
+ * Incoming QoS Settings.
+ * @param outQos {@link BluetoothHidDeviceAppQosSettings} object of
+ * Outgoing QoS Settings.
+ * @param callback {@link BluetoothHidDeviceCallback} object to which
+ * callback messages will be sent.
+ * @return
+ */
+ public boolean registerApp(BluetoothHidDeviceAppSdpSettings sdp,
+ BluetoothHidDeviceAppQosSettings inQos, BluetoothHidDeviceAppQosSettings outQos,
+ BluetoothHidDeviceCallback callback) {
+ Log.v(TAG, "registerApp(): sdp=" + sdp + " inQos=" + inQos + " outQos=" + outQos
+ + " callback=" + callback);
+
+ boolean result = false;
+
+ if (sdp == null || callback == null) {
+ return false;
+ }
+
+ if (mService != null) {
+ try {
+ BluetoothHidDeviceAppConfiguration config =
+ new BluetoothHidDeviceAppConfiguration();
+ BluetoothHidDeviceCallbackWrapper cbw =
+ new BluetoothHidDeviceCallbackWrapper(callback);
+ result = mService.registerApp(config, sdp, inQos, outQos, cbw);
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
+ } else {
+ Log.w(TAG, "Proxy not attached to service");
+ }
+
+ return result;
+ }
+
+ /**
+ * Unregisters application. Active connection will be disconnected and no
+ * new connections will be allowed until registered again using
+ * {@link #registerApp(String, String, String, byte, byte[], BluetoothHidDeviceCallback)}
+ *
+ * @param config {@link BluetoothHidDeviceAppConfiguration} object as
+ * obtained from
+ * {@link BluetoothHidDeviceCallback#onAppStatusChanged(BluetoothDevice,
+ * BluetoothHidDeviceAppConfiguration, boolean)}
+ *
+ * @return
+ */
+ public boolean unregisterApp(BluetoothHidDeviceAppConfiguration config) {
+ Log.v(TAG, "unregisterApp()");
+
+ boolean result = false;
+
+ if (mService != null) {
+ try {
+ result = mService.unregisterApp(config);
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
+ } else {
+ Log.w(TAG, "Proxy not attached to service");
+ }
+
+ return result;
+ }
+
+ /**
+ * Sends report to remote host using interrupt channel.
+ *
+ * @param id Report Id, as defined in descriptor. Can be 0 in case Report Id
+ * are not defined in descriptor.
+ * @param data Report data, not including Report Id.
+ * @return
+ */
+ public boolean sendReport(int id, byte[] data) {
+ Log.v(TAG, "sendReport(): id=" + id);
+
+ boolean result = false;
+
+ if (mService != null) {
+ try {
+ result = mService.sendReport(id, data);
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
+ } else {
+ Log.w(TAG, "Proxy not attached to service");
+ }
+
+ return result;
+ }
+
+ /**
+ * Sends report to remote host as reply for GET_REPORT request from
+ * {@link BluetoothHidDeviceCallback#onGetReport(byte, byte, int)}.
+ *
+ * @param type Report Type, as in request.
+ * @param id Report Id, as in request.
+ * @param data Report data, not including Report Id.
+ * @return
+ */
+ public boolean replyReport(byte type, byte id, byte[] data) {
+ Log.v(TAG, "replyReport(): type=" + type + " id=" + id);
+
+ boolean result = false;
+
+ if (mService != null) {
+ try {
+ result = mService.replyReport(type, id, data);
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
+ } else {
+ Log.w(TAG, "Proxy not attached to service");
+ }
+
+ return result;
+ }
+
+ /**
+ * Sends error handshake message as reply for invalid SET_REPORT request
+ * from {@link BluetoothHidDeviceCallback#onSetReport(byte, byte, byte[])}.
+ *
+ * @param error Error to be sent for SET_REPORT via HANDSHAKE.
+ * @return
+ */
+ public boolean reportError(byte error) {
+ Log.v(TAG, "reportError(): error = " + error);
+
+ boolean result = false;
+
+ if (mService != null) {
+ try {
+ result = mService.reportError(error);
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
+ } else {
+ Log.w(TAG, "Proxy not attached to service");
+ }
+
+ return result;
+ }
+
+ /**
+ * Sends Virtual Cable Unplug to currently connected host.
+ *
+ * @return
+ */
+ public boolean unplug() {
+ Log.v(TAG, "unplug()");
+
+ boolean result = false;
+
+ if (mService != null) {
+ try {
+ result = mService.unplug();
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
+ } else {
+ Log.w(TAG, "Proxy not attached to service");
+ }
+
+ return result;
+ }
+
+ /**
+ * Initiates connection to host which currently has Virtual Cable
+ * established with device.
+ *
+ * @return
+ */
+ public boolean connect() {
+ Log.v(TAG, "connect()");
+
+ boolean result = false;
+
+ if (mService != null) {
+ try {
+ result = mService.connect();
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
+ } else {
+ Log.w(TAG, "Proxy not attached to service");
+ }
+
+ return result;
+ }
+
+ /**
+ * Disconnects from currently connected host.
+ *
+ * @return
+ */
+ public boolean disconnect() {
+ Log.v(TAG, "disconnect()");
+
+ boolean result = false;
+
+ if (mService != null) {
+ try {
+ result = mService.disconnect();
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
+ } else {
+ Log.w(TAG, "Proxy not attached to service");
+ }
+
+ return result;
+ }
+}
diff --git a/core/java/android/bluetooth/BluetoothProfile.java b/core/java/android/bluetooth/BluetoothProfile.java
index f363607..2f64c71 100644
--- a/core/java/android/bluetooth/BluetoothProfile.java
+++ b/core/java/android/bluetooth/BluetoothProfile.java
@@ -143,11 +143,17 @@
public static final int MAP_CLIENT = 18;
/**
+ * Input Host
+ * @hide
+ */
+ static public final int INPUT_HOST = 19;
+
+ /**
* Max profile ID. This value should be updated whenever a new profile is added to match
* the largest value assigned to a profile.
* @hide
*/
- public static final int MAX_PROFILE_ID = 17;
+ public static final int MAX_PROFILE_ID = 19;
/**
* Default priority for devices that we try to auto-connect to and
diff --git a/core/java/android/bluetooth/IBluetoothHidDeviceCallback.aidl b/core/java/android/bluetooth/IBluetoothHidDeviceCallback.aidl
new file mode 100644
index 0000000..1252876
--- /dev/null
+++ b/core/java/android/bluetooth/IBluetoothHidDeviceCallback.aidl
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2016, 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.bluetooth;
+
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothHidDeviceAppConfiguration;
+
+/** @hide */
+interface IBluetoothHidDeviceCallback {
+ void onAppStatusChanged(in BluetoothDevice device, in BluetoothHidDeviceAppConfiguration config, boolean registered);
+ void onConnectionStateChanged(in BluetoothDevice device, in int state);
+ void onGetReport(in byte type, in byte id, in int bufferSize);
+ void onSetReport(in byte type, in byte id, in byte[] data);
+ void onSetProtocol(in byte protocol);
+ void onIntrData(in byte reportId, in byte[] data);
+ void onVirtualCableUnplug();
+}
diff --git a/core/java/android/bluetooth/IBluetoothInputHost.aidl b/core/java/android/bluetooth/IBluetoothInputHost.aidl
new file mode 100644
index 0000000..b2c421c
--- /dev/null
+++ b/core/java/android/bluetooth/IBluetoothInputHost.aidl
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2016 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.bluetooth;
+
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothHidDeviceAppConfiguration;
+import android.bluetooth.IBluetoothHidDeviceCallback;
+import android.bluetooth.BluetoothHidDeviceAppSdpSettings;
+import android.bluetooth.BluetoothHidDeviceAppQosSettings;
+
+/** @hide */
+interface IBluetoothInputHost {
+ boolean registerApp(in BluetoothHidDeviceAppConfiguration config,
+ in BluetoothHidDeviceAppSdpSettings sdp, in BluetoothHidDeviceAppQosSettings inQos,
+ in BluetoothHidDeviceAppQosSettings outQos, in IBluetoothHidDeviceCallback callback);
+ boolean unregisterApp(in BluetoothHidDeviceAppConfiguration config);
+ boolean sendReport(in int id, in byte[] data);
+ boolean replyReport(in byte type, in byte id, in byte[] data);
+ boolean reportError(byte error);
+ boolean unplug();
+ boolean connect();
+ boolean disconnect();
+}
diff --git a/core/java/android/bluetooth/IBluetoothManager.aidl b/core/java/android/bluetooth/IBluetoothManager.aidl
index 2b853a3..5afd774 100644
--- a/core/java/android/bluetooth/IBluetoothManager.aidl
+++ b/core/java/android/bluetooth/IBluetoothManager.aidl
@@ -34,9 +34,9 @@
void registerStateChangeCallback(in IBluetoothStateChangeCallback callback);
void unregisterStateChangeCallback(in IBluetoothStateChangeCallback callback);
boolean isEnabled();
- boolean enable();
- boolean enableNoAutoConnect();
- boolean disable(boolean persist);
+ boolean enable(String packageName);
+ boolean enableNoAutoConnect(String packageName);
+ boolean disable(String packageName, boolean persist);
int getState();
IBluetoothGatt getBluetoothGatt();
@@ -47,6 +47,6 @@
String getName();
boolean isBleScanAlwaysAvailable();
- int updateBleAppCount(IBinder b, boolean enable);
+ int updateBleAppCount(IBinder b, boolean enable, String packageName);
boolean isBleAppPresent();
}
diff --git a/core/java/android/content/pm/IPackageManager.aidl b/core/java/android/content/pm/IPackageManager.aidl
index 11f0eb6..f35b13d 100644
--- a/core/java/android/content/pm/IPackageManager.aidl
+++ b/core/java/android/content/pm/IPackageManager.aidl
@@ -458,6 +458,15 @@
void notifyPackageUse(String packageName, int reason);
/**
+ * Notify the package manager that a list of dex files have been loaded.
+ *
+ * @param loadingPackageName the name of the package who performs the load
+ * @param dexPats the list of the dex files paths that have been loaded
+ * @param loaderIsa the ISA of the loader process
+ */
+ void notifyDexLoad(String loadingPackageName, in List<String> dexPaths, String loaderIsa);
+
+ /**
* Ask the package manager to perform dex-opt (if needed) on the given
* package if it already hasn't done so.
*
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index 2093124..3011a69f 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -342,6 +342,7 @@
public final int[] splitRevisionCodes;
public final boolean coreApp;
+ public final boolean debuggable;
public final boolean multiArch;
public final boolean use32bitAbi;
public final boolean extractNativeLibs;
@@ -359,6 +360,7 @@
this.baseRevisionCode = baseApk.revisionCode;
this.splitRevisionCodes = splitRevisionCodes;
this.coreApp = baseApk.coreApp;
+ this.debuggable = baseApk.debuggable;
this.multiArch = baseApk.multiArch;
this.use32bitAbi = baseApk.use32bitAbi;
this.extractNativeLibs = baseApk.extractNativeLibs;
@@ -388,6 +390,7 @@
public final Signature[] signatures;
public final Certificate[][] certificates;
public final boolean coreApp;
+ public final boolean debuggable;
public final boolean multiArch;
public final boolean use32bitAbi;
public final boolean extractNativeLibs;
@@ -395,7 +398,8 @@
public ApkLite(String codePath, String packageName, String splitName, int versionCode,
int revisionCode, int installLocation, List<VerifierInfo> verifiers,
Signature[] signatures, Certificate[][] certificates, boolean coreApp,
- boolean multiArch, boolean use32bitAbi, boolean extractNativeLibs) {
+ boolean debuggable, boolean multiArch, boolean use32bitAbi,
+ boolean extractNativeLibs) {
this.codePath = codePath;
this.packageName = packageName;
this.splitName = splitName;
@@ -406,6 +410,7 @@
this.signatures = signatures;
this.certificates = certificates;
this.coreApp = coreApp;
+ this.debuggable = debuggable;
this.multiArch = multiArch;
this.use32bitAbi = use32bitAbi;
this.extractNativeLibs = extractNativeLibs;
@@ -1440,6 +1445,7 @@
int versionCode = 0;
int revisionCode = 0;
boolean coreApp = false;
+ boolean debuggable = false;
boolean multiArch = false;
boolean use32bitAbi = false;
boolean extractNativeLibs = true;
@@ -1479,6 +1485,9 @@
if (parser.getDepth() == searchDepth && "application".equals(parser.getName())) {
for (int i = 0; i < attrs.getAttributeCount(); ++i) {
final String attr = attrs.getAttributeName(i);
+ if ("debuggable".equals(attr)) {
+ debuggable = attrs.getAttributeBooleanValue(i, false);
+ }
if ("multiArch".equals(attr)) {
multiArch = attrs.getAttributeBooleanValue(i, false);
}
@@ -1494,7 +1503,7 @@
return new ApkLite(codePath, packageSplit.first, packageSplit.second, versionCode,
revisionCode, installLocation, verifiers, signatures, certificates, coreApp,
- multiArch, use32bitAbi, extractNativeLibs);
+ debuggable, multiArch, use32bitAbi, extractNativeLibs);
}
/**
diff --git a/core/java/android/hardware/location/ContextHubManager.java b/core/java/android/hardware/location/ContextHubManager.java
index d4dcacc..0c4573b 100644
--- a/core/java/android/hardware/location/ContextHubManager.java
+++ b/core/java/android/hardware/location/ContextHubManager.java
@@ -391,7 +391,7 @@
public ContextHubManager(Context context, Looper mainLooper) {
mMainLooper = mainLooper;
- IBinder b = ServiceManager.getService(ContextHubService.CONTEXTHUB_SERVICE);
+ IBinder b = ServiceManager.getService(Context.CONTEXTHUB_SERVICE);
if (b != null) {
mContextHubService = IContextHubService.Stub.asInterface(b);
diff --git a/core/java/android/hardware/usb/UsbManager.java b/core/java/android/hardware/usb/UsbManager.java
index 3df57bc..ee646c0 100644
--- a/core/java/android/hardware/usb/UsbManager.java
+++ b/core/java/android/hardware/usb/UsbManager.java
@@ -181,6 +181,14 @@
public static final String USB_DATA_UNLOCKED = "unlocked";
/**
+ * Boolean extra indicating whether the intent represents a change in the usb
+ * configuration (as opposed to a state update).
+ *
+ * {@hide}
+ */
+ public static final String USB_CONFIG_CHANGED = "config_changed";
+
+ /**
* A placeholder indicating that no USB function is being specified.
* Used to distinguish between selecting no function vs. the default function in
* {@link #setCurrentFunction(String)}.
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index 43c8c81..51431eb 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -2079,6 +2079,8 @@
@SystemApi
public void startTethering(int type, boolean showProvisioningUi,
final OnStartTetheringCallback callback, Handler handler) {
+ checkNotNull(callback, "OnStartTetheringCallback cannot be null.");
+
ResultReceiver wrappedCallback = new ResultReceiver(handler) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
@@ -2089,6 +2091,7 @@
}
}
};
+
try {
mService.startTethering(type, wrappedCallback, showProvisioningUi);
} catch (RemoteException e) {
@@ -2657,6 +2660,7 @@
public static final int CALLBACK_IP_CHANGED = BASE + 7;
/** @hide */
public static final int CALLBACK_RELEASED = BASE + 8;
+ // TODO: consider deleting CALLBACK_EXIT and shifting following enum codes down by 1.
/** @hide */
public static final int CALLBACK_EXIT = BASE + 9;
/** @hide obj = NetworkCapabilities, arg1 = seq number */
@@ -2687,24 +2691,17 @@
}
private class CallbackHandler extends Handler {
- private final HashMap<NetworkRequest, NetworkCallback>mCallbackMap;
- private final AtomicInteger mRefCount;
private static final String TAG = "ConnectivityManager.CallbackHandler";
- private final ConnectivityManager mCm;
private static final boolean DBG = false;
- CallbackHandler(Looper looper, HashMap<NetworkRequest, NetworkCallback>callbackMap,
- AtomicInteger refCount, ConnectivityManager cm) {
+ CallbackHandler(Looper looper) {
super(looper);
- mCallbackMap = callbackMap;
- mRefCount = refCount;
- mCm = cm;
}
@Override
public void handleMessage(Message message) {
- NetworkRequest request = (NetworkRequest) getObject(message, NetworkRequest.class);
- Network network = (Network) getObject(message, Network.class);
+ NetworkRequest request = getObject(message, NetworkRequest.class);
+ Network network = getObject(message, Network.class);
if (DBG) {
Log.d(TAG, whatToString(message.what) + " for network " + network);
}
@@ -2747,9 +2744,7 @@
case CALLBACK_CAP_CHANGED: {
NetworkCallback callback = getCallback(request, "CAP_CHANGED");
if (callback != null) {
- NetworkCapabilities cap = (NetworkCapabilities)getObject(message,
- NetworkCapabilities.class);
-
+ NetworkCapabilities cap = getObject(message, NetworkCapabilities.class);
callback.onCapabilitiesChanged(network, cap);
}
break;
@@ -2757,9 +2752,7 @@
case CALLBACK_IP_CHANGED: {
NetworkCallback callback = getCallback(request, "IP_CHANGED");
if (callback != null) {
- LinkProperties lp = (LinkProperties)getObject(message,
- LinkProperties.class);
-
+ LinkProperties lp = getObject(message, LinkProperties.class);
callback.onLinkPropertiesChanged(network, lp);
}
break;
@@ -2779,24 +2772,16 @@
break;
}
case CALLBACK_RELEASED: {
- NetworkCallback callback = null;
- synchronized(mCallbackMap) {
- callback = mCallbackMap.remove(request);
+ final NetworkCallback callback;
+ synchronized(sCallbacks) {
+ callback = sCallbacks.remove(request);
}
- if (callback != null) {
- synchronized(mRefCount) {
- if (mRefCount.decrementAndGet() == 0) {
- getLooper().quit();
- }
- }
- } else {
+ if (callback == null) {
Log.e(TAG, "callback not found for RELEASED message");
}
break;
}
case CALLBACK_EXIT: {
- Log.d(TAG, "Listener quitting");
- getLooper().quit();
break;
}
case EXPIRE_LEGACY_REQUEST: {
@@ -2806,14 +2791,14 @@
}
}
- private Object getObject(Message msg, Class c) {
- return msg.getData().getParcelable(c.getSimpleName());
+ private <T> T getObject(Message msg, Class<T> c) {
+ return (T) msg.getData().getParcelable(c.getSimpleName());
}
private NetworkCallback getCallback(NetworkRequest req, String name) {
NetworkCallback callback;
- synchronized(mCallbackMap) {
- callback = mCallbackMap.get(req);
+ synchronized(sCallbacks) {
+ callback = sCallbacks.get(req);
}
if (callback == null) {
Log.e(TAG, "callback not found for " + name + " message");
@@ -2822,63 +2807,56 @@
}
}
- private void incCallbackHandlerRefCount() {
- synchronized(sCallbackRefCount) {
- if (sCallbackRefCount.incrementAndGet() == 1) {
- // TODO: switch this to ConnectivityThread
- HandlerThread callbackThread = new HandlerThread("ConnectivityManager");
- callbackThread.start();
- sCallbackHandler = new CallbackHandler(callbackThread.getLooper(),
- sNetworkCallback, sCallbackRefCount, this);
+ private CallbackHandler getHandler() {
+ synchronized (sCallbacks) {
+ if (sCallbackHandler == null) {
+ sCallbackHandler = new CallbackHandler(ConnectivityThread.getInstanceLooper());
}
+ return sCallbackHandler;
}
}
- private void decCallbackHandlerRefCount() {
- synchronized(sCallbackRefCount) {
- if (sCallbackRefCount.decrementAndGet() == 0) {
- sCallbackHandler.obtainMessage(CALLBACK_EXIT).sendToTarget();
- sCallbackHandler = null;
- }
- }
- }
-
- static final HashMap<NetworkRequest, NetworkCallback> sNetworkCallback =
- new HashMap<NetworkRequest, NetworkCallback>();
- static final AtomicInteger sCallbackRefCount = new AtomicInteger(0);
- static CallbackHandler sCallbackHandler = null;
+ static final HashMap<NetworkRequest, NetworkCallback> sCallbacks = new HashMap<>();
+ static CallbackHandler sCallbackHandler;
private final static int LISTEN = 1;
private final static int REQUEST = 2;
private NetworkRequest sendRequestForNetwork(NetworkCapabilities need,
- NetworkCallback networkCallback, int timeoutMs, int action,
- int legacyType) {
- if (networkCallback == null) {
+ NetworkCallback callback, int timeoutMs, int action, int legacyType) {
+ return sendRequestForNetwork(need, callback, getHandler(), timeoutMs, action, legacyType);
+ }
+
+ private NetworkRequest sendRequestForNetwork(NetworkCapabilities need,
+ NetworkCallback callback, Handler handler, int timeoutMs, int action, int legacyType) {
+ if (callback == null) {
throw new IllegalArgumentException("null NetworkCallback");
}
if (need == null && action != REQUEST) {
throw new IllegalArgumentException("null NetworkCapabilities");
}
+ // TODO: throw an exception if callback.networkRequest is not null.
+ // http://b/20701525
+ final NetworkRequest request;
try {
- incCallbackHandlerRefCount();
- synchronized(sNetworkCallback) {
+ synchronized(sCallbacks) {
+ Messenger messenger = new Messenger(handler);
+ Binder binder = new Binder();
if (action == LISTEN) {
- networkCallback.networkRequest = mService.listenForNetwork(need,
- new Messenger(sCallbackHandler), new Binder());
+ request = mService.listenForNetwork(need, messenger, binder);
} else {
- networkCallback.networkRequest = mService.requestNetwork(need,
- new Messenger(sCallbackHandler), timeoutMs, new Binder(), legacyType);
+ request = mService.requestNetwork(
+ need, messenger, timeoutMs, binder, legacyType);
}
- if (networkCallback.networkRequest != null) {
- sNetworkCallback.put(networkCallback.networkRequest, networkCallback);
+ if (request != null) {
+ sCallbacks.put(request, callback);
}
+ callback.networkRequest = request;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
- if (networkCallback.networkRequest == null) decCallbackHandlerRefCount();
- return networkCallback.networkRequest;
+ return request;
}
/**
diff --git a/core/java/android/net/ConnectivityThread.java b/core/java/android/net/ConnectivityThread.java
index 55c3402..0b218e7 100644
--- a/core/java/android/net/ConnectivityThread.java
+++ b/core/java/android/net/ConnectivityThread.java
@@ -27,25 +27,30 @@
* @hide
*/
public final class ConnectivityThread extends HandlerThread {
- private static ConnectivityThread sInstance;
+
+ // A class implementing the lazy holder idiom: the unique static instance
+ // of ConnectivityThread is instantiated in a thread-safe way (guaranteed by
+ // the language specs) the first time that Singleton is referenced in get()
+ // or getInstanceLooper().
+ private static class Singleton {
+ private static final ConnectivityThread INSTANCE = createInstance();
+ }
private ConnectivityThread() {
super("ConnectivityThread");
}
- private static synchronized ConnectivityThread getInstance() {
- if (sInstance == null) {
- sInstance = new ConnectivityThread();
- sInstance.start();
- }
- return sInstance;
+ private static ConnectivityThread createInstance() {
+ ConnectivityThread t = new ConnectivityThread();
+ t.start();
+ return t;
}
public static ConnectivityThread get() {
- return getInstance();
+ return Singleton.INSTANCE;
}
public static Looper getInstanceLooper() {
- return getInstance().getLooper();
+ return Singleton.INSTANCE.getLooper();
}
}
diff --git a/core/java/android/net/EventLogTags.logtags b/core/java/android/net/EventLogTags.logtags
new file mode 100644
index 0000000..d5ed014
--- /dev/null
+++ b/core/java/android/net/EventLogTags.logtags
@@ -0,0 +1,6 @@
+# See system/core/logcat/event.logtags for a description of the format of this file.
+
+option java_package android.net
+
+50080 ntp_success (server|3),(rtt|2),(offset|2)
+50081 ntp_failure (server|3),(msg|3)
diff --git a/core/java/android/net/IIpConnectivityMetrics.aidl b/core/java/android/net/IIpConnectivityMetrics.aidl
index 8f634bb..d36b766 100644
--- a/core/java/android/net/IIpConnectivityMetrics.aidl
+++ b/core/java/android/net/IIpConnectivityMetrics.aidl
@@ -23,7 +23,8 @@
interface IIpConnectivityMetrics {
/**
- * @return number of remaining available slots in buffer.
+ * @return the number of remaining available slots in buffer,
+ * or -1 if the event was dropped due to rate limiting.
*/
int logEvent(in ConnectivityMetricsEvent event);
}
diff --git a/core/java/android/net/INetworkRecommendationProvider.aidl b/core/java/android/net/INetworkRecommendationProvider.aidl
index 5e455d3..052c92c 100644
--- a/core/java/android/net/INetworkRecommendationProvider.aidl
+++ b/core/java/android/net/INetworkRecommendationProvider.aidl
@@ -16,6 +16,7 @@
package android.net;
+import android.net.NetworkKey;
import android.net.RecommendationRequest;
import android.os.IRemoteCallback;
@@ -38,4 +39,15 @@
void requestRecommendation(in RecommendationRequest request,
in IRemoteCallback callback,
int sequence);
+
+ /**
+ * Request scoring for networks.
+ *
+ * Implementations should use {@link NetworkScoreManager#updateScores(ScoredNetwork[])} to
+ * respond to score requests.
+ *
+ * @param networks an array of {@link NetworkKey}s to score
+ * @hide
+ */
+ void requestScores(in NetworkKey[] networks);
}
\ No newline at end of file
diff --git a/core/java/android/net/INetworkScoreService.aidl b/core/java/android/net/INetworkScoreService.aidl
index 542a0a7..932f031 100644
--- a/core/java/android/net/INetworkScoreService.aidl
+++ b/core/java/android/net/INetworkScoreService.aidl
@@ -17,6 +17,7 @@
package android.net;
import android.net.INetworkScoreCache;
+import android.net.NetworkKey;
import android.net.RecommendationRequest;
import android.net.RecommendationResult;
import android.net.ScoredNetwork;
@@ -58,12 +59,14 @@
/**
* Register a cache to receive scoring updates.
*
- * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}.
- * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores.
- * @throws SecurityException if the caller is not the system.
+ * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}
+ * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores
+ * @param filterType the {@link CacheUpdateFilter} to apply
+ * @throws SecurityException if the caller is not the system
+ * @throws IllegalArgumentException if a score cache is already registed for this type
* @hide
*/
- void registerNetworkScoreCache(int networkType, INetworkScoreCache scoreCache);
+ void registerNetworkScoreCache(int networkType, INetworkScoreCache scoreCache, int filterType);
/**
* Unregister a cache to receive scoring updates.
@@ -85,4 +88,16 @@
*/
RecommendationResult requestRecommendation(in RecommendationRequest request);
+ /**
+ * Request scoring for networks.
+ *
+ * Implementations should delegate to the registered network recommendation provider or
+ * fulfill the request locally if possible.
+ *
+ * @param networks an array of {@link NetworkKey}s to score
+ * @return true if the request was delegated or fulfilled locally, false otherwise
+ * @throws SecurityException if the caller is not the system
+ * @hide
+ */
+ boolean requestScores(in NetworkKey[] networks);
}
diff --git a/core/java/android/net/NetworkIdentity.java b/core/java/android/net/NetworkIdentity.java
index d570e66..c704ef0 100644
--- a/core/java/android/net/NetworkIdentity.java
+++ b/core/java/android/net/NetworkIdentity.java
@@ -171,7 +171,8 @@
String subscriberId = null;
String networkId = null;
boolean roaming = false;
- boolean metered = false;
+ boolean metered = !state.networkCapabilities.hasCapability(
+ NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
if (isNetworkTypeMobile(type)) {
if (state.subscriberId == null) {
@@ -185,9 +186,6 @@
subscriberId = state.subscriberId;
roaming = state.networkInfo.isRoaming();
- metered = !state.networkCapabilities.hasCapability(
- NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
-
} else if (type == TYPE_WIFI) {
if (state.networkId != null) {
networkId = state.networkId;
diff --git a/core/java/android/net/NetworkPolicyManager.java b/core/java/android/net/NetworkPolicyManager.java
index 11b861a..22850b4 100644
--- a/core/java/android/net/NetworkPolicyManager.java
+++ b/core/java/android/net/NetworkPolicyManager.java
@@ -298,8 +298,11 @@
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
if (cycleDay > cal.getActualMaximum(Calendar.DAY_OF_MONTH)) {
- cal.set(Calendar.DAY_OF_MONTH, 1);
cal.add(Calendar.MONTH, 1);
+ cal.set(Calendar.DAY_OF_MONTH, 1);
+ cal.set(Calendar.HOUR_OF_DAY, 0);
+ cal.set(Calendar.MINUTE, 0);
+ cal.set(Calendar.SECOND, 0);
cal.add(Calendar.SECOND, -1);
} else {
cal.set(Calendar.DAY_OF_MONTH, cycleDay);
diff --git a/core/java/android/net/NetworkRecommendationProvider.java b/core/java/android/net/NetworkRecommendationProvider.java
index cd2ede8..16ae867 100644
--- a/core/java/android/net/NetworkRecommendationProvider.java
+++ b/core/java/android/net/NetworkRecommendationProvider.java
@@ -10,6 +10,11 @@
import android.os.RemoteException;
import android.util.Log;
+import com.android.internal.annotations.VisibleForTesting;
+
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicBoolean;
+
/**
* The base class for implementing a network recommendation provider.
* @hide
@@ -42,11 +47,21 @@
*
* @param request a {@link RecommendationRequest} instance containing additional
* request details
- * @return a {@link RecommendationResult} instance containing the recommended
- * network to connect to
+ * @param callback a {@link ResultCallback} instance. When a {@link RecommendationResult} is
+ * available it must be passed into
+ * {@link ResultCallback#onResult(RecommendationResult)}.
*/
- public abstract RecommendationResult onRequestRecommendation(RecommendationRequest request);
+ public abstract void onRequestRecommendation(RecommendationRequest request,
+ ResultCallback callback);
+ /**
+ * Invoked when network scores have been requested.
+ * <p>
+ * Use {@link NetworkScoreManager#updateScores(ScoredNetwork[])} to respond to score requests.
+ *
+ * @param networks a non-empty array of {@link NetworkKey}s to score.
+ */
+ public abstract void onRequestScores(NetworkKey[] networks);
/**
* Services that can handle {@link NetworkScoreManager#ACTION_RECOMMEND_NETWORKS} should
@@ -56,8 +71,63 @@
return mService;
}
+ /**
+ * A callback implementing applications should invoke when a {@link RecommendationResult}
+ * is available.
+ */
+ public static class ResultCallback {
+ private final IRemoteCallback mCallback;
+ private final int mSequence;
+ private final AtomicBoolean mCallbackRun;
+
+ /**
+ * @hide
+ */
+ @VisibleForTesting
+ public ResultCallback(IRemoteCallback callback, int sequence) {
+ mCallback = callback;
+ mSequence = sequence;
+ mCallbackRun = new AtomicBoolean(false);
+ }
+
+ /**
+ * Run the callback with the available {@link RecommendationResult}.
+ * @param result a {@link RecommendationResult} instance.
+ */
+ public void onResult(RecommendationResult result) {
+ if (!mCallbackRun.compareAndSet(false, true)) {
+ throw new IllegalStateException("The callback cannot be run more than once.");
+ }
+ final Bundle data = new Bundle();
+ data.putInt(EXTRA_SEQUENCE, mSequence);
+ data.putParcelable(EXTRA_RECOMMENDATION_RESULT, result);
+ try {
+ mCallback.sendResult(data);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Callback failed for seq: " + mSequence, e);
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ ResultCallback that = (ResultCallback) o;
+
+ return mSequence == that.mSequence
+ && Objects.equals(mCallback, that.mCallback);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mCallback, mSequence);
+ }
+ }
+
private final class ServiceHandler extends Handler {
static final int MSG_GET_RECOMMENDATION = 1;
+ static final int MSG_REQUEST_SCORES = 2;
ServiceHandler(Looper looper) {
super(looper, null /*callback*/, true /*async*/);
@@ -72,16 +142,13 @@
final int seq = msg.arg1;
final RecommendationRequest request =
msg.getData().getParcelable(EXTRA_RECOMMENDATION_REQUEST);
- final RecommendationResult result = onRequestRecommendation(request);
- final Bundle data = new Bundle();
- data.putInt(EXTRA_SEQUENCE, seq);
- data.putParcelable(EXTRA_RECOMMENDATION_RESULT, result);
- try {
- callback.sendResult(data);
- } catch (RemoteException e) {
- Log.w(TAG, "Callback failed for seq: " + seq, e);
- }
+ final ResultCallback resultCallback = new ResultCallback(callback, seq);
+ onRequestRecommendation(request, resultCallback);
+ break;
+ case MSG_REQUEST_SCORES:
+ final NetworkKey[] networks = (NetworkKey[]) msg.obj;
+ onRequestScores(networks);
break;
default:
@@ -110,5 +177,12 @@
msg.setData(data);
msg.sendToTarget();
}
+
+ @Override
+ public void requestScores(NetworkKey[] networks) throws RemoteException {
+ if (networks != null && networks.length > 0) {
+ mHandler.obtainMessage(ServiceHandler.MSG_REQUEST_SCORES, networks).sendToTarget();
+ }
+ }
}
}
diff --git a/core/java/android/net/NetworkScoreManager.java b/core/java/android/net/NetworkScoreManager.java
index af21cef..1825956 100644
--- a/core/java/android/net/NetworkScoreManager.java
+++ b/core/java/android/net/NetworkScoreManager.java
@@ -17,6 +17,7 @@
package android.net;
import android.Manifest;
+import android.annotation.IntDef;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
@@ -28,6 +29,9 @@
import android.os.ServiceManager;
import android.os.UserHandle;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
/**
* Class that manages communication between network subsystems and a network scorer.
*
@@ -131,6 +135,29 @@
*/
public static final String EXTRA_NEW_SCORER = "newScorer";
+ /** @hide */
+ @IntDef({CACHE_FILTER_NONE, CACHE_FILTER_CURRENT_NETWORK, CACHE_FILTER_SCAN_RESULTS})
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface CacheUpdateFilter {}
+
+ /**
+ * Do not filter updates sent to the cache.
+ * @hide
+ */
+ public static final int CACHE_FILTER_NONE = 0;
+
+ /**
+ * Only send cache updates when the network matches the connected network.
+ * @hide
+ */
+ public static final int CACHE_FILTER_CURRENT_NETWORK = 1;
+
+ /**
+ * Only send cache updates when the network is part of the current scan result set.
+ * @hide
+ */
+ public static final int CACHE_FILTER_SCAN_RESULTS = 2;
+
private final Context mContext;
private final INetworkScoreService mService;
@@ -156,7 +183,7 @@
if (app == null) {
return null;
}
- return app.mPackageName;
+ return app.packageName;
}
/**
@@ -245,19 +272,11 @@
* @hide
*/
public boolean requestScores(NetworkKey[] networks) throws SecurityException {
- String activeScorer = getActiveScorerPackage();
- if (activeScorer == null) {
- return false;
+ try {
+ return mService.requestScores(networks);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
}
- Intent intent = new Intent(ACTION_SCORE_NETWORKS);
- intent.setPackage(activeScorer);
- intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
- intent.putExtra(EXTRA_NETWORKS_TO_SCORE, networks);
- // A scorer should never become active if its package doesn't hold SCORE_NETWORKS, but
- // ensure the package still holds it to be extra safe.
- // TODO: http://b/23422763
- mContext.sendBroadcastAsUser(intent, UserHandle.SYSTEM, Manifest.permission.SCORE_NETWORKS);
- return true;
}
/**
@@ -268,11 +287,29 @@
* @throws SecurityException if the caller does not hold the
* {@link android.Manifest.permission#BROADCAST_NETWORK_PRIVILEGED} permission.
* @throws IllegalArgumentException if a score cache is already registered for this type.
+ * @deprecated equivalent to registering for cache updates with CACHE_FILTER_NONE.
* @hide
*/
+ @Deprecated // migrate to registerNetworkScoreCache(int, INetworkScoreCache, int)
public void registerNetworkScoreCache(int networkType, INetworkScoreCache scoreCache) {
+ registerNetworkScoreCache(networkType, scoreCache, CACHE_FILTER_NONE);
+ }
+
+ /**
+ * Register a network score cache.
+ *
+ * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}
+ * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores
+ * @param filterType the {@link CacheUpdateFilter} to apply
+ * @throws SecurityException if the caller does not hold the
+ * {@link android.Manifest.permission#BROADCAST_NETWORK_PRIVILEGED} permission.
+ * @throws IllegalArgumentException if a score cache is already registered for this type.
+ * @hide
+ */
+ public void registerNetworkScoreCache(int networkType, INetworkScoreCache scoreCache,
+ @CacheUpdateFilter int filterType) {
try {
- mService.registerNetworkScoreCache(networkType, scoreCache);
+ mService.registerNetworkScoreCache(networkType, scoreCache, filterType);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -299,6 +336,8 @@
/**
* Request a recommendation for which network to connect to.
*
+ * <p>It is not safe to call this method from the main thread.
+ *
* @param request a {@link RecommendationRequest} instance containing additional
* request details
* @return a {@link RecommendationResult} instance containing the recommended network
diff --git a/core/java/android/net/NetworkScorerAppManager.java b/core/java/android/net/NetworkScorerAppManager.java
index ebb31c9..4282ca7 100644
--- a/core/java/android/net/NetworkScorerAppManager.java
+++ b/core/java/android/net/NetworkScorerAppManager.java
@@ -19,160 +19,176 @@
import android.Manifest;
import android.Manifest.permission;
import android.annotation.Nullable;
+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.ResolveInfo;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
-
+import com.android.internal.R;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
- * Internal class for managing the primary network scorer application.
- *
- * TODO: Rename this to something more generic.
+ * Internal class for discovering and managing the network scorer/recommendation application.
*
* @hide
*/
public class NetworkScorerAppManager {
private static final String TAG = "NetworkScorerAppManager";
-
- private static final Intent SCORE_INTENT =
- new Intent(NetworkScoreManager.ACTION_SCORE_NETWORKS);
-
+ private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+ private static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE);
private final Context mContext;
public NetworkScorerAppManager(Context context) {
mContext = context;
}
+ /**
+ * Holds metadata about a discovered network scorer/recommendation application.
+ */
public static class NetworkScorerAppData {
/** Package name of this scorer app. */
- public final String mPackageName;
+ public final String packageName;
/** UID of the scorer app. */
- public final int mPackageUid;
-
- /** Name of this scorer app for display. */
- public final CharSequence mScorerName;
+ public final int packageUid;
/**
- * Optional class name of a configuration activity. Null if none is set.
- *
- * @see NetworkScoreManager#ACTION_CUSTOM_ENABLE
+ * Name of the recommendation service we can bind to.
*/
- public final String mConfigurationActivityClassName;
+ public final String recommendationServiceClassName;
- /**
- * Optional class name of the scoring service we can bind to. Null if none is set.
- */
- public final String mScoringServiceClassName;
-
- public NetworkScorerAppData(String packageName, int packageUid, CharSequence scorerName,
- @Nullable String configurationActivityClassName,
- @Nullable String scoringServiceClassName) {
- mScorerName = scorerName;
- mPackageName = packageName;
- mPackageUid = packageUid;
- mConfigurationActivityClassName = configurationActivityClassName;
- mScoringServiceClassName = scoringServiceClassName;
+ public NetworkScorerAppData(String packageName, int packageUid,
+ String recommendationServiceClassName) {
+ this.packageName = packageName;
+ this.packageUid = packageUid;
+ this.recommendationServiceClassName = recommendationServiceClassName;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("NetworkScorerAppData{");
- sb.append("mPackageName='").append(mPackageName).append('\'');
- sb.append(", mPackageUid=").append(mPackageUid);
- sb.append(", mScorerName=").append(mScorerName);
- sb.append(", mConfigurationActivityClassName='").append(mConfigurationActivityClassName)
- .append('\'');
- sb.append(", mScoringServiceClassName='").append(mScoringServiceClassName).append('\'');
+ sb.append("mPackageName='").append(packageName).append('\'');
+ sb.append(", packageUid=").append(packageUid);
+ sb.append(", recommendationServiceClassName='")
+ .append(recommendationServiceClassName).append('\'');
sb.append('}');
return sb.toString();
}
}
/**
- * Returns the list of available scorer apps.
+ * @return A {@link NetworkScorerAppData} instance containing information about the
+ * best configured network recommendation provider installed or {@code null}
+ * if none of the configured packages can recommend networks.
*
- * <p>A network scorer is any application which:
+ * <p>A network recommendation provider is any application which:
* <ul>
+ * <li>Is listed in the <code>config_networkRecommendationPackageNames</code> config.
* <li>Declares the {@link android.Manifest.permission#SCORE_NETWORKS} permission.
- * <li>Includes a receiver for {@link NetworkScoreManager#ACTION_SCORE_NETWORKS} guarded by the
- * {@link android.Manifest.permission#BROADCAST_NETWORK_PRIVILEGED} permission.
+ * <li>Includes a Service for {@link NetworkScoreManager#ACTION_RECOMMEND_NETWORKS}.
* </ul>
- *
- * @return the list of scorers, or the empty list if there are no valid scorers.
*/
- public Collection<NetworkScorerAppData> getAllValidScorers() {
- // Network scorer apps can only run as the primary user so exit early if we're not the
- // primary user.
+ public NetworkScorerAppData getNetworkRecommendationProviderData() {
+ // Network recommendation apps can only run as the primary user right now.
+ // http://b/23422763
if (UserHandle.getCallingUserId() != UserHandle.USER_SYSTEM) {
+ return null;
+ }
+
+ final List<String> potentialPkgs = getPotentialRecommendationProviderPackages();
+ if (potentialPkgs.isEmpty()) {
+ if (DEBUG) {
+ Log.d(TAG, "No Network Recommendation Providers specified.");
+ }
+ return null;
+ }
+
+ final PackageManager pm = mContext.getPackageManager();
+ for (int i = 0; i < potentialPkgs.size(); i++) {
+ final String potentialPkg = potentialPkgs.get(i);
+
+ // Look for the recommendation service class and required receiver.
+ final ResolveInfo resolveServiceInfo = findRecommendationService(potentialPkg);
+ if (resolveServiceInfo != null) {
+ return new NetworkScorerAppData(potentialPkg,
+ resolveServiceInfo.serviceInfo.applicationInfo.uid,
+ resolveServiceInfo.serviceInfo.name);
+ } else {
+ if (DEBUG) {
+ Log.d(TAG, potentialPkg + " does not have the required components, skipping.");
+ }
+ }
+ }
+
+ // None of the configured packages are valid.
+ return null;
+ }
+
+ /**
+ * @return A priority order list of package names that have been granted the
+ * permission needed for them to act as a network recommendation provider.
+ * The packages in the returned list may not contain the other required
+ * network recommendation provider components so additional checks are required
+ * before making a package the network recommendation provider.
+ */
+ public List<String> getPotentialRecommendationProviderPackages() {
+ final String[] packageArray = mContext.getResources().getStringArray(
+ R.array.config_networkRecommendationPackageNames);
+ if (packageArray == null || packageArray.length == 0) {
+ if (DEBUG) {
+ Log.d(TAG, "No Network Recommendation Providers specified.");
+ }
return Collections.emptyList();
}
- List<NetworkScorerAppData> scorers = new ArrayList<>();
- PackageManager pm = mContext.getPackageManager();
- // Only apps installed under the primary user of the device can be scorers.
- // TODO: http://b/23422763
- List<ResolveInfo> receivers =
- pm.queryBroadcastReceiversAsUser(SCORE_INTENT, 0 /* flags */, UserHandle.USER_SYSTEM);
- for (ResolveInfo receiver : receivers) {
- // This field is a misnomer, see android.content.pm.ResolveInfo#activityInfo
- final ActivityInfo receiverInfo = receiver.activityInfo;
- if (receiverInfo == null) {
- // Should never happen with queryBroadcastReceivers, but invalid nonetheless.
- continue;
- }
- if (!permission.BROADCAST_NETWORK_PRIVILEGED.equals(receiverInfo.permission)) {
- // Receiver doesn't require the BROADCAST_NETWORK_PRIVILEGED permission, which
- // means anyone could trigger network scoring and flood the framework with score
- // requests.
- continue;
- }
- if (pm.checkPermission(permission.SCORE_NETWORKS, receiverInfo.packageName) !=
- PackageManager.PERMISSION_GRANTED) {
- // Application doesn't hold the SCORE_NETWORKS permission, so the user never
- // approved it as a network scorer.
- continue;
- }
-
- // Optionally, this package may specify a configuration activity.
- String configurationActivityClassName = null;
- Intent intent = new Intent(NetworkScoreManager.ACTION_CUSTOM_ENABLE);
- intent.setPackage(receiverInfo.packageName);
- List<ResolveInfo> configActivities = pm.queryIntentActivities(intent, 0 /* flags */);
- if (configActivities != null && !configActivities.isEmpty()) {
- ActivityInfo activityInfo = configActivities.get(0).activityInfo;
- if (activityInfo != null) {
- configurationActivityClassName = activityInfo.name;
- }
- }
-
- // Find the scoring service class we can bind to, if any.
- String scoringServiceClassName = null;
- Intent serviceIntent = new Intent(NetworkScoreManager.ACTION_SCORE_NETWORKS);
- serviceIntent.setPackage(receiverInfo.packageName);
- ResolveInfo resolveServiceInfo = pm.resolveService(serviceIntent, 0 /* flags */);
- if (resolveServiceInfo != null && resolveServiceInfo.serviceInfo != null) {
- scoringServiceClassName = resolveServiceInfo.serviceInfo.name;
- }
-
- // NOTE: loadLabel will attempt to load the receiver's label and fall back to the
- // app label if none is present.
- scorers.add(new NetworkScorerAppData(receiverInfo.packageName,
- receiverInfo.applicationInfo.uid, receiverInfo.loadLabel(pm),
- configurationActivityClassName, scoringServiceClassName));
+ if (VERBOSE) {
+ Log.d(TAG, "Configured packages: " + TextUtils.join(", ", packageArray));
}
- return scorers;
+ List<String> packages = new ArrayList<>();
+ final PackageManager pm = mContext.getPackageManager();
+ for (String potentialPkg : packageArray) {
+ if (pm.checkPermission(permission.SCORE_NETWORKS, potentialPkg)
+ == PackageManager.PERMISSION_GRANTED) {
+ packages.add(potentialPkg);
+ } else {
+ if (DEBUG) {
+ Log.d(TAG, potentialPkg + " has not been granted " + permission.SCORE_NETWORKS
+ + ", skipping.");
+ }
+ }
+ }
+
+ return packages;
+ }
+
+ private ResolveInfo findRecommendationService(String packageName) {
+ final PackageManager pm = mContext.getPackageManager();
+ final int resolveFlags = 0;
+
+ final Intent serviceIntent = new Intent(NetworkScoreManager.ACTION_RECOMMEND_NETWORKS);
+ serviceIntent.setPackage(packageName);
+ final ResolveInfo resolveServiceInfo =
+ pm.resolveService(serviceIntent, resolveFlags);
+
+ if (VERBOSE) {
+ Log.d(TAG, "Resolved " + serviceIntent + " to " + resolveServiceInfo);
+ }
+
+ if (resolveServiceInfo != null && resolveServiceInfo.serviceInfo != null) {
+ return resolveServiceInfo;
+ }
+
+ if (VERBOSE) {
+ Log.v(TAG, packageName + " does not have a service for " + serviceIntent);
+ }
+ return null;
}
/**
@@ -182,10 +198,15 @@
* selected) or if the previously-set scorer is no longer a valid scorer app (e.g. because
* it was disabled or uninstalled).
*/
+ @Nullable
public NetworkScorerAppData getActiveScorer() {
- String scorerPackage = Settings.Global.getString(mContext.getContentResolver(),
- Settings.Global.NETWORK_SCORER_APP);
- return getScorer(scorerPackage);
+ if (isNetworkRecommendationsDisabled()) {
+ // If recommendations are disabled then there can't be an active scorer.
+ return null;
+ }
+
+ // Otherwise return the recommendation provider (which may be null).
+ return getNetworkRecommendationProviderData();
}
/**
@@ -195,33 +216,13 @@
*
* @param packageName the packageName of the new scorer to use. If null, scoring will be
* disabled. Otherwise, the scorer will only be set if it is a valid scorer application.
- * @return true if the scorer was changed, or false if the package is not a valid scorer.
+ * @return true if the scorer was changed, or false if the package is not a valid scorer or
+ * a valid network recommendation provider exists.
+ * @deprecated Scorers are now selected from a configured list.
*/
+ @Deprecated
public boolean setActiveScorer(String packageName) {
- String oldPackageName = Settings.Global.getString(mContext.getContentResolver(),
- Settings.Global.NETWORK_SCORER_APP);
- if (TextUtils.equals(oldPackageName, packageName)) {
- // No change.
- return true;
- }
-
- Log.i(TAG, "Changing network scorer from " + oldPackageName + " to " + packageName);
-
- if (packageName == null) {
- Settings.Global.putString(mContext.getContentResolver(),
- Settings.Global.NETWORK_SCORER_APP, null);
- return true;
- } else {
- // We only make the change if the new package is valid.
- if (getScorer(packageName) != null) {
- Settings.Global.putString(mContext.getContentResolver(),
- Settings.Global.NETWORK_SCORER_APP, packageName);
- return true;
- } else {
- Log.w(TAG, "Requested network scorer is not valid: " + packageName);
- return false;
- }
- }
+ return false;
}
/** Determine whether the application with the given UID is the enabled scorer. */
@@ -230,7 +231,7 @@
if (defaultApp == null) {
return false;
}
- if (callingUid != defaultApp.mPackageUid) {
+ if (callingUid != defaultApp.packageUid) {
return false;
}
// To be extra safe, ensure the caller holds the SCORE_NETWORKS permission. It always
@@ -239,17 +240,9 @@
PackageManager.PERMISSION_GRANTED;
}
- /** Returns the {@link NetworkScorerAppData} for the given app, or null if it's not a scorer. */
- public NetworkScorerAppData getScorer(String packageName) {
- if (TextUtils.isEmpty(packageName)) {
- return null;
- }
- Collection<NetworkScorerAppData> applications = getAllValidScorers();
- for (NetworkScorerAppData app : applications) {
- if (packageName.equals(app.mPackageName)) {
- return app;
- }
- }
- return null;
+ private boolean isNetworkRecommendationsDisabled() {
+ final ContentResolver cr = mContext.getContentResolver();
+ // A value of 1 indicates enabled.
+ return Settings.Global.getInt(cr, Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0) != 1;
}
}
diff --git a/core/java/android/net/NetworkStats.java b/core/java/android/net/NetworkStats.java
index 25806fa..77ce65b 100644
--- a/core/java/android/net/NetworkStats.java
+++ b/core/java/android/net/NetworkStats.java
@@ -68,11 +68,18 @@
// TODO: Rename TAG_NONE to TAG_ALL.
public static final int TAG_NONE = 0;
- /** {@link #set} value for all roaming values. */
+ /** {@link #metered} value to account for all metered states. */
+ public static final int METERED_ALL = -1;
+ /** {@link #metered} value where native, unmetered data is accounted. */
+ public static final int METERED_NO = 0;
+ /** {@link #metered} value where metered data is accounted. */
+ public static final int METERED_YES = 1;
+
+ /** {@link #roaming} value to account for all roaming states. */
public static final int ROAMING_ALL = -1;
- /** {@link #set} value where native, non-roaming data is accounted. */
+ /** {@link #roaming} value where native, non-roaming data is accounted. */
public static final int ROAMING_NO = 0;
- /** {@link #set} value where roaming data is accounted. */
+ /** {@link #roaming} value where roaming data is accounted. */
public static final int ROAMING_YES = 1;
// TODO: move fields to "mVariable" notation
@@ -88,6 +95,7 @@
private int[] uid;
private int[] set;
private int[] tag;
+ private int[] metered;
private int[] roaming;
private long[] rxBytes;
private long[] rxPackets;
@@ -105,6 +113,12 @@
* to disk. We merge in the correct value when reporting this value to clients of
* getSummary().
*/
+ public int metered;
+ /**
+ * Note that this is only populated w/ the default value when read from /proc or written
+ * to disk. We merge in the correct value when reporting this value to clients of
+ * getSummary().
+ */
public int roaming;
public long rxBytes;
public long rxPackets;
@@ -123,16 +137,17 @@
public Entry(String iface, int uid, int set, int tag, long rxBytes, long rxPackets,
long txBytes, long txPackets, long operations) {
- this(iface, uid, set, tag, ROAMING_NO, rxBytes, rxPackets, txBytes, txPackets,
- operations);
+ this(iface, uid, set, tag, METERED_NO, ROAMING_NO, rxBytes, rxPackets, txBytes,
+ txPackets, operations);
}
- public Entry(String iface, int uid, int set, int tag, int roaming, long rxBytes,
- long rxPackets, long txBytes, long txPackets, long operations) {
+ public Entry(String iface, int uid, int set, int tag, int metered, int roaming,
+ long rxBytes, long rxPackets, long txBytes, long txPackets, long operations) {
this.iface = iface;
this.uid = uid;
this.set = set;
this.tag = tag;
+ this.metered = metered;
this.roaming = roaming;
this.rxBytes = rxBytes;
this.rxPackets = rxPackets;
@@ -165,6 +180,7 @@
builder.append(" uid=").append(uid);
builder.append(" set=").append(setToString(set));
builder.append(" tag=").append(tagToString(tag));
+ builder.append(" metered=").append(meteredToString(metered));
builder.append(" roaming=").append(roamingToString(roaming));
builder.append(" rxBytes=").append(rxBytes);
builder.append(" rxPackets=").append(rxPackets);
@@ -178,13 +194,18 @@
public boolean equals(Object o) {
if (o instanceof Entry) {
final Entry e = (Entry) o;
- return uid == e.uid && set == e.set && tag == e.tag && roaming == e.roaming
- && rxBytes == e.rxBytes && rxPackets == e.rxPackets && txBytes == e.txBytes
- && txPackets == e.txPackets && operations == e.operations
- && iface.equals(e.iface);
+ return uid == e.uid && set == e.set && tag == e.tag && metered == e.metered
+ && roaming == e.roaming && rxBytes == e.rxBytes && rxPackets == e.rxPackets
+ && txBytes == e.txBytes && txPackets == e.txPackets
+ && operations == e.operations && iface.equals(e.iface);
}
return false;
}
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(uid, set, tag, metered, roaming, iface);
+ }
}
public NetworkStats(long elapsedRealtime, int initialSize) {
@@ -196,6 +217,7 @@
this.uid = new int[initialSize];
this.set = new int[initialSize];
this.tag = new int[initialSize];
+ this.metered = new int[initialSize];
this.roaming = new int[initialSize];
this.rxBytes = new long[initialSize];
this.rxPackets = new long[initialSize];
@@ -209,6 +231,7 @@
this.uid = EmptyArray.INT;
this.set = EmptyArray.INT;
this.tag = EmptyArray.INT;
+ this.metered = EmptyArray.INT;
this.roaming = EmptyArray.INT;
this.rxBytes = EmptyArray.LONG;
this.rxPackets = EmptyArray.LONG;
@@ -226,6 +249,7 @@
uid = parcel.createIntArray();
set = parcel.createIntArray();
tag = parcel.createIntArray();
+ metered = parcel.createIntArray();
roaming = parcel.createIntArray();
rxBytes = parcel.createLongArray();
rxPackets = parcel.createLongArray();
@@ -243,6 +267,7 @@
dest.writeIntArray(uid);
dest.writeIntArray(set);
dest.writeIntArray(tag);
+ dest.writeIntArray(metered);
dest.writeIntArray(roaming);
dest.writeLongArray(rxBytes);
dest.writeLongArray(rxPackets);
@@ -277,10 +302,11 @@
}
@VisibleForTesting
- public NetworkStats addValues(String iface, int uid, int set, int tag, int roaming,
+ public NetworkStats addValues(String iface, int uid, int set, int tag, int metered, int roaming,
long rxBytes, long rxPackets, long txBytes, long txPackets, long operations) {
return addValues(new Entry(
- iface, uid, set, tag, roaming, rxBytes, rxPackets, txBytes, txPackets, operations));
+ iface, uid, set, tag, metered, roaming, rxBytes, rxPackets, txBytes, txPackets,
+ operations));
}
/**
@@ -294,6 +320,7 @@
uid = Arrays.copyOf(uid, newLength);
set = Arrays.copyOf(set, newLength);
tag = Arrays.copyOf(tag, newLength);
+ metered = Arrays.copyOf(metered, newLength);
roaming = Arrays.copyOf(roaming, newLength);
rxBytes = Arrays.copyOf(rxBytes, newLength);
rxPackets = Arrays.copyOf(rxPackets, newLength);
@@ -307,6 +334,7 @@
uid[size] = entry.uid;
set[size] = entry.set;
tag[size] = entry.tag;
+ metered[size] = entry.metered;
roaming[size] = entry.roaming;
rxBytes[size] = entry.rxBytes;
rxPackets[size] = entry.rxPackets;
@@ -327,6 +355,7 @@
entry.uid = uid[i];
entry.set = set[i];
entry.tag = tag[i];
+ entry.metered = metered[i];
entry.roaming = roaming[i];
entry.rxBytes = rxBytes[i];
entry.rxPackets = rxPackets[i];
@@ -381,7 +410,8 @@
* also be used to subtract values from existing rows.
*/
public NetworkStats combineValues(Entry entry) {
- final int i = findIndex(entry.iface, entry.uid, entry.set, entry.tag, entry.roaming);
+ final int i = findIndex(entry.iface, entry.uid, entry.set, entry.tag, entry.metered,
+ entry.roaming);
if (i == -1) {
// only create new entry when positive contribution
addValues(entry);
@@ -409,10 +439,11 @@
/**
* Find first stats index that matches the requested parameters.
*/
- public int findIndex(String iface, int uid, int set, int tag, int roaming) {
+ public int findIndex(String iface, int uid, int set, int tag, int metered, int roaming) {
for (int i = 0; i < size; i++) {
if (uid == this.uid[i] && set == this.set[i] && tag == this.tag[i]
- && roaming == this.roaming[i] && Objects.equals(iface, this.iface[i])) {
+ && metered == this.metered[i] && roaming == this.roaming[i]
+ && Objects.equals(iface, this.iface[i])) {
return i;
}
}
@@ -424,7 +455,7 @@
* search around the hinted index as an optimization.
*/
@VisibleForTesting
- public int findIndexHinted(String iface, int uid, int set, int tag, int roaming,
+ public int findIndexHinted(String iface, int uid, int set, int tag, int metered, int roaming,
int hintIndex) {
for (int offset = 0; offset < size; offset++) {
final int halfOffset = offset / 2;
@@ -438,7 +469,8 @@
}
if (uid == this.uid[i] && set == this.set[i] && tag == this.tag[i]
- && roaming == this.roaming[i] && Objects.equals(iface, this.iface[i])) {
+ && metered == this.metered[i] && roaming == this.roaming[i]
+ && Objects.equals(iface, this.iface[i])) {
return i;
}
}
@@ -452,7 +484,7 @@
*/
public void spliceOperationsFrom(NetworkStats stats) {
for (int i = 0; i < size; i++) {
- final int j = stats.findIndex(iface[i], uid[i], set[i], tag[i], roaming[i]);
+ final int j = stats.findIndex(iface[i], uid[i], set[i], tag[i], metered[i], roaming[i]);
if (j == -1) {
operations[i] = 0;
} else {
@@ -542,6 +574,7 @@
entry.uid = limitUid;
entry.set = SET_ALL;
entry.tag = TAG_NONE;
+ entry.metered = METERED_ALL;
entry.roaming = ROAMING_ALL;
entry.rxBytes = 0;
entry.rxPackets = 0;
@@ -637,11 +670,12 @@
entry.uid = left.uid[i];
entry.set = left.set[i];
entry.tag = left.tag[i];
+ entry.metered = left.metered[i];
entry.roaming = left.roaming[i];
// find remote row that matches, and subtract
final int j = right.findIndexHinted(entry.iface, entry.uid, entry.set, entry.tag,
- entry.roaming, i);
+ entry.metered, entry.roaming, i);
if (j == -1) {
// newly appearing row, return entire value
entry.rxBytes = left.rxBytes[i];
@@ -687,6 +721,7 @@
entry.uid = UID_ALL;
entry.set = SET_ALL;
entry.tag = TAG_NONE;
+ entry.metered = METERED_ALL;
entry.roaming = ROAMING_ALL;
entry.operations = 0L;
@@ -716,6 +751,7 @@
entry.iface = IFACE_ALL;
entry.set = SET_ALL;
entry.tag = TAG_NONE;
+ entry.metered = METERED_ALL;
entry.roaming = ROAMING_ALL;
for (int i = 0; i < size; i++) {
@@ -762,6 +798,7 @@
pw.print(" uid="); pw.print(uid[i]);
pw.print(" set="); pw.print(setToString(set[i]));
pw.print(" tag="); pw.print(tagToString(tag[i]));
+ pw.print(" metered="); pw.print(meteredToString(metered[i]));
pw.print(" roaming="); pw.print(roamingToString(roaming[i]));
pw.print(" rxBytes="); pw.print(rxBytes[i]);
pw.print(" rxPackets="); pw.print(rxPackets[i]);
@@ -830,6 +867,22 @@
}
/**
+ * Return text description of {@link #metered} value.
+ */
+ public static String meteredToString(int metered) {
+ switch (metered) {
+ case METERED_ALL:
+ return "ALL";
+ case METERED_NO:
+ return "NO";
+ case METERED_YES:
+ return "YES";
+ default:
+ return "UNKNOWN";
+ }
+ }
+
+ /**
* Return text description of {@link #roaming} value.
*/
public static String roamingToString(int roaming) {
@@ -904,7 +957,8 @@
if (pool.isEmpty()) {
return true;
}
- Entry moved = addTrafficToApplications(tunIface, underlyingIface, tunIfaceTotal, pool);
+ Entry moved =
+ addTrafficToApplications(tunUid, tunIface, underlyingIface, tunIfaceTotal, pool);
deductTrafficFromVpnApp(tunUid, underlyingIface, moved);
if (!moved.isEmpty()) {
@@ -919,9 +973,9 @@
* Initializes the data used by the migrateTun() method.
*
* This is the first pass iteration which does the following work:
- * (1) Adds up all the traffic through tun0.
- * (2) Adds up all the traffic through the tunUid's underlyingIface
+ * (1) Adds up all the traffic through the tunUid's underlyingIface
* (both foreground and background).
+ * (2) Adds up all the traffic through tun0 excluding traffic from the vpn app itself.
*/
private void tunAdjustmentInit(int tunUid, String tunIface, String underlyingIface,
Entry tunIfaceTotal, Entry underlyingIfaceTotal) {
@@ -941,8 +995,9 @@
underlyingIfaceTotal.add(recycle);
}
- if (recycle.tag == TAG_NONE && Objects.equals(tunIface, recycle.iface)) {
- // Add up all tunIface traffic.
+ if (recycle.uid != tunUid && recycle.tag == TAG_NONE
+ && Objects.equals(tunIface, recycle.iface)) {
+ // Add up all tunIface traffic excluding traffic from the vpn app itself.
tunIfaceTotal.add(recycle);
}
}
@@ -958,13 +1013,15 @@
return pool;
}
- private Entry addTrafficToApplications(String tunIface, String underlyingIface,
+ private Entry addTrafficToApplications(int tunUid, String tunIface, String underlyingIface,
Entry tunIfaceTotal, Entry pool) {
Entry moved = new Entry();
Entry tmpEntry = new Entry();
tmpEntry.iface = underlyingIface;
for (int i = 0; i < size; i++) {
- if (Objects.equals(iface[i], tunIface)) {
+ // the vpn app is excluded from the redistribution but all moved traffic will be
+ // deducted from the vpn app (see deductTrafficFromVpnApp below).
+ if (Objects.equals(iface[i], tunIface) && uid[i] != tunUid) {
if (tunIfaceTotal.rxBytes > 0) {
tmpEntry.rxBytes = pool.rxBytes * rxBytes[i] / tunIfaceTotal.rxBytes;
} else {
@@ -994,6 +1051,7 @@
tmpEntry.uid = uid[i];
tmpEntry.tag = tag[i];
tmpEntry.set = set[i];
+ tmpEntry.metered = metered[i];
tmpEntry.roaming = roaming[i];
combineValues(tmpEntry);
if (tag[i] == TAG_NONE) {
@@ -1013,24 +1071,25 @@
moved.set = SET_DBG_VPN_OUT;
moved.tag = TAG_NONE;
moved.iface = underlyingIface;
+ moved.metered = METERED_ALL;
moved.roaming = ROAMING_ALL;
combineValues(moved);
// Caveat: if the vpn software uses tag, the total tagged traffic may be greater than
// the TAG_NONE traffic.
//
- // Relies on the fact that the underlying traffic only has state ROAMING_NO, which
- // should be the case as it comes directly from the /proc file. We only blend in the
+ // Relies on the fact that the underlying traffic only has state ROAMING_NO and METERED_NO,
+ // which should be the case as it comes directly from the /proc file. We only blend in the
// roaming data after applying these adjustments, by checking the NetworkIdentity of the
// underlying iface.
int idxVpnBackground = findIndex(underlyingIface, tunUid, SET_DEFAULT, TAG_NONE,
- ROAMING_NO);
+ METERED_NO, ROAMING_NO);
if (idxVpnBackground != -1) {
tunSubtract(idxVpnBackground, this, moved);
}
int idxVpnForeground = findIndex(underlyingIface, tunUid, SET_FOREGROUND, TAG_NONE,
- ROAMING_NO);
+ METERED_NO, ROAMING_NO);
if (idxVpnForeground != -1) {
tunSubtract(idxVpnForeground, this, moved);
}
diff --git a/core/java/android/net/NetworkUtils.java b/core/java/android/net/NetworkUtils.java
index 35e3065..a677d73 100644
--- a/core/java/android/net/NetworkUtils.java
+++ b/core/java/android/net/NetworkUtils.java
@@ -52,6 +52,17 @@
public native static void attachRaFilter(FileDescriptor fd, int packetType) throws SocketException;
/**
+ * Attaches a socket filter that accepts L2-L4 signaling traffic required for IP connectivity.
+ *
+ * This includes: all ARP, ICMPv6 RS/RA/NS/NA messages, and DHCPv4 exchanges.
+ *
+ * @param fd the socket's {@link FileDescriptor}.
+ * @param packetType the hardware address type, one of ARPHRD_*.
+ */
+ public native static void attachControlPacketFilter(FileDescriptor fd, int packetType)
+ throws SocketException;
+
+ /**
* Configures a socket for receiving ICMPv6 router solicitations and sending advertisements.
* @param fd the socket's {@link FileDescriptor}.
* @param ifIndex the interface index.
diff --git a/core/java/android/net/RecommendationRequest.java b/core/java/android/net/RecommendationRequest.java
index 05ca1aa..a96f90d 100644
--- a/core/java/android/net/RecommendationRequest.java
+++ b/core/java/android/net/RecommendationRequest.java
@@ -105,7 +105,16 @@
}
protected RecommendationRequest(Parcel in) {
- mScanResults = (ScanResult[]) in.readParcelableArray(ScanResult.class.getClassLoader());
+ final int resultCount = in.readInt();
+ if (resultCount > 0) {
+ mScanResults = new ScanResult[resultCount];
+ for (int i = 0; i < resultCount; i++) {
+ mScanResults[i] = in.readParcelable(ScanResult.class.getClassLoader());
+ }
+ } else {
+ mScanResults = null;
+ }
+
mCurrentSelectedConfig = in.readParcelable(WifiConfiguration.class.getClassLoader());
mRequiredCapabilities = in.readParcelable(NetworkCapabilities.class.getClassLoader());
}
@@ -117,7 +126,14 @@
@Override
public void writeToParcel(Parcel dest, int flags) {
- dest.writeParcelableArray(mScanResults, flags);
+ if (mScanResults != null) {
+ dest.writeInt(mScanResults.length);
+ for (int i = 0; i < mScanResults.length; i++) {
+ dest.writeParcelable(mScanResults[i], flags);
+ }
+ } else {
+ dest.writeInt(0);
+ }
dest.writeParcelable(mCurrentSelectedConfig, flags);
dest.writeParcelable(mRequiredCapabilities, flags);
}
diff --git a/core/java/android/net/RecommendationResult.java b/core/java/android/net/RecommendationResult.java
index a330d84..70cf09c 100644
--- a/core/java/android/net/RecommendationResult.java
+++ b/core/java/android/net/RecommendationResult.java
@@ -16,6 +16,7 @@
package android.net;
+import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.net.wifi.WifiConfiguration;
@@ -23,6 +24,7 @@
import android.os.Parcelable;
import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.util.Preconditions;
/**
* The result of a network recommendation.
@@ -34,7 +36,32 @@
public final class RecommendationResult implements Parcelable {
private final WifiConfiguration mWifiConfiguration;
- public RecommendationResult(@Nullable WifiConfiguration wifiConfiguration) {
+ /**
+ * Create a {@link RecommendationResult} that indicates that no network connection should be
+ * attempted at this time.
+ *
+ * @return a {@link RecommendationResult}
+ */
+ public static RecommendationResult createDoNotConnectRecommendation() {
+ return new RecommendationResult((WifiConfiguration) null);
+ }
+
+ /**
+ * Create a {@link RecommendationResult} that indicates that a connection attempt should be
+ * made for the given Wi-Fi network.
+ *
+ * @param wifiConfiguration {@link WifiConfiguration} with at least SSID and BSSID set.
+ * @return a {@link RecommendationResult}
+ */
+ public static RecommendationResult createConnectRecommendation(
+ @NonNull WifiConfiguration wifiConfiguration) {
+ Preconditions.checkNotNull(wifiConfiguration, "wifiConfiguration must not be null");
+ Preconditions.checkNotNull(wifiConfiguration.SSID, "SSID must not be null");
+ Preconditions.checkNotNull(wifiConfiguration.BSSID, "BSSID must not be null");
+ return new RecommendationResult(wifiConfiguration);
+ }
+
+ private RecommendationResult(@Nullable WifiConfiguration wifiConfiguration) {
mWifiConfiguration = wifiConfiguration;
}
@@ -43,14 +70,29 @@
}
/**
- * @return The recommended {@link WifiConfiguration} to connect to. A {@code null} value
- * indicates that no WiFi connection should be attempted at this time.
+ * @return {@code true} if a network recommendation exists. {@code false} indicates that
+ * no connection should be attempted at this time.
*/
- public WifiConfiguration getWifiConfiguration() {
+ public boolean hasRecommendation() {
+ return mWifiConfiguration != null;
+ }
+
+ /**
+ * @return The recommended {@link WifiConfiguration} to connect to. A {@code null} value
+ * is returned if {@link #hasRecommendation} returns {@code false}.
+ */
+ @Nullable public WifiConfiguration getWifiConfiguration() {
return mWifiConfiguration;
}
@Override
+ public String toString() {
+ return "RecommendationResult{" +
+ "mWifiConfiguration=" + mWifiConfiguration +
+ "}";
+ }
+
+ @Override
public int describeContents() {
return 0;
}
diff --git a/core/java/android/net/ScoredNetwork.java b/core/java/android/net/ScoredNetwork.java
index 0f3f957..94e5187 100644
--- a/core/java/android/net/ScoredNetwork.java
+++ b/core/java/android/net/ScoredNetwork.java
@@ -16,11 +16,14 @@
package android.net;
+import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
+import java.lang.Math;
+import java.lang.UnsupportedOperationException;
import java.util.Objects;
/**
@@ -43,7 +46,17 @@
* <p>
* If no value is associated with this key then it's unknown.
*/
- public static final String EXTRA_HAS_CAPTIVE_PORTAL = "android.net.extra.HAS_CAPTIVE_PORTAL";
+ public static final String ATTRIBUTES_KEY_HAS_CAPTIVE_PORTAL =
+ "android.net.attributes.key.HAS_CAPTIVE_PORTAL";
+
+ /**
+ * Key used with the {@link #attributes} bundle to define the rankingScoreOffset int value.
+ *
+ * <p>The rankingScoreOffset is used when calculating the ranking score used to rank networks
+ * against one another. See {@link #calculateRankingScore} for more information.
+ */
+ public static final String ATTRIBUTES_KEY_RANKING_SCORE_OFFSET =
+ "android.net.attributes.key.RANKING_SCORE_OFFSET";
/** A {@link NetworkKey} uniquely identifying this network. */
public final NetworkKey networkKey;
@@ -71,8 +84,10 @@
* An additional collection of optional attributes set by
* the Network Recommendation Provider.
*
- * @see #EXTRA_HAS_CAPTIVE_PORTAL
+ * @see #ATTRIBUTES_KEY_HAS_CAPTIVE_PORTAL
+ * @see #ATTRIBUTES_KEY_RANKING_SCORE_OFFSET_KEY
*/
+ @Nullable
public final Bundle attributes;
/**
@@ -104,7 +119,7 @@
* metered.
*/
public ScoredNetwork(NetworkKey networkKey, RssiCurve rssiCurve, boolean meteredHint) {
- this(networkKey, rssiCurve, false /* meteredHint */, null /* attributes */);
+ this(networkKey, rssiCurve, meteredHint, null /* attributes */);
}
/**
@@ -122,7 +137,7 @@
* @param attributes optional provider specific attributes
*/
public ScoredNetwork(NetworkKey networkKey, RssiCurve rssiCurve, boolean meteredHint,
- Bundle attributes) {
+ @Nullable Bundle attributes) {
this.networkKey = networkKey;
this.rssiCurve = rssiCurve;
this.meteredHint = meteredHint;
@@ -136,7 +151,7 @@
} else {
rssiCurve = null;
}
- meteredHint = in.readByte() != 0;
+ meteredHint = (in.readByte() == 1);
attributes = in.readBundle();
}
@@ -156,7 +171,6 @@
}
out.writeByte((byte) (meteredHint ? 1 : 0));
out.writeBundle(attributes);
-
}
@Override
@@ -187,6 +201,54 @@
'}';
}
+ /**
+ * Returns true if a ranking score can be calculated for this network.
+ *
+ * @hide
+ */
+ public boolean hasRankingScore() {
+ return (rssiCurve != null)
+ || (attributes != null
+ && attributes.containsKey(ATTRIBUTES_KEY_RANKING_SCORE_OFFSET));
+ }
+
+ /**
+ * Returns a ranking score for a given RSSI which can be used to comparatively
+ * rank networks.
+ *
+ * <p>The score obtained by the rssiCurve is bitshifted left by 8 bits to expand it to an
+ * integer and then the offset is added. If the addition operation overflows or underflows,
+ * Integer.MAX_VALUE and Integer.MIN_VALUE will be returned respectively.
+ *
+ * <p>{@link #hasRankingScore} should be called first to ensure this network is capable
+ * of returning a ranking score.
+ *
+ * @throws UnsupportedOperationException if there is no RssiCurve and no rankingScoreOffset
+ * for this network (hasRankingScore returns false).
+ *
+ * @hide
+ */
+ public int calculateRankingScore(int rssi) throws UnsupportedOperationException {
+ if (!hasRankingScore()) {
+ throw new UnsupportedOperationException(
+ "Either rssiCurve or rankingScoreOffset is required to calculate the "
+ + "ranking score");
+ }
+
+ int offset = 0;
+ if (attributes != null) {
+ offset += attributes.getInt(ATTRIBUTES_KEY_RANKING_SCORE_OFFSET, 0 /* default */);
+ }
+
+ int score = (rssiCurve == null) ? 0 : rssiCurve.lookupScore(rssi) << Byte.SIZE;
+
+ try {
+ return Math.addExact(score, offset);
+ } catch (ArithmeticException e) {
+ return (score < 0) ? Integer.MIN_VALUE : Integer.MAX_VALUE;
+ }
+ }
+
public static final Parcelable.Creator<ScoredNetwork> CREATOR =
new Parcelable.Creator<ScoredNetwork>() {
@Override
diff --git a/core/java/android/net/SntpClient.java b/core/java/android/net/SntpClient.java
index cf9243f..cea56b5 100644
--- a/core/java/android/net/SntpClient.java
+++ b/core/java/android/net/SntpClient.java
@@ -36,8 +36,7 @@
* }
* </pre>
*/
-public class SntpClient
-{
+public class SntpClient {
private static final String TAG = "SntpClient";
private static final boolean DBG = true;
@@ -88,6 +87,7 @@
try {
address = InetAddress.getByName(host);
} catch (Exception e) {
+ EventLogTags.writeNtpFailure(host, e.toString());
if (DBG) Log.d(TAG, "request time failed: " + e);
return false;
}
@@ -142,6 +142,7 @@
// = (transit + skew - transit + skew)/2
// = (2 * skew)/2 = skew
long clockOffset = ((receiveTime - originateTime) + (transmitTime - responseTime))/2;
+ EventLogTags.writeNtpSuccess(address.toString(), roundTripTime, clockOffset);
if (DBG) {
Log.d(TAG, "round trip: " + roundTripTime + "ms, " +
"clock offset: " + clockOffset + "ms");
@@ -153,6 +154,7 @@
mNtpTimeReference = responseTicks;
mRoundTripTime = roundTripTime;
} catch (Exception e) {
+ EventLogTags.writeNtpFailure(address.toString(), e.toString());
if (DBG) Log.d(TAG, "request time failed: " + e);
return false;
} finally {
diff --git a/core/java/android/net/metrics/NetworkEvent.java b/core/java/android/net/metrics/NetworkEvent.java
index 3b3fa69..0667495 100644
--- a/core/java/android/net/metrics/NetworkEvent.java
+++ b/core/java/android/net/metrics/NetworkEvent.java
@@ -42,6 +42,15 @@
public static final int NETWORK_DISCONNECTED = 7;
/** {@hide} */
+ public static final int NETWORK_FIRST_VALIDATION_SUCCESS = 8;
+ /** {@hide} */
+ public static final int NETWORK_REVALIDATION_SUCCESS = 9;
+ /** {@hide} */
+ public static final int NETWORK_FIRST_VALIDATION_PORTAL_FOUND = 10;
+ /** {@hide} */
+ public static final int NETWORK_REVALIDATION_PORTAL_FOUND = 11;
+
+ /** {@hide} */
@IntDef(value = {
NETWORK_CONNECTED,
NETWORK_VALIDATED,
@@ -50,6 +59,10 @@
NETWORK_LINGER,
NETWORK_UNLINGER,
NETWORK_DISCONNECTED,
+ NETWORK_FIRST_VALIDATION_SUCCESS,
+ NETWORK_REVALIDATION_SUCCESS,
+ NETWORK_FIRST_VALIDATION_PORTAL_FOUND,
+ NETWORK_REVALIDATION_PORTAL_FOUND,
})
@Retention(RetentionPolicy.SOURCE)
public @interface EventType {}
diff --git a/core/java/android/net/metrics/ValidationProbeEvent.java b/core/java/android/net/metrics/ValidationProbeEvent.java
index 1a31b56..a724ec1 100644
--- a/core/java/android/net/metrics/ValidationProbeEvent.java
+++ b/core/java/android/net/metrics/ValidationProbeEvent.java
@@ -44,10 +44,8 @@
public static final int DNS_FAILURE = 0;
public static final int DNS_SUCCESS = 1;
- /** {@hide} */
- @IntDef(value = {PROBE_DNS, PROBE_HTTP, PROBE_HTTPS, PROBE_PAC})
- @Retention(RetentionPolicy.SOURCE)
- public @interface ProbeType {}
+ private static final int FIRST_VALIDATION = 1 << 8;
+ private static final int REVALIDATION = 2 << 8;
/** {@hide} */
@IntDef(value = {DNS_FAILURE, DNS_SUCCESS})
@@ -56,12 +54,17 @@
public final int netId;
public final long durationMs;
- public final @ProbeType int probeType;
+ // probeType byte format (MSB to LSB):
+ // byte 0: unused
+ // byte 1: unused
+ // byte 2: 0 = UNKNOWN, 1 = FIRST_VALIDATION, 2 = REVALIDATION
+ // byte 3: PROBE_* constant
+ public final int probeType;
public final @ReturnCode int returnCode;
/** {@hide} */
public ValidationProbeEvent(
- int netId, long durationMs, @ProbeType int probeType, @ReturnCode int returnCode) {
+ int netId, long durationMs, int probeType, @ReturnCode int returnCode) {
this.netId = netId;
this.durationMs = durationMs;
this.probeType = probeType;
@@ -100,8 +103,18 @@
};
/** @hide */
+ public static int makeProbeType(int probeType, boolean firstValidation) {
+ return (probeType & 0xff) | (firstValidation ? FIRST_VALIDATION : REVALIDATION);
+ }
+
+ /** @hide */
public static String getProbeName(int probeType) {
- return Decoder.constants.get(probeType, "PROBE_???");
+ return Decoder.constants.get(probeType & 0xff, "PROBE_???");
+ }
+
+ /** @hide */
+ public static String getValidationStage(int probeType) {
+ return Decoder.constants.get(probeType & 0xff00, "UNKNOWN");
}
public static void logEvent(int netId, long durationMs, int probeType, int returnCode) {
@@ -109,12 +122,13 @@
@Override
public String toString() {
- return String.format("ValidationProbeEvent(%d, %s:%d, %dms)",
- netId, getProbeName(probeType), returnCode, durationMs);
+ return String.format("ValidationProbeEvent(%d, %s:%d %s, %dms)", netId,
+ getProbeName(probeType), returnCode, getValidationStage(probeType), durationMs);
}
final static class Decoder {
static final SparseArray<String> constants = MessageUtils.findMessageNames(
- new Class[]{ValidationProbeEvent.class}, new String[]{"PROBE_"});
+ new Class[]{ValidationProbeEvent.class},
+ new String[]{"PROBE_", "FIRST_", "REVALIDATION"});
}
}
diff --git a/core/java/android/net/nsd/NsdManager.java b/core/java/android/net/nsd/NsdManager.java
index 86bd502..33d12a3 100644
--- a/core/java/android/net/nsd/NsdManager.java
+++ b/core/java/android/net/nsd/NsdManager.java
@@ -103,11 +103,11 @@
* to {@link DiscoveryListener#onServiceFound} and a service lost is notified on
* {@link DiscoveryListener#onServiceLost}.
*
- * <p> Once the peer application discovers the "Example" http srevice, and needs to receive data
- * from the "Example" application, it can initiate a resolve with {@link #resolveService} to
- * resolve the host and port details for the purpose of establishing a connection. A successful
- * resolve is notified on {@link ResolveListener#onServiceResolved} and a failure is notified
- * on {@link ResolveListener#onResolveFailed}.
+ * <p> Once the peer application discovers the "Example" http service, and either needs to read the
+ * attributes of the service or wants to receive data from the "Example" application, it can
+ * initiate a resolve with {@link #resolveService} to resolve the attributes, host, and port
+ * details. A successful resolve is notified on {@link ResolveListener#onServiceResolved} and a
+ * failure is notified on {@link ResolveListener#onResolveFailed}.
*
* Applications can reserve for a service type at
* http://www.iana.org/form/ports-service. Existing services can be found at
diff --git a/core/java/android/net/nsd/NsdServiceInfo.java b/core/java/android/net/nsd/NsdServiceInfo.java
index 4a06fb1..7b845be 100644
--- a/core/java/android/net/nsd/NsdServiceInfo.java
+++ b/core/java/android/net/nsd/NsdServiceInfo.java
@@ -250,7 +250,8 @@
}
/**
- * Retrive attributes as a map of String keys to byte[] values.
+ * Retrieve attributes as a map of String keys to byte[] values. The attributes map is only
+ * valid for a resolved service.
*
* <p> The returned map is unmodifiable; changes must be made through {@link #setAttribute} and
* {@link #removeAttribute}.
diff --git a/core/java/android/os/HwRemoteBinder.java b/core/java/android/os/HwRemoteBinder.java
index 83866b3c..e617e0a 100644
--- a/core/java/android/os/HwRemoteBinder.java
+++ b/core/java/android/os/HwRemoteBinder.java
@@ -39,6 +39,9 @@
public native final void transact(
int code, HwParcel request, HwParcel reply, int flags);
+ public native boolean linkToDeath(DeathRecipient recipient, long cookie);
+ public native boolean unlinkToDeath(DeathRecipient recipient);
+
private static native final long native_init();
private native final void native_setup_empty();
@@ -52,5 +55,9 @@
128 /* size */);
}
+ private static final void sendDeathNotice(DeathRecipient recipient, long cookie) {
+ recipient.serviceDied(cookie);
+ }
+
private long mNativeContext;
}
diff --git a/core/java/android/os/IHwBinder.java b/core/java/android/os/IHwBinder.java
index 76e881e..f93bfd7 100644
--- a/core/java/android/os/IHwBinder.java
+++ b/core/java/android/os/IHwBinder.java
@@ -26,4 +26,16 @@
int code, HwParcel request, HwParcel reply, int flags);
public IHwInterface queryLocalInterface(String descriptor);
+
+ /**
+ * Interface for receiving a callback when the process hosting a service
+ * has gone away.
+ */
+ public interface DeathRecipient {
+ public void serviceDied(long cookie);
+ }
+
+ public boolean linkToDeath(DeathRecipient recipient, long cookie);
+
+ public boolean unlinkToDeath(DeathRecipient recipient);
}
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index 4eee854..9cd1a42 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -398,6 +398,10 @@
* make easily identifyable processes even if you are using the same base
* <var>processClass</var> to start them.
*
+ * When invokeWith is not null, the process will be started as a fresh app
+ * and not a zygote fork. Note that this is only allowed for uid 0 or when
+ * debugFlags contains DEBUG_ENABLE_DEBUGGER.
+ *
* @param processClass The class to use as the process's main entry
* point.
* @param niceName A more readable name to use for the process.
@@ -410,6 +414,7 @@
* @param abi non-null the ABI this app should be started with.
* @param instructionSet null-ok the instruction set to use.
* @param appDataDir null-ok the data directory of the app.
+ * @param invokeWith null-ok the command to invoke with.
* @param zygoteArgs Additional arguments to supply to the zygote process.
*
* @return An object that describes the result of the attempt to start the process.
@@ -426,10 +431,11 @@
String abi,
String instructionSet,
String appDataDir,
+ String invokeWith,
String[] zygoteArgs) {
return zygoteProcess.start(processClass, niceName, uid, gid, gids,
debugFlags, mountExternal, targetSdkVersion, seInfo,
- abi, instructionSet, appDataDir, zygoteArgs);
+ abi, instructionSet, appDataDir, invokeWith, zygoteArgs);
}
/** @hide */
@@ -442,10 +448,11 @@
String abi,
String instructionSet,
String appDataDir,
+ String invokeWith,
String[] zygoteArgs) {
return WebViewZygote.getProcess().start(processClass, niceName, uid, gid, gids,
debugFlags, mountExternal, targetSdkVersion, seInfo,
- abi, instructionSet, appDataDir, zygoteArgs);
+ abi, instructionSet, appDataDir, invokeWith, zygoteArgs);
}
/**
diff --git a/core/java/android/os/ServiceSpecificException.java b/core/java/android/os/ServiceSpecificException.java
index 04fca19..3e0f6da 100644
--- a/core/java/android/os/ServiceSpecificException.java
+++ b/core/java/android/os/ServiceSpecificException.java
@@ -39,4 +39,9 @@
public ServiceSpecificException(int errorCode) {
this.errorCode = errorCode;
}
+
+ @Override
+ public String toString() {
+ return super.toString() + " (code " + errorCode + ")";
+ }
}
diff --git a/core/java/android/os/Trace.java b/core/java/android/os/Trace.java
index 3ae28fd..2225296 100644
--- a/core/java/android/os/Trace.java
+++ b/core/java/android/os/Trace.java
@@ -83,6 +83,8 @@
public static final long TRACE_TAG_DATABASE = 1L << 20;
/** @hide */
public static final long TRACE_TAG_NETWORK = 1L << 21;
+ /** @hide */
+ public static final long TRACE_TAG_ADB = 1L << 22;
private static final long TRACE_TAG_NOT_READY = 1L << 63;
private static final int MAX_SECTION_NAME_LEN = 127;
diff --git a/core/java/android/os/ZygoteProcess.java b/core/java/android/os/ZygoteProcess.java
index c45fe5a..5ac33a1 100644
--- a/core/java/android/os/ZygoteProcess.java
+++ b/core/java/android/os/ZygoteProcess.java
@@ -170,6 +170,10 @@
* make easily identifyable processes even if you are using the same base
* <var>processClass</var> to start them.
*
+ * When invokeWith is not null, the process will be started as a fresh app
+ * and not a zygote fork. Note that this is only allowed for uid 0 or when
+ * debugFlags contains DEBUG_ENABLE_DEBUGGER.
+ *
* @param processClass The class to use as the process's main entry
* point.
* @param niceName A more readable name to use for the process.
@@ -182,6 +186,7 @@
* @param abi non-null the ABI this app should be started with.
* @param instructionSet null-ok the instruction set to use.
* @param appDataDir null-ok the data directory of the app.
+ * @param invokeWith null-ok the command to invoke with.
* @param zygoteArgs Additional arguments to supply to the zygote process.
*
* @return An object that describes the result of the attempt to start the process.
@@ -196,11 +201,12 @@
String abi,
String instructionSet,
String appDataDir,
+ String invokeWith,
String[] zygoteArgs) {
try {
return startViaZygote(processClass, niceName, uid, gid, gids,
debugFlags, mountExternal, targetSdkVersion, seInfo,
- abi, instructionSet, appDataDir, zygoteArgs);
+ abi, instructionSet, appDataDir, invokeWith, zygoteArgs);
} catch (ZygoteStartFailedEx ex) {
Log.e(LOG_TAG,
"Starting VM process through Zygote failed");
@@ -330,6 +336,7 @@
String abi,
String instructionSet,
String appDataDir,
+ String invokeWith,
String[] extraArgs)
throws ZygoteStartFailedEx {
ArrayList<String> argsForZygote = new ArrayList<String>();
@@ -407,6 +414,11 @@
argsForZygote.add("--app-data-dir=" + appDataDir);
}
+ if (invokeWith != null) {
+ argsForZygote.add("--invoke-with");
+ argsForZygote.add(invokeWith);
+ }
+
argsForZygote.add(processClass);
if (extraArgs != null) {
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index db7baac..e52983e 100755
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -7172,6 +7172,13 @@
*/
public static final String MOBILE_DATA_ALWAYS_ON = "mobile_data_always_on";
+ /**
+ * Size of the event buffer for IP connectivity metrics.
+ * @hide
+ */
+ public static final String CONNECTIVITY_METRICS_BUFFER_SIZE =
+ "connectivity_metrics_buffer_size";
+
/** {@hide} */
public static final String NETSTATS_ENABLED = "netstats_enabled";
/** {@hide} */
diff --git a/core/java/android/util/apk/ApkSignatureSchemeV2Verifier.java b/core/java/android/util/apk/ApkSignatureSchemeV2Verifier.java
index 78d3b7b..0216a07 100644
--- a/core/java/android/util/apk/ApkSignatureSchemeV2Verifier.java
+++ b/core/java/android/util/apk/ApkSignatureSchemeV2Verifier.java
@@ -579,7 +579,7 @@
throws SignatureNotFoundException {
// Look up the offset of ZIP Central Directory.
long centralDirOffset = ZipUtils.getZipEocdCentralDirectoryOffset(eocd);
- if (centralDirOffset >= eocdOffset) {
+ if (centralDirOffset > eocdOffset) {
throw new SignatureNotFoundException(
"ZIP Central Directory offset out of range: " + centralDirOffset
+ ". ZIP End of Central Directory offset: " + eocdOffset);
diff --git a/core/java/android/util/apk/ZipUtils.java b/core/java/android/util/apk/ZipUtils.java
index cdbac18..fa5477e 100644
--- a/core/java/android/util/apk/ZipUtils.java
+++ b/core/java/android/util/apk/ZipUtils.java
@@ -160,7 +160,7 @@
}
int maxCommentLength = Math.min(archiveSize - ZIP_EOCD_REC_MIN_SIZE, UINT16_MAX_VALUE);
int eocdWithEmptyCommentStartPosition = archiveSize - ZIP_EOCD_REC_MIN_SIZE;
- for (int expectedCommentLength = 0; expectedCommentLength < maxCommentLength;
+ for (int expectedCommentLength = 0; expectedCommentLength <= maxCommentLength;
expectedCommentLength++) {
int eocdStartPos = eocdWithEmptyCommentStartPosition - expectedCommentLength;
if (zipContents.getInt(eocdStartPos) == ZIP_EOCD_REC_SIG) {
diff --git a/core/java/com/android/internal/content/NativeLibraryHelper.java b/core/java/com/android/internal/content/NativeLibraryHelper.java
index f479f4f..83b7d2f 100644
--- a/core/java/com/android/internal/content/NativeLibraryHelper.java
+++ b/core/java/com/android/internal/content/NativeLibraryHelper.java
@@ -76,6 +76,7 @@
final long[] apkHandles;
final boolean multiArch;
final boolean extractNativeLibs;
+ final boolean debuggable;
public static Handle create(File packageFile) throws IOException {
try {
@@ -89,15 +90,17 @@
public static Handle create(Package pkg) throws IOException {
return create(pkg.getAllCodePaths(),
(pkg.applicationInfo.flags & ApplicationInfo.FLAG_MULTIARCH) != 0,
- (pkg.applicationInfo.flags & ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS) != 0);
+ (pkg.applicationInfo.flags & ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS) != 0,
+ (pkg.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0);
}
public static Handle create(PackageLite lite) throws IOException {
- return create(lite.getAllCodePaths(), lite.multiArch, lite.extractNativeLibs);
+ return create(lite.getAllCodePaths(), lite.multiArch, lite.extractNativeLibs,
+ lite.debuggable);
}
private static Handle create(List<String> codePaths, boolean multiArch,
- boolean extractNativeLibs) throws IOException {
+ boolean extractNativeLibs, boolean debuggable) throws IOException {
final int size = codePaths.size();
final long[] apkHandles = new long[size];
for (int i = 0; i < size; i++) {
@@ -112,13 +115,15 @@
}
}
- return new Handle(apkHandles, multiArch, extractNativeLibs);
+ return new Handle(apkHandles, multiArch, extractNativeLibs, debuggable);
}
- Handle(long[] apkHandles, boolean multiArch, boolean extractNativeLibs) {
+ Handle(long[] apkHandles, boolean multiArch, boolean extractNativeLibs,
+ boolean debuggable) {
this.apkHandles = apkHandles;
this.multiArch = multiArch;
this.extractNativeLibs = extractNativeLibs;
+ this.debuggable = debuggable;
mGuard.open("close");
}
@@ -149,15 +154,17 @@
private static native long nativeOpenApk(String path);
private static native void nativeClose(long handle);
- private static native long nativeSumNativeBinaries(long handle, String cpuAbi);
+ private static native long nativeSumNativeBinaries(long handle, String cpuAbi,
+ boolean debuggable);
private native static int nativeCopyNativeBinaries(long handle, String sharedLibraryPath,
- String abiToCopy, boolean extractNativeLibs, boolean hasNativeBridge);
+ String abiToCopy, boolean extractNativeLibs, boolean hasNativeBridge,
+ boolean debuggable);
private static long sumNativeBinaries(Handle handle, String abi) {
long sum = 0;
for (long apkHandle : handle.apkHandles) {
- sum += nativeSumNativeBinaries(apkHandle, abi);
+ sum += nativeSumNativeBinaries(apkHandle, abi, handle.debuggable);
}
return sum;
}
@@ -173,7 +180,7 @@
public static int copyNativeBinaries(Handle handle, File sharedLibraryDir, String abi) {
for (long apkHandle : handle.apkHandles) {
int res = nativeCopyNativeBinaries(apkHandle, sharedLibraryDir.getPath(), abi,
- handle.extractNativeLibs, HAS_NATIVE_BRIDGE);
+ handle.extractNativeLibs, HAS_NATIVE_BRIDGE, handle.debuggable);
if (res != INSTALL_SUCCEEDED) {
return res;
}
@@ -191,7 +198,7 @@
public static int findSupportedAbi(Handle handle, String[] supportedAbis) {
int finalRes = NO_NATIVE_LIBRARIES;
for (long apkHandle : handle.apkHandles) {
- final int res = nativeFindSupportedAbi(apkHandle, supportedAbis);
+ final int res = nativeFindSupportedAbi(apkHandle, supportedAbis, handle.debuggable);
if (res == NO_NATIVE_LIBRARIES) {
// No native code, keep looking through all APKs.
} else if (res == INSTALL_FAILED_NO_MATCHING_ABIS) {
@@ -213,7 +220,8 @@
return finalRes;
}
- private native static int nativeFindSupportedAbi(long handle, String[] supportedAbis);
+ private native static int nativeFindSupportedAbi(long handle, String[] supportedAbis,
+ boolean debuggable);
// Convenience method to call removeNativeBinariesFromDirLI(File)
public static void removeNativeBinariesLI(String nativeLibraryPath) {
diff --git a/core/java/com/android/internal/os/InstallerConnection.java b/core/java/com/android/internal/os/InstallerConnection.java
deleted file mode 100644
index 419c3d8..0000000
--- a/core/java/com/android/internal/os/InstallerConnection.java
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * Copyright (C) 2008 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.internal.os;
-
-import android.net.LocalSocket;
-import android.net.LocalSocketAddress;
-import android.os.SystemClock;
-import android.text.TextUtils;
-import android.util.Slog;
-
-import com.android.internal.util.Preconditions;
-
-import libcore.io.IoUtils;
-import libcore.io.Streams;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Arrays;
-
-/**
- * Represents a connection to {@code installd}. Allows multiple connect and
- * disconnect cycles.
- *
- * @hide for internal use only
- */
-public class InstallerConnection {
- private static final String TAG = "InstallerConnection";
- private static final boolean LOCAL_DEBUG = false;
-
- private InputStream mIn;
- private OutputStream mOut;
- private LocalSocket mSocket;
-
- private volatile Object mWarnIfHeld;
-
- private final byte buf[] = new byte[1024];
-
- public InstallerConnection() {
- }
-
- /**
- * Yell loudly if someone tries making future calls while holding a lock on
- * the given object.
- */
- public void setWarnIfHeld(Object warnIfHeld) {
- Preconditions.checkState(mWarnIfHeld == null);
- mWarnIfHeld = Preconditions.checkNotNull(warnIfHeld);
- }
-
- public synchronized String transact(String cmd) {
- if (mWarnIfHeld != null && Thread.holdsLock(mWarnIfHeld)) {
- Slog.wtf(TAG, "Calling thread " + Thread.currentThread().getName() + " is holding 0x"
- + Integer.toHexString(System.identityHashCode(mWarnIfHeld)), new Throwable());
- }
-
- if (!connect()) {
- Slog.e(TAG, "connection failed");
- return "-1";
- }
-
- if (!writeCommand(cmd)) {
- /*
- * If installd died and restarted in the background (unlikely but
- * possible) we'll fail on the next write (this one). Try to
- * reconnect and write the command one more time before giving up.
- */
- Slog.e(TAG, "write command failed? reconnect!");
- if (!connect() || !writeCommand(cmd)) {
- return "-1";
- }
- }
- if (LOCAL_DEBUG) {
- Slog.i(TAG, "send: '" + cmd + "'");
- }
-
- final int replyLength = readReply();
- if (replyLength > 0) {
- String s = new String(buf, 0, replyLength);
- if (LOCAL_DEBUG) {
- Slog.i(TAG, "recv: '" + s + "'");
- }
- return s;
- } else {
- if (LOCAL_DEBUG) {
- Slog.i(TAG, "fail");
- }
- return "-1";
- }
- }
-
- public String[] execute(String cmd, Object... args) throws InstallerException {
- final StringBuilder builder = new StringBuilder(cmd);
- for (Object arg : args) {
- String escaped;
- if (arg == null) {
- escaped = "";
- } else {
- escaped = String.valueOf(arg);
- }
- if (escaped.indexOf('\0') != -1 || escaped.indexOf(' ') != -1 || "!".equals(escaped)) {
- throw new InstallerException(
- "Invalid argument while executing " + cmd + " " + Arrays.toString(args));
- }
- if (TextUtils.isEmpty(escaped)) {
- escaped = "!";
- }
- builder.append(' ').append(escaped);
- }
- final String[] resRaw = transact(builder.toString()).split(" ");
- int res = -1;
- try {
- res = Integer.parseInt(resRaw[0]);
- } catch (ArrayIndexOutOfBoundsException | NumberFormatException ignored) {
- }
- if (res != 0) {
- throw new InstallerException(
- "Failed to execute " + cmd + " " + Arrays.toString(args) + ": " + res);
- }
- return resRaw;
- }
-
- public void dexopt(String apkPath, int uid, String instructionSet, int dexoptNeeded,
- int dexFlags, String compilerFilter, String volumeUuid, String sharedLibraries)
- throws InstallerException {
- dexopt(apkPath, uid, "*", instructionSet, dexoptNeeded, null /*outputPath*/, dexFlags,
- compilerFilter, volumeUuid, sharedLibraries);
- }
-
- public void dexopt(String apkPath, int uid, String pkgName, String instructionSet,
- int dexoptNeeded, String outputPath, int dexFlags, String compilerFilter,
- String volumeUuid, String sharedLibraries) throws InstallerException {
- execute("dexopt",
- apkPath,
- uid,
- pkgName,
- instructionSet,
- dexoptNeeded,
- outputPath,
- dexFlags,
- compilerFilter,
- volumeUuid,
- sharedLibraries);
- }
-
- private boolean safeParseBooleanResult(String[] res) throws InstallerException {
- if ((res == null) || (res.length != 2)) {
- throw new InstallerException("Invalid size result: " + Arrays.toString(res));
- }
-
- // Just as a sanity check. Anything != "true" will be interpreted as false by parseBoolean.
- if (!res[1].equals("true") && !res[1].equals("false")) {
- throw new InstallerException("Invalid boolean result: " + Arrays.toString(res));
- }
-
- return Boolean.parseBoolean(res[1]);
- }
-
- public boolean mergeProfiles(int uid, String pkgName) throws InstallerException {
- final String[] res = execute("merge_profiles", uid, pkgName);
-
- return safeParseBooleanResult(res);
- }
-
- public boolean dumpProfiles(String gid, String packageName, String codePaths)
- throws InstallerException {
- final String[] res = execute("dump_profiles", gid, packageName, codePaths);
-
- return safeParseBooleanResult(res);
- }
-
- private boolean connect() {
- if (mSocket != null) {
- return true;
- }
- Slog.i(TAG, "connecting...");
- try {
- mSocket = new LocalSocket();
-
- LocalSocketAddress address = new LocalSocketAddress("installd",
- LocalSocketAddress.Namespace.RESERVED);
-
- mSocket.connect(address);
-
- mIn = mSocket.getInputStream();
- mOut = mSocket.getOutputStream();
- } catch (IOException ex) {
- disconnect();
- return false;
- }
- return true;
- }
-
- public void disconnect() {
- Slog.i(TAG, "disconnecting...");
- IoUtils.closeQuietly(mSocket);
- IoUtils.closeQuietly(mIn);
- IoUtils.closeQuietly(mOut);
-
- mSocket = null;
- mIn = null;
- mOut = null;
- }
-
-
- private boolean readFully(byte[] buffer, int len) {
- try {
- Streams.readFully(mIn, buffer, 0, len);
- } catch (IOException ioe) {
- Slog.e(TAG, "read exception");
- disconnect();
- return false;
- }
-
- if (LOCAL_DEBUG) {
- Slog.i(TAG, "read " + len + " bytes");
- }
-
- return true;
- }
-
- private int readReply() {
- if (!readFully(buf, 2)) {
- return -1;
- }
-
- final int len = (((int) buf[0]) & 0xff) | ((((int) buf[1]) & 0xff) << 8);
- if ((len < 1) || (len > buf.length)) {
- Slog.e(TAG, "invalid reply length (" + len + ")");
- disconnect();
- return -1;
- }
-
- if (!readFully(buf, len)) {
- return -1;
- }
-
- return len;
- }
-
- private boolean writeCommand(String cmdString) {
- final byte[] cmd = cmdString.getBytes();
- final int len = cmd.length;
- if ((len < 1) || (len > buf.length)) {
- return false;
- }
-
- buf[0] = (byte) (len & 0xff);
- buf[1] = (byte) ((len >> 8) & 0xff);
- try {
- mOut.write(buf, 0, 2);
- mOut.write(cmd, 0, len);
- } catch (IOException ex) {
- Slog.e(TAG, "write error");
- disconnect();
- return false;
- }
- return true;
- }
-
- public void waitForConnection() {
- for (;;) {
- try {
- execute("ping");
- return;
- } catch (InstallerException ignored) {
- }
- Slog.w(TAG, "installd not ready");
- SystemClock.sleep(1000);
- }
- }
-
- public static class InstallerException extends Exception {
- public InstallerException(String detailMessage) {
- super(detailMessage);
- }
- }
-}
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index 66b294d..44c6e85 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -697,9 +697,11 @@
throws ZygoteSecurityException {
int peerUid = peer.getUid();
- if (args.invokeWith != null && peerUid != 0) {
- throw new ZygoteSecurityException("Peer is not permitted to specify "
- + "an explicit invoke-with wrapper command");
+ if (args.invokeWith != null && peerUid != 0 &&
+ (args.debugFlags & Zygote.DEBUG_ENABLE_DEBUGGER) == 0) {
+ throw new ZygoteSecurityException("Peer is permitted to specify an"
+ + "explicit invoke-with wrapper command only for debuggable"
+ + "applications.");
}
}
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index e1118d8..ef5231c 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -26,11 +26,16 @@
import android.icu.util.ULocale;
import android.net.LocalServerSocket;
import android.opengl.EGL14;
+import android.os.IInstalld;
import android.os.Process;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.ServiceSpecificException;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.Trace;
import android.os.ZygoteProcess;
+import android.os.storage.StorageManager;
import android.security.keystore.AndroidKeyStoreProvider;
import android.system.ErrnoException;
import android.system.Os;
@@ -41,7 +46,6 @@
import android.webkit.WebViewFactory;
import android.widget.TextView;
-import com.android.internal.os.InstallerConnection.InstallerException;
import dalvik.system.DexFile;
import dalvik.system.PathClassLoader;
@@ -492,54 +496,55 @@
*/
private static void performSystemServerDexOpt(String classPath) {
final String[] classPathElements = classPath.split(":");
- final InstallerConnection installer = new InstallerConnection();
- installer.waitForConnection();
+ final IInstalld installd = IInstalld.Stub
+ .asInterface(ServiceManager.getService("installd"));
final String instructionSet = VMRuntime.getRuntime().vmInstructionSet();
- try {
- String sharedLibraries = "";
- for (String classPathElement : classPathElements) {
- // System server is fully AOTed and never profiled
- // for profile guided compilation.
- // TODO: Make this configurable between INTERPRET_ONLY, SPEED, SPACE and EVERYTHING?
+ String sharedLibraries = "";
+ for (String classPathElement : classPathElements) {
+ // System server is fully AOTed and never profiled
+ // for profile guided compilation.
+ // TODO: Make this configurable between INTERPRET_ONLY, SPEED, SPACE and EVERYTHING?
- int dexoptNeeded;
- try {
- dexoptNeeded = DexFile.getDexOptNeeded(
- classPathElement, instructionSet, "speed",
- false /* newProfile */);
- } catch (FileNotFoundException ignored) {
- // Do not add to the classpath.
- Log.w(TAG, "Missing classpath element for system server: " + classPathElement);
- continue;
- } catch (IOException e) {
- // Not fully clear what to do here as we don't know the cause of the
- // IO exception. Add to the classpath to be conservative, but don't
- // attempt to compile it.
- Log.w(TAG, "Error checking classpath element for system server: "
- + classPathElement, e);
- dexoptNeeded = DexFile.NO_DEXOPT_NEEDED;
- }
-
- if (dexoptNeeded != DexFile.NO_DEXOPT_NEEDED) {
- try {
- installer.dexopt(classPathElement, Process.SYSTEM_UID, instructionSet,
- dexoptNeeded, 0 /*dexFlags*/, "speed", null /*volumeUuid*/,
- sharedLibraries);
- } catch (InstallerException e) {
- // Ignore (but log), we need this on the classpath for fallback mode.
- Log.w(TAG, "Failed compiling classpath element for system server: "
- + classPathElement, e);
- }
- }
-
- if (!sharedLibraries.isEmpty()) {
- sharedLibraries += ":";
- }
- sharedLibraries += classPathElement;
+ int dexoptNeeded;
+ try {
+ dexoptNeeded = DexFile.getDexOptNeeded(
+ classPathElement, instructionSet, "speed",
+ false /* newProfile */);
+ } catch (FileNotFoundException ignored) {
+ // Do not add to the classpath.
+ Log.w(TAG, "Missing classpath element for system server: " + classPathElement);
+ continue;
+ } catch (IOException e) {
+ // Not fully clear what to do here as we don't know the cause of the
+ // IO exception. Add to the classpath to be conservative, but don't
+ // attempt to compile it.
+ Log.w(TAG, "Error checking classpath element for system server: "
+ + classPathElement, e);
+ dexoptNeeded = DexFile.NO_DEXOPT_NEEDED;
}
- } finally {
- installer.disconnect();
+
+ if (dexoptNeeded != DexFile.NO_DEXOPT_NEEDED) {
+ final String packageName = "*";
+ final String outputPath = null;
+ final int dexFlags = 0;
+ final String compilerFilter = "speed";
+ final String uuid = StorageManager.UUID_PRIVATE_INTERNAL;
+ try {
+ installd.dexopt(classPathElement, Process.SYSTEM_UID, packageName,
+ instructionSet, dexoptNeeded, outputPath, dexFlags, compilerFilter,
+ uuid, sharedLibraries);
+ } catch (RemoteException | ServiceSpecificException e) {
+ // Ignore (but log), we need this on the classpath for fallback mode.
+ Log.w(TAG, "Failed compiling classpath element for system server: "
+ + classPathElement, e);
+ }
+ }
+
+ if (!sharedLibraries.isEmpty()) {
+ sharedLibraries += ":";
+ }
+ sharedLibraries += classPathElement;
}
}
diff --git a/core/java/com/android/internal/util/TokenBucket.java b/core/java/com/android/internal/util/TokenBucket.java
new file mode 100644
index 0000000..effb82b
--- /dev/null
+++ b/core/java/com/android/internal/util/TokenBucket.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2016 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.internal.util;
+
+import android.os.SystemClock;
+
+import static com.android.internal.util.Preconditions.checkArgumentNonnegative;
+import static com.android.internal.util.Preconditions.checkArgumentPositive;
+
+/**
+ * A class useful for rate-limiting or throttling that stores and distributes tokens.
+ *
+ * A TokenBucket starts with a fixed capacity of tokens, an initial amount of tokens, and
+ * a fixed filling period (in milliseconds).
+ *
+ * For every filling period, the bucket gains one token, up to its maximum capacity from
+ * which point tokens simply overflow and are lost. Tokens can be obtained one by one or n by n.
+ *
+ * The available amount of tokens is computed lazily when the bucket state is inspected.
+ * Therefore it is purely synchronous and does not involve any asynchronous activity.
+ * It is not synchronized in any way and not a thread-safe object.
+ */
+public class TokenBucket {
+
+ private final int mFillDelta; // Time in ms it takes to generate one token.
+ private final int mCapacity; // Maximum number of tokens that can be stored.
+ private long mLastFill; // Last time in ms the bucket generated tokens.
+ private int mAvailable; // Current number of available tokens.
+
+ /**
+ * Create a new TokenBucket.
+ * @param deltaMs the time in milliseconds it takes to generate a new token.
+ * Must be strictly positive.
+ * @param capacity the maximum token capacity. Must be strictly positive.
+ * @param tokens the starting amount of token. Must be positive or zero.
+ */
+ public TokenBucket(int deltaMs, int capacity, int tokens) {
+ mFillDelta = checkArgumentPositive(deltaMs, "deltaMs must be strictly positive");
+ mCapacity = checkArgumentPositive(capacity, "capacity must be strictly positive");
+ mAvailable = Math.min(checkArgumentNonnegative(tokens), mCapacity);
+ mLastFill = scaledTime();
+ }
+
+ /**
+ * Create a new TokenBucket that starts completely filled.
+ * @param deltaMs the time in milliseconds it takes to generate a new token.
+ * Must be strictly positive.
+ * @param capacity the maximum token capacity. Must be strictly positive.
+ */
+ public TokenBucket(int deltaMs, int capacity) {
+ this(deltaMs, capacity, capacity);
+ }
+
+ /** Reset this TokenBucket and set its number of available tokens. */
+ public void reset(int tokens) {
+ checkArgumentNonnegative(tokens);
+ mAvailable = Math.min(tokens, mCapacity);
+ mLastFill = scaledTime();
+ }
+
+ /** Returns this TokenBucket maximum token capacity. */
+ public int capacity() {
+ return mCapacity;
+ }
+
+ /** Returns this TokenBucket currently number of available tokens. */
+ public int available() {
+ fill();
+ return mAvailable;
+ }
+
+ /** Returns true if this TokenBucket as one or more tokens available. */
+ public boolean has() {
+ fill();
+ return mAvailable > 0;
+ }
+
+ /** Consumes a token from this TokenBucket and returns true if a token is available. */
+ public boolean get() {
+ return (get(1) == 1);
+ }
+
+ /**
+ * Try to consume many tokens from this TokenBucket.
+ * @param n the number of tokens to consume.
+ * @return the number of tokens that were actually consumed.
+ */
+ public int get(int n) {
+ fill();
+ if (n <= 0) {
+ return 0;
+ }
+ if (n > mAvailable) {
+ int got = mAvailable;
+ mAvailable = 0;
+ return got;
+ }
+ mAvailable -= n;
+ return n;
+ }
+
+ private void fill() {
+ final long now = scaledTime();
+ final int diff = (int) (now - mLastFill);
+ mAvailable = Math.min(mCapacity, mAvailable + diff);
+ mLastFill = now;
+ }
+
+ private long scaledTime() {
+ return SystemClock.elapsedRealtime() / mFillDelta;
+ }
+}
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index 9a596c6..70e9004 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -20,10 +20,6 @@
LOCAL_CFLAGS += -DENABLE_CPUSETS
endif
-ifneq ($(ENABLE_SCHED_BOOST),)
- LOCAL_CFLAGS += -DENABLE_SCHED_BOOST
-endif
-
LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
LOCAL_CFLAGS += -DU_USING_ICU_NAMESPACE=0
@@ -185,6 +181,7 @@
hwbinder/EphemeralStorage.cpp \
LOCAL_C_INCLUDES += \
+ $(LOCAL_PATH)/include \
$(JNI_H_INCLUDE) \
$(LOCAL_PATH)/android/graphics \
$(LOCAL_PATH)/../../libs/hwui \
@@ -279,8 +276,10 @@
# <bionic_tls.h> in com_google_android_gles_jni_GLImpl.cpp
LOCAL_C_INCLUDES += bionic/libc/private
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
+
# AndroidRuntime.h depends on nativehelper/jni.h
-LOCAL_EXPORT_C_INCLUDE_DIRS := libnativehelper/include
+LOCAL_EXPORT_C_INCLUDE_DIRS += libnativehelper/include
LOCAL_MODULE:= libandroid_runtime
diff --git a/core/jni/android_net_LocalSocketImpl.cpp b/core/jni/android_net_LocalSocketImpl.cpp
index d6d4310..37b6df1 100644
--- a/core/jni/android_net_LocalSocketImpl.cpp
+++ b/core/jni/android_net_LocalSocketImpl.cpp
@@ -202,9 +202,7 @@
msg.msg_control = cmsgbuf;
msg.msg_controllen = sizeof(cmsgbuf);
- do {
- ret = recvmsg(fd, &msg, MSG_NOSIGNAL);
- } while (ret < 0 && errno == EINTR);
+ ret = TEMP_FAILURE_RETRY(recvmsg(fd, &msg, MSG_NOSIGNAL | MSG_CMSG_CLOEXEC));
if (ret < 0 && errno == EPIPE) {
// Treat this as an end of stream
diff --git a/core/jni/android_net_NetUtils.cpp b/core/jni/android_net_NetUtils.cpp
index 26a2cf0..3e99521 100644
--- a/core/jni/android_net_NetUtils.cpp
+++ b/core/jni/android_net_NetUtils.cpp
@@ -44,28 +44,33 @@
namespace android {
+static const uint32_t kEtherTypeOffset = offsetof(ether_header, ether_type);
+static const uint32_t kEtherHeaderLen = sizeof(ether_header);
+static const uint32_t kIPv4Protocol = kEtherHeaderLen + offsetof(iphdr, protocol);
+static const uint32_t kIPv4FlagsOffset = kEtherHeaderLen + offsetof(iphdr, frag_off);
+static const uint32_t kIPv6NextHeader = kEtherHeaderLen + offsetof(ip6_hdr, ip6_nxt);
+static const uint32_t kIPv6PayloadStart = kEtherHeaderLen + sizeof(ip6_hdr);
+static const uint32_t kICMPv6TypeOffset = kIPv6PayloadStart + offsetof(icmp6_hdr, icmp6_type);
+static const uint32_t kUDPSrcPortIndirectOffset = kEtherHeaderLen + offsetof(udphdr, source);
+static const uint32_t kUDPDstPortIndirectOffset = kEtherHeaderLen + offsetof(udphdr, dest);
static const uint16_t kDhcpClientPort = 68;
static void android_net_utils_attachDhcpFilter(JNIEnv *env, jobject clazz, jobject javaFd)
{
- uint32_t ip_offset = sizeof(ether_header);
- uint32_t proto_offset = ip_offset + offsetof(iphdr, protocol);
- uint32_t flags_offset = ip_offset + offsetof(iphdr, frag_off);
- uint32_t dport_indirect_offset = ip_offset + offsetof(udphdr, dest);
struct sock_filter filter_code[] = {
// Check the protocol is UDP.
- BPF_STMT(BPF_LD | BPF_B | BPF_ABS, proto_offset),
+ BPF_STMT(BPF_LD | BPF_B | BPF_ABS, kIPv4Protocol),
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, IPPROTO_UDP, 0, 6),
// Check this is not a fragment.
- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, flags_offset),
- BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 4, 0),
+ BPF_STMT(BPF_LD | BPF_H | BPF_ABS, kIPv4FlagsOffset),
+ BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, IP_OFFMASK, 4, 0),
// Get the IP header length.
- BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, ip_offset),
+ BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, kEtherHeaderLen),
// Check the destination port.
- BPF_STMT(BPF_LD | BPF_H | BPF_IND, dport_indirect_offset),
+ BPF_STMT(BPF_LD | BPF_H | BPF_IND, kUDPDstPortIndirectOffset),
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, kDhcpClientPort, 0, 1),
// Accept or reject.
@@ -93,17 +98,13 @@
return;
}
- uint32_t ipv6_offset = sizeof(ether_header);
- uint32_t ipv6_next_header_offset = ipv6_offset + offsetof(ip6_hdr, ip6_nxt);
- uint32_t icmp6_offset = ipv6_offset + sizeof(ip6_hdr);
- uint32_t icmp6_type_offset = icmp6_offset + offsetof(icmp6_hdr, icmp6_type);
struct sock_filter filter_code[] = {
// Check IPv6 Next Header is ICMPv6.
- BPF_STMT(BPF_LD | BPF_B | BPF_ABS, ipv6_next_header_offset),
+ BPF_STMT(BPF_LD | BPF_B | BPF_ABS, kIPv6NextHeader),
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, IPPROTO_ICMPV6, 0, 3),
// Check ICMPv6 type is Router Advertisement.
- BPF_STMT(BPF_LD | BPF_B | BPF_ABS, icmp6_type_offset),
+ BPF_STMT(BPF_LD | BPF_B | BPF_ABS, kICMPv6TypeOffset),
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, ND_ROUTER_ADVERT, 0, 1),
// Accept or reject.
@@ -122,6 +123,81 @@
}
}
+// TODO: Move all this filter code into libnetutils.
+static void android_net_utils_attachControlPacketFilter(
+ JNIEnv *env, jobject clazz, jobject javaFd, jint hardwareAddressType) {
+ if (hardwareAddressType != ARPHRD_ETHER) {
+ jniThrowExceptionFmt(env, "java/net/SocketException",
+ "attachControlPacketFilter only supports ARPHRD_ETHER");
+ return;
+ }
+
+ // Capture all:
+ // - ARPs
+ // - DHCPv4 packets
+ // - Router Advertisements & Solicitations
+ // - Neighbor Advertisements & Solicitations
+ //
+ // tcpdump:
+ // arp or
+ // '(ip and udp port 68)' or
+ // '(icmp6 and ip6[40] >= 133 and ip6[40] <= 136)'
+ struct sock_filter filter_code[] = {
+ // Load the link layer next payload field.
+ BPF_STMT(BPF_LD | BPF_H | BPF_ABS, kEtherTypeOffset),
+
+ // Accept all ARP.
+ // TODO: Figure out how to better filter ARPs on noisy networks.
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, ETHERTYPE_ARP, 16, 0),
+
+ // If IPv4:
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, ETHERTYPE_IP, 0, 9),
+
+ // Check the protocol is UDP.
+ BPF_STMT(BPF_LD | BPF_B | BPF_ABS, kIPv4Protocol),
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, IPPROTO_UDP, 0, 14),
+
+ // Check this is not a fragment.
+ BPF_STMT(BPF_LD | BPF_H | BPF_ABS, kIPv4FlagsOffset),
+ BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, IP_OFFMASK, 12, 0),
+
+ // Get the IP header length.
+ BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, kEtherHeaderLen),
+
+ // Check the source port.
+ BPF_STMT(BPF_LD | BPF_H | BPF_IND, kUDPSrcPortIndirectOffset),
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, kDhcpClientPort, 8, 0),
+
+ // Check the destination port.
+ BPF_STMT(BPF_LD | BPF_H | BPF_IND, kUDPDstPortIndirectOffset),
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, kDhcpClientPort, 6, 7),
+
+ // IPv6 ...
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, ETHERTYPE_IPV6, 0, 6),
+ // ... check IPv6 Next Header is ICMPv6 (ignore fragments), ...
+ BPF_STMT(BPF_LD | BPF_B | BPF_ABS, kIPv6NextHeader),
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, IPPROTO_ICMPV6, 0, 4),
+ // ... and check the ICMPv6 type is one of RS/RA/NS/NA.
+ BPF_STMT(BPF_LD | BPF_B | BPF_ABS, kICMPv6TypeOffset),
+ BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, ND_ROUTER_SOLICIT, 0, 2),
+ BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, ND_NEIGHBOR_ADVERT, 1, 0),
+
+ // Accept or reject.
+ BPF_STMT(BPF_RET | BPF_K, 0xffff),
+ BPF_STMT(BPF_RET | BPF_K, 0)
+ };
+ struct sock_fprog filter = {
+ sizeof(filter_code) / sizeof(filter_code[0]),
+ filter_code,
+ };
+
+ int fd = jniGetFDFromFileDescriptor(env, javaFd);
+ if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter, sizeof(filter)) != 0) {
+ jniThrowExceptionFmt(env, "java/net/SocketException",
+ "setsockopt(SO_ATTACH_FILTER): %s", strerror(errno));
+ }
+}
+
static void android_net_utils_setupRaSocket(JNIEnv *env, jobject clazz, jobject javaFd,
jint ifIndex)
{
@@ -263,6 +339,7 @@
{ "queryUserAccess", "(II)Z", (void*)android_net_utils_queryUserAccess },
{ "attachDhcpFilter", "(Ljava/io/FileDescriptor;)V", (void*) android_net_utils_attachDhcpFilter },
{ "attachRaFilter", "(Ljava/io/FileDescriptor;I)V", (void*) android_net_utils_attachRaFilter },
+ { "attachControlPacketFilter", "(Ljava/io/FileDescriptor;I)V", (void*) android_net_utils_attachControlPacketFilter },
{ "setupRaSocket", "(Ljava/io/FileDescriptor;I)V", (void*) android_net_utils_setupRaSocket },
};
diff --git a/core/jni/android_os_HwBinder.cpp b/core/jni/android_os_HwBinder.cpp
index 740b24d..95e031b 100644
--- a/core/jni/android_os_HwBinder.cpp
+++ b/core/jni/android_os_HwBinder.cpp
@@ -26,10 +26,11 @@
#include <JNIHelp.h>
#include <android/hidl/manager/1.0/IServiceManager.h>
#include <android/hidl/base/1.0/IBase.h>
-#include <android/hidl/base/1.0/IHwBase.h>
+#include <android/hidl/base/1.0/BpBase.h>
#include <android_runtime/AndroidRuntime.h>
#include <hidl/ServiceManagement.h>
#include <hidl/Status.h>
+#include <hidl/HidlTransportSupport.h>
#include <hwbinder/ProcessState.h>
#include <nativehelper/ScopedLocalRef.h>
@@ -242,14 +243,18 @@
sp<hardware::IBinder> binder = JHwBinder::GetNativeContext(env, thiz);
- sp<hidl::base::V1_0::IBase> base = hidl::base::V1_0::IHwBase::asInterface(binder);
- if (base.get() == nullptr) {
- LOG(ERROR) << "IBinder object cannot be casted to the base interface.";
+ /* TODO(b/33440494) this is not right */
+ sp<hidl::base::V1_0::IBase> base = new hidl::base::V1_0::BpBase(binder);
+
+ auto manager = hardware::defaultServiceManager();
+
+ if (manager == nullptr) {
+ LOG(ERROR) << "Could not get hwservicemanager.";
signalExceptionForError(env, UNKNOWN_ERROR);
return;
}
- bool ok = hardware::defaultServiceManager()->add(
+ bool ok = manager->add(
interfaceChain,
serviceName,
base);
@@ -294,13 +299,21 @@
<< serviceName
<< "'";
+ auto manager = hardware::defaultServiceManager();
+
+ if (manager == nullptr) {
+ LOG(ERROR) << "Could not get hwservicemanager.";
+ signalExceptionForError(env, UNKNOWN_ERROR);
+ return NULL;
+ }
+
sp<hardware::IBinder> service;
- hardware::defaultServiceManager()->get(
+ manager->get(
ifaceName,
serviceName,
[&service](sp<hidl::base::V1_0::IBase> out) {
service = hardware::toBinder<
- hidl::base::V1_0::IBase, hidl::base::V1_0::IHwBase
+ hidl::base::V1_0::IBase, hidl::base::V1_0::BpBase
>(out);
});
diff --git a/core/jni/android_os_HwRemoteBinder.cpp b/core/jni/android_os_HwRemoteBinder.cpp
index 1d5d6d5..0a7d84d 100644
--- a/core/jni/android_os_HwRemoteBinder.cpp
+++ b/core/jni/android_os_HwRemoteBinder.cpp
@@ -25,6 +25,7 @@
#include <JNIHelp.h>
#include <android_runtime/AndroidRuntime.h>
#include <hidl/Status.h>
+#include <ScopedUtfChars.h>
#include <nativehelper/ScopedLocalRef.h>
#include "core_jni_helpers.h"
@@ -38,26 +39,196 @@
namespace android {
static struct fields_t {
+ jclass proxy_class;
jfieldID contextID;
jmethodID constructID;
+ jmethodID sendDeathNotice;
+} gProxyOffsets;
-} gFields;
+static struct class_offsets_t
+{
+ jmethodID mGetName;
+} gClassOffsets;
+
+static JavaVM* jnienv_to_javavm(JNIEnv* env)
+{
+ JavaVM* vm;
+ return env->GetJavaVM(&vm) >= 0 ? vm : NULL;
+}
+
+static JNIEnv* javavm_to_jnienv(JavaVM* vm)
+{
+ JNIEnv* env;
+ return vm->GetEnv((void **)&env, JNI_VERSION_1_4) >= 0 ? env : NULL;
+}
+
+// ----------------------------------------------------------------------------
+class HwBinderDeathRecipient : public hardware::IBinder::DeathRecipient
+{
+public:
+ HwBinderDeathRecipient(JNIEnv* env, jobject object, jlong cookie, const sp<HwBinderDeathRecipientList>& list)
+ : mVM(jnienv_to_javavm(env)), mObject(env->NewGlobalRef(object)),
+ mObjectWeak(NULL), mCookie(cookie), mList(list)
+ {
+ // These objects manage their own lifetimes so are responsible for final bookkeeping.
+ // The list holds a strong reference to this object.
+ list->add(this);
+ }
+
+ void binderDied(const wp<hardware::IBinder>& who)
+ {
+ if (mObject != NULL) {
+ JNIEnv* env = javavm_to_jnienv(mVM);
+
+ env->CallStaticVoidMethod(gProxyOffsets.proxy_class, gProxyOffsets.sendDeathNotice, mObject, mCookie);
+ if (env->ExceptionCheck()) {
+ ALOGE("Uncaught exception returned from death notification.");
+ env->ExceptionClear();
+ }
+
+ // Serialize with our containing HwBinderDeathRecipientList so that we can't
+ // delete the global ref on mObject while the list is being iterated.
+ sp<HwBinderDeathRecipientList> list = mList.promote();
+ if (list != NULL) {
+ AutoMutex _l(list->lock());
+
+ // Demote from strong ref to weak after binderDied() has been delivered,
+ // to allow the DeathRecipient and BinderProxy to be GC'd if no longer needed.
+ mObjectWeak = env->NewWeakGlobalRef(mObject);
+ env->DeleteGlobalRef(mObject);
+ mObject = NULL;
+ }
+ }
+ }
+
+ void clearReference()
+ {
+ sp<HwBinderDeathRecipientList> list = mList.promote();
+ if (list != NULL) {
+ list->remove(this);
+ } else {
+ ALOGE("clearReference() on JDR %p but DRL wp purged", this);
+ }
+ }
+
+ bool matches(jobject obj) {
+ bool result;
+ JNIEnv* env = javavm_to_jnienv(mVM);
+
+ if (mObject != NULL) {
+ result = env->IsSameObject(obj, mObject);
+ } else {
+ jobject me = env->NewLocalRef(mObjectWeak);
+ result = env->IsSameObject(obj, me);
+ env->DeleteLocalRef(me);
+ }
+ return result;
+ }
+
+ void warnIfStillLive() {
+ if (mObject != NULL) {
+ // Okay, something is wrong -- we have a hard reference to a live death
+ // recipient on the VM side, but the list is being torn down.
+ JNIEnv* env = javavm_to_jnienv(mVM);
+ ScopedLocalRef<jclass> objClassRef(env, env->GetObjectClass(mObject));
+ ScopedLocalRef<jstring> nameRef(env,
+ (jstring) env->CallObjectMethod(objClassRef.get(), gClassOffsets.mGetName));
+ ScopedUtfChars nameUtf(env, nameRef.get());
+ if (nameUtf.c_str() != NULL) {
+ ALOGW("BinderProxy is being destroyed but the application did not call "
+ "unlinkToDeath to unlink all of its death recipients beforehand. "
+ "Releasing leaked death recipient: %s", nameUtf.c_str());
+ } else {
+ ALOGW("BinderProxy being destroyed; unable to get DR object name");
+ env->ExceptionClear();
+ }
+ }
+ }
+
+protected:
+ virtual ~HwBinderDeathRecipient()
+ {
+ JNIEnv* env = javavm_to_jnienv(mVM);
+ if (mObject != NULL) {
+ env->DeleteGlobalRef(mObject);
+ } else {
+ env->DeleteWeakGlobalRef(mObjectWeak);
+ }
+ }
+
+private:
+ JavaVM* const mVM;
+ jobject mObject;
+ jweak mObjectWeak; // will be a weak ref to the same VM-side DeathRecipient after binderDied()
+ jlong mCookie;
+ wp<HwBinderDeathRecipientList> mList;
+};
+// ----------------------------------------------------------------------------
+
+HwBinderDeathRecipientList::HwBinderDeathRecipientList() {
+}
+
+HwBinderDeathRecipientList::~HwBinderDeathRecipientList() {
+ AutoMutex _l(mLock);
+
+ for (const sp<HwBinderDeathRecipient>& deathRecipient : mList) {
+ deathRecipient->warnIfStillLive();
+ }
+}
+
+void HwBinderDeathRecipientList::add(const sp<HwBinderDeathRecipient>& recipient) {
+ AutoMutex _l(mLock);
+
+ mList.push_back(recipient);
+}
+
+void HwBinderDeathRecipientList::remove(const sp<HwBinderDeathRecipient>& recipient) {
+ AutoMutex _l(mLock);
+
+ List< sp<HwBinderDeathRecipient> >::iterator iter;
+ for (iter = mList.begin(); iter != mList.end(); iter++) {
+ if (*iter == recipient) {
+ mList.erase(iter);
+ return;
+ }
+ }
+}
+
+sp<HwBinderDeathRecipient> HwBinderDeathRecipientList::find(jobject recipient) {
+ AutoMutex _l(mLock);
+
+ for (const sp<HwBinderDeathRecipient>& deathRecipient : mList) {
+ if (deathRecipient->matches(recipient)) {
+ return deathRecipient;
+ }
+ }
+ return NULL;
+}
+
+Mutex& HwBinderDeathRecipientList::lock() {
+ return mLock;
+}
// static
void JHwRemoteBinder::InitClass(JNIEnv *env) {
- ScopedLocalRef<jclass> clazz(env, FindClassOrDie(env, CLASS_PATH));
+ jclass clazz = FindClassOrDie(env, CLASS_PATH);
- gFields.contextID =
- GetFieldIDOrDie(env, clazz.get(), "mNativeContext", "J");
+ gProxyOffsets.proxy_class = MakeGlobalRefOrDie(env, clazz);
+ gProxyOffsets.contextID =
+ GetFieldIDOrDie(env, clazz, "mNativeContext", "J");
+ gProxyOffsets.constructID = GetMethodIDOrDie(env, clazz, "<init>", "()V");
+ gProxyOffsets.sendDeathNotice = GetStaticMethodIDOrDie(env, clazz, "sendDeathNotice",
+ "(Landroid/os/IHwBinder$DeathRecipient;J)V");
- gFields.constructID = GetMethodIDOrDie(env, clazz.get(), "<init>", "()V");
+ clazz = FindClassOrDie(env, "java/lang/Class");
+ gClassOffsets.mGetName = GetMethodIDOrDie(env, clazz, "getName", "()Ljava/lang/String;");
}
// static
sp<JHwRemoteBinder> JHwRemoteBinder::SetNativeContext(
JNIEnv *env, jobject thiz, const sp<JHwRemoteBinder> &context) {
sp<JHwRemoteBinder> old =
- (JHwRemoteBinder *)env->GetLongField(thiz, gFields.contextID);
+ (JHwRemoteBinder *)env->GetLongField(thiz, gProxyOffsets.contextID);
if (context != NULL) {
context->incStrong(NULL /* id */);
@@ -67,7 +238,7 @@
old->decStrong(NULL /* id */);
}
- env->SetLongField(thiz, gFields.contextID, (long)context.get());
+ env->SetLongField(thiz, gProxyOffsets.contextID, (long)context.get());
return old;
}
@@ -75,7 +246,7 @@
// static
sp<JHwRemoteBinder> JHwRemoteBinder::GetNativeContext(
JNIEnv *env, jobject thiz) {
- return (JHwRemoteBinder *)env->GetLongField(thiz, gFields.contextID);
+ return (JHwRemoteBinder *)env->GetLongField(thiz, gProxyOffsets.contextID);
}
// static
@@ -84,7 +255,7 @@
ScopedLocalRef<jclass> clazz(env, FindClassOrDie(env, CLASS_PATH));
// XXX Have to look up the constructor here because otherwise that static
- // class initializer isn't called and gFields.constructID is undefined :(
+ // class initializer isn't called and gProxyOffsets.constructID is undefined :(
jmethodID constructID = GetMethodIDOrDie(env, clazz.get(), "<init>", "()V");
@@ -97,6 +268,7 @@
JHwRemoteBinder::JHwRemoteBinder(
JNIEnv *env, jobject thiz, const sp<hardware::IBinder> &binder)
: mBinder(binder) {
+ mDeathRecipientList = new HwBinderDeathRecipientList();
jclass clazz = env->GetObjectClass(thiz);
CHECK(clazz != NULL);
@@ -114,7 +286,7 @@
mClass = NULL;
}
-sp<hardware::IBinder> JHwRemoteBinder::getBinder() {
+sp<hardware::IBinder> JHwRemoteBinder::getBinder() const {
return mBinder;
}
@@ -122,6 +294,10 @@
mBinder = binder;
}
+sp<HwBinderDeathRecipientList> JHwRemoteBinder::getDeathRecipientList() const {
+ return mDeathRecipientList;
+}
+
} // namespace android
////////////////////////////////////////////////////////////////////////////////
@@ -174,6 +350,73 @@
signalExceptionForError(env, err);
}
+static jboolean JHwRemoteBinder_linkToDeath(JNIEnv* env, jobject thiz,
+ jobject recipient, jlong cookie)
+{
+ if (recipient == NULL) {
+ jniThrowNullPointerException(env, NULL);
+ return JNI_FALSE;
+ }
+
+ sp<JHwRemoteBinder> context = JHwRemoteBinder::GetNativeContext(env, thiz);
+ sp<hardware::IBinder> binder = context->getBinder();
+
+ if (!binder->localBinder()) {
+ HwBinderDeathRecipientList* list = (context->getDeathRecipientList()).get();
+ sp<HwBinderDeathRecipient> jdr = new HwBinderDeathRecipient(env, recipient, cookie, list);
+ status_t err = binder->linkToDeath(jdr, NULL, 0);
+ if (err != NO_ERROR) {
+ // Failure adding the death recipient, so clear its reference
+ // now.
+ jdr->clearReference();
+ return JNI_FALSE;
+ }
+ }
+
+ return JNI_TRUE;
+}
+
+static jboolean JHwRemoteBinder_unlinkToDeath(JNIEnv* env, jobject thiz,
+ jobject recipient)
+{
+ jboolean res = JNI_FALSE;
+ if (recipient == NULL) {
+ jniThrowNullPointerException(env, NULL);
+ return res;
+ }
+
+ sp<JHwRemoteBinder> context = JHwRemoteBinder::GetNativeContext(env, thiz);
+ sp<hardware::IBinder> binder = context->getBinder();
+
+ if (!binder->localBinder()) {
+ status_t err = NAME_NOT_FOUND;
+
+ // If we find the matching recipient, proceed to unlink using that
+ HwBinderDeathRecipientList* list = (context->getDeathRecipientList()).get();
+ sp<HwBinderDeathRecipient> origJDR = list->find(recipient);
+ if (origJDR != NULL) {
+ wp<hardware::IBinder::DeathRecipient> dr;
+ err = binder->unlinkToDeath(origJDR, NULL, 0, &dr);
+ if (err == NO_ERROR && dr != NULL) {
+ sp<hardware::IBinder::DeathRecipient> sdr = dr.promote();
+ HwBinderDeathRecipient* jdr = static_cast<HwBinderDeathRecipient*>(sdr.get());
+ if (jdr != NULL) {
+ jdr->clearReference();
+ }
+ }
+ }
+
+ if (err == NO_ERROR || err == DEAD_OBJECT) {
+ res = JNI_TRUE;
+ } else {
+ jniThrowException(env, "java/util/NoSuchElementException",
+ "Death link does not exist");
+ }
+ }
+
+ return res;
+}
+
static JNINativeMethod gMethods[] = {
{ "native_init", "()J", (void *)JHwRemoteBinder_native_init },
@@ -183,6 +426,14 @@
{ "transact",
"(IL" PACKAGE_PATH "/HwParcel;L" PACKAGE_PATH "/HwParcel;I)V",
(void *)JHwRemoteBinder_native_transact },
+
+ {"linkToDeath",
+ "(Landroid/os/IHwBinder$DeathRecipient;J)Z",
+ (void*)JHwRemoteBinder_linkToDeath},
+
+ {"unlinkToDeath",
+ "(Landroid/os/IHwBinder$DeathRecipient;)Z",
+ (void*)JHwRemoteBinder_unlinkToDeath},
};
namespace android {
diff --git a/core/jni/android_os_HwRemoteBinder.h b/core/jni/android_os_HwRemoteBinder.h
index fd33338..77a0278 100644
--- a/core/jni/android_os_HwRemoteBinder.h
+++ b/core/jni/android_os_HwRemoteBinder.h
@@ -20,10 +20,33 @@
#include <android-base/macros.h>
#include <hwbinder/Binder.h>
#include <jni.h>
+#include <utils/List.h>
+#include <utils/Mutex.h>
#include <utils/RefBase.h>
namespace android {
+// Per-IBinder death recipient bookkeeping. This is how we reconcile local jobject
+// death recipient references passed in through JNI with the permanent corresponding
+// HwBinderDeathRecipient objects.
+
+class HwBinderDeathRecipient;
+
+class HwBinderDeathRecipientList : public RefBase {
+ List< sp<HwBinderDeathRecipient> > mList;
+ Mutex mLock;
+
+public:
+ HwBinderDeathRecipientList();
+ ~HwBinderDeathRecipientList();
+
+ void add(const sp<HwBinderDeathRecipient>& recipient);
+ void remove(const sp<HwBinderDeathRecipient>& recipient);
+ sp<HwBinderDeathRecipient> find(jobject recipient);
+
+ Mutex& lock(); // Use with care; specifically for mutual exclusion during binder death
+};
+
struct JHwRemoteBinder : public RefBase {
static void InitClass(JNIEnv *env);
@@ -37,8 +60,9 @@
JHwRemoteBinder(
JNIEnv *env, jobject thiz, const sp<hardware::IBinder> &binder);
- sp<hardware::IBinder> getBinder();
+ sp<hardware::IBinder> getBinder() const;
void setBinder(const sp<hardware::IBinder> &binder);
+ sp<HwBinderDeathRecipientList> getDeathRecipientList() const;
protected:
virtual ~JHwRemoteBinder();
@@ -48,7 +72,7 @@
jobject mObject;
sp<hardware::IBinder> mBinder;
-
+ sp<HwBinderDeathRecipientList> mDeathRecipientList;
DISALLOW_COPY_AND_ASSIGN(JHwRemoteBinder);
};
diff --git a/core/jni/android_util_Process.cpp b/core/jni/android_util_Process.cpp
index 1cfbd97..b57f2362 100644
--- a/core/jni/android_util_Process.cpp
+++ b/core/jni/android_util_Process.cpp
@@ -240,7 +240,7 @@
t_pri = getpriority(PRIO_PROCESS, t_pid);
if (t_pri <= ANDROID_PRIORITY_AUDIO) {
- int scheduler = sched_getscheduler(t_pid);
+ int scheduler = sched_getscheduler(t_pid) & ~SCHED_RESET_ON_FORK;
if ((scheduler == SCHED_FIFO) || (scheduler == SCHED_RR)) {
// This task wants to stay in its current audio group so it can keep its budget
// don't update its cpuset or cgroup
diff --git a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
index 7e01657..f8f9efe 100644
--- a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
+++ b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
@@ -49,9 +49,6 @@
#define RS_BITCODE_SUFFIX ".bc"
-#define GDBSERVER "gdbserver"
-#define GDBSERVER_LEN (sizeof(GDBSERVER) - 1)
-
#define TMP_FILE_PATTERN "/tmp.XXXXXX"
#define TMP_FILE_PATTERN_LEN (sizeof(TMP_FILE_PATTERN) - 1)
@@ -246,7 +243,7 @@
return INSTALL_FAILED_INTERNAL_ERROR;
}
- *(localFileName + nativeLibPath.size()) = '/';
+ *(localTmpFileName + nativeLibPath.size()) = '/';
if (strlcpy(localTmpFileName + nativeLibPath.size(), TMP_FILE_PATTERN,
TMP_FILE_PATTERN_LEN - nativeLibPath.size()) != TMP_FILE_PATTERN_LEN) {
@@ -313,20 +310,20 @@
*/
class NativeLibrariesIterator {
private:
- NativeLibrariesIterator(ZipFileRO* zipFile, void* cookie)
- : mZipFile(zipFile), mCookie(cookie), mLastSlash(NULL) {
+ NativeLibrariesIterator(ZipFileRO* zipFile, bool debuggable, void* cookie)
+ : mZipFile(zipFile), mDebuggable(debuggable), mCookie(cookie), mLastSlash(NULL) {
fileName[0] = '\0';
}
public:
- static NativeLibrariesIterator* create(ZipFileRO* zipFile) {
+ static NativeLibrariesIterator* create(ZipFileRO* zipFile, bool debuggable) {
void* cookie = NULL;
// Do not specify a suffix to find both .so files and gdbserver.
if (!zipFile->startIteration(&cookie, APK_LIB, NULL /* suffix */)) {
return NULL;
}
- return new NativeLibrariesIterator(zipFile, cookie);
+ return new NativeLibrariesIterator(zipFile, debuggable, cookie);
}
ZipEntryRO next() {
@@ -347,15 +344,8 @@
const char* lastSlash = strrchr(fileName, '/');
ALOG_ASSERT(lastSlash != NULL, "last slash was null somehow for %s\n", fileName);
- // Exception: If we find the gdbserver binary, return it.
- if (!strncmp(lastSlash + 1, GDBSERVER, GDBSERVER_LEN)) {
- mLastSlash = lastSlash;
- break;
- }
-
- // Make sure the filename starts with lib and ends with ".so".
- if (strncmp(fileName + fileNameLen - LIB_SUFFIX_LEN, LIB_SUFFIX, LIB_SUFFIX_LEN)
- || strncmp(lastSlash, LIB_PREFIX, LIB_PREFIX_LEN)) {
+ // Skip directories.
+ if (*(lastSlash + 1) == 0) {
continue;
}
@@ -364,6 +354,14 @@
continue;
}
+ if (!mDebuggable) {
+ // Make sure the filename starts with lib and ends with ".so".
+ if (strncmp(fileName + fileNameLen - LIB_SUFFIX_LEN, LIB_SUFFIX, LIB_SUFFIX_LEN)
+ || strncmp(lastSlash, LIB_PREFIX, LIB_PREFIX_LEN)) {
+ continue;
+ }
+ }
+
mLastSlash = lastSlash;
break;
}
@@ -386,19 +384,21 @@
char fileName[PATH_MAX];
ZipFileRO* const mZipFile;
+ const bool mDebuggable;
void* mCookie;
const char* mLastSlash;
};
static install_status_t
iterateOverNativeFiles(JNIEnv *env, jlong apkHandle, jstring javaCpuAbi,
- iterFunc callFunc, void* callArg) {
+ jboolean debuggable, iterFunc callFunc, void* callArg) {
ZipFileRO* zipFile = reinterpret_cast<ZipFileRO*>(apkHandle);
if (zipFile == NULL) {
return INSTALL_FAILED_INVALID_APK;
}
- std::unique_ptr<NativeLibrariesIterator> it(NativeLibrariesIterator::create(zipFile));
+ std::unique_ptr<NativeLibrariesIterator> it(
+ NativeLibrariesIterator::create(zipFile, debuggable));
if (it.get() == NULL) {
return INSTALL_FAILED_INVALID_APK;
}
@@ -432,7 +432,8 @@
}
-static int findSupportedAbi(JNIEnv *env, jlong apkHandle, jobjectArray supportedAbisArray) {
+static int findSupportedAbi(JNIEnv *env, jlong apkHandle, jobjectArray supportedAbisArray,
+ jboolean debuggable) {
const int numAbis = env->GetArrayLength(supportedAbisArray);
Vector<ScopedUtfChars*> supportedAbis;
@@ -446,7 +447,8 @@
return INSTALL_FAILED_INVALID_APK;
}
- std::unique_ptr<NativeLibrariesIterator> it(NativeLibrariesIterator::create(zipFile));
+ std::unique_ptr<NativeLibrariesIterator> it(
+ NativeLibrariesIterator::create(zipFile, debuggable));
if (it.get() == NULL) {
return INSTALL_FAILED_INVALID_APK;
}
@@ -488,29 +490,29 @@
static jint
com_android_internal_content_NativeLibraryHelper_copyNativeBinaries(JNIEnv *env, jclass clazz,
jlong apkHandle, jstring javaNativeLibPath, jstring javaCpuAbi,
- jboolean extractNativeLibs, jboolean hasNativeBridge)
+ jboolean extractNativeLibs, jboolean hasNativeBridge, jboolean debuggable)
{
void* args[] = { &javaNativeLibPath, &extractNativeLibs, &hasNativeBridge };
- return (jint) iterateOverNativeFiles(env, apkHandle, javaCpuAbi,
+ return (jint) iterateOverNativeFiles(env, apkHandle, javaCpuAbi, debuggable,
copyFileIfChanged, reinterpret_cast<void*>(args));
}
static jlong
com_android_internal_content_NativeLibraryHelper_sumNativeBinaries(JNIEnv *env, jclass clazz,
- jlong apkHandle, jstring javaCpuAbi)
+ jlong apkHandle, jstring javaCpuAbi, jboolean debuggable)
{
size_t totalSize = 0;
- iterateOverNativeFiles(env, apkHandle, javaCpuAbi, sumFiles, &totalSize);
+ iterateOverNativeFiles(env, apkHandle, javaCpuAbi, debuggable, sumFiles, &totalSize);
return totalSize;
}
static jint
com_android_internal_content_NativeLibraryHelper_findSupportedAbi(JNIEnv *env, jclass clazz,
- jlong apkHandle, jobjectArray javaCpuAbisToSearch)
+ jlong apkHandle, jobjectArray javaCpuAbisToSearch, jboolean debuggable)
{
- return (jint) findSupportedAbi(env, apkHandle, javaCpuAbisToSearch);
+ return (jint) findSupportedAbi(env, apkHandle, javaCpuAbisToSearch, debuggable);
}
enum bitcode_scan_result_t {
@@ -569,13 +571,13 @@
"(J)V",
(void *)com_android_internal_content_NativeLibraryHelper_close},
{"nativeCopyNativeBinaries",
- "(JLjava/lang/String;Ljava/lang/String;ZZ)I",
+ "(JLjava/lang/String;Ljava/lang/String;ZZZ)I",
(void *)com_android_internal_content_NativeLibraryHelper_copyNativeBinaries},
{"nativeSumNativeBinaries",
- "(JLjava/lang/String;)J",
+ "(JLjava/lang/String;Z)J",
(void *)com_android_internal_content_NativeLibraryHelper_sumNativeBinaries},
{"nativeFindSupportedAbi",
- "(J[Ljava/lang/String;)I",
+ "(J[Ljava/lang/String;Z)I",
(void *)com_android_internal_content_NativeLibraryHelper_findSupportedAbi},
{"hasRenderscriptBitcode", "(J)I",
(void *)com_android_internal_content_NativeLibraryHelper_hasRenderscriptBitcode},
diff --git a/core/jni/com_android_internal_net_NetworkStatsFactory.cpp b/core/jni/com_android_internal_net_NetworkStatsFactory.cpp
index 9fa90ac..4a2b881 100644
--- a/core/jni/com_android_internal_net_NetworkStatsFactory.cpp
+++ b/core/jni/com_android_internal_net_NetworkStatsFactory.cpp
@@ -43,6 +43,7 @@
jfieldID uid;
jfieldID set;
jfieldID tag;
+ jfieldID metered;
jfieldID roaming;
jfieldID rxBytes;
jfieldID rxPackets;
@@ -239,6 +240,9 @@
ScopedIntArrayRW tag(env, get_int_array(env, stats,
gNetworkStatsClassInfo.tag, size, grow));
if (tag.get() == NULL) return -1;
+ ScopedIntArrayRW metered(env, get_int_array(env, stats,
+ gNetworkStatsClassInfo.metered, size, grow));
+ if (metered.get() == NULL) return -1;
ScopedIntArrayRW roaming(env, get_int_array(env, stats,
gNetworkStatsClassInfo.roaming, size, grow));
if (roaming.get() == NULL) return -1;
@@ -265,7 +269,7 @@
uid[i] = lines[i].uid;
set[i] = lines[i].set;
tag[i] = lines[i].tag;
- // Roaming is populated in Java-land by inspecting the iface properties.
+ // Metered and Roaming are populated in Java-land by inspecting the iface properties.
rxBytes[i] = lines[i].rxBytes;
rxPackets[i] = lines[i].rxPackets;
txBytes[i] = lines[i].txBytes;
@@ -279,6 +283,7 @@
env->SetObjectField(stats, gNetworkStatsClassInfo.uid, uid.getJavaArray());
env->SetObjectField(stats, gNetworkStatsClassInfo.set, set.getJavaArray());
env->SetObjectField(stats, gNetworkStatsClassInfo.tag, tag.getJavaArray());
+ env->SetObjectField(stats, gNetworkStatsClassInfo.metered, metered.getJavaArray());
env->SetObjectField(stats, gNetworkStatsClassInfo.roaming, roaming.getJavaArray());
env->SetObjectField(stats, gNetworkStatsClassInfo.rxBytes, rxBytes.getJavaArray());
env->SetObjectField(stats, gNetworkStatsClassInfo.rxPackets, rxPackets.getJavaArray());
@@ -311,6 +316,7 @@
gNetworkStatsClassInfo.uid = GetFieldIDOrDie(env, clazz, "uid", "[I");
gNetworkStatsClassInfo.set = GetFieldIDOrDie(env, clazz, "set", "[I");
gNetworkStatsClassInfo.tag = GetFieldIDOrDie(env, clazz, "tag", "[I");
+ gNetworkStatsClassInfo.metered = GetFieldIDOrDie(env, clazz, "metered", "[I");
gNetworkStatsClassInfo.roaming = GetFieldIDOrDie(env, clazz, "roaming", "[I");
gNetworkStatsClassInfo.rxBytes = GetFieldIDOrDie(env, clazz, "rxBytes", "[J");
gNetworkStatsClassInfo.rxPackets = GetFieldIDOrDie(env, clazz, "rxPackets", "[J");
diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp
index d081549..fec8f4e 100644
--- a/core/jni/com_android_internal_os_Zygote.cpp
+++ b/core/jni/com_android_internal_os_Zygote.cpp
@@ -37,6 +37,7 @@
#include <sys/prctl.h>
#include <sys/resource.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/wait.h>
@@ -153,6 +154,24 @@
}
}
+// Resets nice priority for zygote process. Zygote priority can be set
+// to high value during boot phase to speed it up. We want to ensure
+// zygote is running at normal priority before childs are forked from it.
+//
+// This ends up being called repeatedly before each fork(), but there's
+// no real harm in that.
+static void ResetNicePriority(JNIEnv* env) {
+ errno = 0;
+ int prio = getpriority(PRIO_PROCESS, 0);
+ if (prio == -1 && errno != 0) {
+ ALOGW("getpriority failed: %s\n", strerror(errno));
+ }
+ if (prio != 0 && setpriority(PRIO_PROCESS, 0, 0) != 0) {
+ ALOGE("setpriority(%d, 0, 0) failed: %s", PRIO_PROCESS, strerror(errno));
+ RuntimeAbort(env, __LINE__, "setpriority failed");
+ }
+}
+
// Sets the SIGCHLD handler back to default behavior in zygote children.
static void UnsetSigChldHandler() {
struct sigaction sa;
@@ -418,27 +437,6 @@
}
}
-#ifdef ENABLE_SCHED_BOOST
-static void SetForkLoad(bool boost) {
- // set scheduler knob to boost forked processes
- pid_t currentPid = getpid();
- // fits at most "/proc/XXXXXXX/sched_init_task_load\0"
- char schedPath[35];
- snprintf(schedPath, sizeof(schedPath), "/proc/%u/sched_init_task_load", currentPid);
- int schedBoostFile = open(schedPath, O_WRONLY);
- if (schedBoostFile < 0) {
- ALOGW("Unable to set zygote scheduler boost");
- return;
- }
- if (boost) {
- write(schedBoostFile, "100\0", 4);
- } else {
- write(schedBoostFile, "0\0", 2);
- }
- close(schedBoostFile);
-}
-#endif
-
// The list of open zygote file descriptors.
static FileDescriptorTable* gOpenFdTable = NULL;
@@ -452,10 +450,6 @@
jstring instructionSet, jstring dataDir) {
SetSigChldHandler();
-#ifdef ENABLE_SCHED_BOOST
- SetForkLoad(true);
-#endif
-
// Close any logging related FDs before we start evaluating the list of
// file descriptors.
__android_log_close();
@@ -472,6 +466,8 @@
RuntimeAbort(env, __LINE__, "Unable to restat file descriptor table.");
}
+ ResetNicePriority(env);
+
pid_t pid = fork();
if (pid == 0) {
@@ -614,12 +610,6 @@
}
} else if (pid > 0) {
// the parent process
-
-#ifdef ENABLE_SCHED_BOOST
- // unset scheduler knob
- SetForkLoad(false);
-#endif
-
}
return pid;
}
@@ -750,4 +740,3 @@
return RegisterMethodsOrDie(env, "com/android/internal/os/Zygote", gMethods, NELEM(gMethods));
}
} // namespace android
-
diff --git a/core/jni/fd_utils-inl.h b/core/jni/fd_utils-inl.h
index af27069..b78b8ff 100644
--- a/core/jni/fd_utils-inl.h
+++ b/core/jni/fd_utils-inl.h
@@ -51,6 +51,7 @@
"/dev/null",
"/dev/socket/zygote",
"/dev/socket/zygote_secondary",
+ "/dev/socket/webview_zygote",
"/sys/kernel/debug/tracing/trace_marker",
"/system/framework/framework-res.apk",
"/dev/urandom",
diff --git a/include/android_runtime/AndroidRuntime.h b/core/jni/include/android_runtime/AndroidRuntime.h
similarity index 98%
rename from include/android_runtime/AndroidRuntime.h
rename to core/jni/include/android_runtime/AndroidRuntime.h
index ed77d9a..c2189d4 100644
--- a/include/android_runtime/AndroidRuntime.h
+++ b/core/jni/include/android_runtime/AndroidRuntime.h
@@ -98,7 +98,7 @@
* Called when the Java application exits to perform additional cleanup actions
* before the process is terminated.
*/
- virtual void onExit(int code) { }
+ virtual void onExit(int /*code*/) { }
/** create a new thread that is visible from Java */
static android_thread_id_t createJavaThread(const char* name, void (*start)(void *),
diff --git a/include/android_runtime/Log.h b/core/jni/include/android_runtime/Log.h
similarity index 100%
rename from include/android_runtime/Log.h
rename to core/jni/include/android_runtime/Log.h
diff --git a/include/android_runtime/android_app_NativeActivity.h b/core/jni/include/android_runtime/android_app_NativeActivity.h
similarity index 100%
rename from include/android_runtime/android_app_NativeActivity.h
rename to core/jni/include/android_runtime/android_app_NativeActivity.h
diff --git a/include/android_runtime/android_content_res_Configuration.h b/core/jni/include/android_runtime/android_content_res_Configuration.h
similarity index 100%
rename from include/android_runtime/android_content_res_Configuration.h
rename to core/jni/include/android_runtime/android_content_res_Configuration.h
diff --git a/include/android_runtime/android_graphics_SurfaceTexture.h b/core/jni/include/android_runtime/android_graphics_SurfaceTexture.h
similarity index 100%
rename from include/android_runtime/android_graphics_SurfaceTexture.h
rename to core/jni/include/android_runtime/android_graphics_SurfaceTexture.h
diff --git a/include/android_runtime/android_hardware_camera2_CameraMetadata.h b/core/jni/include/android_runtime/android_hardware_camera2_CameraMetadata.h
similarity index 100%
rename from include/android_runtime/android_hardware_camera2_CameraMetadata.h
rename to core/jni/include/android_runtime/android_hardware_camera2_CameraMetadata.h
diff --git a/include/android_runtime/android_util_AssetManager.h b/core/jni/include/android_runtime/android_util_AssetManager.h
similarity index 100%
rename from include/android_runtime/android_util_AssetManager.h
rename to core/jni/include/android_runtime/android_util_AssetManager.h
diff --git a/include/android_runtime/android_view_InputQueue.h b/core/jni/include/android_runtime/android_view_InputQueue.h
similarity index 100%
rename from include/android_runtime/android_view_InputQueue.h
rename to core/jni/include/android_runtime/android_view_InputQueue.h
diff --git a/include/android_runtime/android_view_Surface.h b/core/jni/include/android_runtime/android_view_Surface.h
similarity index 100%
rename from include/android_runtime/android_view_Surface.h
rename to core/jni/include/android_runtime/android_view_Surface.h
diff --git a/include/android_runtime/android_view_SurfaceSession.h b/core/jni/include/android_runtime/android_view_SurfaceSession.h
similarity index 100%
rename from include/android_runtime/android_view_SurfaceSession.h
rename to core/jni/include/android_runtime/android_view_SurfaceSession.h
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 4e98e34..60cf810 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -181,6 +181,8 @@
<protected-broadcast
android:name="android.bluetooth.input.profile.action.VIRTUAL_UNPLUG_STATUS" />
<protected-broadcast
+ android:name="android.bluetooth.inputhost.profile.action.CONNECTION_STATE_CHANGED" />
+ <protected-broadcast
android:name="android.bluetooth.map.profile.action.CONNECTION_STATE_CHANGED" />
<protected-broadcast android:name="android.bluetooth.mapmce.profile.action.CONNECTION_STATE_CHANGED" />
<protected-broadcast android:name="android.bluetooth.mapmce.profile.action.MESSAGE_RECEIVED" />
diff --git a/core/res/res/drawable/ic_signal_wifi_badged_0_bars.xml b/core/res/res/drawable/ic_signal_wifi_badged_0_bars.xml
new file mode 100644
index 0000000..bd1eb41
--- /dev/null
+++ b/core/res/res/drawable/ic_signal_wifi_badged_0_bars.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
+ android:viewportWidth="18"
+ android:viewportHeight="18"
+ android:width="18dp"
+ android:height="18dp">
+ <group
+ android:translateX="386"
+ android:translateY="-298">
+ <path
+ android:pathData="M-377 308.5c0 -2.5 2 -4.5 4.5 -4.5l3.5 0 0.79999 -1c-0.29999 -0.29999 -3.70001 -3 -8.79999 -3 -5.09998 0 -8.5 2.79999 -8.79999 3l8.79999 11 0 0 0 0 1.60001 -2c-0.9 -0.89999 -1.60001 -2.10001 -1.60001 -3.5z"
+ android:fillColor="#FFFFFF"
+ android:fillAlpha="0.3" />
+ </group>
+</vector>
diff --git a/core/res/res/drawable/ic_signal_wifi_badged_1_bar.xml b/core/res/res/drawable/ic_signal_wifi_badged_1_bar.xml
new file mode 100644
index 0000000..aedb12c
--- /dev/null
+++ b/core/res/res/drawable/ic_signal_wifi_badged_1_bar.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
+ android:viewportWidth="18"
+ android:viewportHeight="18"
+ android:width="18dp"
+ android:height="18dp">
+ <group
+ android:translateX="386"
+ android:translateY="-298">
+ <path
+ android:pathData="M-377 308.5c0 -2.5 2 -4.5 4.5 -4.5l3.5 0 0.79999 -1c-0.29999 -0.29999 -3.70001 -3 -8.79999 -3 -5.09998 0 -8.5 2.79999 -8.79999 3l8.79999 11 0 0 0 0 1.60001 -2c-0.9 -0.89999 -1.60001 -2.10001 -1.60001 -3.5z"
+ android:fillColor="#FFFFFF"
+ android:fillAlpha="0.3" />
+ <path
+ android:pathData="M-377 308.5c0 -0.20001 0 -0.29999 0.10001 -0.5 0 0 0 0 -0.10001 0 -2.10001 0 -3.60001 1.20001 -3.79999 1.29999L-377 314l1.60001 -2.10001c-0.9 -0.79998 -1.60001 -2 -1.60001 -3.39999z"
+ android:fillColor="#FFFFFF" />
+ </group>
+</vector>
diff --git a/core/res/res/drawable/ic_signal_wifi_badged_2_bars.xml b/core/res/res/drawable/ic_signal_wifi_badged_2_bars.xml
new file mode 100644
index 0000000..6f07cb5
--- /dev/null
+++ b/core/res/res/drawable/ic_signal_wifi_badged_2_bars.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
+ android:viewportWidth="18"
+ android:viewportHeight="18"
+ android:width="18dp"
+ android:height="18dp">
+ <group
+ android:translateX="386"
+ android:translateY="-298">
+ <path
+ android:pathData="M-377 308.5c0 -2.5 2 -4.5 4.5 -4.5l3.5 0 0.79999 -1c-0.29999 -0.29999 -3.70001 -3 -8.79999 -3 -5.09998 0 -8.5 2.79999 -8.79999 3l8.79999 11 0 0 0 0 1.60001 -2c-0.9 -0.89999 -1.60001 -2.10001 -1.60001 -3.5z"
+ android:fillColor="#FFFFFF"
+ android:fillAlpha="0.3" />
+ <path
+ android:pathData="M-377 308.5c0 -0.89999 0.29999 -1.70001 0.70001 -2.5 -0.20001 0 -0.5 0 -0.70001 0 -2.79999 0 -4.79999 1.60001 -5 1.79999l5 6.20001 0 0 0 0 1.60001 -2c-1 -0.89999 -1.60001 -2.10001 -1.60001 -3.5z"
+ android:fillColor="#FFFFFF" />
+ </group>
+</vector>
diff --git a/core/res/res/drawable/ic_signal_wifi_badged_3_bars.xml b/core/res/res/drawable/ic_signal_wifi_badged_3_bars.xml
new file mode 100644
index 0000000..c41a8ca
--- /dev/null
+++ b/core/res/res/drawable/ic_signal_wifi_badged_3_bars.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
+ android:viewportWidth="18"
+ android:viewportHeight="18"
+ android:width="18dp"
+ android:height="18dp">
+ <group
+ android:translateX="386"
+ android:translateY="-298">
+ <path
+ android:pathData="M-377 308.5c0 -2.5 2 -4.5 4.5 -4.5l3.5 0 0.79999 -1c-0.29999 -0.29999 -3.70001 -3 -8.79999 -3 -5.09998 0 -8.5 2.79999 -8.79999 3l8.79999 11 0 0 0 0 1.60001 -2c-0.9 -0.89999 -1.60001 -2.10001 -1.60001 -3.5z"
+ android:fillColor="#FFFFFF"
+ android:fillAlpha="0.3" />
+ <path
+ android:pathData="M-375.39999 311.89999c-1 -0.79998 -1.60001 -2.1 -1.60001 -3.39999 0 -1.79999 1.10001 -3.39999 2.70001 -4.10001C-375.09998 304.19998 -376 304 -377 304c-3.60001 0 -6 1.89999 -6.29999 2.20001L-377 314l0 0 0 0"
+ android:fillColor="#FFFFFF" />
+ </group>
+</vector>
diff --git a/core/res/res/drawable/ic_signal_wifi_badged_4_bars.xml b/core/res/res/drawable/ic_signal_wifi_badged_4_bars.xml
new file mode 100644
index 0000000..ec0a52f
--- /dev/null
+++ b/core/res/res/drawable/ic_signal_wifi_badged_4_bars.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
+ android:viewportWidth="18"
+ android:viewportHeight="18"
+ android:width="18dp"
+ android:height="18dp">
+ <group
+ android:translateX="386"
+ android:translateY="-298">
+ <path
+ android:pathData="M-377 308.5c0 -2.5 2 -4.5 4.5 -4.5l3.5 0 0.79999 -1c-0.29999 -0.29999 -3.70001 -3 -8.79999 -3 -5.09998 0 -8.5 2.79999 -8.79999 3l8.79999 11 0 0 0 0 1.60001 -2c-0.9 -0.89999 -1.60001 -2.10001 -1.60001 -3.5z"
+ android:fillColor="#FFFFFF" />
+ </group>
+</vector>
diff --git a/core/res/res/drawable/ic_signal_wifi_badged_4k.xml b/core/res/res/drawable/ic_signal_wifi_badged_4k.xml
new file mode 100644
index 0000000..78bd0a0
--- /dev/null
+++ b/core/res/res/drawable/ic_signal_wifi_badged_4k.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
+ android:viewportWidth="18"
+ android:viewportHeight="18"
+ android:width="18dp"
+ android:height="18dp">
+ <group
+ android:translateX="386"
+ android:translateY="-298">
+ <path
+ android:pathData="M-373.04999 308.79999l0.5 0 0 0.89999 -0.5 0 0 1.20001 -1.1 0 0 -1.20001 -1.9 0 -0.1 -0.70001 1.89999 -3.70001 1.10001 0 0 3.50003 0.1 0zm-1.89999 0l0.89999 0 0 -1.9 0 0 -0.89999 1.9z"
+ android:fillColor="#FFFFFF" />
+ <path
+ android:pathData="M-370.44998 308.70001l-0.5 0.60001 0 1.70001 -1.10001 0 0 -5.70001 1.10001 0 0 2.5 0.39999 -0.60001 1.10001 -1.89999 1.39999 0 -1.6 2.5 1.70001 3.20001 -1.29999 0 -1.20001 -2.30002z"
+ android:fillColor="#FFFFFF" />
+ </group>
+</vector>
diff --git a/core/res/res/drawable/ic_signal_wifi_badged_hd.xml b/core/res/res/drawable/ic_signal_wifi_badged_hd.xml
new file mode 100644
index 0000000..78085c2f
--- /dev/null
+++ b/core/res/res/drawable/ic_signal_wifi_badged_hd.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
+ android:viewportWidth="18"
+ android:viewportHeight="18"
+ android:width="18dp"
+ android:height="18dp">
+ <group
+ android:translateX="386"
+ android:translateY="-298">
+ <path
+ android:pathData="M-371.79999 311l-1.1 0 0 -2.29999 -0.79999 0 0 2.29999 -1.10001 0 0 -5.70001 1.10001 0 0 2.39999 0.79999 0 0 -2.39999 1.1 0 0 5.70001z"
+ android:fillColor="#FFFFFF" />
+ <path
+ android:pathData="M-371.33557 310.98651l0 -5.68701 1.39068 0c0.27848 0 0.53336 0.0532 0.76465 0.16016 0.2313 0.10693 0.42954 0.2622 0.59568 0.46679 0.16519 0.20459 0.29357 0.45557 0.38421 0.75391 0.0906 0.29834 0.13593 0.63867 0.13593 1.02148l0 0.88672c0 0.38281 -0.0453 0.72363 -0.13593 1.021 -0.0906 0.29785 -0.21902 0.5498 -0.38421 0.7539 -0.16614 0.20411 -0.36628 0.35938 -0.59946 0.46485 -0.23316 0.10547 -0.49182 0.1582 -0.77786 0.1582l-1.37369 0zm1.06879 -4.76904l0 3.85107 0.26333 0c0.15491 0 0.28452 -0.0283 0.38971 -0.084 0.10516 -0.0557 0.19077 -0.14356 0.25681 -0.26367 0.066 -0.12012 0.11331 -0.27198 0.14184 -0.4585 0.0285 -0.18652 0.0424 -0.41113 0.0424 -0.67383l0 -0.89453c0 -0.26562 -0.0138 -0.49219 -0.0424 -0.67969 -0.0285 -0.1875 -0.0758 -0.33984 -0.14102 -0.45703 -0.0644 -0.11719 -0.1492 -0.20312 -0.25275 -0.25781 -0.10437 -0.0547 -0.23071 -0.082 -0.37991 -0.082l-0.27801 0z"
+ android:fillColor="#FFFFFF" />
+ </group>
+</vector>
diff --git a/core/res/res/drawable/ic_signal_wifi_badged_ld.xml b/core/res/res/drawable/ic_signal_wifi_badged_ld.xml
new file mode 100644
index 0000000..f660ab7
--- /dev/null
+++ b/core/res/res/drawable/ic_signal_wifi_badged_ld.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
+ android:viewportWidth="18"
+ android:viewportHeight="18"
+ android:width="18dp"
+ android:height="18dp">
+ <group
+ android:translateX="386"
+ android:translateY="-298">
+ <path
+ android:pathData="M-371.33557 310.98651l0 -5.68701 1.39068 0c0.27848 0 0.53336 0.0532 0.76465 0.16016 0.2313 0.10693 0.42954 0.2622 0.59568 0.46679 0.16519 0.20459 0.29357 0.45557 0.38421 0.75391 0.0906 0.29834 0.13593 0.63867 0.13593 1.02148l0 0.88672c0 0.38281 -0.0453 0.72363 -0.13593 1.021 -0.0906 0.29785 -0.21902 0.5498 -0.38421 0.7539 -0.16614 0.20411 -0.36628 0.35938 -0.59946 0.46485 -0.23316 0.10547 -0.49182 0.1582 -0.77786 0.1582l-1.37369 0zm1.06879 -4.76904l0 3.85107 0.26333 0c0.15491 0 0.28452 -0.0283 0.38971 -0.084 0.10516 -0.0557 0.19077 -0.14356 0.25681 -0.26367 0.066 -0.12012 0.11331 -0.27198 0.14184 -0.4585 0.0285 -0.18652 0.0424 -0.41113 0.0424 -0.67383l0 -0.89453c0 -0.26562 -0.0138 -0.49219 -0.0424 -0.67969 -0.0285 -0.1875 -0.0758 -0.33984 -0.14102 -0.45703 -0.0644 -0.11719 -0.1492 -0.20312 -0.25275 -0.25781 -0.10437 -0.0547 -0.23071 -0.082 -0.37991 -0.082l-0.27801 0z"
+ android:fillColor="#FFFFFF" />
+ <path
+ android:pathData="M-373.13333 310.13333l1.33334 0 0 0.86667 -2.46667 0 0 -5.66666 1.13333 0 0 4.79999z"
+ android:fillColor="#FFFFFF" />
+ </group>
+</vector>
diff --git a/core/res/res/drawable/ic_signal_wifi_badged_sd.xml b/core/res/res/drawable/ic_signal_wifi_badged_sd.xml
new file mode 100644
index 0000000..43b8653
--- /dev/null
+++ b/core/res/res/drawable/ic_signal_wifi_badged_sd.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
+ android:viewportWidth="18"
+ android:viewportHeight="18"
+ android:width="18dp"
+ android:height="18dp">
+ <group
+ android:translateX="386"
+ android:translateY="-298">
+ <path
+ android:pathData="M-371.33557 310.98651l0 -5.68701 1.39068 0c0.27848 0 0.53336 0.0532 0.76465 0.16016 0.2313 0.10693 0.42954 0.2622 0.59568 0.46679 0.16519 0.20459 0.29357 0.45557 0.38421 0.75391 0.0906 0.29834 0.13593 0.63867 0.13593 1.02148l0 0.88672c0 0.38281 -0.0453 0.72363 -0.13593 1.021 -0.0906 0.29785 -0.21902 0.5498 -0.38421 0.7539 -0.16614 0.20411 -0.36628 0.35938 -0.59946 0.46485 -0.23316 0.10547 -0.49182 0.1582 -0.77786 0.1582l-1.37369 0zm1.06879 -4.76904l0 3.85107 0.26333 0c0.15491 0 0.28452 -0.0283 0.38971 -0.084 0.10516 -0.0557 0.19077 -0.14356 0.25681 -0.26367 0.066 -0.12012 0.11331 -0.27198 0.14184 -0.4585 0.0285 -0.18652 0.0424 -0.41113 0.0424 -0.67383l0 -0.89453c0 -0.26562 -0.0138 -0.49219 -0.0424 -0.67969 -0.0285 -0.1875 -0.0758 -0.33984 -0.14102 -0.45703 -0.0644 -0.11719 -0.1492 -0.20312 -0.25275 -0.25781 -0.10437 -0.0547 -0.23071 -0.082 -0.37991 -0.082l-0.27801 0z"
+ android:fillColor="#FFFFFF" />
+ <path
+ android:pathData="M-372.87598 309.47461c0 -0.10645 -0.01 -0.20117 -0.0303 -0.28223 -0.0205 -0.0811 -0.0576 -0.15527 -0.11035 -0.22265 -0.0537 -0.0674 -0.12598 -0.12891 -0.21777 -0.18457 -0.0908 -0.0566 -0.20704 -0.11231 -0.34668 -0.16797 -0.24903 -0.0889 -0.47657 -0.18457 -0.68165 -0.28614 -0.20605 -0.10156 -0.38281 -0.2207 -0.53027 -0.35839 -0.14746 -0.13721 -0.26172 -0.29639 -0.34277 -0.47803 -0.0811 -0.18164 -0.12207 -0.39697 -0.12207 -0.646 0 -0.23144 0.042 -0.4414 0.12793 -0.63086 0.085 -0.18945 0.20312 -0.35205 0.35644 -0.48779 0.15235 -0.13623 0.33496 -0.2417 0.54883 -0.31641 0.21289 -0.0752 0.44824 -0.1123 0.70508 -0.1123 0.2666 0 0.50683 0.0425 0.71973 0.12744 0.21386 0.0854 0.39648 0.2041 0.54687 0.35645 0.15137 0.15234 0.26758 0.333 0.34766 0.54101 0.0791 0.2085 0.11914 0.43604 0.11914 0.68262l-1.07422 0c0 -0.11963 -0.0127 -0.22998 -0.0381 -0.33154 -0.0254 -0.10205 -0.0654 -0.18897 -0.12011 -0.26123 -0.0547 -0.0723 -0.125 -0.12891 -0.20997 -0.16993 -0.085 -0.0405 -0.1875 -0.0605 -0.30664 -0.0605 -0.11132 0 -0.208 0.0171 -0.29004 0.0513 -0.0811 0.0342 -0.14843 0.0815 -0.20117 0.14111 -0.0537 0.0596 -0.0928 0.13037 -0.11816 0.21143 -0.0254 0.0815 -0.0381 0.16894 -0.0381 0.26318 0 0.0937 0.0166 0.17725 0.0508 0.24951 0.0342 0.0723 0.0869 0.14014 0.15625 0.20361 0.0703 0.064 0.16016 0.125 0.26856 0.18311 0.10937 0.0586 0.23926 0.11963 0.38965 0.1831 0.24316 0.084 0.46093 0.17823 0.65136 0.2837 0.19043 0.10498 0.35059 0.22998 0.48047 0.37158 0.12891 0.14258 0.22754 0.30762 0.29493 0.49316 0.0674 0.1875 0.10156 0.40235 0.10156 0.64649 0 0.24121 -0.04 0.458 -0.12012 0.64843 -0.0801 0.19043 -0.19434 0.35059 -0.3418 0.48145 -0.14746 0.13086 -0.32617 0.23144 -0.53711 0.30176 -0.21093 0.0693 -0.44726 0.10449 -0.70898 0.10449 -0.23633 0 -0.46777 -0.0361 -0.69531 -0.1084 -0.22754 -0.0723 -0.43067 -0.18359 -0.61035 -0.33203 -0.17872 -0.14844 -0.32325 -0.33691 -0.43262 -0.56543 -0.10938 -0.22852 -0.16309 -0.49805 -0.16309 -0.80859l1.07813 0c0 0.17089 0.0166 0.31445 0.0498 0.43261 0.0332 0.11817 0.084 0.21485 0.15235 0.29004 0.0684 0.0752 0.15429 0.12891 0.25683 0.16211 0.10352 0.0332 0.22461 0.0488 0.36426 0.0488 0.11719 0 0.21582 -0.0156 0.2959 -0.0488 0.0801 -0.0332 0.14355 -0.0781 0.19238 -0.13574 0.0478 -0.0566 0.082 -0.125 0.10254 -0.2041 0.0205 -0.0781 0.0303 -0.16504 0.0303 -0.25879z"
+ android:fillColor="#FFFFFF" />
+ </group>
+</vector>
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 22255b4..4cf1226 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -1287,7 +1287,8 @@
This may be empty if network scoring and recommending isn't supported.
-->
<string-array name="config_networkRecommendationPackageNames" translatable="false">
- <!-- Add packages here -->
+ <!-- The standard AOSP network recommendation provider -->
+ <item>com.android.networkrecommendation</item>
</string-array>
<!-- Whether to enable Hardware FLP overlay which allows Hardware FLP to be
@@ -1681,7 +1682,7 @@
<bool name="config_actionMenuItemAllCaps">true</bool>
<!-- Remote server that can provide NTP responses. -->
- <string translatable="false" name="config_ntpServer">2.android.pool.ntp.org</string>
+ <string translatable="false" name="config_ntpServer">time.android.com</string>
<!-- Normal polling frequency in milliseconds -->
<integer name="config_ntpPollingInterval">86400000</integer>
<!-- Try-again polling interval in milliseconds, in case the network request failed -->
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index c26fac1..fe88cd1 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -1230,6 +1230,15 @@
<java-symbol type="drawable" name="platlogo" />
<java-symbol type="drawable" name="stat_notify_sync_error" />
<java-symbol type="drawable" name="stat_notify_wifi_in_range" />
+ <java-symbol type="drawable" name="ic_signal_wifi_badged_0_bars" />
+ <java-symbol type="drawable" name="ic_signal_wifi_badged_1_bar" />
+ <java-symbol type="drawable" name="ic_signal_wifi_badged_2_bars" />
+ <java-symbol type="drawable" name="ic_signal_wifi_badged_3_bars" />
+ <java-symbol type="drawable" name="ic_signal_wifi_badged_4_bars" />
+ <java-symbol type="drawable" name="ic_signal_wifi_badged_4k" />
+ <java-symbol type="drawable" name="ic_signal_wifi_badged_hd" />
+ <java-symbol type="drawable" name="ic_signal_wifi_badged_sd" />
+ <java-symbol type="drawable" name="ic_signal_wifi_badged_ld" />
<java-symbol type="drawable" name="stat_notify_rssi_in_range" />
<java-symbol type="drawable" name="stat_sys_gps_on" />
<java-symbol type="drawable" name="stat_sys_tether_wifi" />
@@ -2716,7 +2725,6 @@
<java-symbol type="bool" name="config_permissionReviewRequired" />
-
<java-symbol type="drawable" name="ic_restart" />
<java-symbol type="drawable" name="emergency_icon" />
@@ -2731,5 +2739,4 @@
<!-- Network Recommendation -->
<java-symbol type="array" name="config_networkRecommendationPackageNames" />
-
</resources>
diff --git a/core/tests/coretests/src/android/net/NetworkRecommendationProviderTest.java b/core/tests/coretests/src/android/net/NetworkRecommendationProviderTest.java
new file mode 100644
index 0000000..bdc0200
--- /dev/null
+++ b/core/tests/coretests/src/android/net/NetworkRecommendationProviderTest.java
@@ -0,0 +1,161 @@
+package android.net;
+
+import static android.net.NetworkRecommendationProvider.EXTRA_RECOMMENDATION_RESULT;
+import static android.net.NetworkRecommendationProvider.EXTRA_SEQUENCE;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.IRemoteCallback;
+import android.test.InstrumentationTestCase;
+import android.test.suitebuilder.annotation.MediumTest;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Unit test for the {@link NetworkRecommendationProvider}.
+ */
+public class NetworkRecommendationProviderTest extends InstrumentationTestCase {
+ @Mock private IRemoteCallback mMockRemoteCallback;
+ private NetworkRecProvider mRecProvider;
+ private Handler mHandler;
+ private INetworkRecommendationProvider mStub;
+ private CountDownLatch mRecRequestLatch;
+ private CountDownLatch mScoreRequestLatch;
+ private NetworkKey[] mTestNetworkKeys;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ // Configuration needed to make mockito/dexcache work.
+ final Context context = getInstrumentation().getTargetContext();
+ System.setProperty("dexmaker.dexcache",
+ context.getCacheDir().getPath());
+ ClassLoader newClassLoader = getInstrumentation().getClass().getClassLoader();
+ Thread.currentThread().setContextClassLoader(newClassLoader);
+
+ MockitoAnnotations.initMocks(this);
+
+ HandlerThread thread = new HandlerThread("NetworkRecommendationProviderTest");
+ thread.start();
+ mRecRequestLatch = new CountDownLatch(1);
+ mScoreRequestLatch = new CountDownLatch(1);
+ mHandler = new Handler(thread.getLooper());
+ mRecProvider = new NetworkRecProvider(mHandler, mRecRequestLatch, mScoreRequestLatch);
+ mStub = INetworkRecommendationProvider.Stub.asInterface(mRecProvider.getBinder());
+ mTestNetworkKeys = new NetworkKey[2];
+ mTestNetworkKeys[0] = new NetworkKey(new WifiKey("\"ssid_01\"", "00:00:00:00:00:11"));
+ mTestNetworkKeys[1] = new NetworkKey(new WifiKey("\"ssid_02\"", "00:00:00:00:00:22"));
+ }
+
+ @MediumTest
+ public void testRecommendationRequestReceived() throws Exception {
+ final RecommendationRequest request = new RecommendationRequest.Builder().build();
+ final int sequence = 100;
+ mStub.requestRecommendation(request, mMockRemoteCallback, sequence);
+
+ // wait for onRequestRecommendation() to be called in our impl below.
+ mRecRequestLatch.await(200, TimeUnit.MILLISECONDS);
+ NetworkRecommendationProvider.ResultCallback expectedResultCallback =
+ new NetworkRecommendationProvider.ResultCallback(mMockRemoteCallback, sequence);
+ assertEquals(request, mRecProvider.mCapturedRequest);
+ assertEquals(expectedResultCallback, mRecProvider.mCapturedCallback);
+ }
+
+ @SmallTest
+ public void testResultCallbackOnResult() throws Exception {
+ final int sequence = 100;
+ final NetworkRecommendationProvider.ResultCallback callback =
+ new NetworkRecommendationProvider.ResultCallback(mMockRemoteCallback, sequence);
+
+ final RecommendationResult result = RecommendationResult.createDoNotConnectRecommendation();
+ callback.onResult(result);
+
+ final ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class);
+ Mockito.verify(mMockRemoteCallback).sendResult(bundleCaptor.capture());
+ Bundle capturedBundle = bundleCaptor.getValue();
+ assertEquals(sequence, capturedBundle.getInt(EXTRA_SEQUENCE));
+ assertSame(result, capturedBundle.getParcelable(EXTRA_RECOMMENDATION_RESULT));
+ }
+
+ @SmallTest
+ public void testResultCallbackOnResult_runTwice_throwsException() throws Exception {
+ final int sequence = 100;
+ final NetworkRecommendationProvider.ResultCallback callback =
+ new NetworkRecommendationProvider.ResultCallback(mMockRemoteCallback, sequence);
+
+ final RecommendationResult result = RecommendationResult.createDoNotConnectRecommendation();
+ callback.onResult(result);
+
+ try {
+ callback.onResult(result);
+ fail("Callback ran more than once.");
+ } catch (IllegalStateException e) {
+ // expected
+ }
+ }
+
+ @MediumTest
+ public void testScoreRequestReceived() throws Exception {
+ mStub.requestScores(mTestNetworkKeys);
+
+ // wait for onRequestScores() to be called in our impl below.
+ mScoreRequestLatch.await(200, TimeUnit.MILLISECONDS);
+
+ assertSame(mTestNetworkKeys, mRecProvider.mCapturedNetworks);
+ }
+
+ @MediumTest
+ public void testScoreRequest_nullInput() throws Exception {
+ mStub.requestScores(null);
+
+ // onRequestScores() should never be called
+ assertFalse(mScoreRequestLatch.await(200, TimeUnit.MILLISECONDS));
+ }
+
+ @MediumTest
+ public void testScoreRequest_emptyInput() throws Exception {
+ mStub.requestScores(new NetworkKey[0]);
+
+ // onRequestScores() should never be called
+ assertFalse(mScoreRequestLatch.await(200, TimeUnit.MILLISECONDS));
+ }
+
+ private static class NetworkRecProvider extends NetworkRecommendationProvider {
+ private final CountDownLatch mRecRequestLatch;
+ private final CountDownLatch mScoreRequestLatch;
+ RecommendationRequest mCapturedRequest;
+ ResultCallback mCapturedCallback;
+ NetworkKey[] mCapturedNetworks;
+
+ NetworkRecProvider(Handler handler, CountDownLatch recRequestLatch,
+ CountDownLatch networkRequestLatch) {
+ super(handler);
+ mRecRequestLatch = recRequestLatch;
+ mScoreRequestLatch = networkRequestLatch;
+ }
+
+ @Override
+ public void onRequestRecommendation(RecommendationRequest request,
+ ResultCallback callback) {
+ mCapturedRequest = request;
+ mCapturedCallback = callback;
+ mRecRequestLatch.countDown();
+ }
+
+ @Override
+ public void onRequestScores(NetworkKey[] networks) {
+ mCapturedNetworks = networks;
+ mScoreRequestLatch.countDown();
+ }
+ }
+}
diff --git a/core/tests/coretests/src/android/net/NetworkScorerAppManagerTest.java b/core/tests/coretests/src/android/net/NetworkScorerAppManagerTest.java
index 02c2517..5bfff26 100644
--- a/core/tests/coretests/src/android/net/NetworkScorerAppManagerTest.java
+++ b/core/tests/coretests/src/android/net/NetworkScorerAppManagerTest.java
@@ -16,32 +16,33 @@
package android.net;
+import static org.mockito.Mockito.when;
+
import android.Manifest.permission;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
+import android.content.res.Resources;
import android.net.NetworkScorerAppManager.NetworkScorerAppData;
-import android.os.UserHandle;
+import android.provider.Settings;
import android.test.InstrumentationTestCase;
-
+import com.android.internal.R;
+import java.util.List;
import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
public class NetworkScorerAppManagerTest extends InstrumentationTestCase {
@Mock private Context mMockContext;
@Mock private PackageManager mMockPm;
-
+ @Mock private Resources mResources;
+ @Mock private ContentResolver mContentResolver;
+ private Context mTargetContext;
private NetworkScorerAppManager mNetworkScorerAppManager;
@Override
@@ -49,154 +50,161 @@
super.setUp();
// Configuration needed to make mockito/dexcache work.
- System.setProperty("dexmaker.dexcache",
- getInstrumentation().getTargetContext().getCacheDir().getPath());
+ mTargetContext = getInstrumentation().getTargetContext();
+ System.setProperty("dexmaker.dexcache", mTargetContext.getCacheDir().getPath());
ClassLoader newClassLoader = getInstrumentation().getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(newClassLoader);
MockitoAnnotations.initMocks(this);
- Mockito.when(mMockContext.getPackageManager()).thenReturn(mMockPm);
+ when(mMockContext.getPackageManager()).thenReturn(mMockPm);
+ when(mMockContext.getResources()).thenReturn(mResources);
+ when(mMockContext.getContentResolver()).thenReturn(mTargetContext.getContentResolver());
mNetworkScorerAppManager = new NetworkScorerAppManager(mMockContext);
}
- public void testGetAllValidScorers() throws Exception {
- // Package 1 - Valid scorer.
- ResolveInfoHolder package1 = buildResolveInfo("package1", 1, true, true, false, false);
-
- // Package 2 - Receiver does not have BROADCAST_NETWORK_PRIVILEGED permission.
- ResolveInfoHolder package2 = buildResolveInfo("package2", 2, false, true, false, false);
-
- // Package 3 - App does not have SCORE_NETWORKS permission.
- ResolveInfoHolder package3 = buildResolveInfo("package3", 3, true, false, false, false);
-
- // Package 4 - Valid scorer w/ optional config activity.
- ResolveInfoHolder package4 = buildResolveInfo("package4", 4, true, true, true, false);
-
- // Package 5 - Valid scorer w/ optional service to bind to.
- ResolveInfoHolder package5 = buildResolveInfo("package5", 5, true, true, false, true);
-
- List<ResolveInfoHolder> scorers = new ArrayList<>();
- scorers.add(package1);
- scorers.add(package2);
- scorers.add(package3);
- scorers.add(package4);
- scorers.add(package5);
- setScorers(scorers);
-
- Iterator<NetworkScorerAppData> result =
- mNetworkScorerAppManager.getAllValidScorers().iterator();
-
- assertTrue(result.hasNext());
- NetworkScorerAppData next = result.next();
- assertEquals("package1", next.mPackageName);
- assertEquals(1, next.mPackageUid);
- assertNull(next.mConfigurationActivityClassName);
-
- assertTrue(result.hasNext());
- next = result.next();
- assertEquals("package4", next.mPackageName);
- assertEquals(4, next.mPackageUid);
- assertEquals(".ConfigActivity", next.mConfigurationActivityClassName);
-
- assertTrue(result.hasNext());
- next = result.next();
- assertEquals("package5", next.mPackageName);
- assertEquals(5, next.mPackageUid);
- assertEquals(".ScoringService", next.mScoringServiceClassName);
-
- assertFalse(result.hasNext());
+ public void testGetPotentialRecommendationProviderPackages_emptyConfig() throws Exception {
+ setNetworkRecommendationPackageNames(/*no configured packages*/);
+ assertTrue(mNetworkScorerAppManager.getPotentialRecommendationProviderPackages().isEmpty());
}
- private void setScorers(List<ResolveInfoHolder> scorers) {
- List<ResolveInfo> receivers = new ArrayList<>();
- for (final ResolveInfoHolder scorer : scorers) {
- receivers.add(scorer.scorerResolveInfo);
- if (scorer.configActivityResolveInfo != null) {
- // This scorer has a config activity.
- Mockito.when(mMockPm.queryIntentActivities(
- Mockito.argThat(new ArgumentMatcher<Intent>() {
- @Override
- public boolean matches(Object object) {
- Intent intent = (Intent) object;
- return NetworkScoreManager.ACTION_CUSTOM_ENABLE.equals(
- intent.getAction())
- && scorer.scorerResolveInfo.activityInfo.packageName.equals(
- intent.getPackage());
- }
- }), Mockito.eq(0))).thenReturn(
- Collections.singletonList(scorer.configActivityResolveInfo));
- }
+ public void testGetPotentialRecommendationProviderPackages_permissionNotGranted()
+ throws Exception {
+ setNetworkRecommendationPackageNames("package1");
+ mockScoreNetworksDenied("package1");
- if (scorer.serviceResolveInfo != null) {
- // This scorer has a service to bind to
- Mockito.when(mMockPm.resolveService(
- Mockito.argThat(new ArgumentMatcher<Intent>() {
- @Override
- public boolean matches(Object object) {
- Intent intent = (Intent) object;
- return NetworkScoreManager.ACTION_SCORE_NETWORKS.equals(
- intent.getAction())
- && scorer.scorerResolveInfo.activityInfo.packageName.equals(
- intent.getPackage());
- }
- }), Mockito.eq(0))).thenReturn(scorer.serviceResolveInfo);
- }
+ assertTrue(mNetworkScorerAppManager.getPotentialRecommendationProviderPackages().isEmpty());
+ }
+
+ public void testGetPotentialRecommendationProviderPackages_permissionGranted()
+ throws Exception {
+ setNetworkRecommendationPackageNames("package1");
+ mockScoreNetworksGranted("package1");
+
+ List<String> potentialProviderPackages =
+ mNetworkScorerAppManager.getPotentialRecommendationProviderPackages();
+
+ assertFalse(potentialProviderPackages.isEmpty());
+ assertEquals("package1", potentialProviderPackages.get(0));
+ }
+
+ public void testGetPotentialRecommendationProviderPackages_multipleConfigured()
+ throws Exception {
+ setNetworkRecommendationPackageNames("package1", "package2");
+ mockScoreNetworksDenied("package1");
+ mockScoreNetworksGranted("package2");
+
+ List<String> potentialProviderPackages =
+ mNetworkScorerAppManager.getPotentialRecommendationProviderPackages();
+
+ assertEquals(1, potentialProviderPackages.size());
+ assertEquals("package2", potentialProviderPackages.get(0));
+ }
+
+ public void testGetNetworkRecommendationProviderData_noPotentialPackages() throws Exception {
+ setNetworkRecommendationPackageNames(/*no configured packages*/);
+ assertNull(mNetworkScorerAppManager.getNetworkRecommendationProviderData());
+ }
+
+ public void testGetNetworkRecommendationProviderData_serviceMissing() throws Exception {
+ setNetworkRecommendationPackageNames("package1");
+ mockScoreNetworksGranted("package1");
+
+ assertNull(mNetworkScorerAppManager.getNetworkRecommendationProviderData());
+ }
+
+ public void testGetNetworkRecommendationProviderData_scoreNetworksNotGranted()
+ throws Exception {
+ setNetworkRecommendationPackageNames("package1");
+ mockScoreNetworksDenied("package1");
+ mockRecommendationServiceAvailable("package1", 924 /* packageUid */);
+
+ assertNull(mNetworkScorerAppManager.getNetworkRecommendationProviderData());
+ }
+
+ public void testGetNetworkRecommendationProviderData_available() throws Exception {
+ setNetworkRecommendationPackageNames("package1");
+ mockScoreNetworksGranted("package1");
+ mockRecommendationServiceAvailable("package1", 924 /* packageUid */);
+
+ NetworkScorerAppData appData =
+ mNetworkScorerAppManager.getNetworkRecommendationProviderData();
+ assertNotNull(appData);
+ assertEquals("package1", appData.packageName);
+ assertEquals(924, appData.packageUid);
+ assertEquals(".RecommendationService", appData.recommendationServiceClassName);
+ }
+
+ public void testGetActiveScorer_providerAvailable() throws Exception {
+ setNetworkRecommendationPackageNames("package1");
+ mockScoreNetworksGranted("package1");
+ mockRecommendationServiceAvailable("package1", 924 /* packageUid */);
+
+ ContentResolver cr = mTargetContext.getContentResolver();
+ Settings.Global.putInt(cr, Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 1);
+
+ final NetworkScorerAppData activeScorer = mNetworkScorerAppManager.getActiveScorer();
+ assertNotNull(activeScorer);
+ assertEquals("package1", activeScorer.packageName);
+ assertEquals(924, activeScorer.packageUid);
+ assertEquals(".RecommendationService", activeScorer.recommendationServiceClassName);
+ }
+
+ public void testGetActiveScorer_providerNotAvailable()
+ throws Exception {
+ ContentResolver cr = mTargetContext.getContentResolver();
+ Settings.Global.putInt(cr, Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 1);
+
+ final NetworkScorerAppData activeScorer = mNetworkScorerAppManager.getActiveScorer();
+ assertNull(activeScorer);
+ }
+
+ public void testGetActiveScorer_recommendationsDisabled() throws Exception {
+ setNetworkRecommendationPackageNames("package1");
+ mockScoreNetworksGranted("package1");
+ mockRecommendationServiceAvailable("package1", 924 /* packageUid */);
+ ContentResolver cr = mTargetContext.getContentResolver();
+ Settings.Global.putInt(cr, Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0);
+
+ final NetworkScorerAppData activeScorer = mNetworkScorerAppManager.getActiveScorer();
+ assertNull(activeScorer);
+ }
+
+ private void setNetworkRecommendationPackageNames(String... names) {
+ if (names == null) {
+ names = new String[0];
}
+ when(mResources.getStringArray(R.array.config_networkRecommendationPackageNames))
+ .thenReturn(names);
+ }
- Mockito.when(mMockPm.queryBroadcastReceiversAsUser(
+ private void mockScoreNetworksGranted(String packageName) {
+ when(mMockPm.checkPermission(permission.SCORE_NETWORKS, packageName))
+ .thenReturn(PackageManager.PERMISSION_GRANTED);
+ }
+
+ private void mockScoreNetworksDenied(String packageName) {
+ when(mMockPm.checkPermission(permission.SCORE_NETWORKS, packageName))
+ .thenReturn(PackageManager.PERMISSION_DENIED);
+ }
+
+ private void mockRecommendationServiceAvailable(final String packageName, int packageUid) {
+ final ResolveInfo serviceInfo = new ResolveInfo();
+ serviceInfo.serviceInfo = new ServiceInfo();
+ serviceInfo.serviceInfo.name = ".RecommendationService";
+ serviceInfo.serviceInfo.packageName = packageName;
+ serviceInfo.serviceInfo.applicationInfo = new ApplicationInfo();
+ serviceInfo.serviceInfo.applicationInfo.uid = packageUid;
+
+ final int flags = 0;
+ when(mMockPm.resolveService(
Mockito.argThat(new ArgumentMatcher<Intent>() {
@Override
public boolean matches(Object object) {
Intent intent = (Intent) object;
- return NetworkScoreManager.ACTION_SCORE_NETWORKS.equals(intent.getAction());
+ return NetworkScoreManager.ACTION_RECOMMEND_NETWORKS
+ .equals(intent.getAction())
+ && packageName.equals(intent.getPackage());
}
- }), Mockito.eq(0), Mockito.eq(UserHandle.USER_SYSTEM)))
- .thenReturn(receivers);
- }
-
- private ResolveInfoHolder buildResolveInfo(String packageName, int packageUid,
- boolean hasReceiverPermission, boolean hasScorePermission, boolean hasConfigActivity,
- boolean hasServiceInfo) throws Exception {
- Mockito.when(mMockPm.checkPermission(permission.SCORE_NETWORKS, packageName))
- .thenReturn(hasScorePermission ?
- PackageManager.PERMISSION_GRANTED : PackageManager.PERMISSION_DENIED);
-
- ResolveInfo resolveInfo = new ResolveInfo();
- resolveInfo.activityInfo = new ActivityInfo();
- resolveInfo.activityInfo.packageName = packageName;
- resolveInfo.activityInfo.applicationInfo = new ApplicationInfo();
- resolveInfo.activityInfo.applicationInfo.uid = packageUid;
- if (hasReceiverPermission) {
- resolveInfo.activityInfo.permission = permission.BROADCAST_NETWORK_PRIVILEGED;
- }
-
- ResolveInfo configActivityInfo = null;
- if (hasConfigActivity) {
- configActivityInfo = new ResolveInfo();
- configActivityInfo.activityInfo = new ActivityInfo();
- configActivityInfo.activityInfo.name = ".ConfigActivity";
- }
-
- ResolveInfo serviceInfo = null;
- if (hasServiceInfo) {
- serviceInfo = new ResolveInfo();
- serviceInfo.serviceInfo = new ServiceInfo();
- serviceInfo.serviceInfo.name = ".ScoringService";
- }
-
- return new ResolveInfoHolder(resolveInfo, configActivityInfo, serviceInfo);
- }
-
- private static class ResolveInfoHolder {
- final ResolveInfo scorerResolveInfo;
- final ResolveInfo configActivityResolveInfo;
- final ResolveInfo serviceResolveInfo;
-
- public ResolveInfoHolder(ResolveInfo scorerResolveInfo,
- ResolveInfo configActivityResolveInfo, ResolveInfo serviceResolveInfo) {
- this.scorerResolveInfo = scorerResolveInfo;
- this.configActivityResolveInfo = configActivityResolveInfo;
- this.serviceResolveInfo = serviceResolveInfo;
- }
+ }), Mockito.eq(flags))).thenReturn(serviceInfo);
}
}
diff --git a/core/tests/coretests/src/android/net/NetworkStatsTest.java b/core/tests/coretests/src/android/net/NetworkStatsTest.java
index 9074f8a..eb85eb4 100644
--- a/core/tests/coretests/src/android/net/NetworkStatsTest.java
+++ b/core/tests/coretests/src/android/net/NetworkStatsTest.java
@@ -16,6 +16,9 @@
package android.net;
+import static android.net.NetworkStats.METERED_ALL;
+import static android.net.NetworkStats.METERED_NO;
+import static android.net.NetworkStats.METERED_YES;
import static android.net.NetworkStats.ROAMING_ALL;
import static android.net.NetworkStats.ROAMING_NO;
import static android.net.NetworkStats.ROAMING_YES;
@@ -45,103 +48,124 @@
private static final long TEST_START = 1194220800000L;
public void testFindIndex() throws Exception {
- final NetworkStats stats = new NetworkStats(TEST_START, 4)
- .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, ROAMING_NO, 1024L, 8L, 0L,
- 0L, 10)
- .addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, ROAMING_NO, 0L, 0L, 1024L,
- 8L, 11)
- .addValues(TEST_IFACE, 102, SET_DEFAULT, TAG_NONE, ROAMING_NO, 1024L, 8L,
- 1024L, 8L, 12)
- .addValues(TEST_IFACE, 102, SET_DEFAULT, TAG_NONE, ROAMING_YES, 1024L, 8L,
- 1024L, 8L, 12);
+ final NetworkStats stats = new NetworkStats(TEST_START, 5)
+ .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 1024L,
+ 8L, 0L, 0L, 10)
+ .addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 0L, 0L,
+ 1024L, 8L, 11)
+ .addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, METERED_YES, ROAMING_NO, 0L, 0L,
+ 1024L, 8L, 11)
+ .addValues(TEST_IFACE, 102, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 1024L,
+ 8L, 1024L, 8L, 12)
+ .addValues(TEST_IFACE, 102, SET_DEFAULT, TAG_NONE, METERED_YES, ROAMING_YES, 1024L,
+ 8L, 1024L, 8L, 12);
- assertEquals(3, stats.findIndex(TEST_IFACE, 102, SET_DEFAULT, TAG_NONE, ROAMING_YES));
- assertEquals(2, stats.findIndex(TEST_IFACE, 102, SET_DEFAULT, TAG_NONE, ROAMING_NO));
- assertEquals(1, stats.findIndex(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, ROAMING_NO));
- assertEquals(0, stats.findIndex(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, ROAMING_NO));
- assertEquals(-1, stats.findIndex(TEST_IFACE, 6, SET_DEFAULT, TAG_NONE, ROAMING_NO));
+ assertEquals(4, stats.findIndex(TEST_IFACE, 102, SET_DEFAULT, TAG_NONE, METERED_YES,
+ ROAMING_YES));
+ assertEquals(3, stats.findIndex(TEST_IFACE, 102, SET_DEFAULT, TAG_NONE, METERED_NO,
+ ROAMING_NO));
+ assertEquals(2, stats.findIndex(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, METERED_YES,
+ ROAMING_NO));
+ assertEquals(1, stats.findIndex(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, METERED_NO,
+ ROAMING_NO));
+ assertEquals(0, stats.findIndex(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, METERED_NO,
+ ROAMING_NO));
+ assertEquals(-1, stats.findIndex(TEST_IFACE, 6, SET_DEFAULT, TAG_NONE, METERED_NO,
+ ROAMING_NO));
}
public void testFindIndexHinted() {
final NetworkStats stats = new NetworkStats(TEST_START, 3)
- .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, ROAMING_NO, 1024L, 8L, 0L,
- 0L, 10)
- .addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, ROAMING_NO, 0L, 0L, 1024L,
- 8L, 11)
- .addValues(TEST_IFACE, 102, SET_DEFAULT, TAG_NONE, ROAMING_NO, 1024L, 8L,
- 1024L, 8L, 12)
- .addValues(TEST_IFACE2, 100, SET_FOREGROUND, TAG_NONE, ROAMING_NO, 1024L, 8L,
- 0L, 0L, 10)
- .addValues(TEST_IFACE2, 101, SET_DEFAULT, 0xF00D, ROAMING_NO, 0L, 0L, 1024L,
- 8L, 11)
- .addValues(TEST_IFACE2, 102, SET_DEFAULT, TAG_NONE, ROAMING_NO, 1024L, 8L,
- 1024L, 8L, 12)
- .addValues(TEST_IFACE2, 102, SET_DEFAULT, TAG_NONE, ROAMING_YES, 1024L, 8L,
- 1024L, 8L, 12);
+ .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 1024L,
+ 8L, 0L, 0L, 10)
+ .addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 0L, 0L,
+ 1024L, 8L, 11)
+ .addValues(TEST_IFACE, 102, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 1024L,
+ 8L, 1024L, 8L, 12)
+ .addValues(TEST_IFACE2, 100, SET_FOREGROUND, TAG_NONE, METERED_NO, ROAMING_NO,
+ 1024L, 8L, 0L, 0L, 10)
+ .addValues(TEST_IFACE2, 101, SET_DEFAULT, 0xF00D, METERED_NO, ROAMING_NO, 0L, 0L,
+ 1024L, 8L, 11)
+ .addValues(TEST_IFACE2, 101, SET_DEFAULT, 0xF00D, METERED_YES, ROAMING_NO, 0L, 0L,
+ 1024L, 8L, 11)
+ .addValues(TEST_IFACE2, 102, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 1024L,
+ 8L, 1024L, 8L, 12)
+ .addValues(TEST_IFACE2, 102, SET_DEFAULT, TAG_NONE, METERED_YES, ROAMING_YES, 1024L,
+ 8L, 1024L, 8L, 12);
// verify that we correctly find across regardless of hinting
for (int hint = 0; hint < stats.size(); hint++) {
assertEquals(0, stats.findIndexHinted(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE,
- ROAMING_NO, hint));
+ METERED_NO, ROAMING_NO, hint));
assertEquals(1, stats.findIndexHinted(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE,
- ROAMING_NO, hint));
+ METERED_NO, ROAMING_NO, hint));
assertEquals(2, stats.findIndexHinted(TEST_IFACE, 102, SET_DEFAULT, TAG_NONE,
- ROAMING_NO, hint));
+ METERED_NO, ROAMING_NO, hint));
assertEquals(3, stats.findIndexHinted(TEST_IFACE2, 100, SET_FOREGROUND, TAG_NONE,
- ROAMING_NO, hint));
+ METERED_NO, ROAMING_NO, hint));
assertEquals(4, stats.findIndexHinted(TEST_IFACE2, 101, SET_DEFAULT, 0xF00D,
- ROAMING_NO, hint));
- assertEquals(5, stats.findIndexHinted(TEST_IFACE2, 102, SET_DEFAULT, TAG_NONE,
- ROAMING_NO, hint));
+ METERED_NO, ROAMING_NO, hint));
+ assertEquals(5, stats.findIndexHinted(TEST_IFACE2, 101, SET_DEFAULT, 0xF00D,
+ METERED_YES, ROAMING_NO, hint));
assertEquals(6, stats.findIndexHinted(TEST_IFACE2, 102, SET_DEFAULT, TAG_NONE,
- ROAMING_YES, hint));
+ METERED_NO, ROAMING_NO, hint));
+ assertEquals(7, stats.findIndexHinted(TEST_IFACE2, 102, SET_DEFAULT, TAG_NONE,
+ METERED_YES, ROAMING_YES, hint));
assertEquals(-1, stats.findIndexHinted(TEST_IFACE, 6, SET_DEFAULT, TAG_NONE,
- ROAMING_NO, hint));
+ METERED_NO, ROAMING_NO, hint));
}
}
public void testAddEntryGrow() throws Exception {
- final NetworkStats stats = new NetworkStats(TEST_START, 3);
+ final NetworkStats stats = new NetworkStats(TEST_START, 4);
assertEquals(0, stats.size());
- assertEquals(3, stats.internalSize());
+ assertEquals(4, stats.internalSize());
- stats.addValues(TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, ROAMING_NO, 1L, 1L, 2L,
- 2L, 3);
- stats.addValues(TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, ROAMING_NO, 2L, 2L, 2L,
- 2L, 4);
- stats.addValues(TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, ROAMING_YES, 3L, 3L, 2L,
- 2L, 5);
-
- assertEquals(3, stats.size());
- assertEquals(3, stats.internalSize());
-
- stats.addValues(TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, ROAMING_NO, 4L, 40L, 4L,
- 40L, 7);
- stats.addValues(TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, ROAMING_NO, 5L, 50L, 4L,
- 40L, 8);
- stats.addValues(TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, ROAMING_NO, 6L, 60L, 5L,
- 50L, 10);
- stats.addValues(TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, ROAMING_YES, 7L, 70L, 5L,
- 50L, 11);
-
- assertEquals(7, stats.size());
- assertTrue(stats.internalSize() >= 7);
-
- assertValues(stats, 0, TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, ROAMING_NO, 1L, 1L,
+ stats.addValues(TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 1L, 1L,
2L, 2L, 3);
- assertValues(stats, 1, TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, ROAMING_NO, 2L, 2L,
+ stats.addValues(TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 2L, 2L,
2L, 2L, 4);
- assertValues(stats, 2, TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, ROAMING_YES, 3L, 3L,
- 2L, 2L, 5);
- assertValues(stats, 3, TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, ROAMING_NO, 4L,
+ stats.addValues(TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_YES, 3L,
+ 3L, 2L, 2L, 5);
+ stats.addValues(TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_YES, ROAMING_YES, 3L,
+ 3L, 2L, 2L, 5);
+
+ assertEquals(4, stats.size());
+ assertEquals(4, stats.internalSize());
+
+ stats.addValues(TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 4L,
40L, 4L, 40L, 7);
- assertValues(stats, 4, TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, ROAMING_NO, 5L,
+ stats.addValues(TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 5L,
50L, 4L, 40L, 8);
- assertValues(stats, 5, TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, ROAMING_NO, 6L,
+ stats.addValues(TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 6L,
60L, 5L, 50L, 10);
- assertValues(stats, 6, TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, ROAMING_YES, 7L,
+ stats.addValues(TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_YES, 7L,
70L, 5L, 50L, 11);
+ stats.addValues(TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_YES, ROAMING_YES, 7L,
+ 70L, 5L, 50L, 11);
+
+ assertEquals(9, stats.size());
+ assertTrue(stats.internalSize() >= 9);
+
+ assertValues(stats, 0, TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 1L, 1L, 2L, 2L, 3);
+ assertValues(stats, 1, TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 2L, 2L, 2L, 2L, 4);
+ assertValues(stats, 2, TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_YES,
+ 3L, 3L, 2L, 2L, 5);
+ assertValues(stats, 3, TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_YES,
+ ROAMING_YES, 3L, 3L, 2L, 2L, 5);
+ assertValues(stats, 4, TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 4L, 40L, 4L, 40L, 7);
+ assertValues(stats, 5, TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 5L, 50L, 4L, 40L, 8);
+ assertValues(stats, 6, TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 6L, 60L, 5L, 50L, 10);
+ assertValues(stats, 7, TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_YES,
+ 7L, 70L, 5L, 50L, 11);
+ assertValues(stats, 8, TEST_IFACE, TEST_UID, SET_DEFAULT, TAG_NONE, METERED_YES,
+ ROAMING_YES, 7L, 70L, 5L, 50L, 11);
}
public void testCombineExisting() throws Exception {
@@ -152,20 +176,18 @@
stats.combineValues(TEST_IFACE, 1001, SET_DEFAULT, TAG_NONE, -128L, -1L,
-128L, -1L, -1);
- assertValues(stats, 0, TEST_IFACE, 1001, SET_DEFAULT, TAG_NONE, ROAMING_NO, 384L, 3L,
- 128L, 1L, 9);
- assertValues(stats, 1, TEST_IFACE, 1001, SET_DEFAULT, 0xff, ROAMING_NO, 128L, 1L, 128L,
- 1L, 2);
+ assertValues(stats, 0, TEST_IFACE, 1001, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 384L, 3L, 128L, 1L, 9);
+ assertValues(stats, 1, TEST_IFACE, 1001, SET_DEFAULT, 0xff, METERED_NO, ROAMING_NO, 128L,
+ 1L, 128L, 1L, 2);
// now try combining that should create row
- stats.combineValues(TEST_IFACE, 5005, SET_DEFAULT, TAG_NONE, 128L, 1L,
- 128L, 1L, 3);
- assertValues(stats, 2, TEST_IFACE, 5005, SET_DEFAULT, TAG_NONE, ROAMING_NO, 128L, 1L,
- 128L, 1L, 3);
- stats.combineValues(TEST_IFACE, 5005, SET_DEFAULT, TAG_NONE, 128L, 1L,
- 128L, 1L, 3);
- assertValues(stats, 2, TEST_IFACE, 5005, SET_DEFAULT, TAG_NONE, ROAMING_NO, 256L, 2L,
- 256L, 2L, 6);
+ stats.combineValues(TEST_IFACE, 5005, SET_DEFAULT, TAG_NONE, 128L, 1L, 128L, 1L, 3);
+ assertValues(stats, 2, TEST_IFACE, 5005, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 128L, 1L, 128L, 1L, 3);
+ stats.combineValues(TEST_IFACE, 5005, SET_DEFAULT, TAG_NONE, 128L, 1L, 128L, 1L, 3);
+ assertValues(stats, 2, TEST_IFACE, 5005, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 256L, 2L, 256L, 2L, 6);
}
public void testSubtractIdenticalData() throws Exception {
@@ -180,10 +202,10 @@
final NetworkStats result = after.subtract(before);
// identical data should result in zero delta
- assertValues(result, 0, TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, ROAMING_NO, 0L, 0L, 0L,
- 0L, 0);
- assertValues(result, 1, TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, ROAMING_NO, 0L, 0L, 0L,
- 0L, 0);
+ assertValues(result, 0, TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 0L,
+ 0L, 0L, 0L, 0);
+ assertValues(result, 1, TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 0L,
+ 0L, 0L, 0L, 0);
}
public void testSubtractIdenticalRows() throws Exception {
@@ -198,10 +220,10 @@
final NetworkStats result = after.subtract(before);
// expect delta between measurements
- assertValues(result, 0, TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, ROAMING_NO, 1L, 1L, 2L,
- 1L, 4);
- assertValues(result, 1, TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, ROAMING_NO, 3L, 1L, 4L,
- 1L, 8);
+ assertValues(result, 0, TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 1L,
+ 1L, 2L, 1L, 4);
+ assertValues(result, 1, TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 3L,
+ 1L, 4L, 1L, 8);
}
public void testSubtractNewRows() throws Exception {
@@ -217,12 +239,12 @@
final NetworkStats result = after.subtract(before);
// its okay to have new rows
- assertValues(result, 0, TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, ROAMING_NO, 0L, 0L, 0L,
- 0L, 0);
- assertValues(result, 1, TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, ROAMING_NO, 0L, 0L, 0L,
- 0L, 0);
- assertValues(result, 2, TEST_IFACE, 102, SET_DEFAULT, TAG_NONE, ROAMING_NO, 1024L, 8L,
- 1024L, 8L, 20);
+ assertValues(result, 0, TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 0L,
+ 0L, 0L, 0L, 0);
+ assertValues(result, 1, TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 0L,
+ 0L, 0L, 0L, 0);
+ assertValues(result, 2, TEST_IFACE, 102, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 1024L, 8L, 1024L, 8L, 20);
}
public void testSubtractMissingRows() throws Exception {
@@ -237,8 +259,8 @@
// should silently drop omitted rows
assertEquals(1, result.size());
- assertValues(result, 0, TEST_IFACE2, UID_ALL, SET_DEFAULT, TAG_NONE, ROAMING_NO, 1L,
- 2L, 3L, 4L, 0);
+ assertValues(result, 0, TEST_IFACE2, UID_ALL, SET_DEFAULT, TAG_NONE, METERED_NO,
+ ROAMING_NO, 1L, 2L, 3L, 4L, 0);
assertEquals(4L, result.getTotalBytes());
}
@@ -263,13 +285,22 @@
.addValues(TEST_IFACE, 101, SET_DEFAULT, 0xF00D, 8L, 0L, 0L, 0L, 0L);
assertEquals(64L, uidTag.getTotalBytes());
+ final NetworkStats uidMetered = new NetworkStats(TEST_START, 3)
+ .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 32L, 0L,
+ 0L, 0L, 0L)
+ .addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, METERED_YES, ROAMING_NO, 32L, 0L,
+ 0L, 0L, 0L)
+ .addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, METERED_YES, ROAMING_NO, 32L, 0L,
+ 0L, 0L, 0L);
+ assertEquals(96L, uidMetered.getTotalBytes());
+
final NetworkStats uidRoaming = new NetworkStats(TEST_START, 3)
- .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, ROAMING_NO, 32L, 0L, 0L, 0L,
- 0L)
- .addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, ROAMING_NO, 32L, 0L, 0L, 0L,
- 0L)
- .addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, ROAMING_YES, 32L, 0L, 0L, 0L,
- 0L);
+ .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 32L, 0L,
+ 0L, 0L, 0L)
+ .addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, METERED_YES, ROAMING_NO, 32L, 0L,
+ 0L, 0L, 0L)
+ .addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_YES, 32L, 0L,
+ 0L, 0L, 0L);
assertEquals(96L, uidRoaming.getTotalBytes());
}
@@ -283,95 +314,95 @@
public void testGroupedByIfaceAll() throws Exception {
final NetworkStats uidStats = new NetworkStats(TEST_START, 3)
- .addValues(IFACE_ALL, 100, SET_ALL, TAG_NONE, ROAMING_NO, 128L, 8L, 0L, 2L,
- 20L)
- .addValues(IFACE_ALL, 101, SET_FOREGROUND, TAG_NONE, ROAMING_NO, 128L, 8L, 0L,
+ .addValues(IFACE_ALL, 100, SET_ALL, TAG_NONE, METERED_NO, ROAMING_NO, 128L, 8L, 0L,
2L, 20L)
- .addValues(IFACE_ALL, 101, SET_ALL, TAG_NONE, ROAMING_YES, 128L, 8L, 0L, 2L,
- 20L);
+ .addValues(IFACE_ALL, 101, SET_FOREGROUND, TAG_NONE, METERED_YES, ROAMING_NO, 128L,
+ 8L, 0L, 2L, 20L)
+ .addValues(IFACE_ALL, 101, SET_ALL, TAG_NONE, METERED_NO, ROAMING_YES, 128L, 8L, 0L,
+ 2L, 20L);
final NetworkStats grouped = uidStats.groupedByIface();
assertEquals(3, uidStats.size());
assertEquals(1, grouped.size());
- assertValues(grouped, 0, IFACE_ALL, UID_ALL, SET_ALL, TAG_NONE, ROAMING_ALL, 384L, 24L, 0L,
- 6L, 0L);
+ assertValues(grouped, 0, IFACE_ALL, UID_ALL, SET_ALL, TAG_NONE, METERED_ALL, ROAMING_ALL,
+ 384L, 24L, 0L, 6L, 0L);
}
public void testGroupedByIface() throws Exception {
final NetworkStats uidStats = new NetworkStats(TEST_START, 7)
- .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, ROAMING_NO, 128L, 8L, 0L,
- 2L, 20L)
- .addValues(TEST_IFACE2, 100, SET_DEFAULT, TAG_NONE, ROAMING_NO, 512L, 32L, 0L,
- 0L, 0L)
- .addValues(TEST_IFACE2, 100, SET_DEFAULT, 0xF00D, ROAMING_NO, 64L, 4L, 0L, 0L,
- 0L)
- .addValues(TEST_IFACE2, 100, SET_FOREGROUND, TAG_NONE, ROAMING_NO, 512L, 32L,
+ .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 128L, 8L,
+ 0L, 2L, 20L)
+ .addValues(TEST_IFACE2, 100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 512L,
+ 32L, 0L, 0L, 0L)
+ .addValues(TEST_IFACE2, 100, SET_DEFAULT, 0xF00D, METERED_NO, ROAMING_NO, 64L, 4L,
0L, 0L, 0L)
- .addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, ROAMING_NO, 128L, 8L, 0L,
- 0L, 0L)
- .addValues(TEST_IFACE, 101, SET_DEFAULT, 0xF00D, ROAMING_NO, 128L, 8L, 0L, 0L,
- 0L)
- .addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, ROAMING_YES, 128L, 8L, 0L,
- 0L, 0L);
+ .addValues(TEST_IFACE2, 100, SET_FOREGROUND, TAG_NONE, METERED_NO, ROAMING_NO, 512L,
+ 32L, 0L, 0L, 0L)
+ .addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 128L, 8L,
+ 0L, 0L, 0L)
+ .addValues(TEST_IFACE, 101, SET_DEFAULT, 0xF00D, METERED_YES, ROAMING_NO, 128L, 8L,
+ 0L, 0L, 0L)
+ .addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_YES, 128L,
+ 8L, 0L, 0L, 0L);
final NetworkStats grouped = uidStats.groupedByIface();
assertEquals(7, uidStats.size());
assertEquals(2, grouped.size());
- assertValues(grouped, 0, TEST_IFACE, UID_ALL, SET_ALL, TAG_NONE, ROAMING_ALL, 384L, 24L, 0L,
- 2L, 0L);
- assertValues(grouped, 1, TEST_IFACE2, UID_ALL, SET_ALL, TAG_NONE, ROAMING_ALL, 1024L, 64L,
- 0L, 0L, 0L);
+ assertValues(grouped, 0, TEST_IFACE, UID_ALL, SET_ALL, TAG_NONE, METERED_ALL, ROAMING_ALL,
+ 384L, 24L, 0L, 2L, 0L);
+ assertValues(grouped, 1, TEST_IFACE2, UID_ALL, SET_ALL, TAG_NONE, METERED_ALL, ROAMING_ALL,
+ 1024L, 64L, 0L, 0L, 0L);
}
public void testAddAllValues() {
final NetworkStats first = new NetworkStats(TEST_START, 5)
- .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, ROAMING_NO, 32L, 0L, 0L, 0L,
- 0L)
- .addValues(TEST_IFACE, 100, SET_FOREGROUND, TAG_NONE, ROAMING_NO, 32L, 0L, 0L,
- 0L, 0L)
- .addValues(TEST_IFACE, 100, SET_FOREGROUND, TAG_NONE, ROAMING_YES, 32L, 0L, 0L,
- 0L, 0L);
+ .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, METERED_YES, ROAMING_NO, 32L, 0L,
+ 0L, 0L, 0L)
+ .addValues(TEST_IFACE, 100, SET_FOREGROUND, TAG_NONE, METERED_NO, ROAMING_NO, 32L,
+ 0L, 0L, 0L, 0L)
+ .addValues(TEST_IFACE, 100, SET_FOREGROUND, TAG_NONE, METERED_YES, ROAMING_YES, 32L,
+ 0L, 0L, 0L, 0L);
final NetworkStats second = new NetworkStats(TEST_START, 2)
- .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, ROAMING_NO, 32L, 0L, 0L, 0L,
- 0L)
- .addValues(TEST_IFACE2, UID_ALL, SET_DEFAULT, TAG_NONE, ROAMING_NO, 32L, 0L,
+ .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, METERED_YES, ROAMING_NO, 32L, 0L,
0L, 0L, 0L)
- .addValues(TEST_IFACE, 100, SET_FOREGROUND, TAG_NONE, ROAMING_YES, 32L, 0L, 0L,
- 0L, 0L);
+ .addValues(TEST_IFACE2, UID_ALL, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 32L,
+ 0L, 0L, 0L, 0L)
+ .addValues(TEST_IFACE, 100, SET_FOREGROUND, TAG_NONE, METERED_YES, ROAMING_YES, 32L,
+ 0L, 0L, 0L, 0L);
first.combineAllValues(second);
assertEquals(4, first.size());
- assertValues(first, 0, TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, ROAMING_NO, 64L, 0L, 0L,
- 0L, 0L);
- assertValues(first, 1, TEST_IFACE, 100, SET_FOREGROUND, TAG_NONE, ROAMING_NO, 32L, 0L,
- 0L, 0L, 0L);
- assertValues(first, 2, TEST_IFACE, 100, SET_FOREGROUND, TAG_NONE, ROAMING_YES, 64L, 0L,
- 0L, 0L, 0L);
- assertValues(first, 3, TEST_IFACE2, UID_ALL, SET_DEFAULT, TAG_NONE, ROAMING_NO, 32L,
+ assertValues(first, 0, TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, METERED_YES, ROAMING_NO, 64L,
0L, 0L, 0L, 0L);
+ assertValues(first, 1, TEST_IFACE, 100, SET_FOREGROUND, TAG_NONE, METERED_NO, ROAMING_NO,
+ 32L, 0L, 0L, 0L, 0L);
+ assertValues(first, 2, TEST_IFACE, 100, SET_FOREGROUND, TAG_NONE, METERED_YES, ROAMING_YES,
+ 64L, 0L, 0L, 0L, 0L);
+ assertValues(first, 3, TEST_IFACE2, UID_ALL, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 32L, 0L, 0L, 0L, 0L);
}
public void testGetTotal() {
final NetworkStats stats = new NetworkStats(TEST_START, 7)
- .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, ROAMING_NO, 128L, 8L, 0L,
- 2L, 20L)
- .addValues(TEST_IFACE2, 100, SET_DEFAULT, TAG_NONE, ROAMING_NO, 512L, 32L, 0L,
- 0L, 0L)
- .addValues(TEST_IFACE2, 100, SET_DEFAULT, 0xF00D, ROAMING_NO, 64L, 4L, 0L, 0L,
- 0L)
- .addValues(TEST_IFACE2, 100, SET_FOREGROUND, TAG_NONE, ROAMING_NO, 512L, 32L,
+ .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 128L, 8L,
+ 0L, 2L, 20L)
+ .addValues(TEST_IFACE2, 100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 512L,
+ 32L, 0L, 0L, 0L)
+ .addValues(TEST_IFACE2, 100, SET_DEFAULT, 0xF00D, METERED_NO, ROAMING_NO, 64L, 4L,
0L, 0L, 0L)
- .addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, ROAMING_NO, 128L, 8L, 0L,
- 0L, 0L)
- .addValues(TEST_IFACE, 101, SET_DEFAULT, 0xF00D, ROAMING_NO, 128L, 8L, 0L, 0L,
- 0L)
- .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, ROAMING_YES, 128L, 8L, 0L,
- 0L, 0L);
+ .addValues(TEST_IFACE2, 100, SET_FOREGROUND, TAG_NONE, METERED_NO, ROAMING_NO, 512L,
+ 32L, 0L, 0L, 0L)
+ .addValues(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, METERED_YES, ROAMING_NO, 128L,
+ 8L, 0L, 0L, 0L)
+ .addValues(TEST_IFACE, 101, SET_DEFAULT, 0xF00D, METERED_NO, ROAMING_NO, 128L, 8L,
+ 0L, 0L, 0L)
+ .addValues(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_YES, 128L,
+ 8L, 0L, 0L, 0L);
assertValues(stats.getTotal(null), 1408L, 88L, 0L, 2L, 20L);
assertValues(stats.getTotal(null, 100), 1280L, 80L, 0L, 2L, 20L);
@@ -396,10 +427,10 @@
final NetworkStats after = before.withoutUids(new int[] { 100 });
assertEquals(6, before.size());
assertEquals(2, after.size());
- assertValues(after, 0, TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, ROAMING_NO, 128L, 8L,
- 0L, 0L, 0L);
- assertValues(after, 1, TEST_IFACE, 101, SET_DEFAULT, 0xF00D, ROAMING_NO, 128L, 8L, 0L,
- 0L, 0L);
+ assertValues(after, 0, TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 128L, 8L, 0L, 0L, 0L);
+ assertValues(after, 1, TEST_IFACE, 101, SET_DEFAULT, 0xF00D, METERED_NO, ROAMING_NO, 128L,
+ 8L, 0L, 0L, 0L);
}
public void testClone() throws Exception {
@@ -434,105 +465,175 @@
final String underlyingIface = "wlan0";
final int testTag1 = 8888;
NetworkStats delta = new NetworkStats(TEST_START, 17)
- .addValues(tunIface, 10100, SET_DEFAULT, TAG_NONE, 39605L, 46L, 12259L, 55L, 0L)
- .addValues(tunIface, 10100, SET_FOREGROUND, TAG_NONE, 0L, 0L, 0L, 0L, 0L)
- .addValues(tunIface, 10120, SET_DEFAULT, TAG_NONE, 72667L, 197L, 43909L, 241L, 0L)
- .addValues(tunIface, 10120, SET_FOREGROUND, TAG_NONE, 9297L, 17L, 4128L, 21L, 0L)
+ .addValues(tunIface, 10100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 39605L, 46L,
+ 12259L, 55L, 0L)
+ .addValues(tunIface, 10100, SET_FOREGROUND, TAG_NONE, METERED_NO, ROAMING_NO, 0L, 0L,
+ 0L, 0L, 0L)
+ .addValues(tunIface, 10120, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 72667L, 197L,
+ 43909L, 241L, 0L)
+ .addValues(tunIface, 10120, SET_FOREGROUND, TAG_NONE, METERED_NO, ROAMING_NO, 9297L,
+ 17L, 4128L, 21L, 0L)
// VPN package also uses some traffic through unprotected network.
- .addValues(tunIface, tunUid, SET_DEFAULT, TAG_NONE, 4983L, 10L, 1801L, 12L, 0L)
- .addValues(tunIface, tunUid, SET_FOREGROUND, TAG_NONE, 0L, 0L, 0L, 0L, 0L)
+ .addValues(tunIface, tunUid, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 4983L, 10L,
+ 1801L, 12L, 0L)
+ .addValues(tunIface, tunUid, SET_FOREGROUND, TAG_NONE, METERED_NO, ROAMING_NO, 0L, 0L,
+ 0L, 0L, 0L)
// Tag entries
- .addValues(tunIface, 10120, SET_DEFAULT, testTag1, 21691L, 41L, 13820L, 51L, 0L)
- .addValues(tunIface, 10120, SET_FOREGROUND, testTag1, 1281L, 2L, 665L, 2L, 0L)
+ .addValues(tunIface, 10120, SET_DEFAULT, testTag1, METERED_NO, ROAMING_NO, 21691L, 41L,
+ 13820L, 51L, 0L)
+ .addValues(tunIface, 10120, SET_FOREGROUND, testTag1, METERED_NO, ROAMING_NO, 1281L, 2L,
+ 665L, 2L, 0L)
// Irrelevant entries
- .addValues(TEST_IFACE, 10100, SET_DEFAULT, TAG_NONE, 1685L, 5L, 2070L, 6L, 0L)
+ .addValues(TEST_IFACE, 10100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 1685L, 5L,
+ 2070L, 6L, 0L)
// Underlying Iface entries
- .addValues(underlyingIface, 10100, SET_DEFAULT, TAG_NONE, 5178L, 8L, 2139L, 11L, 0L)
- .addValues(underlyingIface, 10100, SET_FOREGROUND, TAG_NONE, 0L, 0L, 0L, 0L, 0L)
- .addValues(underlyingIface, tunUid, SET_DEFAULT, TAG_NONE, 149873L, 287L,
- 59217L /* smaller than sum(tun0) */, 299L /* smaller than sum(tun0) */, 0L)
- .addValues(underlyingIface, tunUid, SET_FOREGROUND, TAG_NONE, 0L, 0L, 0L, 0L, 0L);
+ .addValues(underlyingIface, 10100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 5178L,
+ 8L, 2139L, 11L, 0L)
+ .addValues(underlyingIface, 10100, SET_FOREGROUND, TAG_NONE, METERED_NO, ROAMING_NO, 0L,
+ 0L, 0L, 0L, 0L)
+ .addValues(underlyingIface, tunUid, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 149873L, 287L, 59217L /* smaller than sum(tun0) */,
+ 299L /* smaller than sum(tun0) */, 0L)
+ .addValues(underlyingIface, tunUid, SET_FOREGROUND, TAG_NONE, METERED_NO, ROAMING_NO,
+ 0L, 0L, 0L, 0L, 0L);
assertTrue(delta.migrateTun(tunUid, tunIface, underlyingIface));
- assertEquals(21, delta.size());
+ assertEquals(20, delta.size());
// tunIface and TEST_IFACE entries are not changed.
- assertValues(delta, 0, tunIface, 10100, SET_DEFAULT, TAG_NONE, ROAMING_NO,
+ assertValues(delta, 0, tunIface, 10100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
39605L, 46L, 12259L, 55L, 0L);
- assertValues(delta, 1, tunIface, 10100, SET_FOREGROUND, TAG_NONE, ROAMING_NO, 0L, 0L,
- 0L, 0L, 0L);
- assertValues(delta, 2, tunIface, 10120, SET_DEFAULT, TAG_NONE, ROAMING_NO,
+ assertValues(delta, 1, tunIface, 10100, SET_FOREGROUND, TAG_NONE, METERED_NO, ROAMING_NO,
+ 0L, 0L, 0L, 0L, 0L);
+ assertValues(delta, 2, tunIface, 10120, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
72667L, 197L, 43909L, 241L, 0L);
- assertValues(delta, 3, tunIface, 10120, SET_FOREGROUND, TAG_NONE, ROAMING_NO,
+ assertValues(delta, 3, tunIface, 10120, SET_FOREGROUND, TAG_NONE, METERED_NO, ROAMING_NO,
9297L, 17L, 4128L, 21L, 0L);
- assertValues(delta, 4, tunIface, tunUid, SET_DEFAULT, TAG_NONE, ROAMING_NO,
+ assertValues(delta, 4, tunIface, tunUid, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
4983L, 10L, 1801L, 12L, 0L);
- assertValues(delta, 5, tunIface, tunUid, SET_FOREGROUND, TAG_NONE, ROAMING_NO, 0L, 0L,
- 0L, 0L, 0L);
- assertValues(delta, 6, tunIface, 10120, SET_DEFAULT, testTag1, ROAMING_NO,
+ assertValues(delta, 5, tunIface, tunUid, SET_FOREGROUND, TAG_NONE, METERED_NO, ROAMING_NO,
+ 0L, 0L, 0L, 0L, 0L);
+ assertValues(delta, 6, tunIface, 10120, SET_DEFAULT, testTag1, METERED_NO, ROAMING_NO,
21691L, 41L, 13820L, 51L, 0L);
- assertValues(delta, 7, tunIface, 10120, SET_FOREGROUND, testTag1, ROAMING_NO, 1281L,
- 2L, 665L, 2L, 0L);
- assertValues(delta, 8, TEST_IFACE, 10100, SET_DEFAULT, TAG_NONE, ROAMING_NO, 1685L, 5L,
- 2070L, 6L, 0L);
+ assertValues(delta, 7, tunIface, 10120, SET_FOREGROUND, testTag1, METERED_NO, ROAMING_NO,
+ 1281L, 2L, 665L, 2L, 0L);
+ assertValues(delta, 8, TEST_IFACE, 10100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 1685L, 5L, 2070L, 6L, 0L);
// Existing underlying Iface entries are updated
- assertValues(delta, 9, underlyingIface, 10100, SET_DEFAULT, TAG_NONE, ROAMING_NO,
- 44783L, 54L, 13829L, 60L, 0L);
- assertValues(delta, 10, underlyingIface, 10100, SET_FOREGROUND, TAG_NONE, ROAMING_NO,
- 0L, 0L, 0L, 0L, 0L);
+ assertValues(delta, 9, underlyingIface, 10100, SET_DEFAULT, TAG_NONE, METERED_NO,
+ ROAMING_NO, 44783L, 54L, 14178L, 62L, 0L);
+ assertValues(delta, 10, underlyingIface, 10100, SET_FOREGROUND, TAG_NONE, METERED_NO,
+ ROAMING_NO, 0L, 0L, 0L, 0L, 0L);
// VPN underlying Iface entries are updated
- assertValues(delta, 11, underlyingIface, tunUid, SET_DEFAULT, TAG_NONE, ROAMING_NO,
- 28304L, 27L, 1719L, 12L, 0L);
- assertValues(delta, 12, underlyingIface, tunUid, SET_FOREGROUND, TAG_NONE, ROAMING_NO,
- 0L, 0L, 0L, 0L, 0L);
+ assertValues(delta, 11, underlyingIface, tunUid, SET_DEFAULT, TAG_NONE, METERED_NO,
+ ROAMING_NO, 28304L, 27L, 1L, 2L, 0L);
+ assertValues(delta, 12, underlyingIface, tunUid, SET_FOREGROUND, TAG_NONE, METERED_NO,
+ ROAMING_NO, 0L, 0L, 0L, 0L, 0L);
// New entries are added for new application's underlying Iface traffic
- assertContains(delta, underlyingIface, 10120, SET_DEFAULT, TAG_NONE, ROAMING_NO,
- 72667L, 197L, 41872L, 219L, 0L);
- assertContains(delta, underlyingIface, 10120, SET_FOREGROUND, TAG_NONE, ROAMING_NO,
- 9297L, 17L, 3936, 19L, 0L);
- assertContains(delta, underlyingIface, 10120, SET_DEFAULT, testTag1, ROAMING_NO,
- 21691L, 41L, 13179L, 46L, 0L);
- assertContains(delta, underlyingIface, 10120, SET_FOREGROUND, testTag1, ROAMING_NO,
- 1281L, 2L, 634L, 1L, 0L);
+ assertContains(delta, underlyingIface, 10120, SET_DEFAULT, TAG_NONE, METERED_NO,
+ ROAMING_NO, 72667L, 197L, 43123L, 227L, 0L);
+ assertContains(delta, underlyingIface, 10120, SET_FOREGROUND, TAG_NONE, METERED_NO,
+ ROAMING_NO, 9297L, 17L, 4054, 19L, 0L);
+ assertContains(delta, underlyingIface, 10120, SET_DEFAULT, testTag1, METERED_NO,
+ ROAMING_NO, 21691L, 41L, 13572L, 48L, 0L);
+ assertContains(delta, underlyingIface, 10120, SET_FOREGROUND, testTag1, METERED_NO,
+ ROAMING_NO, 1281L, 2L, 653L, 1L, 0L);
// New entries are added for debug purpose
- assertContains(delta, underlyingIface, 10100, SET_DBG_VPN_IN, TAG_NONE, ROAMING_NO,
- 39605L, 46L, 11690, 49, 0);
- assertContains(delta, underlyingIface, 10120, SET_DBG_VPN_IN, TAG_NONE, ROAMING_NO,
- 81964, 214, 45808, 238, 0);
- assertContains(delta, underlyingIface, tunUid, SET_DBG_VPN_IN, TAG_NONE, ROAMING_NO,
- 4983, 10, 1717, 10, 0);
- assertContains(delta, underlyingIface, tunUid, SET_DBG_VPN_OUT, TAG_NONE, ROAMING_ALL,
- 126552, 270, 59215, 297, 0);
+ assertContains(delta, underlyingIface, 10100, SET_DBG_VPN_IN, TAG_NONE, METERED_NO,
+ ROAMING_NO, 39605L, 46L, 12039, 51, 0);
+ assertContains(delta, underlyingIface, 10120, SET_DBG_VPN_IN, TAG_NONE, METERED_NO,
+ ROAMING_NO, 81964, 214, 47177, 246, 0);
+ assertContains(delta, underlyingIface, tunUid, SET_DBG_VPN_OUT, TAG_NONE, METERED_ALL,
+ ROAMING_ALL, 121569, 260, 59216, 297, 0);
}
+ // Tests a case where all of the data received by the tun0 interface is echo back into the tun0
+ // interface by the vpn app before it's sent out of the underlying interface. The VPN app should
+ // not be charged for the echoed data but it should still be charged for any extra data it sends
+ // via the underlying interface.
+ public void testMigrateTun_VpnAsLoopback() {
+ final int tunUid = 10030;
+ final String tunIface = "tun0";
+ final String underlyingIface = "wlan0";
+ NetworkStats delta = new NetworkStats(TEST_START, 9)
+ // 2 different apps sent/receive data via tun0.
+ .addValues(tunIface, 10100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 50000L, 25L,
+ 100000L, 50L, 0L)
+ .addValues(tunIface, 20100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 500L, 2L,
+ 200L, 5L, 0L)
+ // VPN package resends data through the tunnel (with exaggerated overhead)
+ .addValues(tunIface, tunUid, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 240000,
+ 100L, 120000L, 60L, 0L)
+ // 1 app already has some traffic on the underlying interface, the other doesn't yet
+ .addValues(underlyingIface, 10100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 1000L,
+ 10L, 2000L, 20L, 0L)
+ // Traffic through the underlying interface via the vpn app.
+ // This test should redistribute this data correctly.
+ .addValues(underlyingIface, tunUid, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 75500L, 37L, 130000L, 70L, 0L);
+
+ assertTrue(delta.migrateTun(tunUid, tunIface, underlyingIface));
+ assertEquals(9, delta.size());
+
+ // tunIface entries should not be changed.
+ assertValues(delta, 0, tunIface, 10100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 50000L, 25L, 100000L, 50L, 0L);
+ assertValues(delta, 1, tunIface, 20100, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 500L, 2L, 200L, 5L, 0L);
+ assertValues(delta, 2, tunIface, tunUid, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 240000L, 100L, 120000L, 60L, 0L);
+
+ // Existing underlying Iface entries are updated
+ assertValues(delta, 3, underlyingIface, 10100, SET_DEFAULT, TAG_NONE, METERED_NO,
+ ROAMING_NO, 51000L, 35L, 102000L, 70L, 0L);
+
+ // VPN underlying Iface entries are updated
+ assertValues(delta, 4, underlyingIface, tunUid, SET_DEFAULT, TAG_NONE, METERED_NO,
+ ROAMING_NO, 25000L, 10L, 29800L, 15L, 0L);
+
+ // New entries are added for new application's underlying Iface traffic
+ assertContains(delta, underlyingIface, 20100, SET_DEFAULT, TAG_NONE, METERED_NO,
+ ROAMING_NO, 500L, 2L, 200L, 5L, 0L);
+
+ // New entries are added for debug purpose
+ assertContains(delta, underlyingIface, 10100, SET_DBG_VPN_IN, TAG_NONE, METERED_NO,
+ ROAMING_NO, 50000L, 25L, 100000L, 50L, 0L);
+ assertContains(delta, underlyingIface, 20100, SET_DBG_VPN_IN, TAG_NONE, METERED_NO,
+ ROAMING_NO, 500, 2L, 200L, 5L, 0L);
+ assertContains(delta, underlyingIface, tunUid, SET_DBG_VPN_OUT, TAG_NONE, METERED_ALL,
+ ROAMING_ALL, 50500L, 27L, 100200L, 55, 0);
+ }
+
private static void assertContains(NetworkStats stats, String iface, int uid, int set,
- int tag, int roaming, long rxBytes, long rxPackets, long txBytes, long txPackets,
- long operations) {
- int index = stats.findIndex(iface, uid, set, tag, roaming);
+ int tag, int metered, int roaming, long rxBytes, long rxPackets, long txBytes,
+ long txPackets, long operations) {
+ int index = stats.findIndex(iface, uid, set, tag, metered, roaming);
assertTrue(index != -1);
- assertValues(stats, index, iface, uid, set, tag, roaming,
+ assertValues(stats, index, iface, uid, set, tag, metered, roaming,
rxBytes, rxPackets, txBytes, txPackets, operations);
}
private static void assertValues(NetworkStats stats, int index, String iface, int uid, int set,
- int tag, int roaming, long rxBytes, long rxPackets, long txBytes, long txPackets,
- long operations) {
+ int tag, int metered, int roaming, long rxBytes, long rxPackets, long txBytes,
+ long txPackets, long operations) {
final NetworkStats.Entry entry = stats.getValues(index, null);
- assertValues(entry, iface, uid, set, tag, roaming);
+ assertValues(entry, iface, uid, set, tag, metered, roaming);
assertValues(entry, rxBytes, rxPackets, txBytes, txPackets, operations);
}
private static void assertValues(
- NetworkStats.Entry entry, String iface, int uid, int set, int tag, int roaming) {
+ NetworkStats.Entry entry, String iface, int uid, int set, int tag, int metered,
+ int roaming) {
assertEquals(iface, entry.iface);
assertEquals(uid, entry.uid);
assertEquals(set, entry.set);
assertEquals(tag, entry.tag);
+ assertEquals(metered, entry.metered);
assertEquals(roaming, entry.roaming);
}
diff --git a/core/tests/coretests/src/android/net/RecommendationRequestTest.java b/core/tests/coretests/src/android/net/RecommendationRequestTest.java
new file mode 100644
index 0000000..31560b0
--- /dev/null
+++ b/core/tests/coretests/src/android/net/RecommendationRequestTest.java
@@ -0,0 +1,84 @@
+package android.net;
+
+import android.net.wifi.ScanResult;
+import android.net.wifi.WifiConfiguration;
+import android.os.Parcel;
+import android.test.AndroidTestCase;
+
+public class RecommendationRequestTest extends AndroidTestCase {
+ private ScanResult[] mScanResults;
+ private WifiConfiguration mConfiguration;
+ private NetworkCapabilities mCapabilities;
+
+ @Override
+ public void setUp() throws Exception {
+ mScanResults = new ScanResult[2];
+ mScanResults[0] = new ScanResult();
+ mScanResults[1] = new ScanResult(
+ "ssid",
+ "bssid",
+ 0L /*hessid*/,
+ 1 /*anqpDominId*/,
+ "caps",
+ 2 /*level*/,
+ 3 /*frequency*/,
+ 4L /*tsf*/,
+ 5 /*distCm*/,
+ 6 /*distSdCm*/,
+ 7 /*channelWidth*/,
+ 8 /*centerFreq0*/,
+ 9 /*centerFreq1*/,
+ false /*is80211McRTTResponder*/);
+ mConfiguration = new WifiConfiguration();
+ mConfiguration.SSID = "RecommendationRequestTest";
+ mCapabilities = new NetworkCapabilities()
+ .removeCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED);
+ }
+
+ public void testParceling() throws Exception {
+ RecommendationRequest request = new RecommendationRequest.Builder()
+ .setCurrentRecommendedWifiConfig(mConfiguration)
+ .setScanResults(mScanResults)
+ .setNetworkCapabilities(mCapabilities)
+ .build();
+
+ RecommendationRequest parceled = passThroughParcel(request);
+ assertEquals(request.getCurrentSelectedConfig().SSID,
+ parceled.getCurrentSelectedConfig().SSID);
+ assertEquals(request.getRequiredCapabilities(), parceled.getRequiredCapabilities());
+ ScanResult[] parceledScanResults = parceled.getScanResults();
+ assertNotNull(parceledScanResults);
+ assertEquals(mScanResults.length, parceledScanResults.length);
+ for (int i = 0; i < mScanResults.length; i++) {
+ assertEquals(mScanResults[i].SSID, parceledScanResults[i].SSID);
+ }
+ }
+
+ public void testParceling_nullScanResults() throws Exception {
+ RecommendationRequest request = new RecommendationRequest.Builder()
+ .setCurrentRecommendedWifiConfig(mConfiguration)
+ .setNetworkCapabilities(mCapabilities)
+ .build();
+
+ RecommendationRequest parceled = passThroughParcel(request);
+ assertEquals(request.getCurrentSelectedConfig().SSID,
+ parceled.getCurrentSelectedConfig().SSID);
+ assertEquals(request.getRequiredCapabilities(), parceled.getRequiredCapabilities());
+ ScanResult[] parceledScanResults = parceled.getScanResults();
+ assertNull(parceledScanResults);
+ }
+
+ private RecommendationRequest passThroughParcel(RecommendationRequest request) {
+ Parcel p = Parcel.obtain();
+ RecommendationRequest output = null;
+ try {
+ request.writeToParcel(p, 0);
+ p.setDataPosition(0);
+ output = RecommendationRequest.CREATOR.createFromParcel(p);
+ } finally {
+ p.recycle();
+ }
+ assertNotNull(output);
+ return output;
+ }
+}
diff --git a/core/tests/coretests/src/android/net/ScoredNetworkTest.java b/core/tests/coretests/src/android/net/ScoredNetworkTest.java
new file mode 100644
index 0000000..9c3346e
--- /dev/null
+++ b/core/tests/coretests/src/android/net/ScoredNetworkTest.java
@@ -0,0 +1,169 @@
+/*
+ t Copyright (C) 2016 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;
+
+import static org.junit.Assert.*;
+
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Parcel;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Arrays;
+
+/** Unit tests for {@link ScoredNetwork}. */
+@RunWith(AndroidJUnit4.class)
+public class ScoredNetworkTest {
+
+ private static final int RSSI_START = -110;
+ private static final int TEST_RSSI = -50;
+ private static final byte TEST_SCORE = 5;
+ private static final RssiCurve CURVE =
+ new RssiCurve(RSSI_START, 10, new byte[] {-1, 0, 1, 2, 3, 4, TEST_SCORE, 6, 7});
+
+ private static final byte RANKING_SCORE_OFFSET = 13;
+ private static final Bundle ATTRIBUTES;
+ static {
+ ATTRIBUTES = new Bundle();
+ ATTRIBUTES.putInt(
+ ScoredNetwork.ATTRIBUTES_KEY_RANKING_SCORE_OFFSET, RANKING_SCORE_OFFSET);
+ }
+
+ private static final NetworkKey KEY
+ = new NetworkKey(new WifiKey("\"ssid\"", "00:00:00:00:00:00"));
+
+ @Test
+ public void calculateRankingOffsetShouldThrowUnsupportedOperationException() {
+ // No curve or ranking score offset set in curve
+ ScoredNetwork scoredNetwork = new ScoredNetwork(KEY, null);
+ try {
+ scoredNetwork.calculateRankingScore(TEST_RSSI);
+ fail("Should have thrown UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void calculateRankingOffsetWithRssiCurveShouldReturnExpectedScore() {
+ ScoredNetwork scoredNetwork = new ScoredNetwork(KEY, CURVE);
+ assertEquals(TEST_SCORE << Byte.SIZE, scoredNetwork.calculateRankingScore(TEST_RSSI));
+ }
+
+ @Test
+ public void rankingScoresShouldDifferByRankingScoreOffset() {
+ ScoredNetwork scoredNetwork1 = new ScoredNetwork(KEY, CURVE);
+ ScoredNetwork scoredNetwork2
+ = new ScoredNetwork(KEY, CURVE, false /* meteredHint */, ATTRIBUTES);
+ int scoreDifference =
+ scoredNetwork2.calculateRankingScore(TEST_RSSI)
+ - scoredNetwork1.calculateRankingScore(TEST_RSSI);
+ assertEquals(RANKING_SCORE_OFFSET, scoreDifference);
+ }
+
+ @Test
+ public void calculateRankingScoreShouldNotResultInIntegerOverflow() {
+ Bundle attr = new Bundle();
+ attr.putInt(ScoredNetwork.ATTRIBUTES_KEY_RANKING_SCORE_OFFSET, Integer.MAX_VALUE);
+ ScoredNetwork scoredNetwork
+ = new ScoredNetwork(KEY, CURVE, false /* meteredHint */, attr);
+ assertEquals(Integer.MAX_VALUE, scoredNetwork.calculateRankingScore(TEST_RSSI));
+ }
+
+ @Test
+ public void calculateRankingScoreShouldNotResultInIntegerUnderflow() {
+ Bundle attr = new Bundle();
+ attr.putInt(ScoredNetwork.ATTRIBUTES_KEY_RANKING_SCORE_OFFSET, Integer.MIN_VALUE);
+ ScoredNetwork scoredNetwork =
+ new ScoredNetwork(KEY, CURVE, false /* meteredHint */, attr);
+ assertEquals(Integer.MIN_VALUE, scoredNetwork.calculateRankingScore(RSSI_START));
+ }
+
+ @Test
+ public void hasRankingScoreShouldReturnFalse() {
+ ScoredNetwork network = new ScoredNetwork(KEY, null /* rssiCurve */);
+ assertFalse(network.hasRankingScore());
+ }
+
+ @Test
+ public void hasRankingScoreShouldReturnTrueWhenAttributesHasRankingScoreOffset() {
+ ScoredNetwork network =
+ new ScoredNetwork(KEY, null /* rssiCurve */, false /* meteredHint */, ATTRIBUTES);
+ assertTrue(network.hasRankingScore());
+ }
+
+ @Test
+ public void hasRankingScoreShouldReturnTrueWhenCurveIsPresent() {
+ ScoredNetwork network =
+ new ScoredNetwork(KEY, CURVE , false /* meteredHint */);
+ assertTrue(network.hasRankingScore());
+ }
+
+ @Test
+ public void shouldWriteAndReadFromParcelWhenAllFieldsSet() {
+ ScoredNetwork network = new ScoredNetwork(KEY, CURVE, true /* meteredHint */, ATTRIBUTES);
+ ScoredNetwork newNetwork;
+
+ Parcel parcel = null;
+ try {
+ parcel = Parcel.obtain();
+ network.writeToParcel(parcel, 0 /* flags */);
+ parcel.setDataPosition(0);
+ newNetwork = ScoredNetwork.CREATOR.createFromParcel(parcel);
+ } finally {
+ if (parcel != null) {
+ parcel.recycle();
+ }
+ }
+ assertEquals(CURVE.start, newNetwork.rssiCurve.start);
+ assertEquals(CURVE.bucketWidth, newNetwork.rssiCurve.bucketWidth);
+ assertTrue(Arrays.equals(CURVE.rssiBuckets, newNetwork.rssiCurve.rssiBuckets));
+ assertTrue(newNetwork.meteredHint);
+ assertNotNull(newNetwork.attributes);
+ assertEquals(
+ RANKING_SCORE_OFFSET,
+ newNetwork.attributes.getInt(ScoredNetwork.ATTRIBUTES_KEY_RANKING_SCORE_OFFSET));
+ }
+
+ @Test
+ public void shouldWriteAndReadFromParcelWithoutBundle() {
+ ScoredNetwork network = new ScoredNetwork(KEY, CURVE, true /* meteredHint */);
+ ScoredNetwork newNetwork;
+
+ Parcel parcel = null;
+ try {
+ parcel = Parcel.obtain();
+ network.writeToParcel(parcel, 0 /* flags */);
+ parcel.setDataPosition(0);
+ newNetwork = ScoredNetwork.CREATOR.createFromParcel(parcel);
+ } finally {
+ if (parcel != null) {
+ parcel.recycle();
+ }
+ }
+ assertEquals(CURVE.start, newNetwork.rssiCurve.start);
+ assertEquals(CURVE.bucketWidth, newNetwork.rssiCurve.bucketWidth);
+ assertTrue(Arrays.equals(CURVE.rssiBuckets, newNetwork.rssiCurve.rssiBuckets));
+ assertTrue(newNetwork.meteredHint);
+ assertNull(newNetwork.attributes);
+ }
+}
diff --git a/core/tests/coretests/src/android/util/TokenBucketTest.java b/core/tests/coretests/src/android/util/TokenBucketTest.java
new file mode 100644
index 0000000..f7ac20c
--- /dev/null
+++ b/core/tests/coretests/src/android/util/TokenBucketTest.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2016 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.internal.util;
+
+import android.os.SystemClock;
+import android.text.format.DateUtils;
+import junit.framework.TestCase;
+
+public class TokenBucketTest extends TestCase {
+
+ static final int FILL_DELTA_VERY_SHORT = 1;
+ static final int FILL_DELTA_VERY_LONG = Integer.MAX_VALUE;
+
+ public void testArgumentValidation() {
+ assertThrow(() -> new TokenBucket(0, 1, 1));
+ assertThrow(() -> new TokenBucket(1, 0, 1));
+ assertThrow(() -> new TokenBucket(1, 1, 0));
+ assertThrow(() -> new TokenBucket(0, 1));
+ assertThrow(() -> new TokenBucket(1, 0));
+ assertThrow(() -> new TokenBucket(-1, 1, 1));
+ assertThrow(() -> new TokenBucket(1, -1, 1));
+ assertThrow(() -> new TokenBucket(1, 1, -1));
+ assertThrow(() -> new TokenBucket(-1, 1));
+ assertThrow(() -> new TokenBucket(1, -1));
+
+ new TokenBucket(1000, 100, 0);
+ new TokenBucket(1000, 100, 10);
+ new TokenBucket(5000, 50);
+ new TokenBucket(5000, 1);
+ }
+
+ public void testInitialCapacity() {
+ drain(new TokenBucket(FILL_DELTA_VERY_LONG, 1), 1);
+ drain(new TokenBucket(FILL_DELTA_VERY_LONG, 10), 10);
+ drain(new TokenBucket(FILL_DELTA_VERY_LONG, 1000), 1000);
+
+ drain(new TokenBucket(FILL_DELTA_VERY_LONG, 10, 0), 0);
+ drain(new TokenBucket(FILL_DELTA_VERY_LONG, 10, 3), 3);
+ drain(new TokenBucket(FILL_DELTA_VERY_LONG, 10, 10), 10);
+
+ drain(new TokenBucket(FILL_DELTA_VERY_LONG, 10, 100), 10);
+
+ drain(new TokenBucket((int)DateUtils.MINUTE_IN_MILLIS, 50), 50);
+ drain(new TokenBucket((int)DateUtils.HOUR_IN_MILLIS, 10), 10);
+ drain(new TokenBucket((int)DateUtils.DAY_IN_MILLIS, 200), 200);
+ }
+
+ public void testReset() {
+ TokenBucket tb = new TokenBucket(FILL_DELTA_VERY_LONG, 100, 10);
+ drain(tb, 10);
+
+ tb.reset(50);
+ drain(tb, 50);
+
+ tb.reset(50);
+ getOneByOne(tb, 10);
+ assertTrue(tb.has());
+
+ tb.reset(30);
+ drain(tb, 30);
+ }
+
+ public void testFill() throws Exception {
+ int delta = 50;
+ TokenBucket tb = new TokenBucket(delta, 10, 0);
+
+ assertEmpty(tb);
+
+ Thread.sleep(3 * delta / 2);
+
+ assertTrue(tb.has());
+ }
+
+ public void testRefill() throws Exception {
+ TokenBucket tb = new TokenBucket(FILL_DELTA_VERY_SHORT, 10, 10);
+
+ assertEquals(5, tb.get(5));
+ assertEquals(5, tb.get(5));
+
+ while (tb.available() < 10) {
+ Thread.sleep(2);
+ }
+
+ assertEquals(10, tb.get(10));
+
+ while (tb.available() < 10) {
+ Thread.sleep(2);
+ }
+
+ assertEquals(10, tb.get(100));
+ }
+
+ public void testAverage() throws Exception {
+ final int delta = 3;
+ final int want = 60;
+
+ long start = SystemClock.elapsedRealtime();
+ TokenBucket tb = new TokenBucket(delta, 20, 0);
+
+ for (int i = 0; i < want; i++) {
+ while (!tb.has()) {
+ Thread.sleep(5 * delta);
+ }
+ tb.get();
+ }
+
+ assertDuration(want * delta, SystemClock.elapsedRealtime() - start);
+ }
+
+ public void testBurst() throws Exception {
+ final int delta = 2;
+ final int capacity = 20;
+ final int want = 100;
+
+ long start = SystemClock.elapsedRealtime();
+ TokenBucket tb = new TokenBucket(delta, capacity, 0);
+
+ int total = 0;
+ while (total < want) {
+ while (!tb.has()) {
+ Thread.sleep(capacity * delta - 2);
+ }
+ total += tb.get(tb.available());
+ }
+
+ assertDuration(total * delta, SystemClock.elapsedRealtime() - start);
+ }
+
+ static void getOneByOne(TokenBucket tb, int n) {
+ while (n > 0) {
+ assertTrue(tb.has());
+ assertTrue(tb.available() >= n);
+ assertTrue(tb.get());
+ assertTrue(tb.available() >= n - 1);
+ n--;
+ }
+ }
+
+ void assertEmpty(TokenBucket tb) {
+ assertFalse(tb.has());
+ assertEquals(0, tb.available());
+ assertFalse(tb.get());
+ }
+
+ void drain(TokenBucket tb, int n) {
+ getOneByOne(tb, n);
+ assertEmpty(tb);
+ }
+
+ void assertDuration(long expected, long elapsed) {
+ String msg = String.format(
+ "expected elapsed time at least %d ms, but was %d ms", expected, elapsed);
+ elapsed += 1; // one millisecond extra guard
+ assertTrue(msg, elapsed >= expected);
+ }
+
+ void assertThrow(Fn fn) {
+ try {
+ fn.call();
+ fail("expected n exception to be thrown.");
+ } catch (Throwable t) {}
+ }
+
+ interface Fn { void call(); }
+}
diff --git a/core/tests/coretests/src/com/android/internal/net/NetworkStatsFactoryTest.java b/core/tests/coretests/src/com/android/internal/net/NetworkStatsFactoryTest.java
index 327f3fd..7f13abc 100644
--- a/core/tests/coretests/src/com/android/internal/net/NetworkStatsFactoryTest.java
+++ b/core/tests/coretests/src/com/android/internal/net/NetworkStatsFactoryTest.java
@@ -16,6 +16,7 @@
package com.android.internal.net;
+import static android.net.NetworkStats.METERED_NO;
import static android.net.NetworkStats.ROAMING_NO;
import static android.net.NetworkStats.SET_ALL;
import static android.net.NetworkStats.SET_DEFAULT;
@@ -101,12 +102,14 @@
final NetworkStats stats = mFactory.readNetworkStatsDetail();
assertEquals(70, stats.size());
- assertStatsEntry(stats, "rmnet1", 10021, SET_DEFAULT, 0x30100000, 219110L, 578L, 227423L, 676L);
+ assertStatsEntry(stats, "rmnet1", 10021, SET_DEFAULT, 0x30100000, 219110L, 578L, 227423L,
+ 676L);
assertStatsEntry(stats, "rmnet1", 10021, SET_FOREGROUND, 0x30100000, 742L, 3L, 1265L, 3L);
}
public void testNetworkStatsSingle() throws Exception {
- stageFile(R.raw.xt_qtaguid_iface_typical, new File(mTestProc, "net/xt_qtaguid/iface_stat_all"));
+ stageFile(R.raw.xt_qtaguid_iface_typical,
+ new File(mTestProc, "net/xt_qtaguid/iface_stat_all"));
final NetworkStats stats = mFactory.readNetworkStatsSummaryDev();
assertEquals(6, stats.size());
@@ -122,7 +125,8 @@
final NetworkStats stats = mFactory.readNetworkStatsSummaryXt();
assertEquals(3, stats.size());
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_ALL, TAG_NONE, 6824L, 16L, 5692L, 10L);
- assertStatsEntry(stats, "rmnet1", UID_ALL, SET_ALL, TAG_NONE, 11153922L, 8051L, 190226L, 2468L);
+ assertStatsEntry(stats, "rmnet1", UID_ALL, SET_ALL, TAG_NONE, 11153922L, 8051L, 190226L,
+ 2468L);
assertStatsEntry(stats, "rmnet2", UID_ALL, SET_ALL, TAG_NONE, 4968L, 35L, 3081L, 39L);
}
@@ -157,7 +161,7 @@
private static void assertStatsEntry(NetworkStats stats, String iface, int uid, int set,
int tag, long rxBytes, long txBytes) {
- final int i = stats.findIndex(iface, uid, set, tag, ROAMING_NO);
+ final int i = stats.findIndex(iface, uid, set, tag, METERED_NO, ROAMING_NO);
final NetworkStats.Entry entry = stats.getValues(i, null);
assertEquals("unexpected rxBytes", rxBytes, entry.rxBytes);
assertEquals("unexpected txBytes", txBytes, entry.txBytes);
@@ -165,7 +169,7 @@
private static void assertStatsEntry(NetworkStats stats, String iface, int uid, int set,
int tag, long rxBytes, long rxPackets, long txBytes, long txPackets) {
- final int i = stats.findIndex(iface, uid, set, tag, ROAMING_NO);
+ final int i = stats.findIndex(iface, uid, set, tag, METERED_NO, ROAMING_NO);
final NetworkStats.Entry entry = stats.getValues(i, null);
assertEquals("unexpected rxBytes", rxBytes, entry.rxBytes);
assertEquals("unexpected rxPackets", rxPackets, entry.rxPackets);
diff --git a/legacy-test/Android.mk b/legacy-test/Android.mk
index 0011002..5e72a0d 100644
--- a/legacy-test/Android.mk
+++ b/legacy-test/Android.mk
@@ -21,10 +21,10 @@
# This contains the junit.framework classes that were in Android API level 25.
include $(CLEAR_VARS)
-LOCAL_NO_STANDARD_LIBRARIES := true
-LOCAL_STATIC_JAVA_LIBRARIES := core-junit-static
-
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_MODULE := legacy-test
+LOCAL_NO_STANDARD_LIBRARIES := true
+LOCAL_JAVA_LIBRARIES := core-oj core-libart framework
include $(BUILD_JAVA_LIBRARY)
@@ -34,7 +34,7 @@
# This contains the android.test.PerformanceTestCase class only
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := ../core/java/android/test/PerformanceTestCase.java
+LOCAL_SRC_FILES := src/android/test/PerformanceTestCase.java
LOCAL_MODULE := legacy-performance-test-hostdex
include $(BUILD_HOST_DALVIK_JAVA_LIBRARY)
diff --git a/core/java/android/test/AndroidTestCase.java b/legacy-test/src/android/test/AndroidTestCase.java
similarity index 100%
rename from core/java/android/test/AndroidTestCase.java
rename to legacy-test/src/android/test/AndroidTestCase.java
diff --git a/core/java/android/test/FlakyTest.java b/legacy-test/src/android/test/FlakyTest.java
similarity index 100%
rename from core/java/android/test/FlakyTest.java
rename to legacy-test/src/android/test/FlakyTest.java
diff --git a/core/java/android/test/InstrumentationTestCase.java b/legacy-test/src/android/test/InstrumentationTestCase.java
similarity index 100%
rename from core/java/android/test/InstrumentationTestCase.java
rename to legacy-test/src/android/test/InstrumentationTestCase.java
diff --git a/core/java/android/test/InstrumentationTestSuite.java b/legacy-test/src/android/test/InstrumentationTestSuite.java
similarity index 100%
rename from core/java/android/test/InstrumentationTestSuite.java
rename to legacy-test/src/android/test/InstrumentationTestSuite.java
diff --git a/core/java/android/test/PerformanceTestCase.java b/legacy-test/src/android/test/PerformanceTestCase.java
similarity index 100%
rename from core/java/android/test/PerformanceTestCase.java
rename to legacy-test/src/android/test/PerformanceTestCase.java
diff --git a/core/java/android/test/RepetitiveTest.java b/legacy-test/src/android/test/RepetitiveTest.java
similarity index 100%
rename from core/java/android/test/RepetitiveTest.java
rename to legacy-test/src/android/test/RepetitiveTest.java
diff --git a/core/java/android/test/UiThreadTest.java b/legacy-test/src/android/test/UiThreadTest.java
similarity index 100%
rename from core/java/android/test/UiThreadTest.java
rename to legacy-test/src/android/test/UiThreadTest.java
diff --git a/core/java/android/test/package.html b/legacy-test/src/android/test/package.html
similarity index 100%
rename from core/java/android/test/package.html
rename to legacy-test/src/android/test/package.html
diff --git a/core/java/android/test/suitebuilder/annotation/LargeTest.java b/legacy-test/src/android/test/suitebuilder/annotation/LargeTest.java
similarity index 100%
rename from core/java/android/test/suitebuilder/annotation/LargeTest.java
rename to legacy-test/src/android/test/suitebuilder/annotation/LargeTest.java
diff --git a/core/java/android/test/suitebuilder/annotation/MediumTest.java b/legacy-test/src/android/test/suitebuilder/annotation/MediumTest.java
similarity index 100%
rename from core/java/android/test/suitebuilder/annotation/MediumTest.java
rename to legacy-test/src/android/test/suitebuilder/annotation/MediumTest.java
diff --git a/core/java/android/test/suitebuilder/annotation/SmallTest.java b/legacy-test/src/android/test/suitebuilder/annotation/SmallTest.java
similarity index 100%
rename from core/java/android/test/suitebuilder/annotation/SmallTest.java
rename to legacy-test/src/android/test/suitebuilder/annotation/SmallTest.java
diff --git a/core/java/android/test/suitebuilder/annotation/Smoke.java b/legacy-test/src/android/test/suitebuilder/annotation/Smoke.java
similarity index 100%
rename from core/java/android/test/suitebuilder/annotation/Smoke.java
rename to legacy-test/src/android/test/suitebuilder/annotation/Smoke.java
diff --git a/core/java/android/test/suitebuilder/annotation/Suppress.java b/legacy-test/src/android/test/suitebuilder/annotation/Suppress.java
similarity index 100%
rename from core/java/android/test/suitebuilder/annotation/Suppress.java
rename to legacy-test/src/android/test/suitebuilder/annotation/Suppress.java
diff --git a/legacy-test/src/junit/MODULE_LICENSE_CPL b/legacy-test/src/junit/MODULE_LICENSE_CPL
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/legacy-test/src/junit/MODULE_LICENSE_CPL
diff --git a/legacy-test/src/junit/README.android b/legacy-test/src/junit/README.android
new file mode 100644
index 0000000..1384a1f
--- /dev/null
+++ b/legacy-test/src/junit/README.android
@@ -0,0 +1,11 @@
+URL: https://github.com/junit-team/junit4
+License: Common Public License Version 1.0
+License File: cpl-v10.html
+
+This is JUnit 4.10 source that was previously part of the Android Public API.
+Where necessary it has been patched to be compatible (according to Android API
+requirements) with JUnit 3.8.
+
+These are copied here to ensure that the android.test.runner target remains
+compatible with the last version of the Android API (25) that contained these
+classes even when external/junit is upgraded to a later version.
diff --git a/legacy-test/src/junit/cpl-v10.html b/legacy-test/src/junit/cpl-v10.html
new file mode 100644
index 0000000..36aa208
--- /dev/null
+++ b/legacy-test/src/junit/cpl-v10.html
@@ -0,0 +1,125 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<HTML>
+<HEAD>
+<TITLE>Common Public License - v 1.0</TITLE>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</HEAD>
+
+<BODY BGCOLOR="#FFFFFF" VLINK="#800000">
+
+
+<P ALIGN="CENTER"><B>Common Public License - v 1.0</B>
+<P><B></B><FONT SIZE="3"></FONT>
+<P><FONT SIZE="3"></FONT><FONT SIZE="2">THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.</FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"><B>1. DEFINITIONS</B></FONT>
+<P><FONT SIZE="2">"Contribution" means:</FONT>
+
+<UL><FONT SIZE="2">a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and<BR CLEAR="LEFT">
+b) in the case of each subsequent Contributor:</FONT></UL>
+
+
+<UL><FONT SIZE="2">i) changes to the Program, and</FONT></UL>
+
+
+<UL><FONT SIZE="2">ii) additions to the Program;</FONT></UL>
+
+
+<UL><FONT SIZE="2">where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. </FONT><FONT SIZE="2">A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. </FONT><FONT SIZE="2">Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. </FONT></UL>
+
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">"Contributor" means any person or entity that distributes the Program.</FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. </FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2">"Program" means the Contributions distributed in accordance with this Agreement.</FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.</FONT>
+<P><FONT SIZE="2"><B></B></FONT>
+<P><FONT SIZE="2"><B>2. GRANT OF RIGHTS</B></FONT>
+
+<UL><FONT SIZE="2"></FONT><FONT SIZE="2">a) </FONT><FONT SIZE="2">Subject to the terms of this Agreement, each Contributor hereby grants</FONT><FONT SIZE="2"> Recipient a non-exclusive, worldwide, royalty-free copyright license to</FONT><FONT SIZE="2" COLOR="#FF0000"> </FONT><FONT SIZE="2">reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.</FONT></UL>
+
+
+<UL><FONT SIZE="2"></FONT></UL>
+
+
+<UL><FONT SIZE="2"></FONT><FONT SIZE="2">b) Subject to the terms of this Agreement, each Contributor hereby grants </FONT><FONT SIZE="2">Recipient a non-exclusive, worldwide,</FONT><FONT SIZE="2" COLOR="#008000"> </FONT><FONT SIZE="2">royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. </FONT></UL>
+
+
+<UL><FONT SIZE="2"></FONT></UL>
+
+
+<UL><FONT SIZE="2">c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.</FONT></UL>
+
+
+<UL><FONT SIZE="2"></FONT></UL>
+
+
+<UL><FONT SIZE="2">d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. </FONT></UL>
+
+
+<UL><FONT SIZE="2"></FONT></UL>
+
+<P><FONT SIZE="2"><B>3. REQUIREMENTS</B></FONT>
+<P><FONT SIZE="2"><B></B>A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:</FONT>
+
+<UL><FONT SIZE="2">a) it complies with the terms and conditions of this Agreement; and</FONT></UL>
+
+
+<UL><FONT SIZE="2">b) its license agreement:</FONT></UL>
+
+
+<UL><FONT SIZE="2">i) effectively disclaims</FONT><FONT SIZE="2"> on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; </FONT></UL>
+
+
+<UL><FONT SIZE="2">ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; </FONT></UL>
+
+
+<UL><FONT SIZE="2">iii)</FONT><FONT SIZE="2"> states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and</FONT></UL>
+
+
+<UL><FONT SIZE="2">iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.</FONT><FONT SIZE="2" COLOR="#0000FF"> </FONT><FONT SIZE="2" COLOR="#FF0000"></FONT></UL>
+
+
+<UL><FONT SIZE="2" COLOR="#FF0000"></FONT><FONT SIZE="2"></FONT></UL>
+
+<P><FONT SIZE="2">When the Program is made available in source code form:</FONT>
+
+<UL><FONT SIZE="2">a) it must be made available under this Agreement; and </FONT></UL>
+
+
+<UL><FONT SIZE="2">b) a copy of this Agreement must be included with each copy of the Program. </FONT></UL>
+
+<P><FONT SIZE="2"></FONT><FONT SIZE="2" COLOR="#0000FF"><STRIKE></STRIKE></FONT>
+<P><FONT SIZE="2" COLOR="#0000FF"><STRIKE></STRIKE></FONT><FONT SIZE="2">Contributors may not remove or alter any copyright notices contained within the Program. </FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. </FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"><B>4. COMMERCIAL DISTRIBUTION</B></FONT>
+<P><FONT SIZE="2">Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.</FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.</FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2" COLOR="#0000FF"></FONT>
+<P><FONT SIZE="2" COLOR="#0000FF"></FONT><FONT SIZE="2"><B>5. NO WARRANTY</B></FONT>
+<P><FONT SIZE="2">EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is</FONT><FONT SIZE="2"> solely responsible for determining the appropriateness of using and distributing </FONT><FONT SIZE="2">the Program</FONT><FONT SIZE="2"> and assumes all risks associated with its exercise of rights under this Agreement</FONT><FONT SIZE="2">, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, </FONT><FONT SIZE="2">programs or equipment, and unavailability or interruption of operations</FONT><FONT SIZE="2">. </FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2"><B>6. DISCLAIMER OF LIABILITY</B></FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2">EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES </FONT><FONT SIZE="2">(INCLUDING WITHOUT LIMITATION LOST PROFITS),</FONT><FONT SIZE="2"> HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"><B>7. GENERAL</B></FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2">If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.</FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">If Recipient institutes patent litigation against a Contributor with respect to a patent applicable to software (including a cross-claim or counterclaim in a lawsuit), then any patent licenses granted by that Contributor to such Recipient under this Agreement shall terminate as of the date such litigation is filed. In addition, if Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. </FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. </FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2">Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to </FONT><FONT SIZE="2">publish new versions (including revisions) of this Agreement from time to </FONT><FONT SIZE="2">time. No one other than the Agreement Steward has the right to modify this Agreement. IBM is the initial Agreement Steward. IBM may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. </FONT><FONT SIZE="2">Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new </FONT><FONT SIZE="2">version. </FONT><FONT SIZE="2">Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, </FONT><FONT SIZE="2">by implication, estoppel or otherwise</FONT><FONT SIZE="2">.</FONT><FONT SIZE="2"> All rights in the Program not expressly granted under this Agreement are reserved.</FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.</FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT>
+
+</BODY>
+
+</HTML>
\ No newline at end of file
diff --git a/legacy-test/src/junit/framework/Assert.java b/legacy-test/src/junit/framework/Assert.java
new file mode 100644
index 0000000..3dcc23d
--- /dev/null
+++ b/legacy-test/src/junit/framework/Assert.java
@@ -0,0 +1,296 @@
+package junit.framework;
+
+/**
+ * A set of assert methods. Messages are only displayed when an assert fails.
+ */
+
+public class Assert {
+ /**
+ * Protect constructor since it is a static only class
+ */
+ protected Assert() {
+ }
+
+ /**
+ * Asserts that a condition is true. If it isn't it throws
+ * an AssertionFailedError with the given message.
+ */
+ static public void assertTrue(String message, boolean condition) {
+ if (!condition)
+ fail(message);
+ }
+ /**
+ * Asserts that a condition is true. If it isn't it throws
+ * an AssertionFailedError.
+ */
+ static public void assertTrue(boolean condition) {
+ assertTrue(null, condition);
+ }
+ /**
+ * Asserts that a condition is false. If it isn't it throws
+ * an AssertionFailedError with the given message.
+ */
+ static public void assertFalse(String message, boolean condition) {
+ assertTrue(message, !condition);
+ }
+ /**
+ * Asserts that a condition is false. If it isn't it throws
+ * an AssertionFailedError.
+ */
+ static public void assertFalse(boolean condition) {
+ assertFalse(null, condition);
+ }
+ /**
+ * Fails a test with the given message.
+ */
+ static public void fail(String message) {
+ if (message == null) {
+ throw new AssertionFailedError();
+ }
+ throw new AssertionFailedError(message);
+ }
+ /**
+ * Fails a test with no message.
+ */
+ static public void fail() {
+ fail(null);
+ }
+ /**
+ * Asserts that two objects are equal. If they are not
+ * an AssertionFailedError is thrown with the given message.
+ */
+ static public void assertEquals(String message, Object expected, Object actual) {
+ if (expected == null && actual == null)
+ return;
+ if (expected != null && expected.equals(actual))
+ return;
+ failNotEquals(message, expected, actual);
+ }
+ /**
+ * Asserts that two objects are equal. If they are not
+ * an AssertionFailedError is thrown.
+ */
+ static public void assertEquals(Object expected, Object actual) {
+ assertEquals(null, expected, actual);
+ }
+ /**
+ * Asserts that two Strings are equal.
+ */
+ static public void assertEquals(String message, String expected, String actual) {
+ if (expected == null && actual == null)
+ return;
+ if (expected != null && expected.equals(actual))
+ return;
+ String cleanMessage= message == null ? "" : message;
+ throw new ComparisonFailure(cleanMessage, expected, actual);
+ }
+ /**
+ * Asserts that two Strings are equal.
+ */
+ static public void assertEquals(String expected, String actual) {
+ assertEquals(null, expected, actual);
+ }
+ /**
+ * Asserts that two doubles are equal concerning a delta. If they are not
+ * an AssertionFailedError is thrown with the given message. If the expected
+ * value is infinity then the delta value is ignored.
+ */
+ static public void assertEquals(String message, double expected, double actual, double delta) {
+ if (Double.compare(expected, actual) == 0)
+ return;
+ if (!(Math.abs(expected-actual) <= delta))
+ failNotEquals(message, new Double(expected), new Double(actual));
+ }
+ /**
+ * Asserts that two doubles are equal concerning a delta. If the expected
+ * value is infinity then the delta value is ignored.
+ */
+ static public void assertEquals(double expected, double actual, double delta) {
+ assertEquals(null, expected, actual, delta);
+ }
+ /**
+ * Asserts that two floats are equal concerning a positive delta. If they
+ * are not an AssertionFailedError is thrown with the given message. If the
+ * expected value is infinity then the delta value is ignored.
+ */
+ static public void assertEquals(String message, float expected, float actual, float delta) {
+ if (Float.compare(expected, actual) == 0)
+ return;
+ if (!(Math.abs(expected - actual) <= delta))
+ failNotEquals(message, new Float(expected), new Float(actual));
+ }
+ /**
+ * Asserts that two floats are equal concerning a delta. If the expected
+ * value is infinity then the delta value is ignored.
+ */
+ static public void assertEquals(float expected, float actual, float delta) {
+ assertEquals(null, expected, actual, delta);
+ }
+ /**
+ * Asserts that two longs are equal. If they are not
+ * an AssertionFailedError is thrown with the given message.
+ */
+ static public void assertEquals(String message, long expected, long actual) {
+ assertEquals(message, new Long(expected), new Long(actual));
+ }
+ /**
+ * Asserts that two longs are equal.
+ */
+ static public void assertEquals(long expected, long actual) {
+ assertEquals(null, expected, actual);
+ }
+ /**
+ * Asserts that two booleans are equal. If they are not
+ * an AssertionFailedError is thrown with the given message.
+ */
+ static public void assertEquals(String message, boolean expected, boolean actual) {
+ assertEquals(message, Boolean.valueOf(expected), Boolean.valueOf(actual));
+ }
+ /**
+ * Asserts that two booleans are equal.
+ */
+ static public void assertEquals(boolean expected, boolean actual) {
+ assertEquals(null, expected, actual);
+ }
+ /**
+ * Asserts that two bytes are equal. If they are not
+ * an AssertionFailedError is thrown with the given message.
+ */
+ static public void assertEquals(String message, byte expected, byte actual) {
+ assertEquals(message, new Byte(expected), new Byte(actual));
+ }
+ /**
+ * Asserts that two bytes are equal.
+ */
+ static public void assertEquals(byte expected, byte actual) {
+ assertEquals(null, expected, actual);
+ }
+ /**
+ * Asserts that two chars are equal. If they are not
+ * an AssertionFailedError is thrown with the given message.
+ */
+ static public void assertEquals(String message, char expected, char actual) {
+ assertEquals(message, new Character(expected), new Character(actual));
+ }
+ /**
+ * Asserts that two chars are equal.
+ */
+ static public void assertEquals(char expected, char actual) {
+ assertEquals(null, expected, actual);
+ }
+ /**
+ * Asserts that two shorts are equal. If they are not
+ * an AssertionFailedError is thrown with the given message.
+ */
+ static public void assertEquals(String message, short expected, short actual) {
+ assertEquals(message, new Short(expected), new Short(actual));
+ }
+ /**
+ * Asserts that two shorts are equal.
+ */
+ static public void assertEquals(short expected, short actual) {
+ assertEquals(null, expected, actual);
+ }
+ /**
+ * Asserts that two ints are equal. If they are not
+ * an AssertionFailedError is thrown with the given message.
+ */
+ static public void assertEquals(String message, int expected, int actual) {
+ assertEquals(message, new Integer(expected), new Integer(actual));
+ }
+ /**
+ * Asserts that two ints are equal.
+ */
+ static public void assertEquals(int expected, int actual) {
+ assertEquals(null, expected, actual);
+ }
+ /**
+ * Asserts that an object isn't null.
+ */
+ static public void assertNotNull(Object object) {
+ assertNotNull(null, object);
+ }
+ /**
+ * Asserts that an object isn't null. If it is
+ * an AssertionFailedError is thrown with the given message.
+ */
+ static public void assertNotNull(String message, Object object) {
+ assertTrue(message, object != null);
+ }
+ /**
+ * Asserts that an object is null. If it isn't an {@link AssertionError} is
+ * thrown.
+ * Message contains: Expected: <null> but was: object
+ *
+ * @param object
+ * Object to check or <code>null</code>
+ */
+ static public void assertNull(Object object) {
+ String message = "Expected: <null> but was: " + String.valueOf(object);
+ assertNull(message, object);
+ }
+ /**
+ * Asserts that an object is null. If it is not
+ * an AssertionFailedError is thrown with the given message.
+ */
+ static public void assertNull(String message, Object object) {
+ assertTrue(message, object == null);
+ }
+ /**
+ * Asserts that two objects refer to the same object. If they are not
+ * an AssertionFailedError is thrown with the given message.
+ */
+ static public void assertSame(String message, Object expected, Object actual) {
+ if (expected == actual)
+ return;
+ failNotSame(message, expected, actual);
+ }
+ /**
+ * Asserts that two objects refer to the same object. If they are not
+ * the same an AssertionFailedError is thrown.
+ */
+ static public void assertSame(Object expected, Object actual) {
+ assertSame(null, expected, actual);
+ }
+ /**
+ * Asserts that two objects do not refer to the same object. If they do
+ * refer to the same object an AssertionFailedError is thrown with the
+ * given message.
+ */
+ static public void assertNotSame(String message, Object expected, Object actual) {
+ if (expected == actual)
+ failSame(message);
+ }
+ /**
+ * Asserts that two objects do not refer to the same object. If they do
+ * refer to the same object an AssertionFailedError is thrown.
+ */
+ static public void assertNotSame(Object expected, Object actual) {
+ assertNotSame(null, expected, actual);
+ }
+
+ static public void failSame(String message) {
+ String formatted= "";
+ if (message != null)
+ formatted= message+" ";
+ fail(formatted+"expected not same");
+ }
+
+ static public void failNotSame(String message, Object expected, Object actual) {
+ String formatted= "";
+ if (message != null)
+ formatted= message+" ";
+ fail(formatted+"expected same:<"+expected+"> was not:<"+actual+">");
+ }
+
+ static public void failNotEquals(String message, Object expected, Object actual) {
+ fail(format(message, expected, actual));
+ }
+
+ public static String format(String message, Object expected, Object actual) {
+ String formatted= "";
+ if (message != null && message.length() > 0)
+ formatted= message+" ";
+ return formatted+"expected:<"+expected+"> but was:<"+actual+">";
+ }
+}
diff --git a/legacy-test/src/junit/framework/AssertionFailedError.java b/legacy-test/src/junit/framework/AssertionFailedError.java
new file mode 100644
index 0000000..0d7802c
--- /dev/null
+++ b/legacy-test/src/junit/framework/AssertionFailedError.java
@@ -0,0 +1,20 @@
+package junit.framework;
+
+/**
+ * Thrown when an assertion failed.
+ */
+public class AssertionFailedError extends AssertionError {
+
+ private static final long serialVersionUID= 1L;
+
+ public AssertionFailedError() {
+ }
+
+ public AssertionFailedError(String message) {
+ super(defaultString(message));
+ }
+
+ private static String defaultString(String message) {
+ return message == null ? "" : message;
+ }
+}
\ No newline at end of file
diff --git a/legacy-test/src/junit/framework/ComparisonCompactor.java b/legacy-test/src/junit/framework/ComparisonCompactor.java
new file mode 100644
index 0000000..e540f03
--- /dev/null
+++ b/legacy-test/src/junit/framework/ComparisonCompactor.java
@@ -0,0 +1,87 @@
+package junit.framework;
+
+// android-changed add @hide
+/**
+ * @hide not needed for public API
+ */
+public class ComparisonCompactor {
+
+ private static final String ELLIPSIS= "...";
+ private static final String DELTA_END= "]";
+ private static final String DELTA_START= "[";
+
+ private int fContextLength;
+ private String fExpected;
+ private String fActual;
+ private int fPrefix;
+ private int fSuffix;
+
+ public ComparisonCompactor(int contextLength, String expected, String actual) {
+ fContextLength= contextLength;
+ fExpected= expected;
+ fActual= actual;
+ }
+
+ public String compact(String message) {
+ if (fExpected == null || fActual == null || areStringsEqual()) {
+ // android-changed use local method instead of Assert.format, since
+ // the later is not part of Android API till API 16
+ return format(message, fExpected, fActual);
+ }
+ findCommonPrefix();
+ findCommonSuffix();
+ String expected= compactString(fExpected);
+ String actual= compactString(fActual);
+ // android-changed use local format method
+ return format(message, expected, actual);
+ }
+
+ private String compactString(String source) {
+ String result= DELTA_START + source.substring(fPrefix, source.length() - fSuffix + 1) + DELTA_END;
+ if (fPrefix > 0)
+ result= computeCommonPrefix() + result;
+ if (fSuffix > 0)
+ result= result + computeCommonSuffix();
+ return result;
+ }
+
+ private void findCommonPrefix() {
+ fPrefix= 0;
+ int end= Math.min(fExpected.length(), fActual.length());
+ for (; fPrefix < end; fPrefix++) {
+ if (fExpected.charAt(fPrefix) != fActual.charAt(fPrefix))
+ break;
+ }
+ }
+
+ private void findCommonSuffix() {
+ int expectedSuffix= fExpected.length() - 1;
+ int actualSuffix= fActual.length() - 1;
+ for (; actualSuffix >= fPrefix && expectedSuffix >= fPrefix; actualSuffix--, expectedSuffix--) {
+ if (fExpected.charAt(expectedSuffix) != fActual.charAt(actualSuffix))
+ break;
+ }
+ fSuffix= fExpected.length() - expectedSuffix;
+ }
+
+ private String computeCommonPrefix() {
+ return (fPrefix > fContextLength ? ELLIPSIS : "") + fExpected.substring(Math.max(0, fPrefix - fContextLength), fPrefix);
+ }
+
+ private String computeCommonSuffix() {
+ int end= Math.min(fExpected.length() - fSuffix + 1 + fContextLength, fExpected.length());
+ return fExpected.substring(fExpected.length() - fSuffix + 1, end) + (fExpected.length() - fSuffix + 1 < fExpected.length() - fContextLength ? ELLIPSIS : "");
+ }
+
+ private boolean areStringsEqual() {
+ return fExpected.equals(fActual);
+ }
+
+ // android-changed copy of Assert.format for reasons described above
+ private static String format(String message, Object expected, Object actual) {
+ String formatted= "";
+ if (message != null && message.length() > 0)
+ formatted= message+" ";
+ return formatted+"expected:<"+expected+"> but was:<"+actual+">";
+ }
+}
diff --git a/legacy-test/src/junit/framework/ComparisonFailure.java b/legacy-test/src/junit/framework/ComparisonFailure.java
new file mode 100644
index 0000000..5077993
--- /dev/null
+++ b/legacy-test/src/junit/framework/ComparisonFailure.java
@@ -0,0 +1,52 @@
+package junit.framework;
+
+/**
+ * Thrown when an assert equals for Strings failed.
+ *
+ * Inspired by a patch from Alex Chaffee mailto:alex@purpletech.com
+ */
+public class ComparisonFailure extends AssertionFailedError {
+ private static final int MAX_CONTEXT_LENGTH= 20;
+ private static final long serialVersionUID= 1L;
+
+ private String fExpected;
+ private String fActual;
+
+ /**
+ * Constructs a comparison failure.
+ * @param message the identifying message or null
+ * @param expected the expected string value
+ * @param actual the actual string value
+ */
+ public ComparisonFailure (String message, String expected, String actual) {
+ super (message);
+ fExpected= expected;
+ fActual= actual;
+ }
+
+ /**
+ * Returns "..." in place of common prefix and "..." in
+ * place of common suffix between expected and actual.
+ *
+ * @see Throwable#getMessage()
+ */
+ @Override
+ public String getMessage() {
+ return new ComparisonCompactor(MAX_CONTEXT_LENGTH, fExpected, fActual).compact(super.getMessage());
+ }
+
+ /**
+ * Gets the actual string value
+ * @return the actual string value
+ */
+ public String getActual() {
+ return fActual;
+ }
+ /**
+ * Gets the expected string value
+ * @return the expected string value
+ */
+ public String getExpected() {
+ return fExpected;
+ }
+}
\ No newline at end of file
diff --git a/legacy-test/src/junit/framework/Protectable.java b/legacy-test/src/junit/framework/Protectable.java
new file mode 100644
index 0000000..e143237
--- /dev/null
+++ b/legacy-test/src/junit/framework/Protectable.java
@@ -0,0 +1,14 @@
+package junit.framework;
+
+/**
+ * A <em>Protectable</em> can be run and can throw a Throwable.
+ *
+ * @see TestResult
+ */
+public interface Protectable {
+
+ /**
+ * Run the the following method protected.
+ */
+ public abstract void protect() throws Throwable;
+}
\ No newline at end of file
diff --git a/legacy-test/src/junit/framework/Test.java b/legacy-test/src/junit/framework/Test.java
new file mode 100644
index 0000000..a016ee8
--- /dev/null
+++ b/legacy-test/src/junit/framework/Test.java
@@ -0,0 +1,17 @@
+package junit.framework;
+
+/**
+ * A <em>Test</em> can be run and collect its results.
+ *
+ * @see TestResult
+ */
+public interface Test {
+ /**
+ * Counts the number of test cases that will be run by this test.
+ */
+ public abstract int countTestCases();
+ /**
+ * Runs a test and collects its result in a TestResult instance.
+ */
+ public abstract void run(TestResult result);
+}
\ No newline at end of file
diff --git a/legacy-test/src/junit/framework/TestCase.java b/legacy-test/src/junit/framework/TestCase.java
new file mode 100644
index 0000000..b047ec9
--- /dev/null
+++ b/legacy-test/src/junit/framework/TestCase.java
@@ -0,0 +1,212 @@
+package junit.framework;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+/**
+ * A test case defines the fixture to run multiple tests. To define a test case<br/>
+ * <ol>
+ * <li>implement a subclass of <code>TestCase</code></li>
+ * <li>define instance variables that store the state of the fixture</li>
+ * <li>initialize the fixture state by overriding {@link #setUp()}</li>
+ * <li>clean-up after a test by overriding {@link #tearDown()}.</li>
+ * </ol>
+ * Each test runs in its own fixture so there
+ * can be no side effects among test runs.
+ * Here is an example:
+ * <pre>
+ * public class MathTest extends TestCase {
+ * protected double fValue1;
+ * protected double fValue2;
+ *
+ * protected void setUp() {
+ * fValue1= 2.0;
+ * fValue2= 3.0;
+ * }
+ * }
+ * </pre>
+ *
+ * For each test implement a method which interacts
+ * with the fixture. Verify the expected results with assertions specified
+ * by calling {@link junit.framework.Assert#assertTrue(String, boolean)} with a boolean.
+ * <pre>
+ * public void testAdd() {
+ * double result= fValue1 + fValue2;
+ * assertTrue(result == 5.0);
+ * }
+ * </pre>
+ *
+ * Once the methods are defined you can run them. The framework supports
+ * both a static type safe and more dynamic way to run a test.
+ * In the static way you override the runTest method and define the method to
+ * be invoked. A convenient way to do so is with an anonymous inner class.
+ * <pre>
+ * TestCase test= new MathTest("add") {
+ * public void runTest() {
+ * testAdd();
+ * }
+ * };
+ * test.run();
+ * </pre>
+ *
+ * The dynamic way uses reflection to implement {@link #runTest()}. It dynamically finds
+ * and invokes a method.
+ * In this case the name of the test case has to correspond to the test method
+ * to be run.
+ * <pre>
+ * TestCase test= new MathTest("testAdd");
+ * test.run();
+ * </pre>
+ *
+ * The tests to be run can be collected into a TestSuite. JUnit provides
+ * different <i>test runners</i> which can run a test suite and collect the results.
+ * A test runner either expects a static method <code>suite</code> as the entry
+ * point to get a test to run or it will extract the suite automatically.
+ * <pre>
+ * public static Test suite() {
+ * suite.addTest(new MathTest("testAdd"));
+ * suite.addTest(new MathTest("testDivideByZero"));
+ * return suite;
+ * }
+ * </pre>
+ * @see TestResult
+ * @see TestSuite
+ */
+public abstract class TestCase extends Assert implements Test {
+ /**
+ * the name of the test case
+ */
+ private String fName;
+
+ /**
+ * No-arg constructor to enable serialization. This method
+ * is not intended to be used by mere mortals without calling setName().
+ */
+ public TestCase() {
+ fName= null;
+ }
+ /**
+ * Constructs a test case with the given name.
+ */
+ public TestCase(String name) {
+ fName= name;
+ }
+ /**
+ * Counts the number of test cases executed by run(TestResult result).
+ */
+ public int countTestCases() {
+ return 1;
+ }
+ /**
+ * Creates a default TestResult object
+ *
+ * @see TestResult
+ */
+ protected TestResult createResult() {
+ return new TestResult();
+ }
+ /**
+ * A convenience method to run this test, collecting the results with a
+ * default TestResult object.
+ *
+ * @see TestResult
+ */
+ public TestResult run() {
+ TestResult result= createResult();
+ run(result);
+ return result;
+ }
+ /**
+ * Runs the test case and collects the results in TestResult.
+ */
+ public void run(TestResult result) {
+ result.run(this);
+ }
+ /**
+ * Runs the bare test sequence.
+ * @throws Throwable if any exception is thrown
+ */
+ public void runBare() throws Throwable {
+ Throwable exception= null;
+ setUp();
+ try {
+ runTest();
+ } catch (Throwable running) {
+ exception= running;
+ }
+ finally {
+ try {
+ tearDown();
+ } catch (Throwable tearingDown) {
+ if (exception == null) exception= tearingDown;
+ }
+ }
+ if (exception != null) throw exception;
+ }
+ /**
+ * Override to run the test and assert its state.
+ * @throws Throwable if any exception is thrown
+ */
+ protected void runTest() throws Throwable {
+ assertNotNull("TestCase.fName cannot be null", fName); // Some VMs crash when calling getMethod(null,null);
+ Method runMethod= null;
+ try {
+ // use getMethod to get all public inherited
+ // methods. getDeclaredMethods returns all
+ // methods of this class but excludes the
+ // inherited ones.
+ runMethod= getClass().getMethod(fName, (Class[])null);
+ } catch (NoSuchMethodException e) {
+ fail("Method \""+fName+"\" not found");
+ }
+ if (!Modifier.isPublic(runMethod.getModifiers())) {
+ fail("Method \""+fName+"\" should be public");
+ }
+
+ try {
+ runMethod.invoke(this);
+ }
+ catch (InvocationTargetException e) {
+ e.fillInStackTrace();
+ throw e.getTargetException();
+ }
+ catch (IllegalAccessException e) {
+ e.fillInStackTrace();
+ throw e;
+ }
+ }
+ /**
+ * Sets up the fixture, for example, open a network connection.
+ * This method is called before a test is executed.
+ */
+ protected void setUp() throws Exception {
+ }
+ /**
+ * Tears down the fixture, for example, close a network connection.
+ * This method is called after a test is executed.
+ */
+ protected void tearDown() throws Exception {
+ }
+ /**
+ * Returns a string representation of the test case
+ */
+ @Override
+ public String toString() {
+ return getName() + "(" + getClass().getName() + ")";
+ }
+ /**
+ * Gets the name of a TestCase
+ * @return the name of the TestCase
+ */
+ public String getName() {
+ return fName;
+ }
+ /**
+ * Sets the name of a TestCase
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ fName= name;
+ }
+}
diff --git a/legacy-test/src/junit/framework/TestFailure.java b/legacy-test/src/junit/framework/TestFailure.java
new file mode 100644
index 0000000..6662b1f
--- /dev/null
+++ b/legacy-test/src/junit/framework/TestFailure.java
@@ -0,0 +1,58 @@
+package junit.framework;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+
+/**
+ * A <code>TestFailure</code> collects a failed test together with
+ * the caught exception.
+ * @see TestResult
+ */
+public class TestFailure extends Object {
+ protected Test fFailedTest;
+ protected Throwable fThrownException;
+
+
+ /**
+ * Constructs a TestFailure with the given test and exception.
+ */
+ public TestFailure(Test failedTest, Throwable thrownException) {
+ fFailedTest= failedTest;
+ fThrownException= thrownException;
+ }
+ /**
+ * Gets the failed test.
+ */
+ public Test failedTest() {
+ return fFailedTest;
+ }
+ /**
+ * Gets the thrown exception.
+ */
+ public Throwable thrownException() {
+ return fThrownException;
+ }
+ /**
+ * Returns a short description of the failure.
+ */
+ @Override
+ public String toString() {
+ StringBuffer buffer= new StringBuffer();
+ buffer.append(fFailedTest+": "+fThrownException.getMessage());
+ return buffer.toString();
+ }
+ public String trace() {
+ StringWriter stringWriter= new StringWriter();
+ PrintWriter writer= new PrintWriter(stringWriter);
+ thrownException().printStackTrace(writer);
+ StringBuffer buffer= stringWriter.getBuffer();
+ return buffer.toString();
+ }
+ public String exceptionMessage() {
+ return thrownException().getMessage();
+ }
+ public boolean isFailure() {
+ return thrownException() instanceof AssertionFailedError;
+ }
+}
\ No newline at end of file
diff --git a/legacy-test/src/junit/framework/TestListener.java b/legacy-test/src/junit/framework/TestListener.java
new file mode 100644
index 0000000..9b69443
--- /dev/null
+++ b/legacy-test/src/junit/framework/TestListener.java
@@ -0,0 +1,23 @@
+package junit.framework;
+
+/**
+ * A Listener for test progress
+ */
+public interface TestListener {
+ /**
+ * An error occurred.
+ */
+ public void addError(Test test, Throwable t);
+ /**
+ * A failure occurred.
+ */
+ public void addFailure(Test test, AssertionFailedError t);
+ /**
+ * A test ended.
+ */
+ public void endTest(Test test);
+ /**
+ * A test started.
+ */
+ public void startTest(Test test);
+}
\ No newline at end of file
diff --git a/legacy-test/src/junit/framework/TestResult.java b/legacy-test/src/junit/framework/TestResult.java
new file mode 100644
index 0000000..3052e94
--- /dev/null
+++ b/legacy-test/src/junit/framework/TestResult.java
@@ -0,0 +1,174 @@
+package junit.framework;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Vector;
+
+/**
+ * A <code>TestResult</code> collects the results of executing
+ * a test case. It is an instance of the Collecting Parameter pattern.
+ * The test framework distinguishes between <i>failures</i> and <i>errors</i>.
+ * A failure is anticipated and checked for with assertions. Errors are
+ * unanticipated problems like an {@link ArrayIndexOutOfBoundsException}.
+ *
+ * @see Test
+ */
+public class TestResult extends Object {
+ // BEGIN android-changed changed types from List<> to Vector<> for API compatibility
+ protected Vector<TestFailure> fFailures;
+ protected Vector<TestFailure> fErrors;
+ protected Vector<TestListener> fListeners;
+ // END android-changed
+ protected int fRunTests;
+ private boolean fStop;
+
+ public TestResult() {
+ // BEGIN android-changed to Vector
+ fFailures= new Vector<TestFailure>();
+ fErrors= new Vector<TestFailure>();
+ fListeners= new Vector<TestListener>();
+ // END android-changed
+ fRunTests= 0;
+ fStop= false;
+ }
+ /**
+ * Adds an error to the list of errors. The passed in exception
+ * caused the error.
+ */
+ public synchronized void addError(Test test, Throwable t) {
+ fErrors.add(new TestFailure(test, t));
+ for (TestListener each : cloneListeners())
+ each.addError(test, t);
+ }
+ /**
+ * Adds a failure to the list of failures. The passed in exception
+ * caused the failure.
+ */
+ public synchronized void addFailure(Test test, AssertionFailedError t) {
+ fFailures.add(new TestFailure(test, t));
+ for (TestListener each : cloneListeners())
+ each.addFailure(test, t);
+ }
+ /**
+ * Registers a TestListener
+ */
+ public synchronized void addListener(TestListener listener) {
+ fListeners.add(listener);
+ }
+ /**
+ * Unregisters a TestListener
+ */
+ public synchronized void removeListener(TestListener listener) {
+ fListeners.remove(listener);
+ }
+ /**
+ * Returns a copy of the listeners.
+ */
+ private synchronized List<TestListener> cloneListeners() {
+ List<TestListener> result= new ArrayList<TestListener>();
+ result.addAll(fListeners);
+ return result;
+ }
+ /**
+ * Informs the result that a test was completed.
+ */
+ public void endTest(Test test) {
+ for (TestListener each : cloneListeners())
+ each.endTest(test);
+ }
+ /**
+ * Gets the number of detected errors.
+ */
+ public synchronized int errorCount() {
+ return fErrors.size();
+ }
+ /**
+ * Returns an Enumeration for the errors
+ */
+ public synchronized Enumeration<TestFailure> errors() {
+ return Collections.enumeration(fErrors);
+ }
+
+
+ /**
+ * Gets the number of detected failures.
+ */
+ public synchronized int failureCount() {
+ return fFailures.size();
+ }
+ /**
+ * Returns an Enumeration for the failures
+ */
+ public synchronized Enumeration<TestFailure> failures() {
+ return Collections.enumeration(fFailures);
+ }
+
+ /**
+ * Runs a TestCase.
+ */
+ protected void run(final TestCase test) {
+ startTest(test);
+ Protectable p= new Protectable() {
+ public void protect() throws Throwable {
+ test.runBare();
+ }
+ };
+ runProtected(test, p);
+
+ endTest(test);
+ }
+ /**
+ * Gets the number of run tests.
+ */
+ public synchronized int runCount() {
+ return fRunTests;
+ }
+ /**
+ * Runs a TestCase.
+ */
+ public void runProtected(final Test test, Protectable p) {
+ try {
+ p.protect();
+ }
+ catch (AssertionFailedError e) {
+ addFailure(test, e);
+ }
+ catch (ThreadDeath e) { // don't catch ThreadDeath by accident
+ throw e;
+ }
+ catch (Throwable e) {
+ addError(test, e);
+ }
+ }
+ /**
+ * Checks whether the test run should stop
+ */
+ public synchronized boolean shouldStop() {
+ return fStop;
+ }
+ /**
+ * Informs the result that a test will be started.
+ */
+ public void startTest(Test test) {
+ final int count= test.countTestCases();
+ synchronized(this) {
+ fRunTests+= count;
+ }
+ for (TestListener each : cloneListeners())
+ each.startTest(test);
+ }
+ /**
+ * Marks that the test run should stop.
+ */
+ public synchronized void stop() {
+ fStop= true;
+ }
+ /**
+ * Returns whether the entire test was successful or not.
+ */
+ public synchronized boolean wasSuccessful() {
+ return failureCount() == 0 && errorCount() == 0;
+ }
+}
diff --git a/legacy-test/src/junit/framework/TestSuite.java b/legacy-test/src/junit/framework/TestSuite.java
new file mode 100644
index 0000000..336efd1
--- /dev/null
+++ b/legacy-test/src/junit/framework/TestSuite.java
@@ -0,0 +1,307 @@
+package junit.framework;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Vector;
+
+/**
+ * <p>A <code>TestSuite</code> is a <code>Composite</code> of Tests.
+ * It runs a collection of test cases. Here is an example using
+ * the dynamic test definition.
+ * <pre>
+ * TestSuite suite= new TestSuite();
+ * suite.addTest(new MathTest("testAdd"));
+ * suite.addTest(new MathTest("testDivideByZero"));
+ * </pre>
+ * </p>
+ *
+ * <p>Alternatively, a TestSuite can extract the tests to be run automatically.
+ * To do so you pass the class of your TestCase class to the
+ * TestSuite constructor.
+ * <pre>
+ * TestSuite suite= new TestSuite(MathTest.class);
+ * </pre>
+ * </p>
+ *
+ * <p>This constructor creates a suite with all the methods
+ * starting with "test" that take no arguments.</p>
+ *
+ * <p>A final option is to do the same for a large array of test classes.
+ * <pre>
+ * Class[] testClasses = { MathTest.class, AnotherTest.class }
+ * TestSuite suite= new TestSuite(testClasses);
+ * </pre>
+ * </p>
+ *
+ * @see Test
+ */
+public class TestSuite implements Test {
+
+ /**
+ * ...as the moon sets over the early morning Merlin, Oregon
+ * mountains, our intrepid adventurers type...
+ */
+ static public Test createTest(Class<?> theClass, String name) {
+ Constructor<?> constructor;
+ try {
+ constructor= getTestConstructor(theClass);
+ } catch (NoSuchMethodException e) {
+ return warning("Class "+theClass.getName()+" has no public constructor TestCase(String name) or TestCase()");
+ }
+ Object test;
+ try {
+ if (constructor.getParameterTypes().length == 0) {
+ test= constructor.newInstance(new Object[0]);
+ if (test instanceof TestCase)
+ ((TestCase) test).setName(name);
+ } else {
+ test= constructor.newInstance(new Object[]{name});
+ }
+ } catch (InstantiationException e) {
+ return(warning("Cannot instantiate test case: "+name+" ("+exceptionToString(e)+")"));
+ } catch (InvocationTargetException e) {
+ return(warning("Exception in constructor: "+name+" ("+exceptionToString(e.getTargetException())+")"));
+ } catch (IllegalAccessException e) {
+ return(warning("Cannot access test case: "+name+" ("+exceptionToString(e)+")"));
+ }
+ return (Test) test;
+ }
+
+ /**
+ * Gets a constructor which takes a single String as
+ * its argument or a no arg constructor.
+ */
+ public static Constructor<?> getTestConstructor(Class<?> theClass) throws NoSuchMethodException {
+ try {
+ return theClass.getConstructor(String.class);
+ } catch (NoSuchMethodException e) {
+ // fall through
+ }
+ return theClass.getConstructor(new Class[0]);
+ }
+
+ /**
+ * Returns a test which will fail and log a warning message.
+ */
+ public static Test warning(final String message) {
+ return new TestCase("warning") {
+ @Override
+ protected void runTest() {
+ fail(message);
+ }
+ };
+ }
+
+ /**
+ * Converts the stack trace into a string
+ */
+ private static String exceptionToString(Throwable t) {
+ StringWriter stringWriter= new StringWriter();
+ PrintWriter writer= new PrintWriter(stringWriter);
+ t.printStackTrace(writer);
+ return stringWriter.toString();
+ }
+
+ private String fName;
+
+ private Vector<Test> fTests= new Vector<Test>(10); // Cannot convert this to List because it is used directly by some test runners
+
+ /**
+ * Constructs an empty TestSuite.
+ */
+ public TestSuite() {
+ }
+
+ /**
+ * Constructs a TestSuite from the given class. Adds all the methods
+ * starting with "test" as test cases to the suite.
+ * Parts of this method were written at 2337 meters in the Hueffihuette,
+ * Kanton Uri
+ */
+ public TestSuite(final Class<?> theClass) {
+ addTestsFromTestCase(theClass);
+ }
+
+ private void addTestsFromTestCase(final Class<?> theClass) {
+ fName= theClass.getName();
+ try {
+ getTestConstructor(theClass); // Avoid generating multiple error messages
+ } catch (NoSuchMethodException e) {
+ addTest(warning("Class "+theClass.getName()+" has no public constructor TestCase(String name) or TestCase()"));
+ return;
+ }
+
+ if (!Modifier.isPublic(theClass.getModifiers())) {
+ addTest(warning("Class "+theClass.getName()+" is not public"));
+ return;
+ }
+
+ Class<?> superClass= theClass;
+ List<String> names= new ArrayList<String>();
+ while (Test.class.isAssignableFrom(superClass)) {
+ for (Method each : superClass.getDeclaredMethods())
+ addTestMethod(each, names, theClass);
+ superClass= superClass.getSuperclass();
+ }
+ if (fTests.size() == 0)
+ addTest(warning("No tests found in "+theClass.getName()));
+ }
+
+ /**
+ * Constructs a TestSuite from the given class with the given name.
+ * @see TestSuite#TestSuite(Class)
+ */
+ public TestSuite(Class<? extends TestCase> theClass, String name) {
+ this(theClass);
+ setName(name);
+ }
+
+ /**
+ * Constructs an empty TestSuite.
+ */
+ public TestSuite(String name) {
+ setName(name);
+ }
+
+ /**
+ * Constructs a TestSuite from the given array of classes.
+ * @param classes {@link TestCase}s
+ */
+ public TestSuite (Class<?>... classes) {
+ for (Class<?> each : classes)
+ addTest(testCaseForClass(each));
+ }
+
+ private Test testCaseForClass(Class<?> each) {
+ if (TestCase.class.isAssignableFrom(each))
+ return new TestSuite(each.asSubclass(TestCase.class));
+ else
+ return warning(each.getCanonicalName() + " does not extend TestCase");
+ }
+
+ /**
+ * Constructs a TestSuite from the given array of classes with the given name.
+ * @see TestSuite#TestSuite(Class[])
+ */
+ public TestSuite(Class<? extends TestCase>[] classes, String name) {
+ this(classes);
+ setName(name);
+ }
+
+ /**
+ * Adds a test to the suite.
+ */
+ public void addTest(Test test) {
+ fTests.add(test);
+ }
+
+ /**
+ * Adds the tests from the given class to the suite
+ */
+ public void addTestSuite(Class<? extends TestCase> testClass) {
+ addTest(new TestSuite(testClass));
+ }
+
+ /**
+ * Counts the number of test cases that will be run by this test.
+ */
+ public int countTestCases() {
+ int count= 0;
+ for (Test each : fTests)
+ count+= each.countTestCases();
+ return count;
+ }
+
+ /**
+ * Returns the name of the suite. Not all
+ * test suites have a name and this method
+ * can return null.
+ */
+ public String getName() {
+ return fName;
+ }
+
+ /**
+ * Runs the tests and collects their result in a TestResult.
+ */
+ public void run(TestResult result) {
+ for (Test each : fTests) {
+ if (result.shouldStop() )
+ break;
+ runTest(each, result);
+ }
+ }
+
+ public void runTest(Test test, TestResult result) {
+ test.run(result);
+ }
+
+ /**
+ * Sets the name of the suite.
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ fName= name;
+ }
+
+ /**
+ * Returns the test at the given index
+ */
+ public Test testAt(int index) {
+ return fTests.get(index);
+ }
+
+ /**
+ * Returns the number of tests in this suite
+ */
+ public int testCount() {
+ return fTests.size();
+ }
+
+ /**
+ * Returns the tests as an enumeration
+ */
+ public Enumeration<Test> tests() {
+ return fTests.elements();
+ }
+
+ /**
+ */
+ @Override
+ public String toString() {
+ if (getName() != null)
+ return getName();
+ return super.toString();
+ }
+
+ private void addTestMethod(Method m, List<String> names, Class<?> theClass) {
+ String name= m.getName();
+ if (names.contains(name))
+ return;
+ if (! isPublicTestMethod(m)) {
+ if (isTestMethod(m))
+ addTest(warning("Test method isn't public: "+ m.getName() + "(" + theClass.getCanonicalName() + ")"));
+ return;
+ }
+ names.add(name);
+ addTest(createTest(theClass, name));
+ }
+
+ private boolean isPublicTestMethod(Method m) {
+ return isTestMethod(m) && Modifier.isPublic(m.getModifiers());
+ }
+
+ private boolean isTestMethod(Method m) {
+ return
+ m.getParameterTypes().length == 0 &&
+ m.getName().startsWith("test") &&
+ m.getReturnType().equals(Void.TYPE);
+ }
+}
\ No newline at end of file
diff --git a/include/private/README b/libs/hwui/private/README
similarity index 100%
rename from include/private/README
rename to libs/hwui/private/README
diff --git a/include/private/hwui/DrawGlInfo.h b/libs/hwui/private/hwui/DrawGlInfo.h
similarity index 100%
rename from include/private/hwui/DrawGlInfo.h
rename to libs/hwui/private/hwui/DrawGlInfo.h
diff --git a/libs/storage/Android.bp b/libs/storage/Android.bp
new file mode 100644
index 0000000..911bd1d
--- /dev/null
+++ b/libs/storage/Android.bp
@@ -0,0 +1,19 @@
+cc_library_static {
+ name: "libstorage",
+
+ srcs: [
+ "IMountServiceListener.cpp",
+ "IMountShutdownObserver.cpp",
+ "IObbActionListener.cpp",
+ "IMountService.cpp",
+ ],
+
+ export_include_dirs: ["include"],
+
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+
+ shared_libs: ["libbinder"],
+}
diff --git a/libs/storage/Android.mk b/libs/storage/Android.mk
deleted file mode 100644
index d0eb6d4..0000000
--- a/libs/storage/Android.mk
+++ /dev/null
@@ -1,16 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
- IMountServiceListener.cpp \
- IMountShutdownObserver.cpp \
- IObbActionListener.cpp \
- IMountService.cpp
-
-LOCAL_MODULE:= libstorage
-
-LOCAL_CFLAGS += -Wall -Werror
-
-LOCAL_SHARED_LIBRARIES := libbinder
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/include/storage/IMountService.h b/libs/storage/include/storage/IMountService.h
similarity index 100%
rename from include/storage/IMountService.h
rename to libs/storage/include/storage/IMountService.h
diff --git a/include/storage/IMountServiceListener.h b/libs/storage/include/storage/IMountServiceListener.h
similarity index 100%
rename from include/storage/IMountServiceListener.h
rename to libs/storage/include/storage/IMountServiceListener.h
diff --git a/include/storage/IMountShutdownObserver.h b/libs/storage/include/storage/IMountShutdownObserver.h
similarity index 100%
rename from include/storage/IMountShutdownObserver.h
rename to libs/storage/include/storage/IMountShutdownObserver.h
diff --git a/include/storage/IObbActionListener.h b/libs/storage/include/storage/IObbActionListener.h
similarity index 100%
rename from include/storage/IObbActionListener.h
rename to libs/storage/include/storage/IObbActionListener.h
diff --git a/media/java/android/mtp/MtpServer.java b/media/java/android/mtp/MtpServer.java
index 61fbfb9..44c8b0b 100644
--- a/media/java/android/mtp/MtpServer.java
+++ b/media/java/android/mtp/MtpServer.java
@@ -29,9 +29,21 @@
System.loadLibrary("media_jni");
}
- public MtpServer(MtpDatabase database, boolean usePtp) {
+ public MtpServer(
+ MtpDatabase database,
+ boolean usePtp,
+ String deviceInfoManufacturer,
+ String deviceInfoModel,
+ String deviceInfoDeviceVersion,
+ String deviceInfoSerialNumber) {
mDatabase = database;
- native_setup(database, usePtp);
+ native_setup(
+ database,
+ usePtp,
+ deviceInfoManufacturer,
+ deviceInfoModel,
+ deviceInfoDeviceVersion,
+ deviceInfoSerialNumber);
database.setServer(this);
}
@@ -67,7 +79,18 @@
native_remove_storage(storage.getStorageId());
}
- private native final void native_setup(MtpDatabase database, boolean usePtp);
+ public static void configure(boolean usePtp) {
+ native_configure(usePtp);
+ }
+
+ public static native final void native_configure(boolean usePtp);
+ private native final void native_setup(
+ MtpDatabase database,
+ boolean usePtp,
+ String deviceInfoManufacturer,
+ String deviceInfoModel,
+ String deviceInfoDeviceVersion,
+ String deviceInfoSerialNumber);
private native final void native_run();
private native final void native_cleanup();
private native final void native_send_object_added(int handle);
diff --git a/media/jni/android_mtp_MtpServer.cpp b/media/jni/android_mtp_MtpServer.cpp
index d13187c..c325f4e 100644
--- a/media/jni/android_mtp_MtpServer.cpp
+++ b/media/jni/android_mtp_MtpServer.cpp
@@ -56,17 +56,40 @@
return (MtpServer*)env->GetLongField(thiz, field_MtpServer_nativeContext);
}
+static void android_mtp_configure(JNIEnv *, jobject, jboolean usePtp) {
+ MtpServer::configure(usePtp);
+}
+
static void
-android_mtp_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, jboolean usePtp)
+android_mtp_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, jboolean usePtp,
+ jstring deviceInfoManufacturer,
+ jstring deviceInfoModel,
+ jstring deviceInfoDeviceVersion,
+ jstring deviceInfoSerialNumber)
{
- int fd = open("/dev/mtp_usb", O_RDWR);
- if (fd >= 0) {
- MtpServer* server = new MtpServer(fd, getMtpDatabase(env, javaDatabase),
- usePtp, AID_MEDIA_RW, 0664, 0775);
- env->SetLongField(thiz, field_MtpServer_nativeContext, (jlong)server);
- } else {
- ALOGE("could not open MTP driver, errno: %d", errno);
+ const char *deviceInfoManufacturerStr = env->GetStringUTFChars(deviceInfoManufacturer, NULL);
+ const char *deviceInfoModelStr = env->GetStringUTFChars(deviceInfoModel, NULL);
+ const char *deviceInfoDeviceVersionStr = env->GetStringUTFChars(deviceInfoDeviceVersion, NULL);
+ const char *deviceInfoSerialNumberStr = env->GetStringUTFChars(deviceInfoSerialNumber, NULL);
+ MtpServer* server = new MtpServer(getMtpDatabase(env, javaDatabase),
+ usePtp, AID_MEDIA_RW, 0664, 0775,
+ MtpString((deviceInfoManufacturerStr != NULL) ? deviceInfoManufacturerStr : ""),
+ MtpString((deviceInfoModelStr != NULL) ? deviceInfoModelStr : ""),
+ MtpString((deviceInfoDeviceVersionStr != NULL) ? deviceInfoDeviceVersionStr : ""),
+ MtpString((deviceInfoSerialNumberStr != NULL) ? deviceInfoSerialNumberStr : ""));
+ if (deviceInfoManufacturerStr != NULL) {
+ env->ReleaseStringUTFChars(deviceInfoManufacturer, deviceInfoManufacturerStr);
}
+ if (deviceInfoModelStr != NULL) {
+ env->ReleaseStringUTFChars(deviceInfoModel, deviceInfoModelStr);
+ }
+ if (deviceInfoDeviceVersionStr != NULL) {
+ env->ReleaseStringUTFChars(deviceInfoDeviceVersion, deviceInfoDeviceVersionStr);
+ }
+ if (deviceInfoSerialNumberStr != NULL) {
+ env->ReleaseStringUTFChars(deviceInfoSerialNumber, deviceInfoSerialNumberStr);
+ }
+ env->SetLongField(thiz, field_MtpServer_nativeContext, (jlong)server);
}
static void
@@ -180,7 +203,8 @@
// ----------------------------------------------------------------------------
static const JNINativeMethod gMethods[] = {
- {"native_setup", "(Landroid/mtp/MtpDatabase;Z)V",
+ {"native_configure", "(Z)V", (void *)android_mtp_configure},
+ {"native_setup", "(Landroid/mtp/MtpDatabase;ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
(void *)android_mtp_MtpServer_setup},
{"native_run", "()V", (void *)android_mtp_MtpServer_run},
{"native_cleanup", "()V", (void *)android_mtp_MtpServer_cleanup},
diff --git a/media/mca/filterfw/native/core/shader_program.cpp b/media/mca/filterfw/native/core/shader_program.cpp
index 1e573fb..d460512 100644
--- a/media/mca/filterfw/native/core/shader_program.cpp
+++ b/media/mca/filterfw/native/core/shader_program.cpp
@@ -1028,7 +1028,11 @@
attrib.values = data_cpy;
attrib.owned_data = data_cpy; // Marks this for deletion later on
- return StoreAttribute(attrib);
+ if (StoreAttribute(attrib))
+ return true;
+ // If storing this failed, then it won't be deleted on its own.
+ delete[] data_cpy;
+ return false;
}
bool ShaderProgram::StoreAttribute(VertexAttrib attrib) {
diff --git a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
index b58c87a..bb8eb2c 100644
--- a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
+++ b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
@@ -115,6 +115,7 @@
myWebView.clearCache(true);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
+ webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
mWebViewClient = new MyWebViewClient();
myWebView.setWebViewClient(mWebViewClient);
myWebView.setWebChromeClient(new MyWebChromeClient());
diff --git a/packages/PrintRecommendationService/AndroidManifest.xml b/packages/PrintRecommendationService/AndroidManifest.xml
index c6736d7..2e9342c 100644
--- a/packages/PrintRecommendationService/AndroidManifest.xml
+++ b/packages/PrintRecommendationService/AndroidManifest.xml
@@ -18,11 +18,11 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.printservice.recommendation"
- android:versionCode="1"
- android:versionName="1.0.0">
+ android:versionCode="2"
+ android:versionName="1.1.0">
<uses-sdk android:minSdkVersion="24"
- android:targetSdkVersion="24" />
+ android:targetSdkVersion="25" />
<uses-permission android:name="android.permission.INTERNET" />
diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java b/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
index 3a16a75..252aaab 100644
--- a/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
+++ b/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
@@ -254,7 +254,7 @@
public boolean matches(WifiConfiguration config) {
if (config.isPasspoint() && mConfig != null && mConfig.isPasspoint()) {
- return config.FQDN.equals(mConfig.FQDN);
+ return ssid.equals(removeDoubleQuotes(config.SSID)) && config.FQDN.equals(mConfig.FQDN);
} else {
return ssid.equals(removeDoubleQuotes(config.SSID))
&& security == getSecurity(config)
diff --git a/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java b/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java
index 9eceeac..c96506712 100644
--- a/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java
+++ b/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java
@@ -31,6 +31,7 @@
import com.android.internal.app.AssistUtils;
import com.android.internal.app.IVoiceInteractionSessionListener;
import com.android.internal.app.IVoiceInteractionSessionShowCallback;
+import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.R;
import com.android.systemui.statusbar.BaseStatusBar;
import com.android.systemui.statusbar.CommandQueue;
@@ -282,7 +283,7 @@
@Nullable
private ComponentName getAssistInfo() {
- return mAssistUtils.getAssistComponentForUser(UserHandle.USER_CURRENT);
+ return mAssistUtils.getAssistComponentForUser(KeyguardUpdateMonitor.getCurrentUser());
}
public void showDisclosure() {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java
index 5c8a6e2..a172e19 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java
@@ -358,6 +358,11 @@
private final TouchAnimator.Listener mNonFirstPageListener =
new TouchAnimator.ListenerAdapter() {
@Override
+ public void onAnimationAtEnd() {
+ mQuickQsPanel.setVisibility(View.INVISIBLE);
+ }
+
+ @Override
public void onAnimationStarted() {
mQuickQsPanel.setVisibility(View.VISIBLE);
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
index dfc89fa..612eba7 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
@@ -345,7 +345,10 @@
@Override
public void onAnnouncementRequested(CharSequence announcement) {
- announceForAccessibility(announcement);
+ if (announcement != null) {
+ mHandler.obtainMessage(H.ANNOUNCE_FOR_ACCESSIBILITY, announcement)
+ .sendToTarget();
+ }
}
};
r.tile.addCallback(callback);
@@ -514,10 +517,13 @@
private class H extends Handler {
private static final int SHOW_DETAIL = 1;
private static final int SET_TILE_VISIBILITY = 2;
+ private static final int ANNOUNCE_FOR_ACCESSIBILITY = 3;
@Override
public void handleMessage(Message msg) {
if (msg.what == SHOW_DETAIL) {
handleShowDetail((Record)msg.obj, msg.arg1 != 0);
+ } else if (msg.what == ANNOUNCE_FOR_ACCESSIBILITY) {
+ announceForAccessibility((CharSequence)msg.obj);
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
index 70642ed..f0bbac8 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
@@ -392,7 +392,7 @@
RecentsActivityLaunchState launchState = config.getLaunchState();
if (!loadPlan.hasTasks()) {
loader.preloadTasks(loadPlan, launchState.launchedToTaskId,
- !launchState.launchedFromHome);
+ !launchState.launchedFromHome && !launchState.launchedViaDockGesture);
}
RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options();
@@ -519,12 +519,14 @@
EventBus.getDefault().send(new RecentsVisibilityChangedEvent(this, false));
MetricsLogger.hidden(this, MetricsEvent.OVERVIEW_ACTIVITY);
- // Workaround for b/22542869, if the RecentsActivity is started again, but without going
- // through SystemUI, we need to reset the config launch flags to ensure that we do not
- // wait on the system to send a signal that was never queued.
- RecentsConfiguration config = Recents.getConfiguration();
- RecentsActivityLaunchState launchState = config.getLaunchState();
- launchState.reset();
+ if (!isChangingConfigurations()) {
+ // Workaround for b/22542869, if the RecentsActivity is started again, but without going
+ // through SystemUI, we need to reset the config launch flags to ensure that we do not
+ // wait on the system to send a signal that was never queued.
+ RecentsConfiguration config = Recents.getConfiguration();
+ RecentsActivityLaunchState launchState = config.getLaunchState();
+ launchState.reset();
+ }
}
@Override
diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java
index 75b2dd4..adc59de 100644
--- a/services/core/java/com/android/server/BluetoothManagerService.java
+++ b/services/core/java/com/android/server/BluetoothManagerService.java
@@ -35,11 +35,13 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
+import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.database.ContentObserver;
import android.os.Binder;
import android.os.Bundle;
+import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
@@ -55,14 +57,16 @@
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.util.Slog;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.Map;
+
class BluetoothManagerService extends IBluetoothManager.Stub {
private static final String TAG = "BluetoothManagerService";
private static final boolean DBG = true;
@@ -102,6 +106,7 @@
private static final int MESSAGE_USER_UNLOCKED = 301;
private static final int MESSAGE_ADD_PROXY_DELAYED = 400;
private static final int MESSAGE_BIND_PROFILE_SERVICE = 401;
+
private static final int MAX_SAVE_RETRIES = 3;
private static final int MAX_ERROR_RESTART_RETRIES = 6;
@@ -134,16 +139,46 @@
new ReentrantReadWriteLock();
private boolean mBinding;
private boolean mUnbinding;
+
// used inside handler thread
private boolean mQuietEnable = false;
- // configuarion from external IBinder call which is used to
+ private boolean mEnable;
+
+ /**
+ * Used for tracking apps that enabled / disabled Bluetooth.
+ */
+ private class ActiveLog {
+ private String mPackageName;
+ private boolean mEnable;
+ private long mTimestamp;
+
+ public ActiveLog(String packageName, boolean enable, long timestamp) {
+ mPackageName = packageName;
+ mEnable = enable;
+ mTimestamp = timestamp;
+ }
+
+ public long getTime() {
+ return mTimestamp;
+ }
+
+ public String toString() {
+ return android.text.format.DateFormat.format("MM-dd hh:mm:ss ", mTimestamp) +
+ (mEnable ? " Enabled " : " Disabled ") + " by " + mPackageName;
+ }
+
+ }
+
+ private LinkedList<ActiveLog> mActiveLogs;
+
+ // configuration from external IBinder call which is used to
// synchronize with broadcast receiver.
private boolean mQuietEnableExternal;
- // configuarion from external IBinder call which is used to
- // synchronize with broadcast receiver.
private boolean mEnableExternal;
- // used inside handler thread
- private boolean mEnable;
+
+ // Map of apps registered to keep BLE scanning on.
+ private Map<IBinder, ClientDeathRecipient> mBleApps = new ConcurrentHashMap<IBinder, ClientDeathRecipient>();
+
private int mState;
private final BluetoothHandler mHandler;
private int mErrorRecoveryRetryCounter;
@@ -154,6 +189,8 @@
private final Map <Integer, ProfileServiceConnections> mProfileServices =
new HashMap <Integer, ProfileServiceConnections>();
+ private final boolean mPermissionReviewRequired;
+
private void registerForAirplaneMode(IntentFilter filter) {
final ContentResolver resolver = mContext.getContentResolver();
final String airplaneModeRadios = Settings.Global.getString(resolver,
@@ -167,7 +204,7 @@
}
}
- private final IBluetoothCallback mBluetoothCallback = new IBluetoothCallback.Stub() {
+ private final IBluetoothCallback mBluetoothCallback = new IBluetoothCallback.Stub() {
@Override
public void onBluetoothStateChange(int prevState, int newState) throws RemoteException {
Message msg = mHandler.obtainMessage(MESSAGE_BLUETOOTH_STATE_CHANGE,prevState,newState);
@@ -183,7 +220,12 @@
final boolean bluetoothDisallowed =
newRestrictions.getBoolean(UserManager.DISALLOW_BLUETOOTH);
if ((mEnable || mEnableExternal) && bluetoothDisallowed) {
- disable(true);
+ try {
+ disable("android.os.UserManagerInternal", true);
+ } catch (RemoteException e) {
+ // Shouldn't happen: startConsentUiIfNeeded not called
+ // when from system.
+ }
}
}
};
@@ -219,7 +261,7 @@
} finally {
mBluetoothLock.readLock().unlock();
}
- Slog.d(TAG, "state" + st);
+ Slog.d(TAG, "State " + BluetoothAdapter.nameForState(st));
if (isAirplaneModeOn()) {
// Clear registered LE apps to force shut-off
@@ -241,12 +283,12 @@
} else if (st == BluetoothAdapter.STATE_ON){
// disable without persisting the setting
Slog.d(TAG, "Calling disable");
- sendDisableMsg();
+ sendDisableMsg("airplane mode");
}
} else if (mEnableExternal) {
// enable without persisting the setting
Slog.d(TAG, "Calling enable");
- sendEnableMsg(mQuietEnableExternal);
+ sendEnableMsg(mQuietEnableExternal, "airplane mode");
}
}
}
@@ -257,6 +299,12 @@
mHandler = new BluetoothHandler(IoThread.get().getLooper());
mContext = context;
+
+ mPermissionReviewRequired = Build.PERMISSIONS_REVIEW_REQUIRED
+ || context.getResources().getBoolean(
+ com.android.internal.R.bool.config_permissionReviewRequired);
+
+ mActiveLogs = new LinkedList<ActiveLog>();
mBluetooth = null;
mBluetoothBinder = null;
mBluetoothGatt = null;
@@ -283,15 +331,15 @@
mEnableExternal = true;
}
- int sysUiUid = -1;
+ int systemUiUid = -1;
try {
- sysUiUid = mContext.getPackageManager().getPackageUidAsUser("com.android.systemui",
+ systemUiUid = mContext.getPackageManager().getPackageUidAsUser("com.android.systemui",
PackageManager.MATCH_SYSTEM_ONLY, UserHandle.USER_SYSTEM);
} catch (PackageManager.NameNotFoundException e) {
// Some platforms, such as wearables do not have a system ui.
Slog.w(TAG, "Unable to resolve SystemUI's UID.", e);
}
- mSystemUiUid = sysUiUid;
+ mSystemUiUid = systemUiUid;
}
/**
@@ -320,12 +368,15 @@
/**
* Save the Bluetooth on/off state
- *
*/
private void persistBluetoothSetting(int value) {
+ if (DBG) Slog.d(TAG, "Persisting Bluetooth Setting: " + value);
+ // waive WRITE_SECURE_SETTINGS permission check
+ long callingIdentity = Binder.clearCallingIdentity();
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.BLUETOOTH_ON,
value);
+ Binder.restoreCallingIdentity(callingIdentity);
}
/**
@@ -408,6 +459,10 @@
public void registerStateChangeCallback(IBluetoothStateChangeCallback callback) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM,
"Need BLUETOOTH permission");
+ if (callback == null) {
+ Slog.w(TAG, "registerStateChangeCallback: Callback is null!");
+ return;
+ }
Message msg = mHandler.obtainMessage(MESSAGE_REGISTER_STATE_CHANGE_CALLBACK);
msg.obj = callback;
mHandler.sendMessage(msg);
@@ -416,6 +471,10 @@
public void unregisterStateChangeCallback(IBluetoothStateChangeCallback callback) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM,
"Need BLUETOOTH permission");
+ if (callback == null) {
+ Slog.w(TAG, "unregisterStateChangeCallback: Callback is null!");
+ return;
+ }
Message msg = mHandler.obtainMessage(MESSAGE_UNREGISTER_STATE_CHANGE_CALLBACK);
msg.obj = callback;
mHandler.sendMessage(msg);
@@ -442,7 +501,7 @@
public int getState() {
if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
(!checkIfCallerIsForegroundUser())) {
- Slog.w(TAG, "getState(): not allowed for non-active and non system user");
+ Slog.w(TAG, "getState(): report OFF for non-active and non system user");
return BluetoothAdapter.STATE_OFF;
}
@@ -458,8 +517,14 @@
}
class ClientDeathRecipient implements IBinder.DeathRecipient {
+ private String mPackageName;
+
+ public ClientDeathRecipient(String packageName) {
+ mPackageName = packageName;
+ }
+
public void binderDied() {
- if (DBG) Slog.d(TAG, "Binder is dead - unregister Ble App");
+ if (DBG) Slog.d(TAG, "Binder is dead - unregister " + mPackageName);
if (isBleAppPresent()) {
// Nothing to do, another app is here.
return;
@@ -478,10 +543,11 @@
mBluetoothLock.readLock().unlock();
}
}
- }
- /** Internal death rec list */
- Map<IBinder, ClientDeathRecipient> mBleApps = new ConcurrentHashMap<IBinder, ClientDeathRecipient>();
+ public String getPackageName() {
+ return mPackageName;
+ }
+ }
@Override
public boolean isBleScanAlwaysAvailable() {
@@ -539,28 +605,22 @@
}
}
- public int updateBleAppCount(IBinder token, boolean enable) {
- if (enable) {
- ClientDeathRecipient r = mBleApps.get(token);
- if (r == null) {
- ClientDeathRecipient deathRec = new ClientDeathRecipient();
- try {
- token.linkToDeath(deathRec, 0);
- } catch (RemoteException ex) {
- throw new IllegalArgumentException("Wake lock is already dead.");
- }
- mBleApps.put(token, deathRec);
- if (DBG) Slog.d(TAG, "Registered for death Notification");
+ public int updateBleAppCount(IBinder token, boolean enable, String packageName) {
+ ClientDeathRecipient r = mBleApps.get(token);
+ if (r == null && enable) {
+ ClientDeathRecipient deathRec = new ClientDeathRecipient(packageName);
+ try {
+ token.linkToDeath(deathRec, 0);
+ } catch (RemoteException ex) {
+ throw new IllegalArgumentException("BLE app (" + packageName + ") already dead!");
}
-
- } else {
- ClientDeathRecipient r = mBleApps.get(token);
- if (r != null) {
- // Unregister death recipient as the app goes away.
- token.unlinkToDeath(r, 0);
- mBleApps.remove(token);
- if (DBG) Slog.d(TAG, "Unregistered for death Notification");
- }
+ mBleApps.put(token, deathRec);
+ if (DBG) Slog.d(TAG, "Registered for death of " + packageName);
+ } else if (!enable && r != null) {
+ // Unregister death recipient as the app goes away.
+ token.unlinkToDeath(r, 0);
+ mBleApps.remove(token);
+ if (DBG) Slog.d(TAG, "Unregistered for death of " + packageName);
}
int appCount = mBleApps.size();
if (DBG) Slog.d(TAG, appCount + " registered Ble Apps");
@@ -575,27 +635,33 @@
mBleApps.clear();
}
- /** @hide*/
+ /** @hide */
public boolean isBleAppPresent() {
if (DBG) Slog.d(TAG, "isBleAppPresent() count: " + mBleApps.size());
return mBleApps.size() > 0;
}
/**
- * Action taken when GattService is turned off
+ * Action taken when GattService is turned on
*/
private void onBluetoothGattServiceUp() {
if (DBG) Slog.d(TAG,"BluetoothGatt Service is Up");
try {
mBluetoothLock.readLock().lock();
- if (isBleAppPresent() == false && mBluetooth != null
- && mBluetooth.getState() == BluetoothAdapter.STATE_BLE_ON) {
+ if (mBluetooth == null) {
+ if (DBG) Slog.w(TAG, "onBluetoothServiceUp: mBluetooth is null!");
+ return;
+ }
+ int st = mBluetooth.getState();
+ if (st != BluetoothAdapter.STATE_BLE_ON) {
+ if (DBG) Slog.v(TAG, "onBluetoothServiceUp: state isn't BLE_ON: " +
+ BluetoothAdapter.nameForState(st));
+ return;
+ }
+ if (isBluetoothPersistedStateOnBluetooth() || !isBleAppPresent()) {
+ // This triggers transition to STATE_ON
mBluetooth.onLeServiceUp();
-
- // waive WRITE_SECURE_SETTINGS permission check
- long callingIdentity = Binder.clearCallingIdentity();
persistBluetoothSetting(BLUETOOTH_ON_BLUETOOTH);
- Binder.restoreCallingIdentity(callingIdentity);
}
} catch (RemoteException e) {
Slog.e(TAG,"Unable to call onServiceUp", e);
@@ -635,7 +701,7 @@
}
}
- public boolean enableNoAutoConnect()
+ public boolean enableNoAutoConnect(String packageName)
{
if (isBluetoothDisallowed()) {
if (DBG) {
@@ -660,12 +726,12 @@
synchronized(mReceiver) {
mQuietEnableExternal = true;
mEnableExternal = true;
- sendEnableMsg(true);
+ sendEnableMsg(true, packageName);
}
return true;
}
- public boolean enable() {
+ public boolean enable(String packageName) throws RemoteException {
if (isBluetoothDisallowed()) {
if (DBG) {
Slog.d(TAG,"enable(): not enabling - bluetooth disallowed");
@@ -673,37 +739,57 @@
return false;
}
- if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
- (!checkIfCallerIsForegroundUser())) {
- Slog.w(TAG,"enable(): not allowed for non-active and non system user");
- return false;
+ final int callingUid = Binder.getCallingUid();
+ final boolean callerSystem = UserHandle.getAppId(callingUid) == Process.SYSTEM_UID;
+
+ if (!callerSystem) {
+ if (!checkIfCallerIsForegroundUser()) {
+ Slog.w(TAG, "enable(): not allowed for non-active and non system user");
+ return false;
+ }
+
+ mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
+ "Need BLUETOOTH ADMIN permission");
+
+ if (!isEnabled() && mPermissionReviewRequired) {
+ startConsentUi(packageName, callingUid, BluetoothAdapter.ACTION_REQUEST_ENABLE);
+ return false;
+ }
}
- mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
- "Need BLUETOOTH ADMIN permission");
if (DBG) {
- Slog.d(TAG,"enable(): mBluetooth =" + mBluetooth +
- " mBinding = " + mBinding + " mState = " + mState);
+ Slog.d(TAG,"enable(" + packageName + "): mBluetooth =" + mBluetooth +
+ " mBinding = " + mBinding + " mState = " +
+ BluetoothAdapter.nameForState(mState));
}
synchronized(mReceiver) {
mQuietEnableExternal = false;
mEnableExternal = true;
// waive WRITE_SECURE_SETTINGS permission check
- sendEnableMsg(false);
+ sendEnableMsg(false, packageName);
}
if (DBG) Slog.d(TAG, "enable returning");
return true;
}
- public boolean disable(boolean persist) {
- mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
- "Need BLUETOOTH ADMIN permissicacheNameAndAddresson");
+ public boolean disable(String packageName, boolean persist) throws RemoteException {
+ final int callingUid = Binder.getCallingUid();
+ final boolean callerSystem = UserHandle.getAppId(callingUid) == Process.SYSTEM_UID;
- if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
- (!checkIfCallerIsForegroundUser())) {
- Slog.w(TAG,"disable(): not allowed for non-active and non system user");
- return false;
+ if (!callerSystem) {
+ if (!checkIfCallerIsForegroundUser()) {
+ Slog.w(TAG, "disable(): not allowed for non-active and non system user");
+ return false;
+ }
+
+ mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
+ "Need BLUETOOTH ADMIN permission");
+
+ if (isEnabled() && mPermissionReviewRequired) {
+ startConsentUi(packageName, callingUid, BluetoothAdapter.ACTION_REQUEST_DISABLE);
+ return false;
+ }
}
if (DBG) {
@@ -713,21 +799,39 @@
synchronized(mReceiver) {
if (persist) {
- // waive WRITE_SECURE_SETTINGS permission check
- long callingIdentity = Binder.clearCallingIdentity();
persistBluetoothSetting(BLUETOOTH_OFF);
- Binder.restoreCallingIdentity(callingIdentity);
}
mEnableExternal = false;
- sendDisableMsg();
+ sendDisableMsg(packageName);
}
return true;
}
+ private void startConsentUi(String packageName, int callingUid, String intentAction)
+ throws RemoteException {
+ try {
+ // Validate the package only if we are going to use it
+ ApplicationInfo applicationInfo = mContext.getPackageManager()
+ .getApplicationInfoAsUser(packageName,
+ PackageManager.MATCH_DEBUG_TRIAGED_MISSING,
+ UserHandle.getUserId(callingUid));
+ if (applicationInfo.uid != callingUid) {
+ throw new SecurityException("Package " + callingUid
+ + " not in uid " + callingUid);
+ }
+
+ // Permission review mode, trigger a user prompt
+ Intent intent = new Intent(intentAction);
+ mContext.startActivity(intent);
+ } catch (PackageManager.NameNotFoundException e) {
+ throw new RemoteException(e.getMessage());
+ }
+ }
+
public void unbindAndFinish() {
if (DBG) {
Slog.d(TAG,"unbindAndFinish(): " + mBluetooth +
- " mBinding = " + mBinding);
+ " mBinding = " + mBinding + " mUnbinding = " + mUnbinding);
}
try {
@@ -743,16 +847,13 @@
} catch (RemoteException re) {
Slog.e(TAG, "Unable to unregister BluetoothCallback",re);
}
-
- if (DBG) Slog.d(TAG, "Sending unbind request.");
mBluetoothBinder = null;
mBluetooth = null;
- //Unbind
mContext.unbindService(mConnection);
mUnbinding = false;
mBinding = false;
} else {
- mUnbinding=false;
+ mUnbinding = false;
}
mBluetoothGatt = null;
} finally {
@@ -842,7 +943,7 @@
}
if (mEnableExternal && isBluetoothPersistedStateOnBluetooth()) {
if (DBG) Slog.d(TAG, "Auto-enabling Bluetooth.");
- sendEnableMsg(mQuietEnableExternal);
+ sendEnableMsg(mQuietEnableExternal, "system boot");
} else if (!isNameAndAddressSet()) {
if (DBG) Slog.d(TAG, "Getting adapter name and address");
Message getMsg = mHandler.obtainMessage(MESSAGE_GET_NAME_AND_ADDRESS);
@@ -1028,7 +1129,6 @@
* Inform BluetoothAdapter instances that Adapter service is up
*/
private void sendBluetoothServiceUpCallback() {
- if (DBG) Slog.d(TAG,"Calling onBluetoothServiceUp callbacks");
try {
int n = mCallbacks.beginBroadcast();
Slog.d(TAG,"Broadcasting onBluetoothServiceUp() to " + n + " receivers.");
@@ -1047,7 +1147,6 @@
* Inform BluetoothAdapter instances that Adapter service is down
*/
private void sendBluetoothServiceDownCallback() {
- if (DBG) Slog.d(TAG,"Calling onBluetoothServiceDown callbacks");
try {
int n = mCallbacks.beginBroadcast();
Slog.d(TAG,"Broadcasting onBluetoothServiceDown() to " + n + " receivers.");
@@ -1119,34 +1218,33 @@
}
private class BluetoothServiceConnection implements ServiceConnection {
- public void onServiceConnected(ComponentName className, IBinder service) {
- if (DBG) Slog.d(TAG, "BluetoothServiceConnection: " + className.getClassName());
+ public void onServiceConnected(ComponentName componentName, IBinder service) {
+ String name = componentName.getClassName();
+ if (DBG) Slog.d(TAG, "BluetoothServiceConnection: " + name);
Message msg = mHandler.obtainMessage(MESSAGE_BLUETOOTH_SERVICE_CONNECTED);
- // TBD if (className.getClassName().equals(IBluetooth.class.getName())) {
- if (className.getClassName().equals("com.android.bluetooth.btservice.AdapterService")) {
+ if (name.equals("com.android.bluetooth.btservice.AdapterService")) {
msg.arg1 = SERVICE_IBLUETOOTH;
- // } else if (className.getClassName().equals(IBluetoothGatt.class.getName())) {
- } else if (className.getClassName().equals("com.android.bluetooth.gatt.GattService")) {
+ } else if (name.equals("com.android.bluetooth.gatt.GattService")) {
msg.arg1 = SERVICE_IBLUETOOTHGATT;
} else {
- Slog.e(TAG, "Unknown service connected: " + className.getClassName());
+ Slog.e(TAG, "Unknown service connected: " + name);
return;
}
msg.obj = service;
mHandler.sendMessage(msg);
}
- public void onServiceDisconnected(ComponentName className) {
- // Called if we unexpected disconnected.
- if (DBG) Slog.d(TAG, "BluetoothServiceConnection, disconnected: " +
- className.getClassName());
+ public void onServiceDisconnected(ComponentName componentName) {
+ // Called if we unexpectedly disconnect.
+ String name = componentName.getClassName();
+ if (DBG) Slog.d(TAG, "BluetoothServiceConnection, disconnected: " + name);
Message msg = mHandler.obtainMessage(MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED);
- if (className.getClassName().equals("com.android.bluetooth.btservice.AdapterService")) {
+ if (name.equals("com.android.bluetooth.btservice.AdapterService")) {
msg.arg1 = SERVICE_IBLUETOOTH;
- } else if (className.getClassName().equals("com.android.bluetooth.gatt.GattService")) {
+ } else if (name.equals("com.android.bluetooth.gatt.GattService")) {
msg.arg1 = SERVICE_IBLUETOOTHGATT;
} else {
- Slog.e(TAG, "Unknown service disconnected: " + className.getClassName());
+ Slog.e(TAG, "Unknown service disconnected: " + name);
return;
}
mHandler.sendMessage(msg);
@@ -1164,7 +1262,6 @@
@Override
public void handleMessage(Message msg) {
- if (DBG) Slog.d (TAG, "Message: " + msg.what);
switch (msg.what) {
case MESSAGE_GET_NAME_AND_ADDRESS:
if (DBG) Slog.d(TAG, "MESSAGE_GET_NAME_AND_ADDRESS");
@@ -1202,7 +1299,7 @@
case MESSAGE_ENABLE:
if (DBG) {
- Slog.d(TAG, "MESSAGE_ENABLE: mBluetooth = " + mBluetooth);
+ Slog.d(TAG, "MESSAGE_ENABLE(" + msg.arg1 + "): mBluetooth = " + mBluetooth);
}
mHandler.removeMessages(MESSAGE_RESTART_BLUETOOTH_SERVICE);
mEnable = true;
@@ -1213,8 +1310,9 @@
if (mBluetooth != null) {
int state = mBluetooth.getState();
if (state == BluetoothAdapter.STATE_BLE_ON) {
- Slog.w(TAG, "BT is in BLE_ON State");
+ Slog.w(TAG, "BT Enable in BLE_ON State, going to ON");
mBluetooth.onLeServiceUp();
+ persistBluetoothSetting(BLUETOOTH_ON_BLUETOOTH);
break;
}
}
@@ -1252,6 +1350,7 @@
break;
case MESSAGE_DISABLE:
+ if (DBG) Slog.d(TAG, "MESSAGE_DISABLE: mBluetooth = " + mBluetooth);
mHandler.removeMessages(MESSAGE_RESTART_BLUETOOTH_SERVICE);
if (mEnable && mBluetooth != null) {
waitForOnOff(true, false);
@@ -1267,31 +1366,25 @@
case MESSAGE_REGISTER_ADAPTER:
{
IBluetoothManagerCallback callback = (IBluetoothManagerCallback) msg.obj;
- boolean added = mCallbacks.register(callback);
- Slog.d(TAG,"Added callback: " + (callback == null? "null": callback) +":" +added );
- }
+ mCallbacks.register(callback);
break;
+ }
case MESSAGE_UNREGISTER_ADAPTER:
{
IBluetoothManagerCallback callback = (IBluetoothManagerCallback) msg.obj;
- boolean removed = mCallbacks.unregister(callback);
- Slog.d(TAG,"Removed callback: " + (callback == null? "null": callback) +":" + removed);
+ mCallbacks.unregister(callback);
break;
}
case MESSAGE_REGISTER_STATE_CHANGE_CALLBACK:
{
IBluetoothStateChangeCallback callback = (IBluetoothStateChangeCallback) msg.obj;
- if (callback != null) {
- mStateChangeCallbacks.register(callback);
- }
+ mStateChangeCallbacks.register(callback);
break;
}
case MESSAGE_UNREGISTER_STATE_CHANGE_CALLBACK:
{
IBluetoothStateChangeCallback callback = (IBluetoothStateChangeCallback) msg.obj;
- if (callback != null) {
- mStateChangeCallbacks.unregister(callback);
- }
+ mStateChangeCallbacks.unregister(callback);
break;
}
case MESSAGE_ADD_PROXY_DELAYED:
@@ -1364,13 +1457,11 @@
//Do enable request
try {
if (mQuietEnable == false) {
- if(!mBluetooth.enable()) {
+ if (!mBluetooth.enable()) {
Slog.e(TAG,"IBluetooth.enable() returned false");
}
- }
- else
- {
- if(!mBluetooth.enableNoAutoConnect()) {
+ } else {
+ if (!mBluetooth.enableNoAutoConnect()) {
Slog.e(TAG,"IBluetooth.enableNoAutoConnect() returned false");
}
}
@@ -1388,19 +1479,14 @@
}
break;
}
- case MESSAGE_TIMEOUT_BIND: {
- Slog.e(TAG, "MESSAGE_TIMEOUT_BIND");
- mBluetoothLock.writeLock().lock();
- mBinding = false;
- mBluetoothLock.writeLock().unlock();
-
- break;
- }
case MESSAGE_BLUETOOTH_STATE_CHANGE:
{
int prevState = msg.arg1;
int newState = msg.arg2;
- if (DBG) Slog.d(TAG, "MESSAGE_BLUETOOTH_STATE_CHANGE: prevState = " + prevState + ", newState=" + newState);
+ if (DBG) {
+ Slog.d(TAG, "MESSAGE_BLUETOOTH_STATE_CHANGE: " + BluetoothAdapter.nameForState(prevState) + " > " +
+ BluetoothAdapter.nameForState(newState));
+ }
mState = newState;
bluetoothStateChangeHandler(prevState, newState);
// handle error state transition case from TURNING_ON to OFF
@@ -1440,7 +1526,7 @@
}
case MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED:
{
- Slog.e(TAG, "MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED: " + msg.arg1);
+ Slog.e(TAG, "MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED(" + msg.arg1 + ")");
try {
mBluetoothLock.writeLock().lock();
if (msg.arg1 == SERVICE_IBLUETOOTH) {
@@ -1451,7 +1537,7 @@
mBluetoothGatt = null;
break;
} else {
- Slog.e(TAG, "Bad msg.arg1: " + msg.arg1);
+ Slog.e(TAG, "Unknown argument for service disconnect!");
break;
}
} finally {
@@ -1488,8 +1574,7 @@
}
case MESSAGE_RESTART_BLUETOOTH_SERVICE:
{
- Slog.d(TAG, "MESSAGE_RESTART_BLUETOOTH_SERVICE:"
- +" Restart IBluetooth service");
+ Slog.d(TAG, "MESSAGE_RESTART_BLUETOOTH_SERVICE");
/* Enable without persisting the setting as
it doesnt change when IBluetooth
service restarts */
@@ -1497,7 +1582,13 @@
handleEnable(mQuietEnable);
break;
}
-
+ case MESSAGE_TIMEOUT_BIND: {
+ Slog.e(TAG, "MESSAGE_TIMEOUT_BIND");
+ mBluetoothLock.writeLock().lock();
+ mBinding = false;
+ mBluetoothLock.writeLock().unlock();
+ break;
+ }
case MESSAGE_TIMEOUT_UNBIND:
{
Slog.e(TAG, "MESSAGE_TIMEOUT_UNBIND");
@@ -1583,11 +1674,10 @@
} else if (mBinding || mBluetooth != null) {
Message userMsg = mHandler.obtainMessage(MESSAGE_USER_SWITCHED);
userMsg.arg2 = 1 + msg.arg2;
- // if user is switched when service is being binding
- // delay sending MESSAGE_USER_SWITCHED
+ // if user is switched when service is binding retry after a delay
mHandler.sendMessageDelayed(userMsg, USER_SWITCHED_TIME_MS);
if (DBG) {
- Slog.d(TAG, "delay MESSAGE_USER_SWITCHED " + userMsg.arg2);
+ Slog.d(TAG, "Retry MESSAGE_USER_SWITCHED " + userMsg.arg2);
}
}
break;
@@ -1688,7 +1778,7 @@
parentUser == foregroundUser ||
callingAppId == Process.NFC_UID ||
callingAppId == mSystemUiUid;
- if (DBG) {
+ if (DBG && !valid) {
Slog.d(TAG, "checkIfCallerIsForegroundUser: valid=" + valid
+ " callingUser=" + callingUser
+ " parentUser=" + parentUser
@@ -1701,7 +1791,8 @@
}
private void sendBleStateChanged(int prevState, int newState) {
- if (DBG) Slog.d(TAG,"BLE State Change Intent: " + prevState + " -> " + newState);
+ if (DBG) Slog.d(TAG,"Sending BLE State Change: " + BluetoothAdapter.nameForState(prevState) +
+ " > " + BluetoothAdapter.nameForState(newState));
// Send broadcast message to everyone else
Intent intent = new Intent(BluetoothAdapter.ACTION_BLE_STATE_CHANGED);
intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, prevState);
@@ -1712,75 +1803,76 @@
private void bluetoothStateChangeHandler(int prevState, int newState) {
boolean isStandardBroadcast = true;
- if (prevState != newState) {
- //Notify all proxy objects first of adapter state change
- if (newState == BluetoothAdapter.STATE_BLE_ON ||
- newState == BluetoothAdapter.STATE_OFF) {
- boolean intermediate_off = (prevState == BluetoothAdapter.STATE_TURNING_OFF
- && newState == BluetoothAdapter.STATE_BLE_ON);
+ if (prevState == newState) { // No change. Nothing to do.
+ return;
+ }
+ // Notify all proxy objects first of adapter state change
+ if (newState == BluetoothAdapter.STATE_BLE_ON ||
+ newState == BluetoothAdapter.STATE_OFF) {
+ boolean intermediate_off = (prevState == BluetoothAdapter.STATE_TURNING_OFF
+ && newState == BluetoothAdapter.STATE_BLE_ON);
- if (newState == BluetoothAdapter.STATE_OFF) {
- // If Bluetooth is off, send service down event to proxy objects, and unbind
- if (DBG) Slog.d(TAG, "Bluetooth is complete turn off");
- sendBluetoothServiceDownCallback();
- unbindAndFinish();
- sendBleStateChanged(prevState, newState);
- // Don't broadcast as it has already been broadcast before
- isStandardBroadcast = false;
-
- } else if (!intermediate_off) {
- // connect to GattService
- if (DBG) Slog.d(TAG, "Bluetooth is in LE only mode");
- if (mBluetoothGatt != null) {
- if (DBG) Slog.d(TAG, "Calling BluetoothGattServiceUp");
- onBluetoothGattServiceUp();
- } else {
- if (DBG) Slog.d(TAG, "Binding Bluetooth GATT service");
- if (mContext.getPackageManager().hasSystemFeature(
- PackageManager.FEATURE_BLUETOOTH_LE)) {
- Intent i = new Intent(IBluetoothGatt.class.getName());
- doBind(i, mConnection, Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT, UserHandle.CURRENT);
- }
- }
- sendBleStateChanged(prevState, newState);
- //Don't broadcase this as std intent
- isStandardBroadcast = false;
-
- } else if (intermediate_off){
- if (DBG) Slog.d(TAG, "Intermediate off, back to LE only mode");
- // For LE only mode, broadcast as is
- sendBleStateChanged(prevState, newState);
- sendBluetoothStateCallback(false); // BT is OFF for general users
- // Broadcast as STATE_OFF
- newState = BluetoothAdapter.STATE_OFF;
- sendBrEdrDownCallback();
- }
- } else if (newState == BluetoothAdapter.STATE_ON) {
- boolean isUp = (newState==BluetoothAdapter.STATE_ON);
- sendBluetoothStateCallback(isUp);
+ if (newState == BluetoothAdapter.STATE_OFF) {
+ // If Bluetooth is off, send service down event to proxy objects, and unbind
+ if (DBG) Slog.d(TAG, "Bluetooth is complete send Service Down");
+ sendBluetoothServiceDownCallback();
+ unbindAndFinish();
sendBleStateChanged(prevState, newState);
-
- } else if (newState == BluetoothAdapter.STATE_BLE_TURNING_ON ||
- newState == BluetoothAdapter.STATE_BLE_TURNING_OFF ) {
- sendBleStateChanged(prevState, newState);
+ // Don't broadcast as it has already been broadcast before
isStandardBroadcast = false;
- } else if (newState == BluetoothAdapter.STATE_TURNING_ON ||
- newState == BluetoothAdapter.STATE_TURNING_OFF) {
- sendBleStateChanged(prevState, newState);
- }
-
- if (isStandardBroadcast) {
- if (prevState == BluetoothAdapter.STATE_BLE_ON) {
- // Show prevState of BLE_ON as OFF to standard users
- prevState = BluetoothAdapter.STATE_OFF;
+ } else if (!intermediate_off) {
+ // connect to GattService
+ if (DBG) Slog.d(TAG, "Bluetooth is in LE only mode");
+ if (mBluetoothGatt != null) {
+ if (DBG) Slog.d(TAG, "Calling BluetoothGattServiceUp");
+ onBluetoothGattServiceUp();
+ } else {
+ if (DBG) Slog.d(TAG, "Binding Bluetooth GATT service");
+ if (mContext.getPackageManager().hasSystemFeature(
+ PackageManager.FEATURE_BLUETOOTH_LE)) {
+ Intent i = new Intent(IBluetoothGatt.class.getName());
+ doBind(i, mConnection, Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT, UserHandle.CURRENT);
+ }
}
- Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
- intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, prevState);
- intent.putExtra(BluetoothAdapter.EXTRA_STATE, newState);
- intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
- mContext.sendBroadcastAsUser(intent, UserHandle.ALL, BLUETOOTH_PERM);
+ sendBleStateChanged(prevState, newState);
+ //Don't broadcase this as std intent
+ isStandardBroadcast = false;
+
+ } else if (intermediate_off) {
+ if (DBG) Slog.d(TAG, "Intermediate off, back to LE only mode");
+ // For LE only mode, broadcast as is
+ sendBleStateChanged(prevState, newState);
+ sendBluetoothStateCallback(false); // BT is OFF for general users
+ // Broadcast as STATE_OFF
+ newState = BluetoothAdapter.STATE_OFF;
+ sendBrEdrDownCallback();
}
+ } else if (newState == BluetoothAdapter.STATE_ON) {
+ boolean isUp = (newState == BluetoothAdapter.STATE_ON);
+ sendBluetoothStateCallback(isUp);
+ sendBleStateChanged(prevState, newState);
+
+ } else if (newState == BluetoothAdapter.STATE_BLE_TURNING_ON ||
+ newState == BluetoothAdapter.STATE_BLE_TURNING_OFF ) {
+ sendBleStateChanged(prevState, newState);
+ isStandardBroadcast = false;
+
+ } else if (newState == BluetoothAdapter.STATE_TURNING_ON ||
+ newState == BluetoothAdapter.STATE_TURNING_OFF) {
+ sendBleStateChanged(prevState, newState);
+ }
+
+ if (isStandardBroadcast) {
+ if (prevState == BluetoothAdapter.STATE_BLE_ON) {
+ // Show prevState of BLE_ON as OFF to standard users
+ prevState = BluetoothAdapter.STATE_OFF;
+ }
+ Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
+ intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, prevState);
+ intent.putExtra(BluetoothAdapter.EXTRA_STATE, newState);
+ intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+ mContext.sendBroadcastAsUser(intent, UserHandle.ALL, BLUETOOTH_PERM);
}
}
@@ -1819,13 +1911,24 @@
return false;
}
- private void sendDisableMsg() {
+ private void sendDisableMsg(String packageName) {
mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISABLE));
+ addActiveLog(packageName, false);
}
- private void sendEnableMsg(boolean quietMode) {
+ private void sendEnableMsg(boolean quietMode, String packageName) {
mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_ENABLE,
quietMode ? 1 : 0, 0));
+ addActiveLog(packageName, true);
+ }
+
+ private void addActiveLog(String packageName, boolean enable) {
+ synchronized (mActiveLogs) {
+ if (mActiveLogs.size() > 10) {
+ mActiveLogs.remove();
+ }
+ mActiveLogs.add(new ActiveLog(packageName, enable, System.currentTimeMillis()));
+ }
}
private void recoverBluetoothServiceFromError(boolean clearBle) {
@@ -1896,19 +1999,50 @@
public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
String errorMsg = null;
+
+ boolean protoOut = (args.length > 0) && args[0].startsWith("--proto");
+
+ if (!protoOut) {
+ writer.println("Bluetooth Status");
+ writer.println(" enabled: " + isEnabled());
+ writer.println(" state: " + BluetoothAdapter.nameForState(mState));
+ writer.println(" address: " + mAddress);
+ writer.println(" name: " + mName);
+ if (mEnable) {
+ long onDuration = System.currentTimeMillis() - mActiveLogs.getLast().getTime();
+ String onDurationString = String.format("%02d:%02d:%02d.%03d",
+ (int)(onDuration / (1000 * 60 * 60)),
+ (int)((onDuration / (1000 * 60)) % 60),
+ (int)((onDuration / 1000) % 60),
+ (int)(onDuration % 1000));
+ writer.println(" time since enabled: " + onDurationString + "\n");
+ }
+
+ writer.println("Enable log:");
+ for (ActiveLog log : mActiveLogs) {
+ writer.println(log);
+ }
+
+ writer.println("\n" + mBleApps.size() + " BLE Apps registered:");
+ for (ClientDeathRecipient app : mBleApps.values()) {
+ writer.println(app.getPackageName());
+ }
+
+ writer.flush();
+ }
+
if (mBluetoothBinder == null) {
errorMsg = "Bluetooth Service not connected";
} else {
try {
mBluetoothBinder.dump(fd, args);
} catch (RemoteException re) {
- errorMsg = "RemoteException while calling Bluetooth Service";
+ errorMsg = "RemoteException while dumping Bluetooth Service";
}
}
if (errorMsg != null) {
// Silently return if we are extracting metrics in Protobuf format
- if ((args.length > 0) && args[0].startsWith("--proto"))
- return;
+ if (protoOut) return;
writer.println(errorMsg);
}
}
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 090c744..66f5c4d 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -720,16 +720,6 @@
mHandler = new InternalHandler(mHandlerThread.getLooper());
mTrackerHandler = new NetworkStateTrackerHandler(mHandlerThread.getLooper());
- // setup our unique device name
- if (TextUtils.isEmpty(SystemProperties.get("net.hostname"))) {
- String id = Settings.Secure.getString(context.getContentResolver(),
- Settings.Secure.ANDROID_ID);
- if (id != null && id.length() > 0) {
- String name = new String("android-").concat(id);
- SystemProperties.set("net.hostname", name);
- }
- }
-
mReleasePendingIntentDelayMs = Settings.Secure.getInt(context.getContentResolver(),
Settings.Secure.CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS, 5_000);
@@ -866,6 +856,7 @@
mAvoidBadWifiTracker = createAvoidBadWifiTracker(
mContext, mHandler, () -> rematchForAvoidBadWifiUpdate());
+ mAvoidBadWifiTracker.start();
}
private NetworkRequest createInternetRequestForTransport(
@@ -4615,28 +4606,9 @@
} catch (Exception e) {
loge("Exception in setDnsConfigurationForNetwork: " + e);
}
- final NetworkAgentInfo defaultNai = getDefaultNetwork();
- if (defaultNai != null && defaultNai.network.netId == netId) {
- setDefaultDnsSystemProperties(dnses);
- }
flushVmDnsCache();
}
- private void setDefaultDnsSystemProperties(Collection<InetAddress> dnses) {
- int last = 0;
- for (InetAddress dns : dnses) {
- ++last;
- String key = "net.dns" + last;
- String value = dns.getHostAddress();
- SystemProperties.set(key, value);
- }
- for (int i = last + 1; i <= mNumDnsEntries; ++i) {
- String key = "net.dns" + i;
- SystemProperties.set(key, "");
- }
- mNumDnsEntries = last;
- }
-
private String getNetworkPermission(NetworkCapabilities nc) {
// TODO: make these permission strings AIDL constants instead.
if (!nc.hasCapability(NET_CAPABILITY_NOT_RESTRICTED)) {
@@ -4853,7 +4825,6 @@
notifyLockdownVpn(newNetwork);
handleApplyDefaultProxy(newNetwork.linkProperties.getHttpProxy());
updateTcpBufferSizes(newNetwork);
- setDefaultDnsSystemProperties(newNetwork.linkProperties.getDnsServers());
}
private void processListenRequests(NetworkAgentInfo nai, boolean capabilitiesChanged) {
diff --git a/services/core/java/com/android/server/ContextHubSystemService.java b/services/core/java/com/android/server/ContextHubSystemService.java
index 1b85632..06abca9 100644
--- a/services/core/java/com/android/server/ContextHubSystemService.java
+++ b/services/core/java/com/android/server/ContextHubSystemService.java
@@ -37,7 +37,7 @@
public void onBootPhase(int phase) {
if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
Log.d(TAG, "onBootPhase: PHASE_SYSTEM_SERVICES_READY");
- publishBinderService(ContextHubService.CONTEXTHUB_SERVICE, mContextHubService);
+ publishBinderService(Context.CONTEXTHUB_SERVICE, mContextHubService);
}
}
}
diff --git a/services/core/java/com/android/server/DeviceIdleController.java b/services/core/java/com/android/server/DeviceIdleController.java
index 4405c1b..97f913e 100644
--- a/services/core/java/com/android/server/DeviceIdleController.java
+++ b/services/core/java/com/android/server/DeviceIdleController.java
@@ -49,7 +49,6 @@
import android.os.Environment;
import android.os.FileUtils;
import android.os.Handler;
-import android.os.IBinder;
import android.os.IDeviceIdleController;
import android.os.IMaintenanceActivityListener;
import android.os.Looper;
@@ -1238,7 +1237,7 @@
}
}
- public final class LocalService {
+ public class LocalService {
public void addPowerSaveTempWhitelistAppDirect(int appId, long duration, boolean sync,
String reason) {
addPowerSaveTempWhitelistAppDirectInternal(0, appId, duration, sync, reason);
diff --git a/services/core/java/com/android/server/NetworkScoreService.java b/services/core/java/com/android/server/NetworkScoreService.java
index 6412e01..983d039 100644
--- a/services/core/java/com/android/server/NetworkScoreService.java
+++ b/services/core/java/com/android/server/NetworkScoreService.java
@@ -16,7 +16,11 @@
package com.android.server;
+import static android.net.NetworkRecommendationProvider.EXTRA_RECOMMENDATION_RESULT;
+import static android.net.NetworkRecommendationProvider.EXTRA_SEQUENCE;
+
import android.Manifest.permission;
+import android.annotation.Nullable;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -25,26 +29,30 @@
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
+import android.database.ContentObserver;
+import android.net.INetworkRecommendationProvider;
import android.net.INetworkScoreCache;
import android.net.INetworkScoreService;
-import android.net.NetworkScoreManager;
+import android.net.NetworkKey;
import android.net.NetworkScorerAppManager;
import android.net.NetworkScorerAppManager.NetworkScorerAppData;
+import android.net.NetworkScoreManager;
import android.net.RecommendationRequest;
import android.net.RecommendationResult;
import android.net.ScoredNetwork;
-import android.net.wifi.WifiConfiguration;
+import android.net.Uri;
import android.os.Binder;
+import android.os.Bundle;
import android.os.IBinder;
+import android.os.IRemoteCallback;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.os.UserHandle;
-import android.provider.Settings;
-import android.text.TextUtils;
+import android.provider.Settings.Global;
import android.util.ArrayMap;
import android.util.Log;
+import android.util.TimedRemoteCaller;
-import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.content.PackageMonitor;
@@ -58,6 +66,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;
/**
@@ -66,17 +75,20 @@
*/
public class NetworkScoreService extends INetworkScoreService.Stub {
private static final String TAG = "NetworkScoreService";
- private static final boolean DBG = false;
+ private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);
private final Context mContext;
private final NetworkScorerAppManager mNetworkScorerAppManager;
+ private final RequestRecommendationCaller mRequestRecommendationCaller;
@GuardedBy("mScoreCaches")
private final Map<Integer, RemoteCallbackList<INetworkScoreCache>> mScoreCaches;
/** Lock used to update mPackageMonitor when scorer package changes occur. */
private final Object mPackageMonitorLock = new Object[0];
+ private final Object mServiceConnectionLock = new Object[0];
@GuardedBy("mPackageMonitorLock")
private NetworkScorerPackageMonitor mPackageMonitor;
+ @GuardedBy("mServiceConnectionLock")
private ScoringServiceConnection mServiceConnection;
private BroadcastReceiver mUserIntentReceiver = new BroadcastReceiver() {
@@ -98,10 +110,10 @@
* manages the service connection.
*/
private class NetworkScorerPackageMonitor extends PackageMonitor {
- final String mRegisteredPackage;
+ final List<String> mPackagesToWatch;
- private NetworkScorerPackageMonitor(String mRegisteredPackage) {
- this.mRegisteredPackage = mRegisteredPackage;
+ private NetworkScorerPackageMonitor(List<String> packagesToWatch) {
+ mPackagesToWatch = packagesToWatch;
}
@Override
@@ -135,29 +147,61 @@
}
private void evaluateBinding(String scorerPackageName, boolean forceUnbind) {
- if (mRegisteredPackage.equals(scorerPackageName)) {
- if (DBG) {
- Log.d(TAG, "Evaluating binding for: " + scorerPackageName
- + ", forceUnbind=" + forceUnbind);
- }
- final NetworkScorerAppData activeScorer =
- mNetworkScorerAppManager.getActiveScorer();
- if (activeScorer == null) {
- // Package change has invalidated a scorer, this will also unbind any service
- // connection.
- Log.i(TAG, "Package " + mRegisteredPackage +
- " is no longer valid, disabling scoring.");
- setScorerInternal(null);
- } else if (activeScorer.mScoringServiceClassName == null) {
- // The scoring service is not available, make sure it's unbound.
- unbindFromScoringServiceIfNeeded();
- } else { // The scoring service changed in some way.
- if (forceUnbind) {
- unbindFromScoringServiceIfNeeded();
- }
- bindToScoringServiceIfNeeded(activeScorer);
- }
+ if (!mPackagesToWatch.contains(scorerPackageName)) {
+ // Early exit when we don't care about the package that has changed.
+ return;
}
+
+ if (DBG) {
+ Log.d(TAG, "Evaluating binding for: " + scorerPackageName
+ + ", forceUnbind=" + forceUnbind);
+ }
+ final NetworkScorerAppData activeScorer = mNetworkScorerAppManager.getActiveScorer();
+ if (activeScorer == null) {
+ // Package change has invalidated a scorer, this will also unbind any service
+ // connection.
+ if (DBG) Log.d(TAG, "No active scorers available.");
+ unbindFromScoringServiceIfNeeded();
+ } else if (activeScorer.packageName.equals(scorerPackageName)) {
+ // The active scoring service changed in some way.
+ if (DBG) {
+ Log.d(TAG, "Possible change to the active scorer: "
+ + activeScorer.packageName);
+ }
+ if (forceUnbind) {
+ unbindFromScoringServiceIfNeeded();
+ }
+ bindToScoringServiceIfNeeded(activeScorer);
+ } else {
+ // One of the scoring apps on the device has changed and we may no longer be
+ // bound to the correct scoring app. The logic in bindToScoringServiceIfNeeded()
+ // will sort that out to leave us bound to the most recent active scorer.
+ if (DBG) {
+ Log.d(TAG, "Binding to " + activeScorer.packageName + " if needed.");
+ }
+ bindToScoringServiceIfNeeded(activeScorer);
+ }
+ }
+ }
+
+ /**
+ * Reevaluates the service binding when the Settings toggle is changed.
+ */
+ private class SettingsObserver extends ContentObserver {
+
+ public SettingsObserver() {
+ super(null /*handler*/);
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ onChange(selfChange, null);
+ }
+
+ @Override
+ public void onChange(boolean selfChange, Uri uri) {
+ if (DBG) Log.d(TAG, String.format("onChange(%s, %s)", selfChange, uri));
+ bindToScoringServiceIfNeeded();
}
}
@@ -175,24 +219,16 @@
mContext.registerReceiverAsUser(
mUserIntentReceiver, UserHandle.SYSTEM, filter, null /* broadcastPermission*/,
null /* scheduler */);
+ // TODO(jjoslin): 12/15/16 - Make timeout configurable.
+ mRequestRecommendationCaller =
+ new RequestRecommendationCaller(TimedRemoteCaller.DEFAULT_CALL_TIMEOUT_MILLIS);
}
/** Called when the system is ready to run third-party code but before it actually does so. */
void systemReady() {
if (DBG) Log.d(TAG, "systemReady");
- ContentResolver cr = mContext.getContentResolver();
- if (Settings.Global.getInt(cr, Settings.Global.NETWORK_SCORING_PROVISIONED, 0) == 0) {
- // On first run, we try to initialize the scorer to the one configured at build time.
- // This will be a no-op if the scorer isn't actually valid.
- String defaultPackage = mContext.getResources().getString(
- R.string.config_defaultNetworkScorerPackageName);
- if (!TextUtils.isEmpty(defaultPackage)) {
- mNetworkScorerAppManager.setActiveScorer(defaultPackage);
- }
- Settings.Global.putInt(cr, Settings.Global.NETWORK_SCORING_PROVISIONED, 1);
- }
-
registerPackageMonitorIfNeeded();
+ registerRecommendationSettingObserverIfNeeded();
}
/** Called when the system is ready for us to start third-party code. */
@@ -206,29 +242,40 @@
bindToScoringServiceIfNeeded();
}
+ private void registerRecommendationSettingObserverIfNeeded() {
+ final List<String> providerPackages =
+ mNetworkScorerAppManager.getPotentialRecommendationProviderPackages();
+ if (!providerPackages.isEmpty()) {
+ final ContentResolver resolver = mContext.getContentResolver();
+ final Uri uri = Global.getUriFor(Global.NETWORK_RECOMMENDATIONS_ENABLED);
+ resolver.registerContentObserver(uri, false, new SettingsObserver());
+ }
+ }
+
private void registerPackageMonitorIfNeeded() {
if (DBG) Log.d(TAG, "registerPackageMonitorIfNeeded");
- NetworkScorerAppData scorer = mNetworkScorerAppManager.getActiveScorer();
+ final List<String> providerPackages =
+ mNetworkScorerAppManager.getPotentialRecommendationProviderPackages();
synchronized (mPackageMonitorLock) {
// Unregister the current monitor if needed.
if (mPackageMonitor != null) {
if (DBG) {
Log.d(TAG, "Unregistering package monitor for "
- + mPackageMonitor.mRegisteredPackage);
+ + mPackageMonitor.mPackagesToWatch);
}
mPackageMonitor.unregister();
mPackageMonitor = null;
}
- // Create and register the monitor if a scorer is active.
- if (scorer != null) {
- mPackageMonitor = new NetworkScorerPackageMonitor(scorer.mPackageName);
+ // Create and register the monitor if there are packages that could be providers.
+ if (!providerPackages.isEmpty()) {
+ mPackageMonitor = new NetworkScorerPackageMonitor(providerPackages);
// TODO: Need to update when we support per-user scorers. http://b/23422763
mPackageMonitor.register(mContext, null /* thread */, UserHandle.SYSTEM,
false /* externalStorage */);
if (DBG) {
Log.d(TAG, "Registered package monitor for "
- + mPackageMonitor.mRegisteredPackage);
+ + mPackageMonitor.mPackagesToWatch);
}
}
}
@@ -242,22 +289,24 @@
private void bindToScoringServiceIfNeeded(NetworkScorerAppData scorerData) {
if (DBG) Log.d(TAG, "bindToScoringServiceIfNeeded(" + scorerData + ")");
- if (scorerData != null && scorerData.mScoringServiceClassName != null) {
- ComponentName componentName =
- new ComponentName(scorerData.mPackageName, scorerData.mScoringServiceClassName);
- // If we're connected to a different component then drop it.
- if (mServiceConnection != null
- && !mServiceConnection.mComponentName.equals(componentName)) {
- unbindFromScoringServiceIfNeeded();
- }
+ if (scorerData != null && scorerData.recommendationServiceClassName != null) {
+ ComponentName componentName = new ComponentName(scorerData.packageName,
+ scorerData.recommendationServiceClassName);
+ synchronized (mServiceConnectionLock) {
+ // If we're connected to a different component then drop it.
+ if (mServiceConnection != null
+ && !mServiceConnection.mComponentName.equals(componentName)) {
+ unbindFromScoringServiceIfNeeded();
+ }
- // If we're not connected at all then create a new connection.
- if (mServiceConnection == null) {
- mServiceConnection = new ScoringServiceConnection(componentName);
- }
+ // If we're not connected at all then create a new connection.
+ if (mServiceConnection == null) {
+ mServiceConnection = new ScoringServiceConnection(componentName);
+ }
- // Make sure the connection is connected (idempotent)
- mServiceConnection.connect(mContext);
+ // Make sure the connection is connected (idempotent)
+ mServiceConnection.connect(mContext);
+ }
} else { // otherwise make sure it isn't bound.
unbindFromScoringServiceIfNeeded();
}
@@ -265,10 +314,13 @@
private void unbindFromScoringServiceIfNeeded() {
if (DBG) Log.d(TAG, "unbindFromScoringServiceIfNeeded");
- if (mServiceConnection != null) {
- mServiceConnection.disconnect(mContext);
+ synchronized (mServiceConnectionLock) {
+ if (mServiceConnection != null) {
+ mServiceConnection.disconnect(mContext);
+ }
+ mServiceConnection = null;
}
- mServiceConnection = null;
+ clearInternal();
}
@Override
@@ -278,47 +330,54 @@
" is not the active scorer.");
}
- // Separate networks by type.
- Map<Integer, List<ScoredNetwork>> networksByType = new ArrayMap<>();
- for (ScoredNetwork network : networks) {
- List<ScoredNetwork> networkList = networksByType.get(network.networkKey.type);
- if (networkList == null) {
- networkList = new ArrayList<>();
- networksByType.put(network.networkKey.type, networkList);
- }
- networkList.add(network);
- }
-
- // Pass the scores of each type down to the appropriate network scorer.
- for (final Map.Entry<Integer, List<ScoredNetwork>> entry : networksByType.entrySet()) {
- final RemoteCallbackList<INetworkScoreCache> callbackList;
- final boolean isEmpty;
- synchronized (mScoreCaches) {
- callbackList = mScoreCaches.get(entry.getKey());
- isEmpty = callbackList == null || callbackList.getRegisteredCallbackCount() == 0;
- }
- if (isEmpty) {
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "No scorer registered for type " + entry.getKey() + ", discarding");
+ final long token = Binder.clearCallingIdentity();
+ try {
+ // Separate networks by type.
+ Map<Integer, List<ScoredNetwork>> networksByType = new ArrayMap<>();
+ for (ScoredNetwork network : networks) {
+ List<ScoredNetwork> networkList = networksByType.get(network.networkKey.type);
+ if (networkList == null) {
+ networkList = new ArrayList<>();
+ networksByType.put(network.networkKey.type, networkList);
}
- continue;
+ networkList.add(network);
}
- sendCallback(new Consumer<INetworkScoreCache>() {
- @Override
- public void accept(INetworkScoreCache networkScoreCache) {
- try {
- networkScoreCache.updateScores(entry.getValue());
- } catch (RemoteException e) {
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "Unable to update scores of type " + entry.getKey(), e);
+ // Pass the scores of each type down to the appropriate network scorer.
+ for (final Map.Entry<Integer, List<ScoredNetwork>> entry : networksByType.entrySet()) {
+ final RemoteCallbackList<INetworkScoreCache> callbackList;
+ final boolean isEmpty;
+ synchronized (mScoreCaches) {
+ callbackList = mScoreCaches.get(entry.getKey());
+ isEmpty = callbackList == null
+ || callbackList.getRegisteredCallbackCount() == 0;
+ }
+ if (isEmpty) {
+ if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ Log.v(TAG, "No scorer registered for type " + entry.getKey()
+ + ", discarding");
+ }
+ continue;
+ }
+
+ sendCallback(new Consumer<INetworkScoreCache>() {
+ @Override
+ public void accept(INetworkScoreCache networkScoreCache) {
+ try {
+ networkScoreCache.updateScores(entry.getValue());
+ } catch (RemoteException e) {
+ if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ Log.v(TAG, "Unable to update scores of type " + entry.getKey(), e);
+ }
}
}
- }
- }, Collections.singleton(callbackList));
- }
+ }, Collections.singleton(callbackList));
+ }
- return true;
+ return true;
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
}
@Override
@@ -328,8 +387,13 @@
if (mNetworkScorerAppManager.isCallerActiveScorer(getCallingUid()) ||
mContext.checkCallingOrSelfPermission(permission.BROADCAST_NETWORK_PRIVILEGED) ==
PackageManager.PERMISSION_GRANTED) {
- clearInternal();
- return true;
+ final long token = Binder.clearCallingIdentity();
+ try {
+ clearInternal();
+ return true;
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
} else {
throw new SecurityException(
"Caller is neither the active scorer nor the scorer manager.");
@@ -348,7 +412,8 @@
// mContext.enforceCallingOrSelfPermission(permission.BROADCAST_NETWORK_PRIVILEGED, TAG);
mContext.enforceCallingOrSelfPermission(permission.SCORE_NETWORKS, TAG);
- return setScorerInternal(packageName);
+ // Scorers (recommendation providers) are selected and no longer set.
+ return false;
}
@Override
@@ -358,56 +423,13 @@
if (mNetworkScorerAppManager.isCallerActiveScorer(getCallingUid()) ||
mContext.checkCallingOrSelfPermission(permission.BROADCAST_NETWORK_PRIVILEGED) ==
PackageManager.PERMISSION_GRANTED) {
- // The return value is discarded here because at this point, the call should always
- // succeed. The only reason for failure is if the new package is not a valid scorer, but
- // we're disabling scoring altogether here.
- setScorerInternal(null /* packageName */);
+ // no-op for now but we could write to the setting if needed.
} else {
throw new SecurityException(
"Caller is neither the active scorer nor the scorer manager.");
}
}
- /** Set the active scorer. Callers are responsible for checking permissions as appropriate. */
- private boolean setScorerInternal(String packageName) {
- if (DBG) Log.d(TAG, "setScorerInternal(" + packageName + ")");
- long token = Binder.clearCallingIdentity();
- try {
- unbindFromScoringServiceIfNeeded();
- // Preemptively clear scores even though the set operation could fail. We do this for
- // safety as scores should never be compared across apps; in practice, Settings should
- // only be allowing valid apps to be set as scorers, so failure here should be rare.
- clearInternal();
- // Get the scorer that is about to be replaced, if any, so we can notify it directly.
- NetworkScorerAppData prevScorer = mNetworkScorerAppManager.getActiveScorer();
- boolean result = mNetworkScorerAppManager.setActiveScorer(packageName);
- // Unconditionally attempt to bind to the current scorer. If setActiveScorer() failed
- // then we'll attempt to restore the previous binding (if any), otherwise an attempt
- // will be made to bind to the new scorer.
- bindToScoringServiceIfNeeded();
- if (result) { // new scorer successfully set
- registerPackageMonitorIfNeeded();
-
- Intent intent = new Intent(NetworkScoreManager.ACTION_SCORER_CHANGED);
- if (prevScorer != null) { // Directly notify the old scorer.
- intent.setPackage(prevScorer.mPackageName);
- // TODO: Need to update when we support per-user scorers. http://b/23422763
- mContext.sendBroadcastAsUser(intent, UserHandle.SYSTEM);
- }
-
- if (packageName != null) { // Then notify the new scorer
- intent.putExtra(NetworkScoreManager.EXTRA_NEW_SCORER, packageName);
- intent.setPackage(packageName);
- // TODO: Need to update when we support per-user scorers. http://b/23422763
- mContext.sendBroadcastAsUser(intent, UserHandle.SYSTEM);
- }
- }
- return result;
- } finally {
- Binder.restoreCallingIdentity(token);
- }
- }
-
/** Clear scores. Callers are responsible for checking permissions as appropriate. */
private void clearInternal() {
sendCallback(new Consumer<INetworkScoreCache>() {
@@ -425,48 +447,104 @@
}
@Override
- public void registerNetworkScoreCache(int networkType, INetworkScoreCache scoreCache) {
+ public void registerNetworkScoreCache(int networkType,
+ INetworkScoreCache scoreCache,
+ int filterType) {
mContext.enforceCallingOrSelfPermission(permission.BROADCAST_NETWORK_PRIVILEGED, TAG);
- synchronized (mScoreCaches) {
- RemoteCallbackList<INetworkScoreCache> callbackList = mScoreCaches.get(networkType);
- if (callbackList == null) {
- callbackList = new RemoteCallbackList<>();
- mScoreCaches.put(networkType, callbackList);
- }
- if (!callbackList.register(scoreCache)) {
- if (callbackList.getRegisteredCallbackCount() == 0) {
- mScoreCaches.remove(networkType);
+ final long token = Binder.clearCallingIdentity();
+ try {
+ synchronized (mScoreCaches) {
+ RemoteCallbackList<INetworkScoreCache> callbackList = mScoreCaches.get(networkType);
+ if (callbackList == null) {
+ callbackList = new RemoteCallbackList<>();
+ mScoreCaches.put(networkType, callbackList);
}
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "Unable to register NetworkScoreCache for type " + networkType);
+ if (!callbackList.register(scoreCache, filterType)) {
+ if (callbackList.getRegisteredCallbackCount() == 0) {
+ mScoreCaches.remove(networkType);
+ }
+ if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ Log.v(TAG, "Unable to register NetworkScoreCache for type " + networkType);
+ }
}
}
+ } finally {
+ Binder.restoreCallingIdentity(token);
}
}
@Override
public void unregisterNetworkScoreCache(int networkType, INetworkScoreCache scoreCache) {
mContext.enforceCallingOrSelfPermission(permission.BROADCAST_NETWORK_PRIVILEGED, TAG);
- synchronized (mScoreCaches) {
- RemoteCallbackList<INetworkScoreCache> callbackList = mScoreCaches.get(networkType);
- if (callbackList == null || !callbackList.unregister(scoreCache)) {
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "Unable to unregister NetworkScoreCache for type " + networkType);
+ final long token = Binder.clearCallingIdentity();
+ try {
+ synchronized (mScoreCaches) {
+ RemoteCallbackList<INetworkScoreCache> callbackList = mScoreCaches.get(networkType);
+ if (callbackList == null || !callbackList.unregister(scoreCache)) {
+ if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ Log.v(TAG, "Unable to unregister NetworkScoreCache for type "
+ + networkType);
+ }
+ } else if (callbackList.getRegisteredCallbackCount() == 0) {
+ mScoreCaches.remove(networkType);
}
- } else if (callbackList.getRegisteredCallbackCount() == 0) {
- mScoreCaches.remove(networkType);
}
+ } finally {
+ Binder.restoreCallingIdentity(token);
}
}
@Override
public RecommendationResult requestRecommendation(RecommendationRequest request) {
- // TODO(jjoslin): 11/25/16 - Update with real impl.
- WifiConfiguration selectedConfig = null;
- if (request != null) {
- selectedConfig = request.getCurrentSelectedConfig();
+ mContext.enforceCallingOrSelfPermission(permission.BROADCAST_NETWORK_PRIVILEGED, TAG);
+ throwIfCalledOnMainThread();
+ final long token = Binder.clearCallingIdentity();
+ try {
+ final INetworkRecommendationProvider provider = getRecommendationProvider();
+ if (provider != null) {
+ try {
+ return mRequestRecommendationCaller.getRecommendationResult(provider, request);
+ } catch (RemoteException | TimeoutException e) {
+ Log.w(TAG, "Failed to request a recommendation.", e);
+ // TODO(jjoslin): 12/15/16 - Keep track of failures.
+ }
+ }
+
+ if (DBG) {
+ Log.d(TAG, "Returning the default network recommendation.");
+ }
+
+ if (request != null && request.getCurrentSelectedConfig() != null) {
+ return RecommendationResult.createConnectRecommendation(
+ request.getCurrentSelectedConfig());
+ }
+ return RecommendationResult.createDoNotConnectRecommendation();
+ } finally {
+ Binder.restoreCallingIdentity(token);
}
- return new RecommendationResult(selectedConfig);
+ }
+
+ @Override
+ public boolean requestScores(NetworkKey[] networks) {
+ mContext.enforceCallingOrSelfPermission(permission.BROADCAST_NETWORK_PRIVILEGED, TAG);
+ final long token = Binder.clearCallingIdentity();
+ try {
+ final INetworkRecommendationProvider provider = getRecommendationProvider();
+ if (provider != null) {
+ try {
+ provider.requestScores(networks);
+ // TODO(jjoslin): 12/15/16 - Consider pushing null scores into the cache to
+ // prevent repeated requests for the same scores.
+ return true;
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed to request scores.", e);
+ // TODO(jjoslin): 12/15/16 - Keep track of failures.
+ }
+ }
+ return false;
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
}
@Override
@@ -477,7 +555,7 @@
writer.println("Scoring is disabled.");
return;
}
- writer.println("Current scorer: " + currentScorer.mPackageName);
+ writer.println("Current scorer: " + currentScorer.packageName);
sendCallback(new Consumer<INetworkScoreCache>() {
@Override
@@ -490,10 +568,12 @@
}
}, getScoreCacheLists());
- if (mServiceConnection != null) {
- mServiceConnection.dump(fd, writer, args);
- } else {
- writer.println("ScoringServiceConnection: null");
+ synchronized (mServiceConnectionLock) {
+ if (mServiceConnection != null) {
+ mServiceConnection.dump(fd, writer, args);
+ } else {
+ writer.println("ScoringServiceConnection: null");
+ }
}
writer.flush();
}
@@ -526,10 +606,27 @@
}
}
+ private void throwIfCalledOnMainThread() {
+ if (Thread.currentThread() == mContext.getMainLooper().getThread()) {
+ throw new RuntimeException("Cannot invoke on the main thread");
+ }
+ }
+
+ @Nullable
+ private INetworkRecommendationProvider getRecommendationProvider() {
+ synchronized (mServiceConnectionLock) {
+ if (mServiceConnection != null) {
+ return mServiceConnection.getRecommendationProvider();
+ }
+ }
+ return null;
+ }
+
private static class ScoringServiceConnection implements ServiceConnection {
private final ComponentName mComponentName;
- private boolean mBound = false;
- private boolean mConnected = false;
+ private volatile boolean mBound = false;
+ private volatile boolean mConnected = false;
+ private volatile INetworkRecommendationProvider mRecommendationProvider;
ScoringServiceConnection(ComponentName componentName) {
mComponentName = componentName;
@@ -537,7 +634,7 @@
void connect(Context context) {
if (!mBound) {
- Intent service = new Intent();
+ Intent service = new Intent(NetworkScoreManager.ACTION_RECOMMEND_NETWORKS);
service.setComponent(mComponentName);
mBound = context.bindServiceAsUser(service, this,
Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE,
@@ -560,12 +657,19 @@
} catch (RuntimeException e) {
Log.e(TAG, "Unbind failed.", e);
}
+
+ mRecommendationProvider = null;
+ }
+
+ INetworkRecommendationProvider getRecommendationProvider() {
+ return mRecommendationProvider;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
if (DBG) Log.d(TAG, "ScoringServiceConnection: " + name.flattenToString());
mConnected = true;
+ mRecommendationProvider = INetworkRecommendationProvider.Stub.asInterface(service);
}
@Override
@@ -574,6 +678,7 @@
Log.d(TAG, "ScoringServiceConnection, disconnected: " + name.flattenToString());
}
mConnected = false;
+ mRecommendationProvider = null;
}
public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
@@ -581,4 +686,43 @@
+ ", connected: " + mConnected);
}
}
+
+ /**
+ * Executes the async requestRecommendation() call with a timeout.
+ */
+ private static final class RequestRecommendationCaller
+ extends TimedRemoteCaller<RecommendationResult> {
+ private final IRemoteCallback mCallback;
+
+ RequestRecommendationCaller(long callTimeoutMillis) {
+ super(callTimeoutMillis);
+ mCallback = new IRemoteCallback.Stub() {
+ @Override
+ public void sendResult(Bundle data) throws RemoteException {
+ final RecommendationResult result =
+ data.getParcelable(EXTRA_RECOMMENDATION_RESULT);
+ final int sequence = data.getInt(EXTRA_SEQUENCE, -1);
+ onRemoteMethodResult(result, sequence);
+ }
+ };
+ }
+
+ /**
+ * Runs the requestRecommendation() call on the given {@link INetworkRecommendationProvider}
+ * instance.
+ *
+ * @param target the {@link INetworkRecommendationProvider} to request a recommendation
+ * from
+ * @param request the {@link RecommendationRequest} from the calling client
+ * @return a {@link RecommendationResult} from the provider
+ * @throws RemoteException if the call failed
+ * @throws TimeoutException if the call took longer than the set timeout
+ */
+ RecommendationResult getRecommendationResult(INetworkRecommendationProvider target,
+ RecommendationRequest request) throws RemoteException, TimeoutException {
+ final int sequence = onBeforeRemoteCall();
+ target.requestRecommendation(request, mCallback, sequence);
+ return getResultTimed(sequence);
+ }
+ }
}
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index 10a5388..ae1aef6 100644
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -369,7 +369,7 @@
// we do not start the service and launch a review activity if the calling app
// is in the foreground passing it a pending intent to start the service when
// review is completed.
- if (Build.PERMISSIONS_REVIEW_REQUIRED) {
+ if (mAm.mPermissionReviewRequired || Build.PERMISSIONS_REVIEW_REQUIRED) {
if (!requestStartTargetPermissionsReviewIfNeededLocked(r, callingPackage,
callingUid, service, callerFg, userId)) {
return null;
@@ -913,7 +913,7 @@
// we schedule binding to the service but do not start its process, then
// we launch a review activity to which is passed a callback to invoke
// when done to start the bound service's process to completing the binding.
- if (Build.PERMISSIONS_REVIEW_REQUIRED) {
+ if (mAm.mPermissionReviewRequired || Build.PERMISSIONS_REVIEW_REQUIRED) {
if (mAm.getPackageManagerInternalLocked().isPermissionsReviewRequired(
s.packageName, s.userId)) {
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 4cf1ef5..5b02c79 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -35,7 +35,6 @@
import com.android.internal.os.ProcessCpuTracker;
import com.android.internal.os.TransferPipe;
import com.android.internal.os.Zygote;
-import com.android.internal.os.InstallerConnection.InstallerException;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.FastXmlSerializer;
@@ -54,6 +53,7 @@
import com.android.server.am.ActivityStack.ActivityState;
import com.android.server.firewall.IntentFirewall;
import com.android.server.pm.Installer;
+import com.android.server.pm.Installer.InstallerException;
import com.android.server.statusbar.StatusBarManagerInternal;
import com.android.server.vr.VrManagerInternal;
import com.android.server.wm.WindowManagerService;
@@ -1575,6 +1575,8 @@
// being called for multiwindow assist in a single session.
private int mViSessionId = 1000;
+ final boolean mPermissionReviewRequired;
+
final class KillHandler extends Handler {
static final int KILL_PROCESS_GROUP_MSG = 4000;
@@ -2622,6 +2624,9 @@
Slog.i(TAG, "Memory class: " + ActivityManager.staticGetMemoryClass());
+ mPermissionReviewRequired = mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_permissionReviewRequired);
+
mHandlerThread = new ServiceThread(TAG,
android.os.Process.THREAD_PRIORITY_FOREGROUND, false /*allowIo*/);
mHandlerThread.start();
@@ -3778,6 +3783,15 @@
mNativeDebuggingApp = null;
}
+ String invokeWith = null;
+ if ((app.info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
+ // Debuggable apps may include a wrapper script with their library directory.
+ String wrapperFileName = app.info.nativeLibraryDir + "/wrap.sh";
+ if (new File(wrapperFileName).exists()) {
+ invokeWith = "/system/bin/logwrapper " + wrapperFileName;
+ }
+ }
+
String requiredAbi = (abiOverride != null) ? abiOverride : app.info.primaryCpuAbi;
if (requiredAbi == null) {
requiredAbi = Build.SUPPORTED_ABIS[0];
@@ -3804,12 +3818,12 @@
startResult = Process.startWebView(entryPoint,
app.processName, uid, uid, gids, debugFlags, mountExternal,
app.info.targetSdkVersion, app.info.seinfo, requiredAbi, instructionSet,
- app.info.dataDir, entryPointArgs);
+ app.info.dataDir, null, entryPointArgs);
} else {
startResult = Process.start(entryPoint,
app.processName, uid, uid, gids, debugFlags, mountExternal,
app.info.targetSdkVersion, app.info.seinfo, requiredAbi, instructionSet,
- app.info.dataDir, entryPointArgs);
+ app.info.dataDir, invokeWith, entryPointArgs);
}
checkTime(startTime, "startProcess: returned from zygote!");
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
@@ -10824,7 +10838,7 @@
// If permissions need a review before any of the app components can run,
// we return no provider and launch a review activity if the calling app
// is in the foreground.
- if (Build.PERMISSIONS_REVIEW_REQUIRED) {
+ if (mPermissionReviewRequired || Build.PERMISSIONS_REVIEW_REQUIRED) {
if (!requestTargetProviderPermissionsReviewIfNeededLocked(cpi, r, userId)) {
return null;
}
diff --git a/services/core/java/com/android/server/am/ActivityStarter.java b/services/core/java/com/android/server/am/ActivityStarter.java
index 115971f..907394e 100644
--- a/services/core/java/com/android/server/am/ActivityStarter.java
+++ b/services/core/java/com/android/server/am/ActivityStarter.java
@@ -416,7 +416,8 @@
// If permissions need a review before any of the app components can run, we
// launch the review activity and pass a pending intent to start the activity
// we are to launching now after the review is completed.
- if (Build.PERMISSIONS_REVIEW_REQUIRED && aInfo != null) {
+ if ((mService.mPermissionReviewRequired
+ || Build.PERMISSIONS_REVIEW_REQUIRED) && aInfo != null) {
if (mService.getPackageManagerInternalLocked().isPermissionsReviewRequired(
aInfo.packageName, userId)) {
IIntentSender target = mService.getIntentSenderLocked(
diff --git a/services/core/java/com/android/server/am/BroadcastQueue.java b/services/core/java/com/android/server/am/BroadcastQueue.java
index 362a347..ea901ce 100644
--- a/services/core/java/com/android/server/am/BroadcastQueue.java
+++ b/services/core/java/com/android/server/am/BroadcastQueue.java
@@ -626,7 +626,7 @@
// the broadcast and if the calling app is in the foreground and the broadcast is
// explicit we launch the review UI passing it a pending intent to send the skipped
// broadcast.
- if (Build.PERMISSIONS_REVIEW_REQUIRED) {
+ if (mService.mPermissionReviewRequired || Build.PERMISSIONS_REVIEW_REQUIRED) {
if (!requestStartTargetPermissionsReviewIfNeededLocked(r, filter.packageName,
filter.owningUserId)) {
r.delivery[index] = BroadcastRecord.DELIVERY_SKIPPED;
@@ -1132,7 +1132,8 @@
// the broadcast and if the calling app is in the foreground and the broadcast is
// explicit we launch the review UI passing it a pending intent to send the skipped
// broadcast.
- if (Build.PERMISSIONS_REVIEW_REQUIRED && !skip) {
+ if ((mService.mPermissionReviewRequired
+ || Build.PERMISSIONS_REVIEW_REQUIRED) && !skip) {
if (!requestStartTargetPermissionsReviewIfNeededLocked(r,
info.activityInfo.packageName, UserHandle.getUserId(
info.activityInfo.applicationInfo.uid))) {
diff --git a/services/core/java/com/android/server/connectivity/IpConnectivityEventBuilder.java b/services/core/java/com/android/server/connectivity/IpConnectivityEventBuilder.java
index f1ef947..f1d01e0 100644
--- a/services/core/java/com/android/server/connectivity/IpConnectivityEventBuilder.java
+++ b/services/core/java/com/android/server/connectivity/IpConnectivityEventBuilder.java
@@ -48,6 +48,10 @@
final IpConnectivityLog log = new IpConnectivityLog();
log.events = toProto(events);
log.droppedEvents = dropped;
+ if ((log.events.length > 0) || (dropped > 0)) {
+ // Only write version number if log has some information at all.
+ log.version = IpConnectivityMetrics.VERSION;
+ }
return IpConnectivityLog.toByteArray(log);
}
diff --git a/services/core/java/com/android/server/connectivity/IpConnectivityMetrics.java b/services/core/java/com/android/server/connectivity/IpConnectivityMetrics.java
index 28e724c..be68173 100644
--- a/services/core/java/com/android/server/connectivity/IpConnectivityMetrics.java
+++ b/services/core/java/com/android/server/connectivity/IpConnectivityMetrics.java
@@ -19,19 +19,25 @@
import android.content.Context;
import android.net.ConnectivityMetricsEvent;
import android.net.IIpConnectivityMetrics;
+import android.net.metrics.ApfProgramEvent;
import android.net.metrics.IpConnectivityLog;
import android.os.IBinder;
import android.os.Parcelable;
+import android.provider.Settings;
import android.text.TextUtils;
+import android.text.format.DateUtils;
+import android.util.ArrayMap;
import android.util.Base64;
import android.util.Log;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.util.TokenBucket;
import com.android.server.SystemService;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
+import java.util.function.ToIntFunction;
import static com.android.server.connectivity.metrics.IpConnectivityLogClass.IpConnectivityEvent;
@@ -40,10 +46,21 @@
private static final String TAG = IpConnectivityMetrics.class.getSimpleName();
private static final boolean DBG = false;
+ // The logical version numbers of ipconnectivity.proto, corresponding to the
+ // "version" field of IpConnectivityLog.
+ private static final int NYC = 0;
+ private static final int NYC_MR1 = 1;
+ private static final int NYC_MR2 = 2;
+ public static final int VERSION = NYC_MR2;
+
private static final String SERVICE_NAME = IpConnectivityLog.SERVICE_NAME;
// Default size of the event buffer. Once the buffer is full, incoming events are dropped.
private static final int DEFAULT_BUFFER_SIZE = 2000;
+ // Maximum size of the event buffer.
+ private static final int MAXIMUM_BUFFER_SIZE = DEFAULT_BUFFER_SIZE * 10;
+
+ private static final int ERROR_RATE_LIMITED = -1;
// Lock ensuring that concurrent manipulations of the event buffer are correct.
// There are three concurrent operations to synchronize:
@@ -62,10 +79,19 @@
private int mDropped;
@GuardedBy("mLock")
private int mCapacity;
+ @GuardedBy("mLock")
+ private final ArrayMap<Class<?>, TokenBucket> mBuckets = makeRateLimitingBuckets();
+
+ private final ToIntFunction<Context> mCapacityGetter;
+
+ public IpConnectivityMetrics(Context ctx, ToIntFunction<Context> capacityGetter) {
+ super(ctx);
+ mCapacityGetter = capacityGetter;
+ initBuffer();
+ }
public IpConnectivityMetrics(Context ctx) {
- super(ctx);
- initBuffer();
+ this(ctx, READ_BUFFER_SIZE);
}
@Override
@@ -86,7 +112,7 @@
@VisibleForTesting
public int bufferCapacity() {
- return DEFAULT_BUFFER_SIZE; // TODO: read from config
+ return mCapacityGetter.applyAsInt(getContext());
}
private void initBuffer() {
@@ -104,6 +130,10 @@
if (event == null) {
return left;
}
+ if (isRateLimited(event)) {
+ // Do not count as a dropped event. TODO: consider adding separate counter
+ return ERROR_RATE_LIMITED;
+ }
if (left == 0) {
mDropped++;
return 0;
@@ -113,6 +143,11 @@
}
}
+ private boolean isRateLimited(ConnectivityMetricsEvent event) {
+ TokenBucket tb = mBuckets.get(event.data.getClass());
+ return (tb != null) && !tb.get();
+ }
+
private String flushEncodedOutput() {
final ArrayList<ConnectivityMetricsEvent> events;
final int dropped;
@@ -186,6 +221,7 @@
static final String CMD_FLUSH = "flush";
static final String CMD_LIST = "list";
static final String CMD_STATS = "stats";
+ static final String CMD_DUMPSYS = "-a"; // dumpsys.cpp dumps services with "-a" as arguments
static final String CMD_DEFAULT = CMD_STATS;
@Override
@@ -203,6 +239,8 @@
case CMD_FLUSH:
cmdFlush(fd, pw, args);
return;
+ case CMD_DUMPSYS:
+ // Fallthrough to CMD_LIST when dumpsys.cpp dumps services states (bug reports)
case CMD_LIST:
cmdList(fd, pw, args);
return;
@@ -226,4 +264,20 @@
getContext().enforceCallingOrSelfPermission(what, "IpConnectivityMetrics");
}
};
+
+ private static final ToIntFunction<Context> READ_BUFFER_SIZE = (ctx) -> {
+ int size = Settings.Global.getInt(ctx.getContentResolver(),
+ Settings.Global.CONNECTIVITY_METRICS_BUFFER_SIZE, DEFAULT_BUFFER_SIZE);
+ if (size <= 0) {
+ return DEFAULT_BUFFER_SIZE;
+ }
+ return Math.min(size, MAXIMUM_BUFFER_SIZE);
+ };
+
+ private static ArrayMap<Class<?>, TokenBucket> makeRateLimitingBuckets() {
+ ArrayMap<Class<?>, TokenBucket> map = new ArrayMap<>();
+ // one token every minute, 50 tokens max: burst of ~50 events every hour.
+ map.put(ApfProgramEvent.class, new TokenBucket((int)DateUtils.MINUTE_IN_MILLIS, 50));
+ return map;
+ }
}
diff --git a/services/core/java/com/android/server/connectivity/NetdEventListenerService.java b/services/core/java/com/android/server/connectivity/NetdEventListenerService.java
index 4b175d7..f8638c5 100644
--- a/services/core/java/com/android/server/connectivity/NetdEventListenerService.java
+++ b/services/core/java/com/android/server/connectivity/NetdEventListenerService.java
@@ -24,6 +24,7 @@
import android.net.metrics.DnsEvent;
import android.net.metrics.INetdEventListener;
import android.net.metrics.IpConnectivityLog;
+import android.os.RemoteException;
import android.util.Log;
import com.android.internal.annotations.GuardedBy;
@@ -44,7 +45,7 @@
public static final String SERVICE_NAME = "netd_listener";
private static final String TAG = NetdEventListenerService.class.getSimpleName();
- private static final boolean DBG = true;
+ private static final boolean DBG = false;
private static final boolean VDBG = false;
// TODO: read this constant from system property
@@ -86,7 +87,7 @@
byte[] returnCodes = Arrays.copyOf(mReturnCodes, mEventCount);
int[] latenciesMs = Arrays.copyOf(mLatenciesMs, mEventCount);
mMetricsLog.log(new DnsEvent(mNetId, eventTypes, returnCodes, latenciesMs));
- maybeLog(String.format("Logging %d results for netId %d", mEventCount, mNetId));
+ maybeLog("Logging %d results for netId %d", mEventCount, mNetId);
mEventCount = 0;
}
@@ -136,9 +137,9 @@
// Called concurrently by multiple binder threads.
// This method must not block or perform long-running operations.
public synchronized void onDnsEvent(int netId, int eventType, int returnCode, int latencyMs,
- String hostname, String[] ipAddresses, int ipAddressesCount, int uid) {
- maybeVerboseLog(String.format("onDnsEvent(%d, %d, %d, %d)",
- netId, eventType, returnCode, latencyMs));
+ String hostname, String[] ipAddresses, int ipAddressesCount, int uid)
+ throws RemoteException {
+ maybeVerboseLog("onDnsEvent(%d, %d, %d, %dms)", netId, eventType, returnCode, latencyMs);
DnsEventBatch batch = mEventBatches.get(netId);
if (batch == null) {
@@ -151,9 +152,9 @@
@Override
// Called concurrently by multiple binder threads.
// This method must not block or perform long-running operations.
- public synchronized void onConnectEvent(int netId, int latencyMs, String ipAddr, int port,
- int uid) {
- maybeVerboseLog(String.format("onConnectEvent(%d, %d)", netId, latencyMs));
+ public synchronized void onConnectEvent(int netId, int error, int latencyMs, String ipAddr, int port,
+ int uid) throws RemoteException {
+ maybeVerboseLog("onConnectEvent(%d, %d, %dms)", netId, error, latencyMs);
}
public synchronized void dump(PrintWriter writer) {
@@ -166,11 +167,11 @@
pw.decreaseIndent();
}
- private static void maybeLog(String s) {
- if (DBG) Log.d(TAG, s);
+ private static void maybeLog(String s, Object... args) {
+ if (DBG) Log.d(TAG, String.format(s, args));
}
- private static void maybeVerboseLog(String s) {
- if (VDBG) Log.d(TAG, s);
+ private static void maybeVerboseLog(String s, Object... args) {
+ if (VDBG) Log.d(TAG, String.format(s, args));
}
}
diff --git a/services/core/java/com/android/server/connectivity/NetworkMonitor.java b/services/core/java/com/android/server/connectivity/NetworkMonitor.java
index c73d1dd..ea2cf5f 100644
--- a/services/core/java/com/android/server/connectivity/NetworkMonitor.java
+++ b/services/core/java/com/android/server/connectivity/NetworkMonitor.java
@@ -96,6 +96,24 @@
private static final int SOCKET_TIMEOUT_MS = 10000;
private static final int PROBE_TIMEOUT_MS = 3000;
+ static enum EvaluationResult {
+ VALIDATED(true),
+ CAPTIVE_PORTAL(false);
+ final boolean isValidated;
+ EvaluationResult(boolean isValidated) {
+ this.isValidated = isValidated;
+ }
+ }
+
+ static enum ValidationStage {
+ FIRST_VALIDATION(true),
+ REVALIDATION(false);
+ final boolean isFirstValidation;
+ ValidationStage(boolean isFirstValidation) {
+ this.isFirstValidation = isFirstValidation;
+ }
+ }
+
public static final String ACTION_NETWORK_CONDITIONS_MEASURED =
"android.net.conn.NETWORK_CONDITIONS_MEASURED";
public static final String EXTRA_CONNECTIVITY_TYPE = "extra_connectivity_type";
@@ -215,6 +233,8 @@
protected boolean mIsCaptivePortalCheckEnabled;
private boolean mUseHttps;
+ // The total number of captive portal detection attempts for this NetworkMonitor instance.
+ private int mValidations = 0;
// Set if the user explicitly selected "Do not use this network" in captive portal sign-in app.
private boolean mUserDoesNotWant = false;
@@ -289,6 +309,10 @@
return validationLogs.readOnlyLocalLog();
}
+ private ValidationStage validationStage() {
+ return 0 == mValidations ? ValidationStage.FIRST_VALIDATION : ValidationStage.REVALIDATION;
+ }
+
// DefaultState is the parent of all States. It exists only to handle CMD_* messages but
// does not entail any real state (hence no enter() or exit() routines).
private class DefaultState extends State {
@@ -365,9 +389,11 @@
private class ValidatedState extends State {
@Override
public void enter() {
- maybeLogEvaluationResult(NetworkEvent.NETWORK_VALIDATED);
+ maybeLogEvaluationResult(
+ networkEventType(validationStage(), EvaluationResult.VALIDATED));
mConnectivityServiceHandler.sendMessage(obtainMessage(EVENT_NETWORK_TESTED,
NETWORK_TEST_RESULT_VALID, mNetworkAgentInfo.network.netId, null));
+ mValidations++;
}
@Override
@@ -583,7 +609,8 @@
@Override
public void enter() {
- maybeLogEvaluationResult(NetworkEvent.NETWORK_CAPTIVE_PORTAL_FOUND);
+ maybeLogEvaluationResult(
+ networkEventType(validationStage(), EvaluationResult.CAPTIVE_PORTAL));
// Don't annoy user with sign-in notifications.
if (mDontDisplaySigninNotification) return;
// Create a CustomIntentReceiver that sends us a
@@ -603,6 +630,7 @@
// Retest for captive portal occasionally.
sendMessageDelayed(CMD_CAPTIVE_PORTAL_RECHECK, 0 /* no UID */,
CAPTIVE_PORTAL_REEVALUATE_DELAY_MS);
+ mValidations++;
}
@Override
@@ -678,48 +706,13 @@
long startTime = SystemClock.elapsedRealtime();
- // Pre-resolve the captive portal server host so we can log it.
- // Only do this if HttpURLConnection is about to, to avoid any potentially
- // unnecessary resolution.
- String hostToResolve = null;
+ final CaptivePortalProbeResult result;
if (pacUrl != null) {
- hostToResolve = pacUrl.getHost();
- } else if (proxyInfo != null) {
- hostToResolve = proxyInfo.getHost();
- } else {
- hostToResolve = httpUrl.getHost();
- }
-
- if (!TextUtils.isEmpty(hostToResolve)) {
- String probeName = ValidationProbeEvent.getProbeName(ValidationProbeEvent.PROBE_DNS);
- final Stopwatch dnsTimer = new Stopwatch().start();
- int dnsResult;
- long dnsLatency;
- try {
- InetAddress[] addresses = mNetworkAgentInfo.network.getAllByName(hostToResolve);
- dnsResult = ValidationProbeEvent.DNS_SUCCESS;
- dnsLatency = dnsTimer.stop();
- final StringBuffer connectInfo = new StringBuffer(", " + hostToResolve + "=");
- for (InetAddress address : addresses) {
- connectInfo.append(address.getHostAddress());
- if (address != addresses[addresses.length-1]) connectInfo.append(",");
- }
- validationLog(probeName + " OK " + dnsLatency + "ms" + connectInfo);
- } catch (UnknownHostException e) {
- dnsResult = ValidationProbeEvent.DNS_FAILURE;
- dnsLatency = dnsTimer.stop();
- validationLog(probeName + " FAIL " + dnsLatency + "ms, " + hostToResolve);
- }
- logValidationProbe(dnsLatency, ValidationProbeEvent.PROBE_DNS, dnsResult);
- }
-
- CaptivePortalProbeResult result;
- if (pacUrl != null) {
- result = sendHttpProbe(pacUrl, ValidationProbeEvent.PROBE_PAC);
+ result = sendDnsAndHttpProbes(null, pacUrl, ValidationProbeEvent.PROBE_PAC);
} else if (mUseHttps) {
- result = sendParallelHttpProbes(httpsUrl, httpUrl, fallbackUrl);
+ result = sendParallelHttpProbes(proxyInfo, httpsUrl, httpUrl, fallbackUrl);
} else {
- result = sendHttpProbe(httpUrl, ValidationProbeEvent.PROBE_HTTP);
+ result = sendDnsAndHttpProbes(proxyInfo, httpUrl, ValidationProbeEvent.PROBE_HTTP);
}
long endTime = SystemClock.elapsedRealtime();
@@ -732,8 +725,50 @@
}
/**
- * Do a URL fetch on a known server to see if we get the data we expect.
- * Returns HTTP response code.
+ * Do a DNS resolution and URL fetch on a known web server to see if we get the data we expect.
+ * @return a CaptivePortalProbeResult inferred from the HTTP response.
+ */
+ private CaptivePortalProbeResult sendDnsAndHttpProbes(ProxyInfo proxy, URL url, int probeType) {
+ // Pre-resolve the captive portal server host so we can log it.
+ // Only do this if HttpURLConnection is about to, to avoid any potentially
+ // unnecessary resolution.
+ final String host = (proxy != null) ? proxy.getHost() : url.getHost();
+ sendDnsProbe(host);
+ return sendHttpProbe(url, probeType);
+ }
+
+ /** Do a DNS resolution of the given server. */
+ private void sendDnsProbe(String host) {
+ if (TextUtils.isEmpty(host)) {
+ return;
+ }
+
+ final String name = ValidationProbeEvent.getProbeName(ValidationProbeEvent.PROBE_DNS);
+ final Stopwatch watch = new Stopwatch().start();
+ int result;
+ String connectInfo;
+ try {
+ InetAddress[] addresses = mNetworkAgentInfo.network.getAllByName(host);
+ result = ValidationProbeEvent.DNS_SUCCESS;
+ StringBuffer buffer = new StringBuffer(host).append("=");
+ for (InetAddress address : addresses) {
+ buffer.append(address.getHostAddress());
+ if (address != addresses[addresses.length-1]) buffer.append(",");
+ }
+ connectInfo = buffer.toString();
+ } catch (UnknownHostException e) {
+ result = ValidationProbeEvent.DNS_FAILURE;
+ connectInfo = host;
+ }
+ final long latency = watch.stop();
+ String resultString = (ValidationProbeEvent.DNS_SUCCESS == result) ? "OK" : "FAIL";
+ validationLog(String.format("%s %s %dms, %s", name, resultString, latency, connectInfo));
+ logValidationProbe(latency, ValidationProbeEvent.PROBE_DNS, result);
+ }
+
+ /**
+ * Do a URL fetch on a known web server to see if we get the data we expect.
+ * @return a CaptivePortalProbeResult inferred from the HTTP response.
*/
@VisibleForTesting
protected CaptivePortalProbeResult sendHttpProbe(URL url, int probeType) {
@@ -800,7 +835,7 @@
}
private CaptivePortalProbeResult sendParallelHttpProbes(
- URL httpsUrl, URL httpUrl, URL fallbackUrl) {
+ ProxyInfo proxy, URL httpsUrl, URL httpUrl, URL fallbackUrl) {
// Number of probes to wait for. If a probe completes with a conclusive answer
// it shortcuts the latch immediately by forcing the count to 0.
final CountDownLatch latch = new CountDownLatch(2);
@@ -820,9 +855,10 @@
@Override
public void run() {
if (mIsHttps) {
- mResult = sendHttpProbe(httpsUrl, ValidationProbeEvent.PROBE_HTTPS);
+ mResult =
+ sendDnsAndHttpProbes(proxy, httpsUrl, ValidationProbeEvent.PROBE_HTTPS);
} else {
- mResult = sendHttpProbe(httpUrl, ValidationProbeEvent.PROBE_HTTP);
+ mResult = sendDnsAndHttpProbes(proxy, httpUrl, ValidationProbeEvent.PROBE_HTTP);
}
if ((mIsHttps && mResult.isSuccessful()) || (!mIsHttps && mResult.isPortal())) {
// Stop waiting immediately if https succeeds or if http finds a portal.
@@ -973,6 +1009,22 @@
mMetricsLog.log(new NetworkEvent(mNetId, evtype));
}
+ private int networkEventType(ValidationStage s, EvaluationResult r) {
+ if (s.isFirstValidation) {
+ if (r.isValidated) {
+ return NetworkEvent.NETWORK_FIRST_VALIDATION_SUCCESS;
+ } else {
+ return NetworkEvent.NETWORK_FIRST_VALIDATION_PORTAL_FOUND;
+ }
+ } else {
+ if (r.isValidated) {
+ return NetworkEvent.NETWORK_REVALIDATION_SUCCESS;
+ } else {
+ return NetworkEvent.NETWORK_REVALIDATION_PORTAL_FOUND;
+ }
+ }
+ }
+
private void maybeLogEvaluationResult(int evtype) {
if (mEvaluationTimer.isRunning()) {
mMetricsLog.log(new NetworkEvent(mNetId, evtype, mEvaluationTimer.stop()));
@@ -981,6 +1033,8 @@
}
private void logValidationProbe(long durationMs, int probeType, int probeResult) {
+ probeType =
+ ValidationProbeEvent.makeProbeType(probeType, validationStage().isFirstValidation);
mMetricsLog.log(new ValidationProbeEvent(mNetId, durationMs, probeType, probeResult));
}
}
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java
index ede3bda..afc6247 100644
--- a/services/core/java/com/android/server/connectivity/Vpn.java
+++ b/services/core/java/com/android/server/connectivity/Vpn.java
@@ -27,6 +27,8 @@
import android.annotation.UserIdInt;
import android.app.AppGlobals;
import android.app.AppOpsManager;
+import android.app.Notification;
+import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -76,6 +78,7 @@
import android.util.ArraySet;
import android.util.Log;
+import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.net.LegacyVpnInfo;
@@ -241,12 +244,14 @@
/**
* Update current state, dispaching event to listeners.
*/
- private void updateState(DetailedState detailedState, String reason) {
+ @VisibleForTesting
+ protected void updateState(DetailedState detailedState, String reason) {
if (LOGD) Log.d(TAG, "setting state=" + detailedState + ", reason=" + reason);
mNetworkInfo.setDetailedState(detailedState, reason, null);
if (mNetworkAgent != null) {
mNetworkAgent.sendNetworkInfo(mNetworkInfo);
}
+ updateAlwaysOnNotification(detailedState);
}
/**
@@ -280,7 +285,10 @@
}
mLockdown = (mAlwaysOn && lockdown);
- if (!isCurrentPreparedPackage(packageName)) {
+ if (isCurrentPreparedPackage(packageName)) {
+ updateAlwaysOnNotification(mNetworkInfo.getDetailedState());
+ } else {
+ // Prepare this app. The notification will update as a side-effect of updateState().
prepareInternal(packageName);
}
maybeRegisterPackageChangeReceiverLocked(packageName);
@@ -682,22 +690,19 @@
}
}
- private void agentDisconnect(NetworkInfo networkInfo, NetworkAgent networkAgent) {
- networkInfo.setIsAvailable(false);
- networkInfo.setDetailedState(DetailedState.DISCONNECTED, null, null);
+ private void agentDisconnect(NetworkAgent networkAgent) {
if (networkAgent != null) {
+ NetworkInfo networkInfo = new NetworkInfo(mNetworkInfo);
+ networkInfo.setIsAvailable(false);
+ networkInfo.setDetailedState(DetailedState.DISCONNECTED, null, null);
networkAgent.sendNetworkInfo(networkInfo);
}
}
- private void agentDisconnect(NetworkAgent networkAgent) {
- NetworkInfo networkInfo = new NetworkInfo(mNetworkInfo);
- agentDisconnect(networkInfo, networkAgent);
- }
-
private void agentDisconnect() {
if (mNetworkInfo.isConnected()) {
- agentDisconnect(mNetworkInfo, mNetworkAgent);
+ mNetworkInfo.setIsAvailable(false);
+ updateState(DetailedState.DISCONNECTED, "agentDisconnect");
mNetworkAgent = null;
}
}
@@ -1250,6 +1255,43 @@
}
}
+ private void updateAlwaysOnNotification(DetailedState networkState) {
+ final boolean visible = (mAlwaysOn && networkState != DetailedState.CONNECTED);
+ updateAlwaysOnNotificationInternal(visible);
+ }
+
+ @VisibleForTesting
+ protected void updateAlwaysOnNotificationInternal(boolean visible) {
+ final UserHandle user = UserHandle.of(mUserHandle);
+ final long token = Binder.clearCallingIdentity();
+ try {
+ final NotificationManager notificationManager = NotificationManager.from(mContext);
+ if (!visible) {
+ notificationManager.cancelAsUser(TAG, 0, user);
+ return;
+ }
+ final Intent intent = new Intent(Settings.ACTION_VPN_SETTINGS);
+ final PendingIntent configIntent = PendingIntent.getActivityAsUser(
+ mContext, /* request */ 0, intent,
+ PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT,
+ null, user);
+ final Notification.Builder builder = new Notification.Builder(mContext)
+ .setDefaults(0)
+ .setSmallIcon(R.drawable.vpn_connected)
+ .setContentTitle(mContext.getString(R.string.vpn_lockdown_disconnected))
+ .setContentText(mContext.getString(R.string.vpn_lockdown_config))
+ .setContentIntent(configIntent)
+ .setCategory(Notification.CATEGORY_SYSTEM)
+ .setPriority(Notification.PRIORITY_LOW)
+ .setVisibility(Notification.VISIBILITY_PUBLIC)
+ .setOngoing(true)
+ .setColor(mContext.getColor(R.color.system_notification_accent_color));
+ notificationManager.notifyAsUser(TAG, 0, builder.build(), user);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
private native int jniCreate(int mtu);
private native String jniGetName(int tun);
private native int jniSetAddresses(String interfaze, String addresses);
diff --git a/services/core/java/com/android/server/net/NetworkIdentitySet.java b/services/core/java/com/android/server/net/NetworkIdentitySet.java
index 959a823..c48f430 100644
--- a/services/core/java/com/android/server/net/NetworkIdentitySet.java
+++ b/services/core/java/com/android/server/net/NetworkIdentitySet.java
@@ -91,6 +91,19 @@
}
}
+ /** @return whether any {@link NetworkIdentity} in this set is considered metered. */
+ public boolean isAnyMemberMetered() {
+ if (isEmpty()) {
+ return false;
+ }
+ for (NetworkIdentity ident : this) {
+ if (ident.getMetered()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/** @return whether any {@link NetworkIdentity} in this set is considered roaming. */
public boolean isAnyMemberRoaming() {
if (isEmpty()) {
diff --git a/services/core/java/com/android/server/net/NetworkStatsCollection.java b/services/core/java/com/android/server/net/NetworkStatsCollection.java
index 673dd8f..c45b416 100644
--- a/services/core/java/com/android/server/net/NetworkStatsCollection.java
+++ b/services/core/java/com/android/server/net/NetworkStatsCollection.java
@@ -17,6 +17,8 @@
package com.android.server.net;
import static android.net.NetworkStats.IFACE_ALL;
+import static android.net.NetworkStats.METERED_NO;
+import static android.net.NetworkStats.METERED_YES;
import static android.net.NetworkStats.ROAMING_NO;
import static android.net.NetworkStats.ROAMING_YES;
import static android.net.NetworkStats.SET_ALL;
@@ -242,6 +244,7 @@
entry.uid = key.uid;
entry.set = key.set;
entry.tag = key.tag;
+ entry.metered = key.ident.isAnyMemberMetered() ? METERED_YES : METERED_NO;
entry.roaming = key.ident.isAnyMemberRoaming() ? ROAMING_YES : ROAMING_NO;
entry.rxBytes = historyEntry.rxBytes;
entry.rxPackets = historyEntry.rxPackets;
diff --git a/services/core/java/com/android/server/pm/Installer.java b/services/core/java/com/android/server/pm/Installer.java
index bff68d8..1f83d9e 100644
--- a/services/core/java/com/android/server/pm/Installer.java
+++ b/services/core/java/com/android/server/pm/Installer.java
@@ -20,21 +20,20 @@
import android.content.Context;
import android.content.pm.PackageStats;
import android.os.Build;
+import android.os.IBinder;
+import android.os.IBinder.DeathRecipient;
import android.os.IInstalld;
import android.os.RemoteException;
import android.os.ServiceManager;
-import android.os.ServiceSpecificException;
+import android.text.format.DateUtils;
import android.util.Slog;
-import com.android.internal.os.InstallerConnection;
-import com.android.internal.os.InstallerConnection.InstallerException;
+import com.android.internal.os.BackgroundThread;
import com.android.server.SystemService;
import dalvik.system.VMRuntime;
-import java.util.Arrays;
-
-public final class Installer extends SystemService {
+public class Installer extends SystemService {
private static final String TAG = "Installer";
/* ***************************************************************************
@@ -51,32 +50,28 @@
public static final int DEXOPT_BOOTCOMPLETE = 1 << 4;
/** Hint that the dexopt type is profile-guided. */
public static final int DEXOPT_PROFILE_GUIDED = 1 << 5;
- /** This is an OTA update dexopt */
- public static final int DEXOPT_OTA = 1 << 6;
// NOTE: keep in sync with installd
public static final int FLAG_CLEAR_CACHE_ONLY = 1 << 8;
public static final int FLAG_CLEAR_CODE_CACHE_ONLY = 1 << 9;
- private final InstallerConnection mInstaller;
- private final IInstalld mInstalld;
+ private final boolean mIsolated;
+ private volatile IInstalld mInstalld;
private volatile Object mWarnIfHeld;
public Installer(Context context) {
- super(context);
- mInstaller = new InstallerConnection();
- // TODO: reconnect if installd restarts
- mInstalld = IInstalld.Stub.asInterface(ServiceManager.getService("installd"));
+ this(context, false);
}
- // Package-private installer that accepts a custom InstallerConnection. Used for
- // OtaDexoptService.
- Installer(Context context, InstallerConnection connection) {
+ /**
+ * @param isolated indicates if this object should <em>not</em> connect to
+ * the real {@code installd}. All remote calls will be ignored
+ * unless you extend this class and intercept them.
+ */
+ public Installer(Context context, boolean isolated) {
super(context);
- mInstaller = connection;
- // TODO: reconnect if installd restarts
- mInstalld = IInstalld.Stub.asInterface(ServiceManager.getService("installd"));
+ mIsolated = isolated;
}
/**
@@ -84,227 +79,254 @@
* the given object.
*/
public void setWarnIfHeld(Object warnIfHeld) {
- mInstaller.setWarnIfHeld(warnIfHeld);
mWarnIfHeld = warnIfHeld;
}
@Override
public void onStart() {
- Slog.i(TAG, "Waiting for installd to be ready.");
- mInstaller.waitForConnection();
+ if (mIsolated) {
+ mInstalld = null;
+ } else {
+ connect();
+ }
}
- private void checkLock() {
+ private void connect() {
+ IBinder binder = ServiceManager.getService("installd");
+ if (binder != null) {
+ try {
+ binder.linkToDeath(new DeathRecipient() {
+ @Override
+ public void binderDied() {
+ Slog.w(TAG, "installd died; reconnecting");
+ connect();
+ }
+ }, 0);
+ } catch (RemoteException e) {
+ binder = null;
+ }
+ }
+
+ if (binder != null) {
+ mInstalld = IInstalld.Stub.asInterface(binder);
+ } else {
+ Slog.w(TAG, "installd not found; trying again");
+ BackgroundThread.getHandler().postDelayed(() -> {
+ connect();
+ }, DateUtils.SECOND_IN_MILLIS);
+ }
+ }
+
+ /**
+ * Do several pre-flight checks before making a remote call.
+ *
+ * @return if the remote call should continue.
+ */
+ private boolean checkBeforeRemote() {
if (mWarnIfHeld != null && Thread.holdsLock(mWarnIfHeld)) {
Slog.wtf(TAG, "Calling thread " + Thread.currentThread().getName() + " is holding 0x"
+ Integer.toHexString(System.identityHashCode(mWarnIfHeld)), new Throwable());
}
+ if (mIsolated) {
+ Slog.i(TAG, "Ignoring request because this installer is isolated");
+ return false;
+ } else {
+ return true;
+ }
}
- public void createAppData(String uuid, String packageName, int userId, int flags, int appId,
+ public long createAppData(String uuid, String packageName, int userId, int flags, int appId,
String seInfo, int targetSdkVersion) throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return -1;
try {
- mInstalld.createAppData(uuid, packageName, userId, flags, appId, seInfo,
+ return mInstalld.createAppData(uuid, packageName, userId, flags, appId, seInfo,
targetSdkVersion);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void restoreconAppData(String uuid, String packageName, int userId, int flags, int appId,
String seInfo) throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.restoreconAppData(uuid, packageName, userId, flags, appId, seInfo);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void migrateAppData(String uuid, String packageName, int userId, int flags)
throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.migrateAppData(uuid, packageName, userId, flags);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void clearAppData(String uuid, String packageName, int userId, int flags,
long ceDataInode) throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.clearAppData(uuid, packageName, userId, flags, ceDataInode);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void destroyAppData(String uuid, String packageName, int userId, int flags,
long ceDataInode) throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.destroyAppData(uuid, packageName, userId, flags, ceDataInode);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void moveCompleteApp(String fromUuid, String toUuid, String packageName,
String dataAppName, int appId, String seInfo, int targetSdkVersion)
throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.moveCompleteApp(fromUuid, toUuid, packageName, dataAppName, appId, seInfo,
targetSdkVersion);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
- public void getAppSize(String uuid, String pkgname, int userid, int flags, long ceDataInode,
+ public void getAppSize(String uuid, String packageName, int userId, int flags, long ceDataInode,
String codePath, PackageStats stats) throws InstallerException {
- final String[] res = mInstaller.execute("get_app_size", uuid, pkgname, userid, flags,
- ceDataInode, codePath);
+ if (!checkBeforeRemote()) return;
try {
- stats.codeSize += Long.parseLong(res[1]);
- stats.dataSize += Long.parseLong(res[2]);
- stats.cacheSize += Long.parseLong(res[3]);
- } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) {
- throw new InstallerException("Invalid size result: " + Arrays.toString(res));
+ final long[] res = mInstalld.getAppSize(uuid, packageName, userId, flags, ceDataInode,
+ codePath);
+ stats.codeSize += res[0];
+ stats.dataSize += res[1];
+ stats.cacheSize += res[2];
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
- public long getAppDataInode(String uuid, String packageName, int userId, int flags)
- throws InstallerException {
- checkLock();
- try {
- return mInstalld.getAppDataInode(uuid, packageName, userId, flags);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
- }
- }
-
- public void dexopt(String apkPath, int uid, String instructionSet, int dexoptNeeded,
- int dexFlags, String compilerFilter, String volumeUuid, String sharedLibraries)
- throws InstallerException {
- assertValidInstructionSet(instructionSet);
- mInstaller.dexopt(apkPath, uid, instructionSet, dexoptNeeded, dexFlags,
- compilerFilter, volumeUuid, sharedLibraries);
- }
-
- public void dexopt(String apkPath, int uid, String pkgName, String instructionSet,
+ public void dexopt(String apkPath, int uid, @Nullable String pkgName, String instructionSet,
int dexoptNeeded, @Nullable String outputPath, int dexFlags,
- String compilerFilter, String volumeUuid, String sharedLibraries)
+ String compilerFilter, @Nullable String volumeUuid, @Nullable String sharedLibraries)
throws InstallerException {
assertValidInstructionSet(instructionSet);
- mInstaller.dexopt(apkPath, uid, pkgName, instructionSet, dexoptNeeded,
- outputPath, dexFlags, compilerFilter, volumeUuid, sharedLibraries);
+ if (!checkBeforeRemote()) return;
+ try {
+ mInstalld.dexopt(apkPath, uid, pkgName, instructionSet, dexoptNeeded, outputPath,
+ dexFlags, compilerFilter, volumeUuid, sharedLibraries);
+ } catch (Exception e) {
+ throw InstallerException.from(e);
+ }
}
public boolean mergeProfiles(int uid, String packageName) throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return false;
try {
return mInstalld.mergeProfiles(uid, packageName);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public boolean dumpProfiles(int uid, String packageName, String codePaths)
throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return false;
try {
return mInstalld.dumpProfiles(uid, packageName, codePaths);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void idmap(String targetApkPath, String overlayApkPath, int uid)
throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.idmap(targetApkPath, overlayApkPath, uid);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void rmdex(String codePath, String instructionSet) throws InstallerException {
assertValidInstructionSet(instructionSet);
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.rmdex(codePath, instructionSet);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void rmPackageDir(String packageDir) throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.rmPackageDir(packageDir);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void clearAppProfiles(String packageName) throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.clearAppProfiles(packageName);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void destroyAppProfiles(String packageName) throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.destroyAppProfiles(packageName);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void createUserData(String uuid, int userId, int userSerial, int flags)
throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.createUserData(uuid, userId, userSerial, flags);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void destroyUserData(String uuid, int userId, int flags) throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.destroyUserData(uuid, userId, flags);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void markBootComplete(String instructionSet) throws InstallerException {
assertValidInstructionSet(instructionSet);
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.markBootComplete(instructionSet);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void freeCache(String uuid, long freeStorageSize) throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.freeCache(uuid, freeStorageSize);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
@@ -315,51 +337,51 @@
*/
public void linkNativeLibraryDirectory(String uuid, String packageName, String nativeLibPath32,
int userId) throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.linkNativeLibraryDirectory(uuid, packageName, nativeLibPath32, userId);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void createOatDir(String oatDir, String dexInstructionSet)
throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.createOatDir(oatDir, dexInstructionSet);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void linkFile(String relativePath, String fromBase, String toBase)
throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.linkFile(relativePath, fromBase, toBase);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void moveAb(String apkPath, String instructionSet, String outputPath)
throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.moveAb(apkPath, instructionSet, outputPath);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
public void deleteOdex(String apkPath, String instructionSet, String outputPath)
throws InstallerException {
- checkLock();
+ if (!checkBeforeRemote()) return;
try {
mInstalld.deleteOdex(apkPath, instructionSet, outputPath);
- } catch (RemoteException | ServiceSpecificException e) {
- throw new InstallerException(e.getMessage());
+ } catch (Exception e) {
+ throw InstallerException.from(e);
}
}
@@ -372,4 +394,14 @@
}
throw new InstallerException("Invalid instruction set: " + instructionSet);
}
+
+ public static class InstallerException extends Exception {
+ public InstallerException(String detailMessage) {
+ super(detailMessage);
+ }
+
+ public static InstallerException from(Exception e) throws InstallerException {
+ throw new InstallerException(e.toString());
+ }
+ }
}
diff --git a/services/core/java/com/android/server/pm/OtaDexoptService.java b/services/core/java/com/android/server/pm/OtaDexoptService.java
index 689917c..60c83b4 100644
--- a/services/core/java/com/android/server/pm/OtaDexoptService.java
+++ b/services/core/java/com/android/server/pm/OtaDexoptService.java
@@ -16,11 +16,11 @@
package com.android.server.pm;
-import static com.android.server.pm.Installer.DEXOPT_OTA;
import static com.android.server.pm.InstructionSets.getAppDexInstructionSets;
import static com.android.server.pm.InstructionSets.getDexCodeInstructionSets;
import static com.android.server.pm.PackageManagerServiceCompilerMapping.getCompilerFilterForReason;
+import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.IOtaDexopt;
import android.content.pm.PackageParser;
@@ -29,15 +29,17 @@
import android.os.ResultReceiver;
import android.os.ServiceManager;
import android.os.storage.StorageManager;
+import android.text.TextUtils;
import android.util.Log;
import android.util.Slog;
+
import com.android.internal.logging.MetricsLogger;
-import com.android.internal.os.InstallerConnection;
-import com.android.internal.os.InstallerConnection.InstallerException;
+import com.android.server.pm.Installer.InstallerException;
import java.io.File;
import java.io.FileDescriptor;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -276,9 +278,27 @@
*/
private synchronized List<String> generatePackageDexopts(PackageParser.Package pkg,
int compilationReason) {
- // Use our custom connection that just collects the commands.
- RecordingInstallerConnection collectingConnection = new RecordingInstallerConnection();
- Installer collectingInstaller = new Installer(mContext, collectingConnection);
+ // Intercept and collect dexopt requests
+ final List<String> commands = new ArrayList<String>();
+ final Installer collectingInstaller = new Installer(mContext, true) {
+ @Override
+ public void dexopt(String apkPath, int uid, @Nullable String pkgName,
+ String instructionSet, int dexoptNeeded, @Nullable String outputPath,
+ int dexFlags, String compilerFilter, @Nullable String volumeUuid,
+ @Nullable String sharedLibraries) throws InstallerException {
+ commands.add(buildCommand("dexopt",
+ apkPath,
+ uid,
+ pkgName,
+ instructionSet,
+ dexoptNeeded,
+ outputPath,
+ dexFlags,
+ compilerFilter,
+ volumeUuid,
+ sharedLibraries));
+ }
+ };
// Use the package manager install and install lock here for the OTA dex optimizer.
PackageDexOptimizer optimizer = new OTADexoptPackageDexOptimizer(
@@ -295,7 +315,7 @@
getCompilerFilterForReason(compilationReason),
null /* CompilerStats.PackageStats */);
- return collectingConnection.commands;
+ return commands;
}
@Override
@@ -400,53 +420,33 @@
private static class OTADexoptPackageDexOptimizer extends
PackageDexOptimizer.ForcedUpdatePackageDexOptimizer {
-
public OTADexoptPackageDexOptimizer(Installer installer, Object installLock,
Context context) {
super(installer, installLock, context, "*otadexopt*");
}
-
- @Override
- protected int adjustDexoptFlags(int dexoptFlags) {
- // Add the OTA flag.
- return dexoptFlags | DEXOPT_OTA;
- }
-
}
- private static class RecordingInstallerConnection extends InstallerConnection {
- public List<String> commands = new ArrayList<String>(1);
-
- @Override
- public void setWarnIfHeld(Object warnIfHeld) {
- throw new IllegalStateException("Should not reach here");
+ /**
+ * Cook up argument list in the format that {@code installd} expects.
+ */
+ private static String buildCommand(Object... args) {
+ final StringBuilder builder = new StringBuilder();
+ for (Object arg : args) {
+ String escaped;
+ if (arg == null) {
+ escaped = "";
+ } else {
+ escaped = String.valueOf(arg);
+ }
+ if (escaped.indexOf('\0') != -1 || escaped.indexOf(' ') != -1 || "!".equals(escaped)) {
+ throw new IllegalArgumentException(
+ "Invalid argument while executing " + Arrays.toString(args));
+ }
+ if (TextUtils.isEmpty(escaped)) {
+ escaped = "!";
+ }
+ builder.append(' ').append(escaped);
}
-
- @Override
- public synchronized String transact(String cmd) {
- commands.add(cmd);
- return "0";
- }
-
- @Override
- public boolean mergeProfiles(int uid, String pkgName) throws InstallerException {
- throw new IllegalStateException("Should not reach here");
- }
-
- @Override
- public boolean dumpProfiles(String gid, String packageName, String codePaths)
- throws InstallerException {
- throw new IllegalStateException("Should not reach here");
- }
-
- @Override
- public void disconnect() {
- throw new IllegalStateException("Should not reach here");
- }
-
- @Override
- public void waitForConnection() {
- throw new IllegalStateException("Should not reach here");
- }
+ return builder.toString();
}
}
diff --git a/services/core/java/com/android/server/pm/PackageDexOptimizer.java b/services/core/java/com/android/server/pm/PackageDexOptimizer.java
index acdcc72..30ff32b 100644
--- a/services/core/java/com/android/server/pm/PackageDexOptimizer.java
+++ b/services/core/java/com/android/server/pm/PackageDexOptimizer.java
@@ -27,8 +27,8 @@
import android.util.Log;
import android.util.Slog;
-import com.android.internal.os.InstallerConnection.InstallerException;
import com.android.internal.util.IndentingPrintWriter;
+import com.android.server.pm.Installer.InstallerException;
import java.io.File;
import java.io.IOException;
diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java
index 2ece99f..c85e1d8 100644
--- a/services/core/java/com/android/server/pm/PackageInstallerSession.java
+++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java
@@ -72,10 +72,10 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.content.NativeLibraryHelper;
import com.android.internal.content.PackageHelper;
-import com.android.internal.os.InstallerConnection.InstallerException;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.Preconditions;
+import com.android.server.pm.Installer.InstallerException;
import com.android.server.pm.PackageInstallerService.PackageInstallObserverAdapter;
import java.io.File;
diff --git a/services/core/java/com/android/server/pm/PackageManagerException.java b/services/core/java/com/android/server/pm/PackageManagerException.java
index f243e63..0e3f173 100644
--- a/services/core/java/com/android/server/pm/PackageManagerException.java
+++ b/services/core/java/com/android/server/pm/PackageManagerException.java
@@ -19,7 +19,7 @@
import android.content.pm.PackageManager;
import android.content.pm.PackageParser.PackageParserException;
-import com.android.internal.os.InstallerConnection.InstallerException;
+import com.android.server.pm.Installer.InstallerException;
/** {@hide} */
public class PackageManagerException extends Exception {
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 9102fee..7ce5aa8 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -231,7 +231,6 @@
import com.android.internal.content.PackageHelper;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.os.IParcelFileDescriptorFactory;
-import com.android.internal.os.InstallerConnection.InstallerException;
import com.android.internal.os.SomeArgs;
import com.android.internal.os.Zygote;
import com.android.internal.telephony.CarrierAppUtils;
@@ -250,6 +249,7 @@
import com.android.server.SystemConfig;
import com.android.server.Watchdog;
import com.android.server.net.NetworkPolicyManagerInternal;
+import com.android.server.pm.Installer.InstallerException;
import com.android.server.pm.PermissionsState.PermissionState;
import com.android.server.pm.Settings.DatabaseVersion;
import com.android.server.pm.Settings.VersionInfo;
@@ -1140,6 +1140,8 @@
final @NonNull String mServicesSystemSharedLibraryPackageName;
final @NonNull String mSharedSystemSharedLibraryPackageName;
+ final boolean mPermissionReviewRequired;
+
private final PackageUsage mPackageUsage = new PackageUsage();
private final CompilerStats mCompilerStats = new CompilerStats();
@@ -2070,6 +2072,10 @@
}
mContext = context;
+
+ mPermissionReviewRequired = context.getResources().getBoolean(
+ R.bool.config_permissionReviewRequired);
+
mFactoryTest = factoryTest;
mOnlyCore = onlyCore;
mMetrics = new DisplayMetrics();
@@ -2228,8 +2234,9 @@
getCompilerFilterForReason(REASON_SHARED_APK),
false /* newProfile */);
if (dexoptNeeded != DexFile.NO_DEXOPT_NEEDED) {
- mInstaller.dexopt(lib, Process.SYSTEM_UID, dexCodeInstructionSet,
- dexoptNeeded, DEXOPT_PUBLIC /*dexFlags*/,
+ mInstaller.dexopt(lib, Process.SYSTEM_UID, "*",
+ dexCodeInstructionSet, dexoptNeeded, null,
+ DEXOPT_PUBLIC,
getCompilerFilterForReason(REASON_SHARED_APK),
StorageManager.UUID_PRIVATE_INTERNAL,
SKIP_SHARED_LIBRARY_CHECK);
@@ -4026,7 +4033,7 @@
// their permissions as always granted runtime ones since we need
// to keep the review required permission flag per user while an
// install permission's state is shared across all users.
- if (Build.PERMISSIONS_REVIEW_REQUIRED
+ if ((mPermissionReviewRequired || Build.PERMISSIONS_REVIEW_REQUIRED)
&& pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M
&& bp.isRuntime()) {
return;
@@ -4137,7 +4144,7 @@
// their permissions as always granted runtime ones since we need
// to keep the review required permission flag per user while an
// install permission's state is shared across all users.
- if (Build.PERMISSIONS_REVIEW_REQUIRED
+ if ((mPermissionReviewRequired || Build.PERMISSIONS_REVIEW_REQUIRED)
&& pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M
&& bp.isRuntime()) {
return;
@@ -7353,6 +7360,11 @@
}
}
+ @Override
+ public void notifyDexLoad(String loadingPackageName, List<String> dexPaths, String loaderIsa) {
+ // TODO(calin): b/32871170
+ }
+
// TODO: this is not used nor needed. Delete it.
@Override
public boolean performDexOptIfNeeded(String packageName) {
@@ -10018,7 +10030,8 @@
// their permissions as always granted runtime ones since we need
// to keep the review required permission flag per user while an
// install permission's state is shared across all users.
- if (!appSupportsRuntimePermissions && !Build.PERMISSIONS_REVIEW_REQUIRED) {
+ if (!appSupportsRuntimePermissions && !mPermissionReviewRequired
+ && !Build.PERMISSIONS_REVIEW_REQUIRED) {
// For legacy apps dangerous permissions are install time ones.
grant = GRANT_INSTALL;
} else if (origPermissions.hasInstallPermission(bp.name)) {
@@ -10104,7 +10117,7 @@
changedRuntimePermissionUserIds, userId);
}
// If the app supports runtime permissions no need for a review.
- if (Build.PERMISSIONS_REVIEW_REQUIRED
+ if ((mPermissionReviewRequired || Build.PERMISSIONS_REVIEW_REQUIRED)
&& appSupportsRuntimePermissions
&& (flags & PackageManager
.FLAG_PERMISSION_REVIEW_REQUIRED) != 0) {
@@ -10113,7 +10126,8 @@
changedRuntimePermissionUserIds = ArrayUtils.appendInt(
changedRuntimePermissionUserIds, userId);
}
- } else if (Build.PERMISSIONS_REVIEW_REQUIRED
+ } else if ((mPermissionReviewRequired
+ || Build.PERMISSIONS_REVIEW_REQUIRED)
&& !appSupportsRuntimePermissions) {
// For legacy apps that need a permission review, every new
// runtime permission is granted but it is pending a review.
@@ -16708,7 +16722,7 @@
// If permission review is enabled and this is a legacy app, mark the
// permission as requiring a review as this is the initial state.
int flags = 0;
- if (Build.PERMISSIONS_REVIEW_REQUIRED
+ if ((mPermissionReviewRequired || Build.PERMISSIONS_REVIEW_REQUIRED)
&& ps.pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M) {
flags |= FLAG_PERMISSION_REVIEW_REQUIRED;
}
@@ -19960,8 +19974,9 @@
Preconditions.checkNotNull(app.seinfo);
+ long ceDataInode = -1;
try {
- mInstaller.createAppData(volumeUuid, packageName, userId, flags,
+ ceDataInode = mInstaller.createAppData(volumeUuid, packageName, userId, flags,
appId, app.seinfo, app.targetSdkVersion);
} catch (InstallerException e) {
if (app.isSystemApp()) {
@@ -19969,7 +19984,7 @@
+ ", but trying to recover: " + e);
destroyAppDataLeafLIF(pkg, userId, flags);
try {
- mInstaller.createAppData(volumeUuid, packageName, userId, flags,
+ ceDataInode = mInstaller.createAppData(volumeUuid, packageName, userId, flags,
appId, app.seinfo, app.targetSdkVersion);
logCriticalInfo(Log.DEBUG, "Recovery succeeded!");
} catch (InstallerException e2) {
@@ -19980,21 +19995,13 @@
}
}
- if ((flags & StorageManager.FLAG_STORAGE_CE) != 0) {
- try {
- // CE storage is unlocked right now, so read out the inode and
- // remember for use later when it's locked
- // TODO: mark this structure as dirty so we persist it!
- final long ceDataInode = mInstaller.getAppDataInode(volumeUuid, packageName, userId,
- StorageManager.FLAG_STORAGE_CE);
- synchronized (mPackages) {
- final PackageSetting ps = mSettings.mPackages.get(packageName);
- if (ps != null) {
- ps.setCeDataInode(ceDataInode, userId);
- }
+ if ((flags & StorageManager.FLAG_STORAGE_CE) != 0 && ceDataInode != -1) {
+ // TODO: mark this structure as dirty so we persist it!
+ synchronized (mPackages) {
+ final PackageSetting ps = mSettings.mPackages.get(packageName);
+ if (ps != null) {
+ ps.setCeDataInode(ceDataInode, userId);
}
- } catch (InstallerException e) {
- Slog.e(TAG, "Failed to find inode for " + packageName + ": " + e);
}
}
@@ -20577,7 +20584,7 @@
// permissions to keep per user flag state whether review is needed.
// Hence, if a new user is added we have to propagate dangerous
// permission grants for these legacy apps.
- if (Build.PERMISSIONS_REVIEW_REQUIRED) {
+ if (mPermissionReviewRequired || Build.PERMISSIONS_REVIEW_REQUIRED) {
updatePermissionsLPw(null, null, UPDATE_PERMISSIONS_ALL
| UPDATE_PERMISSIONS_REPLACE_ALL);
}
@@ -21031,7 +21038,7 @@
public boolean isPermissionsReviewRequired(String packageName, int userId) {
synchronized (mPackages) {
// If we do not support permission review, done.
- if (!Build.PERMISSIONS_REVIEW_REQUIRED) {
+ if (!mPermissionReviewRequired && !Build.PERMISSIONS_REVIEW_REQUIRED) {
return false;
}
diff --git a/services/core/java/com/android/server/pm/SELinuxMMAC.java b/services/core/java/com/android/server/pm/SELinuxMMAC.java
index 2176eb1..0fe1539 100644
--- a/services/core/java/com/android/server/pm/SELinuxMMAC.java
+++ b/services/core/java/com/android/server/pm/SELinuxMMAC.java
@@ -59,8 +59,9 @@
private static List<Policy> sPolicies = new ArrayList<>();
/** Path to MAC permissions on system image */
- private static final File MAC_PERMISSIONS = new File(Environment.getRootDirectory(),
- "/etc/security/mac_permissions.xml");
+ private static final File[] MAC_PERMISSIONS =
+ { new File(Environment.getRootDirectory(), "/etc/security/plat_mac_permissions.xml"),
+ new File(Environment.getRootDirectory(), "/etc/security/nonplat_mac_permissions.xml") };
// Append privapp to existing seinfo label
private static final String PRIVILEGED_APP_STR = ":privapp";
@@ -87,49 +88,51 @@
FileReader policyFile = null;
XmlPullParser parser = Xml.newPullParser();
- try {
- policyFile = new FileReader(MAC_PERMISSIONS);
- Slog.d(TAG, "Using policy file " + MAC_PERMISSIONS);
+ for (int i = 0; i < MAC_PERMISSIONS.length; i++) {
+ try {
+ policyFile = new FileReader(MAC_PERMISSIONS[i]);
+ Slog.d(TAG, "Using policy file " + MAC_PERMISSIONS[i]);
- parser.setInput(policyFile);
- parser.nextTag();
- parser.require(XmlPullParser.START_TAG, null, "policy");
+ parser.setInput(policyFile);
+ parser.nextTag();
+ parser.require(XmlPullParser.START_TAG, null, "policy");
- while (parser.next() != XmlPullParser.END_TAG) {
- if (parser.getEventType() != XmlPullParser.START_TAG) {
- continue;
+ while (parser.next() != XmlPullParser.END_TAG) {
+ if (parser.getEventType() != XmlPullParser.START_TAG) {
+ continue;
+ }
+
+ switch (parser.getName()) {
+ case "signer":
+ policies.add(readSignerOrThrow(parser));
+ break;
+ default:
+ skip(parser);
+ }
}
-
- switch (parser.getName()) {
- case "signer":
- policies.add(readSignerOrThrow(parser));
- break;
- default:
- skip(parser);
- }
+ } catch (IllegalStateException | IllegalArgumentException |
+ XmlPullParserException ex) {
+ StringBuilder sb = new StringBuilder("Exception @");
+ sb.append(parser.getPositionDescription());
+ sb.append(" while parsing ");
+ sb.append(MAC_PERMISSIONS[i]);
+ sb.append(":");
+ sb.append(ex);
+ Slog.w(TAG, sb.toString());
+ return false;
+ } catch (IOException ioe) {
+ Slog.w(TAG, "Exception parsing " + MAC_PERMISSIONS[i], ioe);
+ return false;
+ } finally {
+ IoUtils.closeQuietly(policyFile);
}
- } catch (IllegalStateException | IllegalArgumentException |
- XmlPullParserException ex) {
- StringBuilder sb = new StringBuilder("Exception @");
- sb.append(parser.getPositionDescription());
- sb.append(" while parsing ");
- sb.append(MAC_PERMISSIONS);
- sb.append(":");
- sb.append(ex);
- Slog.w(TAG, sb.toString());
- return false;
- } catch (IOException ioe) {
- Slog.w(TAG, "Exception parsing " + MAC_PERMISSIONS, ioe);
- return false;
- } finally {
- IoUtils.closeQuietly(policyFile);
}
// Now sort the policy stanzas
PolicyComparator policySort = new PolicyComparator();
Collections.sort(policies, policySort);
if (policySort.foundDuplicate()) {
- Slog.w(TAG, "ERROR! Duplicate entries found parsing " + MAC_PERMISSIONS);
+ Slog.w(TAG, "ERROR! Duplicate entries found parsing mac_permissions.xml files");
return false;
}
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
index 335af08..39cae37 100644
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -77,13 +77,13 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.os.BackgroundThread;
-import com.android.internal.os.InstallerConnection.InstallerException;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.JournaledFile;
import com.android.internal.util.XmlUtils;
import com.android.server.backup.PreferredActivityBackupHelper;
+import com.android.server.pm.Installer.InstallerException;
import com.android.server.pm.PackageManagerService.DumpState;
import com.android.server.pm.PermissionsState.PermissionState;
diff --git a/services/core/java/com/android/server/power/ShutdownThread.java b/services/core/java/com/android/server/power/ShutdownThread.java
index 44894ed..badee82 100644
--- a/services/core/java/com/android/server/power/ShutdownThread.java
+++ b/services/core/java/com/android/server/power/ShutdownThread.java
@@ -547,7 +547,7 @@
bluetooth.getState() == BluetoothAdapter.STATE_OFF;
if (!bluetoothOff) {
Log.w(TAG, "Disabling Bluetooth...");
- bluetooth.disable(false); // disable but don't persist new state
+ bluetooth.disable(mContext.getPackageName(), false); // disable but don't persist new state
}
} catch (RemoteException ex) {
Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java
index f0c6210..2a525d4 100644
--- a/services/core/java/com/android/server/wm/WindowStateAnimator.java
+++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java
@@ -1013,15 +1013,10 @@
if (attachedTransformation != null) {
tmpMatrix.postConcat(attachedTransformation.getMatrix());
}
+ tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
if (appTransformation != null) {
tmpMatrix.postConcat(appTransformation.getMatrix());
}
-
- // The translation that applies the position of the window needs to be applied at the
- // end in case that other translations include scaling. Otherwise the scaling will
- // affect this translation. But it needs to be set before the screen rotation animation
- // so the pivot point is at the center of the screen for all windows.
- tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
if (screenAnimation) {
tmpMatrix.postConcat(screenRotationAnimation.getEnterTransformation().getMatrix());
}
diff --git a/services/core/proto/ipconnectivity.proto b/services/core/proto/ipconnectivity.proto
index e0d7f09..29b318f 100644
--- a/services/core/proto/ipconnectivity.proto
+++ b/services/core/proto/ipconnectivity.proto
@@ -53,6 +53,7 @@
// The event type code of the probe, represented by constants defined in
// android.net.metrics.IpReachabilityEvent.
+ // NUD_FAILED_ORGANIC and PROVISIONING_LOST_ORGANIC recorded since version 1.
optional int32 event_type = 2;
};
@@ -126,11 +127,12 @@
// Lifetime duration in milliseconds of a DhcpClient state, or transition
// time in milliseconds between specific pairs of DhcpClient's states.
- // Only populated when state_transition is populated.
+ // Only populated since version 1, when state_transition is populated.
optional int32 duration_ms = 4;
}
// Represents the generation of an Android Packet Filter program.
+// Since version 1.
message ApfProgramEvent {
// Lifetime of the program in seconds.
optional int64 lifetime = 1;
@@ -154,6 +156,7 @@
// Represents Router Advertisement listening statistics for an interface with
// Android Packet Filter enabled.
+// Since version 1.
message ApfStatistics {
// The time interval in milliseconds these stastistics cover.
optional int64 duration_ms = 1;
@@ -183,6 +186,7 @@
// Represents the reception of a Router Advertisement packet for an interface
// with Android Packet Filter enabled.
+// Since version 1.
message RaEvent {
// All lifetime values are expressed in seconds. The default value for an
// option lifetime that was not present in the RA option list is -1.
@@ -271,4 +275,11 @@
// The number of events that had to be dropped due to a full buffer.
optional int32 dropped_events = 2;
+
+ // The version number of the metrics events being collected.
+ // nyc-dev: not populated, implicitly 0
+ // nyc-dr1: not populated, implicitly 1 (sailfish and marlin only)
+ // nyc-mr1: not populated, implicitly 1
+ // nyc-mr2: 2
+ optional int32 version = 3;
};
diff --git a/services/net/java/android/net/apf/ApfFilter.java b/services/net/java/android/net/apf/ApfFilter.java
index a8356dc..83001df 100644
--- a/services/net/java/android/net/apf/ApfFilter.java
+++ b/services/net/java/android/net/apf/ApfFilter.java
@@ -194,8 +194,10 @@
{ (byte) 0xff, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
private static final int ICMP6_TYPE_OFFSET = ETH_HEADER_LEN + IPV6_HEADER_LEN;
- private static final int ICMP6_NEIGHBOR_ANNOUNCEMENT = 136;
+ private static final int ICMP6_ROUTER_SOLICITATION = 133;
private static final int ICMP6_ROUTER_ADVERTISEMENT = 134;
+ private static final int ICMP6_NEIGHBOR_SOLICITATION = 135;
+ private static final int ICMP6_NEIGHBOR_ANNOUNCEMENT = 136;
// NOTE: this must be added to the IPv4 header length in IPV4_HEADER_SIZE_MEMORY_SLOT
private static final int UDP_DESTINATION_PORT_OFFSET = ETH_HEADER_LEN + 2;
@@ -805,6 +807,8 @@
// if it's multicast and we're dropping multicast:
// drop
// pass
+ // if it's ICMPv6 RS to any:
+ // drop
// if it's ICMPv6 NA to ff02::1:
// drop
@@ -829,10 +833,12 @@
// Add unsolicited multicast neighbor announcements filter
String skipUnsolicitedMulticastNALabel = "skipUnsolicitedMulticastNA";
- // If not neighbor announcements, skip unsolicited multicast NA filter
gen.addLoad8(Register.R0, ICMP6_TYPE_OFFSET);
+ // Drop all router solicitations (b/32833400)
+ gen.addJumpIfR0Equals(ICMP6_ROUTER_SOLICITATION, gen.DROP_LABEL);
+ // If not neighbor announcements, skip filter.
gen.addJumpIfR0NotEquals(ICMP6_NEIGHBOR_ANNOUNCEMENT, skipUnsolicitedMulticastNALabel);
- // If to ff02::1, drop
+ // If to ff02::1, drop.
// TODO: Drop only if they don't contain the address of on-link neighbours.
gen.addLoadImmediate(Register.R0, IPV6_DEST_ADDR_OFFSET);
gen.addJumpIfBytesNotEqual(Register.R0, IPV6_ALL_NODES_ADDRESS,
@@ -852,6 +858,7 @@
* <li>Pass all non-ICMPv6 IPv6 packets,
* <li>Pass all non-IPv4 and non-IPv6 packets,
* <li>Drop IPv6 ICMPv6 NAs to ff02::1.
+ * <li>Drop IPv6 ICMPv6 RSs.
* <li>Let execution continue off the end of the program for IPv6 ICMPv6 packets. This allows
* insertion of RA filters here, or if there aren't any, just passes the packets.
* </ul>
diff --git a/services/net/java/android/net/dhcp/DhcpPacket.java b/services/net/java/android/net/dhcp/DhcpPacket.java
index ef4bc02..d90a4a2 100644
--- a/services/net/java/android/net/dhcp/DhcpPacket.java
+++ b/services/net/java/android/net/dhcp/DhcpPacket.java
@@ -7,6 +7,7 @@
import android.os.Build;
import android.os.SystemProperties;
import android.system.OsConstants;
+import android.text.TextUtils;
import com.android.internal.annotations.VisibleForTesting;
import java.io.UnsupportedEncodingException;
@@ -25,8 +26,10 @@
* Defines basic data and operations needed to build and use packets for the
* DHCP protocol. Subclasses create the specific packets used at each
* stage of the negotiation.
+ *
+ * @hide
*/
-abstract class DhcpPacket {
+public abstract class DhcpPacket {
protected static final String TAG = "DhcpPacket";
// dhcpcd has a minimum lease of 20 seconds, but DhcpStateMachine would refuse to wake up the
@@ -629,7 +632,8 @@
protected void addCommonClientTlvs(ByteBuffer buf) {
addTlv(buf, DHCP_MAX_MESSAGE_SIZE, (short) MAX_LENGTH);
addTlv(buf, DHCP_VENDOR_CLASS_ID, getVendorId());
- addTlv(buf, DHCP_HOST_NAME, getHostname());
+ final String hn = getHostname();
+ if (!TextUtils.isEmpty(hn)) addTlv(buf, DHCP_HOST_NAME, hn);
}
/**
diff --git a/services/net/java/android/net/ip/ConnectivityPacketTracker.java b/services/net/java/android/net/ip/ConnectivityPacketTracker.java
new file mode 100644
index 0000000..884a8a7
--- /dev/null
+++ b/services/net/java/android/net/ip/ConnectivityPacketTracker.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2016 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.ip;
+
+import static android.system.OsConstants.*;
+
+import android.net.NetworkUtils;
+import android.net.util.BlockingSocketReader;
+import android.net.util.ConnectivityPacketSummary;
+import android.os.Handler;
+import android.system.ErrnoException;
+import android.system.Os;
+import android.system.PacketSocketAddress;
+import android.util.Log;
+import android.util.LocalLog;
+
+import libcore.io.IoBridge;
+import libcore.util.HexEncoding;
+
+import java.io.FileDescriptor;
+import java.io.InterruptedIOException;
+import java.io.IOException;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+
+
+/**
+ * Critical connectivity packet tracking daemon.
+ *
+ * Tracks ARP, DHCPv4, and IPv6 RS/RA/NS/NA packets.
+ *
+ * This class's constructor, start() and stop() methods must only be called
+ * from the same thread on which the passed in |log| is accessed.
+ *
+ * Log lines include a hexdump of the packet, which can be decoded via:
+ *
+ * echo -n H3XSTR1NG | sed -e 's/\([0-9A-F][0-9A-F]\)/\1 /g' -e 's/^/000000 /'
+ * | text2pcap - -
+ * | tcpdump -n -vv -e -r -
+ *
+ * @hide
+ */
+public class ConnectivityPacketTracker {
+ private static final String TAG = ConnectivityPacketTracker.class.getSimpleName();
+ private static final boolean DBG = false;
+ private static final String MARK_START = "--- START ---";
+ private static final String MARK_STOP = "--- STOP ---";
+
+ private final String mTag;
+ private final Handler mHandler;
+ private final LocalLog mLog;
+ private final BlockingSocketReader mPacketListener;
+
+ public ConnectivityPacketTracker(NetworkInterface netif, LocalLog log) {
+ final String ifname;
+ final int ifindex;
+ final byte[] hwaddr;
+ final int mtu;
+
+ try {
+ ifname = netif.getName();
+ ifindex = netif.getIndex();
+ hwaddr = netif.getHardwareAddress();
+ mtu = netif.getMTU();
+ } catch (NullPointerException|SocketException e) {
+ throw new IllegalArgumentException("bad network interface", e);
+ }
+
+ mTag = TAG + "." + ifname;
+ mHandler = new Handler();
+ mLog = log;
+ mPacketListener = new PacketListener(ifindex, hwaddr, mtu);
+ }
+
+ public void start() {
+ mLog.log(MARK_START);
+ mPacketListener.start();
+ }
+
+ public void stop() {
+ mPacketListener.stop();
+ mLog.log(MARK_STOP);
+ }
+
+ private final class PacketListener extends BlockingSocketReader {
+ private final int mIfIndex;
+ private final byte mHwAddr[];
+
+ PacketListener(int ifindex, byte[] hwaddr, int mtu) {
+ super(mtu);
+ mIfIndex = ifindex;
+ mHwAddr = hwaddr;
+ }
+
+ @Override
+ protected FileDescriptor createSocket() {
+ FileDescriptor s = null;
+ try {
+ // TODO: Evaluate switching to SOCK_DGRAM and changing the
+ // BlockingSocketReader's read() to recvfrom(), so that this
+ // might work on non-ethernet-like links (via SLL).
+ s = Os.socket(AF_PACKET, SOCK_RAW, 0);
+ NetworkUtils.attachControlPacketFilter(s, ARPHRD_ETHER);
+ Os.bind(s, new PacketSocketAddress((short) ETH_P_ALL, mIfIndex));
+ } catch (ErrnoException | IOException e) {
+ logError("Failed to create packet tracking socket: ", e);
+ closeSocket(s);
+ return null;
+ }
+ return s;
+ }
+
+ @Override
+ protected void handlePacket(byte[] recvbuf, int length) {
+ final String summary = ConnectivityPacketSummary.summarize(
+ mHwAddr, recvbuf, length);
+ if (summary == null) return;
+
+ if (DBG) Log.d(mTag, summary);
+ addLogEntry(summary +
+ "\n[" + new String(HexEncoding.encode(recvbuf, 0, length)) + "]");
+ }
+
+ @Override
+ protected void logError(String msg, Exception e) {
+ Log.e(mTag, msg, e);
+ addLogEntry(msg + e);
+ }
+
+ private void addLogEntry(String entry) {
+ mHandler.post(() -> mLog.log(entry));
+ }
+ }
+}
diff --git a/services/net/java/android/net/ip/IpManager.java b/services/net/java/android/net/ip/IpManager.java
index 39f14e5..87018ec 100644
--- a/services/net/java/android/net/ip/IpManager.java
+++ b/services/net/java/android/net/ip/IpManager.java
@@ -374,6 +374,7 @@
private static final int EVENT_DHCPACTION_TIMEOUT = 10;
private static final int MAX_LOG_RECORDS = 500;
+ private static final int MAX_PACKET_RECORDS = 100;
private static final boolean NO_CALLBACKS = false;
private static final boolean SEND_CALLBACKS = true;
@@ -399,6 +400,7 @@
private final WakeupMessage mDhcpActionTimeoutAlarm;
private final AvoidBadWifiTracker mAvoidBadWifiTracker;
private final LocalLog mLocalLog;
+ private final LocalLog mConnectivityPacketLog;
private final MessageHandlingLogger mMsgStateLogger;
private final IpConnectivityLog mMetricsLog = new IpConnectivityLog();
@@ -438,6 +440,10 @@
mCallback = new LoggingCallbackWrapper(callback);
mNwService = nwService;
+ mLocalLog = new LocalLog(MAX_LOG_RECORDS);
+ mConnectivityPacketLog = new LocalLog(MAX_PACKET_RECORDS);
+ mMsgStateLogger = new MessageHandlingLogger();
+
mNetlinkTracker = new NetlinkTracker(
mInterfaceName,
new NetlinkTracker.Callback() {
@@ -451,48 +457,79 @@
super.interfaceAdded(iface);
if (mClatInterfaceName.equals(iface)) {
mCallback.setNeighborDiscoveryOffload(false);
+ } else if (!mInterfaceName.equals(iface)) {
+ return;
}
+
+ final String msg = "interfaceAdded(" + iface +")";
+ logMsg(msg);
}
@Override
public void interfaceRemoved(String iface) {
super.interfaceRemoved(iface);
+ // TODO: Also observe mInterfaceName going down and take some
+ // kind of appropriate action.
if (mClatInterfaceName.equals(iface)) {
// TODO: consider sending a message to the IpManager main
// StateMachine thread, in case "NDO enabled" state becomes
// tied to more things that 464xlat operation.
mCallback.setNeighborDiscoveryOffload(true);
+ } else if (!mInterfaceName.equals(iface)) {
+ return;
}
+
+ final String msg = "interfaceRemoved(" + iface +")";
+ logMsg(msg);
+ }
+
+ private void logMsg(String msg) {
+ Log.d(mTag, msg);
+ getHandler().post(() -> { mLocalLog.log("OBSERVED " + msg); });
}
};
- try {
- mNwService.registerObserver(mNetlinkTracker);
- } catch (RemoteException e) {
- Log.e(mTag, "Couldn't register NetlinkTracker: " + e.toString());
- }
+ mLinkProperties = new LinkProperties();
+ mLinkProperties.setInterfaceName(mInterfaceName);
- mAvoidBadWifiTracker = new AvoidBadWifiTracker(mContext, getHandler());
-
- resetLinkProperties();
+ mAvoidBadWifiTracker = new AvoidBadWifiTracker(mContext, getHandler(),
+ () -> { mLocalLog.log("OBSERVED AvoidBadWifi changed"); });
mProvisioningTimeoutAlarm = new WakeupMessage(mContext, getHandler(),
mTag + ".EVENT_PROVISIONING_TIMEOUT", EVENT_PROVISIONING_TIMEOUT);
mDhcpActionTimeoutAlarm = new WakeupMessage(mContext, getHandler(),
mTag + ".EVENT_DHCPACTION_TIMEOUT", EVENT_DHCPACTION_TIMEOUT);
- // Super simple StateMachine.
+ // Anything the StateMachine may access must have been instantiated
+ // before this point.
+ configureAndStartStateMachine();
+
+ // Anything that may send messages to the StateMachine must only be
+ // configured to do so after the StateMachine has started (above).
+ startStateMachineUpdaters();
+ }
+
+ private void configureAndStartStateMachine() {
addState(mStoppedState);
addState(mStartedState);
addState(mRunningState, mStartedState);
addState(mStoppingState);
setInitialState(mStoppedState);
- mLocalLog = new LocalLog(MAX_LOG_RECORDS);
- mMsgStateLogger = new MessageHandlingLogger();
+
super.start();
}
+ private void startStateMachineUpdaters() {
+ try {
+ mNwService.registerObserver(mNetlinkTracker);
+ } catch (RemoteException e) {
+ Log.e(mTag, "Couldn't register NetlinkTracker: " + e.toString());
+ }
+
+ mAvoidBadWifiTracker.start();
+ }
+
@Override
protected void onQuitting() {
mCallback.onQuit();
@@ -501,6 +538,7 @@
// Shut down this IpManager instance altogether.
public void shutdown() {
stop();
+ mAvoidBadWifiTracker.shutdown();
quit();
}
@@ -574,7 +612,7 @@
}
IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
- pw.println("APF dump:");
+ pw.println(mTag + " APF dump:");
pw.increaseIndent();
// Thread-unsafe access to mApfFilter but just used for debugging.
ApfFilter apfFilter = mApfFilter;
@@ -590,6 +628,12 @@
pw.increaseIndent();
mLocalLog.readOnlyLocalLog().dump(fd, pw, args);
pw.decreaseIndent();
+
+ pw.println();
+ pw.println(mTag + " connectivity packet log:");
+ pw.increaseIndent();
+ mConnectivityPacketLog.readOnlyLocalLog().dump(fd, pw, args);
+ pw.decreaseIndent();
}
@@ -1185,6 +1229,7 @@
}
class RunningState extends State {
+ private ConnectivityPacketTracker mPacketTracker;
private boolean mDhcpActionInFlight;
@Override
@@ -1197,6 +1242,9 @@
mCallback.setFallbackMulticastFilter(mMulticastFiltering);
}
+ mPacketTracker = createPacketTracker();
+ if (mPacketTracker != null) mPacketTracker.start();
+
if (mConfiguration.mEnableIPv6 && !startIPv6()) {
doImmediateProvisioningFailure(IpManagerEvent.ERROR_STARTING_IPV6);
transitionTo(mStoppingState);
@@ -1231,6 +1279,11 @@
mDhcpClient.doQuit();
}
+ if (mPacketTracker != null) {
+ mPacketTracker.stop();
+ mPacketTracker = null;
+ }
+
if (mApfFilter != null) {
mApfFilter.shutdown();
mApfFilter = null;
@@ -1239,6 +1292,14 @@
resetLinkProperties();
}
+ private ConnectivityPacketTracker createPacketTracker() {
+ try {
+ return new ConnectivityPacketTracker(mNetworkInterface, mConnectivityPacketLog);
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
+
private void ensureDhcpAction() {
if (!mDhcpActionInFlight) {
mCallback.onPreDhcpAction();
diff --git a/services/net/java/android/net/util/AvoidBadWifiTracker.java b/services/net/java/android/net/util/AvoidBadWifiTracker.java
index c14e811..2abaeb1 100644
--- a/services/net/java/android/net/util/AvoidBadWifiTracker.java
+++ b/services/net/java/android/net/util/AvoidBadWifiTracker.java
@@ -57,7 +57,11 @@
private final Context mContext;
private final Handler mHandler;
private final Runnable mReevaluateRunnable;
+ private final Uri mUri;
+ private final ContentResolver mResolver;
private final SettingObserver mSettingObserver;
+ private final BroadcastReceiver mBroadcastReceiver;
+
private volatile boolean mAvoidBadWifi = true;
public AvoidBadWifiTracker(Context ctx, Handler handler) {
@@ -68,19 +72,36 @@
mContext = ctx;
mHandler = handler;
mReevaluateRunnable = () -> { if (update() && cb != null) cb.run(); };
+ mUri = Settings.Global.getUriFor(NETWORK_AVOID_BAD_WIFI);
+ mResolver = mContext.getContentResolver();
mSettingObserver = new SettingObserver();
-
- final IntentFilter intentFilter = new IntentFilter();
- intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
- mContext.registerReceiverAsUser(new BroadcastReceiver() {
+ mBroadcastReceiver = new BroadcastReceiver() {
+ @Override
public void onReceive(Context context, Intent intent) {
reevaluate();
}
- }, UserHandle.ALL, intentFilter, null, null);
+ };
update();
}
+ public void start() {
+ mResolver.registerContentObserver(mUri, false, mSettingObserver);
+
+ final IntentFilter intentFilter = new IntentFilter();
+ intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
+ mContext.registerReceiverAsUser(
+ mBroadcastReceiver, UserHandle.ALL, intentFilter, null, null);
+
+ reevaluate();
+ }
+
+ public void shutdown() {
+ mResolver.unregisterContentObserver(mSettingObserver);
+
+ mContext.unregisterReceiver(mBroadcastReceiver);
+ }
+
public boolean currentValue() {
return mAvoidBadWifi;
}
@@ -100,8 +121,7 @@
}
public String getSettingsValue() {
- final ContentResolver resolver = mContext.getContentResolver();
- return Settings.Global.getString(resolver, NETWORK_AVOID_BAD_WIFI);
+ return Settings.Global.getString(mResolver, NETWORK_AVOID_BAD_WIFI);
}
@VisibleForTesting
@@ -117,12 +137,8 @@
}
private class SettingObserver extends ContentObserver {
- private final Uri mUri = Settings.Global.getUriFor(NETWORK_AVOID_BAD_WIFI);
-
public SettingObserver() {
super(null);
- final ContentResolver resolver = mContext.getContentResolver();
- resolver.registerContentObserver(mUri, false, this);
}
@Override
diff --git a/services/net/java/android/net/util/BlockingSocketReader.java b/services/net/java/android/net/util/BlockingSocketReader.java
new file mode 100644
index 0000000..12fa1e5
--- /dev/null
+++ b/services/net/java/android/net/util/BlockingSocketReader.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2016 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.util;
+
+import android.annotation.Nullable;
+import android.system.ErrnoException;
+import android.system.Os;
+import android.system.OsConstants;
+
+import libcore.io.IoBridge;
+
+import java.io.FileDescriptor;
+import java.io.InterruptedIOException;
+import java.io.IOException;
+
+
+/**
+ * A thread that reads from a socket and passes the received packets to a
+ * subclass's handlePacket() method. The packet receive buffer is recycled
+ * on every read call, so subclasses should make any copies they would like
+ * inside their handlePacket() implementation.
+ *
+ * All public methods may be called from any thread.
+ *
+ * @hide
+ */
+public abstract class BlockingSocketReader {
+ public static final int DEFAULT_RECV_BUF_SIZE = 2 * 1024;
+
+ private final byte[] mPacket;
+ private final Thread mThread;
+ private volatile FileDescriptor mSocket;
+ private volatile boolean mRunning;
+ private volatile long mPacketsReceived;
+
+ // Make it slightly easier for subclasses to properly close a socket
+ // without having to know this incantation.
+ public static final void closeSocket(@Nullable FileDescriptor fd) {
+ try {
+ IoBridge.closeAndSignalBlockedThreads(fd);
+ } catch (IOException ignored) {}
+ }
+
+ protected BlockingSocketReader() {
+ this(DEFAULT_RECV_BUF_SIZE);
+ }
+
+ protected BlockingSocketReader(int recvbufsize) {
+ if (recvbufsize < DEFAULT_RECV_BUF_SIZE) {
+ recvbufsize = DEFAULT_RECV_BUF_SIZE;
+ }
+ mPacket = new byte[recvbufsize];
+ mThread = new Thread(() -> { mainLoop(); });
+ }
+
+ public final boolean start() {
+ if (mSocket != null) return false;
+
+ try {
+ mSocket = createSocket();
+ } catch (Exception e) {
+ logError("Failed to create socket: ", e);
+ return false;
+ }
+
+ if (mSocket == null) return false;
+
+ mRunning = true;
+ mThread.start();
+ return true;
+ }
+
+ public final void stop() {
+ mRunning = false;
+ closeSocket(mSocket);
+ mSocket = null;
+ }
+
+ public final boolean isRunning() { return mRunning; }
+
+ public final long numPacketsReceived() { return mPacketsReceived; }
+
+ /**
+ * Subclasses MUST create the listening socket here, including setting
+ * all desired socket options, interface or address/port binding, etc.
+ */
+ protected abstract FileDescriptor createSocket();
+
+ /**
+ * Called by the main loop for every packet. Any desired copies of
+ * |recvbuf| should be made in here, and the underlying byte array is
+ * reused across all reads.
+ */
+ protected void handlePacket(byte[] recvbuf, int length) {}
+
+ /**
+ * Called by the main loop to log errors. In some cases |e| may be null.
+ */
+ protected void logError(String msg, Exception e) {}
+
+ /**
+ * Called by the main loop just prior to exiting.
+ */
+ protected void onExit() {}
+
+ private final void mainLoop() {
+ while (isRunning()) {
+ final int bytesRead;
+
+ try {
+ // Blocking read.
+ // TODO: See if this can be converted to recvfrom.
+ bytesRead = Os.read(mSocket, mPacket, 0, mPacket.length);
+ if (bytesRead < 1) {
+ if (isRunning()) logError("Socket closed, exiting", null);
+ break;
+ }
+ mPacketsReceived++;
+ } catch (ErrnoException e) {
+ if (e.errno != OsConstants.EINTR) {
+ if (isRunning()) logError("read error: ", e);
+ break;
+ }
+ continue;
+ } catch (IOException ioe) {
+ if (isRunning()) logError("read error: ", ioe);
+ continue;
+ }
+
+ try {
+ handlePacket(mPacket, bytesRead);
+ } catch (Exception e) {
+ logError("Unexpected exception: ", e);
+ break;
+ }
+ }
+
+ stop();
+ onExit();
+ }
+}
diff --git a/services/net/java/android/net/util/ConnectivityPacketSummary.java b/services/net/java/android/net/util/ConnectivityPacketSummary.java
new file mode 100644
index 0000000..699ba5b
--- /dev/null
+++ b/services/net/java/android/net/util/ConnectivityPacketSummary.java
@@ -0,0 +1,375 @@
+/*
+ * Copyright (C) 2016 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.util;
+
+import android.net.dhcp.DhcpPacket;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.Arrays;
+import java.util.StringJoiner;
+
+import static android.system.OsConstants.*;
+import static android.net.util.NetworkConstants.*;
+
+
+/**
+ * Critical connectivity packet summarizing class.
+ *
+ * Outputs short descriptions of ARP, DHCPv4, and IPv6 RS/RA/NS/NA packets.
+ *
+ * @hide
+ */
+public class ConnectivityPacketSummary {
+ private static final String TAG = ConnectivityPacketSummary.class.getSimpleName();
+
+ private final byte[] mHwAddr;
+ private final byte[] mBytes;
+ private final int mLength;
+ private final ByteBuffer mPacket;
+ private final String mSummary;
+
+ public static String summarize(byte[] hwaddr, byte[] buffer) {
+ return summarize(hwaddr, buffer, buffer.length);
+ }
+
+ // Methods called herein perform some but by no means all error checking.
+ // They may throw runtime exceptions on malformed packets.
+ public static String summarize(byte[] hwaddr, byte[] buffer, int length) {
+ if ((hwaddr == null) || (hwaddr.length != ETHER_ADDR_LEN)) return null;
+ if (buffer == null) return null;
+ length = Math.min(length, buffer.length);
+ return (new ConnectivityPacketSummary(hwaddr, buffer, length)).toString();
+ }
+
+ private ConnectivityPacketSummary(byte[] hwaddr, byte[] buffer, int length) {
+ mHwAddr = hwaddr;
+ mBytes = buffer;
+ mLength = Math.min(length, mBytes.length);
+ mPacket = ByteBuffer.wrap(mBytes, 0, mLength);
+ mPacket.order(ByteOrder.BIG_ENDIAN);
+
+ final StringJoiner sj = new StringJoiner(" ");
+ // TODO: support other link-layers, or even no link-layer header.
+ parseEther(sj);
+ mSummary = sj.toString();
+ }
+
+ public String toString() {
+ return mSummary;
+ }
+
+ private void parseEther(StringJoiner sj) {
+ if (mPacket.remaining() < ETHER_HEADER_LEN) {
+ sj.add("runt:").add(asString(mPacket.remaining()));
+ return;
+ }
+
+ mPacket.position(ETHER_SRC_ADDR_OFFSET);
+ final ByteBuffer srcMac = (ByteBuffer) mPacket.slice().limit(ETHER_ADDR_LEN);
+ sj.add(ByteBuffer.wrap(mHwAddr).equals(srcMac) ? "TX" : "RX");
+ sj.add(getMacAddressString(srcMac));
+
+ mPacket.position(ETHER_DST_ADDR_OFFSET);
+ final ByteBuffer dstMac = (ByteBuffer) mPacket.slice().limit(ETHER_ADDR_LEN);
+ sj.add(">").add(getMacAddressString(dstMac));
+
+ mPacket.position(ETHER_TYPE_OFFSET);
+ final int etherType = asUint(mPacket.getShort());
+ switch (etherType) {
+ case ETHER_TYPE_ARP:
+ sj.add("arp");
+ parseARP(sj);
+ break;
+ case ETHER_TYPE_IPV4:
+ sj.add("ipv4");
+ parseIPv4(sj);
+ break;
+ case ETHER_TYPE_IPV6:
+ sj.add("ipv6");
+ parseIPv6(sj);
+ break;
+ default:
+ // Unknown ether type.
+ sj.add("ethtype").add(asString(etherType));
+ break;
+ }
+ }
+
+ private void parseARP(StringJoiner sj) {
+ if (mPacket.remaining() < ARP_PAYLOAD_LEN) {
+ sj.add("runt:").add(asString(mPacket.remaining()));
+ return;
+ }
+
+ if (asUint(mPacket.getShort()) != ARP_HWTYPE_ETHER ||
+ asUint(mPacket.getShort()) != ETHER_TYPE_IPV4 ||
+ asUint(mPacket.get()) != ETHER_ADDR_LEN ||
+ asUint(mPacket.get()) != IPV4_ADDR_LEN) {
+ sj.add("unexpected header");
+ return;
+ }
+
+ final int opCode = asUint(mPacket.getShort());
+
+ final String senderHwAddr = getMacAddressString(mPacket);
+ final String senderIPv4 = getIPv4AddressString(mPacket);
+ getMacAddressString(mPacket); // target hardware address, unused
+ final String targetIPv4 = getIPv4AddressString(mPacket);
+
+ if (opCode == ARP_REQUEST) {
+ sj.add("who-has").add(targetIPv4);
+ } else if (opCode == ARP_REPLY) {
+ sj.add("reply").add(senderIPv4).add(senderHwAddr);
+ } else {
+ sj.add("unknown opcode").add(asString(opCode));
+ }
+ }
+
+ private void parseIPv4(StringJoiner sj) {
+ if (!mPacket.hasRemaining()) {
+ sj.add("runt");
+ return;
+ }
+
+ final int startOfIpLayer = mPacket.position();
+ final int ipv4HeaderLength = (mPacket.get(startOfIpLayer) & IPV4_IHL_MASK) * 4;
+ if (mPacket.remaining() < ipv4HeaderLength ||
+ mPacket.remaining() < IPV4_HEADER_MIN_LEN) {
+ sj.add("runt:").add(asString(mPacket.remaining()));
+ return;
+ }
+ final int startOfTransportLayer = startOfIpLayer + ipv4HeaderLength;
+
+ mPacket.position(startOfIpLayer + IPV4_FLAGS_OFFSET);
+ final int flagsAndFragment = asUint(mPacket.getShort());
+ final boolean isFragment = (flagsAndFragment & IPV4_FRAGMENT_MASK) != 0;
+
+ mPacket.position(startOfIpLayer + IPV4_PROTOCOL_OFFSET);
+ final int protocol = asUint(mPacket.get());
+
+ mPacket.position(startOfIpLayer + IPV4_SRC_ADDR_OFFSET);
+ final String srcAddr = getIPv4AddressString(mPacket);
+
+ mPacket.position(startOfIpLayer + IPV4_DST_ADDR_OFFSET);
+ final String dstAddr = getIPv4AddressString(mPacket);
+
+ sj.add(srcAddr).add(">").add(dstAddr);
+
+ mPacket.position(startOfTransportLayer);
+ if (protocol == IPPROTO_UDP) {
+ sj.add("udp");
+ if (isFragment) sj.add("fragment");
+ else parseUDP(sj);
+ } else {
+ sj.add("proto").add(asString(protocol));
+ if (isFragment) sj.add("fragment");
+ }
+ }
+
+ private void parseIPv6(StringJoiner sj) {
+ if (mPacket.remaining() < IPV6_HEADER_LEN) {
+ sj.add("runt:").add(asString(mPacket.remaining()));
+ return;
+ }
+
+ final int startOfIpLayer = mPacket.position();
+
+ mPacket.position(startOfIpLayer + IPV6_PROTOCOL_OFFSET);
+ final int protocol = asUint(mPacket.get());
+
+ mPacket.position(startOfIpLayer + IPV6_SRC_ADDR_OFFSET);
+ final String srcAddr = getIPv6AddressString(mPacket);
+ final String dstAddr = getIPv6AddressString(mPacket);
+
+ sj.add(srcAddr).add(">").add(dstAddr);
+
+ mPacket.position(startOfIpLayer + IPV6_HEADER_LEN);
+ if (protocol == IPPROTO_ICMPV6) {
+ sj.add("icmp6");
+ parseICMPv6(sj);
+ } else {
+ sj.add("proto").add(asString(protocol));
+ }
+ }
+
+ private void parseICMPv6(StringJoiner sj) {
+ if (mPacket.remaining() < ICMPV6_HEADER_MIN_LEN) {
+ sj.add("runt:").add(asString(mPacket.remaining()));
+ return;
+ }
+
+ final int icmp6Type = asUint(mPacket.get());
+ final int icmp6Code = asUint(mPacket.get());
+ mPacket.getShort(); // checksum, unused
+
+ switch (icmp6Type) {
+ case ICMPV6_ROUTER_SOLICITATION:
+ sj.add("rs");
+ parseICMPv6RouterSolicitation(sj);
+ break;
+ case ICMPV6_ROUTER_ADVERTISEMENT:
+ sj.add("ra");
+ parseICMPv6RouterAdvertisement(sj);
+ break;
+ case ICMPV6_NEIGHBOR_SOLICITATION:
+ sj.add("ns");
+ parseICMPv6NeighborMessage(sj);
+ break;
+ case ICMPV6_NEIGHBOR_ADVERTISEMENT:
+ sj.add("na");
+ parseICMPv6NeighborMessage(sj);
+ break;
+ default:
+ sj.add("type").add(asString(icmp6Type));
+ sj.add("code").add(asString(icmp6Code));
+ break;
+ }
+ }
+
+ private void parseICMPv6RouterSolicitation(StringJoiner sj) {
+ final int RESERVED = 4;
+ if (mPacket.remaining() < RESERVED) {
+ sj.add("runt:").add(asString(mPacket.remaining()));
+ return;
+ }
+
+ mPacket.position(mPacket.position() + RESERVED);
+ parseICMPv6NeighborDiscoveryOptions(sj);
+ }
+
+ private void parseICMPv6RouterAdvertisement(StringJoiner sj) {
+ final int FLAGS_AND_TIMERS = 3 * 4;
+ if (mPacket.remaining() < FLAGS_AND_TIMERS) {
+ sj.add("runt:").add(asString(mPacket.remaining()));
+ return;
+ }
+
+ mPacket.position(mPacket.position() + FLAGS_AND_TIMERS);
+ parseICMPv6NeighborDiscoveryOptions(sj);
+ }
+
+ private void parseICMPv6NeighborMessage(StringJoiner sj) {
+ final int RESERVED = 4;
+ final int minReq = RESERVED + IPV6_ADDR_LEN;
+ if (mPacket.remaining() < minReq) {
+ sj.add("runt:").add(asString(mPacket.remaining()));
+ return;
+ }
+
+ mPacket.position(mPacket.position() + RESERVED);
+ sj.add(getIPv6AddressString(mPacket));
+ parseICMPv6NeighborDiscoveryOptions(sj);
+ }
+
+ private void parseICMPv6NeighborDiscoveryOptions(StringJoiner sj) {
+ // All ND options are TLV, where T is one byte and L is one byte equal
+ // to the length of T + L + V in units of 8 octets.
+ while (mPacket.remaining() >= ICMPV6_ND_OPTION_MIN_LENGTH) {
+ final int ndType = asUint(mPacket.get());
+ final int ndLength = asUint(mPacket.get());
+ final int ndBytes = ndLength * ICMPV6_ND_OPTION_LENGTH_SCALING_FACTOR - 2;
+ if (mPacket.remaining() < ndBytes) break;
+ final int position = mPacket.position();
+
+ switch (ndType) {
+ case ICMPV6_ND_OPTION_SLLA:
+ sj.add("slla");
+ sj.add(getMacAddressString(mPacket));
+ break;
+ case ICMPV6_ND_OPTION_TLLA:
+ sj.add("tlla");
+ sj.add(getMacAddressString(mPacket));
+ break;
+ case ICMPV6_ND_OPTION_MTU:
+ sj.add("mtu");
+ final short reserved = mPacket.getShort();
+ sj.add(asString(mPacket.getInt()));
+ break;
+ default:
+ // Skip.
+ break;
+ }
+
+ mPacket.position(position + ndBytes);
+ }
+ }
+
+ private void parseUDP(StringJoiner sj) {
+ if (mPacket.remaining() < UDP_HEADER_LEN) {
+ sj.add("runt:").add(asString(mPacket.remaining()));
+ return;
+ }
+
+ final int previous = mPacket.position();
+ final int srcPort = asUint(mPacket.getShort());
+ final int dstPort = asUint(mPacket.getShort());
+ sj.add(asString(srcPort)).add(">").add(asString(dstPort));
+
+ mPacket.position(previous + UDP_HEADER_LEN);
+ if (srcPort == DHCP4_CLIENT_PORT || dstPort == DHCP4_CLIENT_PORT) {
+ sj.add("dhcp4");
+ parseDHCPv4(sj);
+ }
+ }
+
+ private void parseDHCPv4(StringJoiner sj) {
+ final DhcpPacket dhcpPacket;
+ try {
+ dhcpPacket = DhcpPacket.decodeFullPacket(mBytes, mLength, DhcpPacket.ENCAP_L2);
+ sj.add(dhcpPacket.toString());
+ } catch (DhcpPacket.ParseException e) {
+ sj.add("parse error: " + e);
+ }
+ }
+
+ private static String getIPv4AddressString(ByteBuffer ipv4) {
+ return getIpAddressString(ipv4, IPV4_ADDR_LEN);
+ }
+
+ private static String getIPv6AddressString(ByteBuffer ipv6) {
+ return getIpAddressString(ipv6, IPV6_ADDR_LEN);
+ }
+
+ private static String getIpAddressString(ByteBuffer ip, int byteLength) {
+ if (ip == null || ip.remaining() < byteLength) return "invalid";
+
+ byte[] bytes = new byte[byteLength];
+ ip.get(bytes, 0, byteLength);
+ try {
+ InetAddress addr = InetAddress.getByAddress(bytes);
+ return addr.getHostAddress();
+ } catch (UnknownHostException uhe) {
+ return "unknown";
+ }
+ }
+
+ private static String getMacAddressString(ByteBuffer mac) {
+ if (mac == null || mac.remaining() < ETHER_ADDR_LEN) return "invalid";
+
+ byte[] bytes = new byte[ETHER_ADDR_LEN];
+ mac.get(bytes, 0, bytes.length);
+ Byte[] printableBytes = new Byte[bytes.length];
+ int i = 0;
+ for (byte b : bytes) printableBytes[i++] = b;
+
+ final String MAC48_FORMAT = "%02x:%02x:%02x:%02x:%02x:%02x";
+ return String.format(MAC48_FORMAT, printableBytes);
+ }
+}
diff --git a/services/net/java/android/net/util/NetworkConstants.java b/services/net/java/android/net/util/NetworkConstants.java
new file mode 100644
index 0000000..362f757
--- /dev/null
+++ b/services/net/java/android/net/util/NetworkConstants.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2016 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.util;
+
+import java.nio.ByteBuffer;
+
+
+/**
+ * Networking protocol constants.
+ *
+ * Includes:
+ * - constants that describe packet layout
+ * - various helper functions
+ *
+ * @hide
+ */
+public final class NetworkConstants {
+ private NetworkConstants() { throw new RuntimeException("no instance permitted"); }
+
+ /**
+ * Ethernet constants.
+ *
+ * See also:
+ * - https://tools.ietf.org/html/rfc894
+ * - https://tools.ietf.org/html/rfc7042
+ * - http://www.iana.org/assignments/ethernet-numbers/ethernet-numbers.xhtml
+ * - http://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.xhtml
+ */
+ public static final int ETHER_DST_ADDR_OFFSET = 0;
+ public static final int ETHER_SRC_ADDR_OFFSET = 6;
+ public static final int ETHER_ADDR_LEN = 6;
+
+ public static final int ETHER_TYPE_OFFSET = 12;
+ public static final int ETHER_TYPE_LENGTH = 2;
+ public static final int ETHER_TYPE_ARP = 0x0806;
+ public static final int ETHER_TYPE_IPV4 = 0x0800;
+ public static final int ETHER_TYPE_IPV6 = 0x86dd;
+
+ public static final int ETHER_HEADER_LEN = 14;
+
+ private static final byte FF = asByte(0xff);
+ public static final byte[] ETHER_ADDR_BROADCAST = {
+ FF, FF, FF, FF, FF, FF
+ };
+
+ /**
+ * ARP constants.
+ *
+ * See also:
+ * - https://tools.ietf.org/html/rfc826
+ * - http://www.iana.org/assignments/arp-parameters/arp-parameters.xhtml
+ */
+ public static final int ARP_PAYLOAD_LEN = 28; // For Ethernet+IPv4.
+ public static final int ARP_REQUEST = 1;
+ public static final int ARP_REPLY = 2;
+ public static final int ARP_HWTYPE_RESERVED_LO = 0;
+ public static final int ARP_HWTYPE_ETHER = 1;
+ public static final int ARP_HWTYPE_RESERVED_HI = 0xffff;
+
+ /**
+ * IPv4 constants.
+ *
+ * See als:
+ * - https://tools.ietf.org/html/rfc791
+ */
+ public static final int IPV4_HEADER_MIN_LEN = 20;
+ public static final int IPV4_IHL_MASK = 0xf;
+ public static final int IPV4_FLAGS_OFFSET = 6;
+ public static final int IPV4_FRAGMENT_MASK = 0x1fff;
+ public static final int IPV4_PROTOCOL_OFFSET = 9;
+ public static final int IPV4_SRC_ADDR_OFFSET = 12;
+ public static final int IPV4_DST_ADDR_OFFSET = 16;
+ public static final int IPV4_ADDR_LEN = 4;
+
+ /**
+ * IPv6 constants.
+ *
+ * See also:
+ * - https://tools.ietf.org/html/rfc2460
+ */
+ public static final int IPV6_HEADER_LEN = 40;
+ public static final int IPV6_PROTOCOL_OFFSET = 6;
+ public static final int IPV6_SRC_ADDR_OFFSET = 8;
+ public static final int IPV6_DST_ADDR_OFFSET = 24;
+ public static final int IPV6_ADDR_LEN = 16;
+
+ /**
+ * ICMPv6 constants.
+ *
+ * See also:
+ * - https://tools.ietf.org/html/rfc4443
+ * - https://tools.ietf.org/html/rfc4861
+ */
+ public static final int ICMPV6_HEADER_MIN_LEN = 4;
+ public static final int ICMPV6_ROUTER_SOLICITATION = 133;
+ public static final int ICMPV6_ROUTER_ADVERTISEMENT = 134;
+ public static final int ICMPV6_NEIGHBOR_SOLICITATION = 135;
+ public static final int ICMPV6_NEIGHBOR_ADVERTISEMENT = 136;
+
+ public static final int ICMPV6_ND_OPTION_MIN_LENGTH = 8;
+ public static final int ICMPV6_ND_OPTION_LENGTH_SCALING_FACTOR = 8;
+ public static final int ICMPV6_ND_OPTION_SLLA = 1;
+ public static final int ICMPV6_ND_OPTION_TLLA = 2;
+ public static final int ICMPV6_ND_OPTION_MTU = 5;
+
+ /**
+ * UDP constants.
+ *
+ * See also:
+ * - https://tools.ietf.org/html/rfc768
+ */
+ public static final int UDP_HEADER_LEN = 8;
+
+ /**
+ * DHCP(v4) constants.
+ *
+ * See also:
+ * - https://tools.ietf.org/html/rfc2131
+ */
+ public static final int DHCP4_SERVER_PORT = 67;
+ public static final int DHCP4_CLIENT_PORT = 68;
+
+ /**
+ * Utility functions.
+ */
+ public static byte asByte(int i) { return (byte) i; }
+
+ public static String asString(int i) { return Integer.toString(i); }
+
+ public static int asUint(byte b) { return (b & 0xff); }
+ public static int asUint(short s) { return (s & 0xffff); }
+}
diff --git a/services/tests/servicestests/Android.mk b/services/tests/servicestests/Android.mk
index 3183930..2187c57 100644
--- a/services/tests/servicestests/Android.mk
+++ b/services/tests/servicestests/Android.mk
@@ -12,12 +12,12 @@
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_STATIC_JAVA_LIBRARIES := \
+ easymocklib \
frameworks-base-testutils \
services.core \
services.devicepolicy \
services.net \
services.usage \
- easymocklib \
guava \
android-support-test \
mockito-target \
diff --git a/services/tests/servicestests/src/android/net/util/BlockingSocketReaderTest.java b/services/tests/servicestests/src/android/net/util/BlockingSocketReaderTest.java
new file mode 100644
index 0000000..e03350f
--- /dev/null
+++ b/services/tests/servicestests/src/android/net/util/BlockingSocketReaderTest.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2016 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.util;
+
+import static android.system.OsConstants.*;
+
+import android.system.ErrnoException;
+import android.system.Os;
+import android.system.StructTimeval;
+
+import libcore.io.IoBridge;
+
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.SocketException;
+import java.util.Arrays;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests for BlockingSocketReader.
+ *
+ * @hide
+ */
+public class BlockingSocketReaderTest extends TestCase {
+ static final InetAddress LOOPBACK6 = Inet6Address.getLoopbackAddress();
+ static final StructTimeval TIMEO = StructTimeval.fromMillis(500);
+
+ protected CountDownLatch mLatch;
+ protected FileDescriptor mLocalSocket;
+ protected InetSocketAddress mLocalSockName;
+ protected byte[] mLastRecvBuf;
+ protected boolean mExited;
+ protected BlockingSocketReader mReceiver;
+
+ @Override
+ public void setUp() {
+ resetLatch();
+ mLocalSocket = null;
+ mLocalSockName = null;
+ mLastRecvBuf = null;
+ mExited = false;
+
+ mReceiver = new BlockingSocketReader() {
+ @Override
+ protected FileDescriptor createSocket() {
+ FileDescriptor s = null;
+ try {
+ s = Os.socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
+ Os.bind(s, LOOPBACK6, 0);
+ mLocalSockName = (InetSocketAddress) Os.getsockname(s);
+ Os.setsockoptTimeval(s, SOL_SOCKET, SO_SNDTIMEO, TIMEO);
+ } catch (ErrnoException|SocketException e) {
+ closeSocket(s);
+ fail();
+ return null;
+ }
+
+ mLocalSocket = s;
+ return s;
+ }
+
+ @Override
+ protected void handlePacket(byte[] recvbuf, int length) {
+ mLastRecvBuf = Arrays.copyOf(recvbuf, length);
+ mLatch.countDown();
+ }
+
+ @Override
+ protected void onExit() {
+ mExited = true;
+ mLatch.countDown();
+ }
+ };
+ }
+
+ @Override
+ public void tearDown() {
+ if (mReceiver != null) mReceiver.stop();
+ mReceiver = null;
+ }
+
+ void resetLatch() { mLatch = new CountDownLatch(1); }
+
+ void waitForActivity() throws Exception {
+ assertTrue(mLatch.await(500, TimeUnit.MILLISECONDS));
+ resetLatch();
+ }
+
+ void sendPacket(byte[] contents) throws Exception {
+ final DatagramSocket sender = new DatagramSocket();
+ sender.connect(mLocalSockName);
+ sender.send(new DatagramPacket(contents, contents.length));
+ sender.close();
+ }
+
+ public void testBasicWorking() throws Exception {
+ assertTrue(mReceiver.start());
+ assertTrue(mLocalSockName != null);
+ assertEquals(LOOPBACK6, mLocalSockName.getAddress());
+ assertTrue(0 < mLocalSockName.getPort());
+ assertTrue(mLocalSocket != null);
+ assertFalse(mExited);
+
+ final byte[] one = "one 1".getBytes("UTF-8");
+ sendPacket(one);
+ waitForActivity();
+ assertEquals(1, mReceiver.numPacketsReceived());
+ assertTrue(Arrays.equals(one, mLastRecvBuf));
+ assertFalse(mExited);
+
+ final byte[] two = "two 2".getBytes("UTF-8");
+ sendPacket(two);
+ waitForActivity();
+ assertEquals(2, mReceiver.numPacketsReceived());
+ assertTrue(Arrays.equals(two, mLastRecvBuf));
+ assertFalse(mExited);
+
+ mReceiver.stop();
+ waitForActivity();
+ assertEquals(2, mReceiver.numPacketsReceived());
+ assertTrue(Arrays.equals(two, mLastRecvBuf));
+ assertTrue(mExited);
+ }
+}
diff --git a/services/tests/servicestests/src/android/net/util/ConnectivityPacketSummaryTest.java b/services/tests/servicestests/src/android/net/util/ConnectivityPacketSummaryTest.java
new file mode 100644
index 0000000..766e5c0
--- /dev/null
+++ b/services/tests/servicestests/src/android/net/util/ConnectivityPacketSummaryTest.java
@@ -0,0 +1,377 @@
+/*
+ * Copyright (C) 2016 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.util;
+
+import static android.net.util.NetworkConstants.*;
+
+import libcore.util.HexEncoding;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests for ConnectivityPacketSummary.
+ *
+ * @hide
+ */
+public class ConnectivityPacketSummaryTest extends TestCase {
+ private static final byte[] MYHWADDR = {
+ asByte(0x80), asByte(0x7a), asByte(0xbf), asByte(0x6f), asByte(0x48), asByte(0xf3)
+ };
+
+ private String getSummary(String hexBytes) {
+ hexBytes = hexBytes.replaceAll("\\s+", "");
+ final byte[] bytes = HexEncoding.decode(hexBytes.toCharArray(), false);
+ return ConnectivityPacketSummary.summarize(MYHWADDR, bytes);
+ }
+
+ public void testParseICMPv6DADProbe() {
+ final String packet =
+ // Ethernet
+ "3333FF6F48F3 807ABF6F48F3 86DD" +
+ // IPv6
+ "600000000018 3A FF" +
+ "00000000000000000000000000000000" +
+ "FF0200000000000000000001FF6F48F3" +
+ // ICMPv6
+ "87 00 A8E7" +
+ "00000000" +
+ "FE80000000000000827ABFFFFE6F48F3";
+
+ final String expected =
+ "TX 80:7a:bf:6f:48:f3 > 33:33:ff:6f:48:f3 ipv6" +
+ " :: > ff02::1:ff6f:48f3 icmp6" +
+ " ns fe80::827a:bfff:fe6f:48f3";
+
+ assertEquals(expected, getSummary(packet));
+ }
+
+ public void testParseICMPv6RS() {
+ final String packet =
+ // Ethernet
+ "333300000002 807ABF6F48F3 86DD" +
+ // IPv6
+ "600000000010 3A FF" +
+ "FE80000000000000827ABFFFFE6F48F3" +
+ "FF020000000000000000000000000002" +
+ // ICMPv6 RS
+ "85 00 6973" +
+ "00000000" +
+ "01 01 807ABF6F48F3";
+
+ final String expected =
+ "TX 80:7a:bf:6f:48:f3 > 33:33:00:00:00:02 ipv6" +
+ " fe80::827a:bfff:fe6f:48f3 > ff02::2 icmp6" +
+ " rs slla 80:7a:bf:6f:48:f3";
+
+ assertEquals(expected, getSummary(packet));
+ }
+
+ public void testParseICMPv6RA() {
+ final String packet =
+ // Ethernet
+ "807ABF6F48F3 100E7E263FC1 86DD" +
+ // IPv6
+ "600000000068 3A FF" +
+ "FE80000000000000FA000004FD000001" +
+ "FE80000000000000827ABFFFFE6F48F3" +
+ // ICMPv6 RA
+ "86 00 8141" +
+ "40 00 0E10" +
+ "00000000" +
+ "00000000" +
+ "01 01 00005E000265" +
+ "05 01 0000000005DC" +
+ "19 05 000000000E10" +
+ " 20014860486000000000000000008844" +
+ " 20014860486000000000000000008888" +
+ "03 04 40 C0" +
+ " 00278D00" +
+ " 00093A80" +
+ " 00000000" +
+ " 2401FA000004FD000000000000000000";
+
+ final String expected =
+ "RX 10:0e:7e:26:3f:c1 > 80:7a:bf:6f:48:f3 ipv6" +
+ " fe80::fa00:4:fd00:1 > fe80::827a:bfff:fe6f:48f3 icmp6" +
+ " ra slla 00:00:5e:00:02:65 mtu 1500";
+
+ assertEquals(expected, getSummary(packet));
+ }
+
+ public void testParseICMPv6NS() {
+ final String packet =
+ // Ethernet
+ "807ABF6F48F3 100E7E263FC1 86DD" +
+ // IPv6
+ "6C0000000020 3A FF" +
+ "FE80000000000000FA000004FD000001" +
+ "FF0200000000000000000001FF01C146" +
+ // ICMPv6 NS
+ "87 00 8AD4" +
+ "00000000" +
+ "2401FA000004FD0015EA6A5C7B01C146" +
+ "01 01 00005E000265";
+
+ final String expected =
+ "RX 10:0e:7e:26:3f:c1 > 80:7a:bf:6f:48:f3 ipv6" +
+ " fe80::fa00:4:fd00:1 > ff02::1:ff01:c146 icmp6" +
+ " ns 2401:fa00:4:fd00:15ea:6a5c:7b01:c146 slla 00:00:5e:00:02:65";
+
+ assertEquals(expected, getSummary(packet));
+ }
+
+ public void testParseICMPv6NA() {
+ final String packet =
+ // Ethernet
+ "00005E000265 807ABF6F48F3 86DD" +
+ "600000000020 3A FF" +
+ "2401FA000004FD0015EA6A5C7B01C146" +
+ "FE80000000000000FA000004FD000001" +
+ "88 00 E8126" +
+ "0000000" +
+ "2401FA000004FD0015EA6A5C7B01C146" +
+ "02 01 807ABF6F48F3";
+
+ final String expected =
+ "TX 80:7a:bf:6f:48:f3 > 00:00:5e:00:02:65 ipv6" +
+ " 2401:fa00:4:fd00:15ea:6a5c:7b01:c146 > fe80::fa00:4:fd00:1 icmp6" +
+ " na 2401:fa00:4:fd00:15ea:6a5c:7b01:c146 tlla 80:7a:bf:6f:48:f3";
+
+ assertEquals(expected, getSummary(packet));
+ }
+
+ public void testParseARPRequest() {
+ final String packet =
+ // Ethernet
+ "FFFFFFFFFFFF 807ABF6F48F3 0806" +
+ // ARP
+ "0001 0800 06 04" +
+ // Request
+ "0001" +
+ "807ABF6F48F3 64706ADB" +
+ "000000000000 64706FFD";
+
+ final String expected =
+ "TX 80:7a:bf:6f:48:f3 > ff:ff:ff:ff:ff:ff arp" +
+ " who-has 100.112.111.253";
+
+ assertEquals(expected, getSummary(packet));
+ }
+
+ public void testParseARPReply() {
+ final String packet =
+ // Ethernet
+ "807ABF6F48F3 288A1CA8DFC1 0806" +
+ // ARP
+ "0001 0800 06 04" +
+ // Reply
+ "0002" +
+ "288A1CA8DFC1 64706FFD"+
+ "807ABF6F48F3 64706ADB" +
+ // Ethernet padding to packet min size.
+ "0000000000000000000000000000";
+
+ final String expected =
+ "RX 28:8a:1c:a8:df:c1 > 80:7a:bf:6f:48:f3 arp" +
+ " reply 100.112.111.253 28:8a:1c:a8:df:c1";
+
+ assertEquals(expected, getSummary(packet));
+ }
+
+ public void testParseDHCPv4Discover() {
+ final String packet =
+ // Ethernet
+ "FFFFFFFFFFFF 807ABF6F48F3 0800" +
+ // IPv4
+ "451001580000400040113986" +
+ "00000000" +
+ "FFFFFFFF" +
+ // UDP
+ "0044 0043" +
+ "0144 5559" +
+ // DHCPv4
+ "01 01 06 00" +
+ "79F7ACA4" +
+ "0000 0000" +
+ "00000000" +
+ "00000000" +
+ "00000000" +
+ "00000000" +
+ "807ABF6F48F300000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "63 82 53 63" +
+ "35 01 01" +
+ "3D 07 01807ABF6F48F3" +
+ "39 02 05DC" +
+ "3C 12 616E64726F69642D646863702D372E312E32" +
+ "0C 18 616E64726F69642D36623030366333313333393835343139" +
+ "37 0A 01 03 06 0F 1A 1C 33 3A 3B 2B" +
+ "FF" +
+ "00";
+
+ final String expectedPrefix =
+ "TX 80:7a:bf:6f:48:f3 > ff:ff:ff:ff:ff:ff ipv4" +
+ " 0.0.0.0 > 255.255.255.255 udp" +
+ " 68 > 67 dhcp4" +
+ " 80:7a:bf:6f:48:f3 DISCOVER";
+
+ assertTrue(getSummary(packet).startsWith(expectedPrefix));
+ }
+
+ public void testParseDHCPv4Offer() {
+ final String packet =
+ // Ethernet
+ "807ABF6F48F3 288A1CA8DFC1 0800" +
+ // IPv4
+ "4500013D4D2C0000401188CB" +
+ "64706FFD" +
+ "64706ADB" +
+ // UDP
+ "0043 0044" +
+ "0129 371D" +
+ // DHCPv4
+ "02 01 06 01" +
+ "79F7ACA4" +
+ "0000 0000" +
+ "00000000" +
+ "64706ADB" +
+ "00000000" +
+ "00000000" +
+ "807ABF6F48F300000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "63 82 53 63" +
+ "35 01 02" +
+ "36 04 AC188A0B" +
+ "33 04 00000708" +
+ "01 04 FFFFF000" +
+ "03 04 64706FFE" +
+ "06 08 08080808" +
+ " 08080404" +
+ "FF0001076165313A363636FF";
+
+ final String expectedPrefix =
+ "RX 28:8a:1c:a8:df:c1 > 80:7a:bf:6f:48:f3 ipv4" +
+ " 100.112.111.253 > 100.112.106.219 udp" +
+ " 67 > 68 dhcp4" +
+ " 80:7a:bf:6f:48:f3 OFFER";
+
+ assertTrue(getSummary(packet).startsWith(expectedPrefix));
+ }
+
+ public void testParseDHCPv4Request() {
+ final String packet =
+ // Ethernet
+ "FFFFFFFFFFFF 807ABF6F48F3 0800" +
+ // IPv4
+ "45100164000040004011397A" +
+ "00000000" +
+ "FFFFFFFF" +
+ // UDP
+ "0044 0043" +
+ "0150 E5C7" +
+ // DHCPv4
+ "01 01 06 00" +
+ "79F7ACA4" +
+ "0001 0000" +
+ "00000000" +
+ "00000000" +
+ "00000000" +
+ "00000000" +
+ "807ABF6F48F300000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "63 82 53 63" +
+ "35 01 03" +
+ "3D 07 01807ABF6F48F3" +
+ "32 04 64706ADB" +
+ "36 04 AC188A0B" +
+ "39 02 05DC" +
+ "3C 12 616E64726F69642D646863702D372E312E32" +
+ "0C 18 616E64726F69642D36623030366333313333393835343139" +
+ "37 0A 01 03 06 0F 1A 1C 33 3A 3B 2B" +
+ "FF" +
+ "00";
+
+ final String expectedPrefix =
+ "TX 80:7a:bf:6f:48:f3 > ff:ff:ff:ff:ff:ff ipv4" +
+ " 0.0.0.0 > 255.255.255.255 udp" +
+ " 68 > 67 dhcp4" +
+ " 80:7a:bf:6f:48:f3 REQUEST";
+
+ assertTrue(getSummary(packet).startsWith(expectedPrefix));
+ }
+
+ public void testParseDHCPv4Ack() {
+ final String packet =
+ // Ethernet
+ "807ABF6F48F3 288A1CA8DFC1 0800" +
+ // IPv4
+ "4500013D4D3B0000401188BC" +
+ "64706FFD" +
+ "64706ADB" +
+ // UDP
+ "0043 0044" +
+ "0129 341C" +
+ // DHCPv4
+ "02 01 06 01" +
+ "79F7ACA4" +
+ "0001 0000" +
+ "00000000" +
+ "64706ADB" +
+ "00000000" +
+ "00000000" +
+ "807ABF6F48F300000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "0000000000000000000000000000000000000000000000000000000000000000" +
+ "63 82 53 63" +
+ "35 01 05" +
+ "36 04 AC188A0B" +
+ "33 04 00000708" +
+ "01 04 FFFFF000" +
+ "03 04 64706FFE" +
+ "06 08 08080808" +
+ " 08080404" +
+ "FF0001076165313A363636FF";
+
+ final String expectedPrefix =
+ "RX 28:8a:1c:a8:df:c1 > 80:7a:bf:6f:48:f3 ipv4" +
+ " 100.112.111.253 > 100.112.106.219 udp" +
+ " 67 > 68 dhcp4" +
+ " 80:7a:bf:6f:48:f3 ACK";
+
+ assertTrue(getSummary(packet).startsWith(expectedPrefix));
+ }
+}
diff --git a/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
index 8d36ac9..a545af9 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
@@ -16,17 +16,12 @@
package com.android.server;
-import static android.content.Intent.ACTION_UID_REMOVED;
-import static android.content.Intent.EXTRA_UID;
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
import static android.net.ConnectivityManager.TYPE_WIFI;
-import static android.net.NetworkPolicy.CYCLE_NONE;
import static android.net.NetworkPolicy.LIMIT_DISABLED;
import static android.net.NetworkPolicy.WARNING_DISABLED;
import static android.net.NetworkPolicyManager.POLICY_NONE;
import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
-import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
-import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
import static android.net.NetworkPolicyManager.computeLastCycleBoundary;
import static android.net.NetworkPolicyManager.computeNextCycleBoundary;
import static android.net.TrafficStats.KB_IN_BYTES;
@@ -34,28 +29,42 @@
import static android.text.format.DateUtils.DAY_IN_MILLIS;
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
import static android.text.format.Time.TIMEZONE_UTC;
+
import static com.android.server.net.NetworkPolicyManagerService.TYPE_LIMIT;
import static com.android.server.net.NetworkPolicyManagerService.TYPE_LIMIT_SNOOZED;
import static com.android.server.net.NetworkPolicyManagerService.TYPE_WARNING;
-import static org.easymock.EasyMock.anyInt;
-import static org.easymock.EasyMock.anyLong;
-import static org.easymock.EasyMock.aryEq;
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.isA;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isA;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.ActivityManager;
import android.app.IActivityManager;
import android.app.INotificationManager;
-import android.app.IProcessObserver;
+import android.app.IUidObserver;
import android.app.Notification;
+import android.app.usage.UsageStatsManagerInternal;
+import android.content.Context;
import android.content.Intent;
+import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
-import android.net.ConnectivityManager;
import android.net.IConnectivityManager;
import android.net.INetworkManagementEventObserver;
import android.net.INetworkPolicyListener;
@@ -69,40 +78,48 @@
import android.net.NetworkTemplate;
import android.os.Binder;
import android.os.INetworkManagementService;
-import android.os.MessageQueue.IdleHandler;
+import android.os.PowerManagerInternal;
import android.os.UserHandle;
-import android.test.AndroidTestCase;
-import android.test.mock.MockPackageManager;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.test.suitebuilder.annotation.Suppress;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
import android.text.format.Time;
+import android.util.Log;
import android.util.TrustedTime;
import com.android.internal.util.test.BroadcastInterceptingContext;
+import com.android.server.net.NetworkPolicyManagerInternal;
import com.android.server.net.NetworkPolicyManagerService;
+
+import libcore.io.IoUtils;
+
import com.google.common.util.concurrent.AbstractFuture;
-import org.easymock.Capture;
-import org.easymock.EasyMock;
-import org.easymock.IAnswer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
import java.io.File;
-import java.util.Calendar;
+import java.util.ArrayList;
import java.util.LinkedHashSet;
-import java.util.TimeZone;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import java.util.logging.Handler;
-
-import libcore.io.IoUtils;
/**
* Tests for {@link NetworkPolicyManagerService}.
*/
-@LargeTest
-public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+public class NetworkPolicyManagerServiceTest {
private static final String TAG = "NetworkPolicyManagerServiceTest";
private static final long TEST_START = 1194220800000L;
@@ -114,19 +131,19 @@
private BroadcastInterceptingContext mServiceContext;
private File mPolicyDir;
- private IActivityManager mActivityManager;
- private INetworkStatsService mStatsService;
- private INetworkManagementService mNetworkManager;
- private INetworkPolicyListener mPolicyListener;
- private TrustedTime mTime;
- private IConnectivityManager mConnManager;
- private INotificationManager mNotifManager;
+ private @Mock IActivityManager mActivityManager;
+ private @Mock INetworkStatsService mStatsService;
+ private @Mock INetworkManagementService mNetworkManager;
+ private @Mock TrustedTime mTime;
+ private @Mock IConnectivityManager mConnManager;
+ private @Mock INotificationManager mNotifManager;
+ private @Mock PackageManager mPackageManager;
- private NetworkPolicyManagerService mService;
- private IProcessObserver mProcessObserver;
+ private IUidObserver mUidObserver;
private INetworkManagementEventObserver mNetworkObserver;
- private Binder mStubBinder = new Binder();
+ private NetworkPolicyListenerAnswer mPolicyListener;
+ private NetworkPolicyManagerService mService;
private long mStartTime;
private long mElapsedRealtime;
@@ -139,39 +156,30 @@
private static final int UID_A = UserHandle.getUid(USER_ID, APP_ID_A);
private static final int UID_B = UserHandle.getUid(USER_ID, APP_ID_B);
- private static final int PID_1 = 400;
- private static final int PID_2 = 401;
- private static final int PID_3 = 402;
+ private static final String PKG_NAME_A = "name.is.A,pkg.A";
- public void _setUp() throws Exception {
- super.setUp();
+ @BeforeClass
+ public static void registerLocalServices() {
+ addLocalServiceMock(PowerManagerInternal.class);
+ addLocalServiceMock(DeviceIdleController.LocalService.class);
+ final UsageStatsManagerInternal usageStats =
+ addLocalServiceMock(UsageStatsManagerInternal.class);
+ when(usageStats.getIdleUidsForUser(anyInt())).thenReturn(new int[]{});
+ }
+
+ @Before
+ public void callSystemReady() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ final Context context = InstrumentationRegistry.getContext();
setCurrentTimeMillis(TEST_START);
// intercept various broadcasts, and pretend that uids have packages
- mServiceContext = new BroadcastInterceptingContext(getContext()) {
+ mServiceContext = new BroadcastInterceptingContext(context) {
@Override
public PackageManager getPackageManager() {
- return new MockPackageManager() {
- @Override
- public String[] getPackagesForUid(int uid) {
- return new String[] { "com.example" };
- }
-
- @Override
- public PackageInfo getPackageInfo(String packageName, int flags) {
- final PackageInfo info = new PackageInfo();
- final Signature signature;
- if ("android".equals(packageName)) {
- signature = new Signature("F00D");
- } else {
- signature = new Signature("DEAD");
- }
- info.signatures = new Signature[] { signature };
- return info;
- }
-
- };
+ return mPackageManager;
}
@Override
@@ -180,229 +188,112 @@
}
};
- mPolicyDir = getContext().getFilesDir();
+ mPolicyDir = context.getFilesDir();
if (mPolicyDir.exists()) {
IoUtils.deleteContents(mPolicyDir);
}
- mActivityManager = createMock(IActivityManager.class);
- mStatsService = createMock(INetworkStatsService.class);
- mNetworkManager = createMock(INetworkManagementService.class);
- mPolicyListener = createMock(INetworkPolicyListener.class);
- mTime = createMock(TrustedTime.class);
- mConnManager = createMock(IConnectivityManager.class);
- mNotifManager = createMock(INotificationManager.class);
+ doAnswer(new Answer<Void>() {
- mService = new NetworkPolicyManagerService(mServiceContext, mActivityManager,
- mStatsService, mNetworkManager, mTime, mPolicyDir, true);
+ @Override
+ public Void answer(InvocationOnMock invocation) throws Throwable {
+ mUidObserver = (IUidObserver) invocation.getArguments()[0];
+ Log.d(TAG, "set mUidObserver to " + mUidObserver);
+ return null;
+ }
+ }).when(mActivityManager).registerUidObserver(any(), anyInt());
+
+ mService = new NetworkPolicyManagerService(mServiceContext, mActivityManager, mStatsService,
+ mNetworkManager, mTime, mPolicyDir, true);
mService.bindConnectivityManager(mConnManager);
mService.bindNotificationManager(mNotifManager);
+ mPolicyListener = new NetworkPolicyListenerAnswer(mService);
- // RemoteCallbackList needs a binder to use as key
- expect(mPolicyListener.asBinder()).andReturn(mStubBinder).atLeastOnce();
- replay();
- mService.registerListener(mPolicyListener);
- verifyAndReset();
+ // Sets some common expectations.
+ when(mPackageManager.getPackageInfo(anyString(), anyInt())).thenAnswer(
+ new Answer<PackageInfo>() {
- // catch IProcessObserver during systemReady()
- final Capture<IProcessObserver> processObserver = new Capture<IProcessObserver>();
- mActivityManager.registerProcessObserver(capture(processObserver));
- expectLastCall().atLeastOnce();
-
- // catch INetworkManagementEventObserver during systemReady()
- final Capture<INetworkManagementEventObserver> networkObserver = new Capture<
- INetworkManagementEventObserver>();
- mNetworkManager.registerObserver(capture(networkObserver));
- expectLastCall().atLeastOnce();
-
- expect(mNetworkManager.isBandwidthControlEnabled()).andReturn(true).atLeastOnce();
+ @Override
+ public PackageInfo answer(InvocationOnMock invocation) throws Throwable {
+ final String packageName = (String) invocation.getArguments()[0];
+ final PackageInfo info = new PackageInfo();
+ final Signature signature;
+ if ("android".equals(packageName)) {
+ signature = new Signature("F00D");
+ } else {
+ signature = new Signature("DEAD");
+ }
+ info.signatures = new Signature[] {
+ signature
+ };
+ return info;
+ }
+ });
+ when(mPackageManager.getApplicationInfoAsUser(anyString(), anyInt(), anyInt()))
+ .thenReturn(new ApplicationInfo());
+ when(mPackageManager.getPackagesForUid(UID_A)).thenReturn(new String[] {PKG_NAME_A});
+ when(mNetworkManager.isBandwidthControlEnabled()).thenReturn(true);
expectCurrentTime();
- replay();
+ // Prepare NPMS.
mService.systemReady();
- verifyAndReset();
- mProcessObserver = processObserver.getValue();
+ // catch INetworkManagementEventObserver during systemReady()
+ ArgumentCaptor<INetworkManagementEventObserver> networkObserver =
+ ArgumentCaptor.forClass(INetworkManagementEventObserver.class);
+ verify(mNetworkManager).registerObserver(networkObserver.capture());
mNetworkObserver = networkObserver.getValue();
-
}
- public void _tearDown() throws Exception {
+ @After
+ public void removeFiles() throws Exception {
for (File file : mPolicyDir.listFiles()) {
file.delete();
}
-
- mServiceContext = null;
- mPolicyDir = null;
-
- mActivityManager = null;
- mStatsService = null;
- mPolicyListener = null;
- mTime = null;
-
- mService = null;
- mProcessObserver = null;
-
- super.tearDown();
}
- @Suppress
- public void testPolicyChangeTriggersBroadcast() throws Exception {
+ @After
+ public void unregisterLocalServices() throws Exception {
+ // Registered by NetworkPolicyManagerService's constructor.
+ LocalServices.removeServiceForTest(NetworkPolicyManagerInternal.class);
+ }
+
+ // NOTE: testPolicyChangeTriggersListener() and testUidForeground() are too superficial, they
+ // don't check for side-effects (like calls to NetworkManagementService) neither cover all
+ // different modes (Data Saver, Battery Saver, Doze, App idle, etc...).
+ // These scenarios are extensively tested on CTS' HostsideRestrictBackgroundNetworkTests.
+
+ @Test
+ public void testPolicyChangeTriggersListener() throws Exception {
+ mPolicyListener.expect().onRestrictBackgroundBlacklistChanged(anyInt(), anyBoolean());
+
mService.setUidPolicy(APP_ID_A, POLICY_NONE);
-
- // change background policy and expect broadcast
- final Future<Intent> backgroundChanged = mServiceContext.nextBroadcastIntent(
- ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED);
-
mService.setUidPolicy(APP_ID_A, POLICY_REJECT_METERED_BACKGROUND);
- backgroundChanged.get();
+ mPolicyListener.waitAndVerify().onRestrictBackgroundBlacklistChanged(APP_ID_A, true);
}
- @Suppress
- public void testPidForegroundCombined() throws Exception {
- IdleFuture idle;
-
- // push all uid into background
- idle = expectIdle();
- mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, false);
- mProcessObserver.onForegroundActivitiesChanged(PID_2, UID_A, false);
- mProcessObserver.onForegroundActivitiesChanged(PID_3, UID_B, false);
- idle.get();
+ @Test
+ public void testUidForeground() throws Exception {
+ // push all uids into background
+ mUidObserver.onUidStateChanged(UID_A, ActivityManager.PROCESS_STATE_SERVICE);
+ mUidObserver.onUidStateChanged(UID_B, ActivityManager.PROCESS_STATE_SERVICE);
assertFalse(mService.isUidForeground(UID_A));
assertFalse(mService.isUidForeground(UID_B));
- // push one of the shared pids into foreground
- idle = expectIdle();
- mProcessObserver.onForegroundActivitiesChanged(PID_2, UID_A, true);
- idle.get();
+ // push one of the uids into foreground
+ mUidObserver.onUidStateChanged(UID_A, ActivityManager.PROCESS_STATE_TOP);
assertTrue(mService.isUidForeground(UID_A));
assertFalse(mService.isUidForeground(UID_B));
// and swap another uid into foreground
- idle = expectIdle();
- mProcessObserver.onForegroundActivitiesChanged(PID_2, UID_A, false);
- mProcessObserver.onForegroundActivitiesChanged(PID_3, UID_B, true);
- idle.get();
+ mUidObserver.onUidStateChanged(UID_A, ActivityManager.PROCESS_STATE_SERVICE);
+ mUidObserver.onUidStateChanged(UID_B, ActivityManager.PROCESS_STATE_TOP);
assertFalse(mService.isUidForeground(UID_A));
assertTrue(mService.isUidForeground(UID_B));
-
- // push both pid into foreground
- idle = expectIdle();
- mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, true);
- mProcessObserver.onForegroundActivitiesChanged(PID_2, UID_A, true);
- idle.get();
- assertTrue(mService.isUidForeground(UID_A));
-
- // pull one out, should still be foreground
- idle = expectIdle();
- mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, false);
- idle.get();
- assertTrue(mService.isUidForeground(UID_A));
-
- // pull final pid out, should now be background
- idle = expectIdle();
- mProcessObserver.onForegroundActivitiesChanged(PID_2, UID_A, false);
- idle.get();
- assertFalse(mService.isUidForeground(UID_A));
}
- @Suppress
- public void testPolicyNone() throws Exception {
- Future<Void> future;
-
- expectSetUidMeteredNetworkBlacklist(UID_A, false);
- expectSetUidForeground(UID_A, true);
- future = expectRulesChanged(UID_A, RULE_ALLOW_ALL);
- replay();
- mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, true);
- future.get();
- verifyAndReset();
-
- // POLICY_NONE should RULE_ALLOW in foreground
- expectSetUidMeteredNetworkBlacklist(UID_A, false);
- expectSetUidForeground(UID_A, true);
- future = expectRulesChanged(UID_A, RULE_ALLOW_ALL);
- replay();
- mService.setUidPolicy(APP_ID_A, POLICY_NONE);
- future.get();
- verifyAndReset();
-
- // POLICY_NONE should RULE_ALLOW in background
- expectSetUidMeteredNetworkBlacklist(UID_A, false);
- expectSetUidForeground(UID_A, false);
- future = expectRulesChanged(UID_A, RULE_ALLOW_ALL);
- replay();
- mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, false);
- future.get();
- verifyAndReset();
- }
-
- @Suppress
- public void testPolicyReject() throws Exception {
- Future<Void> future;
-
- // POLICY_REJECT should RULE_ALLOW in background
- expectSetUidMeteredNetworkBlacklist(UID_A, true);
- expectSetUidForeground(UID_A, false);
- future = expectRulesChanged(UID_A, RULE_REJECT_METERED);
- replay();
- mService.setUidPolicy(APP_ID_A, POLICY_REJECT_METERED_BACKGROUND);
- future.get();
- verifyAndReset();
-
- // POLICY_REJECT should RULE_ALLOW in foreground
- expectSetUidMeteredNetworkBlacklist(UID_A, false);
- expectSetUidForeground(UID_A, true);
- future = expectRulesChanged(UID_A, RULE_ALLOW_ALL);
- replay();
- mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, true);
- future.get();
- verifyAndReset();
-
- // POLICY_REJECT should RULE_REJECT in background
- expectSetUidMeteredNetworkBlacklist(UID_A, true);
- expectSetUidForeground(UID_A, false);
- future = expectRulesChanged(UID_A, RULE_REJECT_METERED);
- replay();
- mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, false);
- future.get();
- verifyAndReset();
- }
-
- @Suppress
- public void testPolicyRejectAddRemove() throws Exception {
- Future<Void> future;
-
- // POLICY_NONE should have RULE_ALLOW in background
- expectSetUidMeteredNetworkBlacklist(UID_A, false);
- expectSetUidForeground(UID_A, false);
- future = expectRulesChanged(UID_A, RULE_ALLOW_ALL);
- replay();
- mProcessObserver.onForegroundActivitiesChanged(PID_1, UID_A, false);
- mService.setUidPolicy(APP_ID_A, POLICY_NONE);
- future.get();
- verifyAndReset();
-
- // adding POLICY_REJECT should cause RULE_REJECT
- expectSetUidMeteredNetworkBlacklist(UID_A, true);
- expectSetUidForeground(UID_A, false);
- future = expectRulesChanged(UID_A, RULE_REJECT_METERED);
- replay();
- mService.setUidPolicy(APP_ID_A, POLICY_REJECT_METERED_BACKGROUND);
- future.get();
- verifyAndReset();
-
- // removing POLICY_REJECT should return us to RULE_ALLOW
- expectSetUidMeteredNetworkBlacklist(UID_A, false);
- expectSetUidForeground(UID_A, false);
- future = expectRulesChanged(UID_A, RULE_ALLOW_ALL);
- replay();
- mService.setUidPolicy(APP_ID_A, POLICY_NONE);
- future.get();
- verifyAndReset();
- }
-
+ @Test
public void testLastCycleBoundaryThisMonth() throws Exception {
// assume cycle day of "5th", which should be in same month
final long currentTime = parseTime("2007-11-14T00:00:00.000Z");
@@ -414,6 +305,7 @@
assertTimeEquals(expectedCycle, actualCycle);
}
+ @Test
public void testLastCycleBoundaryLastMonth() throws Exception {
// assume cycle day of "20th", which should be in last month
final long currentTime = parseTime("2007-11-14T00:00:00.000Z");
@@ -425,6 +317,7 @@
assertTimeEquals(expectedCycle, actualCycle);
}
+ @Test
public void testLastCycleBoundaryThisMonthFebruary() throws Exception {
// assume cycle day of "30th" in february; should go to january
final long currentTime = parseTime("2007-02-14T00:00:00.000Z");
@@ -436,6 +329,7 @@
assertTimeEquals(expectedCycle, actualCycle);
}
+ @Test
public void testLastCycleBoundaryLastMonthFebruary() throws Exception {
// assume cycle day of "30th" in february, which should clamp
final long currentTime = parseTime("2007-03-14T00:00:00.000Z");
@@ -447,6 +341,7 @@
assertTimeEquals(expectedCycle, actualCycle);
}
+ @Test
public void testCycleBoundaryLeapYear() throws Exception {
final NetworkPolicy policy = new NetworkPolicy(
sTemplateWifi, 29, TIMEZONE_UTC, 1024L, 1024L, false);
@@ -470,6 +365,7 @@
computeNextCycleBoundary(parseTime("2007-03-14T00:00:00.000Z"), policy));
}
+ @Test
public void testNextCycleTimezoneAfterUtc() throws Exception {
// US/Central is UTC-6
final NetworkPolicy policy = new NetworkPolicy(
@@ -478,6 +374,7 @@
computeNextCycleBoundary(parseTime("2012-01-05T00:00:00.000Z"), policy));
}
+ @Test
public void testNextCycleTimezoneBeforeUtc() throws Exception {
// Israel is UTC+2
final NetworkPolicy policy = new NetworkPolicy(
@@ -486,6 +383,7 @@
computeNextCycleBoundary(parseTime("2012-01-05T00:00:00.000Z"), policy));
}
+ @Test
public void testNextCycleSane() throws Exception {
final NetworkPolicy policy = new NetworkPolicy(
sTemplateWifi, 31, TIMEZONE_UTC, WARNING_DISABLED, LIMIT_DISABLED, false);
@@ -501,6 +399,7 @@
}
}
+ @Test
public void testLastCycleSane() throws Exception {
final NetworkPolicy policy = new NetworkPolicy(
sTemplateWifi, 31, TIMEZONE_UTC, WARNING_DISABLED, LIMIT_DISABLED, false);
@@ -516,6 +415,7 @@
}
}
+ @Test
public void testCycleTodayJanuary() throws Exception {
final NetworkPolicy policy = new NetworkPolicy(
sTemplateWifi, 14, "US/Pacific", 1024L, 1024L, false);
@@ -535,6 +435,7 @@
computeLastCycleBoundary(parseTime("2013-01-14T15:11:00.000-08:00"), policy));
}
+ @Test
public void testLastCycleBoundaryDST() throws Exception {
final long currentTime = parseTime("1989-01-02T07:30:00.000");
final long expectedCycle = parseTime("1988-12-03T02:00:00.000Z");
@@ -545,11 +446,21 @@
assertTimeEquals(expectedCycle, actualCycle);
}
- @Suppress
+ @Test
+ public void testLastCycleBoundaryJanuaryDST() throws Exception {
+ final long currentTime = parseTime("1989-01-26T21:00:00.000Z");
+ final long expectedCycle = parseTime("1989-01-01T01:59:59.000Z");
+
+ final NetworkPolicy policy = new NetworkPolicy(
+ sTemplateWifi, 32, "America/Argentina/Buenos_Aires", 1024L, 1024L, false);
+ final long actualCycle = computeLastCycleBoundary(currentTime, policy);
+ assertTimeEquals(expectedCycle, actualCycle);
+ }
+
+ @Test
public void testNetworkPolicyAppliedCycleLastMonth() throws Exception {
NetworkState[] state = null;
NetworkStats stats = null;
- Future<Void> future;
final long TIME_FEB_15 = 1171497600000L;
final long TIME_MAR_10 = 1173484800000L;
@@ -560,75 +471,40 @@
// first, pretend that wifi network comes online. no policy active,
// which means we shouldn't push limit to interface.
state = new NetworkState[] { buildWifi() };
- expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
+ when(mConnManager.getAllNetworkState()).thenReturn(state);
expectCurrentTime();
- expectClearNotifications();
- expectAdvisePersistThreshold();
- future = expectMeteredIfacesChanged();
- replay();
+ mPolicyListener.expect().onMeteredIfacesChanged(any());
mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
- future.get();
- verifyAndReset();
+ mPolicyListener.waitAndVerify().onMeteredIfacesChanged(any());
// now change cycle to be on 15th, and test in early march, to verify we
// pick cycle day in previous month.
- expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
+ when(mConnManager.getAllNetworkState()).thenReturn(state);
expectCurrentTime();
// pretend that 512 bytes total have happened
stats = new NetworkStats(getElapsedRealtime(), 1)
.addIfaceValues(TEST_IFACE, 256L, 2L, 256L, 2L);
- expect(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, TIME_MAR_10))
- .andReturn(stats.getTotalBytes()).atLeastOnce();
- expectPolicyDataEnable(TYPE_WIFI, true);
+ when(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, TIME_MAR_10))
+ .thenReturn(stats.getTotalBytes());
- // TODO: consider making strongly ordered mock
- expectRemoveInterfaceQuota(TEST_IFACE);
- expectSetInterfaceQuota(TEST_IFACE, (2 * MB_IN_BYTES) - 512);
-
- expectClearNotifications();
- expectAdvisePersistThreshold();
- future = expectMeteredIfacesChanged(TEST_IFACE);
-
- replay();
+ mPolicyListener.expect().onMeteredIfacesChanged(any());
setNetworkPolicies(new NetworkPolicy(
sTemplateWifi, CYCLE_DAY, TIMEZONE_UTC, 1 * MB_IN_BYTES, 2 * MB_IN_BYTES, false));
- future.get();
- verifyAndReset();
+ mPolicyListener.waitAndVerify().onMeteredIfacesChanged(eq(new String[]{TEST_IFACE}));
+
+ // TODO: consider making strongly ordered mock
+ verifyPolicyDataEnable(TYPE_WIFI, true);
+ verifyRemoveInterfaceQuota(TEST_IFACE);
+ verifySetInterfaceQuota(TEST_IFACE, (2 * MB_IN_BYTES) - 512);
}
- @Suppress
- public void testUidRemovedPolicyCleared() throws Exception {
- Future<Void> future;
-
- // POLICY_REJECT should RULE_REJECT in background
- expectSetUidMeteredNetworkBlacklist(UID_A, true);
- expectSetUidForeground(UID_A, false);
- future = expectRulesChanged(UID_A, RULE_REJECT_METERED);
- replay();
- mService.setUidPolicy(APP_ID_A, POLICY_REJECT_METERED_BACKGROUND);
- future.get();
- verifyAndReset();
-
- // uninstall should clear RULE_REJECT
- expectSetUidMeteredNetworkBlacklist(UID_A, false);
- expectSetUidForeground(UID_A, false);
- future = expectRulesChanged(UID_A, RULE_ALLOW_ALL);
- replay();
- final Intent intent = new Intent(ACTION_UID_REMOVED);
- intent.putExtra(EXTRA_UID, UID_A);
- mServiceContext.sendBroadcast(intent);
- future.get();
- verifyAndReset();
- }
-
- @Suppress
+ @Test
public void testOverWarningLimitNotification() throws Exception {
NetworkState[] state = null;
NetworkStats stats = null;
- Future<Void> future;
- Future<String> tagFuture;
+ Future<String> tagFuture = null;
final long TIME_FEB_15 = 1171497600000L;
final long TIME_MAR_10 = 1173484800000L;
@@ -643,20 +519,15 @@
{
expectCurrentTime();
- expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
- expect(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis()))
- .andReturn(stats.getTotalBytes()).atLeastOnce();
- expectPolicyDataEnable(TYPE_WIFI, true);
+ when(mConnManager.getAllNetworkState()).thenReturn(state);
+ when(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15,
+ currentTimeMillis())).thenReturn(stats.getTotalBytes());
- expectClearNotifications();
- expectAdvisePersistThreshold();
- future = expectMeteredIfacesChanged();
-
- replay();
+ mPolicyListener.expect().onMeteredIfacesChanged(any());
setNetworkPolicies(new NetworkPolicy(sTemplateWifi, CYCLE_DAY, TIMEZONE_UTC, 1
* MB_IN_BYTES, 2 * MB_IN_BYTES, false));
- future.get();
- verifyAndReset();
+ mPolicyListener.waitAndVerify().onMeteredIfacesChanged(any());
+ verifyPolicyDataEnable(TYPE_WIFI, true);
}
// bring up wifi network
@@ -667,22 +538,17 @@
{
expectCurrentTime();
- expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
- expect(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis()))
- .andReturn(stats.getTotalBytes()).atLeastOnce();
- expectPolicyDataEnable(TYPE_WIFI, true);
+ when(mConnManager.getAllNetworkState()).thenReturn(state);
+ when(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15,
+ currentTimeMillis())).thenReturn(stats.getTotalBytes());
- expectRemoveInterfaceQuota(TEST_IFACE);
- expectSetInterfaceQuota(TEST_IFACE, 2 * MB_IN_BYTES);
-
- expectClearNotifications();
- expectAdvisePersistThreshold();
- future = expectMeteredIfacesChanged(TEST_IFACE);
-
- replay();
+ mPolicyListener.expect().onMeteredIfacesChanged(any());
mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
- future.get();
- verifyAndReset();
+ mPolicyListener.waitAndVerify().onMeteredIfacesChanged(eq(new String[]{TEST_IFACE}));
+
+ verifyPolicyDataEnable(TYPE_WIFI, true);
+ verifyRemoveInterfaceQuota(TEST_IFACE);
+ verifySetInterfaceQuota(TEST_IFACE, 2 * MB_IN_BYTES);
}
// go over warning, which should kick notification
@@ -692,18 +558,15 @@
{
expectCurrentTime();
- expect(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis()))
- .andReturn(stats.getTotalBytes()).atLeastOnce();
- expectPolicyDataEnable(TYPE_WIFI, true);
-
- expectForceUpdate();
- expectClearNotifications();
+ when(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15,
+ currentTimeMillis())).thenReturn(stats.getTotalBytes());
tagFuture = expectEnqueueNotification();
- replay();
mNetworkObserver.limitReached(null, TEST_IFACE);
+
assertNotificationType(TYPE_WARNING, tagFuture.get());
- verifyAndReset();
+ verifyPolicyDataEnable(TYPE_WIFI, true);
+
}
// go over limit, which should kick notification and dialog
@@ -713,18 +576,14 @@
{
expectCurrentTime();
- expect(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis()))
- .andReturn(stats.getTotalBytes()).atLeastOnce();
- expectPolicyDataEnable(TYPE_WIFI, false);
-
- expectForceUpdate();
- expectClearNotifications();
+ when(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15,
+ currentTimeMillis())).thenReturn(stats.getTotalBytes());
tagFuture = expectEnqueueNotification();
- replay();
mNetworkObserver.limitReached(null, TEST_IFACE);
+
assertNotificationType(TYPE_LIMIT, tagFuture.get());
- verifyAndReset();
+ verifyPolicyDataEnable(TYPE_WIFI, false);
}
// now snooze policy, which should remove quota
@@ -732,35 +591,28 @@
{
expectCurrentTime();
- expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
- expect(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis()))
- .andReturn(stats.getTotalBytes()).atLeastOnce();
- expectPolicyDataEnable(TYPE_WIFI, true);
-
- // snoozed interface still has high quota so background data is
- // still restricted.
- expectRemoveInterfaceQuota(TEST_IFACE);
- expectSetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);
- expectAdvisePersistThreshold();
- expectMeteredIfacesChanged(TEST_IFACE);
-
- future = expectClearNotifications();
+ when(mConnManager.getAllNetworkState()).thenReturn(state);
+ when(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15,
+ currentTimeMillis())).thenReturn(stats.getTotalBytes());
tagFuture = expectEnqueueNotification();
- replay();
+ mPolicyListener.expect().onMeteredIfacesChanged(any());
mService.snoozeLimit(sTemplateWifi);
+ mPolicyListener.waitAndVerify().onMeteredIfacesChanged(eq(new String[]{TEST_IFACE}));
+
assertNotificationType(TYPE_LIMIT_SNOOZED, tagFuture.get());
- future.get();
- verifyAndReset();
+ // snoozed interface still has high quota so background data is
+ // still restricted.
+ verifyRemoveInterfaceQuota(TEST_IFACE);
+ verifySetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);
+ verifyPolicyDataEnable(TYPE_WIFI, true);
}
}
- @Suppress
+ @Test
public void testMeteredNetworkWithoutLimit() throws Exception {
NetworkState[] state = null;
NetworkStats stats = null;
- Future<Void> future;
- Future<String> tagFuture;
final long TIME_FEB_15 = 1171497600000L;
final long TIME_MAR_10 = 1173484800000L;
@@ -775,24 +627,19 @@
{
expectCurrentTime();
- expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
- expect(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis()))
- .andReturn(stats.getTotalBytes()).atLeastOnce();
- expectPolicyDataEnable(TYPE_WIFI, true);
+ when(mConnManager.getAllNetworkState()).thenReturn(state);
+ when(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15,
+ currentTimeMillis())).thenReturn(stats.getTotalBytes());
- expectRemoveInterfaceQuota(TEST_IFACE);
- expectSetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);
-
- expectClearNotifications();
- expectAdvisePersistThreshold();
- future = expectMeteredIfacesChanged(TEST_IFACE);
-
- replay();
+ mPolicyListener.expect().onMeteredIfacesChanged(any());
setNetworkPolicies(new NetworkPolicy(
sTemplateWifi, CYCLE_DAY, TIMEZONE_UTC, WARNING_DISABLED, LIMIT_DISABLED,
true));
- future.get();
- verifyAndReset();
+ mPolicyListener.waitAndVerify().onMeteredIfacesChanged(eq(new String[]{TEST_IFACE}));
+
+ verifyPolicyDataEnable(TYPE_WIFI, true);
+ verifyRemoveInterfaceQuota(TEST_IFACE);
+ verifySetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);
}
}
@@ -815,87 +662,36 @@
}
private void expectCurrentTime() throws Exception {
- expect(mTime.forceRefresh()).andReturn(false).anyTimes();
- expect(mTime.hasCache()).andReturn(true).anyTimes();
- expect(mTime.currentTimeMillis()).andReturn(currentTimeMillis()).anyTimes();
- expect(mTime.getCacheAge()).andReturn(0L).anyTimes();
- expect(mTime.getCacheCertainty()).andReturn(0L).anyTimes();
- }
-
- private void expectForceUpdate() throws Exception {
- mStatsService.forceUpdate();
- expectLastCall().atLeastOnce();
- }
-
- private Future<Void> expectClearNotifications() throws Exception {
- final FutureAnswer future = new FutureAnswer();
- mNotifManager.cancelNotificationWithTag(
- isA(String.class), isA(String.class), anyInt(), anyInt());
- expectLastCall().andAnswer(future).anyTimes();
- return future;
+ when(mTime.forceRefresh()).thenReturn(false);
+ when(mTime.hasCache()).thenReturn(true);
+ when(mTime.currentTimeMillis()).thenReturn(currentTimeMillis());
+ when(mTime.getCacheAge()).thenReturn(0L);
+ when(mTime.getCacheCertainty()).thenReturn(0L);
}
private Future<String> expectEnqueueNotification() throws Exception {
- final FutureCapture<String> tag = new FutureCapture<String>();
- mNotifManager.enqueueNotificationWithTag(isA(String.class), isA(String.class),
- capture(tag.capture), anyInt(),
- isA(Notification.class), isA(int[].class), UserHandle.myUserId());
- return tag;
+ final FutureAnswer<String> futureAnswer = new FutureAnswer<String>(2);
+ doAnswer(futureAnswer).when(mNotifManager).enqueueNotificationWithTag(
+ anyString(), anyString(), anyString() /* capture here (index 2)*/,
+ anyInt(), isA(Notification.class), isA(int[].class), anyInt());
+ return futureAnswer;
}
- private void expectSetInterfaceQuota(String iface, long quotaBytes) throws Exception {
- mNetworkManager.setInterfaceQuota(iface, quotaBytes);
- expectLastCall().atLeastOnce();
+ private void verifySetInterfaceQuota(String iface, long quotaBytes) throws Exception {
+ verify(mNetworkManager, atLeastOnce()).setInterfaceQuota(iface, quotaBytes);
}
- private void expectRemoveInterfaceQuota(String iface) throws Exception {
- mNetworkManager.removeInterfaceQuota(iface);
- expectLastCall().atLeastOnce();
+ private void verifyRemoveInterfaceQuota(String iface) throws Exception {
+ verify(mNetworkManager, atLeastOnce()).removeInterfaceQuota(iface);
}
- private void expectSetInterfaceAlert(String iface, long alertBytes) throws Exception {
- mNetworkManager.setInterfaceAlert(iface, alertBytes);
- expectLastCall().atLeastOnce();
- }
-
- private void expectRemoveInterfaceAlert(String iface) throws Exception {
- mNetworkManager.removeInterfaceAlert(iface);
- expectLastCall().atLeastOnce();
- }
-
- private void expectSetUidMeteredNetworkBlacklist(int uid, boolean rejectOnQuotaInterfaces)
- throws Exception {
- mNetworkManager.setUidMeteredNetworkBlacklist(uid, rejectOnQuotaInterfaces);
- expectLastCall().atLeastOnce();
- }
-
- private void expectSetUidForeground(int uid, boolean uidForeground) throws Exception {
- mStatsService.setUidForeground(uid, uidForeground);
- expectLastCall().atLeastOnce();
- }
-
- private Future<Void> expectRulesChanged(int uid, int policy) throws Exception {
- final FutureAnswer future = new FutureAnswer();
- mPolicyListener.onUidRulesChanged(eq(uid), eq(policy));
- expectLastCall().andAnswer(future);
- return future;
- }
-
- private Future<Void> expectMeteredIfacesChanged(String... ifaces) throws Exception {
- final FutureAnswer future = new FutureAnswer();
- mPolicyListener.onMeteredIfacesChanged(aryEq(ifaces));
- expectLastCall().andAnswer(future);
- return future;
- }
-
- private Future<Void> expectPolicyDataEnable(int type, boolean enabled) throws Exception {
+ private Future<Void> verifyPolicyDataEnable(int type, boolean enabled) throws Exception {
// TODO: bring back this test
return null;
}
- private void expectAdvisePersistThreshold() throws Exception {
- mStatsService.advisePersistThreshold(anyLong());
- expectLastCall().anyTimes();
+ private void verifyAdvisePersistThreshold() throws Exception {
+ verify(mStatsService).advisePersistThreshold(anyLong());
}
private static class TestAbstractFuture<T> extends AbstractFuture<T> {
@@ -909,50 +705,21 @@
}
}
- private static class FutureAnswer extends TestAbstractFuture<Void> implements IAnswer<Void> {
+ private static class FutureAnswer<T> extends TestAbstractFuture<T> implements Answer<Void> {
+ private final int index;
+
+ FutureAnswer(int index) {
+ this.index = index;
+ }
@Override
- public Void answer() {
- set(null);
+ public Void answer(InvocationOnMock invocation) throws Throwable {
+ @SuppressWarnings("unchecked")
+ T captured = (T) invocation.getArguments()[index];
+ set(captured);
return null;
}
}
- private static class FutureCapture<T> extends TestAbstractFuture<T> {
- public Capture<T> capture = new Capture<T>() {
- @Override
- public void setValue(T value) {
- super.setValue(value);
- set(value);
- }
- };
- }
-
- private static class IdleFuture extends AbstractFuture<Void> implements IdleHandler {
- @Override
- public Void get() throws InterruptedException, ExecutionException {
- try {
- return get(5, TimeUnit.SECONDS);
- } catch (TimeoutException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public boolean queueIdle() {
- set(null);
- return false;
- }
- }
-
- /**
- * Wait until {@link #mService} internal {@link Handler} is idle.
- */
- private IdleFuture expectIdle() {
- final IdleFuture future = new IdleFuture();
- mService.addIdleHandler(future);
- return future;
- }
-
private static void assertTimeEquals(long expected, long actual) {
if (expected != actual) {
fail("expected " + formatTime(expected) + " but was actually " + formatTime(actual));
@@ -980,7 +747,7 @@
}
private static void assertNotificationType(int expected, String actualTag) {
- assertEquals(
+ assertEquals("notification type mismatch for '" + actualTag +"'",
Integer.toString(expected), actualTag.substring(actualTag.lastIndexOf(':') + 1));
}
@@ -1001,15 +768,59 @@
mElapsedRealtime += duration;
}
- private void replay() {
- EasyMock.replay(mActivityManager, mStatsService, mPolicyListener, mNetworkManager, mTime,
- mConnManager, mNotifManager);
+ /**
+ * Creates a mock and registers it to {@link LocalServices}.
+ */
+ private static <T> T addLocalServiceMock(Class<T> clazz) {
+ final T mock = mock(clazz);
+ LocalServices.addService(clazz, mock);
+ return mock;
}
- private void verifyAndReset() {
- EasyMock.verify(mActivityManager, mStatsService, mPolicyListener, mNetworkManager, mTime,
- mConnManager, mNotifManager);
- EasyMock.reset(mActivityManager, mStatsService, mPolicyListener, mNetworkManager, mTime,
- mConnManager, mNotifManager);
+ /**
+ * Custom Mockito answer used to verify async {@link INetworkPolicyListener} calls.
+ *
+ * <p>Typical usage:
+ * <pre><code>
+ * mPolicyListener.expect().someCallback(any());
+ * // do something on objects under test
+ * mPolicyListener.waitAndVerify().someCallback(eq(expectedValue));
+ * </code></pre>
+ */
+ final class NetworkPolicyListenerAnswer implements Answer<Void> {
+ private CountDownLatch latch;
+ private final INetworkPolicyListener listener;
+
+ NetworkPolicyListenerAnswer(NetworkPolicyManagerService service) {
+ this.listener = mock(INetworkPolicyListener.class);
+ // RemoteCallbackList needs a binder to use as key
+ when(listener.asBinder()).thenReturn(new Binder());
+ service.registerListener(listener);
+ }
+
+ @Override
+ public Void answer(InvocationOnMock invocation) throws Throwable {
+ Log.d(TAG,"counting down on answer: " + invocation);
+ latch.countDown();
+ return null;
+ }
+
+ INetworkPolicyListener expect() {
+ assertNull("expect() called before waitAndVerify()", latch);
+ latch = new CountDownLatch(1);
+ return doAnswer(this).when(listener);
+ }
+
+ INetworkPolicyListener waitAndVerify() {
+ assertNotNull("waitAndVerify() called before expect()", latch);
+ try {
+ assertTrue("callback not called in 5 seconds", latch.await(5, TimeUnit.SECONDS));
+ } catch (InterruptedException e) {
+ fail("Thread interrupted before callback called");
+ } finally {
+ latch = null;
+ }
+ return verify(listener, atLeastOnce());
+ }
}
}
diff --git a/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java
index 0139671..69d27f2 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java
@@ -16,8 +16,13 @@
package com.android.server;
+import static android.net.NetworkRecommendationProvider.EXTRA_RECOMMENDATION_RESULT;
+import static android.net.NetworkRecommendationProvider.EXTRA_SEQUENCE;
+import static android.net.NetworkScoreManager.CACHE_FILTER_NONE;
+
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
@@ -26,11 +31,15 @@
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isA;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import android.Manifest.permission;
@@ -41,29 +50,28 @@
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.res.Resources;
+import android.net.INetworkRecommendationProvider;
import android.net.INetworkScoreCache;
import android.net.NetworkKey;
-import android.net.NetworkScoreManager;
import android.net.NetworkScorerAppManager;
import android.net.NetworkScorerAppManager.NetworkScorerAppData;
+import android.net.RecommendationRequest;
+import android.net.RecommendationResult;
import android.net.ScoredNetwork;
import android.net.WifiKey;
+import android.net.wifi.WifiConfiguration;
+import android.os.Bundle;
import android.os.IBinder;
+import android.os.IRemoteCallback;
+import android.os.Looper;
import android.os.RemoteException;
import android.os.UserHandle;
-import android.provider.Settings;
-import android.provider.Settings.Global;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.support.test.runner.AndroidJUnit4;
-import com.android.internal.R;
import com.android.server.devicepolicy.MockUtils;
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -71,6 +79,13 @@
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.List;
/**
* Tests for {@link NetworkScoreService}.
@@ -81,12 +96,8 @@
private static final ScoredNetwork SCORED_NETWORK =
new ScoredNetwork(new NetworkKey(new WifiKey("\"ssid\"", "00:00:00:00:00:00")),
null /* rssiCurve*/);
- private static final NetworkScorerAppData PREV_SCORER = new NetworkScorerAppData(
- "prevPackageName", 0, "prevScorerName", null /* configurationActivityClassName */,
- "prevScoringServiceClass");
- private static final NetworkScorerAppData NEW_SCORER = new NetworkScorerAppData(
- "newPackageName", 1, "newScorerName", null /* configurationActivityClassName */,
- "newScoringServiceClass");
+ private static final NetworkScorerAppData NEW_SCORER =
+ new NetworkScorerAppData("newPackageName", 1, "newScoringServiceClass");
@Mock private PackageManager mPackageManager;
@Mock private NetworkScorerAppManager mNetworkScorerAppManager;
@@ -94,10 +105,12 @@
@Mock private Resources mResources;
@Mock private INetworkScoreCache.Stub mNetworkScoreCache, mNetworkScoreCache2;
@Mock private IBinder mIBinder, mIBinder2;
+ @Mock private INetworkRecommendationProvider mRecommendationProvider;
@Captor private ArgumentCaptor<List<ScoredNetwork>> mScoredNetworkCaptor;
private ContentResolver mContentResolver;
private NetworkScoreService mNetworkScoreService;
+ private RecommendationRequest mRecommendationRequest;
@Before
public void setUp() throws Exception {
@@ -108,44 +121,11 @@
when(mContext.getContentResolver()).thenReturn(mContentResolver);
when(mContext.getResources()).thenReturn(mResources);
mNetworkScoreService = new NetworkScoreService(mContext, mNetworkScorerAppManager);
- }
-
- @Test
- public void testSystemReady_networkScorerProvisioned() throws Exception {
- Settings.Global.putInt(mContentResolver, Global.NETWORK_SCORING_PROVISIONED, 1);
-
- mNetworkScoreService.systemReady();
-
- verify(mNetworkScorerAppManager, never()).setActiveScorer(anyString());
- }
-
- @Test
- public void testSystemReady_networkScorerNotProvisioned_defaultScorer() throws Exception {
- Settings.Global.putInt(mContentResolver, Global.NETWORK_SCORING_PROVISIONED, 0);
-
- when(mResources.getString(R.string.config_defaultNetworkScorerPackageName))
- .thenReturn(NEW_SCORER.mPackageName);
-
- mNetworkScoreService.systemReady();
-
- verify(mNetworkScorerAppManager).setActiveScorer(NEW_SCORER.mPackageName);
- assertEquals(1,
- Settings.Global.getInt(mContentResolver, Global.NETWORK_SCORING_PROVISIONED));
-
- }
-
- @Test
- public void testSystemReady_networkScorerNotProvisioned_noDefaultScorer() throws Exception {
- Settings.Global.putInt(mContentResolver, Global.NETWORK_SCORING_PROVISIONED, 0);
-
- when(mResources.getString(R.string.config_defaultNetworkScorerPackageName))
- .thenReturn(null);
-
- mNetworkScoreService.systemReady();
-
- verify(mNetworkScorerAppManager, never()).setActiveScorer(anyString());
- assertEquals(1,
- Settings.Global.getInt(mContentResolver, Global.NETWORK_SCORING_PROVISIONED));
+ WifiConfiguration configuration = new WifiConfiguration();
+ configuration.SSID = "NetworkScoreServiceTest_SSID";
+ configuration.BSSID = "NetworkScoreServiceTest_BSSID";
+ mRecommendationRequest = new RecommendationRequest.Builder()
+ .setCurrentRecommendedWifiConfig(configuration).build();
}
@Test
@@ -155,13 +135,129 @@
mNetworkScoreService.systemRunning();
verify(mContext).bindServiceAsUser(MockUtils.checkIntent(new Intent().setComponent(
- new ComponentName(NEW_SCORER.mPackageName, NEW_SCORER.mScoringServiceClassName))),
+ new ComponentName(NEW_SCORER.packageName,
+ NEW_SCORER.recommendationServiceClassName))),
any(ServiceConnection.class),
eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE),
eq(UserHandle.SYSTEM));
}
@Test
+ public void testRequestScores_noPermission() throws Exception {
+ doThrow(new SecurityException()).when(mContext)
+ .enforceCallingOrSelfPermission(eq(permission.BROADCAST_NETWORK_PRIVILEGED),
+ anyString());
+ try {
+ mNetworkScoreService.requestScores(null);
+ fail("BROADCAST_NETWORK_PRIVILEGED not enforced.");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testRequestScores_providerNotConnected() throws Exception {
+ assertFalse(mNetworkScoreService.requestScores(new NetworkKey[0]));
+ verifyZeroInteractions(mRecommendationProvider);
+ }
+
+ @Test
+ public void testRequestScores_providerThrowsRemoteException() throws Exception {
+ injectProvider();
+ doThrow(new RemoteException()).when(mRecommendationProvider)
+ .requestScores(any(NetworkKey[].class));
+
+ assertFalse(mNetworkScoreService.requestScores(new NetworkKey[0]));
+ }
+
+ @Test
+ public void testRequestScores_providerAvailable() throws Exception {
+ injectProvider();
+
+ final NetworkKey[] networks = new NetworkKey[0];
+ assertTrue(mNetworkScoreService.requestScores(networks));
+ verify(mRecommendationProvider).requestScores(networks);
+ }
+
+ @Test
+ public void testRequestRecommendation_noPermission() throws Exception {
+ doThrow(new SecurityException()).when(mContext)
+ .enforceCallingOrSelfPermission(eq(permission.BROADCAST_NETWORK_PRIVILEGED),
+ anyString());
+ try {
+ mNetworkScoreService.requestRecommendation(mRecommendationRequest);
+ fail("BROADCAST_NETWORK_PRIVILEGED not enforced.");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testRequestRecommendation_mainThread() throws Exception {
+ when(mContext.getMainLooper()).thenReturn(Looper.myLooper());
+ try {
+ mNetworkScoreService.requestRecommendation(mRecommendationRequest);
+ fail("requestRecommendation run on main thread.");
+ } catch (RuntimeException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testRequestRecommendation_providerNotConnected() throws Exception {
+ when(mContext.getMainLooper()).thenReturn(Looper.getMainLooper());
+
+ final RecommendationResult result =
+ mNetworkScoreService.requestRecommendation(mRecommendationRequest);
+ assertNotNull(result);
+ assertEquals(mRecommendationRequest.getCurrentSelectedConfig(),
+ result.getWifiConfiguration());
+ }
+
+ @Test
+ public void testRequestRecommendation_providerThrowsRemoteException() throws Exception {
+ injectProvider();
+ when(mContext.getMainLooper()).thenReturn(Looper.getMainLooper());
+ doThrow(new RemoteException()).when(mRecommendationProvider)
+ .requestRecommendation(eq(mRecommendationRequest), isA(IRemoteCallback.class),
+ anyInt());
+
+ final RecommendationResult result =
+ mNetworkScoreService.requestRecommendation(mRecommendationRequest);
+ assertNotNull(result);
+ assertEquals(mRecommendationRequest.getCurrentSelectedConfig(),
+ result.getWifiConfiguration());
+ }
+
+ @Test
+ public void testRequestRecommendation_resultReturned() throws Exception {
+ injectProvider();
+ when(mContext.getMainLooper()).thenReturn(Looper.getMainLooper());
+ final WifiConfiguration wifiConfiguration = new WifiConfiguration();
+ wifiConfiguration.SSID = "testRequestRecommendation_resultReturned_SSID";
+ wifiConfiguration.BSSID = "testRequestRecommendation_resultReturned_BSSID";
+ final RecommendationResult providerResult = RecommendationResult
+ .createConnectRecommendation(wifiConfiguration);
+ final Bundle bundle = new Bundle();
+ bundle.putParcelable(EXTRA_RECOMMENDATION_RESULT, providerResult);
+ doAnswer(invocation -> {
+ bundle.putInt(EXTRA_SEQUENCE, invocation.getArgumentAt(2, int.class));
+ invocation.getArgumentAt(1, IRemoteCallback.class).sendResult(bundle);
+ return null;
+ }).when(mRecommendationProvider)
+ .requestRecommendation(eq(mRecommendationRequest), isA(IRemoteCallback.class),
+ anyInt());
+
+ final RecommendationResult result =
+ mNetworkScoreService.requestRecommendation(mRecommendationRequest);
+ assertNotNull(result);
+ assertEquals(providerResult.getWifiConfiguration().SSID,
+ result.getWifiConfiguration().SSID);
+ assertEquals(providerResult.getWifiConfiguration().BSSID,
+ result.getWifiConfiguration().BSSID);
+ }
+
+ @Test
public void testUpdateScores_notActiveScorer() {
when(mNetworkScorerAppManager.isCallerActiveScorer(anyInt())).thenReturn(false);
@@ -177,7 +273,8 @@
public void testUpdateScores_oneRegisteredCache() throws RemoteException {
when(mNetworkScorerAppManager.isCallerActiveScorer(anyInt())).thenReturn(true);
- mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, mNetworkScoreCache);
+ mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI,
+ mNetworkScoreCache, CACHE_FILTER_NONE);
mNetworkScoreService.updateScores(new ScoredNetwork[]{SCORED_NETWORK});
@@ -191,9 +288,10 @@
public void testUpdateScores_twoRegisteredCaches() throws RemoteException {
when(mNetworkScorerAppManager.isCallerActiveScorer(anyInt())).thenReturn(true);
- mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, mNetworkScoreCache);
+ mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI,
+ mNetworkScoreCache, CACHE_FILTER_NONE);
mNetworkScoreService.registerNetworkScoreCache(
- NetworkKey.TYPE_WIFI, mNetworkScoreCache2);
+ NetworkKey.TYPE_WIFI, mNetworkScoreCache2, CACHE_FILTER_NONE);
// updateScores should update both caches
mNetworkScoreService.updateScores(new ScoredNetwork[]{SCORED_NETWORK});
@@ -215,6 +313,9 @@
// updateScores should not update any caches since they are both unregistered
mNetworkScoreService.updateScores(new ScoredNetwork[]{SCORED_NETWORK});
+ // The register and unregister calls grab the binder from the score cache.
+ verify(mNetworkScoreCache, atLeastOnce()).asBinder();
+ verify(mNetworkScoreCache2, atLeastOnce()).asBinder();
verifyNoMoreInteractions(mNetworkScoreCache, mNetworkScoreCache2);
}
@@ -244,7 +345,8 @@
public void testClearScores_activeScorer() throws RemoteException {
when(mNetworkScorerAppManager.isCallerActiveScorer(anyInt())).thenReturn(true);
- mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, mNetworkScoreCache);
+ mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, mNetworkScoreCache,
+ CACHE_FILTER_NONE);
mNetworkScoreService.clearScores();
verify(mNetworkScoreCache).clearScores();
@@ -257,7 +359,8 @@
when(mContext.checkCallingOrSelfPermission(permission.BROADCAST_NETWORK_PRIVILEGED))
.thenReturn(PackageManager.PERMISSION_GRANTED);
- mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, mNetworkScoreCache);
+ mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, mNetworkScoreCache,
+ CACHE_FILTER_NONE);
mNetworkScoreService.clearScores();
verify(mNetworkScoreCache).clearScores();
@@ -277,43 +380,6 @@
}
@Test
- public void testSetActiveScorer_failure() throws RemoteException {
- when(mNetworkScorerAppManager.getActiveScorer()).thenReturn(PREV_SCORER);
- when(mNetworkScorerAppManager.setActiveScorer(NEW_SCORER.mPackageName)).thenReturn(false);
- mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, mNetworkScoreCache);
-
- boolean success = mNetworkScoreService.setActiveScorer(NEW_SCORER.mPackageName);
-
- assertFalse(success);
- verify(mNetworkScoreCache).clearScores();
- verify(mContext).bindServiceAsUser(MockUtils.checkIntent(new Intent().setComponent(
- new ComponentName(PREV_SCORER.mPackageName, PREV_SCORER.mScoringServiceClassName))),
- any(ServiceConnection.class),
- eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE),
- eq(UserHandle.SYSTEM));
- }
-
- @Test
- public void testSetActiveScorer_success() throws RemoteException {
- when(mNetworkScorerAppManager.getActiveScorer()).thenReturn(PREV_SCORER, NEW_SCORER);
- when(mNetworkScorerAppManager.setActiveScorer(NEW_SCORER.mPackageName)).thenReturn(true);
- mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, mNetworkScoreCache);
-
- boolean success = mNetworkScoreService.setActiveScorer(NEW_SCORER.mPackageName);
-
- assertTrue(success);
- verify(mNetworkScoreCache).clearScores();
- verify(mContext).bindServiceAsUser(MockUtils.checkIntent(new Intent().setComponent(
- new ComponentName(NEW_SCORER.mPackageName, NEW_SCORER.mScoringServiceClassName))),
- any(ServiceConnection.class),
- eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE),
- eq(UserHandle.SYSTEM));
- verify(mContext, times(2)).sendBroadcastAsUser(
- MockUtils.checkIntentAction(NetworkScoreManager.ACTION_SCORER_CHANGED),
- eq(UserHandle.SYSTEM));
- }
-
- @Test
public void testDisableScoring_notActiveScorer_noBroadcastNetworkPermission() {
when(mNetworkScorerAppManager.isCallerActiveScorer(anyInt())).thenReturn(false);
when(mContext.checkCallingOrSelfPermission(permission.BROADCAST_NETWORK_PRIVILEGED))
@@ -325,46 +391,6 @@
} catch (SecurityException e) {
// expected
}
-
- }
-
- @Test
- public void testDisableScoring_activeScorer() throws RemoteException {
- when(mNetworkScorerAppManager.isCallerActiveScorer(anyInt())).thenReturn(true);
- when(mNetworkScorerAppManager.getActiveScorer()).thenReturn(PREV_SCORER, null);
- when(mNetworkScorerAppManager.setActiveScorer(null)).thenReturn(true);
- mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, mNetworkScoreCache);
-
- mNetworkScoreService.disableScoring();
-
- verify(mNetworkScoreCache).clearScores();
- verify(mContext).sendBroadcastAsUser(
- MockUtils.checkIntent(new Intent(NetworkScoreManager.ACTION_SCORER_CHANGED)
- .setPackage(PREV_SCORER.mPackageName)),
- eq(UserHandle.SYSTEM));
- verify(mContext, never()).bindServiceAsUser(any(Intent.class),
- any(ServiceConnection.class), anyInt(), any(UserHandle.class));
- }
-
- @Test
- public void testDisableScoring_notActiveScorer_hasBroadcastNetworkPermission()
- throws RemoteException {
- when(mNetworkScorerAppManager.isCallerActiveScorer(anyInt())).thenReturn(false);
- when(mContext.checkCallingOrSelfPermission(permission.BROADCAST_NETWORK_PRIVILEGED))
- .thenReturn(PackageManager.PERMISSION_GRANTED);
- when(mNetworkScorerAppManager.getActiveScorer()).thenReturn(PREV_SCORER, null);
- when(mNetworkScorerAppManager.setActiveScorer(null)).thenReturn(true);
- mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, mNetworkScoreCache);
-
- mNetworkScoreService.disableScoring();
-
- verify(mNetworkScoreCache).clearScores();
- verify(mContext).sendBroadcastAsUser(
- MockUtils.checkIntent(new Intent(NetworkScoreManager.ACTION_SCORER_CHANGED)
- .setPackage(PREV_SCORER.mPackageName)),
- eq(UserHandle.SYSTEM));
- verify(mContext, never()).bindServiceAsUser(any(Intent.class),
- any(ServiceConnection.class), anyInt(), any(UserHandle.class));
}
@Test
@@ -374,7 +400,7 @@
try {
mNetworkScoreService.registerNetworkScoreCache(
- NetworkKey.TYPE_WIFI, mNetworkScoreCache);
+ NetworkKey.TYPE_WIFI, mNetworkScoreCache, CACHE_FILTER_NONE);
fail("SecurityException expected");
} catch (SecurityException e) {
// expected
@@ -419,4 +445,24 @@
assertFalse(stringWriter.toString().isEmpty());
}
+
+ // "injects" the mock INetworkRecommendationProvider into the NetworkScoreService.
+ private void injectProvider() {
+ final ComponentName componentName = new ComponentName(NEW_SCORER.packageName,
+ NEW_SCORER.recommendationServiceClassName);
+ when(mNetworkScorerAppManager.getActiveScorer()).thenReturn(NEW_SCORER);
+ when(mContext.bindServiceAsUser(isA(Intent.class), isA(ServiceConnection.class), anyInt(),
+ isA(UserHandle.class))).thenAnswer(new Answer<Boolean>() {
+ @Override
+ public Boolean answer(InvocationOnMock invocation) throws Throwable {
+ IBinder mockBinder = mock(IBinder.class);
+ when(mockBinder.queryLocalInterface(anyString()))
+ .thenReturn(mRecommendationProvider);
+ invocation.getArgumentAt(1, ServiceConnection.class)
+ .onServiceConnected(componentName, mockBinder);
+ return true;
+ }
+ });
+ mNetworkScoreService.systemRunning();
+ }
}
diff --git a/services/tests/servicestests/src/com/android/server/net/NetworkStatsObserversTest.java b/services/tests/servicestests/src/com/android/server/net/NetworkStatsObserversTest.java
index 21560ac..5eee7b9 100644
--- a/services/tests/servicestests/src/com/android/server/net/NetworkStatsObserversTest.java
+++ b/services/tests/servicestests/src/com/android/server/net/NetworkStatsObserversTest.java
@@ -25,6 +25,7 @@
import static org.mockito.Mockito.when;
import static android.net.NetworkStats.SET_DEFAULT;
+import static android.net.NetworkStats.METERED_NO;
import static android.net.NetworkStats.ROAMING_NO;
import static android.net.NetworkStats.TAG_NONE;
import static android.net.NetworkTemplate.buildTemplateMobileAll;
@@ -336,7 +337,7 @@
// Baseline
NetworkStats xtSnapshot = null;
NetworkStats uidSnapshot = new NetworkStats(TEST_START, 2 /* initialSize */)
- .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_NO,
+ .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
BASE_BYTES, 2L, BASE_BYTES, 2L, 0L);
mStatsObservers.updateStats(
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
@@ -344,7 +345,7 @@
// Delta
uidSnapshot = new NetworkStats(TEST_START + 2 * MINUTE_IN_MILLIS, 2 /* initialSize */)
- .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_NO,
+ .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
BASE_BYTES + THRESHOLD_BYTES, 2L, BASE_BYTES + THRESHOLD_BYTES, 2L, 0L);
mStatsObservers.updateStats(
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
@@ -374,7 +375,7 @@
// Baseline
NetworkStats xtSnapshot = null;
NetworkStats uidSnapshot = new NetworkStats(TEST_START, 2 /* initialSize */)
- .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_NO,
+ .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
BASE_BYTES, 2L, BASE_BYTES, 2L, 0L);
mStatsObservers.updateStats(
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
@@ -382,7 +383,7 @@
// Delta
uidSnapshot = new NetworkStats(TEST_START + 2 * MINUTE_IN_MILLIS, 2 /* initialSize */)
- .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_NO,
+ .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
BASE_BYTES + THRESHOLD_BYTES, 2L, BASE_BYTES + THRESHOLD_BYTES, 2L, 0L);
mStatsObservers.updateStats(
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
@@ -412,7 +413,7 @@
// Baseline
NetworkStats xtSnapshot = null;
NetworkStats uidSnapshot = new NetworkStats(TEST_START, 2 /* initialSize */)
- .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_NO,
+ .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
BASE_BYTES, 2L, BASE_BYTES, 2L, 0L);
mStatsObservers.updateStats(
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
@@ -420,7 +421,7 @@
// Delta
uidSnapshot = new NetworkStats(TEST_START + 2 * MINUTE_IN_MILLIS, 2 /* initialSize */)
- .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_NO,
+ .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
BASE_BYTES + THRESHOLD_BYTES, 2L, BASE_BYTES + THRESHOLD_BYTES, 2L, 0L);
mStatsObservers.updateStats(
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
@@ -450,16 +451,17 @@
// Baseline
NetworkStats xtSnapshot = null;
NetworkStats uidSnapshot = new NetworkStats(TEST_START, 2 /* initialSize */)
- .addValues(TEST_IFACE, UID_ANOTHER_USER, SET_DEFAULT, TAG_NONE, ROAMING_NO,
- BASE_BYTES, 2L, BASE_BYTES, 2L, 0L);
+ .addValues(TEST_IFACE, UID_ANOTHER_USER, SET_DEFAULT, TAG_NONE, METERED_NO,
+ ROAMING_NO, BASE_BYTES, 2L, BASE_BYTES, 2L, 0L);
mStatsObservers.updateStats(
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
VPN_INFO, TEST_START);
// Delta
uidSnapshot = new NetworkStats(TEST_START + 2 * MINUTE_IN_MILLIS, 2 /* initialSize */)
- .addValues(TEST_IFACE, UID_ANOTHER_USER, SET_DEFAULT, TAG_NONE, ROAMING_NO,
- BASE_BYTES + THRESHOLD_BYTES, 2L, BASE_BYTES + THRESHOLD_BYTES, 2L, 0L);
+ .addValues(TEST_IFACE, UID_ANOTHER_USER, SET_DEFAULT, TAG_NONE, METERED_NO,
+ ROAMING_NO, BASE_BYTES + THRESHOLD_BYTES, 2L, BASE_BYTES + THRESHOLD_BYTES,
+ 2L, 0L);
mStatsObservers.updateStats(
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
VPN_INFO, TEST_START);
diff --git a/services/tests/servicestests/src/com/android/server/net/NetworkStatsServiceTest.java b/services/tests/servicestests/src/com/android/server/net/NetworkStatsServiceTest.java
index 4b69eb3..728eb73 100644
--- a/services/tests/servicestests/src/com/android/server/net/NetworkStatsServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/net/NetworkStatsServiceTest.java
@@ -22,6 +22,9 @@
import static android.net.ConnectivityManager.TYPE_WIFI;
import static android.net.ConnectivityManager.TYPE_WIMAX;
import static android.net.NetworkStats.IFACE_ALL;
+import static android.net.NetworkStats.METERED_ALL;
+import static android.net.NetworkStats.METERED_NO;
+import static android.net.NetworkStats.METERED_YES;
import static android.net.NetworkStats.ROAMING_ALL;
import static android.net.NetworkStats.ROAMING_NO;
import static android.net.NetworkStats.ROAMING_YES;
@@ -40,21 +43,21 @@
import static android.text.format.DateUtils.HOUR_IN_MILLIS;
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
import static android.text.format.DateUtils.WEEK_IN_MILLIS;
+
import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_POLL;
-import static org.easymock.EasyMock.anyInt;
-import static org.easymock.EasyMock.anyLong;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.isA;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
import android.app.AlarmManager;
-import android.app.IAlarmListener;
-import android.app.IAlarmManager;
-import android.app.PendingIntent;
import android.app.usage.NetworkStatsManager;
import android.content.Context;
import android.content.Intent;
@@ -63,6 +66,7 @@
import android.net.INetworkManagementEventObserver;
import android.net.INetworkStatsSession;
import android.net.LinkProperties;
+import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkInfo.DetailedState;
import android.net.NetworkState;
@@ -80,11 +84,10 @@
import android.os.MessageQueue.IdleHandler;
import android.os.Message;
import android.os.PowerManager;
-import android.os.WorkSource;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
import android.telephony.TelephonyManager;
import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.test.suitebuilder.annotation.Suppress;
import android.util.TrustedTime;
import com.android.internal.net.VpnInfo;
@@ -95,8 +98,14 @@
import libcore.io.IoUtils;
-import org.easymock.Capture;
-import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import java.io.File;
import java.util.ArrayList;
@@ -106,11 +115,11 @@
/**
* Tests for {@link NetworkStatsService}.
*
- * TODO: This test is really brittle, largely due to overly-strict use of Easymock.
- * Rewrite w/ Mockito.
+ * TODO: This test used to be really brittle because it used Easymock - it uses Mockito now, but
+ * still uses the Easymock structure, which could be simplified.
*/
-@LargeTest
-public class NetworkStatsServiceTest extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+public class NetworkStatsServiceTest {
private static final String TAG = "NetworkStatsServiceTest";
private static final String TEST_IFACE = "test0";
@@ -137,10 +146,12 @@
private BroadcastInterceptingContext mServiceContext;
private File mStatsDir;
- private INetworkManagementService mNetManager;
- private TrustedTime mTime;
- private NetworkStatsSettings mSettings;
- private IConnectivityManager mConnManager;
+ private @Mock INetworkManagementService mNetManager;
+ private @Mock TrustedTime mTime;
+ private @Mock NetworkStatsSettings mSettings;
+ private @Mock IConnectivityManager mConnManager;
+ private @Mock IBinder mBinder;
+ private @Mock AlarmManager mAlarmManager;
private IdleableHandlerThread mHandlerThread;
private Handler mHandler;
@@ -148,32 +159,24 @@
private INetworkStatsSession mSession;
private INetworkManagementEventObserver mNetworkObserver;
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
+ MockitoAnnotations.initMocks(this);
+ final Context context = InstrumentationRegistry.getContext();
- mServiceContext = new BroadcastInterceptingContext(getContext());
- mStatsDir = getContext().getFilesDir();
+ mServiceContext = new BroadcastInterceptingContext(context);
+ mStatsDir = context.getFilesDir();
if (mStatsDir.exists()) {
IoUtils.deleteContents(mStatsDir);
}
- mNetManager = createMock(INetworkManagementService.class);
-
- // TODO: Mock AlarmManager when migrating this test to Mockito.
- AlarmManager alarmManager = (AlarmManager) mServiceContext
- .getSystemService(Context.ALARM_SERVICE);
- mTime = createMock(TrustedTime.class);
- mSettings = createMock(NetworkStatsSettings.class);
- mConnManager = createMock(IConnectivityManager.class);
-
PowerManager powerManager = (PowerManager) mServiceContext.getSystemService(
Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock =
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
mService = new NetworkStatsService(
- mServiceContext, mNetManager, alarmManager, wakeLock, mTime,
+ mServiceContext, mNetManager, mAlarmManager, wakeLock, mTime,
TelephonyManager.getDefault(), mSettings, new NetworkStatsObservers(),
mStatsDir, getBaseDir(mStatsDir));
mHandlerThread = new IdleableHandlerThread("HandlerThread");
@@ -190,22 +193,20 @@
expectNetworkStatsUidDetail(buildEmptyStats());
expectSystemReady();
- // catch INetworkManagementEventObserver during systemReady()
- final Capture<INetworkManagementEventObserver> networkObserver = new Capture<
- INetworkManagementEventObserver>();
- mNetManager.registerObserver(capture(networkObserver));
- expectLastCall().atLeastOnce();
-
- replay();
mService.systemReady();
mSession = mService.openSession();
- verifyAndReset();
+ assertNotNull("openSession() failed", mSession);
+
+ // catch INetworkManagementEventObserver during systemReady()
+ ArgumentCaptor<INetworkManagementEventObserver> networkObserver =
+ ArgumentCaptor.forClass(INetworkManagementEventObserver.class);
+ verify(mNetManager).registerObserver(networkObserver.capture());
mNetworkObserver = networkObserver.getValue();
}
- @Override
+ @After
public void tearDown() throws Exception {
IoUtils.deleteContents(mStatsDir);
@@ -219,10 +220,9 @@
mSession.close();
mService = null;
-
- super.tearDown();
}
+ @Test
public void testNetworkStatsWifi() throws Exception {
// pretend that wifi network comes online; service should ask about full
// network state, and poll any existing interfaces before updating.
@@ -231,15 +231,13 @@
expectNetworkState(buildWifiState());
expectNetworkStatsSummary(buildEmptyStats());
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
expectBandwidthControlCheck();
- replay();
mService.forceUpdateIfaces();
// verify service has empty history for wifi
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
- verifyAndReset();
+
// modify some number on wifi, and trigger poll event
incrementCurrentTime(HOUR_IN_MILLIS);
@@ -248,14 +246,11 @@
expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1)
.addIfaceValues(TEST_IFACE, 1024L, 1L, 2048L, 2L));
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
-
- replay();
forcePollAndWaitForIdle();
// verify service recorded history
assertNetworkTotal(sTemplateWifi, 1024L, 1L, 2048L, 2L, 0);
- verifyAndReset();
+
// and bump forward again, with counters going higher. this is
// important, since polling should correctly subtract last snapshot.
@@ -265,17 +260,14 @@
expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1)
.addIfaceValues(TEST_IFACE, 4096L, 4L, 8192L, 8L));
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
-
- replay();
forcePollAndWaitForIdle();
// verify service recorded history
assertNetworkTotal(sTemplateWifi, 4096L, 4L, 8192L, 8L, 0);
- verifyAndReset();
}
+ @Test
public void testStatsRebootPersist() throws Exception {
assertStatsFilesExist(false);
@@ -286,15 +278,13 @@
expectNetworkState(buildWifiState());
expectNetworkStatsSummary(buildEmptyStats());
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
expectBandwidthControlCheck();
- replay();
mService.forceUpdateIfaces();
// verify service has empty history for wifi
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
- verifyAndReset();
+
// modify some number on wifi, and trigger poll event
incrementCurrentTime(HOUR_IN_MILLIS);
@@ -308,33 +298,28 @@
.addValues(TEST_IFACE, UID_RED, SET_FOREGROUND, TAG_NONE, 512L, 4L, 256L, 2L, 0L)
.addValues(TEST_IFACE, UID_RED, SET_FOREGROUND, 0xFAAD, 256L, 2L, 128L, 1L, 0L)
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 128L, 1L, 128L, 1L, 0L));
- expectNetworkStatsPoll();
-
mService.setUidForeground(UID_RED, false);
mService.incrementOperationCount(UID_RED, 0xFAAD, 4);
mService.setUidForeground(UID_RED, true);
mService.incrementOperationCount(UID_RED, 0xFAAD, 6);
- replay();
forcePollAndWaitForIdle();
// verify service recorded history
assertNetworkTotal(sTemplateWifi, 1024L, 8L, 2048L, 16L, 0);
assertUidTotal(sTemplateWifi, UID_RED, 1024L, 8L, 512L, 4L, 10);
- assertUidTotal(sTemplateWifi, UID_RED, SET_DEFAULT, ROAMING_NO, 512L, 4L, 256L, 2L, 4);
- assertUidTotal(sTemplateWifi, UID_RED, SET_FOREGROUND, ROAMING_NO, 512L, 4L, 256L, 2L,
- 6);
+ assertUidTotal(sTemplateWifi, UID_RED, SET_DEFAULT, METERED_NO, ROAMING_NO, 512L, 4L, 256L,
+ 2L, 4);
+ assertUidTotal(sTemplateWifi, UID_RED, SET_FOREGROUND, METERED_NO, ROAMING_NO, 512L, 4L,
+ 256L, 2L, 6);
assertUidTotal(sTemplateWifi, UID_BLUE, 128L, 1L, 128L, 1L, 0);
- verifyAndReset();
+
// graceful shutdown system, which should trigger persist of stats, and
// clear any values in memory.
expectCurrentTime();
expectDefaultSettings();
- replay();
mServiceContext.sendBroadcast(new Intent(Intent.ACTION_SHUTDOWN));
- verifyAndReset();
-
assertStatsFilesExist(true);
// boot through serviceReady() again
@@ -343,30 +328,22 @@
expectNetworkStatsUidDetail(buildEmptyStats());
expectSystemReady();
- // catch INetworkManagementEventObserver during systemReady()
- final Capture<INetworkManagementEventObserver> networkObserver = new Capture<
- INetworkManagementEventObserver>();
- mNetManager.registerObserver(capture(networkObserver));
- expectLastCall().atLeastOnce();
-
- replay();
mService.systemReady();
- mNetworkObserver = networkObserver.getValue();
-
// after systemReady(), we should have historical stats loaded again
assertNetworkTotal(sTemplateWifi, 1024L, 8L, 2048L, 16L, 0);
assertUidTotal(sTemplateWifi, UID_RED, 1024L, 8L, 512L, 4L, 10);
- assertUidTotal(sTemplateWifi, UID_RED, SET_DEFAULT, ROAMING_NO, 512L, 4L, 256L, 2L, 4);
- assertUidTotal(sTemplateWifi, UID_RED, SET_FOREGROUND, ROAMING_NO, 512L, 4L, 256L, 2L,
- 6);
+ assertUidTotal(sTemplateWifi, UID_RED, SET_DEFAULT, METERED_NO, ROAMING_NO, 512L, 4L, 256L,
+ 2L, 4);
+ assertUidTotal(sTemplateWifi, UID_RED, SET_FOREGROUND, METERED_NO, ROAMING_NO, 512L, 4L,
+ 256L, 2L, 6);
assertUidTotal(sTemplateWifi, UID_BLUE, 128L, 1L, 128L, 1L, 0);
- verifyAndReset();
}
// TODO: simulate reboot to test bucket resize
- @Suppress
+ @Test
+ @Ignore
public void testStatsBucketResize() throws Exception {
NetworkStatsHistory history = null;
@@ -379,12 +356,10 @@
expectNetworkState(buildWifiState());
expectNetworkStatsSummary(buildEmptyStats());
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
expectBandwidthControlCheck();
- replay();
mService.forceUpdateIfaces();
- verifyAndReset();
+
// modify some number on wifi, and trigger poll event
incrementCurrentTime(2 * HOUR_IN_MILLIS);
@@ -393,9 +368,6 @@
expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1)
.addIfaceValues(TEST_IFACE, 512L, 4L, 512L, 4L));
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
-
- replay();
forcePollAndWaitForIdle();
// verify service recorded history
@@ -403,7 +375,7 @@
assertValues(history, Long.MIN_VALUE, Long.MAX_VALUE, 512L, 4L, 512L, 4L, 0);
assertEquals(HOUR_IN_MILLIS, history.getBucketDuration());
assertEquals(2, history.size());
- verifyAndReset();
+
// now change bucket duration setting and trigger another poll with
// exact same values, which should resize existing buckets.
@@ -411,9 +383,6 @@
expectSettings(0L, 30 * MINUTE_IN_MILLIS, WEEK_IN_MILLIS);
expectNetworkStatsSummary(buildEmptyStats());
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
-
- replay();
forcePollAndWaitForIdle();
// verify identical stats, but spread across 4 buckets now
@@ -421,10 +390,10 @@
assertValues(history, Long.MIN_VALUE, Long.MAX_VALUE, 512L, 4L, 512L, 4L, 0);
assertEquals(30 * MINUTE_IN_MILLIS, history.getBucketDuration());
assertEquals(4, history.size());
- verifyAndReset();
}
+ @Test
public void testUidStatsAcrossNetworks() throws Exception {
// pretend first mobile network comes online
expectCurrentTime();
@@ -432,12 +401,10 @@
expectNetworkState(buildMobile3gState(IMSI_1));
expectNetworkStatsSummary(buildEmptyStats());
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
expectBandwidthControlCheck();
- replay();
mService.forceUpdateIfaces();
- verifyAndReset();
+
// create some traffic on first network
incrementCurrentTime(HOUR_IN_MILLIS);
@@ -449,11 +416,8 @@
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 1536L, 12L, 512L, 4L, 0L)
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L)
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 512L, 4L, 0L, 0L, 0L));
- expectNetworkStatsPoll();
-
mService.incrementOperationCount(UID_RED, 0xF00D, 10);
- replay();
forcePollAndWaitForIdle();
// verify service recorded history
@@ -461,7 +425,7 @@
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
assertUidTotal(sTemplateImsi1, UID_RED, 1536L, 12L, 512L, 4L, 10);
assertUidTotal(sTemplateImsi1, UID_BLUE, 512L, 4L, 0L, 0L, 0);
- verifyAndReset();
+
// now switch networks; this also tests that we're okay with interfaces
// disappearing, to verify we don't count backwards.
@@ -475,13 +439,11 @@
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 1536L, 12L, 512L, 4L, 0L)
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L)
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 512L, 4L, 0L, 0L, 0L));
- expectNetworkStatsPoll();
expectBandwidthControlCheck();
- replay();
mService.forceUpdateIfaces();
forcePollAndWaitForIdle();
- verifyAndReset();
+
// create traffic on second network
incrementCurrentTime(HOUR_IN_MILLIS);
@@ -494,11 +456,8 @@
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L)
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 640L, 5L, 1024L, 8L, 0L)
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, 0xFAAD, 128L, 1L, 1024L, 8L, 0L));
- expectNetworkStatsPoll();
-
mService.incrementOperationCount(UID_BLUE, 0xFAAD, 10);
- replay();
forcePollAndWaitForIdle();
// verify original history still intact
@@ -511,10 +470,10 @@
assertNetworkTotal(sTemplateImsi2, 128L, 1L, 1024L, 8L, 0);
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
assertUidTotal(sTemplateImsi2, UID_BLUE, 128L, 1L, 1024L, 8L, 10);
- verifyAndReset();
}
+ @Test
public void testUidRemovedIsMoved() throws Exception {
// pretend that network comes online
expectCurrentTime();
@@ -522,12 +481,10 @@
expectNetworkState(buildWifiState());
expectNetworkStatsSummary(buildEmptyStats());
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
expectBandwidthControlCheck();
- replay();
mService.forceUpdateIfaces();
- verifyAndReset();
+
// create some traffic
incrementCurrentTime(HOUR_IN_MILLIS);
@@ -540,11 +497,8 @@
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xFAAD, 16L, 1L, 16L, 1L, 0L)
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 4096L, 258L, 512L, 32L, 0L)
.addValues(TEST_IFACE, UID_GREEN, SET_DEFAULT, TAG_NONE, 16L, 1L, 16L, 1L, 0L));
- expectNetworkStatsPoll();
-
mService.incrementOperationCount(UID_RED, 0xFAAD, 10);
- replay();
forcePollAndWaitForIdle();
// verify service recorded history
@@ -552,7 +506,7 @@
assertUidTotal(sTemplateWifi, UID_RED, 16L, 1L, 16L, 1L, 10);
assertUidTotal(sTemplateWifi, UID_BLUE, 4096L, 258L, 512L, 32L, 0);
assertUidTotal(sTemplateWifi, UID_GREEN, 16L, 1L, 16L, 1L, 0);
- verifyAndReset();
+
// now pretend two UIDs are uninstalled, which should migrate stats to
// special "removed" bucket.
@@ -565,9 +519,6 @@
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xFAAD, 16L, 1L, 16L, 1L, 0L)
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 4096L, 258L, 512L, 32L, 0L)
.addValues(TEST_IFACE, UID_GREEN, SET_DEFAULT, TAG_NONE, 16L, 1L, 16L, 1L, 0L));
- expectNetworkStatsPoll();
-
- replay();
final Intent intent = new Intent(ACTION_UID_REMOVED);
intent.putExtra(EXTRA_UID, UID_BLUE);
mServiceContext.sendBroadcast(intent);
@@ -581,10 +532,10 @@
assertUidTotal(sTemplateWifi, UID_BLUE, 0L, 0L, 0L, 0L, 0);
assertUidTotal(sTemplateWifi, UID_GREEN, 16L, 1L, 16L, 1L, 0);
assertUidTotal(sTemplateWifi, UID_REMOVED, 4112L, 259L, 528L, 33L, 10);
- verifyAndReset();
}
+ @Test
public void testUid3g4gCombinedByTemplate() throws Exception {
// pretend that network comes online
expectCurrentTime();
@@ -592,12 +543,10 @@
expectNetworkState(buildMobile3gState(IMSI_1));
expectNetworkStatsSummary(buildEmptyStats());
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
expectBandwidthControlCheck();
- replay();
mService.forceUpdateIfaces();
- verifyAndReset();
+
// create some traffic
incrementCurrentTime(HOUR_IN_MILLIS);
@@ -607,16 +556,13 @@
expectNetworkStatsUidDetail(new NetworkStats(getElapsedRealtime(), 1)
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 1024L, 8L, 1024L, 8L, 0L)
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L));
- expectNetworkStatsPoll();
-
mService.incrementOperationCount(UID_RED, 0xF00D, 5);
- replay();
forcePollAndWaitForIdle();
// verify service recorded history
assertUidTotal(sTemplateImsi1, UID_RED, 1024L, 8L, 1024L, 8L, 5);
- verifyAndReset();
+
// now switch over to 4g network
incrementCurrentTime(HOUR_IN_MILLIS);
@@ -627,13 +573,11 @@
expectNetworkStatsUidDetail(new NetworkStats(getElapsedRealtime(), 1)
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 1024L, 8L, 1024L, 8L, 0L)
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L));
- expectNetworkStatsPoll();
expectBandwidthControlCheck();
- replay();
mService.forceUpdateIfaces();
forcePollAndWaitForIdle();
- verifyAndReset();
+
// create traffic on second network
incrementCurrentTime(HOUR_IN_MILLIS);
@@ -645,19 +589,15 @@
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L)
.addValues(TEST_IFACE2, UID_RED, SET_DEFAULT, TAG_NONE, 512L, 4L, 256L, 2L, 0L)
.addValues(TEST_IFACE2, UID_RED, SET_DEFAULT, 0xFAAD, 512L, 4L, 256L, 2L, 0L));
- expectNetworkStatsPoll();
-
mService.incrementOperationCount(UID_RED, 0xFAAD, 5);
- replay();
forcePollAndWaitForIdle();
// verify that ALL_MOBILE template combines both
assertUidTotal(sTemplateImsi1, UID_RED, 1536L, 12L, 1280L, 10L, 10);
-
- verifyAndReset();
}
+ @Test
public void testSummaryForAllUid() throws Exception {
// pretend that network comes online
expectCurrentTime();
@@ -665,12 +605,10 @@
expectNetworkState(buildWifiState());
expectNetworkStatsSummary(buildEmptyStats());
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
expectBandwidthControlCheck();
- replay();
mService.forceUpdateIfaces();
- verifyAndReset();
+
// create some traffic for two apps
incrementCurrentTime(HOUR_IN_MILLIS);
@@ -681,17 +619,14 @@
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 50L, 5L, 50L, 5L, 0L)
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 10L, 1L, 10L, 1L, 0L)
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 1024L, 8L, 512L, 4L, 0L));
- expectNetworkStatsPoll();
-
mService.incrementOperationCount(UID_RED, 0xF00D, 1);
- replay();
forcePollAndWaitForIdle();
// verify service recorded history
assertUidTotal(sTemplateWifi, UID_RED, 50L, 5L, 50L, 5L, 1);
assertUidTotal(sTemplateWifi, UID_BLUE, 1024L, 8L, 512L, 4L, 0);
- verifyAndReset();
+
// now create more traffic in next hour, but only for one app
incrementCurrentTime(HOUR_IN_MILLIS);
@@ -702,33 +637,29 @@
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 50L, 5L, 50L, 5L, 0L)
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 10L, 1L, 10L, 1L, 0L)
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 2048L, 16L, 1024L, 8L, 0L));
- expectNetworkStatsPoll();
-
- replay();
forcePollAndWaitForIdle();
// first verify entire history present
NetworkStats stats = mSession.getSummaryForAllUid(
sTemplateWifi, Long.MIN_VALUE, Long.MAX_VALUE, true);
assertEquals(3, stats.size());
- assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_NO, 50L, 5L,
- 50L, 5L, 1);
- assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, 0xF00D, ROAMING_NO, 10L, 1L, 10L,
- 1L, 1);
- assertValues(stats, IFACE_ALL, UID_BLUE, SET_DEFAULT, TAG_NONE, ROAMING_NO, 2048L, 16L,
- 1024L, 8L, 0);
+ assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 50L,
+ 5L, 50L, 5L, 1);
+ assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, 0xF00D, METERED_NO, ROAMING_NO, 10L,
+ 1L, 10L, 1L, 1);
+ assertValues(stats, IFACE_ALL, UID_BLUE, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 2048L, 16L, 1024L, 8L, 0);
// now verify that recent history only contains one uid
final long currentTime = currentTimeMillis();
stats = mSession.getSummaryForAllUid(
sTemplateWifi, currentTime - HOUR_IN_MILLIS, currentTime, true);
assertEquals(1, stats.size());
- assertValues(stats, IFACE_ALL, UID_BLUE, SET_DEFAULT, TAG_NONE, ROAMING_NO, 1024L, 8L,
- 512L, 4L, 0);
-
- verifyAndReset();
+ assertValues(stats, IFACE_ALL, UID_BLUE, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
+ 1024L, 8L, 512L, 4L, 0);
}
+ @Test
public void testForegroundBackground() throws Exception {
// pretend that network comes online
expectCurrentTime();
@@ -736,12 +667,10 @@
expectNetworkState(buildWifiState());
expectNetworkStatsSummary(buildEmptyStats());
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
expectBandwidthControlCheck();
- replay();
mService.forceUpdateIfaces();
- verifyAndReset();
+
// create some initial traffic
incrementCurrentTime(HOUR_IN_MILLIS);
@@ -751,16 +680,13 @@
expectNetworkStatsUidDetail(new NetworkStats(getElapsedRealtime(), 1)
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 128L, 2L, 128L, 2L, 0L)
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 64L, 1L, 64L, 1L, 0L));
- expectNetworkStatsPoll();
-
mService.incrementOperationCount(UID_RED, 0xF00D, 1);
- replay();
forcePollAndWaitForIdle();
// verify service recorded history
assertUidTotal(sTemplateWifi, UID_RED, 128L, 2L, 128L, 2L, 1);
- verifyAndReset();
+
// now switch to foreground
incrementCurrentTime(HOUR_IN_MILLIS);
@@ -772,12 +698,9 @@
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 64L, 1L, 64L, 1L, 0L)
.addValues(TEST_IFACE, UID_RED, SET_FOREGROUND, TAG_NONE, 32L, 2L, 32L, 2L, 0L)
.addValues(TEST_IFACE, UID_RED, SET_FOREGROUND, 0xFAAD, 1L, 1L, 1L, 1L, 0L));
- expectNetworkStatsPoll();
-
mService.setUidForeground(UID_RED, true);
mService.incrementOperationCount(UID_RED, 0xFAAD, 1);
- replay();
forcePollAndWaitForIdle();
// test that we combined correctly
@@ -787,18 +710,59 @@
final NetworkStats stats = mSession.getSummaryForAllUid(
sTemplateWifi, Long.MIN_VALUE, Long.MAX_VALUE, true);
assertEquals(4, stats.size());
- assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_NO, 128L, 2L,
- 128L, 2L, 1);
- assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, 0xF00D, ROAMING_NO, 64L, 1L, 64L,
- 1L, 1);
- assertValues(stats, IFACE_ALL, UID_RED, SET_FOREGROUND, TAG_NONE, ROAMING_NO, 32L, 2L,
- 32L, 2L, 1);
- assertValues(stats, IFACE_ALL, UID_RED, SET_FOREGROUND, 0xFAAD, ROAMING_NO, 1L, 1L, 1L,
- 1L, 1);
-
- verifyAndReset();
+ assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 128L,
+ 2L, 128L, 2L, 1);
+ assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, 0xF00D, METERED_NO, ROAMING_NO, 64L,
+ 1L, 64L, 1L, 1);
+ assertValues(stats, IFACE_ALL, UID_RED, SET_FOREGROUND, TAG_NONE, METERED_NO, ROAMING_NO,
+ 32L, 2L, 32L, 2L, 1);
+ assertValues(stats, IFACE_ALL, UID_RED, SET_FOREGROUND, 0xFAAD, METERED_NO, ROAMING_NO, 1L,
+ 1L, 1L, 1L, 1);
}
+ @Test
+ public void testMetered() throws Exception {
+ // pretend that network comes online
+ expectCurrentTime();
+ expectDefaultSettings();
+ expectNetworkState(buildWifiState(true /* isMetered */));
+ expectNetworkStatsSummary(buildEmptyStats());
+ expectNetworkStatsUidDetail(buildEmptyStats());
+ expectBandwidthControlCheck();
+
+ mService.forceUpdateIfaces();
+
+
+ // create some initial traffic
+ incrementCurrentTime(HOUR_IN_MILLIS);
+ expectCurrentTime();
+ expectDefaultSettings();
+ expectNetworkStatsSummary(buildEmptyStats());
+ // Note that all traffic from NetworkManagementService is tagged as METERED_NO and
+ // ROAMING_NO, because metered and roaming isn't tracked at that layer. We layer it
+ // on top by inspecting the iface properties.
+ expectNetworkStatsUidDetail(new NetworkStats(getElapsedRealtime(), 1)
+ .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO, 128L,
+ 2L, 128L, 2L, 0L)
+ .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, METERED_NO, ROAMING_NO, 64L,
+ 1L, 64L, 1L, 0L));
+ mService.incrementOperationCount(UID_RED, 0xF00D, 1);
+
+ forcePollAndWaitForIdle();
+
+ // verify service recorded history
+ assertUidTotal(sTemplateWifi, UID_RED, 128L, 2L, 128L, 2L, 1);
+ // verify entire history present
+ final NetworkStats stats = mSession.getSummaryForAllUid(
+ sTemplateWifi, Long.MIN_VALUE, Long.MAX_VALUE, true);
+ assertEquals(2, stats.size());
+ assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, TAG_NONE, METERED_YES, ROAMING_NO,
+ 128L, 2L, 128L, 2L, 1);
+ assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, 0xF00D, METERED_YES, ROAMING_NO, 64L,
+ 1L, 64L, 1L, 1);
+ }
+
+ @Test
public void testRoaming() throws Exception {
// pretend that network comes online
expectCurrentTime();
@@ -806,29 +770,24 @@
expectNetworkState(buildMobile3gState(IMSI_1, true /* isRoaming */));
expectNetworkStatsSummary(buildEmptyStats());
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
expectBandwidthControlCheck();
- replay();
mService.forceUpdateIfaces();
- verifyAndReset();
+
// Create some traffic
incrementCurrentTime(HOUR_IN_MILLIS);
expectCurrentTime();
expectDefaultSettings();
expectNetworkStatsSummary(buildEmptyStats());
- // Note that all traffic from NetworkManagementService is tagged as ROAMING_NO, because
- // roaming isn't tracked at that layer. We layer it on top by inspecting the iface
- // properties.
+ // Note that all traffic from NetworkManagementService is tagged as METERED_NO and
+ // ROAMING_NO, because metered and roaming isn't tracked at that layer. We layer it
+ // on top by inspecting the iface properties.
expectNetworkStatsUidDetail(new NetworkStats(getElapsedRealtime(), 1)
- .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_NO, 128L, 2L,
- 128L, 2L, 0L)
- .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, ROAMING_NO, 64L, 1L, 64L,
- 1L, 0L));
- expectNetworkStatsPoll();
-
- replay();
+ .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, METERED_ALL, ROAMING_NO,
+ 128L, 2L, 128L, 2L, 0L)
+ .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, METERED_ALL, ROAMING_NO, 64L,
+ 1L, 64L, 1L, 0L));
forcePollAndWaitForIdle();
// verify service recorded history
@@ -838,14 +797,13 @@
final NetworkStats stats = mSession.getSummaryForAllUid(
sTemplateImsi1, Long.MIN_VALUE, Long.MAX_VALUE, true);
assertEquals(2, stats.size());
- assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_YES, 128L, 2L,
- 128L, 2L, 0);
- assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, 0xF00D, ROAMING_YES, 64L, 1L, 64L,
- 1L, 0);
-
- verifyAndReset();
+ assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, TAG_NONE, METERED_ALL, ROAMING_YES,
+ 128L, 2L, 128L, 2L, 0);
+ assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, 0xF00D, METERED_ALL, ROAMING_YES, 64L,
+ 1L, 64L, 1L, 0);
}
+ @Test
public void testTethering() throws Exception {
// pretend first mobile network comes online
expectCurrentTime();
@@ -853,12 +811,10 @@
expectNetworkState(buildMobile3gState(IMSI_1));
expectNetworkStatsSummary(buildEmptyStats());
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
expectBandwidthControlCheck();
- replay();
mService.forceUpdateIfaces();
- verifyAndReset();
+
// create some tethering traffic
incrementCurrentTime(HOUR_IN_MILLIS);
@@ -871,22 +827,20 @@
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 128L, 2L, 128L, 2L, 0L);
final String[] tetherIfacePairs = new String[] { TEST_IFACE, "wlan0" };
final NetworkStats tetherStats = new NetworkStats(getElapsedRealtime(), 1)
- .addValues(TEST_IFACE, UID_TETHERING, SET_DEFAULT, TAG_NONE, 1920L, 14L, 384L, 2L, 0L);
+ .addValues(TEST_IFACE, UID_TETHERING, SET_DEFAULT, TAG_NONE, 1920L, 14L, 384L, 2L,
+ 0L);
expectNetworkStatsUidDetail(uidStats, tetherIfacePairs, tetherStats);
- expectNetworkStatsPoll();
-
- replay();
forcePollAndWaitForIdle();
// verify service recorded history
assertNetworkTotal(sTemplateImsi1, 2048L, 16L, 512L, 4L, 0);
assertUidTotal(sTemplateImsi1, UID_RED, 128L, 2L, 128L, 2L, 0);
assertUidTotal(sTemplateImsi1, UID_TETHERING, 1920L, 14L, 384L, 2L, 0);
- verifyAndReset();
}
+ @Test
public void testRegisterUsageCallback() throws Exception {
// pretend that wifi network comes online; service should ask about full
// network state, and poll any existing interfaces before updating.
@@ -895,16 +849,12 @@
expectNetworkState(buildWifiState());
expectNetworkStatsSummary(buildEmptyStats());
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
expectBandwidthControlCheck();
- replay();
mService.forceUpdateIfaces();
// verify service has empty history for wifi
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
- verifyAndReset();
-
String callingPackage = "the.calling.package";
long thresholdInBytes = 1L; // very small; should be overriden by framework
DataUsageRequest inputRequest = new DataUsageRequest(
@@ -915,23 +865,18 @@
LatchedHandler latchedHandler = new LatchedHandler(Looper.getMainLooper(), cv);
Messenger messenger = new Messenger(latchedHandler);
- // Allow binder to connect
- IBinder mockBinder = createMock(IBinder.class);
- mockBinder.linkToDeath((IBinder.DeathRecipient) anyObject(), anyInt());
- EasyMock.replay(mockBinder);
-
// Force poll
expectCurrentTime();
expectDefaultSettings();
expectNetworkStatsSummary(buildEmptyStats());
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
- replay();
+
+
// Register and verify request and that binder was called
DataUsageRequest request =
mService.registerUsageCallback(callingPackage, inputRequest,
- messenger, mockBinder);
+ messenger, mBinder);
assertTrue(request.requestId > 0);
assertTrue(Objects.equals(sTemplateWifi, request.template));
long minThresholdInBytes = 2 * 1024 * 1024; // 2 MB
@@ -941,11 +886,11 @@
mHandler.sendMessage(mHandler.obtainMessage(-1));
mHandlerThread.waitForIdle(WAIT_TIMEOUT);
- verifyAndReset();
+
// Make sure that the caller binder gets connected
- EasyMock.verify(mockBinder);
- EasyMock.reset(mockBinder);
+ verify(mBinder).linkToDeath(any(IBinder.DeathRecipient.class), anyInt());
+
// modify some number on wifi, and trigger poll event
// not enough traffic to call data usage callback
@@ -955,13 +900,9 @@
expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1)
.addIfaceValues(TEST_IFACE, 1024L, 1L, 2048L, 2L));
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
-
- replay();
forcePollAndWaitForIdle();
// verify service recorded history
- verifyAndReset();
assertNetworkTotal(sTemplateWifi, 1024L, 1L, 2048L, 2L, 0);
// make sure callback has not being called
@@ -975,14 +916,11 @@
expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1)
.addIfaceValues(TEST_IFACE, 4096000L, 4L, 8192000L, 8L));
expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
-
- replay();
forcePollAndWaitForIdle();
// verify service recorded history
assertNetworkTotal(sTemplateWifi, 4096000L, 4L, 8192000L, 8L, 0);
- verifyAndReset();
+
// Wait for the caller to ack receipt of CALLBACK_LIMIT_REACHED
assertTrue(cv.block(WAIT_TIMEOUT));
@@ -990,9 +928,7 @@
cv.close();
// Allow binder to disconnect
- expect(mockBinder.unlinkToDeath((IBinder.DeathRecipient) anyObject(), anyInt()))
- .andReturn(true);
- EasyMock.replay(mockBinder);
+ when(mBinder.unlinkToDeath(any(IBinder.DeathRecipient.class), anyInt())).thenReturn(true);
// Unregister request
mService.unregisterUsageRequest(request);
@@ -1002,9 +938,10 @@
assertEquals(NetworkStatsManager.CALLBACK_RELEASED, latchedHandler.mLastMessageType);
// Make sure that the caller binder gets disconnected
- EasyMock.verify(mockBinder);
+ verify(mBinder).unlinkToDeath(any(IBinder.DeathRecipient.class), anyInt());
}
+ @Test
public void testUnregisterUsageCallback_unknown_noop() throws Exception {
String callingPackage = "the.calling.package";
long thresholdInBytes = 10 * 1024 * 1024; // 10 MB
@@ -1034,18 +971,18 @@
// verify summary API
final NetworkStats stats = mSession.getSummaryForNetwork(template, start, end);
- assertValues(stats, IFACE_ALL, UID_ALL, SET_DEFAULT, TAG_NONE, ROAMING_NO, rxBytes,
- rxPackets, txBytes, txPackets, operations);
+ assertValues(stats, IFACE_ALL, UID_ALL, SET_DEFAULT, TAG_NONE, METERED_ALL, ROAMING_NO,
+ rxBytes, rxPackets, txBytes, txPackets, operations);
}
private void assertUidTotal(NetworkTemplate template, int uid, long rxBytes, long rxPackets,
long txBytes, long txPackets, int operations) throws Exception {
- assertUidTotal(template, uid, SET_ALL, ROAMING_ALL, rxBytes, rxPackets, txBytes, txPackets,
- operations);
+ assertUidTotal(template, uid, SET_ALL, METERED_ALL, ROAMING_ALL, rxBytes, rxPackets,
+ txBytes, txPackets, operations);
}
- private void assertUidTotal(NetworkTemplate template, int uid, int set, int roaming,
- long rxBytes, long rxPackets, long txBytes, long txPackets, int operations)
+ private void assertUidTotal(NetworkTemplate template, int uid, int set, int metered,
+ int roaming, long rxBytes, long rxPackets, long txBytes, long txPackets, int operations)
throws Exception {
// verify history API
final NetworkStatsHistory history = mSession.getHistoryForUid(
@@ -1056,38 +993,35 @@
// verify summary API
final NetworkStats stats = mSession.getSummaryForAllUid(
template, Long.MIN_VALUE, Long.MAX_VALUE, false);
- assertValues(stats, IFACE_ALL, uid, set, TAG_NONE, roaming, rxBytes, rxPackets, txBytes,
- txPackets, operations);
+ assertValues(stats, IFACE_ALL, uid, set, TAG_NONE, metered, roaming, rxBytes, rxPackets,
+ txBytes, txPackets, operations);
}
private void expectSystemReady() throws Exception {
- mNetManager.setGlobalAlert(anyLong());
- expectLastCall().atLeastOnce();
-
expectNetworkStatsSummary(buildEmptyStats());
expectBandwidthControlCheck();
}
private void expectNetworkState(NetworkState... state) throws Exception {
- expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
+ when(mConnManager.getAllNetworkState()).thenReturn(state);
final LinkProperties linkProp = state.length > 0 ? state[0].linkProperties : null;
- expect(mConnManager.getActiveLinkProperties()).andReturn(linkProp).atLeastOnce();
+ when(mConnManager.getActiveLinkProperties()).thenReturn(linkProp);
}
private void expectNetworkStatsSummary(NetworkStats summary) throws Exception {
- expect(mConnManager.getAllVpnInfo()).andReturn(new VpnInfo[0]).atLeastOnce();
+ when(mConnManager.getAllVpnInfo()).thenReturn(new VpnInfo[0]);
expectNetworkStatsSummaryDev(summary);
expectNetworkStatsSummaryXt(summary);
}
private void expectNetworkStatsSummaryDev(NetworkStats summary) throws Exception {
- expect(mNetManager.getNetworkStatsSummaryDev()).andReturn(summary).atLeastOnce();
+ when(mNetManager.getNetworkStatsSummaryDev()).thenReturn(summary);
}
private void expectNetworkStatsSummaryXt(NetworkStats summary) throws Exception {
- expect(mNetManager.getNetworkStatsSummaryXt()).andReturn(summary).atLeastOnce();
+ when(mNetManager.getNetworkStatsSummaryXt()).thenReturn(summary);
}
private void expectNetworkStatsUidDetail(NetworkStats detail) throws Exception {
@@ -1097,11 +1031,10 @@
private void expectNetworkStatsUidDetail(
NetworkStats detail, String[] tetherIfacePairs, NetworkStats tetherStats)
throws Exception {
- expect(mNetManager.getNetworkStatsUidDetail(eq(UID_ALL))).andReturn(detail).atLeastOnce();
+ when(mNetManager.getNetworkStatsUidDetail(UID_ALL)).thenReturn(detail);
// also include tethering details, since they are folded into UID
- expect(mNetManager.getNetworkStatsTethering())
- .andReturn(tetherStats).atLeastOnce();
+ when(mNetManager.getNetworkStatsTethering()).thenReturn(tetherStats);
}
private void expectDefaultSettings() throws Exception {
@@ -1110,38 +1043,33 @@
private void expectSettings(long persistBytes, long bucketDuration, long deleteAge)
throws Exception {
- expect(mSettings.getPollInterval()).andReturn(HOUR_IN_MILLIS).anyTimes();
- expect(mSettings.getTimeCacheMaxAge()).andReturn(DAY_IN_MILLIS).anyTimes();
- expect(mSettings.getSampleEnabled()).andReturn(true).anyTimes();
+ when(mSettings.getPollInterval()).thenReturn(HOUR_IN_MILLIS);
+ when(mSettings.getTimeCacheMaxAge()).thenReturn(DAY_IN_MILLIS);
+ when(mSettings.getSampleEnabled()).thenReturn(true);
final Config config = new Config(bucketDuration, deleteAge, deleteAge);
- expect(mSettings.getDevConfig()).andReturn(config).anyTimes();
- expect(mSettings.getXtConfig()).andReturn(config).anyTimes();
- expect(mSettings.getUidConfig()).andReturn(config).anyTimes();
- expect(mSettings.getUidTagConfig()).andReturn(config).anyTimes();
+ when(mSettings.getDevConfig()).thenReturn(config);
+ when(mSettings.getXtConfig()).thenReturn(config);
+ when(mSettings.getUidConfig()).thenReturn(config);
+ when(mSettings.getUidTagConfig()).thenReturn(config);
- expect(mSettings.getGlobalAlertBytes(anyLong())).andReturn(MB_IN_BYTES).anyTimes();
- expect(mSettings.getDevPersistBytes(anyLong())).andReturn(MB_IN_BYTES).anyTimes();
- expect(mSettings.getXtPersistBytes(anyLong())).andReturn(MB_IN_BYTES).anyTimes();
- expect(mSettings.getUidPersistBytes(anyLong())).andReturn(MB_IN_BYTES).anyTimes();
- expect(mSettings.getUidTagPersistBytes(anyLong())).andReturn(MB_IN_BYTES).anyTimes();
+ when(mSettings.getGlobalAlertBytes(anyLong())).thenReturn(MB_IN_BYTES);
+ when(mSettings.getDevPersistBytes(anyLong())).thenReturn(MB_IN_BYTES);
+ when(mSettings.getXtPersistBytes(anyLong())).thenReturn(MB_IN_BYTES);
+ when(mSettings.getUidPersistBytes(anyLong())).thenReturn(MB_IN_BYTES);
+ when(mSettings.getUidTagPersistBytes(anyLong())).thenReturn(MB_IN_BYTES);
}
private void expectCurrentTime() throws Exception {
- expect(mTime.forceRefresh()).andReturn(false).anyTimes();
- expect(mTime.hasCache()).andReturn(true).anyTimes();
- expect(mTime.currentTimeMillis()).andReturn(currentTimeMillis()).anyTimes();
- expect(mTime.getCacheAge()).andReturn(0L).anyTimes();
- expect(mTime.getCacheCertainty()).andReturn(0L).anyTimes();
- }
-
- private void expectNetworkStatsPoll() throws Exception {
- mNetManager.setGlobalAlert(anyLong());
- expectLastCall().anyTimes();
+ when(mTime.forceRefresh()).thenReturn(false);
+ when(mTime.hasCache()).thenReturn(true);
+ when(mTime.currentTimeMillis()).thenReturn(currentTimeMillis());
+ when(mTime.getCacheAge()).thenReturn(0L);
+ when(mTime.getCacheCertainty()).thenReturn(0L);
}
private void expectBandwidthControlCheck() throws Exception {
- expect(mNetManager.isBandwidthControlEnabled()).andReturn(true).atLeastOnce();
+ when(mNetManager.isBandwidthControlEnabled()).thenReturn(true);
}
private void assertStatsFilesExist(boolean exist) {
@@ -1154,8 +1082,8 @@
}
private static void assertValues(NetworkStats stats, String iface, int uid, int set,
- int tag, int roaming, long rxBytes, long rxPackets, long txBytes, long txPackets,
- int operations) {
+ int tag, int metered, int roaming, long rxBytes, long rxPackets, long txBytes,
+ long txPackets, int operations) {
final NetworkStats.Entry entry = new NetworkStats.Entry();
List<Integer> sets = new ArrayList<>();
if (set == SET_DEFAULT || set == SET_ALL) {
@@ -1173,11 +1101,21 @@
roamings.add(ROAMING_YES);
}
+ List<Integer> meterings = new ArrayList<>();
+ if (metered == METERED_NO || metered == METERED_ALL) {
+ meterings.add(METERED_NO);
+ }
+ if (metered == METERED_YES || metered == METERED_ALL) {
+ meterings.add(METERED_YES);
+ }
+
for (int s : sets) {
for (int r : roamings) {
- final int i = stats.findIndex(iface, uid, s, tag, r);
- if (i != -1) {
- entry.add(stats.getValues(i, null));
+ for (int m : meterings) {
+ final int i = stats.findIndex(iface, uid, s, tag, m, r);
+ if (i != -1) {
+ entry.add(stats.getValues(i, null));
+ }
}
}
}
@@ -1200,11 +1138,19 @@
}
private static NetworkState buildWifiState() {
+ return buildWifiState(false);
+ }
+
+ private static NetworkState buildWifiState(boolean isMetered) {
final NetworkInfo info = new NetworkInfo(TYPE_WIFI, 0, null, null);
info.setDetailedState(DetailedState.CONNECTED, null, null);
final LinkProperties prop = new LinkProperties();
prop.setInterfaceName(TEST_IFACE);
- return new NetworkState(info, prop, null, null, null, TEST_SSID);
+ final NetworkCapabilities capabilities = new NetworkCapabilities();
+ if (!isMetered) {
+ capabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
+ }
+ return new NetworkState(info, prop, capabilities, null, null, TEST_SSID);
}
private static NetworkState buildMobile3gState(String subscriberId) {
@@ -1218,7 +1164,8 @@
info.setRoaming(isRoaming);
final LinkProperties prop = new LinkProperties();
prop.setInterfaceName(TEST_IFACE);
- return new NetworkState(info, prop, null, null, subscriberId, null);
+ final NetworkCapabilities capabilities = new NetworkCapabilities();
+ return new NetworkState(info, prop, capabilities, null, subscriberId, null);
}
private static NetworkState buildMobile4gState(String iface) {
@@ -1226,7 +1173,8 @@
info.setDetailedState(DetailedState.CONNECTED, null, null);
final LinkProperties prop = new LinkProperties();
prop.setInterfaceName(iface);
- return new NetworkState(info, prop, null, null, null, null);
+ final NetworkCapabilities capabilities = new NetworkCapabilities();
+ return new NetworkState(info, prop, capabilities, null, null, null);
}
private NetworkStats buildEmptyStats() {
@@ -1249,15 +1197,6 @@
mElapsedRealtime += duration;
}
- private void replay() {
- EasyMock.replay(mNetManager, mTime, mSettings, mConnManager);
- }
-
- private void verifyAndReset() {
- EasyMock.verify(mNetManager, mTime, mSettings, mConnManager);
- EasyMock.reset(mNetManager, mTime, mSettings, mConnManager);
- }
-
private void forcePollAndWaitForIdle() {
mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
// Send dummy message to make sure that any previous message has been handled
diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
index 15a1e76..b3f5630 100644
--- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java
+++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
@@ -351,8 +351,6 @@
UsbManager.removeFunction(persisted, UsbManager.USB_FUNCTION_MTP));
}
- setEnabledFunctions(null, false, false);
-
String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim();
updateState(state);
@@ -446,13 +444,12 @@
return false;
}
- private boolean setUsbConfig(String config) {
+ private void setUsbConfig(String config) {
if (DEBUG) Slog.d(TAG, "setUsbConfig(" + config + ")");
// set the new configuration
// we always set it due to b/23631400, where adbd was getting killed
// and not restarted due to property timeouts on some devices
SystemProperties.set(USB_CONFIG_PROPERTY, config);
- return waitForState(config);
}
private void setAdbEnabled(boolean enable) {
@@ -547,8 +544,18 @@
// Kick the USB stack to close existing connections.
setUsbConfig(UsbManager.USB_FUNCTION_NONE);
+ if (!waitForState(UsbManager.USB_FUNCTION_NONE)) {
+ Slog.e(TAG, "Failed to kick USB config");
+ return false;
+ }
+
// Set the new USB configuration.
- if (!setUsbConfig(functions)) {
+ setUsbConfig(functions);
+
+ // Start up dependent services.
+ updateUsbStateBroadcastIfNeeded(true);
+
+ if (!waitForState(functions)) {
Slog.e(TAG, "Failed to switch USB config to " + functions);
return false;
}
@@ -631,7 +638,7 @@
return false;
}
- private void updateUsbStateBroadcastIfNeeded() {
+ private void updateUsbStateBroadcastIfNeeded(boolean configChanged) {
// send a sticky broadcast containing current USB state
Intent intent = new Intent(UsbManager.ACTION_USB_STATE);
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
@@ -640,6 +647,7 @@
intent.putExtra(UsbManager.USB_HOST_CONNECTED, mHostConnected);
intent.putExtra(UsbManager.USB_CONFIGURED, mConfigured);
intent.putExtra(UsbManager.USB_DATA_UNLOCKED, isUsbTransferAllowed() && mUsbDataUnlocked);
+ intent.putExtra(UsbManager.USB_CONFIG_CHANGED, configChanged);
if (mCurrentFunctions != null) {
String[] functions = mCurrentFunctions.split(",");
@@ -737,7 +745,7 @@
setEnabledFunctions(null, false, false);
}
if (mBootCompleted) {
- updateUsbStateBroadcastIfNeeded();
+ updateUsbStateBroadcastIfNeeded(false);
updateUsbFunctions();
}
break;
@@ -749,7 +757,7 @@
args.recycle();
updateUsbNotification();
if (mBootCompleted) {
- updateUsbStateBroadcastIfNeeded();
+ updateUsbStateBroadcastIfNeeded(false);
}
break;
case MSG_ENABLE_ADB:
@@ -765,11 +773,11 @@
case MSG_SYSTEM_READY:
updateUsbNotification();
updateAdbNotification();
- updateUsbStateBroadcastIfNeeded();
updateUsbFunctions();
break;
case MSG_BOOT_COMPLETED:
mBootCompleted = true;
+ setEnabledFunctions(null, false, false);
if (mCurrentAccessory != null) {
getCurrentSettings().accessoryAttached(mCurrentAccessory);
}
diff --git a/telecomm/java/android/telecom/Call.java b/telecomm/java/android/telecom/Call.java
index 62625bdf..58c5002 100644
--- a/telecomm/java/android/telecom/Call.java
+++ b/telecomm/java/android/telecom/Call.java
@@ -324,6 +324,7 @@
private final PhoneAccountHandle mAccountHandle;
private final int mCallCapabilities;
private final int mCallProperties;
+ private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
private final DisconnectCause mDisconnectCause;
private final long mConnectTimeMillis;
private final GatewayInfo mGatewayInfo;
@@ -536,6 +537,15 @@
}
/**
+ * @return a bitmask of the audio routes available for the call.
+ *
+ * @hide
+ */
+ public int getSupportedAudioRoutes() {
+ return mSupportedAudioRoutes;
+ }
+
+ /**
* @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
* by {@link android.telecom.DisconnectCause}.
*/
diff --git a/telecomm/java/android/telecom/CallAudioState.java b/telecomm/java/android/telecom/CallAudioState.java
index 2b16722..f601d8b 100644
--- a/telecomm/java/android/telecom/CallAudioState.java
+++ b/telecomm/java/android/telecom/CallAudioState.java
@@ -44,8 +44,12 @@
*/
public static final int ROUTE_WIRED_OR_EARPIECE = ROUTE_EARPIECE | ROUTE_WIRED_HEADSET;
- /** Bit mask of all possible audio routes. */
- private static final int ROUTE_ALL = ROUTE_EARPIECE | ROUTE_BLUETOOTH | ROUTE_WIRED_HEADSET |
+ /**
+ * Bit mask of all possible audio routes.
+ *
+ * @hide
+ **/
+ public static final int ROUTE_ALL = ROUTE_EARPIECE | ROUTE_BLUETOOTH | ROUTE_WIRED_HEADSET |
ROUTE_SPEAKER;
private final boolean isMuted;
diff --git a/telecomm/java/android/telecom/Connection.java b/telecomm/java/android/telecom/Connection.java
index c006185..15960c8 100644
--- a/telecomm/java/android/telecom/Connection.java
+++ b/telecomm/java/android/telecom/Connection.java
@@ -697,6 +697,7 @@
public void onDestroyed(Connection c) {}
public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
public void onConnectionPropertiesChanged(Connection c, int properties) {}
+ public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
public void onVideoProviderChanged(
Connection c, VideoProvider videoProvider) {}
public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
@@ -1403,6 +1404,7 @@
private boolean mRingbackRequested = false;
private int mConnectionCapabilities;
private int mConnectionProperties;
+ private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
private VideoProvider mVideoProvider;
private boolean mAudioModeIsVoip;
private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
@@ -1683,6 +1685,15 @@
}
/**
+ * Returns the connection's supported audio routes.
+ *
+ * @hide
+ */
+ public final int getSupportedAudioRoutes() {
+ return mSupportedAudioRoutes;
+ }
+
+ /**
* Sets the value of the {@link #getAddress()} property.
*
* @param address The new address.
@@ -1904,6 +1915,28 @@
}
/**
+ * Sets the supported audio routes.
+ *
+ * @param supportedAudioRoutes the supported audio routes as a bitmask.
+ * See {@link CallAudioState}
+ * @hide
+ */
+ public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
+ if ((supportedAudioRoutes
+ & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
+ throw new IllegalArgumentException(
+ "supported audio routes must include either speaker or earpiece");
+ }
+
+ if (mSupportedAudioRoutes != supportedAudioRoutes) {
+ mSupportedAudioRoutes = supportedAudioRoutes;
+ for (Listener l : mListeners) {
+ l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
+ }
+ }
+ }
+
+ /**
* Tears down the Connection object.
*/
public final void destroy() {
diff --git a/telecomm/java/android/telecom/ConnectionService.java b/telecomm/java/android/telecom/ConnectionService.java
index 9f0032a..b042d88 100644
--- a/telecomm/java/android/telecom/ConnectionService.java
+++ b/telecomm/java/android/telecom/ConnectionService.java
@@ -1131,6 +1131,7 @@
connection.getState(),
connection.getConnectionCapabilities(),
connection.getConnectionProperties(),
+ connection.getSupportedAudioRoutes(),
connection.getAddress(),
connection.getAddressPresentation(),
connection.getCallerDisplayName(),
@@ -1530,6 +1531,7 @@
connection.getState(),
connection.getConnectionCapabilities(),
connection.getConnectionProperties(),
+ connection.getSupportedAudioRoutes(),
connection.getAddress(),
connection.getAddressPresentation(),
connection.getCallerDisplayName(),
diff --git a/telecomm/java/android/telecom/ParcelableCall.java b/telecomm/java/android/telecom/ParcelableCall.java
index 4a6fd7c..f7a6595 100644
--- a/telecomm/java/android/telecom/ParcelableCall.java
+++ b/telecomm/java/android/telecom/ParcelableCall.java
@@ -39,6 +39,7 @@
private final List<String> mCannedSmsResponses;
private final int mCapabilities;
private final int mProperties;
+ private final int mSupportedAudioRoutes;
private final long mConnectTimeMillis;
private final Uri mHandle;
private final int mHandlePresentation;
@@ -64,6 +65,7 @@
List<String> cannedSmsResponses,
int capabilities,
int properties,
+ int supportedAudioRoutes,
long connectTimeMillis,
Uri handle,
int handlePresentation,
@@ -86,6 +88,7 @@
mCannedSmsResponses = cannedSmsResponses;
mCapabilities = capabilities;
mProperties = properties;
+ mSupportedAudioRoutes = supportedAudioRoutes;
mConnectTimeMillis = connectTimeMillis;
mHandle = handle;
mHandlePresentation = handlePresentation;
@@ -137,6 +140,11 @@
/** Bitmask of properties of the call. */
public int getProperties() { return mProperties; }
+ /** Bitmask of supported routes of the call */
+ public int getSupportedAudioRoutes() {
+ return mSupportedAudioRoutes;
+ }
+
/** The time that the call switched to the active state. */
public long getConnectTimeMillis() {
return mConnectTimeMillis;
@@ -292,6 +300,7 @@
source.readList(conferenceableCallIds, classLoader);
Bundle intentExtras = source.readBundle(classLoader);
Bundle extras = source.readBundle(classLoader);
+ int supportedAudioRoutes = source.readInt();
return new ParcelableCall(
id,
state,
@@ -299,6 +308,7 @@
cannedSmsResponses,
capabilities,
properties,
+ supportedAudioRoutes,
connectTimeMillis,
handle,
handlePresentation,
@@ -355,6 +365,7 @@
destination.writeList(mConferenceableCallIds);
destination.writeBundle(mIntentExtras);
destination.writeBundle(mExtras);
+ destination.writeInt(mSupportedAudioRoutes);
}
@Override
diff --git a/telecomm/java/android/telecom/ParcelableConnection.java b/telecomm/java/android/telecom/ParcelableConnection.java
index 540f388..e9dba68 100644
--- a/telecomm/java/android/telecom/ParcelableConnection.java
+++ b/telecomm/java/android/telecom/ParcelableConnection.java
@@ -37,6 +37,7 @@
private final int mState;
private final int mConnectionCapabilities;
private final int mConnectionProperties;
+ private final int mSupportedAudioRoutes;
private final Uri mAddress;
private final int mAddressPresentation;
private final String mCallerDisplayName;
@@ -57,6 +58,7 @@
int state,
int capabilities,
int properties,
+ int supportedAudioRoutes,
Uri address,
int addressPresentation,
String callerDisplayName,
@@ -74,6 +76,7 @@
mState = state;
mConnectionCapabilities = capabilities;
mConnectionProperties = properties;
+ mSupportedAudioRoutes = supportedAudioRoutes;
mAddress = address;
mAddressPresentation = addressPresentation;
mCallerDisplayName = callerDisplayName;
@@ -117,6 +120,10 @@
return mConnectionProperties;
}
+ public int getSupportedAudioRoutes() {
+ return mSupportedAudioRoutes;
+ }
+
public Uri getHandle() {
return mAddress;
}
@@ -210,12 +217,14 @@
source.readStringList(conferenceableConnectionIds);
Bundle extras = Bundle.setDefusable(source.readBundle(classLoader), true);
int properties = source.readInt();
+ int supportedAudioRoutes = source.readInt();
return new ParcelableConnection(
phoneAccount,
state,
capabilities,
properties,
+ supportedAudioRoutes,
address,
addressPresentation,
callerDisplayName,
@@ -264,5 +273,6 @@
destination.writeStringList(mConferenceableConnectionIds);
destination.writeBundle(mExtras);
destination.writeInt(mConnectionProperties);
+ destination.writeInt(mSupportedAudioRoutes);
}
}
diff --git a/telecomm/java/android/telecom/PhoneAccount.java b/telecomm/java/android/telecom/PhoneAccount.java
index 0457d63..ca54486 100644
--- a/telecomm/java/android/telecom/PhoneAccount.java
+++ b/telecomm/java/android/telecom/PhoneAccount.java
@@ -17,15 +17,6 @@
package android.telecom;
import android.annotation.SystemApi;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.content.res.Resources.NotFoundException;
-import android.graphics.Bitmap;
-import android.graphics.Color;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.ColorDrawable;
-import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.Bundle;
@@ -37,7 +28,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.MissingResourceException;
/**
* Represents a distinct method to place or receive a phone call. Apps which can place calls and
@@ -237,6 +227,7 @@
private final CharSequence mLabel;
private final CharSequence mShortDescription;
private final List<String> mSupportedUriSchemes;
+ private final int mSupportedAudioRoutes;
private final Icon mIcon;
private final Bundle mExtras;
private boolean mIsEnabled;
@@ -246,10 +237,12 @@
* Helper class for creating a {@link PhoneAccount}.
*/
public static class Builder {
+
private PhoneAccountHandle mAccountHandle;
private Uri mAddress;
private Uri mSubscriptionAddress;
private int mCapabilities;
+ private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
private int mHighlightColor = NO_HIGHLIGHT_COLOR;
private CharSequence mLabel;
private CharSequence mShortDescription;
@@ -286,6 +279,7 @@
mIsEnabled = phoneAccount.isEnabled();
mExtras = phoneAccount.getExtras();
mGroupId = phoneAccount.getGroupId();
+ mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
}
/**
@@ -431,6 +425,18 @@
}
/**
+ * Sets the audio routes supported by this {@link PhoneAccount}.
+ *
+ * @param routes bit mask of available routes.
+ * @return The builder.
+ * @hide
+ */
+ public Builder setSupportedAudioRoutes(int routes) {
+ mSupportedAudioRoutes = routes;
+ return this;
+ }
+
+ /**
* Creates an instance of a {@link PhoneAccount} based on the current builder settings.
*
* @return The {@link PhoneAccount}.
@@ -452,6 +458,7 @@
mShortDescription,
mSupportedUriSchemes,
mExtras,
+ mSupportedAudioRoutes,
mIsEnabled,
mGroupId);
}
@@ -468,6 +475,7 @@
CharSequence shortDescription,
List<String> supportedUriSchemes,
Bundle extras,
+ int supportedAudioRoutes,
boolean isEnabled,
String groupId) {
mAccountHandle = account;
@@ -480,6 +488,7 @@
mShortDescription = shortDescription;
mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
mExtras = extras;
+ mSupportedAudioRoutes = supportedAudioRoutes;
mIsEnabled = isEnabled;
mGroupId = groupId;
}
@@ -553,6 +562,17 @@
}
/**
+ * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
+ *
+ * @param route The routes to check.
+ * @return {@code true} if the phone account has the routes.
+ * @hide
+ */
+ public boolean hasAudioRoutes(int routes) {
+ return (mSupportedAudioRoutes & routes) == routes;
+ }
+
+ /**
* A short label describing a {@code PhoneAccount}.
*
* @return A label for this {@code PhoneAccount}.
@@ -592,6 +612,15 @@
}
/**
+ * The audio routes supported by this {@code PhoneAccount}.
+ *
+ * @hide
+ */
+ public int getSupportedAudioRoutes() {
+ return mSupportedAudioRoutes;
+ }
+
+ /**
* The icon to represent this {@code PhoneAccount}.
*
* @return The icon.
@@ -707,6 +736,7 @@
out.writeByte((byte) (mIsEnabled ? 1 : 0));
out.writeBundle(mExtras);
out.writeString(mGroupId);
+ out.writeInt(mSupportedAudioRoutes);
}
public static final Creator<PhoneAccount> CREATOR
@@ -751,6 +781,7 @@
mIsEnabled = in.readByte() == 1;
mExtras = in.readBundle();
mGroupId = in.readString();
+ mSupportedAudioRoutes = in.readInt();
}
@Override
@@ -760,7 +791,9 @@
.append("] PhoneAccount: ")
.append(mAccountHandle)
.append(" Capabilities: ")
- .append(capabilitiesToString(mCapabilities))
+ .append(capabilitiesToString())
+ .append(" Audio Routes: ")
+ .append(audioRoutesToString())
.append(" Schemes: ");
for (String scheme : mSupportedUriSchemes) {
sb.append(scheme)
@@ -780,7 +813,7 @@
* @param capabilities The capabilities bitmask.
* @return String representation of the capabilities bitmask.
*/
- private String capabilitiesToString(int capabilities) {
+ private String capabilitiesToString() {
StringBuilder sb = new StringBuilder();
if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
sb.append("SuppVideo ");
@@ -817,4 +850,23 @@
}
return sb.toString();
}
+
+ private String audioRoutesToString() {
+ StringBuilder sb = new StringBuilder();
+
+ if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
+ sb.append("B");
+ }
+ if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
+ sb.append("E");
+ }
+ if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
+ sb.append("S");
+ }
+ if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
+ sb.append("W");
+ }
+
+ return sb.toString();
+ }
}
diff --git a/telephony/java/android/telephony/CarrierConfigManager.java b/telephony/java/android/telephony/CarrierConfigManager.java
index 40564b6..2c16ca0 100644
--- a/telephony/java/android/telephony/CarrierConfigManager.java
+++ b/telephony/java/android/telephony/CarrierConfigManager.java
@@ -143,6 +143,13 @@
public static final String
KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL = "hide_carrier_network_settings_bool";
+ /**
+ * Control whether users receive a simplified network settings UI and improved network
+ * selection.
+ */
+ public static final String
+ KEY_SIMPLIFIED_NETWORK_SETTINGS_BOOL = "simplified_network_settings_bool";
+
/** Control whether users can reach the SIM lock settings. */
public static final String
KEY_HIDE_SIM_LOCK_SETTINGS_BOOL = "hide_sim_lock_settings_bool";
@@ -618,6 +625,15 @@
public static final String KEY_SUPPORT_CONFERENCE_CALL_BOOL = "support_conference_call_bool";
/**
+ * Determines whether High Definition audio property is displayed in the dialer UI.
+ * If {@code false}, remove the HD audio property from the connection so that HD audio related
+ * UI is not displayed. If {@code true}, keep HD audio property as it is configured.
+ * @hide
+ */
+ public static final String KEY_DISPLAY_HD_AUDIO_PROPERTY_BOOL =
+ "display_hd_audio_property_bool";
+
+ /**
* Determines whether video conference calls are supported by a carrier. When {@code true},
* video calls can be merged into conference calls, {@code false} otherwiwse.
* <p>
@@ -1072,6 +1088,7 @@
sDefaults.putBoolean(KEY_ENABLE_DIALER_KEY_VIBRATION_BOOL, true);
sDefaults.putBoolean(KEY_HAS_IN_CALL_NOISE_SUPPRESSION_BOOL, false);
sDefaults.putBoolean(KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL, false);
+ sDefaults.putBoolean(KEY_SIMPLIFIED_NETWORK_SETTINGS_BOOL, false);
sDefaults.putBoolean(KEY_HIDE_SIM_LOCK_SETTINGS_BOOL, false);
sDefaults.putBoolean(KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL, false);
sDefaults.putBoolean(KEY_OPERATOR_SELECTION_EXPAND_BOOL, true);
@@ -1146,6 +1163,7 @@
sDefaults.putInt(KEY_CDMA_3WAYCALL_FLASH_DELAY_INT , 0);
sDefaults.putBoolean(KEY_SUPPORT_CONFERENCE_CALL_BOOL, true);
sDefaults.putBoolean(KEY_SUPPORT_VIDEO_CONFERENCE_CALL_BOOL, false);
+ sDefaults.putBoolean(KEY_DISPLAY_HD_AUDIO_PROPERTY_BOOL, true);
sDefaults.putBoolean(KEY_EDITABLE_ENHANCED_4G_LTE_BOOL, true);
sDefaults.putBoolean(KEY_HIDE_IMS_APN_BOOL, false);
sDefaults.putBoolean(KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL, false);
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index 000abff..45d0576 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -1824,21 +1824,14 @@
public static final int SIM_STATE_NETWORK_LOCKED = 4;
/** SIM card state: Ready */
public static final int SIM_STATE_READY = 5;
- /** SIM card state: SIM Card is NOT READY
- *@hide
- */
+ /** SIM card state: SIM Card is NOT READY */
public static final int SIM_STATE_NOT_READY = 6;
- /** SIM card state: SIM Card Error, permanently disabled
- *@hide
- */
+ /** SIM card state: SIM Card Error, permanently disabled */
public static final int SIM_STATE_PERM_DISABLED = 7;
- /** SIM card state: SIM Card Error, present but faulty
- *@hide
- */
+ /** SIM card state: SIM Card Error, present but faulty */
public static final int SIM_STATE_CARD_IO_ERROR = 8;
/** SIM card state: SIM Card restricted, present but not usable due to
* carrier restrictions.
- *@hide
*/
public static final int SIM_STATE_CARD_RESTRICTED = 9;
@@ -1884,6 +1877,7 @@
* @see #SIM_STATE_NOT_READY
* @see #SIM_STATE_PERM_DISABLED
* @see #SIM_STATE_CARD_IO_ERROR
+ * @see #SIM_STATE_CARD_RESTRICTED
*/
public int getSimState() {
int slotIdx = getDefaultSim();
@@ -1921,8 +1915,8 @@
* @see #SIM_STATE_NOT_READY
* @see #SIM_STATE_PERM_DISABLED
* @see #SIM_STATE_CARD_IO_ERROR
+ * @see #SIM_STATE_CARD_RESTRICTED
*/
- /** {@hide} */
public int getSimState(int slotIdx) {
int simState = SubscriptionManager.getSimStateForSlotIdx(slotIdx);
return simState;
diff --git a/test-runner/Android.mk b/test-runner/Android.mk
index a317994..0e9a485 100644
--- a/test-runner/Android.mk
+++ b/test-runner/Android.mk
@@ -21,7 +21,6 @@
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_JAVA_LIBRARIES := core-oj core-libart junit framework
-LOCAL_STATIC_JAVA_LIBRARIES := junit-runner
LOCAL_MODULE:= android.test.runner
diff --git a/test-runner/src/junit/MODULE_LICENSE_CPL b/test-runner/src/junit/MODULE_LICENSE_CPL
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test-runner/src/junit/MODULE_LICENSE_CPL
diff --git a/test-runner/src/junit/README.android b/test-runner/src/junit/README.android
new file mode 100644
index 0000000..1384a1f
--- /dev/null
+++ b/test-runner/src/junit/README.android
@@ -0,0 +1,11 @@
+URL: https://github.com/junit-team/junit4
+License: Common Public License Version 1.0
+License File: cpl-v10.html
+
+This is JUnit 4.10 source that was previously part of the Android Public API.
+Where necessary it has been patched to be compatible (according to Android API
+requirements) with JUnit 3.8.
+
+These are copied here to ensure that the android.test.runner target remains
+compatible with the last version of the Android API (25) that contained these
+classes even when external/junit is upgraded to a later version.
diff --git a/test-runner/src/junit/cpl-v10.html b/test-runner/src/junit/cpl-v10.html
new file mode 100644
index 0000000..36aa208
--- /dev/null
+++ b/test-runner/src/junit/cpl-v10.html
@@ -0,0 +1,125 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<HTML>
+<HEAD>
+<TITLE>Common Public License - v 1.0</TITLE>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</HEAD>
+
+<BODY BGCOLOR="#FFFFFF" VLINK="#800000">
+
+
+<P ALIGN="CENTER"><B>Common Public License - v 1.0</B>
+<P><B></B><FONT SIZE="3"></FONT>
+<P><FONT SIZE="3"></FONT><FONT SIZE="2">THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.</FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"><B>1. DEFINITIONS</B></FONT>
+<P><FONT SIZE="2">"Contribution" means:</FONT>
+
+<UL><FONT SIZE="2">a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and<BR CLEAR="LEFT">
+b) in the case of each subsequent Contributor:</FONT></UL>
+
+
+<UL><FONT SIZE="2">i) changes to the Program, and</FONT></UL>
+
+
+<UL><FONT SIZE="2">ii) additions to the Program;</FONT></UL>
+
+
+<UL><FONT SIZE="2">where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. </FONT><FONT SIZE="2">A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. </FONT><FONT SIZE="2">Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. </FONT></UL>
+
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">"Contributor" means any person or entity that distributes the Program.</FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. </FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2">"Program" means the Contributions distributed in accordance with this Agreement.</FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.</FONT>
+<P><FONT SIZE="2"><B></B></FONT>
+<P><FONT SIZE="2"><B>2. GRANT OF RIGHTS</B></FONT>
+
+<UL><FONT SIZE="2"></FONT><FONT SIZE="2">a) </FONT><FONT SIZE="2">Subject to the terms of this Agreement, each Contributor hereby grants</FONT><FONT SIZE="2"> Recipient a non-exclusive, worldwide, royalty-free copyright license to</FONT><FONT SIZE="2" COLOR="#FF0000"> </FONT><FONT SIZE="2">reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.</FONT></UL>
+
+
+<UL><FONT SIZE="2"></FONT></UL>
+
+
+<UL><FONT SIZE="2"></FONT><FONT SIZE="2">b) Subject to the terms of this Agreement, each Contributor hereby grants </FONT><FONT SIZE="2">Recipient a non-exclusive, worldwide,</FONT><FONT SIZE="2" COLOR="#008000"> </FONT><FONT SIZE="2">royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. </FONT></UL>
+
+
+<UL><FONT SIZE="2"></FONT></UL>
+
+
+<UL><FONT SIZE="2">c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.</FONT></UL>
+
+
+<UL><FONT SIZE="2"></FONT></UL>
+
+
+<UL><FONT SIZE="2">d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. </FONT></UL>
+
+
+<UL><FONT SIZE="2"></FONT></UL>
+
+<P><FONT SIZE="2"><B>3. REQUIREMENTS</B></FONT>
+<P><FONT SIZE="2"><B></B>A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:</FONT>
+
+<UL><FONT SIZE="2">a) it complies with the terms and conditions of this Agreement; and</FONT></UL>
+
+
+<UL><FONT SIZE="2">b) its license agreement:</FONT></UL>
+
+
+<UL><FONT SIZE="2">i) effectively disclaims</FONT><FONT SIZE="2"> on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; </FONT></UL>
+
+
+<UL><FONT SIZE="2">ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; </FONT></UL>
+
+
+<UL><FONT SIZE="2">iii)</FONT><FONT SIZE="2"> states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and</FONT></UL>
+
+
+<UL><FONT SIZE="2">iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.</FONT><FONT SIZE="2" COLOR="#0000FF"> </FONT><FONT SIZE="2" COLOR="#FF0000"></FONT></UL>
+
+
+<UL><FONT SIZE="2" COLOR="#FF0000"></FONT><FONT SIZE="2"></FONT></UL>
+
+<P><FONT SIZE="2">When the Program is made available in source code form:</FONT>
+
+<UL><FONT SIZE="2">a) it must be made available under this Agreement; and </FONT></UL>
+
+
+<UL><FONT SIZE="2">b) a copy of this Agreement must be included with each copy of the Program. </FONT></UL>
+
+<P><FONT SIZE="2"></FONT><FONT SIZE="2" COLOR="#0000FF"><STRIKE></STRIKE></FONT>
+<P><FONT SIZE="2" COLOR="#0000FF"><STRIKE></STRIKE></FONT><FONT SIZE="2">Contributors may not remove or alter any copyright notices contained within the Program. </FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. </FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"><B>4. COMMERCIAL DISTRIBUTION</B></FONT>
+<P><FONT SIZE="2">Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.</FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.</FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2" COLOR="#0000FF"></FONT>
+<P><FONT SIZE="2" COLOR="#0000FF"></FONT><FONT SIZE="2"><B>5. NO WARRANTY</B></FONT>
+<P><FONT SIZE="2">EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is</FONT><FONT SIZE="2"> solely responsible for determining the appropriateness of using and distributing </FONT><FONT SIZE="2">the Program</FONT><FONT SIZE="2"> and assumes all risks associated with its exercise of rights under this Agreement</FONT><FONT SIZE="2">, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, </FONT><FONT SIZE="2">programs or equipment, and unavailability or interruption of operations</FONT><FONT SIZE="2">. </FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2"><B>6. DISCLAIMER OF LIABILITY</B></FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2">EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES </FONT><FONT SIZE="2">(INCLUDING WITHOUT LIMITATION LOST PROFITS),</FONT><FONT SIZE="2"> HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"><B>7. GENERAL</B></FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2">If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.</FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">If Recipient institutes patent litigation against a Contributor with respect to a patent applicable to software (including a cross-claim or counterclaim in a lawsuit), then any patent licenses granted by that Contributor to such Recipient under this Agreement shall terminate as of the date such litigation is filed. In addition, if Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. </FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. </FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2">Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to </FONT><FONT SIZE="2">publish new versions (including revisions) of this Agreement from time to </FONT><FONT SIZE="2">time. No one other than the Agreement Steward has the right to modify this Agreement. IBM is the initial Agreement Steward. IBM may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. </FONT><FONT SIZE="2">Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new </FONT><FONT SIZE="2">version. </FONT><FONT SIZE="2">Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, </FONT><FONT SIZE="2">by implication, estoppel or otherwise</FONT><FONT SIZE="2">.</FONT><FONT SIZE="2"> All rights in the Program not expressly granted under this Agreement are reserved.</FONT>
+<P><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2">This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.</FONT>
+<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT>
+<P><FONT SIZE="2"></FONT>
+
+</BODY>
+
+</HTML>
\ No newline at end of file
diff --git a/test-runner/src/junit/runner/BaseTestRunner.java b/test-runner/src/junit/runner/BaseTestRunner.java
new file mode 100644
index 0000000..e7e0431
--- /dev/null
+++ b/test-runner/src/junit/runner/BaseTestRunner.java
@@ -0,0 +1,340 @@
+package junit.runner;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.text.NumberFormat;
+import java.util.Properties;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import junit.framework.TestListener;
+import junit.framework.TestSuite;
+
+/**
+ * Base class for all test runners.
+ * This class was born live on stage in Sardinia during XP2000.
+ */
+public abstract class BaseTestRunner implements TestListener {
+ public static final String SUITE_METHODNAME= "suite";
+
+ private static Properties fPreferences;
+ static int fgMaxMessageLength= 500;
+ static boolean fgFilterStack= true;
+ boolean fLoading= true;
+
+ /*
+ * Implementation of TestListener
+ */
+ public synchronized void startTest(Test test) {
+ testStarted(test.toString());
+ }
+
+ protected static void setPreferences(Properties preferences) {
+ fPreferences= preferences;
+ }
+
+ protected static Properties getPreferences() {
+ if (fPreferences == null) {
+ fPreferences= new Properties();
+ fPreferences.put("loading", "true");
+ fPreferences.put("filterstack", "true");
+ readPreferences();
+ }
+ return fPreferences;
+ }
+
+ public static void savePreferences() throws IOException {
+ FileOutputStream fos= new FileOutputStream(getPreferencesFile());
+ try {
+ getPreferences().store(fos, "");
+ } finally {
+ fos.close();
+ }
+ }
+
+ // android-changed remove 'static' qualifier for API compatibility
+ public void setPreference(String key, String value) {
+ getPreferences().put(key, value);
+ }
+
+ public synchronized void endTest(Test test) {
+ testEnded(test.toString());
+ }
+
+ public synchronized void addError(final Test test, final Throwable t) {
+ testFailed(TestRunListener.STATUS_ERROR, test, t);
+ }
+
+ public synchronized void addFailure(final Test test, final AssertionFailedError t) {
+ testFailed(TestRunListener.STATUS_FAILURE, test, t);
+ }
+
+ // TestRunListener implementation
+
+ public abstract void testStarted(String testName);
+
+ public abstract void testEnded(String testName);
+
+ public abstract void testFailed(int status, Test test, Throwable t);
+
+ /**
+ * Returns the Test corresponding to the given suite. This is
+ * a template method, subclasses override runFailed(), clearStatus().
+ */
+ public Test getTest(String suiteClassName) {
+ if (suiteClassName.length() <= 0) {
+ clearStatus();
+ return null;
+ }
+ Class<?> testClass= null;
+ try {
+ testClass= loadSuiteClass(suiteClassName);
+ } catch (ClassNotFoundException e) {
+ String clazz= e.getMessage();
+ if (clazz == null)
+ clazz= suiteClassName;
+ runFailed("Class not found \""+clazz+"\"");
+ return null;
+ } catch(Exception e) {
+ runFailed("Error: "+e.toString());
+ return null;
+ }
+ Method suiteMethod= null;
+ try {
+ suiteMethod= testClass.getMethod(SUITE_METHODNAME, new Class[0]);
+ } catch(Exception e) {
+ // try to extract a test suite automatically
+ clearStatus();
+ return new TestSuite(testClass);
+ }
+ if (! Modifier.isStatic(suiteMethod.getModifiers())) {
+ runFailed("Suite() method must be static");
+ return null;
+ }
+ Test test= null;
+ try {
+ test= (Test)suiteMethod.invoke(null, (Object[])new Class[0]); // static method
+ if (test == null)
+ return test;
+ }
+ catch (InvocationTargetException e) {
+ runFailed("Failed to invoke suite():" + e.getTargetException().toString());
+ return null;
+ }
+ catch (IllegalAccessException e) {
+ runFailed("Failed to invoke suite():" + e.toString());
+ return null;
+ }
+
+ clearStatus();
+ return test;
+ }
+
+ /**
+ * Returns the formatted string of the elapsed time.
+ */
+ public String elapsedTimeAsString(long runTime) {
+ return NumberFormat.getInstance().format((double)runTime/1000);
+ }
+
+ /**
+ * Processes the command line arguments and
+ * returns the name of the suite class to run or null
+ */
+ protected String processArguments(String[] args) {
+ String suiteName= null;
+ for (int i= 0; i < args.length; i++) {
+ if (args[i].equals("-noloading")) {
+ setLoading(false);
+ } else if (args[i].equals("-nofilterstack")) {
+ fgFilterStack= false;
+ } else if (args[i].equals("-c")) {
+ if (args.length > i+1)
+ suiteName= extractClassName(args[i+1]);
+ else
+ System.out.println("Missing Test class name");
+ i++;
+ } else {
+ suiteName= args[i];
+ }
+ }
+ return suiteName;
+ }
+
+ /**
+ * Sets the loading behaviour of the test runner
+ */
+ public void setLoading(boolean enable) {
+ fLoading= enable;
+ }
+ /**
+ * Extract the class name from a String in VA/Java style
+ */
+ public String extractClassName(String className) {
+ if(className.startsWith("Default package for"))
+ return className.substring(className.lastIndexOf(".")+1);
+ return className;
+ }
+
+ /**
+ * Truncates a String to the maximum length.
+ */
+ public static String truncate(String s) {
+ if (fgMaxMessageLength != -1 && s.length() > fgMaxMessageLength)
+ s= s.substring(0, fgMaxMessageLength)+"...";
+ return s;
+ }
+
+ /**
+ * Override to define how to handle a failed loading of
+ * a test suite.
+ */
+ protected abstract void runFailed(String message);
+
+ // BEGIN android-changed - add back getLoader() for API compatibility
+ /**
+ * Returns the loader to be used.
+ *
+ * @deprecated not present in JUnit4.10
+ */
+ public TestSuiteLoader getLoader() {
+ return new StandardTestSuiteLoader();
+ }
+ // END android-changed
+
+ /**
+ * Returns the loaded Class for a suite name.
+ */
+ protected Class<?> loadSuiteClass(String suiteClassName) throws ClassNotFoundException {
+ return Class.forName(suiteClassName);
+ }
+
+ /**
+ * Clears the status message.
+ */
+ protected void clearStatus() { // Belongs in the GUI TestRunner class
+ }
+
+ protected boolean useReloadingTestSuiteLoader() {
+ return getPreference("loading").equals("true") && fLoading;
+ }
+
+ private static File getPreferencesFile() {
+ String home= System.getProperty("user.home");
+ return new File(home, "junit.properties");
+ }
+
+ private static void readPreferences() {
+ InputStream is= null;
+ try {
+ is= new FileInputStream(getPreferencesFile());
+ setPreferences(new Properties(getPreferences()));
+ getPreferences().load(is);
+ } catch (IOException e) {
+ try {
+ if (is != null)
+ is.close();
+ } catch (IOException e1) {
+ }
+ }
+ }
+
+ public static String getPreference(String key) {
+ return getPreferences().getProperty(key);
+ }
+
+ public static int getPreference(String key, int dflt) {
+ String value= getPreference(key);
+ int intValue= dflt;
+ if (value == null)
+ return intValue;
+ try {
+ intValue= Integer.parseInt(value);
+ } catch (NumberFormatException ne) {
+ }
+ return intValue;
+ }
+
+ /**
+ * Returns a filtered stack trace
+ */
+ public static String getFilteredTrace(Throwable t) {
+ StringWriter stringWriter= new StringWriter();
+ PrintWriter writer= new PrintWriter(stringWriter);
+ t.printStackTrace(writer);
+ StringBuffer buffer= stringWriter.getBuffer();
+ String trace= buffer.toString();
+ return BaseTestRunner.getFilteredTrace(trace);
+ }
+
+ // BEGIN android-changed - add back this method for API compatibility
+ /** @deprecated not present in JUnit4.10 */
+ public static boolean inVAJava() {
+ return false;
+ }
+ // END android-changed
+
+ /**
+ * Filters stack frames from internal JUnit classes
+ */
+ public static String getFilteredTrace(String stack) {
+ if (showStackRaw())
+ return stack;
+
+ StringWriter sw= new StringWriter();
+ PrintWriter pw= new PrintWriter(sw);
+ StringReader sr= new StringReader(stack);
+ // BEGIN android-changed
+ // Use a sensible default buffer size
+ BufferedReader br= new BufferedReader(sr, 1000);
+ // END android-changed
+
+ String line;
+ try {
+ while ((line= br.readLine()) != null) {
+ if (!filterLine(line))
+ pw.println(line);
+ }
+ } catch (Exception IOException) {
+ return stack; // return the stack unfiltered
+ }
+ return sw.toString();
+ }
+
+ protected static boolean showStackRaw() {
+ return !getPreference("filterstack").equals("true") || fgFilterStack == false;
+ }
+
+ static boolean filterLine(String line) {
+ String[] patterns= new String[] {
+ "junit.framework.TestCase",
+ "junit.framework.TestResult",
+ "junit.framework.TestSuite",
+ "junit.framework.Assert.", // don't filter AssertionFailure
+ "junit.swingui.TestRunner",
+ "junit.awtui.TestRunner",
+ "junit.textui.TestRunner",
+ "java.lang.reflect.Method.invoke("
+ };
+ for (int i= 0; i < patterns.length; i++) {
+ if (line.indexOf(patterns[i]) > 0)
+ return true;
+ }
+ return false;
+ }
+
+ static {
+ fgMaxMessageLength= getPreference("maxmessage", fgMaxMessageLength);
+ }
+
+}
diff --git a/test-runner/src/junit/runner/StandardTestSuiteLoader.java b/test-runner/src/junit/runner/StandardTestSuiteLoader.java
new file mode 100644
index 0000000..808963a
--- /dev/null
+++ b/test-runner/src/junit/runner/StandardTestSuiteLoader.java
@@ -0,0 +1,23 @@
+package junit.runner;
+
+// android-changed - class not present in upstream JUnit 4.10
+// added here to retain BaseTestRunner.getLoader API
+
+/**
+ * The standard test suite loader. It can only load the same class once.
+ * {@hide}
+ */
+public class StandardTestSuiteLoader implements TestSuiteLoader {
+ /**
+ * Uses the system class loader to load the test class
+ */
+ public Class load(String suiteClassName) throws ClassNotFoundException {
+ return Class.forName(suiteClassName);
+ }
+ /**
+ * Uses the system class loader to load the test class
+ */
+ public Class reload(Class aClass) throws ClassNotFoundException {
+ return aClass;
+ }
+}
diff --git a/test-runner/src/junit/runner/TestRunListener.java b/test-runner/src/junit/runner/TestRunListener.java
new file mode 100644
index 0000000..0e95819
--- /dev/null
+++ b/test-runner/src/junit/runner/TestRunListener.java
@@ -0,0 +1,20 @@
+package junit.runner;
+/**
+ * A listener interface for observing the
+ * execution of a test run. Unlike TestListener,
+ * this interface using only primitive objects,
+ * making it suitable for remote test execution.
+ * {@hide} - Not needed for 1.0 SDK
+ */
+ public interface TestRunListener {
+ /* test status constants*/
+ public static final int STATUS_ERROR= 1;
+ public static final int STATUS_FAILURE= 2;
+
+ public void testRunStarted(String testSuiteName, int testCount);
+ public void testRunEnded(long elapsedTime);
+ public void testRunStopped(long elapsedTime);
+ public void testStarted(String testName);
+ public void testEnded(String testName);
+ public void testFailed(int status, String testName, String trace);
+}
diff --git a/test-runner/src/junit/runner/TestSuiteLoader.java b/test-runner/src/junit/runner/TestSuiteLoader.java
new file mode 100644
index 0000000..9cc6d81
--- /dev/null
+++ b/test-runner/src/junit/runner/TestSuiteLoader.java
@@ -0,0 +1,11 @@
+package junit.runner;
+
+/**
+ * An interface to define how a test suite should be loaded.
+ *
+ */
+// TODO: deprecate
+public interface TestSuiteLoader {
+ abstract public Class load(String suiteClassName) throws ClassNotFoundException;
+ abstract public Class reload(Class aClass) throws ClassNotFoundException;
+}
diff --git a/test-runner/src/junit/runner/Version.java b/test-runner/src/junit/runner/Version.java
new file mode 100644
index 0000000..dd88c03
--- /dev/null
+++ b/test-runner/src/junit/runner/Version.java
@@ -0,0 +1,20 @@
+package junit.runner;
+
+/**
+ * This class defines the current version of JUnit
+ */
+public class Version {
+ private Version() {
+ // don't instantiate
+ }
+
+ public static String id() {
+ return "4.10";
+ }
+
+ // android-changed
+ /** @hide - not needed for public API */
+ public static void main(String[] args) {
+ System.out.println(id());
+ }
+}
diff --git a/test-runner/src/junit/runner/package-info.java b/test-runner/src/junit/runner/package-info.java
new file mode 100644
index 0000000..b746185
--- /dev/null
+++ b/test-runner/src/junit/runner/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Provides JUnit v3.x test runners.
+ */
+package junit.runner;
\ No newline at end of file
diff --git a/test-runner/src/junit/runner/package.html b/test-runner/src/junit/runner/package.html
new file mode 100644
index 0000000..f08fa70
--- /dev/null
+++ b/test-runner/src/junit/runner/package.html
@@ -0,0 +1,5 @@
+<HTML>
+<BODY>
+Utility classes supporting the junit test framework.
+</BODY>
+</HTML>
diff --git a/test-runner/src/junit/textui/ResultPrinter.java b/test-runner/src/junit/textui/ResultPrinter.java
new file mode 100644
index 0000000..b4914529
--- /dev/null
+++ b/test-runner/src/junit/textui/ResultPrinter.java
@@ -0,0 +1,144 @@
+
+package junit.textui;
+
+import java.io.PrintStream;
+// android-changed
+// The following line was removed for compatibility with Android libraries.
+// import java.text.NumberFormat;
+import java.util.Enumeration;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import junit.framework.TestFailure;
+import junit.framework.TestListener;
+import junit.framework.TestResult;
+import junit.runner.BaseTestRunner;
+
+public class ResultPrinter implements TestListener {
+ PrintStream fWriter;
+ int fColumn= 0;
+
+ public ResultPrinter(PrintStream writer) {
+ fWriter= writer;
+ }
+
+ /* API for use by textui.TestRunner
+ */
+
+ synchronized void print(TestResult result, long runTime) {
+ printHeader(runTime);
+ printErrors(result);
+ printFailures(result);
+ printFooter(result);
+ }
+
+ void printWaitPrompt() {
+ getWriter().println();
+ getWriter().println("<RETURN> to continue");
+ }
+
+ /* Internal methods
+ */
+
+ protected void printHeader(long runTime) {
+ getWriter().println();
+ getWriter().println("Time: "+elapsedTimeAsString(runTime));
+ }
+
+ protected void printErrors(TestResult result) {
+ printDefects(result.errors(), result.errorCount(), "error");
+ }
+
+ protected void printFailures(TestResult result) {
+ printDefects(result.failures(), result.failureCount(), "failure");
+ }
+
+ protected void printDefects(Enumeration<TestFailure> booBoos, int count, String type) {
+ if (count == 0) return;
+ if (count == 1)
+ getWriter().println("There was " + count + " " + type + ":");
+ else
+ getWriter().println("There were " + count + " " + type + "s:");
+ for (int i= 1; booBoos.hasMoreElements(); i++) {
+ printDefect(booBoos.nextElement(), i);
+ }
+ }
+
+ public void printDefect(TestFailure booBoo, int count) { // only public for testing purposes
+ printDefectHeader(booBoo, count);
+ printDefectTrace(booBoo);
+ }
+
+ protected void printDefectHeader(TestFailure booBoo, int count) {
+ // I feel like making this a println, then adding a line giving the throwable a chance to print something
+ // before we get to the stack trace.
+ getWriter().print(count + ") " + booBoo.failedTest());
+ }
+
+ protected void printDefectTrace(TestFailure booBoo) {
+ getWriter().print(BaseTestRunner.getFilteredTrace(booBoo.trace()));
+ }
+
+ protected void printFooter(TestResult result) {
+ if (result.wasSuccessful()) {
+ getWriter().println();
+ getWriter().print("OK");
+ getWriter().println (" (" + result.runCount() + " test" + (result.runCount() == 1 ? "": "s") + ")");
+
+ } else {
+ getWriter().println();
+ getWriter().println("FAILURES!!!");
+ getWriter().println("Tests run: "+result.runCount()+
+ ", Failures: "+result.failureCount()+
+ ", Errors: "+result.errorCount());
+ }
+ getWriter().println();
+ }
+
+
+ /**
+ * Returns the formatted string of the elapsed time.
+ * Duplicated from BaseTestRunner. Fix it.
+ */
+ protected String elapsedTimeAsString(long runTime) {
+ // android-changed
+ // The following line was altered for compatibility with
+ // Android libraries.
+ return Double.toString((double)runTime/1000);
+ }
+
+ public PrintStream getWriter() {
+ return fWriter;
+ }
+ /**
+ * @see junit.framework.TestListener#addError(Test, Throwable)
+ */
+ public void addError(Test test, Throwable t) {
+ getWriter().print("E");
+ }
+
+ /**
+ * @see junit.framework.TestListener#addFailure(Test, AssertionFailedError)
+ */
+ public void addFailure(Test test, AssertionFailedError t) {
+ getWriter().print("F");
+ }
+
+ /**
+ * @see junit.framework.TestListener#endTest(Test)
+ */
+ public void endTest(Test test) {
+ }
+
+ /**
+ * @see junit.framework.TestListener#startTest(Test)
+ */
+ public void startTest(Test test) {
+ getWriter().print(".");
+ if (fColumn++ >= 40) {
+ getWriter().println();
+ fColumn= 0;
+ }
+ }
+
+}
diff --git a/test-runner/src/junit/textui/TestRunner.java b/test-runner/src/junit/textui/TestRunner.java
new file mode 100644
index 0000000..046448e
--- /dev/null
+++ b/test-runner/src/junit/textui/TestRunner.java
@@ -0,0 +1,203 @@
+package junit.textui;
+
+
+import java.io.PrintStream;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
+import junit.runner.BaseTestRunner;
+import junit.runner.Version;
+
+/**
+ * A command line based tool to run tests.
+ * <pre>
+ * java junit.textui.TestRunner [-wait] TestCaseClass
+ * </pre>
+ *
+ * <p>TestRunner expects the name of a TestCase class as argument.
+ * If this class defines a static <code>suite</code> method it
+ * will be invoked and the returned test is run. Otherwise all
+ * the methods starting with "test" having no arguments are run.</p>
+ *
+ * <p> When the wait command line argument is given TestRunner
+ * waits until the users types RETURN.</p>
+ *
+ * <p>TestRunner prints a trace as the tests are executed followed by a
+ * summary at the end.</p>
+ */
+public class TestRunner extends BaseTestRunner {
+ private ResultPrinter fPrinter;
+
+ public static final int SUCCESS_EXIT= 0;
+ public static final int FAILURE_EXIT= 1;
+ public static final int EXCEPTION_EXIT= 2;
+
+ /**
+ * Constructs a TestRunner.
+ */
+ public TestRunner() {
+ this(System.out);
+ }
+
+ /**
+ * Constructs a TestRunner using the given stream for all the output
+ */
+ public TestRunner(PrintStream writer) {
+ this(new ResultPrinter(writer));
+ }
+
+ /**
+ * Constructs a TestRunner using the given ResultPrinter all the output
+ */
+ public TestRunner(ResultPrinter printer) {
+ fPrinter= printer;
+ }
+
+ /**
+ * Runs a suite extracted from a TestCase subclass.
+ */
+ static public void run(Class<? extends TestCase> testClass) {
+ run(new TestSuite(testClass));
+ }
+
+ /**
+ * Runs a single test and collects its results.
+ * This method can be used to start a test run
+ * from your program.
+ * <pre>
+ * public static void main (String[] args) {
+ * test.textui.TestRunner.run(suite());
+ * }
+ * </pre>
+ */
+ static public TestResult run(Test test) {
+ TestRunner runner= new TestRunner();
+ return runner.doRun(test);
+ }
+
+ /**
+ * Runs a single test and waits until the user
+ * types RETURN.
+ */
+ static public void runAndWait(Test suite) {
+ TestRunner aTestRunner= new TestRunner();
+ aTestRunner.doRun(suite, true);
+ }
+
+ @Override
+ public void testFailed(int status, Test test, Throwable t) {
+ }
+
+ @Override
+ public void testStarted(String testName) {
+ }
+
+ @Override
+ public void testEnded(String testName) {
+ }
+
+ /**
+ * Creates the TestResult to be used for the test run.
+ */
+ protected TestResult createTestResult() {
+ return new TestResult();
+ }
+
+ public TestResult doRun(Test test) {
+ return doRun(test, false);
+ }
+
+ public TestResult doRun(Test suite, boolean wait) {
+ TestResult result= createTestResult();
+ result.addListener(fPrinter);
+ long startTime= System.currentTimeMillis();
+ suite.run(result);
+ long endTime= System.currentTimeMillis();
+ long runTime= endTime-startTime;
+ fPrinter.print(result, runTime);
+
+ pause(wait);
+ return result;
+ }
+
+ protected void pause(boolean wait) {
+ if (!wait) return;
+ fPrinter.printWaitPrompt();
+ try {
+ System.in.read();
+ }
+ catch(Exception e) {
+ }
+ }
+
+ public static void main(String args[]) {
+ TestRunner aTestRunner= new TestRunner();
+ try {
+ TestResult r= aTestRunner.start(args);
+ if (!r.wasSuccessful())
+ System.exit(FAILURE_EXIT);
+ System.exit(SUCCESS_EXIT);
+ } catch(Exception e) {
+ System.err.println(e.getMessage());
+ System.exit(EXCEPTION_EXIT);
+ }
+ }
+
+ /**
+ * Starts a test run. Analyzes the command line arguments and runs the given
+ * test suite.
+ */
+ public TestResult start(String args[]) throws Exception {
+ String testCase= "";
+ String method= "";
+ boolean wait= false;
+
+ for (int i= 0; i < args.length; i++) {
+ if (args[i].equals("-wait"))
+ wait= true;
+ else if (args[i].equals("-c"))
+ testCase= extractClassName(args[++i]);
+ else if (args[i].equals("-m")) {
+ String arg= args[++i];
+ int lastIndex= arg.lastIndexOf('.');
+ testCase= arg.substring(0, lastIndex);
+ method= arg.substring(lastIndex + 1);
+ } else if (args[i].equals("-v"))
+ System.err.println("JUnit " + Version.id() + " by Kent Beck and Erich Gamma");
+ else
+ testCase= args[i];
+ }
+
+ if (testCase.equals(""))
+ throw new Exception("Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class");
+
+ try {
+ if (!method.equals(""))
+ return runSingleMethod(testCase, method, wait);
+ Test suite= getTest(testCase);
+ return doRun(suite, wait);
+ } catch (Exception e) {
+ throw new Exception("Could not create and run test suite: " + e);
+ }
+ }
+
+ protected TestResult runSingleMethod(String testCase, String method, boolean wait) throws Exception {
+ Class<? extends TestCase> testClass= loadSuiteClass(testCase).asSubclass(TestCase.class);
+ Test test= TestSuite.createTest(testClass, method);
+ return doRun(test, wait);
+ }
+
+ @Override
+ protected void runFailed(String message) {
+ System.err.println(message);
+ System.exit(FAILURE_EXIT);
+ }
+
+ public void setPrinter(ResultPrinter printer) {
+ fPrinter= printer;
+ }
+
+
+}
\ No newline at end of file
diff --git a/test-runner/src/junit/textui/package-info.java b/test-runner/src/junit/textui/package-info.java
new file mode 100644
index 0000000..2dcc10c
--- /dev/null
+++ b/test-runner/src/junit/textui/package-info.java
@@ -0,0 +1,5 @@
+/**
+ * Provides JUnit v3.x command line based tool to run tests.
+ * {@hide}
+ */
+package junit.textui;
\ No newline at end of file
diff --git a/test-runner/src/junit/textui/package.html b/test-runner/src/junit/textui/package.html
new file mode 100644
index 0000000..723f2ae
--- /dev/null
+++ b/test-runner/src/junit/textui/package.html
@@ -0,0 +1,6 @@
+<HTML>
+<BODY>
+Utility classes supporting the junit test framework.
+{@hide} - Not needed for 1.0 SDK
+</BODY>
+</HTML>
diff --git a/tests/net/java/android/net/ConnectivityMetricsLoggerTest.java b/tests/net/java/android/net/ConnectivityMetricsLoggerTest.java
index 6d42cce..f896030 100644
--- a/tests/net/java/android/net/ConnectivityMetricsLoggerTest.java
+++ b/tests/net/java/android/net/ConnectivityMetricsLoggerTest.java
@@ -18,6 +18,7 @@
import android.os.Bundle;
import android.os.Parcel;
+import android.test.suitebuilder.annotation.SmallTest;
import java.util.List;
import junit.framework.TestCase;
import org.mockito.ArgumentCaptor;
@@ -49,6 +50,7 @@
mLog = new ConnectivityMetricsLogger(mService);
}
+ @SmallTest
public void testLogEvents() throws Exception {
mLog.logEvent(1, FAKE_COMPONENT, FAKE_EVENT, FAKE_EV);
mLog.logEvent(2, FAKE_COMPONENT, FAKE_EVENT, FAKE_EV);
@@ -60,6 +62,7 @@
assertEventsEqual(expectedEvent(3), gotEvents.get(2));
}
+ @SmallTest
public void testLogEventTriggerThrottling() throws Exception {
when(mService.logEvent(any())).thenReturn(1234L);
@@ -70,6 +73,7 @@
assertEventsEqual(expectedEvent(1), gotEvents.get(0));
}
+ @SmallTest
public void testLogEventFails() throws Exception {
when(mService.logEvent(any())).thenReturn(-1L); // Error.
@@ -80,6 +84,7 @@
assertEventsEqual(expectedEvent(1), gotEvents.get(0));
}
+ @SmallTest
public void testLogEventWhenThrottling() throws Exception {
when(mService.logEvent(any())).thenReturn(Long.MAX_VALUE); // Throttled
@@ -92,6 +97,7 @@
assertEventsEqual(expectedEvent(1), gotEvents.get(0));
}
+ @SmallTest
public void testLogEventRecoverFromThrottling() throws Exception {
final long throttleTimeout = System.currentTimeMillis() + 10;
when(mService.logEvent(any())).thenReturn(throttleTimeout, 0L);
diff --git a/tests/net/java/android/net/apf/ApfTest.java b/tests/net/java/android/net/apf/ApfTest.java
index 81f66a5..ff61754 100644
--- a/tests/net/java/android/net/apf/ApfTest.java
+++ b/tests/net/java/android/net/apf/ApfTest.java
@@ -33,7 +33,6 @@
import android.system.Os;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
-import android.test.suitebuilder.annotation.MediumTest;
import static android.system.OsConstants.*;
import com.android.frameworks.tests.net.R;
@@ -155,7 +154,7 @@
* generating bytecode for that program and running it through the
* interpreter to verify it functions correctly.
*/
- @MediumTest
+ @SmallTest
public void testApfInstructions() throws IllegalInstructionException {
// Empty program should pass because having the program counter reach the
// location immediately after the program indicates the packet should be
@@ -563,7 +562,7 @@
* Generate some BPF programs, translate them to APF, then run APF and BPF programs
* over packet traces and verify both programs filter out the same packets.
*/
- @MediumTest
+ @SmallTest
public void testApfAgainstBpf() throws Exception {
String[] tcpdump_filters = new String[]{ "udp", "tcp", "icmp", "icmp6", "udp port 53",
"arp", "dst 239.255.255.250", "arp or tcp or udp port 53", "net 192.168.1.0/24",
@@ -662,9 +661,13 @@
// The IPv6 all nodes address ff02::1
private static final byte[] IPV6_ALL_NODES_ADDRESS =
{ (byte) 0xff, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
+ private static final byte[] IPV6_ALL_ROUTERS_ADDRESS =
+ { (byte) 0xff, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 };
private static final int ICMP6_TYPE_OFFSET = ETH_HEADER_LEN + IPV6_HEADER_LEN;
+ private static final int ICMP6_ROUTER_SOLICITATION = 133;
private static final int ICMP6_ROUTER_ADVERTISEMENT = 134;
+ private static final int ICMP6_NEIGHBOR_SOLICITATION = 135;
private static final int ICMP6_NEIGHBOR_ANNOUNCEMENT = 136;
private static final int ICMP6_RA_HEADER_LEN = 16;
@@ -721,7 +724,7 @@
private static final byte[] ANOTHER_IPV4_ADDR = {10, 0, 0, 2};
private static final byte[] IPV4_ANY_HOST_ADDR = {0, 0, 0, 0};
- @MediumTest
+ @SmallTest
public void testApfFilterIPv4() throws Exception {
MockIpManagerCallback ipManagerCallback = new MockIpManagerCallback();
LinkAddress link = new LinkAddress(InetAddress.getByAddress(MOCK_IPV4_ADDR), 19);
@@ -776,7 +779,7 @@
apfFilter.shutdown();
}
- @MediumTest
+ @SmallTest
public void testApfFilterIPv6() throws Exception {
MockIpManagerCallback ipManagerCallback = new MockIpManagerCallback();
ApfFilter apfFilter = new TestApfFilter(ipManagerCallback, ALLOW_MULTICAST, mLog);
@@ -799,10 +802,16 @@
put(packet, IPV6_DEST_ADDR_OFFSET, IPV6_ALL_NODES_ADDRESS);
assertDrop(program, packet.array());
+ // Verify ICMPv6 RS to any is dropped
+ packet.put(ICMP6_TYPE_OFFSET, (byte)ICMP6_ROUTER_SOLICITATION);
+ assertDrop(program, packet.array());
+ put(packet, IPV6_DEST_ADDR_OFFSET, IPV6_ALL_ROUTERS_ADDRESS);
+ assertDrop(program, packet.array());
+
apfFilter.shutdown();
}
- @MediumTest
+ @SmallTest
public void testApfFilterMulticast() throws Exception {
final byte[] unicastIpv4Addr = {(byte)192,0,2,63};
final byte[] broadcastIpv4Addr = {(byte)192,0,2,(byte)255};
@@ -912,7 +921,7 @@
assertDrop(program, garpReply());
}
- @MediumTest
+ @SmallTest
public void testApfFilterArp() throws Exception {
MockIpManagerCallback ipManagerCallback = new MockIpManagerCallback();
ApfFilter apfFilter = new TestApfFilter(ipManagerCallback, ALLOW_MULTICAST, mLog);
@@ -1031,7 +1040,7 @@
ipManagerCallback.assertNoProgramUpdate();
}
- @MediumTest
+ @SmallTest
public void testApfFilterRa() throws Exception {
MockIpManagerCallback ipManagerCallback = new MockIpManagerCallback();
TestApfFilter apfFilter = new TestApfFilter(ipManagerCallback, DROP_MULTICAST, mLog);
diff --git a/tests/net/java/android/net/dhcp/DhcpPacketTest.java b/tests/net/java/android/net/dhcp/DhcpPacketTest.java
index bc8baa1..d79c312 100644
--- a/tests/net/java/android/net/dhcp/DhcpPacketTest.java
+++ b/tests/net/java/android/net/dhcp/DhcpPacketTest.java
@@ -473,6 +473,7 @@
assertEquals(Integer.toHexString(expected), Integer.toHexString(got));
}
+ @SmallTest
public void testTruncatedOfferPackets() throws Exception {
final byte[] packet = HexDump.hexStringToByteArray(
// IP header.
@@ -506,6 +507,7 @@
}
}
+ @SmallTest
public void testRandomPackets() throws Exception {
final int maxRandomPacketSize = 512;
final Random r = new Random();
diff --git a/tests/net/java/android/net/netlink/NetlinkErrorMessageTest.java b/tests/net/java/android/net/netlink/NetlinkErrorMessageTest.java
index e677475..5deba27 100644
--- a/tests/net/java/android/net/netlink/NetlinkErrorMessageTest.java
+++ b/tests/net/java/android/net/netlink/NetlinkErrorMessageTest.java
@@ -24,6 +24,7 @@
import android.net.netlink.NetlinkErrorMessage;
import android.net.netlink.NetlinkMessage;
import android.net.netlink.StructNlMsgErr;
+import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -53,6 +54,7 @@
public static final byte[] NLM_ERROR_OK =
HexEncoding.decode(NLM_ERROR_OK_HEX.toCharArray(), false);
+ @SmallTest
public void testParseNlmErrorOk() {
final ByteBuffer byteBuffer = ByteBuffer.wrap(NLM_ERROR_OK);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); // For testing.
diff --git a/tests/net/java/android/net/netlink/NetlinkSocketTest.java b/tests/net/java/android/net/netlink/NetlinkSocketTest.java
index c599fe3..78b3b70 100644
--- a/tests/net/java/android/net/netlink/NetlinkSocketTest.java
+++ b/tests/net/java/android/net/netlink/NetlinkSocketTest.java
@@ -20,6 +20,7 @@
import android.net.netlink.RtNetlinkNeighborMessage;
import android.net.netlink.StructNdMsg;
import android.net.netlink.StructNlMsgHdr;
+import android.test.suitebuilder.annotation.SmallTest;
import android.system.ErrnoException;
import android.system.NetlinkSocketAddress;
import android.system.OsConstants;
@@ -33,6 +34,7 @@
public class NetlinkSocketTest extends TestCase {
private final String TAG = "NetlinkSocketTest";
+ @SmallTest
public void testBasicWorkingGetNeighborsQuery() throws Exception {
NetlinkSocket s = new NetlinkSocket(OsConstants.NETLINK_ROUTE);
assertNotNull(s);
@@ -91,6 +93,7 @@
s.close();
}
+ @SmallTest
public void testRepeatedCloseCallsAreQuiet() throws Exception {
// Create a working NetlinkSocket.
NetlinkSocket s = new NetlinkSocket(OsConstants.NETLINK_ROUTE);
diff --git a/tests/net/java/android/net/netlink/RtNetlinkNeighborMessageTest.java b/tests/net/java/android/net/netlink/RtNetlinkNeighborMessageTest.java
index 19ee000..029758e 100644
--- a/tests/net/java/android/net/netlink/RtNetlinkNeighborMessageTest.java
+++ b/tests/net/java/android/net/netlink/RtNetlinkNeighborMessageTest.java
@@ -21,12 +21,13 @@
import android.net.netlink.RtNetlinkNeighborMessage;
import android.net.netlink.StructNdMsg;
import android.net.netlink.StructNlMsgHdr;
+import android.test.suitebuilder.annotation.SmallTest;
import android.system.OsConstants;
import android.util.Log;
import libcore.util.HexEncoding;
-import java.net.InetAddress;
import java.net.Inet4Address;
+import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -135,6 +136,7 @@
public static final byte[] RTM_GETNEIGH_RESPONSE =
HexEncoding.decode(RTM_GETNEIGH_RESPONSE_HEX.replaceAll(" ", "").toCharArray(), false);
+ @SmallTest
public void testParseRtmDelNeigh() {
final ByteBuffer byteBuffer = ByteBuffer.wrap(RTM_DELNEIGH);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); // For testing.
@@ -161,6 +163,7 @@
assertEquals(InetAddress.parseNumericAddress("192.168.159.254"), destination);
}
+ @SmallTest
public void testParseRtmNewNeigh() {
final ByteBuffer byteBuffer = ByteBuffer.wrap(RTM_NEWNEIGH);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); // For testing.
@@ -187,6 +190,7 @@
assertEquals(InetAddress.parseNumericAddress("fe80::86c9:b2ff:fe6a:ed4b"), destination);
}
+ @SmallTest
public void testParseRtmGetNeighResponse() {
final ByteBuffer byteBuffer = ByteBuffer.wrap(RTM_GETNEIGH_RESPONSE);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); // For testing.
@@ -211,6 +215,7 @@
assertEquals(14, messageCount);
}
+ @SmallTest
public void testCreateRtmNewNeighMessage() {
final int seqNo = 2635;
final int ifIndex = 14;
diff --git a/tests/net/java/com/android/server/ConnectivityServiceTest.java b/tests/net/java/com/android/server/ConnectivityServiceTest.java
index fc8cc81..d62c30d 100644
--- a/tests/net/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/net/java/com/android/server/ConnectivityServiceTest.java
@@ -70,7 +70,6 @@
import android.test.AndroidTestCase;
import android.test.FlakyTest;
import android.test.mock.MockContentResolver;
-import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log;
import android.util.LogPrinter;
@@ -91,6 +90,7 @@
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.BooleanSupplier;
/**
* Tests for {@link ConnectivityService}.
@@ -195,6 +195,7 @@
}
// Tests that IdleableHandlerThread works as expected.
+ @SmallTest
public void testIdleableHandlerThread() {
final int attempts = 50; // Causes the test to take about 200ms on bullhead-eng.
@@ -219,6 +220,7 @@
}
}
+ @SmallTest
@FlakyTest(tolerance = 3)
public void testNotWaitingForIdleCausesRaceConditions() {
// Bring up a network that we can use to send messages to ConnectivityService.
@@ -622,7 +624,7 @@
}
private class WrappedAvoidBadWifiTracker extends AvoidBadWifiTracker {
- public boolean configRestrictsAvoidBadWifi;
+ public volatile boolean configRestrictsAvoidBadWifi;
public WrappedAvoidBadWifiTracker(Context c, Handler h, Runnable r) {
super(c, h, r);
@@ -839,7 +841,7 @@
return cv;
}
- @LargeTest
+ @SmallTest
public void testLingering() throws Exception {
verifyNoNetwork();
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
@@ -879,7 +881,7 @@
verifyNoNetwork();
}
- @LargeTest
+ @SmallTest
public void testValidatedCellularOutscoresUnvalidatedWiFi() throws Exception {
// Test bringing up unvalidated WiFi
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
@@ -914,7 +916,7 @@
verifyNoNetwork();
}
- @LargeTest
+ @SmallTest
public void testUnvalidatedWifiOutscoresUnvalidatedCellular() throws Exception {
// Test bringing up unvalidated cellular.
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
@@ -940,7 +942,7 @@
verifyNoNetwork();
}
- @LargeTest
+ @SmallTest
public void testUnlingeringDoesNotValidate() throws Exception {
// Test bringing up unvalidated WiFi.
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
@@ -968,7 +970,7 @@
NET_CAPABILITY_VALIDATED));
}
- @LargeTest
+ @SmallTest
public void testCellularOutscoresWeakWifi() throws Exception {
// Test bringing up validated cellular.
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
@@ -994,7 +996,7 @@
verifyActiveNetwork(TRANSPORT_WIFI);
}
- @LargeTest
+ @SmallTest
public void testReapingNetwork() throws Exception {
// Test bringing up WiFi without NET_CAPABILITY_INTERNET.
// Expect it to be torn down immediately because it satisfies no requests.
@@ -1027,7 +1029,7 @@
waitFor(cv);
}
- @LargeTest
+ @SmallTest
public void testCellularFallback() throws Exception {
// Test bringing up validated cellular.
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
@@ -1065,7 +1067,7 @@
verifyActiveNetwork(TRANSPORT_WIFI);
}
- @LargeTest
+ @SmallTest
public void testWiFiFallback() throws Exception {
// Test bringing up unvalidated WiFi.
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
@@ -1192,7 +1194,7 @@
}
}
- @LargeTest
+ @SmallTest
public void testStateChangeNetworkCallbacks() throws Exception {
final TestNetworkCallback genericNetworkCallback = new TestNetworkCallback();
final TestNetworkCallback wifiNetworkCallback = new TestNetworkCallback();
@@ -1575,7 +1577,7 @@
handlerThread.quit();
}
- @LargeTest
+ @SmallTest
public void testNetworkFactoryRequests() throws Exception {
tryNetworkFactoryRequests(NET_CAPABILITY_MMS);
tryNetworkFactoryRequests(NET_CAPABILITY_SUPL);
@@ -1595,7 +1597,7 @@
// Skipping VALIDATED and CAPTIVE_PORTAL as they're disallowed.
}
- @LargeTest
+ @SmallTest
public void testNoMutableNetworkRequests() throws Exception {
PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, new Intent("a"), 0);
NetworkRequest.Builder builder = new NetworkRequest.Builder();
@@ -1620,7 +1622,7 @@
} catch (IllegalArgumentException expected) {}
}
- @LargeTest
+ @SmallTest
public void testMMSonWiFi() throws Exception {
// Test bringing up cellular without MMS NetworkRequest gets reaped
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
@@ -1655,7 +1657,7 @@
verifyActiveNetwork(TRANSPORT_WIFI);
}
- @LargeTest
+ @SmallTest
public void testMMSonCell() throws Exception {
// Test bringing up cellular without MMS
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
@@ -1681,7 +1683,7 @@
verifyActiveNetwork(TRANSPORT_CELLULAR);
}
- @LargeTest
+ @SmallTest
public void testCaptivePortal() {
final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
final NetworkRequest captivePortalRequest = new NetworkRequest.Builder()
@@ -1730,7 +1732,7 @@
validatedCallback.expectCallback(CallbackState.LOST, mWiFiNetworkAgent);
}
- @LargeTest
+ @SmallTest
public void testAvoidOrIgnoreCaptivePortals() {
final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
final NetworkRequest captivePortalRequest = new NetworkRequest.Builder()
@@ -1801,7 +1803,7 @@
execptionCalled);
}
- @LargeTest
+ @SmallTest
public void testRegisterDefaultNetworkCallback() throws Exception {
final TestNetworkCallback defaultNetworkCallback = new TestNetworkCallback();
mCm.registerDefaultNetworkCallback(defaultNetworkCallback);
@@ -1862,7 +1864,7 @@
}
}
- @LargeTest
+ @SmallTest
public void testRequestCallbackUpdates() throws Exception {
// File a network request for mobile.
final TestNetworkCallback cellNetworkCallback = new TestRequestUpdateCallback();
@@ -1997,6 +1999,7 @@
@SmallTest
public void testRequestBenchmark() throws Exception {
+ // TODO: turn this unit test into a real benchmarking test.
// Benchmarks connecting and switching performance in the presence of a large number of
// NetworkRequests.
// 1. File NUM_REQUESTS requests.
@@ -2010,61 +2013,80 @@
final CountDownLatch availableLatch = new CountDownLatch(NUM_REQUESTS);
final CountDownLatch losingLatch = new CountDownLatch(NUM_REQUESTS);
- final int REGISTER_TIME_LIMIT_MS = 100;
- long startTime = System.currentTimeMillis();
for (int i = 0; i < NUM_REQUESTS; i++) {
callbacks[i] = new NetworkCallback() {
@Override public void onAvailable(Network n) { availableLatch.countDown(); }
@Override public void onLosing(Network n, int t) { losingLatch.countDown(); }
};
- mCm.registerNetworkCallback(request, callbacks[i]);
}
- long timeTaken = System.currentTimeMillis() - startTime;
- String msg = String.format("Register %d callbacks: %dms, acceptable %dms",
- NUM_REQUESTS, timeTaken, REGISTER_TIME_LIMIT_MS);
- Log.d(TAG, msg);
- assertTrue(msg, timeTaken < REGISTER_TIME_LIMIT_MS);
- final int CONNECT_TIME_LIMIT_MS = 30;
+ final int REGISTER_TIME_LIMIT_MS = 180;
+ assertTimeLimit("Registering callbacks", REGISTER_TIME_LIMIT_MS, () -> {
+ for (NetworkCallback cb : callbacks) {
+ mCm.registerNetworkCallback(request, cb);
+ }
+ });
+
+ final int CONNECT_TIME_LIMIT_MS = 40;
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
// Don't request that the network validate, because otherwise connect() will block until
// the network gets NET_CAPABILITY_VALIDATED, after all the callbacks below have fired,
// and we won't actually measure anything.
mCellNetworkAgent.connect(false);
- startTime = System.currentTimeMillis();
- if (!availableLatch.await(CONNECT_TIME_LIMIT_MS, TimeUnit.MILLISECONDS)) {
- fail(String.format("Only dispatched %d/%d onAvailable callbacks in %dms",
- NUM_REQUESTS - availableLatch.getCount(), NUM_REQUESTS,
- CONNECT_TIME_LIMIT_MS));
- }
- timeTaken = System.currentTimeMillis() - startTime;
- Log.d(TAG, String.format("Connect, %d callbacks: %dms, acceptable %dms",
- NUM_REQUESTS, timeTaken, CONNECT_TIME_LIMIT_MS));
- final int SWITCH_TIME_LIMIT_MS = 30;
+ long onAvailableDispatchingDuration = durationOf(() -> {
+ if (!awaitLatch(availableLatch, CONNECT_TIME_LIMIT_MS)) {
+ fail(String.format("Only dispatched %d/%d onAvailable callbacks in %dms",
+ NUM_REQUESTS - availableLatch.getCount(), NUM_REQUESTS,
+ CONNECT_TIME_LIMIT_MS));
+ }
+ });
+ Log.d(TAG, String.format("Connect, %d callbacks: %dms, acceptable %dms",
+ NUM_REQUESTS, onAvailableDispatchingDuration, CONNECT_TIME_LIMIT_MS));
+
+ final int SWITCH_TIME_LIMIT_MS = 40;
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
// Give wifi a high enough score that we'll linger cell when wifi comes up.
mWiFiNetworkAgent.adjustScore(40);
mWiFiNetworkAgent.connect(false);
- startTime = System.currentTimeMillis();
- if (!losingLatch.await(SWITCH_TIME_LIMIT_MS, TimeUnit.MILLISECONDS)) {
- fail(String.format("Only dispatched %d/%d onLosing callbacks in %dms",
- NUM_REQUESTS - losingLatch.getCount(), NUM_REQUESTS, SWITCH_TIME_LIMIT_MS));
- }
- timeTaken = System.currentTimeMillis() - startTime;
+
+ long onLostDispatchingDuration = durationOf(() -> {
+ if (!awaitLatch(losingLatch, SWITCH_TIME_LIMIT_MS)) {
+ fail(String.format("Only dispatched %d/%d onLosing callbacks in %dms",
+ NUM_REQUESTS - losingLatch.getCount(), NUM_REQUESTS, SWITCH_TIME_LIMIT_MS));
+ }
+ });
Log.d(TAG, String.format("Linger, %d callbacks: %dms, acceptable %dms",
- NUM_REQUESTS, timeTaken, SWITCH_TIME_LIMIT_MS));
+ NUM_REQUESTS, onLostDispatchingDuration, SWITCH_TIME_LIMIT_MS));
final int UNREGISTER_TIME_LIMIT_MS = 10;
- startTime = System.currentTimeMillis();
- for (int i = 0; i < NUM_REQUESTS; i++) {
- mCm.unregisterNetworkCallback(callbacks[i]);
- }
- timeTaken = System.currentTimeMillis() - startTime;
- msg = String.format("Unregister %d callbacks: %dms, acceptable %dms",
- NUM_REQUESTS, timeTaken, UNREGISTER_TIME_LIMIT_MS);
+ assertTimeLimit("Unregistering callbacks", UNREGISTER_TIME_LIMIT_MS, () -> {
+ for (NetworkCallback cb : callbacks) {
+ mCm.unregisterNetworkCallback(cb);
+ }
+ });
+ }
+
+ private long durationOf(Runnable fn) {
+ long startTime = SystemClock.elapsedRealtime();
+ fn.run();
+ return SystemClock.elapsedRealtime() - startTime;
+ }
+
+ private void assertTimeLimit(String descr, long timeLimit, Runnable fn) {
+ long timeTaken = durationOf(fn);
+ String msg = String.format("%s: took %dms, limit was %dms", descr, timeTaken, timeLimit);
Log.d(TAG, msg);
- assertTrue(msg, timeTaken < UNREGISTER_TIME_LIMIT_MS);
+ assertTrue(msg, timeTaken <= timeLimit);
+ }
+
+ private boolean awaitLatch(CountDownLatch l, long timeoutMs) {
+ try {
+ if (l.await(timeoutMs, TimeUnit.MILLISECONDS)) {
+ return true;
+ }
+ } catch (InterruptedException e) {}
+ return false;
}
@SmallTest
@@ -2145,7 +2167,7 @@
tracker.reevaluate();
mService.waitForIdle();
String msg = String.format("config=false, setting=%s", values[i]);
- assertTrue(msg, mService.avoidBadWifi());
+ assertEventuallyTrue(() -> mService.avoidBadWifi(), 50);
assertFalse(msg, tracker.shouldNotifyWifiUnvalidated());
}
@@ -2154,19 +2176,19 @@
Settings.Global.putInt(cr, settingName, 0);
tracker.reevaluate();
mService.waitForIdle();
- assertFalse(mService.avoidBadWifi());
+ assertEventuallyTrue(() -> !mService.avoidBadWifi(), 50);
assertFalse(tracker.shouldNotifyWifiUnvalidated());
Settings.Global.putInt(cr, settingName, 1);
tracker.reevaluate();
mService.waitForIdle();
- assertTrue(mService.avoidBadWifi());
+ assertEventuallyTrue(() -> mService.avoidBadWifi(), 50);
assertFalse(tracker.shouldNotifyWifiUnvalidated());
Settings.Global.putString(cr, settingName, null);
tracker.reevaluate();
mService.waitForIdle();
- assertFalse(mService.avoidBadWifi());
+ assertEventuallyTrue(() -> !mService.avoidBadWifi(), 50);
assertTrue(tracker.shouldNotifyWifiUnvalidated());
}
@@ -2383,6 +2405,17 @@
networkCallback.assertNoCallback();
}
+ public void assertEventuallyTrue(BooleanSupplier fn, long maxWaitingTimeMs) throws Exception {
+ long start = SystemClock.elapsedRealtime();
+ while (SystemClock.elapsedRealtime() <= start + maxWaitingTimeMs) {
+ if (fn.getAsBoolean()) {
+ return;
+ }
+ Thread.sleep(10);
+ }
+ assertTrue(fn.getAsBoolean());
+ }
+
private static class TestKeepaliveCallback extends PacketKeepaliveCallback {
public static enum CallbackType { ON_STARTED, ON_STOPPED, ON_ERROR };
@@ -2472,6 +2505,7 @@
return mWiFiNetworkAgent.getNetwork();
}
+ @SmallTest
public void testPacketKeepalives() throws Exception {
InetAddress myIPv4 = InetAddress.getByName("192.0.2.129");
InetAddress notMyIPv4 = InetAddress.getByName("192.0.2.35");
diff --git a/tests/net/java/com/android/server/connectivity/IpConnectivityEventBuilderTest.java b/tests/net/java/com/android/server/connectivity/IpConnectivityEventBuilderTest.java
index aed3635..84f0f90 100644
--- a/tests/net/java/com/android/server/connectivity/IpConnectivityEventBuilderTest.java
+++ b/tests/net/java/com/android/server/connectivity/IpConnectivityEventBuilderTest.java
@@ -71,7 +71,8 @@
" transport_types: 3",
" >",
" time_ms: 1",
- ">");
+ ">",
+ "version: 2");
verifySerialization(want, ev);
}
@@ -93,7 +94,8 @@
" state_transition: \"SomeState\"",
" >",
" time_ms: 1",
- ">");
+ ">",
+ "version: 2");
verifySerialization(want, ev);
}
@@ -114,7 +116,8 @@
" state_transition: \"\"",
" >",
" time_ms: 1",
- ">");
+ ">",
+ "version: 2");
verifySerialization(want, ev);
}
@@ -160,7 +163,8 @@
" return_codes: 178",
" >",
" time_ms: 1",
- ">");
+ ">",
+ "version: 2");
verifySerialization(want, ev);
}
@@ -181,7 +185,8 @@
" latency_ms: 5678",
" >",
" time_ms: 1",
- ">");
+ ">",
+ "version: 2");
verifySerialization(want, ev);
}
@@ -200,7 +205,8 @@
" if_name: \"wlan0\"",
" >",
" time_ms: 1",
- ">");
+ ">",
+ "version: 2");
verifySerialization(want, ev);
}
@@ -223,7 +229,8 @@
" >",
" >",
" time_ms: 1",
- ">");
+ ">",
+ "version: 2");
verifySerialization(want, ev);
}
@@ -248,7 +255,8 @@
" probe_result: 204",
" probe_type: 1",
" >",
- ">");
+ ">",
+ "version: 2");
verifySerialization(want, ev);
}
@@ -274,7 +282,8 @@
" program_length: 2048",
" >",
" time_ms: 1",
- ">");
+ ">",
+ "version: 2");
verifySerialization(want, ev);
}
@@ -305,7 +314,8 @@
" zero_lifetime_ras: 1",
" >",
" time_ms: 1",
- ">");
+ ">",
+ "version: 2");
verifySerialization(want, ev);
}
@@ -332,7 +342,8 @@
" router_lifetime: 2000",
" >",
" time_ms: 1",
- ">");
+ ">",
+ "version: 2");
verifySerialization(want, ev);
}
diff --git a/tests/net/java/com/android/server/connectivity/IpConnectivityMetricsTest.java b/tests/net/java/com/android/server/connectivity/IpConnectivityMetricsTest.java
index 3fc89b9..aa491bb 100644
--- a/tests/net/java/com/android/server/connectivity/IpConnectivityMetricsTest.java
+++ b/tests/net/java/com/android/server/connectivity/IpConnectivityMetricsTest.java
@@ -19,6 +19,7 @@
import android.content.Context;
import android.net.ConnectivityMetricsEvent;
import android.net.IIpConnectivityMetrics;
+import android.net.metrics.ApfProgramEvent;
import android.net.metrics.ApfStats;
import android.net.metrics.DefaultNetworkEvent;
import android.net.metrics.DhcpClientEvent;
@@ -57,7 +58,7 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
- mService = new IpConnectivityMetrics(mCtx);
+ mService = new IpConnectivityMetrics(mCtx, (ctx) -> 2000);
}
public void testLoggingEvents() throws Exception {
@@ -112,6 +113,27 @@
assertEquals("", output3);
}
+ public void testRateLimiting() {
+ final IpConnectivityLog logger = new IpConnectivityLog(mService.impl);
+ final ApfProgramEvent ev = new ApfProgramEvent(0, 0, 0, 0, 0);
+ final long fakeTimestamp = 1;
+
+ int attempt = 100; // More than burst quota, but less than buffer size.
+ for (int i = 0; i < attempt; i++) {
+ logger.log(ev);
+ }
+
+ String output1 = getdump("flush");
+ assertFalse("".equals(output1));
+
+ for (int i = 0; i < attempt; i++) {
+ assertFalse("expected event to be dropped", logger.log(fakeTimestamp, ev));
+ }
+
+ String output2 = getdump("flush");
+ assertEquals("", output2);
+ }
+
public void testEndToEndLogging() {
IpConnectivityLog logger = new IpConnectivityLog(mService.impl);
@@ -204,7 +226,8 @@
" router_lifetime: 2000",
" >",
" time_ms: 700",
- ">");
+ ">",
+ "version: 2");
verifySerialization(want, getdump("flush"));
}
diff --git a/tests/net/java/com/android/server/connectivity/LingerMonitorTest.java b/tests/net/java/com/android/server/connectivity/LingerMonitorTest.java
index bce5787e..77956be 100644
--- a/tests/net/java/com/android/server/connectivity/LingerMonitorTest.java
+++ b/tests/net/java/com/android/server/connectivity/LingerMonitorTest.java
@@ -24,6 +24,7 @@
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkMisc;
+import android.test.suitebuilder.annotation.SmallTest;
import android.text.format.DateUtils;
import com.android.internal.R;
import com.android.server.ConnectivityService;
@@ -70,6 +71,7 @@
mMonitor = new TestableLingerMonitor(mCtx, mNotifier, HIGH_DAILY_LIMIT, HIGH_RATE_LIMIT);
}
+ @SmallTest
public void testTransitions() {
setNotificationSwitch(transition(WIFI, CELLULAR));
NetworkAgentInfo nai1 = wifiNai(100);
@@ -79,6 +81,7 @@
assertFalse(mMonitor.isNotificationEnabled(nai2, nai1));
}
+ @SmallTest
public void testNotificationOnLinger() {
setNotificationSwitch(transition(WIFI, CELLULAR));
setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION);
@@ -89,6 +92,7 @@
verifyNotification(from, to);
}
+ @SmallTest
public void testToastOnLinger() {
setNotificationSwitch(transition(WIFI, CELLULAR));
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
@@ -99,6 +103,7 @@
verifyToast(from, to);
}
+ @SmallTest
public void testNotificationClearedAfterDisconnect() {
setNotificationSwitch(transition(WIFI, CELLULAR));
setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION);
@@ -112,6 +117,7 @@
verify(mNotifier, times(1)).clearNotification(100);
}
+ @SmallTest
public void testNotificationClearedAfterSwitchingBack() {
setNotificationSwitch(transition(WIFI, CELLULAR));
setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION);
@@ -125,6 +131,7 @@
verify(mNotifier, times(1)).clearNotification(100);
}
+ @SmallTest
public void testUniqueToast() {
setNotificationSwitch(transition(WIFI, CELLULAR));
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
@@ -142,6 +149,7 @@
verifyNoNotifications();
}
+ @SmallTest
public void testMultipleNotifications() {
setNotificationSwitch(transition(WIFI, CELLULAR));
setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION);
@@ -160,6 +168,7 @@
verifyNotification(wifi2, cell);
}
+ @SmallTest
public void testRateLimiting() throws InterruptedException {
mMonitor = new TestableLingerMonitor(mCtx, mNotifier, HIGH_DAILY_LIMIT, LOW_RATE_LIMIT);
@@ -185,6 +194,7 @@
verifyNoNotifications();
}
+ @SmallTest
public void testDailyLimiting() throws InterruptedException {
mMonitor = new TestableLingerMonitor(mCtx, mNotifier, LOW_DAILY_LIMIT, HIGH_RATE_LIMIT);
@@ -211,6 +221,7 @@
verifyNoNotifications();
}
+ @SmallTest
public void testUniqueNotification() {
setNotificationSwitch(transition(WIFI, CELLULAR));
setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION);
@@ -227,6 +238,7 @@
verifyNotification(from, to);
}
+ @SmallTest
public void testIgnoreNeverValidatedNetworks() {
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
setNotificationSwitch(transition(WIFI, CELLULAR));
@@ -238,6 +250,7 @@
verifyNoNotifications();
}
+ @SmallTest
public void testIgnoreCurrentlyValidatedNetworks() {
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
setNotificationSwitch(transition(WIFI, CELLULAR));
@@ -249,6 +262,7 @@
verifyNoNotifications();
}
+ @SmallTest
public void testNoNotificationType() {
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
setNotificationSwitch();
@@ -259,6 +273,7 @@
verifyNoNotifications();
}
+ @SmallTest
public void testNoTransitionToNotify() {
setNotificationType(LingerMonitor.NOTIFY_TYPE_NONE);
setNotificationSwitch(transition(WIFI, CELLULAR));
@@ -269,6 +284,7 @@
verifyNoNotifications();
}
+ @SmallTest
public void testDifferentTransitionToNotify() {
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
setNotificationSwitch(transition(CELLULAR, WIFI));
diff --git a/tests/net/java/com/android/server/connectivity/MetricsLoggerServiceTest.java b/tests/net/java/com/android/server/connectivity/MetricsLoggerServiceTest.java
index 5f84ea1..5981f48 100644
--- a/tests/net/java/com/android/server/connectivity/MetricsLoggerServiceTest.java
+++ b/tests/net/java/com/android/server/connectivity/MetricsLoggerServiceTest.java
@@ -20,6 +20,7 @@
import android.net.ConnectivityMetricsEvent;
import android.os.Bundle;
import android.os.RemoteException;
+import android.test.suitebuilder.annotation.SmallTest;
import static android.net.ConnectivityMetricsEvent.Reference;
import junit.framework.TestCase;
@@ -67,12 +68,14 @@
mService.onStart();
}
+ @SmallTest
public void testGetNoEvents() throws Exception {
Reference r = new Reference(0);
assertArrayEquals(NO_EVENTS, mService.mBinder.getEvents(r));
assertEquals(0, r.getValue());
}
+ @SmallTest
public void testLogAndGetEvents() throws Exception {
mService.mBinder.logEvents(EVENTS);
@@ -85,6 +88,7 @@
assertEquals(N_EVENTS, r.getValue());
}
+ @SmallTest
public void testLogOneByOne() throws Exception {
for (ConnectivityMetricsEvent ev : EVENTS) {
mService.mBinder.logEvent(ev);
@@ -99,6 +103,7 @@
assertEquals(N_EVENTS, r.getValue());
}
+ @SmallTest
public void testInterleavedLogAndGet() throws Exception {
mService.mBinder.logEvents(Arrays.copyOfRange(EVENTS, 0, 3));
@@ -117,6 +122,7 @@
assertEquals(N_EVENTS, r.getValue());
}
+ @SmallTest
public void testMultipleGetAll() throws Exception {
mService.mBinder.logEvents(Arrays.copyOf(EVENTS, 3));
@@ -131,6 +137,7 @@
assertEquals(N_EVENTS, r2.getValue());
}
+ @SmallTest
public void testLogAndDumpConcurrently() throws Exception {
for (int i = 0; i < 50; i++) {
mContext = null;
diff --git a/tests/net/java/com/android/server/connectivity/NetdEventListenerServiceTest.java b/tests/net/java/com/android/server/connectivity/NetdEventListenerServiceTest.java
index 9e2fd62..2bb62bb 100644
--- a/tests/net/java/com/android/server/connectivity/NetdEventListenerServiceTest.java
+++ b/tests/net/java/com/android/server/connectivity/NetdEventListenerServiceTest.java
@@ -22,6 +22,8 @@
import android.net.metrics.DnsEvent;
import android.net.metrics.INetdEventListener;
import android.net.metrics.IpConnectivityLog;
+import android.os.RemoteException;
+import android.test.suitebuilder.annotation.SmallTest;
import junit.framework.TestCase;
import org.junit.Before;
@@ -82,6 +84,7 @@
verify(mCm, times(1)).registerNetworkCallback(any(), mCallbackCaptor.capture());
}
+ @SmallTest
public void testOneBatch() throws Exception {
log(105, LATENCIES);
log(106, Arrays.copyOf(LATENCIES, BATCH_SIZE - 1)); // one lookup short of a batch event
@@ -96,6 +99,7 @@
new DnsEvent(106, EVENT_TYPES, RETURN_CODES, LATENCIES));
}
+ @SmallTest
public void testSeveralBatches() throws Exception {
log(105, LATENCIES);
log(106, LATENCIES);
@@ -109,6 +113,7 @@
new DnsEvent(107, EVENT_TYPES, RETURN_CODES, LATENCIES));
}
+ @SmallTest
public void testBatchAndNetworkLost() throws Exception {
byte[] eventTypes = Arrays.copyOf(EVENT_TYPES, 20);
byte[] returnCodes = Arrays.copyOf(RETURN_CODES, 20);
@@ -125,6 +130,7 @@
new DnsEvent(105, EVENT_TYPES, RETURN_CODES, LATENCIES));
}
+ @SmallTest
public void testConcurrentBatchesAndDumps() throws Exception {
final long stop = System.currentTimeMillis() + 100;
final PrintWriter pw = new PrintWriter(new FileOutputStream("/dev/null"));
@@ -146,6 +152,7 @@
new DnsEvent(107, EVENT_TYPES, RETURN_CODES, LATENCIES));
}
+ @SmallTest
public void testConcurrentBatchesAndNetworkLoss() throws Exception {
logAsync(105, LATENCIES);
Thread.sleep(10L);
@@ -157,9 +164,13 @@
}
void log(int netId, int[] latencies) {
- for (int l : latencies) {
- mNetdEventListenerService.onDnsEvent(netId, EVENT_TYPE, RETURN_CODE, l, null, null, 0,
- 0);
+ try {
+ for (int l : latencies) {
+ mNetdEventListenerService.onDnsEvent(netId, EVENT_TYPE, RETURN_CODE, l, null, null,
+ 0, 0);
+ }
+ } catch (RemoteException re) {
+ throw re.rethrowFromSystemServer();
}
}
diff --git a/tests/net/java/com/android/server/connectivity/VpnTest.java b/tests/net/java/com/android/server/connectivity/VpnTest.java
index 5d8b843..b51b277 100644
--- a/tests/net/java/com/android/server/connectivity/VpnTest.java
+++ b/tests/net/java/com/android/server/connectivity/VpnTest.java
@@ -25,9 +25,11 @@
import android.annotation.UserIdInt;
import android.app.AppOpsManager;
+import android.app.NotificationManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
+import android.net.NetworkInfo.DetailedState;
import android.net.UidRange;
import android.os.INetworkManagementService;
import android.os.Looper;
@@ -43,6 +45,8 @@
import java.util.Map;
import java.util.Set;
+import org.mockito.ArgumentCaptor;
+import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -88,14 +92,18 @@
@Mock private PackageManager mPackageManager;
@Mock private INetworkManagementService mNetService;
@Mock private AppOpsManager mAppOps;
+ @Mock private NotificationManager mNotificationManager;
@Override
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
setMockedPackages(mPackages);
+ when(mContext.getPackageName()).thenReturn(Vpn.class.getPackage().getName());
when(mContext.getSystemService(eq(Context.USER_SERVICE))).thenReturn(mUserManager);
when(mContext.getSystemService(eq(Context.APP_OPS_SERVICE))).thenReturn(mAppOps);
+ when(mContext.getSystemService(eq(Context.NOTIFICATION_SERVICE)))
+ .thenReturn(mNotificationManager);
doNothing().when(mNetService).registerObserver(any());
}
@@ -103,7 +111,7 @@
public void testRestrictedProfilesAreAddedToVpn() {
setMockedUsers(primaryUser, secondaryUser, restrictedProfileA, restrictedProfileB);
- final Vpn vpn = new MockVpn(primaryUser.id);
+ final Vpn vpn = spyVpn(primaryUser.id);
final Set<UidRange> ranges = vpn.createUserAndRestrictedProfilesRanges(primaryUser.id,
null, null);
@@ -117,7 +125,7 @@
public void testManagedProfilesAreNotAddedToVpn() {
setMockedUsers(primaryUser, managedProfileA);
- final Vpn vpn = new MockVpn(primaryUser.id);
+ final Vpn vpn = spyVpn(primaryUser.id);
final Set<UidRange> ranges = vpn.createUserAndRestrictedProfilesRanges(primaryUser.id,
null, null);
@@ -130,7 +138,7 @@
public void testAddUserToVpnOnlyAddsOneUser() {
setMockedUsers(primaryUser, restrictedProfileA, managedProfileA);
- final Vpn vpn = new MockVpn(primaryUser.id);
+ final Vpn vpn = spyVpn(primaryUser.id);
final Set<UidRange> ranges = new ArraySet<>();
vpn.addUserToRanges(ranges, primaryUser.id, null, null);
@@ -141,7 +149,7 @@
@SmallTest
public void testUidWhiteAndBlacklist() throws Exception {
- final Vpn vpn = new MockVpn(primaryUser.id);
+ final Vpn vpn = spyVpn(primaryUser.id);
final UidRange user = UidRange.createForUser(primaryUser.id);
final String[] packages = {PKGS[0], PKGS[1], PKGS[2]};
@@ -166,15 +174,15 @@
@SmallTest
public void testLockdownChangingPackage() throws Exception {
- final MockVpn vpn = new MockVpn(primaryUser.id);
+ final Vpn vpn = spyVpn(primaryUser.id);
final UidRange user = UidRange.createForUser(primaryUser.id);
// Default state.
- vpn.assertUnblocked(user.start + PKG_UIDS[0], user.start + PKG_UIDS[1], user.start + PKG_UIDS[2], user.start + PKG_UIDS[3]);
+ assertUnblocked(vpn, user.start + PKG_UIDS[0], user.start + PKG_UIDS[1], user.start + PKG_UIDS[2], user.start + PKG_UIDS[3]);
// Set always-on without lockdown.
assertTrue(vpn.setAlwaysOnPackage(PKGS[1], false));
- vpn.assertUnblocked(user.start + PKG_UIDS[0], user.start + PKG_UIDS[1], user.start + PKG_UIDS[2], user.start + PKG_UIDS[3]);
+ assertUnblocked(vpn, user.start + PKG_UIDS[0], user.start + PKG_UIDS[1], user.start + PKG_UIDS[2], user.start + PKG_UIDS[3]);
// Set always-on with lockdown.
assertTrue(vpn.setAlwaysOnPackage(PKGS[1], true));
@@ -182,8 +190,8 @@
new UidRange(user.start, user.start + PKG_UIDS[1] - 1),
new UidRange(user.start + PKG_UIDS[1] + 1, user.stop)
}));
- vpn.assertBlocked(user.start + PKG_UIDS[0], user.start + PKG_UIDS[2], user.start + PKG_UIDS[3]);
- vpn.assertUnblocked(user.start + PKG_UIDS[1]);
+ assertBlocked(vpn, user.start + PKG_UIDS[0], user.start + PKG_UIDS[2], user.start + PKG_UIDS[3]);
+ assertUnblocked(vpn, user.start + PKG_UIDS[1]);
// Switch to another app.
assertTrue(vpn.setAlwaysOnPackage(PKGS[3], true));
@@ -195,13 +203,13 @@
new UidRange(user.start, user.start + PKG_UIDS[3] - 1),
new UidRange(user.start + PKG_UIDS[3] + 1, user.stop)
}));
- vpn.assertBlocked(user.start + PKG_UIDS[0], user.start + PKG_UIDS[1], user.start + PKG_UIDS[2]);
- vpn.assertUnblocked(user.start + PKG_UIDS[3]);
+ assertBlocked(vpn, user.start + PKG_UIDS[0], user.start + PKG_UIDS[1], user.start + PKG_UIDS[2]);
+ assertUnblocked(vpn, user.start + PKG_UIDS[3]);
}
@SmallTest
public void testLockdownAddingAProfile() throws Exception {
- final MockVpn vpn = new MockVpn(primaryUser.id);
+ final Vpn vpn = spyVpn(primaryUser.id);
setMockedUsers(primaryUser);
// Make a copy of the restricted profile, as we're going to mark it deleted halfway through.
@@ -220,7 +228,7 @@
}));
// Verify restricted user isn't affected at first.
- vpn.assertUnblocked(profile.start + PKG_UIDS[0]);
+ assertUnblocked(vpn, profile.start + PKG_UIDS[0]);
// Add the restricted user.
setMockedUsers(primaryUser, tempProfile);
@@ -239,24 +247,53 @@
}));
}
+ @SmallTest
+ public void testNotificationShownForAlwaysOnApp() {
+ final Vpn vpn = spyVpn(primaryUser.id);
+ final InOrder order = inOrder(vpn);
+ setMockedUsers(primaryUser);
+
+ // Don't show a notification for regular disconnected states.
+ vpn.updateState(DetailedState.DISCONNECTED, TAG);
+ order.verify(vpn).updateAlwaysOnNotificationInternal(false);
+
+ // Start showing a notification for disconnected once always-on.
+ vpn.setAlwaysOnPackage(PKGS[0], false);
+ order.verify(vpn).updateAlwaysOnNotificationInternal(true);
+
+ // Stop showing the notification once connected.
+ vpn.updateState(DetailedState.CONNECTED, TAG);
+ order.verify(vpn).updateAlwaysOnNotificationInternal(false);
+
+ // Show the notification if we disconnect again.
+ vpn.updateState(DetailedState.DISCONNECTED, TAG);
+ order.verify(vpn).updateAlwaysOnNotificationInternal(true);
+
+ // Notification should be cleared after unsetting always-on package.
+ vpn.setAlwaysOnPackage(null, false);
+ order.verify(vpn).updateAlwaysOnNotificationInternal(false);
+ }
+
/**
- * A subclass of {@link Vpn} with some of the fields pre-mocked.
+ * Mock some methods of vpn object.
*/
- private class MockVpn extends Vpn {
- public MockVpn(@UserIdInt int userId) {
- super(Looper.myLooper(), mContext, mNetService, userId);
- }
+ private Vpn spyVpn(@UserIdInt int userId) {
+ final Vpn vpn = spy(new Vpn(Looper.myLooper(), mContext, mNetService, userId));
- public void assertBlocked(int... uids) {
- for (int uid : uids) {
- assertTrue("Uid " + uid + " should be blocked", isBlockingUid(uid));
- }
- }
+ // Block calls to the NotificationManager or PendingIntent#getActivity.
+ doNothing().when(vpn).updateAlwaysOnNotificationInternal(anyBoolean());
+ return vpn;
+ }
- public void assertUnblocked(int... uids) {
- for (int uid : uids) {
- assertFalse("Uid " + uid + " should not be blocked", isBlockingUid(uid));
- }
+ private static void assertBlocked(Vpn vpn, int... uids) {
+ for (int uid : uids) {
+ assertTrue("Uid " + uid + " should be blocked", vpn.isBlockingUid(uid));
+ }
+ }
+
+ private static void assertUnblocked(Vpn vpn, int... uids) {
+ for (int uid : uids) {
+ assertFalse("Uid " + uid + " should not be blocked", vpn.isBlockingUid(uid));
}
}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/libcore/io/BridgeBufferIterator.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/libcore/io/BridgeBufferIterator.java
index 7e361a1..96cba78 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/libcore/io/BridgeBufferIterator.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/libcore/io/BridgeBufferIterator.java
@@ -40,6 +40,11 @@
}
@Override
+ public int pos() {
+ return mByteBuffer.position();
+ }
+
+ @Override
public void skip(int byteCount) {
int newPosition = mByteBuffer.position() + byteCount;
assert newPosition <= mSize;
diff --git a/tools/preload2/Android.mk b/tools/preload2/Android.mk
index 769db6b..d3ee1d3 100644
--- a/tools/preload2/Android.mk
+++ b/tools/preload2/Android.mk
@@ -17,6 +17,8 @@
LOCAL_MODULE:= preload2
include $(BUILD_HOST_JAVA_LIBRARY)
+# Copy to build artifacts
+$(call dist-for-goals,dist_files,$(LOCAL_BUILT_MODULE):$(LOCAL_MODULE).jar)
# Copy the preload-tool shell script to the host's bin directory.
include $(CLEAR_VARS)
diff --git a/tools/preload2/src/com/android/preload/classdataretrieval/hprof/Hprof.java b/tools/preload2/src/com/android/preload/classdataretrieval/hprof/Hprof.java
index 21b7a04..84ec8b7 100644
--- a/tools/preload2/src/com/android/preload/classdataretrieval/hprof/Hprof.java
+++ b/tools/preload2/src/com/android/preload/classdataretrieval/hprof/Hprof.java
@@ -171,6 +171,9 @@
arg1.getDevice().getSyncService().pullFile(arg0,
target.getAbsoluteFile().toString(), new NullProgressMonitor());
} catch (Exception e) {
+ if (target != null) {
+ target.delete();
+ }
e.printStackTrace();
target = null;
}
@@ -189,6 +192,9 @@
out.write(arg0);
out.close();
} catch (Exception e) {
+ if (target != null) {
+ target.delete();
+ }
e.printStackTrace();
target = null;
}
@@ -215,6 +221,8 @@
return analyzeHprof(hprofLocalFile);
} catch (Exception e) {
throw new RuntimeException(e);
+ } finally {
+ hprofLocalFile.delete();
}
}
}
diff --git a/wifi/java/android/net/wifi/ScanResult.java b/wifi/java/android/net/wifi/ScanResult.java
index da87135..da9aa06 100644
--- a/wifi/java/android/net/wifi/ScanResult.java
+++ b/wifi/java/android/net/wifi/ScanResult.java
@@ -16,6 +16,7 @@
package android.net.wifi;
+import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
@@ -259,10 +260,10 @@
public long blackListTimestamp;
/**
- * Status: indicating the scan result is not a result
- * that is part of user's saved configurations
+ * Status indicating the scan result does not correspond to a user's saved configuration
* @hide
*/
+ @SystemApi
public boolean untrusted;
/**
diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java
index 43e6246..3b7f721 100644
--- a/wifi/java/android/net/wifi/WifiConfiguration.java
+++ b/wifi/java/android/net/wifi/WifiConfiguration.java
@@ -701,6 +701,7 @@
* {@link com.android.server.wifi.WifiStateMachine}, or via a network score in
* {@link com.android.server.wifi.ExternalScoreEvaluator}.
*/
+ @SystemApi
public boolean meteredHint;
/**
diff --git a/wifi/java/android/net/wifi/WifiNetworkScoreCache.java b/wifi/java/android/net/wifi/WifiNetworkScoreCache.java
new file mode 100755
index 0000000..9dd118b
--- /dev/null
+++ b/wifi/java/android/net/wifi/WifiNetworkScoreCache.java
@@ -0,0 +1,276 @@
+/*
+ * Copyright (C) 2014 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.Manifest.permission;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.annotation.SystemApi;
+import android.content.Context;
+import android.os.Handler;
+import android.net.INetworkScoreCache;
+import android.net.NetworkKey;
+import android.net.ScoredNetwork;
+import android.util.Log;
+
+import com.android.internal.util.Preconditions;
+import com.android.internal.annotations.GuardedBy;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * {@link INetworkScoreCache} implementation for Wifi Networks.
+ *
+ * @hide
+ */
+public class WifiNetworkScoreCache extends INetworkScoreCache.Stub {
+ private static final String TAG = "WifiNetworkScoreCache";
+ private static final boolean DBG = false;
+
+ // A Network scorer returns a score in the range [-128, +127]
+ // We treat the lowest possible score as though there were no score, effectively allowing the
+ // scorer to provide an RSSI threshold below which a network should not be used.
+ public static final int INVALID_NETWORK_SCORE = Byte.MIN_VALUE;
+
+ // See {@link #CacheListener}.
+ @Nullable
+ @GuardedBy("mCacheLock")
+ private CacheListener mListener;
+
+ private final Context mContext;
+ private final Object mCacheLock = new Object();
+
+ // The key is of the form "<ssid>"<bssid>
+ // TODO: What about SSIDs that can't be encoded as UTF-8?
+ private final Map<String, ScoredNetwork> mNetworkCache;
+
+
+ public WifiNetworkScoreCache(Context context) {
+ this(context, null /* listener */);
+ }
+
+ /**
+ * Instantiates a WifiNetworkScoreCache.
+ *
+ * @param context Application context
+ * @param listener CacheListener for cache updates
+ */
+ public WifiNetworkScoreCache(Context context, @Nullable CacheListener listener) {
+ mContext = context.getApplicationContext();
+ mListener = listener;
+ mNetworkCache = new HashMap<String, ScoredNetwork>();
+ }
+
+ @Override public final void updateScores(List<ScoredNetwork> networks) {
+ if (networks == null || networks.isEmpty()) {
+ return;
+ }
+ Log.d(TAG, "updateScores list size=" + networks.size());
+
+ synchronized(mNetworkCache) {
+ for (ScoredNetwork network : networks) {
+ String networkKey = buildNetworkKey(network);
+ if (networkKey == null) continue;
+ mNetworkCache.put(networkKey, network);
+ }
+ }
+
+ synchronized (mCacheLock) {
+ if (mListener != null) {
+ mListener.post(networks);
+ }
+ }
+ }
+
+ @Override public final void clearScores() {
+ synchronized (mNetworkCache) {
+ mNetworkCache.clear();
+ }
+ }
+
+ /**
+ * Returns whether there is any score info for the given ScanResult.
+ *
+ * This includes null-score info, so it should only be used when determining whether to request
+ * scores from the network scorer.
+ */
+ public boolean isScoredNetwork(ScanResult result) {
+ return getScoredNetwork(result) != null;
+ }
+
+ /**
+ * Returns whether there is a non-null score curve for the given ScanResult.
+ *
+ * A null score curve has special meaning - we should never connect to an ephemeral network if
+ * the score curve is null.
+ */
+ public boolean hasScoreCurve(ScanResult result) {
+ ScoredNetwork network = getScoredNetwork(result);
+ return network != null && network.rssiCurve != null;
+ }
+
+ public int getNetworkScore(ScanResult result) {
+
+ int score = INVALID_NETWORK_SCORE;
+
+ ScoredNetwork network = getScoredNetwork(result);
+ if (network != null && network.rssiCurve != null) {
+ score = network.rssiCurve.lookupScore(result.level);
+ if (DBG) {
+ Log.e(TAG, "getNetworkScore found scored network " + network.networkKey
+ + " score " + Integer.toString(score)
+ + " RSSI " + result.level);
+ }
+ }
+ return score;
+ }
+
+ /**
+ * Returns the ScoredNetwork metered hint for a given ScanResult.
+ *
+ * If there is no ScoredNetwork associated with the ScanResult then false will be returned.
+ */
+ public boolean getMeteredHint(ScanResult result) {
+ ScoredNetwork network = getScoredNetwork(result);
+ return network != null && network.meteredHint;
+ }
+
+ public int getNetworkScore(ScanResult result, boolean isActiveNetwork) {
+
+ int score = INVALID_NETWORK_SCORE;
+
+ ScoredNetwork network = getScoredNetwork(result);
+ if (network != null && network.rssiCurve != null) {
+ score = network.rssiCurve.lookupScore(result.level, isActiveNetwork);
+ if (DBG) {
+ Log.e(TAG, "getNetworkScore found scored network " + network.networkKey
+ + " score " + Integer.toString(score)
+ + " RSSI " + result.level
+ + " isActiveNetwork " + isActiveNetwork);
+ }
+ }
+ return score;
+ }
+
+ private ScoredNetwork getScoredNetwork(ScanResult result) {
+ String key = buildNetworkKey(result);
+ if (key == null) return null;
+
+ //find it
+ synchronized(mNetworkCache) {
+ ScoredNetwork network = mNetworkCache.get(key);
+ return network;
+ }
+ }
+
+ private String buildNetworkKey(ScoredNetwork network) {
+ if (network == null || network.networkKey == null) return null;
+ if (network.networkKey.wifiKey == null) return null;
+ if (network.networkKey.type == NetworkKey.TYPE_WIFI) {
+ String key = network.networkKey.wifiKey.ssid;
+ if (key == null) return null;
+ if (network.networkKey.wifiKey.bssid != null) {
+ key = key + network.networkKey.wifiKey.bssid;
+ }
+ return key;
+ }
+ return null;
+ }
+
+ private String buildNetworkKey(ScanResult result) {
+ if (result == null || result.SSID == null) {
+ return null;
+ }
+ StringBuilder key = new StringBuilder("\"");
+ key.append(result.SSID);
+ key.append("\"");
+ if (result.BSSID != null) {
+ key.append(result.BSSID);
+ }
+ return key.toString();
+ }
+
+ @Override protected final void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
+ mContext.enforceCallingOrSelfPermission(permission.DUMP, TAG);
+ writer.println("WifiNetworkScoreCache");
+ writer.println(" All score curves:");
+ for (Map.Entry<String, ScoredNetwork> entry : mNetworkCache.entrySet()) {
+ ScoredNetwork scoredNetwork = entry.getValue();
+ writer.println(" " + entry.getKey() + ": " + scoredNetwork.rssiCurve
+ + ", meteredHint=" + scoredNetwork.meteredHint);
+ }
+ writer.println(" Current network scores:");
+ WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
+ for (ScanResult scanResult : wifiManager.getScanResults()) {
+ writer.println(" " + buildNetworkKey(scanResult) + ": " + getNetworkScore(scanResult));
+ }
+ }
+
+ /** Registers a CacheListener instance, replacing the previous listener if it existed. */
+ public void registerListener(CacheListener listener) {
+ synchronized (mCacheLock) {
+ mListener = listener;
+ }
+ }
+
+ /** Removes the registered CacheListener. */
+ public void unregisterListener() {
+ synchronized (mCacheLock) {
+ mListener = null;
+ }
+ }
+
+ /** Listener for updates to the cache inside WifiNetworkScoreCache. */
+ public abstract static class CacheListener {
+
+ private Handler mHandler;
+
+ /**
+ * Constructor for CacheListener.
+ *
+ * @param handler the Handler on which to invoke the {@link #networkCacheUpdated} method.
+ * This cannot be null.
+ */
+ public CacheListener(@NonNull Handler handler) {
+ Preconditions.checkNotNull(handler);
+ mHandler = handler;
+ }
+
+ /** Invokes the {@link #networkCacheUpdated(List<ScoredNetwork>)} method on the handler. */
+ void post(List<ScoredNetwork> updatedNetworks) {
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ networkCacheUpdated(updatedNetworks);
+ }
+ });
+ }
+
+ /**
+ * Invoked whenever the cache is updated.
+ *
+ * <p>Clearing the cache does not invoke this method.
+ *
+ * @param updatedNetworks the networks that were updated
+ */
+ public abstract void networkCacheUpdated(List<ScoredNetwork> updatedNetworks);
+ }
+}
diff --git a/wifi/tests/Android.mk b/wifi/tests/Android.mk
index 5850fee..eac49d2 100644
--- a/wifi/tests/Android.mk
+++ b/wifi/tests/Android.mk
@@ -50,6 +50,7 @@
LOCAL_STATIC_JAVA_LIBRARIES := \
android-support-test \
+ guava \
mockito-target-minus-junit4 \
frameworks-base-testutils \
diff --git a/wifi/tests/src/android/net/wifi/WifiNetworkScoreCacheTest.java b/wifi/tests/src/android/net/wifi/WifiNetworkScoreCacheTest.java
new file mode 100644
index 0000000..18f6bc8
--- /dev/null
+++ b/wifi/tests/src/android/net/wifi/WifiNetworkScoreCacheTest.java
@@ -0,0 +1,203 @@
+/*
+ * Copyright (C) 2016 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 static org.junit.Assert.*;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.net.NetworkKey;
+import android.net.RssiCurve;
+import android.net.ScoredNetwork;
+import android.net.WifiKey;
+import android.net.wifi.WifiNetworkScoreCache.CacheListener;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+
+import com.google.common.collect.ImmutableList;
+
+import org.junit.Rule;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+
+/** Unit tests for {@link WifiNetworkScoreCache}. */
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class WifiNetworkScoreCacheTest {
+
+ public static final String SSID = "ssid";
+ public static final String FORMATTED_SSID = "\"" + SSID + "\"";
+ public static final String BSSID = "AA:AA:AA:AA:AA:AA";
+
+ public static final WifiKey VALID_KEY = new WifiKey(FORMATTED_SSID, BSSID);
+
+ public static final ScanResult VALID_SCAN_RESULT = buildScanResult(SSID, BSSID);
+
+ @Mock private Context mockApplicationContext;
+ @Mock private Context mockContext; // isn't used, can be null
+ @Mock private RssiCurve mockRssiCurve;
+
+
+ private CacheListener mCacheListener;
+ private CountDownLatch mLatch;
+ private Handler mHandler;
+ private List<ScoredNetwork> mUpdatedNetworksCaptor;
+ private ScoredNetwork mValidScoredNetwork;
+ private WifiNetworkScoreCache mScoreCache;
+
+ private static ScanResult buildScanResult(String ssid, String bssid) {
+ return new ScanResult(
+ WifiSsid.createFromAsciiEncoded(ssid),
+ bssid,
+ "" /* caps */,
+ 0 /* level */,
+ 0 /* frequency */,
+ 0 /* tsf */,
+ 0 /* distCm */,
+ 0 /* distSdCm*/);
+ }
+
+ private static ScoredNetwork buildScoredNetwork(WifiKey key, RssiCurve curve) {
+ return new ScoredNetwork(new NetworkKey(key), curve);
+ }
+
+ // Called from setup
+ private void initializeCacheWithValidScoredNetwork() {
+ mScoreCache.updateScores(ImmutableList.of(mValidScoredNetwork));
+ }
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ when(mockContext.getApplicationContext()).thenReturn(mockApplicationContext);
+
+ mValidScoredNetwork = buildScoredNetwork(VALID_KEY, mockRssiCurve);
+ mScoreCache = new WifiNetworkScoreCache(mockContext);
+ initializeCacheWithValidScoredNetwork();
+
+ HandlerThread thread = new HandlerThread("WifiNetworkScoreCacheTest Handler Thread");
+ thread.start();
+ mHandler = new Handler(thread.getLooper());
+ mLatch = new CountDownLatch(1);
+ mCacheListener = new CacheListener(mHandler) {
+ @Override
+ public void networkCacheUpdated(List<ScoredNetwork> updatedNetworks) {
+ mUpdatedNetworksCaptor = updatedNetworks;
+ mLatch.countDown();
+ }
+ };
+ }
+
+
+ @Test
+ public void isScoredNetworkShouldReturnTrueAfterUpdateScoresIsCalled() {
+ assertTrue(mScoreCache.isScoredNetwork(VALID_SCAN_RESULT));
+ }
+
+ @Test
+ public void isScoredNetworkShouldReturnFalseAfterClearScoresIsCalled() {
+ mScoreCache.clearScores();
+ assertFalse(mScoreCache.isScoredNetwork(VALID_SCAN_RESULT));
+ }
+
+ @Test
+ public void updateScoresShouldAddNewNetwork() {
+ WifiKey key2 = new WifiKey("\"ssid2\"", BSSID);
+ ScoredNetwork network2 = buildScoredNetwork(key2, mockRssiCurve);
+ ScanResult result2 = buildScanResult("ssid2", BSSID);
+
+ mScoreCache.updateScores(ImmutableList.of(network2));
+
+ assertTrue(mScoreCache.isScoredNetwork(VALID_SCAN_RESULT));
+ assertTrue(mScoreCache.isScoredNetwork(result2));
+ }
+
+ @Test
+ public void hasScoreCurveShouldReturnTrue() {
+ assertTrue(mScoreCache.hasScoreCurve(VALID_SCAN_RESULT));
+ }
+
+ @Test
+ public void hasScoreCurveShouldReturnFalseWhenNoCachedNetwork() {
+ ScanResult unscored = buildScanResult("fake", BSSID);
+ assertFalse(mScoreCache.hasScoreCurve(unscored));
+ }
+
+ @Test
+ public void hasScoreCurveShouldReturnFalseWhenScoredNetworkHasNoCurve() {
+ ScoredNetwork noCurve = buildScoredNetwork(VALID_KEY, null /* rssiCurve */);
+ mScoreCache.updateScores(ImmutableList.of(noCurve));
+
+ assertFalse(mScoreCache.hasScoreCurve(VALID_SCAN_RESULT));
+ }
+
+ @Test
+ public void getNetworkScoreShouldReturnScore() {
+ final byte score = 50;
+ final int rssi = -70;
+ ScanResult result = new ScanResult(VALID_SCAN_RESULT);
+ result.level = rssi;
+
+ when(mockRssiCurve.lookupScore(rssi)).thenReturn(score);
+
+ assertEquals(score, mScoreCache.getNetworkScore(result));
+ }
+
+ @Test
+ public void getMeteredHintShouldReturnFalse() {
+ assertFalse(mScoreCache.getMeteredHint(VALID_SCAN_RESULT));
+ }
+
+ @Test
+ public void getMeteredHintShouldReturnTrue() {
+ ScoredNetwork network =
+ new ScoredNetwork(
+ new NetworkKey(VALID_KEY), mockRssiCurve, true /* metered Hint */);
+ mScoreCache.updateScores(ImmutableList.of(network));
+
+ assertTrue(mScoreCache.getMeteredHint(VALID_SCAN_RESULT));
+ }
+
+ @Test
+ public void updateScoresShouldInvokeCacheListener_networkCacheUpdated() {
+ mScoreCache = new WifiNetworkScoreCache(mockContext, mCacheListener);
+ initializeCacheWithValidScoredNetwork();
+
+ try {
+ mLatch.await(1, TimeUnit.SECONDS); // wait for listener to be executed
+ } catch (InterruptedException e) {
+ fail("Interrupted Exception while waiting for listener to be invoked.");
+ }
+ assertEquals("One network should be updated", 1, mUpdatedNetworksCaptor.size());
+ assertEquals(mValidScoredNetwork, mUpdatedNetworksCaptor.get(0));
+ }
+}