diff options
131 files changed, 2214 insertions, 3341 deletions
diff --git a/CleanSpec.mk b/CleanSpec.mk index 667ed025d1a7..48be749a5b37 100644 --- a/CleanSpec.mk +++ b/CleanSpec.mk @@ -234,6 +234,7 @@ $(call add-clean-step, rm -rf $(PRODUCT_OUT)/symbols/system/lib/libinputflingerh $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/lib/libinputflingerhost.so $(PRODUCT_OUT)/obj_arm/lib/libinputflingerhost.so) $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libinputflingerhost_intermediates $(PRODUCT_OUT)/obj_arm/SHARED_LIBRARIES/libinputflingerhost_intermediates) $(call add-clean-step, rm -rf $(PRODUCT_OUT)/target/common/obj/framework.aidl) +$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates) # ****************************************************************** # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST ABOVE THIS BANNER diff --git a/api/current.txt b/api/current.txt index 55b14db15478..43c1ade911ed 100644 --- a/api/current.txt +++ b/api/current.txt @@ -17,7 +17,6 @@ package android { field public static final java.lang.String ACCESS_WIFI_STATE = "android.permission.ACCESS_WIFI_STATE"; field public static final java.lang.String ACCOUNT_MANAGER = "android.permission.ACCOUNT_MANAGER"; field public static final java.lang.String ADD_VOICEMAIL = "com.android.voicemail.permission.ADD_VOICEMAIL"; - field public static final java.lang.String AUTHENTICATE_ACCOUNTS = "android.permission.AUTHENTICATE_ACCOUNTS"; field public static final java.lang.String BATTERY_STATS = "android.permission.BATTERY_STATS"; field public static final java.lang.String BIND_ACCESSIBILITY_SERVICE = "android.permission.BIND_ACCESSIBILITY_SERVICE"; field public static final java.lang.String BIND_APPWIDGET = "android.permission.BIND_APPWIDGET"; @@ -86,7 +85,6 @@ package android { field public static final java.lang.String INTERNET = "android.permission.INTERNET"; field public static final java.lang.String KILL_BACKGROUND_PROCESSES = "android.permission.KILL_BACKGROUND_PROCESSES"; field public static final java.lang.String LOCATION_HARDWARE = "android.permission.LOCATION_HARDWARE"; - field public static final java.lang.String MANAGE_ACCOUNTS = "android.permission.MANAGE_ACCOUNTS"; field public static final java.lang.String MANAGE_APP_TOKENS = "android.permission.MANAGE_APP_TOKENS"; field public static final java.lang.String MANAGE_DOCUMENTS = "android.permission.MANAGE_DOCUMENTS"; field public static final java.lang.String MASTER_CLEAR = "android.permission.MASTER_CLEAR"; @@ -145,7 +143,6 @@ package android { field public static final java.lang.String TRANSMIT_IR = "android.permission.TRANSMIT_IR"; field public static final java.lang.String UNINSTALL_SHORTCUT = "com.android.launcher.permission.UNINSTALL_SHORTCUT"; field public static final java.lang.String UPDATE_DEVICE_STATS = "android.permission.UPDATE_DEVICE_STATS"; - field public static final java.lang.String USE_CREDENTIALS = "android.permission.USE_CREDENTIALS"; field public static final java.lang.String USE_FINGERPRINT = "android.permission.USE_FINGERPRINT"; field public static final java.lang.String USE_SIP = "android.permission.USE_SIP"; field public static final java.lang.String VIBRATE = "android.permission.VIBRATE"; @@ -5681,23 +5678,6 @@ package android.app.admin { field public static final java.lang.String EXTRA_LOCK_TASK_PACKAGE = "android.app.extra.LOCK_TASK_PACKAGE"; } - public class DeviceInitializerStatus { - field public static final int FLAG_STATUS_CUSTOM = 33554432; // 0x2000000 - field public static final int FLAG_STATUS_ERROR = 16777216; // 0x1000000 - field public static final int FLAG_STATUS_HIGH_PRIORITY = 134217728; // 0x8000000 - field public static final int FLAG_STATUS_RESERVED = 67108864; // 0x4000000 - field public static final int STATUS_ERROR_CONNECT_WIFI = 16777237; // 0x1000015 - field public static final int STATUS_ERROR_DELETE_APPS = 16777242; // 0x100001a - field public static final int STATUS_ERROR_DOUBLE_BUMP = 16777246; // 0x100001e - field public static final int STATUS_ERROR_DOWNLOAD_PACKAGE = 16777239; // 0x1000017 - field public static final int STATUS_ERROR_INSTALL_PACKAGE = 16777240; // 0x1000018 - field public static final int STATUS_ERROR_RESET_PROTECTION_BLOCKING_PROVISIONING = 16777238; // 0x1000016 - field public static final int STATUS_ERROR_SET_DEVICE_POLICY = 16777241; // 0x1000019 - field public static final int STATUS_STATE_CONNECTING_BLUETOOTH_PROXY = 134217736; // 0x8000008 - field public static final int STATUS_STATE_DEVICE_PROVISIONED = 134217738; // 0x800000a - field public static final int STATUS_STATE_DISCONNECTING_BLUETOOTH_PROXY = 134217737; // 0x8000009 - } - public class DevicePolicyManager { method public void addCrossProfileIntentFilter(android.content.ComponentName, android.content.IntentFilter, int); method public boolean addCrossProfileWidgetProvider(android.content.ComponentName, java.lang.String); @@ -5765,7 +5745,6 @@ package android.app.admin { method public boolean removeCrossProfileWidgetProvider(android.content.ComponentName, java.lang.String); method public boolean removeUser(android.content.ComponentName, android.os.UserHandle); method public boolean resetPassword(java.lang.String, int); - method public void sendDeviceInitializerStatus(int, java.lang.String); method public void setAccountManagementDisabled(android.content.ComponentName, java.lang.String, boolean); method public boolean setApplicationHidden(android.content.ComponentName, java.lang.String, boolean); method public void setApplicationRestrictions(android.content.ComponentName, java.lang.String, android.os.Bundle); @@ -5829,10 +5808,6 @@ package android.app.admin { field public static final java.lang.String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; field public static final java.lang.String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; field public static final java.lang.String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; - field public static final java.lang.String EXTRA_PROVISIONING_BT_DEVICE_ID = "android.app.extra.PROVISIONING_BT_DEVICE_ID"; - field public static final java.lang.String EXTRA_PROVISIONING_BT_MAC_ADDRESS = "android.app.extra.PROVISIONING_BT_MAC_ADDRESS"; - field public static final java.lang.String EXTRA_PROVISIONING_BT_USE_PROXY = "android.app.extra.PROVISIONING_BT_USE_PROXY"; - field public static final java.lang.String EXTRA_PROVISIONING_BT_UUID = "android.app.extra.PROVISIONING_BT_UUID"; field public static final java.lang.String EXTRA_PROVISIONING_DEVICE_ADMIN_CERTIFICATE_CHECKSUM = "android.app.extra.PROVISIONING_DEVICE_ADMIN_CERTIFICATE_CHECKSUM"; field public static final java.lang.String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; field public static final java.lang.String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; @@ -6148,10 +6123,10 @@ package android.app.usage { method public java.lang.String getPackageName(); method public long getTimeStamp(); field public static final int CONFIGURATION_CHANGE = 5; // 0x5 - field public static final int INTERACTION = 6; // 0x6 field public static final int MOVE_TO_BACKGROUND = 2; // 0x2 field public static final int MOVE_TO_FOREGROUND = 1; // 0x1 field public static final int NONE = 0; // 0x0 + field public static final int USER_INTERACTION = 7; // 0x7 } public final class UsageStats implements android.os.Parcelable { @@ -24477,6 +24452,7 @@ package android.printservice { method protected abstract void onPrintJobQueued(android.printservice.PrintJob); method protected abstract void onRequestCancelPrintJob(android.printservice.PrintJob); field public static final java.lang.String EXTRA_PRINTER_INFO = "android.intent.extra.print.EXTRA_PRINTER_INFO"; + field public static final java.lang.String EXTRA_PRINT_DOCUMENT_INFO = "android.printservice.extra.PRINT_DOCUMENT_INFO"; field public static final java.lang.String EXTRA_PRINT_JOB_INFO = "android.intent.extra.print.PRINT_JOB_INFO"; field public static final java.lang.String SERVICE_INTERFACE = "android.printservice.PrintService"; field public static final java.lang.String SERVICE_META_DATA = "android.printservice"; @@ -33930,7 +33906,7 @@ package android.util { public final class ArrayMap implements java.util.Map { ctor public ArrayMap(); ctor public ArrayMap(int); - ctor public ArrayMap(android.util.ArrayMap); + ctor public ArrayMap(android.util.ArrayMap<K, V>); method public void clear(); method public boolean containsAll(java.util.Collection<?>); method public boolean containsKey(java.lang.Object); @@ -33955,6 +33931,31 @@ package android.util { method public java.util.Collection<V> values(); } + public final class ArraySet implements java.util.Collection java.util.Set { + ctor public ArraySet(); + ctor public ArraySet(int); + ctor public ArraySet(android.util.ArraySet<E>); + method public boolean add(E); + method public void addAll(android.util.ArraySet<? extends E>); + method public boolean addAll(java.util.Collection<? extends E>); + method public void clear(); + method public boolean contains(java.lang.Object); + method public boolean containsAll(java.util.Collection<?>); + method public void ensureCapacity(int); + method public int indexOf(java.lang.Object); + method public boolean isEmpty(); + method public java.util.Iterator<E> iterator(); + method public boolean remove(java.lang.Object); + method public boolean removeAll(android.util.ArraySet<? extends E>); + method public boolean removeAll(java.util.Collection<?>); + method public E removeAt(int); + method public boolean retainAll(java.util.Collection<?>); + method public int size(); + method public java.lang.Object[] toArray(); + method public T[] toArray(T[]); + method public E valueAt(int); + } + public class AtomicFile { ctor public AtomicFile(java.io.File); method public void delete(); diff --git a/api/removed.txt b/api/removed.txt index 0046a700b72d..f6ad27bd92f4 100644 --- a/api/removed.txt +++ b/api/removed.txt @@ -1,12 +1,3 @@ -package android { - - public static final class Manifest.permission { - field public static final java.lang.String SUBSCRIBED_FEEDS_READ = "android.permission.SUBSCRIBED_FEEDS_READ"; - field public static final java.lang.String SUBSCRIBED_FEEDS_WRITE = "android.permission.SUBSCRIBED_FEEDS_WRITE"; - } - -} - package android.content.pm { public class PackageInfo implements android.os.Parcelable { diff --git a/api/system-current.txt b/api/system-current.txt index 67bcdf51098c..2345ef6d0a30 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -24,7 +24,6 @@ package android { field public static final java.lang.String ACCOUNT_MANAGER = "android.permission.ACCOUNT_MANAGER"; field public static final java.lang.String ADD_VOICEMAIL = "com.android.voicemail.permission.ADD_VOICEMAIL"; field public static final java.lang.String ALLOW_ANY_CODEC_FOR_PLAYBACK = "android.permission.ALLOW_ANY_CODEC_FOR_PLAYBACK"; - field public static final java.lang.String AUTHENTICATE_ACCOUNTS = "android.permission.AUTHENTICATE_ACCOUNTS"; field public static final java.lang.String BACKUP = "android.permission.BACKUP"; field public static final java.lang.String BATTERY_STATS = "android.permission.BATTERY_STATS"; field public static final java.lang.String BIND_ACCESSIBILITY_SERVICE = "android.permission.BIND_ACCESSIBILITY_SERVICE"; @@ -117,7 +116,6 @@ package android { field public static final java.lang.String LOCAL_MAC_ADDRESS = "android.permission.LOCAL_MAC_ADDRESS"; field public static final java.lang.String LOCATION_HARDWARE = "android.permission.LOCATION_HARDWARE"; field public static final java.lang.String LOOP_RADIO = "android.permission.LOOP_RADIO"; - field public static final java.lang.String MANAGE_ACCOUNTS = "android.permission.MANAGE_ACCOUNTS"; field public static final java.lang.String MANAGE_ACTIVITY_STACKS = "android.permission.MANAGE_ACTIVITY_STACKS"; field public static final java.lang.String MANAGE_APP_TOKENS = "android.permission.MANAGE_APP_TOKENS"; field public static final java.lang.String MANAGE_CA_CERTIFICATES = "android.permission.MANAGE_CA_CERTIFICATES"; @@ -217,7 +215,6 @@ package android { field public static final java.lang.String UPDATE_DEVICE_STATS = "android.permission.UPDATE_DEVICE_STATS"; field public static final java.lang.String UPDATE_LOCK = "android.permission.UPDATE_LOCK"; field public static final java.lang.String USER_ACTIVITY = "android.permission.USER_ACTIVITY"; - field public static final java.lang.String USE_CREDENTIALS = "android.permission.USE_CREDENTIALS"; field public static final java.lang.String USE_FINGERPRINT = "android.permission.USE_FINGERPRINT"; field public static final java.lang.String USE_SIP = "android.permission.USE_SIP"; field public static final java.lang.String VIBRATE = "android.permission.VIBRATE"; @@ -5781,23 +5778,6 @@ package android.app.admin { field public static final java.lang.String EXTRA_LOCK_TASK_PACKAGE = "android.app.extra.LOCK_TASK_PACKAGE"; } - public class DeviceInitializerStatus { - field public static final int FLAG_STATUS_CUSTOM = 33554432; // 0x2000000 - field public static final int FLAG_STATUS_ERROR = 16777216; // 0x1000000 - field public static final int FLAG_STATUS_HIGH_PRIORITY = 134217728; // 0x8000000 - field public static final int FLAG_STATUS_RESERVED = 67108864; // 0x4000000 - field public static final int STATUS_ERROR_CONNECT_WIFI = 16777237; // 0x1000015 - field public static final int STATUS_ERROR_DELETE_APPS = 16777242; // 0x100001a - field public static final int STATUS_ERROR_DOUBLE_BUMP = 16777246; // 0x100001e - field public static final int STATUS_ERROR_DOWNLOAD_PACKAGE = 16777239; // 0x1000017 - field public static final int STATUS_ERROR_INSTALL_PACKAGE = 16777240; // 0x1000018 - field public static final int STATUS_ERROR_RESET_PROTECTION_BLOCKING_PROVISIONING = 16777238; // 0x1000016 - field public static final int STATUS_ERROR_SET_DEVICE_POLICY = 16777241; // 0x1000019 - field public static final int STATUS_STATE_CONNECTING_BLUETOOTH_PROXY = 134217736; // 0x8000008 - field public static final int STATUS_STATE_DEVICE_PROVISIONED = 134217738; // 0x800000a - field public static final int STATUS_STATE_DISCONNECTING_BLUETOOTH_PROXY = 134217737; // 0x8000009 - } - public class DevicePolicyManager { method public void addCrossProfileIntentFilter(android.content.ComponentName, android.content.IntentFilter, int); method public boolean addCrossProfileWidgetProvider(android.content.ComponentName, java.lang.String); @@ -5874,7 +5854,6 @@ package android.app.admin { method public boolean removeCrossProfileWidgetProvider(android.content.ComponentName, java.lang.String); method public boolean removeUser(android.content.ComponentName, android.os.UserHandle); method public boolean resetPassword(java.lang.String, int); - method public void sendDeviceInitializerStatus(int, java.lang.String); method public void setAccountManagementDisabled(android.content.ComponentName, java.lang.String, boolean); method public deprecated boolean setActiveProfileOwner(android.content.ComponentName, java.lang.String) throws java.lang.IllegalArgumentException; method public boolean setApplicationHidden(android.content.ComponentName, java.lang.String, boolean); @@ -5927,7 +5906,6 @@ package android.app.admin { field public static final java.lang.String ACTION_MANAGED_PROFILE_PROVISIONED = "android.app.action.MANAGED_PROFILE_PROVISIONED"; field public static final java.lang.String ACTION_PROVISION_MANAGED_DEVICE = "android.app.action.PROVISION_MANAGED_DEVICE"; field public static final java.lang.String ACTION_PROVISION_MANAGED_PROFILE = "android.app.action.PROVISION_MANAGED_PROFILE"; - field public static final java.lang.String ACTION_SEND_DEVICE_INITIALIZER_STATUS = "android.app.action.SEND_DEVICE_INITIALIZER_STATUS"; field public static final java.lang.String ACTION_SET_NEW_PASSWORD = "android.app.action.SET_NEW_PASSWORD"; field public static final java.lang.String ACTION_SET_PROFILE_OWNER = "android.app.action.SET_PROFILE_OWNER"; field public static final java.lang.String ACTION_START_ENCRYPTION = "android.app.action.START_ENCRYPTION"; @@ -5939,15 +5917,9 @@ package android.app.admin { field public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; // 0x0 field public static final java.lang.String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION"; field public static final java.lang.String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN"; - field public static final java.lang.String EXTRA_DEVICE_INITIALIZER_STATUS_CODE = "android.app.extra.DEVICE_INITIALIZER_STATUS_CODE"; - field public static final java.lang.String EXTRA_DEVICE_INITIALIZER_STATUS_DESCRIPTION = "android.app.extra.DEVICE_INITIALIZER_STATUS_DESCRIPTION"; field public static final java.lang.String EXTRA_PROFILE_OWNER_NAME = "android.app.extra.PROFILE_OWNER_NAME"; field public static final java.lang.String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE = "android.app.extra.PROVISIONING_ACCOUNT_TO_MIGRATE"; field public static final java.lang.String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE = "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE"; - field public static final java.lang.String EXTRA_PROVISIONING_BT_DEVICE_ID = "android.app.extra.PROVISIONING_BT_DEVICE_ID"; - field public static final java.lang.String EXTRA_PROVISIONING_BT_MAC_ADDRESS = "android.app.extra.PROVISIONING_BT_MAC_ADDRESS"; - field public static final java.lang.String EXTRA_PROVISIONING_BT_USE_PROXY = "android.app.extra.PROVISIONING_BT_USE_PROXY"; - field public static final java.lang.String EXTRA_PROVISIONING_BT_UUID = "android.app.extra.PROVISIONING_BT_UUID"; field public static final java.lang.String EXTRA_PROVISIONING_DEVICE_ADMIN_CERTIFICATE_CHECKSUM = "android.app.extra.PROVISIONING_DEVICE_ADMIN_CERTIFICATE_CHECKSUM"; field public static final java.lang.String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME = "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME"; field public static final java.lang.String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE = "android.app.extra.PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE"; @@ -6341,10 +6313,10 @@ package android.app.usage { method public java.lang.String getPackageName(); method public long getTimeStamp(); field public static final int CONFIGURATION_CHANGE = 5; // 0x5 - field public static final int INTERACTION = 6; // 0x6 field public static final int MOVE_TO_BACKGROUND = 2; // 0x2 field public static final int MOVE_TO_FOREGROUND = 1; // 0x1 field public static final int NONE = 0; // 0x0 + field public static final int USER_INTERACTION = 7; // 0x7 } public final class UsageStats implements android.os.Parcelable { @@ -26415,6 +26387,7 @@ package android.printservice { method protected abstract void onPrintJobQueued(android.printservice.PrintJob); method protected abstract void onRequestCancelPrintJob(android.printservice.PrintJob); field public static final java.lang.String EXTRA_PRINTER_INFO = "android.intent.extra.print.EXTRA_PRINTER_INFO"; + field public static final java.lang.String EXTRA_PRINT_DOCUMENT_INFO = "android.printservice.extra.PRINT_DOCUMENT_INFO"; field public static final java.lang.String EXTRA_PRINT_JOB_INFO = "android.intent.extra.print.PRINT_JOB_INFO"; field public static final java.lang.String SERVICE_INTERFACE = "android.printservice.PrintService"; field public static final java.lang.String SERVICE_META_DATA = "android.printservice"; @@ -36210,7 +36183,7 @@ package android.util { public final class ArrayMap implements java.util.Map { ctor public ArrayMap(); ctor public ArrayMap(int); - ctor public ArrayMap(android.util.ArrayMap); + ctor public ArrayMap(android.util.ArrayMap<K, V>); method public void clear(); method public boolean containsAll(java.util.Collection<?>); method public boolean containsKey(java.lang.Object); @@ -36235,6 +36208,31 @@ package android.util { method public java.util.Collection<V> values(); } + public final class ArraySet implements java.util.Collection java.util.Set { + ctor public ArraySet(); + ctor public ArraySet(int); + ctor public ArraySet(android.util.ArraySet<E>); + method public boolean add(E); + method public void addAll(android.util.ArraySet<? extends E>); + method public boolean addAll(java.util.Collection<? extends E>); + method public void clear(); + method public boolean contains(java.lang.Object); + method public boolean containsAll(java.util.Collection<?>); + method public void ensureCapacity(int); + method public int indexOf(java.lang.Object); + method public boolean isEmpty(); + method public java.util.Iterator<E> iterator(); + method public boolean remove(java.lang.Object); + method public boolean removeAll(android.util.ArraySet<? extends E>); + method public boolean removeAll(java.util.Collection<?>); + method public E removeAt(int); + method public boolean retainAll(java.util.Collection<?>); + method public int size(); + method public java.lang.Object[] toArray(); + method public T[] toArray(T[]); + method public E valueAt(int); + } + public class AtomicFile { ctor public AtomicFile(java.io.File); method public void delete(); diff --git a/api/system-removed.txt b/api/system-removed.txt index 0046a700b72d..f6ad27bd92f4 100644 --- a/api/system-removed.txt +++ b/api/system-removed.txt @@ -1,12 +1,3 @@ -package android { - - public static final class Manifest.permission { - field public static final java.lang.String SUBSCRIBED_FEEDS_READ = "android.permission.SUBSCRIBED_FEEDS_READ"; - field public static final java.lang.String SUBSCRIBED_FEEDS_WRITE = "android.permission.SUBSCRIBED_FEEDS_WRITE"; - } - -} - package android.content.pm { public class PackageInfo implements android.os.Parcelable { diff --git a/core/java/android/accounts/AccountManager.java b/core/java/android/accounts/AccountManager.java index 31e129b787f6..993b53d17d70 100644 --- a/core/java/android/accounts/AccountManager.java +++ b/core/java/android/accounts/AccountManager.java @@ -51,10 +51,7 @@ import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import static android.Manifest.permission.AUTHENTICATE_ACCOUNTS; import static android.Manifest.permission.GET_ACCOUNTS; -import static android.Manifest.permission.MANAGE_ACCOUNTS; -import static android.Manifest.permission.USE_CREDENTIALS; /** * This class provides access to a centralized registry of the user's @@ -319,14 +316,12 @@ public class AccountManager { * * <p>It is safe to call this method from the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#AUTHENTICATE_ACCOUNTS} - * and to have the same UID as the account's authenticator. + * <p>This method requires the caller to have a signature match with the + * authenticator that owns the specified account. * - * @param account The account to query for a password + * @param account The account to query for a password. Must not be {@code null}. * @return The account's password, null if none or if the account doesn't exist */ - @RequiresPermission(AUTHENTICATE_ACCOUNTS) public String getPassword(final Account account) { if (account == null) throw new IllegalArgumentException("account is null"); try { @@ -345,14 +340,12 @@ public class AccountManager { * * <p>It is safe to call this method from the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#AUTHENTICATE_ACCOUNTS} - * and to have the same UID as the account's authenticator. + * <p>This method requires the caller to have a signature match with the + * authenticator that owns the specified account. * * @param account The account to query for user data * @return The user data, null if the account or key doesn't exist */ - @RequiresPermission(AUTHENTICATE_ACCOUNTS) public String getUserData(final Account account, final String key) { if (account == null) throw new IllegalArgumentException("account is null"); if (key == null) throw new IllegalArgumentException("key is null"); @@ -662,10 +655,8 @@ public class AccountManager { * wizards associated with authenticators, not directly by applications. * * <p>It is safe to call this method from the main thread. - * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#AUTHENTICATE_ACCOUNTS} - * and to have the same UID as the added account's authenticator. + * <p>This method requires the caller to have a signature match with the + * authenticator that owns the specified account. * * @param account The {@link Account} to add * @param password The password to associate with the account, null for none @@ -673,7 +664,6 @@ public class AccountManager { * @return True if the account was successfully added, false if the account * already exists, the account is null, or another error occurs. */ - @RequiresPermission(AUTHENTICATE_ACCOUNTS) public boolean addAccountExplicitly(Account account, String password, Bundle userdata) { if (account == null) throw new IllegalArgumentException("account is null"); try { @@ -692,14 +682,13 @@ public class AccountManager { * <p> * It is not safe to call this method from the main thread. As such, call it * from another thread. - * <p> - * This method requires the caller to hold the permission - * {@link android.Manifest.permission#AUTHENTICATE_ACCOUNTS} and should be - * called from the account's authenticator. + * <p>This method requires the caller to have a signature match with the + * authenticator that owns the specified account. * * @param account The {@link Account} to be updated. + * @return boolean {@code true} if the authentication of the account has been successfully + * acknowledged. Otherwise {@code false}. */ - @RequiresPermission(AUTHENTICATE_ACCOUNTS) public boolean notifyAccountAuthenticated(Account account) { if (account == null) throw new IllegalArgumentException("account is null"); @@ -717,9 +706,8 @@ public class AccountManager { * * <p>It is safe to call this method from the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#AUTHENTICATE_ACCOUNTS} - * and have the same UID as the account's authenticator. + * <p>This method requires the caller to have a signature match with the + * authenticator that manages the specified account. * * @param account The {@link Account} to rename * @param newName String name to be associated with the account. @@ -731,7 +719,6 @@ public class AccountManager { * after the name change. If successful the account's name will be the * specified new name. */ - @RequiresPermission(AUTHENTICATE_ACCOUNTS) public AccountManagerFuture<Account> renameAccount( final Account account, @Size(min = 1) final String newName, @@ -783,11 +770,8 @@ public class AccountManager { * The authenticator may have its own policies preventing account * deletion, in which case the account will not be deleted. * - * <p>This method may be called from any thread, but the returned - * {@link AccountManagerFuture} must not be used on the main thread. - * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#MANAGE_ACCOUNTS}. + * <p>This method requires the caller to have a signature match with the + * authenticator that manages the specified account. * * @param account The {@link Account} to remove * @param callback Callback to invoke when the request completes, @@ -800,15 +784,16 @@ public class AccountManager { * {@link #removeAccount(Account, Activity, AccountManagerCallback, Handler)} * instead */ - @RequiresPermission(MANAGE_ACCOUNTS) @Deprecated public AccountManagerFuture<Boolean> removeAccount(final Account account, AccountManagerCallback<Boolean> callback, Handler handler) { if (account == null) throw new IllegalArgumentException("account is null"); return new Future2Task<Boolean>(handler, callback) { + @Override public void doWork() throws RemoteException { mService.removeAccount(mResponse, account, false); } + @Override public Boolean bundleToResult(Bundle bundle) throws AuthenticatorException { if (!bundle.containsKey(KEY_BOOLEAN_RESULT)) { throw new AuthenticatorException("no result in response"); @@ -827,8 +812,8 @@ public class AccountManager { * <p>This method may be called from any thread, but the returned * {@link AccountManagerFuture} must not be used on the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#MANAGE_ACCOUNTS}. + * <p>This method requires the caller to have a signature match with the + * authenticator that manages the specified account. * * @param account The {@link Account} to remove * @param activity The {@link Activity} context to use for launching a new @@ -855,11 +840,11 @@ public class AccountManager { * adding accounts (of this type) has been disabled by policy * </ul> */ - @RequiresPermission(MANAGE_ACCOUNTS) public AccountManagerFuture<Bundle> removeAccount(final Account account, final Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) { if (account == null) throw new IllegalArgumentException("account is null"); return new AmsTask(activity, handler, callback) { + @Override public void doWork() throws RemoteException { mService.removeAccount(mResponse, account, activity != null); } @@ -880,9 +865,11 @@ public class AccountManager { if (account == null) throw new IllegalArgumentException("account is null"); if (userHandle == null) throw new IllegalArgumentException("userHandle is null"); return new Future2Task<Boolean>(handler, callback) { + @Override public void doWork() throws RemoteException { mService.removeAccountAsUser(mResponse, account, false, userHandle.getIdentifier()); } + @Override public Boolean bundleToResult(Bundle bundle) throws AuthenticatorException { if (!bundle.containsKey(KEY_BOOLEAN_RESULT)) { throw new AuthenticatorException("no result in response"); @@ -918,17 +905,14 @@ public class AccountManager { * in which case the account will not be deleted. * <p> * It is safe to call this method from the main thread. - * <p> - * This method requires the caller to hold the permission - * {@link android.Manifest.permission#AUTHENTICATE_ACCOUNTS} and to have the - * same UID or signature as the account's authenticator. + * <p>This method requires the caller to have a signature match with the + * authenticator that manages the specified account. * * @param account The {@link Account} to delete. * @return True if the account was successfully deleted, false if the * account did not exist, the account is null, or another error * occurs. */ - @RequiresPermission(AUTHENTICATE_ACCOUNTS) public boolean removeAccountExplicitly(Account account) { if (account == null) throw new IllegalArgumentException("account is null"); try { @@ -948,14 +932,9 @@ public class AccountManager { * * <p>It is safe to call this method from the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#MANAGE_ACCOUNTS} or - * {@link android.Manifest.permission#USE_CREDENTIALS} - * * @param accountType The account type of the auth token to invalidate, must not be null * @param authToken The auth token to invalidate, may be null */ - @RequiresPermission(anyOf = {MANAGE_ACCOUNTS, USE_CREDENTIALS}) public void invalidateAuthToken(final String accountType, final String authToken) { if (accountType == null) throw new IllegalArgumentException("accountType is null"); try { @@ -976,16 +955,15 @@ public class AccountManager { * * <p>It is safe to call this method from the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#AUTHENTICATE_ACCOUNTS} - * and to have the same UID as the account's authenticator. + * <p>This method requires the caller to have a signature match with the + * authenticator that manages the specified account. * - * @param account The account to fetch an auth token for - * @param authTokenType The type of auth token to fetch, see {#getAuthToken} + * @param account The account for which an auth token is to be fetched. Cannot be {@code null}. + * @param authTokenType The type of auth token to fetch. Cannot be {@code null}. * @return The cached auth token for this account and type, or null if * no auth token is cached or the account does not exist. + * @see #getAuthToken */ - @RequiresPermission(AUTHENTICATE_ACCOUNTS) public String peekAuthToken(final Account account, final String authTokenType) { if (account == null) throw new IllegalArgumentException("account is null"); if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null"); @@ -1005,14 +983,12 @@ public class AccountManager { * * <p>It is safe to call this method from the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#AUTHENTICATE_ACCOUNTS} - * and have the same UID as the account's authenticator. + * <p>This method requires the caller to have a signature match with the + * authenticator that manages the specified account. * - * @param account The account to set a password for + * @param account The account whose password is to be set. Cannot be {@code null}. * @param password The password to set, null to clear the password */ - @RequiresPermission(AUTHENTICATE_ACCOUNTS) public void setPassword(final Account account, final String password) { if (account == null) throw new IllegalArgumentException("account is null"); try { @@ -1030,14 +1006,14 @@ public class AccountManager { * permissions, and may be used by applications or management interfaces * to "sign out" from an account. * - * <p>It is safe to call this method from the main thread. + * <p>This method only successfully clear the account's password when the + * caller has the same signature as the authenticator that owns the + * specified account. Otherwise, this method will silently fail. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#MANAGE_ACCOUNTS} + * <p>It is safe to call this method from the main thread. * * @param account The account whose password to clear */ - @RequiresPermission(MANAGE_ACCOUNTS) public void clearPassword(final Account account) { if (account == null) throw new IllegalArgumentException("account is null"); try { @@ -1055,15 +1031,13 @@ public class AccountManager { * * <p>It is safe to call this method from the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#AUTHENTICATE_ACCOUNTS} - * and to have the same UID as the account's authenticator. + * <p>This method requires the caller to have a signature match with the + * authenticator that manages the specified account. * - * @param account The account to set the userdata for - * @param key The userdata key to set. Must not be null - * @param value The value to set, null to clear this userdata key + * @param account Account whose user data is to be set. Must not be {@code null}. + * @param key String user data key to set. Must not be null + * @param value String value to set, {@code null} to clear this user data key */ - @RequiresPermission(AUTHENTICATE_ACCOUNTS) public void setUserData(final Account account, final String key, final String value) { if (account == null) throw new IllegalArgumentException("account is null"); if (key == null) throw new IllegalArgumentException("key is null"); @@ -1083,15 +1057,13 @@ public class AccountManager { * * <p>It is safe to call this method from the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#AUTHENTICATE_ACCOUNTS} - * and to have the same UID as the account's authenticator. + * <p>This method requires the caller to have a signature match with the + * authenticator that manages the specified account. * * @param account The account to set an auth token for * @param authTokenType The type of the auth token, see {#getAuthToken} * @param authToken The auth token to add to the cache */ - @RequiresPermission(AUTHENTICATE_ACCOUNTS) public void setAuthToken(Account account, final String authTokenType, final String authToken) { if (account == null) throw new IllegalArgumentException("account is null"); if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null"); @@ -1110,9 +1082,6 @@ public class AccountManager { * <p>This method may block while a network request completes, and must * never be made from the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#USE_CREDENTIALS}. - * * @param account The account to fetch an auth token for * @param authTokenType The auth token type, see {@link #getAuthToken getAuthToken()} * @param notifyAuthFailure If true, display a notification and return null @@ -1126,7 +1095,6 @@ public class AccountManager { * @throws java.io.IOException if the authenticator experienced an I/O problem * creating a new auth token, usually because of network trouble */ - @RequiresPermission(USE_CREDENTIALS) public String blockingGetAuthToken(Account account, String authTokenType, boolean notifyAuthFailure) throws OperationCanceledException, IOException, AuthenticatorException { @@ -1165,9 +1133,6 @@ public class AccountManager { * <p>This method may be called from any thread, but the returned * {@link AccountManagerFuture} must not be used on the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#USE_CREDENTIALS}. - * * @param account The account to fetch an auth token for * @param authTokenType The auth token type, an authenticator-dependent * string token, must not be null @@ -1201,7 +1166,6 @@ public class AccountManager { * authenticator-dependent. The caller should verify the validity of the * account before requesting an auth token. */ - @RequiresPermission(USE_CREDENTIALS) public AccountManagerFuture<Bundle> getAuthToken( final Account account, final String authTokenType, final Bundle options, final Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) { @@ -1253,9 +1217,6 @@ public class AccountManager { * <p>This method may be called from any thread, but the returned * {@link AccountManagerFuture} must not be used on the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#USE_CREDENTIALS}. - * * @param account The account to fetch an auth token for * @param authTokenType The auth token type, an authenticator-dependent * string token, must not be null @@ -1292,7 +1253,6 @@ public class AccountManager { * boolean, AccountManagerCallback, android.os.Handler)} instead */ @Deprecated - @RequiresPermission(USE_CREDENTIALS) public AccountManagerFuture<Bundle> getAuthToken( final Account account, final String authTokenType, final boolean notifyAuthFailure, @@ -1333,9 +1293,6 @@ public class AccountManager { * <p>This method may be called from any thread, but the returned * {@link AccountManagerFuture} must not be used on the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#USE_CREDENTIALS}. - * * @param account The account to fetch an auth token for * @param authTokenType The auth token type, an authenticator-dependent * string token, must not be null @@ -1371,7 +1328,6 @@ public class AccountManager { * authenticator-dependent. The caller should verify the validity of the * account before requesting an auth token. */ - @RequiresPermission(USE_CREDENTIALS) public AccountManagerFuture<Bundle> getAuthToken( final Account account, final String authTokenType, final Bundle options, final boolean notifyAuthFailure, @@ -1401,9 +1357,6 @@ public class AccountManager { * <p>This method may be called from any thread, but the returned * {@link AccountManagerFuture} must not be used on the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#MANAGE_ACCOUNTS}. - * * @param accountType The type of account to add; must not be null * @param authTokenType The type of auth token (see {@link #getAuthToken}) * this account will need to be able to generate, null for none @@ -1441,7 +1394,6 @@ public class AccountManager { * creating a new account, usually because of network trouble * </ul> */ - @RequiresPermission(MANAGE_ACCOUNTS) public AccountManagerFuture<Bundle> addAccount(final String accountType, final String authTokenType, final String[] requiredFeatures, final Bundle addAccountOptions, @@ -1586,9 +1538,6 @@ public class AccountManager { * <p>This method may be called from any thread, but the returned * {@link AccountManagerFuture} must not be used on the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#MANAGE_ACCOUNTS}. - * * @param account The account to confirm password knowledge for * @param options Authenticator-specific options for the request; * if the {@link #KEY_PASSWORD} string field is present, the @@ -1615,11 +1564,11 @@ public class AccountManager { * If no activity or password was specified, the returned Bundle contains * {@link #KEY_INTENT} with the {@link Intent} needed to launch the * password prompt. - * + * * <p>Also the returning Bundle may contain {@link * #KEY_LAST_AUTHENTICATED_TIME} indicating the last time the * credential was validated/created. - * + * * If an error occurred,{@link AccountManagerFuture#getResult()} throws: * <ul> * <li> {@link AuthenticatorException} if the authenticator failed to respond @@ -1629,7 +1578,6 @@ public class AccountManager { * verifying the password, usually because of network trouble * </ul> */ - @RequiresPermission(MANAGE_ACCOUNTS) public AccountManagerFuture<Bundle> confirmCredentials(final Account account, final Bundle options, final Activity activity, @@ -1668,9 +1616,6 @@ public class AccountManager { * <p>This method may be called from any thread, but the returned * {@link AccountManagerFuture} must not be used on the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#MANAGE_ACCOUNTS}. - * * @param account The account to update credentials for * @param authTokenType The credentials entered must allow an auth token * of this type to be created (but no actual auth token is returned); @@ -1706,7 +1651,6 @@ public class AccountManager { * verifying the password, usually because of network trouble * </ul> */ - @RequiresPermission(MANAGE_ACCOUNTS) public AccountManagerFuture<Bundle> updateCredentials(final Account account, final String authTokenType, final Bundle options, final Activity activity, @@ -1729,8 +1673,8 @@ public class AccountManager { * <p>This method may be called from any thread, but the returned * {@link AccountManagerFuture} must not be used on the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#MANAGE_ACCOUNTS}. + * <p>This method requires the caller to have the same signature as the + * authenticator associated with the specified account type. * * @param accountType The account type associated with the authenticator * to adjust @@ -1758,7 +1702,6 @@ public class AccountManager { * updating settings, usually because of network trouble * </ul> */ - @RequiresPermission(MANAGE_ACCOUNTS) public AccountManagerFuture<Bundle> editProperties(final String accountType, final Activity activity, final AccountManagerCallback<Bundle> callback, final Handler handler) { @@ -2253,9 +2196,6 @@ public class AccountManager { * <p>This method may be called from any thread, but the returned * {@link AccountManagerFuture} must not be used on the main thread. * - * <p>This method requires the caller to hold the permission - * {@link android.Manifest.permission#MANAGE_ACCOUNTS}. - * * @param accountType The account type required * (see {@link #getAccountsByType}), must not be null * @param authTokenType The desired auth token type @@ -2292,7 +2232,6 @@ public class AccountManager { * updating settings, usually because of network trouble * </ul> */ - @RequiresPermission(MANAGE_ACCOUNTS) public AccountManagerFuture<Bundle> getAuthTokenByFeatures( final String accountType, final String authTokenType, final String[] features, final Activity activity, final Bundle addAccountOptions, diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java index 9604789895f5..c2bf28a931c8 100644 --- a/core/java/android/app/LoadedApk.java +++ b/core/java/android/app/LoadedApk.java @@ -55,6 +55,7 @@ import java.lang.ref.WeakReference; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; +import java.util.List; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; @@ -166,6 +167,7 @@ public final class LoadedApk { if (runtimeIsa.equals(secondaryIsa)) { final ApplicationInfo modified = new ApplicationInfo(info); modified.nativeLibraryDir = modified.secondaryNativeLibraryDir; + modified.primaryCpuAbi = modified.secondaryCpuAbi; return modified; } } @@ -272,8 +274,9 @@ public final class LoadedApk { } } - final ArrayList<String> zipPaths = new ArrayList<>(); - final ArrayList<String> libPaths = new ArrayList<>(); + final List<String> zipPaths = new ArrayList<>(); + final List<String> apkPaths = new ArrayList<>(); + final List<String> libPaths = new ArrayList<>(); if (mRegisterPackage) { try { @@ -329,6 +332,8 @@ public final class LoadedApk { } } + apkPaths.addAll(zipPaths); + if (mSharedLibraries != null) { for (String lib : mSharedLibraries) { if (!zipPaths.contains(lib)) { @@ -346,6 +351,14 @@ public final class LoadedApk { } final String zip = TextUtils.join(File.pathSeparator, zipPaths); + + // Add path to libraries in apk for current abi + if (mApplicationInfo.primaryCpuAbi != null) { + for (String apk : apkPaths) { + libPaths.add(apk + "!/lib/" + mApplicationInfo.primaryCpuAbi); + } + } + final String lib = TextUtils.join(File.pathSeparator, libPaths); /* diff --git a/core/java/android/app/admin/DeviceInitializerStatus.java b/core/java/android/app/admin/DeviceInitializerStatus.java deleted file mode 100644 index 7de518b46f7b..000000000000 --- a/core/java/android/app/admin/DeviceInitializerStatus.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2015 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.app.admin; - -/** - * Defines constants designating device provisioning status used with {@link - * android.app.admin.DevicePolicyManager#sendDeviceInitializerStatus(int,String)}. - * - * This class contains flag constants that define special status codes: - * <ul> - * <li>{@link #FLAG_STATUS_ERROR} is used to define provisioning error status codes - * <li>{@link #FLAG_STATUS_CUSTOM} is used to define custom status codes - * <li>{@link #FLAG_STATUS_HIGH_PRIORITY} is used to define high priority status codes - * </ul> - * - * <p>Status codes used by ManagedProvisioning are also defined in this class. These status codes - * include provisioning errors and status codes. - * <ul> - * <li>{@link #STATUS_ERROR_CONNECT_WIFI} - * <li>{@link #STATUS_ERROR_RESET_PROTECTION_BLOCKING_PROVISIONING} - * <li>{@link #STATUS_ERROR_DOWNLOAD_PACKAGE} - * <li>{@link #STATUS_ERROR_INSTALL_PACKAGE} - * <li>{@link #STATUS_ERROR_SET_DEVICE_POLICY} - * <li>{@link #STATUS_ERROR_DELETE_APPS} - * <li>{@link #STATUS_ERROR_DOUBLE_BUMP} - * <li>{@link #STATUS_STATE_CONNECTING_BLUETOOTH_PROXY} - * <li>{@link #STATUS_STATE_DISCONNECTING_BLUETOOTH_PROXY} - * <li>{@link #STATUS_STATE_DEVICE_PROVISIONED} - * </ul> - */ -public class DeviceInitializerStatus { - /** - * A flag used to designate an error status. - * - * <p>This flag is used with {@code statusCode} values sent through - * {@link android.app.admin.DevicePolicyManager#sendDeviceInitializerStatus(int,String)} - * @see #isErrorStatus(int) - */ - public static final int FLAG_STATUS_ERROR = 0x01000000; - - /** - * A flag used to designate a custom status. Custom status codes will be defined by device - * initializer agents. - * - * <p>This flag is used with {@code statusCode} values sent through - * {@link android.app.admin.DevicePolicyManager#sendDeviceInitializerStatus(int,String)} - * @see #isCustomStatus(int) - */ - public static final int FLAG_STATUS_CUSTOM = 0x02000000; - - /** - * A bit flag used to designate a reserved status. Reserved status codes will not be defined - * in AOSP. - * - * <p>This flag is used with {@code statusCode} values sent through - * {@link android.app.admin.DevicePolicyManager#sendDeviceInitializerStatus(int,String)} - */ - public static final int FLAG_STATUS_RESERVED = 0x04000000; - - /** - * A flag used to indicate that a status message is high priority. - * - * <p>This flag is used with {@code statusCode} values sent through - * {@link android.app.admin.DevicePolicyManager#sendDeviceInitializerStatus(int,String)} - * @see #isHighPriority(int) - */ - public static final int FLAG_STATUS_HIGH_PRIORITY = 0x08000000; - - /** - * Device provisioning status code that indicates that a device is connecting to establish - * a Bluetooth network proxy. - */ - public static final int STATUS_STATE_CONNECTING_BLUETOOTH_PROXY = FLAG_STATUS_HIGH_PRIORITY | 8; - - /** - * Device provisioning status code that indicates that a connected Bluetooth network proxy - * is being shut down. - */ - public static final int STATUS_STATE_DISCONNECTING_BLUETOOTH_PROXY = FLAG_STATUS_HIGH_PRIORITY | 9; - - /** - * Device provisioning status code that indicates that a device has been successfully - * provisioned. - */ - public static final int STATUS_STATE_DEVICE_PROVISIONED = FLAG_STATUS_HIGH_PRIORITY | 10; - - /** - * Device provisioning error status code that indicates that a device could not connect to - * a Wi-Fi network. - */ - public static final int STATUS_ERROR_CONNECT_WIFI = FLAG_STATUS_ERROR | 21; - - /** - * Device provisioning error status indicating that factory reset protection is enabled on - * the provisioned device and cannot be disabled with the provided data. - */ - public static final int STATUS_ERROR_RESET_PROTECTION_BLOCKING_PROVISIONING = - FLAG_STATUS_ERROR | 22; - - /** - * Device provisioning error status indicating that device administrator and device initializer - * packages could not be downloaded and verified successfully. - */ - public static final int STATUS_ERROR_DOWNLOAD_PACKAGE = FLAG_STATUS_ERROR | 23; - - /** - * Device provisioning error status indicating that device owner and device initializer packages - * could not be installed. - */ - public static final int STATUS_ERROR_INSTALL_PACKAGE = FLAG_STATUS_ERROR | 24; - - /** - * Device provisioning error status indicating that the device owner or device initializer - * components could not be set. - */ - public static final int STATUS_ERROR_SET_DEVICE_POLICY = FLAG_STATUS_ERROR | 25; - - /** - * Device provisioning error status indicating that deleting non-required applications during - * provisioning failed. - */ - public static final int STATUS_ERROR_DELETE_APPS = FLAG_STATUS_ERROR | 26; - - /** - * Device provisioning error status code that indicates that a provisioning attempt has failed - * because the device has already been provisioned or that provisioning has already started. - */ - public static final int STATUS_ERROR_DOUBLE_BUMP = FLAG_STATUS_ERROR | 30; - - private DeviceInitializerStatus() {} -} diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index bf4474651530..996748ae990b 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -540,50 +540,6 @@ public class DevicePolicyManager { = "android.app.extra.PROVISIONING_DEVICE_INITIALIZER_CERTIFICATE_CHECKSUM"; /** - * A String extra holding the MAC address of the Bluetooth device to connect to with status - * updates during provisioning. - * - * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner - * provisioning via an NFC bump. - */ - public static final String EXTRA_PROVISIONING_BT_MAC_ADDRESS - = "android.app.extra.PROVISIONING_BT_MAC_ADDRESS"; - - /** - * A String extra holding the Bluetooth service UUID on the device to connect to with status - * updates during provisioning. - * - * <p>This value must be specified when {@code #EXTRA_PROVISIONING_BT_MAC_ADDRESS} is present. - * - * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner - * provisioning via an NFC bump. - */ - public static final String EXTRA_PROVISIONING_BT_UUID - = "android.app.extra.PROVISIONING_BT_UUID"; - - /** - * A String extra holding a unique identifier used to identify the device connecting over - * Bluetooth. This identifier will be part of every status message sent to the remote device. - * - * <p>This value must be specified when {@code #EXTRA_PROVISIONING_BT_MAC_ADDRESS} is present. - * - * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner - * provisioning via an NFC bump. - */ - public static final String EXTRA_PROVISIONING_BT_DEVICE_ID - = "android.app.extra.PROVISIONING_BT_DEVICE_ID"; - - /** - * A Boolean extra that that will cause a provisioned device to temporarily proxy network - * traffic over Bluetooth. When a Wi-Fi network is available, the network proxy will stop. - * - * <p>Use in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC_V2} that starts device owner - * provisioning via an NFC bump. - */ - public static final String EXTRA_PROVISIONING_BT_USE_PROXY - = "android.app.extra.PROVISIONING_BT_USE_PROXY"; - - /** * A {@link android.os.Parcelable} extra of type {@link android.os.PersistableBundle} that * holds data needed by the system to wipe factory reset protection. The data needed to wipe * the device depend on the installed factory reset protection implementation. For example, @@ -665,11 +621,7 @@ public class DevicePolicyManager { * Replaces {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME}. The value of the property * should be converted to a String via * {@link android.content.ComponentName#flattenToString()}</li> - * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE}, optional</li> - * <li>{@link #EXTRA_PROVISIONING_BT_MAC_ADDRESS}, optional</li> - * <li>{@link #EXTRA_PROVISIONING_BT_UUID}, optional</li> - * <li>{@link #EXTRA_PROVISIONING_BT_DEVICE_ID}, optional</li> - * <li>{@link #EXTRA_PROVISIONING_BT_USE_PROXY}, optional</li></ul> + * <li>{@link #EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE}, optional</li></ul> * * <p> When device owner provisioning has completed, an intent of the type * {@link DeviceAdminReceiver#ACTION_PROFILE_PROVISIONING_COMPLETE} is broadcasted to the @@ -727,45 +679,6 @@ public class DevicePolicyManager { = "android.app.action.SET_PROFILE_OWNER"; /** - * Protected broadcast action that will be sent to managed provisioning to notify it that a - * status update has been reported by the device initializer. The status update will be - * reported to the remote setup device over Bluetooth. - * - * <p>Broadcasts with this action must supply a - * {@linkplain DeviceInitializerStatus#FLAG_STATUS_CUSTOM custom} status code in the - * {@link EXTRA_DEVICE_INITIALIZER_STATUS_CODE} extra. - * - * <p>Broadcasts may optionally contain a description in the - * {@link EXTRA_DEVICE_INITIALIZER_STATUS_DESCRIPTION} extra. - * @hide - */ - @SystemApi - public static final String ACTION_SEND_DEVICE_INITIALIZER_STATUS - = "android.app.action.SEND_DEVICE_INITIALIZER_STATUS"; - - /** - * An integer extra that contains the status code that defines a status update. This extra must - * sent as part of a broadcast with an action of {@code ACTION_SEND_DEVICE_INITIALIZER_STATUS}. - * - * <p>The status code sent with this extra must be a custom status code as defined by - * {@link DeviceInitializerStatus#FLAG_STATUS_CUSTOM}. - * @hide - */ - @SystemApi - public static final String EXTRA_DEVICE_INITIALIZER_STATUS_CODE - = "android.app.extra.DEVICE_INITIALIZER_STATUS_CODE"; - - /** - * A {@code String} extra that contains an optional description accompanying a status update. - * This extra my be sent as part of a broadcast with an action of - * {@code ACTION_SEND_DEVICE_INITIALIZER_STATUS}. - * @hide - */ - @SystemApi - public static final String EXTRA_DEVICE_INITIALIZER_STATUS_DESCRIPTION - = "android.app.extra.DEVICE_INITIALIZER_STATUS_DESCRIPTION"; - - /** * @hide * Name of the profile owner admin that controls the user. */ @@ -3975,6 +3888,9 @@ public class DevicePolicyManager { * <p>Any packages that shares uid with an allowed package will also be allowed * to activate lock task. * + * From {@link android.os.Build.VERSION_CODES#MNC} removing packages from the lock task + * package list results in locked tasks belonging to those packages to be finished. + * * This function can only be called by the device owner. * @param packages The list of packages allowed to enter lock task mode * @param admin Which {@link DeviceAdminReceiver} this request is associated with. @@ -4288,21 +4204,6 @@ public class DevicePolicyManager { } /** - * Called by device initializer to send a provisioning status update to the remote setup device. - * - * @param statusCode a custom status code value as defined by - * {@link DeviceInitializerStatus#FLAG_STATUS_CUSTOM}. - * @param description custom description of the status code sent - */ - public void sendDeviceInitializerStatus(int statusCode, String description) { - try { - mService.sendDeviceInitializerStatus(statusCode, description); - } catch (RemoteException re) { - Log.w(TAG, "Could not send device initializer status", re); - } - } - - /** * Called by device owners to set a local system update policy. When a new policy is set, * {@link #ACTION_SYSTEM_UPDATE_POLICY_CHANGED} is broadcasted. * diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl index a700806f5cad..376a3d82f7f1 100644 --- a/core/java/android/app/admin/IDevicePolicyManager.aidl +++ b/core/java/android/app/admin/IDevicePolicyManager.aidl @@ -220,7 +220,6 @@ interface IDevicePolicyManager { void setUserIcon(in ComponentName admin, in Bitmap icon); - void sendDeviceInitializerStatus(int statusCode, String description); void setSystemUpdatePolicy(in ComponentName who, in SystemUpdatePolicy policy); SystemUpdatePolicy getSystemUpdatePolicy(); diff --git a/core/java/android/app/usage/UsageEvents.java b/core/java/android/app/usage/UsageEvents.java index 58279d744124..369b692a1213 100644 --- a/core/java/android/app/usage/UsageEvents.java +++ b/core/java/android/app/usage/UsageEvents.java @@ -68,9 +68,15 @@ public final class UsageEvents implements Parcelable { public static final int CONFIGURATION_CHANGE = 5; /** - * An event type denoting that a package was interacted with in some way. + * An event type denoting that a package was interacted with in some way by the system. + * @hide */ - public static final int INTERACTION = 6; + public static final int SYSTEM_INTERACTION = 6; + + /** + * An event type denoting that a package was interacted with in some way by the user. + */ + public static final int USER_INTERACTION = 7; /** * {@hide} diff --git a/core/java/android/app/usage/UsageStats.java b/core/java/android/app/usage/UsageStats.java index 81c74227edd4..0fce4e2cd184 100644 --- a/core/java/android/app/usage/UsageStats.java +++ b/core/java/android/app/usage/UsageStats.java @@ -41,11 +41,19 @@ public final class UsageStats implements Parcelable { public long mEndTimeStamp; /** + * Last time used by the user with an explicit action (notification, activity launch). * {@hide} */ public long mLastTimeUsed; /** + * The last time the package was used via implicit, non-user initiated actions (service + * was bound, etc). + * {@hide} + */ + public long mLastTimeSystemUsed; + + /** * Last time the package was used and the beginning of the idle countdown. * This uses a different timebase that is about how much the device has been in use in general. * {@hide} @@ -82,6 +90,7 @@ public final class UsageStats implements Parcelable { mLaunchCount = stats.mLaunchCount; mLastEvent = stats.mLastEvent; mBeginIdleTime = stats.mBeginIdleTime; + mLastTimeSystemUsed = stats.mLastTimeSystemUsed; } public String getPackageName() { @@ -119,6 +128,16 @@ public final class UsageStats implements Parcelable { /** * @hide + * Get the last time this package was used by the system (not the user). This can be different + * from {@link #getLastTimeUsed()} when the system binds to one of this package's services. + * See {@link System#currentTimeMillis()}. + */ + public long getLastTimeSystemUsed() { + return mLastTimeSystemUsed; + } + + /** + * @hide * Get the last time this package was active, measured in milliseconds. This timestamp * uses a timebase that represents how much the device was used and not wallclock time. */ @@ -151,6 +170,7 @@ public final class UsageStats implements Parcelable { mEndTimeStamp = right.mEndTimeStamp; mLastTimeUsed = right.mLastTimeUsed; mBeginIdleTime = right.mBeginIdleTime; + mLastTimeSystemUsed = right.mLastTimeSystemUsed; } mBeginTimeStamp = Math.min(mBeginTimeStamp, right.mBeginTimeStamp); mTotalTimeInForeground += right.mTotalTimeInForeground; @@ -172,6 +192,7 @@ public final class UsageStats implements Parcelable { dest.writeInt(mLaunchCount); dest.writeInt(mLastEvent); dest.writeLong(mBeginIdleTime); + dest.writeLong(mLastTimeSystemUsed); } public static final Creator<UsageStats> CREATOR = new Creator<UsageStats>() { @@ -186,6 +207,7 @@ public final class UsageStats implements Parcelable { stats.mLaunchCount = in.readInt(); stats.mLastEvent = in.readInt(); stats.mBeginIdleTime = in.readLong(); + stats.mLastTimeSystemUsed = in.readLong(); return stats; } diff --git a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java index ed167f06e0c5..8512b239114c 100644 --- a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java +++ b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java @@ -52,6 +52,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -79,7 +80,7 @@ public class CameraDeviceImpl extends CameraDevice { private volatile StateCallbackKK mSessionStateCallback; private final Handler mDeviceHandler; - private volatile boolean mClosing = false; + private final AtomicBoolean mClosing = new AtomicBoolean(); private boolean mInError = false; private boolean mIdle = true; @@ -906,6 +907,10 @@ public class CameraDeviceImpl extends CameraDevice { @Override public void close() { synchronized (mInterfaceLock) { + if (mClosing.getAndSet(true)) { + return; + } + try { if (mRemoteDevice != null) { mRemoteDevice.disconnect(); @@ -1917,7 +1922,7 @@ public class CameraDeviceImpl extends CameraDevice { /** Whether the camera device has started to close (may not yet have finished) */ private boolean isClosed() { - return mClosing; + return mClosing.get(); } private CameraCharacteristics getCharacteristics() { diff --git a/core/java/android/hardware/camera2/legacy/LegacyCameraDevice.java b/core/java/android/hardware/camera2/legacy/LegacyCameraDevice.java index a3a998e0e50c..cc95c0ea26ef 100644 --- a/core/java/android/hardware/camera2/legacy/LegacyCameraDevice.java +++ b/core/java/android/hardware/camera2/legacy/LegacyCameraDevice.java @@ -87,6 +87,9 @@ public class LegacyCameraDevice implements AutoCloseable { public static final int MAX_DIMEN_FOR_ROUNDING = 1080; // maximum allowed width for rounding + // Keep up to date with values in system/core/include/system/window.h + public static final int NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW = 1; + private CaptureResultExtras getExtrasFromRequest(RequestHolder holder) { if (holder == null) { return new CaptureResultExtras(ILLEGAL_VALUE, ILLEGAL_VALUE, ILLEGAL_VALUE, @@ -690,6 +693,13 @@ public class LegacyCameraDevice implements AutoCloseable { LegacyExceptionUtils.throwOnError(nativeSetNextTimestamp(surface, timestamp)); } + static void setScalingMode(Surface surface, int mode) + throws BufferQueueAbandonedException { + checkNotNull(surface); + LegacyExceptionUtils.throwOnError(nativeSetScalingMode(surface, mode)); + } + + private static native int nativeDetectSurfaceType(Surface surface); private static native int nativeDetectSurfaceDimens(Surface surface, @@ -717,5 +727,7 @@ public class LegacyCameraDevice implements AutoCloseable { private static native int nativeDetectSurfaceUsageFlags(Surface surface); + private static native int nativeSetScalingMode(Surface surface, int scalingMode); + static native int nativeGetJpegFooterSize(); } diff --git a/core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java b/core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java index 33a802bb1401..8bdd42a30c78 100644 --- a/core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java +++ b/core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java @@ -415,8 +415,9 @@ public class LegacyMetadataMapper { Range<Integer>[] ranges = new Range[rangesSize]; int i = 0; for (int[] r : fpsRanges) { - ranges[i++] = Range.create(r[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], - r[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); + ranges[i++] = Range.create( + (int) Math.floor(r[Camera.Parameters.PREVIEW_FPS_MIN_INDEX] / 1000.0), + (int) Math.ceil(r[Camera.Parameters.PREVIEW_FPS_MAX_INDEX] / 1000.0)); } m.set(CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, ranges); } diff --git a/core/java/android/hardware/camera2/legacy/LegacyRequestMapper.java b/core/java/android/hardware/camera2/legacy/LegacyRequestMapper.java index d5d7f0d21019..6a44ac50de0a 100644 --- a/core/java/android/hardware/camera2/legacy/LegacyRequestMapper.java +++ b/core/java/android/hardware/camera2/legacy/LegacyRequestMapper.java @@ -162,17 +162,19 @@ public class LegacyRequestMapper { if (aeFpsRange != null) { int[] legacyFps = convertAeFpsRangeToLegacy(aeFpsRange); - // TODO - Should we enforce that all HAL1 devices must include (30, 30) FPS range? - boolean supported = false; + int[] rangeToApply = null; for(int[] range : params.getSupportedPreviewFpsRange()) { - if (legacyFps[0] == range[0] && legacyFps[1] == range[1]) { - supported = true; + // Round range up/down to integer FPS value + int intRangeLow = (int) Math.floor(range[0] / 1000.0) * 1000; + int intRangeHigh = (int) Math.ceil(range[1] / 1000.0) * 1000; + if (legacyFps[0] == intRangeLow && legacyFps[1] == intRangeHigh) { + rangeToApply = range; break; } } - if (supported) { - params.setPreviewFpsRange(legacyFps[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], - legacyFps[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); + if (rangeToApply != null) { + params.setPreviewFpsRange(rangeToApply[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], + rangeToApply[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); } else { Log.w(TAG, "Unsupported FPS range set [" + legacyFps[0] + "," + legacyFps[1] + "]"); } @@ -626,8 +628,8 @@ public class LegacyRequestMapper { private static int[] convertAeFpsRangeToLegacy(Range<Integer> fpsRange) { int[] legacyFps = new int[2]; - legacyFps[Parameters.PREVIEW_FPS_MIN_INDEX] = fpsRange.getLower(); - legacyFps[Parameters.PREVIEW_FPS_MAX_INDEX] = fpsRange.getUpper(); + legacyFps[Parameters.PREVIEW_FPS_MIN_INDEX] = fpsRange.getLower() * 1000; + legacyFps[Parameters.PREVIEW_FPS_MAX_INDEX] = fpsRange.getUpper() * 1000; return legacyFps; } diff --git a/core/java/android/hardware/camera2/legacy/RequestThreadManager.java b/core/java/android/hardware/camera2/legacy/RequestThreadManager.java index 5ea1ab87bb7b..348b14a2c760 100644 --- a/core/java/android/hardware/camera2/legacy/RequestThreadManager.java +++ b/core/java/android/hardware/camera2/legacy/RequestThreadManager.java @@ -384,6 +384,8 @@ public class RequestThreadManager { callbackOutputSizes.add(outSize); break; default: + LegacyCameraDevice.setScalingMode(s, LegacyCameraDevice. + NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); mPreviewOutputs.add(s); previewOutputSizes.add(outSize); break; @@ -412,6 +414,9 @@ public class RequestThreadManager { mParams.setPreviewFpsRange(bestRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], bestRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); + Size smallestSupportedJpegSize = calculatePictureSize(mCallbackOutputs, + callbackOutputSizes, mParams); + if (previewOutputSizes.size() > 0) { Size largestOutput = SizeAreaComparator.findLargestByArea(previewOutputSizes); @@ -419,6 +424,9 @@ public class RequestThreadManager { // Find largest jpeg dimension - assume to have the same aspect ratio as sensor. Size largestJpegDimen = ParameterUtils.getLargestSupportedJpegSizeByArea(mParams); + Size chosenJpegDimen = (smallestSupportedJpegSize != null) ? smallestSupportedJpegSize + : largestJpegDimen; + List<Size> supportedPreviewSizes = ParameterUtils.convertSizeList( mParams.getSupportedPreviewSizes()); @@ -430,7 +438,7 @@ public class RequestThreadManager { for (Size s : supportedPreviewSizes) { long currArea = s.getWidth() * s.getHeight(); long bestArea = bestPreviewDimen.getWidth() * bestPreviewDimen.getHeight(); - if (checkAspectRatiosMatch(largestJpegDimen, s) && (currArea < bestArea && + if (checkAspectRatiosMatch(chosenJpegDimen, s) && (currArea < bestArea && currArea >= largestOutputArea)) { bestPreviewDimen = s; } @@ -451,8 +459,6 @@ public class RequestThreadManager { } } - Size smallestSupportedJpegSize = calculatePictureSize(mCallbackOutputs, - callbackOutputSizes, mParams); if (smallestSupportedJpegSize != null) { /* * Set takePicture size to the smallest supported JPEG size large enough diff --git a/core/java/android/inputmethodservice/Keyboard.java b/core/java/android/inputmethodservice/Keyboard.java index 45f18897b0e2..4d0ee7d2a730 100644 --- a/core/java/android/inputmethodservice/Keyboard.java +++ b/core/java/android/inputmethodservice/Keyboard.java @@ -400,16 +400,26 @@ public class Keyboard { public void onPressed() { pressed = !pressed; } - + /** - * Changes the pressed state of the key. If it is a sticky key, it will also change the - * toggled state of the key if the finger was release inside. - * @param inside whether the finger was released inside the key + * Changes the pressed state of the key. + * + * <p>Toggled state of the key will be flipped when all the following conditions are + * fulfilled:</p> + * + * <ul> + * <li>This is a sticky key, that is, {@link #sticky} is {@code true}. + * <li>The parameter {@code inside} is {@code true}. + * <li>{@link Build.VERSION.SDK_INT} is greater than {@link VERSION_CODES.LOLLIPOP_MR1}. + * </ul> + * + * @param inside whether the finger was released inside the key. Works only on Android M and + * later. See the method document for details. * @see #onPressed() */ public void onReleased(boolean inside) { pressed = !pressed; - if (sticky) { + if (sticky && inside) { on = !on; } } diff --git a/core/java/android/os/ParcelFileDescriptor.java b/core/java/android/os/ParcelFileDescriptor.java index 1c9c71336bdd..135f369f895f 100644 --- a/core/java/android/os/ParcelFileDescriptor.java +++ b/core/java/android/os/ParcelFileDescriptor.java @@ -621,6 +621,9 @@ public class ParcelFileDescriptor implements Parcelable, Closeable { final int fd = getFd(); Parcel.clearFileDescriptor(mFd); writeCommStatusAndClose(Status.DETACHED, null); + mClosed = true; + mGuard.close(); + releaseResources(); return fd; } } diff --git a/core/java/android/os/storage/DiskInfo.java b/core/java/android/os/storage/DiskInfo.java index 04e54aafbce9..5bc45d572085 100644 --- a/core/java/android/os/storage/DiskInfo.java +++ b/core/java/android/os/storage/DiskInfo.java @@ -80,6 +80,12 @@ public class DiskInfo implements Parcelable { if (label.toLowerCase().contains("generic")) { return false; } + if (label.toLowerCase().startsWith("usb")) { + return false; + } + if (label.toLowerCase().startsWith("multiple")) { + return false; + } return true; } diff --git a/core/java/android/preference/SeekBarVolumizer.java b/core/java/android/preference/SeekBarVolumizer.java index 4bd085f2c6ba..979c828c476e 100644 --- a/core/java/android/preference/SeekBarVolumizer.java +++ b/core/java/android/preference/SeekBarVolumizer.java @@ -16,6 +16,7 @@ package android.preference; +import android.app.NotificationManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -31,6 +32,7 @@ import android.os.HandlerThread; import android.os.Message; import android.preference.VolumePreference.VolumeStore; import android.provider.Settings; +import android.provider.Settings.Global; import android.provider.Settings.System; import android.util.Log; import android.widget.SeekBar; @@ -46,7 +48,7 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba public interface Callback { void onSampleStarting(SeekBarVolumizer sbv); void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch); - void onMuted(boolean muted); + void onMuted(boolean muted, boolean zenMuted); } private final Context mContext; @@ -54,6 +56,7 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba private final Callback mCallback; private final Uri mDefaultUri; private final AudioManager mAudioManager; + private final NotificationManager mNotificationManager; private final int mStreamType; private final int mMaxStreamVolume; private boolean mAffectedByRingerMode; @@ -63,12 +66,14 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba private Handler mHandler; private Observer mVolumeObserver; private int mOriginalStreamVolume; + private int mLastAudibleStreamVolume; private Ringtone mRingtone; private int mLastProgress = -1; private boolean mMuted; private SeekBar mSeekBar; private int mVolumeBeforeMute = -1; private int mRingerMode; + private int mZenMode; private static final int MSG_SET_STREAM_VOLUME = 0; private static final int MSG_START_SAMPLE = 1; @@ -78,19 +83,22 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba public SeekBarVolumizer(Context context, int streamType, Uri defaultUri, Callback callback) { mContext = context; - mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); + mAudioManager = context.getSystemService(AudioManager.class); + mNotificationManager = context.getSystemService(NotificationManager.class); mStreamType = streamType; mAffectedByRingerMode = mAudioManager.isStreamAffectedByRingerMode(mStreamType); mNotificationOrRing = isNotificationOrRing(mStreamType); if (mNotificationOrRing) { mRingerMode = mAudioManager.getRingerModeInternal(); } + mZenMode = mNotificationManager.getZenMode(); mMaxStreamVolume = mAudioManager.getStreamMaxVolume(mStreamType); mCallback = callback; mOriginalStreamVolume = mAudioManager.getStreamVolume(mStreamType); + mLastAudibleStreamVolume = mAudioManager.getLastAudibleStreamVolume(mStreamType); mMuted = mAudioManager.isStreamMute(mStreamType); if (mCallback != null) { - mCallback.onMuted(mMuted); + mCallback.onMuted(mMuted, isZenMuted()); } if (defaultUri == null) { if (mStreamType == AudioManager.STREAM_RING) { @@ -119,8 +127,17 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba mSeekBar.setOnSeekBarChangeListener(this); } + private boolean isZenMuted() { + return mNotificationOrRing && mZenMode == Global.ZEN_MODE_ALARMS + || mZenMode == Global.ZEN_MODE_NO_INTERRUPTIONS; + } + protected void updateSeekBar() { - if (mNotificationOrRing && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) { + final boolean zenMuted = isZenMuted(); + mSeekBar.setEnabled(!zenMuted); + if (zenMuted) { + mSeekBar.setProgress(mLastAudibleStreamVolume); + } else if (mNotificationOrRing && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) { mSeekBar.setProgress(0); } else if (mMuted) { mSeekBar.setProgress(0); @@ -316,11 +333,12 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba if (msg.what == UPDATE_SLIDER) { if (mSeekBar != null) { mLastProgress = msg.arg1; - final boolean muted = msg.arg2 != 0; + mLastAudibleStreamVolume = Math.abs(msg.arg2); + final boolean muted = msg.arg2 < 0; if (muted != mMuted) { mMuted = muted; if (mCallback != null) { - mCallback.onMuted(mMuted); + mCallback.onMuted(mMuted, isZenMuted()); } } updateSeekBar(); @@ -328,16 +346,18 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba } } - public void postUpdateSlider(int volume, boolean mute) { - obtainMessage(UPDATE_SLIDER, volume, mute ? 1 : 0).sendToTarget(); + public void postUpdateSlider(int volume, int lastAudibleVolume, boolean mute) { + final int arg2 = lastAudibleVolume * (mute ? -1 : 1); + obtainMessage(UPDATE_SLIDER, volume, arg2).sendToTarget(); } } private void updateSlider() { if (mSeekBar != null && mAudioManager != null) { final int volume = mAudioManager.getStreamVolume(mStreamType); + final int lastAudibleVolume = mAudioManager.getLastAudibleStreamVolume(mStreamType); final boolean mute = mAudioManager.isStreamMute(mStreamType); - mUiHandler.postUpdateSlider(volume, mute); + mUiHandler.postUpdateSlider(volume, lastAudibleVolume, mute); } } @@ -362,6 +382,7 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba if (listening) { final IntentFilter filter = new IntentFilter(AudioManager.VOLUME_CHANGED_ACTION); filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION); + filter.addAction(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED); mContext.registerReceiver(this, filter); } else { mContext.unregisterReceiver(this); @@ -379,7 +400,7 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba if (mSeekBar != null && streamMatch && streamValue != -1) { final boolean muted = mAudioManager.isStreamMute(mStreamType) || streamValue == 0; - mUiHandler.postUpdateSlider(streamValue, muted); + mUiHandler.postUpdateSlider(streamValue, mLastAudibleStreamVolume, muted); } } else if (AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION.equals(action)) { if (mNotificationOrRing) { @@ -388,6 +409,9 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba if (mAffectedByRingerMode) { updateSlider(); } + } else if (NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED.equals(action)) { + mZenMode = mNotificationManager.getZenMode(); + updateSlider(); } } } diff --git a/core/java/android/preference/VolumePreference.java b/core/java/android/preference/VolumePreference.java index 573499a75217..8a66c243b17c 100644 --- a/core/java/android/preference/VolumePreference.java +++ b/core/java/android/preference/VolumePreference.java @@ -161,7 +161,7 @@ public class VolumePreference extends SeekBarDialogPreference implements } @Override - public void onMuted(boolean muted) { + public void onMuted(boolean muted, boolean zenMuted) { // noop } diff --git a/core/java/android/printservice/PrintService.java b/core/java/android/printservice/PrintService.java index 527c8aee392f..6295822c7e4a 100644 --- a/core/java/android/printservice/PrintService.java +++ b/core/java/android/printservice/PrintService.java @@ -231,6 +231,19 @@ public abstract class PrintService extends Service { */ public static final String EXTRA_PRINTER_INFO = "android.intent.extra.print.EXTRA_PRINTER_INFO"; + /** + * If you declared an optional activity with advanced print options via the + * {@link android.R.attr#advancedPrintOptionsActivity advancedPrintOptionsActivity} + * attribute, this extra is used to pass in the meta-data for the currently printed + * document as a {@link android.print.PrintDocumentInfo} to your activity allowing + * you to inspect it. + * + * @see #EXTRA_PRINT_JOB_INFO + * @see #EXTRA_PRINTER_INFO + */ + public static final String EXTRA_PRINT_DOCUMENT_INFO = + "android.printservice.extra.PRINT_DOCUMENT_INFO"; + private Handler mHandler; private IPrintServiceClient mClient; diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java index d9c412b67749..aebe7f10d523 100644 --- a/core/java/android/provider/ContactsContract.java +++ b/core/java/android/provider/ContactsContract.java @@ -8931,157 +8931,4 @@ public final class ContactsContract { public static final String EXTRA_DATA_SET = "android.provider.extra.DATA_SET"; } } - - /** - * @hide - */ - protected interface MetadataSyncColumns { - - /** - * The raw contact backup id. - * A reference to the {@link ContactsContract.RawContacts#BACKUP_ID} that save the - * persistent unique id for each raw contact within its source system. - * - * @hide - */ - public static final String RAW_CONTACT_BACKUP_ID = "raw_contact_backup_id"; - - /** - * The account type to which the raw_contact of this item is associated. See - * {@link RawContacts#ACCOUNT_TYPE} - * - * @hide - */ - public static final String ACCOUNT_TYPE = "account_type"; - - /** - * The account name to which the raw_contact of this item is associated. See - * {@link RawContacts#ACCOUNT_NAME} - * - * @hide - */ - public static final String ACCOUNT_NAME = "account_name"; - - /** - * The data set within the account that the raw_contact of this row belongs to. This allows - * multiple sync adapters for the same account type to distinguish between - * each others' data. - * {@link RawContacts#DATA_SET} - * - * @hide - */ - public static final String DATA_SET = "data_set"; - - /** - * A text column contains the Json string got from People API. The Json string contains - * all the metadata related to the raw contact, i.e., all the data fields and - * aggregation exceptions. - * - * Here is an example of the Json string got from the actual schema. - * <pre> - * { - * "unique_contact_id": { - * "account_type": "CUSTOM_ACCOUNT", - * "custom_account_type": "facebook", - * "account_name": "android-test", - * "contact_id": "1111111", - * "data_set": "FOCUS" - * }, - * "contact_prefs": { - * "send_to_voicemail": true, - * "starred": false, - * "pinned": 2 - * }, - * "aggregation_data": [ - * { - * "type": "TOGETHER", - * "contact_ids": [ - * { - * "account_type": "GOOGLE_ACCOUNT", - * "account_name": "android-test2", - * "contact_id": "2222222", - * "data_set": "GOOGLE_PLUS" - * }, - * { - * "account_type": "GOOGLE_ACCOUNT", - * "account_name": "android-test3", - * "contact_id": "3333333", - * "data_set": "CUSTOM", - * "custom_data_set": "custom type" - * } - * ] - * } - * ], - * "field_data": [ - * { - * "field_data_id": "1001", - * "field_data_prefs": { - * "is_primary": true, - * "is_super_primary": true - * }, - * "usage_stats": [ - * { - * "usage_type": "CALL", - * "last_time_used": 10000001, - * "usage_count": 10 - * } - * ] - * } - * ] - * } - * </pre> - * - * @hide - */ - public static final String DATA = "data"; - - /** - * The "deleted" flag: "0" by default, "1" if the row has been marked - * for deletion. When {@link android.content.ContentResolver#delete} is - * called on a raw contact, updating MetadataSync table to set the flag of the raw contact - * as "1", then metadata sync adapter deletes the raw contact metadata on the server. - * <P>Type: INTEGER</P> - * - * @hide - */ - public static final String DELETED = "deleted"; - } - - /** - * Constants for the metadata sync table. This table is used to cache the metadata_sync data - * from server before it is merged into other CP2 tables. - * - * @hide - */ - public static final class MetadataSync implements BaseColumns, MetadataSyncColumns { - - /** The authority for the contacts metadata */ - public static final String METADATA_AUTHORITY = "com.android.contacts.metadata"; - - /** A content:// style uri to the authority for the contacts metadata */ - public static final Uri METADATA_AUTHORITY_URI = Uri.parse( - "content://" + METADATA_AUTHORITY); - - /** - * This utility class cannot be instantiated - */ - private MetadataSync() { - } - - /** - * The content:// style URI for this table. - */ - public static final Uri CONTENT_URI = Uri.withAppendedPath(METADATA_AUTHORITY_URI, - "metadata_sync"); - - /** - * The MIME type of {@link #CONTENT_URI} providing a directory of contact metadata - */ - public static final String CONTENT_TYPE = "vnd.android.cursor.dir/contact_metadata"; - - /** - * The MIME type of a {@link #CONTENT_URI} subdirectory of a single contact metadata. - */ - public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_metadata"; - } } diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 167d8e584a78..f2d3e7109f7b 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -7087,6 +7087,36 @@ public final class Settings { BLUETOOTH_SAP_PRIORITY_PREFIX = "bluetooth_sap_priority_"; /** + * Device Idle (Doze) specific settings. + * This is encoded as a key=value list, separated by commas. Ex: + * + * "inactive_timeout=60000,sensing_timeout=400000" + * + * The following keys are supported: + * + * <pre> + * inactive_to (long) + * sensing_to (long) + * motion_inactive_to (long) + * idle_after_inactive_to (long) + * idle_pending_to (long) + * max_idle_pending_to (long) + * idle_pending_factor (float) + * idle_to (long) + * max_idle_to (long) + * idle_factor (float) + * min_time_to_alarm (long) + * max_temp_app_whitelist_duration (long) + * </pre> + * + * <p> + * Type: string + * @hide + * @see com.android.server.DeviceIdleController.Constants + */ + public static final String DEVICE_IDLE_CONSTANTS = "device_idle_constants"; + + /** * Get the key that retrieves a bluetooth headset's priority. * @hide */ diff --git a/core/java/android/text/TextUtils.java b/core/java/android/text/TextUtils.java index 6c4d8fd01443..d51aa7939c3d 100644 --- a/core/java/android/text/TextUtils.java +++ b/core/java/android/text/TextUtils.java @@ -1790,6 +1790,15 @@ public class TextUtils { } } + /** + * Return localized string representing the given number of selected items. + * + * @hide + */ + public static CharSequence formatSelectedCount(int count) { + return Resources.getSystem().getQuantityString(R.plurals.selected_count, count, count); + } + private static Object sLock = new Object(); private static char[] sTemp = null; diff --git a/core/java/android/util/ArrayMap.java b/core/java/android/util/ArrayMap.java index 6ed388515599..4ee9807da850 100644 --- a/core/java/android/util/ArrayMap.java +++ b/core/java/android/util/ArrayMap.java @@ -266,7 +266,7 @@ public final class ArrayMap<K, V> implements Map<K, V> { /** * Create a new ArrayMap with the mappings from the given ArrayMap. */ - public ArrayMap(ArrayMap map) { + public ArrayMap(ArrayMap<K, V> map) { this(); if (map != null) { putAll(map); @@ -843,7 +843,8 @@ public final class ArrayMap<K, V> implements Map<K, V> { * in the array map. * * <p><b>Note:</b> this is a very inefficient way to access the array contents, it - * requires generating a number of temporary objects.</p> + * requires generating a number of temporary objects and allocates additional state + * information associated with the container that will remain for the life of the container.</p> * * <p><b>Note:</b></p> the semantics of this * Set are subtly different than that of a {@link java.util.HashMap}: most important, @@ -861,7 +862,8 @@ public final class ArrayMap<K, V> implements Map<K, V> { * in the array map. * * <p><b>Note:</b> this is a fairly inefficient way to access the array contents, it - * requires generating a number of temporary objects.</p> + * requires generating a number of temporary objects and allocates additional state + * information associated with the container that will remain for the life of the container.</p> */ @Override public Set<K> keySet() { @@ -873,7 +875,8 @@ public final class ArrayMap<K, V> implements Map<K, V> { * in the array map. * * <p><b>Note:</b> this is a fairly inefficient way to access the array contents, it - * requires generating a number of temporary objects.</p> + * requires generating a number of temporary objects and allocates additional state + * information associated with the container that will remain for the life of the container.</p> */ @Override public Collection<V> values() { diff --git a/core/java/android/util/ArraySet.java b/core/java/android/util/ArraySet.java index 7da3941914f6..b7a3c42e8f24 100644 --- a/core/java/android/util/ArraySet.java +++ b/core/java/android/util/ArraySet.java @@ -42,8 +42,6 @@ import java.util.Set; * you have no control over this shrinking -- if you set a capacity and then remove an * item, it may reduce the capacity to better match the current size. In the future an * explicit call to set the capacity should turn off this aggressive shrinking behavior.</p> - * - * @hide */ public final class ArraySet<E> implements Collection<E>, Set<E> { private static final boolean DEBUG = false; @@ -660,11 +658,24 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { return mCollections; } + /** + * Return an {@link java.util.Iterator} over all values in the set. + * + * <p><b>Note:</b> this is a fairly inefficient way to access the array contents, it + * requires generating a number of temporary objects and allocates additional state + * information associated with the container that will remain for the life of the container.</p> + */ @Override public Iterator<E> iterator() { return getCollection().getKeySet().iterator(); } + /** + * Determine if the array set contains all of the values in the given collection. + * @param collection The collection whose contents are to be checked against. + * @return Returns true if this array set contains a value for every entry + * in <var>collection</var>, else returns false. + */ @Override public boolean containsAll(Collection<?> collection) { Iterator<?> it = collection.iterator(); @@ -676,6 +687,10 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { return true; } + /** + * Perform an {@link #add(Object)} of all values in <var>collection</var> + * @param collection The collection whose contents are to be retrieved. + */ @Override public boolean addAll(Collection<? extends E> collection) { ensureCapacity(mSize + collection.size()); @@ -686,6 +701,11 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { return added; } + /** + * Remove all values in the array set that exist in the given collection. + * @param collection The collection whose contents are to be used to remove values. + * @return Returns true if any values were removed from the array set, else false. + */ @Override public boolean removeAll(Collection<?> collection) { boolean removed = false; @@ -695,6 +715,12 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { return removed; } + /** + * Remove all values in the array set that do <b>not</b> exist in the given collection. + * @param collection The collection whose contents are to be used to determine which + * values to keep. + * @return Returns true if any values were removed from the array set, else false. + */ @Override public boolean retainAll(Collection<?> collection) { boolean removed = false; diff --git a/core/java/android/util/KeyValueListParser.java b/core/java/android/util/KeyValueListParser.java new file mode 100644 index 000000000000..4abdde00e6c6 --- /dev/null +++ b/core/java/android/util/KeyValueListParser.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2015 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.util; + +import android.text.TextUtils; + +/** + * Parses a list of key=value pairs, separated by some delimiter, and puts the results in + * an internal Map. Values can be then queried by key, or if not found, a default value + * can be used. + * @hide + */ +public class KeyValueListParser { + private final ArrayMap<String, String> mValues = new ArrayMap<>(); + private final TextUtils.StringSplitter mSplitter; + + /** + * Constructs a new KeyValueListParser. This can be reused for different strings + * by calling {@link #setString(String)}. + * @param delim The delimiter that separates key=value pairs. + */ + public KeyValueListParser(char delim) { + mSplitter = new TextUtils.SimpleStringSplitter(delim); + } + + /** + * Resets the parser with a new string to parse. The string is expected to be in the following + * format: + * <pre>key1=value,key2=value,key3=value</pre> + * + * where the delimiter is a comma. + * + * @param str the string to parse. + * @throws IllegalArgumentException if the string is malformed. + */ + public void setString(String str) throws IllegalArgumentException { + mValues.clear(); + if (str != null) { + mSplitter.setString(str); + for (String pair : mSplitter) { + int sep = pair.indexOf('='); + if (sep < 0) { + mValues.clear(); + throw new IllegalArgumentException( + "'" + pair + "' in '" + str + "' is not a valid key-value pair"); + } + mValues.put(pair.substring(0, sep).trim(), pair.substring(sep + 1).trim()); + } + } + } + + /** + * Get the value for key as a long. + * @param key The key to lookup. + * @param def The value to return if the key was not found, or the value was not a long. + * @return the long value associated with the key. + */ + public long getLong(String key, long def) { + String value = mValues.get(key); + if (value != null) { + try { + return Long.parseLong(value); + } catch (NumberFormatException e) { + // fallthrough + } + } + return def; + } + + /** + * Get the value for key as a float. + * @param key The key to lookup. + * @param def The value to return if the key was not found, or the value was not a float. + * @return the float value associated with the key. + */ + public float getFloat(String key, float def) { + String value = mValues.get(key); + if (value != null) { + try { + return Float.parseFloat(value); + } catch (NumberFormatException e) { + // fallthrough + } + } + return def; + } + + /** + * Get the value for key as a string. + * @param key The key to lookup. + * @param def The value to return if the key was not found. + * @return the string value associated with the key. + */ + public String getString(String key, String def) { + String value = mValues.get(key); + if (value != null) { + return value; + } + return def; + } +} diff --git a/core/java/android/view/Choreographer.java b/core/java/android/view/Choreographer.java index d2b6533fd4ac..a865307b12bb 100644 --- a/core/java/android/view/Choreographer.java +++ b/core/java/android/view/Choreographer.java @@ -22,6 +22,7 @@ import android.os.Looper; import android.os.Message; import android.os.SystemClock; import android.os.SystemProperties; +import android.os.Trace; import android.util.Log; import android.util.TimeUtils; @@ -160,6 +161,14 @@ public final class Choreographer { FrameInfo mFrameInfo = new FrameInfo(); /** + * Must be kept in sync with CALLBACK_* ints below, used to index into this array. + * @hide + */ + private static final String[] CALLBACK_TRACE_TITLES = { + "input", "animation", "traversal", "commit" + }; + + /** * Callback type: Input callback. Runs first. * @hide */ @@ -584,16 +593,22 @@ public final class Choreographer { mLastFrameTimeNanos = frameTimeNanos; } - mFrameInfo.markInputHandlingStart(); - doCallbacks(Choreographer.CALLBACK_INPUT, frameTimeNanos); + try { + Trace.traceBegin(Trace.TRACE_TAG_VIEW, "Choreographer#doFrame"); + + mFrameInfo.markInputHandlingStart(); + doCallbacks(Choreographer.CALLBACK_INPUT, frameTimeNanos); - mFrameInfo.markAnimationsStart(); - doCallbacks(Choreographer.CALLBACK_ANIMATION, frameTimeNanos); + mFrameInfo.markAnimationsStart(); + doCallbacks(Choreographer.CALLBACK_ANIMATION, frameTimeNanos); - mFrameInfo.markPerformTraversalsStart(); - doCallbacks(Choreographer.CALLBACK_TRAVERSAL, frameTimeNanos); + mFrameInfo.markPerformTraversalsStart(); + doCallbacks(Choreographer.CALLBACK_TRAVERSAL, frameTimeNanos); - doCallbacks(Choreographer.CALLBACK_COMMIT, frameTimeNanos); + doCallbacks(Choreographer.CALLBACK_COMMIT, frameTimeNanos); + } finally { + Trace.traceEnd(Trace.TRACE_TAG_VIEW); + } if (DEBUG_FRAMES) { final long endNanos = System.nanoTime(); @@ -627,6 +642,7 @@ public final class Choreographer { // safe by ensuring the commit time is always at least one frame behind. if (callbackType == Choreographer.CALLBACK_COMMIT) { final long jitterNanos = now - frameTimeNanos; + Trace.traceCounter(Trace.TRACE_TAG_VIEW, "jitterNanos", (int) jitterNanos); if (jitterNanos >= 2 * mFrameIntervalNanos) { final long lastFrameOffset = jitterNanos % mFrameIntervalNanos + mFrameIntervalNanos; @@ -644,6 +660,7 @@ public final class Choreographer { } } try { + Trace.traceBegin(Trace.TRACE_TAG_VIEW, CALLBACK_TRACE_TITLES[callbackType]); for (CallbackRecord c = callbacks; c != null; c = c.next) { if (DEBUG_FRAMES) { Log.d(TAG, "RunCallback: type=" + callbackType @@ -661,6 +678,7 @@ public final class Choreographer { callbacks = next; } while (callbacks != null); } + Trace.traceEnd(Trace.TRACE_TAG_VIEW); } } diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index be372d0bf859..d2ee0e56a034 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -741,6 +741,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, private static boolean sUseBrokenMakeMeasureSpec = false; /** + * Always return a size of 0 for MeasureSpec values with a mode of UNSPECIFIED + */ + static boolean sUseZeroUnspecifiedMeasureSpec = false; + + /** * Ignore any optimizations using the measure cache. */ private static boolean sIgnoreMeasureCache = false; @@ -3796,6 +3801,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Canvas.sCompatibilityRestore = targetSdkVersion < MNC; + // In MNC and newer, our widgets can pass a "hint" value in the size + // for UNSPECIFIED MeasureSpecs. This lets child views of scrolling containers + // know what the expected parent size is going to be, so e.g. list items can size + // themselves at 1/3 the size of their container. It breaks older apps though, + // specifically apps that use some popular open source libraries. + sUseZeroUnspecifiedMeasureSpec = targetSdkVersion < MNC; + sCompatibilityDone = true; } } @@ -21032,6 +21044,19 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** + * Like {@link #makeMeasureSpec(int, int)}, but any spec with a mode of UNSPECIFIED + * will automatically get a size of 0. Older apps expect this. + * + * @hide internal use only for compatibility with system widgets and older apps + */ + public static int makeSafeMeasureSpec(int size, int mode) { + if (sUseZeroUnspecifiedMeasureSpec && mode == UNSPECIFIED) { + return 0; + } + return makeMeasureSpec(size, mode); + } + + /** * Extracts the mode from the supplied measure specification. * * @param measureSpec the measure specification to extract the mode from diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index dd32f854e26d..89743e539fa2 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -5963,12 +5963,12 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } else if (childDimension == LayoutParams.MATCH_PARENT) { // Child wants to be our size... find out how big it should // be - resultSize = size; + resultSize = View.sUseZeroUnspecifiedMeasureSpec ? 0 : size; resultMode = MeasureSpec.UNSPECIFIED; } else if (childDimension == LayoutParams.WRAP_CONTENT) { // Child wants to determine its own size.... find out how // big it should be - resultSize = size; + resultSize = View.sUseZeroUnspecifiedMeasureSpec ? 0 : size; resultMode = MeasureSpec.UNSPECIFIED; } break; diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index e1e015498512..e2f42db0f085 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -1105,12 +1105,7 @@ public final class ViewRootImpl implements ViewParent, Debug.startMethodTracing("ViewAncestor"); } - Trace.traceBegin(Trace.TRACE_TAG_VIEW, "performTraversals"); - try { - performTraversals(); - } finally { - Trace.traceEnd(Trace.TRACE_TAG_VIEW); - } + performTraversals(); if (mProfile) { Debug.stopMethodTracing(); diff --git a/core/java/android/webkit/WebViewFactory.java b/core/java/android/webkit/WebViewFactory.java index b7d529e0c884..b4ef58afb94d 100644 --- a/core/java/android/webkit/WebViewFactory.java +++ b/core/java/android/webkit/WebViewFactory.java @@ -333,8 +333,8 @@ public final class WebViewFactory { newVmSize = Math.max(newVmSize, f.length()); continue; } - if (path.contains("!")) { - String[] split = TextUtils.split(path, "!"); + if (path.contains("!/")) { + String[] split = TextUtils.split(path, "!/"); if (split.length == 2) { try { ZipFile z = new ZipFile(split[0]); @@ -384,7 +384,7 @@ public final class WebViewFactory { ZipEntry e = z.getEntry(entry); if (e != null && e.getMethod() == ZipEntry.STORED) { // Return a path formatted for dlopen() load from APK. - return apkPath + "!" + entry; + return apkPath + "!/" + entry; } } } catch (IOException e) { diff --git a/core/java/android/widget/FastScroller.java b/core/java/android/widget/FastScroller.java index f06f3c218276..11d70265342d 100644 --- a/core/java/android/widget/FastScroller.java +++ b/core/java/android/widget/FastScroller.java @@ -662,7 +662,7 @@ class FastScroller { final int adjMaxWidth = maxWidth - marginLeft - marginRight; final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(adjMaxWidth, MeasureSpec.AT_MOST); - final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(container.height(), + final int heightMeasureSpec = MeasureSpec.makeSafeMeasureSpec(container.height(), MeasureSpec.UNSPECIFIED); view.measure(widthMeasureSpec, heightMeasureSpec); @@ -702,7 +702,7 @@ class FastScroller { final int containerWidth = container.width(); final int adjMaxWidth = containerWidth - marginLeft - marginRight; final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(adjMaxWidth, MeasureSpec.AT_MOST); - final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(container.height(), + final int heightMeasureSpec = MeasureSpec.makeSafeMeasureSpec(container.height(), MeasureSpec.UNSPECIFIED); preview.measure(widthMeasureSpec, heightMeasureSpec); @@ -768,7 +768,7 @@ class FastScroller { final Rect container = mContainerRect; final int maxWidth = container.width(); final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(maxWidth, MeasureSpec.AT_MOST); - final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(container.height(), + final int heightMeasureSpec = MeasureSpec.makeSafeMeasureSpec(container.height(), MeasureSpec.UNSPECIFIED); track.measure(widthMeasureSpec, heightMeasureSpec); diff --git a/core/java/android/widget/GridView.java b/core/java/android/widget/GridView.java index dcaafa527920..f994d4ad91be 100644 --- a/core/java/android/widget/GridView.java +++ b/core/java/android/widget/GridView.java @@ -1073,7 +1073,7 @@ public class GridView extends AbsListView { p.forceAdd = true; int childHeightSpec = getChildMeasureSpec( - MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), + MeasureSpec.makeSafeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.UNSPECIFIED), 0, p.height); int childWidthSpec = getChildMeasureSpec( MeasureSpec.makeMeasureSpec(mColumnWidth, MeasureSpec.EXACTLY), 0, p.width); diff --git a/core/java/android/widget/LinearLayout.java b/core/java/android/widget/LinearLayout.java index 9d14254bdbbd..056323db9560 100644 --- a/core/java/android/widget/LinearLayout.java +++ b/core/java/android/widget/LinearLayout.java @@ -1062,9 +1062,9 @@ public class LinearLayout extends ViewGroup { // use as much space as it wants because we can shrink things // later (and re-measure). if (baselineAligned) { - final int freeWidthSpec = MeasureSpec.makeMeasureSpec( + final int freeWidthSpec = MeasureSpec.makeSafeMeasureSpec( MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.UNSPECIFIED); - final int freeHeightSpec = MeasureSpec.makeMeasureSpec( + final int freeHeightSpec = MeasureSpec.makeSafeMeasureSpec( MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.UNSPECIFIED); child.measure(freeWidthSpec, freeHeightSpec); } else { diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java index f8b965fce8c2..fd0395a8a036 100644 --- a/core/java/android/widget/ListView.java +++ b/core/java/android/widget/ListView.java @@ -1206,7 +1206,7 @@ public class ListView extends AbsListView { if (lpHeight > 0) { childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY); } else { - childHeightSpec = MeasureSpec.makeMeasureSpec(heightHint, MeasureSpec.UNSPECIFIED); + childHeightSpec = MeasureSpec.makeSafeMeasureSpec(heightHint, MeasureSpec.UNSPECIFIED); } child.measure(childWidthSpec, childHeightSpec); } @@ -1943,7 +1943,7 @@ public class ListView extends AbsListView { if (lpHeight > 0) { childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY); } else { - childHeightSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), + childHeightSpec = MeasureSpec.makeSafeMeasureSpec(getMeasuredHeight(), MeasureSpec.UNSPECIFIED); } child.measure(childWidthSpec, childHeightSpec); @@ -2698,7 +2698,7 @@ public class ListView extends AbsListView { if (lpHeight > 0) { childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY); } else { - childHeightSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), + childHeightSpec = MeasureSpec.makeSafeMeasureSpec(getMeasuredHeight(), MeasureSpec.UNSPECIFIED); } child.measure(childWidthSpec, childHeightSpec); diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java index 11904e12cda9..58a94b96a7f2 100644 --- a/core/java/android/widget/ScrollView.java +++ b/core/java/android/widget/ScrollView.java @@ -1263,7 +1263,7 @@ public class ScrollView extends FrameLayout { childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec, mPaddingLeft + mPaddingRight, lp.width); - childHeightMeasureSpec = MeasureSpec.makeMeasureSpec( + childHeightMeasureSpec = MeasureSpec.makeSafeMeasureSpec( MeasureSpec.getSize(parentHeightMeasureSpec), MeasureSpec.UNSPECIFIED); child.measure(childWidthMeasureSpec, childHeightMeasureSpec); @@ -1277,7 +1277,7 @@ public class ScrollView extends FrameLayout { final int childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec, mPaddingLeft + mPaddingRight + lp.leftMargin + lp.rightMargin + widthUsed, lp.width); - final int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec( + final int childHeightMeasureSpec = MeasureSpec.makeSafeMeasureSpec( MeasureSpec.getSize(parentHeightMeasureSpec), MeasureSpec.UNSPECIFIED); child.measure(childWidthMeasureSpec, childHeightMeasureSpec); diff --git a/core/java/android/widget/Spinner.java b/core/java/android/widget/Spinner.java index 6fe34ddfc0d3..fdabe913e80a 100644 --- a/core/java/android/widget/Spinner.java +++ b/core/java/android/widget/Spinner.java @@ -812,9 +812,9 @@ public class Spinner extends AbsSpinner implements OnClickListener { View itemView = null; int itemType = 0; final int widthMeasureSpec = - MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.UNSPECIFIED); + MeasureSpec.makeSafeMeasureSpec(getMeasuredWidth(), MeasureSpec.UNSPECIFIED); final int heightMeasureSpec = - MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.UNSPECIFIED); + MeasureSpec.makeSafeMeasureSpec(getMeasuredHeight(), MeasureSpec.UNSPECIFIED); // Make sure the number of items we'll measure is capped. If it's a huge data set // with wildly varying sizes, oh well. diff --git a/core/java/android/widget/TabWidget.java b/core/java/android/widget/TabWidget.java index aa7168c617f0..d9cff4e24940 100644 --- a/core/java/android/widget/TabWidget.java +++ b/core/java/android/widget/TabWidget.java @@ -174,7 +174,8 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener { // First, measure with no constraint final int width = MeasureSpec.getSize(widthMeasureSpec); - final int unspecifiedWidth = MeasureSpec.makeMeasureSpec(width, MeasureSpec.UNSPECIFIED); + final int unspecifiedWidth = MeasureSpec.makeSafeMeasureSpec(width, + MeasureSpec.UNSPECIFIED); mImposedTabsHeight = -1; super.measureHorizontal(unspecifiedWidth, heightMeasureSpec); diff --git a/core/java/android/widget/TableRow.java b/core/java/android/widget/TableRow.java index d4288d69c2c2..f7f9c9177034 100644 --- a/core/java/android/widget/TableRow.java +++ b/core/java/android/widget/TableRow.java @@ -303,7 +303,7 @@ public class TableRow extends LinearLayout { spec = getChildMeasureSpec(widthMeasureSpec, 0, LayoutParams.WRAP_CONTENT); break; case LayoutParams.MATCH_PARENT: - spec = MeasureSpec.makeMeasureSpec( + spec = MeasureSpec.makeSafeMeasureSpec( MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.UNSPECIFIED); break; diff --git a/core/java/com/android/internal/app/ResolverComparator.java b/core/java/com/android/internal/app/ResolverComparator.java index 42668f140393..585cdf163b8c 100644 --- a/core/java/com/android/internal/app/ResolverComparator.java +++ b/core/java/com/android/internal/app/ResolverComparator.java @@ -45,7 +45,7 @@ import java.util.Map; class ResolverComparator implements Comparator<ResolvedComponentInfo> { private static final String TAG = "ResolverComparator"; - private static final boolean DEBUG = true; + private static final boolean DEBUG = false; // Two weeks private static final long USAGE_STATS_PERIOD = 1000 * 60 * 60 * 24 * 14; diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index 087db78edbb2..07d1fc8624de 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -4634,7 +4634,7 @@ public final class BatteryStatsImpl extends BatteryStats { @Override public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { int bin = 0; - while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS) { + while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS-1) { csph = csph >> 3; bin++; } diff --git a/core/java/com/android/internal/widget/ActionBarContextView.java b/core/java/com/android/internal/widget/ActionBarContextView.java index 106272bd9568..c5d329020a17 100644 --- a/core/java/com/android/internal/widget/ActionBarContextView.java +++ b/core/java/com/android/internal/widget/ActionBarContextView.java @@ -367,7 +367,7 @@ public class ActionBarContextView extends AbsActionBarView implements AnimatorLi if (mTitleLayout != null && mCustomView == null) { if (mTitleOptional) { - final int titleWidthSpec = MeasureSpec.makeMeasureSpec(contentWidth, + final int titleWidthSpec = MeasureSpec.makeSafeMeasureSpec(contentWidth, MeasureSpec.UNSPECIFIED); mTitleLayout.measure(titleWidthSpec, childSpecHeight); final int titleWidth = mTitleLayout.getMeasuredWidth(); diff --git a/core/java/com/android/internal/widget/SlidingTab.java b/core/java/com/android/internal/widget/SlidingTab.java index 0066ed0db859..79adada9cc98 100644 --- a/core/java/com/android/internal/widget/SlidingTab.java +++ b/core/java/com/android/internal/widget/SlidingTab.java @@ -403,10 +403,10 @@ public class SlidingTab extends ViewGroup { public void measure(int widthMeasureSpec, int heightMeasureSpec) { int width = MeasureSpec.getSize(widthMeasureSpec); int height = MeasureSpec.getSize(heightMeasureSpec); - tab.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.UNSPECIFIED), - View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.UNSPECIFIED)); - text.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.UNSPECIFIED), - View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.UNSPECIFIED)); + tab.measure(View.MeasureSpec.makeSafeMeasureSpec(width, View.MeasureSpec.UNSPECIFIED), + View.MeasureSpec.makeSafeMeasureSpec(height, View.MeasureSpec.UNSPECIFIED)); + text.measure(View.MeasureSpec.makeSafeMeasureSpec(width, View.MeasureSpec.UNSPECIFIED), + View.MeasureSpec.makeSafeMeasureSpec(height, View.MeasureSpec.UNSPECIFIED)); } /** diff --git a/core/jni/android/graphics/Shader.cpp b/core/jni/android/graphics/Shader.cpp index d0f75917106a..ad3a5e2c5624 100644 --- a/core/jni/android/graphics/Shader.cpp +++ b/core/jni/android/graphics/Shader.cpp @@ -84,7 +84,11 @@ static jlong BitmapShader_constructor(JNIEnv* env, jobject o, jobject jbitmap, jint tileModeX, jint tileModeY) { SkBitmap bitmap; - GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap); + if (jbitmap) { + // Only pass a valid SkBitmap object to the constructor if the Bitmap exists. Otherwise, + // we'll pass an empty SkBitmap to avoid crashing/excepting for compatibility. + GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap); + } SkShader* s = SkShader::CreateBitmapShader(bitmap, (SkShader::TileMode)tileModeX, (SkShader::TileMode)tileModeY); diff --git a/core/jni/android/graphics/SurfaceTexture.cpp b/core/jni/android/graphics/SurfaceTexture.cpp index 08d61d593b0a..b9e48a0c0cc8 100644 --- a/core/jni/android/graphics/SurfaceTexture.cpp +++ b/core/jni/android/graphics/SurfaceTexture.cpp @@ -49,6 +49,12 @@ struct fields_t { }; static fields_t fields; +// Get an ID that's unique within this process. +static int32_t createProcessUniqueId() { + static volatile int32_t globalCounter = 0; + return android_atomic_inc(&globalCounter); +} + // ---------------------------------------------------------------------------- static void SurfaceTexture_setSurfaceTexture(JNIEnv* env, jobject thiz, @@ -253,6 +259,11 @@ static void SurfaceTexture_init(JNIEnv* env, jobject thiz, jboolean isDetached, "Unable to create native SurfaceTexture"); return; } + surfaceTexture->setName(String8::format("SurfaceTexture-%d-%d-%d", + (isDetached ? 0 : texName), + getpid(), + createProcessUniqueId())); + SurfaceTexture_setSurfaceTexture(env, thiz, surfaceTexture); SurfaceTexture_setProducer(env, thiz, producer); diff --git a/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp b/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp index afdfd8f13909..5bef65370aac 100644 --- a/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp +++ b/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp @@ -689,6 +689,23 @@ static jint LegacyCameraDevice_nativeSetNextTimestamp(JNIEnv* env, jobject thiz, return NO_ERROR; } +static jint LegacyCameraDevice_nativeSetScalingMode(JNIEnv* env, jobject thiz, jobject surface, + jint mode) { + ALOGV("nativeSetScalingMode"); + sp<ANativeWindow> anw; + if ((anw = getNativeWindow(env, surface)) == NULL) { + ALOGE("%s: Could not retrieve native window from surface.", __FUNCTION__); + return BAD_VALUE; + } + status_t err = NO_ERROR; + if ((err = native_window_set_scaling_mode(anw.get(), static_cast<int>(mode))) != NO_ERROR) { + ALOGE("%s: Unable to set surface scaling mode, error %s (%d)", __FUNCTION__, + strerror(-err), err); + return err; + } + return NO_ERROR; +} + static jint LegacyCameraDevice_nativeGetJpegFooterSize(JNIEnv* env, jobject thiz) { ALOGV("nativeGetJpegFooterSize"); return static_cast<jint>(sizeof(struct camera3_jpeg_blob)); @@ -733,6 +750,9 @@ static JNINativeMethod gCameraDeviceMethods[] = { { "nativeDetectSurfaceUsageFlags", "(Landroid/view/Surface;)I", (void *)LegacyCameraDevice_nativeDetectSurfaceUsageFlags }, + { "nativeSetScalingMode", + "(Landroid/view/Surface;I)I", + (void *)LegacyCameraDevice_nativeSetScalingMode }, }; // Get all the required offsets in java class and register native functions diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 521238bfc468..47b180fad31e 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -90,7 +90,6 @@ <protected-broadcast android:name="android.app.action.ENTER_DESK_MODE" /> <protected-broadcast android:name="android.app.action.EXIT_DESK_MODE" /> <protected-broadcast android:name="android.app.action.NEXT_ALARM_CLOCK_CHANGED" /> - <protected-broadcast android:name="android.app.action.SEND_DEVICE_INITIALIZER_STATUS" /> <protected-broadcast android:name="android.appwidget.action.APPWIDGET_UPDATE_OPTIONS" /> <protected-broadcast android:name="android.appwidget.action.APPWIDGET_DELETED" /> @@ -981,33 +980,11 @@ <!-- Allows access to the list of accounts in the Accounts Service --> <permission android:name="android.permission.GET_ACCOUNTS" - android:permissionGroup="android.permission-group.ACCOUNTS" + android:permissionGroup="android.permission-group.CONTACTS" android:protectionLevel="normal" android:description="@string/permdesc_getAccounts" android:label="@string/permlab_getAccounts" /> - <!-- Allows an application to act as an AccountAuthenticator for - the AccountManager --> - <permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" - android:permissionGroup="android.permission-group.ACCOUNTS" - android:protectionLevel="dangerous" - android:label="@string/permlab_authenticateAccounts" - android:description="@string/permdesc_authenticateAccounts" /> - - <!-- Allows an application to request authtokens from the AccountManager --> - <permission android:name="android.permission.USE_CREDENTIALS" - android:permissionGroup="android.permission-group.ACCOUNTS" - android:protectionLevel="dangerous" - android:label="@string/permlab_useCredentials" - android:description="@string/permdesc_useCredentials" /> - - <!-- Allows an application to manage the list of accounts in the AccountManager --> - <permission android:name="android.permission.MANAGE_ACCOUNTS" - android:permissionGroup="android.permission-group.ACCOUNTS" - android:protectionLevel="dangerous" - android:label="@string/permlab_manageAccounts" - android:description="@string/permdesc_manageAccounts" /> - <!-- @SystemApi Allows applications to call into AccountAuthenticators. <p>Not for use by third-party applications. --> <permission android:name="android.permission.ACCOUNT_MANAGER" @@ -1205,12 +1182,16 @@ <permission android:name="android.permission.BIND_TELECOM_CONNECTION_SERVICE" android:protectionLevel="system|signature" /> - <!-- @SystemApi Allows an application to control the in-call experience. @hide --> <permission android:name="android.permission.CONTROL_INCALL_EXPERIENCE" android:protectionLevel="system|signature" /> + <!-- Allows an application to receive STK related commands. + @hide --> + <permission android:name="android.permission.RECEIVE_STK_COMMANDS" + android:protectionLevel="system|signature" /> + <!-- ================================== --> <!-- Permissions for sdcard interaction --> <!-- ================================== --> @@ -2432,11 +2413,6 @@ <permission android:name="android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS" android:protectionLevel="signature" /> - <!-- Allows receiving status updates from a device initializer. - @hide Not for use by third-party applications. --> - <permission android:name="android.permission.RECEIVE_DEVICE_INITIALIZER_STATUS" - android:protectionLevel="signature" /> - <!-- The system process that is allowed to bind to services in carrier apps will have this permission. Carrier apps should use this permission to protect their services that only the system is allowed to bind to. --> diff --git a/core/res/res/layout/media_route_controller_dialog.xml b/core/res/res/layout/media_route_controller_dialog.xml index 78287e0ba585..0bf70dae062c 100644 --- a/core/res/res/layout/media_route_controller_dialog.xml +++ b/core/res/res/layout/media_route_controller_dialog.xml @@ -14,47 +14,50 @@ limitations under the License. --> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="vertical" - android:divider="?android:attr/dividerHorizontal" - android:showDividers="middle"> - <!-- Optional volume slider section. --> - <LinearLayout android:id="@+id/media_route_volume_layout" - android:layout_width="match_parent" - android:layout_height="64dp" - android:gravity="center_vertical" - android:padding="8dp" - android:visibility="gone"> - <ImageView android:layout_width="48dp" - android:layout_height="48dp" - android:src="@drawable/ic_audio_vol" - android:gravity="center" - android:scaleType="center" /> - <SeekBar android:id="@+id/media_route_volume_slider" - android:layout_width="0dp" - android:layout_height="wrap_content" - android:layout_weight="1" - android:layout_marginLeft="8dp" - android:layout_marginRight="8dp" /> - </LinearLayout> - - <!-- Optional content view section. --> - <FrameLayout android:id="@+id/media_route_control_frame" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:visibility="gone" /> - - <!-- Disconnect button. --> +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" - style="?attr/buttonBarStyle"> - <Button android:id="@+id/media_route_disconnect_button" - android:layout_width="match_parent" - android:layout_height="match_parent" - style="?attr/buttonBarButtonStyle" - android:gravity="center" - android:text="@string/media_route_controller_disconnect" /> + android:orientation="vertical" + android:divider="?android:attr/dividerHorizontal" + android:showDividers="middle"> + <!-- Optional volume slider section. --> + <LinearLayout android:id="@+id/media_route_volume_layout" + android:layout_width="match_parent" + android:layout_height="64dp" + android:gravity="center_vertical" + android:padding="8dp" + android:visibility="gone"> + <ImageView android:layout_width="48dp" + android:layout_height="48dp" + android:src="@drawable/ic_audio_vol" + android:gravity="center" + android:scaleType="center" /> + <SeekBar android:id="@+id/media_route_volume_slider" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + android:layout_marginLeft="8dp" + android:layout_marginRight="8dp" /> + </LinearLayout> + + <!-- Optional content view section. --> + <FrameLayout android:id="@+id/media_route_control_frame" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:visibility="gone" /> + + <!-- Disconnect button. --> + <LinearLayout android:layout_width="match_parent" + android:layout_height="wrap_content" + style="?attr/buttonBarStyle"> + <Button android:id="@+id/media_route_disconnect_button" + android:layout_width="match_parent" + android:layout_height="match_parent" + style="?attr/buttonBarButtonStyle" + android:gravity="center" + android:text="@string/media_route_controller_disconnect" /> + </LinearLayout> </LinearLayout> -</LinearLayout> +</ScrollView>
\ No newline at end of file diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml index 470e3455cbbc..f31c1d61d7c5 100644 --- a/core/res/res/values/attrs_manifest.xml +++ b/core/res/res/values/attrs_manifest.xml @@ -1058,18 +1058,20 @@ lockTask mode is disabled. <p>While in lockTask mode with multiple permitted tasks running, each launched task is permitted to finish, transitioning to the previous locked task, until there is only one - task remaining. At that point the last task running is not permitted to finish. --> + task remaining. At that point the last task running is not permitted to finish, unless it + uses the value always. --> <attr name="lockTaskMode"> <!-- This is the default value. Tasks will not launch into lockTask mode but can be placed there by calling {@link android.app.Activity#startLockTask}. If a task with this mode has been whitelisted using {@link - android.app.admin.DevicePolicyManager#setLockTaskPackages} then calling startLockTask - will enter lockTask mode immediately, otherwise the user will be presented with a - dialog to approve entering lockTask mode. + android.app.admin.DevicePolicyManager#setLockTaskPackages} then calling + {@link android.app.Activity#startLockTask} will enter lockTask mode immediately, + otherwise the user will be presented with a dialog to approve entering pinned mode. <p>If the system is already in lockTask mode when a new task rooted at this activity is launched that task will or will not start depending on whether the package of this activity has been whitelisted. - <p>Tasks rooted at this activity can only exit lockTask mode using stopLockTask(). --> + <p>Tasks rooted at this activity can only exit lockTask mode using + {@link android.app.Activity#stopLockTask}. --> <enum name="normal" value="0"/> <!-- Tasks will not launch into lockTask mode and cannot be placed there using {@link android.app.Activity#startLockTask} or be pinned from the Overview screen. @@ -1082,16 +1084,17 @@ <!-- Tasks rooted at this activity will always launch into lockTask mode. If the system is already in lockTask mode when this task is launched then the new task will be launched on top of the current task. Tasks launched in this mode are capable of exiting - lockTask mode using finish(), whereas tasks entering lockTask mode using - startLockTask() must use stopLockTask() to exit. + lockTask mode using {@link android.app.Activity#finish()}. <p>Note: This mode is only available to system and privileged applications. Non-privileged apps with this value will be treated as normal. --> <enum name="always" value="2"/> <!-- If the DevicePolicyManager (DPM) authorizes this package ({@link android.app.admin.DevicePolicyManager#setLockTaskPackages}) then this mode is - identical to always. If the DPM does not authorize this package then this - mode is identical to normal. --> + identical to always, except that the activity needs to call + {@link android.app.Activity#stopLockTask} before being able to finish if it is the last + locked task. + If the DPM does not authorize this package then this mode is identical to normal. --> <enum name="if_whitelisted" value="3"/> </attr> <!-- When set installer will extract native libraries. If set to false diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 0183e3eb80c6..19fc4a1478e1 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -1113,27 +1113,6 @@ the list of accounts known by the phone. This may include any accounts created by applications you have installed.</string> - - <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. --> - <string name="permlab_authenticateAccounts">create accounts and set passwords</string> - <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. --> - <string name="permdesc_authenticateAccounts">Allows the app - to use the account authenticator capabilities of the - AccountManager, including creating accounts and getting and - setting their passwords.</string> - - <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. --> - <string name="permlab_manageAccounts">add or remove accounts</string> - <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. --> - <string name="permdesc_manageAccounts">Allows the app to - perform operations like adding and removing accounts, and deleting - their password.</string> - - <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. --> - <string name="permlab_useCredentials">use accounts on the device</string> - <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. --> - <string name="permdesc_useCredentials">Allows the app to request authentication tokens.</string> - <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. --> <string name="permlab_accessNetworkState">view network connections</string> <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. --> @@ -4201,4 +4180,9 @@ notification_template_material_inbox.xml. DO NOT TRANSLATE --> <string name="notification_inbox_ellipsis">\u2026</string> + + <!-- Label describing the number of selected items [CHAR LIMIT=48] --> + <plurals name="selected_count"> + <item quantity="other"><xliff:g id="count" example="3">%1$d</xliff:g> selected</item> + </plurals> </resources> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 890068816233..b019adbbe1eb 100755 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -2306,5 +2306,6 @@ <java-symbol type="string" name="ext_media_status_missing" /> <java-symbol type="string" name="ext_media_unsupported_notification_message" /> <java-symbol type="string" name="ext_media_unsupported_notification_title" /> + <java-symbol type="plurals" name="selected_count" /> </resources> diff --git a/data/fonts/Android.mk b/data/fonts/Android.mk index 6d8d81ff9203..3181017a2e5a 100644 --- a/data/fonts/Android.mk +++ b/data/fonts/Android.mk @@ -17,8 +17,8 @@ LOCAL_PATH := $(call my-dir) -# Use full Noto Sans Japanese font on extended footprint -ifeq ($(EXTENDED_FONT_FOOTPRINT),true) +# Use full Noto Sans Japanese font on non-smaller footprints +ifneq ($(SMALLER_FONT_FOOTPRINT),true) FONT_NOTOSANS_JP_FULL := true endif @@ -38,7 +38,7 @@ ALL_MODULES.$(1).INSTALLED := \ endef ########################################## -# The following fonts are distributed as symlink only. +# The following fonts are just symlinks, for backward compatibility. ########################################## $(eval $(call create-font-symlink,DroidSans.ttf,Roboto-Regular.ttf)) $(eval $(call create-font-symlink,DroidSans-Bold.ttf,Roboto-Bold.ttf)) @@ -54,7 +54,7 @@ extra_font_files := \ ################################ # Do not include Motoya on space-constrained devices ifneq ($(SMALLER_FONT_FOOTPRINT),true) -# Do not include Motoya if we are including full NotoSans +# Do not include Motoya if we are including Noto Sans Japanese ifneq ($(FONT_NOTOSANS_JP_FULL),true) include $(CLEAR_VARS) @@ -82,26 +82,19 @@ include $(BUILD_PREBUILT) extra_font_files := ################################ -# Include DroidSansFallback only on non-EXTENDED_FONT_FOOTPRINT builds -ifneq ($(EXTENDED_FONT_FOOTPRINT),true) - -# Include a subset of DroidSansFallback on SMALLER_FONT_FOOTPRINT build +# Include the DroidSansFallback subset on SMALLER_FONT_FOOTPRINT build ifeq ($(SMALLER_FONT_FOOTPRINT),true) -droidsans_fallback_src := DroidSansFallback.ttf -else # !SMALLER_FONT_FOOTPRINT -droidsans_fallback_src := DroidSansFallbackFull.ttf -endif # SMALLER_FONT_FOOTPRINT include $(CLEAR_VARS) LOCAL_MODULE := DroidSansFallback.ttf -LOCAL_SRC_FILES := $(droidsans_fallback_src) +LOCAL_SRC_FILES := $(LOCAL_MODULE) LOCAL_MODULE_CLASS := ETC LOCAL_MODULE_TAGS := optional LOCAL_MODULE_PATH := $(TARGET_OUT)/fonts include $(BUILD_PREBUILT) droidsans_fallback_src := -endif # !EXTENDED_FONT_FOOTPRINT +endif # SMALLER_FONT_FOOTPRINT ################################ # Build the rest of font files as prebuilt. diff --git a/docs/html/guide/faq/commontasks.jd b/docs/html/guide/faq/commontasks.jd deleted file mode 100644 index 2943aefc9c19..000000000000 --- a/docs/html/guide/faq/commontasks.jd +++ /dev/null @@ -1,826 +0,0 @@ -page.title=Common Tasks and How to Do Them in Android -excludeFromSuggestions=true -@jd:body - -<ul> - <li><a href="#neweclipseandroidproject">Creating an Android Application using - the Eclipse plugin</a></li> - <li><a href="#newandroidprojectnoeclipse">Creating an Android Application without - the Eclipse plugin</a></li> - <li><a href="#addexternallibrary">Adding an External Library (.jar) using Eclipse</a></li> - <li><a href="#implementcallbacks">Implementing Activity callbacks</a> (Android - calls your activity at various key moments in its life cycle. You must know - how to handle each of these to draw your screen, initialize class members, - and acquire data.)</li> - <li><a href="#opennewscreen">Opening a new screen</a></li> - <li><a href="#listening">Listening for button clicks </a></li> - <li><a href="#configurewindowproperties">Configuring general window properties </a></li> - <li><a href="#localhostalias">Referring to localhost from the emulated environment</a></li> - <li><a href="#appstate">Storing and retrieving state</a></li> - <li><a href="{@docRoot}guide/topics/data/data-storage.html#preferences">Storing and retrieving preferences</a></li> - <li><a href="#storingandretrieving">Storing and retrieving larger or more complex - persistent data</a> (files and data) </li> - <li><a href="#playback">Playing audio, video, still, or other media files</a></li> - <li><a href="#broadcastreceivers">Listening for and broadcasting global messages - and setting alarms</a></li> - <li><a href="#alerts">Displaying alerts </a></li> - <li><a href="#progressbar">Displaying a progress bar</a> </li> - <li><a href="#addmenuitems">Adding items to the screen menu</a> </li> - <li><a href="#webpage">Display a web page</a> </li> - <li><a href="#binding">Binding to data</a></li> - <li><a href="#handle">Getting a Handle to a Screen Element</a></li> - <li><a href="#captureimages">Capture images from the phone camera </a></li> - <li><a href="#threading">Handling expensive operations in the UI thread</a></li> - <li><a href="#selectingtext">Selecting, highlighting, or styling portions of - text</a></li> - <li><a href="#querymap">Utilizing attributes in a Map query</a></li> - <li><a href="#filelist">List of files for an Android application</a></li> - <li><a href="#logging">Print messages to a log file</a></li> -</ul> -<p>The ApiDemos sample application includes many, many examples of common -tasks and UI features. See the code inside -<code><sdk>samples/ApiDemos</code> and the other sample applications -under the <code>samples/</code> folder in the SDK.</p> - - -<h2 id="neweclipseandroidproject">Creating an Android Application using the Eclipse Plugin</h2> - -<p>Using the Android Eclipse plugin is the fastest and easiest way -to start creating a new Android application. The plugin automatically generates -the correct project structure for your application, and keeps the resources -compiled for you automatically.</p> - -<p>It is still a good idea to know what is going on though. Take a look at <a -href="{@docRoot}guide/topics/fundamentals.html">Application Fundamentals</a> -to understand the basics of how an Android application works.</p> - -<p>You should also take a look at the ApiDemos application and the other sample -applications included in the SDK, in the <code><sdk>/samples/</code> -folder in the SDK.</p> - -<p>Finally, a great way to started with Android development in Eclipse is to -follow both the <a href="{@docRoot}resources/tutorials/hello-world.html">Hello, -World</a> and <a -href="{@docRoot}training/notepad/index.html">Notepad</a> code -tutorials. In particular, the start of the Hello Android tutorial is an -excellent introduction to creating a new Android application in Eclipse.</p> - -<h2 id="newandroidprojectnoeclipse">Creating an Android Application without the Eclipse Plugin</h2> - -<p>This topic describes the manual steps in creating an Android application. -Before reading this, you should read <a -href="{@docRoot}guide/topics/fundamentals.html">Application Fundamentals</a> -to understand the basics of how an Android application works. You might also -want to look at the sample code included with the Android SDK, in the -<code><sdk>/samples/</code> directory. </p> - -<p>Here is a list of the basic steps in building an application.</p> -<ol> - <li><strong>Create your required resource files</strong> This includes - the AndroidManifest.xml global description file, string files that your application - needs, and layout files describing your user interface. A full list of optional - and required files and syntax details for each is given in <a href="#filelist">File - List for an Android Application</a>. </li> - <li><strong>Design your user interface</strong> See <a - href="{@docRoot}guide/topics/ui/index.html">User Interface</a> for - details on elements of the Android screen. </li> - <li><strong>Implement your Activity </strong>(this page)<strong> </strong> You - will create one class/file for each screen in your application. Screens will - inherit from an {@link android.app android.app} class, typically {@link android.app.Activity - android.app.Activity} for basic screens, {@link android.app.ListActivity - android.app.ListActivity} for list screens, or {@link android.app.Dialog - android.app.Dialog} for dialog boxes. You will implement the required callbacks - that let you draw your screen, query data, and commit changes, and also perform - any required tasks such as opening additional screens or reading data from - the device. Common tasks, such as opening a new screen or reading data from - the device, are described below. - The list of files you'll need for your application are described in <a href="#filelist">List - of Files for an Android Application</a>. </li> - <li><strong><a href="{@docRoot}guide/developing/building/building-cmdline.html">Build and install your - package</a>.</strong> The Android SDK has some nice tools for generating - projects and debugging code. </li> -</ol> - -<h2 id="addexternallibrary">Adding an External Library (.jar) using Eclipse</h2> -<p> -You can use a third party JAR in your application by adding it to your Eclipse project as follows: -</p> -<ol> -<li> -In the <strong>Package Explorer</strong> panel, right-click on your project and select <strong>Properties</strong>. -<li> -Select <strong>Java Build Path</strong>, then the tab <strong>Libraries</strong>. -<li> -Press the <strong>Add External JARs...</strong> button and select the JAR file. -</ol> -<p> -Alternatively, if you want to include third party JARs with your package, create a new directory for them within your project and select <strong>Add Library...</strong> instead.</p> -<p> -It is not necessary to put external JARs in the assets folder. -</p> - -<a name="implementcallbacks" id="implementcallbacks"></a> -<h2>Implementing Activity Callbacks</h2> -<p>Android calls a number of callbacks to let you draw your screen, store data before - pausing, and refresh data after closing. You must implement at least some of - these methods. Read the <a -href="{@docRoot}guide/topics/fundamentals/activities.html#Lifecycle">Activities</a> - document to learn when and in what order these methods - are called. Here are some of the standard types of screen classes that Android provides:</p> -<ul> - <li>{@link android.app.Activity android.app.Activity} - This is a standard screen, - with no specialization.</li> - <li>{@link android.app.ListActivity android.app.ListActivity} - This is a screen - that is used to display a list of something. It hosts a ListView object, - and exposes methods to let you identify the selected item, receive callbacks - when the selected item changes, and perform other list-related actions. </li> - <li>{@link android.app.Dialog android.app.Dialog} - This is a small, popup dialog-style - window that isn't intended to remain in the history stack. (It is not resizeable - or moveable by the user.)</li> -</ul> - -<a name="opennewscreen" id="opennewscreen"></a><h2>Opening a New Screen</h2> -<p>Your Activity will often need to open another Activity screen as it progresses. - This new screen can be part of the same application or part of another application, - the new screen can be floating or full screen, it can return a result, and you - can decide whether to close this screen and remove it from the history stack - when you are done with it, or to keep the screen open in history. These next - sections describe all these options. </p> -<h3>Floating or full?<a name="floatingorfull" id="floatingorfull"></a></h3> -<p>When you open a new screen you can decide whether to make it transparent or floating, - or full-screen. The choice of new screen affects the event sequence of events - in the old screen (if the new screen obscures the old screen, a different - series of events is called in the old screen). See the <a - href="{@docRoot}guide/topics/fundamentals/activities.html#Lifecycle">Activities</a> document for -details. </p> -<p>Transparent or floating windows are implemented in three - standard ways: </p> -<ul> - <li>Create an {@link android.app.Dialog app.Dialog} class </li> - <li>Create an {@link android.app.AlertDialog app.AlertDialog} class </li> - <li>Set the {@link android.R.style#Theme_Dialog} <em>theme</em> attribute to <code>@android:style/Theme.Dialog</code> - in your AndroidManifest.xml file. For example: - <pre><activity class="AddRssItem" android:label="Add an item" android:theme="@android:style/Theme.Dialog"/></pre></li> -</ul> - -<p>Calling startActivity() or startActivityForResult() will open a new screen in whatever - way it defines itself (if it uses a floating theme it will be floating, - otherwise it will be full screen). </p> -<h3>Opening a Screen </h3> -<p>When you want to open a new screen, you can either explicitly specify the activity - class to open, or you can let the operating system decide which screen to open, - based upon the data and various parameters you pass in. A screen is opened by - calling {@link android.app.Activity#startActivity(android.content.Intent) startActivity} - and passing in an {@link android.content.Intent Intent} object, which specifies - the criteria for the handling screen. To specify a specific screen, call Intent.setClass - or setClassName with the exact activity class to open. Otherwise, set a variety - of values and data, and let Android decide which screen is appropriate to open. - Android will find one or zero Activities that match the specified requirements; - it will never open multiple activities for a single request. More information - on Intents and how Android resolves them to a specific class is given in the - {@link android.content.Intent Intent} topic. </p> -<a name="intentexamples" id="intentexamples"></a><h3>Some Intent examples </h3> -<p>The following snippet loads the com.android.samples.Animation1 class, and - passes it some arbitrary data.:</p> -<pre>Intent myIntent = new Intent(); -myIntent.setClassName("com.android.samples", "com.android.samples.Animation1"); -myIntent.putExtra("com.android.samples.SpecialValue", "Hello, Joe!"); // key/value pair, where key needs current package prefix. -startActivity(myIntent); </pre> -<p>The next snippet requests that a Web page be opened by specifying the VIEW action, - and a URI data string starting with "http://" schema:</p> -<pre>Intent myIntent = new Intent(Intent.VIEW_ACTION, Uri.parse("http://www.google.com"));</pre> -<p>Here is the intent filter from the AndroidManifest.xml file for com.android.browser:</p> -<pre><intent-filter> - <action android:name="android.intent.action.VIEW" /> - <category android:name="android.intent.category.DEFAULT" /> - <scheme android:name="http" /> - <scheme android:name="https" /> - <scheme android:name="file" /> -</intent-filter> </pre> -<p>Android defines a number of standard values, for instance the action constants - defined by {@link android.content.Intent}. You can define custom values, but - both the caller and handler must use them. See the <intent-filter> - tag description in <a href="{@docRoot}guide/topics/manifest/manifest-intro.html">The AndroidManifest.xml - File</a> for more information on the manifest syntax for the handling - application. </p> -<a name="returningaresult" id="returningaresult"></a><h3>Returning a Result from a Screen</h3> -<p>A window can return a result after it closes. This result will be passed back - into the calling Activity's {@link android.app.Activity#onActivityResult(int,int,android.content.Intent) - onActivityResult()} method, which can supply an Intent containing arbitrary data, along with - the request code passed to startActivityForResult(). Note that you must call the {@link - android.app.Activity#startActivityForResult(android.content.Intent,int) startActivityForResult()} - method that accepts a request code parameter to get this callback. The following - code demonstrates opening a new screen and retrieving a result. </p> -<pre>// Open the new screen. -public void onClick(View v){ - // Start the activity whose result we want to retrieve. The - // result will come back with request code GET_CODE. - Intent intent = new Intent(this, com.example.app.ChooseYourBoxer.class); - startActivityForResult(intent, CHOOSE_FIGHTER); -} - -// Listen for results. -protected void onActivityResult(int requestCode, int resultCode, Intent data){ - // See which child activity is calling us back. - switch (requestCode) { - case CHOOSE_FIGHTER: - // This is the standard resultCode that is sent back if the - // activity crashed or didn't doesn't supply an explicit result. - if (resultCode == RESULT_CANCELED){ - myMessageboxFunction("Fight cancelled"); - } - else { - myFightFunction(data); - } - default: - break; - } -} - -// Class SentResult -// Temporary screen to let the user choose something. - private OnClickListener mLincolnListener = new OnClickListener(){ - public void onClick(View v) { - Bundle stats = new Bundle(); - stats.putString("height","6\'4\""); - stats.putString("weight", "190 lbs"); - stats.putString("reach", "74\""); - setResult(RESULT_OK, "Lincoln", stats); - finish(); - } - }; - - private OnClickListener mWashingtonListener = new OnClickListener() { - public void onClick(View v){ - Bundle stats = new Bundle(); - stats.putString("height","6\'2\""); - stats.putString("weight", "190 lbs"); - stats.putString("reach", "73\""); - setResult(RESULT_OK, "Washington", stats); - finish(); - } - }; - </pre> -<h3>Lifetime of the new screen </h3> -<p>An activity can remove itself from the history stack by calling {@link android.app.Activity#finish() - Activity.finish()} on itself, or the activity that opened the screen can call - {@link android.app.Activity#finishActivity(int) Activity.finishActivity()} - on any screens that it opens to close them. </p> -<a name="listening" id="listening"></a><h2>Listening for Button Clicks</h2> -<p>Button click and other UI event capturing are covered in <a -href="{@docRoot}guide/topics/ui/ui-events.html">Input Events</a>.</p> -<a name="configurewindowproperties" id="configurewindowproperties"></a><h2>Configuring General Window Properties</h2> -<p>You can set a number of general window properties, such as whether to display - a title, whether the window is floating, and whether it displays an icon, by - calling methods on the {@link android.view.Window Window} member - of the underlying View object for the window. Examples include calling {@link - android.app.Activity#getWindow() getWindow().requestFeature()} (or the convenience - method {@link android.app.Activity#requestWindowFeature(int) requestWindowFeature(<em>some_feature</em>)}) - to hide the title. Here is an example of hiding the title bar:</p> -<pre>//Hide the title bar -requestWindowFeature(Window.FEATURE_NO_TITLE); -</pre> -<p>A better way to achieve the same end is to specify a theme in your Android -Manifest file:</p> -<pre><application android:icon="@drawable/icon" android:theme="@android:style/Theme.NoTitleBar"> -</pre> -<p>This is preferable because it tells the system not to show a title bar while -your application is starting up. With the explicit method call, your application -will have a title bar visible to the user until <code>onCreate</code> runs.</p> -<p>(Note that this can be applied to either the <code><application></code> -tag or to individual <code><activity></code> tags.)</p> -<p class="caution"><strong>Caution:</strong> This theme will also hide the Action Bar on Android -3.0 and higher. If you want to keep the Action Bar, but hide the title bar, see how you can <a -href="{@docRoot}guide/topics/ui/themes.html#SelectATheme">select a theme based on platform -version</a>.</p> -<a name="localhostalias" id="localhostalias"></a><h2>Referring to localhost from the emulated -environment</h2> -<p> -If you need to refer to your host computer's <em>localhost</em>, such as when you -want the emulator client to contact a server running on the same host, use the alias -<code>10.0.2.2</code> to refer to the host computer's loopback interface. -From the emulator's perspective, localhost (<code>127.0.0.1</code>) refers to its own -loopback interface. -</p> -<a name="appstate" id="appstate"></a><h2>Storing and Retrieving State</h2> -<p>If your application is dumped from memory because of space concerns, it will lose - all user interface state information such as checkbox state and text box values - as well as class member values. Android calls {@link android.app.Activity#onSaveInstanceState(android.os.Bundle) - Activity.onSaveInstanceState} before it pauses the application. This method hands in a {@link - android.os.Bundle Bundle} that can be used to store name/value pairs that will - persist and be handed back to the application even if it is dropped from memory. - Android will pass this Bundle back to you when it calls {@link android.app.Activity#onCreate(android.os.Bundle) - onCreate()}. This Bundle only exists while the application is still in the history - stack (whether or not it has been removed from memory) and will be lost when - the application is finalized. See the topics for {@link android.app.Activity#onSaveInstanceState} and - {@link android.app.Activity#onCreate} for - examples of storing and retrieving state.</p> -<p>Read more about the lifecycle of an activity in <a -href="{@docRoot}guide/topics/fundamentals/activities.html">Activities</a> document.</p> -<h3>Storing and Retrieving Larger or More Complex Persistent Data<a name="storingandretrieving" id="storingandretrieving"></a></h3> -<p>Your application can store files or complex collection objects, and reserve them - for private use by itself or other activities in the application, or it can expose - its data to all other applications on the device. See <a href="{@docRoot}guide/topics/data/data-storage.html">Storing, - Retrieving, and Exposing Data</a> to learn how to store and retrieve private data, - how to store and retrieve common data from the device, and how to expose your - private data to other applications.</p> -<a name="playback" id="playback"></a><h2>Playing Media Files</h2> -<p>Please see the document <a href="{@docRoot}guide/topics/media/index.html">Audio and Video</a> for more details.</p> -<a name="broadcastreceivers" id="broadcastreceivers"></a><h2>Listening For and Broadcasting Global Messages, and Setting Alarms</h2> -<p>You can create a listening class that can be notified or even instantiated whenever - a specific type of system message is sent. -</p> -<p>The listening classes, called broadcast receivers, extend {@link android.content.BroadcastReceiver - BroadcastReceiver}. If you want Android to instantiate the object whenever an appropriate - intent notification is sent, define the receiver with a <code><receiver></code> element - in the AndroidManifext.xml file. If the caller is expected to instantiate the - object in preparation to receive a message, this is not required. The receiver - will get a call to their {@link android.content.BroadcastReceiver#onReceive(android.content.Context,android.content.Intent) - BroadcastReceiver.onReceive()} method. A receiver can define an <code><intent-filter></code> tag - that describes the types of messages it will receive. Just as Android's IntentResolver - will look for appropriate Activity matches for a startActivity() call, it will - look for any matching Receivers (but it will send the message to all matching - receivers, not to the "best" match). </p> -<p>To send a notification, the caller creates an {@link android.content.Intent Intent} - object and calls {@link android.app.Activity#sendBroadcast(android.content.Intent) - Context.sendBroadcast()} with that Intent. Multiple recipients can receive - the same message. You can broadcast an Intent message to an intent receiver in - any application, not only your own. If the receiving class is not registered - using <code><receiver></code> in its manifest, you can dynamically instantiate - and register a receiver by calling {@link android.content.Context#registerReceiver(android.content.BroadcastReceiver,android.content.IntentFilter) - Context.registerReceiver()}. </p> -<p>Receivers can include intent filters to specify what kinds of intents they are - listening for. Alternatively, if you expect a single known caller to contact - a single known receiver, the receiver does not specify an intent filter, and - the caller specifies the receiver's class name in the Intent by calling {@link - android.content.Intent#setClassName(java.lang.String, java.lang.String) Intent.setClassName()} - with the recipient's class name. The recipient receives a {@link android.content.Context - Context} object that refers to its own package, not to the package of the sender.</p> -<p><em><strong>Note:</strong></em> If a receiver or broadcaster - enforces permissions, your application might need to request permission - to send or receive messages from that object. You can request permission by using - the <uses-permission> tag in the manifest. </p> -<p>Here is a code snippet of a sender and receiver. This example does not demonstrate - registering receivers dynamically. For a full code example, see the AlarmService - class in the ApiDemos project.</p> -<h3>Sending the message</h3> -<pre>// We are sending this to a specific recipient, so we will -// only specify the recipient class name. -Intent intent = new Intent(this, AlarmReceiver.class); -intent.putExtra("message","Wake up."); -sendBroadcast(intent); -</pre> -<h3>Receiving the message</h3> -<p><strong>Receiver AndroidManifest.xml </strong>(because there is no intent filter - child, this class will only receive a broadcast when the receiver class is specified - by name, as is done in this example):</p> -<pre> -<receiver class=".AlarmReceiver" /></pre> -<p><strong>Receiver Java code: </strong></p> -<pre> -public class AlarmReceiver extends BroadcastReceiver{ - // Display an alert that we've received a message. - @Override - public void onReceive(Context context, Intent intent){ - // Send a text notification to the screen. - NotificationManager nm = (NotificationManager) - context.getSystemService(Context.NOTIFICATION_SERVICE); - nm.notifyWithText(R.id.alarm, - "Alarm!!!", - NotificationManager.LENGTH_SHORT, - null); - } -} </pre> -<h3>Other system messages</h3> -<p>You can listen for other system messages sent by Android as well, such as USB - connection/removal messages, SMS arrival messages, and timezone changes. See - {@link android.content.Intent} for a list of broadcast messages to listen for. - Messages are marked "Broadcast Action" in the documentation. </p> -<h3>Listening for phone events<a name="phoneevents" id="phoneevents"></a></h3> -<p>The {@link android.telephony android.telephony} package overview page describes how to - register to listen for phone events. </p> -<a name="alarms" id="alarms"></a><h3>Setting Alarms </h3> -<p>Android provides an {@link android.app.AlarmManager AlarmManager} service that - will let you specify an Intent to send at a designated time. This intent is typically - used to start an application at a preset time. (Note: If you want to send - a notification to a sleeping or running application, use {@link android.os.Handler - Handler} instead.)</p> -<a name="alerts" id="alerts"></a><h2>Displaying Alerts</h2> -<p>There are two major kinds of alerts that you may display to the user: -(1) Normal alerts are displayed in response to a user action, such as -trying to perform an action that is not allowed. (2) Out-of-band alerts, -called notifications, are -displayed as a result of something happening in the background, such as the -user receiving new e-mail.</p> - -<a name="dialogsandalerts" id="dialogsandalerts"></a><h3>Normal Alerts</h3> - -<p>Android provides a number of ways for you to show popup notifications to your - user as they interact with your application. </p> -<table width="100%" border="1"> - <tr> - <th scope="col">Class</th> - <th scope="col">Description</th> - </tr> - <tr> - <td>{@link android.app.Dialog app.Dialog}</td> - <td>A generic floating dialog box with a layout that you design. </td> - </tr> - <tr> - <td><p>{@link android.app.AlertDialog app.AlertDialog}</p></td> - <td>A popup alert dialog with two buttons (typically OK and Cancel) that - take callback handlers. See the section after this table for more details. </td> - </tr> - <tr> - <td>{@link android.app.ProgressDialog ProgressDialog} </td> - <td>A dialog box used to indicate progress of an operation with a known progress - value or an indeterminate length (setProgress(bool)). See <strong>Views</strong> > <strong>Progress Bar</strong> in - ApiDemos for examples. </td> - </tr> - <tr> - <td>Activity</td> - <td>By setting the theme of an activity to - {@link android.R.style#Theme_Dialog - android:theme="@android:style/Theme.Dialog"}, - your activity will take on - the appearance of a normal dialog, floating on top of whatever was - underneath it. You usually set the theme through the - {@link android.R.attr#theme android:theme} attribute in your AndroidManifest.xml. - The advantage of this - over Dialog and AlertDialog is that Application has a much better managed - life cycle than dialogs: if a dialog goes to the background and is killed, - you cannot recapture state, whereas Application exposes a {@link android.os.Bundle - Bundle} of saved values in <code>onCreate()</code> to help you maintain state.</td> - </tr> -</table> -<h3>AlertDialog</h3> -<p>This is a basic warning dialog box that lets you configure a message, button text, - and callback. You can create one by calling using the {@link - android.app.AlertDialog.Builder} class, as shown here. </p> -<pre>private Handler mHandler = new Handler() { - public void handleMessage(Message msg) { - switch (msg.what) { - case ACCEPT_CALL: - answer(msg.obj); - break; - - case BOUNCE_TO_VOICEMAIL: - voicemail(msg.obj); - break; - - } - } -}; - - -private void IncomingMotherInlawCall(Connection c) { - String Text; - - // "Answer" callback. - Message acceptMsg = Message.obtain(); - acceptMsg.target = mHandler; - acceptMsg.what = ACCEPT_CALL; - acceptMsg.obj = c.getCall(); - - // "Cancel" callback. - final Message rejectMsg = Message.obtain(); - rejectMsg.target = mHandler; - rejectMsg.what = BOUNCE_TO_VOICEMAIL; - rejectMsg.obj = c.getCall(); - - new AlertDialog.Builder(this) - .setMessage("Phyllis is calling") - .setPositiveButton("Answer", acceptMsg) - .setOnCanceListener(new OnCancelListener() { - public void onCancel(DialogInterface dialog) { - rejectMsg.sendToTarget(); - }}); - .show(); -} </pre> - -<h3>Notifications</h3> - -<p>Out-of-band alerts should always be displayed using the -{@link android.app.NotificationManager}, which allows you to tell the user -about something they may be interested in without disrupting what they are -currently doing. A notification can be anything from a brief pop-up box -informing the user of the new information, through displaying a persistent -icon in the status bar, to vibrating, playing sounds, or flashing lights to -get the user's attention. In all cases, the user must explicitly shift their -focus to the notification before they can interact with it.</p> - -<p>The following code demonstrates using NotificationManager to display a basic text - popup when a new SMS message arrives in a listening service, and provides the - current message count. You can see several more examples in the ApiDemos application, - under app/ (named <em>notification</em>*.java).</p> -<pre>static void setNewMessageIndicator(Context context, int messageCount){ - // Get the static global NotificationManager object. - NotificationManager nm = NotificationManager.getDefault();</p> - - // If we're being called because a new message has been received, - // then display an icon and a count. Otherwise, delete the persistent - // message. - if (messageCount > 0) { - nm.notifyWithText(myApp.NOTIFICATION_GUID, // ID for this notification. - messageCount + " new message" + messageCount > 1 ? "s":"", // Text to display. - NotificationManager.LENGTH_SHORT); // Show it for a short time only. - } -}</pre> -<p>To display a notification in the status bar and have it launch an intent when - the user selects it (such as the new text message notification does), call {@link - android.app.NotificationManager#notify(int, android.app.Notification) NotificationManager.notify()}, - and pass in vibration patterns, status bar icons, or Intents to associate with - the notification. </p> -<a name="progressbar" id="progressbar"></a><h2>Displaying a Progress Bar</h2> -<p>An activity can display a progress bar to notify the user that something is happening. - To display a progress bar in a screen, call {@link android.app.Activity#requestWindowFeature(int) - Activity.requestWindowFeature(Window.FEATURE_PROGRESS)}. To set the value - of the progress bar, call {@link android.view.Window#setFeatureInt(int,int) - Activity.getWindow().setFeatureInt(Window.FEATURE_PROGRESS, <em>level</em>)}. - Progress bar values are from 0 to 9,999, or set the value to 10,000 to make the - progress bar invisible. </p> -<p>You can also use the {@link android.app.ProgressDialog ProgressDialog} class, - which enables a dialog box with an embedded progress bar to send a "I'm working - on it" notification to the user. </p> -<a name="addmenuitems" id="addmenuitems"></a><h2>Adding Items to the Screen Menu</h2> -<p>See <a href="{@docRoot}guide/topics/ui/menus.html">Menus</a>.</p> - -<a name="webpage" id="webpage"></a><h2>Display a Web Page</h2> -<p>Use the {@link android.webkit.WebView webkit.WebView} object. </p> -<a name="binding" id="binding"></a><h2>Binding to Data</h2> -<p>You can bind a ListView to a set of underlying data by using a shim class called - {@link android.widget.ListAdapter ListAdapter} (or a subclass). ListAdapter subclasses - bind to a variety of data sources, and expose a common set of methods such as - getItem() and getView(), and uses them to pick View items to display in its list. - You can extend ListAdapter and override getView() to create your own custom list - items. There are essentially only two steps you need to perform to bind to data: </p> -<ol> - <li>Create a ListAdapter object and specify its data source</li> - <li>Give the ListAdapter to your ListView object.</li> -</ol> -<p>That's it!</p> -<p>Here's an example of binding a ListActivity screen to the results from a cursor - query. (Note that the setListAdapter() method shown is a convenience method that - gets the page's ListView object and calls setAdapter() on it.)</p> -<pre>// Run a query and get a Cursor pointing to the results. -Cursor c = People.query(this.getContentResolver(), null); -startManagingCursor(c); - -// Create the ListAdapter. A SimpleCursorAdapter lets you specify two interesting things: -// an XML template for your list item, and -// The column to map to a specific item, by ID, in your template. -ListAdapter adapter = new SimpleCursorAdapter(this, - android.R.layout.simple_list_item_1, // Use a template that displays a text view - c, // Give the cursor to the list adapter - new String[] {People.NAME} , // Map the NAME column in the people database to... - new String[] {"text1"}); // The "text1" view defined in the XML template -setListAdapter(adapter);</pre> -<p>See view/List4 in the ApiDemos project for an example of extending ListAdapter - for a new data type. </p> - -<a name="handle"></a> - -<h2>Getting a Handle to a Screen Element</h2> -<p>You can get a handle to a screen element by calling {@link -android.app.Activity#findViewById(int) Activity.findViewById}. You can then use -the handle to set or retrieve any values exposed by the object. </p> -<a name="captureimages" id="captureimages"></a><h2>Capture Images from the Phone Camera</h2> -<p>You can hook into the device's camera onto your own Canvas object by using the - {@link android.hardware.Camera Camera} class. See that class's documentation, - and the ApiDemos project's Camera Preview application (Graphics/Camera Preview) - for example code. </p> - - -<a name="threading" id="threading"></a><h2>Handling Expensive Operations in the UI Thread</h2> -<p>Avoid performing long-running operations (such as network I/O) directly in the UI thread — -the main thread of an application where the UI is run — or your application may be blocked -and become unresponsive. Here is a brief summary of the recommended approach for handling expensive operations:</p> -<ol> -<li>Create a Handler object in your UI thread</li> -<li>Spawn off worker threads to perform any required expensive operations</li> -<li>Post results from a worker thread back to the UI thread's handler either through a Runnable or a {@link android.os.Message}</li> -<li>Update the views on the UI thread as needed</li> -</ol> - -<p>The following outline illustrates a typical implementation:</p> - -<pre> -public class MyActivity extends Activity { - - [ . . . ] - // Need handler for callbacks to the UI thread - final Handler mHandler = new Handler(); - - // Create runnable for posting - final Runnable mUpdateResults = new Runnable() { - public void run() { - updateResultsInUi(); - } - }; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - [ . . . ] - } - - protected void startLongRunningOperation() { - - // Fire off a thread to do some work that we shouldn't do directly in the UI thread - Thread t = new Thread() { - public void run() { - mResults = doSomethingExpensive(); - mHandler.post(mUpdateResults); - } - }; - t.start(); - } - - private void updateResultsInUi() { - - // Back in the UI thread -- update our UI elements based on the data in mResults - [ . . . ] - } -} -</pre> - -<p>For further discussions on this topic, see -<a href="{@docRoot}guide/practices/design/responsiveness.html">Designing for Responsiveness</a> -and the {@link android.os.Handler} documentation.</p> - -<a name="selectingtext" id="selectingtext"></a><h2>Selecting, Highlighting, or Styling Portions of Text</h2> -<p>You can highlight or style the formatting of strings or substrings of text in - a TextView object. There are two ways to do this:</p> -<ul> - <li>If you use a <a href="{@docRoot}guide/topics/resources/string-resource.html">string resource</a>, - you can add some simple styling, such as bold or italic using HTML notation. - The currently supported tags are: <code>B</code> (bold), - <code>I</code> (italic), <code>U</code> (underline), - <code>TT</code> (monospace), <code>BIG</code>, <code>SMALL</code>, - <code>SUP</code> (superscript), <code>SUB</code> (subscript), - and <code>STRIKE</code> (strikethrough). - So, for example, in res/values/strings.xml you could declare this:<br /> - <code><resources><br /> - <string name="styled_welcome_message">We - are <b><i>so</i></b> glad to see you.</string><br /> - </resources></code></li> - <li>To style text on the fly, or to add highlighting or more complex styling, - you must use the Spannable object as described next. </li> -</ul> -<p>To style text on the fly, you must make sure the TextView is using {@link android.text.Spannable} - storage for the text (this will always be true if the TextView is an EditText), - retrieve its text with {@link android.widget.TextView#getText}, and call {@link - android.text.Spannable#setSpan}, passing in a new style class from the {@link - android.text.style} package and the selection range. </p> -<p>The following code snippet demonstrates creating a string with a highlighted section, - italic section, and bold section, and adding it to an EditText object. </p> -<pre>// Get our EditText object. -EditText vw = (EditText)findViewById(R.id.text); - -// Set the EditText's text. -vw.setText("Italic, highlighted, bold."); - -// If this were just a TextView, we could do: -// vw.setText("Italic, highlighted, bold.", TextView.BufferType.SPANNABLE); -// to force it to use Spannable storage so styles can be attached. -// Or we could specify that in the XML. - -// Get the EditText's internal text storage -Spannable str = vw.getText(); - -// Create our span sections, and assign a format to each. -str.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); -str.setSpan(new BackgroundColorSpan(0xFFFFFF00), 8, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); -str.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 21, str.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); -</pre> - -<a name="querymap" id="querymap"></a><h2>Utilizing attributes in a Map query</h2> -<p> -When using a search intent to ask the Maps activity to search for something, the Maps activity responds to the following attributes in the optional context bundle: -</p> -<pre> - float "centerLatitude" default 0.0f - float "centerLongitude" default 0.0f - float "latitudeSpan" default 0.0f - float "longitudeSpan" default 0.0f - int "zoomLevel" default 10 -</pre> -<p> -This context information is used to center the search result in a particular area, and is equivalent to adjusting the Map activity to the described location and zoom level before issuing the query. -</p> -<p> -If the latitudeSpan, longitudeSpan, and zoomLevel attributes are not consistent, then it is undefined which one takes precedence. -</p> - -<a name="filelist" id="filelist"></a><h2>List of Files for an Android Application</h2> -<p>The following list describes the structure and files of an Android application. - Many of these files can be built for you (or stubbed out) by the android tool - shipped in the tools/ menu of the SDK. </p> -<table width="100%" border="0"> - <tr> - <td width="28%" valign="top">MyApp/<br /></td> - <td width="72%" valign="top"> </td> - </tr> - <tr> - <td valign="top"> AndroidManifest.xml</td> - <td valign="top">(<em>required</em>) Advertises the screens that this application provides, - where they can be launched (from the main program menu or elsewhere), - any content providers it implements and what kind of data they handle, - where the implementation classes are, and other application-wide - information. Syntax details for this file are described in <a href="{@docRoot}guide/topics/manifest/manifest-intro.html">The AndroidManifest.xml File</a>.</td> - </tr> - <tr> - <td valign="top"> src/<br /> - /<em>myPackagePath</em>/.../<em>MyClass</em>.java</td> - <td valign="top">(<em>required</em>) This folder holds all the source code files for your - application, inside the appropriate package subfolders. </td> - </tr> - <tr> - <td valign="top"> res/</td> - <td valign="top">(<em>required</em>) This folder holds all the <em>resources</em> for - your application. Resources are external data files or description files - that are compiled into your code at build time. Files in different folders - are compiled differently, so you must put the proper resource into the - proper folder. (See <a href="{@docRoot}guide/topics/resources/resources-i18n.html">Resources</a> for details.)</td> - </tr> - <tr> - <td valign="top"> anim/<br /> - <em>animation1</em>.xml<br /> - <em>...</em></td> - <td valign="top">(<em>optional</em>) Holds any animation XML description files that the - application uses. The format of these files is described in <a href="{@docRoot}guide/topics/resources/resources-i18n.html">Resources</a>. </td> - </tr> - <tr> - <td valign="top"> drawable/<br /> - <em>some_picture</em>.png<br /> - <em>some_stretchable</em>.9.png<br /> - <em>some_background</em>.xml<br /> - ...</td> - <td valign="top">(<em>optional</em>) Zero or more files that will be compiled to {@link - android.graphics.drawable android.graphics.drawable} resources. Files - can be image files (png, gif, or other) or XML files describing other - graphics such as bitmaps, stretchable bitmaps, or gradients. Supported - bitmap file formats are PNG (preferred), JPG, and GIF (discouraged), - as well as the custom 9-patch stretchable bitmap format. These formats - are described in <a href="{@docRoot}guide/topics/resources/resources-i18n.html">Resources</a>. </td> - </tr> - <tr> - <td valign="top"> layout/<br /> - <em>screen_1_layout</em>.xml<br /> - ...<br /></td> - <td valign="top">(<em>optional</em>) Holds all the XML files describing screens or parts - of screens. Although you could create a screen in Java, defining them - in XML files is typically easier. A layout file is similar in concept - to an HTML file that describes the screen layout and components. See <a href="{@docRoot}guide/topics/ui/index.html">User Interface</a> for more information about designing screens, and <a href="{@docRoot}guide/topics/resources/available-resources.html#layoutresources">Available Resource Types</a> for the syntax of these files.</td> - </tr> - <tr> - <td valign="top"> values/<br /> - arrays<br /> - classes.xml<br /> - colors.xml<br /> - dimens.xml<br /> - strings.xml<br /> - styles.xml<br /> - values.xml<br /></td> - <td valign="top"><p>(<em>optional</em>) XML files describing additional resources - such as strings, colors, and styles. The naming, quantity, and number - of these files are not enforced--any XML file is compiled, but these - are the standard names given to these files. However, the syntax - of these files is prescribed by Android, and described in <a href="{@docRoot}guide/topics/resources/resources-i18n.html">Resources</a>. </p> - </td> - </tr> - <tr> - <td valign="top"> xml/</td> - <td valign="top">(<em>optional</em>) XML files that can be read at run time on the device. </td> - </tr> - <tr> - <td valign="top"> raw/</td> - <td valign="top">(<em>optional</em>) Any files to be copied directly to the device. </td> - </tr> -</table> - - -<a name="logging" ></a> -<h2>Print Messages to a Log File</h2> - -<p>To write log messages from your application:</p> -<ol><li>Import <code>android.util.Log</code>.</li> - <li>Use <code>Log.v()</code>, <code>Log.d()</code>, <code>Log.i()</code>, - <code>Log.w()</code>, or <code>Log.e()</code> to log messages. - (See the {@link android.util.Log} class.)<br/> E.g., - <code>Log.e(this.toString(), "error: " + err.toString())</code></li> - <li>Launch <a href="{@docRoot}guide/developing/tools/ddms.html">DDMS</a> from a terminal - by executing <code>ddms</code> in your Android SDK <code>/tools</code> path.</li> - <li>Run your application in the Android emulator.</li> - <li>From the DDMS application, select the emulator - (e.g., "emulator-5554") and click <b>Device > Run logcat...</b> - to view all the log data.</li> -</ol> -<p class="note"><strong>Note:</strong> If you are running Eclipse and -encounter a warning about the VM debug port when opening DDMS, you can ignore it -if you're only interested in logs. However, if you want to further inspect and -control your processes from DDMS, then you should close Eclipse before launching DDMS so that -it may use the VM debugging port.</p> - - diff --git a/docs/html/guide/faq/framework.jd b/docs/html/guide/faq/framework.jd deleted file mode 100644 index c851e72120b6..000000000000 --- a/docs/html/guide/faq/framework.jd +++ /dev/null @@ -1,185 +0,0 @@ -page.title=Android Application Framework FAQ -excludeFromSuggestions=true -@jd:body - -<ul> - <li><a href="#1">Do all the Activities and Services of an - application run in a single process?</a></li> - <li><a href="#2">Do all Activities run in the main thread of - an application process?</a></li> - <li><a href="#3">How do I pass complicated data structures - from one Activity/Service to another?</a></li> - <li><a href="#4">How can I check if an Activity is already - running before starting it?</a></li> - <li><a href="#5">If an Activity starts a remote service, is - there any way for the Service to pass a message back to the Activity?</a></li> - <li><a href="#6">How to avoid getting the Application not - responding dialog?</a></li> - <li><a href="#7">How does an application know if a package is - added or removed?</a></li> -</ul> - - -<a name="1" id="1"></a> - -<h2>Do all the Activities and Services of an application run in a -single process?</h2> - -<p>All Activities and Services in an application run in a single process by -default. If needed, you can declare an <code>android:process</code> attribute -in your manifest file, to explicitly place a component (Activity/Service) in -another process.</p> - - - -<a name="2" id="2"></a> - -<h2>Do all Activities run in the main thread of an application -process?</h2> - -<p>By default, all of the application code in a single process runs -in the main UI thread. This is the same thread -that also handles UI events. The only exception is the code that handles -IPC calls coming in from other processes. The system maintains a -separate pool of transaction threads in each process to dispatch all -incoming IPC calls. The developer should create separate threads for any -long-running code, to avoid blocking the main UI thread.</p> - - - -<a name="3" id="3"></a> - -<h2>How do I pass data between Activities/Services within a single -application?</h2> - -<p>It depends on the type of data that you want to share:</p> - -<h3>Primitive Data Types</h3> - -<p>To share primitive data between Activities/Services in an -application, use Intent.putExtras(). For passing primitive data that -needs to persist use the -<a href="{@docRoot}guide/topics/data/data-storage.html#preferences"> -Preferences</a> storage mechanism.</p> - -<h3>Non-Persistent Objects</h3> - -<p>For sharing complex non-persistent user-defined objects for short -duration, the following approaches are recommended: -</p> - <h4>Singleton class</h4> - <p>You can take advantage of the fact that your application -components run in the same process through the use of a singleton. -This is a class that is designed to have only one instance. It -has a static method with a name such as <code>getInstance()</code> -that returns the instance; the first time this method is called, -it creates the global instance. Because all callers get the same -instance, they can use this as a point of interaction. For -example activity A may retrieve the instance and call setValue(3); -later activity B may retrieve the instance and call getValue() to -retrieve the last set value.</p> - - <h4>A public static field/method</h4> - <p>An alternate way to make data accessible across Activities/Services is to use <em>public static</em> -fields and/or methods. You can access these static fields from any other -class in your application. To share an object, the activity which creates your object sets a -static field to point to this object and any other activity that wants to use -this object just accesses this static field.</p> - - <h4>A HashMap of WeakReferences to Objects</h4> - <p>You can also use a HashMap of WeakReferences to Objects with Long -keys. When an activity wants to pass an object to another activity, it -simply puts the object in the map and sends the key (which is a unique -Long based on a counter or time stamp) to the recipient activity via -intent extras. The recipient activity retrieves the object using this -key.</p> - -<h3>Persistent Objects</h3> - -<p>Even while an application appears to continue running, the system -may choose to kill its process and restart it later. If you have data -that you need to persist from one activity invocation to the next, you -need to represent that data as state that gets saved by an activity when -it is informed that it might go away.</p> - -<p>For sharing complex persistent user-defined objects, the -following approaches are recommended: -<ul> - <li>Application Preferences</li> - <li>Files</li> - <li>contentProviders</li> - <li>SQLite DB</li> -</ul> -</p> - -<p>If the shared data needs to be retained across points where the application -process can be killed, then place that data in persistent storage like -Application Preferences, SQLite DB, Files or ContentProviders. Please refer to -the <a href="{@docRoot}guide/topics/data/data-storage.html">Data Storage</a> -for further details on how to use these components.</p> - - - - -<a name="4" id="4"></a> - -<h2>How can I check if an Activity is already running before starting -it?</h2> - -<p>The general mechanism to start a new activity if its not running— -or to bring the activity stack to the front if is already running in the -background— is the to use the NEW_TASK_LAUNCH flag in the startActivity() -call.</p> - - - -<a name="5" id="5"></a> - -<h2>If an Activity starts a remote service, is there any way for the -Service to pass a message back to the Activity?</h2> - -<p>See the {@link android.app.Service} documentation's for examples of -how clients can interact with a service. You can take advantage of the -fact that your components run in the same process to greatly simplify -service interaction from the generic remote case, as shown by the "Local -Service Sample". In some cases techniques like singletons may also make sense. - - -<a name="6" id="6"></a> - -<h2>How to avoid getting the Application not responding dialog?</h2> - -<p>Please read the <a href="{@docRoot}guide/practices/design/responsiveness.html">Designing for Responsiveness</a> -document.</p> - - - - -<a name="7" id="7"></a> - -<h2>How does an application know if a package is added or removed? -</h2> - -<p>Whenever a package is added, an intent with PACKAGE_ADDED action -is broadcast by the system. Similarly when a package is removed, an -intent with PACKAGE_REMOVED action is broadcast. To receive these -intents, you should write something like this: -<pre> - <receiver android:name ="com.android.samples.app.PackageReceiver"> - <intent-filter> - <action android:name="android.intent.action.PACKAGE_ADDED"/> - <action android:name="android.intent.action.PACKAGE_REMOVED"/> - - <data android:scheme="package" /> - </intent-filter> - </receiver> - </pre> - <br> -Here PackageReceiver is a BroadcastReceiver class.Its onReceive() -method is invoked, every time an application package is installed or -removed. - -</p> - - - diff --git a/docs/html/guide/faq/index.jd b/docs/html/guide/faq/index.jd deleted file mode 100644 index 0c5fb0e5ef1d..000000000000 --- a/docs/html/guide/faq/index.jd +++ /dev/null @@ -1,12 +0,0 @@ -page.title=Android FAQs -excludeFromSuggestions=true -@jd:body - -<dl> - <dt><a href="framework.html">Application Framework FAQ</a></dt> - <dd>Common questions about the Android Application Framework.</dd> - <dt><a href="licensingandoss.html">Open Source Licensing FAQ</a></dt> - <dd>Common topics around licensing and Android Open Source</dd> - <dt><a href="security.html">Android Security FAQ</a></dt> - <dd>Answers to common questions about Android security.</dd> -</dl> diff --git a/docs/html/guide/faq/licensingandoss.jd b/docs/html/guide/faq/licensingandoss.jd deleted file mode 100644 index d1dd9a7e8744..000000000000 --- a/docs/html/guide/faq/licensingandoss.jd +++ /dev/null @@ -1,18 +0,0 @@ -page.title=Android Open Source Licensing FAQ -excludeFromSuggestions=true -@jd:body - -<ul> - <li><a href="#mirror">Where can I find the open source components of Android?</a></li> - <li><a href="#timeline">When will we see more code released under open source licenses?</a></li> - <li><a href="#apache2">Why are you releasing the code under the Apache License instead of GPLv2?</a></li> -</ul> - -<a name="mirror" id="mirror"></a><h2>Where can I find the open source components of Android?</h2> -<p>The source code for the full Android stack is available from the <a href="http://source.android.com">Android Open Source Project </a> site. - -<p>Other mirrored GPL and LGPL'd components are available at <a href="http://code.google.com/p/android/downloads/list"><code>http://code.google.com/p/android/downloads/list</code></a>.</p> -<p>Notices for other licenses can be found within the SDK.</p> - -<a name="apache2" id="apache2"></a><h2>Why are you releasing the code under the Apache License instead of GPLv2?</h2> -<p>One of the best explanations for the reasoning behind releasing code under Apache2 can be found in a <a href="http://arstechnica.com/news.ars/post/20071106-why-google-chose-the-apache-software-license-over-gplv2.html">ArsTechnica article</a> by Ryan Paul.</p> diff --git a/docs/html/guide/faq/security.jd b/docs/html/guide/faq/security.jd deleted file mode 100644 index 8ccf21fc390e..000000000000 --- a/docs/html/guide/faq/security.jd +++ /dev/null @@ -1,157 +0,0 @@ -page.title=Android Security FAQ -excludeFromSuggestions=true -@jd:body - -<ul> - <li><a href="#secure">Is Android Secure?</a></li> - <li><a href="#issue">I think I found a security flaw. How do I report - it?</a></li> - <li><a href="#informed">How can I stay informed about Android security?</a></li> - <li><a href="#use">How do I securely use my Android phone?</a></li> - <li><a href="#malware">I think I found malicious software being distributed - for Android. How can I help?</a></li> - <li><a href="#fixes">How will Android-powered devices receive security fixes?</a> - </li> - <li><a href="#directfix">Can I get a fix directly from the Android Platform - Project?</a></li> -</ul> - - -<a name="secure" id="secure"></a><h2>Is Android secure?</h2> - -<p>The security and privacy of our users' data is of primary importance to the -Android Open Source Project. We are dedicated to building and maintaining one -of the most secure mobile platforms available while still fulfilling our goal -of opening the mobile device space to innovation and competition.</p> - -<p> A comprehensive overview of the <a -href="http://source.android.com/tech/security/index.html">Android -security model and Android security processes</a> is provided in the Android -Open Source Project Website.</p> - -<p>Application developers play an important part in the security of Android. -The Android Platform provides developers with a rich <a -href="http://code.google.com/android/devel/security.html">security model</a> -that to request the capabilities, or access, needed by their -application and to define new capabilities that other applications can request. -The Android user can choose to grant or deny an application's request for -certain capabilities on the handset.</p> - -<p>We have made great efforts to secure the Android platform, but it is -inevitable that security bugs will be found in any system of this complexity. -Therefore, the Android team works hard to find new bugs internally and responds -quickly and professionally to vulnerability reports from external researchers. -</p> - - -<a name="issue" id="issue"></a><h2>I think I found a security flaw. How do I -report it?</h2> - -<p>You can reach the Android security team at security@android.com. If you like, you -can protect your message using our <a -href="http://code.google.com/android/security_at_android_dot_com.txt">PGP -key</a>.</p> - -<p>We appreciate researchers practicing responsible disclosure by emailing us -with a detailed summary of the issue and keeping the issue confidential while -users are at risk. In return, we will make sure to keep the researcher informed -of our progress in issuing a fix. </p> - -<p>Vulnerabilities specific to Android OEMs should be reported to the relevant -vendor. An incomplete list of Android vendor security contacts can be found below. -To be added to this list, please contact security@android.com.</p> - -<ul> - <li><a href="http://www.htc.com/www/terms/product-security/">HTC</a></li> - <li><a href="http://www.motorolasolutions.com/US-EN/About/Security%20Vulnerability">Motorola</a></li> - <li><a href="http://developer.samsung.com/notice/How-to-Use-the-Forum">Samsung</a> - m.security@samsung.com</li> -</ul> - -<a name="informed" id="informed"></a><h2>How can I stay informed about Android security?</h2> - -<p>For general discussion of Android platform security, or how to use -security features in your Android application, please subscribe to <a -href="http://groups.google.com/group/android-security-discuss">android-security-discuss</a>. -</p> - - -<a name="use" id="use"></a><h2>How do I securely use my Android phone?</h2> - -<p>Android was designed so that you can safely use your phone without making -any changes to the device or installing any special software. Android applications -run in an Application Sandbox that limits access to sensitive information or data -with the users permission.</p> - -<p>To fully benefit from the security protections in Android, it is important that -users only download and install software from known sources.</p> - -<p>As an open platform, Android allows users to visit any website and load -software from any developer onto a device. As with a home PC, the user must be -aware of who is providing the software they are downloading and must decide -whether they want to grant the application the capabilities it requests. -This decision can be informed by the user's judgment of the software -developer's trustworthiness, and where the software came from.</p> - - -<a name="malware" id="malware"></a><h2>I think I found malicious software being -distributed for Android. How can I help?</h2> - -<p>Like any other platform, it will be possible for unethical developers -to create malicious software, known as <a -href="http://en.wikipedia.org/wiki/Malware">malware</a>, for Android. If you -think somebody is trying to spread malware, please let us know at -security@android.com. Please include as -much detail about the application as possible, with the location it is -being distributed from and why you suspect it of being malicious software.</p> - -<p>The term <i>malicious software</i> is subjective, and we cannot make an -exhaustive definition. Some examples of what the Android Security Team believes -to be malicious software is any application that: -<ul> - <li>uses a bug or security vulnerability to gain permissions that have not - been granted by the user</li> - <li>shows the user unsolicited messages (especially messages urging the - user to buy something);</li> - <li>resists (or attempts to resist) the user's effort to uninstall it;</li> - <li>attempts to automatically spread itself to other devices;</li> - <li>hides its files and/or processes;</li> - <li>discloses the user's private information to a third party, without the - user's knowledge and consent;</li> - <li>destroys the user's data (or the device itself) without the user's - knowledge and consent;</li> - <li>impersonates the user (such as by sending email or buying things from a - web store) without the user's knowledge and consent; or</li> - <li>otherwise degrades the user's experience with the device.</li> -</ul> -</p> - - -<a name="fixes" id="fixes"></a><h2>How do Android-powered devices receive security -fixes?</h2> - -<p>The manufacturer of each device is responsible for distributing software -upgrades for it, including security fixes. Many devices will update themselves -automatically with software downloaded "over the air", while some devices -require the user to upgrade them manually.</p> - -<p>Google provides software updates for a number of Android devices, including -the <a href="http://www.google.com/nexus">Nexus</a> -series of devices, using an "over the air" (OTA) update. These updates may include -security fixes as well as new features.</p> - -<a name="directfix" id="directfix"></a><h2>Can I get a fix directly from the -Android Platform Project?</h2> - -<p>Android is a mobile platform that is released as open source and -available for free use by anybody. This means that there are many -Android-based products available to consumers, and most of them are created -without the knowledge or participation of the Android Open Source Project. Like -the maintainers of other open source projects, we cannot build and release -patches for the entire ecosystem of products using Android. Instead, we will -work diligently to find and fix flaws as quickly as possible and to distribute -those fixes to the manufacturers of the products through the open source project.</p> - -<p>If you are making an Android-powered device and would like to know how you can -properly support your customers by keeping abreast of software updates, please -contact us at <a -href="mailto:info@openhandsetalliance.com">info@openhandsetalliance.com</a>.</p> diff --git a/docs/html/guide/faq/troubleshooting.jd b/docs/html/guide/faq/troubleshooting.jd deleted file mode 100644 index 8bb7eeb9d88c..000000000000 --- a/docs/html/guide/faq/troubleshooting.jd +++ /dev/null @@ -1,336 +0,0 @@ -page.title=Troubleshooting -excludeFromSuggestions=true -@jd:body - - -<p>Here are some tips and tricks for common Android errors. Don't forget to use the - ddms logcat capability to get a deeper view when errors occur. - See the <a href="{@docRoot}guide/developing/debugging/index.html">Debugging</a> documentation for more information.</p> -<ul> - <li><a href="#installeclipsecomponents">ADT Installation Error: "requires plug-in org.eclipse.wst.sse.ui".</a></li> - <li><a href="#nodevice">ADB reports "no device" when an emulator is running</a></li> - <li><a href="#noapp">My new application/activity isn't showing up in the device application - list </a></li> - <li><a href="#noupdate">I updated my app, but the updates don't seem to be showing up on - the device</a></li> - <li><a href="#layout_wilih">I'm getting a "Binary XML file line #2: You must supply a layout_wilih - attribute" error when I start an application</a></li> - <li><a href="#permission">My request to (<em>make a call, catch an incoming SMS, receive - a notification, send an intent to an Android application</em>) is being - ignored</a></li> - <li><a href="#build">Help! My project won't build in Eclipse</a></li> - <li><a href="#eclipse">Eclipse isn't talking to the emulator</a></li> - <li><a href="#majorminor">When I go to preferences in Eclipse and select "Android", I get the following error message: Unsupported major.minor version 49.0.</a></li> - <li><a href="#apidemosreinstall">I can't install ApiDemos apps in my IDE because of a signing error</a></li> - <li><a href="#gesturebuilderinstall">I can't install the GestureBuilder sample -app in the emulator</a></li> - <li><a href="#signingcalendar">I can't compile my app because the build tools generated an expired debug certificate</a></li> - <li><a href="#manifestfiles">Unable to view manifest files from within Eclipse</a></li> -</ul> - -<a name="installeclipsecomponents" id="installeclipsecomponents"></a><h2>ADT Installation Error: "requires plug-in org.eclipse.wst.sse.ui".</h2> -<p> -The "Android Editors" feature of the ADT Plugin requires specific Eclipse components, such as WST. If you -encounter this error message during ADT installation, you need to install the -required Eclipse components and then try the ADT installation again. Follow the steps below to install the required components for the -Android Editors feature, based on the version of Eclipse that you are using.</p> - -<table style="font-size:100%"> -<tr><th>Eclipse 3.3 (Europa)</th><th>Eclipse 3.4 (Ganymede)</th></tr> -<tr> -<td width="50%"> -<ol> -<li>From the dialog where you select the <strong>Update sites to visit</strong>, select the checkboxes for both the -ADT site, and the Callisto/Europa/Ganymede Discovery Site (you may want to -check <strong>Automatically select mirrors</strong> at the bottom).</li> -<li>Click <strong>Finish</strong>.</li> -<li>In the <strong>Next</strong> dialog, select the Android Plugins.</li> -<li>Now, expand the tree item of the discovery site. It seems that if you -don't do it, it doesn't load the content of the discovery site.</li> -<li>On the right, click <strong>Select required</strong>. This will select all the components -that are required to install the Android plugin (wst, emf, etc...).</li> -<li>Click <strong>Next</strong>, accept the agreement, click <strong>Install All</strong>, and restart Eclipse.</li> -</ol> -</td> -<td> -<ol> - <li>Select <strong>Help</strong> > <strong>Software Updates...</strong></li> - <li>Select the <strong>Installed Software</strong> tab.</li> - <li>Click <strong>Update...</strong></li> - <li>If an update for ADT is available, select it and click <strong>Finish</strong>.</li> -</ol> -</td> -</tr> -</table> - - -</p> -<a name="nodevice"></a><h2>ADB reports "no device" when an emulator is running</h2> - <p>Try restarting adb by stopping it (<code>adb - kill-server</code>) then any other adb command to restart it.</p> - -<a name="noapp"></a><h2>My new application/activity isn't showing up in the - applications list </h2> -<ul> - <li>You often must restart your device or emulator before a new activity shows - up in the applications list. This is particularly true when it is a completely - new application with a new AndroidManifest.xml file.</li> - <li>If this is for a new activity in an existing AndroidManifest.xml file, did - you include an <code><activity></code> tag for your app (or a <code><service></code> tag - for a service, or a <code><receiver></code> tag for a receiver, etc.)? </li> - <li>Make sure that your AndroidManifest.xml file is valid. Errors in attribute - values, such as the <em>value </em> attribute in <code><action <em>value</em>="<em><something></em>"></code> - will often not be caught by compilers, but will prevent your application - from being displayed because the intent filter will not be matched. Extra - spaces or other characters can often sneak into these strings.</li> - <li>Did you send your .apk file to the device (<a href="{@docRoot}guide/developing/tools/adb.html#move">adb install</a>)?</li> - <li>Run logcat on your device (<code>adb logcat</code>) - and then install your .apk file. Check the logcat output to see whether the - application is being installed and recognized properly. Here's sample output - from a successful installation: -<pre>I/FileObserver( 414): *** onEvent wfd: 3 mask: 8 path: MyRSSReader.apk -D/PackageManager( 414): Scanning package: /data/app/MyRSSReader.apk -D/PackageManager( 414): Adding package com.example.codelab.rssexample -D/PackageManager( 414): Registered content provider: my_rss_item, className = com.example.codelab.rssexample.RssContentProvider, isSyncable = false -D/PackageManager( 414): Providers: com.example.codelab.rssexample.RssContentProvider -D/PackageManager( 414): Activities: com.example.codelab.rssexample.MyRssReader com.example.codelab.rssexample.MyRssReader2 </pre> - </li> - <li>If logcat shows that the package manager is having problems loading the manifest - file, force your manifest to be recompiled by adding a space in the file and - compiling it.</li> -</ul> -<a name="noupdate"></a><h2>I updated my app, but the updates don't seem to be showing up on the device</h2> - <p>Did you remember to send your .apk file to the device (<a href="{@docRoot}guide/developing/tools/adb.html#move">adb - install</a>)?</p> - -<a name="layout_wilih"></a><h2>I'm getting a "Binary XML file line #2: You must supply a layout_wilih - attribute" error - when I start an application (but I declare a layout_wilih attribute <em>right - there!!!</em>)</h2> -<ul> - <li>Make sure that the SDK you are building with is the same version as the Android - OS that you are running on. </li> - <li>Make sure that you're calling setContentView() early in your onCreate() method. - Calling other methods, such as setListAdapter() before calling setContentView() - can sometimes create odd errors when Android tries to access screen elements - that haven't been set before.</li> -</ul> -<a name="permission"></a><h2>My request to (<em>make a call, catch an incoming SMS, -receive a notification, send an intent to an Android application</em>) is being -ignored</h2> - <p>You might not have permission (or might not have requested permission) to - call this activity or receive this intent. Many standard Android activities, - such as making a call, have a permission assigned to it to prevent arbitrary - applications from sending or receiving requests. See <a - href="{@docRoot}guide/topics/security/security.html">Security and - Permissions</a> for more information on permissions, and - {@link android.Manifest.permission Manifest.permission} for a list of - standard permissions supported by the Android platform. -</p> -<a name="build"></a><h2>Help! My project won't build in Eclipse</h2> -<p>If your project doesn't build, you may notice symptoms such as new -resources added in the <code>res/</code> sub-folders not showing up in the R class, -the emulator not being started, not being able to run the application, or even seeming to run an old version of the application.</p> -<p>To troubleshoot these types of problems, first try:</p> -<ol> - <li>Switch to the DDMS view in Eclipse (if you don't already have it open): - <ol type="a"> - <li>From the menu select <code>Window > Open Perspective > Other</code></li> - <li>Select DDMS from the list and hit OK</li> - </ol> - </li> - <li>In the Devices panel (top right panel by default), click on the down triangle - to bring up the panel menu</li> - <li>Select <code>Reset ADB</code> from the menu, and then try running the - application again</li> -</ol> -<p>If the above still doesn't work, you can try these steps:</p> -<ol> - <li> - Check the console and problems tabs at the bottom of the Eclipse UI - </li> - <li> - If there are problems listed in either place, they should give you a clue - what is wrong - </li> - <li> - If you aren't sure if the problems are fresh or stale, clear the console - with a right click > Clear, then clean the project - </li> - <li> - To clean the project (a good idea with any kind of build error), select - Project > Clean from the eclipse main menu, then select the project you - are working on (or clean all) - </li> -</ol> -<a name="eclipse"></a><h2>Eclipse isn't talking to the emulator</h2> -<p>When communication doesn't seem to be happening between Eclipse and the emulator, symptoms can include: nothing happening when you press run, the emulator hanging waiting -for a debugger to connect, or errors that Eclipse reports about not being able -to find the emulator or shell. By far the most common symptom is that when you press run, the emulator starts (or -is already running), but the application doesn't start.</p> -<p> -You may find any of these steps will fix the problem and with practice you -probably can figure out which one you need to do for your particular issue, but -to start with, the safest option is to run through all of them in order:</p> -<ol> - <li> - Quit the emulator if it is running - </li> - <li> - Check that any emulator processes are killed (sometimes they can hang, use ps on unix or mac, or task manager in the process view on - windows). - </li> - <li> - Quit Eclipse - </li> - <li> - From the command line, type: -<pre>adb kill-server </pre> - </li> - <li> - Start Eclipse and try again - </li> -</ol> - -<a name="majorminor"></a><h2>When I go to preferences in Eclipse and select "Android", I get the following error message: Unsupported major.minor version 49.0.</h2> -<p>This error is displayed if you are using an older version of the JDK. Please make sure you are using JDK version 5 or 6.</p> - -<h2 id="apidemosreinstall">I can't install ApiDemos apps in my IDE because of a signing error</a></h2> - -<p>The Android system requires that all applications be signed, as described in - <a href="{@docRoot}guide/publishing/app-signing.html">Signing Your Applications</a>. The ApiDemos -applications included with the SDK are preinstalled on the emulator and for that reason have been -compiled and signed with a private key.</p> - -If you want to modify or run one of the ApiDemos apps from Eclipse/ADT or other IDE, you can do so -so only after you uninstall the <em>preinstalled</em> version of the app from the emulator. If -you try to run an ApiDemos apps from your IDE without removing the preinstalled version first, -you will get errors similar to: </p> - -<pre>[2008-08-13 15:14:15 - ApiDemos] Re-installation failed due to different application signatures. -[2008-08-13 15:14:15 - ApiDemos] You must perform a full uninstall of the application. WARNING: ...This will remove the application data! -[2008-08-13 15:14:15 - ApiDemos] Please execute 'adb uninstall com.android.samples' in a shell.</pre> - -<p>The error occurs because, in this case, you are attempting to install another copy of ApiDemos -onto the emulator, a copy that is signed with a different certificate (the Android IDE tools will -have signed the app with a debug certificate, where the existing version was already signed with -a private certificate). The system does not allow this type of reinstallation. </p> - -<p>To resolve the issue, you need to fully uninstall the preinstalled and then reinstall it using -the adb tool. Here's how to do that:</p> - -<ol> - <li>In a terminal, change to the tools directory of the SDK.</li> - <li>If no emulator instance is running, start an emulator using using the command <code>emulator</code>.</li> - <li>Uninstall the preinstalled app using the command <code>adb uninstall com.example.android.apis</code>.</li> - <li>Reinstall the app using the command <code>adb install <path to the ApiDemos.apk></code>. If you are - working in Eclipse/ADT, you can just compile and run the app in the normal way. </li> -</ol> - -<p>Note that if multiple emulator instances are running, you need to direct your uninstall/install -commands to the emulator instance that you are targeting. To do that you can add the -<code>-s <serialNumber></code> to the command, for example: </p> - -<pre>adb -s emulator-5556 install</pre> - -<p>For more information about adb, see the <a href="{@docRoot}guide/developing/tools/adb.html">Android Debug Bridge</a> -documentation.</p> - -<h2 id="gesturebuilderinstall">I can't install the GestureBuilder sample -app in the emulator</a></h2> - -<p>This is similar to the ApiDemos problem described above, except that -you cannot fix it by uninstalling GestureBuilder from the emulator. The -GestureBuilder app cannot be uninstalled because it is currently installed -within the system files themselves.</p> - -<p><strong>Symptoms</strong></p> - -<ul><li><p>You cannot run GestureBuilder in the emulator:</p> - -<pre>[2009-12-10 14:57:19 - GestureBuilderActivity]Re-installation failed due to different application signatures. -[2009-12-10 14:57:19 - GestureBuilderActivity]You must perform a full uninstall of the application. WARNING: This will remove the application data! -[2009-12-10 14:57:19 - GestureBuilderActivity]Please execute 'adb uninstall com.android.gesture.builder' in a shell.</pre> -</li> - -<li><p>Running <code>adb uninstall com.android.gesture.builder</code> fails:</p> -<pre>$ adb uninstall com.android.gesture.builder - Failure</pre> -</li></ul> - -<p>For now, the work-around is to change the sample's package name -so that the system can install it as a new app rather than as a -replacement for the existing GestureBuilder app. To change the -package name, open the manifest file and modify the package attribute -of the manifest element. Next, update imports and other references to -the package name, rebuild the app, and run it in an AVD.</p> - -<p>For example, here's how you could do this in Eclipse:</p> - -<ol> - <li>Right-click on the package name -(<code>src/com.android.gesture.builder</code>).</li> - <li>Select <strong>Refactor > Rename</strong> and change the name, for example to -<code>com.android.gestureNEW.builder</code>. </li> - <li>Open the manifest file. Inside the <code><manifest></code> -tag, change the package name to -<code>com.android.gestureNEW.builder</code>.</li> - <li>Open each of the two Activity files and do Ctrl-Shift-O to add -missing import packages, then save each file.</li> -<li>Run the GestureBuilder application on the emulator.</li> -</ol> - -<p>If you get an error message such as "Could not load /sdcard/gestures. -Make sure you have a mounted SD card," be sure that your target AVD has an -SD card. To create an AVD that has an SD card, specify one when creating -an AVD with the AVD manager. See -<a href="{@docRoot}guide/developing/devices/managing-avds.html#createavd"> -Creating and Managing AVDs with AVD Manager</a> for more information.</p> - -<h2 id="signingcalendar">I can't compile my app because the build tools generated an expired debug certificate</h2> - -<p>If your development machine uses a locale that has a non-Gregorian calendar, you may encounter problems when first trying to compile and run your application. Specifically, you may find that the Android build tools won't compile your application because the debug key is expired. </p> - -<p>The problem occurs because the Keytool utility — included in the JDK and used by the Android build tools — fails to properly handle non-Gregorian locales and may create validity dates that are in the past. That is, it may generate a debug key that is already expired, which results in the compile error.</p> - -<p>If you encounter this problem, follow these steps to work around it: </p> - -<ol> -<li>First, delete the debug keystore/key already generated by the Android build tools. Specifically, delete the <code>debug.keystore</code> file. On Linux/Mac OSX, the file is stored in <code>~/.android</code>. On Windows XP, the file is stored in <code> -C:\Documents and Settings\<user>\.android</code>. On Windows Vista, the file is stored in <code> -C:\Users\<user>\.android</code></li> -<li>Next, you can either -<ul> -<li>Temporarily change your development machine's locale (date and time) to one that uses a Gregorian calendar, for example, United States. Once the locale is changed, use the Android build tools to compile and install your app. The build tools will regenerate a new keystore and debug key with valid dates. Once the new debug key is generated, you can reset your development machine to the original locale. </li> -<li>Alternatively, if you do not want to change your machine's locale settings, you can generate the keystore/key on any machine using the Gregorian calendar, then copy the <code>debug.keystore</code> file from that computer to the proper location on your development machine. </li> -</ul> -</li> -</ol> - -<p>This problem has been verified on Windows and may apply to other platforms. </p> - -<p>For general information about signing Android applications, see -<a href="{@docRoot}guide/publishing/app-signing.html">Signing Your Applications</a>. </p> - -<h2 id="manifestfiles">Unable to view manifest files from within -Eclipse</a></h2> - -<p>When you try to open an application's manifest file from within -Eclipse, you might get an error such as this one:</p> -<pre>An error has occurred. See error log for more details. -org.eclipse.wst.sse.ui.StructuredTextEditor.isBlockSelectionModeEnabled()Z</pre> - -<p>Try reverting to the 3.0 version of the Eclipse XML Editors and -Tools. If this does not work, remove the 3.1 version of the tool. To do -this in Eclipse 3.4:</p> - -<ol> - <li>Select <strong>Help > Software Updates...</strong></li> - <li>Select the <strong>Installed Software</strong> tab.</li> - <li>Select <strong>Eclipse XML Editors and Tools</strong>.</li> - <li>Click <strong>Uninstall</strong>.</li> - <li>Click <strong>Finish</strong>.</li> -</ol> - -<p>When you restart Eclipse, you should be able to view the manifest -files. </p>
\ No newline at end of file diff --git a/docs/html/robots.txt b/docs/html/robots.txt index ab379bb6e047..f5222208b094 100644 --- a/docs/html/robots.txt +++ b/docs/html/robots.txt @@ -15,5 +15,4 @@ Disallow: /shareables/ Disallow: /guide/tutorials/ Disallow: /guide/samples/ Disallow: /community/ -Disallow: /preview/ Sitemap: http://developer.android.com/sitemap.txt diff --git a/docs/html/sdk/index.jd b/docs/html/sdk/index.jd index bdc60a27302d..02beefd519bb 100644 --- a/docs/html/sdk/index.jd +++ b/docs/html/sdk/index.jd @@ -5,46 +5,46 @@ page.image=images/cards/android-studio_2x.png header.hide=1 page.metaDescription=Download the official Android IDE and developer tools to build apps for Android phones, tablets, wearables, TVs, and more. -studio.version=1.2.1.1 +studio.version=1.2.2.0 -studio.linux_bundle_download=android-studio-ide-141.1903250-linux.zip -studio.linux_bundle_bytes=258634089 -studio.linux_bundle_checksum=61f576a24ac9aa00d498bb62942c028ef4a8905b +studio.linux_bundle_download=android-studio-ide-141.1980579-linux.zip +studio.linux_bundle_bytes=258628239 +studio.linux_bundle_checksum=1fcb226bcf71760296b07dc0db74216563ce83f7 -studio.mac_bundle_download=android-studio-ide-141.1903250-mac.dmg -studio.mac_bundle_bytes=260877150 -studio.mac_bundle_checksum=a5a6ba50e3590de0973230a238d17726a1d9395c +studio.mac_bundle_download=android-studio-ide-141.1980579-mac.dmg +studio.mac_bundle_bytes=260363204 +studio.mac_bundle_checksum=811a868958f8799a1c86a3acfab0fc5dc8de2f41 -studio.win_bundle_download=android-studio-ide-141.1903250-windows.zip -studio.win_bundle_bytes=261042465 -studio.win_bundle_checksum=ce924e0e4cff4b7f24df3f7ce0c1ce2379347d72 +studio.win_bundle_download=android-studio-ide-141.1980579-windows.zip +studio.win_bundle_bytes=261036618 +studio.win_bundle_checksum=e61c9c27a92eff943f6bfdcdec3827199dd0c63d -studio.win_bundle_exe_download=android-studio-bundle-141.1903250-windows.exe -studio.win_bundle_exe_bytes=930462136 -studio.win_bundle_exe_checksum=680668b6b4a51c519efda814b96c2b61541a50f2 +studio.win_bundle_exe_download=android-studio-bundle-141.1980579-windows.exe +studio.win_bundle_exe_bytes=930456592 +studio.win_bundle_exe_checksum=964959e5165e90aaf693e868d5d1c2f7b38e8754 -studio.win_notools_exe_download=android-studio-ide-141.1903250-windows.exe -studio.win_notools_exe_bytes=243747312 -studio.win_notools_exe_checksum=d89917dd044e0559c87d6a05d49780ab110269f7 +studio.win_notools_exe_download=android-studio-ide-141.1980579-windows.exe +studio.win_notools_exe_bytes=243741776 +studio.win_notools_exe_checksum=ae09797db2537afb572a00b7eacc292bb66d539e -sdk.linux_download=android-sdk_r24.2-linux.tgz -sdk.linux_bytes=168119905 -sdk.linux_checksum=1a29f9827ef395a96db629209b0e38d5e2dd8089 +sdk.linux_download=android-sdk_r24.3.2-linux.tgz +sdk.linux_bytes=309563606 +sdk.linux_checksum=98e70ce403fea2e24e90103395d418feb3a9b7e8 -sdk.mac_download=android-sdk_r24.2-macosx.zip -sdk.mac_bytes=88949635 -sdk.mac_checksum=256c9bf642f56242d963c090d147de7402733451 +sdk.mac_download=android-sdk_r24.3.2-macosx.zip +sdk.mac_bytes=98259310 +sdk.mac_checksum=aa9aef30ff27358118318d82414b1481625faf2a -sdk.win_download=android-sdk_r24.2-windows.zip -sdk.win_bytes=155944165 -sdk.win_checksum=2611ed9a6080f4838f1d4e55172801714a8a169b +sdk.win_download=android-sdk_r24.3.2-windows.zip +sdk.win_bytes=187214094 +sdk.win_checksum=c33a63a955bb448ee550710a764ba18c37cb58d6 -sdk.win_installer=installer_r24.2-windows.exe -sdk.win_installer_bytes=107849819 -sdk.win_installer_checksum=e764ea93aa72766737f9be3b9fb3e42d879ab599 +sdk.win_installer=installer_r24.3.2-windows.exe +sdk.win_installer_bytes=139471724 +sdk.win_installer_checksum=8f9d0ae9fdb37973ed62d6e93975ff375beb5542 diff --git a/docs/html/tools/revisions/studio.jd b/docs/html/tools/revisions/studio.jd index 7138efe81016..b727d969dded 100644 --- a/docs/html/tools/revisions/studio.jd +++ b/docs/html/tools/revisions/studio.jd @@ -43,10 +43,24 @@ Android Studio, as denoted by revision number. </p> <div class="toggle-content opened"> <p><a href="#" onclick="return toggleContent(this)"> <img src="{@docRoot}assets/images/triangle-opened.png" class="toggle-content-img" + alt=""/>Android Studio v1.2.2</a> <em>(June 2015)</em> + </p> + <div class="toggle-content-toggleme"> + <p>Fixes and enhancements:</p> + <ul> + <li>Fixed build issues that were blocking builds from completing. </li> + </ul> + </div> +</div> + + +<div class="toggle-content closed"> + <p><a href="#" onclick="return toggleContent(this)"> + <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" alt=""/>Android Studio v1.2.1</a> <em>(May 2015)</em> </p> <div class="toggle-content-toggleme"> - <p>Various fixes and enhancements:</p> + <p>Fixes and enhancements:</p> <ul> <li>Fixed minor performance and feature issues. </li> </ul> @@ -62,7 +76,7 @@ Android Studio, as denoted by revision number. </p> </p> <div class="toggle-content-toggleme"> - <p>Various fixes and enhancements:</p> + <p>Fixes and enhancements:</p> <ul> <li>Updated the Android runtime window to include the <a href="{@docRoot}tools/studio/index.html#mem-cpu">Memory Monitor</a> tool diff --git a/docs/html/tools/sdk/tools-notes.jd b/docs/html/tools/sdk/tools-notes.jd index 434dc447ca26..326fbe29fe6a 100644 --- a/docs/html/tools/sdk/tools-notes.jd +++ b/docs/html/tools/sdk/tools-notes.jd @@ -21,9 +21,98 @@ Tools you are using, refer to the "Installed Packages" listing in the Android SD <p>For a summary of all known issues in SDK Tools, see <a href="http://tools.android.com/knownissues">http://tools.android.com/knownissues</a>.</p> + <div class="toggle-content opened"> <p><a href="#" onclick="return toggleContent(this)"> <img src="{@docRoot}assets/images/triangle-opened.png" class="toggle-content-img" + alt=""/>SDK Tools, Revision 24.3.2</a> <em>(June 2015)</em> + </p> + + <div class="toggle-content-toggleme"> + + <dl> + <dt>Dependencies:</dt> + + <dd> + <ul> + <li>Android SDK Platform-tools revision 19 or later.</li> + </ul> + </dd> + + <dt>General Notes:</dt> + <dd> + <ul> + <li>Fixed issues with the ARM 64-bit emulator.</li> + </ul> + </dd> + </div> +</div> + + +<div class="toggle-content closed"> + <p><a href="#" onclick="return toggleContent(this)"> + <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" + alt=""/>SDK Tools, Revision 24.3.1</a> <em>(June 2015)</em> + </p> + + <div class="toggle-content-toggleme"> + + <dl> + <dt>Dependencies:</dt> + + <dd> + <ul> + <li>Android SDK Platform-tools revision 19 or later.</li> + </ul> + </dd> + + <dt>General Notes:</dt> + <dd> + <ul> + <li>Fixed issue with the <code>root/</code> and <code>lib/</code> folders. </li> + </ul> + <p class="caution"><strong>Caution:</strong> This release is known to contain issues which + prevent builds from completing. We strongly recommend that you update to SDK Tools 24.3.2 + as soon as possible. </p> + </dd> + </div> +</div> + + +<div class="toggle-content closed"> + <p><a href="#" onclick="return toggleContent(this)"> + <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" + alt=""/>SDK Tools, Revision 24.3.0</a> <em>(June 2015)</em> + </p> + + <div class="toggle-content-toggleme"> + + <dl> + <dt>Dependencies:</dt> + + <dd> + <ul> + <li>Android SDK Platform-tools revision 19 or later.</li> + </ul> + </dd> + + <dt>General Notes:</dt> + <dd> + <ul> + <li>Fixed several minor emulator issues.</li> + </ul> + <p class="caution"><strong>Caution:</strong> This release is known to contain issues which + prevent builds from completing. We strongly recommend that you update to SDK Tools 24.3.2 + as soon as possible. </p> + </dd> + </div> +</div> + + + +<div class="toggle-content closed"> + <p><a href="#" onclick="return toggleContent(this)"> + <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" alt=""/>SDK Tools, Revision 24.2.0</a> <em>(May 2015)</em> </p> diff --git a/docs/html/training/cloudsync/gcm.jd b/docs/html/training/cloudsync/gcm.jd deleted file mode 100644 index 630337260900..000000000000 --- a/docs/html/training/cloudsync/gcm.jd +++ /dev/null @@ -1,212 +0,0 @@ -page.title=Making the Most of Google Cloud Messaging - -trainingnavtop=true - -@jd:body - -<div id="tb-wrapper"> - <div id="tb"> - <h2>This lesson teaches you to</h2> - <ol> - <li><a href="#multicast">Send Multicast Messages Efficiently</a></li> - <li><a href="#collapse">Collapse Messages that can Be Replaced</a></li> - <li><a href="#embed">Embed Data Directly in the GCM Message</a></li> - <li><a href="#react">React Intelligently to GCM Messages</a></li> - </ol> - <h2>You should also read</h2> - <ul> - <li><a href="http://developer.android.com/google/gcm/index.html">Google - Cloud Messaging for Android</a></li> - </ul> - </div> -</div> - -<p>Google Cloud Messaging (GCM) is a free service for sending -messages to Android devices. GCM messaging can greatly enhance the user -experience. Your application can stay up to date without wasting battery power -on waking up the radio and polling the server when there are no updates. Also, -GCM allows you to attach up to 1,000 recipients to a single message, letting you easily contact -large user bases quickly when appropriate, while minimizing the work load on -your server.</p> - -<p>This lesson covers some of the best practices -for integrating GCM into your application, and assumes you are already familiar -with basic implementation of this service. If this is not the case, you can read the <a - href="{@docRoot}google/gcm/demo.html">GCM demo app tutorial</a>.</p> - -<h2 id="multicast">Send Multicast Messages Efficiently</h2> -<p>One of the most useful features in GCM is support for up to 1,000 recipients for -a single message. This capability makes it much easier to send out important messages to -your entire user base. For instance, let's say you had a message that needed to -be sent to 1,000,000 of your users, and your server could handle sending out -about 500 messages per second. If you send each message with only a single -recipient, it would take 1,000,000/500 = 2,000 seconds, or around half an hour. -However, attaching 1,000 recipients to each message, the total time required to -send a message out to 1,000,000 recipients becomes (1,000,000/1,000) / 500 = 2 -seconds. This is not only useful, but important for timely data, such as natural -disaster alerts or sports scores, where a 30 minute interval might render the -information useless.</p> - -<p>Taking advantage of this functionality is easy. If you're using the <a - href="{@docRoot}google/gcm/gs.html#libs">GCM helper - library</a> for Java, simply provide a <code>List<String></code> collection of -registration IDs to the <code>send</code> or <code>sendNoRetry</code> method, -instead of a single registration ID.</p> - -<pre> -// This method name is completely fabricated, but you get the idea. -List<String> regIds = whoShouldISendThisTo(message); - -// If you want the SDK to automatically retry a certain number of times, use the -// standard send method. -MulticastResult result = sender.send(message, regIds, 5); - -// Otherwise, use sendNoRetry. -MulticastResult result = sender.sendNoRetry(message, regIds); -</pre> - -<p>For those implementing GCM support in a language other than Java, construct -an HTTP POST request with the following headers:</p> -<ul> - <li><code>Authorization: key=YOUR_API_KEY</code></li> - <li><code>Content-type: application/json</code></li> -</ul> - -<p>Then encode the parameters you want into a JSON object, listing all the -registration IDs under the key <code>registration_ids</code>. The snippet below -serves as an example. All parameters except <code>registration_ids</code> are -optional, and the items nested in <code>data</code> represent the user-defined payload, not -GCM-defined parameters. The endpoint for this HTTP POST message will be -<code>https://android.googleapis.com/gcm/send</code>.</p> - -<pre> -{ "collapse_key": "score_update", - "time_to_live": 108, - "delay_while_idle": true, - "data": { - "score": "4 x 8", - "time": "15:16.2342" - }, - "registration_ids":["4", "8", "15", "16", "23", "42"] -} -</pre> - -<p>For a more thorough overview of the format of multicast GCM messages, see the <a - href="{@docRoot}google/gcm/gcm.html#send-msg">Sending - Messages</a> section of the GCM guide.</pre> - -<h2 id="collapse">Collapse Messages that Can Be Replaced</h2> -<p>GCM messages are often a tickle, telling the mobile application to -contact the server for fresh data. In GCM, it's possible (and recommended) to -create collapsible messages for this situation, wherein new messages replace -older ones. Let's take the example -of sports scores. If you send out a message to all users following a certain -game with the updated score, and then 15 minutes later an updated score message -goes out, the earlier one no longer matters. For any users who haven't received -the first message yet, there's no reason to send both, and force the device to -react (and possibly alert the user) twice when only one of the messages is still -important.</p> - -<p>When you define a collapse key, when multiple messages are queued up in the GCM -servers for the same user, only the last one with any given collapse key is -delivered. For a situation like with sports scores, this saves the device from -doing needless work and potentially over-notifying the user. For situations -that involve a server sync (like checking email), this can cut down on the -number of syncs the device has to do. For instance, if there are 10 emails -waiting on the server, and ten "new email" GCM tickles have been sent to the -device, it only needs one, since it should only sync once.</p> - -<p>In order to use this feature, just add a collapse key to your outgoing -message. If you're using the GCM helper library, use the Message class's <code>collapseKey(String key)</code> method.</p> - -<pre> -Message message = new Message.Builder(regId) - .collapseKey("game4_scores") // The key for game 4. - .ttl(600) // Time in seconds to keep message queued if device offline. - .delayWhileIdle(true) // Wait for device to become active before sending. - .addPayload("key1", "value1") - .addPayload("key2", "value2") - .build(); -</pre> - -<p>If not using the helper library, simply add a variable to the -POST header you're constructing, with <code>collapse_key</code> as the field -name, and the string you're using for that set of updates as the value.</p> - - - -<h2 id="embed">Embed Data Directly in the GCM Message</h2> -<p>Often, GCM messages are meant to be a tickle, or indication to the device -that there's fresh data waiting on a server somewhere. However, a GCM message -can be up to 4kb in size, so sometimes it makes sense to simply send the -data within the GCM message itself, so that the device doesn't need to contact the -server at all. Consider this approach for situations where all of the -following statements are true: -<ul> - <li>The total data fits inside the 4kb limit.</li> - <li>Each message is important, and should be preserved.</li> - <li>It doesn't make sense to collapse multiple GCM messages into a single - "new data on the server" tickle.</li> -</ul> - -<p>For instance, short messages or encoded player moves -in a turn-based network game are examples of good use-cases for data to embed directly -into a GCM message. Email is an example of a bad use-case, since messages are -often larger than 4kb, -and users don't need a GCM message for each email waiting for them on -the server.</p> - -<p>Also consider this approach when sending -multicast messages, so you don't tell every device across your user base to hit -your server for updates simultaneously.</p> -<p>This strategy isn't appropriate for sending large amounts of data, for a few -reasons:</p> -<ul> - <li>Rate limits are in place to prevent malicious or poorly coded apps from spamming an - individual device with messages.</li> - <li>Messages aren't guaranteed to arrive in-order.</li> - <li>Messages aren't guaranteed to arrive as fast as you send them out. Even - if the device receives one GCM message a second, at a max of 1K, that's 8kbps, or - about the speed of home dial-up internet in the early 1990's. Your app rating - on Google Play will reflect having done that to your users.</p> -</ul> - -<p>When used appropriately, directly embedding data in the GCM message can speed -up the perceived speediness of your application, by letting it skip a round trip -to the server.</p> - -<h2 id="react">React Intelligently to GCM Messages</h2> -<p>Your application should not only react to incoming GCM messages, but react -<em>intelligently</em>. How to react depends on the context.</p> - -<h3>Don't be irritating</h3> -<p>When it comes to alerting your user of fresh data, it's easy to cross the line -from "useful" to "annoying". If your application uses status bar notifications, -<a - href="http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Updating">update - your existing notification</a> instead of creating a second one. If you -beep or vibrate to alert the user, consider setting up a timer. Don't let the -application alert more than once a minute, lest users be tempted to uninstall -your application, turn the device off, or toss it in a nearby river.</p> - -<h3>Sync smarter, not harder</h3> -<p>When using GCM as an indicator to the device that data needs to be downloaded -from the server, remember you have 4kb of metadata you can send along to -help your application be smart about it. For instance, if you have a feed -reading app, and your user has 100 feeds that they follow, help the device be -smart about what it downloads from the server! Look at the following examples -of what metadata is sent to your application in the GCM payload, and how the application -can react:</p> -<ul> - <li><code>refresh</code> — Your app basically got told to request a dump of - every feed it follows. Your app would either need to send feed requests to 100 different servers, or - if you have an aggregator on your server, send a request to retrieve, bundle - and - transmit recent data from 100 different feeds, every time one updates.</li> - <li><code>refresh</code>, <code>feedID</code> — Better: Your app knows to check - a specific feed for updates.</li> - <li><code>refresh</code>, <code>feedID</code>, <code>timestamp</code> — - Best: If the user happened to manually refresh before the GCM message - arrived, the application can compare timestamps of the most recent post, and - determine that it <em>doesn't need to do anything</em>. -</ul> diff --git a/docs/html/training/cloudsync/index.jd b/docs/html/training/cloudsync/index.jd index cf7117c3a12d..082ace5af31f 100644 --- a/docs/html/training/cloudsync/index.jd +++ b/docs/html/training/cloudsync/index.jd @@ -21,10 +21,8 @@ helps you build rich cloud-enabled apps that sync their data to a remote web service, making sure all your devices always stay in sync, and your valuable data is always backed up to the cloud.</p> -<p>This class covers different strategies for cloud enabled applications. It -covers syncing data with the cloud using your own back-end web application, and -backing up data using the cloud so that users can restore their data when -installing your application on a new device. +<p>This class covers strategies for backing up data using the cloud so that +users can restore their data when installing your application on a new device. </p> <h2>Lessons</h2> @@ -34,9 +32,5 @@ installing your application on a new device. <dd>Learn how to integrate the Backup API into your Android Application, so that user data such as preferences, notes, and high scores update seamlessly across all of a user's devices</dd> - <dt><strong><a href="gcm.html">Making the Most of Google Cloud Messaging</a></strong></dt> - <dd>Learn how to efficiently send multicast messages, react intelligently to - incoming Google Cloud Messaging (GCM) messages, and use GCM messages to - efficiently sync with the server.</dd> </dl> diff --git a/docs/html/training/sync-adapters/creating-sync-adapter.jd b/docs/html/training/sync-adapters/creating-sync-adapter.jd index b13ce0718fa4..9bd17ba90305 100644 --- a/docs/html/training/sync-adapters/creating-sync-adapter.jd +++ b/docs/html/training/sync-adapters/creating-sync-adapter.jd @@ -583,13 +583,6 @@ public class MainActivity extends FragmentActivity { running the sync adapter, see <a href="running-sync-adapter.html" >Running A Sync Adapter</a>. </dd> - <dt> -{@link android.Manifest.permission#AUTHENTICATE_ACCOUNTS android.permission.AUTHENTICATE_ACCOUNTS} - </dt> - <dd> - Allows you to use the authenticator component you created in the lesson - <a href="creating-authenticator.html">Creating a Stub Authenticator</a>. - </dd> </dl> <p> The following snippet shows how to add the permissions: diff --git a/docs/html/training/training_toc.cs b/docs/html/training/training_toc.cs index 0baef147431b..ccefe7267cf9 100644 --- a/docs/html/training/training_toc.cs +++ b/docs/html/training/training_toc.cs @@ -596,10 +596,6 @@ include the action bar on devices running Android 2.1 or higher." Using the Backup API </a> </li> - <li><a href="<?cs var:toroot ?>training/cloudsync/gcm.html"> - Making the Most of Google Cloud Messaging - </a> - </li> </ul> <li><a href="<?cs var:toroot ?>training/cloudsave/conflict-res.html" description= diff --git a/graphics/java/android/graphics/BitmapShader.java b/graphics/java/android/graphics/BitmapShader.java index bd74bc88e33f..9211225c7185 100644 --- a/graphics/java/android/graphics/BitmapShader.java +++ b/graphics/java/android/graphics/BitmapShader.java @@ -16,6 +16,8 @@ package android.graphics; +import android.annotation.NonNull; + /** * Shader used to draw a bitmap as a texture. The bitmap can be repeated or * mirrored by setting the tiling mode. @@ -38,7 +40,7 @@ public class BitmapShader extends Shader { * @param tileX The tiling mode for x to draw the bitmap in. * @param tileY The tiling mode for y to draw the bitmap in. */ - public BitmapShader(Bitmap bitmap, TileMode tileX, TileMode tileY) { + public BitmapShader(@NonNull Bitmap bitmap, TileMode tileX, TileMode tileY) { mBitmap = bitmap; mTileX = tileX; mTileY = tileY; diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index 392a5b635536..73866370f300 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -1728,8 +1728,7 @@ public class Canvas { * @param contextIndex the start of the context for shaping. Must be * no greater than index. * @param contextCount the number of characters in the context for shaping. - * contexIndex + contextCount must be no less than index - * + count. + * contexIndex + contextCount must be no less than index + count. * @param x the x position at which to draw the text * @param y the y position at which to draw the text * @param isRtl whether the run is in RTL direction @@ -1744,12 +1743,14 @@ public class Canvas { if (paint == null) { throw new NullPointerException("paint is null"); } - if ((index | count | text.length - index - count) < 0) { + if ((index | count | contextIndex | contextCount | index - contextIndex + | (contextIndex + contextCount) - (index + count) + | text.length - (contextIndex + contextCount)) < 0) { throw new IndexOutOfBoundsException(); } - native_drawTextRun(mNativeCanvasWrapper, text, index, count, - contextIndex, contextCount, x, y, isRtl, paint.getNativeInstance(), paint.mNativeTypeface); + native_drawTextRun(mNativeCanvasWrapper, text, index, count, contextIndex, contextCount, + x, y, isRtl, paint.getNativeInstance(), paint.mNativeTypeface); } /** @@ -1796,14 +1797,15 @@ public class Canvas { if (paint == null) { throw new NullPointerException("paint is null"); } - if ((start | end | end - start | text.length() - end) < 0) { + if ((start | end | contextStart | contextEnd | start - contextStart | end - start + | contextEnd - end | text.length() - contextEnd) < 0) { throw new IndexOutOfBoundsException(); } if (text instanceof String || text instanceof SpannedString || text instanceof SpannableString) { - native_drawTextRun(mNativeCanvasWrapper, text.toString(), start, end, - contextStart, contextEnd, x, y, isRtl, paint.getNativeInstance(), paint.mNativeTypeface); + native_drawTextRun(mNativeCanvasWrapper, text.toString(), start, end, contextStart, + contextEnd, x, y, isRtl, paint.getNativeInstance(), paint.mNativeTypeface); } else if (text instanceof GraphicsOperations) { ((GraphicsOperations) text).drawTextRun(this, start, end, contextStart, contextEnd, x, y, isRtl, paint); diff --git a/keystore/java/android/security/KeyChain.java b/keystore/java/android/security/KeyChain.java index 059d8e6dbf00..f482bf00ab0a 100644 --- a/keystore/java/android/security/KeyChain.java +++ b/keystore/java/android/security/KeyChain.java @@ -29,15 +29,14 @@ import android.os.Looper; import android.os.Process; import android.os.RemoteException; import android.os.UserHandle; -import android.security.keystore.KeyInfo; +import android.security.keystore.AndroidKeyStoreProvider; import android.security.keystore.KeyProperties; import java.io.ByteArrayInputStream; import java.io.Closeable; -import java.security.InvalidKeyException; -import java.security.KeyFactory; import java.security.Principal; import java.security.PrivateKey; +import java.security.UnrecoverableKeyException; import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; @@ -47,7 +46,6 @@ import java.util.Locale; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; -import com.android.org.conscrypt.OpenSSLEngine; import com.android.org.conscrypt.TrustedCertificateStore; /** @@ -90,8 +88,6 @@ import com.android.org.conscrypt.TrustedCertificateStore; // TODO reference intent for credential installation when public public final class KeyChain { - private static final String TAG = "KeyChain"; - /** * @hide Also used by KeyChainService implementation */ @@ -372,15 +368,14 @@ public final class KeyChain { if (keyId == null) { throw new KeyChainException("keystore had a problem"); } - - final OpenSSLEngine engine = OpenSSLEngine.getInstance("keystore"); - return engine.getPrivateKeyById(keyId); + return AndroidKeyStoreProvider.loadAndroidKeyStorePrivateKeyFromKeystore( + KeyStore.getInstance(), keyId); } catch (RemoteException e) { throw new KeyChainException(e); } catch (RuntimeException e) { // only certain RuntimeExceptions can be propagated across the IKeyChainService call throw new KeyChainException(e); - } catch (InvalidKeyException e) { + } catch (UnrecoverableKeyException e) { throw new KeyChainException(e); } finally { keyChainConnection.close(); diff --git a/keystore/java/android/security/KeyPairGeneratorSpec.java b/keystore/java/android/security/KeyPairGeneratorSpec.java index efbce41f9dc7..d8493175e63f 100644 --- a/keystore/java/android/security/KeyPairGeneratorSpec.java +++ b/keystore/java/android/security/KeyPairGeneratorSpec.java @@ -331,7 +331,9 @@ public final class KeyPairGeneratorSpec implements AlgorithmParameterSpec { if (keyType == null) { throw new NullPointerException("keyType == null"); } else { - if (KeyStore.getKeyTypeForAlgorithm(keyType) == -1) { + try { + KeyProperties.KeyAlgorithm.toKeymasterAsymmetricKeyAlgorithm(keyType); + } catch (IllegalArgumentException e) { throw new NoSuchAlgorithmException("Unsupported key type: " + keyType); } } diff --git a/keystore/java/android/security/KeyStore.java b/keystore/java/android/security/KeyStore.java index 893771aab987..6a08368321d8 100644 --- a/keystore/java/android/security/KeyStore.java +++ b/keystore/java/android/security/KeyStore.java @@ -19,7 +19,6 @@ package android.security; import android.app.ActivityThread; import android.app.Application; import android.app.KeyguardManager; -import com.android.org.conscrypt.NativeConstants; import android.content.Context; import android.hardware.fingerprint.FingerprintManager; @@ -38,7 +37,6 @@ import android.security.keymaster.OperationResult; import android.security.keystore.KeyExpiredException; import android.security.keystore.KeyNotYetValidException; import android.security.keystore.KeyPermanentlyInvalidatedException; -import android.security.keystore.KeyProperties; import android.security.keystore.UserNotAuthenticatedException; import android.util.Log; @@ -110,15 +108,10 @@ public class KeyStore { } public static Context getApplicationContext() { - ActivityThread activityThread = ActivityThread.currentActivityThread(); - if (activityThread == null) { - throw new IllegalStateException( - "Failed to obtain application Context: no ActivityThread"); - } - Application application = activityThread.getApplication(); + Application application = ActivityThread.currentApplication(); if (application == null) { throw new IllegalStateException( - "Failed to obtain application Context: no Application"); + "Failed to obtain application Context from ActivityThread"); } return application; } @@ -136,16 +129,6 @@ public class KeyStore { return mToken; } - public static int getKeyTypeForAlgorithm(@KeyProperties.KeyAlgorithmEnum String keyType) { - if (KeyProperties.KEY_ALGORITHM_RSA.equalsIgnoreCase(keyType)) { - return NativeConstants.EVP_PKEY_RSA; - } else if (KeyProperties.KEY_ALGORITHM_EC.equalsIgnoreCase(keyType)) { - return NativeConstants.EVP_PKEY_EC; - } else { - return -1; - } - } - public State state(int userId) { final int ret; try { @@ -710,16 +693,13 @@ public class KeyStore { } private long getFingerprintOnlySid() { - FingerprintManager fingerprintManager = - mContext.getSystemService(FingerprintManager.class); + FingerprintManager fingerprintManager = mContext.getSystemService(FingerprintManager.class); if (fingerprintManager == null) { return 0; } - if (!fingerprintManager.isHardwareDetected()) { - return 0; - } - + // TODO: Restore USE_FINGERPRINT permission check in + // FingerprintManager.getAuthenticatorId once the ID is no longer needed here. return fingerprintManager.getAuthenticatorId(); } diff --git a/keystore/java/android/security/keystore/AndroidKeyStoreECPrivateKey.java b/keystore/java/android/security/keystore/AndroidKeyStoreECPrivateKey.java new file mode 100644 index 000000000000..5dbcd681fe8f --- /dev/null +++ b/keystore/java/android/security/keystore/AndroidKeyStoreECPrivateKey.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2015 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.security.keystore; + +import java.security.PrivateKey; +import java.security.interfaces.ECKey; +import java.security.spec.ECParameterSpec; + +/** + * EC private key (instance of {@link PrivateKey} and {@link ECKey}) backed by keystore. + * + * @hide + */ +public class AndroidKeyStoreECPrivateKey extends AndroidKeyStorePrivateKey implements ECKey { + private final ECParameterSpec mParams; + + public AndroidKeyStoreECPrivateKey(String alias, ECParameterSpec params) { + super(alias, KeyProperties.KEY_ALGORITHM_EC); + mParams = params; + } + + @Override + public ECParameterSpec getParams() { + return mParams; + } +} diff --git a/keystore/java/android/security/keystore/AndroidKeyStoreKey.java b/keystore/java/android/security/keystore/AndroidKeyStoreKey.java index 1751aa5d1256..e76802f1dca5 100644 --- a/keystore/java/android/security/keystore/AndroidKeyStoreKey.java +++ b/keystore/java/android/security/keystore/AndroidKeyStoreKey.java @@ -52,4 +52,42 @@ public class AndroidKeyStoreKey implements Key { // This key does not export its key material return null; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((mAlgorithm == null) ? 0 : mAlgorithm.hashCode()); + result = prime * result + ((mAlias == null) ? 0 : mAlias.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + AndroidKeyStoreKey other = (AndroidKeyStoreKey) obj; + if (mAlgorithm == null) { + if (other.mAlgorithm != null) { + return false; + } + } else if (!mAlgorithm.equals(other.mAlgorithm)) { + return false; + } + if (mAlias == null) { + if (other.mAlias != null) { + return false; + } + } else if (!mAlias.equals(other.mAlias)) { + return false; + } + return true; + } } diff --git a/keystore/java/android/security/keystore/AndroidKeyStoreKeyPairGeneratorSpi.java b/keystore/java/android/security/keystore/AndroidKeyStoreKeyPairGeneratorSpi.java index 69155a89851f..35af34fbf6b6 100644 --- a/keystore/java/android/security/keystore/AndroidKeyStoreKeyPairGeneratorSpi.java +++ b/keystore/java/android/security/keystore/AndroidKeyStoreKeyPairGeneratorSpi.java @@ -20,7 +20,6 @@ import android.annotation.Nullable; import android.security.Credentials; import android.security.KeyPairGeneratorSpec; import android.security.KeyStore; -import android.security.keymaster.ExportResult; import android.security.keymaster.KeyCharacteristics; import android.security.keymaster.KeymasterArguments; import android.security.keymaster.KeymasterDefs; @@ -44,29 +43,24 @@ import com.android.org.bouncycastle.asn1.x9.X9ObjectIdentifiers; import com.android.org.bouncycastle.jce.X509Principal; import com.android.org.bouncycastle.jce.provider.X509CertificateObject; import com.android.org.bouncycastle.x509.X509V3CertificateGenerator; -import com.android.org.conscrypt.OpenSSLEngine; import libcore.util.EmptyArray; import java.math.BigInteger; import java.security.InvalidAlgorithmParameterException; -import java.security.InvalidKeyException; -import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.KeyPairGeneratorSpi; -import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.ProviderException; import java.security.PublicKey; import java.security.SecureRandom; +import java.security.UnrecoverableKeyException; import java.security.cert.CertificateEncodingException; import java.security.cert.X509Certificate; import java.security.spec.AlgorithmParameterSpec; import java.security.spec.ECGenParameterSpec; -import java.security.spec.InvalidKeySpecException; import java.security.spec.RSAKeyGenParameterSpec; -import java.security.spec.X509EncodedKeySpec; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -147,6 +141,7 @@ public abstract class AndroidKeyStoreKeyPairGeneratorSpi extends KeyPairGenerato SUPPORTED_EC_NIST_CURVE_NAMES.addAll(SUPPORTED_EC_NIST_CURVE_NAME_TO_SIZE.keySet()); Collections.sort(SUPPORTED_EC_NIST_CURVE_NAMES); } + private final int mOriginalKeymasterAlgorithm; private KeyStore mKeyStore; @@ -431,24 +426,6 @@ public abstract class AndroidKeyStoreKeyPairGeneratorSpi extends KeyPairGenerato args.addInts(KeymasterDefs.KM_TAG_PADDING, mKeymasterSignaturePaddings); args.addInts(KeymasterDefs.KM_TAG_DIGEST, mKeymasterDigests); - // TODO: Remove the digest and padding NONE workaround below once Android Keystore returns - // keys which are backed by AndroidKeyStoreBCWorkaround provider instead of Conscrypt. The - // workaround is needed because Conscrypt (via keystore-engine) uses old KeyStore API which - // translates into digest NONE and padding NONE in the new API. keystore-engine cannot be - // updated to pass in the correct padding and digest values because it uses - // OpenSSL/BoringSSL engine which performs digesting and padding prior before invoking - // KeyStore API. - if (!com.android.internal.util.ArrayUtils.contains( - mKeymasterDigests, KeymasterDefs.KM_DIGEST_NONE)) { - args.addInt(KeymasterDefs.KM_TAG_DIGEST, KeymasterDefs.KM_DIGEST_NONE); - } - if ((!com.android.internal.util.ArrayUtils.contains( - mKeymasterSignaturePaddings, KeymasterDefs.KM_PAD_NONE)) - && (!com.android.internal.util.ArrayUtils.contains( - mKeymasterEncryptionPaddings, KeymasterDefs.KM_PAD_NONE))) { - args.addInt(KeymasterDefs.KM_TAG_PADDING, KeymasterDefs.KM_PAD_NONE); - } - KeymasterUtils.addUserAuthArgs(args, mSpec.isUserAuthenticationRequired(), mSpec.getUserAuthenticationValidityDurationSeconds()); @@ -483,40 +460,23 @@ public abstract class AndroidKeyStoreKeyPairGeneratorSpi extends KeyPairGenerato "Failed to generate key pair", KeyStore.getKeyStoreException(errorCode)); } - final PrivateKey privKey; - final OpenSSLEngine engine = OpenSSLEngine.getInstance("keystore"); + KeyPair result; try { - privKey = engine.getPrivateKeyById(privateKeyAlias); - } catch (InvalidKeyException e) { - throw new ProviderException("Failed to obtain generated private key", e); + result = AndroidKeyStoreProvider.loadAndroidKeyStoreKeyPairFromKeystore( + mKeyStore, privateKeyAlias); + } catch (UnrecoverableKeyException e) { + throw new ProviderException("Failed to load generated key pair from keystore", e); } - ExportResult exportResult = - mKeyStore.exportKey( - privateKeyAlias, KeymasterDefs.KM_KEY_FORMAT_X509, null, null); - if (exportResult == null) { - throw new KeyStoreConnectException(); - } else if (exportResult.resultCode != KeyStore.NO_ERROR) { - throw new ProviderException( - "Failed to obtain X.509 form of generated public key", - KeyStore.getKeyStoreException(exportResult.resultCode)); - } - final byte[] pubKeyBytes = exportResult.exportData; - - final PublicKey pubKey; - try { - final KeyFactory keyFact = KeyFactory.getInstance(mJcaKeyAlgorithm); - pubKey = keyFact.generatePublic(new X509EncodedKeySpec(pubKeyBytes)); - } catch (NoSuchAlgorithmException e) { + if (!mJcaKeyAlgorithm.equalsIgnoreCase(result.getPrivate().getAlgorithm())) { throw new ProviderException( - "Failed to obtain " + mJcaKeyAlgorithm + " KeyFactory", e); - } catch (InvalidKeySpecException e) { - throw new ProviderException("Invalid X.509 encoding of generated public key", e); + "Generated key pair algorithm does not match requested algorithm: " + + result.getPrivate().getAlgorithm() + " vs " + mJcaKeyAlgorithm); } final X509Certificate cert; try { - cert = generateSelfSignedCertificate(privKey, pubKey); + cert = generateSelfSignedCertificate(result.getPrivate(), result.getPublic()); } catch (Exception e) { throw new ProviderException("Failed to generate self-signed certificate", e); } @@ -539,7 +499,6 @@ public abstract class AndroidKeyStoreKeyPairGeneratorSpi extends KeyPairGenerato KeyStore.getKeyStoreException(insertErrorCode)); } - KeyPair result = new KeyPair(pubKey, privKey); success = true; return result; } finally { diff --git a/keystore/java/android/security/keystore/AndroidKeyStoreProvider.java b/keystore/java/android/security/keystore/AndroidKeyStoreProvider.java index cb270bbfc0d9..967319af1684 100644 --- a/keystore/java/android/security/keystore/AndroidKeyStoreProvider.java +++ b/keystore/java/android/security/keystore/AndroidKeyStoreProvider.java @@ -16,11 +16,28 @@ package android.security.keystore; +import android.annotation.NonNull; import android.security.KeyStore; +import android.security.keymaster.ExportResult; +import android.security.keymaster.KeyCharacteristics; +import android.security.keymaster.KeymasterDefs; +import java.security.KeyFactory; +import java.security.KeyPair; +import java.security.NoSuchAlgorithmException; import java.security.Provider; +import java.security.ProviderException; +import java.security.PublicKey; import java.security.Security; import java.security.Signature; +import java.security.UnrecoverableKeyException; +import java.security.interfaces.ECKey; +import java.security.interfaces.ECPublicKey; +import java.security.interfaces.RSAKey; +import java.security.interfaces.RSAPublicKey; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.X509EncodedKeySpec; +import java.util.List; import javax.crypto.Cipher; import javax.crypto.Mac; @@ -146,4 +163,145 @@ public class AndroidKeyStoreProvider extends Provider { } return ((KeyStoreCryptoOperation) spi).getOperationHandle(); } + + @NonNull + public static AndroidKeyStorePublicKey getAndroidKeyStorePublicKey( + @NonNull String alias, + @NonNull @KeyProperties.KeyAlgorithmEnum String keyAlgorithm, + @NonNull byte[] x509EncodedForm) { + PublicKey publicKey; + try { + KeyFactory keyFactory = KeyFactory.getInstance(keyAlgorithm); + publicKey = keyFactory.generatePublic(new X509EncodedKeySpec(x509EncodedForm)); + } catch (NoSuchAlgorithmException e) { + throw new ProviderException( + "Failed to obtain " + keyAlgorithm + " KeyFactory", e); + } catch (InvalidKeySpecException e) { + throw new ProviderException("Invalid X.509 encoding of public key", e); + } + if (KeyProperties.KEY_ALGORITHM_EC.equalsIgnoreCase(keyAlgorithm)) { + return new AndroidKeyStoreECPublicKey(alias, (ECPublicKey) publicKey); + } else if (KeyProperties.KEY_ALGORITHM_RSA.equalsIgnoreCase(keyAlgorithm)) { + return new AndroidKeyStoreRSAPublicKey(alias, (RSAPublicKey) publicKey); + } else { + throw new ProviderException("Unsupported Android Keystore public key algorithm: " + + keyAlgorithm); + } + } + + @NonNull + public static AndroidKeyStorePrivateKey getAndroidKeyStorePrivateKey( + @NonNull AndroidKeyStorePublicKey publicKey) { + String keyAlgorithm = publicKey.getAlgorithm(); + if (KeyProperties.KEY_ALGORITHM_EC.equalsIgnoreCase(keyAlgorithm)) { + return new AndroidKeyStoreECPrivateKey( + publicKey.getAlias(), ((ECKey) publicKey).getParams()); + } else if (KeyProperties.KEY_ALGORITHM_RSA.equalsIgnoreCase(keyAlgorithm)) { + return new AndroidKeyStoreRSAPrivateKey( + publicKey.getAlias(), ((RSAKey) publicKey).getModulus()); + } else { + throw new ProviderException("Unsupported Android Keystore public key algorithm: " + + keyAlgorithm); + } + } + + @NonNull + public static AndroidKeyStorePublicKey loadAndroidKeyStorePublicKeyFromKeystore( + @NonNull KeyStore keyStore, @NonNull String privateKeyAlias) + throws UnrecoverableKeyException { + KeyCharacteristics keyCharacteristics = new KeyCharacteristics(); + int errorCode = keyStore.getKeyCharacteristics( + privateKeyAlias, null, null, keyCharacteristics); + if (errorCode != KeyStore.NO_ERROR) { + throw (UnrecoverableKeyException) + new UnrecoverableKeyException("Failed to obtain information about private key") + .initCause(KeyStore.getKeyStoreException(errorCode)); + } + ExportResult exportResult = keyStore.exportKey( + privateKeyAlias, KeymasterDefs.KM_KEY_FORMAT_X509, null, null); + if (exportResult.resultCode != KeyStore.NO_ERROR) { + throw (UnrecoverableKeyException) + new UnrecoverableKeyException("Failed to obtain X.509 form of public key") + .initCause(KeyStore.getKeyStoreException(errorCode)); + } + final byte[] x509EncodedPublicKey = exportResult.exportData; + + int keymasterAlgorithm = keyCharacteristics.getInt(KeymasterDefs.KM_TAG_ALGORITHM, -1); + if (keymasterAlgorithm == -1) { + throw new UnrecoverableKeyException("Key algorithm unknown"); + } + + String jcaKeyAlgorithm; + try { + jcaKeyAlgorithm = KeyProperties.KeyAlgorithm.fromKeymasterAsymmetricKeyAlgorithm( + keymasterAlgorithm); + } catch (IllegalArgumentException e) { + throw (UnrecoverableKeyException) + new UnrecoverableKeyException("Failed to load private key") + .initCause(e); + } + + return AndroidKeyStoreProvider.getAndroidKeyStorePublicKey( + privateKeyAlias, jcaKeyAlgorithm, x509EncodedPublicKey); + } + + @NonNull + public static KeyPair loadAndroidKeyStoreKeyPairFromKeystore( + @NonNull KeyStore keyStore, @NonNull String privateKeyAlias) + throws UnrecoverableKeyException { + AndroidKeyStorePublicKey publicKey = + loadAndroidKeyStorePublicKeyFromKeystore(keyStore, privateKeyAlias); + AndroidKeyStorePrivateKey privateKey = + AndroidKeyStoreProvider.getAndroidKeyStorePrivateKey(publicKey); + return new KeyPair(publicKey, privateKey); + } + + @NonNull + public static AndroidKeyStorePrivateKey loadAndroidKeyStorePrivateKeyFromKeystore( + @NonNull KeyStore keyStore, @NonNull String privateKeyAlias) + throws UnrecoverableKeyException { + KeyPair keyPair = loadAndroidKeyStoreKeyPairFromKeystore(keyStore, privateKeyAlias); + return (AndroidKeyStorePrivateKey) keyPair.getPrivate(); + } + + @NonNull + public static AndroidKeyStoreSecretKey loadAndroidKeyStoreSecretKeyFromKeystore( + @NonNull KeyStore keyStore, @NonNull String secretKeyAlias) + throws UnrecoverableKeyException { + KeyCharacteristics keyCharacteristics = new KeyCharacteristics(); + int errorCode = keyStore.getKeyCharacteristics( + secretKeyAlias, null, null, keyCharacteristics); + if (errorCode != KeyStore.NO_ERROR) { + throw (UnrecoverableKeyException) + new UnrecoverableKeyException("Failed to obtain information about key") + .initCause(KeyStore.getKeyStoreException(errorCode)); + } + + int keymasterAlgorithm = keyCharacteristics.getInt(KeymasterDefs.KM_TAG_ALGORITHM, -1); + if (keymasterAlgorithm == -1) { + throw new UnrecoverableKeyException("Key algorithm unknown"); + } + + List<Integer> keymasterDigests = + keyCharacteristics.getInts(KeymasterDefs.KM_TAG_DIGEST); + int keymasterDigest; + if (keymasterDigests.isEmpty()) { + keymasterDigest = -1; + } else { + // More than one digest can be permitted for this key. Use the first one to form the + // JCA key algorithm name. + keymasterDigest = keymasterDigests.get(0); + } + + @KeyProperties.KeyAlgorithmEnum String keyAlgorithmString; + try { + keyAlgorithmString = KeyProperties.KeyAlgorithm.fromKeymasterSecretKeyAlgorithm( + keymasterAlgorithm, keymasterDigest); + } catch (IllegalArgumentException e) { + throw (UnrecoverableKeyException) + new UnrecoverableKeyException("Unsupported secret key type").initCause(e); + } + + return new AndroidKeyStoreSecretKey(secretKeyAlias, keyAlgorithmString); + } } diff --git a/keystore/java/android/security/keystore/AndroidKeyStorePublicKey.java b/keystore/java/android/security/keystore/AndroidKeyStorePublicKey.java index 8133d468d1a2..9fea30d23a00 100644 --- a/keystore/java/android/security/keystore/AndroidKeyStorePublicKey.java +++ b/keystore/java/android/security/keystore/AndroidKeyStorePublicKey.java @@ -17,6 +17,7 @@ package android.security.keystore; import java.security.PublicKey; +import java.util.Arrays; /** * {@link PublicKey} backed by Android Keystore. @@ -41,4 +42,30 @@ public class AndroidKeyStorePublicKey extends AndroidKeyStoreKey implements Publ public byte[] getEncoded() { return ArrayUtils.cloneIfNotEmpty(mEncoded); } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + Arrays.hashCode(mEncoded); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + AndroidKeyStorePublicKey other = (AndroidKeyStorePublicKey) obj; + if (!Arrays.equals(mEncoded, other.mEncoded)) { + return false; + } + return true; + } } diff --git a/keystore/java/android/security/keystore/AndroidKeyStoreRSAPrivateKey.java b/keystore/java/android/security/keystore/AndroidKeyStoreRSAPrivateKey.java new file mode 100644 index 000000000000..179ffd8c1efd --- /dev/null +++ b/keystore/java/android/security/keystore/AndroidKeyStoreRSAPrivateKey.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2015 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.security.keystore; + +import java.math.BigInteger; +import java.security.PrivateKey; +import java.security.interfaces.RSAKey; + +/** + * RSA private key (instance of {@link PrivateKey} and {@link RSAKey}) backed by keystore. + * + * @hide + */ +public class AndroidKeyStoreRSAPrivateKey extends AndroidKeyStorePrivateKey implements RSAKey { + + private final BigInteger mModulus; + + public AndroidKeyStoreRSAPrivateKey(String alias, BigInteger modulus) { + super(alias, KeyProperties.KEY_ALGORITHM_RSA); + mModulus = modulus; + } + + @Override + public BigInteger getModulus() { + return mModulus; + } +} diff --git a/keystore/java/android/security/keystore/AndroidKeyStoreSignatureSpiBase.java b/keystore/java/android/security/keystore/AndroidKeyStoreSignatureSpiBase.java index 4c4062f936e4..f072ae755fef 100644 --- a/keystore/java/android/security/keystore/AndroidKeyStoreSignatureSpiBase.java +++ b/keystore/java/android/security/keystore/AndroidKeyStoreSignatureSpiBase.java @@ -25,7 +25,7 @@ import android.security.keymaster.KeymasterArguments; import android.security.keymaster.KeymasterDefs; import android.security.keymaster.OperationResult; -import com.android.org.conscrypt.util.EmptyArray; +import libcore.util.EmptyArray; import java.nio.ByteBuffer; import java.security.InvalidKeyException; diff --git a/keystore/java/android/security/keystore/AndroidKeyStoreSpi.java b/keystore/java/android/security/keystore/AndroidKeyStoreSpi.java index c03be63d976c..831a1061561a 100644 --- a/keystore/java/android/security/keystore/AndroidKeyStoreSpi.java +++ b/keystore/java/android/security/keystore/AndroidKeyStoreSpi.java @@ -16,9 +16,6 @@ package android.security.keystore; -import com.android.org.conscrypt.OpenSSLEngine; -import com.android.org.conscrypt.OpenSSLKeyHolder; - import libcore.util.EmptyArray; import android.security.Credentials; @@ -35,7 +32,6 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.security.InvalidKeyException; import java.security.Key; import java.security.KeyStore.Entry; import java.security.KeyStore.PrivateKeyEntry; @@ -45,6 +41,7 @@ import java.security.KeyStoreException; import java.security.KeyStoreSpi; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; +import java.security.PublicKey; import java.security.UnrecoverableKeyException; import java.security.cert.Certificate; import java.security.cert.CertificateEncodingException; @@ -59,7 +56,6 @@ import java.util.Date; import java.util.Enumeration; import java.util.HashSet; import java.util.Iterator; -import java.util.List; import java.util.Set; import javax.crypto.SecretKey; @@ -92,59 +88,17 @@ public class AndroidKeyStoreSpi extends KeyStoreSpi { public Key engineGetKey(String alias, char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyException { if (isPrivateKeyEntry(alias)) { - final OpenSSLEngine engine = OpenSSLEngine.getInstance("keystore"); - try { - return engine.getPrivateKeyById(Credentials.USER_PRIVATE_KEY + alias); - } catch (InvalidKeyException e) { - UnrecoverableKeyException t = new UnrecoverableKeyException("Can't get key"); - t.initCause(e); - throw t; - } + String privateKeyAlias = Credentials.USER_PRIVATE_KEY + alias; + return AndroidKeyStoreProvider.loadAndroidKeyStorePrivateKeyFromKeystore( + mKeyStore, privateKeyAlias); } else if (isSecretKeyEntry(alias)) { - KeyCharacteristics keyCharacteristics = new KeyCharacteristics(); - String keyAliasInKeystore = Credentials.USER_SECRET_KEY + alias; - int errorCode = mKeyStore.getKeyCharacteristics( - keyAliasInKeystore, null, null, keyCharacteristics); - if (errorCode != KeyStore.NO_ERROR) { - throw (UnrecoverableKeyException) - new UnrecoverableKeyException("Failed to load information about key") - .initCause(mKeyStore.getInvalidKeyException(alias, errorCode)); - } - - int keymasterAlgorithm = - keyCharacteristics.hwEnforced.getInt(KeymasterDefs.KM_TAG_ALGORITHM, -1); - if (keymasterAlgorithm == -1) { - keymasterAlgorithm = - keyCharacteristics.swEnforced.getInt(KeymasterDefs.KM_TAG_ALGORITHM, -1); - } - if (keymasterAlgorithm == -1) { - throw new UnrecoverableKeyException("Key algorithm unknown"); - } - - List<Integer> keymasterDigests = - keyCharacteristics.getInts(KeymasterDefs.KM_TAG_DIGEST); - int keymasterDigest; - if (keymasterDigests.isEmpty()) { - keymasterDigest = -1; - } else { - // More than one digest can be permitted for this key. Use the first one to form the - // JCA key algorithm name. - keymasterDigest = keymasterDigests.get(0); - } - - @KeyProperties.KeyAlgorithmEnum String keyAlgorithmString; - try { - keyAlgorithmString = KeyProperties.KeyAlgorithm.fromKeymasterSecretKeyAlgorithm( - keymasterAlgorithm, keymasterDigest); - } catch (IllegalArgumentException e) { - throw (UnrecoverableKeyException) - new UnrecoverableKeyException("Unsupported secret key type").initCause(e); - } - - return new AndroidKeyStoreSecretKey(keyAliasInKeystore, keyAlgorithmString); + String secretKeyAlias = Credentials.USER_SECRET_KEY + alias; + return AndroidKeyStoreProvider.loadAndroidKeyStoreSecretKeyFromKeystore( + mKeyStore, secretKeyAlias); + } else { + // Key not found + return null; } - - return null; } @Override @@ -188,22 +142,36 @@ public class AndroidKeyStoreSpi extends KeyStoreSpi { byte[] certificate = mKeyStore.get(Credentials.USER_CERTIFICATE + alias); if (certificate != null) { - return toCertificate(certificate); + return wrapIntoKeyStoreCertificate( + Credentials.USER_PRIVATE_KEY + alias, toCertificate(certificate)); } certificate = mKeyStore.get(Credentials.CA_CERTIFICATE + alias); if (certificate != null) { - return toCertificate(certificate); + return wrapIntoKeyStoreCertificate( + Credentials.USER_PRIVATE_KEY + alias, toCertificate(certificate)); } return null; } + /** + * Wraps the provided cerificate into {@link KeyStoreX509Certificate} so that the public key + * returned by the certificate contains information about the alias of the private key in + * keystore. This is needed so that Android Keystore crypto operations using public keys can + * find out which key alias to use. These operations cannot work without an alias. + */ + private static KeyStoreX509Certificate wrapIntoKeyStoreCertificate( + String privateKeyAlias, X509Certificate certificate) { + return (certificate != null) + ? new KeyStoreX509Certificate(privateKeyAlias, certificate) : null; + } + private static X509Certificate toCertificate(byte[] bytes) { try { final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); - return (X509Certificate) certFactory - .generateCertificate(new ByteArrayInputStream(bytes)); + return (X509Certificate) certFactory.generateCertificate( + new ByteArrayInputStream(bytes)); } catch (CertificateException e) { Log.w(NAME, "Couldn't parse certificate in keystore", e); return null; @@ -214,8 +182,8 @@ public class AndroidKeyStoreSpi extends KeyStoreSpi { private static Collection<X509Certificate> toCertificates(byte[] bytes) { try { final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); - return (Collection<X509Certificate>) certFactory - .generateCertificates(new ByteArrayInputStream(bytes)); + return (Collection<X509Certificate>) certFactory.generateCertificates( + new ByteArrayInputStream(bytes)); } catch (CertificateException e) { Log.w(NAME, "Couldn't parse certificates in keystore", e); return new ArrayList<X509Certificate>(); @@ -406,9 +374,7 @@ public class AndroidKeyStoreSpi extends KeyStoreSpi { } final String pkeyAlias; - if (key instanceof OpenSSLKeyHolder) { - pkeyAlias = ((OpenSSLKeyHolder) key).getOpenSSLKey().getAlias(); - } else if (key instanceof AndroidKeyStorePrivateKey) { + if (key instanceof AndroidKeyStorePrivateKey) { pkeyAlias = ((AndroidKeyStoreKey) key).getAlias(); } else { pkeyAlias = null; @@ -851,6 +817,19 @@ public class AndroidKeyStoreSpi extends KeyStoreSpi { if (cert == null) { return null; } + if (!"X.509".equalsIgnoreCase(cert.getType())) { + // Only X.509 certificates supported + return null; + } + byte[] targetCertBytes; + try { + targetCertBytes = cert.getEncoded(); + } catch (CertificateEncodingException e) { + return null; + } + if (targetCertBytes == null) { + return null; + } final Set<String> nonCaEntries = new HashSet<String>(); @@ -868,10 +847,9 @@ public class AndroidKeyStoreSpi extends KeyStoreSpi { continue; } - final Certificate c = toCertificate(certBytes); nonCaEntries.add(alias); - if (cert.equals(c)) { + if (Arrays.equals(certBytes, targetCertBytes)) { return alias; } } @@ -893,9 +871,7 @@ public class AndroidKeyStoreSpi extends KeyStoreSpi { continue; } - final Certificate c = - toCertificate(mKeyStore.get(Credentials.CA_CERTIFICATE + alias)); - if (cert.equals(c)) { + if (Arrays.equals(certBytes, targetCertBytes)) { return alias; } } @@ -954,4 +930,25 @@ public class AndroidKeyStoreSpi extends KeyStoreSpi { } } + /** + * {@link X509Certificate} which returns {@link AndroidKeyStorePublicKey} from + * {@link #getPublicKey()}. This is so that crypto operations on these public keys contain + * can find out which keystore private key entry to use. This is needed so that Android Keystore + * crypto operations using public keys can find out which key alias to use. These operations + * require an alias. + */ + static class KeyStoreX509Certificate extends DelegatingX509Certificate { + private final String mPrivateKeyAlias; + KeyStoreX509Certificate(String privateKeyAlias, X509Certificate delegate) { + super(delegate); + mPrivateKeyAlias = privateKeyAlias; + } + + @Override + public PublicKey getPublicKey() { + PublicKey original = super.getPublicKey(); + return AndroidKeyStoreProvider.getAndroidKeyStorePublicKey( + mPrivateKeyAlias, original.getAlgorithm(), original.getEncoded()); + } + } } diff --git a/keystore/java/android/security/keystore/DelegatingX509Certificate.java b/keystore/java/android/security/keystore/DelegatingX509Certificate.java new file mode 100644 index 000000000000..03d202fa323c --- /dev/null +++ b/keystore/java/android/security/keystore/DelegatingX509Certificate.java @@ -0,0 +1,212 @@ +/* + * Copyright (C) 2015 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.security.keystore; + +import java.math.BigInteger; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Principal; +import java.security.PublicKey; +import java.security.SignatureException; +import java.security.cert.CertificateEncodingException; +import java.security.cert.CertificateException; +import java.security.cert.CertificateExpiredException; +import java.security.cert.CertificateNotYetValidException; +import java.security.cert.CertificateParsingException; +import java.security.cert.X509Certificate; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Set; + +import javax.security.auth.x500.X500Principal; + +class DelegatingX509Certificate extends X509Certificate { + private final X509Certificate mDelegate; + + DelegatingX509Certificate(X509Certificate delegate) { + mDelegate = delegate; + } + + @Override + public Set<String> getCriticalExtensionOIDs() { + return mDelegate.getCriticalExtensionOIDs(); + } + + @Override + public byte[] getExtensionValue(String oid) { + return mDelegate.getExtensionValue(oid); + } + + @Override + public Set<String> getNonCriticalExtensionOIDs() { + return mDelegate.getNonCriticalExtensionOIDs(); + } + + @Override + public boolean hasUnsupportedCriticalExtension() { + return mDelegate.hasUnsupportedCriticalExtension(); + } + + @Override + public void checkValidity() throws CertificateExpiredException, + CertificateNotYetValidException { + mDelegate.checkValidity(); + } + + @Override + public void checkValidity(Date date) throws CertificateExpiredException, + CertificateNotYetValidException { + mDelegate.checkValidity(date); + } + + @Override + public int getBasicConstraints() { + return mDelegate.getBasicConstraints(); + } + + @Override + public Principal getIssuerDN() { + return mDelegate.getIssuerDN(); + } + + @Override + public boolean[] getIssuerUniqueID() { + return mDelegate.getIssuerUniqueID(); + } + + @Override + public boolean[] getKeyUsage() { + return mDelegate.getKeyUsage(); + } + + @Override + public Date getNotAfter() { + return mDelegate.getNotAfter(); + } + + @Override + public Date getNotBefore() { + return mDelegate.getNotBefore(); + } + + @Override + public BigInteger getSerialNumber() { + return mDelegate.getSerialNumber(); + } + + @Override + public String getSigAlgName() { + return mDelegate.getSigAlgName(); + } + + @Override + public String getSigAlgOID() { + return mDelegate.getSigAlgOID(); + } + + @Override + public byte[] getSigAlgParams() { + return mDelegate.getSigAlgParams(); + } + + @Override + public byte[] getSignature() { + return mDelegate.getSignature(); + } + + @Override + public Principal getSubjectDN() { + return mDelegate.getSubjectDN(); + } + + @Override + public boolean[] getSubjectUniqueID() { + return mDelegate.getSubjectUniqueID(); + } + + @Override + public byte[] getTBSCertificate() throws CertificateEncodingException { + return mDelegate.getTBSCertificate(); + } + + @Override + public int getVersion() { + return mDelegate.getVersion(); + } + + @Override + public byte[] getEncoded() throws CertificateEncodingException { + return mDelegate.getEncoded(); + } + + @Override + public PublicKey getPublicKey() { + return mDelegate.getPublicKey(); + } + + @Override + public String toString() { + return mDelegate.toString(); + } + + @Override + public void verify(PublicKey key) + throws CertificateException, + NoSuchAlgorithmException, + InvalidKeyException, + NoSuchProviderException, + SignatureException { + mDelegate.verify(key); + } + + @Override + public void verify(PublicKey key, String sigProvider) + throws CertificateException, + NoSuchAlgorithmException, + InvalidKeyException, + NoSuchProviderException, + SignatureException { + mDelegate.verify(key, sigProvider); + } + + @Override + public List<String> getExtendedKeyUsage() throws CertificateParsingException { + return mDelegate.getExtendedKeyUsage(); + } + + @Override + public Collection<List<?>> getIssuerAlternativeNames() throws CertificateParsingException { + return mDelegate.getIssuerAlternativeNames(); + } + + @Override + public X500Principal getIssuerX500Principal() { + return mDelegate.getIssuerX500Principal(); + } + + @Override + public Collection<List<?>> getSubjectAlternativeNames() throws CertificateParsingException { + return mDelegate.getSubjectAlternativeNames(); + } + + @Override + public X500Principal getSubjectX500Principal() { + return mDelegate.getSubjectX500Principal(); + } +} diff --git a/keystore/java/android/security/keystore/KeyGenParameterSpec.java b/keystore/java/android/security/keystore/KeyGenParameterSpec.java index 19ff9c764f6e..68c9c795a6c7 100644 --- a/keystore/java/android/security/keystore/KeyGenParameterSpec.java +++ b/keystore/java/android/security/keystore/KeyGenParameterSpec.java @@ -449,9 +449,6 @@ public final class KeyGenParameterSpec implements AlgorithmParameterSpec { * invalid signature. This is OK if the certificate is only used for obtaining the * public key from Android KeyStore. * - * <p><b>NOTE: The {@code purposes} parameter has currently no effect on asymmetric - * key pairs.</b> - * * <p>See {@link KeyProperties}.{@code PURPOSE} flags. */ public Builder(@NonNull String keystoreAlias, @KeyProperties.PurposeEnum int purposes) { @@ -556,8 +553,6 @@ public final class KeyGenParameterSpec implements AlgorithmParameterSpec { * * <p>By default, the key is valid at any instant. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * @see #setKeyValidityEnd(Date) */ @NonNull @@ -571,8 +566,6 @@ public final class KeyGenParameterSpec implements AlgorithmParameterSpec { * * <p>By default, the key is valid at any instant. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * @see #setKeyValidityStart(Date) * @see #setKeyValidityForConsumptionEnd(Date) * @see #setKeyValidityForOriginationEnd(Date) @@ -589,8 +582,6 @@ public final class KeyGenParameterSpec implements AlgorithmParameterSpec { * * <p>By default, the key is valid at any instant. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * @see #setKeyValidityForConsumptionEnd(Date) */ @NonNull @@ -605,8 +596,6 @@ public final class KeyGenParameterSpec implements AlgorithmParameterSpec { * * <p>By default, the key is valid at any instant. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * @see #setKeyValidityForOriginationEnd(Date) */ @NonNull @@ -624,8 +613,6 @@ public final class KeyGenParameterSpec implements AlgorithmParameterSpec { * keys, the set of digests defaults to the digest associated with the key algorithm (e.g., * {@code SHA-256} for key algorithm {@code HmacSHA256} * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * @see KeyProperties.Digest */ @NonNull @@ -642,8 +629,6 @@ public final class KeyGenParameterSpec implements AlgorithmParameterSpec { * * <p>This must be specified for keys which are used for encryption/decryption. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * <p>See {@link KeyProperties}.{@code ENCRYPTION_PADDING} constants. */ @NonNull @@ -660,8 +645,6 @@ public final class KeyGenParameterSpec implements AlgorithmParameterSpec { * * <p>This must be specified for RSA keys which are used for signing/verification. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * <p>See {@link KeyProperties}.{@code SIGNATURE_PADDING} constants. */ @NonNull @@ -678,8 +661,6 @@ public final class KeyGenParameterSpec implements AlgorithmParameterSpec { * * <p>This must be specified for encryption/decryption keys. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * <p>See {@link KeyProperties}.{@code BLOCK_MODE} constants. */ @NonNull @@ -723,8 +704,6 @@ public final class KeyGenParameterSpec implements AlgorithmParameterSpec { * <li>If you are using RSA encryption without padding, consider switching to encryption * padding schemes which offer {@code IND-CPA}, such as PKCS#1 or OAEP.</li> * </ul> - * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> */ @NonNull public Builder setRandomizedEncryptionRequired(boolean required) { @@ -748,8 +727,6 @@ public final class KeyGenParameterSpec implements AlgorithmParameterSpec { * <p>This restriction applies only to private key operations. Public key operations are not * restricted. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * @see #setUserAuthenticationValidityDurationSeconds(int) */ @NonNull @@ -764,8 +741,6 @@ public final class KeyGenParameterSpec implements AlgorithmParameterSpec { * * <p>By default, the user needs to authenticate for every use of the key. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * @param seconds duration in seconds or {@code -1} if the user needs to authenticate for * every use of the key. * diff --git a/keystore/java/android/security/keystore/KeyProtection.java b/keystore/java/android/security/keystore/KeyProtection.java index f52a193fab6a..48c0ed0f7c5a 100644 --- a/keystore/java/android/security/keystore/KeyProtection.java +++ b/keystore/java/android/security/keystore/KeyProtection.java @@ -305,9 +305,6 @@ public final class KeyProtection implements ProtectionParameter { * @param purposes set of purposes (e.g., encrypt, decrypt, sign) for which the key can be * used. Attempts to use the key for any other purpose will be rejected. * - * <p><b>NOTE: The {@code purposes} parameter has currently no effect on asymmetric - * key pairs.</b> - * * <p>See {@link KeyProperties}.{@code PURPOSE} flags. */ public Builder(@KeyProperties.PurposeEnum int purposes) { @@ -319,8 +316,6 @@ public final class KeyProtection implements ProtectionParameter { * * <p>By default, the key is valid at any instant. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * @see #setKeyValidityEnd(Date) */ @NonNull @@ -334,8 +329,6 @@ public final class KeyProtection implements ProtectionParameter { * * <p>By default, the key is valid at any instant. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * @see #setKeyValidityStart(Date) * @see #setKeyValidityForConsumptionEnd(Date) * @see #setKeyValidityForOriginationEnd(Date) @@ -352,8 +345,6 @@ public final class KeyProtection implements ProtectionParameter { * * <p>By default, the key is valid at any instant. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * @see #setKeyValidityForConsumptionEnd(Date) */ @NonNull @@ -368,8 +359,6 @@ public final class KeyProtection implements ProtectionParameter { * * <p>By default, the key is valid at any instant. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * @see #setKeyValidityForOriginationEnd(Date) */ @NonNull @@ -385,8 +374,6 @@ public final class KeyProtection implements ProtectionParameter { * * <p>This must be specified for keys which are used for encryption/decryption. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * <p>See {@link KeyProperties}.{@code ENCRYPTION_PADDING} constants. */ @NonNull @@ -403,8 +390,6 @@ public final class KeyProtection implements ProtectionParameter { * * <p>This must be specified for RSA keys which are used for signing/verification. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * <p>See {@link KeyProperties}.{@code SIGNATURE_PADDING} constants. */ @NonNull @@ -423,8 +408,6 @@ public final class KeyProtection implements ProtectionParameter { * {@link Key#getAlgorithm()}. For asymmetric signing keys the set of digest algorithms * must be specified. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * <p>See {@link KeyProperties}.{@code DIGEST} constants. */ @NonNull @@ -440,8 +423,6 @@ public final class KeyProtection implements ProtectionParameter { * * <p>This must be specified for encryption/decryption keys. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * <p>See {@link KeyProperties}.{@code BLOCK_MODE} constants. */ @NonNull @@ -483,8 +464,6 @@ public final class KeyProtection implements ProtectionParameter { * <li>If you are using RSA encryption without padding, consider switching to padding * schemes which offer {@code IND-CPA}, such as PKCS#1 or OAEP.</li> * </ul> - * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> */ @NonNull public Builder setRandomizedEncryptionRequired(boolean required) { @@ -505,8 +484,6 @@ public final class KeyProtection implements ProtectionParameter { * <a href="{@docRoot}training/articles/keystore.html#UserAuthentication">More * information</a>. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * @see #setUserAuthenticationValidityDurationSeconds(int) */ @NonNull @@ -521,8 +498,6 @@ public final class KeyProtection implements ProtectionParameter { * * <p>By default, the user needs to authenticate for every use of the key. * - * <p><b>NOTE: This has currently no effect on asymmetric key pairs.</b> - * * @param seconds duration in seconds or {@code -1} if the user needs to authenticate for * every use of the key. * diff --git a/keystore/java/android/security/keystore/KeymasterUtils.java b/keystore/java/android/security/keystore/KeymasterUtils.java index 0639d49ba22a..4b37d905edc5 100644 --- a/keystore/java/android/security/keystore/KeymasterUtils.java +++ b/keystore/java/android/security/keystore/KeymasterUtils.java @@ -101,13 +101,10 @@ public abstract class KeymasterUtils { // fingerprint-only auth. FingerprintManager fingerprintManager = KeyStore.getApplicationContext().getSystemService(FingerprintManager.class); - if ((fingerprintManager == null) || (!fingerprintManager.isHardwareDetected())) { - throw new IllegalStateException( - "This device does not support keys which require authentication for every" - + " use -- this requires fingerprint authentication which is not" - + " available on this device"); - } - long fingerprintOnlySid = fingerprintManager.getAuthenticatorId(); + // TODO: Restore USE_FINGERPRINT permission check in + // FingerprintManager.getAuthenticatorId once the ID is no longer needed here. + long fingerprintOnlySid = + (fingerprintManager != null) ? fingerprintManager.getAuthenticatorId() : 0; if (fingerprintOnlySid == 0) { throw new IllegalStateException( "At least one fingerprint must be enrolled to create keys requiring user" diff --git a/keystore/tests/src/android/security/KeyStoreTest.java b/keystore/tests/src/android/security/KeyStoreTest.java index 44fb826d3a03..0b60c625f509 100644 --- a/keystore/tests/src/android/security/KeyStoreTest.java +++ b/keystore/tests/src/android/security/KeyStoreTest.java @@ -20,7 +20,6 @@ import android.app.Activity; import android.os.Binder; import android.os.IBinder; import android.os.Process; -import android.os.ServiceManager; import android.security.keymaster.ExportResult; import android.security.keymaster.KeyCharacteristics; import android.security.keymaster.KeymasterArguments; @@ -34,13 +33,9 @@ import android.test.suitebuilder.annotation.MediumTest; import com.android.org.conscrypt.NativeConstants; import java.nio.charset.StandardCharsets; import java.util.Arrays; -import java.util.Date; import java.util.HashSet; import java.security.spec.RSAKeyGenParameterSpec; -import android.util.Log; -import android.util.Base64; - /** * Junit / Instrumentation test case for KeyStore class * diff --git a/keystore/tests/src/android/security/keystore/AndroidKeyPairGeneratorTest.java b/keystore/tests/src/android/security/keystore/AndroidKeyPairGeneratorTest.java index 8488acd96398..e5c15c50377b 100644 --- a/keystore/tests/src/android/security/keystore/AndroidKeyPairGeneratorTest.java +++ b/keystore/tests/src/android/security/keystore/AndroidKeyPairGeneratorTest.java @@ -26,17 +26,21 @@ import android.test.AndroidTestCase; import java.io.ByteArrayInputStream; import java.math.BigInteger; import java.security.KeyPair; +import java.security.KeyPairGenerator; import java.security.PrivateKey; import java.security.PublicKey; import java.security.SecureRandom; import java.security.cert.Certificate; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; +import java.security.interfaces.ECKey; import java.security.interfaces.ECPublicKey; +import java.security.interfaces.RSAKey; import java.security.interfaces.RSAPublicKey; import java.security.spec.AlgorithmParameterSpec; import java.security.spec.RSAKeyGenParameterSpec; import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.Date; import javax.security.auth.x500.X500Principal; @@ -158,6 +162,26 @@ public class AndroidKeyPairGeneratorTest extends AndroidTestCase { } public void testKeyPairGenerator_GenerateKeyPair_EC_Unencrypted_Success() throws Exception { + KeyPairGenerator generator = KeyPairGenerator.getInstance("EC", "AndroidKeyStore"); + generator.initialize(new KeyGenParameterSpec.Builder( + TEST_ALIAS_1, + KeyProperties.PURPOSE_SIGN | KeyProperties.PURPOSE_VERIFY) + .setCertificateSubject(TEST_DN_1) + .setCertificateSerialNumber(TEST_SERIAL_1) + .setCertificateNotBefore(NOW) + .setCertificateNotAfter(NOW_PLUS_10_YEARS) + .setDigests(KeyProperties.DIGEST_SHA256) + .build()); + + final KeyPair pair = generator.generateKeyPair(); + assertNotNull("The KeyPair returned should not be null", pair); + + assertKeyPairCorrect(pair, TEST_ALIAS_1, "EC", 256, null, TEST_DN_1, TEST_SERIAL_1, NOW, + NOW_PLUS_10_YEARS); + } + + public void testKeyPairGenerator_Legacy_GenerateKeyPair_EC_Unencrypted_Success() + throws Exception { mGenerator.initialize(new KeyPairGeneratorSpec.Builder(getContext()) .setAlias(TEST_ALIAS_1) .setKeyType("EC") @@ -328,19 +352,40 @@ public class AndroidKeyPairGeneratorTest extends AndroidTestCase { assertNotNull("The PrivateKey for the KeyPair should be not null", privKey); assertEquals(keyType, privKey.getAlgorithm()); + if ("EC".equalsIgnoreCase(keyType)) { + assertTrue("EC private key must be instanceof ECKey: " + privKey.getClass().getName(), + privKey instanceof ECKey); + assertEquals("Private and public key must have the same EC parameters", + ((ECKey) pubKey).getParams(), ((ECKey) privKey).getParams()); + } else if ("RSA".equalsIgnoreCase(keyType)) { + assertTrue("RSA private key must be instance of RSAKey: " + + privKey.getClass().getName(), + privKey instanceof RSAKey); + assertEquals("Private and public key must have the same RSA modulus", + ((RSAKey) pubKey).getModulus(), ((RSAKey) privKey).getModulus()); + } + final byte[] userCertBytes = mAndroidKeyStore.get(Credentials.USER_CERTIFICATE + alias); assertNotNull("The user certificate should exist for the generated entry", userCertBytes); final CertificateFactory cf = CertificateFactory.getInstance("X.509"); - final Certificate userCert = cf - .generateCertificate(new ByteArrayInputStream(userCertBytes)); + final Certificate userCert = + cf.generateCertificate(new ByteArrayInputStream(userCertBytes)); assertTrue("Certificate should be in X.509 format", userCert instanceof X509Certificate); final X509Certificate x509userCert = (X509Certificate) userCert; + assertEquals( + "Public key used to sign certificate should have the same algorithm as in KeyPair", + pubKey.getAlgorithm(), x509userCert.getPublicKey().getAlgorithm()); + assertEquals("PublicKey used to sign certificate should match one returned in KeyPair", - pubKey, x509userCert.getPublicKey()); + pubKey, + AndroidKeyStoreProvider.getAndroidKeyStorePublicKey( + Credentials.USER_PRIVATE_KEY + alias, + x509userCert.getPublicKey().getAlgorithm(), + x509userCert.getPublicKey().getEncoded())); assertEquals("The Subject DN should be the one passed into the params", dn, x509userCert.getSubjectDN()); @@ -357,7 +402,10 @@ public class AndroidKeyPairGeneratorTest extends AndroidTestCase { assertDateEquals("The notAfter date should be the one passed into the params", end, x509userCert.getNotAfter()); + // Assert that the cert's signature verifies using the public key from generated KeyPair x509userCert.verify(pubKey); + // Assert that the cert's signature verifies using the public key from the cert itself. + x509userCert.verify(x509userCert.getPublicKey()); final byte[] caCerts = mAndroidKeyStore.get(Credentials.CA_CERTIFICATE + alias); assertNull("A list of CA certificates should not exist for the generated entry", caCerts); @@ -368,6 +416,8 @@ public class AndroidKeyPairGeneratorTest extends AndroidTestCase { final byte[] pubKeyBytes = exportResult.exportData; assertNotNull("The keystore should return the public key for the generated key", pubKeyBytes); + assertTrue("Public key X.509 format should be as expected", + Arrays.equals(pubKey.getEncoded(), pubKeyBytes)); } private static void assertDateEquals(String message, Date date1, Date date2) throws Exception { diff --git a/keystore/tests/src/android/security/keystore/AndroidKeyStoreTest.java b/keystore/tests/src/android/security/keystore/AndroidKeyStoreTest.java index 336fa402e35f..c3b731b19010 100644 --- a/keystore/tests/src/android/security/keystore/AndroidKeyStoreTest.java +++ b/keystore/tests/src/android/security/keystore/AndroidKeyStoreTest.java @@ -19,38 +19,31 @@ package android.security.keystore; import com.android.org.bouncycastle.x509.X509V3CertificateGenerator; import com.android.org.conscrypt.NativeConstants; -import com.android.org.conscrypt.OpenSSLEngine; import android.security.Credentials; import android.security.KeyStore; import android.security.KeyStoreParameter; -import android.security.keymaster.ExportResult; -import android.security.keymaster.KeymasterDefs; import android.test.AndroidTestCase; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.OutputStream; import java.math.BigInteger; -import java.security.InvalidKeyException; import java.security.Key; import java.security.KeyFactory; +import java.security.KeyPair; import java.security.KeyStore.Entry; import java.security.KeyStore.PrivateKeyEntry; import java.security.KeyStore.TrustedCertificateEntry; import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.PublicKey; import java.security.cert.Certificate; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; -import java.security.interfaces.ECPrivateKey; -import java.security.interfaces.ECPublicKey; -import java.security.interfaces.RSAPrivateKey; -import java.security.spec.InvalidKeySpecException; +import java.security.interfaces.ECKey; +import java.security.interfaces.RSAKey; import java.security.spec.PKCS8EncodedKeySpec; -import java.security.spec.X509EncodedKeySpec; import java.util.Arrays; import java.util.Collection; import java.util.Date; @@ -1203,14 +1196,14 @@ public class AndroidKeyStoreTest extends AndroidTestCase { private void assertPrivateKeyEntryEquals(PrivateKeyEntry keyEntry, PrivateKey expectedKey, Certificate expectedCert, Collection<Certificate> expectedChain) throws Exception { - if (expectedKey instanceof ECPrivateKey) { + if (expectedKey instanceof ECKey) { assertEquals("Returned PrivateKey should be what we inserted", - ((ECPrivateKey) expectedKey).getParams().getCurve(), - ((ECPublicKey) keyEntry.getCertificate().getPublicKey()).getParams().getCurve()); - } else if (expectedKey instanceof RSAPrivateKey) { + ((ECKey) expectedKey).getParams().getCurve(), + ((ECKey) keyEntry.getCertificate().getPublicKey()).getParams().getCurve()); + } else if (expectedKey instanceof RSAKey) { assertEquals("Returned PrivateKey should be what we inserted", - ((RSAPrivateKey) expectedKey).getModulus(), - ((RSAPrivateKey) keyEntry.getPrivateKey()).getModulus()); + ((RSAKey) expectedKey).getModulus(), + ((RSAKey) keyEntry.getPrivateKey()).getModulus()); } assertEquals("Returned Certificate should be what we inserted", expectedCert, @@ -1263,15 +1256,14 @@ public class AndroidKeyStoreTest extends AndroidTestCase { Key key = mKeyStore.getKey(TEST_ALIAS_1, null); assertNotNull("Key should exist", key); - assertTrue("Should be a RSAPrivateKey", key instanceof RSAPrivateKey); - - RSAPrivateKey actualKey = (RSAPrivateKey) key; + assertTrue("Should be a PrivateKey", key instanceof PrivateKey); + assertTrue("Should be a RSAKey", key instanceof RSAKey); KeyFactory keyFact = KeyFactory.getInstance("RSA"); PrivateKey expectedKey = keyFact.generatePrivate(new PKCS8EncodedKeySpec(FAKE_RSA_KEY_1)); assertEquals("Inserted key should be same as retrieved key", - ((RSAPrivateKey) expectedKey).getModulus(), actualKey.getModulus()); + ((RSAKey) expectedKey).getModulus(), ((RSAKey) key).getModulus()); } public void testKeyStore_GetKey_NoPassword_Unencrypted_Success() throws Exception { @@ -1287,15 +1279,14 @@ public class AndroidKeyStoreTest extends AndroidTestCase { Key key = mKeyStore.getKey(TEST_ALIAS_1, null); assertNotNull("Key should exist", key); - assertTrue("Should be a RSAPrivateKey", key instanceof RSAPrivateKey); - - RSAPrivateKey actualKey = (RSAPrivateKey) key; + assertTrue("Should be a PrivateKey", key instanceof PrivateKey); + assertTrue("Should be a RSAKey", key instanceof RSAKey); KeyFactory keyFact = KeyFactory.getInstance("RSA"); PrivateKey expectedKey = keyFact.generatePrivate(new PKCS8EncodedKeySpec(FAKE_RSA_KEY_1)); assertEquals("Inserted key should be same as retrieved key", - ((RSAPrivateKey) expectedKey).getModulus(), actualKey.getModulus()); + ((RSAKey) expectedKey).getModulus(), ((RSAKey) key).getModulus()); } public void testKeyStore_GetKey_Certificate_Encrypted_Failure() throws Exception { @@ -1926,31 +1917,11 @@ public class AndroidKeyStoreTest extends AndroidTestCase { Date notAfter) throws Exception { final String privateKeyAlias = Credentials.USER_PRIVATE_KEY + alias; - final PrivateKey privKey; - final OpenSSLEngine engine = OpenSSLEngine.getInstance("keystore"); - try { - privKey = engine.getPrivateKeyById(privateKeyAlias); - } catch (InvalidKeyException e) { - throw new RuntimeException("Can't get key", e); - } - - ExportResult exportResult = - keyStore.exportKey(privateKeyAlias, KeymasterDefs.KM_KEY_FORMAT_X509, null, null); - assertEquals(KeyStore.NO_ERROR, exportResult.resultCode); - final byte[] pubKeyBytes = exportResult.exportData; - - final PublicKey pubKey; - try { - final KeyFactory keyFact = KeyFactory.getInstance("RSA"); - pubKey = keyFact.generatePublic(new X509EncodedKeySpec(pubKeyBytes)); - } catch (NoSuchAlgorithmException e) { - throw new IllegalStateException("Can't instantiate RSA key generator", e); - } catch (InvalidKeySpecException e) { - throw new IllegalStateException("keystore returned invalid key encoding", e); - } + KeyPair keyPair = AndroidKeyStoreProvider.loadAndroidKeyStoreKeyPairFromKeystore( + keyStore, privateKeyAlias); final X509V3CertificateGenerator certGen = new X509V3CertificateGenerator(); - certGen.setPublicKey(pubKey); + certGen.setPublicKey(keyPair.getPublic()); certGen.setSerialNumber(serialNumber); certGen.setSubjectDN(subjectDN); certGen.setIssuerDN(subjectDN); @@ -1958,7 +1929,7 @@ public class AndroidKeyStoreTest extends AndroidTestCase { certGen.setNotAfter(notAfter); certGen.setSignatureAlgorithm("sha1WithRSA"); - final X509Certificate cert = certGen.generate(privKey); + final X509Certificate cert = certGen.generate(keyPair.getPrivate()); return cert; } diff --git a/media/jni/android_media_ImageReader.cpp b/media/jni/android_media_ImageReader.cpp index 49614bdc76fd..635fa11c6b44 100644 --- a/media/jni/android_media_ImageReader.cpp +++ b/media/jni/android_media_ImageReader.cpp @@ -72,6 +72,12 @@ static struct { jmethodID ctor; } gSurfacePlaneClassInfo; +// Get an ID that's unique within this process. +static int32_t createProcessUniqueId() { + static volatile int32_t globalCounter = 0; + return android_atomic_inc(&globalCounter); +} + // ---------------------------------------------------------------------------- class JNIImageReaderContext : public ConsumerBase::FrameAvailableListener @@ -808,6 +814,9 @@ static void ImageReader_init(JNIEnv* env, jobject thiz, jobject weakThiz, sp<ConsumerBase> consumer; sp<CpuConsumer> cpuConsumer; sp<BufferItemConsumer> opaqueConsumer; + String8 consumerName = String8::format("ImageReader-%dx%df%xm%d-%d-%d", + width, height, format, maxImages, getpid(), + createProcessUniqueId()); if (isFormatOpaque(nativeFormat)) { // Use the SW_READ_NEVER usage to tell producer that this format is not for preview or video // encoding. The only possibility will be ZSL output. @@ -819,6 +828,7 @@ static void ImageReader_init(JNIEnv* env, jobject thiz, jobject weakThiz, return; } ctx->setOpaqueConsumer(opaqueConsumer); + opaqueConsumer->setName(consumerName); consumer = opaqueConsumer; } else { cpuConsumer = new CpuConsumer(gbConsumer, maxImages, /*controlledByApp*/true); @@ -828,6 +838,7 @@ static void ImageReader_init(JNIEnv* env, jobject thiz, jobject weakThiz, return; } ctx->setCpuConsumer(cpuConsumer); + cpuConsumer->setName(consumerName); consumer = cpuConsumer; } diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CodecTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CodecTest.java index bcfcbf30a010..8f7d6ac312b8 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CodecTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CodecTest.java @@ -60,6 +60,7 @@ public class CodecTest { private static boolean onPrepareSuccess = false; public static boolean onCompleteSuccess = false; public static boolean mPlaybackError = false; + public static boolean mFailedToCompleteWithNoError = true; public static int mMediaInfoUnknownCount = 0; public static int mMediaInfoVideoTrackLaggingCount = 0; public static int mMediaInfoBadInterleavingCount = 0; @@ -801,6 +802,7 @@ public class CodecTest { mMediaInfoNotSeekableCount = 0; mMediaInfoMetdataUpdateCount = 0; mPlaybackError = false; + mFailedToCompleteWithNoError = true; String testResult; initializeMessageLooper(); @@ -843,6 +845,9 @@ public class CodecTest { } catch (Exception e) { Log.v(TAG, "playMediaSamples:" + e.getMessage()); } + // Check if playback state is unknown (neither completed nor erroneous) unless + // it's not interrupted in the middle. If true, that is an exceptional case to investigate. + mFailedToCompleteWithNoError = !(onCompleteSuccess || mPlaybackError); return onCompleteSuccess; } } diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaPlayerStressTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaPlayerStressTest.java index e28981297723..4221f1bad30c 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaPlayerStressTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaPlayerStressTest.java @@ -65,6 +65,7 @@ public class MediaPlayerStressTest extends ActivityInstrumentationTestCase2<Medi private int mTotalBadInterleaving = 0; private int mTotalNotSeekable = 0; private int mTotalMetaDataUpdate = 0; + private int mTotalFailedToCompleteWithNoError = 0; //Test result output file private static final String PLAYBACK_RESULT = "PlaybackTestResult.txt"; @@ -78,6 +79,8 @@ public class MediaPlayerStressTest extends ActivityInstrumentationTestCase2<Medi output.write(" Bad Interleaving: " + CodecTest.mMediaInfoBadInterleavingCount); output.write(" Not Seekable: " + CodecTest.mMediaInfoNotSeekableCount); output.write(" Info Meta data update: " + CodecTest.mMediaInfoMetdataUpdateCount); + output.write(" Failed To Complete With No Error: " + + CodecTest.mFailedToCompleteWithNoError); output.write("\n"); } @@ -90,16 +93,21 @@ public class MediaPlayerStressTest extends ActivityInstrumentationTestCase2<Medi output.write("Total Bad Interleaving: " + mTotalBadInterleaving + "\n"); output.write("Total Not Seekable: " + mTotalNotSeekable + "\n"); output.write("Total Info Meta data update: " + mTotalMetaDataUpdate + "\n"); + output.write("Total Failed To Complete With No Error: " + + mTotalFailedToCompleteWithNoError); output.write("\n"); } private void updateTestResult(){ - if (CodecTest.onCompleteSuccess){ + if (CodecTest.onCompleteSuccess) { mTotalComplete++; } - else if (CodecTest.mPlaybackError){ + else if (CodecTest.mPlaybackError) { mTotalPlaybackError++; } + else if (CodecTest.mFailedToCompleteWithNoError) { + mTotalFailedToCompleteWithNoError++; + } mTotalInfoUnknown += CodecTest.mMediaInfoUnknownCount; mTotalVideoTrackLagging += CodecTest.mMediaInfoVideoTrackLaggingCount; mTotalBadInterleaving += CodecTest.mMediaInfoBadInterleavingCount; @@ -149,4 +157,4 @@ public class MediaPlayerStressTest extends ActivityInstrumentationTestCase2<Medi assertTrue("testMediaSamples", testResult); } } -}
\ No newline at end of file +} diff --git a/packages/DocumentsUI/res/values/strings.xml b/packages/DocumentsUI/res/values/strings.xml index 943104d2e094..a4e6ce78f523 100644 --- a/packages/DocumentsUI/res/values/strings.xml +++ b/packages/DocumentsUI/res/values/strings.xml @@ -68,9 +68,6 @@ <!-- Button label that copies files to the current directory [CHAR LIMIT=24] --> <string name="button_copy">Copy</string> - <!-- Action mode title summarizing the number of documents selected [CHAR LIMIT=32] --> - <string name="mode_selected_count"><xliff:g id="count" example="3">%1$d</xliff:g> selected</string> - <!-- Mode that sorts documents by their display name alphabetically [CHAR LIMIT=24] --> <string name="sort_name">By name</string> <!-- Mode that sorts documents by their last modified time in descending order; most recent first [CHAR LIMIT=24] --> diff --git a/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java b/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java index a789da86badd..f4be9c5252b7 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java +++ b/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java @@ -54,6 +54,7 @@ import android.os.OperationCanceledException; import android.os.Parcelable; import android.provider.DocumentsContract; import android.provider.DocumentsContract.Document; +import android.text.TextUtils; import android.text.format.DateUtils; import android.text.format.Formatter; import android.text.format.Time; @@ -474,8 +475,7 @@ public class DirectoryFragment extends Fragment { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { mode.getMenuInflater().inflate(R.menu.mode_directory, menu); - mode.setTitle(getResources() - .getString(R.string.mode_selected_count, mCurrentView.getCheckedItemCount())); + mode.setTitle(TextUtils.formatSelectedCount(mCurrentView.getCheckedItemCount())); return true; } @@ -571,8 +571,7 @@ public class DirectoryFragment extends Fragment { } } - mode.setTitle(getResources() - .getString(R.string.mode_selected_count, mCurrentView.getCheckedItemCount())); + mode.setTitle(TextUtils.formatSelectedCount(mCurrentView.getCheckedItemCount())); } }; diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java index e6a89f143ffa..273f166888e6 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -117,6 +117,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { private static final int MSG_FINGERPRINT_AUTH_FAILED = 326; private static final int MSG_FACE_UNLOCK_STATE_CHANGED = 327; private static final int MSG_SIM_SUBSCRIPTION_INFO_CHANGED = 328; + private static final int MSG_AIRPLANE_MODE_CHANGED = 329; private static KeyguardUpdateMonitor sInstance; @@ -222,6 +223,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { case MSG_SIM_SUBSCRIPTION_INFO_CHANGED: handleSimSubscriptionInfoChanged(); break; + case MSG_AIRPLANE_MODE_CHANGED: + handleAirplaneModeChanged(); + break; } } }; @@ -305,6 +309,15 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } } + private void handleAirplaneModeChanged() { + for (int j = 0; j < mCallbacks.size(); j++) { + KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get(); + if (cb != null) { + cb.onRefreshCarrierInfo(); + } + } + } + /** @return List of SubscriptionInfo records, maybe empty but never null */ List<SubscriptionInfo> getSubscriptionInfo(boolean forceReload) { List<SubscriptionInfo> sil = mSubscriptionInfo; @@ -486,6 +499,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } else if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) { String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); mHandler.sendMessage(mHandler.obtainMessage(MSG_PHONE_STATE_CHANGED, state)); + } else if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) { + mHandler.sendEmptyMessage(MSG_AIRPLANE_MODE_CHANGED); } else if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { dispatchBootCompleted(); } @@ -721,6 +736,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { filter.addAction(Intent.ACTION_TIME_CHANGED); filter.addAction(Intent.ACTION_BATTERY_CHANGED); filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); + filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java index 4ba04e53db2a..3c5dae3eda36 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java +++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java @@ -679,6 +679,8 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat if (resolvedActivities.get(0).activityInfo.exported) { intent.putExtra(PrintService.EXTRA_PRINT_JOB_INFO, mPrintJob); intent.putExtra(PrintService.EXTRA_PRINTER_INFO, printer); + intent.putExtra(PrintService.EXTRA_PRINT_JOB_INFO, + mPrintedDocument.getDocumentInfo().info); // This is external activity and may not be there. try { diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java index 1dba942e5b36..5137e1be451b 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java @@ -516,7 +516,7 @@ public class SettingsProvider extends ContentProvider { } private void dumpSettings(Cursor cursor, PrintWriter pw) { - if (!cursor.moveToFirst()) { + if (cursor == null || !cursor.moveToFirst()) { return; } diff --git a/packages/StatementService/src/com/android/statementservice/retriever/AbstractStatementRetriever.java b/packages/StatementService/src/com/android/statementservice/retriever/AbstractStatementRetriever.java index 3b59fd6a5d83..fe9b99a0a976 100644 --- a/packages/StatementService/src/com/android/statementservice/retriever/AbstractStatementRetriever.java +++ b/packages/StatementService/src/com/android/statementservice/retriever/AbstractStatementRetriever.java @@ -90,7 +90,7 @@ public abstract class AbstractStatementRetriever { * Creates a new StatementRetriever that directly retrieves statements from the asset. * * <p> For web assets, {@link AbstractStatementRetriever} will try to retrieve the statement - * file from URL: {@code [webAsset.site]/.well-known/statements.json"} where {@code + * file from URL: {@code [webAsset.site]/.well-known/assetlinks.json"} where {@code * [webAsset.site]} is in the form {@code http{s}://[hostname]:[optional_port]}. The file * should contain one JSON array of statements. * diff --git a/packages/StatementService/src/com/android/statementservice/retriever/DirectStatementRetriever.java b/packages/StatementService/src/com/android/statementservice/retriever/DirectStatementRetriever.java index 2ca85e98d522..e4feb90339cb 100644 --- a/packages/StatementService/src/com/android/statementservice/retriever/DirectStatementRetriever.java +++ b/packages/StatementService/src/com/android/statementservice/retriever/DirectStatementRetriever.java @@ -38,7 +38,7 @@ import java.util.List; private static final int HTTP_CONNECTION_TIMEOUT_MILLIS = 5000; private static final long HTTP_CONTENT_SIZE_LIMIT_IN_BYTES = 1024 * 1024; private static final int MAX_INCLUDE_LEVEL = 1; - private static final String WELL_KNOWN_STATEMENT_PATH = "/.well-known/statements.json"; + private static final String WELL_KNOWN_STATEMENT_PATH = "/.well-known/assetlinks.json"; private final URLFetcher mUrlFetcher; private final AndroidPackageInfoFetcher mAndroidFetcher; diff --git a/packages/StatementService/src/com/android/statementservice/retriever/Statement.java b/packages/StatementService/src/com/android/statementservice/retriever/Statement.java index da3c3553d731..0f40a6221017 100644 --- a/packages/StatementService/src/com/android/statementservice/retriever/Statement.java +++ b/packages/StatementService/src/com/android/statementservice/retriever/Statement.java @@ -21,7 +21,7 @@ import android.annotation.NonNull; /** * An immutable value type representing a statement, consisting of a source, target, and relation. * This reflects an assertion that the relation holds for the source, target pair. For example, if a - * web site has the following in its statements.json file: + * web site has the following in its assetlinks.json file: * * <pre> * { diff --git a/packages/StatementService/src/com/android/statementservice/retriever/URLFetcher.java b/packages/StatementService/src/com/android/statementservice/retriever/URLFetcher.java index 969aa88f3cf7..225e26c06db2 100644 --- a/packages/StatementService/src/com/android/statementservice/retriever/URLFetcher.java +++ b/packages/StatementService/src/com/android/statementservice/retriever/URLFetcher.java @@ -60,33 +60,36 @@ public class URLFetcher { throw new IllegalArgumentException("The url protocol should be on http or https."); } - HttpURLConnection connection; - connection = (HttpURLConnection) url.openConnection(); - connection.setInstanceFollowRedirects(true); - connection.setConnectTimeout(connectionTimeoutMillis); - connection.setReadTimeout(connectionTimeoutMillis); - connection.setUseCaches(true); - connection.setInstanceFollowRedirects(false); - connection.addRequestProperty("Cache-Control", "max-stale=60"); - - if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { - Log.e(TAG, "The responses code is not 200 but " + connection.getResponseCode()); - return new WebContent("", DO_NOT_CACHE_RESULT); - } + HttpURLConnection connection = null; + try { + connection = (HttpURLConnection) url.openConnection(); + connection.setInstanceFollowRedirects(true); + connection.setConnectTimeout(connectionTimeoutMillis); + connection.setReadTimeout(connectionTimeoutMillis); + connection.setUseCaches(true); + connection.setInstanceFollowRedirects(false); + connection.addRequestProperty("Cache-Control", "max-stale=60"); + + if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { + Log.e(TAG, "The responses code is not 200 but " + connection.getResponseCode()); + return new WebContent("", DO_NOT_CACHE_RESULT); + } - if (connection.getContentLength() > fileSizeLimit) { - Log.e(TAG, "The content size of the url is larger than " + fileSizeLimit); - return new WebContent("", DO_NOT_CACHE_RESULT); - } + if (connection.getContentLength() > fileSizeLimit) { + Log.e(TAG, "The content size of the url is larger than " + fileSizeLimit); + return new WebContent("", DO_NOT_CACHE_RESULT); + } - Long expireTimeMillis = getExpirationTimeMillisFromHTTPHeader(connection.getHeaderFields()); + Long expireTimeMillis = getExpirationTimeMillisFromHTTPHeader( + connection.getHeaderFields()); - try { return new WebContent(inputStreamToString( connection.getInputStream(), connection.getContentLength(), fileSizeLimit), expireTimeMillis); } finally { - connection.disconnect(); + if (connection != null) { + connection.disconnect(); + } } } diff --git a/packages/SystemUI/res/drawable/managed_profile_toast_background.xml b/packages/SystemUI/res/drawable/managed_profile_toast_background.xml new file mode 100644 index 000000000000..5c77b9a1f660 --- /dev/null +++ b/packages/SystemUI/res/drawable/managed_profile_toast_background.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Copyright (C) 2015 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. +--> +<shape xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="rectangle"> + <corners android:radius="2dp" /> + <solid android:color="@color/managed_profile_toast_background" /> +</shape> diff --git a/packages/SystemUI/res/drawable/stat_sys_managed_profile_status.xml b/packages/SystemUI/res/drawable/stat_sys_managed_profile_status.xml index 3c4c6468d6a6..2bfa39d2392c 100644 --- a/packages/SystemUI/res/drawable/stat_sys_managed_profile_status.xml +++ b/packages/SystemUI/res/drawable/stat_sys_managed_profile_status.xml @@ -20,10 +20,10 @@ Copyright (C) 2015 The Android Open Source Project android:viewportHeight="17.0"> <group android:translateX="2.0"> <path - android:fillColor="#FF000000" + android:fillColor="@android:color/white" android:pathData="M9.9,11.6H7v-1.1H2.1v2.8c0,0.8,0.6,1.4,1.4,1.4h9.9c0.8,0,1.4,-0.6,1.4,-1.4v-2.8H9.9V11.6z"/> <path - android:fillColor="#FF000000" + android:fillColor="@android:color/white" android:pathData="M14.1,4.2h-2.5V3.2l-1.1,-1.1H6.3L5.3,3.2v1H2.8C2,4.2,1.4,4.9,1.4,5.6v2.8c0,0.8,0.6,1.4,1.4,1.4H7V8.8h2.8v1.1h4.2 c0.8,0,1.4,-0.6,1.4,-1.4V5.6C15.5,4.9,14.8,4.2,14.1,4.2z M10.6,4.2H6.3V3.2h4.2V4.2z"/> </group> </vector> diff --git a/packages/SystemUI/res/layout/managed_profile_toast.xml b/packages/SystemUI/res/layout/managed_profile_toast.xml new file mode 100644 index 000000000000..5a01ca7f16a6 --- /dev/null +++ b/packages/SystemUI/res/layout/managed_profile_toast.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2015 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. +--> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:paddingTop="16dp" + android:paddingBottom="16dp" + android:paddingLeft="32dp" + android:paddingRight="32dp" + android:background="@drawable/managed_profile_toast_background"> + <ImageView + android:layout_width="32dp" + android:layout_height="32dp" + android:layout_gravity="center_horizontal" + android:layout_marginBottom="16dp" + android:src="@drawable/stat_sys_managed_profile_status"/> + <TextView android:text="@string/managed_profile_foreground_toast" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textColor="@android:color/white" + android:textSize="14sp" + android:layout_gravity="center_horizontal" /> +</LinearLayout> diff --git a/packages/SystemUI/res/layout/quick_settings_brightness_dialog.xml b/packages/SystemUI/res/layout/quick_settings_brightness_dialog.xml index a9962607d696..38ea6e11c45f 100644 --- a/packages/SystemUI/res/layout/quick_settings_brightness_dialog.xml +++ b/packages/SystemUI/res/layout/quick_settings_brightness_dialog.xml @@ -35,6 +35,7 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1" + android:contentDescription="@string/accessibility_brightness" systemui:text="@string/status_bar_settings_auto_brightness_label" /> </LinearLayout> diff --git a/packages/SystemUI/res/layout/status_bar_toggle_slider.xml b/packages/SystemUI/res/layout/status_bar_toggle_slider.xml index a5bf68e286a4..062e6cb0334a 100644 --- a/packages/SystemUI/res/layout/status_bar_toggle_slider.xml +++ b/packages/SystemUI/res/layout/status_bar_toggle_slider.xml @@ -45,7 +45,6 @@ android:paddingBottom="16dp" android:thumb="@drawable/ic_brightness_thumb" android:splitTrack="false" - android:contentDescription="@string/accessibility_brightness" /> <TextView android:id="@+id/label" diff --git a/packages/SystemUI/res/values/colors.xml b/packages/SystemUI/res/values/colors.xml index 0dcbe884b30f..9a96939f700d 100644 --- a/packages/SystemUI/res/values/colors.xml +++ b/packages/SystemUI/res/values/colors.xml @@ -143,4 +143,6 @@ <color name="volume_icon_color">#ffffffff</color> <color name="volume_settings_icon_color">#7fffffff</color> <color name="volume_slider_inactive">#FFB0BEC5</color><!-- blue grey 200 --> + + <color name="managed_profile_toast_background">#E5000000</color><!-- 90% black --> </resources> diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index a2a2e5f0c63a..a0b70f01dd96 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -1012,7 +1012,7 @@ <string name="volumeui_notification_text">Touch to restore the original.</string> <!-- Toast shown when user unlocks screen and managed profile activity is in the foreground --> - <string name="managed_profile_foreground_toast">You are in the work profile</string> + <string name="managed_profile_foreground_toast">You\'re using your work profile</string> <string-array name="volume_stream_titles" translatable="false"> <item>Voice calls</item> <!-- STREAM_VOICE_CALL --> diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java index 49eb9b2ff53f..c8212c23f6d9 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java @@ -404,7 +404,9 @@ public class QSPanel extends ViewGroup { ((TileRecord) r).openingDetail = true; } } else { - MetricsLogger.hidden(mContext, mDetailRecord.detailAdapter.getMetricsCategory()); + if (mDetailRecord != null) { + MetricsLogger.hidden(mContext, mDetailRecord.detailAdapter.getMetricsCategory()); + } mClosingDetail = true; setGridContentVisibility(true); listener = mTeardownDetailWhenDone; diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/RotationLockTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/RotationLockTile.java index 7c378f08639a..915867ba6878 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/RotationLockTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/RotationLockTile.java @@ -73,6 +73,10 @@ public class RotationLockTile extends QSTile<QSTile.BooleanState> { : mController.isRotationLocked(); final boolean userInitiated = arg != null ? ((UserBoolean) arg).userInitiated : false; state.visible = mController.isRotationLockAffordanceVisible(); + if (state.value == rotationLocked) { + // No change, no need to update all the values. + return; + } state.value = rotationLocked; final boolean portrait = mContext.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE; diff --git a/packages/SystemUI/src/com/android/systemui/settings/ToggleSlider.java b/packages/SystemUI/src/com/android/systemui/settings/ToggleSlider.java index 8abfe033571a..cdb8e69eca03 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/ToggleSlider.java +++ b/packages/SystemUI/src/com/android/systemui/settings/ToggleSlider.java @@ -74,6 +74,8 @@ public class ToggleSlider extends RelativeLayout { mLabel = (TextView) findViewById(R.id.label); mLabel.setText(a.getString(R.styleable.ToggleSlider_text)); + setLabelFor(R.id.slider); // use our a11y text to annotate, not replace, the slider's + a.recycle(); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java index ef8c5db6a5ee..0b49564e5059 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java @@ -24,7 +24,6 @@ import android.app.ActivityManagerNative; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; -import android.app.RemoteInput; import android.app.TaskStackBuilder; import android.app.admin.DevicePolicyManager; import android.content.BroadcastReceiver; @@ -65,6 +64,7 @@ import android.util.Slog; import android.util.SparseArray; import android.util.SparseBooleanArray; import android.view.Display; +import android.view.Gravity; import android.view.IWindowManager; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -101,7 +101,6 @@ import com.android.systemui.statusbar.phone.NotificationGroupManager; import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; import com.android.systemui.statusbar.policy.HeadsUpManager; import com.android.systemui.statusbar.policy.PreviewInflater; -import com.android.systemui.statusbar.policy.RemoteInputView; import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; import java.util.ArrayList; @@ -121,8 +120,6 @@ public abstract class BaseStatusBar extends SystemUI implements // STOPSHIP disable once we resolve b/18102199 private static final boolean NOTIFICATION_CLICK_DEBUG = true; - public static final boolean ENABLE_REMOTE_INPUT = - Build.IS_DEBUGGABLE && SystemProperties.getBoolean("debug.enable_remote_input", false); public static final boolean ENABLE_CHILD_NOTIFICATIONS = Build.IS_DEBUGGABLE && SystemProperties.getBoolean("debug.child_notifs", false); @@ -395,8 +392,14 @@ public abstract class BaseStatusBar extends SystemUI implements if (recentTask != null && recentTask.size() > 0) { UserInfo user = mUserManager.getUserInfo(recentTask.get(0).userId); if (user != null && user.isManagedProfile()) { - Toast.makeText(mContext, R.string.managed_profile_foreground_toast, - Toast.LENGTH_SHORT).show(); + LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( + Context.LAYOUT_INFLATER_SERVICE); + View layout = inflater.inflate(R.layout.managed_profile_toast, null); + Toast toast = new Toast(mContext); + toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); + toast.setDuration(Toast.LENGTH_SHORT); + toast.setView(layout); + toast.show(); } } } else if (BANNER_ACTION_CANCEL.equals(action) || BANNER_ACTION_SETUP.equals(action)) { @@ -456,7 +459,7 @@ public abstract class BaseStatusBar extends SystemUI implements mHandler.post(new Runnable() { @Override public void run() { - processForRemoteInput(sbn.getNotification()); + String key = sbn.getKey(); boolean isUpdate = mNotificationData.get(key) != null; @@ -1307,9 +1310,6 @@ public abstract class BaseStatusBar extends SystemUI implements NotificationContentView contentContainerPublic = row.getPublicLayout(); row.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); - if (ENABLE_REMOTE_INPUT) { - row.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); - } mNotificationClicker.register(row, sbn); @@ -1472,104 +1472,8 @@ public abstract class BaseStatusBar extends SystemUI implements } row.setUserLocked(userLocked); row.setStatusBarNotification(entry.notification); - applyRemoteInput(entry); - return true; - } - - /** - * Adds RemoteInput actions from the WearableExtender; to be removed once more apps support this - * via first-class API. - * - * TODO: Remove once enough apps specify remote inputs on their own. - */ - private void processForRemoteInput(Notification n) { - if (!ENABLE_REMOTE_INPUT) return; - - if (n.extras != null && n.extras.containsKey("android.wearable.EXTENSIONS") && - (n.actions == null || n.actions.length == 0)) { - Notification.Action viableAction = null; - Notification.WearableExtender we = new Notification.WearableExtender(n); - - List<Notification.Action> actions = we.getActions(); - final int numActions = actions.size(); - - for (int i = 0; i < numActions; i++) { - Notification.Action action = actions.get(i); - RemoteInput[] remoteInputs = action.getRemoteInputs(); - for (RemoteInput ri : action.getRemoteInputs()) { - if (ri.getAllowFreeFormInput()) { - viableAction = action; - break; - } - } - if (viableAction != null) { - break; - } - } - - if (viableAction != null) { - Notification stripped = n.clone(); - Notification.Builder.stripForDelivery(stripped); - stripped.actions = new Notification.Action[] { viableAction }; - stripped.extras.putBoolean("android.rebuild.contentView", true); - stripped.contentView = null; - stripped.extras.putBoolean("android.rebuild.bigView", true); - stripped.bigContentView = null; - stripped.extras.putBoolean("android.rebuild.hudView", true); - stripped.headsUpContentView = null; - - Notification rebuilt = Notification.Builder.rebuild(mContext, stripped); - - n.actions = rebuilt.actions; - n.bigContentView = rebuilt.bigContentView; - n.headsUpContentView = rebuilt.headsUpContentView; - n.publicVersion = rebuilt.publicVersion; - } - } - } - - private void applyRemoteInput(final Entry entry) { - if (!ENABLE_REMOTE_INPUT) return; - RemoteInput remoteInput = null; - - // See if the notification has exactly one action and this action allows free-form input - // TODO: relax restrictions once we support more than one remote input action. - Notification.Action[] actions = entry.notification.getNotification().actions; - if (actions != null && actions.length == 1) { - if (actions[0].getRemoteInputs() != null) { - for (RemoteInput ri : actions[0].getRemoteInputs()) { - if (ri.getAllowFreeFormInput()) { - remoteInput = ri; - break; - } - } - } - } - - // See if we have somewhere to put that remote input - if (remoteInput != null) { - View bigContentView = entry.getExpandedContentView(); - if (bigContentView != null) { - inflateRemoteInput(bigContentView, remoteInput, actions); - } - View headsUpContentView = entry.getHeadsUpContentView(); - if (headsUpContentView != null) { - inflateRemoteInput(headsUpContentView, remoteInput, actions); - } - } - - } - - private void inflateRemoteInput(View view, RemoteInput remoteInput, - Notification.Action[] actions) { - View actionContainerCandidate = view.findViewById(com.android.internal.R.id.actions); - if (actionContainerCandidate instanceof ViewGroup) { - ViewGroup actionContainer = (ViewGroup) actionContainerCandidate; - actionContainer.removeAllViews(); - actionContainer.addView( - RemoteInputView.inflate(mContext, actionContainer, actions[0], remoteInput)); - } + return true; } private final class NotificationClicker implements View.OnClickListener { @@ -2065,8 +1969,6 @@ public abstract class BaseStatusBar extends SystemUI implements entry.row.setStatusBarNotification(notification); entry.row.notifyContentUpdated(); entry.row.resetHeight(); - - applyRemoteInput(entry); } protected void notifyHeadsUpScreenOff() { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableView.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableView.java index 03d048272f46..08a66037e620 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableView.java @@ -134,6 +134,14 @@ public abstract class ExpandableView extends FrameLayout { } @Override + public boolean dispatchGenericMotionEvent(MotionEvent ev) { + if (filterMotionEvent(ev)) { + return super.dispatchGenericMotionEvent(ev); + } + return false; + } + + @Override public boolean dispatchTouchEvent(MotionEvent ev) { if (filterMotionEvent(ev)) { return super.dispatchTouchEvent(ev); @@ -143,6 +151,8 @@ public abstract class ExpandableView extends FrameLayout { protected boolean filterMotionEvent(MotionEvent event) { return event.getActionMasked() != MotionEvent.ACTION_DOWN + && event.getActionMasked() != MotionEvent.ACTION_HOVER_ENTER + && event.getActionMasked() != MotionEvent.ACTION_HOVER_MOVE || event.getY() > mClipTopAmount && event.getY() < mActualHeight; } @@ -343,7 +353,8 @@ public abstract class ExpandableView extends FrameLayout { @Override public void getBoundsOnScreen(Rect outRect, boolean clipToParent) { super.getBoundsOnScreen(outRect, clipToParent); - outRect.bottom = (int) (outRect.top + getActualHeight()); + outRect.bottom = outRect.top + getActualHeight(); + outRect.top += getClipTopOptimization(); } public int getContentHeight() { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java index 58017d07100b..0d816dd1b6a1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java @@ -119,8 +119,7 @@ public class StatusBarWindowManager { private void applyFocusableFlag(State state) { boolean panelFocusable = state.statusBarFocusable && state.panelExpanded; - if (state.keyguardShowing && state.keyguardNeedsInput && state.bouncerShowing - || BaseStatusBar.ENABLE_REMOTE_INPUT && panelFocusable) { + if (state.keyguardShowing && state.keyguardNeedsInput && state.bouncerShowing) { mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; } else if (state.isKeyguardShowingAndNotOccluded() || panelFocusable) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java index 7f1fea1624d0..634270c12651 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java @@ -83,6 +83,10 @@ public class StatusBarWindowView extends FrameLayout { insets.top = 0; insets.right = 0; } else { + if (mRightInset != 0) { + mRightInset = 0; + applyMargins(); + } boolean changed = getPaddingLeft() != 0 || getPaddingRight() != 0 || getPaddingTop() != 0 diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialog.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialog.java index 49278c56b012..aa891b6faf67 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialog.java +++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialog.java @@ -17,6 +17,7 @@ package com.android.systemui.volume; import static android.accessibilityservice.AccessibilityServiceInfo.FEEDBACK_ALL_MASK; +import static android.accessibilityservice.AccessibilityServiceInfo.FEEDBACK_GENERIC; import android.accessibilityservice.AccessibilityServiceInfo; import android.animation.LayoutTransition; @@ -422,17 +423,15 @@ public class VolumeDialog { protected void rescheduleTimeoutH() { mHandler.removeMessages(H.DISMISS); - int timeout = -1; - if (!mAccessibility.mFeedbackEnabled) { - timeout = computeTimeoutH(); - mHandler.sendMessageDelayed(mHandler - .obtainMessage(H.DISMISS, Events.DISMISS_REASON_TIMEOUT, 0), timeout); - } + final int timeout = computeTimeoutH(); + mHandler.sendMessageDelayed(mHandler + .obtainMessage(H.DISMISS, Events.DISMISS_REASON_TIMEOUT, 0), timeout); if (D.BUG) Log.d(TAG, "rescheduleTimeout " + timeout + " " + Debug.getCaller()); mController.userActivity(); } private int computeTimeoutH() { + if (mAccessibility.mFeedbackEnabled) return 20000; if (mSafetyWarning != null) return 5000; if (mExpanded || mExpanding) return 5000; if (mActiveStream == AudioManager.STREAM_MUSIC) return 1500; @@ -959,7 +958,7 @@ public class VolumeDialog { } } - private final class Accessibility { + private final class Accessibility extends AccessibilityDelegate { private AccessibilityManager mMgr; private boolean mFeedbackEnabled; @@ -976,14 +975,7 @@ public class VolumeDialog { updateFeedbackEnabled(); } }); - mDialogView.setAccessibilityDelegate(new AccessibilityDelegate() { - @Override - public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, - AccessibilityEvent event) { - rescheduleTimeoutH(); - return super.onRequestSendAccessibilityEvent(host, child, event); - } - }); + mDialogView.setAccessibilityDelegate(this); mMgr.addAccessibilityStateChangeListener(new AccessibilityStateChangeListener() { @Override public void onAccessibilityStateChanged(boolean enabled) { @@ -993,15 +985,23 @@ public class VolumeDialog { updateFeedbackEnabled(); } + @Override + public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, + AccessibilityEvent event) { + rescheduleTimeoutH(); + return super.onRequestSendAccessibilityEvent(host, child, event); + } + private void updateFeedbackEnabled() { mFeedbackEnabled = computeFeedbackEnabled(); } private boolean computeFeedbackEnabled() { + // are there any enabled non-generic a11y services? final List<AccessibilityServiceInfo> services = mMgr.getEnabledAccessibilityServiceList(FEEDBACK_ALL_MASK); for (AccessibilityServiceInfo asi : services) { - if ((asi.feedbackType & FEEDBACK_ALL_MASK) != 0) { + if (asi.feedbackType != 0 && asi.feedbackType != FEEDBACK_GENERIC) { return true; } } diff --git a/services/core/java/com/android/server/DeviceIdleController.java b/services/core/java/com/android/server/DeviceIdleController.java index 4c7b52362a01..ad34b370e846 100644 --- a/services/core/java/com/android/server/DeviceIdleController.java +++ b/services/core/java/com/android/server/DeviceIdleController.java @@ -22,6 +22,7 @@ import android.app.AlarmManager; import android.app.AppGlobals; import android.app.PendingIntent; import android.content.BroadcastReceiver; +import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; @@ -29,12 +30,14 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; +import android.database.ContentObserver; import android.hardware.Sensor; import android.hardware.SensorManager; import android.hardware.TriggerEvent; import android.hardware.TriggerEventListener; import android.hardware.display.DisplayManager; import android.net.INetworkPolicyManager; +import android.net.Uri; import android.os.Binder; import android.os.Environment; import android.os.FileUtils; @@ -48,11 +51,11 @@ import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemClock; import android.os.UserHandle; +import android.provider.Settings; import android.util.ArrayMap; import android.util.ArraySet; -import android.util.Log; +import android.util.KeyValueListParser; import android.util.Slog; -import android.util.SparseArray; import android.util.SparseBooleanArray; import android.util.SparseLongArray; import android.util.TimeUtils; @@ -62,7 +65,6 @@ import android.view.Display; import com.android.internal.app.IBatteryStats; import com.android.internal.os.AtomicFile; import com.android.internal.os.BackgroundThread; -import com.android.internal.util.ArrayUtils; import com.android.internal.util.FastXmlSerializer; import com.android.internal.util.XmlUtils; import com.android.server.am.BatteryStatsService; @@ -103,84 +105,7 @@ public class DeviceIdleController extends SystemService // TODO: These need to be moved to system settings. - /** - * This is the time, after becoming inactive, at which we start looking at the - * motion sensor to determine if the device is being left alone. We don't do this - * immediately after going inactive just because we don't want to be continually running - * the significant motion sensor whenever the screen is off. - */ - - private static final long DEFAULT_INACTIVE_TIMEOUT = !COMPRESS_TIME ? 30*60*1000L - : 3 * 60 * 1000L; - - /** - * If we don't receive a callback from AnyMotion in this amount of time, we will change from - * STATE_SENSING to STATE_INACTIVE, and any AnyMotion callbacks while not in STATE_SENSING will - * be ignored. - */ - private static final long DEFAULT_SENSING_TIMEOUT = !DEBUG ? 5 * 60 * 1000L : 60 * 1000L; - - /** - * This is the time, after seeing motion, that we wait after becoming inactive from - * that until we start looking for motion again. - */ - private static final long DEFAULT_MOTION_INACTIVE_TIMEOUT = !COMPRESS_TIME ? 10*60*1000L - : 60 * 1000L; - - /** - * This is the time, after the inactive timeout elapses, that we will wait looking - * for significant motion until we truly consider the device to be idle. - */ - - private static final long DEFAULT_IDLE_AFTER_INACTIVE_TIMEOUT = !COMPRESS_TIME ? 30*60*1000L - : 3 * 60 * 1000L; - - /** - * This is the initial time, after being idle, that we will allow ourself to be back - * in the IDLE_PENDING state allowing the system to run normally until we return to idle. - */ - - private static final long DEFAULT_IDLE_PENDING_TIMEOUT = !COMPRESS_TIME ? 5*60*1000L - : 30 * 1000L; - - /** - * Maximum pending idle timeout (time spent running) we will be allowed to use. - */ - private static final long DEFAULT_MAX_IDLE_PENDING_TIMEOUT = !COMPRESS_TIME ? 10*60*1000L - : 60 * 1000L; - /** - * Scaling factor to apply to current pending idle timeout each time we cycle through - * that state. - */ - private static final float DEFAULT_IDLE_PENDING_FACTOR = 2f; - /** - * This is the initial time that we want to sit in the idle state before waking up - * again to return to pending idle and allowing normal work to run. - */ - - private static final long DEFAULT_IDLE_TIMEOUT = !COMPRESS_TIME ? 60*60*1000L - : 6 * 60 * 1000L; - - /** - * Maximum idle duration we will be allowed to use. - */ - private static final long DEFAULT_MAX_IDLE_TIMEOUT = !COMPRESS_TIME ? 6*60*60*1000L - : 30 * 60 * 1000L; - /** - * Scaling factor to apply to current idle timeout each time we cycle through that state. - */ - private static final float DEFAULT_IDLE_FACTOR = 2f; - /** - * This is the minimum time we will allow until the next upcoming alarm for us to - * actually go in to idle mode. - */ - private static final long DEFAULT_MIN_TIME_TO_ALARM = !COMPRESS_TIME ? 60*60*1000L - : 6 * 60 * 1000L; - /** - * Max amount of time to temporarily whitelist an app when it receives a high priority tickle. - */ - private static final long MAX_TEMP_APP_WHITELIST_DURATION = 5 * 60 * 1000L; private AlarmManager mAlarmManager; private IBatteryStats mBatteryStats; @@ -306,6 +231,230 @@ public class DeviceIdleController extends SystemService } }; + /** + * All times are in milliseconds. These constants are kept synchronized with the system + * global Settings. Any access to this class or its fields should be done while + * holding the DeviceIdleController lock. + */ + private class Constants extends ContentObserver { + // Key names stored in the settings value. + private static final String KEY_INACTIVE_TIMEOUT = "inactive_to"; + private static final String KEY_SENSING_TIMEOUT = "sensing_to"; + private static final String KEY_MOTION_INACTIVE_TIMEOUT = "motion_inactive_to"; + private static final String KEY_IDLE_AFTER_INACTIVE_TIMEOUT = "idle_after_inactive_to"; + private static final String KEY_IDLE_PENDING_TIMEOUT = "idle_pending_to"; + private static final String KEY_MAX_IDLE_PENDING_TIMEOUT = "max_idle_pending_to"; + private static final String KEY_IDLE_PENDING_FACTOR = "idle_pending_factor"; + private static final String KEY_IDLE_TIMEOUT = "idle_to"; + private static final String KEY_MAX_IDLE_TIMEOUT = "max_idle_to"; + private static final String KEY_IDLE_FACTOR = "idle_factor"; + private static final String KEY_MIN_TIME_TO_ALARM = "min_time_to_alarm"; + private static final String KEY_MAX_TEMP_APP_WHITELIST_DURATION = + "max_temp_app_whitelist_duration"; + + /** + * This is the time, after becoming inactive, at which we start looking at the + * motion sensor to determine if the device is being left alone. We don't do this + * immediately after going inactive just because we don't want to be continually running + * the significant motion sensor whenever the screen is off. + * @see Settings.Global#DEVICE_IDLE_CONSTANTS + * @see #KEY_INACTIVE_TIMEOUT + */ + public long INACTIVE_TIMEOUT; + + /** + * If we don't receive a callback from AnyMotion in this amount of time, we will change from + * STATE_SENSING to STATE_INACTIVE, and any AnyMotion callbacks while not in STATE_SENSING + * will be ignored. + * @see Settings.Global#DEVICE_IDLE_CONSTANTS + * @see #KEY_SENSING_TIMEOUT + */ + public long SENSING_TIMEOUT; + + /** + * This is the time, after seeing motion, that we wait after becoming inactive from + * that until we start looking for motion again. + * @see Settings.Global#DEVICE_IDLE_CONSTANTS + * @see #KEY_MOTION_INACTIVE_TIMEOUT + */ + public long MOTION_INACTIVE_TIMEOUT; + + /** + * This is the time, after the inactive timeout elapses, that we will wait looking + * for significant motion until we truly consider the device to be idle. + * @see Settings.Global#DEVICE_IDLE_CONSTANTS + * @see #KEY_IDLE_AFTER_INACTIVE_TIMEOUT + */ + public long IDLE_AFTER_INACTIVE_TIMEOUT; + + /** + * This is the initial time, after being idle, that we will allow ourself to be back + * in the IDLE_PENDING state allowing the system to run normally until we return to idle. + * @see Settings.Global#DEVICE_IDLE_CONSTANTS + * @see #KEY_IDLE_PENDING_TIMEOUT + */ + public long IDLE_PENDING_TIMEOUT; + + /** + * Maximum pending idle timeout (time spent running) we will be allowed to use. + * @see Settings.Global#DEVICE_IDLE_CONSTANTS + * @see #KEY_MAX_IDLE_PENDING_TIMEOUT + */ + public long MAX_IDLE_PENDING_TIMEOUT; + + /** + * Scaling factor to apply to current pending idle timeout each time we cycle through + * that state. + * @see Settings.Global#DEVICE_IDLE_CONSTANTS + * @see #KEY_IDLE_PENDING_FACTOR + */ + public float IDLE_PENDING_FACTOR; + + /** + * This is the initial time that we want to sit in the idle state before waking up + * again to return to pending idle and allowing normal work to run. + * @see Settings.Global#DEVICE_IDLE_CONSTANTS + * @see #KEY_IDLE_TIMEOUT + */ + public long IDLE_TIMEOUT; + + /** + * Maximum idle duration we will be allowed to use. + * @see Settings.Global#DEVICE_IDLE_CONSTANTS + * @see #KEY_MAX_IDLE_TIMEOUT + */ + public long MAX_IDLE_TIMEOUT; + + /** + * Scaling factor to apply to current idle timeout each time we cycle through that state. + * @see Settings.Global#DEVICE_IDLE_CONSTANTS + * @see #KEY_IDLE_FACTOR + */ + public float IDLE_FACTOR; + + /** + * This is the minimum time we will allow until the next upcoming alarm for us to + * actually go in to idle mode. + * @see Settings.Global#DEVICE_IDLE_CONSTANTS + * @see #KEY_MIN_TIME_TO_ALARM + */ + public long MIN_TIME_TO_ALARM; + + /** + * Max amount of time to temporarily whitelist an app when it receives a high priority + * tickle. + * @see Settings.Global#DEVICE_IDLE_CONSTANTS + * @see #KEY_MAX_TEMP_APP_WHITELIST_DURATION + */ + public long MAX_TEMP_APP_WHITELIST_DURATION; + + private final ContentResolver mResolver; + private final KeyValueListParser mParser = new KeyValueListParser(','); + + public Constants(Handler handler, ContentResolver resolver) { + super(handler); + mResolver = resolver; + mResolver.registerContentObserver( + Settings.Global.getUriFor(Settings.Global.DEVICE_IDLE_CONSTANTS), false, this); + updateConstants(); + } + + @Override + public void onChange(boolean selfChange, Uri uri) { + updateConstants(); + } + + private void updateConstants() { + synchronized (DeviceIdleController.this) { + try { + mParser.setString(Settings.Global.getString(mResolver, + Settings.Global.DEVICE_IDLE_CONSTANTS)); + } catch (IllegalArgumentException e) { + // Failed to parse the settings string, log this and move on + // with defaults. + Slog.e(TAG, "Bad device idle settings", e); + } + + INACTIVE_TIMEOUT = mParser.getLong(KEY_INACTIVE_TIMEOUT, + !COMPRESS_TIME ? 30 * 60 * 1000L : 3 * 60 * 1000L); + SENSING_TIMEOUT = mParser.getLong(KEY_SENSING_TIMEOUT, + !DEBUG ? 5 * 60 * 1000L : 60 * 1000L); + MOTION_INACTIVE_TIMEOUT = mParser.getLong(KEY_MOTION_INACTIVE_TIMEOUT, + !COMPRESS_TIME ? 10 * 60 * 1000L : 60 * 1000L); + IDLE_AFTER_INACTIVE_TIMEOUT = mParser.getLong(KEY_IDLE_AFTER_INACTIVE_TIMEOUT, + !COMPRESS_TIME ? 30 * 60 * 1000L : 3 * 60 * 1000L); + IDLE_PENDING_TIMEOUT = mParser.getLong(KEY_IDLE_PENDING_TIMEOUT, + !COMPRESS_TIME ? 5 * 60 * 1000L : 30 * 1000L); + MAX_IDLE_PENDING_TIMEOUT = mParser.getLong(KEY_MAX_IDLE_PENDING_TIMEOUT, + !COMPRESS_TIME ? 10 * 60 * 1000L : 60 * 1000L); + IDLE_PENDING_FACTOR = mParser.getFloat(KEY_IDLE_PENDING_FACTOR, + 2f); + IDLE_TIMEOUT = mParser.getLong(KEY_IDLE_TIMEOUT, + !COMPRESS_TIME ? 60 * 60 * 1000L : 6 * 60 * 1000L); + MAX_IDLE_TIMEOUT = mParser.getLong(KEY_MAX_IDLE_TIMEOUT, + !COMPRESS_TIME ? 6 * 60 * 60 * 1000L : 30 * 60 * 1000L); + IDLE_FACTOR = mParser.getFloat(KEY_IDLE_FACTOR, + 2f); + MIN_TIME_TO_ALARM = mParser.getLong(KEY_MIN_TIME_TO_ALARM, + !COMPRESS_TIME ? 60 * 60 * 1000L : 6 * 60 * 1000L); + MAX_TEMP_APP_WHITELIST_DURATION = mParser.getLong(KEY_MAX_TEMP_APP_WHITELIST_DURATION, + 5 * 60 * 1000L); + } + } + + void dump(PrintWriter pw) { + pw.println(" Settings:"); + + pw.print(" DOZE_INACTIVE_TIMEOUT="); + TimeUtils.formatDuration(INACTIVE_TIMEOUT, pw); + pw.println(); + + pw.print(" DOZE_SENSING_TIMEOUT="); + TimeUtils.formatDuration(SENSING_TIMEOUT, pw); + pw.println(); + + pw.print(" DOZE_MOTION_INACTIVE_TIMEOUT="); + TimeUtils.formatDuration(MOTION_INACTIVE_TIMEOUT, pw); + pw.println(); + + pw.print(" DOZE_IDLE_AFTER_INACTIVE_TIMEOUT="); + TimeUtils.formatDuration(IDLE_AFTER_INACTIVE_TIMEOUT, pw); + pw.println(); + + pw.print(" DOZE_IDLE_PENDING_TIMEOUT="); + TimeUtils.formatDuration(IDLE_PENDING_TIMEOUT, pw); + pw.println(); + + pw.print(" DOZE_MAX_IDLE_PENDING_TIMEOUT="); + TimeUtils.formatDuration(MAX_IDLE_PENDING_TIMEOUT, pw); + pw.println(); + + pw.print(" DOZE_IDLE_PENDING_FACTOR="); + pw.println(IDLE_PENDING_FACTOR); + + pw.print(" DOZE_IDLE_TIMEOUT="); + TimeUtils.formatDuration(IDLE_TIMEOUT, pw); + pw.println(); + + pw.print(" DOZE_MAX_IDLE_TIMEOUT="); + TimeUtils.formatDuration(MAX_IDLE_TIMEOUT, pw); + pw.println(); + + pw.print(" DOZE_IDLE_FACTOR="); + pw.println(IDLE_FACTOR); + + pw.print(" DOZE_MIN_TIME_TO_ALARM="); + TimeUtils.formatDuration(MIN_TIME_TO_ALARM, pw); + pw.println(); + + pw.print(" DOZE_MAX_TEMP_APP_WHITELIST_DURATION="); + TimeUtils.formatDuration(MAX_TEMP_APP_WHITELIST_DURATION, pw); + pw.println(); + } + } + + private Constants mConstants; + @Override public void onAnyMotionResult(int result) { if (DEBUG) Slog.d(TAG, "onAnyMotionResult(" + result + ")"); @@ -474,6 +623,8 @@ public class DeviceIdleController extends SystemService } } + mConstants = new Constants(mHandler, getContext().getContentResolver()); + readConfigFileLocked(); updateWhitelistAppIdsLocked(); @@ -482,7 +633,7 @@ public class DeviceIdleController extends SystemService // a battery update the next time the level drops. mCharging = true; mState = STATE_ACTIVE; - mInactiveTimeout = DEFAULT_INACTIVE_TIMEOUT; + mInactiveTimeout = mConstants.INACTIVE_TIMEOUT; } publishBinderService(SERVICE_NAME, new BinderService()); @@ -613,14 +764,12 @@ public class DeviceIdleController extends SystemService */ public void addPowerSaveTempWhitelistAppInternal(String packageName, long duration, int userId) { - if (duration > MAX_TEMP_APP_WHITELIST_DURATION) { - duration = MAX_TEMP_APP_WHITELIST_DURATION; - } try { int uid = getContext().getPackageManager().getPackageUid(packageName, userId); int appId = UserHandle.getAppId(uid); final long timeNow = System.currentTimeMillis(); synchronized (this) { + duration = Math.min(duration, mConstants.MAX_TEMP_APP_WHITELIST_DURATION); long currentEndTime = mTempWhitelistAppIdEndTimes.get(appId); // Set the new end time mTempWhitelistAppIdEndTimes.put(appId, timeNow + duration); @@ -704,7 +853,7 @@ public class DeviceIdleController extends SystemService EventLogTags.writeDeviceIdle(STATE_ACTIVE, reason); scheduleReportActiveLocked(false); mState = STATE_ACTIVE; - mInactiveTimeout = DEFAULT_INACTIVE_TIMEOUT; + mInactiveTimeout = mConstants.INACTIVE_TIMEOUT; mNextIdlePendingDelay = 0; mNextIdleDelay = 0; cancelAlarmLocked(); @@ -731,7 +880,7 @@ public class DeviceIdleController extends SystemService * within the DEFAULT_SENSING_TIMEOUT, to return to STATE_INACTIVE. */ void enterInactiveStateLocked() { - mInactiveTimeout = DEFAULT_INACTIVE_TIMEOUT; + mInactiveTimeout = mConstants.INACTIVE_TIMEOUT; becomeInactiveIfAppropriateLocked(); } @@ -740,7 +889,7 @@ public class DeviceIdleController extends SystemService EventLogTags.writeDeviceIdleStep(); final long now = SystemClock.elapsedRealtime(); - if ((now+DEFAULT_MIN_TIME_TO_ALARM) > mAlarmManager.getNextWakeFromIdleTime()) { + if ((now+mConstants.MIN_TIME_TO_ALARM) > mAlarmManager.getNextWakeFromIdleTime()) { // Whoops, there is an upcoming alarm. We don't actually want to go idle. if (mState != STATE_ACTIVE) { becomeActiveLocked("alarm"); @@ -753,10 +902,10 @@ public class DeviceIdleController extends SystemService // We have now been inactive long enough, it is time to start looking // for significant motion and sleep some more while doing so. startMonitoringSignificantMotion(); - scheduleAlarmLocked(DEFAULT_IDLE_AFTER_INACTIVE_TIMEOUT, false); + scheduleAlarmLocked(mConstants.IDLE_AFTER_INACTIVE_TIMEOUT, false); // Reset the upcoming idle delays. - mNextIdlePendingDelay = DEFAULT_IDLE_PENDING_TIMEOUT; - mNextIdleDelay = DEFAULT_IDLE_TIMEOUT; + mNextIdlePendingDelay = mConstants.IDLE_PENDING_TIMEOUT; + mNextIdleDelay = mConstants.IDLE_TIMEOUT; mState = STATE_IDLE_PENDING; if (DEBUG) Slog.d(TAG, "Moved from STATE_INACTIVE to STATE_IDLE_PENDING."); EventLogTags.writeDeviceIdle(mState, "step"); @@ -764,7 +913,7 @@ public class DeviceIdleController extends SystemService case STATE_IDLE_PENDING: mState = STATE_SENSING; if (DEBUG) Slog.d(TAG, "Moved from STATE_IDLE_PENDING to STATE_SENSING."); - scheduleSensingAlarmLocked(DEFAULT_SENSING_TIMEOUT); + scheduleSensingAlarmLocked(mConstants.SENSING_TIMEOUT); mAnyMotionDetector.checkForAnyMotion(); break; case STATE_SENSING: @@ -773,11 +922,9 @@ public class DeviceIdleController extends SystemService scheduleAlarmLocked(mNextIdleDelay, true); if (DEBUG) Slog.d(TAG, "Moved to STATE_IDLE. Next alarm in " + mNextIdleDelay + " ms."); - mNextIdleDelay = (long)(mNextIdleDelay * DEFAULT_IDLE_FACTOR); + mNextIdleDelay = (long)(mNextIdleDelay * mConstants.IDLE_FACTOR); if (DEBUG) Slog.d(TAG, "Setting mNextIdleDelay = " + mNextIdleDelay); - if (mNextIdleDelay > DEFAULT_MAX_IDLE_TIMEOUT) { - mNextIdleDelay = DEFAULT_MAX_IDLE_TIMEOUT; - } + mNextIdleDelay = Math.min(mNextIdleDelay, mConstants.MAX_IDLE_TIMEOUT); mState = STATE_IDLE; mHandler.sendEmptyMessage(MSG_REPORT_IDLE_ON); break; @@ -786,10 +933,8 @@ public class DeviceIdleController extends SystemService scheduleAlarmLocked(mNextIdlePendingDelay, false); if (DEBUG) Slog.d(TAG, "Moved from STATE_IDLE to STATE_IDLE_MAINTENANCE. " + "Next alarm in " + mNextIdlePendingDelay + " ms."); - mNextIdlePendingDelay = (long)(mNextIdlePendingDelay*DEFAULT_IDLE_PENDING_FACTOR); - if (mNextIdlePendingDelay > DEFAULT_MAX_IDLE_PENDING_TIMEOUT) { - mNextIdlePendingDelay = DEFAULT_MAX_IDLE_PENDING_TIMEOUT; - } + mNextIdlePendingDelay = Math.min(mConstants.MAX_IDLE_PENDING_TIMEOUT, + (long)(mNextIdlePendingDelay * mConstants.IDLE_PENDING_FACTOR)); mState = STATE_IDLE_MAINTENANCE; EventLogTags.writeDeviceIdle(mState, "step"); mHandler.sendEmptyMessage(MSG_REPORT_IDLE_OFF); @@ -807,7 +952,7 @@ public class DeviceIdleController extends SystemService if (mState != STATE_ACTIVE) { scheduleReportActiveLocked(true); mState = STATE_ACTIVE; - mInactiveTimeout = DEFAULT_MOTION_INACTIVE_TIMEOUT; + mInactiveTimeout = mConstants.MOTION_INACTIVE_TIMEOUT; EventLogTags.writeDeviceIdle(mState, "motion"); becomeInactiveIfAppropriateLocked(); } @@ -1179,6 +1324,9 @@ public class DeviceIdleController extends SystemService pw.println(); } } + + mConstants.dump(pw); + pw.print(" mSigMotionSensor="); pw.println(mSigMotionSensor); pw.print(" mCurDisplay="); pw.println(mCurDisplay); pw.print(" mIdleDisabled="); pw.println(mIdleDisabled); diff --git a/services/core/java/com/android/server/accounts/AccountManagerService.java b/services/core/java/com/android/server/accounts/AccountManagerService.java index 21f96c9dbdbd..49d9988ac549 100644 --- a/services/core/java/com/android/server/accounts/AccountManagerService.java +++ b/services/core/java/com/android/server/accounts/AccountManagerService.java @@ -87,11 +87,8 @@ import java.io.File; import java.io.FileDescriptor; import java.io.PrintWriter; import java.lang.ref.WeakReference; -import java.nio.ByteBuffer; -import java.nio.charset.Charset; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -100,7 +97,6 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; @@ -526,14 +522,20 @@ public class AccountManagerService @Override public String getPassword(Account account) { + int callingUid = Binder.getCallingUid(); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "getPassword: " + account + ", caller's uid " + Binder.getCallingUid() + ", pid " + Binder.getCallingPid()); } if (account == null) throw new IllegalArgumentException("account is null"); - checkAuthenticateAccountsPermission(account); - + if (!isAccountOwnedByCallingUid(account.type, callingUid)) { + String msg = String.format( + "uid %s cannot get secrets for accounts of type: %s", + callingUid, + account.type); + throw new SecurityException(msg); + } UserAccounts accounts = getUserAccountsForCaller(); long identityToken = clearCallingIdentity(); try { @@ -617,15 +619,21 @@ public class AccountManagerService @Override public String getUserData(Account account, String key) { + final int callingUid = Binder.getCallingUid(); if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.v(TAG, "getUserData: " + account - + ", key " + key - + ", caller's uid " + Binder.getCallingUid() - + ", pid " + Binder.getCallingPid()); + String msg = String.format("getUserData( account: %s, key: %s, callerUid: %s, pid: %s", + account, key, callingUid, Binder.getCallingPid()); + Log.v(TAG, msg); } if (account == null) throw new IllegalArgumentException("account is null"); if (key == null) throw new IllegalArgumentException("key is null"); - checkAuthenticateAccountsPermission(account); + if (!isAccountOwnedByCallingUid(account.type, callingUid)) { + String msg = String.format( + "uid %s cannot get user data for accounts of type: %s", + callingUid, + account.type); + throw new SecurityException(msg); + } UserAccounts accounts = getUserAccountsForCaller(); long identityToken = clearCallingIdentity(); try { @@ -676,13 +684,20 @@ public class AccountManagerService @Override public boolean addAccountExplicitly(Account account, String password, Bundle extras) { + final int callingUid = Binder.getCallingUid(); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "addAccountExplicitly: " + account - + ", caller's uid " + Binder.getCallingUid() + + ", caller's uid " + callingUid + ", pid " + Binder.getCallingPid()); } if (account == null) throw new IllegalArgumentException("account is null"); - checkAuthenticateAccountsPermission(account); + if (!isAccountOwnedByCallingUid(account.type, callingUid)) { + String msg = String.format( + "uid %s cannot explicitly add accounts of type: %s", + callingUid, + account.type); + throw new SecurityException(msg); + } /* * Child users are not allowed to add accounts. Only the accounts that are * shared by the parent profile can be added to child profile. @@ -758,10 +773,24 @@ public class AccountManagerService @Override public boolean accountAuthenticated(final Account account) { + final int callingUid = Binder.getCallingUid(); + if (Log.isLoggable(TAG, Log.VERBOSE)) { + String msg = String.format( + "accountAuthenticated( account: %s, callerUid: %s)", + account, + callingUid); + Log.v(TAG, msg); + } if (account == null) { throw new IllegalArgumentException("account is null"); } - checkAuthenticateAccountsPermission(account); + if (!isAccountOwnedByCallingUid(account.type, callingUid)) { + String msg = String.format( + "uid %s cannot notify authentication for accounts of type: %s", + callingUid, + account.type); + throw new SecurityException(msg); + } int userId = Binder.getCallingUserHandle().getIdentifier(); if (!canUserModifyAccounts(userId) || !canUserModifyAccountsForType(userId, account.type)) { return false; @@ -1007,16 +1036,21 @@ public class AccountManagerService @Override public void renameAccount( IAccountManagerResponse response, Account accountToRename, String newName) { + final int callingUid = Binder.getCallingUid(); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "renameAccount: " + accountToRename + " -> " + newName - + ", caller's uid " + Binder.getCallingUid() + + ", caller's uid " + callingUid + ", pid " + Binder.getCallingPid()); } if (accountToRename == null) throw new IllegalArgumentException("account is null"); - checkAuthenticateAccountsPermission(accountToRename); + if (!isAccountOwnedByCallingUid(accountToRename.type, callingUid)) { + String msg = String.format( + "uid %s cannot rename accounts of type: %s", + callingUid, + accountToRename.type); + throw new SecurityException(msg); + } UserAccounts accounts = getUserAccountsForCaller(); - - int callingUid = getCallingUid(); long identityToken = clearCallingIdentity(); try { Account resultingAccount = renameAccountInternal(accounts, accountToRename, newName, @@ -1125,65 +1159,21 @@ public class AccountManagerService @Override public void removeAccount(IAccountManagerResponse response, Account account, boolean expectActivityLaunch) { - if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.v(TAG, "removeAccount: " + account - + ", response " + response - + ", caller's uid " + Binder.getCallingUid() - + ", pid " + Binder.getCallingPid()); - } - if (response == null) throw new IllegalArgumentException("response is null"); - if (account == null) throw new IllegalArgumentException("account is null"); - checkManageAccountsPermission(); - UserHandle user = Binder.getCallingUserHandle(); - UserAccounts accounts = getUserAccountsForCaller(); - int userId = Binder.getCallingUserHandle().getIdentifier(); - if (!canUserModifyAccounts(userId)) { - try { - // TODO: This should be ERROR_CODE_USER_RESTRICTED instead. See http://b/16322768 - response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION, - "User cannot modify accounts"); - } catch (RemoteException re) { - } - return; - } - if (!canUserModifyAccountsForType(userId, account.type)) { - try { - response.onError(AccountManager.ERROR_CODE_MANAGEMENT_DISABLED_FOR_ACCOUNT_TYPE, - "User cannot modify accounts of this type (policy)."); - } catch (RemoteException re) { - } - return; - } - - long identityToken = clearCallingIdentity(); - - cancelNotification(getSigninRequiredNotificationId(accounts, account), user); - synchronized (accounts.credentialsPermissionNotificationIds) { - for (Pair<Pair<Account, String>, Integer> pair: - accounts.credentialsPermissionNotificationIds.keySet()) { - if (account.equals(pair.first.first)) { - int id = accounts.credentialsPermissionNotificationIds.get(pair); - cancelNotification(id, user); - } - } - } - - logRecord(accounts, DebugDbHelper.ACTION_CALLED_ACCOUNT_REMOVE, TABLE_ACCOUNTS); - - try { - new RemoveAccountSession(accounts, response, account, expectActivityLaunch).bind(); - } finally { - restoreCallingIdentity(identityToken); - } + removeAccountAsUser( + response, + account, + expectActivityLaunch, + UserHandle.getCallingUserId()); } @Override public void removeAccountAsUser(IAccountManagerResponse response, Account account, boolean expectActivityLaunch, int userId) { + final int callingUid = Binder.getCallingUid(); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "removeAccount: " + account + ", response " + response - + ", caller's uid " + Binder.getCallingUid() + + ", caller's uid " + callingUid + ", pid " + Binder.getCallingPid() + ", for user id " + userId); } @@ -1193,7 +1183,18 @@ public class AccountManagerService // Only allow the system process to modify accounts of other users enforceCrossUserPermission(userId, "User " + UserHandle.getCallingUserId() + " trying to remove account for " + userId); - checkManageAccountsPermission(); + /* + * Only the system or authenticator should be allowed to remove accounts for that + * authenticator. This will let users remove accounts (via Settings in the system) but not + * arbitrary applications (like competing authenticators). + */ + if (!isAccountOwnedByCallingUid(account.type, callingUid) && !isSystemUid(callingUid)) { + String msg = String.format( + "uid %s cannot remove accounts of type: %s", + callingUid, + account.type); + throw new SecurityException(msg); + } UserAccounts accounts = getUserAccounts(userId); if (!canUserModifyAccounts(userId)) { @@ -1238,13 +1239,26 @@ public class AccountManagerService @Override public boolean removeAccountExplicitly(Account account) { + final int callingUid = Binder.getCallingUid(); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "removeAccountExplicitly: " + account - + ", caller's uid " + Binder.getCallingUid() + + ", caller's uid " + callingUid + ", pid " + Binder.getCallingPid()); } - if (account == null) throw new IllegalArgumentException("account is null"); - checkAuthenticateAccountsPermission(account); + if (account == null) { + /* + * Null accounts should result in returning false, as per + * AccountManage.addAccountExplicitly(...) java doc. + */ + Log.e(TAG, "account is null"); + return false; + } else if (!isAccountOwnedByCallingUid(account.type, callingUid)) { + String msg = String.format( + "uid %s cannot explicitly add accounts of type: %s", + callingUid, + account.type); + throw new SecurityException(msg); + } UserAccounts accounts = getUserAccountsForCaller(); int userId = Binder.getCallingUserHandle().getIdentifier(); @@ -1357,7 +1371,6 @@ public class AccountManagerService } if (accountType == null) throw new IllegalArgumentException("accountType is null"); if (authToken == null) throw new IllegalArgumentException("authToken is null"); - checkManageAccountsOrUseCredentialsPermissions(); UserAccounts accounts = getUserAccountsForCaller(); long identityToken = clearCallingIdentity(); try { @@ -1490,15 +1503,22 @@ public class AccountManagerService @Override public String peekAuthToken(Account account, String authTokenType) { + final int callingUid = Binder.getCallingUid(); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "peekAuthToken: " + account + ", authTokenType " + authTokenType - + ", caller's uid " + Binder.getCallingUid() + + ", caller's uid " + callingUid + ", pid " + Binder.getCallingPid()); } if (account == null) throw new IllegalArgumentException("account is null"); if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null"); - checkAuthenticateAccountsPermission(account); + if (!isAccountOwnedByCallingUid(account.type, callingUid)) { + String msg = String.format( + "uid %s cannot peek the authtokens associated with accounts of type: %s", + callingUid, + account.type); + throw new SecurityException(msg); + } UserAccounts accounts = getUserAccountsForCaller(); long identityToken = clearCallingIdentity(); try { @@ -1510,15 +1530,22 @@ public class AccountManagerService @Override public void setAuthToken(Account account, String authTokenType, String authToken) { + final int callingUid = Binder.getCallingUid(); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "setAuthToken: " + account + ", authTokenType " + authTokenType - + ", caller's uid " + Binder.getCallingUid() + + ", caller's uid " + callingUid + ", pid " + Binder.getCallingPid()); } if (account == null) throw new IllegalArgumentException("account is null"); if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null"); - checkAuthenticateAccountsPermission(account); + if (!isAccountOwnedByCallingUid(account.type, callingUid)) { + String msg = String.format( + "uid %s cannot set auth tokens associated with accounts of type: %s", + callingUid, + account.type); + throw new SecurityException(msg); + } UserAccounts accounts = getUserAccountsForCaller(); long identityToken = clearCallingIdentity(); try { @@ -1530,15 +1557,21 @@ public class AccountManagerService @Override public void setPassword(Account account, String password) { + final int callingUid = Binder.getCallingUid(); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "setAuthToken: " + account - + ", caller's uid " + Binder.getCallingUid() + + ", caller's uid " + callingUid + ", pid " + Binder.getCallingPid()); } if (account == null) throw new IllegalArgumentException("account is null"); - checkAuthenticateAccountsPermission(account); + if (!isAccountOwnedByCallingUid(account.type, callingUid)) { + String msg = String.format( + "uid %s cannot set secrets for accounts of type: %s", + callingUid, + account.type); + throw new SecurityException(msg); + } UserAccounts accounts = getUserAccountsForCaller(); - int callingUid = getCallingUid(); long identityToken = clearCallingIdentity(); try { setPasswordInternal(accounts, account, password, callingUid); @@ -1594,16 +1627,21 @@ public class AccountManagerService @Override public void clearPassword(Account account) { + final int callingUid = Binder.getCallingUid(); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "clearPassword: " + account - + ", caller's uid " + Binder.getCallingUid() + + ", caller's uid " + callingUid + ", pid " + Binder.getCallingPid()); } if (account == null) throw new IllegalArgumentException("account is null"); - checkManageAccountsPermission(); + if (!isAccountOwnedByCallingUid(account.type, callingUid)) { + String msg = String.format( + "uid %s cannot clear passwords for accounts of type: %s", + callingUid, + account.type); + throw new SecurityException(msg); + } UserAccounts accounts = getUserAccountsForCaller(); - - int callingUid = getCallingUid(); long identityToken = clearCallingIdentity(); try { setPasswordInternal(accounts, account, null, callingUid); @@ -1614,15 +1652,22 @@ public class AccountManagerService @Override public void setUserData(Account account, String key, String value) { + final int callingUid = Binder.getCallingUid(); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "setUserData: " + account + ", key " + key - + ", caller's uid " + Binder.getCallingUid() + + ", caller's uid " + callingUid + ", pid " + Binder.getCallingPid()); } if (key == null) throw new IllegalArgumentException("key is null"); if (account == null) throw new IllegalArgumentException("account is null"); - checkAuthenticateAccountsPermission(account); + if (!isAccountOwnedByCallingUid(account.type, callingUid)) { + String msg = String.format( + "uid %s cannot set user data for accounts of type: %s", + callingUid, + account.type); + throw new SecurityException(msg); + } UserAccounts accounts = getUserAccountsForCaller(); long identityToken = clearCallingIdentity(); try { @@ -1769,7 +1814,6 @@ public class AccountManagerService return; } - checkBinderPermission(Manifest.permission.USE_CREDENTIALS); final UserAccounts accounts = getUserAccountsForCaller(); final RegisteredServicesCache.ServiceInfo<AuthenticatorDescription> authenticatorInfo; authenticatorInfo = mAuthenticatorCache.getServiceInfo( @@ -2047,7 +2091,6 @@ public class AccountManagerService } if (response == null) throw new IllegalArgumentException("response is null"); if (accountType == null) throw new IllegalArgumentException("accountType is null"); - checkManageAccountsPermission(); // Is user disallowed from modifying accounts? int userId = Binder.getCallingUserHandle().getIdentifier(); @@ -2122,7 +2165,6 @@ public class AccountManagerService } if (response == null) throw new IllegalArgumentException("response is null"); if (accountType == null) throw new IllegalArgumentException("accountType is null"); - checkManageAccountsPermission(); // Only allow the system process to add accounts of other users enforceCrossUserPermission(userId, "User " + UserHandle.getCallingUserId() @@ -2213,7 +2255,6 @@ public class AccountManagerService } if (response == null) throw new IllegalArgumentException("response is null"); if (account == null) throw new IllegalArgumentException("account is null"); - checkManageAccountsPermission(); UserAccounts accounts = getUserAccounts(userId); long identityToken = clearCallingIdentity(); try { @@ -2250,7 +2291,6 @@ public class AccountManagerService if (response == null) throw new IllegalArgumentException("response is null"); if (account == null) throw new IllegalArgumentException("account is null"); if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null"); - checkManageAccountsPermission(); UserAccounts accounts = getUserAccountsForCaller(); long identityToken = clearCallingIdentity(); try { @@ -2278,16 +2318,23 @@ public class AccountManagerService @Override public void editProperties(IAccountManagerResponse response, final String accountType, final boolean expectActivityLaunch) { + final int callingUid = Binder.getCallingUid(); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "editProperties: accountType " + accountType + ", response " + response + ", expectActivityLaunch " + expectActivityLaunch - + ", caller's uid " + Binder.getCallingUid() + + ", caller's uid " + callingUid + ", pid " + Binder.getCallingPid()); } if (response == null) throw new IllegalArgumentException("response is null"); if (accountType == null) throw new IllegalArgumentException("accountType is null"); - checkManageAccountsPermission(); + if (!isAccountOwnedByCallingUid(accountType, callingUid) && !isSystemUid(callingUid)) { + String msg = String.format( + "uid %s cannot edit authenticator properites for account type: %s", + callingUid, + accountType); + throw new SecurityException(msg); + } UserAccounts accounts = getUserAccountsForCaller(); long identityToken = clearCallingIdentity(); try { @@ -3588,7 +3635,7 @@ public class AccountManagerService private boolean permissionIsGranted(Account account, String authTokenType, int callerUid) { final boolean isPrivileged = isPrivileged(callerUid); final boolean fromAuthenticator = account != null - && hasAuthenticatorUid(account.type, callerUid); + && isAccountManagedByCaller(account.type, callerUid); final boolean hasExplicitGrants = account != null && hasExplicitlyGrantedPermission(account, authTokenType, callerUid); if (Log.isLoggable(TAG, Log.VERBOSE)) { @@ -3600,14 +3647,17 @@ public class AccountManagerService return fromAuthenticator || hasExplicitGrants || isPrivileged; } - private boolean hasAuthenticatorUid(String accountType, int callingUid) { + private boolean isAccountManagedByCaller(String accountType, int callingUid) { final int callingUserId = UserHandle.getUserId(callingUid); for (RegisteredServicesCache.ServiceInfo<AuthenticatorDescription> serviceInfo : mAuthenticatorCache.getAllServices(callingUserId)) { if (serviceInfo.type.type.equals(accountType)) { - return (serviceInfo.uid == callingUid) || - (mPackageManager.checkSignatures(serviceInfo.uid, callingUid) - == PackageManager.SIGNATURE_MATCH); + /* + * We can't simply compare uids because uids can be recycled before the + * authenticator cache is updated. + */ + final int sigChk = mPackageManager.checkSignatures(serviceInfo.uid, callingUid); + return sigChk == PackageManager.SIGNATURE_MATCH; } } return false; @@ -3648,36 +3698,49 @@ public class AccountManagerService } } - private void checkCallingUidAgainstAuthenticator(Account account) { - final int uid = Binder.getCallingUid(); - if (account == null || !hasAuthenticatorUid(account.type, uid)) { - String msg = "caller uid " + uid + " is different than the authenticator's uid"; - Log.w(TAG, msg); - throw new SecurityException(msg); + private boolean isSystemUid(int callingUid) { + String[] packages = null; + long ident = Binder.clearCallingIdentity(); + try { + packages = mPackageManager.getPackagesForUid(callingUid); + } finally { + Binder.restoreCallingIdentity(ident); } - if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.v(TAG, "caller uid " + uid + " is the same as the authenticator's uid"); + if (packages != null) { + for (String name : packages) { + try { + PackageInfo packageInfo = mPackageManager.getPackageInfo(name, 0 /* flags */); + if (packageInfo != null + && (packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) + != 0) { + return true; + } + } catch (PackageManager.NameNotFoundException e) { + Log.w(TAG, String.format("Could not find package [%s]", name), e); + } + } + } else { + Log.w(TAG, "No known packages with uid " + callingUid); } + return false; } - private void checkAuthenticateAccountsPermission(Account account) { - checkBinderPermission(Manifest.permission.AUTHENTICATE_ACCOUNTS); - checkCallingUidAgainstAuthenticator(account); + private boolean isAccountOwnedByCallingUid(String accountType, int callingUid) { + if (!isAccountManagedByCaller(accountType, callingUid)) { + String msg = "caller uid " + callingUid + " is different than the authenticator's uid"; + Log.w(TAG, msg); + return false; + } + if (Log.isLoggable(TAG, Log.VERBOSE)) { + Log.v(TAG, "caller uid " + callingUid + " is the same as the authenticator's uid"); + } + return true; } private void checkReadAccountsPermission() { checkBinderPermission(Manifest.permission.GET_ACCOUNTS); } - private void checkManageAccountsPermission() { - checkBinderPermission(Manifest.permission.MANAGE_ACCOUNTS); - } - - private void checkManageAccountsOrUseCredentialsPermissions() { - checkBinderPermission(Manifest.permission.MANAGE_ACCOUNTS, - Manifest.permission.USE_CREDENTIALS); - } - private boolean canUserModifyAccounts(int userId) { if (getUserManager().getUserRestrictions(new UserHandle(userId)) .getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS)) { diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 0d08c2ab5ea2..6496ba2b1285 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -32,6 +32,7 @@ import static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID; import static com.android.server.am.TaskRecord.INVALID_TASK_ID; import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK; import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE; +import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE_PRIV; import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_PINNABLE; import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT; import static org.xmlpull.v1.XmlPullParser.START_TAG; @@ -2967,9 +2968,14 @@ public final class ActivityManagerService extends ActivityManagerNative // should never happen). SparseArray<ProcessRecord> procs = mProcessNames.getMap().get(processName); if (procs == null) return null; - final int N = procs.size(); - for (int i = 0; i < N; i++) { - if (UserHandle.isSameUser(procs.keyAt(i), uid)) return procs.valueAt(i); + final int procCount = procs.size(); + for (int i = 0; i < procCount; i++) { + final int procUid = procs.keyAt(i); + if (UserHandle.isApp(procUid) || !UserHandle.isSameUser(procUid, uid)) { + // Don't use an app process or different user process for system component. + continue; + } + return procs.valueAt(i); } } ProcessRecord proc = mProcessNames.get(processName, uid); @@ -4197,9 +4203,9 @@ public final class ActivityManagerService extends ActivityManagerNative if (rootR == null) { Slog.w(TAG, "Finishing task with all activities already finished"); } - // Do not allow task to finish if last task in lockTask mode. Launchable apps can - // finish themselves. - if (tr.mLockTaskAuth != LOCK_TASK_AUTH_LAUNCHABLE && rootR == r && + // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps can + // finish. + if (tr.mLockTaskAuth != LOCK_TASK_AUTH_LAUNCHABLE_PRIV && rootR == r && mStackSupervisor.isLastLockedTask(tr)) { Slog.i(TAG, "Not finishing task in lock task mode"); mStackSupervisor.showLockTaskToast(); @@ -4361,9 +4367,10 @@ public final class ActivityManagerService extends ActivityManagerNative return false; } - // Do not allow the last non-launchable task to finish in Lock Task mode. + // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps + // can finish. final TaskRecord task = r.task; - if (task.mLockTaskAuth != LOCK_TASK_AUTH_LAUNCHABLE && + if (task.mLockTaskAuth != LOCK_TASK_AUTH_LAUNCHABLE_PRIV && mStackSupervisor.isLastLockedTask(task) && task.getRootActivity() == r) { mStackSupervisor.showLockTaskToast(); return false; @@ -18617,7 +18624,7 @@ public final class ActivityManagerService extends ActivityManagerNative if (packages != null) { for (int i = 0; i < packages.length; i++) { mUsageStatsService.reportEvent(packages[i], app.userId, - UsageEvents.Event.INTERACTION); + UsageEvents.Event.SYSTEM_INTERACTION); } } } diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index 23e62e22eee1..9e33f2a99607 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -35,6 +35,7 @@ import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE; import static com.android.server.am.ActivityStack.ActivityState.*; import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK; import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE; +import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE_PRIV; import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_PINNABLE; import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_WHITELISTED; @@ -1179,7 +1180,8 @@ public final class ActivityStackSupervisor implements DisplayListener { mService.updateOomAdjLocked(); final TaskRecord task = r.task; - if (task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE) { + if (task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE || + task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE_PRIV) { setLockTaskModeLocked(task, LOCK_TASK_MODE_LOCKED, "mLockTaskAuth==LAUNCHABLE", false); } @@ -3785,6 +3787,7 @@ public final class ActivityStackSupervisor implements DisplayListener { switch (lockTaskAuth) { case LOCK_TASK_AUTH_DONT_LOCK: return !mLockTaskModeTasks.isEmpty(); + case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: case LOCK_TASK_AUTH_LAUNCHABLE: case LOCK_TASK_AUTH_WHITELISTED: return false; @@ -3801,12 +3804,14 @@ public final class ActivityStackSupervisor implements DisplayListener { boolean didSomething = false; for (int taskNdx = mLockTaskModeTasks.size() - 1; taskNdx >= 0; --taskNdx) { final TaskRecord lockedTask = mLockTaskModeTasks.get(taskNdx); - if (lockedTask.mLockTaskMode != LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED) { - continue; - } - final boolean wasLaunchable = lockedTask.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE; + final boolean wasWhitelisted = + (lockedTask.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE) || + (lockedTask.mLockTaskAuth == LOCK_TASK_AUTH_WHITELISTED); lockedTask.setLockTaskAuth(); - if (wasLaunchable && lockedTask.mLockTaskAuth != LOCK_TASK_AUTH_LAUNCHABLE) { + final boolean isWhitelisted = + (lockedTask.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE) || + (lockedTask.mLockTaskAuth == LOCK_TASK_AUTH_WHITELISTED); + if (wasWhitelisted && !isWhitelisted) { // Lost whitelisting authorization. End it now. if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "onLockTaskPackagesUpdated: removing " + lockedTask + " mLockTaskAuth=" + lockedTask.lockTaskAuthToString()); diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java index f966bcf405f8..78f9f181bae0 100644 --- a/services/core/java/com/android/server/am/TaskRecord.java +++ b/services/core/java/com/android/server/am/TaskRecord.java @@ -134,12 +134,15 @@ final class TaskRecord { /** Can't be put in lockTask mode. */ final static int LOCK_TASK_AUTH_DONT_LOCK = 0; - /** Can enter lockTask with user approval. Can never start over existing lockTask task. */ + /** Can enter app pinning with user approval. Can never start over existing lockTask task. */ final static int LOCK_TASK_AUTH_PINNABLE = 1; /** Starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing lockTask task. */ final static int LOCK_TASK_AUTH_LAUNCHABLE = 2; - /** Can enter lockTask with user approval. Can start over existing lockTask task. */ + /** Can enter lockTask without user approval. Can start over existing lockTask task. */ final static int LOCK_TASK_AUTH_WHITELISTED = 3; + /** Priv-app that starts in LOCK_TASK_MODE_LOCKED automatically. Can start over existing + * lockTask task. */ + final static int LOCK_TASK_AUTH_LAUNCHABLE_PRIV = 4; int mLockTaskAuth = LOCK_TASK_AUTH_PINNABLE; int mLockTaskUid = -1; // The uid of the application that called startLockTask(). @@ -747,11 +750,18 @@ final class TaskRecord { case LOCK_TASK_AUTH_PINNABLE: return "LOCK_TASK_AUTH_PINNABLE"; case LOCK_TASK_AUTH_LAUNCHABLE: return "LOCK_TASK_AUTH_LAUNCHABLE"; case LOCK_TASK_AUTH_WHITELISTED: return "LOCK_TASK_AUTH_WHITELISTED"; + case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: return "LOCK_TASK_AUTH_LAUNCHABLE_PRIV"; default: return "unknown=" + mLockTaskAuth; } } void setLockTaskAuth() { + if (!mPrivileged && + (mLockTaskMode == LOCK_TASK_LAUNCH_MODE_ALWAYS || + mLockTaskMode == LOCK_TASK_LAUNCH_MODE_NEVER)) { + // Non-priv apps are not allowed to use always or never, fall back to default + mLockTaskMode = LOCK_TASK_LAUNCH_MODE_DEFAULT; + } switch (mLockTaskMode) { case LOCK_TASK_LAUNCH_MODE_DEFAULT: mLockTaskAuth = isLockTaskWhitelistedLocked() ? @@ -759,13 +769,11 @@ final class TaskRecord { break; case LOCK_TASK_LAUNCH_MODE_NEVER: - mLockTaskAuth = mPrivileged ? - LOCK_TASK_AUTH_DONT_LOCK : LOCK_TASK_AUTH_PINNABLE; + mLockTaskAuth = LOCK_TASK_AUTH_DONT_LOCK; break; case LOCK_TASK_LAUNCH_MODE_ALWAYS: - mLockTaskAuth = mPrivileged ? - LOCK_TASK_AUTH_LAUNCHABLE: LOCK_TASK_AUTH_PINNABLE; + mLockTaskAuth = LOCK_TASK_AUTH_LAUNCHABLE_PRIV; break; case LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED: diff --git a/services/core/java/com/android/server/fingerprint/FingerprintService.java b/services/core/java/com/android/server/fingerprint/FingerprintService.java index b0d576550cab..7f0be5766d1a 100644 --- a/services/core/java/com/android/server/fingerprint/FingerprintService.java +++ b/services/core/java/com/android/server/fingerprint/FingerprintService.java @@ -706,9 +706,22 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe @Override // Binder call public long getAuthenticatorId(String opPackageName) { - if (!canUseFingerprint(opPackageName)) { - return 0; - } + // In this method, we're not checking whether the caller is permitted to use fingerprint + // API because current authenticator ID is leaked (in a more contrived way) via Android + // Keystore (android.security.keystore package): the user of that API can create a key + // which requires fingerprint authentication for its use, and then query the key's + // characteristics (hidden API) which returns, among other things, fingerprint + // authenticator ID which was active at key creation time. + // + // Reason: The part of Android Keystore which runs inside an app's process invokes this + // method in certain cases. Those cases are not always where the developer demonstrates + // explicit intent to use fingerprint functionality. Thus, to avoiding throwing an + // unexpected SecurityException this method does not check whether its caller is + // permitted to use fingerprint API. + // + // The permission check should be restored once Android Keystore no longer invokes this + // method from inside app processes. + return FingerprintService.this.getAuthenticatorId(); } } diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 8ee20766ee72..90e912d03e60 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -1407,7 +1407,7 @@ public class NotificationManagerService extends SystemService { mAppUsageStats.reportEvent(r.sbn.getPackageName(), userId == UserHandle.USER_ALL ? UserHandle.USER_OWNER : userId, - UsageEvents.Event.INTERACTION); + UsageEvents.Event.USER_INTERACTION); r.setSeen(); } } diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 486105066f7e..1b63ca02cd8f 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -208,7 +208,7 @@ public class WindowManagerService extends IWindowManager.Stub static final boolean DEBUG_APP_ORIENTATION = false; static final boolean DEBUG_CONFIGURATION = false; static final boolean DEBUG_APP_TRANSITIONS = false; - static final boolean DEBUG_STARTING_WINDOW = true; + static final boolean DEBUG_STARTING_WINDOW = false; static final boolean DEBUG_WALLPAPER = false; static final boolean DEBUG_WALLPAPER_LIGHT = false || DEBUG_WALLPAPER; static final boolean DEBUG_DRAG = false; @@ -577,8 +577,10 @@ public class WindowManagerService extends IWindowManager.Stub public SettingsObserver() { super(new Handler()); ContentResolver resolver = mContext.getContentResolver(); - resolver.registerContentObserver(mShowImeWithHardKeyboardUri, false, this); - resolver.registerContentObserver(mDisplayInversionEnabledUri, false, this); + resolver.registerContentObserver(mShowImeWithHardKeyboardUri, false, this, + UserHandle.USER_ALL); + resolver.registerContentObserver(mDisplayInversionEnabledUri, false, this, + UserHandle.USER_ALL); } @Override @@ -5917,11 +5919,15 @@ public class WindowManagerService extends IWindowManager.Stub if (mContext.getResources().getConfiguration().isScreenRound() && mContext.getResources().getBoolean( com.android.internal.R.bool.config_windowShowCircularMask)) { + final int currentUserId; + synchronized(mWindowMap) { + currentUserId = mCurrentUserId; + } // Device configuration calls for a circular display mask, but we only enable the mask // if the accessibility color inversion feature is disabled, as the inverted mask // causes artifacts. int inversionState = Settings.Secure.getIntForUser(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, 0, mCurrentUserId); + Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, 0, currentUserId); int showMask = (inversionState == 1) ? 0 : 1; Message m = mH.obtainMessage(H.SHOW_CIRCULAR_DISPLAY_MASK); m.arg1 = showMask; @@ -7422,10 +7428,10 @@ public class WindowManagerService extends IWindowManager.Stub } public void updateShowImeWithHardKeyboard() { - final boolean showImeWithHardKeyboard = Settings.Secure.getIntForUser( - mContext.getContentResolver(), Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, 0, - mCurrentUserId) == 1; synchronized (mWindowMap) { + final boolean showImeWithHardKeyboard = Settings.Secure.getIntForUser( + mContext.getContentResolver(), Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, 0, + mCurrentUserId) == 1; if (mShowImeWithHardKeyboard != showImeWithHardKeyboard) { mShowImeWithHardKeyboard = showImeWithHardKeyboard; mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index ab1206bb13ea..275370068b8b 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -5975,40 +5975,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } @Override - public void sendDeviceInitializerStatus(int statusCode, String description) { - synchronized (this) { - String packageName = getDeviceInitializer(); - if (packageName == null) { - throw new SecurityException("No device initializers"); - } - UserHandle callingUser = Binder.getCallingUserHandle(); - int deviceInitializerUid = -1; - try { - deviceInitializerUid = mContext.getPackageManager().getPackageUid( - packageName, callingUser.getIdentifier()); - } catch (NameNotFoundException e) { - throw new SecurityException(e); - } - if (Binder.getCallingUid() != deviceInitializerUid) { - throw new SecurityException("Caller must be a device initializer"); - } - long id = Binder.clearCallingIdentity(); - try { - Intent intent = new Intent( - DevicePolicyManager.ACTION_SEND_DEVICE_INITIALIZER_STATUS); - intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_INITIALIZER_STATUS_CODE, - statusCode); - intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_INITIALIZER_STATUS_DESCRIPTION, - description); - mContext.sendBroadcastAsUser(intent, callingUser, - android.Manifest.permission.RECEIVE_DEVICE_INITIALIZER_STATUS); - } finally { - restoreCallingIdentity(id); - } - } - } - - @Override public boolean setKeyguardDisabled(ComponentName who, boolean disabled) { Preconditions.checkNotNull(who, "ComponentName is null"); synchronized (this) { diff --git a/services/usage/java/com/android/server/usage/IntervalStats.java b/services/usage/java/com/android/server/usage/IntervalStats.java index a61567567b76..1aa297854e72 100644 --- a/services/usage/java/com/android/server/usage/IntervalStats.java +++ b/services/usage/java/com/android/server/usage/IntervalStats.java @@ -110,7 +110,10 @@ class IntervalStats { usageStats.mLastEvent = eventType; } - usageStats.mLastTimeUsed = timeStamp; + if (eventType != UsageEvents.Event.SYSTEM_INTERACTION) { + usageStats.mLastTimeUsed = timeStamp; + } + usageStats.mLastTimeSystemUsed = timeStamp; usageStats.mEndTimeStamp = timeStamp; if (eventType == UsageEvents.Event.MOVE_TO_FOREGROUND) { @@ -131,9 +134,9 @@ class IntervalStats { usageStats.mBeginIdleTime = timeStamp; } - void updateLastUsedTime(String packageName, long lastUsedTime) { + void updateSystemLastUsedTime(String packageName, long lastUsedTime) { UsageStats usageStats = getOrCreateUsageStats(packageName); - usageStats.mLastTimeUsed = lastUsedTime; + usageStats.mLastTimeSystemUsed = lastUsedTime; } void updateConfigurationStats(Configuration config, long timeStamp) { diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java index 633aee82b384..7a3475790ce2 100644 --- a/services/usage/java/com/android/server/usage/UsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UsageStatsService.java @@ -60,7 +60,6 @@ import android.provider.Settings; import android.telephony.TelephonyManager; import android.util.ArraySet; import android.util.AtomicFile; -import android.util.Log; import android.util.Slog; import android.util.SparseArray; import android.view.Display; @@ -543,14 +542,15 @@ public class UsageStatsService extends SystemService implements final UserUsageStatsService service = getUserDataAndInitializeIfNeededLocked(userId, timeNow); final long beginIdleTime = service.getBeginIdleTime(event.mPackage); - final long lastUsedTime = service.getLastUsedTime(event.mPackage); + final long lastUsedTime = service.getSystemLastUsedTime(event.mPackage); final boolean previouslyIdle = hasPassedIdleTimeoutLocked(beginIdleTime, lastUsedTime, screenOnTime, timeNow); service.reportEvent(event, getScreenOnTimeLocked(timeNow)); // Inform listeners if necessary if ((event.mEventType == Event.MOVE_TO_FOREGROUND || event.mEventType == Event.MOVE_TO_BACKGROUND - || event.mEventType == Event.INTERACTION)) { + || event.mEventType == Event.SYSTEM_INTERACTION + || event.mEventType == Event.USER_INTERACTION)) { if (previouslyIdle) { // Slog.d(TAG, "Informing listeners of out-of-idle " + event.mPackage); mHandler.sendMessage(mHandler.obtainMessage(MSG_INFORM_LISTENERS, userId, @@ -575,11 +575,11 @@ public class UsageStatsService extends SystemService implements final UserUsageStatsService service = getUserDataAndInitializeIfNeededLocked(userId, timeNow); final long beginIdleTime = service.getBeginIdleTime(packageName); - final long lastUsedTime = service.getLastUsedTime(packageName); + final long lastUsedTime = service.getSystemLastUsedTime(packageName); final boolean previouslyIdle = hasPassedIdleTimeoutLocked(beginIdleTime, lastUsedTime, screenOnTime, timeNow); service.setBeginIdleTime(packageName, deviceUsageTime); - service.setLastUsedTime(packageName, + service.setSystemLastUsedTime(packageName, timeNow - (idle ? DEFAULT_WALLCLOCK_APP_IDLE_THRESHOLD_MILLIS : 0) - 5000); // Inform listeners if necessary if (previouslyIdle != idle) { @@ -666,7 +666,7 @@ public class UsageStatsService extends SystemService implements final UserUsageStatsService service = getUserDataAndInitializeIfNeededLocked(userId, timeNow); long beginIdleTime = service.getBeginIdleTime(packageName); - long lastUsedTime = service.getLastUsedTime(packageName); + long lastUsedTime = service.getSystemLastUsedTime(packageName); return hasPassedIdleTimeoutLocked(beginIdleTime, lastUsedTime, screenOnTime, timeNow); } } diff --git a/services/usage/java/com/android/server/usage/UsageStatsXmlV1.java b/services/usage/java/com/android/server/usage/UsageStatsXmlV1.java index 01112014c753..f2ca3a4047fa 100644 --- a/services/usage/java/com/android/server/usage/UsageStatsXmlV1.java +++ b/services/usage/java/com/android/server/usage/UsageStatsXmlV1.java @@ -55,6 +55,7 @@ final class UsageStatsXmlV1 { // Time attributes stored as an offset of the beginTime. private static final String LAST_TIME_ACTIVE_ATTR = "lastTimeActive"; + private static final String LAST_TIME_ACTIVE_SYSTEM_ATTR = "lastTimeActiveSystem"; private static final String BEGIN_IDLE_TIME_ATTR = "beginIdleTime"; private static final String END_TIME_ATTR = "endTime"; private static final String TIME_ATTR = "time"; @@ -71,6 +72,16 @@ final class UsageStatsXmlV1 { // Apply the offset to the beginTime to find the absolute time. stats.mLastTimeUsed = statsOut.beginTime + XmlUtils.readLongAttribute( parser, LAST_TIME_ACTIVE_ATTR); + + final String lastTimeUsedSystem = parser.getAttributeValue(null, + LAST_TIME_ACTIVE_SYSTEM_ATTR); + if (TextUtils.isEmpty(lastTimeUsedSystem)) { + // If the field isn't present, use the old one. + stats.mLastTimeSystemUsed = stats.mLastTimeUsed; + } else { + stats.mLastTimeSystemUsed = statsOut.beginTime + Long.parseLong(lastTimeUsedSystem); + } + final String beginIdleTime = parser.getAttributeValue(null, BEGIN_IDLE_TIME_ATTR); if (!TextUtils.isEmpty(beginIdleTime)) { stats.mBeginIdleTime = Long.parseLong(beginIdleTime); @@ -130,6 +141,8 @@ final class UsageStatsXmlV1 { // Write the time offset. XmlUtils.writeLongAttribute(xml, LAST_TIME_ACTIVE_ATTR, usageStats.mLastTimeUsed - stats.beginTime); + XmlUtils.writeLongAttribute(xml, LAST_TIME_ACTIVE_SYSTEM_ATTR, + usageStats.mLastTimeSystemUsed - stats.beginTime); XmlUtils.writeStringAttribute(xml, PACKAGE_ATTR, usageStats.mPackageName); XmlUtils.writeLongAttribute(xml, TOTAL_TIME_ACTIVE_ATTR, usageStats.mTotalTimeInForeground); diff --git a/services/usage/java/com/android/server/usage/UserUsageStatsService.java b/services/usage/java/com/android/server/usage/UserUsageStatsService.java index 7c00dae8e2f0..b07b8153279d 100644 --- a/services/usage/java/com/android/server/usage/UserUsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UserUsageStatsService.java @@ -157,7 +157,7 @@ class UserUsageStatsService { if (pi.applicationInfo != null && (firstUpdate || pi.applicationInfo.isSystemApp()) && getBeginIdleTime(packageName) == -1) { for (IntervalStats stats : mCurrentStats) { - stats.update(packageName, currentTimeMillis, Event.INTERACTION); + stats.update(packageName, currentTimeMillis, Event.SYSTEM_INTERACTION); stats.updateBeginIdleTime(packageName, deviceUsageTime); mStatsChanged = true; } @@ -199,7 +199,7 @@ class UserUsageStatsService { if (currentDailyStats.events == null) { currentDailyStats.events = new TimeSparseArray<>(); } - if (event.mEventType != UsageEvents.Event.INTERACTION) { + if (event.mEventType != UsageEvents.Event.SYSTEM_INTERACTION) { currentDailyStats.events.put(event.mTimeStamp, event); } @@ -226,9 +226,9 @@ class UserUsageStatsService { notifyStatsChanged(); } - void setLastUsedTime(String packageName, long lastUsedTime) { + void setSystemLastUsedTime(String packageName, long lastUsedTime) { for (IntervalStats stats : mCurrentStats) { - stats.updateLastUsedTime(packageName, lastUsedTime); + stats.updateSystemLastUsedTime(packageName, lastUsedTime); } notifyStatsChanged(); } @@ -397,13 +397,13 @@ class UserUsageStatsService { } } - long getLastUsedTime(String packageName) { + long getSystemLastUsedTime(String packageName) { final IntervalStats yearly = mCurrentStats[UsageStatsManager.INTERVAL_YEARLY]; UsageStats packageUsage; if ((packageUsage = yearly.packageStats.get(packageName)) == null) { return -1; } else { - return packageUsage.getLastTimeUsed(); + return packageUsage.getLastTimeSystemUsed(); } } @@ -586,8 +586,11 @@ class UserUsageStatsService { for (int i = 0; i < pkgCount; i++) { final UsageStats usageStats = pkgStats.valueAt(i); pw.printPair("package", usageStats.mPackageName); - pw.printPair("totalTime", formatElapsedTime(usageStats.mTotalTimeInForeground, prettyDates)); + pw.printPair("totalTime", + formatElapsedTime(usageStats.mTotalTimeInForeground, prettyDates)); pw.printPair("lastTime", formatDateTime(usageStats.mLastTimeUsed, prettyDates)); + pw.printPair("lastTimeSystem", + formatDateTime(usageStats.mLastTimeSystemUsed, prettyDates)); pw.printPair("inactiveTime", formatElapsedTime(screenOnTime - usageStats.mBeginIdleTime, prettyDates)); pw.println(); @@ -596,8 +599,7 @@ class UserUsageStatsService { pw.println("configurations"); pw.increaseIndent(); - final ArrayMap<Configuration, ConfigurationStats> configStats = - stats.configurations; + final ArrayMap<Configuration, ConfigurationStats> configStats = stats.configurations; final int configCount = configStats.size(); for (int i = 0; i < configCount; i++) { final ConfigurationStats config = configStats.valueAt(i); @@ -659,8 +661,10 @@ class UserUsageStatsService { return "CONTINUE_PREVIOUS_DAY"; case UsageEvents.Event.CONFIGURATION_CHANGE: return "CONFIGURATION_CHANGE"; - case UsageEvents.Event.INTERACTION: - return "INTERACTION"; + case UsageEvents.Event.SYSTEM_INTERACTION: + return "SYSTEM_INTERACTION"; + case UsageEvents.Event.USER_INTERACTION: + return "USER_INTERACTION"; default: return "UNKNOWN"; } diff --git a/telephony/java/android/telephony/CarrierConfigManager.java b/telephony/java/android/telephony/CarrierConfigManager.java index 6de438c64bff..da0c547cbd6f 100644 --- a/telephony/java/android/telephony/CarrierConfigManager.java +++ b/telephony/java/android/telephony/CarrierConfigManager.java @@ -114,11 +114,6 @@ public class CarrierConfigManager { * (Some carriers require that emergency calls *not* be logged, presumably to avoid the risk of * accidental redialing from the call log UI. This is a good idea, so the default here is * false.) - * <p> - * TODO: on the other hand, it might still be useful to have some record of the emergency calls - * you've made, or to be able to look up the exact date/time of an emergency call. So perhaps we - * <b>should</b> log those calls, but instead fix the call log to disable the "call" button for - * emergency numbers. */ public static final String KEY_ALLOW_EMERGENCY_NUMBERS_IN_CALL_LOG_BOOL = "allow_emergency_numbers_in_call_log_bool"; diff --git a/tests/UsageStatsTest/src/com/android/tests/usagestats/UsageLogActivity.java b/tests/UsageStatsTest/src/com/android/tests/usagestats/UsageLogActivity.java index 8e6daea43367..05cac10f92c6 100644 --- a/tests/UsageStatsTest/src/com/android/tests/usagestats/UsageLogActivity.java +++ b/tests/UsageStatsTest/src/com/android/tests/usagestats/UsageLogActivity.java @@ -28,8 +28,6 @@ import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; -import java.util.ArrayList; - public class UsageLogActivity extends ListActivity implements Runnable { private static final long USAGE_STATS_PERIOD = 1000 * 60 * 60 * 24 * 14; @@ -166,8 +164,8 @@ public class UsageLogActivity extends ListActivity implements Runnable { case UsageEvents.Event.CONFIGURATION_CHANGE: return "Config change"; - case UsageEvents.Event.INTERACTION: - return "Interaction"; + case UsageEvents.Event.USER_INTERACTION: + return "User Interaction"; default: return "Unknown: " + eventType; |