Merge "Introducing "strict project map"." into froyo
diff --git a/Android.mk b/Android.mk
index cecc26a..10b6d67 100644
--- a/Android.mk
+++ b/Android.mk
@@ -117,6 +117,7 @@
core/java/android/hardware/ISensorService.aidl \
core/java/android/net/IConnectivityManager.aidl \
core/java/android/net/INetworkManagementEventObserver.aidl \
+ core/java/android/net/IThrottleManager.aidl \
core/java/android/os/IMessenger.aidl \
core/java/android/os/storage/IMountService.aidl \
core/java/android/os/storage/IMountServiceListener.aidl \
diff --git a/api/current.xml b/api/current.xml
index 21b75eb..8cffff1b 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -34,17 +34,6 @@
visibility="public"
>
</constructor>
-<field name="ACCESS_CACHE_FILESYSTEM"
- type="java.lang.String"
- transient="false"
- volatile="false"
- value=""android.permission.ACCESS_CACHE_FILESYSTEM""
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
<field name="ACCESS_CHECKIN_PROPERTIES"
type="java.lang.String"
transient="false"
@@ -716,17 +705,6 @@
visibility="public"
>
</field>
-<field name="MOVE_PACKAGE"
- type="java.lang.String"
- transient="false"
- volatile="false"
- value=""android.permission.MOVE_PACKAGE""
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
<field name="PERSISTENT_ACTIVITY"
type="java.lang.String"
transient="false"
@@ -25450,6 +25428,17 @@
visibility="public"
>
</field>
+<field name="ENABLE_CAR_MODE_GO_CAR_HOME"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="1"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="MODE_NIGHT_AUTO"
type="int"
transient="false"
@@ -27073,19 +27062,6 @@
deprecated="not deprecated"
visibility="public"
>
-<method name="setKeyPrefix"
- return="void"
- abstract="false"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="keyPrefix" type="java.lang.String">
-</parameter>
-</method>
<method name="writeEntityData"
return="int"
abstract="false"
@@ -27120,28 +27096,6 @@
<exception name="IOException" type="java.io.IOException">
</exception>
</method>
-<field name="OP_DELETE"
- type="int"
- transient="false"
- volatile="false"
- value="2"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
-<field name="OP_UPDATE"
- type="int"
- transient="false"
- volatile="false"
- value="1"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
</class>
<interface name="BackupHelper"
abstract="true"
@@ -72887,6 +72841,17 @@
visibility="public"
>
</field>
+<field name="FOCUS_MODE_EDOF"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value=""edof""
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="FOCUS_MODE_FIXED"
type="java.lang.String"
transient="false"
@@ -72942,6 +72907,17 @@
visibility="public"
>
</field>
+<field name="SCENE_MODE_BARCODE"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value=""barcode""
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="SCENE_MODE_BEACH"
type="java.lang.String"
transient="false"
@@ -89051,7 +89027,7 @@
<method name="getMobileRxBytes"
return="long"
abstract="false"
- native="false"
+ native="true"
synchronized="false"
static="true"
final="false"
@@ -89062,7 +89038,7 @@
<method name="getMobileRxPackets"
return="long"
abstract="false"
- native="false"
+ native="true"
synchronized="false"
static="true"
final="false"
@@ -89073,7 +89049,7 @@
<method name="getMobileTxBytes"
return="long"
abstract="false"
- native="false"
+ native="true"
synchronized="false"
static="true"
final="false"
@@ -89084,7 +89060,7 @@
<method name="getMobileTxPackets"
return="long"
abstract="false"
- native="false"
+ native="true"
synchronized="false"
static="true"
final="false"
@@ -89095,7 +89071,7 @@
<method name="getTotalRxBytes"
return="long"
abstract="false"
- native="false"
+ native="true"
synchronized="false"
static="true"
final="false"
@@ -89106,7 +89082,7 @@
<method name="getTotalRxPackets"
return="long"
abstract="false"
- native="false"
+ native="true"
synchronized="false"
static="true"
final="false"
@@ -89117,7 +89093,7 @@
<method name="getTotalTxBytes"
return="long"
abstract="false"
- native="false"
+ native="true"
synchronized="false"
static="true"
final="false"
@@ -89128,7 +89104,7 @@
<method name="getTotalTxPackets"
return="long"
abstract="false"
- native="false"
+ native="true"
synchronized="false"
static="true"
final="false"
@@ -89139,7 +89115,7 @@
<method name="getUidRxBytes"
return="long"
abstract="false"
- native="false"
+ native="true"
synchronized="false"
static="true"
final="false"
@@ -89152,7 +89128,7 @@
<method name="getUidTxBytes"
return="long"
abstract="false"
- native="false"
+ native="true"
synchronized="false"
static="true"
final="false"
@@ -90881,6 +90857,19 @@
<parameter name="userAgent" type="java.lang.String">
</parameter>
</method>
+<method name="parseDate"
+ return="long"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="dateString" type="java.lang.String">
+</parameter>
+</method>
<field name="DEFAULT_SYNC_MIN_GZIP_BYTES"
type="long"
transient="false"
@@ -90892,38 +90881,6 @@
>
</field>
</class>
-<class name="HttpDateTime"
- extends="java.lang.Object"
- abstract="false"
- static="false"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-<constructor name="HttpDateTime"
- type="android.net.http.HttpDateTime"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</constructor>
-<method name="parse"
- return="java.lang.Long"
- abstract="false"
- native="false"
- synchronized="false"
- static="true"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="timeString" type="java.lang.String">
-</parameter>
-<exception name="IllegalArgumentException" type="java.lang.IllegalArgumentException">
-</exception>
-</method>
-</class>
<class name="SslCertificate"
extends="java.lang.Object"
abstract="false"
diff --git a/cmds/stagefright/Android.mk b/cmds/stagefright/Android.mk
index 52f767e..34648b5 100644
--- a/cmds/stagefright/Android.mk
+++ b/cmds/stagefright/Android.mk
@@ -5,7 +5,8 @@
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
- stagefright.cpp
+ stagefright.cpp \
+ SineSource.cpp
LOCAL_SHARED_LIBRARIES := \
libstagefright libmedia libutils libbinder
diff --git a/cmds/stagefright/stagefright.cpp b/cmds/stagefright/stagefright.cpp
index fec9e1a..4405da6 100644
--- a/cmds/stagefright/stagefright.cpp
+++ b/cmds/stagefright/stagefright.cpp
@@ -20,9 +20,12 @@
#include <string.h>
#include <unistd.h>
+#include "SineSource.h"
+
#include <binder/IServiceManager.h>
#include <binder/ProcessState.h>
#include <media/IMediaPlayerService.h>
+#include <media/stagefright/AudioPlayer.h>
#include <media/stagefright/CachingDataSource.h>
#include <media/stagefright/FileSource.h>
#include <media/stagefright/HTTPDataSource.h>
@@ -42,6 +45,7 @@
static long gMaxNumFrames; // 0 means decode all available.
static long gReproduceBug; // if not -1.
static bool gPreferSoftwareCodec;
+static bool gPlaybackAudio;
static int64_t getNowUs() {
struct timeval tv;
@@ -73,7 +77,20 @@
rawSource->start();
- if (gReproduceBug >= 3 && gReproduceBug <= 5) {
+ if (gPlaybackAudio) {
+ AudioPlayer *player = new AudioPlayer(NULL);
+ player->setSource(rawSource);
+
+ player->start(true /* sourceAlreadyStarted */);
+
+ status_t finalStatus;
+ while (!player->reachedEOS(&finalStatus)) {
+ usleep(100000ll);
+ }
+
+ delete player;
+ player = NULL;
+ } else if (gReproduceBug >= 3 && gReproduceBug <= 5) {
int64_t durationUs;
CHECK(meta->findInt64(kKeyDuration, &durationUs));
@@ -245,6 +262,7 @@
fprintf(stderr, " -p(rofiles) dump decoder profiles supported\n");
fprintf(stderr, " -t(humbnail) extract video thumbnail or album art\n");
fprintf(stderr, " -s(oftware) prefer software codec\n");
+ fprintf(stderr, " -o playback audio\n");
}
int main(int argc, char **argv) {
@@ -258,9 +276,10 @@
gMaxNumFrames = 0;
gReproduceBug = -1;
gPreferSoftwareCodec = false;
+ gPlaybackAudio = false;
int res;
- while ((res = getopt(argc, argv, "han:lm:b:pts")) >= 0) {
+ while ((res = getopt(argc, argv, "han:lm:b:ptso")) >= 0) {
switch (res) {
case 'a':
{
@@ -314,6 +333,12 @@
break;
}
+ case 'o':
+ {
+ gPlaybackAudio = true;
+ break;
+ }
+
case '?':
case 'h':
default:
@@ -325,6 +350,11 @@
}
}
+ if (gPlaybackAudio && !audioOnly) {
+ // This doesn't make any sense if we're decoding the video track.
+ gPlaybackAudio = false;
+ }
+
argc -= optind;
argv += optind;
@@ -456,6 +486,11 @@
dataSource = new FileSource(filename);
}
+ if (dataSource == NULL) {
+ fprintf(stderr, "Unable to create data source.\n");
+ return 1;
+ }
+
bool isJPEG = false;
size_t len = strlen(filename);
@@ -467,10 +502,18 @@
if (isJPEG) {
mediaSource = new JPEGSource(dataSource);
+ } else if (!strncasecmp("sine:", filename, 5)) {
+ char *end;
+ long sampleRate = strtol(filename + 5, &end, 10);
+
+ if (end == filename + 5) {
+ sampleRate = 44100;
+ }
+ mediaSource = new SineSource(sampleRate, 1);
} else {
sp<MediaExtractor> extractor = MediaExtractor::Create(dataSource);
if (extractor == NULL) {
- fprintf(stderr, "could not create data source\n");
+ fprintf(stderr, "could not create extractor.\n");
return -1;
}
@@ -492,6 +535,17 @@
if (!audioOnly && !strncasecmp(mime, "video/", 6)) {
break;
}
+
+ meta = NULL;
+ }
+
+ if (meta == NULL) {
+ fprintf(stderr,
+ "No suitable %s track found. The '-a' option will "
+ "target audio tracks only, the default is to target "
+ "video tracks only.\n",
+ audioOnly ? "audio" : "video");
+ return -1;
}
int64_t thumbTimeUs;
diff --git a/common/java/com/android/common/OperationScheduler.java b/common/java/com/android/common/OperationScheduler.java
index 0a48fe7..1786957 100644
--- a/common/java/com/android/common/OperationScheduler.java
+++ b/common/java/com/android/common/OperationScheduler.java
@@ -17,7 +17,7 @@
package com.android.common;
import android.content.SharedPreferences;
-import android.net.http.HttpDateTime;
+import android.net.http.AndroidHttpClient;
import android.text.format.Time;
import java.util.Map;
@@ -124,7 +124,8 @@
}
/**
- * Compute the time of the next operation. Does not modify any state.
+ * Compute the time of the next operation. Does not modify any state
+ * (unless the clock rolls backwards, in which case timers are reset).
*
* @param options to use for this computation.
* @return the wall clock time ({@link System#currentTimeMillis()}) when the
@@ -143,11 +144,11 @@
// clipped to the current time so we don't languish forever.
int errorCount = mStorage.getInt(PREFIX + "errorCount", 0);
- long now = System.currentTimeMillis();
+ long now = currentTimeMillis();
long lastSuccessTimeMillis = getTimeBefore(PREFIX + "lastSuccessTimeMillis", now);
long lastErrorTimeMillis = getTimeBefore(PREFIX + "lastErrorTimeMillis", now);
long triggerTimeMillis = mStorage.getLong(PREFIX + "triggerTimeMillis", Long.MAX_VALUE);
- long moratoriumSetMillis = mStorage.getLong(PREFIX + "moratoriumSetTimeMillis", 0);
+ long moratoriumSetMillis = getTimeBefore(PREFIX + "moratoriumSetTimeMillis", now);
long moratoriumTimeMillis = getTimeBefore(PREFIX + "moratoriumTimeMillis",
moratoriumSetMillis + options.maxMoratoriumMillis);
@@ -155,9 +156,8 @@
if (options.periodicIntervalMillis > 0) {
time = Math.min(time, lastSuccessTimeMillis + options.periodicIntervalMillis);
}
- if (time >= moratoriumTimeMillis - options.maxMoratoriumMillis) {
- time = Math.max(time, moratoriumTimeMillis);
- }
+
+ time = Math.max(time, moratoriumTimeMillis);
time = Math.max(time, lastSuccessTimeMillis + options.minTriggerMillis);
if (errorCount > 0) {
time = Math.max(time, lastErrorTimeMillis + options.backoffFixedMillis +
@@ -205,7 +205,7 @@
/**
* Request an operation to be performed at a certain time. The actual
* scheduled time may be affected by error backoff logic and defined
- * minimum intervals.
+ * minimum intervals. Use {@link Long#MAX_VALUE} to disable triggering.
*
* @param millis wall clock time ({@link System#currentTimeMillis()}) to
* trigger another operation; 0 to trigger immediately
@@ -218,13 +218,13 @@
* Forbid any operations until after a certain (absolute) time.
* Limited by {@link #Options.maxMoratoriumMillis}.
*
- * @param millis wall clock time ({@link System#currentTimeMillis()}) to
- * wait before attempting any more operations; 0 to remove moratorium
+ * @param millis wall clock time ({@link System#currentTimeMillis()})
+ * when operations should be allowed again; 0 to remove moratorium
*/
public void setMoratoriumTimeMillis(long millis) {
mStorage.edit()
.putLong(PREFIX + "moratoriumTimeMillis", millis)
- .putLong(PREFIX + "moratoriumSetTimeMillis", System.currentTimeMillis())
+ .putLong(PREFIX + "moratoriumSetTimeMillis", currentTimeMillis())
.commit();
}
@@ -239,11 +239,11 @@
public boolean setMoratoriumTimeHttp(String retryAfter) {
try {
long ms = Long.valueOf(retryAfter) * 1000;
- setMoratoriumTimeMillis(ms + System.currentTimeMillis());
+ setMoratoriumTimeMillis(ms + currentTimeMillis());
return true;
} catch (NumberFormatException nfe) {
try {
- setMoratoriumTimeMillis(HttpDateTime.parse(retryAfter));
+ setMoratoriumTimeMillis(AndroidHttpClient.parseDate(retryAfter));
return true;
} catch (IllegalArgumentException iae) {
return false;
@@ -269,13 +269,12 @@
public void onSuccess() {
resetTransientError();
resetPermanentError();
- long now = System.currentTimeMillis();
mStorage.edit()
.remove(PREFIX + "errorCount")
.remove(PREFIX + "lastErrorTimeMillis")
.remove(PREFIX + "permanentError")
.remove(PREFIX + "triggerTimeMillis")
- .putLong(PREFIX + "lastSuccessTimeMillis", now).commit();
+ .putLong(PREFIX + "lastSuccessTimeMillis", currentTimeMillis()).commit();
}
/**
@@ -284,8 +283,7 @@
* purposes.
*/
public void onTransientError() {
- long now = System.currentTimeMillis();
- mStorage.edit().putLong(PREFIX + "lastErrorTimeMillis", now).commit();
+ mStorage.edit().putLong(PREFIX + "lastErrorTimeMillis", currentTimeMillis()).commit();
mStorage.edit().putInt(PREFIX + "errorCount",
mStorage.getInt(PREFIX + "errorCount", 0) + 1).commit();
}
@@ -338,4 +336,13 @@
}
return out.append("]").toString();
}
+
+ /**
+ * Gets the current time. Can be overridden for unit testing.
+ *
+ * @return {@link System#currentTimeMillis()}
+ */
+ protected long currentTimeMillis() {
+ return System.currentTimeMillis();
+ }
}
diff --git a/common/tests/src/com/android/common/OperationSchedulerTest.java b/common/tests/src/com/android/common/OperationSchedulerTest.java
index 866d1a8..955508f 100644
--- a/common/tests/src/com/android/common/OperationSchedulerTest.java
+++ b/common/tests/src/com/android/common/OperationSchedulerTest.java
@@ -22,19 +22,34 @@
import android.test.suitebuilder.annotation.SmallTest;
public class OperationSchedulerTest extends AndroidTestCase {
+ /**
+ * OperationScheduler subclass which uses an artificial time.
+ * Set {@link #timeMillis} to whatever value you like.
+ */
+ private class TimeTravelScheduler extends OperationScheduler {
+ static final long DEFAULT_TIME = 1250146800000L; // 13-Aug-2009, 12:00:00 am
+ public long timeMillis = DEFAULT_TIME;
+
+ @Override
+ protected long currentTimeMillis() { return timeMillis; }
+ public TimeTravelScheduler() { super(getFreshStorage()); }
+ }
+
+ private SharedPreferences getFreshStorage() {
+ SharedPreferences sp = getContext().getSharedPreferences("OperationSchedulerTest", 0);
+ sp.edit().clear().commit();
+ return sp;
+ }
+
@MediumTest
public void testScheduler() throws Exception {
- String name = "OperationSchedulerTest.testScheduler";
- SharedPreferences storage = getContext().getSharedPreferences(name, 0);
- storage.edit().clear().commit();
-
- OperationScheduler scheduler = new OperationScheduler(storage);
+ TimeTravelScheduler scheduler = new TimeTravelScheduler();
OperationScheduler.Options options = new OperationScheduler.Options();
assertEquals(Long.MAX_VALUE, scheduler.getNextTimeMillis(options));
assertEquals(0, scheduler.getLastSuccessTimeMillis());
assertEquals(0, scheduler.getLastAttemptTimeMillis());
- long beforeTrigger = System.currentTimeMillis();
+ long beforeTrigger = scheduler.timeMillis;
scheduler.setTriggerTimeMillis(beforeTrigger + 1000000);
assertEquals(beforeTrigger + 1000000, scheduler.getNextTimeMillis(options));
@@ -51,33 +66,26 @@
assertEquals(beforeTrigger + 1500000, scheduler.getNextTimeMillis(options));
// Backoff interval after an error
- long beforeError = System.currentTimeMillis();
+ long beforeError = (scheduler.timeMillis += 100);
scheduler.onTransientError();
- long afterError = System.currentTimeMillis();
assertEquals(0, scheduler.getLastSuccessTimeMillis());
- assertTrue(beforeError <= scheduler.getLastAttemptTimeMillis());
- assertTrue(afterError >= scheduler.getLastAttemptTimeMillis());
+ assertEquals(beforeError, scheduler.getLastAttemptTimeMillis());
assertEquals(beforeTrigger + 1500000, scheduler.getNextTimeMillis(options));
options.backoffFixedMillis = 1000000;
options.backoffIncrementalMillis = 500000;
- assertTrue(beforeError + 1500000 <= scheduler.getNextTimeMillis(options));
- assertTrue(afterError + 1500000 >= scheduler.getNextTimeMillis(options));
+ assertEquals(beforeError + 1500000, scheduler.getNextTimeMillis(options));
// Two errors: backoff interval increases
- beforeError = System.currentTimeMillis();
+ beforeError = (scheduler.timeMillis += 100);
scheduler.onTransientError();
- afterError = System.currentTimeMillis();
- assertTrue(beforeError <= scheduler.getLastAttemptTimeMillis());
- assertTrue(afterError >= scheduler.getLastAttemptTimeMillis());
- assertTrue(beforeError + 2000000 <= scheduler.getNextTimeMillis(options));
- assertTrue(afterError + 2000000 >= scheduler.getNextTimeMillis(options));
+ assertEquals(beforeError, scheduler.getLastAttemptTimeMillis());
+ assertEquals(beforeError + 2000000, scheduler.getNextTimeMillis(options));
// Reset transient error: no backoff interval
scheduler.resetTransientError();
assertEquals(0, scheduler.getLastSuccessTimeMillis());
assertEquals(beforeTrigger + 1500000, scheduler.getNextTimeMillis(options));
- assertTrue(beforeError <= scheduler.getLastAttemptTimeMillis());
- assertTrue(afterError >= scheduler.getLastAttemptTimeMillis());
+ assertEquals(beforeError, scheduler.getLastAttemptTimeMillis());
// Permanent error holds true even if transient errors are reset
// However, we remember that the transient error was reset...
@@ -89,30 +97,26 @@
assertEquals(beforeTrigger + 1500000, scheduler.getNextTimeMillis(options));
// Success resets the trigger
- long beforeSuccess = System.currentTimeMillis();
+ long beforeSuccess = (scheduler.timeMillis += 100);
scheduler.onSuccess();
- long afterSuccess = System.currentTimeMillis();
- assertTrue(beforeSuccess <= scheduler.getLastAttemptTimeMillis());
- assertTrue(afterSuccess >= scheduler.getLastAttemptTimeMillis());
- assertTrue(beforeSuccess <= scheduler.getLastSuccessTimeMillis());
- assertTrue(afterSuccess >= scheduler.getLastSuccessTimeMillis());
+ assertEquals(beforeSuccess, scheduler.getLastAttemptTimeMillis());
+ assertEquals(beforeSuccess, scheduler.getLastSuccessTimeMillis());
assertEquals(Long.MAX_VALUE, scheduler.getNextTimeMillis(options));
// The moratorium is not reset by success!
- scheduler.setTriggerTimeMillis(beforeSuccess + 500000);
+ scheduler.setTriggerTimeMillis(0);
assertEquals(beforeTrigger + 1500000, scheduler.getNextTimeMillis(options));
scheduler.setMoratoriumTimeMillis(0);
- assertEquals(beforeSuccess + 500000, scheduler.getNextTimeMillis(options));
+ assertEquals(beforeSuccess, scheduler.getNextTimeMillis(options));
// Periodic interval after success
options.periodicIntervalMillis = 250000;
- assertTrue(beforeSuccess + 250000 <= scheduler.getNextTimeMillis(options));
- assertTrue(afterSuccess + 250000 >= scheduler.getNextTimeMillis(options));
+ scheduler.setTriggerTimeMillis(Long.MAX_VALUE);
+ assertEquals(beforeSuccess + 250000, scheduler.getNextTimeMillis(options));
// Trigger minimum is also since the last success
options.minTriggerMillis = 1000000;
- assertTrue(beforeSuccess + 1000000 <= scheduler.getNextTimeMillis(options));
- assertTrue(afterSuccess + 1000000 >= scheduler.getNextTimeMillis(options));
+ assertEquals(beforeSuccess + 1000000, scheduler.getNextTimeMillis(options));
}
@SmallTest
@@ -138,23 +142,19 @@
@SmallTest
public void testMoratoriumWithHttpDate() throws Exception {
- String name = "OperationSchedulerTest.testMoratoriumWithHttpDate";
- SharedPreferences storage = getContext().getSharedPreferences(name, 0);
- storage.edit().clear().commit();
-
- OperationScheduler scheduler = new OperationScheduler(storage);
+ TimeTravelScheduler scheduler = new TimeTravelScheduler();
OperationScheduler.Options options = new OperationScheduler.Options();
- long beforeTrigger = System.currentTimeMillis();
+ long beforeTrigger = scheduler.timeMillis;
scheduler.setTriggerTimeMillis(beforeTrigger + 1000000);
assertEquals(beforeTrigger + 1000000, scheduler.getNextTimeMillis(options));
scheduler.setMoratoriumTimeMillis(beforeTrigger + 2000000);
assertEquals(beforeTrigger + 2000000, scheduler.getNextTimeMillis(options));
- long beforeMoratorium = System.currentTimeMillis();
+ long beforeMoratorium = scheduler.timeMillis;
assertTrue(scheduler.setMoratoriumTimeHttp("3000"));
- long afterMoratorium = System.currentTimeMillis();
+ long afterMoratorium = scheduler.timeMillis;
assertTrue(beforeMoratorium + 3000000 <= scheduler.getNextTimeMillis(options));
assertTrue(afterMoratorium + 3000000 >= scheduler.getNextTimeMillis(options));
@@ -164,4 +164,56 @@
assertFalse(scheduler.setMoratoriumTimeHttp("not actually a date"));
}
+
+ @SmallTest
+ public void testClockRollbackScenario() throws Exception {
+ TimeTravelScheduler scheduler = new TimeTravelScheduler();
+ OperationScheduler.Options options = new OperationScheduler.Options();
+ options.minTriggerMillis = 2000;
+
+ // First, set up a scheduler with reasons to wait: a transient
+ // error with backoff and a moratorium for a few minutes.
+
+ long beforeTrigger = scheduler.timeMillis;
+ long triggerTime = beforeTrigger - 10000000;
+ scheduler.setTriggerTimeMillis(triggerTime);
+ assertEquals(triggerTime, scheduler.getNextTimeMillis(options));
+ assertEquals(0, scheduler.getLastAttemptTimeMillis());
+
+ long beforeSuccess = (scheduler.timeMillis += 100);
+ scheduler.onSuccess();
+ scheduler.setTriggerTimeMillis(triggerTime);
+ assertEquals(beforeSuccess, scheduler.getLastAttemptTimeMillis());
+ assertEquals(beforeSuccess + 2000, scheduler.getNextTimeMillis(options));
+
+ long beforeError = (scheduler.timeMillis += 100);
+ scheduler.onTransientError();
+ assertEquals(beforeError, scheduler.getLastAttemptTimeMillis());
+ assertEquals(beforeError + 5000, scheduler.getNextTimeMillis(options));
+
+ long beforeMoratorium = (scheduler.timeMillis += 100);
+ scheduler.setMoratoriumTimeMillis(beforeTrigger + 1000000);
+ assertEquals(beforeTrigger + 1000000, scheduler.getNextTimeMillis(options));
+
+ // Now set the time back a few seconds.
+ // The moratorium time should still be honored.
+ long beforeRollback = (scheduler.timeMillis = beforeTrigger - 10000);
+ assertEquals(beforeTrigger + 1000000, scheduler.getNextTimeMillis(options));
+
+ // The rollback also moved the last-attempt clock back to the rollback time.
+ assertEquals(scheduler.timeMillis, scheduler.getLastAttemptTimeMillis());
+
+ // But if we set the time back more than a day, the moratorium
+ // resets to the maximum moratorium (a day, by default), exposing
+ // the original trigger time.
+ beforeRollback = (scheduler.timeMillis = beforeTrigger - 100000000);
+ assertEquals(triggerTime, scheduler.getNextTimeMillis(options));
+ assertEquals(beforeRollback, scheduler.getLastAttemptTimeMillis());
+
+ // If we roll forward until after the re-set moratorium, then it expires.
+ scheduler.timeMillis = triggerTime + 5000000;
+ assertEquals(triggerTime, scheduler.getNextTimeMillis(options));
+ assertEquals(beforeRollback, scheduler.getLastAttemptTimeMillis());
+ assertEquals(beforeRollback, scheduler.getLastSuccessTimeMillis());
+ }
}
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index b3223e5..c9096cf 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -145,6 +145,13 @@
public static final int RECENT_WITH_EXCLUDED = 0x0001;
/**
+ * @hide
+ * TODO: Make this public. Provides a list that does not contain any
+ * recent tasks that currently are not available to the user.
+ */
+ public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002;
+
+ /**
* Return a list of the tasks that the user has recently launched, with
* the most recent being first and older ones after in order.
*
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index a556a32..fd84859 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -150,13 +150,13 @@
public static IPackageManager getPackageManager() {
if (sPackageManager != null) {
- //Log.v("PackageManager", "returning cur default = " + sPackageManager);
+ //Slog.v("PackageManager", "returning cur default = " + sPackageManager);
return sPackageManager;
}
IBinder b = ServiceManager.getService("package");
- //Log.v("PackageManager", "default service binder = " + b);
+ //Slog.v("PackageManager", "default service binder = " + b);
sPackageManager = IPackageManager.Stub.asInterface(b);
- //Log.v("PackageManager", "default service = " + sPackageManager);
+ //Slog.v("PackageManager", "default service = " + sPackageManager);
return sPackageManager;
}
@@ -170,7 +170,7 @@
}
DisplayMetrics metrics = mDisplayMetrics = new DisplayMetrics();
mDisplay.getMetrics(metrics);
- //Log.i("foo", "New metrics: w=" + metrics.widthPixels + " h="
+ //Slog.i("foo", "New metrics: w=" + metrics.widthPixels + " h="
// + metrics.heightPixels + " den=" + metrics.density
// + " xdpi=" + metrics.xdpi + " ydpi=" + metrics.ydpi);
return metrics;
@@ -189,14 +189,14 @@
synchronized (mPackages) {
// Resources is app scale dependent.
if (false) {
- Log.w(TAG, "getTopLevelResources: " + resDir + " / "
+ Slog.w(TAG, "getTopLevelResources: " + resDir + " / "
+ compInfo.applicationScale);
}
WeakReference<Resources> wr = mActiveResources.get(key);
r = wr != null ? wr.get() : null;
if (r != null && r.getAssets().isUpToDate()) {
if (false) {
- Log.w(TAG, "Returning cached resources " + r + " " + resDir
+ Slog.w(TAG, "Returning cached resources " + r + " " + resDir
+ ": appScale=" + r.getCompatibilityInfo().applicationScale);
}
return r;
@@ -204,7 +204,7 @@
}
//if (r != null) {
- // Log.w(TAG, "Throwing away out-of-date resources!!!! "
+ // Slog.w(TAG, "Throwing away out-of-date resources!!!! "
// + r + " " + resDir);
//}
@@ -213,11 +213,11 @@
return null;
}
- //Log.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics);
+ //Slog.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics);
DisplayMetrics metrics = getDisplayMetricsLocked(false);
r = new Resources(assets, metrics, getConfiguration(), compInfo);
if (false) {
- Log.i(TAG, "Created app resources " + resDir + " " + r + ": "
+ Slog.i(TAG, "Created app resources " + resDir + " " + r + ": "
+ r.getConfiguration() + " appScale="
+ r.getCompatibilityInfo().applicationScale);
}
@@ -306,7 +306,7 @@
mSystemContext.getResources().updateConfiguration(
mainThread.getConfiguration(),
mainThread.getDisplayMetricsLocked(false));
- //Log.i(TAG, "Created system resources "
+ //Slog.i(TAG, "Created system resources "
// + mSystemContext.getResources() + ": "
// + mSystemContext.getResources().getConfiguration());
}
@@ -465,7 +465,7 @@
* create the class loader.
*/
- if (localLOGV) Log.v(TAG, "Class path: " + zip);
+ if (localLOGV) Slog.v(TAG, "Class path: " + zip);
mClassLoader =
ApplicationLoaders.getDefault().getClassLoader(
@@ -692,7 +692,7 @@
}
}
mUnregisteredReceivers.remove(context);
- //Log.i(TAG, "Receiver registrations: " + mReceivers);
+ //Slog.i(TAG, "Receiver registrations: " + mReceivers);
HashMap<ServiceConnection, ServiceDispatcher> smap =
mServices.remove(context);
if (smap != null) {
@@ -714,7 +714,7 @@
}
}
mUnboundServices.remove(context);
- //Log.i(TAG, "Service registrations: " + mServices);
+ //Slog.i(TAG, "Service registrations: " + mServices);
}
public IIntentReceiver getReceiverDispatcher(BroadcastReceiver r,
@@ -810,8 +810,8 @@
ReceiverDispatcher rd = mDispatcher.get();
if (DEBUG_BROADCAST) {
int seq = intent.getIntExtra("seq", -1);
- Log.i(TAG, "Receiving broadcast " + intent.getAction() + " seq=" + seq
- + " to " + rd);
+ Slog.i(TAG, "Receiving broadcast " + intent.getAction() + " seq=" + seq
+ + " to " + (rd != null ? rd.mReceiver : null));
}
if (rd != null) {
rd.performReceive(intent, resultCode, data, extras,
@@ -821,9 +821,8 @@
// receiver in this process, but before it could be delivered the
// receiver was unregistered. Acknowledge the broadcast on its
// behalf so that the system's broadcast sequence can continue.
- if (DEBUG_BROADCAST) {
- Log.i(TAG, "Broadcast to unregistered receiver");
- }
+ if (DEBUG_BROADCAST) Slog.i(TAG,
+ "Finishing broadcast to unregistered receiver");
IActivityManager mgr = ActivityManagerNative.getDefault();
try {
mgr.finishReceiver(this, resultCode, data, extras, false);
@@ -855,16 +854,29 @@
BroadcastReceiver receiver = mReceiver;
if (DEBUG_BROADCAST) {
int seq = mCurIntent.getIntExtra("seq", -1);
- Log.i(TAG, "Dispatching broadcast " + mCurIntent.getAction()
+ Slog.i(TAG, "Dispatching broadcast " + mCurIntent.getAction()
+ " seq=" + seq + " to " + mReceiver);
+ Slog.i(TAG, " mRegistered=" + mRegistered
+ + " mCurOrdered=" + mCurOrdered);
}
- if (receiver == null) {
- return;
- }
-
+
IActivityManager mgr = ActivityManagerNative.getDefault();
Intent intent = mCurIntent;
mCurIntent = null;
+
+ if (receiver == null) {
+ if (mRegistered && mCurOrdered) {
+ try {
+ if (DEBUG_BROADCAST) Slog.i(TAG,
+ "Finishing null broadcast to " + mReceiver);
+ mgr.finishReceiver(mIIntentReceiver,
+ mCurCode, mCurData, mCurMap, false);
+ } catch (RemoteException ex) {
+ }
+ }
+ return;
+ }
+
try {
ClassLoader cl = mReceiver.getClass().getClassLoader();
intent.setExtrasClassLoader(cl);
@@ -880,6 +892,8 @@
} catch (Exception e) {
if (mRegistered && mCurOrdered) {
try {
+ if (DEBUG_BROADCAST) Slog.i(TAG,
+ "Finishing failed broadcast to " + mReceiver);
mgr.finishReceiver(mIIntentReceiver,
mCurCode, mCurData, mCurMap, false);
} catch (RemoteException ex) {
@@ -894,6 +908,8 @@
}
if (mRegistered && mCurOrdered) {
try {
+ if (DEBUG_BROADCAST) Slog.i(TAG,
+ "Finishing broadcast to " + mReceiver);
mgr.finishReceiver(mIIntentReceiver,
receiver.getResultCode(),
receiver.getResultData(),
@@ -961,7 +977,7 @@
String data, Bundle extras, boolean ordered, boolean sticky) {
if (DEBUG_BROADCAST) {
int seq = intent.getIntExtra("seq", -1);
- Log.i(TAG, "Enqueueing broadcast " + intent.getAction() + " seq=" + seq
+ Slog.i(TAG, "Enqueueing broadcast " + intent.getAction() + " seq=" + seq
+ " to " + mReceiver);
}
Args args = new Args();
@@ -972,9 +988,11 @@
args.mCurOrdered = ordered;
args.mCurSticky = sticky;
if (!mActivityThread.post(args)) {
- if (mRegistered) {
+ if (mRegistered && ordered) {
IActivityManager mgr = ActivityManagerNative.getDefault();
try {
+ if (DEBUG_BROADCAST) Slog.i(TAG,
+ "Finishing sync broadcast to " + mReceiver);
mgr.finishReceiver(mIIntentReceiver, args.mCurCode,
args.mCurData, args.mCurMap, false);
} catch (RemoteException ex) {
@@ -2133,7 +2151,7 @@
IActivityManager am = ActivityManagerNative.getDefault();
ActivityRecord prev;
do {
- if (localLOGV) Log.v(
+ if (localLOGV) Slog.v(
TAG, "Reporting idle of " + a +
" finished=" +
(a.activity != null ? a.activity.mFinished : false));
@@ -2252,7 +2270,7 @@
ref = mResourcePackages.get(packageName);
}
PackageInfo packageInfo = ref != null ? ref.get() : null;
- //Log.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo);
+ //Slog.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo);
if (packageInfo != null && (packageInfo.mResources == null
|| packageInfo.mResources.getAssets().isUpToDate())) {
if (packageInfo.isSecurityViolation()
@@ -2319,7 +2337,7 @@
PackageInfo packageInfo = ref != null ? ref.get() : null;
if (packageInfo == null || (packageInfo.mResources != null
&& !packageInfo.mResources.getAssets().isUpToDate())) {
- if (localLOGV) Log.v(TAG, (includeCode ? "Loading code package "
+ if (localLOGV) Slog.v(TAG, (includeCode ? "Loading code package "
: "Loading resource-only package ") + aInfo.packageName
+ " (in " + (mBoundApplication != null
? mBoundApplication.processName : null)
@@ -2402,7 +2420,7 @@
context.getResources().updateConfiguration(
getConfiguration(), getDisplayMetricsLocked(false));
mSystemContext = context;
- //Log.i(TAG, "Created system resources " + context.getResources()
+ //Slog.i(TAG, "Created system resources " + context.getResources()
// + ": " + context.getResources().getConfiguration());
}
}
@@ -2442,10 +2460,10 @@
void doGcIfNeeded() {
mGcIdlerScheduled = false;
final long now = SystemClock.uptimeMillis();
- //Log.i(TAG, "**** WE MIGHT WANT TO GC: then=" + Binder.getLastGcTime()
+ //Slog.i(TAG, "**** WE MIGHT WANT TO GC: then=" + Binder.getLastGcTime()
// + "m now=" + now);
if ((BinderInternal.getLastGcTime()+MIN_TIME_BETWEEN_GCS) < now) {
- //Log.i(TAG, "**** WE DO, WE DO WANT TO GC!");
+ //Slog.i(TAG, "**** WE DO, WE DO WANT TO GC!");
BinderInternal.forceGc("bg");
}
}
@@ -2481,7 +2499,7 @@
} else {
name = "(Intent " + intent + ").getComponent() returned null";
}
- Log.v(TAG, "Performing launch: action=" + intent.getAction()
+ Slog.v(TAG, "Performing launch: action=" + intent.getAction()
+ ", comp=" + name
+ ", token=" + token);
}
@@ -2495,7 +2513,7 @@
public final void sendActivityResult(
IBinder token, String id, int requestCode,
int resultCode, Intent data) {
- if (DEBUG_RESULTS) Log.v(TAG, "sendActivityResult: id=" + id
+ if (DEBUG_RESULTS) Slog.v(TAG, "sendActivityResult: id=" + id
+ " req=" + requestCode + " res=" + resultCode + " data=" + data);
ArrayList<ResultInfo> list = new ArrayList<ResultInfo>();
list.add(new ResultInfo(id, requestCode, resultCode, data));
@@ -2514,7 +2532,7 @@
private final void queueOrSendMessage(int what, Object obj, int arg1, int arg2) {
synchronized (this) {
- if (localLOGV) Log.v(
+ if (localLOGV) Slog.v(
TAG, "SCHEDULE " + what + " " + mH.codeToString(what)
+ ": " + arg1 + " / " + obj);
Message msg = Message.obtain();
@@ -2576,8 +2594,8 @@
try {
Application app = r.packageInfo.makeApplication(false, mInstrumentation);
- if (localLOGV) Log.v(TAG, "Performing launch of " + r);
- if (localLOGV) Log.v(
+ if (localLOGV) Slog.v(TAG, "Performing launch of " + r);
+ if (localLOGV) Slog.v(
TAG, r + ": app=" + app
+ ", appName=" + app.getPackageName()
+ ", pkg=" + r.packageInfo.getPackageName()
@@ -2590,7 +2608,7 @@
appContext.setOuterContext(activity);
CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager());
Configuration config = new Configuration(mConfiguration);
- if (DEBUG_CONFIGURATION) Log.v(TAG, "Launching activity "
+ if (DEBUG_CONFIGURATION) Slog.v(TAG, "Launching activity "
+ r.activityInfo.name + " with config " + config);
activity.attach(appContext, this, getInstrumentation(), r.token,
r.ident, app, r.intent, r.activityInfo, title, r.parent,
@@ -2659,7 +2677,7 @@
// we are back active so skip it.
unscheduleGcIdler();
- if (localLOGV) Log.v(
+ if (localLOGV) Slog.v(
TAG, "Handling launch of " + r);
Activity a = performLaunchActivity(r, customIntent);
@@ -2765,6 +2783,8 @@
receiver = (BroadcastReceiver)cl.loadClass(component).newInstance();
} catch (Exception e) {
try {
+ if (DEBUG_BROADCAST) Slog.i(TAG,
+ "Finishing failed broadcast to " + data.intent.getComponent());
mgr.finishReceiver(mAppThread.asBinder(), data.resultCode,
data.resultData, data.resultExtras, data.resultAbort);
} catch (RemoteException ex) {
@@ -2777,7 +2797,7 @@
try {
Application app = packageInfo.makeApplication(false, mInstrumentation);
- if (localLOGV) Log.v(
+ if (localLOGV) Slog.v(
TAG, "Performing receive of " + data.intent
+ ": app=" + app
+ ", appName=" + app.getPackageName()
@@ -2794,6 +2814,8 @@
data.intent);
} catch (Exception e) {
try {
+ if (DEBUG_BROADCAST) Slog.i(TAG,
+ "Finishing failed broadcast to " + data.intent.getComponent());
mgr.finishReceiver(mAppThread.asBinder(), data.resultCode,
data.resultData, data.resultExtras, data.resultAbort);
} catch (RemoteException ex) {
@@ -2807,11 +2829,15 @@
try {
if (data.sync) {
+ if (DEBUG_BROADCAST) Slog.i(TAG,
+ "Finishing ordered broadcast to " + data.intent.getComponent());
mgr.finishReceiver(
mAppThread.asBinder(), receiver.getResultCode(),
receiver.getResultData(), receiver.getResultExtras(false),
receiver.getAbortBroadcast());
} else {
+ if (DEBUG_BROADCAST) Slog.i(TAG,
+ "Finishing broadcast to " + data.intent.getComponent());
mgr.finishReceiver(mAppThread.asBinder(), 0, null, null, false);
}
} catch (RemoteException ex) {
@@ -2820,7 +2846,7 @@
// Instantiate a BackupAgent and tell it that it's alive
private final void handleCreateBackupAgent(CreateBackupAgentData data) {
- if (DEBUG_BACKUP) Log.v(TAG, "handleCreateBackupAgent: " + data);
+ if (DEBUG_BACKUP) Slog.v(TAG, "handleCreateBackupAgent: " + data);
// no longer idle; we have backup work to do
unscheduleGcIdler();
@@ -2829,7 +2855,7 @@
PackageInfo packageInfo = getPackageInfoNoCheck(data.appInfo);
String packageName = packageInfo.mPackageName;
if (mBackupAgents.get(packageName) != null) {
- Log.d(TAG, "BackupAgent " + " for " + packageName
+ Slog.d(TAG, "BackupAgent " + " for " + packageName
+ " already exists");
return;
}
@@ -2851,7 +2877,7 @@
agent = (BackupAgent) cl.loadClass(data.appInfo.backupAgentName).newInstance();
// set up the agent's context
- if (DEBUG_BACKUP) Log.v(TAG, "Initializing BackupAgent "
+ if (DEBUG_BACKUP) Slog.v(TAG, "Initializing BackupAgent "
+ data.appInfo.backupAgentName);
ContextImpl context = new ContextImpl();
@@ -2886,7 +2912,7 @@
// Tear down a BackupAgent
private final void handleDestroyBackupAgent(CreateBackupAgentData data) {
- if (DEBUG_BACKUP) Log.v(TAG, "handleDestroyBackupAgent: " + data);
+ if (DEBUG_BACKUP) Slog.v(TAG, "handleDestroyBackupAgent: " + data);
PackageInfo packageInfo = getPackageInfoNoCheck(data.appInfo);
String packageName = packageInfo.mPackageName;
@@ -2924,7 +2950,7 @@
}
try {
- if (localLOGV) Log.v(TAG, "Creating service " + data.info.name);
+ if (localLOGV) Slog.v(TAG, "Creating service " + data.info.name);
ContextImpl context = new ContextImpl();
context.init(packageInfo, null, this);
@@ -3049,7 +3075,7 @@
Service s = mServices.remove(token);
if (s != null) {
try {
- if (localLOGV) Log.v(TAG, "Destroying service " + s);
+ if (localLOGV) Slog.v(TAG, "Destroying service " + s);
s.onDestroy();
Context context = s.getBaseContext();
if (context instanceof ContextImpl) {
@@ -3070,13 +3096,13 @@
}
}
}
- //Log.i(TAG, "Running services: " + mServices);
+ //Slog.i(TAG, "Running services: " + mServices);
}
public final ActivityRecord performResumeActivity(IBinder token,
boolean clearHide) {
ActivityRecord r = mActivities.get(token);
- if (localLOGV) Log.v(TAG, "Performing resume of " + r
+ if (localLOGV) Slog.v(TAG, "Performing resume of " + r
+ " finished=" + r.activity.mFinished);
if (r != null && !r.activity.mFinished) {
if (clearHide) {
@@ -3122,7 +3148,7 @@
if (r != null) {
final Activity a = r.activity;
- if (localLOGV) Log.v(
+ if (localLOGV) Slog.v(
TAG, "Resume " + r + " started activity: " +
a.mStartedActivity + ", hideForNow: " + r.hideForNow
+ ", finished: " + a.mFinished);
@@ -3159,7 +3185,7 @@
// we started another activity, then don't yet make the
// window visible.
} else if (!willBeVisible) {
- if (localLOGV) Log.v(
+ if (localLOGV) Slog.v(
TAG, "Launch " + r + " mStartedActivity set");
r.hideForNow = true;
}
@@ -3169,12 +3195,12 @@
if (!r.activity.mFinished && willBeVisible
&& r.activity.mDecor != null && !r.hideForNow) {
if (r.newConfig != null) {
- if (DEBUG_CONFIGURATION) Log.v(TAG, "Resuming activity "
+ if (DEBUG_CONFIGURATION) Slog.v(TAG, "Resuming activity "
+ r.activityInfo.name + " with newConfig " + r.newConfig);
performConfigurationChanged(r.activity, r.newConfig);
r.newConfig = null;
}
- if (localLOGV) Log.v(TAG, "Resuming " + r + " with isForward="
+ if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward="
+ isForward);
WindowManager.LayoutParams l = r.window.getAttributes();
if ((l.softInputMode
@@ -3198,7 +3224,7 @@
r.nextIdle = mNewActivities;
mNewActivities = r;
- if (localLOGV) Log.v(
+ if (localLOGV) Slog.v(
TAG, "Scheduling idle handler for " + r);
Looper.myQueue().addIdleHandler(new Idler());
@@ -3256,7 +3282,7 @@
boolean userLeaving, int configChanges) {
ActivityRecord r = mActivities.get(token);
if (r != null) {
- //Log.v(TAG, "userLeaving=" + userLeaving + " handling pause of " + r);
+ //Slog.v(TAG, "userLeaving=" + userLeaving + " handling pause of " + r);
if (userLeaving) {
performUserLeavingActivity(r);
}
@@ -3351,7 +3377,7 @@
private final void performStopActivityInner(ActivityRecord r,
StopInfo info, boolean keepShown) {
- if (localLOGV) Log.v(TAG, "Performing stop of " + r);
+ if (localLOGV) Slog.v(TAG, "Performing stop of " + r);
if (r != null) {
if (!keepShown && r.stopped) {
if (r.activity.mFinished) {
@@ -3412,7 +3438,7 @@
}
}
if (r.newConfig != null) {
- if (DEBUG_CONFIGURATION) Log.v(TAG, "Updating activity vis "
+ if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis "
+ r.activityInfo.name + " with new config " + r.newConfig);
performConfigurationChanged(r.activity, r.newConfig);
r.newConfig = null;
@@ -3434,7 +3460,7 @@
StopInfo info = new StopInfo();
performStopActivityInner(r, info, show);
- if (localLOGV) Log.v(
+ if (localLOGV) Slog.v(
TAG, "Finishing stop of " + r + ": show=" + show
+ " win=" + r.window);
@@ -3469,7 +3495,7 @@
r.stopped = false;
}
if (r.activity.mDecor != null) {
- if (Config.LOGV) Log.v(
+ if (Config.LOGV) Slog.v(
TAG, "Handle window " + r + " visibility: " + show);
updateVisibility(r, show);
}
@@ -3483,7 +3509,7 @@
if (ri.mData != null) {
ri.mData.setExtrasClassLoader(r.activity.getClassLoader());
}
- if (DEBUG_RESULTS) Log.v(TAG,
+ if (DEBUG_RESULTS) Slog.v(TAG,
"Delivering result to activity " + r + " : " + ri);
r.activity.dispatchActivityResult(ri.mResultWho,
ri.mRequestCode, ri.mResultCode, ri.mData);
@@ -3500,7 +3526,7 @@
private final void handleSendResult(ResultData res) {
ActivityRecord r = mActivities.get(res.token);
- if (DEBUG_RESULTS) Log.v(TAG, "Handling send result to " + r);
+ if (DEBUG_RESULTS) Slog.v(TAG, "Handling send result to " + r);
if (r != null) {
final boolean resumed = !r.paused;
if (!r.activity.mFinished && r.activity.mDecor != null
@@ -3545,7 +3571,7 @@
private final ActivityRecord performDestroyActivity(IBinder token, boolean finishing,
int configChanges, boolean getNonConfigInstance) {
ActivityRecord r = mActivities.get(token);
- if (localLOGV) Log.v(TAG, "Performing finish of " + r);
+ if (localLOGV) Slog.v(TAG, "Performing finish of " + r);
if (r != null) {
r.activity.mConfigChangeFlags |= configChanges;
if (finishing) {
@@ -3695,7 +3721,7 @@
Configuration changedConfig = null;
- if (DEBUG_CONFIGURATION) Log.v(TAG, "Relaunching activity "
+ if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity "
+ tmp.token + " with configChanges=0x"
+ Integer.toHexString(configChanges));
@@ -3717,7 +3743,7 @@
}
if (tmp == null) {
- if (DEBUG_CONFIGURATION) Log.v(TAG, "Abort, activity not relaunching!");
+ if (DEBUG_CONFIGURATION) Slog.v(TAG, "Abort, activity not relaunching!");
return;
}
@@ -3741,7 +3767,7 @@
}
}
- if (DEBUG_CONFIGURATION) Log.v(TAG, "Relaunching activity "
+ if (DEBUG_CONFIGURATION) Slog.v(TAG, "Relaunching activity "
+ tmp.token + ": changedConfig=" + changedConfig);
// If there was a pending configuration change, execute it first.
@@ -3750,7 +3776,7 @@
}
ActivityRecord r = mActivities.get(tmp.token);
- if (DEBUG_CONFIGURATION) Log.v(TAG, "Handling relaunch of " + r);
+ if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handling relaunch of " + r);
if (r == null) {
return;
}
@@ -3836,7 +3862,7 @@
// the activity manager may, before then, decide the
// activity needs to be destroyed to handle its new
// configuration.
- if (DEBUG_CONFIGURATION) Log.v(TAG, "Setting activity "
+ if (DEBUG_CONFIGURATION) Slog.v(TAG, "Setting activity "
+ ar.activityInfo.name + " newConfig=" + newConfig);
ar.newConfig = newConfig;
}
@@ -3895,7 +3921,7 @@
}
}
- if (DEBUG_CONFIGURATION) Log.v(TAG, "Config callback " + cb
+ if (DEBUG_CONFIGURATION) Slog.v(TAG, "Config callback " + cb
+ ": shouldChangeConfig=" + shouldChangeConfig);
if (shouldChangeConfig) {
cb.onConfigurationChanged(config);
@@ -3917,7 +3943,7 @@
mResConfiguration = new Configuration();
}
if (!mResConfiguration.isOtherSeqNewer(config)) {
- if (DEBUG_CONFIGURATION) Log.v(TAG, "Skipping new config: curSeq="
+ if (DEBUG_CONFIGURATION) Slog.v(TAG, "Skipping new config: curSeq="
+ mResConfiguration.seq + ", newSeq=" + config.seq);
return false;
}
@@ -3932,7 +3958,7 @@
Resources.updateSystemConfiguration(config, dm);
ContextImpl.ApplicationPackageManager.configurationChanged();
- //Log.i(TAG, "Configuration changed in " + currentPackageName());
+ //Slog.i(TAG, "Configuration changed in " + currentPackageName());
Iterator<WeakReference<Resources>> it =
mActiveResources.values().iterator();
@@ -3942,13 +3968,13 @@
WeakReference<Resources> v = it.next();
Resources r = v.get();
if (r != null) {
- if (DEBUG_CONFIGURATION) Log.v(TAG, "Changing resources "
+ if (DEBUG_CONFIGURATION) Slog.v(TAG, "Changing resources "
+ r + " config to: " + config);
r.updateConfiguration(config, dm);
- //Log.i(TAG, "Updated app resources " + v.getKey()
+ //Slog.i(TAG, "Updated app resources " + v.getKey()
// + " " + r + ": " + r.getConfiguration());
} else {
- //Log.i(TAG, "Removing old resources " + v.getKey());
+ //Slog.i(TAG, "Removing old resources " + v.getKey());
it.remove();
}
}
@@ -3972,7 +3998,7 @@
return;
}
- if (DEBUG_CONFIGURATION) Log.v(TAG, "Handle configuration changed: "
+ if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle configuration changed: "
+ config);
applyConfigurationToResourcesLocked(config);
@@ -4002,7 +4028,7 @@
return;
}
- if (DEBUG_CONFIGURATION) Log.v(TAG, "Handle activity config changed: "
+ if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: "
+ r.activityInfo.name);
performConfigurationChanged(r.activity, mConfiguration);
@@ -4095,7 +4121,7 @@
// XXX should have option to change the port.
Debug.changeDebugPort(8100);
if (data.debugMode == IApplicationThread.DEBUG_WAIT) {
- Log.w(TAG, "Application " + data.info.getPackageName()
+ Slog.w(TAG, "Application " + data.info.getPackageName()
+ " is waiting for the debugger on port 8100...");
IActivityManager mgr = ActivityManagerNative.getDefault();
@@ -4112,7 +4138,7 @@
}
} else {
- Log.w(TAG, "Application " + data.info.getPackageName()
+ Slog.w(TAG, "Application " + data.info.getPackageName()
+ " can be debugged on port 8100...");
}
}
@@ -4208,7 +4234,7 @@
if (mBoundApplication.profileFile != null && mBoundApplication.handlingProfiling) {
Debug.stopMethodTracing();
}
- //Log.i(TAG, "am: " + ActivityManagerNative.getDefault()
+ //Slog.i(TAG, "am: " + ActivityManagerNative.getDefault()
// + ", app thr: " + mAppThread);
try {
am.finishInstrumentation(mAppThread, resultCode, results);
@@ -4275,12 +4301,12 @@
IContentProvider prov = installProvider(context, holder.provider,
holder.info, true);
- //Log.i(TAG, "noReleaseNeeded=" + holder.noReleaseNeeded);
+ //Slog.i(TAG, "noReleaseNeeded=" + holder.noReleaseNeeded);
if (holder.noReleaseNeeded || holder.provider == null) {
// We are not going to release the provider if it is an external
// provider that doesn't care about being released, or if it is
// a local provider running in this process.
- //Log.i(TAG, "*** NO RELEASE NEEDED");
+ //Slog.i(TAG, "*** NO RELEASE NEEDED");
synchronized(mProviderMap) {
mProviderRefCountMap.put(prov.asBinder(), new ProviderRefCount(10000));
}
@@ -4312,7 +4338,7 @@
synchronized(mProviderMap) {
ProviderRefCount prc = mProviderRefCountMap.get(jBinder);
if(prc == null) {
- if(localLOGV) Log.v(TAG, "releaseProvider::Weird shouldnt be here");
+ if(localLOGV) Slog.v(TAG, "releaseProvider::Weird shouldnt be here");
return false;
} else {
prc.count--;
@@ -4344,7 +4370,7 @@
if (name != null) {
try {
- if(localLOGV) Log.v(TAG, "removeProvider::Invoking " +
+ if(localLOGV) Slog.v(TAG, "removeProvider::Invoking " +
"ActivityManagerNative.removeContentProvider(" + name);
ActivityManagerNative.getDefault().removeContentProvider(
getApplicationThread(), name);
@@ -4370,10 +4396,10 @@
if (myBinder == providerBinder) {
//find if its published by this process itself
if(pr.mLocalProvider != null) {
- if(localLOGV) Log.i(TAG, "removeProvider::found local provider returning");
+ if(localLOGV) Slog.i(TAG, "removeProvider::found local provider returning");
return name;
}
- if(localLOGV) Log.v(TAG, "removeProvider::Not local provider Unlinking " +
+ if(localLOGV) Slog.v(TAG, "removeProvider::Not local provider Unlinking " +
"death recipient");
//content provider is in another process
myBinder.unlinkToDeath(pr, 0);
@@ -4392,7 +4418,7 @@
synchronized(mProviderMap) {
ProviderRecord pr = mProviderMap.get(name);
if (pr.mProvider.asBinder() == provider.asBinder()) {
- Log.i(TAG, "Removing dead content provider: " + name);
+ Slog.i(TAG, "Removing dead content provider: " + name);
ProviderRecord removed = mProviderMap.remove(name);
if (removed != null) {
removed.mProvider.asBinder().unlinkToDeath(removed, 0);
@@ -4404,7 +4430,7 @@
final void removeDeadProviderLocked(String name, IContentProvider provider) {
ProviderRecord pr = mProviderMap.get(name);
if (pr.mProvider.asBinder() == provider.asBinder()) {
- Log.i(TAG, "Removing dead content provider: " + name);
+ Slog.i(TAG, "Removing dead content provider: " + name);
ProviderRecord removed = mProviderMap.remove(name);
if (removed != null) {
removed.mProvider.asBinder().unlinkToDeath(removed, 0);
@@ -4417,7 +4443,7 @@
ContentProvider localProvider = null;
if (provider == null) {
if (noisy) {
- Log.d(TAG, "Loading provider " + info.authority + ": "
+ Slog.d(TAG, "Loading provider " + info.authority + ": "
+ info.name);
}
Context c = null;
@@ -4452,7 +4478,7 @@
info.applicationInfo.sourceDir);
return null;
}
- if (Config.LOGV) Log.v(
+ if (Config.LOGV) Slog.v(
TAG, "Instantiating local provider " + info.name);
// XXX Need to create the correct context for this provider.
localProvider.attachInfo(c, info);
@@ -4465,7 +4491,7 @@
return null;
}
} else if (localLOGV) {
- Log.v(TAG, "Installing external provider " + info.authority + ": "
+ Slog.v(TAG, "Installing external provider " + info.authority + ": "
+ info.name);
}
@@ -4586,6 +4612,6 @@
String name = (thread.mInitialApplication != null)
? thread.mInitialApplication.getPackageName()
: "<unknown>";
- Log.i(TAG, "Main thread of " + name + " is now exiting");
+ Slog.i(TAG, "Main thread of " + name + " is now exiting");
}
}
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index 950f34f..fd0edaa 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -67,6 +67,8 @@
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.net.IConnectivityManager;
+import android.net.ThrottleManager;
+import android.net.IThrottleManager;
import android.net.Uri;
import android.net.wifi.IWifiManager;
import android.net.wifi.WifiManager;
@@ -164,6 +166,7 @@
private static AlarmManager sAlarmManager;
private static PowerManager sPowerManager;
private static ConnectivityManager sConnectivityManager;
+ private static ThrottleManager sThrottleManager;
private static WifiManager sWifiManager;
private static LocationManager sLocationManager;
private static final HashMap<File, SharedPreferencesImpl> sSharedPrefs =
@@ -793,7 +796,7 @@
scheduler = mMainThread.getHandler();
}
rd = new ActivityThread.PackageInfo.ReceiverDispatcher(
- receiver, context, scheduler, null, false).getIIntentReceiver();
+ receiver, context, scheduler, null, true).getIIntentReceiver();
}
}
try {
@@ -929,6 +932,8 @@
return getPowerManager();
} else if (CONNECTIVITY_SERVICE.equals(name)) {
return getConnectivityManager();
+ } else if (THROTTLE_SERVICE.equals(name)) {
+ return getThrottleManager();
} else if (WIFI_SERVICE.equals(name)) {
return getWifiManager();
} else if (NOTIFICATION_SERVICE.equals(name)) {
@@ -1028,6 +1033,18 @@
return sConnectivityManager;
}
+ private ThrottleManager getThrottleManager()
+ {
+ synchronized (sSync) {
+ if (sThrottleManager == null) {
+ IBinder b = ServiceManager.getService(THROTTLE_SERVICE);
+ IThrottleManager service = IThrottleManager.Stub.asInterface(b);
+ sThrottleManager = new ThrottleManager(service);
+ }
+ }
+ return sThrottleManager;
+ }
+
private WifiManager getWifiManager()
{
synchronized (sSync) {
diff --git a/core/java/android/app/IUiModeManager.aidl b/core/java/android/app/IUiModeManager.aidl
index 7b668d2..7e9873e 100644
--- a/core/java/android/app/IUiModeManager.aidl
+++ b/core/java/android/app/IUiModeManager.aidl
@@ -25,7 +25,7 @@
* Enables the car mode. Only the system can do this.
* @hide
*/
- void enableCarMode();
+ void enableCarMode(int flags);
/**
* Disables the car mode.
diff --git a/core/java/android/app/UiModeManager.java b/core/java/android/app/UiModeManager.java
index a76dfb1..95451d6 100644
--- a/core/java/android/app/UiModeManager.java
+++ b/core/java/android/app/UiModeManager.java
@@ -116,13 +116,13 @@
}
/**
- * Flag for use with {@link #disableCarMode(int)}: go to the normal
- * home activity as part of the disable. Disabling this way ensures
- * a clean transition between the current activity (in car mode) and
- * the original home activity (which was typically last running without
- * being in car mode).
+ * Flag for use with {@link #enableCarMode(int)}: go to the car
+ * home activity as part of the enable. Enabling this way ensures
+ * a clean transition between the current activity (in non-car-mode) and
+ * the car home activity that will serve as home while in car mode. This
+ * will switch to the car home activity even if we are already in car mode.
*/
- public static final int DISABLE_CAR_MODE_GO_HOME = 0x0001;
+ public static final int ENABLE_CAR_MODE_GO_CAR_HOME = 0x0001;
/**
* Force device into car mode, like it had been placed in the car dock.
@@ -133,7 +133,7 @@
public void enableCarMode(int flags) {
if (mService != null) {
try {
- mService.enableCarMode();
+ mService.enableCarMode(flags);
} catch (RemoteException e) {
Log.e(TAG, "disableCarMode: RemoteException", e);
}
@@ -141,6 +141,15 @@
}
/**
+ * Flag for use with {@link #disableCarMode(int)}: go to the normal
+ * home activity as part of the disable. Disabling this way ensures
+ * a clean transition between the current activity (in car mode) and
+ * the original home activity (which was typically last running without
+ * being in car mode).
+ */
+ public static final int DISABLE_CAR_MODE_GO_HOME = 0x0001;
+
+ /**
* Turn off special mode if currently in car mode.
* @param flags May be 0 or {@link #DISABLE_CAR_MODE_GO_HOME}.
*/
diff --git a/core/java/android/app/backup/BackupAgent.java b/core/java/android/app/backup/BackupAgent.java
index f9dcab8..0bb2cb5 100644
--- a/core/java/android/app/backup/BackupAgent.java
+++ b/core/java/android/app/backup/BackupAgent.java
@@ -29,18 +29,57 @@
import java.io.IOException;
/**
- * This is the central interface between an application and Android's settings
- * backup mechanism. Any implementation of a backup agent should perform backup
- * and restore actions in
+ * {@link android.app.backup.BackupAgent} is the central interface between an
+ * application and Android's data backup infrastructure. An application that wishes
+ * to participate in the backup and restore mechanism will declare a subclass of
+ * {@link android.app.backup.BackupAgent}, implement the
* {@link #onBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor)}
- * and {@link #onRestore(BackupDataInput, int, ParcelFileDescriptor)}
- * respectively.
+ * and {@link #onRestore(BackupDataInput, int, ParcelFileDescriptor)} methods,
+ * and provide the name of its agent class in the AndroidManifest.xml file via
+ * the <application> tag's android:backupAgent attribute.
* <p>
- * A backup agent based on convenient helper classes is available in
- * {@link android.app.backup.BackupAgentHelper} for less complex implementation
- * requirements.
+ * <b>Basic Operation</b>
* <p>
- * STOPSHIP write more documentation about the backup process here.
+ * When the application makes changes to data that it wishes to keep backed up,
+ * it should call the
+ * {@link android.app.backup.BackupManager#dataChanged() BackupManager.dataChanged()} method.
+ * This notifies the Android backup manager that the application needs an opportunity
+ * to update its backup image. The backup manager, in turn, will then schedule a
+ * backup pass to be performed at an opportune time.
+ * <p>
+ * Restore operations are typically only performed when applications are first
+ * installed on a device. At that time, the operating system checks to see whether
+ * there is a previously-saved data set available for the application, and if so,
+ * begins an immediate restore pass to deliver that data as part of the installation
+ * process.
+ * <p>
+ * When a backup or restore pass is run, the application's process will be launched
+ * (if not already running), the manifest-declared agent class instantiated within
+ * that process, and the agent's {@link #onCreate()} method invoked. This prepares the
+ * agent instance to run the actual backup or restore logic. At this point the
+ * agent's
+ * {@link #onBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor) onBackup()} or
+ * {@link #onRestore(BackupDataInput, int, ParcelFileDescriptor) onRestore()} method will be
+ * invoked as appropriate for the operation being performed.
+ * <p>
+ * A backup data set consists of one or more "entities," flattened binary data records
+ * that are each identified with a key string unique within the data set. Adding a
+ * record to the active data set, or updating an existing record, are done by simply
+ * writing new entity data under the desired key. Deleting an entity from the data set
+ * is done by writing an entity under that key with header specifying a negative data
+ * size, and no actual entity data.
+ * <p>
+ * <b>Helper Classes</b>
+ * <p>
+ * An extensible agent based on convenient helper classes is available in
+ * {@link android.app.backup.BackupAgentHelper}. That class is particularly
+ * suited to handling of simple file or {@link android.content.SharedPreferences}
+ * backup and restore.
+ *
+ * @see android.app.backup.BackupManager
+ * @see android.app.backup.BackupAgentHelper
+ * @see android.app.backup.BackupDataInput
+ * @see android.app.backup.BackupDataOutput
*/
public abstract class BackupAgent extends ContextWrapper {
private static final String TAG = "BackupAgent";
@@ -50,9 +89,22 @@
super(null);
}
+ /**
+ * Provided as a convenience for agent implementations that need an opportunity
+ * to do one-time initialization before the actual backup or restore operation
+ * is begun.
+ * <p>
+ * Agents do not need to override this method.
+ */
public void onCreate() {
}
+ /**
+ * Provided as a convenience for agent implementations that need to do some
+ * sort of shutdown process after backup or restore is completed.
+ * <p>
+ * Agents do not need to override this method.
+ */
public void onDestroy() {
}
@@ -65,18 +117,26 @@
* cases, a representation of the final backup state after this pass should
* be written to the file pointed to by the file descriptor wrapped in
* <code>newState</code>.
+ * <p>
+ * Each entity written to the {@link android.app.backup.BackupDataOutput}
+ * <code>data</code> stream will be transmitted
+ * over the current backup transport and stored in the remote data set under
+ * the key supplied as part of the entity. Writing an entity with a negative
+ * data size instructs the transport to delete whatever entity currently exists
+ * under that key from the remote data set.
*
* @param oldState An open, read-only ParcelFileDescriptor pointing to the
* last backup state provided by the application. May be
* <code>null</code>, in which case no prior state is being
* provided and the application should perform a full backup.
* @param data A structured wrapper around an open, read/write
- * ParcelFileDescriptor pointing to the backup data destination.
+ * file descriptor pointing to the backup data destination.
* Typically the application will use backup helper classes to
* write to this file.
* @param newState An open, read/write ParcelFileDescriptor pointing to an
* empty file. The application should record the final backup
- * state here after writing the requested data to dataFd.
+ * state here after writing the requested data to the <code>data</code>
+ * output stream.
*/
public abstract void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
ParcelFileDescriptor newState) throws IOException;
@@ -84,8 +144,7 @@
/**
* The application is being restored from backup and should replace any
* existing data with the contents of the backup. The backup data is
- * provided in the file descriptor pointed to by the
- * {@link android.app.backup.BackupDataInput} instance <code>data</code>. Once
+ * provided through the <code>data</code> parameter. Once
* the restore is finished, the application should write a representation of
* the final state to the <code>newState</code> file descriptor.
* <p>
@@ -98,17 +157,18 @@
* before proceeding.
*
* @param data A structured wrapper around an open, read-only
- * ParcelFileDescriptor pointing to a full snapshot of the
- * application's data. Typically the application will use helper
- * classes to read this data.
- * @param appVersionCode The android:versionCode value of the application
- * that backed up this particular data set. This makes it easier
- * for an application's agent to distinguish among several
+ * file descriptor pointing to a full snapshot of the
+ * application's data. The application should consume every
+ * entity represented in this data stream.
+ * @param appVersionCode The
+ * {@link android.R.styleable#AndroidManifest_versionCode android:versionCode}
+ * value of the application that backed up this particular data set. This
+ * makes it possible for an application's agent to distinguish among any
* possible older data versions when asked to perform the restore
* operation.
* @param newState An open, read/write ParcelFileDescriptor pointing to an
* empty file. The application should record the final backup
- * state here after restoring its data from dataFd.
+ * state here after restoring its data from the <code>data</code> stream.
*/
public abstract void onRestore(BackupDataInput data, int appVersionCode,
ParcelFileDescriptor newState)
diff --git a/core/java/android/app/backup/BackupAgentHelper.java b/core/java/android/app/backup/BackupAgentHelper.java
index 7b6be23..6d73090 100644
--- a/core/java/android/app/backup/BackupAgentHelper.java
+++ b/core/java/android/app/backup/BackupAgentHelper.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 The Android Open Source Project
+ * Copyright (C) 2009 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.
@@ -21,15 +21,30 @@
import java.io.IOException;
/**
- * A convenient BackupAgent wrapper class that automatically manages
+ * A convenient {@link BackupAgent} wrapper class that automatically manages
* heterogeneous data sets within the backup data, each identified by a unique
- * key prefix. An application will typically extend this class in their own
- * backup agent. Then, within the agent's onBackup() and onRestore() methods, it
- * will call {@link #addHelper(String, BackupHelper)} one or more times to
- * specify the data sets, then invoke super.onBackup() or super.onRestore() to
- * have the BackupAgentHelper implementation process the data.
+ * key prefix. When processing a backup or restore operation, the BackupAgentHelper
+ * dispatches to one or more installed {@link BackupHelper helpers} objects, each
+ * of which is responsible for a defined subset of the data being processed.
* <p>
- * STOPSHIP: document!
+ * An application will typically extend this class in their own
+ * backup agent. Then, within the agent's {@link BackupAgent#onCreate() onCreate()}
+ * method, it will call {@link #addHelper(String, BackupHelper)} one or more times to
+ * install the handlers for each kind of data it wishes to manage within its backups.
+ * <p>
+ * The Android framework currently provides two predefined {@link BackupHelper} classes:
+ * {@link FileBackupHelper}, which manages the backup and restore of entire files
+ * within an application's data directory hierarchy; and {@link SharedPreferencesBackupHelper},
+ * which manages the backup and restore of an application's
+ * {@link android.content.SharedPreferences} data.
+ * <p>
+ * An application can also implement its own helper classes to work within the
+ * {@link BackupAgentHelper} framework. See the {@link BackupHelper} interface
+ * documentation for details.
+ *
+ * @see BackupHelper
+ * @see FileBackupHelper
+ * @see SharedPreferencesBackupHelper
*/
public class BackupAgentHelper extends BackupAgent {
static final String TAG = "BackupAgentHelper";
diff --git a/core/java/android/app/backup/BackupDataInput.java b/core/java/android/app/backup/BackupDataInput.java
index 2da0c11..976e0c9 100644
--- a/core/java/android/app/backup/BackupDataInput.java
+++ b/core/java/android/app/backup/BackupDataInput.java
@@ -20,7 +20,41 @@
import java.io.IOException;
/**
- * STOPSHIP: document!
+ * BackupDataInput is the structured interface used for passing the contents of
+ * a backup data set to an application's {@link BackupAgent} class in its
+ * {@link BackupAgent#onRestore(BackupDataInput, int, android.os.ParcelFileDescriptor)}
+ * method. The data is presented as a set of "entities," each
+ * representing one named record as previously stored by the agent's
+ * {@link BackupAgent#onBackup(android.os.ParcelFileDescriptor, BackupDataOutput, android.os.ParcelFileDescriptor)}
+ * implementation. An entity is composed of a descriptive header plus a
+ * byte array that holds its raw data.
+ * <p>
+ * The agent must consume every entity in the data stream, otherwise the
+ * restored state of the application will be incomplete.
+ * <p>
+ * <b>Example</b>
+ * <p>
+ * A typical
+ * {@link BackupAgent#onRestore(BackupDataInput, int, android.os.ParcelFileDescriptor) BackupAgent.onRestore(data, appVersionCode, newState)}
+ * implementation might be structured something like this:
+ * <pre>
+ * while (data.readNextHeader()) {
+ * String key = data.getKey();
+ * int dataSize = data.getDataSize();
+ *
+ * if (key.equals(MY_BACKUP_KEY_ONE)) {
+ * // process this kind of record here
+ * byte[] buffer = new byte[dataSize];
+ * data.readEntityData(buffer, 0, dataSize); // reads the entire entity at once
+ *
+ * // now 'buffer' holds the raw data and can be processed however
+ * // the agent wishes
+ * processBackupKeyOne(buffer);
+ * } else if (key.equals(MY_BACKUP_KEY_TO_IGNORE) {
+ * // a key we recognize but wish to discard
+ * data.skipEntityData();
+ * } // ... etc.
+ * }</pre>
*/
public class BackupDataInput {
int mBackupReader;
@@ -52,10 +86,12 @@
}
/**
- * Consumes the next header from the restore stream.
+ * Extract the next entity header from the restore stream. After this method
+ * return success, the {@link #getKey()} and {@link #getDataSize()} methods can
+ * be used to inspect the entity that is now available for processing.
*
- * @return true when there is an entity ready for consumption from the restore stream,
- * false if the restore stream has been fully consumed.
+ * @return <code>true</code> when there is an entity ready for consumption from the
+ * restore stream, <code>false</code> if the restore stream has been fully consumed.
* @throws IOException if an error occurred while reading the restore stream
*/
public boolean readNextHeader() throws IOException {
@@ -71,25 +107,25 @@
} else {
// error
mHeaderReady = false;
- throw new IOException("result=0x" + Integer.toHexString(result));
+ throw new IOException("failed: 0x" + Integer.toHexString(result));
}
}
/**
- * Report the key associated with the current record in the restore stream
- * @return the current record's key string
+ * Report the key associated with the current entity in the restore stream
+ * @return the current entity's key string
* @throws IllegalStateException if the next record header has not yet been read
*/
public String getKey() {
if (mHeaderReady) {
return mHeader.key;
} else {
- throw new IllegalStateException("mHeaderReady=false");
+ throw new IllegalStateException("Entity header not read");
}
}
/**
- * Report the size in bytes of the data associated with the current record in the
+ * Report the size in bytes of the data associated with the current entity in the
* restore stream.
*
* @return The size of the record's raw data, in bytes
@@ -99,7 +135,7 @@
if (mHeaderReady) {
return mHeader.dataSize;
} else {
- throw new IllegalStateException("mHeaderReady=false");
+ throw new IllegalStateException("Entity header not read");
}
}
@@ -107,13 +143,15 @@
* Read a record's raw data from the restore stream. The record's header must first
* have been processed by the {@link #readNextHeader()} method. Multiple calls to
* this method may be made in order to process the data in chunks; not all of it
- * must be read in a single call.
+ * must be read in a single call. Once all of the raw data for the current entity
+ * has been read, further calls to this method will simply return zero.
*
* @param data An allocated byte array of at least 'size' bytes
* @param offset Offset within the 'data' array at which the data will be placed
- * when read from the stream.
- * @param size The number of bytes to read in this pass.
- * @return The number of bytes of data read
+ * when read from the stream
+ * @param size The number of bytes to read in this pass
+ * @return The number of bytes of data read. Once all of the data for this entity
+ * has been read, further calls to this method will return zero.
* @throws IOException if an error occurred when trying to read the restore data stream
*/
public int readEntityData(byte[] data, int offset, int size) throws IOException {
@@ -125,12 +163,12 @@
throw new IOException("result=0x" + Integer.toHexString(result));
}
} else {
- throw new IllegalStateException("mHeaderReady=false");
+ throw new IllegalStateException("Entity header not read");
}
}
/**
- * Consume the current record's data without actually reading it into a buffer
+ * Consume the current entity's data without extracting it into a buffer
* for further processing. This allows a {@link android.app.backup.BackupAgent} to
* efficiently discard obsolete or otherwise uninteresting records during the
* restore operation.
@@ -141,7 +179,7 @@
if (mHeaderReady) {
skipEntityData_native(mBackupReader);
} else {
- throw new IllegalStateException("mHeaderReady=false");
+ throw new IllegalStateException("Entity header not read");
}
}
diff --git a/core/java/android/app/backup/BackupDataInputStream.java b/core/java/android/app/backup/BackupDataInputStream.java
index a7f4ba6..465b3b6 100644
--- a/core/java/android/app/backup/BackupDataInputStream.java
+++ b/core/java/android/app/backup/BackupDataInputStream.java
@@ -20,7 +20,21 @@
import java.io.IOException;
/**
- * STOPSHIP: document */
+ * Used by {@link BackupHelper} classes within the {@link BackupAgentHelper} mechanism,
+ * this class provides an {@link java.io.InputStream}-like interface for accessing an
+ * entity's data during a restore operation.
+ * <p>
+ * When {@link BackupHelper#restoreEntity(BackupDataInputStream) BackupHelper.restoreEntity(BackupDataInputStream)}
+ * is called, the current entity's header has already been read from the underlying
+ * {@link BackupDataInput}. The entity's key string and total data size are available
+ * through this class's {@link #getKey()} and {@link #size()} methods, respectively.
+ * <p class="note">
+ * <em>Note:</em> The caller should take care not to seek or close the underlying data
+ * source, or to read more than {@link #size()} bytes total from the stream.</p>
+ *
+ * @see BackupAgentHelper
+ * @see BackupHelper
+ */
public class BackupDataInputStream extends InputStream {
String key;
@@ -34,6 +48,13 @@
mData = data;
}
+ /**
+ * Read one byte of entity data from the stream, returning it as
+ * an integer value. If more than {@link #size()} bytes of data
+ * are read from the stream, the output of this method is undefined.
+ *
+ * @return The byte read, or undefined if the end of the stream has been reached.
+ */
public int read() throws IOException {
byte[] one = mOneByte;
if (mOneByte == null) {
@@ -43,18 +64,52 @@
return one[0];
}
+ /**
+ * Read up to {@code size} bytes of data into a byte array, beginning at position
+ * {@code offset} within the array.
+ *
+ * @param b Byte array into which the data will be read
+ * @param offset The data will be stored in {@code b} beginning at this index
+ * within the array.
+ * @param size The number of bytes to read in this operation. If insufficient
+ * data exists within the entity to fulfill this request, only as much data
+ * will be read as is available.
+ * @return The number of bytes of data read, or zero if all of the entity's
+ * data has already been read.
+ */
public int read(byte[] b, int offset, int size) throws IOException {
return mData.readEntityData(b, offset, size);
}
+ /**
+ * Read enough entity data into a byte array to fill the array.
+ *
+ * @param b Byte array to fill with data from the stream. If the stream does not
+ * have sufficient data to fill the array, then the contents of the remainder of
+ * the array will be undefined.
+ * @return The number of bytes of data read, or zero if all of the entity's
+ * data has already been read.
+ */
public int read(byte[] b) throws IOException {
return mData.readEntityData(b, 0, b.length);
}
+ /**
+ * Report the key string associated with this entity within the backup data set.
+ *
+ * @return The key string for this entity, equivalent to calling
+ * {@link BackupDataInput#getKey()} on the underlying {@link BackupDataInput}.
+ */
public String getKey() {
return this.key;
}
-
+
+ /**
+ * Report the total number of bytes of data available for the current entity.
+ *
+ * @return The number of data bytes available, equivalent to calling
+ * {@link BackupDataInput#getDataSize()} on the underlying {@link BackupDataInput}.
+ */
public int size() {
return this.dataSize;
}
diff --git a/core/java/android/app/backup/BackupDataOutput.java b/core/java/android/app/backup/BackupDataOutput.java
index 53b1d46..a69547a 100644
--- a/core/java/android/app/backup/BackupDataOutput.java
+++ b/core/java/android/app/backup/BackupDataOutput.java
@@ -16,18 +16,53 @@
package android.app.backup;
+import android.os.ParcelFileDescriptor;
+
import java.io.FileDescriptor;
import java.io.IOException;
/**
- * STOPSHIP: document
+ * This class is the structured conduit through which a {@link BackupAgent} commits
+ * information to the current backup data set. Data written for backup is presented
+ * as a set of "entities," key/value pairs in which each binary data record "value" is
+ * named with a string "key."
+ * <p>
+ * To commit a data record to the backup transport, the agent's
+ * {@link BackupAgent#onBackup(android.os.ParcelFileDescriptor, BackupDataOutput, android.os.ParcelFileDescriptor)}
+ * method first writes an "entity header" that supplies the key string for the record
+ * and the total size of the binary value for the record. After the header has been
+ * written the agent then writes the binary entity value itself. The entity value can
+ * be written in multiple chunks if desired, as long as the total count of bytes written
+ * matches what was supplied to {@link #writeEntityHeader(String, int)}.
+ * <p>
+ * Entity key strings are considered to be unique within a given application's backup
+ * data set. If a new entity is written under an existing key string, its value will
+ * replace any previous value in the transport's remote data store. A record can be
+ * removed entirely from the remote data set by writing a new entity header using the
+ * existing record's key, but supplying a negative <code>dataSize</code> parameter.
+ * When doing this the agent does not need to call {@link #writeEntityData(byte[], int)}.
+ * <p>
+ * <b>Example</b>
+ * <p>
+ * Here is an example illustrating a way to back up the value of a String variable
+ * called <code>mStringToBackUp</code>:
+ * <pre>
+ * static final String MY_STRING_KEY = "storedstring";
+ *
+ * public void {@link BackupAgent#onBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor) onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState)}
+ * throws IOException {
+ * ...
+ * byte[] stringBytes = mStringToBackUp.getBytes();
+ * data.writeEntityHeader(MY_STRING_KEY, stringBytes.length);
+ * data.writeEntityData(stringBytes, stringBytes.length);
+ * ...
+ * }</pre>
+ *
+ * @see BackupAgent
*/
public class BackupDataOutput {
int mBackupWriter;
- public static final int OP_UPDATE = 1;
- public static final int OP_DELETE = 2;
-
/** @hide */
public BackupDataOutput(FileDescriptor fd) {
if (fd == null) throw new NullPointerException();
@@ -71,6 +106,7 @@
}
}
+ /** @hide */
public void setKeyPrefix(String keyPrefix) {
setKeyPrefix_native(mBackupWriter, keyPrefix);
}
diff --git a/core/java/android/app/backup/BackupHelper.java b/core/java/android/app/backup/BackupHelper.java
index b7ef268..87b581b 100644
--- a/core/java/android/app/backup/BackupHelper.java
+++ b/core/java/android/app/backup/BackupHelper.java
@@ -19,11 +19,21 @@
import android.os.ParcelFileDescriptor;
/**
- * A convenient interface to be used with the
- * {@link android.app.backup.BackupAgentHelper} to implement backup and restore of
- * arbitrary data types.
+ * This interface defines the calling interface that {@link BackupAgentHelper} uses
+ * when dispatching backup and restore operations to the installed helpers.
+ * Applications can define and install their own helpers as well as using those
+ * provided as part of the Android framework.
* <p>
- * STOPSHOP: document!
+ * Although multiple helper objects may be installed simultaneously, each helper
+ * is responsible only for handling its own data, and will not see entities
+ * created by other components within the backup system. Invocations of multiple
+ * helpers are performed sequentially by the {@link BackupAgentHelper}, with each
+ * helper given a chance to access its own saved state from within the state record
+ * produced during the previous backup operation.
+ *
+ * @see BackupAgentHelper
+ * @see FileBackupHelper
+ * @see SharedPreferencesBackupHelper
*/
public interface BackupHelper {
/**
@@ -31,25 +41,46 @@
* application's data directory need to be backed up, write them to
* <code>data</code>, and fill in <code>newState</code> with the state as it
* exists now.
+ * <p>
+ * Implementing this method is much like implementing
+ * {@link BackupAgent#onBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor)}
+ * — the method parameters are the same. When this method is invoked the
+ * {@code oldState} descriptor points to the beginning of the state data
+ * written during this helper's previous backup operation, and the {@code newState}
+ * descriptor points to the file location at which the helper should write its
+ * new state after performing the backup operation.
+ * <p class="note">
+ * <em>Note:</em> The helper should not close or seek either the {@code oldState} or
+ * the {@code newState} file descriptors.</p>
*/
public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
ParcelFileDescriptor newState);
/**
* Called by {@link android.app.backup.BackupAgentHelper BackupAgentHelper}
- * to restore one entity from the restore dataset.
- * <p class=note>
- * Do not close the <code>data</code> stream. Do not read more than
- * <code>data.size()</code> bytes from <code>data</code>.
+ * to restore a single entity from the restore data set. This method will be
+ * called for each entity in the data set that belongs to this handler.
+ * <p class="note">
+ * <em>Note:</em> Do not close the <code>data</code> stream. Do not read more than
+ * <code>data.size()</code> bytes from <code>data</code>.</p>
*/
public void restoreEntity(BackupDataInputStream data);
/**
* Called by {@link android.app.backup.BackupAgentHelper BackupAgentHelper}
- * to write the new backup state file corresponding to
- * the current state of the app's data at the time the backup operation was
- * performed.
+ * after a restore operation to write the backup state file corresponding to
+ * the data as processed by the helper. The data written here will be
+ * available to the helper during the next call to its
+ * {@link #performBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor)}
+ * method.
+ * <p>
+ * Note that this method will be called even if the handler's
+ * {@link #restoreEntity(BackupDataInputStream)} method was never invoked during
+ * the restore operation.
+ * <p class="note">
+ * <em>Note:</em> The helper should not close or seek the {@code newState}
+ * file descriptor.</p>
*/
- public void writeNewStateDescription(ParcelFileDescriptor fd);
+ public void writeNewStateDescription(ParcelFileDescriptor newState);
}
diff --git a/core/java/android/app/backup/BackupManager.java b/core/java/android/app/backup/BackupManager.java
index 7eb6265..7070827 100644
--- a/core/java/android/app/backup/BackupManager.java
+++ b/core/java/android/app/backup/BackupManager.java
@@ -25,9 +25,9 @@
import android.util.Log;
/**
- * BackupManager is the interface to the system's backup service. Applications
- * simply instantiate one, and then use that instance to communicate with the
- * backup infrastructure.
+ * The BackupManager class is interface through which an application's user interface
+ * code will interact with the Android backup service. Applications simply instantiate one
+ * and then issue calls through that instance.
* <p>
* When an application has made changes to data which should be backed up, a
* call to {@link #dataChanged()} will notify the backup service. The system
@@ -35,24 +35,23 @@
* calls to {@link #dataChanged()} have no further effect until the backup
* operation actually occurs.
* <p>
- * The backup operation itself begins with the system launching the
+ * A backup or restore operation begins with the system launching the
* {@link android.app.backup.BackupAgent} subclass declared in your manifest. See the
* documentation for {@link android.app.backup.BackupAgent} for a detailed description
- * of how the backup then proceeds.
- * <p>
- * A simple implementation of a BackupAgent useful for backing up Preferences
- * and files is available by using {@link android.app.backup.BackupAgentHelper}.
- * <p>
- * STOPSHIP: more documentation!
+ * of how the operation then proceeds.
* <p>
* <b>XML attributes</b>
* <p>
- * See {@link android.R.styleable#AndroidManifestApplication
- * AndroidManifest.xml's application attributes}
+ * Several attributes affecting the operation of the backup and restore mechanism
+ * can be set on the <application> tag in the application's
+ * AndroidManifest.xml file. See the documentation on the
+ * {@link android.R.styleable#AndroidManifestApplication AndroidManifest.xml's application attributes}
+ * for details.
*
* @attr ref android.R.styleable#AndroidManifestApplication_allowBackup
* @attr ref android.R.styleable#AndroidManifestApplication_backupAgent
* @attr ref android.R.styleable#AndroidManifestApplication_killAfterRestore
+ * @attr ref android.R.styleable#AndroidManifestApplication_restoreAnyVersion
*/
public class BackupManager {
private static final String TAG = "BackupManager";
@@ -82,7 +81,8 @@
/**
* Notifies the Android backup system that your application wishes to back up
* new changes to its data. A backup operation using your application's
- * {@link android.app.backup.BackupAgent} subclass will be scheduled when you call this method.
+ * {@link android.app.backup.BackupAgent} subclass will be scheduled when you
+ * call this method.
*/
public void dataChanged() {
checkServiceBinder();
@@ -97,11 +97,12 @@
/**
* Convenience method for callers who need to indicate that some other package
- * needs a backup pass. This can be relevant in the case of groups of packages
- * that share a uid, for example.
- *
+ * needs a backup pass. This can be useful in the case of groups of packages
+ * that share a uid.
+ * <p>
* This method requires that the application hold the "android.permission.BACKUP"
- * permission if the package named in the argument is not the caller's own.
+ * permission if the package named in the argument does not run under the same uid
+ * as the caller.
*/
public static void dataChanged(String packageName) {
checkServiceBinder();
diff --git a/core/java/android/app/backup/FileBackupHelper.java b/core/java/android/app/backup/FileBackupHelper.java
index 3ce5b43..a326941 100644
--- a/core/java/android/app/backup/FileBackupHelper.java
+++ b/core/java/android/app/backup/FileBackupHelper.java
@@ -26,18 +26,13 @@
* A helper class which can be used in conjunction with
* {@link android.app.backup.BackupAgentHelper} to manage the backup of a set of
* files. Whenever backup is performed, all files changed since the last backup
- * will be saved in their entirety. During the first time the backup happens,
- * all the files in the list will be backed up. Note that this should only be
- * used with small configuration files and not with large binary files.
+ * will be saved in their entirety. During the first time the backup happens,
+ * every file in the list will be backed up. Note that this should only be
+ * used with small configuration files, not with large binary files.
* <p>
- * Any files not present in the list of files during the restore procedure will
- * be ignored. If files present in a previous version of an application are
- * removed in subsequent versions, it is the responsibility of the developer to
- * design a mechanism to remove those files. Otherwise files no longer needed
- * will linger and consume space on the device.
- * <p>
- * STOPSHIP: document! [manages backup of a set of files; restore is totally
- * opaque]
+ * During restore, if the helper encounters data for a file that was not
+ * specified when the FileBackupHelper object was constructed, that data
+ * will be ignored.
*/
public class FileBackupHelper extends FileBackupHelperBase implements BackupHelper {
private static final String TAG = "FileBackupHelper";
@@ -69,8 +64,8 @@
* now. When <code>oldState</code> is <code>null</code>, all the files will
* be backed up.
* <p>
- * This should be called from {@link android.app.backup.BackupAgentHelper}
- * directly. See
+ * This should only be called directly from within the {@link BackupAgentHelper}
+ * implementation. See
* {@link android.app.backup.BackupAgent#onBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor)}
* for a description of parameter meanings.
*/
@@ -91,6 +86,9 @@
/**
* Restore one record [representing a single file] from the restore dataset.
+ * <p>
+ * This should only be called directly from within the {@link BackupAgentHelper}
+ * implementation.
*/
public void restoreEntity(BackupDataInputStream data) {
if (DEBUG) Log.d(TAG, "got entity '" + data.getKey() + "' size=" + data.size());
diff --git a/core/java/android/app/backup/SharedPreferencesBackupHelper.java b/core/java/android/app/backup/SharedPreferencesBackupHelper.java
index f9e6b28..9efecc5 100644
--- a/core/java/android/app/backup/SharedPreferencesBackupHelper.java
+++ b/core/java/android/app/backup/SharedPreferencesBackupHelper.java
@@ -26,11 +26,45 @@
/**
* A helper class which can be used in conjunction with
* {@link android.app.backup.BackupAgentHelper} to manage the backup of
- * {@link android.content.SharedPreferences}. Whenever backup is performed it
+ * {@link android.content.SharedPreferences}. Whenever a backup is performed it
* will back up all named shared preferences which have changed since the last
- * backup.
+ * backup operation.
* <p>
- * STOPSHIP: document!
+ * To use this class, the application's agent class should extend
+ * {@link android.app.backup.BackupAgentHelper}. Then, in the agent's
+ * {@link BackupAgent#onCreate()} method, an instance of this class should be
+ * allocated and installed as a backup/restore handler within the BackupAgentHelper
+ * framework. An implementation of an agent supporting backup and restore for
+ * an application that wishes to back up two groups of {@link android.content.SharedPreferences}
+ * data might look something like this:
+ * <pre>
+ * import android.app.backup.BackupAgentHelper;
+ * import android.app.backup.SharedPreferencesBackupHelper;
+ *
+ * public class MyBackupAgent extends BackupAgentHelper {
+ * // The names of the SharedPreferences groups that the application maintains. These
+ * // are the same strings that are passed to {@link Context#getSharedPreferences(String, int)}.
+ * static final String PREFS_DISPLAY = "displayprefs";
+ * static final String PREFS_SCORES = "highscores";
+ *
+ * // An arbitrary string used within the BackupAgentHelper implementation to
+ * // identify the SharedPreferenceBackupHelper's data.
+ * static final String MY_PREFS_BACKUP_KEY = "myprefs";
+ *
+ * // Simply allocate a helper and install it
+ * void onCreate() {
+ * SharedPreferencesBackupHelper helper =
+ * new SharedPreferencesBackupHelper(this, PREFS_DISPLAY, PREFS_SCORES);
+ * addHelper(MY_PREFS_BACKUP_KEY, helper);
+ * }
+ * }</pre>
+ * <p>
+ * No further implementation is needed; the BackupAgentHelper mechanism automatically
+ * dispatches the
+ * {@link BackupAgent#onBackup(android.os.ParcelFileDescriptor, BackupDataOutput, android.os.ParcelFileDescriptor) BackupAgent.onBackup()}
+ * and
+ * {@link BackupAgent#onRestore(BackupDataInput, int, android.os.ParcelFileDescriptor) BackupAgent.onRestore()}
+ * callbacks to the SharedPreferencesBackupHelper as appropriate.
*/
public class SharedPreferencesBackupHelper extends FileBackupHelperBase implements BackupHelper {
private static final String TAG = "SharedPreferencesBackupHelper";
diff --git a/core/java/android/content/ContentResolver.java b/core/java/android/content/ContentResolver.java
index 1cb2353..d114ecc 100644
--- a/core/java/android/content/ContentResolver.java
+++ b/core/java/android/content/ContentResolver.java
@@ -1307,7 +1307,7 @@
String blockingPackage = ActivityThread.currentPackageName();
EventLog.writeEvent(
- EventLogTags.CONTENT_QUERY_OPERATION,
+ EventLogTags.CONTENT_QUERY_SAMPLE,
uri.toString(),
projectionBuffer.toString(),
selection != null ? selection : "",
@@ -1329,7 +1329,7 @@
}
String blockingPackage = ActivityThread.currentPackageName();
EventLog.writeEvent(
- EventLogTags.CONTENT_UPDATE_OPERATION,
+ EventLogTags.CONTENT_UPDATE_SAMPLE,
uri.toString(),
operation,
selection != null ? selection : "",
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index 3a2aa55..30822d4 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -1398,7 +1398,7 @@
* @see android.os.Vibrator
*/
public static final String VIBRATOR_SERVICE = "vibrator";
-
+
/**
* Use with {@link #getSystemService} to retrieve a {@link
* android.app.StatusBarManager} for interacting with the status bar.
@@ -1421,6 +1421,17 @@
/**
* Use with {@link #getSystemService} to retrieve a {@link
+ * android.net.ThrottleManager} for handling management of
+ * throttling.
+ *
+ * @hide
+ * @see #getSystemService
+ * @see android.net.ThrottleManager
+ */
+ public static final String THROTTLE_SERVICE = "throttle";
+
+ /**
+ * Use with {@link #getSystemService} to retrieve a {@link
* android.net.NetworkManagementService} for handling management of
* system network services
*
diff --git a/core/java/android/content/EventLogTags.logtags b/core/java/android/content/EventLogTags.logtags
index 0a8c9b0..21ea90a 100644
--- a/core/java/android/content/EventLogTags.logtags
+++ b/core/java/android/content/EventLogTags.logtags
@@ -2,6 +2,6 @@
option java_package android.content;
-52002 content_query_operation (uri|3),(projection|3),(selection|3),(sortorder|3),(time|1|3),(blocking_package|3),(sample_percent|1|6)
-52003 content_update_operation (uri|3),(operation|3),(selection|3),(time|1|3),(blocking_package|3),(sample_percent|1|6)
-52004 binder_operation (descriptor|3),(method_num|1|5),(time|1|3),(blocking_package|3),(sample_percent|1|6)
+52002 content_query_sample (uri|3),(projection|3),(selection|3),(sortorder|3),(time|1|3),(blocking_package|3),(sample_percent|1|6)
+52003 content_update_sample (uri|3),(operation|3),(selection|3),(time|1|3),(blocking_package|3),(sample_percent|1|6)
+52004 binder_sample (descriptor|3),(method_num|1|5),(time|1|3),(blocking_package|3),(sample_percent|1|6)
diff --git a/core/java/android/database/sqlite/SQLiteCompiledSql.java b/core/java/android/database/sqlite/SQLiteCompiledSql.java
index 72ceb9b..047e176 100644
--- a/core/java/android/database/sqlite/SQLiteCompiledSql.java
+++ b/core/java/android/database/sqlite/SQLiteCompiledSql.java
@@ -54,6 +54,9 @@
private boolean mInUse = false;
/* package */ SQLiteCompiledSql(SQLiteDatabase db, String sql) {
+ if (!db.isOpen()) {
+ throw new IllegalStateException("database " + db.getPath() + " already closed");
+ }
mDatabase = db;
mSqlStmt = sql;
mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace();
@@ -75,6 +78,9 @@
* existing compiled SQL program already around
*/
private void compile(String sql, boolean forceCompilation) {
+ if (!mDatabase.isOpen()) {
+ throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+ }
// Only compile if we don't have a valid statement already or the caller has
// explicitly requested a recompile.
if (forceCompilation) {
@@ -90,6 +96,9 @@
}
/* package */ void releaseSqlStatement() {
+ if (!mDatabase.isOpen()) {
+ throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+ }
// Note that native_finalize() checks to make sure that nStatement is
// non-null before destroying it.
if (nStatement != 0) {
diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java
index 3b7416e..70f681f 100644
--- a/core/java/android/database/sqlite/SQLiteDatabase.java
+++ b/core/java/android/database/sqlite/SQLiteDatabase.java
@@ -500,10 +500,10 @@
* {@link #yieldIfContendedSafely}.
*/
public void beginTransactionWithListener(SQLiteTransactionListener transactionListener) {
+ lockForced();
if (!isOpen()) {
throw new IllegalStateException("database not open");
}
- lockForced();
boolean ok = false;
try {
// If this thread already had the lock then get out
@@ -915,11 +915,11 @@
* @return the database version
*/
public int getVersion() {
+ SQLiteStatement prog = null;
+ lock();
if (!isOpen()) {
throw new IllegalStateException("database not open");
}
- SQLiteStatement prog = null;
- lock();
try {
prog = new SQLiteStatement(this, "PRAGMA user_version;");
long version = prog.simpleQueryForLong();
@@ -936,9 +936,6 @@
* @param version the new database version
*/
public void setVersion(int version) {
- if (!isOpen()) {
- throw new IllegalStateException("database not open");
- }
execSQL("PRAGMA user_version = " + version);
}
@@ -948,11 +945,11 @@
* @return the new maximum database size
*/
public long getMaximumSize() {
+ SQLiteStatement prog = null;
+ lock();
if (!isOpen()) {
throw new IllegalStateException("database not open");
}
- SQLiteStatement prog = null;
- lock();
try {
prog = new SQLiteStatement(this,
"PRAGMA max_page_count;");
@@ -972,11 +969,11 @@
* @return the new maximum database size
*/
public long setMaximumSize(long numBytes) {
+ SQLiteStatement prog = null;
+ lock();
if (!isOpen()) {
throw new IllegalStateException("database not open");
}
- SQLiteStatement prog = null;
- lock();
try {
long pageSize = getPageSize();
long numPages = numBytes / pageSize;
@@ -1000,11 +997,11 @@
* @return the database page size, in bytes
*/
public long getPageSize() {
+ SQLiteStatement prog = null;
+ lock();
if (!isOpen()) {
throw new IllegalStateException("database not open");
}
- SQLiteStatement prog = null;
- lock();
try {
prog = new SQLiteStatement(this,
"PRAGMA page_size;");
@@ -1024,9 +1021,6 @@
* @param numBytes the database page size, in bytes
*/
public void setPageSize(long numBytes) {
- if (!isOpen()) {
- throw new IllegalStateException("database not open");
- }
execSQL("PRAGMA page_size = " + numBytes);
}
@@ -1143,10 +1137,10 @@
* @return a pre-compiled statement object.
*/
public SQLiteStatement compileStatement(String sql) throws SQLException {
+ lock();
if (!isOpen()) {
throw new IllegalStateException("database not open");
}
- lock();
try {
return new SQLiteStatement(this, sql);
} finally {
@@ -1586,10 +1580,10 @@
* whereClause.
*/
public int delete(String table, String whereClause, String[] whereArgs) {
+ lock();
if (!isOpen()) {
throw new IllegalStateException("database not open");
}
- lock();
SQLiteStatement statement = null;
try {
statement = compileStatement("DELETE FROM " + table
@@ -1641,10 +1635,6 @@
*/
public int updateWithOnConflict(String table, ContentValues values,
String whereClause, String[] whereArgs, int conflictAlgorithm) {
- if (!isOpen()) {
- throw new IllegalStateException("database not open");
- }
-
if (values == null || values.size() == 0) {
throw new IllegalArgumentException("Empty values");
}
@@ -1673,6 +1663,9 @@
}
lock();
+ if (!isOpen()) {
+ throw new IllegalStateException("database not open");
+ }
SQLiteStatement statement = null;
try {
statement = compileStatement(sql.toString());
@@ -1724,11 +1717,11 @@
* @throws SQLException If the SQL string is invalid for some reason
*/
public void execSQL(String sql) throws SQLException {
+ long timeStart = SystemClock.uptimeMillis();
+ lock();
if (!isOpen()) {
throw new IllegalStateException("database not open");
}
- long timeStart = SystemClock.uptimeMillis();
- lock();
logTimeStat(mLastSqlStatement, timeStart, GET_LOCK_LOG_PREFIX);
try {
native_execSQL(sql);
@@ -1759,14 +1752,14 @@
* @throws SQLException If the SQL string is invalid for some reason
*/
public void execSQL(String sql, Object[] bindArgs) throws SQLException {
- if (!isOpen()) {
- throw new IllegalStateException("database not open");
- }
if (bindArgs == null) {
throw new IllegalArgumentException("Empty bindArgs");
}
long timeStart = SystemClock.uptimeMillis();
lock();
+ if (!isOpen()) {
+ throw new IllegalStateException("database not open");
+ }
SQLiteStatement statement = null;
try {
statement = compileStatement(sql);
diff --git a/core/java/android/database/sqlite/SQLiteProgram.java b/core/java/android/database/sqlite/SQLiteProgram.java
index 66ce3b0..5f13eb1 100644
--- a/core/java/android/database/sqlite/SQLiteProgram.java
+++ b/core/java/android/database/sqlite/SQLiteProgram.java
@@ -173,6 +173,9 @@
* @param index The 1-based index to the parameter to bind null to
*/
public void bindNull(int index) {
+ if (!mDatabase.isOpen()) {
+ throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+ }
acquireReference();
try {
native_bind_null(index);
@@ -189,6 +192,9 @@
* @param value The value to bind
*/
public void bindLong(int index, long value) {
+ if (!mDatabase.isOpen()) {
+ throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+ }
acquireReference();
try {
native_bind_long(index, value);
@@ -205,6 +211,9 @@
* @param value The value to bind
*/
public void bindDouble(int index, double value) {
+ if (!mDatabase.isOpen()) {
+ throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+ }
acquireReference();
try {
native_bind_double(index, value);
@@ -224,6 +233,9 @@
if (value == null) {
throw new IllegalArgumentException("the bind value at index " + index + " is null");
}
+ if (!mDatabase.isOpen()) {
+ throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+ }
acquireReference();
try {
native_bind_string(index, value);
@@ -243,6 +255,9 @@
if (value == null) {
throw new IllegalArgumentException("the bind value at index " + index + " is null");
}
+ if (!mDatabase.isOpen()) {
+ throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+ }
acquireReference();
try {
native_bind_blob(index, value);
@@ -255,6 +270,9 @@
* Clears all existing bindings. Unset bindings are treated as NULL.
*/
public void clearBindings() {
+ if (!mDatabase.isOpen()) {
+ throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+ }
acquireReference();
try {
native_clear_bindings();
@@ -267,6 +285,9 @@
* Release this program's resources, making it invalid.
*/
public void close() {
+ if (!mDatabase.isOpen()) {
+ throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+ }
mDatabase.lock();
try {
releaseReference();
diff --git a/core/java/android/database/sqlite/SQLiteStatement.java b/core/java/android/database/sqlite/SQLiteStatement.java
index 7f484ff..98da414 100644
--- a/core/java/android/database/sqlite/SQLiteStatement.java
+++ b/core/java/android/database/sqlite/SQLiteStatement.java
@@ -44,6 +44,9 @@
* some reason
*/
public void execute() {
+ if (!mDatabase.isOpen()) {
+ throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+ }
long timeStart = SystemClock.uptimeMillis();
mDatabase.lock();
@@ -67,6 +70,9 @@
* some reason
*/
public long executeInsert() {
+ if (!mDatabase.isOpen()) {
+ throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+ }
long timeStart = SystemClock.uptimeMillis();
mDatabase.lock();
@@ -90,6 +96,9 @@
* @throws android.database.sqlite.SQLiteDoneException if the query returns zero rows
*/
public long simpleQueryForLong() {
+ if (!mDatabase.isOpen()) {
+ throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+ }
long timeStart = SystemClock.uptimeMillis();
mDatabase.lock();
@@ -113,6 +122,9 @@
* @throws android.database.sqlite.SQLiteDoneException if the query returns zero rows
*/
public String simpleQueryForString() {
+ if (!mDatabase.isOpen()) {
+ throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
+ }
long timeStart = SystemClock.uptimeMillis();
mDatabase.lock();
diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java
index 2495619..8687a89 100644
--- a/core/java/android/hardware/Camera.java
+++ b/core/java/android/hardware/Camera.java
@@ -824,6 +824,12 @@
public static final String SCENE_MODE_PARTY = "party";
public static final String SCENE_MODE_CANDLELIGHT = "candlelight";
+ /**
+ * Applications are looking for a barcode. Camera driver will be
+ * optimized for barcode reading.
+ */
+ public static final String SCENE_MODE_BARCODE = "barcode";
+
// Values for focus mode settings.
/**
* Auto-focus mode.
@@ -845,6 +851,13 @@
*/
public static final String FOCUS_MODE_FIXED = "fixed";
+ /**
+ * Extended depth of field (EDOF). Focusing is done digitally and
+ * continuously. Applications should not call {@link
+ * #autoFocus(AutoFocusCallback)} in this mode.
+ */
+ public static final String FOCUS_MODE_EDOF = "edof";
+
// Formats for setPreviewFormat and setPictureFormat.
private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp";
private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp";
@@ -1507,9 +1520,11 @@
}
/**
- * Sets the scene mode. Other parameters may be changed after changing
- * scene mode. For example, flash and supported flash mode may be
- * changed to "off" in night scene mode. After setting scene mode,
+ * Sets the scene mode. Changing scene mode may override other
+ * parameters (such as flash mode, focus mode, white balance). For
+ * example, suppose originally flash mode is on and supported flash
+ * modes are on/off. In night scene mode, both flash mode and supported
+ * flash mode may be changed to off. After setting scene mode,
* applications should call getParameters to know if some parameters are
* changed.
*
diff --git a/core/java/android/net/IThrottleManager.aidl b/core/java/android/net/IThrottleManager.aidl
new file mode 100644
index 0000000..a12469d
--- /dev/null
+++ b/core/java/android/net/IThrottleManager.aidl
@@ -0,0 +1,40 @@
+/**
+ * Copyright (c) 2010, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net;
+
+import android.os.IBinder;
+
+/**
+ * Interface that answers queries about data transfer amounts and throttling
+ */
+/** {@hide} */
+interface IThrottleManager
+{
+ long getByteCount(String iface, int dir, int period, int ago);
+
+ int getThrottle(String iface);
+
+ long getResetTime(String iface);
+
+ long getPeriodStartTime(String iface);
+
+ long getCliffThreshold(String iface, int cliff);
+
+ int getCliffLevel(String iface, int cliff);
+
+ String getHelpUri();
+}
diff --git a/core/java/android/net/ThrottleManager.java b/core/java/android/net/ThrottleManager.java
new file mode 100644
index 0000000..5fdac58
--- /dev/null
+++ b/core/java/android/net/ThrottleManager.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net;
+
+import android.annotation.SdkConstant;
+import android.annotation.SdkConstant.SdkConstantType;
+import android.os.Binder;
+import android.os.RemoteException;
+
+/**
+ * Class that handles throttling. It provides read/write numbers per interface
+ * and methods to apply throttled rates.
+ * {@hide}
+ */
+public class ThrottleManager
+{
+ /**
+ * Broadcast each polling period to indicate new data counts.
+ *
+ * Includes four extras:
+ * EXTRA_CYCLE_READ - a long of the read bytecount for the current cycle
+ * EXTRA_CYCLE_WRITE -a long of the write bytecount for the current cycle
+ * EXTRA_CYLCE_START -a long of MS for the cycle start time
+ * EXTRA_CYCLE_END -a long of MS for the cycle stop time
+ * {@hide}
+ */
+ public static final String THROTTLE_POLL_ACTION = "android.net.thrott.POLL_ACTION";
+ /**
+ * The lookup key for a long for the read bytecount for this period. Retrieve with
+ * {@link android.content.Intent#getLongExtra(String)}.
+ * {@hide}
+ */
+ public static final String EXTRA_CYCLE_READ = "cycleRead";
+ /**
+ * contains a long of the number of bytes written in the cycle
+ * {@hide}
+ */
+ public static final String EXTRA_CYCLE_WRITE = "cycleWrite";
+ /**
+ * contains a long of the number of bytes read in the cycle
+ * {@hide}
+ */
+ public static final String EXTRA_CYCLE_START = "cycleStart";
+ /**
+ * contains a long of the ms since 1970 used to init a calendar, etc for the end
+ * of the cycle
+ * {@hide}
+ */
+ public static final String EXTRA_CYCLE_END = "cycleEnd";
+
+ /**
+ * Broadcast when the thottle level changes.
+ * {@hide}
+ */
+ public static final String THROTTLE_ACTION = "android.net.thrott.THROTTLE_ACTION";
+ /**
+ * int of the current bandwidth in TODO
+ * {@hide}
+ */
+ public static final String EXTRA_THROTTLE_LEVEL = "level";
+
+ /**
+ * Broadcast on boot and whenever the settings change.
+ * {@hide}
+ */
+ public static final String POLICY_CHANGED_ACTION = "android.net.thrott.POLICY_CHANGED_ACTION";
+
+ // {@hide}
+ public static final int DIRECTION_TX = 0;
+ // {@hide}
+ public static final int DIRECTION_RX = 1;
+
+ // {@hide}
+ public static final int PERIOD_CYCLE = 0;
+ // {@hide}
+ public static final int PERIOD_YEAR = 1;
+ // {@hide}
+ public static final int PERIOD_MONTH = 2;
+ // {@hide}
+ public static final int PERIOD_WEEK = 3;
+ // @hide
+ public static final int PERIOD_7DAY = 4;
+ // @hide
+ public static final int PERIOD_DAY = 5;
+ // @hide
+ public static final int PERIOD_24HOUR = 6;
+ // @hide
+ public static final int PERIOD_HOUR = 7;
+ // @hide
+ public static final int PERIOD_60MIN = 8;
+ // @hide
+ public static final int PERIOD_MINUTE = 9;
+ // @hide
+ public static final int PERIOD_60SEC = 10;
+ // @hide
+ public static final int PERIOD_SECOND = 11;
+
+
+
+ /**
+ * returns a long of the ms from the epoch to the time the current cycle ends for the
+ * named interface
+ * {@hide}
+ */
+ public long getResetTime(String iface) {
+ try {
+ return mService.getResetTime(iface);
+ } catch (RemoteException e) {
+ return -1;
+ }
+ }
+
+ /**
+ * returns a long of the ms from the epoch to the time the current cycle started for the
+ * named interface
+ * {@hide}
+ */
+ public long getPeriodStartTime(String iface) {
+ try {
+ return mService.getPeriodStartTime(iface);
+ } catch (RemoteException e) {
+ return -1;
+ }
+ }
+
+ /**
+ * returns a long of the byte count either read or written on the named interface
+ * for the period described. Direction is either DIRECTION_RX or DIRECTION_TX and
+ * period may only be PERIOD_CYCLE for the current cycle (other periods may be supported
+ * in the future). Ago indicates the number of periods in the past to lookup - 0 means
+ * the current period, 1 is the last one, 2 was two periods ago..
+ * {@hide}
+ */
+ public long getByteCount(String iface, int direction, int period, int ago) {
+ try {
+ return mService.getByteCount(iface, direction, period, ago);
+ } catch (RemoteException e) {
+ return -1;
+ }
+ }
+
+ /**
+ * returns the number of bytes read+written after which a particular cliff
+ * takes effect on the named iface. Currently only cliff #1 is supported (1 step)
+ * {@hide}
+ */
+ public long getCliffThreshold(String iface, int cliff) {
+ try {
+ return mService.getCliffThreshold(iface, cliff);
+ } catch (RemoteException e) {
+ return -1;
+ }
+ }
+
+ /**
+ * returns the thottling bandwidth (bps) for a given cliff # on the named iface.
+ * only cliff #1 is currently supported.
+ * {@hide}
+ */
+ public int getCliffLevel(String iface, int cliff) {
+ try {
+ return mService.getCliffLevel(iface, cliff);
+ } catch (RemoteException e) {
+ return -1;
+ }
+ }
+
+ /**
+ * returns the help URI for throttling
+ * {@hide}
+ */
+ public String getHelpUri() {
+ try {
+ return mService.getHelpUri();
+ } catch (RemoteException e) {
+ return null;
+ }
+ }
+
+
+ private IThrottleManager mService;
+
+ /**
+ * Don't allow use of default constructor.
+ */
+ @SuppressWarnings({"UnusedDeclaration"})
+ private ThrottleManager() {
+ }
+
+ /**
+ * {@hide}
+ */
+ public ThrottleManager(IThrottleManager service) {
+ if (service == null) {
+ throw new IllegalArgumentException(
+ "ThrottleManager() cannot be constructed with null service");
+ }
+ mService = service;
+ }
+}
diff --git a/core/java/android/net/TrafficStats.java b/core/java/android/net/TrafficStats.java
index ad8e2bf..0d64dab 100644
--- a/core/java/android/net/TrafficStats.java
+++ b/core/java/android/net/TrafficStats.java
@@ -23,12 +23,12 @@
import java.io.IOException;
/**
- * Class that provides network traffic statistics. These statistics include bytes transmitted and
- * received and network packets transmitted and received, over all interfaces, over the mobile
- * interface, and on a per-UID basis.
+ * Class that provides network traffic statistics. These statistics include
+ * bytes transmitted and received and network packets transmitted and received,
+ * over all interfaces, over the mobile interface, and on a per-UID basis.
* <p>
- * These statistics may not be available on all platforms. If the statistics are not supported
- * by this device, {@link #UNSUPPORTED} will be returned.
+ * These statistics may not be available on all platforms. If the statistics
+ * are not supported by this device, {@link #UNSUPPORTED} will be returned.
*/
public class TrafficStats {
/**
@@ -36,27 +36,13 @@
*/
public final static int UNSUPPORTED = -1;
- // Logging tag.
- private final static String TAG = "trafficstats";
-
- // We pre-create all the File objects so we don't spend a lot of
- // CPU at runtime converting from Java Strings to byte[] for the
- // kernel calls.
- private final static File[] MOBILE_TX_PACKETS = mobileFiles("tx_packets");
- private final static File[] MOBILE_RX_PACKETS = mobileFiles("rx_packets");
- private final static File[] MOBILE_TX_BYTES = mobileFiles("tx_bytes");
- private final static File[] MOBILE_RX_BYTES = mobileFiles("rx_bytes");
- private final static File SYS_CLASS_NET_DIR = new File("/sys/class/net");
-
/**
* Get the total number of packets transmitted through the mobile interface.
*
* @return number of packets. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
*/
- public static long getMobileTxPackets() {
- return getMobileStat(MOBILE_TX_PACKETS);
- }
+ public static native long getMobileTxPackets();
/**
* Get the total number of packets received through the mobile interface.
@@ -64,9 +50,7 @@
* @return number of packets. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
*/
- public static long getMobileRxPackets() {
- return getMobileStat(MOBILE_RX_PACKETS);
- }
+ public static native long getMobileRxPackets();
/**
* Get the total number of bytes transmitted through the mobile interface.
@@ -74,9 +58,7 @@
* @return number of bytes. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
*/
- public static long getMobileTxBytes() {
- return getMobileStat(MOBILE_TX_BYTES);
- }
+ public static native long getMobileTxBytes();
/**
* Get the total number of bytes received through the mobile interface.
@@ -84,9 +66,7 @@
* @return number of bytes. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
*/
- public static long getMobileRxBytes() {
- return getMobileStat(MOBILE_RX_BYTES);
- }
+ public static native long getMobileRxBytes();
/**
* Get the total number of packets sent through all network interfaces.
@@ -94,9 +74,7 @@
* @return the number of packets. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
*/
- public static long getTotalTxPackets() {
- return getTotalStat("tx_packets");
- }
+ public static native long getTotalTxPackets();
/**
* Get the total number of packets received through all network interfaces.
@@ -104,9 +82,7 @@
* @return number of packets. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
*/
- public static long getTotalRxPackets() {
- return getTotalStat("rx_packets");
- }
+ public static native long getTotalRxPackets();
/**
* Get the total number of bytes sent through all network interfaces.
@@ -114,9 +90,7 @@
* @return number of bytes. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
*/
- public static long getTotalTxBytes() {
- return getTotalStat("tx_bytes");
- }
+ public static native long getTotalTxBytes();
/**
* Get the total number of bytes received through all network interfaces.
@@ -124,9 +98,7 @@
* @return number of bytes. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
*/
- public static long getTotalRxBytes() {
- return getTotalStat("rx_bytes");
- }
+ public static native long getTotalRxBytes();
/**
* Get the number of bytes sent through the network for this UID.
@@ -138,9 +110,7 @@
* @return number of bytes. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
*/
- public static long getUidTxBytes(int uid) {
- return getNumberFromFilePath("/proc/uid_stat/" + uid + "/tcp_snd");
- }
+ public static native long getUidTxBytes(int uid);
/**
* Get the number of bytes received through the network for this UID.
@@ -151,115 +121,5 @@
* @param uid The UID of the process to examine.
* @return number of bytes
*/
- public static long getUidRxBytes(int uid) {
- return getNumberFromFilePath("/proc/uid_stat/" + uid + "/tcp_rcv");
- }
-
- /**
- * Returns the array of two possible File locations for a given
- * statistic.
- */
- private static File[] mobileFiles(String whatStat) {
- // Note that we stat them at runtime to see which is
- // available, rather than here, to guard against the files
- // coming & going later as modules shut down (e.g. airplane
- // mode) and whatnot. The runtime stat() isn't expensive compared
- // to the previous charset conversion that happened before we
- // were reusing File instances.
- File[] files = new File[2];
- files[0] = new File("/sys/class/net/rmnet0/statistics/" + whatStat);
- files[1] = new File("/sys/class/net/ppp0/statistics/" + whatStat);
- return files;
- }
-
- private static long getTotalStat(String whatStat) {
- File netdir = new File("/sys/class/net");
-
- File[] nets = SYS_CLASS_NET_DIR.listFiles();
- if (nets == null) {
- return UNSUPPORTED;
- }
- long total = 0;
- StringBuffer strbuf = new StringBuffer();
- for (File net : nets) {
- strbuf.append(net.getPath()).append(File.separator).append("statistics")
- .append(File.separator).append(whatStat);
- total += getNumberFromFilePath(strbuf.toString());
- strbuf.setLength(0);
- }
- return total;
- }
-
- private static long getMobileStat(File[] files) {
- for (int i = 0; i < files.length; i++) {
- File file = files[i];
- if (!file.exists()) {
- continue;
- }
- try {
- RandomAccessFile raf = new RandomAccessFile(file, "r");
- return getNumberFromFile(raf, file.getAbsolutePath());
- } catch (IOException e) {
- Log.w(TAG,
- "Exception opening TCP statistics file " + file.getAbsolutePath(),
- e);
- }
- }
- return UNSUPPORTED;
- }
-
- // File will have format <number><newline>
- private static long getNumberFromFilePath(String filename) {
- RandomAccessFile raf = getFile(filename);
- if (raf == null) {
- return UNSUPPORTED;
- }
- return getNumberFromFile(raf, filename);
- }
-
- // Private buffer for getNumberFromFile. Safe for re-use because
- // getNumberFromFile is synchronized.
- private final static byte[] buf = new byte[16];
-
- private static synchronized long getNumberFromFile(RandomAccessFile raf, String filename) {
- try {
- raf.read(buf);
- raf.close();
- } catch (IOException e) {
- Log.w(TAG, "Exception getting TCP bytes from " + filename, e);
- return UNSUPPORTED;
- } finally {
- if (raf != null) {
- try {
- raf.close();
- } catch (IOException e) {
- Log.w(TAG, "Exception closing " + filename, e);
- }
- }
- }
-
- long num = 0L;
- for (int i = 0; i < buf.length; i++) {
- if (buf[i] < '0' || buf[i] > '9') {
- break;
- }
- num *= 10;
- num += buf[i] - '0';
- }
- return num;
- }
-
- private static RandomAccessFile getFile(String filename) {
- File f = new File(filename);
- if (!f.canRead()) {
- return null;
- }
-
- try {
- return new RandomAccessFile(f, "r");
- } catch (IOException e) {
- Log.w(TAG, "Exception opening TCP statistics file " + filename, e);
- return null;
- }
- }
+ public static native long getUidRxBytes(int uid);
}
diff --git a/core/java/android/net/http/AndroidHttpClient.java b/core/java/android/net/http/AndroidHttpClient.java
index 3517737..e07ee59 100644
--- a/core/java/android/net/http/AndroidHttpClient.java
+++ b/core/java/android/net/http/AndroidHttpClient.java
@@ -16,6 +16,7 @@
package android.net.http;
+import com.android.internal.http.HttpDateTime;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
@@ -444,4 +445,22 @@
return builder.toString();
}
+
+ /**
+ * Returns the date of the given HTTP date string. This method can identify
+ * and parse the date formats emitted by common HTTP servers, such as
+ * <a href="http://www.ietf.org/rfc/rfc0822.txt">RFC 822</a>,
+ * <a href="http://www.ietf.org/rfc/rfc0850.txt">RFC 850</a>,
+ * <a href="http://www.ietf.org/rfc/rfc1036.txt">RFC 1036</a>,
+ * <a href="http://www.ietf.org/rfc/rfc1123.txt">RFC 1123</a> and
+ * <a href="http://www.opengroup.org/onlinepubs/007908799/xsh/asctime.html">ANSI
+ * C's asctime()</a>.
+ *
+ * @return the number of milliseconds since Jan. 1, 1970, midnight GMT.
+ * @throws IllegalArgumentException if {@code dateString} is not a date or
+ * of an unsupported format.
+ */
+ public static long parseDate(String dateString) {
+ return HttpDateTime.parse(dateString);
+ }
}
diff --git a/core/java/android/os/RecoverySystem.java b/core/java/android/os/RecoverySystem.java
index b3ec114..b6dc1b5 100644
--- a/core/java/android/os/RecoverySystem.java
+++ b/core/java/android/os/RecoverySystem.java
@@ -304,9 +304,7 @@
/**
* Reboots the device in order to install the given update
* package.
- * Requires the {@link android.Manifest.permission#REBOOT}
- * and {@link android.Manifest.permission#ACCESS_CACHE_FILESYSTEM}
- * permissions.
+ * Requires the {@link android.Manifest.permission#REBOOT} permission.
*
* @param context the Context to use
* @param packageFile the update package to install. Currently
@@ -337,9 +335,7 @@
* sometimes called a "factory reset", which is something of a
* misnomer because the system partition is not restored to its
* factory state.
- * Requires the {@link android.Manifest.permission#REBOOT}
- * and {@link android.Manifest.permission#ACCESS_CACHE_FILESYSTEM}
- * permissions.
+ * Requires the {@link android.Manifest.permission#REBOOT} permission.
*
* @param context the Context to use
*
diff --git a/core/java/android/provider/Browser.java b/core/java/android/provider/Browser.java
index b466b40..2fba1d79 100644
--- a/core/java/android/provider/Browser.java
+++ b/core/java/android/provider/Browser.java
@@ -574,7 +574,9 @@
}
/**
- * Request all icons from the database.
+ * Request all icons from the database. This call must either be called
+ * in the main thread or have had Looper.prepare() invoked in the calling
+ * thread.
* Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
* @param cr The ContentResolver used to access the database.
* @param where Clause to be used to limit the query from the database.
@@ -584,25 +586,8 @@
*/
public static final void requestAllIcons(ContentResolver cr, String where,
WebIconDatabase.IconListener listener) {
- Cursor c = null;
- try {
- c = cr.query(
- BOOKMARKS_URI,
- new String[] { BookmarkColumns.URL },
- where, null, null);
- if (c.moveToFirst()) {
- final WebIconDatabase db = WebIconDatabase.getInstance();
- do {
- db.requestIconForPageUrl(c.getString(0), listener);
- } while (c.moveToNext());
- }
- } catch (IllegalStateException e) {
- Log.e(LOGTAG, "requestAllIcons", e);
- } finally {
- if (c != null) {
- c.close();
- }
- }
+ WebIconDatabase.getInstance()
+ .bulkRequestIconForPageUrl(cr, where, listener);
}
public static class BookmarkColumns implements BaseColumns {
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index c07ac31..e8c09b0 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -3295,7 +3295,44 @@
* @hide
*/
public static final String DEFAULT_INSTALL_LOCATION = "default_install_location";
-
+
+ /**
+ * The bandwidth throttle polling freqency in seconds
+ * @hide
+ */
+ public static final String THROTTLE_POLLING_SEC = "throttle_polling_sec";
+
+ /**
+ * The bandwidth throttle threshold (long)
+ * @hide
+ */
+ public static final String THROTTLE_THRESHOLD_BYTES = "throttle_threshold_bytes";
+
+ /**
+ * The bandwidth throttle value (kbps)
+ * @hide
+ */
+ public static final String THROTTLE_VALUE_KBITSPS = "throttle_value_kbitsps";
+
+ /**
+ * The bandwidth throttle reset calendar day (1-28)
+ * @hide
+ */
+ public static final String THROTTLE_RESET_DAY = "throttle_reset_day";
+
+ /**
+ * The throttling notifications we should send
+ * @hide
+ */
+ public static final String THROTTLE_NOTIFICATION_TYPE = "throttle_notification_type";
+
+ /**
+ * Help URI for data throttling policy
+ * @hide
+ */
+ public static final String THROTTLE_HELP_URI = "throttle_help_uri";
+
+
/**
* @hide
*/
diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java
index 096ad39..893db2e 100644
--- a/core/java/android/server/BluetoothA2dpService.java
+++ b/core/java/android/server/BluetoothA2dpService.java
@@ -313,6 +313,8 @@
"Need BLUETOOTH_ADMIN permission");
if (DBG) log("connectSink(" + device + ")");
+ if (!mBluetoothService.isEnabled()) return false;
+
// ignore if there are any active sinks
if (lookupSinksMatchingStates(new int[] {
BluetoothA2dp.STATE_CONNECTING,
@@ -485,12 +487,6 @@
if (state != prevState) {
if (state == BluetoothA2dp.STATE_DISCONNECTED ||
state == BluetoothA2dp.STATE_DISCONNECTING) {
- if (prevState == BluetoothA2dp.STATE_CONNECTED ||
- prevState == BluetoothA2dp.STATE_PLAYING) {
- // disconnecting or disconnected
- Intent intent = new Intent(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
- mContext.sendBroadcast(intent);
- }
mSinkCount--;
} else if (state == BluetoothA2dp.STATE_CONNECTED) {
mSinkCount ++;
diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index e56a6fe..bf94707 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -766,7 +766,7 @@
// make sure touch mode code executes by setting cached value
// to opposite of the added touch mode.
mAttachInfo.mInTouchMode = !mAddedTouchMode;
- ensureTouchModeLocally(mAddedTouchMode, false);
+ ensureTouchModeLocally(mAddedTouchMode);
} else {
if (!mAttachInfo.mContentInsets.equals(mPendingContentInsets)) {
mAttachInfo.mContentInsets.set(mPendingContentInsets);
@@ -983,7 +983,7 @@
}
boolean focusChangedDueToTouchMode = ensureTouchModeLocally(
- (relayoutResult&WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE) != 0, true);
+ (relayoutResult&WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE) != 0);
if (focusChangedDueToTouchMode || mWidth != host.mMeasuredWidth
|| mHeight != host.mMeasuredHeight || contentInsetsChanged) {
childWidthMeasureSpec = getRootMeasureSpec(mWidth, lp.width);
@@ -1043,13 +1043,6 @@
startTime = SystemClock.elapsedRealtime();
}
host.layout(0, 0, host.mMeasuredWidth, host.mMeasuredHeight);
- if (mFirst) {
- if (mAddedTouchMode) {
- enterTouchMode();
- } else {
- leaveTouchMode();
- }
- }
if (Config.DEBUG && ViewDebug.consistencyCheckEnabled) {
if (!host.dispatchConsistencyCheck(ViewDebug.CONSISTENCY_LAYOUT)) {
@@ -1899,7 +1892,7 @@
mAttachInfo.mHasWindowFocus = hasWindowFocus;
if (hasWindowFocus) {
boolean inTouchMode = msg.arg2 != 0;
- ensureTouchModeLocally(inTouchMode, true);
+ ensureTouchModeLocally(inTouchMode);
if (mGlWanted) {
checkEglErrors();
@@ -2009,17 +2002,16 @@
}
// handle the change
- return ensureTouchModeLocally(inTouchMode, true);
+ return ensureTouchModeLocally(inTouchMode);
}
/**
* Ensure that the touch mode for this window is set, and if it is changing,
* take the appropriate action.
* @param inTouchMode Whether we want to be in touch mode.
- * @param dispatchFocus
* @return True if the touch mode changed and focus changed was changed as a result
*/
- private boolean ensureTouchModeLocally(boolean inTouchMode, boolean dispatchFocus) {
+ private boolean ensureTouchModeLocally(boolean inTouchMode) {
if (DBG) Log.d("touchmode", "ensureTouchModeLocally(" + inTouchMode + "), current "
+ "touch mode is " + mAttachInfo.mInTouchMode);
@@ -2028,7 +2020,7 @@
mAttachInfo.mInTouchMode = inTouchMode;
mAttachInfo.mTreeObserver.dispatchOnTouchModeChanged(inTouchMode);
- return dispatchFocus && (inTouchMode) ? enterTouchMode() : leaveTouchMode();
+ return (inTouchMode) ? enterTouchMode() : leaveTouchMode();
}
private boolean enterTouchMode() {
diff --git a/core/java/android/webkit/CacheManager.java b/core/java/android/webkit/CacheManager.java
index d19805e..d5058b0 100644
--- a/core/java/android/webkit/CacheManager.java
+++ b/core/java/android/webkit/CacheManager.java
@@ -17,8 +17,8 @@
package android.webkit;
import android.content.Context;
+import android.net.http.AndroidHttpClient;
import android.net.http.Headers;
-import android.net.http.HttpDateTime;
import android.os.FileUtils;
import android.util.Log;
import java.io.File;
@@ -716,7 +716,7 @@
ret.expiresString = headers.getExpires();
if (ret.expiresString != null) {
try {
- ret.expires = HttpDateTime.parse(ret.expiresString);
+ ret.expires = AndroidHttpClient.parseDate(ret.expiresString);
} catch (IllegalArgumentException ex) {
// Take care of the special "-1" and "0" cases
if ("-1".equals(ret.expiresString)
@@ -831,7 +831,7 @@
// 24 * 60 * 60 * 1000
long lastmod = System.currentTimeMillis() + 86400000;
try {
- lastmod = HttpDateTime.parse(ret.lastModified);
+ lastmod = AndroidHttpClient.parseDate(ret.lastModified);
} catch (IllegalArgumentException ex) {
Log.e(LOGTAG, "illegal lastModified: " + ret.lastModified);
}
diff --git a/core/java/android/webkit/CookieManager.java b/core/java/android/webkit/CookieManager.java
index 758a152..ac20791 100644
--- a/core/java/android/webkit/CookieManager.java
+++ b/core/java/android/webkit/CookieManager.java
@@ -18,7 +18,7 @@
import android.net.ParseException;
import android.net.WebAddress;
-import android.net.http.HttpDateTime;
+import android.net.http.AndroidHttpClient;
import android.util.Log;
@@ -939,7 +939,7 @@
}
if (name.equals(EXPIRES)) {
try {
- cookie.expires = HttpDateTime.parse(value);
+ cookie.expires = AndroidHttpClient.parseDate(value);
} catch (IllegalArgumentException ex) {
Log.e(LOGTAG,
"illegal format for expires: " + value);
diff --git a/core/java/android/webkit/FrameLoader.java b/core/java/android/webkit/FrameLoader.java
index 906264a..7fd993a 100644
--- a/core/java/android/webkit/FrameLoader.java
+++ b/core/java/android/webkit/FrameLoader.java
@@ -102,8 +102,9 @@
com.android.internal.R.string.httpErrorBadUrl));
return false;
}
- // Make sure it is correctly URL encoded before sending the request
- if (!URLUtil.verifyURLEncoding(url)) {
+ // Make sure the host part of the url is correctly
+ // encoded before sending the request
+ if (!URLUtil.verifyURLEncoding(mListener.host())) {
mListener.error(EventHandler.ERROR_BAD_URL,
mListener.getContext().getString(
com.android.internal.R.string.httpErrorBadUrl));
diff --git a/core/java/android/webkit/HTML5VideoViewProxy.java b/core/java/android/webkit/HTML5VideoViewProxy.java
index eee8025..eda2e72 100644
--- a/core/java/android/webkit/HTML5VideoViewProxy.java
+++ b/core/java/android/webkit/HTML5VideoViewProxy.java
@@ -132,6 +132,7 @@
if (mVideoView.isPlaying()) {
mVideoView.stopPlayback();
}
+ mCurrentProxy.dispatchOnEnded();
mCurrentProxy = null;
mLayout.removeView(mVideoView);
mVideoView = null;
@@ -154,7 +155,7 @@
if (mCurrentProxy != null) {
// Some other video is already playing. Notify the caller that its playback ended.
- proxy.playbackEnded();
+ proxy.dispatchOnEnded();
return;
}
@@ -245,7 +246,10 @@
// MediaPlayer.OnCompletionListener;
public void onCompletion(MediaPlayer mp) {
- playbackEnded();
+ // The video ended by itself, so we need to
+ // send a message to the UI thread to dismiss
+ // the video view and to return to the WebView.
+ sendMessage(obtainMessage(ENDED));
}
// MediaPlayer.OnErrorListener
@@ -254,11 +258,9 @@
return false;
}
- public void playbackEnded() {
+ public void dispatchOnEnded() {
Message msg = Message.obtain(mWebCoreHandler, ENDED);
mWebCoreHandler.sendMessage(msg);
- // also send a message to ourselves to return to the WebView
- sendMessage(obtainMessage(ENDED));
}
public void onTimeupdate() {
diff --git a/core/java/android/webkit/LoadListener.java b/core/java/android/webkit/LoadListener.java
index 1130e95..e0f8bc0 100644
--- a/core/java/android/webkit/LoadListener.java
+++ b/core/java/android/webkit/LoadListener.java
@@ -380,7 +380,8 @@
}
// At this point, mMimeType has been set to non-null.
if (mIsMainPageLoader && mIsMainResourceLoader && mUserGesture &&
- Pattern.matches(XML_MIME_TYPE, mMimeType)) {
+ Pattern.matches(XML_MIME_TYPE, mMimeType) &&
+ !mMimeType.equalsIgnoreCase("application/xhtml+xml")) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse(url()), mMimeType);
ResolveInfo info = mContext.getPackageManager().resolveActivity(i,
@@ -475,6 +476,7 @@
}
WebViewWorker.CacheEncoding ce = new WebViewWorker.CacheEncoding();
ce.mEncoding = mEncoding;
+ ce.mListener = this;
WebViewWorker.getHandler().obtainMessage(
WebViewWorker.MSG_UPDATE_CACHE_ENCODING, ce).sendToTarget();
}
diff --git a/core/java/android/webkit/WebIconDatabase.java b/core/java/android/webkit/WebIconDatabase.java
index 6cc6bb4..bb9ec48 100644
--- a/core/java/android/webkit/WebIconDatabase.java
+++ b/core/java/android/webkit/WebIconDatabase.java
@@ -16,10 +16,15 @@
package android.webkit;
+import android.content.ContentResolver;
+import android.database.Cursor;
+import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;
-import android.graphics.Bitmap;
+import android.provider.Browser;
+import android.util.Log;
+import java.util.HashMap;
import java.util.Vector;
/**
@@ -30,6 +35,7 @@
* single object.
*/
public final class WebIconDatabase {
+ private static final String LOGTAG = "WebIconDatabase";
// Global instance of a WebIconDatabase
private static WebIconDatabase sIconDatabase;
// EventHandler for handling messages before and after the WebCore thread is
@@ -45,6 +51,7 @@
static final int REQUEST_ICON = 3;
static final int RETAIN_ICON = 4;
static final int RELEASE_ICON = 5;
+ static final int BULK_REQUEST_ICON = 6;
// Message for dispatching icon request results
private static final int ICON_RESULT = 10;
// Actual handler that runs in WebCore thread
@@ -100,12 +107,11 @@
case REQUEST_ICON:
IconListener l = (IconListener) msg.obj;
String url = msg.getData().getString("url");
- Bitmap icon = nativeIconForPageUrl(url);
- if (icon != null) {
- EventHandler.this.sendMessage(
- Message.obtain(null, ICON_RESULT,
- new IconResult(url, icon, l)));
- }
+ requestIconAndSendResult(url, l);
+ break;
+
+ case BULK_REQUEST_ICON:
+ bulkRequestIcons(msg);
break;
case RETAIN_ICON:
@@ -126,6 +132,10 @@
}
}
+ private synchronized boolean hasHandler() {
+ return mHandler != null;
+ }
+
private synchronized void postMessage(Message msg) {
if (mMessages != null) {
mMessages.add(msg);
@@ -133,6 +143,39 @@
mHandler.sendMessage(msg);
}
}
+
+ private void bulkRequestIcons(Message msg) {
+ HashMap map = (HashMap) msg.obj;
+ IconListener listener = (IconListener) map.get("listener");
+ ContentResolver cr = (ContentResolver) map.get("contentResolver");
+ String where = (String) map.get("where");
+
+ Cursor c = null;
+ try {
+ c = cr.query(
+ Browser.BOOKMARKS_URI,
+ new String[] { Browser.BookmarkColumns.URL },
+ where, null, null);
+ if (c.moveToFirst()) {
+ do {
+ String url = c.getString(0);
+ requestIconAndSendResult(url, listener);
+ } while (c.moveToNext());
+ }
+ } catch (IllegalStateException e) {
+ Log.e(LOGTAG, "BulkRequestIcons", e);
+ } finally {
+ if (c != null) c.close();
+ }
+ }
+
+ private void requestIconAndSendResult(String url, IconListener listener) {
+ Bitmap icon = nativeIconForPageUrl(url);
+ if (icon != null) {
+ sendMessage(obtainMessage(ICON_RESULT,
+ new IconResult(url, icon, listener)));
+ }
+ }
}
/**
@@ -192,6 +235,30 @@
mEventHandler.postMessage(msg);
}
+ /** {@hide}
+ */
+ public void bulkRequestIconForPageUrl(ContentResolver cr, String where,
+ IconListener listener) {
+ if (listener == null) {
+ return;
+ }
+
+ // Special case situation: we don't want to add this message to the
+ // queue if there is no handler because we may never have a real
+ // handler to service the messages and the cursor will never get
+ // closed.
+ if (mEventHandler.hasHandler()) {
+ // Don't use Bundle as it is parcelable.
+ HashMap<String, Object> map = new HashMap<String, Object>();
+ map.put("contentResolver", cr);
+ map.put("where", where);
+ map.put("listener", listener);
+ Message msg =
+ Message.obtain(null, EventHandler.BULK_REQUEST_ICON, map);
+ mEventHandler.postMessage(msg);
+ }
+ }
+
/**
* Retain the icon for the given page url.
* @param url The page's url.
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java
index 870f512c..dc952e6 100644
--- a/core/java/android/webkit/WebTextView.java
+++ b/core/java/android/webkit/WebTextView.java
@@ -343,6 +343,7 @@
@Override
protected void onSelectionChanged(int selStart, int selEnd) {
+ if (mInSetTextAndKeepSelection) return;
// This code is copied from TextView.onDraw(). That code does not get
// executed, however, because the WebTextView does not draw, allowing
// webkit's drawing to show through.
@@ -799,8 +800,14 @@
/* package */ void setTextAndKeepSelection(String text) {
mPreChange = text.toString();
Editable edit = (Editable) getText();
+ int selStart = Selection.getSelectionStart(edit);
+ int selEnd = Selection.getSelectionEnd(edit);
mInSetTextAndKeepSelection = true;
edit.replace(0, edit.length(), text);
+ int newLength = edit.length();
+ if (selStart > newLength) selStart = newLength;
+ if (selEnd > newLength) selEnd = newLength;
+ Selection.setSelection(edit, selStart, selEnd);
mInSetTextAndKeepSelection = false;
updateCachedTextfield();
}
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 0526362..602eedf 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -475,6 +475,7 @@
private static final int MOTIONLESS_FALSE = 0;
private static final int MOTIONLESS_PENDING = 1;
private static final int MOTIONLESS_TRUE = 2;
+ private static final int MOTIONLESS_IGNORE = 3;
private int mHeldMotionless;
// whether support multi-touch
@@ -539,10 +540,10 @@
static final int FIND_AGAIN = 126;
static final int CENTER_FIT_RECT = 127;
static final int REQUEST_KEYBOARD_WITH_SELECTION_MSG_ID = 128;
+ static final int SET_SCROLLBAR_MODES = 129;
private static final int FIRST_PACKAGE_MSG_ID = SCROLL_TO_MSG_ID;
- private static final int LAST_PACKAGE_MSG_ID
- = REQUEST_KEYBOARD_WITH_SELECTION_MSG_ID;
+ private static final int LAST_PACKAGE_MSG_ID = SET_SCROLLBAR_MODES;
static final String[] HandlerPrivateDebugString = {
"REMEMBER_PASSWORD", // = 1;
@@ -585,7 +586,8 @@
"RETURN_LABEL", // = 125;
"FIND_AGAIN", // = 126;
"CENTER_FIT_RECT", // = 127;
- "REQUEST_KEYBOARD_WITH_SELECTION_MSG_ID" // = 128;
+ "REQUEST_KEYBOARD_WITH_SELECTION_MSG_ID", // = 128;
+ "SET_SCROLLBAR_MODES" // = 129;
};
// If the site doesn't use the viewport meta tag to specify the viewport,
@@ -656,6 +658,14 @@
private static final int DRAW_EXTRAS_SELECTION = 2;
private static final int DRAW_EXTRAS_CURSOR_RING = 3;
+ // keep this in sync with WebCore:ScrollbarMode in WebKit
+ private static final int SCROLLBAR_AUTO = 0;
+ private static final int SCROLLBAR_ALWAYSOFF = 1;
+ // as we auto fade scrollbar, this is ignored.
+ private static final int SCROLLBAR_ALWAYSON = 2;
+ private int mHorizontalScrollBarMode = SCROLLBAR_AUTO;
+ private int mVerticalScrollBarMode = SCROLLBAR_AUTO;
+
// Used to match key downs and key ups
private boolean mGotKeyDown;
@@ -1274,30 +1284,57 @@
* overwritten with this WebView's picture data.
* @return True if the picture was successfully saved.
*/
- public boolean savePicture(Bundle b, File dest) {
+ public boolean savePicture(Bundle b, final File dest) {
if (dest == null || b == null) {
return false;
}
final Picture p = capturePicture();
- try {
- final FileOutputStream out = new FileOutputStream(dest);
- p.writeToStream(out);
- out.close();
- // now update the bundle
- b.putInt("scrollX", mScrollX);
- b.putInt("scrollY", mScrollY);
- b.putFloat("scale", mActualScale);
- b.putFloat("textwrapScale", mTextWrapScale);
- b.putBoolean("overview", mInZoomOverview);
- return true;
- } catch (FileNotFoundException e){
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (RuntimeException e) {
- e.printStackTrace();
- }
- return false;
+ // Use a temporary file while writing to ensure the destination file
+ // contains valid data.
+ final File temp = new File(dest.getPath() + ".writing");
+ new Thread(new Runnable() {
+ public void run() {
+ try {
+ FileOutputStream out = new FileOutputStream(temp);
+ p.writeToStream(out);
+ out.close();
+ // Writing the picture succeeded, rename the temporary file
+ // to the destination.
+ temp.renameTo(dest);
+ } catch (Exception e) {
+ // too late to do anything about it.
+ } finally {
+ temp.delete();
+ }
+ }
+ }).start();
+ // now update the bundle
+ b.putInt("scrollX", mScrollX);
+ b.putInt("scrollY", mScrollY);
+ b.putFloat("scale", mActualScale);
+ b.putFloat("textwrapScale", mTextWrapScale);
+ b.putBoolean("overview", mInZoomOverview);
+ return true;
+ }
+
+ private void restoreHistoryPictureFields(Picture p, Bundle b) {
+ int sx = b.getInt("scrollX", 0);
+ int sy = b.getInt("scrollY", 0);
+ float scale = b.getFloat("scale", 1.0f);
+ mDrawHistory = true;
+ mHistoryPicture = p;
+ mScrollX = sx;
+ mScrollY = sy;
+ mHistoryWidth = Math.round(p.getWidth() * scale);
+ mHistoryHeight = Math.round(p.getHeight() * scale);
+ // as getWidth() / getHeight() of the view are not available yet, set up
+ // mActualScale, so that when onSizeChanged() is called, the rest will
+ // be set correctly
+ mActualScale = scale;
+ mInvActualScale = 1 / scale;
+ mTextWrapScale = b.getFloat("textwrapScale", scale);
+ mInZoomOverview = b.getBoolean("overview");
+ invalidate();
}
/**
@@ -1311,42 +1348,35 @@
if (src == null || b == null) {
return false;
}
- if (src.exists()) {
- Picture p = null;
- try {
- final FileInputStream in = new FileInputStream(src);
- p = Picture.createFromStream(in);
- in.close();
- } catch (FileNotFoundException e){
- e.printStackTrace();
- } catch (RuntimeException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- if (p != null) {
- int sx = b.getInt("scrollX", 0);
- int sy = b.getInt("scrollY", 0);
- float scale = b.getFloat("scale", 1.0f);
- mDrawHistory = true;
- mHistoryPicture = p;
- mScrollX = sx;
- mScrollY = sy;
- mHistoryWidth = Math.round(p.getWidth() * scale);
- mHistoryHeight = Math.round(p.getHeight() * scale);
- // as getWidth() / getHeight() of the view are not
- // available yet, set up mActualScale, so that when
- // onSizeChanged() is called, the rest will be set
- // correctly
- mActualScale = scale;
- mInvActualScale = 1 / scale;
- mTextWrapScale = b.getFloat("textwrapScale", scale);
- mInZoomOverview = b.getBoolean("overview");
- invalidate();
- return true;
- }
+ if (!src.exists()) {
+ return false;
}
- return false;
+ try {
+ final FileInputStream in = new FileInputStream(src);
+ final Bundle copy = new Bundle(b);
+ new Thread(new Runnable() {
+ public void run() {
+ final Picture p = Picture.createFromStream(in);
+ if (p != null) {
+ // Post a runnable on the main thread to update the
+ // history picture fields.
+ mPrivateHandler.post(new Runnable() {
+ public void run() {
+ restoreHistoryPictureFields(p, copy);
+ }
+ });
+ }
+ try {
+ in.close();
+ } catch (Exception e) {
+ // Nothing we can do now.
+ }
+ }
+ }).start();
+ } catch (FileNotFoundException e){
+ e.printStackTrace();
+ }
+ return true;
}
/**
@@ -1701,8 +1731,7 @@
* Return true if the browser is displaying a TextView for text input.
*/
private boolean inEditingMode() {
- return mWebTextView != null && mWebTextView.getParent() != null
- && mWebTextView.hasFocus();
+ return mWebTextView != null && mWebTextView.getParent() != null;
}
/**
@@ -2130,11 +2159,15 @@
mScrollX = pinLocX(Math.round(sx));
mScrollY = pinLocY(Math.round(sy));
+ // update webkit
if (oldX != mScrollX || oldY != mScrollY) {
onScrollChanged(mScrollX, mScrollY, oldX, oldY);
+ } else {
+ // the scroll position is adjusted at the beginning of the
+ // zoom animation. But we want to update the WebKit at the
+ // end of the zoom animation. See comments in onScaleEnd().
+ sendOurVisibleRect();
}
-
- // update webkit
sendViewSizeZoom();
}
}
@@ -2253,6 +2286,8 @@
protected int computeHorizontalScrollRange() {
if (mDrawHistory) {
return mHistoryWidth;
+ } else if (mHorizontalScrollBarMode == SCROLLBAR_ALWAYSOFF) {
+ return computeHorizontalScrollExtent();
} else {
// to avoid rounding error caused unnecessary scrollbar, use floor
return (int) Math.floor(mContentWidth * mActualScale);
@@ -2263,6 +2298,8 @@
protected int computeVerticalScrollRange() {
if (mDrawHistory) {
return mHistoryHeight;
+ } else if (mVerticalScrollBarMode == SCROLLBAR_ALWAYSOFF) {
+ return computeVerticalScrollExtent();
} else {
// to avoid rounding error caused unnecessary scrollbar, use floor
return (int) Math.floor(mContentHeight * mActualScale);
@@ -3339,6 +3376,7 @@
if (null == mWebViewCore) return; // CallbackProxy may trigger this
if (mDrawHistory && mWebViewCore.pictureReady()) {
mDrawHistory = false;
+ mHistoryPicture = null;
invalidate();
int oldScrollX = mScrollX;
int oldScrollY = mScrollY;
@@ -4634,13 +4672,16 @@
ted.mY = contentY;
ted.mMetaState = ev.getMetaState();
ted.mReprocess = mDeferTouchProcess;
- mWebViewCore.sendMessage(EventHub.TOUCH_EVENT, ted);
if (mDeferTouchProcess) {
// still needs to set them for compute deltaX/Y
mLastTouchX = x;
mLastTouchY = y;
+ ted.mViewX = x;
+ ted.mViewY = y;
+ mWebViewCore.sendMessage(EventHub.TOUCH_EVENT, ted);
break;
}
+ mWebViewCore.sendMessage(EventHub.TOUCH_EVENT, ted);
if (!inFullScreenMode()) {
mPrivateHandler.sendMessageDelayed(mPrivateHandler
.obtainMessage(PREVENT_DEFAULT_TIMEOUT,
@@ -4666,17 +4707,20 @@
// pass the touch events from UI thread to WebCore thread
if (shouldForwardTouchEvent() && mConfirmMove && (firstMove
|| eventTime - mLastSentTouchTime > mCurrentTouchInterval)) {
+ mLastSentTouchTime = eventTime;
TouchEventData ted = new TouchEventData();
ted.mAction = action;
ted.mX = contentX;
ted.mY = contentY;
ted.mMetaState = ev.getMetaState();
ted.mReprocess = mDeferTouchProcess;
- mWebViewCore.sendMessage(EventHub.TOUCH_EVENT, ted);
- mLastSentTouchTime = eventTime;
if (mDeferTouchProcess) {
+ ted.mViewX = x;
+ ted.mViewY = y;
+ mWebViewCore.sendMessage(EventHub.TOUCH_EVENT, ted);
break;
}
+ mWebViewCore.sendMessage(EventHub.TOUCH_EVENT, ted);
if (firstMove && !inFullScreenMode()) {
mPrivateHandler.sendMessageDelayed(mPrivateHandler
.obtainMessage(PREVENT_DEFAULT_TIMEOUT,
@@ -4841,6 +4885,10 @@
ted.mY = contentY;
ted.mMetaState = ev.getMetaState();
ted.mReprocess = mDeferTouchProcess;
+ if (mDeferTouchProcess) {
+ ted.mViewX = x;
+ ted.mViewY = y;
+ }
mWebViewCore.sendMessage(EventHub.TOUCH_EVENT, ted);
}
mLastTouchUpTime = eventTime;
@@ -4855,6 +4903,10 @@
ted.mY = contentY;
ted.mMetaState = ev.getMetaState();
ted.mReprocess = mDeferTouchProcess;
+ if (mDeferTouchProcess) {
+ ted.mViewX = x;
+ ted.mViewY = y;
+ }
mWebViewCore.sendMessage(EventHub.TOUCH_EVENT, ted);
} else if (mPreventDefault != PREVENT_DEFAULT_YES){
doDoubleTap();
@@ -4882,6 +4934,9 @@
// we will not rewrite drag code here, but we
// will try fling if it applies.
WebViewCore.reducePriority();
+ // to get better performance, pause updating the
+ // picture
+ WebViewCore.pauseUpdatePicture(mWebViewCore);
// fall through to TOUCH_DRAG_MODE
} else {
break;
@@ -4899,9 +4954,6 @@
case TOUCH_DRAG_MODE:
mPrivateHandler.removeMessages(DRAG_HELD_MOTIONLESS);
mPrivateHandler.removeMessages(AWAKEN_SCROLL_BARS);
- mHeldMotionless = MOTIONLESS_TRUE;
- // redraw in high-quality, as we're done dragging
- invalidate();
// if the user waits a while w/o moving before the
// up, we don't want to do a fling
if (eventTime - mLastTouchTime <= MIN_FLING_TIME) {
@@ -4913,11 +4965,24 @@
+ mDeferTouchProcess);
}
mVelocityTracker.addMovement(ev);
+ // set to MOTIONLESS_IGNORE so that it won't keep
+ // removing and sending message in
+ // drawCoreAndCursorRing()
+ mHeldMotionless = MOTIONLESS_IGNORE;
doFling();
break;
}
+ // redraw in high-quality, as we're done dragging
+ mHeldMotionless = MOTIONLESS_TRUE;
+ invalidate();
+ // fall through
+ case TOUCH_DRAG_START_MODE:
+ // TOUCH_DRAG_START_MODE should not happen for the real
+ // device as we almost certain will get a MOVE. But this
+ // is possible on emulator.
mLastVelocity = 0;
WebViewCore.resumePriority();
+ WebViewCore.resumeUpdatePicture(mWebViewCore);
break;
}
stopTouch();
@@ -4963,6 +5028,8 @@
private void startDrag() {
WebViewCore.reducePriority();
+ // to get better performance, pause updating the picture
+ WebViewCore.pauseUpdatePicture(mWebViewCore);
if (!mDragFromTextInput) {
nativeHideCursor();
}
@@ -4970,7 +5037,9 @@
if (settings.supportZoom()
&& settings.getBuiltInZoomControls()
&& !getZoomButtonsController().isVisible()
- && mMinZoomScale < mMaxZoomScale) {
+ && mMinZoomScale < mMaxZoomScale
+ && (mHorizontalScrollBarMode != SCROLLBAR_ALWAYSOFF
+ || mVerticalScrollBarMode != SCROLLBAR_ALWAYSOFF)) {
mZoomButtonsController.setVisible(true);
int count = settings.getDoubleTapToastCount();
if (mInZoomOverview && count > 0) {
@@ -5026,6 +5095,7 @@
}
if (mTouchMode == TOUCH_DRAG_MODE) {
WebViewCore.resumePriority();
+ WebViewCore.resumeUpdatePicture(mWebViewCore);
}
mPrivateHandler.removeMessages(SWITCH_TO_SHORTPRESS);
mPrivateHandler.removeMessages(SWITCH_TO_LONGPRESS);
@@ -5360,6 +5430,7 @@
}
if ((maxX == 0 && vy == 0) || (maxY == 0 && vx == 0)) {
WebViewCore.resumePriority();
+ WebViewCore.resumeUpdatePicture(mWebViewCore);
return;
}
float currentVelocity = mScroller.getCurrVelocity();
@@ -6114,6 +6185,10 @@
// simplicity for now, we don't set it.
ted.mMetaState = 0;
ted.mReprocess = mDeferTouchProcess;
+ if (mDeferTouchProcess) {
+ ted.mViewX = mLastTouchX;
+ ted.mViewY = mLastTouchY;
+ }
mWebViewCore.sendMessage(EventHub.TOUCH_EVENT, ted);
} else if (mPreventDefault != PREVENT_DEFAULT_YES) {
mTouchMode = TOUCH_DONE_MODE;
@@ -6369,6 +6444,7 @@
break;
case RESUME_WEBCORE_PRIORITY:
WebViewCore.resumePriority();
+ WebViewCore.resumeUpdatePicture(mWebViewCore);
break;
case LONG_PRESS_CENTER:
@@ -6409,31 +6485,27 @@
TouchEventData ted = (TouchEventData) msg.obj;
switch (ted.mAction) {
case MotionEvent.ACTION_DOWN:
- mLastDeferTouchX = contentToViewX(ted.mX)
- - mScrollX;
- mLastDeferTouchY = contentToViewY(ted.mY)
- - mScrollY;
+ mLastDeferTouchX = ted.mViewX;
+ mLastDeferTouchY = ted.mViewY;
mDeferTouchMode = TOUCH_INIT_MODE;
break;
case MotionEvent.ACTION_MOVE: {
// no snapping in defer process
- int x = contentToViewX(ted.mX) - mScrollX;
- int y = contentToViewY(ted.mY) - mScrollY;
if (mDeferTouchMode != TOUCH_DRAG_MODE) {
mDeferTouchMode = TOUCH_DRAG_MODE;
- mLastDeferTouchX = x;
- mLastDeferTouchY = y;
+ mLastDeferTouchX = ted.mViewX;
+ mLastDeferTouchY = ted.mViewY;
startDrag();
}
int deltaX = pinLocX((int) (mScrollX
- + mLastDeferTouchX - x))
+ + mLastDeferTouchX - ted.mViewX))
- mScrollX;
int deltaY = pinLocY((int) (mScrollY
- + mLastDeferTouchY - y))
+ + mLastDeferTouchY - ted.mViewY))
- mScrollY;
doDrag(deltaX, deltaY);
- if (deltaX != 0) mLastDeferTouchX = x;
- if (deltaY != 0) mLastDeferTouchY = y;
+ if (deltaX != 0) mLastDeferTouchX = ted.mViewX;
+ if (deltaY != 0) mLastDeferTouchY = ted.mViewY;
break;
}
case MotionEvent.ACTION_UP:
@@ -6446,8 +6518,8 @@
break;
case WebViewCore.ACTION_DOUBLETAP:
// doDoubleTap() needs mLastTouchX/Y as anchor
- mLastTouchX = contentToViewX(ted.mX) - mScrollX;
- mLastTouchY = contentToViewY(ted.mY) - mScrollY;
+ mLastTouchX = ted.mViewX;
+ mLastTouchY = ted.mViewY;
doDoubleTap();
mDeferTouchMode = TOUCH_DONE_MODE;
break;
@@ -6584,6 +6656,11 @@
centerFitRect(r.left, r.top, r.width(), r.height());
break;
+ case SET_SCROLLBAR_MODES:
+ mHorizontalScrollBarMode = msg.arg1;
+ mVerticalScrollBarMode = msg.arg2;
+ break;
+
default:
super.handleMessage(msg);
break;
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index 625e7ba..4118119 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -708,6 +708,8 @@
int mY;
int mMetaState;
boolean mReprocess;
+ float mViewX;
+ float mViewY;
}
static class GeolocationPermissionsData {
@@ -2451,6 +2453,15 @@
new Rect(x, y, x + width, y + height)).sendToTarget();
}
+ // called by JNI
+ private void setScrollbarModes(int hMode, int vMode) {
+ if (mWebView == null) {
+ return;
+ }
+ mWebView.mPrivateHandler.obtainMessage(WebView.SET_SCROLLBAR_MODES,
+ hMode, vMode).sendToTarget();
+ }
+
private native void nativePause();
private native void nativeResume();
private native void nativeFreeMemory();
diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java
index 873dc67..959e982 100644
--- a/core/java/android/widget/ScrollView.java
+++ b/core/java/android/widget/ScrollView.java
@@ -330,7 +330,7 @@
mTempRect.setEmpty();
if (!canScroll()) {
- if (isFocused()) {
+ if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) {
View currentFocused = findFocus();
if (currentFocused == this) currentFocused = null;
View nextFocused = FocusFinder.getInstance().findNextFocus(this,
diff --git a/core/java/android/net/http/HttpDateTime.java b/core/java/com/android/internal/http/HttpDateTime.java
similarity index 98%
rename from core/java/android/net/http/HttpDateTime.java
rename to core/java/com/android/internal/http/HttpDateTime.java
index c7a31ee..8ebd4aa 100644
--- a/core/java/android/net/http/HttpDateTime.java
+++ b/core/java/com/android/internal/http/HttpDateTime.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.net.http;
+package com.android.internal.http;
import android.text.format.Time;
@@ -82,7 +82,7 @@
int second;
}
- public static Long parse(String timeString)
+ public static long parse(String timeString)
throws IllegalArgumentException {
int date = 1;
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index 85d1a6f..a39d06b 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -58,6 +58,7 @@
android_os_UEventObserver.cpp \
android_net_LocalSocketImpl.cpp \
android_net_NetUtils.cpp \
+ android_net_TrafficStats.cpp \
android_net_wifi_Wifi.cpp \
android_nio_utils.cpp \
android_pim_EventRecurrence.cpp \
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index 7f8e854..487f3d4 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -139,6 +139,7 @@
extern int register_android_os_MemoryFile(JNIEnv* env);
extern int register_android_net_LocalSocketImpl(JNIEnv* env);
extern int register_android_net_NetworkUtils(JNIEnv* env);
+extern int register_android_net_TrafficStats(JNIEnv* env);
extern int register_android_net_wifi_WifiManager(JNIEnv* env);
extern int register_android_security_Md5MessageDigest(JNIEnv *env);
extern int register_android_text_AndroidCharacter(JNIEnv *env);
@@ -1246,6 +1247,7 @@
REG_JNI(register_android_os_UEventObserver),
REG_JNI(register_android_net_LocalSocketImpl),
REG_JNI(register_android_net_NetworkUtils),
+ REG_JNI(register_android_net_TrafficStats),
REG_JNI(register_android_net_wifi_WifiManager),
REG_JNI(register_android_os_MemoryFile),
REG_JNI(register_com_android_internal_os_ZygoteInit),
diff --git a/core/jni/android_net_TrafficStats.cpp b/core/jni/android_net_TrafficStats.cpp
new file mode 100644
index 0000000..ff46bdd
--- /dev/null
+++ b/core/jni/android_net_TrafficStats.cpp
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+#define LOG_TAG "TrafficStats"
+
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <android_runtime/AndroidRuntime.h>
+#include <cutils/logger.h>
+#include <jni.h>
+#include <utils/misc.h>
+#include <utils/Log.h>
+
+namespace android {
+
+// Returns an ASCII decimal number read from the specified file, -1 on error.
+static jlong readNumber(char const* filename) {
+#ifdef HAVE_ANDROID_OS
+ char buf[80];
+ int fd = open(filename, O_RDONLY);
+ if (fd < 0) {
+ if (errno != ENOENT) LOGE("Can't open %s: %s", filename, strerror(errno));
+ return -1;
+ }
+
+ int len = read(fd, buf, sizeof(buf) - 1);
+ if (len < 0) {
+ LOGE("Can't read %s: %s", filename, strerror(errno));
+ close(fd);
+ return -1;
+ }
+
+ close(fd);
+ buf[len] = '\0';
+ return atoll(buf);
+#else // Simulator
+ return -1;
+#endif
+}
+
+// Return the number from the first file which exists and contains data
+static jlong tryBoth(char const* a, char const* b) {
+ jlong num = readNumber(a);
+ return num >= 0 ? num : readNumber(b);
+}
+
+// Returns the sum of numbers from the specified path under /sys/class/net/*,
+// -1 if no such file exists.
+static jlong readTotal(char const* suffix) {
+#ifdef HAVE_ANDROID_OS
+ char filename[PATH_MAX] = "/sys/class/net/";
+ DIR *dir = opendir(filename);
+ if (dir == NULL) {
+ LOGE("Can't list %s: %s", filename, strerror(errno));
+ return -1;
+ }
+
+ int len = strlen(filename);
+ jlong total = -1;
+ while (struct dirent *entry = readdir(dir)) {
+ // Skip ., .., and localhost interfaces.
+ if (entry->d_name[0] != '.' && strncmp(entry->d_name, "lo", 2) != 0) {
+ strlcpy(filename + len, entry->d_name, sizeof(filename) - len);
+ strlcat(filename, suffix, sizeof(filename));
+ jlong num = readNumber(filename);
+ if (num >= 0) total = total < 0 ? num : total + num;
+ }
+ }
+
+ closedir(dir);
+ return total;
+#else // Simulator
+ return -1;
+#endif
+}
+
+// Mobile stats get accessed a lot more often than total stats.
+// Note the individual files can come and go at runtime, so we check
+// each file every time (rather than caching which ones exist).
+
+static jlong getMobileTxPackets(JNIEnv* env, jobject clazz) {
+ return tryBoth(
+ "/sys/class/net/rmnet0/statistics/tx_packets",
+ "/sys/class/net/ppp0/statistics/tx_packets");
+}
+
+static jlong getMobileRxPackets(JNIEnv* env, jobject clazz) {
+ return tryBoth(
+ "/sys/class/net/rmnet0/statistics/rx_packets",
+ "/sys/class/net/ppp0/statistics/rx_packets");
+}
+
+static jlong getMobileTxBytes(JNIEnv* env, jobject clazz) {
+ return tryBoth(
+ "/sys/class/net/rmnet0/statistics/tx_bytes",
+ "/sys/class/net/ppp0/statistics/tx_bytes");
+}
+
+static jlong getMobileRxBytes(JNIEnv* env, jobject clazz) {
+ return tryBoth(
+ "/sys/class/net/rmnet0/statistics/rx_bytes",
+ "/sys/class/net/ppp0/statistics/rx_bytes");
+}
+
+// Total stats are read less often, so we're willing to put up
+// with listing the directory and concatenating filenames.
+
+static jlong getTotalTxPackets(JNIEnv* env, jobject clazz) {
+ return readTotal("/statistics/tx_packets");
+}
+
+static jlong getTotalRxPackets(JNIEnv* env, jobject clazz) {
+ return readTotal("/statistics/rx_packets");
+}
+
+static jlong getTotalTxBytes(JNIEnv* env, jobject clazz) {
+ return readTotal("/statistics/tx_bytes");
+}
+
+static jlong getTotalRxBytes(JNIEnv* env, jobject clazz) {
+ return readTotal("/statistics/rx_bytes");
+}
+
+// Per-UID stats require reading from a constructed filename.
+
+static jlong getUidRxBytes(JNIEnv* env, jobject clazz, jint uid) {
+ char filename[80];
+ sprintf(filename, "/proc/uid_stat/%d/tcp_rcv", uid);
+ return readNumber(filename);
+}
+
+static jlong getUidTxBytes(JNIEnv* env, jobject clazz, jint uid) {
+ char filename[80];
+ sprintf(filename, "/proc/uid_stat/%d/tcp_snd", uid);
+ return readNumber(filename);
+}
+
+static JNINativeMethod gMethods[] = {
+ {"getMobileTxPackets", "()J", (void*) getMobileTxPackets},
+ {"getMobileRxPackets", "()J", (void*) getMobileRxPackets},
+ {"getMobileTxBytes", "()J", (void*) getMobileTxBytes},
+ {"getMobileRxBytes", "()J", (void*) getMobileRxBytes},
+ {"getTotalTxPackets", "()J", (void*) getTotalTxPackets},
+ {"getTotalRxPackets", "()J", (void*) getTotalRxPackets},
+ {"getTotalTxBytes", "()J", (void*) getTotalTxBytes},
+ {"getTotalRxBytes", "()J", (void*) getTotalRxBytes},
+ {"getUidTxBytes", "(I)J", (void*) getUidTxBytes},
+ {"getUidRxBytes", "(I)J", (void*) getUidRxBytes},
+};
+
+int register_android_net_TrafficStats(JNIEnv* env) {
+ return AndroidRuntime::registerNativeMethods(env, "android/net/TrafficStats",
+ gMethods, NELEM(gMethods));
+}
+
+}
diff --git a/core/jni/android_util_EventLog.cpp b/core/jni/android_util_EventLog.cpp
index 75f6cb2..e43478c 100644
--- a/core/jni/android_util_EventLog.cpp
+++ b/core/jni/android_util_EventLog.cpp
@@ -165,14 +165,32 @@
jint *tagValues = env->GetIntArrayElements(tags, NULL);
uint8_t buf[LOGGER_ENTRY_MAX_LEN];
+ struct timeval timeout = {0, 0};
+ fd_set readset;
+ FD_ZERO(&readset);
+
for (;;) {
+ // Use a short select() to try to avoid problems hanging on read().
+ // This means we block for 5ms at the end of the log -- oh well.
+ timeout.tv_usec = 5000;
+ FD_SET(fd, &readset);
+ int r = select(fd + 1, &readset, NULL, NULL, &timeout);
+ if (r == 0) {
+ break; // no more events
+ } else if (r < 0 && errno == EINTR) {
+ continue; // interrupted by signal, try again
+ } else if (r < 0) {
+ jniThrowIOException(env, errno); // Will throw on return
+ break;
+ }
+
int len = read(fd, buf, sizeof(buf));
if (len == 0 || (len < 0 && errno == EAGAIN)) {
- break;
+ break; // no more events
+ } else if (len < 0 && errno == EINTR) {
+ continue; // interrupted by signal, try again
} else if (len < 0) {
- // This calls env->ThrowNew(), which doesn't throw an exception
- // now, but sets a flag to trigger an exception after we return.
- jniThrowIOException(env, errno);
+ jniThrowIOException(env, errno); // Will throw on return
break;
} else if ((size_t) len < sizeof(logger_entry) + sizeof(int32_t)) {
jniThrowException(env, "java/io/IOException", "Event too short");
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 9e3e8a4..db71b21b 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -1031,7 +1031,8 @@
android:description="@string/permdesc_deletePackages"
android:protectionLevel="signatureOrSystem" />
- <!-- Allows an application to move location of installed package. -->
+ <!-- Allows an application to move location of installed package.
+ @hide -->
<permission android:name="android.permission.MOVE_PACKAGE"
android:label="@string/permlab_movePackage"
android:description="@string/permdesc_movePackage"
@@ -1207,7 +1208,8 @@
android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
android:protectionLevel="signatureOrSystem" />
- <!-- Allow an application to read and write the cache partition. -->
+ <!-- Allow an application to read and write the cache partition.
+ @hide -->
<permission android:name="android.permission.ACCESS_CACHE_FILESYSTEM"
android:label="@string/permlab_cache_filesystem"
android:description="@string/permdesc_cache_filesystem"
diff --git a/core/res/res/drawable-hdpi/stat_sys_throttled.png b/core/res/res/drawable-hdpi/stat_sys_throttled.png
new file mode 100644
index 0000000..33c0521
--- /dev/null
+++ b/core/res/res/drawable-hdpi/stat_sys_throttled.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/stat_notify_chat.png b/core/res/res/drawable-mdpi/stat_notify_chat.png
index 097a979..068b7ec 100644
--- a/core/res/res/drawable-mdpi/stat_notify_chat.png
+++ b/core/res/res/drawable-mdpi/stat_notify_chat.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/stat_sys_throttled.png b/core/res/res/drawable-mdpi/stat_sys_throttled.png
new file mode 100644
index 0000000..97ac427
--- /dev/null
+++ b/core/res/res/drawable-mdpi/stat_sys_throttled.png
Binary files differ
diff --git a/core/res/res/layout/keyguard_screen_tab_unlock.xml b/core/res/res/layout/keyguard_screen_tab_unlock.xml
index 945d283..79ca617 100644
--- a/core/res/res/layout/keyguard_screen_tab_unlock.xml
+++ b/core/res/res/layout/keyguard_screen_tab_unlock.xml
@@ -164,6 +164,7 @@
android:layout_marginBottom="80dip"
style="@style/Widget.Button.Transparent"
android:drawablePadding="8dip"
+ android:visibility="gone"
/>
</RelativeLayout>
diff --git a/core/res/res/layout/keyguard_screen_tab_unlock_land.xml b/core/res/res/layout/keyguard_screen_tab_unlock_land.xml
index 6b76004e..8353887 100644
--- a/core/res/res/layout/keyguard_screen_tab_unlock_land.xml
+++ b/core/res/res/layout/keyguard_screen_tab_unlock_land.xml
@@ -163,6 +163,7 @@
style="@style/Widget.Button.Transparent"
android:drawablePadding="8dip"
android:layout_marginRight="80dip"
+ android:visibility="gone"
/>
</LinearLayout>
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index 3585bf1..ed7447c 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -584,8 +584,8 @@
<!-- Application's requirement for five way navigation -->
<attr name="reqFiveWayNav" format="boolean" />
- <!-- The name of the class implementing <code>BackupAgent</code> to manage
- backup and restore of application data on external storage. -->
+ <!-- The name of the class subclassing <code>BackupAgent</code> to manage
+ backup and restore of the application's data on external storage. -->
<attr name="backupAgent" format="string" />
<!-- Whether to allow the application to participate in backup
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 29a815f..64f05fe 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -128,11 +128,15 @@
in to AC and 2 to stay on when plugged in to USB. (So 3 for both.) -->
<integer name="config_carDockKeepsScreenOn">1</integer>
- <!-- Control whether being in the desk dock should enable accelerometer based screen orientation -->
+ <!-- Control whether being in the desk dock should enable accelerometer
+ based screen orientation. Note this should probably default to true
+ like car dock, but we haven't had a chance to test it. -->
<bool name="config_deskDockEnablesAccelerometer">false</bool>
- <!-- Control whether being in the car dock should enable accelerometer based screen orientation -->
- <bool name="config_carDockEnablesAccelerometer">false</bool>
+ <!-- Control whether being in the car dock should enable accelerometer based
+ screen orientation. This defaults to true because putting a device in
+ a car dock make the accelerometer more a physical input (like a lid). -->
+ <bool name="config_carDockEnablesAccelerometer">true</bool>
<!-- Indicate whether the lid state impacts the accessibility of
the physical keyboard. 0 means it doesn't, 1 means it is accessible
@@ -286,4 +290,21 @@
<!-- Boolean indicating if current platform supports bluetooth SCO for off call
use cases -->
<bool name="config_bluetooth_sco_off_call">true</bool>
+
+ <!-- The default data-use polling period. -->
+ <integer name="config_datause_polling_period_sec">600</integer>
+
+ <!-- The default data-use threshold in bytes. 0 disables-->
+ <integer name="config_datause_threshold_bytes">0</integer>
+
+ <!-- The default reduced-datarate value in kilobits per sec -->
+ <integer name="config_datause_throttle_kbitsps">300</integer>
+
+ <!-- The default iface on which to monitor data use -->
+ <string name="config_datause_iface">rmnet0</string>
+
+ <!-- The default reduced-datarate notification mask -->
+ <!-- 2 means give warning -->
+ <integer name="config_datause_notification_type">2</integer>
+
</resources>
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 48d1ad7..45d7aea 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -2257,4 +2257,14 @@
<!-- Shown when the device is tethered -->
<string name="tethered_notification_title">Tethering active</string>
<string name="tethered_notification_message">Touch to configure</string>
+
+ <!-- Strings for throttling notification -->
+ <!-- Shown when the user is in danger of being throttled -->
+ <string name="throttle_warning_notification_title">High mobile data use</string>
+ <string name="throttle_warning_notification_message">Touch to learn more about mobile data use</string>
+
+ <!-- Strings for throttling notification -->
+ <!-- Shown when the users bandwidth is reduced because of excessive data use -->
+ <string name="throttled_notification_title">Mobile data limit exceeded</string>
+ <string name="throttled_notification_message">Touch to learn more about mobile data use</string>
</resources>
diff --git a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java
index 7fa64ca..7ced94f 100755
--- a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java
+++ b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java
@@ -165,12 +165,18 @@
}
}
- PackageManager getPm() {
+ private PackageManager getPm() {
return mContext.getPackageManager();
}
+ private IPackageManager getIPm() {
+ IPackageManager ipm = IPackageManager.Stub.asInterface(
+ ServiceManager.getService("package"));
+ return ipm;
+ }
+
public boolean invokeInstallPackage(Uri packageURI, int flags,
- final String pkgName, GenericReceiver receiver) throws Exception {
+ GenericReceiver receiver) throws Exception {
PackageInstallObserver observer = new PackageInstallObserver();
final boolean received = false;
mContext.registerReceiver(receiver, receiver.filter);
@@ -209,8 +215,7 @@
}
}
- public boolean invokeInstallPackageFail(Uri packageURI, int flags,
- final String pkgName, int result) throws Exception {
+ public void invokeInstallPackageFail(Uri packageURI, int flags, int result) throws Exception {
PackageInstallObserver observer = new PackageInstallObserver();
try {
// Wait on observer
@@ -224,7 +229,7 @@
if(!observer.isDone()) {
throw new Exception("Timed out waiting for packageInstalled callback");
}
- return (observer.returnCode == result);
+ assertEquals(observer.returnCode, result);
}
} finally {
}
@@ -284,17 +289,6 @@
private static final int INSTALL_LOC_INT = 1;
private static final int INSTALL_LOC_SD = 2;
private static final int INSTALL_LOC_ERR = -1;
- private int checkDefaultPolicy(long pkgLen) {
- // Check for free memory internally
- if (checkInt(pkgLen)) {
- return INSTALL_LOC_INT;
- }
- // Check for free memory externally
- if (checkSd(pkgLen)) {
- return INSTALL_LOC_SD;
- }
- return INSTALL_LOC_ERR;
- }
private int getInstallLoc(int flags, int expInstallLocation, long pkgLen) {
// Flags explicitly over ride everything else.
if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0 ) {
@@ -306,7 +300,6 @@
}
// Manifest option takes precedence next
if (expInstallLocation == PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL) {
- // TODO fitsonSd check
if (checkSd(pkgLen)) {
return INSTALL_LOC_SD;
}
@@ -322,36 +315,36 @@
return INSTALL_LOC_ERR;
}
if (expInstallLocation == PackageInfo.INSTALL_LOCATION_AUTO) {
- return checkDefaultPolicy(pkgLen);
+ // Check for free memory internally
+ if (checkInt(pkgLen)) {
+ return INSTALL_LOC_INT;
+ }
+ // Check for free memory externally
+ if (checkSd(pkgLen)) {
+ return INSTALL_LOC_SD;
+ }
+ return INSTALL_LOC_ERR;
}
// Check for settings preference.
boolean checkSd = false;
- int setLoc = 0;
- try {
- setLoc = Settings.System.getInt(mContext.getContentResolver(), Settings.Secure.SET_INSTALL_LOCATION);
- } catch (SettingNotFoundException e) {
- failStr(e);
- }
- if (setLoc == 1) {
- int userPref = APP_INSTALL_AUTO;
- try {
- userPref = Settings.System.getInt(mContext.getContentResolver(), Settings.Secure.DEFAULT_INSTALL_LOCATION);
- } catch (SettingNotFoundException e) {
- failStr(e);
+ int userPref = getDefaultInstallLoc();
+ if (userPref == APP_INSTALL_DEVICE) {
+ if (checkInt(pkgLen)) {
+ return INSTALL_LOC_INT;
}
- if (userPref == APP_INSTALL_DEVICE) {
- if (checkInt(pkgLen)) {
- return INSTALL_LOC_INT;
- }
- return INSTALL_LOC_ERR;
- } else if (userPref == APP_INSTALL_SDCARD) {
- if (checkSd(pkgLen)) {
- return INSTALL_LOC_SD;
- }
- return INSTALL_LOC_ERR;
+ return INSTALL_LOC_ERR;
+ } else if (userPref == APP_INSTALL_SDCARD) {
+ if (checkSd(pkgLen)) {
+ return INSTALL_LOC_SD;
}
+ return INSTALL_LOC_ERR;
}
- return checkDefaultPolicy(pkgLen);
+ // Default system policy for apps with no manifest option specified.
+ // Check for free memory internally
+ if (checkInt(pkgLen)) {
+ return INSTALL_LOC_INT;
+ }
+ return INSTALL_LOC_ERR;
}
private void assertInstall(PackageParser.Package pkg, int flags, int expInstallLocation) {
@@ -402,14 +395,20 @@
}
class InstallParams {
- String outFileName;
Uri packageURI;
PackageParser.Package pkg;
- InstallParams(PackageParser.Package pkg, String outFileName, Uri packageURI) {
- this.outFileName = outFileName;
- this.packageURI = packageURI;
+ InstallParams(String outFileName, int rawResId) {
+ this.pkg = getParsedPackage(outFileName, rawResId);
+ this.packageURI = Uri.fromFile(new File(pkg.mScanPath));
+ }
+ InstallParams(PackageParser.Package pkg) {
+ this.packageURI = Uri.fromFile(new File(pkg.mScanPath));
this.pkg = pkg;
}
+ long getApkSize() {
+ File file = new File(pkg.mScanPath);
+ return file.length();
+ }
}
private InstallParams sampleInstallFromRawResource(int flags, boolean cleanUp) {
@@ -520,45 +519,36 @@
* copies it into own data directory and invokes
* PackageManager api to install it.
*/
- private InstallParams installFromRawResource(String outFileName,
- int rawResId, int flags, boolean cleanUp, boolean fail, int result,
+ private void installFromRawResource(InstallParams ip,
+ int flags, boolean cleanUp, boolean fail, int result,
int expInstallLocation) {
PackageManager pm = mContext.getPackageManager();
- File filesDir = mContext.getFilesDir();
- File outFile = new File(filesDir, outFileName);
- Uri packageURI = getInstallablePackage(rawResId, outFile);
- PackageParser.Package pkg = parsePackage(packageURI);
- assertNotNull(pkg);
+ PackageParser.Package pkg = ip.pkg;
+ Uri packageURI = ip.packageURI;
if ((flags & PackageManager.INSTALL_REPLACE_EXISTING) == 0) {
// Make sure the package doesn't exist
try {
ApplicationInfo appInfo = pm.getApplicationInfo(pkg.packageName,
PackageManager.GET_UNINSTALLED_PACKAGES);
GenericReceiver receiver = new DeleteReceiver(pkg.packageName);
- invokeDeletePackage(packageURI, 0,
- pkg.packageName, receiver);
+ invokeDeletePackage(pkg.packageName, 0, receiver);
} catch (NameNotFoundException e1) {
} catch (Exception e) {
failStr(e);
}
}
- InstallParams ip = null;
try {
if (fail) {
- assertTrue(invokeInstallPackageFail(packageURI, flags,
- pkg.packageName, result));
+ invokeInstallPackageFail(packageURI, flags, result);
if ((flags & PackageManager.INSTALL_REPLACE_EXISTING) == 0) {
assertNotInstalled(pkg.packageName);
}
} else {
InstallReceiver receiver = new InstallReceiver(pkg.packageName);
- assertTrue(invokeInstallPackage(packageURI, flags,
- pkg.packageName, receiver));
+ assertTrue(invokeInstallPackage(packageURI, flags, receiver));
// Verify installed information
assertInstall(pkg, flags, expInstallLocation);
- ip = new InstallParams(pkg, outFileName, packageURI);
}
- return ip;
} catch (Exception e) {
failStr("Failed with exception : " + e);
} finally {
@@ -566,6 +556,19 @@
cleanUpInstall(ip);
}
}
+ }
+
+ /*
+ * Utility function that reads a apk bundled as a raw resource
+ * copies it into own data directory and invokes
+ * PackageManager api to install it.
+ */
+ private InstallParams installFromRawResource(String outFileName,
+ int rawResId, int flags, boolean cleanUp, boolean fail, int result,
+ int expInstallLocation) {
+ PackageManager pm = mContext.getPackageManager();
+ InstallParams ip = new InstallParams(outFileName, rawResId);
+ installFromRawResource(ip, flags, cleanUp, fail, result, expInstallLocation);
return ip;
}
@@ -654,8 +657,7 @@
}
try {
try {
- assertEquals(invokeInstallPackage(ip.packageURI, flags,
- ip.pkg.packageName, receiver), replace);
+ assertEquals(invokeInstallPackage(ip.packageURI, flags, receiver), replace);
if (replace) {
assertInstall(ip.pkg, flags, ip.pkg.installLocation);
}
@@ -736,8 +738,8 @@
}
}
- public boolean invokeDeletePackage(Uri packageURI, int flags,
- final String pkgName, GenericReceiver receiver) throws Exception {
+ public boolean invokeDeletePackage(final String pkgName, int flags,
+ GenericReceiver receiver) throws Exception {
DeleteObserver observer = new DeleteObserver();
final boolean received = false;
mContext.registerReceiver(receiver, receiver.filter);
@@ -777,8 +779,7 @@
GenericReceiver receiver = new DeleteReceiver(ip.pkg.packageName);
DeleteObserver observer = new DeleteObserver();
try {
- assertTrue(invokeDeletePackage(ip.packageURI, dFlags,
- ip.pkg.packageName, receiver));
+ assertTrue(invokeDeletePackage(ip.pkg.packageName, dFlags, receiver));
ApplicationInfo info = null;
Log.i(TAG, "okay4");
try {
@@ -907,7 +908,7 @@
boolean getMediaState() {
try {
- String mPath = Environment.getExternalStorageDirectory().toString();
+ String mPath = Environment.getExternalStorageDirectory().getPath();
String state = getMs().getVolumeState(mPath);
return Environment.MEDIA_MOUNTED.equals(state);
} catch (RemoteException e) {
@@ -928,13 +929,17 @@
}
}
-
-
private boolean unmountMedia() {
- if (!getMediaState()) {
- return true;
+ String path = Environment.getExternalStorageDirectory().getPath();
+ try {
+ String state = getMs().getVolumeState(path);
+ if (Environment.MEDIA_UNMOUNTED.equals(state)) {
+ return true;
+ }
+ } catch (RemoteException e) {
+ failStr(e);
}
- String path = Environment.getExternalStorageDirectory().toString();
+
StorageListener observer = new StorageListener();
StorageManager sm = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
sm.registerListener(observer);
@@ -948,11 +953,12 @@
waitTime += WAIT_TIME_INCR;
}
if(!observer.isDone()) {
- throw new Exception("Timed out waiting for packageInstalled callback");
+ throw new Exception("Timed out waiting for unmount media notification");
}
return true;
}
} catch (Exception e) {
+ Log.e(TAG, "Exception : " + e);
return false;
} finally {
sm.unregisterListener(observer);
@@ -1029,7 +1035,7 @@
Runtime.getRuntime().gc();
Log.i(TAG, "Deleting package : " + ip.pkg.packageName);
getPm().deletePackage(ip.pkg.packageName, null, 0);
- File outFile = new File(ip.outFileName);
+ File outFile = new File(ip.pkg.mScanPath);
if (outFile != null && outFile.exists()) {
outFile.delete();
}
@@ -1095,8 +1101,7 @@
GenericReceiver receiver = new ReplaceReceiver(ip.pkg.packageName);
int replaceFlags = rFlags | PackageManager.INSTALL_REPLACE_EXISTING;
try {
- assertEquals(invokeInstallPackage(ip.packageURI, replaceFlags,
- ip.pkg.packageName, receiver), true);
+ assertEquals(invokeInstallPackage(ip.packageURI, replaceFlags, receiver), true);
assertInstall(ip.pkg, rFlags, ip.pkg.installLocation);
} catch (Exception e) {
failStr("Failed with exception : " + e);
@@ -1117,8 +1122,7 @@
GenericReceiver receiver = new ReplaceReceiver(ip.pkg.packageName);
int replaceFlags = rFlags | PackageManager.INSTALL_REPLACE_EXISTING;
try {
- assertEquals(invokeInstallPackage(ip.packageURI, replaceFlags,
- ip.pkg.packageName, receiver), true);
+ assertEquals(invokeInstallPackage(ip.packageURI, replaceFlags, receiver), true);
assertInstall(ip.pkg, iFlags, ip.pkg.installLocation);
} catch (Exception e) {
failStr("Failed with exception : " + e);
@@ -1298,11 +1302,9 @@
return true;
}
- private int getInstallLoc() {
- boolean userSetting = false;
+ private int getDefaultInstallLoc() {
int origDefaultLoc = PackageInfo.INSTALL_LOCATION_AUTO;
try {
- userSetting = Settings.System.getInt(mContext.getContentResolver(), Settings.Secure.SET_INSTALL_LOCATION) != 0;
origDefaultLoc = Settings.System.getInt(mContext.getContentResolver(), Settings.Secure.DEFAULT_INSTALL_LOCATION);
} catch (SettingNotFoundException e1) {
}
@@ -1326,7 +1328,7 @@
private void moveFromRawResource(String outFileName,
int rawResId, int installFlags, int moveFlags, boolean cleanUp,
boolean fail, int result) {
- int origDefaultLoc = getInstallLoc();
+ int origDefaultLoc = getDefaultInstallLoc();
InstallParams ip = null;
try {
setInstallLoc(PackageHelper.APP_INSTALL_AUTO);
@@ -1416,7 +1418,7 @@
final int result = PackageManager.MOVE_FAILED_DOESNT_EXIST;
int rawResId = R.raw.install;
- int origDefaultLoc = getInstallLoc();
+ int origDefaultLoc = getDefaultInstallLoc();
InstallParams ip = null;
try {
PackageManager pm = getPm();
@@ -1447,10 +1449,10 @@
// Unmount sdcard
assertTrue(unmountMedia());
// Try to install and make sure an error code is returned.
- assertNull(installFromRawResource("install.apk", R.raw.install,
+ installFromRawResource("install.apk", R.raw.install,
PackageManager.INSTALL_EXTERNAL, false,
true, PackageManager.INSTALL_FAILED_MEDIA_UNAVAILABLE,
- PackageInfo.INSTALL_LOCATION_AUTO));
+ PackageInfo.INSTALL_LOCATION_AUTO);
} finally {
// Restore original media state
if (origState) {
@@ -1470,11 +1472,9 @@
try {
// Unmount sdcard
assertTrue(unmountMedia());
- // Try to install and make sure an error code is returned.
- assertNotNull(installFromRawResource("install.apk", R.raw.install_loc_sdcard,
- 0, false,
- false, -1,
- PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY));
+ InstallParams ip = new InstallParams("install.apk", R.raw.install_loc_sdcard);
+ installFromRawResource(ip, 0, true, false, -1,
+ PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY);
} finally {
// Restore original media state
if (origState) {
@@ -1912,7 +1912,7 @@
false,
false, -1,
PackageInfo.INSTALL_LOCATION_UNSPECIFIED);
- int origSetting = getInstallLoc();
+ int origSetting = getDefaultInstallLoc();
try {
// Set user setting
setInstallLoc(userSetting);
@@ -1976,7 +1976,7 @@
}
private void setUserX(boolean enable, int userSetting, int iloc) {
boolean origUserSetting = getUserSettingSetInstallLocation();
- int origSetting = getInstallLoc();
+ int origSetting = getDefaultInstallLoc();
try {
setUserSettingSetInstallLocation(enable);
// Set user setting
@@ -2101,8 +2101,7 @@
GenericReceiver receiver = new DeleteReceiver(ip.pkg.packageName);
try {
- invokeDeletePackage(ip.packageURI, PackageManager.DONT_DELETE_DATA,
- ip.pkg.packageName, receiver);
+ invokeDeletePackage(ip.pkg.packageName, PackageManager.DONT_DELETE_DATA, receiver);
} catch (Exception e) {
failStr(e);
}
@@ -2121,8 +2120,7 @@
// **: Upon deleting package, are all permissions removed?
try {
- invokeDeletePackage(ip.packageURI, 0,
- ip.pkg.packageName, receiver);
+ invokeDeletePackage(ip.pkg.packageName, 0, receiver);
ip = null;
} catch (Exception e) {
failStr(e);
@@ -2134,8 +2132,7 @@
GenericReceiver receiver2 = new DeleteReceiver(ip2.pkg.packageName);
try {
- invokeDeletePackage(ip2.packageURI, 0,
- ip2.pkg.packageName, receiver);
+ invokeDeletePackage(ip2.pkg.packageName, 0, receiver);
ip2 = null;
} catch (Exception e) {
failStr(e);
@@ -2170,8 +2167,7 @@
// **: Upon deleting package, are all permissions removed?
try {
- invokeDeletePackage(ip.packageURI, 0,
- ip.pkg.packageName, receiver);
+ invokeDeletePackage(ip.pkg.packageName, 0, receiver);
ip = null;
} catch (Exception e) {
failStr(e);
@@ -2182,8 +2178,7 @@
// **: Delete package using permissions; nothing to check here.
try {
- invokeDeletePackage(ip2.packageURI, 0,
- ip2.pkg.packageName, receiver);
+ invokeDeletePackage(ip2.pkg.packageName, 0, receiver);
ip2 = null;
} catch (Exception e) {
failStr(e);
@@ -2252,7 +2247,7 @@
unmountMedia();
// Delete the app on sdcard to leave a stale container on sdcard.
GenericReceiver receiver = new DeleteReceiver(pkg.packageName);
- assertTrue(invokeDeletePackage(packageURI, 0, pkg.packageName, receiver));
+ assertTrue(invokeDeletePackage(pkg.packageName, 0, receiver));
mountMedia();
// Reinstall the app and make sure it gets installed.
installFromRawResource(outFileName, rawResId,
diff --git a/data/fonts/DroidSansArabic.ttf b/data/fonts/DroidSansArabic.ttf
index c179bc6..660e2a9 100644
--- a/data/fonts/DroidSansArabic.ttf
+++ b/data/fonts/DroidSansArabic.ttf
Binary files differ
diff --git a/data/fonts/DroidSansHebrew.ttf b/data/fonts/DroidSansHebrew.ttf
index 0b48628..8d77e3e 100644
--- a/data/fonts/DroidSansHebrew.ttf
+++ b/data/fonts/DroidSansHebrew.ttf
Binary files differ
diff --git a/docs/html/guide/guide_toc.cs b/docs/html/guide/guide_toc.cs
index dce78c4..fd163f6 100644
--- a/docs/html/guide/guide_toc.cs
+++ b/docs/html/guide/guide_toc.cs
@@ -99,18 +99,36 @@
</li>
<li class="toggle-list">
<div><a href="<?cs var:toroot ?>guide/topics/resources/index.html">
- <span class="en">Resources and Assets</span>
+ <span class="en">Application Resources</span>
</a></div>
<ul>
- <li><a href="<?cs var:toroot ?>guide/topics/resources/resources-i18n.html">
- <span class="en">Resources and I18n</span>
+ <li><a href="<?cs var:toroot ?>guide/topics/resources/providing-resources.html">
+ <span class="en">Providing Resources</span>
</a></li>
- <li><a href="<?cs var:toroot ?>guide/topics/resources/available-resources.html">
- <span class="en">Available Resource Types</span>
+ <li><a href="<?cs var:toroot ?>guide/topics/resources/accessing-resources.html">
+ <span class="en">Accessing Resources</span>
+ </a></li>
+ <li><a href="<?cs var:toroot ?>guide/topics/resources/runtime-changes.html">
+ <span class="en">Handling Runtime Changes</span>
</a></li>
<li><a href="<?cs var:toroot ?>guide/topics/resources/localization.html">
<span class="en">Localization</span>
</a></li>
+ <li class="toggle-list">
+ <div><a href="<?cs var:toroot ?>guide/topics/resources/available-resources.html">
+ <span class="en">Resource Types</span>
+ </a></div>
+ <ul>
+ <li><a href="<?cs var:toroot ?>guide/topics/resources/animation-resource.html">Animation</a></li>
+ <li><a href="<?cs var:toroot ?>guide/topics/resources/color-list-resource.html">Color State List</a></li>
+ <li><a href="<?cs var:toroot ?>guide/topics/resources/drawable-resource.html">Drawable</a></li>
+ <li><a href="<?cs var:toroot ?>guide/topics/resources/layout-resource.html">Layout</a></li>
+ <li><a href="<?cs var:toroot ?>guide/topics/resources/menu-resource.html">Menu</a></li>
+ <li><a href="<?cs var:toroot ?>guide/topics/resources/string-resource.html">String</a></li>
+ <li><a href="<?cs var:toroot ?>guide/topics/resources/style-resource.html">Style</a></li>
+ <li><a href="<?cs var:toroot ?>guide/topics/resources/more-resources.html">More Types</a></li>
+ </ul>
+ </li>
</ul>
</li>
<li><a href="<?cs var:toroot ?>guide/topics/intents/intents-filters.html">
diff --git a/docs/html/guide/practices/screens_support.jd b/docs/html/guide/practices/screens_support.jd
index 0fad4c6..5e61e6c 100644
--- a/docs/html/guide/practices/screens_support.jd
+++ b/docs/html/guide/practices/screens_support.jd
@@ -116,7 +116,7 @@
generalized densities: high, medium, and low. Applications can provide custom
resources for each of these three densities — the platform handles the
scaling of the resources up or down to meet the actual screen density. </p></dd>
-<dt><em>Density independent pixel (dip)</em></dt>
+<dt><em>Density-independent pixel (dip)</em></dt>
<dd>A virtual pixel unit that applications can use in defining their UI, to
express layout dimensions or position in a density-independent way.
<p>The density-independent pixel is equivalent to one physical pixel on a 160
@@ -432,7 +432,7 @@
<ul>
<li>Through pre-scaling of drawable resources (scaled at resource loading
time)</li>
-<li>Through auto-scaling of device-independent pixel (dip) values used in
+<li>Through auto-scaling of density-independent pixel (dip) values used in
layouts</li>
<li>Through auto-scaling of absolute pixel values used in the application (only
needed if the application has set <code>android:anyDensity="false"</code> in its
@@ -573,7 +573,7 @@
are signaling to the platform that your application wants to manage its UI by
itself, for all screen densities, using the actual screen dimensions and pixels.
In this case, the application must ensure that it declares its UI dimensions
-using device-independent pixels and scales any actual pixel values or math by
+using density-independent pixels and scales any actual pixel values or math by
the scaling factor available from
{@link android.util.DisplayMetrics#density android.util.DisplayMetrics.density}.</p>
diff --git a/docs/html/guide/topics/graphics/2d-graphics.jd b/docs/html/guide/topics/graphics/2d-graphics.jd
index 051427b..e46dbb4 100644
--- a/docs/html/guide/topics/graphics/2d-graphics.jd
+++ b/docs/html/guide/topics/graphics/2d-graphics.jd
@@ -442,7 +442,7 @@
<p>While you can define the frames of an animation in your code, using the
{@link android.graphics.drawable.AnimationDrawable} class API, it's more simply accomplished with a single XML
file that lists the frames that compose the animation. Like the tween animation above, the XML file for this kind
-of animation belongs in the <code>res/anim/</code> directory of your Android project. In this case,
+of animation belongs in the <code>res/drawable/</code> directory of your Android project. In this case,
the instructions are the order and duration for each frame of the animation.</p>
<p>The XML file consists of an <code><animation-list></code> element as the root node and a series
@@ -459,7 +459,7 @@
<p>This animation runs for just three frames. By setting the <code>android:oneshot</code> attribute of the
list to <var>true</var>, it will cycle just once then stop and hold on the last frame. If it is set <var>false</var> then
-the animation will loop. With this XML saved as <code>rocket_thrust.xml</code> in the <code>res/anim/</code> directory
+the animation will loop. With this XML saved as <code>rocket_thrust.xml</code> in the <code>res/drawable/</code> directory
of the project, it can be added as the background image to a View and then called to play. Here's an example Activity,
in which the animation is added to an {@link android.widget.ImageView} and then animated when the screen is touched:</p>
<pre>
@@ -470,7 +470,7 @@
setContentView(R.layout.main);
ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
- rocketImage.setBackgroundResource(R.anim.rocket_thrust);
+ rocketImage.setBackgroundResource(R.drawable.rocket_thrust);
rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
}
diff --git a/docs/html/guide/topics/manifest/application-element.jd b/docs/html/guide/topics/manifest/application-element.jd
index 5b3fcd5..08f35e9 100644
--- a/docs/html/guide/topics/manifest/application-element.jd
+++ b/docs/html/guide/topics/manifest/application-element.jd
@@ -3,19 +3,23 @@
<dl class="xml">
<dt>syntax:</dt>
-<dd><pre class="stx"><application android:<a href="#clear">allowClearUserData</a>=["true" | "false"]
+<dd><pre class="stx"><application android:<a href="#backup">allowBackup</a>=["true" | "false"]
+ android:<a href="#clear">allowClearUserData</a>=["true" | "false"]
android:<a href="#reparent">allowTaskReparenting</a>=["true" | "false"]
+ android:<a href="#agent">backupAgent</a>="<i>string</i>"
android:<a href="#debug">debuggable</a>=["true" | "false"]
android:<a href="#desc">description</a>="<i>string resource</i>"
android:<a href="#enabled">enabled</a>=["true" | "false"]
android:<a href="#code">hasCode</a>=["true" | "false"]
android:<a href="#icon">icon</a>="<i>drawable resource</i>"
+ android:<a href="#killrst">killAfterRestore</a>=["true" | "false"]
android:<a href="#label">label</a>="<i>string resource</i>"
android:<a href="#space">manageSpaceActivity</a>="<i>string</i>"
android:<a href="#nm">name</a>="<i>string</i>"
android:<a href="#prmsn">permission</a>="<i>string</i>"
android:<a href="#persistent">persistent</a>=["true" | "false"]
android:<a href="#proc">process</a>="<i>string</i>"
+ android:<a href="#restoreany">restoreAnyVersion</a>=["true" | "false"]
android:<a href="#aff">taskAffinity</a>="<i>string</i>"
android:<a href="#theme">theme</a>="<i>resource or theme</i>" >
. . .
@@ -45,6 +49,16 @@
<dt>attributes</dt>
<dd><dl class="attr">
+<dt><a name="backup"></a>{@code android:allowBackup}</dt>
+<dd>Whether the application allows its data to be backed up through the Android
+Backup Manager — "{@code true}" if it does, "{@code false}" if not. By
+default this attribute is "{@code true}". If an application declares this
+attribute to be "{@code false}" the Backup Manager will never attempt to
+perform any backup or restore operation, even if the application declares a
+valid <a href="#agent">{@code android:backupAgent}</a> attribute in its
+manifest.
+</dd>
+
<dt><a name="clear"></a>{@code android:allowClearUserData}</dt>
<dd>Whether or not users are given the option to remove user data —
"{@code true}" if they are, and "{@code false}" if not. If the value is
@@ -67,6 +81,20 @@
information.
</p></dd>
+<dt><a name="agent"></a>{@code android:backupAgent}</dt>
+<dd>The name of the class that implement's the application's backup agent,
+a subclass of {@link android.app.backup.BackupAgent}. The attribute value should be
+a fully qualified class name (such as, "{@code com.example.project.MyBackupAgent}").
+However, as a shorthand, if the first character of the name is a period
+(for example, "{@code .MyBackupAgent}"), it is appended to the
+package name specified in the
+<code><a href="{@docRoot}guide/topics/manifest/manifest-element.html"><manifest></a></code>
+element.
+
+<p>
+There is no default. The name must be specified.
+</p></dd>
+
<dt><a name="debug"></a>{@code android:debuggable}</dt>
<dd>Whether or not the application can be debugged, even when running
on a device in user mode — "{@code true}" if it can be, and "{@code false}"
@@ -113,6 +141,19 @@
the image definition. There is no default icon.
</p></dd>
+<dt><a name="killrst"></a>{@code android:killAfterRestore}</dt>
+<dd>Whether the application in question should be terminated after its
+settings have been restored during a full-system restore operation.
+Single-package restore operations will never cause the application to
+be shut down. Full-system restore operations typically only occur once,
+when the phone is first set up. Third-party applications will not normally
+need to use this attribute.
+
+<p>The default is {@code true}, which means that after the application
+has finished processing its data during a full-system restore, it will be
+terminated.
+</p></dd>
+
<dt><a name="label"></a>{@code android:label}</dt>
<dd>A user-readable label for the application as a whole, and a default
label for each of the application's components. See the individual
@@ -196,6 +237,17 @@
applications, reducing resource usage.
</p></dd>
+<dt><a href name="restoreany"></a>{@code android:restoreAnyVersion}</dt>
+<dd>Indicate that the application is prepared to attempt a restore of any
+backed-up data set, even if the backup was stored by a newer version
+of the application than is currently installed on the device. Setting
+this attribute to {@code true} will permit the Backup Manager to
+attempt restore even when a version mismatch suggests that the data are
+incompatible. <em>Use with caution!</em>
+
+<p>The default value of this attribute is {@code false}.
+</p></dd>
+
<dt><a href name="aff"></a>{@code android:taskAffinity}</dt>
<dd>An affinity name that applies to all activities within the application,
except for those that set a different affinity with their own
diff --git a/docs/html/guide/topics/manifest/manifest-element.jd b/docs/html/guide/topics/manifest/manifest-element.jd
index 1255949..734a79d 100644
--- a/docs/html/guide/topics/manifest/manifest-element.jd
+++ b/docs/html/guide/topics/manifest/manifest-element.jd
@@ -109,7 +109,7 @@
</dd>
<dt><a name="install"></a>{@code android:installLocation}</dt>
-<dd>The default install location for your application.
+<dd>The default install location for the application.
<p>This attribute was introduced in API Level 8.</p>
<p>The following keyword strings are accepted:</p>
@@ -124,15 +124,15 @@
saved preference.</td>
</tr><tr>
<td>"{@code internalOnly}"</td>
- <td>Request to be installed only on the internal device storage. If this is set, then
-the application will never be installed on the external storage (SD card). If the internal storage
-is full, then the application will not install.</td>
+ <td>The application requests to be installed on the internal device storage only. If this is set,
+then the application will never be installed on the external storage (SD card). If the internal
+storage is full, then the system will not install the application.</td>
</tr><tr>
<td>"{@code preferExternal}"</td>
- <td>Prefer to be installed on external storage (SD card). There is no guarantee that the system
-will honor this request. The application might be installed on internal storage if the
-external media is unavailable or full, or if the application uses the forward-locking mechanism
-(not supported on external storage).</td>
+ <td>The application prefers to be installed on the external storage (SD card). There is no
+guarantee that the system will honor this request. The application might be installed on internal
+storage if the external media is unavailable or full, or if the application uses the forward-locking
+mechanism (not supported on external storage).</td>
</tr>
</table>
@@ -149,7 +149,8 @@
</ul>
<p>The user may also request to move an application from the internal storage to the external
-storage. However, this will not be allowed if this attribute is set to {@code internalOnly}.
+storage. However, the system will not allow the user to move the application to external storage if
+this attribute is set to {@code internalOnly}.
</p>
</dd>
@@ -159,9 +160,7 @@
<!-- ##api level indication## -->
<dt>introduced in:</dt>
-<dd>API Level 1 for all attributes except for
-<code><a href="#uidlabel">sharedUserLabel</a></code>, which was added in
-level 3.</dd>
+<dd>API Level 1 for all attributes, unless noted otherwise in the attribute description.</dd>
<p>
<dt>see also:</dt>
diff --git a/docs/html/guide/topics/resources/accessing-resources.jd b/docs/html/guide/topics/resources/accessing-resources.jd
new file mode 100644
index 0000000..e3e4055
--- /dev/null
+++ b/docs/html/guide/topics/resources/accessing-resources.jd
@@ -0,0 +1,284 @@
+page.title=Accessing Resources
+parent.title=Application Resources
+parent.link=index.html
+@jd:body
+
+<div id="qv-wrapper">
+<div id="qv">
+ <h2>Quickview</h2>
+ <ul>
+ <li>Resources can be referenced from code using integers from {@code R.java}, such as
+{@code R.drawable.myimage}</li>
+ <li>Resources can be referenced from resources using a special XML syntax, such as {@code
+@drawable/myimage}</li>
+ <li>You can also access your app resources with methods in
+{@link android.content.res.Resources}</li>
+ </ul>
+
+ <h2>Key classes</h2>
+ <ol>
+ <li>{@link android.content.res.Resources}</li>
+ </ol>
+
+ <h2>In this document</h2>
+ <ol>
+ <li><a href="#ResourcesInCode">Accessing Resources in Code</a></li>
+ <li><a href="#ReferencesToResources">Accessing Resources in Other XML Resources</a>
+ <ol>
+ <li><a href="#ReferencesToThemeAttributes">Referencing style attributes</a></li>
+ </ol>
+ </li>
+ </ol>
+
+ <h2>See also</h2>
+ <ol>
+ <li><a href="providing-resources.html">Providing Resources</a></li>
+ <li><a href="available-resources.html">Resource Types</a></li>
+ </ol>
+</div>
+</div>
+
+
+<p>There are two ways you can reference your resources for use in your application:</p>
+<ul>
+ <li><strong>From your code:</strong> Using an integer from a sub-class in your {@code R} class,
+such as:
+ <p>{@code R.string.hello}</p>
+ <p>You will see Android APIs that accept this kind of resource identifier as a method parameter
+(usually defined as the {@code id} parameter).</p>
+ </li>
+ <li><strong>From another resource:</strong> Using a special XML syntax that corresponds to the
+{@code R} sub-class, such as:
+ <p>{@code @string/hello}</p>
+ <p>You can use this syntax in an XML resource any place where a value is expected that is
+matched by the existing resource. For example, if you need to provide a string in either an XML
+attribute or element value, you can reference a resource instead of providing a hard-coded
+string.</p>
+ </li>
+</ul>
+
+
+
+<h2 id="ResourcesInCode">Accessing Resources in Code </h2>
+
+<p>When your application is compiled, Android generates the {@code R.java} file (inside
+the {@code gen/} directory), which contains resource
+identifiers to all the resources in your {@code res/} directory. For each type of resource, a
+specific subclass is added to the {@code R} class (for example,
+{@code R.drawable}) and for each resource of that type, a static
+integer is added to the subclass (for example,
+{@code R.drawable.icon}). This integer is the resource ID and you can use it to retrieve
+your resource from your application code.</p>
+
+
+<div class="sidebox-wrapper">
+<div class="sidebox">
+<h2>Access to Original Files</h2>
+
+<p>While uncommon, you might need access your original files and directories. If you do, then
+saving your files in {@code res/} won't work for you. Instead, you can save your resources in the
+{@code assets/} directory.</p>
+<p>Files saved in the {@code assets/} directory will <em>not</em> be given a resource
+ID, so you can't reference them through the {@code R} class or from XML resources. Instead, you can
+query files in the {@code assets/} directory like a normal file system and read raw data using
+{@link android.content.res.AssetManager}.</p>
+<p>However, if all you require is the ability to read raw data (such as a video or audio file),
+then save the file in the {@code res/raw/} directory and read a stream of bytes using {@link
+android.content.res.Resources#openRawResource(int)}.</p>
+
+</div>
+</div>
+
+
+<p class="caution"><strong>Caution:</strong> You should never modify the {@code
+R.java} file by hand—it is generated by the {@code aapt} tool when your project is
+compiled. Any changes will be overridden next time you compile.</p>
+
+<p>Here is the syntax to reference a resource in code:</p>
+<p>
+<code>[<em><package_name></em>.]R.<em><resource_type></em>.<em><resource_name></em></code>
+</p>
+
+<ul>
+ <li><em>{@code <package_name>}</em> is the name of the package in which the resource is located (not
+required when referencing resources from your own package).</li>
+ <li><em>{@code <resource_type>}</em> is the {@code R} subclass for the resource type.</li>
+ <li><em>{@code <resource_name>}</em> is either the {@code
+android:name} attribute value (for some resources defined in XML files) or the resource filename
+without the extension.</li>
+</ul>
+<p>See <a href="resource-types.html">Resource Types</a> for
+more information about each resource type and how to reference them.</p>
+
+<p>In many cases, you can supply an API method with the resource ID. For example, to set the image
+for an {@link android.widget.ImageView}:</p>
+<pre>
+ImageView iv = (ImageView) findViewById(R.id.myimageview);
+iv.setImageResource(R.drawable.myimage);
+</pre>
+
+<p>You can also retrieve your
+resource objects using methods in {@link android.content.res.Resources}, which you can create an
+instance of with {@link android.content.Context#getResources Context.getResources()}. For example,
+to get a string:</p>
+<pre>
+Resources res = this.getResources();
+String string = res.getString(R.string.mystring);
+</pre>
+
+<p>You can also access resources from the platform by prefixing the {@code android}
+namespace. Android contains a number of standard resources, such as styles and themes for your
+layout, button backgrounds, and layouts. To refer to these in code, qualify your reference with the
+<code>android</code> package name. For example,
+<code>android.R.layout.simple_gallery_item</code>.</p>
+
+<p>Here are some examples of using resources in code:</p>
+
+<pre>
+// Load a background for the current screen from a drawable resource
+{@link android.app.Activity#getWindow()}.{@link
+android.view.Window#setBackgroundDrawableResource(int)
+setBackgroundDrawableResource}(R.drawable.my_background_image) ;
+
+// Set the Activity title by getting a string from the Resources object, because
+// this method requires a CharSequence rather than a resource ID
+{@link android.app.Activity#getWindow()}.{@link android.view.Window#setTitle(CharSequence)
+setTitle}(getResources().{@link android.content.res.Resources#getText(int)
+getText}(R.string.main_title));
+
+// Load a custom layout for the current screen
+{@link android.app.Activity#setContentView(int)
+setContentView}(R.layout.main_screen);
+
+// Set a slide in animation by getting an Animation from the Resources object
+mFlipper.{@link android.widget.ViewAnimator#setInAnimation(Animation)
+setInAnimation}(AnimationUtils.loadAnimation(this,
+ R.anim.hyperspace_in));
+
+// Set the text on a TextView object using a resource ID
+TextView msgTextView = (TextView) findViewById(R.id.msg);
+msgTextView.{@link android.widget.TextView#setText(int) setText}(R.string.hello_message);
+</pre>
+
+
+
+
+
+
+<h2 id="ReferencesToResources">Accessing Resources in other XML Resources</h2>
+
+<p>When creating an XML resource, some values for attributes and elements can be a reference to
+an existing resource. This is often used in layout files to supply strings and images.</p>
+
+<p>Here is the syntax to reference a resource in an XML resource:</p>
+<p><code>@[<em><package_name></em>:]<em><resource_type></em>/<em><resource_name></em></code></p>
+
+<ul>
+ <li>{@code <package_name>} is the name of the package in which the resource is located (not
+required when referencing resources from the same package)</li>
+ <li>{@code <resource_type>} is the
+{@code R} subclass for the resource type</li>
+ <li>{@code <resource_name>} is either the {@code
+android:name} attribute value (for some resources defined in XML files) or the resource filename
+without the extension</li>
+</ul>
+
+<p>See <a href="resource-types.html">Resource Types</a> for
+more information about each resource type and how to reference them.</p>
+
+<p>For example, if you have the following resource file that includes a <a
+href="more-resources.html#Color">color resource</a> and a <a
+href="string-resource.html">string resource</a>:</p>
+
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <color name="opaque_red">#f00</color>
+ <string name="hello">Hello!</string>
+</resources>
+</pre>
+
+<p>You can use these resources in the following layout file to set the text color and
+text string:</p>
+
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<EditText xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ <strong>android:textColor="@color/opaque_red"
+ android:text="@string/hello"</strong> />
+</pre>
+
+<p>In this case you don't need to specify the package name in the resource reference because the
+resources are from your own package. To
+reference a system resource, you would need to include the package name. For example:</p>
+
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<EditText xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ <strong>android:textColor="@android:color/secondary_text_dark"</strong>
+ android:text="@string/hello" />
+</pre>
+
+<p class="note"><strong>Note:</strong> You should always use a string resource when supplying
+strings in a layout file, as demonstrated above, so that the strings can be localized. For
+information about creating alternative resources (such as localized strings), see <a
+href="providing-resources.html#AlternativeResources">Providing Alternative
+Resources</a>.</p>
+
+<p>This facility for referencing resources between resources can also be used to create
+alias resources. For example, you can create new drawable resources that is an alias for an existing
+image:</p>
+
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
+ android:src="@drawable/other_drawable" />
+</pre>
+
+<p>This is discussed further in <a href="providing-resources.html#AliasResources">Creating
+alias resources</a>.</p>
+
+
+
+
+<h3 id="ReferencesToThemeAttributes">Referencing style attributes</h3>
+
+<p>A style attribute resource is another type of resource that allows you to reference the value
+of an attribute in the currently-applied theme. Referencing a style attribute allows you to
+customize the look of UI elements by styling them to match standard variations supplied by the
+current theme, instead of supplying a hard-coded value. Referencing a style attribute
+essentially says, "use the style that is defined by this attribute, in the current theme."</p>
+
+<p>To reference a style attribute, the name syntax is almost identical to the normal resource
+format, but instead of the at-symbol ({@code @}), use a question-mark ({@code ?}), and the
+resource type portion is optional. For instance:</p>
+
+<p>
+<code>
+?[<em><package_name></em>:][<em><resource_type></em>/]<em><resource_name></em>
+</code>
+</p>
+
+<p>For example, here's how you might reference an attribute in a layout,
+to set the text color to match the "primary" text color of the system theme:</p>
+
+<pre>
+<EditText id="text"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ <strong>android:textColor="?android:textColorSecondary"</strong>
+ android:text="@string/hello_world" />
+</pre>
+
+<p>Using this markup, you are
+supplying the name of an attribute resource that will be looked up in the theme.
+Because the system resource tool knows that an attribute resource is expected,
+you do not need to explicitly state the type (which would be
+<code>?android:attr/textColorSecondary</code>), so you can exclude the {@code attr} type.</p>
+
+
+
diff --git a/docs/html/guide/topics/resources/animation-resource.jd b/docs/html/guide/topics/resources/animation-resource.jd
new file mode 100644
index 0000000..b2fab04
--- /dev/null
+++ b/docs/html/guide/topics/resources/animation-resource.jd
@@ -0,0 +1,564 @@
+page.title=Animation Resources
+parent.title=Resource Types
+parent.link=available-resources.html
+@jd:body
+
+<div id="qv-wrapper">
+ <div id="qv">
+ <h2>See also</h2>
+ <ol>
+ <li><a href="{@docRoot}guide/topics/graphics/2d-graphics.html#tween-animation">2D
+Graphics</a></li>
+ </ol>
+ </div>
+</div>
+
+
+<p>An animation resource can define one of two types of animations:</p>
+<dl>
+ <dt><a href="#Tween">Tween Animation</a></dt>
+ <dd>Creates an animation by performing a series of transformations on a single image.
+ An {@link android.view.animation.Animation}.</dd>
+ <dt><a href="#Frame">Frame Animation</a></dt>
+ <dd>Creates an animation by showing a sequence of images in order.
+ An {@link android.graphics.drawable.AnimationDrawable}.</dd>
+</dl>
+
+
+
+<h2 id="Tween">Tween Animation</h2>
+
+<p>An animation defined in XML that performs transitions such as rotating,
+fading, moving, and stretching on a graphic.
+</p>
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/anim/<em>filename</em>.xml</code><br/>
+The filename will be used as the resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to an {@link android.view.animation.Animation}.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.anim.<em>filename</em></code><br/>
+In XML: <code>@[<em>package</em>:]anim/<em>filename</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#set-element">set</a> xmlns:android="http://schemas.android.com/apk/res/android"
+ android:interpolator="@[package:]anim/<em>interpolator_resource</em>"
+ android:shareInterpolator=["true" | "false"] >
+ <<a href="#alpha-element">alpha</a>
+ android:fromAlpha="<em>float</em>"
+ android:toAlpha="<em>float</em>" />
+ <<a href="#scale-element">scale</a>
+ android:fromXScale="<em>float</em>"
+ android:toXScale="<em>float</em>"
+ android:fromYScale="<em>float</em>"
+ android:toYScale="<em>float</em>"
+ android:pivotX="<em>string</em>"
+ android:pivotY="<em>string</em>" />
+ <<a href="#translate-element">translate</a>
+ android:fromX="<em>string</em>"
+ android:toX="<em>string</em>"
+ android:fromY="<em>string</em>"
+ android:toY="<em>string</em>" />
+ <<a href="#rotate-element">rotate</a>
+ android:fromDegrees="<em>float</em>"
+ android:toDegrees="<em>float</em>"
+ android:pivotX="<em>string</em>"
+ android:pivotY="<em>string</em>" />
+ <<a href="#set-element">set</a>>
+ ...
+ </set>
+</set>
+</pre>
+
+<p>The file must have a single root element: either an
+<code><alpha></code>, <code><scale></code>, <code><translate></code>,
+<code><rotate></code>, or <code><set></code> element that holds
+a group (or groups) of other animation elements (even nested <code><set></code> elements).
+</p>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+<dl class="tag-list">
+ <dt id="set-element"><code><set></code></dt>
+ <dd>A container that holds other animation elements
+(<code><alpha></code>, <code><scale></code>, <code><translate></code>,
+<code><rotate></code>) or other <code><set></code> elements. Represents an {@link
+android.view.animation.AnimationSet}.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:interpolator</code></dt>
+ <dd><em>Interpolator resource</em>.
+ An {@link android.view.animation.Interpolator} to apply on the animation.
+ The value must be a reference to a resource that specifies an interpolator
+ (not an interpolator class name). There are default interpolator
+ resources available from the platform or you can create your own interpolator resource.
+ See the discussion below for more about <a href="#Interpolators">Interpolators</a>.</dd>
+ <dt><code>android:shareInterpolator</code></dt>
+ <dd><em>Boolean</em>. "true" if you want to share the same interpolator among all child
+elements.</dd>
+ </dl>
+ </dd>
+ <dt id="alpha-element"><code><alpha></code></dt>
+ <dd>A fade-in or fade-out animation. Represents an {@link
+android.view.animation.AlphaAnimation}.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:fromAlpha</code></dt>
+ <dd><em>Float</em>. Starting opacity offset, where 0.0 is transparent and 1.0
+is opaque.</dd>
+ <dt><code>android:toAlpha</code></dt>
+ <dd><em>Float</em>. Ending opacity offset, where 0.0 is transparent and 1.0
+is opaque.</dd>
+ </dl>
+ <p>For more attributes supported by <code><alpha></code>, see the
+{@link android.view.animation.Animation} class reference (of which, all XML attributes are
+inherrited by this element).</p>
+ </dd>
+ <dt id="scale-element"><code><scale></code></dt>
+ <dd>A resizing animation. You can specify the center point of the image from which it grows
+outward (or inward) by specifying {@code pivotX} and {@code pivotY}. For example, if these values
+are 0, 0 (top-left corner), all growth will be down and to the right. Represents a {@link
+android.view.animation.ScaleAnimation}.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:fromXScale</code></dt>
+ <dd><em>Float</em>. Starting X size offset, where 1.0 is no change.</dd>
+ <dt><code>android:toXScale</code></dt>
+ <dd><em>Float</em>. Ending X size offset, where 1.0 is no change.</dd>
+ <dt><code>android:fromYScale</code></dt>
+ <dd><em>Float</em>. Starting Y size offset, where 1.0 is no change.</dd>
+ <dt><code>android:toYScale</code></dt>
+ <dd><em>Float</em>. Ending Y size offset, where 1.0 is no change.</dd>
+ <dt><code>android:pivotX</code></dt>
+ <dd><em>Float</em>. The X coordinate to remain fixed when the object is scaled.</dd>
+ <dt><code>android:pivotY</code></dt>
+ <dd><em>Float</em>. The Y coordinate to remain fixed when the object is scaled.</dd>
+ </dl>
+ <p>For more attributes supported by <code><scale></code>, see the
+{@link android.view.animation.Animation} class reference (of which, all XML attributes are
+inherrited by this element).</p>
+ </dd>
+ <dt id="translate-element"><code><translate></code></dt>
+ <dd>A vertical and/or horizontal motion. Supports the following attributes in any of
+the following three formats: values from -100 to 100 ending with "%", indicating a percentage
+relative to itself; values from -100 to 100 ending in "%p", indicating a percentage relative to its
+parent; a float value with no suffix, indicating an absolute value. Represents a {@link
+android.view.animation.TranslateAnimation}.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:fromXDelta</code></dt>
+ <dd><em>Float or percentage</em>. Starting X offset. Either in: pixels relative to the
+normal position, in percentage relative to the element width (%), or relative to the parent width
+(%p).</dd>
+ <dt><code>android:toXDelta</code></dt>
+ <dd><em>Float or percentage</em>. Ending X offset. Either in: pixels relative to the
+normal position, in percentage relative to the element width (%), or relative to the parent width
+(%p).</dd>
+ <dt><code>android:fromYDelta</code></dt>
+ <dd><em>Float or percentage</em>. Starting Y offset. Either in: pixels relative to the
+normal position, in percentage relative to the element height (%), or relative to the parent height
+(%p).</dd>
+ <dt><code>android:toYDelta</code></dt>
+ <dd><em>Float or percentage</em>. Ending Y offset. Either in: pixels relative to the
+normal position, in percentage relative to the element height (%), or relative to the parent height
+(%p).</dd>
+ </dl>
+ <p>For more attributes supported by <code><translate></code>, see the
+{@link android.view.animation.Animation} class reference (of which, all XML attributes are
+inherrited by this element).</p>
+ </dd>
+ <dt id="rotate-element"><code><rotate></code></dt>
+ <dd>A rotation animation. Represents a {@link android.view.animation.RotateAnimation}.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:fromDegrees</code></dt>
+ <dd><em>Integer</em>. Starting angular position, in degrees.</dd>
+ <dt><code>android:toDegrees</code></dt>
+ <dd><em>Integer</em>. Ending angular position, in degrees.</dd>
+ <dt><code>android:pivotX</code></dt>
+ <dd><em>Integer or percentage</em>. The X coordinate of the center of rotation, in total
+pixels (where 0 is the left edge) or percentage of the screen width.</dd>
+ <dt><code>android:pivotY</code></dt>
+ <dd><em>Integer or percentage</em>. The Y coordinate of the center of rotation, in total
+pixels (where 0 is the top edge) or percentage of the screen height.</dd>
+ </dl>
+ <p>For more attributes supported by <code><rotate></code>, see the
+{@link android.view.animation.Animation} class reference (of which, all XML attributes are
+inherrited by this element).</p>
+ </dd>
+</dl>
+</dd> <!-- end elements and attributes -->
+
+<dt>example:</dt>
+<dd>
+ <pp>XML file saved at <code>res/anim/hyperspace_jump.xml</code>:</p>
+<pre>
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shareInterpolator="false">
+ <scale
+ android:interpolator="@android:anim/accelerate_decelerate_interpolator"
+ android:fromXScale="1.0"
+ android:toXScale="1.4"
+ android:fromYScale="1.0"
+ android:toYScale="0.6"
+ android:pivotX="50%"
+ android:pivotY="50%"
+ android:fillAfter="false"
+ android:duration="700" />
+ <set
+ android:interpolator="@android:anim/accelerate_interpolator"
+ android:startOffset="700">
+ <scale
+ android:fromXScale="1.4"
+ android:toXScale="0.0"
+ android:fromYScale="0.6"
+ android:toYScale="0.0"
+ android:pivotX="50%"
+ android:pivotY="50%"
+ android:duration="400" />
+ <rotate
+ android:fromDegrees="0"
+ android:toDegrees="-45"
+ android:toYScale="0.0"
+ android:pivotX="50%"
+ android:pivotY="50%"
+ android:duration="400" />
+ </set>
+</set>
+</pre>
+ <p>This application code will apply the animation to an {@link android.widget.ImageView} and
+start the animation:</p>
+<pre>
+ImageView image = (ImageView) findViewById(R.id.image);
+Animation hyperspaceJump = AnimationUtils.{@link android.view.animation.AnimationUtils#loadAnimation(Context,int) loadAnimation}(this, R.anim.hyperspace_jump);
+image.{@link android.view.View#startAnimation(Animation) startAnimation}(hyperspaceJump);
+</pre>
+</dd> <!-- end example -->
+
+
+<dt>see also:</dt>
+<dd>
+<ul>
+ <li><a href="{@docRoot}guide/topics/graphics/2d-graphics.html#tween-animation">2D
+Graphics: Tween Animation</a></li>
+</ul>
+</dd>
+
+</dl>
+
+
+
+
+
+<h3 id="Interpolators">Interpolators</h3>
+
+<p>An interpolator is an animation modifier defined in XML that affects the rate of change in an
+animation. This allows your existing animation effects to be accelerated, decelerated, repeated,
+bounced, etc.</p>
+
+<p>An interpolator is applied to an animation element with the {@code android:interpolator}
+attribute, the value of which is a reference to an interpolator resource.</p>
+
+<p>All interpolators available in Android are subclasses of the {@link
+android.view.animation.Interpolator} class. For each interpolator class, Android
+includes a public resource you can reference in order to apply the interpolator to an animation
+using the the {@code android:interpolator} attribute.
+The following table specifies the resource to use for each interpolator:</p>
+
+<table>
+ <tr><th>Interpolator class</th><th>Resource ID</th></tr>
+ <tr>
+ <td>{@link android.view.animation.AccelerateDecelerateInterpolator}</td>
+ <td>{@code @android:anim/accelerate_decelerate_interpolator}</td>
+ </tr>
+ <tr>
+ <td>{@link android.view.animation.AccelerateInterpolator}</td>
+ <td>{@code @android:anim/accelerate_interpolator}</td>
+ </tr>
+ <tr>
+ <td>{@link android.view.animation.AnticipateInterpolator}</td>
+ <td>{@code @android:anim/anticipate_interpolator}</td>
+ </tr>
+ <tr>
+ <td>{@link android.view.animation.AnticipateOvershootInterpolator}</td>
+ <td>{@code @android:anim/anticipate_overshoot_interpolator}</td>
+ </tr>
+ <tr>
+ <td>{@link android.view.animation.BounceInterpolator}</td>
+ <td>{@code @android:anim/bounce_interpolator}</td>
+ </tr>
+ <tr>
+ <td>{@link android.view.animation.CycleInterpolator}</td>
+ <td>{@code @android:anim/cycle_interpolator}</td>
+ </tr>
+ <tr>
+ <td>{@link android.view.animation.DecelerateInterpolator}</td>
+ <td>{@code @android:anim/decelerate_interpolator}</td>
+ </tr>
+ <tr>
+ <td>{@link android.view.animation.LinearInterpolator}</td>
+ <td>{@code @android:anim/linear_interpolator}</td>
+ </tr>
+ <tr>
+ <td>{@link android.view.animation.OvershootInterpolator}</td>
+ <td>{@code @android:anim/overshoot_interpolator}</td>
+ </tr>
+</table>
+
+<p>Here's how you can apply one of these with the {@code android:interpolator} attribute:</p>
+<pre>
+<set android:interpolator="@android:anim/accelerate_interpolator">
+ ...
+</set>
+</pre>
+
+
+<h4>Custom interpolators</h4>
+
+<p>If you're not satisfied with the interpolators provided by the platform (listed in the
+table above), you can create a custom interpolator resource with modified attributes.
+For example, you can adjust the rate of
+acceleration for the {@link android.view.animation.AnticipateInterpolator}, or adjust the number of
+cycles for the {@link android.view.animation.CycleInterpolator}. In order to do so, you need to
+create your own interpolator resource in an XML file.
+</p>
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/anim/<em>filename</em>.xml</code><br/>
+The filename will be used as the resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to the corresponding interpolator object.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In XML: <code>@[<em>package</em>:]anim/<em>filename</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<em>InterpolatorName</em> xmlns:android="http://schemas.android.com/apk/res/android"
+ android:<em>attribute_name</em>="<em>value</em>"
+ />
+</pre>
+<p>If you don't apply any attributes, then your interpolator will function exactly the same as
+those provided by the platform (listed in the table above).</p>
+</dd>
+
+<dt>elements:</dt>
+<dd>Notice that each {@link android.view.animation.Interpolator} implementation, when
+defined in XML, begins its name in lowercase.</p>
+
+<dl class="tag-list">
+ <dt><code><accelerateDecelerateInterpolator></code></dt>
+ <dd>The rate of change starts and ends slowly but accelerates through the
+middle. <p>No attributes.</p></dd>
+ <dt><code><accelerateInterpolator></code></dt>
+ <dd>The rate of change starts out slowly, then accelerates.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:factor</code></dt>
+ <dd><em>Float</em>. The acceleration rate (default is 1).</dd>
+ </dl>
+ </dd>
+ <dt><code><anticipateInterpolator></code></dt>
+ <dd>The change starts backward then flings forward.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:tension</code></dt>
+ <dd><em>Float</em>. The amount of tension to apply (default is 2).</dd>
+ </dl>
+ </dd>
+ <dt><code><anticipateOvershootInterpolator></code></dt>
+ <dd>The change starts backward, flings forward and overshoots the target value, then
+settles at the final value.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:tension</code></dt>
+ <dd><em>Float</em>. The amount of tension to apply (default is 2).</dd>
+ <dt><code>android:extraTension</code></dt>
+ <dd><em>Float</em>. The amount by which to multiply the tension (default is
+ 1.5).</dd>
+ </dl>
+ </dd>
+ <dt><code><bounceInterpolator></code></dt>
+ <dd>The change bounces at the end. <p>No attributes</p></dd>
+ <dt><code><cycleInterpolator></code></dt>
+ <dd>Repeats the animation for a specified number of cycles. The rate of change follows a
+sinusoidal pattern.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:cycles</code></dt>
+ <dd><em>Integer</em>. The number of cycles (default is 1).</dd>
+ </dl>
+ </dd>
+ <dt><code><decelerateInterpolator></code></dt>
+ <dd>The rate of change starts out quickly, then decelerates.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:factor</code></dt>
+ <dd><em>Float</em>. The deceleration rate (default is 1).</dd>
+ </dl>
+ </dd>
+ <dt><code><linearInterpolator></code></dt>
+ <dd>The rate of change is constant. <p>No attributes.</p></dd>
+ <dt><code><overshootInterpolator></code></dt>
+ <dd>The change flings forward and overshoots the last value, then comes back.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:tension</code></dt>
+ <dd><em>Float</em>. The amount of tension to apply (default is 2).</dd>
+ </dl>
+ </dd>
+</dl>
+
+<dt>example:</dt>
+<dd>
+ <p>XML file saved at <code>res/anim/my_overshoot_interpolator.xml</code>:</p>
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<overshootInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
+ android:tension="7.0"
+ />
+</pre>
+ <p>This animation XML will apply the interpolator:</p>
+<pre>
+<scale xmlns:android="http://schemas.android.com/apk/res/android"
+ android:interpolator="@anim/my_overshoot_interpolator"
+ android:fromXScale="1.0"
+ android:toXScale="3.0"
+ android:fromYScale="1.0"
+ android:toYScale="3.0"
+ android:pivotX="50%"
+ android:pivotY="50%"
+ android:duration="700" />
+</pre>
+</dd>
+</dl>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+<h2 id="Frame">Frame Animation</h2>
+
+<p>An animation defined in XML that shows a sequence of images in order (like a film).
+</p>
+
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/drawable/<em>filename</em>.xml</code><br/>
+The filename will be used as the resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to an {@link android.graphics.drawable.AnimationDrawable}.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.drawable.<em>filename</em></code><br/>
+In XML: <code>@[<em>package</em>:]drawable.<em>filename</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#animation-list-element">animation-list</a> xmlns:android="http://schemas.android.com/apk/res/android"
+ android:oneshot=["true" | "false"] >
+ <<a href="#item-element">item</a>
+ android:drawable="@[package:]drawable/<em>drawable_resource_name</em>"
+ android:duration="<em>integer</em>" />
+</animation-list>
+</pre>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+<dl class="tag-list">
+<dt id="animation-list-element"><code><animation-list></code></dt>
+ <dd><strong>Required</strong>. This must be the root element. Contains one or more
+<code><item></code> elements.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:oneshot</code></dt>
+ <dd><em>Boolean</em>. "true" if you want to perform the animation once; "false" to loop the
+animation.</dd>
+ </dl>
+ </dd>
+<dt id="item-element"><code><item></code></dt>
+ <dd>A single frame of animation. Must be a child of a <code><animation-list></code> element.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:drawable</code></dt>
+ <dd><em>Drawable resource</em>. The drawable to use for this frame.</dd>
+ <dt><code>android:duration</code></dt>
+ <dd><em>Integer</em>. The duration to show this frame, in milliseconds.</dd>
+ </dl>
+ </dd>
+</dl>
+</dd> <!-- end elements and attributes -->
+
+<dt>example:</dt>
+<dd>
+ <dl>
+ <dt>XML file saved at <code>res/anim/rocket.xml</code>:</dt>
+ <dd>
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
+ android:oneshot="false">
+ <item android:drawable="@drawable/rocket_thrust1" android:duration="200" />
+ <item android:drawable="@drawable/rocket_thrust2" android:duration="200" />
+ <item android:drawable="@drawable/rocket_thrust3" android:duration="200" />
+</animation-list>
+</pre>
+ </dd>
+
+ <dt>This application code will set the animation as the background for a View,
+ then play the animation:</dt>
+ <dd>
+<pre>
+ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
+rocketImage.{@link android.view.View#setBackgroundResource(int) setBackgroundResource}(R.drawable.rocket_thrust);
+
+rocketAnimation = (AnimationDrawable) rocketImage.{@link android.view.View#getBackground()};
+rocketAnimation.{@link android.graphics.drawable.AnimationDrawable#start()};
+</pre>
+ </dd>
+
+ </dl>
+</dd> <!-- end example -->
+
+</dl>
+
+
+
diff --git a/docs/html/guide/topics/resources/available-resources.jd b/docs/html/guide/topics/resources/available-resources.jd
index 0e003a0e..19babee 100644
--- a/docs/html/guide/topics/resources/available-resources.jd
+++ b/docs/html/guide/topics/resources/available-resources.jd
@@ -1,1451 +1,59 @@
-page.title=Available Resource Types
-parent.title=Resources and Assets
+page.title=Resource Types
+parent.title=Application Resources
parent.link=index.html
@jd:body
<div id="qv-wrapper">
<div id="qv">
-
- <h2>Key classes</h2>
+ <h2>See also</h2>
<ol>
- <li>{@link android.content.res.Resources}</li>
- <li>{@link android.content.res.AssetManager}</li>
+ <li><a href="providing-resources.html">Providing Resources</a></li>
+ <li><a href="accessing-resources.html">Accessing Resources</a></li>
</ol>
-
- <h2>In this document</h2>
- <ol>
- <li><a href="#simplevalues">Simple Values</a>
- <ol>
- <li><a href="#colorvals">Color Values</a></li>
- <li><a href="#stringresources">Strings and Styled Text</a></li>
- <li><a href="#dimension">Dimension Values</a></li>
- </ol>
- </li>
- <li><a href="#drawables">Drawables</a>
- <ol>
- <li><a href="#imagefileresources">Bitmap Files</a></li>
- <li><a href="#colordrawableresources">Color Drawables</a></li>
- <li><a href="#ninepatch">Nine-Patch (Stretchable) Images</a></li>
- </ol>
- </li>
- <li><a href="#animation">Animation</a></li>
- <li><a href="#menus">Menus</a></li>
- <li><a href="#layoutresources">Layout</a>
- <ol>
- <li><a href="#customresources">Custom Layout Resources</a>
- </ol>
- </li>
- <li><a href="#stylesandthemes">Styles and Themes</a></li>
- <li><a href="#Searchable">Searchable</a></li>
- </ol>
-
</div>
</div>
-<p>This page describes the different types of resources that you can
-externalize from your code and package with your application. </p>
+<p>Each of the documents in this section describe the usage, format and syntax for a certain type
+of application resource that you can provide in your resources directory ({@code res/}).</p>
-
-<p>For more details on how to use resources in your application, please see the
- <a href="resources-i18n.html">Resources and Internationalization</a>
- documentation.</p>
-
-
-<h2 id="simplevalues">Simple Values</h2>
-
-<p>All simple resource values can be expressed as a string, using various
-formats to unambiguously indicate the type of resource being created. For
-this reason, these values can be defined both as standard resources
-(under res/values/), as well as direct values supplied for
-mappings in <a href="#stylesandthemes">styles and themes</a>, and attributes in
-XML files such as <a href="#layoutresources">layouts</a>.</p>
-
-
-
-<h3 id="colorvals">Color Values</h3>
-<p>
- A color value specifies an RGB value with an alpha channel, which can
- be used in various places such as specifying a solid color for a {@link android.graphics.drawable.Drawable}
- or the color to use for text. A color value always begins with
- a pound (#) character and then followed by the Alpha-Red-Green-Blue information
- in one of the following formats:
-</p>
-<ul>
-<li> #RGB
-<li> #ARGB
-<li> #RRGGBB
-<li> #AARRGGBB
-</ul>
-<p>
- If you want to retrieve the color represented by a resource ID, you can call
- the {@link android.content.res.Resources#getColor(int) Resources.getColor()} method.
-</p>
-<p>
- <strong>Source file format:</strong> XML file requiring a
- <code><?xml version="1.0" encoding="utf-8"?></code> declaration, and
- a root <code><resources></code> element containing one or more
- <code><color></code> tags.
-</p>
-<p>
- <strong>Resource source file location</strong>: {@code res/values/<em>colors</em>.xml} (File name is arbitrary.)
-</p>
-<p>
- <strong>Compiled resource datatype:</strong> Resource pointer to a Java int.
-</p>
-<p>
- <strong>Resource reference name:</strong>
-</p>
-<ul>
- <li>
- <strong>Java:</strong> <code>R.color.<em>some_name</em></code>
- </li>
- <li>
- <strong>XML:</strong> <code>@[<em>package</em>:]color/some_name</code> (where <em>some_name</em> is the <em>name</em> of a specific color)
- </li>
-</ul>
-<p>
- <strong>Syntax</strong>
-</p>
-<pre>
-<color name=<em>color_name</em>><em>#color_value</em></color>
-</pre>
-<dl>
- <dt>
- <color>
- </dt>
- <dd>
- Value is a color, using web-style syntax, as describe above. Has only one attribute:
- <ul>
- <li>
- <em>name</em> - The name used in referring to this color.
- </li>
- </ul>
- </dd>
-</dl>
-<p>
- <strong>Example XML Declaration</strong>
-</p>
-<p>
- The following code declares two colors, the first fully opaque, and the
- second translucent.
-</p>
-<pre>
-<resources>
- <color name="opaque_red">#f00</color>
- <color name="translucent_red">#80ff0000</color>
-</resources>
-</pre>
-<p>
- <strong>Example Code Use</strong>
-</p>
-<p>
- Example Java code
-</p>
-<pre>
-// Retrieve a color value.
-int color = getResources.getColor(R.color.opaque_red);
-</pre>
-<p>
- Example XML code
-</p>
-<pre>
-<TextView android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textAlign="center"
- android:textColor="@color/translucent_red"
- android:text="Some Text"/>
-</pre>
-
-
-
-<h3 id="stringresources">Strings and Styled Text</h3>
-<p>
- Strings, with optional <a href="#styledtext">simple formatting</a>, can be
-stored and retrieved as resources. You can add formatting to your string by
-using three standard HTML tags: <b>, <i>, and <u>. To
-guarantee getting an unstyled string only (the raw text) call the
-<code>toString()</code> method of the retrieved CharSequence object.
-Methods that accept string resources should be able to process these styling
-tags.
-</p>
-<p>
- If you want to retrieve the String represented by a resource ID, you can call the {@link android.content.Context#getString(int) Context.getString()} method.
-</p>
-<p>
- <strong>Note:</strong> If you use an apostrophe or a quote in your string, you must either escape it or enclose the whole string in the other kind of enclosing quotes:
-</p>
-<pre>
-<string name="good_example">"This'll work"</string>
-<string name="good_example_2">This\'ll also work</string>
-<string name="bad_example">This won't work!</string>
-<string name="bad_example_2">XML encodings won&apos;t work either!</string>
-</pre>
-<p>
- <strong>Source file format:</strong> XML file requiring a <code><?xml version="1.0" encoding="utf-8"?></code> declaration, and a root <code><resources></code> element containing one or more <code><string></code> tags.
-</p>
-<p>
- <strong>Resource source file location</strong>: {@code res/values/<em>strings</em>.xml} (File name is arbitrary.)
-</p>
-<p>
- <strong>Compiled resource datatype:</strong> Resource pointer to a Java CharSequence.
-</p>
-<p>
- <strong>Resource reference name:</strong>
-</p>
-<ul>
- <li>
- <strong>Java:</strong> <code>R.string.<em>some_name</em></code>
- </li>
- <li>
- <strong>XML:</strong> <code>@[<em>package</em>:]string/some_name</code> (where <em>some_name</em> is the <em>name</em> of a specific string)
- </li>
-</ul>
-<p>
- <strong>Syntax</strong>
-</p>
-<pre>
-<string name=<em>string_name</em>><em>string_value</em></string>
-</pre>
-<dl>
- <dt>
- <string>
- </dt>
- <dd>
- Value is a string, with optional styling tags. Has only one attribute:
- <ul>
- <li>
- <em>name</em> - The name used in referring to this string.
- </li>
- </ul>
- </dd>
-</dl>
-<p>
- <strong>Example XML Declaration</strong>
-</p>
-<p>
- The following declares two strings: the first — simple text with no
- formatting (resulting in a CharSequence that is simply a String object) — the second includes formatting information in the string (resulting
- in a CharSequence that is a complex data structure). If you are using the custom editor for string files in Eclipse, the HTML formatting tags will automatically be escaped and you will need to use {@link android.content.Context#getString(int) Context.getString()} and {@link android.text.Html#fromHtml} to retrieve the resource and then convert it to formatted text.
-</p>
-<pre>
-<resources>
- <string name="simple_welcome_message">Welcome!</string>
- <string name="styled_welcome_message">We are <b><i>so</i></b> glad to see you.</string>
-</resources>
-</pre>
-<p>
- <strong>Example Code Use</strong>
-</p>
-<p>
- Example Java code
-</p>
-<pre>
-// Assign a styled string resource to a TextView
-// on the current screen.
-CharSequence str = getString(R.string.styled_welcome_message);
-TextView tv = (TextView)findViewByID(R.id.text);
-tv.setText(str);
-</pre>
-<p>
- Example XML code
-</p>
-<pre>
-<TextView android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textAlign="center"
- android:text="@string/simple_welcome_message"/>
-</pre>
-
-
-<h4 id="styledtext">Using Styled Text as a Format String</h4>
-<p>
-Sometimes you may want to create a styled text resource that is also used as a
-format string. This cannot be done directly because there is no way of passing
-the styled text as the format string argument of String.format()
-without stripping out the style information. The workaround is to store the
-style tags as escaped HTML tags, and then convert the escaped HTML string into
-a styled text after formatting has taken place.
-</p>
-<p>
-To use styled text as a format string, do the following.
-</p>
-<ol>
- <li>Store your styled text resource as an escaped string, so that the HTML tags in your text resource are not interpreted as if they were XML tags:
-<pre>
-<resources>
- <string name="search_results_resultsTextFormat">%1$d results for &lt;b>&amp;quot;%2$s&amp;quot;&lt;/b></string>
-</resources>
-</pre>
-<p>
-In this example the format string has two arguments: <code>%1$d</code> is a decimal number, <code>%2$s</code> is a string.
-</p>
-</li>
-<li>
- Make sure any String arguments are properly escaped if they might contain '<' or '&' characters.
-The {@link android.text.TextUtils#htmlEncode} method will do this:
-<pre>
-String escapedTitle = TextUtil.htmlEncode(title);
-</pre>
-</li>
-<li>
- Use String.format() to format the HTML text, then use {@link android.text.Html#fromHtml} to convert the HTML text into styled text:
-<pre>
-String resultsTextFormat = getContext().getResources().getString(R.string.search_results_resultsTextFormat);
-String resultsText = String.format(resultsTextFormat, count, escapedTitle);
-CharSequence styledResults = Html.fromHtml(resultsText);
-</pre>
-</li>
-</ol>
-
-
-<h3 id="dimension"Dimension Values</h3>
-<p>You can create common dimensions to use for various screen elements by
-defining dimension values in XML. A dimension resource is a number followed by
-a unit of measurement. For example: 10px, 2in, 5sp. Here are the units of
-measurement supported by Android:</p>
-<dl>
- <dt>px</dt>
- <dd>Pixels - corresponds to actual pixels on the screen.</dd>
-
- <dt>in</dt>
- <dd>Inches - based on the physical size of the screen.</dd>
-
- <dt>mm</dt>
- <dd>Millimeters - based on the physical size of the screen.</dd>
-
- <dt>pt</dt>
- <dd>Points - 1/72 of an inch based on the physical size of the screen.</dd>
-
- <dt>dp</dt>
- <dd>Density-independent Pixels - an abstract unit that is based on the
- physical density of the screen. These units are relative to a 160 dpi
- screen, so one dp is one pixel on a 160 dpi screen. The ratio of
- dp-to-pixel will change with the screen density, but not necessarily
- in direct proportion. <strong>Note:</strong> The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".</dd>
-
- <dt>sp</dt>
- <dd>Scale-independent Pixels - this is like the dp unit, but it is also
- scaled by the user's font size preference. It is recommend you use this
- unit when specifying font sizes, so they will be adjusted for both the
- screen density and user's preference.</dd>
-</dl>
-
-<p>Dimension values are not normally used as raw resources, but rather as
-attribute values in XML files. You can, however, create plain resources
-containing this data type.</p>
-
-<p><strong>Source file format:</strong> XML file requiring a <code><?xml
-version="1.0" encoding="utf-8"?></code> declaration, and a root
-<code><resources></code> element containing one or more
-<code><dimen></code> tags.</p>
-
-<p><strong>Resource source file location</strong>: {@code res/values/dimens.xml} (File
-name is arbitrary, but standard practice is to put all dimensions in one file
-devoted to dimensions.)</p>
-<p><strong>Compiled resource datatype:</strong> Resource pointer to a
-dimension.</p>
-<p>
- <strong>Resource reference name:</strong>
-</p>
-<ul>
- <li>
- <strong>Java:</strong> <code>R.dimen.<em>some_name</em></code>
- </li>
- <li>
- <strong>XML:</strong> <code>@[<em>package</em>:]dimen/<em>some_name</em></code> (where <em>some_name</em> is the <em>name</em> of a specific <code><dimen></code> element)
- </li>
-</ul>
-<p>
- <strong>Syntax</strong>
-</p>
-<pre>
-<dimen name=<em>dimen_name</em>><em>dimen_value</em></dimen>
-</pre>
-<dl>
- <dt>
- <dimen>
- </dt>
- <dd>
- A valid dimension value.
- <ul>
- <li>
- <em>name</em> - The name used in referring to this dimension.
- </li>
- </ul>
- </dd>
-</dl>
-<p>
- <strong>Example XML Declaration</strong>
-</p>
-<p>
- The following code declares several dimension values.
-</p>
-<pre>
-<resources>
- <dimen name="one_pixel">1px</dimen>
- <dimen name="double_density">2dp</dimen>
- <dimen name="sixteen_sp">16sp</dimen>
-</resources>
-</pre>
-<p>
- <strong>Example Code Use</strong>
-</p>
-<p>
- Example Java code:
-</p>
-<pre>
-float dimen = Resources.getDimen(R.dimen.one_pixel);
-</pre>
-<p>
- Example XML code:
-</p>
-<pre>
-<TextView android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textSize="@dimen/sixteen_sp"/>
-</pre>
-
-
-<h2 id="drawables">Drawables</h2>
-
-<p>A {@link android.graphics.drawable.Drawable} is a type of resource that
-you retrieve with {@link android.content.res.Resources#getDrawable
-Resources.getDrawable()} and use to draw to the screen. There are a
-number of drawable resources that can be created.</p>
-
-
-
-<h3 id="imagefileresources">Bitmap Files</h3>
-<p>Android supports bitmap resource files in a few different formats: png
-(preferred), jpg (acceptable), gif (discouraged). The bitmap file itself is
-compiled and referenced by the file name without the extension (so
-res/drawable/my_picture.png would be referenced as R.drawable.my_picture).</p>
-
-<p>
- <strong>Source file formats:</strong> png (preferred), jpg (acceptable), gif (discouraged). One resource per file.
-</p>
-<p>
- <strong>Resource file location</strong>: {@code res/drawable/<em>some_file</em>.png}
-</p>
-<p>
- <strong>Compiled resource datatype:</strong> Resource pointer to a {@link android.graphics.drawable.BitmapDrawable BitmapDrawable}.
-</p>
-<p>
- <strong>Resource reference name:</strong>
-</p>
-<ul>
- <li>
- <strong>Java:</strong> <code>R.drawable.<em>some_file</em></code>
- </li>
- <li>
- <strong>XML:</strong> <code>@[<em>package</em>:]drawable/<em>some_file</em></code>
- </li>
-</ul>
-
-<p>For more discussion and examples using drawable resources, see the discussion in <a href="{@docRoot}guide/topics/graphics/2d-graphics.html#drawable-resource#drawables">2D Graphics</a>.</p>
-
-
-<h3 id="colordrawableresources">Color Drawables</h3>
-<p>You can create a {@link android.graphics.drawable.PaintDrawable} object that is a rectangle of color,
-with optionally rounded corners. This element can be defined in any of the
-files inside res/values/.</p>
-<p><strong>Source file format:</strong> XML file requiring a <code><?xml
-version="1.0" encoding="utf-8"?></code> declaration, and a root
-<code><resources></code> element containing one or more
-<code><drawable></code> tags.</p>
-<p>
- <strong>Resource source file location</strong>: {@code res/values/colors.xml} (File name is arbitrary, but standard practice is to put the PaintDrawable
- items in the file along with the <a href="resources-i18n.html#numericcolorresources">numeric color values</a>.)
-</p>
-<p>
- <strong>Compiled resource datatype:</strong> Resource pointer to a {@link android.graphics.drawable.PaintDrawable}.
-</p>
-<p>
- <strong>Resource reference name:</strong>
-</p>
-<ul>
- <li>
- <strong>Java:</strong> <code>R.drawable.<em>some_name</em></code>
- </li>
- <li>
- <strong>XML:</strong> <code>@[<em>package</em>:]drawable/<em>some_name</em></code> (where <em>some_name</em> is the name of a specific resource)
- </li>
-</ul>
-<p>
- <strong>Syntax</strong>
-</p>
-<pre>
-<drawable name=<em>color_name</em>><em>color_value</em></drawable>
-</pre>
-<dl>
- <dt>
- <drawable>
- </dt>
- <dd>
- A valid <a href="#colorvals">color value</a>.
- <ul>
- <li>
- <em>name</em> - The name used in referring to this drawable.
- </li>
- </ul>
- </dd>
-</dl>
-<p>
- <strong>Example XML Declaration</strong>
-</p>
-<p>
- The following code declares several color drawables.
-</p>
-<pre>
-<resources>
- <drawable name="solid_red">#f00</drawable>
- <drawable name="solid_blue">#0000ff</drawable>
- <drawable name="solid_green">#f0f0</drawable>
-</resources>
-</pre>
-<p>
- <strong>Example Code Use</strong>
-</p>
-<p>
- Example Java code
-</p>
-<pre>
-// Assign a PaintDrawable as the background to
-// a TextView on the current screen.
-Drawable redDrawable = Resources.getDrawable(R.drawable.solid_red);
-TextView tv = (TextView)findViewByID(R.id.text);
-tv.setBackground(redDrawable);
-</pre>
-<p>
- Example XML code
-</p>
-<pre>
-<TextView android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textAlign="center"
- android:background="@drawable/solid_red"/>
-</pre>
-
-
-<h3 id="ninepatch">Nine-Patch (stretchable) Images</h3>
-<p>
- Android supports a stretchable bitmap image, called a
- {@link android.graphics.NinePatch} graphic. This is a PNG image in which
- you define stretchable sections that Android will resize to fit the object
- at display time to accommodate variable sized sections, such as text strings.
- You typically assign this resource to the View's background. An example use
- of a stretchable image is the button backgrounds that Android uses; buttons
- must stretch to accommodate strings of various lengths.
-</p>
-
-<p>
- <strong>Source file format:</strong> PNG — one resource per file
-</p>
-<p>
- <strong>Resource source file location</strong>: {@code res/drawable/<em>some_name</em>.9.png} (Filename must end in {@code .9.png})
-</p>
-<p>
- <strong>Compiled resource datatype:</strong> Resource pointer to a {@link android.graphics.drawable.NinePatchDrawable NinePatchDrawable}.
-</p>
-<p>
- <strong>Resource reference name:</strong>
-</p>
-<ul>
- <li>
- <strong>Java:</strong> <code>R.drawable.<em>some_file</em></code>
- </li>
- <li>
- <strong>XML:</strong> <code>@[<em>package</em>:]drawable.<em>some_file</em></code>
- </li>
-</ul>
-
-
-<p>For more information and examples using NinePatch drawables, see the discussion
-in <a href="{@docRoot}guide/topics/graphics/2d-graphics.html#nine-patch">2D Graphics</a>.</p>
-
-
-
-<h2 id="animation">Animation</h2>
-
-<h3 id="tweenedanimation">Tweened Animation</h3>
-<p>
- Android can perform simple animation on a graphic, or a series of graphics. These include rotations, fading, moving, and stretching.
-</p>
-<p>
- <strong>Source file format:</strong> XML file, one resource per file, one root tag with no <code><?xml></code> declaration
-</p>
-<p>
- <strong>Resource file location</strong>: {@code res/anim/<em>some_file</em>.xml}
-</p>
-<p>
- <strong>Compiled resource datatype:</strong> Resource pointer to an {@link android.view.animation.Animation}.
-</p>
-<p>
- <strong>Resource reference name:</strong>
-</p>
-<ul>
- <li>
- <strong>Java:</strong> <code>R.anim.<em>some_file</em></code>
- </li>
- <li>
- <strong>XML:</strong> <code>@[<em>package</em>:]anim/<em>some_file</em></code>
- </li>
-</ul>
-<p>
- <strong>Syntax</strong>
-</p>
-<p>
- The file must have a single root element: this will be either a single <code><alpha></code>, <code><scale></code>, <code><translate></code>, <code><rotate></code>, interpolator element, or <code><set></code> element that holds groups of these elements (which may include another <code><set></code>). By default, all elements are applied simultaneously. To have them occur sequentially, you must specify the <code>startOffset</code> attribute.
-</p>
-<pre>
-<set android:shareInterpolator=boolean> // Only required if multiple tags are used.
- <alpha android:fromAlpha=float
- android:toAlpha=float > |
- <scale android:fromXScale=float
- android:toXScale=float
- android:fromYScale=float
- android:toYScale=float
- android:pivotX=string
- android:pivotY=string > |
- <translate android:fromX=string
- android:toX=string
- android:fromY=string
- android:toY=string > |
- <rotate android:fromDegrees=float
- android:toDegrees=float
- android:pivotX=string
- android:pivotY=string > |
- <<em>interpolator tag</em>>
- <set>
-</set>
-</pre>
-<p>
- <strong>Elements and Attributes</strong>
-</p>
-<dl>
- <dt>
- <set>
- </dt>
- <dd>
- A container that can recursively hold itself or other animations.
- Represents an {@link android.view.animation.AnimationSet}.
- You can include as many child elements of the same or different types as you like.
- Supports the following attribute:
- <ul>
- <li>
- <em>shareInterpolator</em> - Whether to share the same Interpolator among all immediate child elements.
- </li>
- </ul>
- </dd>
- <dt>
- <alpha>
- </dt>
- <dd>
- A fading animation. Represents an {@link android.view.animation.AlphaAnimation}.
- Supports the following attributes:
- <ul>
- <li>
- <em>fromAlpha</em> - 0.0 to 1.0, where 0.0 is transparent.
- </li>
- <li>
- <em>toAlpha</em> - 0.0 to 1.0, where 0.0 is transparent.
- </li>
- </ul>
- </dd>
- <dt>
- <scale>
- </dt>
- <dd>
- A resizing animation. Represents a {@link android.view.animation.ScaleAnimation}.
- You can specify what is the center point of the image (the pinned center), from which it grows outward (or inward), by specifying pivotX and pivotY. So, for example, if these were 0, 0 (top left corner), all growth would be down and to the right. <code>scale</code> supports the following attributes:
- <ul>
- <li>
- <em>fromXScale</em> - Starting X size, where 1.0 is no change.
- </li>
- <li>
- <em>toXScale</em> - Ending X size, where 1.0 is no change.
- </li>
- <li>
- <em>fromYScale</em> - Starting Y size, where 1.0 is no change.
- </li>
- <li>
- <em>toYScale</em> - Ending Y size, where 1.0 is no change.
- </li>
- <li>
- <em>pivotX</em> - The X coordinate of the pinned center.
- </li>
- <li>
- <em>pivotY</em> - The Y coordinate of the pinned center.
- </li>
- </ul>
- </dd>
- <dt>
- <translate>
- </dt>
- <dd>
- A vertical/horizontal motion animation.
- Represents a {@link android.view.animation.TranslateAnimation}.
-Supports the following attributes in any of the following three formats: values from -100 to 100, ending with "%", indicating a percentage relative to itself; values from -100 to 100, ending in "%p", indicating a percentage relative to its parent; a float with no suffix, indicating an absolute value.
- <ul>
- <li>
- <em>fromXDelta</em> - Starting X location.
- </li>
- <li>
- <em>toXDelta</em> - Ending X location.
- </li>
- <li>
- <em>fromYDelta</em> - Starting Y location.
- </li>
- <li>
- <em>toYDelta</em> - Ending Y location.
- </li>
- </ul>
- </dd>
- <dt>
- <rotate>
- </dt>
- <dd>
- A rotation animation. Represents a {@link android.view.animation.RotateAnimation}.
- Supports the following attributes:
- <ul>
- <li>
- <em>fromDegrees</em> - Starting rotation, in degrees.
- </li>
- <li>
- <em>toDegrees</em> - Ending rotation, in degrees.
- </li>
- <li>
- <em>pivotX</em> - The X coordinate of the center of rotation, in pixels, where (0,0) is the top left corner.
- </li>
- <li>
- <em>pivotY</em> - The Y coordinate of the center of rotation, in pixels, where (0,0) is the top left corner.
- </li>
- </ul>
- </dd>
- <dt>
- <em><interpolator tag></em>
- </dt>
- <dd>
- You can also use any of the interpolator subclass elements defined in {@link android.R.styleable}. Examples include <CycleInterpolator>, <EaseInInterpolator>, and <EaseOutInterpolator>. These objects define a velocity curve that describes how quickly a visual action takes place on a timeline (fast at first and slow later, slow at first and gradually faster, and so on).
- </dd>
-</dl>
-<p>
-In addition to the attributes defined for each element above, the elements
-<code><alpha></code>, <code><scale></code>, <code><translate></code>,
-<code><rotate></code>, and <code><set></code> all support the following attributes (inherited
-from the {@link android.view.animation.Animation} class):
-</p>
-<dl>
- <dt><em>{@link android.R.attr#duration duration}</em></dt>
- <dd>
- Duration, in milliseconds, for this effect.
- </dd>
- <dt><em>{@link android.R.attr#startOffset startOffset}</em></dt>
- <dd>
- Offset start time for this effect, in milliseconds.
- </dd>
- <dt><em>{@link android.R.attr#fillBefore fillBefore}</em></dt>
- <dd>
- When set true, the animation transformation is applied before the animation begins.
- </dd>
- <dt><em>{@link android.R.attr#fillAfter fillAfter}</em></dt>
- <dd>
- When set true, the animation transformation is applied after the animation ends.
- </dd>
- <dt><em>{@link android.R.attr#repeatCount repeatCount}</em></dt>
- <dd>
- Defines the number of times the animation should repeat.
- </dd>
- <dt><em>{@link android.R.attr#repeatMode repeatMode}</em></dt>
- <dd>
- Defines the animation behavior when it reaches the end and the repeat count is greater than 0.
- Options are to either restart or reverse the animation.
- </dd>
- <dt><em>{@link android.R.attr#zAdjustment zAdjustment}</em></dt>
- <dd>
- Defines the z-axis ordering mode to use when running the animation (normal, top, or bottom).
- </dd>
- <dt><em>{@link android.R.attr#interpolator interpolator}</em></dt>
- <dd>
- You can optionally set an interpolator for each element to determine how quickly or slowly it performs its effect over time. For example, slow at the beginning and faster at the end for EaseInInterpolator, and the reverse for EaseOutInterpolator. A list of interpolators is given in {@link android.R.anim}. To specify these, use the syntax @android:anim/<em>interpolatorName</em>.
- </dd>
-</dl>
-
-<p>For more discussion and animation code samples, see the discussion in the
-<a href="{@docRoot}guide/topics/graphics/2d-graphics.html#tween-animation">2D Graphics</a> document.</p>
-
-
-
-<h2 id="menus">Menus</h2>
-<p>Application menus (Options Menu, Context Menu, or Sub Menu) can be defined as
-XML resources and inflated by your application using {@link android.view.MenuInflater}.</p>
-
-<p><strong>Source file format:</strong> XML file, one resource per file, one root tag,
-<code><?xml></code> declaration not required.</p>
-<p><strong>Resource file location:</strong> res/menu/<em>some_file</em>.xml</p>
-<p><strong>Compiled resource datatype:</strong> Resource pointer to a {@link android.view.Menu} (or subclass) resource.</p>
-<p><strong>Resource reference name:</strong> </p>
-<ul><li><strong>Java:</strong> <code>R.menu.<em>some_file</em></code></li></ul>
-
-<h3>Syntax</h3>
-<p>The file must have a single root element: a <code><menu></code> element. In all,
-there are three valid elements: <code><menu></code>, <code><group></code> and <code><item></code>. The
-<code><item></code> and <code><group></code> elements must be the children of a <code><menu></code>, but <code><item></code>
-elements can also be the children of a <code><group></code>, and another <code><menu></code> element may be the child
-of an <code><item></code> (to create a Sub Menu).</p>
-<pre>
-<menu xmlns:android="http://schemas.android.com/apk/res/android">
-
- <item android:id="@+id/<em>example_item</em>
- android:title="<em>Example Item</em>"
- android:icon="<em>@drawable/example_item_icon</em>" />
-
- <group android:id="@+id/<em>example_group</em>">
- <item android:id="@+id/<em>example_item2</em>
- android:title="<em>Example Item 2</em>"
- android:icon="<em>@drawable/example_item2_icon</em>" />
- </group>
-
- <item android:id="@+id/<em>example_submenu</em>
- android:title="<em>Example Sub Menu</em>" >
- <menu>
- <item android:id="@+id/<em>example_submenu_item</em>
- android:title="<em>Example Sub Menu Item</em>" />
- </menu>
- </item>
-
-</menu>
-</pre>
-
-<h3>Elements and Attributes</h3>
-<p>All attributes must be defined with the <em>android</em> namespace (e.g., <em>android:icon="@drawable/icon"</em>).</p>
-<dl>
- <dt><menu></dt>
- <dd>The root of a menu. Contains <code><item></code> and <code><group></code> nodes. No attributes.</dd>
- <dt><group></dt>
- <dd>A menu group. Contains <code><item></code> elements. Valid attributes:
- <ul>
- <li><em>id</em> - A unique integer ID for the group.</li>
- <li><em>menuCategory</em> - Value corresponding to Menu CATEGORY_* constants — defines the priority of the group. Valid values:
- <em>container</em>, <em>system</em>, <em>secondary</em>, and <em>alternative</em>.</li>
- <li><em>orderInCategory</em> - An integer that defines the default order of the items within the category.</li>
- <li><em>checkableBehavior</em> - Whether the items are checkable. Valid values:
- <em>none</em>, <em>all</em> (exclusive / radio buttons), <em>single</em> (non-exclusive / checkboxes)</li>
- <li><em>visible</em> - Whether the group is visible. <em>true</em> or <em>false</em>.</li>
- <li><em>enabled</em> - Whether the group is enabled. <em>true</em> or <em>false</em>.</li>
- </ul>
- </dd>
- <dt><item></dt>
- <dd>A menu item. May contain a <code><menu></code> element (for a Sub Menu). Valid attributes:
- <ul>
- <li><em>id</em> - A unique resource ID for the item.</li>
- <li><em>menuCategory</em> - Used to define the menu category.</li>
- <li><em>orderInCategory</em> - Used to define the order of the item, within a group.</li>
- <li><em>title</em> - A string for the menu title.</li>
- <li><em>titleCondensed</em> - A condensed string title, for situations in which the normal title is too long.</li>
- <li><em>icon</em> - A resource identifier for a drawable icon.</li>
- <li><em>alphabeticShortcut</em> - A character for the alphabetic shortcut key.</li>
- <li><em>numericShortcut</em> - A number for the numeric shortcut key.</li>
- <li><em>checkable</em> - Whether the item is checkable. <em>true</em> or <em>false</em>.</li>
- <li><em>checked</em> - Whether the item is checked by default. <em>true</em> or <em>false</em>.</li>
- <li><em>visible</em> - Whether the item is visible by default. <em>true</em> or <em>false</em>.</li>
- <li><em>enabled</em> - Whether the item is enabled by default. <em>true</em> or <em>false</em>.</li>
- </ul>
- </dd>
-</dl>
-
-<p>For more discussion on how to create menus in XML and inflate them in your application,
-read <a href="{@docRoot}guide/topics/ui/menus.html">Creating Menus</a>.</p>
-
-
-
-<h2 id="layoutresources">Layout</h2>
-<p>Android lets you specify screen layouts using XML elements inside an XML
-file, similar to designing screen layout for a webpage in an HTML file. Each
-file contains a whole screen or a part of a screen, and is compiled into a
-View resource that can be passed in to
-{@link android.app.Activity#setContentView(int) Activity.setContentView} or used as a
-reference by other layout resource elements. Files are saved in the
-<code>res/layout/</code> folder of your project, and compiled by the Android resource
-compiler, aapt. </p>
-
-<p> Every layout XML file must evaluate to a single root
-element. First we'll describe how to use the standard XML tags understood by
-Android as it is shipped, and then we'll give a little information on how you
-can define your own custom XML elements for custom View objects.
-
-<p> The root element must have
-the Android namespace "http://schemas.android.com/apk/res/android" defined in
-the root element.</p>
-
-<p>For a complete discussion on creating layouts, see the
-<a href="{@docRoot}guide/topics/ui/index.html">User Interface</a> topic.</p>
-
-<p> <strong>Source file format:</strong> XML file
-requiring a <code><?xml version="1.0" encoding="utf-8"?></code>
-declaration, and a root element of one of the supported XML layout elements.
-</p>
-
-
-<p><strong>Resource file location</strong>:
-res/layout/<em>some_file</em>.xml.</p>
-<p>
- <strong>Compiled resource datatype:</strong> Resource pointer to a {@link android.view.View} (or subclass) resource.
-</p>
-<p>
- <strong>Resource reference name:</strong>
-</p>
-<ul>
- <li>
- <strong>Java:</strong> <code>R.layout.<em>some_file</em></code>
- </li>
- <li>
- <strong>XML:</strong> <code>@[<em>package</em>:]layout/<em>some_file</em></code>
- </li>
-</ul>
-<p>
- <strong>Syntax</strong>
-</p>
-<pre>
-<<em>ViewGroupClass</em> xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/<em>string_name</em>" (attributes)>
- <<em>widget</em> or other nested <em>ViewGroupClass</em>>+
- <requestFocus/>(0 or 1 per layout file, assigned to any element)
-</<em>ViewGroupClass</em>>
-</pre>
-<dl>
- <dt>
- <<em>ViewGroupClass</em>>
- </dt>
- <dd>
- <p>The file must have a single root element. This can be a ViewGroup class that contains other elements, or a widget (or custom item) if it's only one object. By default, you can use any (case-sensitive) Android {@link android.widget widget} or {@link android.view.ViewGroup ViewGroup} class name as an element. These elements support attributes that apply to the underlying class, but the naming is not as clear. How to discover what attributes are supported for what tags is discussed below. You should not assume that any nesting is valid (for example you cannot enclose <code><TextView></code> elements inside a <code><ListLayout></code>).</p>
- <p>If a class derives from another class, the XML element inherits all the attributes from the element that it "derives" from. So, for example, <code><EditText></code> is the corresponding XML element for the EditText class. It exposes its own unique attributes (<code>EditText_numeric</code>), as well as all attributes supported by <code><TextView></code> and <code><View></code>. For the <em>id</em> attribute of a tag in XML, you should use a special syntax: "@+id/<em>somestringvalue</em>". The "@+" syntax creates a resource number in the R.id class, if one doesn't exist, or uses it, if it does exist. When declaring an ID value for an XML tag, use this syntax. Example: <code><TextView android:id="@+id/nameTextbox"/></code>, and refer to it this way in Java: <code>findViewById(R.id.nameTextbox)</code>. All elements support the following values:</p>
- <ul>
- <li>
- <em>id</em> - An ID value used to access this element in Java. Typically you will use the syntax @+id/<em>string_name</em> to generate an ID for you in the id.xml file if you haven't created one yourself.
- </li>
- <li>
- <code>xmlns:android="http://schemas.android.com/apk/res/android"</code> - <em><strong>Required for the root element only.</strong></em>
- </li>
- </ul>
- </dd>
- <dt>
- <requestFocus>
- </dt>
- <dd>
- Any element representing a View object can include this empty element, which gives it's parent tag initial focus on the screen. You can have only one of these elements per file.
- </dd>
-</dl>
-<p>
- <strong>What Attributes Are Supported for What Elements?</strong>
-</p>
-<p>
- Android uses the {@link android.view.LayoutInflater} class at run time to load an XML layout resource and translate it into visual elements. By default, all widget class names are supported directly as tags, but a full list of supported tags and attributes is listed in the {@link android.R.styleable} reference page. However, the attribute names are somewhat obscure. If an underscore appears in the name, this indicates that it is an attribute — typically of the element before the underscore. So, for example, <code>EditText_autoText</code> means that the <code><EditText></code> tag supports an attribute <em>autoText</em>. When you actually use the attribute in that element, use only the portion after the last underscore, and prefix the attribute with the prefix "<code>android:</code>". So, for example, if {@link android.R.styleable} lists the following values:
-</p>
-<ul>
- <li>
- <code>TextView</code>
- </li>
- <li>
- <code>TextView_lines</code>
- </li>
- <li>
- <code>TextView_maxlines</code>
- </li>
-</ul>
-<p>
- You could create an element like this:
-</p>
-<pre>
-<TextView android:lines="10" android:maxlines="20"/>
-</pre>
-<p>
- This would create a {@link android.widget.TextView} object and set its lines and maxlines properties.
-</p>
-<p>
- Attributes come from three sources:
-</p>
-<ul>
- <li>
- <strong>Attributes exposed directly by the element.</strong> For example, <code>TextView</code> supports <code>TextView_text</code>, as discussed above.
- </li>
- <li>
- <strong>Attributes exposed by all the superclasses of that element.</strong> For example, the TextView class extends the View class, so the <code><TextView></code> element supports all the attributes that the <code><View></code> element exposes — a long list, including <code>View_paddingBottom</code> and <code>View_scrollbars</code>. These too are used without the class name: <code><TextView android:paddingBottom="20" android:scrollbars="horizontal" /></code>.
- </li>
- <li>
- <strong>Attributes of the object's {@link android.view.ViewGroup.LayoutParams} subclass.</strong> All View objects support a LayoutParams member (see <a href="{@docRoot}guide/topics/ui/declaring-layout.html#layout-params">Declaring Layout</a>). To set properties on an element's LayoutParams member, the attribute to use is "android:layout_<em>layoutParamsProperty</em>". For example: <code>android:layout_gravity</code> for an object wrapped by a <code><LinearLayout></code> element. Remember that each LayoutParams subclass also supports inherited attributes. Attributes exposed by each subclass are given in the format <em>someLayoutParamsSubclass</em>_Layout_layout_<em>someproperty</em>. This defines an attribute "android:layout_<em>someproperty</em>". Here is an example of how Android documentation lists the properties of the {@link android.widget.LinearLayout.LayoutParams LinearLayout.LayoutParams} class:
- </li>
-</ul>
-<ul>
- <li>LinearLayout_Layout // The actual object — not used.
- </li>
- <li>LinearLayout_Layout_layout_gravity // Exposes a <code>gravity</code> attribute
- </li>
- <li>LinearLayout_Layout_layout_height // Exposes a <code>height</code> attribute
- </li>
- <li>LinearLayout_Layout_layout_weight // Exposes a <code>weight</code> attribute
- </li>
- <li>LinearLayout_Layout_layout_width // Exposes a <code>width</code> attribute
- </li>
-</ul>
-<p>
- Here is an example that sets some of these values on a few objects, including direct attributes, inherited attributes, and LayoutParams attributes:
-</p>
-<pre>
-<?xml version="1.0" encoding="utf-8"?>
-<!-- res/main_screen.xml -->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" // The object's own orientation property
- android:padding="4" // Inherited View property
- android:gravity="center" // The object's own property
- android:layout_width="fill_parent" // Parent object's LinearLayout.LayoutParams.width
- android:layout_height="fill_parent"> // Parent object's LinearLayout.LayoutParams.height
-
- <TextView android:layout_width="fill_parent" // TextView.LayoutParams.width
- android:layout_height="wrap_content" // TextView.LayoutParams.height
- android:layout_weight="0" // TextView.LayoutParams.weight
- android:paddingBottom="4" // TextView.paddingBottom
- android:text="@string/redirect_getter"/> // TextView.text
-
- <EditText android:id="@+id/text"
- android:layout_width="fill_parent" // EditText.LayoutParams.width
- android:layout_height="wrap_content" // EditText.LayoutParams.height
- android:layout_weight="0" // EditText.LinearLayoutParams.weight
- android:paddingBottom="4"> // EditText.paddingBottom
- <requestFocus />
- </EditText>
-
- <Button android:id="@+id/apply"
- android:layout_width="wrap_content" // Button.LayoutParams.width
- android:layout_height="wrap_content" // Button.LayoutParams.height
- android:text="@string/apply" /> // TextView.text
-</LinearLayout>
-</pre>
-<p>
- <strong>Example Code Use</strong>
-</p>
-<p>
- The most common use is to load the XML file (located at <em>res/main_screen.xml</em>) and use it as the current screen, as shown here with the preceding file:
-</p>
-<pre>
-setContentView(R.layout.main_screen);
-</pre>
-<p>
- However, layout elements can also represent repeating elements used as templates.
-</p>
-
-<p>Also see <a href="{@docRoot}guide/topics/ui/index.html">User Interface</a> for more information on layouts.</p>
-
-
-
-<h3 id="customresources">Custom Layout Resources</h3>
-<p>
- You can define custom elements to use in layout resources. These custom elements can then be used the same as any Android layout elements: that is, you can use them and specify their attributes in other resources. The ApiDemos sample application has an example of creating a custom layout XML tag, LabelView. To create a custom element, you will need the following files:
-</p>
-<ul>
- <li>
- <strong>Java implementation file</strong> - The implementation file. The class must extend {@link android.view.View View} or a subclass. See LabelView.java in ApiDemos.
- </li>
- <li>
- <strong>res/values/attrs.xml</strong> - Defines the XML element, and the attributes that it supports, for clients to use to instantiate your object in their layout XML file. Define your element in a <code><declare-styleable name=<em>your_java_class_name</em>></code>. See res/values/attrs.xml in ApiDemos.
- </li>
- <li>
- <strong>res/layout/<em>your_class</em>.xml</strong> [<em>optional</em>] - An optional XML file to describe the layout of your object. This could also be done in Java. See custom_view_1.xml in ApiDemos.
- </li>
-</ul>
-<p>
- <strong>Source file format:</strong> XML file without an <code><?xml></code> declaration, and a <code><resources></code> root element containing one or more custom element tags.
-</p>
-<p>
- <strong>Resource file location</strong>: {@code res/values/<em>attrs</em>.xml} (File name is arbitrary.)
-</p>
-<p>
- <strong>Compiled resource datatype:</strong> Resource pointer to a {@link android.view.View} (or subclass) resource.
-</p>
-<p>
- <strong>Resource reference name:</strong> R.styleable.<em>some_file</em> (Java).
-</p>
-
-
-
-<h2 id="stylesandthemes">Styles and Themes</h2>
-<p>
- A <em>style</em> is one or more attributes applied to a single element (for example, 10 point red Arial font, applied to a TextView). A style is applied as an attribute to an element in a layout XML file.
-</p>
-<p>
- A <em>theme</em> is one or more attributes applied to a whole screen — for example, you might apply the stock Android Theme.dialog theme to an activity designed to be a floating dialog box. A theme is assigned as an attribute to an Activity in the manifest file.
-</p>
-<p>
- Both styles and themes are defined in a <code><style></code> block containing one or more string or numerical values (typically color values), or references to other resources (drawables and so on). These elements support inheritance, so you could have MyBaseTheme, MyBaseTheme.Fancy, MyBaseTheme.Small, and so on.
-</p>
-
-<p>For a complete discussion on styles and themes, read
-<a href="{@docRoot}guide/topics/ui/themes.html">Applying Styles and Themes</a>.</p>
-
-<p>
- <strong>Source file format:</strong> XML file requiring a <code><?xml version="1.0" encoding="utf-8"?></code> declaration, and a root <code><resources></code> element containing one or more <code><style></code> tags.
-</p>
-<p>
- <strong>Resource source file location</strong>: {@code res/values/styles.xml} (File name is arbitrary, but standard practice is to put all styles into a file named styles.xml.)
-</p>
-<p>
- <strong>Compiled resource datatype:</strong> Resource pointer to a Java CharSequence.
-</p>
-<p>
- <strong>Resource reference name:</strong>
-</p>
-<ul>
- <li>
- <strong>Java:</strong> <code>R.style.<em>styleID</em></code> for the whole style, <code>R.style.<em>styleID</em>.<em>itemID</em></code> for an individual setting
- </li>
- <li>
- <strong>XML:</strong> <code>@[<em>package</em>:]style/<em>styleID</em></code> for a whole style, <code>@[<em>package</em>:]style/<em>styleID</em>/<em>itemID</em></code> for an individual item. <strong>Note</strong>: to refer to a value in the <em>currently</em> applied theme, use "?" instead of "@" as described below (XML).
- </li>
-</ul>
-<p>
- <strong>Syntax</strong>
-</p>
-<pre>
-<style name=<em>string</em> [parent=<em>string</em>] >
- <item name=<em>string</em>><em>Hex value | string value | reference</em></item>+<em>
-</em></style>
-</pre>
-<dl>
- <dt>
- <style>
- </dt>
- <dd>
- Holds one or more <item> elements, each describing one value. This style, which is a bundle of values, can be referred to as a <em>theme</em>.
- <ul>
- <li>
- <em>name</em> - The name used in referring to this theme.
- </li>
- <li>
- <em>parent</em> - An optional parent theme. All values from the specified theme will be inherited into this theme. Any values with identical names that you specify will override inherited values. The name must be qualified by the package, but you don't need the /style directive (for example, <code>android:Theme</code> for the base Android theme, or <code>MyTheme</code> for a theme defined in your package).
- </li>
- </ul>
- </dd>
- <dt>
- <item>
- </dt>
- <dd>
- A value to use in this theme. It can be a standard string, a hex color value, or a reference to any other resource type.
- </dd>
-</dl>
-
-<p>For examples of how to declare and apply styles and themes, read
-<a href="{@docRoot}guide/topics/ui/themes.html">Applying Styles and Themes</a>.</p>
-
-
-
-<h2 id="Searchable">Searchable</h2>
-
-<p>To make search appear to the user as a seamless system-wide feature, the Android framework
-offers APIs that let applications control how they are searched.
-Applications can customize how search is invoked, how the search dialog looks, and what type of
-search results are available, including suggestions that are shown as the user types.</p>
-
-<p>In order to utilize the Android search framework, an application must provide a search configuration
-in the form of an XML resource.
-This section describes the search configuration XML in terms of its syntax and usage. For a more
-complete discussion about how to implement search features for your application, see
-<!-- <a href="{@docRoot}guide/topics/search/index.html">Search</a> -->
-{@link android.app.SearchManager}.</p>
-
-<p>
- <strong>Source file format:</strong>
- XML file requiring a <code><?xml version="1.0" encoding="utf-8"?></code>
- declaration, and a root <code><searchable></code> element.
-</p>
-
-<p>
- <strong>Resource source file location</strong>: {@code res/xml/searchable.xml}
- (The file name is arbitrary, but standard practice is to use searchable.xml.)
-</p>
-
-<p>
- <strong>Compiled resource datatype:</strong>
- Resource pointer to an xml object.
-</p>
-
-<p>
- <strong>Resource reference name:</strong>
-</p>
-
-<ul>
- <li>
- <strong>Java:</strong>
- <code>R.xml.<em>filename</em></code>.
- </li>
- <li>
- <strong>XML:</strong>
- <code>@[<em>package</em>:]xml/<em>filename</em></code> (e.g., <code>@xml/searchable</code>).
- </li>
-</ul>
-
-<p>
- <strong>Syntax</strong>
-</p>
-
-<pre>
-<searchable xmlns:android="http://schemas.android.com/apk/res/android
- android:label="@string/search_label"
- ... >
- <em><actionkey
- android:keycode="KEYCODE_CALL"
- ... ></em>
-</searchable>
-</pre>
+<p>Here's a brief summary of each resource type:</p>
<dl>
- <dt>
- <searchable>
- </dt>
- <dd>
- Defines all application search configurations, including settings for text and voice searches
- performed within the application. It accepts the following attributes:
- <ul>
- <li>
- <em>label</em> - <strong>Required</strong>. This is the name for your application, as it
- will appear to the user. This will be visible only if <em>searchMode</em> is set to
- "showSearchLabelAsBadge" (see below).
- </li>
- <li>
- <em>hint</em> - This is the text to display in the search text field when no text has
- been entered. This is recommended in order to provide context to the search about to be
- performed (e.g., "Search the Dictionary").
- </li>
- <li>
- <em>searchMode</em> - If provided and non-zero, this sets additional modes for control
- of the search presentation. The following mode values are accepted:
- <ul>
- <li>
- <em>showSearchLabelAsBadge</em> - If set, this enables the display of the
- search target (label) within the search bar.
- </li>
- <li>
- <em>queryRewriteFromData</em> - If set, this causes the suggestion column
- SUGGEST_COLUMN_INTENT_DATA to be considered as the text for suggestion query
- rewriting. This should only be used when the values in
- SUGGEST_COLUMN_INTENT_DATA are suitable for user inspection and editing -
- typically, HTTP/HTTPS Uri's.
- </li>
- <li>
- <em>queryRewriteFromText</em> - If set, this causes the suggestion
- column SUGGEST_COLUMN_TEXT_1 to be considered as the text for suggestion query
- rewriting. This should be used for suggestions in which no query
- text is provided and the SUGGEST_COLUMN_INTENT_DATA values are not suitable
- for user inspection and editing.
- </li>
- </ul>
- <p>More than one of the above values for <em>searchMode</em> can be used at once. For
- example, you can declare two modes at once, like this:
- <code>searchMode="queryRewriteFromData|queryRewriteFromText"</code>
- </li>
- <li>
- <em>inputType</em> - If provided, supplies a hint about the type of search text
- the user will be entering. For most searches, in which free form text is expected,
- this attribute is not needed. See
- {@link android.R.attr#inputType} for a list of suitable values for this attribute.
- </li>
- <li>
- <em>imeOptions</em> - If provided, supplies additional options for the input method.
- For most searches, in which free form text is expected, this attribute is not needed,
- and will default to "actionSearch". See
- {@link android.R.attr#imeOptions} for a list of suitable values for this attribute.
- </li>
- </ul>
-
- <p>If you have defined a content provider to generate search suggestions, you need to
- provide some more searchable metadata in order to configure communications with the content
- provider. The following are additional {@code <searchable>} attributes for use when
- providing search suggestions:</p>
-
- <ul>
- <li>
- <em>searchSuggestAuthority</em> - <strong>Required to provide search suggestions</strong>.
- This value must match the authority string provided in the provider section of your manifest.
- </li>
- <li>
- <em>searchSuggestPath</em> - If provided, this path will be inserted in the suggestions
- query Uri, after the authority you have provide but before the standard suggestions path.
- This is only required if you have a single content provider issuing different types
- of suggestions (e.g. for different data types) and you need
- a way to disambiguate the suggestions queries when they are received.
- </li>
- <li>
- <em>searchSuggestSelection</em> - If provided, this value will be passed into your
- query function as the selection parameter. Typically this will be a WHERE clause for
- your database, and will contain a single question mark, which represents the actual query
- string that has been typed by the user. However, you can also use any non-null value to simply
- trigger the delivery of the query text (via selection arguments), and then use the query
- text in any way appropriate for your provider (ignoring the actual text of the selection parameter.)
- </li>
- <li>
- <em>searchSuggestIntentAction</em> - The default Intent action to be used when a user
- clicks on a search suggestion.
- If provided, and not overridden by the selected suggestion, this value will
- be placed in the action field of the {@link android.content.Intent} when the
- user clicks a suggestion.
- </li>
- <li>
- <em>searchSuggestIntentData</em> - The default Intent data to be used when a user
- clicks on a search suggestion.
- If provided, and not overridden by the selected suggestion, this value will be
- placed in the data field of the {@link android.content.Intent} when the user clicks
- a suggestion.
- </li>
- </ul>
-
- <p>Beyond providing search suggestions while using your application's local search, you
- can also configure your search suggestions to be made available to Quick Search Box,
- which will allow users so receive search suggestions from your application content from outside
- your application. The following are additional {@code <searchable>} attributes for use when
- providing search suggestions to Quick Search Box:</p>
-
- <ul>
- <li>
- <em>includeInGlobalSearch</em> - <strong>Required to provide search suggestions in
- Quick Search Box</strong>. If true, this indicates the search suggestions provided by your
- application should be included in the globally accessible Quick Search Box. The user must
- still enable your application as a searchable item in the system search settings in order
- for your suggestions to appear in Quick Search Box.
- </li>
- <li>
- <em>searchSettingsDescription</em> - If provided, this provides a brief description
- of the search suggestions that you provide to Quick Search Box,
- and will be displayed in the search settings entry for your application.
- </li>
- <li>
- <em>queryAfterZeroResults</em> - Indicates whether a source should be invoked for
- supersets of queries it has returned zero results for in the past. For example, if a
- source returned zero results for "bo", it would be ignored for "bob". If set to false,
- this source will only be ignored for a single session; the next time the search dialog
- is invoked, all sources will be queried. The default value is false.
- </li>
- <li>
- <em>searchSuggestThreshold</em> - Indicates the minimum number of characters needed to
- trigger a source lookup from Quick Search Box. Only guarantees that a source will not be
- queried for anything shorter than the threshold. The default value is 0.
- </li>
- </ul>
-
- <p>To enable voice search for your Activity, you can add fields to the searchable metadata
- that enable and configure voice search. The following are additional {@code <searchable>}
- attributes for use when implementing voice search:</p>
-
- <ul>
- <li>
- <em>voiceSearchMode</em> - <strong>Required to provide voice search
- capabilities</strong>.
- If provided and non-zero, enables voice search.
- (Voice search may not be provided by the device, in which case these flags will
- have no effect.) The following mode values are accepted:
- <ul>
- <li>
- <em>showVoiceSearchButton</em> - If set, display a voice search button. This only
- takes effect if voice search is available on the device. If set, then "launchWebSearch"
- or "launchRecognizer" must also be set.
- </li>
- <li>
- <em>launchWebSearch</em> - If set, the voice search button will take the user directly
- to a built-in voice web search activity. Most applications will not use this flag, as
- it will take the user away from the activity in which search was invoked.
- </li>
- <li>
- <em>launchRecognizer</em> - If set, the voice search button will take
- the user directly to a built-in voice recording activity. This activity
- will prompt the user to speak, transcribe the spoken text, and forward the resulting
- query text to the searchable activity, just as if the user had typed it into the
- search UI and clicked the search button.
- </li>
- </ul>
- </li>
- <li>
- <em>voiceLanguageModel</em> - A string constant from
- {@link android.speech.RecognizerIntent}.
- If provided, this specifies the language model that
- should be used by the voice recognition system. See
- {@link android.speech.RecognizerIntent#EXTRA_LANGUAGE_MODEL } for more
- information. If not provided, the default value
- {@link android.speech.RecognizerIntent#LANGUAGE_MODEL_FREE_FORM } will be used.
- </li>
- <li>
- <em>voicePromptText</em> - A string. If provided, this specifies a prompt
- that will be displayed during voice input. If not provided, a default prompt
- will be displayed.
- </li>
- <li>
- <em>voiceLanguage</em> - A string constant from {@link java.util.Locale}.
- If provided, this specifies the spoken language to be expected.
- This is only needed if it is different from the current value of
- {@link java.util.Locale#getDefault()}.
- </li>
- <li>
- <em>voiceMaxResults</em> - If provided, enforces the maximum number of results to return,
- including the "best" result which will always be provided as the SEARCH intent's primary
- query. Must be one or greater. Use EXTRA_RESULTS to get the results from the intent.
- If not provided, the recognizer will choose how many results to return.
- </li>
- </ul>
- </dd>
-
- <dt>
- <actionkey>
- </dt>
- <dd>
- Defines a shortcut key for a search action.
- <ul>
- <li>
- <em>keycode</em> - <strong>Required</strong>. This attribute denotes the action key
- you wish to respond to. Note that not all action keys are actually supported using
- this mechanism, as many of them are used for typing,
- navigation, or system functions. This will be added to the
- {@link android.content.Intent#ACTION_SEARCH ACTION_SEARCH} Intent that is passed to your
- searchable Activity. To examine the key code, use
- {@link android.content.Intent#getIntExtra getIntExtra(SearchManager.ACTION_KEY)}.
- Note that, in addition to the keycode, you must also provide one or more of
- the action specifier attributes below.
- </li>
- <li>
- <em>queryActionMsg</em> - If you wish to handle an action key during normal
- search query entry, you must define an action string here. This will be added to the
- {@link android.content.Intent#ACTION_SEARCH ACTION_SEARCH} Intent that is
- passed to your searchable Activity. To examine the string, use
- {@link android.content.Intent#getStringExtra
- getStringExtra(SearchManager.ACTION_MSG)}.
- </li>
- <li>
- <em>suggestActionMsg</em> - If you wish to handle an action key while a
- suggestion is being displayed and selected, there are two ways to handle this.
- If all of your suggestions can handle the action key, you can simply define
- the action message using this attribute. This will be added to the
- {@link android.content.Intent#ACTION_SEARCH} Intent that is passed to your
- searchable Activity. To examine the string,
- use {@link android.content.Intent#getStringExtra
- getStringExtra(SearchManager.ACTION_MSG)}.
- </li>
- <li>
- <em>suggestActionMsgColumn</em> - If you wish to handle an action key while
- a suggestion is being displayed and selected, but you do not wish to enable
- this action key for every suggestion, then you can use this attribute to control
- it on a suggestion-by-suggestion basis. First, you must define a column
- (and name it here) where your suggestions will include the action string. Then,
- in your content provider, you must provide this column, and when desired,
- provide data in this column. The search manager will look at your suggestion cursor,
- using the string provided here in order to select a column, and will use
- that to select a string from the cursor. That string will be added to the
- {@link android.content.Intent#ACTION_SEARCH ACTION_SEARCH}
- Intent that is passed to your searchable Activity. To examine
- the string, use {@link android.content.Intent#getStringExtra
- getStringExtra(SearchManager.ACTION_MSG)}. If the data does not exist for the
- selection suggestion, the action key will be ignored.
- </li>
- </ul>
- </dd>
+ <dt><a href="{@docRoot}guide/topics/resources/animation-resource.html">Animation Resources</a></dt>
+ <dd>Define pre-determined animations.<br/>
+Tween animations are saved in {@code res/anim/} and accessed from the {@code R.anim} class.<br/>
+Frame animations are saved in {@code res/drawable/} and accessed from the {@code R.drawable} class.</dd>
+ <dt><a href="{@docRoot}guide/topics/resources/color-list-resource.html">Color State List Resource</a></dt>
+ <dd>Define a color resources that changes based on the View state.<br/>
+Saved in {@code res/color/} and accessed from the {@code R.color} class.</dd>
+ <dt><a href="{@docRoot}guide/topics/resources/drawable-resource.html">Drawable Resources</a></dt>
+ <dd>Define various graphics with bitmaps or XML.<br/>
+Saved in {@code res/drawable/} and accessed from the {@code R.drawable} class.</dd>
+ <dt><a href="{@docRoot}guide/topics/resources/layout-resource.html">Layout Resource</a></dt>
+ <dd>Define the layout for your application UI.<br/>
+Saved in {@code res/layout/} and accessed from the {@code R.layout} class.</dd>
+ <dt><a href="{@docRoot}guide/topics/resources/menu-resource.html">Menu Resource</a></dt>
+ <dd>Define the contents of your application menus.<br/>
+Saved in {@code res/menu/} and accessed from the {@code R.menu} class.</dd>
+ <dt><a href="{@docRoot}guide/topics/resources/string-resource.html">String Resources</a></dt>
+ <dd>Define strings, string arrays, and plurals (and include string formatting and styling).<br/>
+Saved in {@code res/values/} and accessed from the {@code R.string}, {@code R.array},
+and {@code R.plurals} classes.</dd>
+ <dt><a href="{@docRoot}guide/topics/resources/style-resource.html">Style Resource</a></dt>
+ <dd>Define the look and format for UI elements.<br/>
+Saved in {@code res/values/} and accessed from the {@code R.style} class.</dd>
+ <dt><a href="{@docRoot}guide/topics/resources/more-resources.html">More Resource Types</a></dt>
+ <dd>Define values such as booleans, integers, dimensions, colors, and other arrays.<br/>
+Saved in {@code res/values/} but each accessed from unique {@code R} sub-classes (such as {@code
+R.bool}, {@code R.integer}, {@code R.dimen}, etc.).</dd>
</dl>
+
+
+
+
+
diff --git a/docs/html/guide/topics/resources/color-list-resource.jd b/docs/html/guide/topics/resources/color-list-resource.jd
new file mode 100644
index 0000000..449b66f
--- /dev/null
+++ b/docs/html/guide/topics/resources/color-list-resource.jd
@@ -0,0 +1,165 @@
+page.title=Color State List Resource
+parent.title=Resource Types
+parent.link=available-resources.html
+@jd:body
+
+<div id="qv-wrapper">
+ <div id="qv">
+ <h2>See also</h2>
+ <ol>
+ <li><a href="more-resources.html#Color">Color (simple value)</a></li>
+ </ol>
+ </div>
+</div>
+
+
+<p>A {@link android.content.res.ColorStateList} is an object you can define in XML
+that you can apply as a color, but will actually change colors, depending on the state of
+the {@link android.view.View} object to which it is applied. For example, a {@link
+android.widget.Button} widget can exist in one of several different states (pressed, focused,
+or niether) and, using a color state list, you can provide a different color during each state.</p>
+
+<p>You can describe the state list in an XML file. Each color is defined in an {@code
+<item>} element inside a single {@code <selector>} element. Each {@code <item>}
+uses various attributes to describe the state in which it should be used.</p>
+
+<p>During each state change, the state list is traversed top to bottom and the first item that
+matches the current state will be used—the selection is <em>not</em> based on the "best
+match," but simply the first item that meets the minimum criteria of the state.</p>
+
+<p class="note"><strong>Note:</strong> If you want to provide a static color resource, use a
+simple <a href="more-resources.html#Color">Color</a> value.</p>
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/color/<em>filename</em>.xml</code><br/>
+The filename will be used as the resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to a {@link android.content.res.ColorStateList}.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.color.<em>filename</em></code><br/>
+In XML: <code>@[<em>package</em>:]color/<em>filename</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#selector-element">selector</a> xmlns:android="http://schemas.android.com/apk/res/android" >
+ <<a href="#item-element">item</a>
+ android:color="<em>hex_color</em>"
+ android:state_pressed=["true" | "false"]
+ android:state_focused=["true" | "false"]
+ android:state_selected=["true" | "false"]
+ android:state_active=["true" | "false"]
+ android:state_checkable=["true" | "false"]
+ android:state_checked=["true" | "false"]
+ android:state_enabled=["true" | "false"]
+ android:state_window_focused=["true" | "false"] />
+</selector>
+</pre>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+<dl class="tag-list">
+
+ <dt id="selector-element"><code><selector></code></dt>
+ <dd><strong>Required.</strong> This must be the root element. Contains one or more {@code
+<item>} elements.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>xmlns:android</code></dt>
+ <dd><em>String</em>. <strong>Required.</strong> Defines the XML namespace, which must be
+ <code>"http://schemas.android.com/apk/res/android"</code>.
+ </dl>
+ </dd>
+ <dt id="item-element"><code><item></code></dt>
+ <dd>Defines a color to use during certain states, as described by its attributes. Must be a
+child of a <code><selector></code> element.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:color</code></dt>
+ <dd><em>Hexadeximal color</em>. <strong>Required</strong>. The color is specified with an
+RGB value and optional alpha channel.
+<p>The value always begins with a pound (#) character and then followed by the
+Alpha-Red-Green-Blue information in one of the following formats:</p>
+<ul>
+ <li>#<em>RGB</em></li>
+ <li>#<em>ARGB</em></li>
+ <li>#<em>RRGGBB</em></li>
+ <li>#<em>AARRGGBB</em></li>
+</ul></dd>
+ <dt><code>android:state_pressed</code></dt>
+ <dd><em>Boolean</em>. "true" if this item should be used when the object is pressed (such as when a button
+is touched/clicked); "false" if this item should be used in the default, non-pressed state.</dd>
+ <dt><code>android:state_focused</code></dt>
+ <dd><em>Boolean</em>. "true" if this item should be used when the object is focused (such as when a button
+is highlighted using the trackball/d-pad); "false" if this item should be used in the default,
+non-focused state.</dd>
+ <dt><code>android:state_selected</code></dt>
+ <dd><em>Boolean</em>. "true" if this item should be used when the object is selected (such as when a
+tab is opened); "false" if this item should be used when the object is not selected.</dd>
+ <dt><code>android:state_checkable</code></dt>
+ <dd><em>Boolean</em>. "true" if this item should be used when the object is checkable; "false" if this
+item should be used when the object is not checkable. (Only useful if the object can
+transition between a checkable and non-checkable widget.)</dd>
+ <dt><code>android:state_checked</code></dt>
+ <dd><em>Boolean</em>. "true" if this item should be used when the object is checked; "false" if it
+should be used when the object is un-checked.</dd>
+ <dt><code>android:state_enabled</code></dt>
+ <dd><em>Boolean</em>. "true" if this item should be used when the object is enabled (capable of
+receiving touch/click events); "false" if it should be used when the object is disabled.</dd>
+ <dt><code>android:state_window_focused</code></dt>
+ <dd><em>Boolean</em>. "true" if this item should be used when the application window has focus (the
+application is in the foreground), "false" if this item should be used when the application
+window does not have focus (for example, if the notification shade is pulled down or a dialog appears).</dd>
+ </dl>
+ <p class="note"><strong>Note:</strong> Remember that the first item in the state list that
+matches the current state of the object will be applied. So if the first item in the list contains
+none of the state attributes above, then it will be applied every time, which is why your
+default value should always be last (as demonstrated in the following example).</p>
+ </dd>
+
+</dl>
+</dd> <!-- end elements and attributes -->
+
+<dt>example:</dt>
+<dd>XML file saved at <code>res/color/button_text.xml</code>:
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_pressed="true"
+ android:color="#ffff0000"/> <!-- pressed -->
+ <item android:state_focused="true"
+ android:color="#ff0000ff"/> <!-- focused -->
+ <item android:color="#ff000000"/> <!-- default -->
+</selector>
+</pre>
+
+<p>This layout XML will apply the color list to a View:</p>
+<pre>
+<Button
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/button_text"
+ android:textColor="@color/button_text" />
+</pre>
+</dd> <!-- end example -->
+
+<dt>see also:</dt>
+<dd>
+<ul>
+ <li><a href="more-resources.html#Color">Color (simple value)</a></li>
+ <li>{@link android.content.res.ColorStateList}</li>
+ <li><a href="drawable-resource.html#StateList">State List Drawable</a></li>
+</ul>
+</dd>
+
+</dl>
+
+
diff --git a/docs/html/guide/topics/resources/drawable-resource.jd b/docs/html/guide/topics/resources/drawable-resource.jd
new file mode 100644
index 0000000..ec964ed
--- /dev/null
+++ b/docs/html/guide/topics/resources/drawable-resource.jd
@@ -0,0 +1,711 @@
+page.title=Drawable Resources
+parent.title=Resource Types
+parent.link=available-resources.html
+@jd:body
+
+<div id="qv-wrapper">
+ <div id="qv">
+ <h2>See also</h2>
+ <ol>
+ <li><a href="{@docRoot}guide/topics/graphics/2d-graphics.html">2D Graphics</a></li>
+ </ol>
+ </div>
+</div>
+
+<p>A drawable resource is a general concept for a graphic that you
+can retrieve with {@link android.content.res.Resources#getDrawable(int)}
+and draw on the screen. There are several different types of drawables:</p>
+<dl>
+ <dt><a href="#Bitmap">Bitmap File</a><dt>
+ <dd>A bitmap graphic file ({@code .png}, {@code .jpg}, or {@code .gif}).
+ A {@link android.graphics.drawable.BitmapDrawable}.</dd>
+ <dt><a href="#NinePatch">Nine-Patch File</a></dt>
+ <dd>A PNG file with stretchable regions to allow image resizing based on content ({@code
+.9.png}). A {@link android.graphics.drawable.NinePatchDrawable}.</dd>
+<!-- <dt><a href="#BitmapAlias">Bitmap Alias</a><dt>
+ <dd>An alias for a drawable.</dd> -->
+ <dt><a href="#StateList">State List</a></dt>
+ <dd>An XML file that references different bitmap graphics
+ for different states (for example, to use a different image when a button is pressed).
+ A {@link android.graphics.drawable.StateListDrawable}.</dd>
+ <dt><a href="#Color">Color</a></dt>
+ <dd>A resource defined in XML that specifies a rectangle of color, with
+ optionally rounded corners. A {@link android.graphics.drawable.PaintDrawable}.</dd>
+ <dt><a href="#Shape">Shape</a></dt>
+ <dd>An XML file that defines a geometric shape, including colors and gradients.
+ A {@link android.graphics.drawable.ShapeDrawable}.</dd>
+</dl>
+
+<p>Documentation for the {@link android.graphics.drawable.AnimationDrawable} resource
+is in the <a href="animation-resource.html">Animation Resource</a> document.</p>
+
+<h2 id="Bitmap">Bitmap File</h2>
+
+<p>A basic bitmap image. Android supports basic bitmap files in a few different formats:
+{@code .png} (preferred), {@code .jpg} (acceptable), {@code .gif} (discouraged).</p>
+
+<p class="note"><strong>Note:</strong> Bitmap files may be automatically optimized with lossless
+image compression by the <a href="{@docRoot}guide/developing/tools/aapt.html">aapt</a> tool. For
+example, a true-color PNG that does not require more than 256 colors may be converted to an 8-bit
+PNG with a color palette. This will result in an image of equal quality but which requires less
+memory. So be aware that the image binaries placed in this directory can change during the build. If
+you plan on reading an image as a bit stream in order to convert it to a bitmap, put your images in
+the <code>res/raw/</code> folder instead, where they will not be optimized.</p>
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/drawable/<em>filename</em>.png</code> ({@code .png}, {@code .jpg}, or {@code .gif})<br/>
+The filename will be used as the resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to a {@link android.graphics.drawable.BitmapDrawable}.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.drawable.<em>filename</em></code></li><br/>
+In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
+</dd>
+
+<dt>example:</dt>
+<dd>With an image saved at <code>res/drawable/myimage.png</code>, this layout XML will apply
+the image to a View:
+<pre>
+<ImageView
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ <strong>android:src="@drawable/myimage"</strong> />
+</pre>
+<p>This application code will retrieve the image as a {@link
+android.graphics.drawable.Drawable}:</p>
+<pre>
+Resources res = {@link android.content.Context#getResources()};
+Drawable drawable = res.{@link android.content.res.Resources#getDrawable(int) getDrawable}(R.drawable.myimage);
+</pre>
+</dd>
+
+<dt>see also:</dt>
+<dd>
+<ul>
+ <li><a href="{@docRoot}guide/topics/graphics/2d-graphics.html">2D Graphics</a></li>
+ <li>{@link android.graphics.drawable.BitmapDrawable}</li>
+</ul>
+</dd>
+
+</dl>
+
+
+
+
+
+
+
+<h2 id="NinePatch">Nine-Patch File</h2>
+
+<p>A {@link android.graphics.NinePatch} is a PNG image in which you can define stretchable regions
+that Android will scale when content within the View exceeds the normal image bounds. You will
+typically assign this type of image as the background of a View that has at least one dimension set
+to {@code "wrap_content"}, and when the View grows to accomodate the content, the Nine-Patch image
+will also be scaled to match the size of the View. An example use of a Nine-Patch image is the
+background used by Android's standard {@link android.widget.Button} widget, which must stretch to
+accommodate the text (or image) inside the button.</p>
+
+<p>For a complete discussion about how to define a Nine-Patch file with stretchable regions,
+see the <a href="{@docRoot}guide/topics/graphics/2d-graphics.html#nine-patch">2D Graphics</a>
+document.</p>
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/drawable/<em>filename</em>.9.png</code><br/>
+The filename will be used as the resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to a {@link android.graphics.drawable.NinePatchDrawable}.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.drawable.<em>filename</em></code><br/>
+In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
+</dd>
+
+<dt>example:</dt>
+<dd>With an image saved at <code>res/drawable/myninepatch.9.png</code>, this layout XML will
+apply the Nine-Patch to a View:
+<pre>
+<Button
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ <strong>android:background="@drawable/myninepatch"</strong> />
+</pre>
+</dd>
+
+<dt>see also:</dt>
+<dd>
+<ul>
+ <li><a href="{@docRoot}guide/topics/graphics/2d-graphics.html#nine-patch">2D Graphics</a></li>
+ <li>{@link android.graphics.drawable.NinePatchDrawable}</li>
+</ul>
+</dd>
+
+</dl>
+
+
+
+
+
+
+
+
+<h2 id="StateList">State List</h2>
+
+<p>A {@link android.graphics.drawable.StateListDrawable} is a drawable object defined in XML
+that uses a several different images to represent the same graphic, depending on the state of
+the object. For example, a {@link
+android.widget.Button} widget can exist in one of several different states (pressed, focused,
+or niether) and, using a state list drawable, you can provide a different button image for each
+state.</p>
+
+<p>You can describe the state list in an XML file. Each graphic is represented by an {@code
+<item>} element inside a single {@code <selector>} element. Each {@code <item>}
+uses various attributes to describe the state in which it should be used as the graphic for the
+drawable.</p>
+<p>During each state change, the state list is traversed top to bottom and the first item that
+matches the current state will be used—the selection is <em>not</em> based on the "best
+match," but simply the first item that meets the minimum criteria of the state.</p>
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/drawable/<em>filename</em>.xml</code><br/>
+The filename will be used as the resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to a {@link android.graphics.drawable.StateListDrawable}.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.drawable.<em>filename</em></code><br/>
+In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#selector-element">selector</a> xmlns:android="http://schemas.android.com/apk/res/android"
+ android:constantSize=["true" | "false"]
+ android:dither=["true" | "false"]
+ android:variablePadding=["true" | "false"] >
+ <<a href="#item-element">item</a>
+ android:drawable="@[package:]drawable/<em>drawable_resource</em>"
+ android:state_pressed=["true" | "false"]
+ android:state_focused=["true" | "false"]
+ android:state_selected=["true" | "false"]
+ android:state_active=["true" | "false"]
+ android:state_checkable=["true" | "false"]
+ android:state_checked=["true" | "false"]
+ android:state_enabled=["true" | "false"]
+ android:state_window_focused=["true" | "false"] />
+</selector>
+</pre>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+<dl class="tag-list">
+
+ <dt id="selector-element"><code><selector></code></dt>
+ <dd><strong>Required.</strong> This must be the root element. Contains one or more {@code
+<item>} elements.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>xmlns:android</code></dt>
+ <dd><em>String</em>. <strong>Required.</strong> Defines the XML namespace, which must be
+ <code>"http://schemas.android.com/apk/res/android"</code>.
+ <dt><code>android:constantSize</code></dt>
+ <dd><em>Boolean</em>. "true" if the drawable's reported internal size will remain constant as the state
+changes (the size will be the maximum of all of the states); "false" if the size will vary based on
+the current state. Default is false.</dd>
+ <dt><code>android:dither</code></dt>
+ <dd><em>Boolean</em>. "true" to enable dithering of the bitmap if the bitmap does not have the same pixel
+configuration as the screen (for instance, an ARGB 8888 bitmap with an RGB 565 screen); "false" to
+disable dithering. Default is true.</dd>
+ <dt><code>android:variablePadding</code></dt>
+ <dd><em>Boolean</em>. "true" if the drawable's padding should change based on the current
+state that is selected; "false" if the padding should stay the same (based on the maximum
+padding of all the states). Enabling this feature requires that you deal with
+performing layout when the state changes, which is often not supported. Default is false.</dd>
+ </dl>
+ </dd>
+ <dt id="item-element"><code><item></code></dt>
+ <dd>Defines a drawable to use during certain states, as described by its attributes. Must be a
+child of a <code><selector></code> element.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:drawable</code></dt>
+ <dd><em>Drawable resource</em>. <strong>Required</strong>. Reference to a drawable resource.</dd>
+ <dt><code>android:state_pressed</code></dt>
+ <dd><em>Boolean</em>. "true" if this item should be used when the object is pressed (such as when a button
+is touched/clicked); "false" if this item should be used in the default, non-pressed state.</dd>
+ <dt><code>android:state_focused</code></dt>
+ <dd><em>Boolean</em>. "true" if this item should be used when the object is focused (such as when a button
+is highlighted using the trackball/d-pad); "false" if this item should be used in the default,
+non-focused state.</dd>
+ <dt><code>android:state_selected</code></dt>
+ <dd><em>Boolean</em>. "true" if this item should be used when the object is selected (such as when a
+tab is opened); "false" if this item should be used when the object is not selected.</dd>
+ <dt><code>android:state_checkable</code></dt>
+ <dd><em>Boolean</em>. "true" if this item should be used when the object is checkable; "false" if this
+item should be used when the object is not checkable. (Only useful if the object can
+transition between a checkable and non-checkable widget.)</dd>
+ <dt><code>android:state_checked</code></dt>
+ <dd><em>Boolean</em>. "true" if this item should be used when the object is checked; "false" if it
+should be used when the object is un-checked.</dd>
+ <dt><code>android:state_enabled</code></dt>
+ <dd><em>Boolean</em>. "true" if this item should be used when the object is enabled (capable of
+receiving touch/click events); "false" if it should be used when the object is disabled.</dd>
+ <dt><code>android:state_window_focused</code></dt>
+ <dd><em>Boolean</em>. "true" if this item should be used when the application window has focus (the
+application is in the foreground), "false" if this item should be used when the application
+window does not have focus (for example, if the notification shade is pulled down or a dialog appears).</dd>
+ </dl>
+ <p class="note"><strong>Note:</strong>Remember that the first item in the state list that
+matches the current state of the object will be applied. So if the first item in the list contains
+none of the state attributes above, then it will be applied every time, which is why your
+default value should always be last (as demonstrated in the following example).</p>
+ </dd>
+
+</dl>
+</dd> <!-- end elements and attributes -->
+
+<dt>example:</dt>
+<dd>XML file saved at <code>res/drawable/button.xml</code>:
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_pressed="true"
+ android:drawable="@drawable/button_pressed" /> <!-- pressed -->
+ <item android:state_focused="true"
+ android:drawable="@drawable/button_focused" /> <!-- focused -->
+ <item android:drawable="@drawable/button_normal" /> <!-- default -->
+</selector>
+</pre>
+
+<p>This layout XML will apply the drawable to a View:</p>
+<pre>
+<ImageView
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ <strong>android:src="@drawable/button"</strong> />
+</pre>
+</dd> <!-- end example -->
+
+<dt>see also:</dt>
+<dd>
+<ul>
+ <li>{@link android.graphics.drawable.StateListDrawable}</li>
+</ul>
+</dd>
+
+</dl>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+<h2 id="Color">Color</h2>
+
+<p>This is a color defined in XML that's used as a drawable to fill a rectangular space,
+with optionally rounded corners. This kind of drawable behaves like a color fill.</p>
+
+<p class="note"><strong>Note:</strong> A color drawable is a simple resource that is referenced
+using the value provided in the {@code name} attribute (not the name of the XML file). As
+such, you can combine a color drawable resources with other simple resources in the one XML file,
+under one {@code <resources>} element.</p>
+
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/drawable/<em>filename</em>.png</code><br/>
+The filename is arbitrary. The element's {@code name} will be used as the resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to a {@link android.graphics.drawable.PaintDrawable}.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.drawable.<em>color_name</em></code><br/>
+In XML: <code>@[<em>package</em>:]drawable/<em>color_name</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#color-resources-element">resources</a>>
+ <<a href="#drawable-element">drawable</a>
+ name="<em>color_name</em>"
+ ><em>color</em></drawable>
+</resources>
+</pre>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+<dl class="tag-list">
+
+ <dt id="color-resources-element"><code><resources></code></dt>
+ <dd><strong>Required.</strong> This must be the root node.
+ <p>No attributes.</p>
+ </dd>
+ <dt id="drawable-element"><code><drawable></code></dt>
+ <dd>A color to use as a drawable rectangle. The value can be
+ any valid hexadecimal color value or a <a href="more-resources.html#Color">color
+ resource</a>. A color value always begins with a pound (#) character, followed
+ by the Alpha-Red-Green-Blue information in one of the following formats:
+ #<em>RGB</em>, #<em>RRGGBB</em>, #<em>ARGB</em>, or #<em>AARRGGBB</em>.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>name</code></dt>
+ <dd><em>String</em>. <strong>Required</strong>.
+ A name for the color. This name will be used as the resource ID.</dd>
+ </dl>
+
+ </dd>
+
+</dl>
+</dd> <!-- end elements and attributes -->
+
+<dt>example:</dt>
+<dd>XML file saved at <code>res/drawable/colors.xml</code>:
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <drawable name="solid_red">#f00</drawable>
+ <drawable name="solid_blue">#0000ff</drawable>
+</resources>
+</pre>
+ <p>This layout XML will apply a color drawable to a View:</p>
+<pre>
+<TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ <strong>android:background="@drawable/solid_blue"</strong> />
+</pre>
+ <p>This application code will get a color drawable and apply it to a View:</p>
+<pre>
+Resources res = {@link android.content.Context#getResources()};
+Drawable redDrawable = res.{@link android.content.res.Resources#getDrawable(int) getDrawable}(R.drawable.solid_red);
+
+TextView tv = (TextView) findViewByID(R.id.text);
+tv.setBackground(redDrawable);
+</pre>
+</dd> <!-- end example -->
+
+<dt>see also:</dt>
+<dd>
+<ul>
+ <li>{@link android.graphics.drawable.PaintDrawable}</li>
+</ul>
+</dd>
+
+</dl>
+
+
+
+
+
+
+
+
+
+
+
+
+<h2 id="Shape">Shape</h2>
+
+<p>This is a generic shape defined in XML.</p>
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/drawable/<em>filename</em>.xml</code><br/>
+The filename will be used as the resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to a {@link android.graphics.drawable.ShapeDrawable}.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.drawable.<em>filename</em></code><br/>
+In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#shape-element">shape</a> xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape=["rectangle" | "oval" | "line" | "ring"] >
+ <<a href="#gradient-element">gradient</a>
+ android:angle="<em>integer</em>"
+ android:centerX="<em>integer</em>"
+ android:centerY="<em>integer</em>"
+ android:centerColor="<em>integer</em>"
+ android:gradientRadius="<em>integer</em>"
+ android:type=""
+ android:usesLevel=""
+ android:startColor="<em>color</em>"
+ android:endColor="<em>color</em>" />
+ <<a href="#solid-element">solid</a>
+ android:color="<em>color</em>" />
+ <<a href="#stroke-element">stroke</a>
+ android:width="<em>integer</em>"
+ android:color="<em>color</em>"
+ android:dashWidth="<em>integer</em>"
+ android:dashGap="<em>integer</em>" />
+ <<a href="#padding-element">padding</a>
+ android:left="<em>integer</em>"
+ android:top="<em>integer</em>"
+ android:right="<em>integer</em>"
+ android:bottom="<em>integer</em>" />
+ <<a href="#corners-element">corners</a>
+ android:radius="<em>integer</em>"
+ android:topLeftRadius="<em>integer</em>"
+ android:topRightRadius="<em>integer</em>"
+ android:bottomLeftRadius="<em>integer</em>"
+ android:bottomRightRadius="<em>integer</em>" />
+</shape>
+</pre>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+<dl class="tag-list">
+
+ <dt id="shape-element"><code><shape></code></dt>
+ <dd><strong>Required.</strong> This must be the root element.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:shape</code></dt>
+ <dd><em>Keyword</em>. Defines the type of shape. Valid values are:
+ <table>
+ <tr><th>Value</th><th>Desciption</th></tr>
+ <tr><td>{@code "rectangle"}</td>
+ <td>A rectangle that fills the containing View. This is the default shape.</td></tr>
+ <tr><td>{@code "oval"}</td>
+ <td>An oval shape that fits the dimensions of the containing View.</td></tr>
+ <tr><td>{@code "line"}</td>
+ <td>A horizontal line that spans the width of the containing View. This
+ shape requires the {@code <stroke>} element to define the width of the
+ line.</td></tr>
+ <tr><td>{@code "ring"}</td>
+ <td>A ring shape.</td></tr>
+ </table>
+ </dd>
+ </dl>
+ <p>The following attributes are used only when {@code android:shape="ring"}:</p>
+ <dl class="atn-list">
+ <dt><code>android:innerRadius</code></dt>
+ <dd><em>Dimension</em>. The radius for the
+inner part of the ring (the hole in the middle), as a dimension value or <a
+href="more-resources.html#Dimension">dimension resource</a>.</dd>
+ <dt><code>android:innerRadiusRatio</code></dt>
+ <dd><em>Float</em>. The radius for the inner
+part of the ring, expressed as a ratio of the ring's width. For instance, if {@code
+android:innerRadiusRatio="5"}, then the inner radius equals the ring's width divided by 5. This
+value will be overridden by {@code android:innerRadius}. Default value is 9.</dd>
+ <dt><code>android:thickness</code></dt>
+ <dd><em>Dimension</em>. The thickness of the
+ring, as a dimension value or <a
+href="more-resources.html#Dimension">dimension resource</a>.</dd>
+ <dt><code>android:thicknessRatio</code></dt>
+ <dd><em>Float</em>. The thickness of the ring,
+expressed as a ratio of the ring's width. For instance, if {@code android:thicknessRatio="2"}, then
+the thickness equals the ring's width divided by 2. This value will be overridden by {@code
+android:innerRadius}. Default value is 3.</dd>
+ <dt><code>android:useLevel</code></dt>
+ <dd><em>Boolean</em>. "true" if this is used as
+a {@link android.graphics.drawable.LevelListDrawable}. This should normally be "false"
+ or your shape may not appear.</dd>
+ </dl>
+ <dt id="gradient-element"><code><gradient></code></dt>
+ <dd>Specifies a gradient color for the shape.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:type</code></dt>
+ <dd><em>Keyword</em>. The type of gradient pattern to apply. Valid values are:
+ <table>
+ <tr><th>Value</th><th>Description</th></tr>
+ <tr><td>{@code "linear"}</td>
+ <td>A linear gradient. This is the default.</td></tr>
+ <tr><td>{@code "radial"}</td>
+ <td>A radial gradient. The start color is the center color.</td></tr>
+ <tr><td>{@code "sweep"}</td>
+ <td>A sweeping line gradient. </td></tr>
+ </table>
+ </dd>
+ <dt><code>android:angle</code></dt>
+ <dd><em>Integer</em>. The angle for the gradient, in degrees. 0 is left to right, 90 is
+bottom to top. It must be a multiple of 45. Default is 0.</dd>
+ <dt><code>android:centerX</code></dt>
+ <dd><em>Float</em>. The relative X-position for the center of the gradient (0 - 1.0).
+Does not apply when {@code android:type="linear"}.</dd>
+ <dt><code>android:centerY</code></dt>
+ <dd><em>Float</em>. The relative Y-position for the center of the gradient (0 - 1.0).
+Does not apply when {@code android:type="linear"}.</dd>
+ <dt><code>android:centerColor</code></dt>
+ <dd><em>Color</em>. Optional color that comes between the start and end colors, as a
+hexadecimal value or <a href="more-resources.html#Color">color resource</a>.</dd>
+ <dt><code>android:gradientRadius</code></dt>
+ <dd><em>Float</em>. The radius for the gradient. Only applied when {@code
+android:type="radial"}.</dd>
+ <dt><code>android:useLevel</code></dt>
+ <dd><em>Boolean</em>. "true" if this is used as a {@link
+android.graphics.drawable.LevelListDrawable}.</dd>
+ <dt><code>android:startColor</code></dt>
+ <dd><em>Color</em>. The starting color, as a hexadecimal
+value or <a href="more-resources.html#Color">color resource</a>.</dd>
+ <dt><code>android:endColor</code></dt>
+ <dd><em>Color</em>. The ending color, as a hexadecimal
+value or <a href="more-resources.html#Color">color resource</a>.</dd>
+ </dl>
+ </dd>
+ <dt id="solid-element"><code><solid></code></dt>
+ <dd>A solid color to fill the shape.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:color</code></dt>
+ <dd><em>Color</em>. The color to apply to the shape, as a hexadecimal
+value or <a href="more-resources.html#Color">color resource</a>.</dd>
+ </dl>
+ </dd>
+ <dt id="stroke-element"><code><stroke></code></dt>
+ <dd>A stroke line for the shape.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:width</code></dt>
+ <dd><em>Dimension</em>. The thickness of the line, as a dimension value or <a
+href="more-resources.html#Dimension">dimension resource</a>.</dd>
+ <dt><code>android:color</code></dt>
+ <dd><em>Color</em>. The color of the line, as a
+hexadecimal value or <a href="more-resources.html#Color">color resource</a>.</dd>
+ <dt><code>android:dashGap</code></dt>
+ <dd><em>Dimension</em>. The distance between line dashes, as a dimension value or <a
+href="more-resources.html#Dimension">dimension resource</a>. Only valid if {@code
+android:dashWidth} is set.</dd>
+ <dt><code>android:dashWidth</code></dt>
+ <dd><em>Dimension</em>. The size of each dash line, as a dimension value or <a
+href="more-resources.html#Dimension">dimension resource</a>. Only valid if {@code
+android:dashGap} is set.</dd>
+ </dl>
+ </dd>
+ <dt id="padding-element"><code><padding></code></dt>
+ <dd>Padding to apply to the containing View element (this pads the position of the View
+content, not the shape).
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:left</code></dt>
+ <dd><em>Dimension</em>. Left padding, as a dimension value or <a
+href="more-resources.html#Dimension">dimension resource</a>.</dd>
+ <dt><code>android:top</code></dt>
+ <dd><em>Dimension</em>. Top padding, as a dimension value or <a
+href="more-resources.html#Dimension">dimension resource</a>.</dd>
+ <dt><code>android:right</code></dt>
+ <dd><em>Dimension</em>. Right padding, as a dimension value or <a
+href="more-resources.html#Dimension">dimension resource</a>.</dd>
+ <dt><code>android:bottom</code></dt>
+ <dd><em>Dimension</em>. Bottom padding, as a dimension value or <a
+href="more-resources.html#Dimension">dimension resource</a>.</dd>
+ </dl>
+ </dd>
+ <dt id="corners-element"><code><corners></code></dt>
+ <dd>Creates rounded corners for the shape. Applies only when the shape is a rectangle.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:radius</code></dt>
+ <dd><em>Dimension</em>. The radius for all corners, as a dimension value or <a
+href="more-resources.html#Dimension">dimension resource</a>. This will be overridden for each
+corner by the following attributes.</dd>
+ <dt><code>android:topLeftRadius</code></dt>
+ <dd><em>Dimension</em>. The radius for the top-left corner, as a dimension value or <a
+href="more-resources.html#Dimension">dimension resource</a>.</dd>
+ <dt><code>android:topRightRadius</code></dt>
+ <dd><em>Dimension</em>. The radius for the top-right corner, as a dimension value or <a
+href="more-resources.html#Dimension">dimension resource</a>.</dd>
+ <dt><code>android:bottomLeftRadius</code></dt>
+ <dd><em>Dimension</em>. The radius for the bottom-left corner, as a dimension value or <a
+href="more-resources.html#Dimension">dimension resource</a>.</dd>
+ <dt><code>android:bottomRightRadius</code></dt>
+ <dd><em>Dimension</em>. The radius for the bottom-right corner, as a dimension value or <a
+href="more-resources.html#Dimension">dimension resource</a>.</dd>
+ </dl>
+ <p class="note"><strong>Note:</strong> Every corner must (initially) be provided a corner
+radius greater than zero, or else no corners will be rounded. If you want specific corners
+to <em>not</em> be rounded, a work-around is to use {@code android:radius} to set a default corner
+radius greater than zero, but then override each and every corner with the values you really
+want, providing zero ("0dp") where you don't want rounded corners.</p>
+ </dd>
+
+</dl>
+</dd> <!-- end elements and attributes -->
+
+<dt>example:</dt>
+<dd>XML file saved at <code>res/drawable/gradient_box.xml</code>:
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <gradient
+ android:startColor="#FFFF0000"
+ android:endColor="#80FF00FF"
+ android:angle="45"/>
+ <padding android:left="7dp"
+ android:top="7dp"
+ android:right="7dp"
+ android:bottom="7dp" />
+ <corners android:radius="8dp" />
+</shape>
+</pre>
+ <p>This layout XML will apply the shape drawable to a View:</p>
+<pre>
+<TextView
+ android:background="@drawable/gradient_box"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content" />
+</pre>
+ <p>This application code will get the shape drawable and apply it to a View:</p>
+<pre>
+Resources res = {@link android.content.Context#getResources()};
+Drawable shape = res. {@link android.content.res.Resources#getDrawable(int) getDrawable}(R.drawable.gradient_box);
+
+TextView tv = (TextView)findViewByID(R.id.textview);
+tv.setBackground(shape);
+</pre>
+</dd> <!-- end example -->
+
+</dl>
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/html/guide/topics/resources/index.jd b/docs/html/guide/topics/resources/index.jd
index 1425cfa..f602a04 100644
--- a/docs/html/guide/topics/resources/index.jd
+++ b/docs/html/guide/topics/resources/index.jd
@@ -1,40 +1,104 @@
-page.title=Resources and Assets
+page.title=Application Resources
@jd:body
<div id="qv-wrapper">
<div id="qv">
-
- <h2>Key classes</h2>
+ <h2>Topics</h2>
<ol>
- <li>{@link android.content.res.Resources}</li>
- <li>{@link android.content.res.AssetManager}</li>
+ <li><a href="providing-resources.html">Providing Resources</a></li>
+ <li><a href="accessing-resources.html">Accessing Resources</a></li>
+ <li><a href="runtime-changes.html">Handling Runtime Changes</a></li>
+ <li><a href="localization.html">Localization</a></li>
</ol>
+ <h2>Reference</h2>
+ <ol>
+ <li><a href="available-resources.html">Resource Types</a></li>
+ </ol>
</div>
</div>
-<p>Resources are an integral part of an Android application.
-In general, these are external elements that you want to include and reference within your application,
-like images, audio, video, text strings, layouts, themes, etc. Every Android application contains
-a directory for resources (<code>res/</code>) and a directory for assets (<code>assets/</code>).
-Assets are used less often, because their applications are far fewer. You only need to save data
-as an asset when you need to read the raw bytes. The directories for resources and assets both
-reside at the top of an Android project tree, at the same level as your source code directory
-(<code>src/</code>).</p>
-<p>The difference between "resources" and "assets" isn't much on the surface, but in general,
-you'll use resources to store your external content much more often than you'll use assets.
-The real difference is that anything
-placed in the resources directory will be easily accessible from your application from the
-<code>R</code> class, which is compiled by Android. Whereas, anything placed in the assets
-directory will maintain its raw file format and, in order to read it, you must use the
-{@link android.content.res.AssetManager} to read the file as a stream of bytes. So keeping
-files and data in resources (<code>res/</code>) makes them easily accessible.</p>
+<p>You should always externalize resources such as images and strings from your application
+code, so that you can maintain them independently. Externalizing your
+resources also allows you to provide alternative resources that support specific device
+configurations such as different languages or screen sizes, which becomes increasingly
+important as more Android-powered devices become available with different configurations. In order
+to provide this functionality, you must organize resources in your project's {@code res/}
+directory, using various sub-directories that group resources by type and configuration.</p>
-<p>Within the documents of this topic, you'll find information on the kinds of standard resources
-that are typically used in an Android application and how to reference them from you code.
-<a href="{@docRoot}guide/topics/resources/resources-i18n.html">Resources and Internationalization</a>
-is where you should start, to learn more about how Android utilizes project resources. Then, the
-<a href="{@docRoot}guide/topics/resources/available-resources.html">Available Resource Types</a>
-document offers a summary of various resource types and a reference to their specifications.
-</p>
+<div class="figure" style="width:441px">
+<img src="{@docRoot}images/resources/resource_devices_diagram1.png" height="137" alt="" />
+<p class="img-caption">
+<strong>Figure 1.</strong> Two device configurations, both using default
+resources.</p>
+</div>
+
+<div class="figure" style="width:441px">
+<img src="{@docRoot}images/resources/resource_devices_diagram2.png" height="137" alt="" />
+<p class="img-caption">
+<strong>Figure 2.</strong> Two device configurations, one using alternative
+resources.</p>
+</div>
+
+<p>For any type of resource, you can specify <em>default</em> and multiple
+<em>alternative</em> resources for your application:</p>
+<ul>
+ <li>Default resources are those that should be used regardless of
+the device configuration or when there are no alternative resources that match the current
+configuration.</li>
+ <li>Alternative resources are those that you've designed for use with a specific
+configuration. To specify that a group of resources are for a specific configuration,
+append an appropriate configuration qualifier to the directory name.</li>
+</ul>
+
+<p>For example, while your default UI
+layout is saved in the {@code res/layout/} directory, you might specify a different UI layout to
+be used when the screen is in landscape orientation, by saving it in the {@code res/layout-land/}
+directory. The Android system will automatically apply the appropriate resources by matching the
+device's current configuration to your resource directory names.</p>
+
+<p>Figure 1 demonstrates how a collection of default resources from an application will be applied
+to two different devices when there are no alternative resources available. Figure 2 shows
+the same application with a set of alternative resources that qualify for one of the device
+configurations, thus, the two devices uses different resources.</p>
+
+<p>The information above is just an introduction to how application resources work on Android.
+The following documents provide a complete guide to how you can organize your application resources,
+specify alternative resources, access them in your application, and more:</p>
+
+<dl>
+ <dt><strong><a href="providing-resources.html">Providing Resources</a></strong></dt>
+ <dd>What kinds of resources you can provide in your app, where to save them, and how to create
+alternative resources for specific device configurations.</dd>
+ <dt><strong><a href="accessing-resources.html">Accessing Resources</a></strong></dt>
+ <dd>How to use the resources you've provided, either by referencing them from your application
+code or from other XML resources.</dd>
+ <dt><strong><a href="runtime-changes.html">Handling Runtime Changes</a></strong></dt>
+ <dd>How to manage configuration changes that occur while your Activity is running.</dd>
+ <dt><strong><a href="localization.html">Localization</a></strong></dt>
+ <dd>A bottom-up guide to localizing your application using alternative resources. While this is
+just one specific use of alternative resources, it is very important in order to reach more
+users.</dd>
+ <dt><strong><a href="available-resources.html">Resource Types</a></strong></dt>
+ <dd>A reference of various resource types you can provide, describing their XML elements,
+attributes, and syntax. For example, this reference shows you how to create a resource for
+application menus, drawables, animations, and more.</dd>
+</dl>
+
+<!--
+<h2>Raw Assets</h2>
+
+<p>An alternative to saving files in {@code res/} is to save files in the {@code
+assets/} directory. This should only be necessary if you need direct access to original files and
+directories by name. Files saved in the {@code assets/} directory will not be given a resource
+ID, so you can't reference them through the {@code R} class or from XML resources. Instead, you can
+query data in the {@code assets/} directory like an ordinary file system, search through the
+directory and
+read raw data using {@link android.content.res.AssetManager}. For example, this can be more useful
+when dealing with textures for a game. However, if you only need to read raw data from a file
+(such as a video or audio file), then you should save files into the {@code res/raw/} directory and
+then read a stream of bytes using {@link android.content.res.Resources#openRawResource(int)}. This
+is uncommon, but if you need direct access to original files in {@code assets/}, refer to the {@link
+android.content.res.AssetManager} documentation.</p>
+-->
diff --git a/docs/html/guide/topics/resources/layout-resource.jd b/docs/html/guide/topics/resources/layout-resource.jd
new file mode 100644
index 0000000..a6b177f
--- /dev/null
+++ b/docs/html/guide/topics/resources/layout-resource.jd
@@ -0,0 +1,224 @@
+page.title=Layout Resource
+parent.title=Resource Types
+parent.link=available-resources.html
+@jd:body
+
+<div id="qv-wrapper">
+ <div id="qv">
+ <h2>See also</h2>
+ <ol>
+ <li><a href="{@docRoot}guide/topics/ui/declaring-layout.html">Declaring Layout</a></li>
+ </ol>
+ </div>
+</div>
+
+<p>A layout resource defines the architecture for the UI in an Activity or a component of a UI.</p>
+
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/layout/<em>filename</em>.xml</code><br/>
+The filename will be used as the resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to a {@link android.view.View} (or subclass) resource.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.layout.<em>filename</em></code><br/>
+In XML: <code>@[<em>package</em>:]layout/<em>filename</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#viewgroup-element"><em>ViewGroup</em></a> xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/<em>name</em>"
+ android:layout_height="@+id/<em>string_name</em>"
+ android:layout_width="@+id/<em>string_name</em>"
+ [<em>other attributes</em>] >
+ <<a href="#view-element"><em>View</em></a>
+ android:id="@+id/<em>name</em>"
+ android:layout_height="@+id/<em>string_name</em>"
+ android:layout_width="@+id/<em>string_name</em>"
+ [<em>other attributes</em>] >
+ <<a href="#requestfocus-element">requestFocus</a>/>
+ </<em>View</em>>
+ <<a href="#viewgroup-element"><em>ViewGroup</em></a> >
+ <<a href="#view-element"><em>View</em></a> />
+ </<em>ViewGroup</em>>
+</<em>ViewGroup</em>>
+</pre>
+<p class="note"><strong>Note:</strong> The root element can be either a
+{@link android.view.ViewGroup} or a {@link android.view.View}, but there must be only
+one root element and it must contain the {@code xmlns:android} attribute with the {@code android}
+namespace as shown.</p>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+ <dl class="tag-list">
+
+ <dt id="viewgroup-element"><code><ViewGroup></code></dt>
+ <dd>A container for other {@link android.view.View} elements. There are many
+ different kinds of {@link android.view.ViewGroup} objects and each one lets you
+ specify the layout of the child elements in different ways. Different kinds of
+ {@link android.view.ViewGroup} objects include {@link android.widget.LinearLayout},
+ {@link android.widget.RelativeLayout}, and {@link android.widget.FrameLayout}.
+ <p>You should not assume that any derivation of {@link android.view.ViewGroup}
+ will accept nested {@link android.view.View}s. Some {@link android.view.ViewGroup}s
+ are implementations of the {@link android.widget.AdapterView} class, which determines
+ its children only from an {@link android.widget.Adapter}.</p>
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:id</code></dt>
+ <dd><em>Resource name</em>. A unique resource name for the element, which you can
+use to obtain a reference to the {@link android.view.ViewGroup} from your application.
+ The value takes the form: <code>"@+id/<em>name</em>"</code>. See more about the
+ <a href="#idvalue">value for {@code android:id}</a> below.
+ </dd>
+ <dt><code>android:layout_height</code></dt>
+ <dd><em>Dimension or keyword</em>. <strong>Required</strong>. The height for the group, as a
+dimension value (or <a
+href="more-resources.html#Dimension">dimension resource</a>) or a keyword ({@code "fill_parent"}
+or {@code "wrap_content"}). See the <a href="#layoutvalues">valid values</a> below.
+ </dd>
+ <dt><code>android:layout_width</code></dt>
+ <dd><em>Dimension or keyword</em>. <strong>Required</strong>. The width for the group, as a
+dimension value (or <a
+href="more-resources.html#Dimension">dimension resource</a>) or a keyword ({@code "fill_parent"}
+or {@code "wrap_content"}). See the <a href="#layoutvalues">valid values</a> below.
+ </dd>
+ </dl>
+ <p>More attributes are supported by the {@link android.view.ViewGroup}
+ base class, and many more are supported by each implementation of
+ {@link android.view.ViewGroup}. For a reference of all available attributes,
+ see the corresponding reference documentation for the {@link android.view.ViewGroup} class
+(for example, the <a
+ href="{@docRoot}reference/android/widget/LinearLayout#lattrs">LinearLayout XML attributes</a>).</p>
+ </dd>
+ <dt id="view-element"><code><View></code></dt>
+ <dd>An individual UI component, generally referred to as a "widget". Different
+ kinds of {@link android.view.View} objects include {@link android.widget.TextView},
+ {@link android.widget.Button}, and {@link android.widget.CheckBox}.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:id</code></dt>
+ <dd><em>Resource name</em>. A unique resource name for the element, which you can use to
+ obtain a reference to the {@link android.view.View} from your application.
+ The value takes the form: <code>"@+id/<em>name</em>"</code>. See more about the
+ <a href="#idvalue">value for {@code android:id}</a> below.
+ </dd>
+ <dt><code>android:layout_height</code></dt>
+ <dd><em>Dimension or keyword</em>. <strong>Required</strong>. The height for the element, as
+a dimension value (or <a
+href="more-resources.html#Dimension">dimension resource</a>) or a keyword ({@code "fill_parent"}
+or {@code "wrap_content"}). See the <a href="#layoutvalues">valid values</a> below.
+ </dd>
+ <dt><code>android:layout_width</code></dt>
+ <dd><em>Dimension or keyword</em>. <strong>Required</strong>. The width for the element, as
+a dimension value (or <a
+href="more-resources.html#Dimension">dimension resource</a>) or a keyword ({@code "fill_parent"}
+or {@code "wrap_content"}). See the <a href="#layoutvalues">valid values</a> below.
+ </dd>
+ </dl>
+ <p>More attributes are supported by the {@link android.view.View}
+ base class, and many more are supported by each implementation of
+ {@link android.view.View}. Read <a href="{@docRoot}guide/topics/ui/declaring-layout.html">Declaring
+ Layout</a> for more information. For a reference of all available attributes,
+ see the corresponding reference documentation (for example, the <a
+ href="{@docRoot}reference/android/widget/TextView.html#lattrs">TextView XML attributes</a>).</p>
+ </dd>
+ <dt id="requestfocus-element"><code><requestFocus></code></dt>
+ <dd>Any element representing a {@link android.view.View} object can include this empty element,
+ which gives it's parent initial focus on the screen. You can have only one of these
+ elements per file.</dd>
+
+ </dl>
+
+<h4 id="idvalue">Value for <code>android:id</code></h4>
+
+<p>For the ID value, you should use this syntax form: <code>"@+id/<em>name</em>"</code>. The plus symbol,
+{@code +}, indicates that this is a new resource ID and the aapt tool will create
+a new resource number to the {@code R.java} class, if it doesn't already exist. For example:</p>
+<pre>
+<TextView android:id="@+id/nameTextbox"/>
+</pre>
+<p>You can then refer to it this way in Java:</p>
+<pre>
+findViewById(R.id.nameTextbox);
+</pre>
+
+<h4 id="layoutvalues">Value for <code>android:layout_height</code> and
+<code>android:layout_width</code>:</h4>
+
+ <p>The height and width value can be expressed using any of the
+ <a href="more-resources.html#Dimension">dimension
+ units</a> supported by Android (px, dp, sp, pt, in, mm) or with the following keywords:</p>
+ <table><tr><th>Value</th><th>Description</th></tr>
+ <tr>
+ <td><code>match_parent</code></td>
+ <td>Sets the dimension to match that of the parent element. Added in API Level 8 to
+deprecate <code>fill_parent</code>.</td>
+ </tr>
+ <tr>
+ <td><code>fill_parent</code></td>
+ <td>Sets the dimension to match that of the parent element.</td>
+ </tr><tr>
+ <td><code>wrap_content</code></td>
+ <td>Sets the dimension only to the size required to fit the content of this element.</td>
+ </tr>
+ </table>
+
+<h4>Custom View elements</h4>
+
+<p>You can create your own custom {@link android.view.View} and {@link android.view.ViewGroup}
+elements and apply them to your layout the same as a standard layout
+element. You can also specify the attributes supported in the XML element. To learn more,
+read <a href="{@docRoot}guide/topics/ui/custom-components.html">Building Custom Components</a>.
+</p>
+
+</dd> <!-- end elements and attributes -->
+
+<dt>example:</dt>
+<dd>XML file saved at <code>res/layout/main_activity.xml</code>:
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical" >
+ <TextView android:id="@+id/text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Hello, I am a TextView" />
+ <Button android:id="@+id/button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Hello, I am a Button" />
+</LinearLayout>
+</pre>
+ <p>This application code will load the layout for an {@link android.app.Activity}, in the
+ {@link android.app.Activity#onCreate(Bundle) onCreate()} method:</dt>
+ <dd>
+<pre>
+public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView.(R.layout.main_activity);
+}
+</pre>
+</dd> <!-- end example -->
+
+
+<dt>see also:</dt>
+<dd>
+<ul>
+ <li><a href="{@docRoot}guide/topics/ui/declaring-layout.html">Declaring Layout</a></li>
+ <li>{@link android.view.View}</li>
+ <li>{@link android.view.ViewGroup}</li>
+</ul>
+</dd>
+
+</dl>
\ No newline at end of file
diff --git a/docs/html/guide/topics/resources/localization.jd b/docs/html/guide/topics/resources/localization.jd
index 192695b..e76a92c 100755
--- a/docs/html/guide/topics/resources/localization.jd
+++ b/docs/html/guide/topics/resources/localization.jd
@@ -1,5 +1,5 @@
page.title=Localization
-parent.title=Resources and Assets
+parent.title=Application Resources
parent.link=index.html
@jd:body
@@ -25,12 +25,11 @@
<ol><li><a href="#defaults-r-important">Why Default Resources Are Important</a></li></ol>
<li><a href="#using-framework">Using Resources for Localization</a>
<ol>
- <li><a href="#creating-defaults">How to Create Default Resources</a></li><li>
- <a href="#creating-alternates">How to Create Alternate Resources</a></li>
+ <li><a href="#creating-defaults">How to Create Default Resources</a></li>
+ <li><a href="#creating-alternatives">How to Create Alternative Resources</a></li>
<li><a href="#resource-precedence">Which Resources Take Precedence?</a></li>
<li><a href="#referring-to-resources">Referring to Resources in Java</a></li>
-
- </ol>
+ </ol>
</li>
<li><a href="#strategies">Localization Strategies</a></li>
<li><a href="#testing">Testing Localized Applications</a></li>
@@ -52,7 +51,7 @@
<ol>
<li><a
href="{@docRoot}resources/tutorials/localization/index.html">Hello, L10N Tutorial</a></li>
- <li><a href="resources-i18n.html">Resources</a></li>
+ <li><a href="{@docRoot}guide/topics/resources/providing-resources.html">Providing Resources</a></li>
<li><a href="{@docRoot}guide/topics/ui/declaring-layout.html">Declaring Layout</a></li>
<li><a href="{@docRoot}reference/android/app/Activity.html#ActivityLifecycle">Activity Lifecycle</a></li>
</ol>
@@ -80,7 +79,7 @@
<ul>
<li>You can put most or all of the <em>contents</em> of your application's
user interface into resource files, as described in this document and in <a
-href="index.html">Resources</a>. </li>
+href="{@docRoot}guide/topics/resources/providing-resources.html">Providing Resources</a>.</li>
<li>The <em>behavior</em> of the user interface, on the other hand, is driven
by your Java code.
For example, if users input data that needs to be formatted or sorted
@@ -107,14 +106,15 @@
<p>(This document focuses on localization and locale. For a complete description
of resource-switching and all the types of configurations that you can
specify — screen orientation, touchscreen type, and so on — see <a
-href="resources-i18n.html#AlternateResources">Alternate Resources</a>.)</p>
+href="{@docRoot}guide/topics/resources/providing-resources.html#AlternativeResources">Providing
+Alternative Resources</a>.)</p>
<table border="0" cellspacing="0" cellpadding="0">
<tr border="0">
<td width="180" style="border: 0pt none ;"><p class="special-note">
<strong>When you write your application:</strong>
<br><br>
- You create a set of default resources, plus alternates to be used in
+ You create a set of default resources, plus alternatives to be used in
different locales.</p></td>
<td style="border: 0pt none; padding:0">
<p style="border:0; padding:0"><img src="../../../images/resources/right-arrow.png" alt="right-arrow"
@@ -126,7 +126,7 @@
</tr>
</table>
-<p>When you write your application, you create default and alternate resources
+<p>When you write your application, you create default and alternative resources
for your application to use. To create resources, you place files within
specially named subdirectories of the project's <code>res/</code> directory.
</p>
@@ -204,18 +204,19 @@
<em>default</em> string file must contain them all.
</p>
-<h3 id="creating-alternates">How to Create Alternate Resources</h3>
+<h3 id="creating-alternatives">How to Create Alternative Resources</h3>
-<p>A large part of localizing an application is providing alternate text for
-different languages. In some cases you will also provide alternate graphics,
+<p>A large part of localizing an application is providing alternative text for
+different languages. In some cases you will also provide alternative graphics,
sounds, layouts, and other locale-specific resources. </p>
<p>An application can specify many <code>res/<em><qualifiers></em>/</code>
-directories, each with different qualifiers. To create an alternate resource for
+directories, each with different qualifiers. To create an alternative resource for
a different locale, you use a qualifier that specifies a language or a
language-region combination. (The name of a resource directory must conform
to the naming scheme described in
-<a href="resources-i18n.html#AlternateResources">Alternate Resources</a>,
+<a href="{@docRoot}guide/topics/resources/providing-resources.html#AlternativeResources">Providing
+Alternative Resources</a>,
or else it will not compile.)</p>
<p><em>Example:</em></p>
@@ -223,7 +224,7 @@
<p>Suppose that your application's default language is English. Suppose also
that you want to localize all the text in your application to French, and most
of the text in your application (everything except the application's title) to
-Japanese. In this case, you could create three alternate <code>strings.xml</code>
+Japanese. In this case, you could create three alternative <code>strings.xml</code>
files, each stored in a locale-specific resource directory:</p>
<ol>
@@ -315,19 +316,21 @@
will prefer an MCC match over a language match. </p>
<p>The selection process is not always as straightforward as these examples
-suggest. Please read <a href="resources-i18n.html#best-match">How Android finds
-the best matching directory</a> for a more nuanced description of the
+suggest. Please read <a
+href="{@docRoot}guide/topics/resources/creating-resources.html#BestMatch">How Android Finds
+the Best-matching Resource</a> for a more nuanced description of the
process. All the qualifiers are described and listed in order of
-precedence in <a href="resources-i18n.html#table2">Table 2 in the Resources
-document</a>.</p>
+precedence in <a
+href="{@docRoot}guide/topics/resources/creating-resources.html#table2">Table 2 of Providing
+Alternative Resources</a>.</p>
<h3 id="referring-to-resources">Referring to Resources in Java</h3>
<p>In your application's Java code, you refer to resources using the syntax
<code>R.<em>resource_type</em>.<em>resource_name</em></code> or
<code>android.R.<em>resource_type</em>.<em>resource_name</em></code><em>.</em>
-For more about this, see <a href="resources-i18n.html#ResourcesInCode">Using
-Resources in Code</a>.</p>
+For more about this, see <a
+href="{@docRoot}guide/topics/resources/using-resources.html">Accessing Resources</a>.</p>
<h2 id="strategies">Localization Strategies</h2>
@@ -359,7 +362,7 @@
<h4>Design a flexible layout</h4>
<p> If you need to rearrange your layout to fit a certain language (for example
-German with its long words), you can create an alternate layout for that
+German with its long words), you can create an alternative layout for that
language (for example <code>res/layout-de/main.xml</code>). However, doing this
can make your application harder to maintain. It is better to create a single
layout that is more flexible.</p>
@@ -383,10 +386,10 @@
<p>You probably do not need to create a locale-specific
alternative for every resource in your application. For example, the layout
defined in the <code>res/layout/main.xml</code> file might work in any locale,
-in which case there would be no need to create any alternate layout files.
+in which case there would be no need to create any alternative layout files.
</p>
-<p>Also, you might not need to create alternate text for every
+<p>Also, you might not need to create alternative text for every
string. For example, assume the following:</p>
<ul>
@@ -395,7 +398,7 @@
English spellings, in <code>res/values/strings.xml</code>. </li>
<li>For a few important phrases, you want to provide
-British English spelling. You want these alternate strings to be used when your
+British English spelling. You want these alternative strings to be used when your
application runs on a device in the United Kingdom. </li>
</ul>
diff --git a/docs/html/guide/topics/resources/menu-resource.jd b/docs/html/guide/topics/resources/menu-resource.jd
new file mode 100644
index 0000000..c9f27fa
--- /dev/null
+++ b/docs/html/guide/topics/resources/menu-resource.jd
@@ -0,0 +1,207 @@
+page.title=Menu Resource
+parent.title=Resource Types
+parent.link=available-resources.html
+@jd:body
+
+<div id="qv-wrapper">
+ <div id="qv">
+ <h2>See also</h2>
+ <ol>
+ <li><a href="{@docRoot}guide/topics/ui/menus.html">Creating Menus</a></li>
+ </ol>
+ </div>
+</div>
+
+<p>A menu resource defines an application menu (Options Menu, Context Menu, or Sub Menu) that
+can be inflated with {@link android.view.MenuInflater}.</p>
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/menu/<em>filename</em>.xml</code><br/>
+The filename will be used as the resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to a {@link android.view.Menu} (or subclass) resource.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.menu.<em>filename</em></code><br/>
+In XML: <code>@[<em>package</em>:]menu.<em>filename</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#menu-element">menu</a> xmlns:android="http://schemas.android.com/apk/res/android">
+ <<a href="#item-element">item</a> android:id="<em>resource ID</em>"
+ android:menuCategory=["container" | "system" | "secondary" | "alternative"]
+ android:orderInCategory="<em>integer</em>"
+ android:title="<em>string</em>"
+ android:titleCondensed="<em>string</em>"
+ android:icon="<em>drawable resource</em>"
+ android:alphabeticShortcut="<em>string</em>"
+ android:numericShortcut="<em>string</em>"
+ android:checkable=["true" | "false"]
+ android:visible=["visible" | "invisible" | "gone"]
+ android:enabled=["enabled" | "disabled"] />
+ <<a href="#group-element">group</a> android:id="<em>resource ID</em>"
+ android:menuCategory=["container" | "system" | "secondary" | "alternative"]
+ android:orderInCategory="<em>integer</em>"
+ android:checkableBehavior=["none" | "all" | "single"]
+ android:visible=["visible" | "invisible" | "gone"]
+ android:enabled=["enabled" | "disabled"] >
+ <<a href="#item-element">item</a> />
+ </group>
+ <<a href="#item-element">item</a> >
+ <<a href="#menu-element">menu</a>>
+ <<a href="#item-element">item</a> />
+ </menu>
+ </item>
+</menu>
+</pre>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+<dl class="tag-list">
+
+ <dt id="menu-element"><code><menu></code></dt>
+ <dd><strong>Required.</strong> This must be the root node. Contains <code><item></code> and/or
+ <code><group></code> elements.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>xmlns:android</code></dt>
+ <dd><em>String</em>. <strong>Required.</strong> Defines the XML namespace, which must be
+ <code>"http://schemas.android.com/apk/res/android"</code>.
+ </dl>
+ </dd>
+ <dt id="group-element"><code><group></code></dt>
+ <dd>A menu group (to create a collection of items that share traits, such as whether they are
+visible, enabled, or checkable). Contains one or more <code><item></code> elements. Must be a
+child of a <code><menu></code> element.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:id</code></dt>
+ <dd><em>Resource name</em>. A unique resource name. The value takes the form:
+<code>"@+id/<em>name</em>"</code>.</dd>
+ <dt><code>android:menuCategory</code></dt>
+ <dd><em>Keyword</em>. Value corresponding to {@link android.view.Menu} {@code CATEGORY_*}
+ constants, which define the group's priority. Valid values:
+ <table>
+ <tr><th>Value</th><th>Description</th></tr>
+ <tr><td><code>container</code></td><td>For groups that are part of a
+container.</td></tr>
+ <tr><td><code>system</code></td><td>For groups that are provided by the
+system.</td></tr>
+ <tr><td><code>secondary</code></td><td>For groups that are user-supplied secondary
+(infrequently used) options.</td></tr>
+ <tr><td><code>alternative</code></td><td>For groups that are alternative actions
+on the data that is currently displayed.</td></tr>
+ </table>
+ </dd>
+ <dt><code>android:orderInCategory</code></dt>
+ <dd><em>Integer</em>. The default order of the items within the category.</dd>
+ <dt><code>android:checkableBehavior</code></dt>
+ <dd><em>Keyword</em>. The type of checkable behavior for the group. Valid values:
+ <table>
+ <tr><th>Value</th><th>Description</th></tr>
+ <tr><td><code>none</code></td><td>Not checkable</td></tr>
+ <tr><td><code>all</code></td><td>All items can be checked (use checkboxes)</td></tr>
+ <tr><td><code>single</code></td><td>Only one item can be checked (use radio buttons)</td></tr>
+ </table>
+ </dd>
+ <dt><code>android:visible</code></dt>
+ <dd><em>Boolean</em>. "true" if the group is visible.</dd>
+ <dt><code>android:enabled</code></dt>
+ <dd><em>Boolean</em>. "true" if the group is enabled.</dd>
+ </dl>
+ </dd>
+ <dt id="item-element"><code><item></code></dt>
+ <dd>A menu item. May contain a <code><menu></code> element (for a Sub
+ Menu). Must be a child of a <code><menu></code> or <code><group></code> element.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:id</code></dt>
+ <dd><em>Resource name</em>. A unique resource name. The value takes the form:
+<code>"@+id/<em>name</em>"</code>.</dd>
+ <dt><code>android:menuCategory</code></dt>
+ <dd><em>Keyword</em>. Value corresponding to {@link android.view.Menu} {@code CATEGORY_*}
+ constants, which define the item's priority. Valid values:
+ <table>
+ <tr><th>Value</th><th>Description</th></tr>
+ <tr><td><code>container</code></td><td>For items that are part of a
+container.</td></tr>
+ <tr><td><code>system</code></td><td>For items that are provided by the
+system.</td></tr>
+ <tr><td><code>secondary</code></td><td>For items that are user-supplied secondary
+(infrequently used) options.</td></tr>
+ <tr><td><code>alternative</code></td><td>For items that are alternative actions
+on the data that is currently displayed.</td></tr>
+ </table>
+ </dd>
+ <dt><code>android:orderInCategory</code></dt>
+ <dd><em>Integer</em>. The order of "importance" of the item, within a group.</dd>
+ <dt><code>android:title</code></dt>
+ <dd><em>String</em>. The menu title.</dd>
+ <dt><code>android:titleCondensed</code></dt>
+ <dd><em>String</em>. A condensed title, for situations in which the normal title is
+too long.</dd>
+ <dt><code>android:icon</code></dt>
+ <dd><em>Drawable resource</em>. An image to be used as the menu item icon.</dd>
+ <dt><code>android:alphabeticShortcut</code></dt>
+ <dd><em>Char</em>. A character for the alphabetic shortcut key.</dd>
+ <dt><code>android:numericShortcut</code></dt>
+ <dd><em>Integer</em>. A number for the numeric shortcut key.</dd>
+ <dt><code>android:checkable</code></dt>
+ <dd><em>Boolean</em>. "true" if the item is checkable.</dd>
+ <dt><code>android:checked</code></dt>
+ <dd><em>Boolean</em>. "true" if the item is checked by default.</dd>
+ <dt><code>android:visible</code></dt>
+ <dd><em>Boolean</em>. "true" if the item is visible by default.</dd>
+ <dt><code>android:enabled</code></dt>
+ <dd><em>Boolean</em>. "true" if the item is enabled by default.</dd>
+ </dl>
+ </dd>
+</dl>
+
+</dd>
+
+<dt>example:</dt>
+<dd>XML file saved at <code>res/menu/example_menu.xml</code>:
+<pre>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/example_item"
+ android:title="Example Item"
+ android:icon="@drawable/example_item_icon" />
+ <group android:id="@+id/example_group">
+ <item android:id="@+id/group_item1"
+ android:title="Group Item 1"
+ android:icon="@drawable/example_item1_icon" />
+ <item android:id="@+id/group_item2"
+ android:title="Group Item 2"
+ android:icon="@drawable/example_item2_icon" />
+ </group>
+ <item android:id="@+id/submenu"
+ android:title="Sub Menu" >
+ <menu>
+ <item android:id="@+id/submenu_item"
+ android:title="Sub Menu Item" />
+ </menu>
+ </item>
+</menu>
+</pre>
+ <p>This application code will inflate the menu from the {@link
+android.app.Activity#onCreateOptionsMenu(Menu)} callback:</p>
+<pre>
+public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.example_menu, menu);
+ return true;
+}
+</pre>
+</dd> <!-- end example -->
+
+
+</dl>
\ No newline at end of file
diff --git a/docs/html/guide/topics/resources/more-resources.jd b/docs/html/guide/topics/resources/more-resources.jd
new file mode 100644
index 0000000..0e2b30be
--- /dev/null
+++ b/docs/html/guide/topics/resources/more-resources.jd
@@ -0,0 +1,684 @@
+page.title=More Resource Types
+parent.title=Resource Types
+parent.link=available-resources.html
+@jd:body
+
+<p>This page defines more types of resources you can externalize, including:</p>
+
+<dl>
+ <dt><a href="#Bool">Bool</a></dt>
+ <dd>XML resource that carries a boolean value.</dd>
+ <dt><a href="#Color">Color</a></dt>
+ <dd>XML resource that carries a color value (a hexadecimal color).</dd>
+ <dt><a href="#Dimension">Dimension</a></dt>
+ <dd>XML resource that carries a dimension value (with a unit of measure).</dd>
+ <dt><a href="#Integer">Integer</a></dt>
+ <dd>XML resource that carries an integer value.</dd>
+ <dt><a href="#IntegerArray">Integer Array</a></dt>
+ <dd>XML resource that provides an array of integers.</dd>
+ <dt><a href="#TypedArray">Typed Array</a></dt>
+ <dd>XML resource that provides a {@link android.content.res.TypedArray} (which you can use
+for an array of drawables).</dd>
+</dl>
+
+
+
+
+<h2 id="Bool">Bool</h2>
+
+<p>A boolean value defined in XML.</p>
+
+<p class="note"><strong>Note:</strong> A bool is a simple resource that is referenced
+using the value provided in the {@code name} attribute (not the name of the XML file). As
+such, you can combine bool resources with other simple resources in the one XML file,
+under one {@code <resources>} element.</p>
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/values/<em>filename</em>.xml</code><br/>
+The filename is arbitrary. The {@code <bool>} element's {@code name} will be used as the resource
+ID.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.bool.<em>bool_name</em></code><br/>
+In XML: <code>@[<em>package</em>:]bool/<em>bool_name</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#bool-resources-element">resources</a>>
+ <<a href="#bool-element">bool</a>
+ name="<em>bool_name</em>"
+ >[true | false]</bool>
+</resources>
+</pre>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+<dl class="tag-list">
+
+ <dt id="bool-resources-element"><code><resources></code></dt>
+ <dd><strong>Required.</strong> This must be the root node.
+ <p>No attributes.</p>
+ </dd>
+ <dt id="bool-element"><code><bool></code></dt>
+ <dd>A boolean value: {@code true} or {@code false}.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>name</code></dt>
+ <dd><em>String</em>. A name for the bool value. This will be used as the resource ID.</dd>
+ </dl>
+ </dd>
+
+</dl>
+</dd> <!-- end elements and attributes -->
+
+<dt>example:</dt>
+<dd>XML file saved at <code>res/values-small/bools.xml</code>:
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <bool name="screen_small">true</bool>
+ <bool name="adjust_view_bounds">true</bool>
+</resources>
+</pre>
+
+ <p>This application code retrieves the boolean:</p>
+<pre>
+Resources res = {@link android.content.Context#getResources()};
+boolean screenIsSmall = res.{@link android.content.res.Resources#getBoolean(int) getBoolean}(R.bool.screen_small);
+</pre>
+ <p>This layout XML uses the boolean for an attribute:</p>
+<pre>
+<ImageView
+ android:layout_height="fill_parent"
+ android:layout_width="fill_parent"
+ android:src="@drawable/logo"
+ android:adjustViewBounds="@bool/adjust_view_bounds" />
+</pre>
+</dd> <!-- end example -->
+
+</dl>
+
+
+
+
+<h2 id="Color">Color</h2>
+
+<p>A color value defined in XML.
+The color is specified with an RGB value and alpha channel. A color resource can be used
+any place that expects a hexadecimal color value.</p>
+
+<p>The value always begins with a pound (#) character and then followed by the
+Alpha-Red-Green-Blue information in one of the following formats:</p>
+<ul>
+ <li>#<em>RGB</em></li>
+ <li>#<em>ARGB</em></li>
+ <li>#<em>RRGGBB</em></li>
+ <li>#<em>AARRGGBB</em></li>
+</ul>
+
+<p class="note"><strong>Note:</strong> A color is a simple resource that is referenced
+using the value provided in the {@code name} attribute (not the name of the XML file). As
+such, you can combine color resources with other simple resources in the one XML file,
+under one {@code <resources>} element.</p>
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/values/colors.xml</code><br/>
+The filename is arbitrary. The {@code <color>} element's {@code name} will be used as the
+resource ID.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.color.<em>color_name</em></code><br/>
+In XML: <code>@[<em>package</em>:]color/<em>color_name</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#color-resources-element">resources</a>>
+ <<a href="#color-element">color</a>
+ name="<em>color_name</em>"
+ ><em>hex_color</em></color>
+</resources>
+</pre>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+<dl class="tag-list">
+
+ <dt id="color-resources-element"><code><resources></code></dt>
+ <dd><strong>Required.</strong> This must be the root node.
+ <p>No attributes.</p>
+ </dd>
+ <dt id="color-element"><code><color></code></dt>
+ <dd>A color expressed in hexadecimal, as described above.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>name</code></dt>
+ <dd><em>String</em>. A name for the color. This will be used as the resource ID.
+ </dd>
+ </dl>
+ </dd>
+
+</dl>
+</dd> <!-- end elements and attributes -->
+
+<dt>example:</dt>
+<dd>XML file saved at <code>res/values/colors.xml</code>:
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <color name="opaque_red">#f00</color>
+ <color name="translucent_red">#80ff0000</color>
+</resources>
+</pre>
+
+ <p>This application code retrieves the color resource:</p>
+<pre>
+Resources res = {@link android.content.Context#getResources()};
+int color = res.{@link android.content.res.Resources#getColor(int) getColor}(R.color.opaque_red);
+</pre>
+ <p>This layout XML applies the color to an attribute:</p>
+<pre>
+<TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textColor="@color/translucent_red"
+ android:text="Hello"/>
+</pre>
+</dd> <!-- end example -->
+
+</dl>
+
+
+
+
+
+<h2 id="Dimension">Dimension</h2>
+
+<p>A dimension value defined in XML. A dimension
+is specified with a number followed by a unit of measure.
+For example: 10px, 2in, 5sp. The following units of measure are supported by Android:</p>
+<dl>
+ <dt>{@code dp}</dt>
+ <dd>Density-independent Pixels - an abstract unit that is based on the physical density of the screen.
+ These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of
+ dp-to-pixel will change with the screen density, but not necessarily in direct proportion. The
+ compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".</dd>
+ <dt>{@code sp}</dt>
+ <dd>Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font
+ size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted
+ for both the screen density and the user's preference.</dd>
+ <dt>{@code pt}</dt>
+ <dd>Points - 1/72 of an inch based on the physical size of the screen.</dd>
+ <dt>{@code px}</dt>
+ <dd>Pixels - corresponds to actual pixels on the screen. This unit of measure is not recommended because
+ the actual representation can vary across devices; each devices may have a different number of pixels
+ per inch and may have more or fewer total pixels available on the screen.</dd>
+ <dt>{@code mm}</dt>
+ <dd>Millimeters - based on the physical size of the screen.</dd>
+ <dt>{@code in}</dt>
+ <dd>Inches - based on the physical size of the screen.</dd>
+</dl>
+
+<p class="note"><strong>Note:</strong> A dimension is a simple resource that is referenced
+using the value provided in the {@code name} attribute (not the name of the XML file). As
+such, you can combine dimension resources with other simple resources in the one XML file,
+under one {@code <resources>} element.</p>
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/values/<em>filename</em>.xml</code><br/>
+The filename is arbitrary. The {@code <dimen>} element's {@code name} will be used as the
+resource ID.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.dimen.<em>dimension_name</em></code><br/>
+In XML: <code>@[<em>package</em>:]dimen/<em>dimension_name</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#dimen-resources-element">resources</a>>
+ <<a href="#dimen-element">dimen</a>
+ name="<em>dimension_name</em>"
+ ><em>dimension</em></dimen>
+</resources>
+</pre>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+<dl class="tag-list">
+
+ <dt id="dimen-resources-element"><code><resources></code></dt>
+ <dd><strong>Required.</strong> This must be the root node.
+ <p>No attributes.</p>
+ </dd>
+ <dt id="dimen-element"><code><dimen></code></dt>
+ <dd>A dimension, represented by a float, followed by a unit of measurement (dp, sp, pt, px, mm, in),
+ as described above.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>name</code></dt>
+ <dd><em>String</em>. A name for the dimension. This will be used as the resource ID.
+ </dd>
+ </dl>
+ </dd>
+
+</dl>
+</dd> <!-- end elements and attributes -->
+
+<dt>example:</dt>
+<dd>XML file saved at <code>res/values/dimens.xml</code>:
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <dimen name="textview_height">25dp</dimen>
+ <dimen name="textview_width">150dp</dimen>
+ <dimen name="ball_radius">30dp</dimen>
+ <dimen name="font_size">16sp</dimen>
+</resources>
+</pre>
+
+ <p>This application code retrieves a dimension:</p>
+<pre>
+Resources res = {@link android.content.Context#getResources()};
+float fontSize = res.{@link android.content.res.Resources#getDimension(int) getDimension}(R.dimen.font_size);
+</pre>
+ <p>This layout XML applies dimensions to attributes:</p>
+<pre>
+<TextView
+ android:layout_height="@dimen/textview_height"
+ android:layout_width="@dimen/textview_width"
+ android:textSize="@dimen/sixteen_sp"/>
+</pre>
+ </dl>
+</dd> <!-- end example -->
+
+</dl>
+
+
+
+
+
+
+<h2 id="Integer">Integer</h2>
+
+<p>An integer defined in XML.</p>
+
+<p class="note"><strong>Note:</strong> An integer is a simple resource that is referenced
+using the value provided in the {@code name} attribute (not the name of the XML file). As
+such, you can combine integer resources with other simple resources in the one XML file,
+under one {@code <resources>} element.</p>
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/values/<em>filename.xml</em></code><br/>
+The filename is arbitrary. The {@code <integer>} element's {@code name} will be used as the
+resource ID.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.integer.<em>integer_name</em></code><br/>
+In XML: <code>@[<em>package</em>:]integer/<em>integer_name</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#integer-resources-element">resources</a>>
+ <<a href="#integer-element">integer</a>
+ name="<em>integer_name</em>"
+ ><em>integer</em></dimen>
+</resources>
+</pre>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+<dl class="tag-list">
+
+ <dt id="integer-resources-element"><code><resources></code></dt>
+ <dd><strong>Required.</strong> This must be the root node.
+ <p>No attributes.</p>
+ </dd>
+ <dt id="integer-element"><code><integer></code></dt>
+ <dd>An integer.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>name</code></dt>
+ <dd><em>String</em>. A name for the integer. This will be used as the resource ID.
+ </dd>
+ </dl>
+ </dd>
+
+</dl>
+</dd> <!-- end elements and attributes -->
+
+<dt>example:</dt>
+<dd>
+ <p>XML file saved at <code>res/values/integers.xml</code>:</p>
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <integer name="max_speed">75</dimen>
+ <integer name="min_speed">5</dimen>
+</resources>
+</pre>
+ <p>This application code retrieves an integer:</p>
+<pre>
+Resources res = {@link android.content.Context#getResources()};
+int maxSpeed = res.{@link android.content.res.Resources#getInteger(int) getInteger}(R.integer.max_speed);
+</pre>
+</dd> <!-- end example -->
+
+
+</dl>
+
+
+
+
+
+<h2 id="IntegerArray">Integer Array</h2>
+
+<p>An array of integers defined in XML.</p>
+
+<p class="note"><strong>Note:</strong> An integer array is a simple resource that is referenced
+using the value provided in the {@code name} attribute (not the name of the XML file). As
+such, you can combine integer array resources with other simple resources in the one XML file,
+under one {@code <resources>} element.</p>
+
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/values/<em>filename</em>.xml</code><br/>
+The filename is arbitrary. The {@code <integer-array>} element's {@code name} will be used as the
+resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to an array of integers.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.array.<em>string_array_name</em></code><br/>
+In XML: <code>@[<em>package</em>:]array.<em>integer_array_name</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#integer-array-resources-element">resources</a>>
+ <<a href="#integer-array-element">integer-array</a>
+ name="<em>integer_array_name</em>">
+ <<a href="#integer-array-item-element">item</a>
+ ><em>integer</em></item>
+ </integer-array>
+</resources>
+</pre>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+<dl class="tag-list">
+ <dt id="integer-array-resources-element"><code><resources></code></dt>
+ <dd><strong>Required.</strong> This must be the root node.
+ <p>No attributes.</p>
+ </dd>
+ <dt id="integer-array-element"><code><string-array></code></dt>
+ <dd>Defines an array of integers. Contains one or more child {@code <item>} elements.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:name</code></dt>
+ <dd><em>String</em>. A name for the array. This name will be used as the resource
+ID to reference the array.</dd>
+ </dl>
+ </dd>
+ <dt id="integer-array-item-element"><code><item></code></dt>
+ <dd>An integer. The value can be a referenced to another
+integer resource. Must be a child of a {@code <integer-array>} element.
+ <p>No attributes.</p>
+ </dd>
+</dl>
+</dd> <!-- end elements -->
+
+<dt>example:</dt>
+<dd>XML file saved at <code>res/values/integers.xml</code>:
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <integer-array name="bits">
+ <item>4</item>
+ <item>8</item>
+ <item>16</item>
+ <item>32</item>
+ </integer-array>
+</resources>
+</pre>
+
+ <p>This application code retrieves the integer array:</p>
+<pre>
+Resources res = {@link android.content.Context#getResources()};
+int[] bits = res.{@link android.content.res.Resources#getIntArray(int) getIntArray}(R.array.bits);
+</pre>
+</dd> <!-- end example -->
+
+</dl>
+
+
+
+
+
+<h2 id="TypedArray">Typed Array</h2>
+
+<p>A {@link android.content.res.TypedArray} defined in XML. You can use
+this to create an array of other resources, such as drawables. Note that the array
+is not required to be homogeneous, so you can create an array of mixed resource types, but
+you must be aware of what and where the data types are in the array so that you can properly obtain
+each item with the {@link android.content.res.TypedArray}'s {@code get...()} methods.</p>
+
+<p class="note"><strong>Note:</strong> A typed array is a simple resource that is referenced
+using the value provided in the {@code name} attribute (not the name of the XML file). As
+such, you can combine typed array resources with other simple resources in the one XML file,
+under one {@code <resources>} element.</p>
+
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/values/<em>filename</em>.xml</code><br/>
+The filename is arbitrary. The {@code <array>} element's {@code name} will be used as the
+resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to a {@link android.content.res.TypedArray}.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.array.<em>array_name</em></code><br/>
+In XML: <code>@[<em>package</em>:]array.<em>array_name</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#array-resources-element">resources</a>>
+ <<a href="#array-element">array</a>
+ name="<em>integer_array_name</em>">
+ <<a href="#array-item-element">item</a>><em>resource</em></item>
+ </array>
+</resources>
+</pre>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+<dl class="tag-list">
+ <dt id="array-resources-element"><code><resources></code></dt>
+ <dd><strong>Required.</strong> This must be the root node.
+ <p>No attributes.</p>
+ </dd>
+ <dt id="array-element"><code><array></code></dt>
+ <dd>Defines an array. Contains one or more child {@code <item>} elements.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>android:name</code></dt>
+ <dd><em>String</em>. A name for the array. This name will be used as the resource
+ID to reference the array.</dd>
+ </dl>
+ </dd>
+ <dt id="array-item-element"><code><item></code></dt>
+ <dd>A generic resource. The value can be a reference to a resource or a simple data type.
+Must be a child of an {@code <array>} element.
+ <p>No attributes.</p>
+ </dd>
+</dl>
+</dd> <!-- end elements -->
+
+<dt>example:</dt>
+<dd>XML file saved at <code>res/values/arrays.xml</code>:
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <array name="icons">
+ <item>@drawable/home</item>
+ <item>@drawable/settings</item>
+ <item>@drawable/logout</item>
+ </array>
+ <array name="colors">
+ <item>#FFFF0000</item>
+ <item>#FF00FF00</item>
+ <item>#FF0000FF</item>
+ </array>
+</resources>
+</pre>
+
+ <p>This application code retrieves each array and then obtains the first entry in each array:</p>
+<pre>
+Resources res = {@link android.content.Context#getResources()};
+TypedArray icons = res.{@link android.content.res.Resources#obtainTypedArray(int) obtainTypedArray}(R.array.icons);
+Drawable drawable = icons.{@link android.content.res.TypedArray#getDrawable(int) getDrawable}(0);
+
+TypedArray colors = res.{@link android.content.res.Resources#obtainTypedArray(int) obtainTypedArray}(R.array.icons);
+int color = colors.{@link android.content.res.TypedArray#getColor(int,int) getColor}(0,0);
+</pre>
+</dd> <!-- end example -->
+
+</dl>
+
+
+
+
+
+
+
+
+
+
+<!-- TODO
+
+
+<h2>Styleable Attribute</h2>
+
+
+<dl class="xml">
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+</pre>
+</dd>
+
+<dt>file location:</dt>
+<dd><code>res/</code></dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to a {@link android.view.Menu} (or subclass) resource.</dd>
+
+<dt>resource reference:</dt>
+<dd>Java: <code>R.</code><br/>
+ XML:
+</dd>
+
+<dt>elements and attributes:</dt>
+<dd>
+<dl class="attr">
+
+ <dt><code></code></dt>
+ <dd></dd>
+ <dt><code></code></dt>
+ <dd>Valid attributes:
+ <dl>
+ <dt><code></code></dt>
+ <dd>
+ </dd>
+ <dt><code></code></dt>
+ <dd>
+ </dd>
+ </dl>
+ </dd>
+
+</dl>
+</dd>
+
+<dt>example:</dt>
+<dd>
+ <dl>
+
+ <dt>XML file saved at <code>res/</code>:</dt>
+ <dd>
+<pre>
+
+</pre>
+ </dd>
+
+ <dt>Java code :</dt>
+ <dd>
+<pre>
+
+</pre>
+ </dd>
+
+ </dl>
+</dd>
+
+
+<dt>see also:</dt>
+<dd>
+<ul>
+ <li></li>
+</ul>
+</dd>
+
+</dl>
+
+
+
+
+
+
+-->
+
+
+
+
diff --git a/docs/html/guide/topics/resources/providing-resources.jd b/docs/html/guide/topics/resources/providing-resources.jd
new file mode 100644
index 0000000..b495eb8
--- /dev/null
+++ b/docs/html/guide/topics/resources/providing-resources.jd
@@ -0,0 +1,723 @@
+page.title=Providing Resources
+parent.title=Application Resources
+parent.link=index.html
+@jd:body
+
+<div id="qv-wrapper">
+<div id="qv">
+ <h2>Quickview</h2>
+ <ul>
+ <li>Different types of resources belong in different sub-directories of {@code res/}</li>
+ <li>Alternative resources provide configuration-specific resource files</li>
+ </ul>
+ <h2>In this document</h2>
+ <ol>
+ <li><a href="#AlternativeResources">Providing Alternative Resources</a>
+ <ol>
+ <li><a href="#AliasResources">Creating alias resources</a></li>
+ </ol>
+ </li>
+ <li><a href="#BestMatch">How Android Finds the Best-matching Resource</a></li>
+ </ol>
+
+ <h2>See also</h2>
+ <ol>
+ <li><a href="accessing-resources.html">Accessing Resources</a></li>
+ <li><a href="available-resources.html">Resource Types</a></li>
+ </ol>
+</div>
+</div>
+
+<p>There are several types of resource files you can
+include in your application and each type belongs in a specific sub-directory of your project's
+{@code res/} directory. Absolutely no files should be saved directly inside {@code res/}.</p>
+
+<p>For example, here's the file hierarchy for a simple project:</p>
+
+<pre class="no-pretty-print">
+MyProject/
+ src/ <span style="color:black">
+ MyActivity.java </span>
+ res/
+ drawable/ <span style="color:black">
+ icon.png </span>
+ layout/ <span style="color:black">
+ main_layout.xml </span>
+ values/ <span style="color:black">
+ strings.xml </span>
+</pre>
+
+<p>This project includes an image resource, a layout resource, and string resource file.</p>
+
+<p>Table 1 lists the different {@code res/} sub-directories supported
+and describes the types of resource files that belong in each one.</p>
+
+<p class="table-caption" id="table1"><strong>Table 1.</strong> Resource directories. Each directory
+belongs inside the project {@code res/} directory.</p>
+
+<table>
+ <tr>
+ <th scope="col">Directory</th>
+ <th scope="col">Resource Types</th>
+ </tr>
+
+ <tr>
+ <td><code>anim/</code></td>
+ <td>XML files that define tween animations. See <a
+href="animation-resource.html">Animation Resources</a>.</td>
+ </tr>
+
+ <tr>
+ <td><code>color/</code></td>
+ <td>XML files that define a state list of colors. See <a href="color-list-resource.html">Color
+State List Resources</a></td>
+ </tr>
+
+ <tr>
+ <td><code>drawable/</code></td>
+ <td><p>Bitmap files ({@code .png}, {@code .9.png}, {@code .jpg}, {@code .gif}) or XML files that
+are compiled into the following Drawable resource subtypes:</p>
+ <ul>
+ <li>Bitmap files</li>
+ <li>Nine-Patches (re-sizable bitmaps)</li>
+ <li>State lists</li>
+ <li>Color drawables</li>
+ <li>Shapes</li>
+ <li>Animation drawables</li>
+ </ul>
+ <p>See <a href="drawable-resource.html">Drawable Resources</a>.</p>
+ </td>
+ </tr>
+
+ <tr>
+ <td><code>layout/</code></td>
+ <td>XML files that define a user interface layout.
+ See <a href="layout-resource.html">Layout Resource</a>.</td>
+ </tr>
+
+ <tr>
+ <td><code>menu/</code></td>
+ <td>XML files that define application menus, such as an Options Menu, Context Menu, or Sub
+Menu. See <a href="menu-resource.html">Menu Resource</a>.</td>
+ </tr>
+
+ <tr>
+ <td><code>raw/</code></td>
+ <td><p>Arbitrary files to save in their raw form. Files in here are not compressed by the
+system. To open these resources with a raw {@link java.io.InputStream}, call {@link
+android.content.res.Resources#openRawResource(int)
+Resources.openRawResource()} with the resource ID, which is {@code R.raw.<em>filename</em>}.</p>
+ <p>However, if you require direct access to original file names and file hierarchy, instead of
+using a resource ID to access your files, you might consider saving some resources in the {@code
+assets/} directory, instead of {@code res/raw/}. You can query data in the {@code assets/} directory
+like an ordinary file system, search through the directory and read raw data using {@link
+android.content.res.AssetManager}.</p></td>
+ </tr>
+
+ <tr>
+ <td><code>values/</code></td>
+ <td><p>XML files that contain simple values, such as strings, integers, and colors.</p>
+ <p>Unlike the other {@code res/} subdirectories, this one
+ can hold files that contain descriptions of more than one resource, rather than
+just one resource for the file. The XML element types of an XML file in {@code values/} control
+how these resources are defined in the {@code R} class. For example, a {@code <string>}
+element will create an
+{@code R.string} resource, and a {@code <color>} element will create an {@code R.color}
+resource.</p>
+ <p>While the name of a file in this directory is arbitrary and not related to the name given
+to a resource produced, you might want to separate different types of resources into different
+files for easier maintenance. Here are some filename conventions for some of the different types
+of resources you can save here:</p>
+ <ul>
+ <li>arrays.xml to define resource arrays (<a
+href="more-resources.html#TypedArray">typed arrays</a>).</li>
+ <li>colors.xml to define <a
+href="more-resources.html#Color">color values</a></li>
+ <li>dimens.xml to define <a
+href="more-resources.html#Dimension">dimension values</a>.</li>
+ <li>strings.xml to define <a href="string-resource.html">string
+values</a>.</li>
+ <li>styles.xml to define <a href="style-resource.html">styles</a>.</li>
+ </ul>
+ <p>See <a href="string-resource.html">String Resources</a>,
+ <a href="style-resource.html">Style Resource</a>, and
+ <a href="more-resources.html">More Resource Types</a>.</p>
+ </td>
+ </tr>
+
+ <tr>
+ <td><code>xml/</code></td>
+ <td>Arbitrary XML files that are compiled and can be read at runtime by calling {@link
+android.content.res.Resources#getXml(int) Resources.getXML()}. Various XML configuration files
+must also be saved here, such as a <a
+href="{@docRoot}guide/topics/search/searchable-config.html">searchable configuration</a>.
+<!-- or preferences configuration. --></td>
+ </tr>
+</table>
+
+<p>For more information about certain types of resources, see the <a
+href="available-resources.html">Resource Types</a> documentation.</p>
+
+
+
+
+
+
+<h2 id="AlternativeResources">Providing Alternative Resources</h2>
+
+
+<div class="figure" style="width:441px">
+<img src="{@docRoot}images/resources/resource_devices_diagram2.png" height="137" alt="" />
+<p class="img-caption">
+<strong>Figure 1.</strong> Two device configurations, one using alternative resources.</p>
+</div>
+
+<p>Almost every application should provide alternative resources to support specific device
+configurations. For instance, you should include different drawable resources for different
+screen densities and different string resources for different languages. At runtime, Android
+will automatically detect the current device configuration and then load the appropriate
+resources.</p>
+
+<p>For each set of resources for which you want to provide configuration-specific alternatives:</p>
+<ol>
+ <li>Create a new directory in {@code res/} named in the form {@code
+<em><resources_name></em>-<em><config_qualifier></em>}.
+ <ul>
+ <li><em>{@code <resources_name>}</em> is the directory name of the corresponding default
+resources.</li>
+ <li><em>{@code <config_qualifier>}</em> is a name that specifies a configuration
+for which these resources are to be used.</li>
+ </ul>
+ <p>You can append more than one <em>{@code <config_qualifier>}</em>. Separate each
+one with a dash.</p>
+ </li>
+ <li>Save your alternative resources in this directory, named exactly the same as the default
+resource files.</li>
+</ol>
+
+<p>For example, here are some default and alternative resources:</p>
+
+<pre class="no-pretty-print">
+res/
+ drawable/ <span style="color:black">
+ icon.png
+ background.png </span>
+ drawable-hdpi/ <span style="color:black">
+ icon.png
+ background.png </span>
+</pre>
+
+<p>The {@code hdpi} qualifier indicates that the resources are for devices with a high-density
+screen. While the images in each directory are different, the filenames are
+identical. This way, the resource ID that you use to reference the {@code icon.png} image is
+always the same. When you request the {@code icon} drawable, Android will select the
+version of that drawable that best matches the current device configuration.</p>
+
+<p>Android supports several configuration qualifiers and you can
+add multiple qualifiers to one directory name in order to further specify the configuration, by
+separating the qualifiers with dashes. Table 2 lists the valid configuration qualifiers, in order
+of precedence—they must be specified in the directory name in the order that they are listed
+in the table.</p>
+
+
+<p class="table-caption" id="table2"><strong>Table 2.</strong> Alternative resource qualifier
+names.</p>
+<table border="1">
+ <tr>
+ <th>Qualifier</th>
+ <th>Values</th>
+ <th>Description</th>
+ </tr>
+ <tr>
+ <td>MCC and MNC</td>
+ <td>Examples:<br/>
+ <code>mcc310</code><br/>
+ <code><nobr>mcc310-mnc004</nobr></code><br/>
+ <code>mcc208-mnc00</code><br/>
+ etc.
+ </td>
+ <td>
+ <p>Specifies resources based on the mobile country code (MCC), optionally followed by mobile
+network code (MNC)
+ from the SIM in the device. For example, <code>mcc310</code> is U.S. on any carrier,
+ <code>mcc310-mnc004</code> is U.S. on Verizon, and <code>mcc208-mnc00</code> is France on
+ Orange.</p>
+ <p>If the device uses a radio connection (GSM phone), the MCC will come
+ from the SIM, and the MNC will come from the network to which the
+ device is attached.</p>
+ <p>You might sometimes use the MCC alone, for example to include country-specific legal
+resources in your application, but if you only need to specify based on language, then use the
+language and region qualifier below. If you decide to use the MCC and MNC qualifier, you
+should do so with great care and completely test that it works as expected.</p></td>
+ </tr>
+ <tr>
+ <td>Language and region</td>
+ <td>Examples:<br/>
+ <code>en</code><br/>
+ <code>fr</code><br/>
+ <code>en-rUS</code><br/>
+ <code>fr-rFR</code><br/>
+ <code>fr-rCA</code><br/>
+ etc.
+ </td>
+ <td><p>This is defined by a two-letter <a
+href="http://www.loc.gov/standards/iso639-2/php/code_list.php">ISO
+ 639-1</a> language code, optionally followed by a two letter
+ <a
+href="http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html">ISO
+ 3166-1-alpha-2</a> region code (preceded by lowercase "r").
+ </p><p>
+ The codes are <em>not</em> case-sensitive; the {@code r} prefix is used to
+ distinguish the region portion.
+ You cannot specify a region alone.</p>
+ <p>This can change during the life
+of your application if the user changes their language in the system settings. See <a
+href="runtime-changes.html">Handling Runtime Changes</a> for information about
+how this can affect your application during runtime.</p>
+ <p>See <a href="localization.html">Localization</a> for a complete guide to localizing
+your application for other langauges.</p>
+ </td>
+ </tr>
+ <tr>
+ <td>Screen size</td>
+ <td>
+ <code>small</code><br/>
+ <code>normal</code><br/>
+ <code>large</code>
+ </td>
+ <td>
+ <ul>
+ <li> <b>Small screens</b> are based on the space available on a
+ QVGA low density screen. Considering a portrait HVGA display, this has
+ the same available width but less height -- it is 3:4 vs. HVGA's
+ 2:3 aspect ratio. Examples are QVGA low density and VGA high
+ density.</li>
+ <li> <b>Normal screens</b> are based on the traditional Android HVGA
+ medium density screen. A screen is considered to be normal if it is
+ at least this size (independent of density) and not larger. Examples
+ of such screens a WQVGA low density, HVGA medium density, WVGA
+ high density.</li>
+ <li> <b>Large screens</b> are based on the space available on a
+ VGA medium density screen. Such a screen has significantly more
+ available space in both width and height than an HVGA display.
+ Examples are VGA and WVGA medium density screens.</li>
+ </ul>
+ <p>See <a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
+Screens</a> for more information.</p>
+ </td>
+ </tr>
+ <tr>
+ <td>Wider/taller screens</td>
+ <td>
+ <code>long</code><br/>
+ <code>notlong</code>
+ </td>
+ <td>
+ <p>This is based purely on the aspect ratio of the screen (a "long" screen is wider):
+ <ul>
+ <li><strong>Long</strong>: WQVGA, WVGA, FWVGA</li>
+ <li><strong>Not long</strong>: QVGA, HVGA, and VGA</li>
+ </ul>
+ <p>This is not related to the screen orientation.</p>
+ </td>
+ </tr>
+ <tr>
+ <td>Screen orientation</td>
+ <td>
+ <code>port</code><br/>
+ <code>land</code> <!-- <br/>
+ <code>square</code> -->
+ </td>
+ <td>
+ <p>Portrait orientation ({@code port}) is vertical and landscape orientation
+({@code land}) is horizontal. <!-- Square mode is currently not used. --> </p>
+ <p>This can change during the life of your application if the user rotates the
+screen. See <a href="runtime-changes.html">Handling Runtime Changes</a> for information about
+how this affects your application during runtime.</p>
+ </td>
+ </tr>
+ <tr>
+ <td>Dock mode</td>
+ <td>
+ <code>car</code><br/>
+ <code>desk</code>
+ </td>
+ <td>
+ <p>These configurations can be initiated when the device is placed in a dock.</p>
+ <p><em>Added in API Level 8.</em></p>
+ <p>This can change during the life of your application if the user places the device in a
+dock. See <a href="runtime-changes.html">Handling Runtime Changes</a> for
+information about how this affects your application during runtime. Also see {@link
+android.app.UiModeManager}.</p>
+ </td>
+ </tr>
+ <tr>
+ <td>Night mode</td>
+ <td>
+ <code>night</code><br/>
+ <code>notnight</code>
+ </td>
+ <td>
+ <p>
+ These configurations can be initiated by the device light sensor (if available).</p>
+ <p><em>Added in API Level 8.</em></p>
+ <p>This can change during the life of your application if the device determines that the
+user environment is a "night" (dark) setting. See <a href="runtime-changes.html">Handling Runtime
+Changes</a> for information about how this affects your application during runtime. You can
+also explicitly set this mode using {@link android.app.UiModeManager}.</p>
+ </td>
+ </tr>
+ <tr>
+ <td>Screen pixel density (dpi)</td>
+ <td>
+ <code>ldpi</code><br/>
+ <code>mdpi</code><br/>
+ <code>hdpi</code><br/>
+ <code>nodpi</code>
+ </td>
+ <td>
+ <p>The medium
+ density of traditional HVGA screens (mdpi) is defined to be approximately
+ 160dpi; low density (ldpi) is 120, and high density (hdpi) is 240. There
+ is thus a 4:3 scaling factor between each density, so a 9x9 bitmap
+ in ldpi would be 12x12 in mdpi and 16x16 in hdpi. The special
+ <code>nodpi</code> density can be used with bitmap resources to prevent
+ them from being scaled at load time to match the device density.
+ </p><p>
+ When Android selects which resource files to use,
+ it handles screen density differently than the other qualifiers.
+ In step 1 of <a href="#BestMatch">How Android finds the best
+ matching directory</a> (below), screen density is always considered to
+ be a match. In step 4, if the qualifier being considered is screen
+ density, Android will select the best final match at that point,
+ without any need to move on to step 5.
+ </p>
+ <p>See <a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
+Screens</a> for more information.</p>
+ </td>
+ </tr>
+ <tr>
+ <td>Touchscreen type</td>
+ <td>
+ <code>notouch</code><br/>
+ <code>stylus</code><br/>
+ <code>finger</code>
+ </td>
+ <td><p>If the device has a resistive touch screen that's suited for use with a stylus,
+then it may use the {@code stylus} resources.</p>
+ </td>
+ </tr>
+ <tr>
+ <td>Keyboard availability</td>
+ <td>
+ <code>keysexposed</code><br/>
+ <code>keyshidden</code><br/>
+ <code>keyssoft</code>
+ </td>
+ <td>
+ <p>If your application has specific resources that should only be used with a soft keyboard,
+use the <code>keyssoft</code> value. If you do not provide <code>keyssoft</code> resources, but do
+provide <code>keysexposed</code> and <code>keyshidden</code>, and the device shows a soft keyboard,
+the system will use <code>keysexposed</code> resources.</p>
+ <p>This can change during the life of your application if the user opens a keyboard. See <a
+href="runtime-changes.html">Handling Runtime Changes</a> for information about how this affects your
+application during runtime.</p>
+ </td>
+ </tr>
+ <tr>
+ <td>Primary text input method</td>
+ <td>
+ <code>nokeys</code><br/>
+ <code>qwerty</code><br/>
+ <code>12key</code>
+ </td>
+ <td><p>If the device has no hardware keys for text input, then it may use the {@code
+nokeys} resources. Even if the device has a QWERTY keyboard but it is currently hidden, it may use
+the {@code qwerty} resources.</td>
+ </tr>
+ <tr>
+ <td>Navigation key availability</td>
+ <td>
+ <code>navexposed</code><br/>
+ <code>navhidden</code>
+ </td>
+ <td>
+ <p>
+ If the device's navigation keys are currently available to
+ the user, it may use the {@code navexposed} resources; if they are not
+ available (such as behind a closed lid), it may use the {@code navhidden} resources.</p>
+ <p>This can change during the life of your application if the user reveals the navigation
+keys. See <a href="runtime-changes.html">Handling Runtime Changes</a> for
+information about how this affects your application during runtime.</p>
+ </td>
+ </tr>
+ <tr>
+ <td>Primary non-touch navigation method</td>
+ <td>
+ <code>nonav</code><br/>
+ <code>dpad</code><br/>
+ <code>trackball</code><br/>
+ <code>wheel</code>
+ </td>
+ <td><p>If the device has no navigation facility other than using the touchscreen, then it
+may use the {@code nonav} resources.</p>
+ </td>
+ </tr>
+<!-- DEPRECATED
+ <tr>
+ <td>Screen dimensions</td>
+ <td>Examples:<br/>
+ <code>320x240</code><br/>
+ <code>640x480</code><br/>
+ etc.
+ </td>
+ <td>
+ <p>The larger dimension must be specified first. <strong>This configuration is deprecated
+and should not be used</strong>. Instead use "screen size," "wider/taller screens," and "screen
+orientation" described above.</p>
+ </td>
+ </tr>
+-->
+ <tr>
+ <td>API Level</td>
+ <td>Examples:<br/>
+ <code>v4</code><br/>
+ <code>v5</code><br/>
+ <code>v6</code><br/>
+ <code>v7</code><br/>
+ etc.</td>
+ <td>
+ <p>The API Level supported by the device, for example <code>v1</code> for API Level 1
+(Android 1.0) or <code>v5</code> for API Level 5 (Android 2.0). See the <a
+href="{@docRoot}guide/appendix/api-levels.html">Android API Levels</a> document for more information
+about these values.</p>
+ </td>
+ </tr>
+</table>
+
+<p>Here are some important rules about using resource qualifier names:</p>
+
+<ul>
+ <li>You can specify multiple qualifiers for a single set of resources, separated by dashes. For
+example, <code>drawable-en-rUS-land</code> applies to US-English devices in landscape
+orientation.</li>
+ <li>The qualifiers must be in the order listed in <a href="#table2">Table 2</a> above. For
+example:
+ <ul>
+ <li>Wrong: <code>drawable-hdpi-port/</code></li>
+ <li>Correct: <code>drawable-port-hdpi/</code></li>
+ </ul>
+ </li>
+ <li>Qualified directories cannot be nested. For example, you cannot have
+<code>res/drawable/drawable-en/</code>.</li>
+ <li>Values are case-insensitive. The resource compiler converts directory names
+ to lower case before processing to avoid problems on case-insensitive
+ file systems. Any capitalization in the names is only to benefit readability.</li>
+ <li>Only one value for each qualifier type is supported. For example, if you want to use
+the same drawable files for Spain and France, you <em>cannot</em> have a directory named
+<code>drawable-rES-rFR/</code>. Instead you need two resource directories, such as
+<code>drawable-rES/</code> and <code>drawable-rFR/</code>, which contain the appropriate files.
+However, you are not required to actually duplicate the same files in both locations (which
+could multiply the size of your package if the files are large). Instead, you can create a
+reference to one instance of the resources. See <a href="#AliasResources">Creating
+alias resources</a>, below.</li>
+</ul>
+
+
+
+<h3 id="AliasResources">Creating alias resources</h3>
+
+<p>When you have a resource that you'd like to use for more than one device
+configuration (but not for all configurations), you <em>don't</em> have to put the same resource in
+each of the alternative resource directories. Instead, you can (in some cases) create an alternative
+resource that acts as an alias for a resource saved in your default resource directory.</p>
+
+<p>For example, imagine you have an image, {@code icon.png}, and you have different versions of it
+for different locales, but two locales, English-Canadian and French-Canadian, need to
+use the same version. You might assume that you need to copy the Canadian version of the
+icon into the alternative resource directory for both English-Canadian and French-Canadian, but it's
+not true. What you can do instead is save the Canadian version as {@code icon_ca.png} (any name
+other than {@code icon.png}) and put
+it in the default {@code res/drawable/} directory. Then create an {@code icon.xml} file in {@code
+res/drawable-en-rCA/} and {@code res/drawable-fr-rCA/} that refers to the {@code icon_ca.png}
+resource using the {@code <bitmap>} element. This allows you to store just one version of the
+PNG file and two small XML files that point to it. (An example XML file is shown below.)</p>
+
+<p class="note"><strong>Note:</strong> Not all resources offer a mechanism by which you can
+create an alias to another resource. In particular, animation, menu, raw, and other unspecified
+resources in the {@code xml/} directory don't provide this kind of feature.</p>
+
+
+<h4>Drawable</h4>
+
+<p>To create an alias to an existing drawable, use the {@code <bitmap>} element.
+For example:</p>
+
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
+ android:src="@drawable/icon_ca" />
+</pre>
+
+<p>If you save this file as {@code icon.xml}, it will be compiled into a resource that you
+can reference as {@code R.drawable.icon}, but is actually an alias for the {@code
+R.drawable.icon_ca} resource.</p>
+
+
+<h4>Layout</h4>
+
+<p>To create an alias to an existing layout, use the {@code <include>}
+element, wrapped in a {@code <merge>}. For example:</p>
+
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<merge>
+ <include layout="@layout/main_ltr"/>
+</merge>
+</pre>
+
+<p>If you save this file as {@code main.xml}, it will be compiled into a resource you can reference
+as {@code R.layout.main}, but is actually an alias for the {@code R.layout.main_ltr}
+resource.</p>
+
+
+<h4>Strings and other simple values</h4>
+
+<p>To create an alias to an existing string, simply use the resource ID of the desired
+string as the value for the new string. For example:</p>
+
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="hello">Hello</string>
+ <string name="hi">@string/hello</string>
+</resources>
+</pre>
+
+<p>The {@code R.string.hi} resource is now an alias for the {@code R.string.hello}.</p>
+
+<p> <a href="{@docRoot}guide/topics/resources/more-resources.html">Other simple values</a> work the
+same way. For example, a color:</p>
+
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <color name="yellow">#f00</color>
+ <color name="highlight">@color/red</color>
+</resources>
+</pre>
+
+
+
+
+
+
+<h2 id="BestMatch">How Android Finds the Best-matching Resource</h2>
+
+<p>Once you have saved alternative resources for your application, Android will pick which of the
+various underlying resource files should be used at runtime for each resource
+requested, depending on the current device configuration. To demonstrate how Android will select the
+resource to use, assume the following drawables are available:</p>
+
+<pre class="no-pretty-print">
+res/drawable/
+res/drawable-en/
+res/drawable-fr-rCA/
+res/drawable-en-port/
+res/drawable-en-notouch-12key/
+res/drawable-port-ldpi/
+res/drawable-port-notouch-12key
+</pre>
+
+<p>And assume the following is the device configuration:</p>
+
+<p style="margin-left:2em;">
+Locale = <code>en-GB</code> <br/>
+Screen orientation = <code>port</code> <br/>
+Screen pixel density = <code>hdpi</code> <br/>
+Touchscreen type = <code>notouch</code> <br/>
+Primary text input method = <code>12key</code>
+</p>
+
+
+<p>Here is how Android makes the drawable selection and how a drawable will be selected from the
+configuration above: </p>
+
+<ol>
+ <li>Eliminate resource files that contradict the device configuration.
+ <p>The <code>drawable-fr-rCA/</code> directory will be eliminated, because it
+contradicts the locale of the device.</p>
+<pre class="no-pretty-print">
+drawable/
+drawable-en/
+<strike>drawable-fr-rCA/</strike>
+drawable-en-port/
+drawable-en-notouch-12key/
+drawable-port-ldpi/
+drawable-port-notouch-12key
+</pre>
+<p class="note"><strong>Exception: </strong>Screen pixel density is the one qualifier that is not
+used to eliminate files. Even though the screen density of the device is mdpi,
+<code>drawable-port-ldpi/</code> is not eliminated because every screen density is
+considered to be a match at this point.</p></li>
+
+ <li>From <a href="#table2">Table 2</a>, pick the (next) highest-precedence qualifier in
+the list. (Start with MCC, then move down through the list.) </li>
+ <li>Do any of the available resource directories include this qualifier? </li>
+ <ul>
+ <li>If No, return to step 2 and look at the next qualifier. In the example,
+ the answer is "no" until the language qualifier is reached.</li>
+ <li>If Yes, move on to step 4.</li>
+ </ul>
+ </li>
+
+ <li>Eliminate resource directories that do not include this qualifier. In the example, the system
+eliminates all the directories that do not include a language qualifier:</li>
+<pre class="no-pretty-print">
+<strike>drawable/</strike>
+drawable-en/
+drawable-en-port/
+drawable-en-notouch-12key/
+<strike>drawable-port-ldpi/</strike>
+<strike>drawable-port-notouch-12key</strike>
+</pre>
+<p class="note"><strong>Exception:</strong> If the qualifier in question is screen pixel density,
+Android will
+select the option that most closely matches the device, and the selection process will be complete.
+In general, Android will prefer scaling down a larger original image to scaling up a smaller
+original image.</p>
+ </li>
+
+ <li>Go back and repeat steps 2, 3, and 4 until only one choice remains. In the example, screen
+orientation is the next qualifier for which there are any matches.
+So, resources that do not specify a screen orientation are eliminated:
+<pre class="no-pretty-print">
+<strike>drawable-en/</strike>
+drawable-en-port/
+<strike>drawable-en-notouch-12key/</strike>
+</pre>
+<p>Only one choice remains, so the drawable will be taken from the {@code drawable-en-port}
+directory.</p>
+ </li>
+</ol>
+
+<p>Though this procedure is executed for each resource requested, the system will further optimize
+some aspects. One such optimization is that once the device configuration is known, it might
+completely eliminate alternative resources that can never match. For example, if the configuration
+language is English ("en"), then any resource directory that has a language qualifier set to
+something other than English will never be included in the pool of resources checked (though a
+resource directory <em>without</em> the language qualifier is still included).</p>
+
+<p class="note"><strong>Note:</strong> The <em>precedence</em> of the qualifier (in <a
+href="#table2">Table 2</a>) is more important
+than the number of qualifiers that exactly match the device. For example, in step 4 above, the last
+choice on the list includes three qualifiers that exactly match the device (orientation, touchscreen
+type, and input method), while <code>drawable-en</code> has only one parameter that matches
+(language). However, language has a higher precedence than these other qualifiers, so
+<code>drawable-port-notouch-12key</code>
+is out.</p>
+
+<p>The following flowchart summarizes how Android selects the resource directory to use.</p>
+<p><img src="{@docRoot}images/resources/res-selection-flowchart.png" alt=""
+height="471" /></p>
+
diff --git a/docs/html/guide/topics/resources/resources-i18n.jd b/docs/html/guide/topics/resources/resources-i18n.jd
index fcf2af9..e1c96fb 100755
--- a/docs/html/guide/topics/resources/resources-i18n.jd
+++ b/docs/html/guide/topics/resources/resources-i18n.jd
@@ -1,808 +1,8 @@
-page.title=Resources and Internationalization
-parent.title=Resources and Assets
-parent.link=index.html
+page.title=Application Resources
@jd:body
-<div id="qv-wrapper">
-<div id="qv">
+<script type="text/javascript">
+ window.location = toRoot + "guide/topics/resources/index.html";
+</script>
- <h2>Key classes</h2>
- <ol>
- <li>{@link android.content.res.Resources}</li>
- </ol>
-
- <h2>In this document</h2>
- <ol>
- <li><a href="#intro">Introduction</a></li>
- <li><a href="#CreatingResources">Creating Resources</a></li>
- <li><a href="#UsingResources">Using Resources</a>
- <ol>
- <li><a href="#ResourcesInCode">Using Resources in Code</a></li>
- <li><a href="#ReferencesToResources">References to Resources</a></li>
- <li><a href="#ReferencesToThemeAttributes">References to Theme Attributes</a></li>
- <li><a href="#UsingSystemResources">Using System Resources</a></li>
- </ol>
- </li>
- <li><a href="#AlternateResources">Alternate Resources</a></li>
- <li><a href="#ResourcesTerminology">Terminology</a></li>
- <li><a href="#i18n">Internationalization (I18N)</a></li>
- </ol>
-</div>
-</div>
-
-<p>Resources are external files (that is, non-code files) that are used by
-your code and compiled into your application at build time. Android
-supports a number of different kinds of resource files, including XML,
-PNG, and JPEG files. The XML files have very different formats depending
-on what they describe. This document describes what kinds of files are
-supported, and the syntax or format of each.</p>
-<p>Resources are externalized from source code, and XML files are compiled into
-a binary, fast loading format for efficiency reasons. Strings, likewise, are compressed
-into a more efficient storage form. It is for these reasons that we have these
-different resource types in the Android platform.</p>
-
-<p>This is a fairly technically dense document, and together with the
-<a href="available-resources.html">Available Resources</a>
-document, they cover a lot of information about resources. It is not necessary
-to know this document by heart to use Android, but rather to know that the
-information is here when you need it.</p>
-
-<a name="intro"></a>
-<h2>Introduction</h2>
-
-<p>This topic includes a terminology list associated with resources, and a series
- of examples of using resources in code. For a complete guide to the supported
- Android resource types, see
- <a href="available-resources.html">Available Resources</a>.
- </p>
-<p>The Android resource system keeps track of all non-code
- assets associated with an application. You use the
- {@link android.content.res.Resources Resources} class to access your
- application's resources; the Resources instance associated with your
- application can generally be found through
- {@link android.content.Context#getResources Context.getResources()}.</p>
-<p>An application's resources are compiled into the application
-binary at build time for you by the build system. To use a resource,
-you must install it correctly in the source tree and build your
-application. As part of the build process, symbols for each
-of the resources are generated that you can use in your source
-code -- this allows the compiler to verify that your application code matches
-up with the resources you defined.</p>
-
-<p>The rest of this section is organized as a tutorial on how to
-use resources in an application.</p>
-
-<a name="CreatingResources" id="CreatingResources"></a>
-<h2>Creating Resources</h2>
-
-<p>Android supports string, bitmap, and many other types of resource. The syntax and format
-of each, and where they're stored, depends upon the type of object. In
-general, though, you create resources from three types of files: XML files
-(everything but bitmaps and raw), bitmap files(for images) and Raw files (anything
-else, for example sound files, etc.). In fact, there are two different types of
-XML file as well, those that get compiled as-is into the package, and those that
-are used to generate resources by aapt. Here is a list of each
-resource type, the format of the file, a description of the file, and details
-of any XML files. </p>
-
-<p>You will create and store your resource files under the appropriate
-subdirectory under the <code>res/</code> directory in your project. Android
-has a resource compiler (aapt) that compiles resources according to which
-subfolder they are in, and the format of the file. Table 1 shows a list of the file
-types for each resource. See the
-<a href="available-resources.html">Available Resources</a> for
-descriptions of each type of object, the syntax, and the format or syntax of
-the containing file.</p>
-<p class="caption">Table 1</p>
-<table width="100%" border="1">
- <tr>
- <th scope="col">Directory</th>
- <th scope="col">Resource Types </th>
- </tr>
- <tr>
- <td><code>res/anim/</code></td>
- <td>XML files that are compiled into
- <a href="available-resources.html#animationdrawable">frame by
- frame animation</a> or
- <a href="available-resources.html#tweenedanimation">tweened
- animation</a> objects </td>
- </tr>
- <tr>
- <td><code>res/drawable/</code></td>
- <td><p>.png, .9.png, .jpg files that are compiled into the following
- Drawable resource subtypes:</p>
- <ul class="nolist">
- <li><a href="available-resources.html#imagefileresources">bitmap files</a></li>
- <li><a href="available-resources.html#ninepatch">9-patches (resizable bitmaps)</a></li>
- </ul>
- <p>To get a resource of this type, use <code>mContext.getResources().getDrawable(R.drawable.<em>imageId</em>)</code></p>
- <p class="note"><strong>Note:</strong> Image resources placed in here may
- be automatically optimized with lossless image compression by the
- <a href="{@docRoot}guide/developing/tools/aapt.html">aapt</a> tool. For example, a true-color PNG
- that does not require more than 256 colors may be converted to an 8-bit PNG with a color palette.
- This will result in an image of equal quality but which requires less memory. So be aware that the
- image binaries placed in this directory can change during the build. If you plan on reading
- an image as a bit stream in order to convert it to a bitmap, put your images in the
- <code>res/raw/</code> folder instead, where they will not be optimized.</p>
- </td>
- </tr>
- <tr>
- <td><code>res/layout/</code></td>
- <td>XML files that are compiled into screen layouts (or part of a screen).
- See <a href="{@docRoot}guide/topics/ui/declaring-layout.html">Declaring Layout</a>.</td>
- </tr>
- <tr>
- <td><code>res/values/</code></td>
- <td><p>XML files that can be compiled into many kinds of resource.</p>
- <p class="note"><strong>Note:</strong> Unlike the other res/ folders, this one
- can hold any number of files that hold descriptions of resources to create
- rather than the resources themselves. The XML element types control
- where these resources are placed under the R class.</p>
- <p>While the files can be named anything, these are
- the typical files in this folder (the convention is to name
- the file after the type of elements defined within):</p>
- <ul>
- <li><strong>arrays.xml</strong> to define arrays </li>
- <!-- TODO: add section on arrays -->
- <li><strong>colors.xml</strong> to define <a href="available-resources.html#colordrawableresources">color
- drawables</a> and <a href="#colorvals">color string values</a>.
- Use <code>Resources.getDrawable()</code> and
- <code>Resources.getColor(), respectively,</code>
- to get these resources.</li>
- <li><strong>dimens.xml</strong> to define <a href="available-resources.html#dimension">dimension value</a>. Use <code>Resources.getDimension()</code> to get
- these resources.</li>
- <li><strong>strings.xml</strong> to define <a href="available-resources.html#stringresources">string</a> values (use either
- <code>Resources.getString</code> or preferably <code>Resources.getText()</code>
- to get
- these resources. <code>getText()</code> will retain any rich text styling
- which is usually desirable for UI strings.</li>
- <li><strong>styles.xml</strong> to define <a href="available-resources.html#stylesandthemes">style</a> objects.</li>
- </ul></td>
- </tr>
- <tr>
- <td><code>res/xml/</code></td>
- <td>Arbitrary XML files that are compiled and can be read at run time by
- calling {@link android.content.res.Resources#getXml(int) Resources.getXML()}.</td>
- </tr>
- <tr>
- <td><code>res/raw/</code></td>
- <td>Arbitrary files to copy directly to the device. They are added uncompiled
- to the compressed file that your application build produces. To use these
- resources in your application, call {@link android.content.res.Resources#openRawResource(int)
- Resources.openRawResource()} with the resource ID, which is R.raw.<em>somefilename</em>.</td>
- </tr>
-</table>
-<p>Resources are compiled into the final APK file. Android creates a wrapper class,
- called R, that you can use to refer to these resources in your code. R contains subclasses
- named according to the path and file name of the source file</p>
-<a name="colorvals" id="colorvals"></a>
-<h3>Global Resource Notes</h3>
-<ul>
- <li>Several resources allow you to define colors. Android accepts color values
- written in various web-style formats -- a hexadecimal constant in any of the
- following forms: #RGB, #ARGB, #RRGGBB, #AARRGGBB. </li>
- <li>All color values support setting an alpha channel value, where the first
- two hexadecimal numbers specify the transparency. Zero in the alpha channel
- means transparent. The default value is opaque. </li>
-</ul>
-<a name="UsingResources" id="UsingResources"></a>
-<h2>Using Resources </h2>
-<p>This section describes how to use the resources you've created. It includes the
- following topics:</p>
-<ul>
- <li><a href="#ResourcesInCode">Using resources in code</a> - How to call
- resources in your code to instantiate them. </li>
- <li><a href="#ReferencesToResources">Referring to resources from other resources</a> -
- You can reference resources from other resources. This lets you reuse common
- resource values inside resources. </li>
- <li><a href="#AlternateResources">Supporting Alternate Resources for Alternate
- Configurations</a> - You can specify different resources
- to load, depending on the language or display configuration of the host
- hardware. </li>
-</ul>
-<p>At compile time, Android generates a class named R that contains resource identifiers
- to all the resources in your program. This class contains several subclasses,
- one for each type of resource supported by Android, and for which you provided
- a resource file. Each class contains one or more identifiers for the compiled resources,
- that you use in your code to load the resource. Here is a small resource file
- that contains string, layout (screens or parts of screens), and image resources.</p>
-<p class="note"><strong>Note:</strong> the R class is an auto-generated file and is not
-designed to be edited by hand. It will be automatically re-created as needed when
-the resources are updated.</p>
-<pre class="prettyprint">package com.android.samples;
-public final class R {
- public static final class string {
- public static final int greeting=0x0204000e;
- public static final int start_button_text=0x02040001;
- public static final int submit_button_text=0x02040008;
- public static final int main_screen_title=0x0204000a;
- };
- public static final class layout {
- public static final int start_screen=0x02070000;
- public static final int new_user_pane=0x02070001;
- public static final int select_user_list=0x02070002;
-
- };
- public static final class drawable {
- public static final int company_logo=0x02020005;
- public static final int smiling_cat=0x02020006;
- public static final int yellow_fade_background=0x02020007;
- public static final int stretch_button_1=0x02020008;
-
- };
-};
-</pre>
-<a name="ResourcesInCode" id="ResourcesInCode"></a>
-<h3>Using Resources in Code </h3>
-
-<p>Using resources in code is just a matter of knowing the full resource ID
-and what type of object your resource has been compiled into. Here is the
-syntax for referring to a resource:</p>
-<p><code>R.<em>resource_type</em>.<em>resource_name</em></code></p>
-<p>or</p>
-<p><code>android.R.<em>resource_type</em>.<em>resource_name</em></code></p>
-
-<p>Where <code>resource_type</code> is the R subclass that holds a specific type
-of resource. <code>resource_name</code> is the <em>name</em> attribute for resources
-defined in XML files, or the file name (without the extension) for resources
-defined by other file types. Each type of resource will be added to a specific
-R subclass, depending on the type of resource it is; to learn which R subclass
-hosts your compiled resource type, consult the
-<a href="available-resources.html">Available Resources</a> document. Resources compiled by your own application can
-be referred to without a package name (simply as
-<code>R.<em>resource_type</em>.<em>resource_name</em></code>). Android contains
-a number of standard resources, such as screen styles and button backgrounds. To
-refer to these in code, you must qualify them with <code>android</code>, as in
-<code>android.R.drawable.button_background</code>.</p>
-
-<p>Here are some good and bad examples of using compiled resources in code:</p>
-
-<pre class="prettyprint">// Load a background for the current screen from a drawable resource.
-this.getWindow().setBackgroundDrawableResource(R.drawable.my_background_image);
-
-// WRONG Sending a string resource reference into a
-// method that expects a string.
-this.getWindow().setTitle(R.string.main_title);
-
-// RIGHT Need to get the title from the Resources wrapper.
-this.getWindow().setTitle(Resources.getText(R.string.main_title));
-
-// Load a custom layout for the current screen.
-setContentView(R.layout.main_screen);
-
-// Set a slide in animation for a ViewFlipper object.
-mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,
- R.anim.hyperspace_in));
-
-// Set the text on a TextView object.
-TextView msgTextView = (TextView)findViewByID(R.id.msg);
-msgTextView.setText(R.string.hello_message); </pre>
-
-<a name="ReferencesToResources" id="ReferencesToResources"></a>
-<h3>References to Resources</h3>
-
-<p>A value supplied in an attribute (or resource) can also be a reference to
-a resource. This is often used in layout files to supply strings (so they
-can be localized) and images (which exist in another file), though a reference
-can be any resource type including colors and integers.</p>
-
-<p>For example, if we have
-<a href="available-resources.html#colordrawableresources">color
-resources</a>, we can write a layout file that sets the text color size to be
-the value contained in one of those resources:</p>
-
-<pre>
-<?xml version="1.0" encoding="utf-8"?>
-<EditText id="text"
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent" android:layout_height="fill_parent"
- <strong>android:textColor="@color/opaque_red"</strong>
- android:text="Hello, World!" />
-</pre>
-
-<p>Note here the use of the '@' prefix to introduce a resource reference -- the
-text following that is the name of a resource in the form
-of <code>@[package:]type/name</code>. In this case we didn't need to specify
-the package because we are referencing a resource in our own package. To
-reference a system resource, you would need to write:</p>
-
-<pre>
-<?xml version="1.0" encoding="utf-8"?>
-<EditText id="text"
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent" android:layout_height="fill_parent"
- android:textColor="@<strong>android:</strong>color/opaque_red"
- android:text="Hello, World!" />
-</pre>
-
-<p>As another example, you should always use resource references when supplying
-strings in a layout file so that they can be localized:</p>
-
-<pre>
-<?xml version="1.0" encoding="utf-8"?>
-<EditText id="text"
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent" android:layout_height="fill_parent"
- android:textColor="@android:color/opaque_red"
- android:text="@string/hello_world" />
-</pre>
-
-<p>This facility can also be used to create references between resources.
-For example, we can create new drawable resources that are aliases for
-existing images:</p>
-
-<pre>
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
- <drawable id="my_background">@android:drawable/theme2_background</drawable>
-</resources>
-</pre>
-
-<a name="ReferencesToThemeAttributes"></a>
-<h3>References to Theme Attributes</h3>
-
-<p>Another kind of resource value allows you to reference the value of an
-attribute in the current theme. This attribute reference can <em>only</em>
-be used in style resources and XML attributes; it allows you to customize the
-look of UI elements by changing them to standard variations supplied by the
-current theme, instead of supplying more concrete values.</p>
-
-<p>As an example, we can use this in our layout to set the text color to
-one of the standard colors defined in the base system theme:</p>
-
-<pre>
-<?xml version="1.0" encoding="utf-8"?>
-<EditText id="text"
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent" android:layout_height="fill_parent"
- <strong>android:textColor="?android:textDisabledColor"</strong>
- android:text="@string/hello_world" />
-</pre>
-
-<p>Note that this is very similar to a resource reference, except we are using
-an '?' prefix instead of '@'. When you use this markup, you are supplying
-the name of an attribute resource that will be looked up in the theme --
-because the resource tool knows that an attribute resource is expected,
-you do not need to explicitly state the type (which would be
-<code>?android:attr/android:textDisabledColor</code>).</p>
-
-<p>Other than using this resource identifier to find the value in the
-theme instead of raw resources, the name syntax is identical to the '@' format:
-<code>?[namespace:]type/name</code> with the type here being optional.</p>
-
-<a name="UsingSystemResources"></a>
-<h3>Using System Resources</h3>
-
-<p>Many resources included with the system are available to applications.
-All such resources are defined under the class "android.R". For example,
-you can display the standard application icon in a screen with the following
-code:</p>
-
-<pre class="prettyprint">
-public class MyActivity extends Activity
-{
- public void onStart()
- {
- requestScreenFeatures(FEATURE_BADGE_IMAGE);
-
- super.onStart();
-
- setBadgeResource(android.R.drawable.sym_def_app_icon);
- }
-}
-</pre>
-
-<p>In a similar way, this code will apply to your screen the standard
-"green background" visual treatment defined by the system:</p>
-
-<pre class="prettyprint">
-public class MyActivity extends Activity
-{
- public void onStart()
- {
- super.onStart();
-
- setTheme(android.R.style.Theme_Black);
- }
-}
-</pre>
-
-<a name="AlternateResources" id="AlternateResources"></a>
-<h2>Alternate Resources (for alternate languages and configurations)</h2>
-
-<p>You can supply different resources for your application to use depending on the UI
-language or hardware configuration on the device. Note that although you can
-include different string, layout, and other resources, the SDK does not expose
-methods to let you specify which alternate resource set to load. Android
-detects the proper set for the hardware and location, and loads them as
-appropriate. Users can select alternate language settings using the settings
-panel on the device. </p>
-<p>To include alternate resources, create parallel resource folders with
-qualifiers appended to the folder names, indicating the configuration it
-applies to (language, screen orientation, and so on). For example, here is a
-project that holds one string resource file for English, and another for
-French:</p>
-
-<pre>
-MyApp/
- res/
- values-en/
- strings.xml
- values-fr/
- strings.xml
-</pre>
-
-<p>Android supports several types of qualifiers, with various values for each.
-Append these to the end of the resource folder name, separated by dashes. You
-can add multiple qualifiers to each folder name, but they must appear in the
-order they are listed here. For example, a folder containing drawable
-resources for a fully specified configuration would look like this:</p>
-
-<pre>
-MyApp/
- res/
- drawable-en-rUS-large-long-port-mdpi-finger-keysexposed-qwerty-navexposed-dpad-480x320/
-</pre>
-
-<p>More typically, you will only specify a few specific configuration options. You may drop any of the values from the
-complete list, as long as the remaining values are still in the same
-order:</p>
-
-<pre>
-MyApp/
- res/
- drawable-en-rUS-finger/
- drawable-port/
- drawable-port-mdpi/
- drawable-qwerty/
-</pre>
-<p>Table 2 lists the valid folder-name qualifiers, in order of precedence. Qualifiers that are listed higher in the table take precedence over those listed lower, as described in <a href="#best-match">How Android finds the best matching directory</a>. </p>
-<p class="caption" id="table2">Table 2</p>
-<table border="1">
- <tr>
- <th> Qualifier </th>
- <th> Values </th>
- </tr>
- <tr>
- <td>MCC and MNC</td>
- <td><p>The mobile country code optionally followed by mobile network code
- from the SIM in the device. For example
- <code>mcc310</code> (U.S. on any carrier);
- <code>mcc310-mnc004</code> (U.S., Verizon brand);
- <code>mcc208-mnc00</code> (France, Orange brand);
- <code>mcc234-mnc00</code> (U.K., BT brand).
- </p><p>
- If the device uses a radio connection (GSM phone), the MCC will come
- from the SIM, and the MNC will come from the network to which the
- device is attached. You might sometimes use the MCC alone, for example
- to include country-specific legal resources in your application. If
- your application specifies resources for a MCC/MNC combination, those
- resources can only be used if both the MCC and the MNC match. </p></td>
- </tr>
- <tr>
- <td>Language and region</td>
- <td><p>The two letter <a href="http://www.loc.gov/standards/iso639-2/php/code_list.php">ISO
- 639-1</a> language code optionally followed by a two letter
- <a href="http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html">ISO
- 3166-1-alpha-2</a> region code (preceded by lowercase "r"). For example
- <code>fr</code>, <code>en-rUS</code>, <code>fr-rFR</code>, <code>es-rES</code>.
- </p><p>
- The codes are <em>not</em> case-sensitive; the r prefix is used to
- distinguish the region portion.
- You cannot specify a region alone, but you can specify a language alone,
- for example <code>en</code>, <code>fr</code>, <code>es</code>.</p> </td>
- </tr>
- <tr>
- <td>Screen dimensions</td>
- <td><p><code>small</code>, <code>normal</code>, <code>large</code>
- </p><p>
- Specify that the resource is for a particular class of screen.
- The meanings of these are:</p>
- <ul>
- <li> <b>Normal screens</b> are based on the traditional Android HVGA
- medium density screen. A screen is considered to be normal if it is
- at least this size (independent of density) and not large. Examples
- of such screens a WQVGA low density, HVGA medium density, WVGA
- high density.
- <li> <b>Small screens</b> are based on the space available on a
- QVGA low density screen. Considering a portrait HVGA display, this has
- the same available width but less height -- it is 3:4 vs. HVGA's
- 2:3 aspect ratio. Examples are QVGA low density and VGA high
- density.
- <li> <b>Large screens</b> are based on the space available on a
- VGA medium density screen. Such a screen has significantly more
- available space in both width and height than an HVGA display.
- Examples are VGA and WVGA medium density screens.
- </td>
- </tr>
- <tr>
- <td>Wider/taller screens</td>
- <td><p><code>long</code>, <code>notlong</code>
- </p><p>
- Specify that the resource is for a taller/wider than traditional
- screen. This is based purely on the aspect ration of the screen:
- QVGA, HVGA, and VGA are notlong; WQVGA, WVGA, FWVGA are long. Note
- that long may mean either wide or tall, depending on the current
- orientation.</p>
- </td>
- </tr>
- <tr>
- <td>Screen orientation</td>
- <td><p><code>port</code>, <code>land</code>, <code>square</code>
- </p><p>
- Specifies that the resource is for a screen that is tall (port)
- or wide (land); square is not currently used.</p>
- </td>
- </tr>
- <tr>
- <td>Screen pixel density</td>
- <td><p><code>ldpi</code>, <code>mdpi</code>, <code>hdpi</code>, <code>nodpi</code>
- </p><p>
- Specifies the screen density the resource is defined for. The medium
- density of traditional HVGA screens (mdpi) is defined to be approximately
- 160dpi; low density (ldpi) is 120, and high density (hdpi) is 240. There
- is thus a 4:3 scaling factor between each density, so a 9x9 bitmap
- in ldpi would be 12x12 is mdpi and 16x16 in hdpi. The special
- <code>nodpi</code> density can be used with bitmap resources to prevent
- them from being scaled at load time to match the device density.
- </p><p>
- When Android selects which resource files to use,
- it handles screen density differently than the other qualifiers.
- In step 1 of <a href="#best-match">How Android finds the best
- matching directory</a> (below), screen density is always considered to
- be a match. In step 4, if the qualifier being considered is screen
- density, Android will select the best final match at that point,
- without any need to move on to step 5.
- </p><p>
- You can also specify explicit densities like <code>92dpi</code>
- or <code>108dpi</code>, but these are not fully supported by the
- system so should not be used.
- </p>
- </td>
- </tr>
- <tr>
- <td>Touchscreen type</td>
- <td><code>notouch</code>, <code>stylus</code>, <code>finger</code></td>
- </tr>
- <tr>
- <td>Whether the keyboard is available to the user</td>
- <td><p><code>keysexposed</code>, <code>keyshidden</code>, <code>keyssoft</code>
- </p><p>
- If your application has specific resources that should only be used with a soft keyboard, use the <code>keyssoft</code> value. If no <code>keyssoft</code> resources are available (only <code>keysexposed</code> and <code>keyshidden</code>) and the device shows a soft keyboard, the system will use <code>keysexposed</code> resources.</p> </td>
- </tr>
- <tr>
- <td>Primary text input method</td>
- <td><code>nokeys</code>, <code>qwerty</code>, <code>12key</code> </td>
- </tr>
- <tr>
- <td>Whether the navigation keys are available to the user</td>
- <td><p><code>navexposed</code>, <code>navhidden</code>
- </p><p>
- If the hardware's navigation keys are currently available to
- the user, the navexposed resources will be used; if they are not
- available (such as behind a closed lid), navhidden will be used.</p></td>
- </tr>
- <tr>
- <td>Primary non-touchscreen<br />
- navigation method</td>
- <td><code>nonav</code>, <code>dpad</code>, <code>trackball</code>, <code>wheel</code> </td>
- </tr>
- <tr>
- <td>Screen dimensions</td>
- <td><code>320x240</code>, <code>640x480</code>, etc. The larger dimension
- must be specified first. This configuration is deprecated and
- should not be used; use instead screen dimension, wider/taller
- screens, and screen orientation described above.</td>
- </tr>
- <tr>
- <td>SDK version</td>
- <td>The SDK version supported by the device, for example <code>v3</code>. The Android 1.0 SDK is <code>v1, </code> the 1.1 SDK is <code>v2</code>, and the 1.5 SDK is <code>v3</code>.</td>
- </tr>
- <tr>
- <td>(Minor version)</td>
- <td>(You cannot currently specify minor version. It is always set to 0.)</td>
- </tr>
-</table>
-
-<p>This list does not include device-specific parameters such as carrier,
-branding, device/hardware, or manufacturer. Everything that an application
-needs to know about the device that it is running on is encoded via the
-resource qualifiers in the table above.</p>
-
-<p>All resource directories, qualified and unqualified, live under the <code>res/</code> folder. Here are some guidelines on qualified resource directory names:</p>
-
-<ul>
- <li>You can specify multiple qualifiers, separated by dashes. For example, <code>drawable-en-rUS-land</code> will apply to US-English
- devices in landscape orientation. </li>
- <li>The qualifiers must be in the order listed in <a href="#table2">Table 2</a> above. For example:
- <ul>
- <li>Correct: <code>values-mcc460-nokeys/</code></li>
- <li>Incorrect: <code>values-nokeys-mcc460/</code></li>
- </ul>
- </li>
- <li>Values are case-insensitive. The resource compiler converts folder names
- to lower case before processing to avoid problems in case-insensitive
- file systems. On case-sensitive file systems, you should keep all names
- lower-case or at least use a consistent case to protect your future
- sanity when trying to find a resource file.</li>
- <li>Only one value for each qualifier type is supported. For example, if you want to use exactly the same drawable files for Spain and France, you will need two resource directories, such as <code>drawable-rES/</code> and <code>drawable-rFR/</code>, containing identical files. You cannot
- have a directory named <code>drawable-rES-rFR/</code>. </li>
- <li>Qualified directories cannot be nested. For example, you cannot have <code>res/drawable/drawable-en</code>. </li>
-</ul>
-
-<h3>How resources are referenced in code</h3>
-<p>All resources will be referenced in code or resource reference syntax by
- their simple, undecorated names. So if a resource were named this:<br />
- <code>MyApp/res/drawable-port-mdpi/myimage.png</code><br />
- It would be referenced as this:<br />
- <code>R.drawable.myimage</code> (code)<br />
- <code>@drawable/myimage</code> (XML)</p>
-<p>If several drawable directories are available, Android will select one of them (as described below) and load <code>myimage.png</code> from it.</p>
-<h3 id="best-match">How Android finds the best matching directory </h3>
-
-<p>Android will pick which of the various underlying resource files should be
-used at runtime, depending on the current configuration of the device.
-The example used here assumes the following device configuration:</p>
-
- <p style="margin-left:2em">Locale = <code>en-GB</code><br>
- Screen orientation = <code>port</code><br>
- Screen pixel density = <code>mdpi</code><br>
- Touchscreen type = <code>notouch</code><br>
- Primary text input method = <code>12key</code><br>
- </p>
-
-<p>Here is how Android makes the selection: </p>
-<ol>
- <li>
- Eliminate resource files that contradict the
- device configuration. For example, assume that the following resource directories are available for drawables. The <code>drawable-fr-rCA/</code> directory will be eliminated, because it contradicts the locale of the device.<br>
-<pre>MyApp/res/drawable/
-MyApp/res/drawable-en/
-<strike>MyApp/res/drawable-fr-rCA/</strike>
-MyApp/res/drawable-en-port/
-MyApp/res/drawable-en-notouch-12key/
-MyApp/res/drawable-port-ldpi/
-MyApp/res/drawable-port-notouch-12key</pre>
- <strong>Exception: </strong>Screen pixel density is the one qualifier that is not used to eliminate files. Even though the screen density of the device is medium dpi, <code>drawable-port-ldpi/</code> is not eliminated from the list, because every screen density is considered to be a
- match at this point.</li>
- <li>From <a href="#table2">Table 2</a>, pick the highest-precedence qualifier that remains in the list. (Start with MCC, then move down through the list.) </li>
- <li>Do any of the available resource directories include this qualifier? </li>
- <ul>
- <li>If No, return to step 2 and look at the next qualifier listed in Table 2. In our example, the answer is "no" until we reach Language.</li>
- <li>If Yes, move on to step 4.</li>
- </ul>
- <li>Eliminate resource directories that do not include this qualifier. In our example, we eliminate all the directories that do not include a language qualifier. </li>
- <pre><strike>MyApp/res/drawable/</strike>
-MyApp/res/drawable-en/
-MyApp/res/drawable-en-port/
-MyApp/res/drawable-en-notouch-12key/
-<strike>MyApp/res/drawable-port-ldpi/</strike>
-<strike>MyApp/res/drawable-port-notouch-12key</strike></pre>
- <strong>Exception:</strong> If the qualifier in question is screen pixel density, Android will select the option that most closely matches the device, and the selection process will be complete. In general, Android will prefer scaling down a larger original image to scaling up a smaller original image.<br><br></li>
-
-<li>Go back and repeat steps 2, 3, and 4 until only one choice remains. In the example, screen orientation is the next qualifier in the table for which we have any matches.
- Eliminate resources that do not specify a screen orientation. </p>
- <pre><strike>MyApp/res/drawable-en/</strike>
-MyApp/res/drawable-en-port/
-<strike>MyApp/res/drawable-en-notouch-12key/</strike></pre>
- Only one choice remains, so that's it. When drawables are called for in this
- example application, the Android system will load resources from the
- <code>MyApp/res/drawable-en-port/</code> directory. In addition, if the
- resource being loaded is a bitmap, it will be scaled up so that its supplied
- low density matches the device's medium density.
-</ol>
-<p class="note"><strong>Tip:</strong> The <em>precedence</em> of the qualifiers is more important than the number of qualifiers that exactly match the device. For example, in step 4 above, the last choice on the list includes three qualifiers that exactly match the device (orientation, touchscreen type, and input method), while <code>drawable-en</code> has only one parameter that matches (language). However, language has a higher precedence, so <code>drawable-port-notouch-12key</code> is out.</p>
-<p>This flowchart summarizes how Android selects resource directories to load.</p>
-<p><img src="../../../images/resources/res-selection-flowchart.png" alt="resource-selection" width="461" height="471" style="margin:15px"></p>
-<h3>Terminology</h3>
-<p>The resource system brings a number of different pieces together to
-form the final complete resource functionality. To help understand the
-overall system, here are some brief definitions of the core concepts and
-components you will encounter in using it:</p>
-
-<p><strong>Asset</strong>: A single blob of data associated with an application. This
-includes object files compiled from the Java source code, graphics (such as PNG
-images), XML files, etc. These files are organized in a directory hierarchy
-that, during final packaging of the application, is bundled together into a
-single ZIP file.</p>
-
-<p><strong>aapt</strong>: Android Asset Packaging Tool. The tool that generates the
-final ZIP file of application assets. In addition to collecting raw assets
-together, it also parses resource definitions into binary asset data.</p>
-
-<p><strong>Resource Table</strong>: A special asset that aapt generates for you,
-describing all of the resources contained in an application/package.
-This file is accessed for you by the Resources class; it is not touched
-directly by applications.</p>
-
-<p><strong>Resource</strong>: An entry in the Resource Table describing a single
-named value. Broadly, there are two types of resources: primitives and
-bags.</p>
-
-<p><strong>Resource Identifier</strong>: In the Resource Table all resources are
-identified by a unique integer number. In source code (resource descriptions,
-XML files, Java source code) you can use symbolic names that stand as constants for
-the actual resource identifier integer.</p>
-
-<p><strong>Primitive Resource</strong>: All primitive resources can be written as a
-simple string, using formatting to describe a variety of primitive types
-included in the resource system: integers, colors, strings, references to
-other resources, etc. Complex resources, such as bitmaps and XML
-describes, are stored as a primitive string resource whose value is the path
-of the underlying Asset holding its actual data.</p>
-
-<p><strong>Bag Resource</strong>: A special kind of resource entry that, instead of a
-simple string, holds an arbitrary list of name/value pairs. Each name is
-itself a resource identifier, and each value can hold
-the same kinds of string formatted data as a normal resource. Bags also
-support inheritance: a bag can inherit the values from another bag, selectively
-replacing or extending them to generate its own contents.</p>
-
-<p><strong>Kind</strong>: The resource kind is a way to organize resource identifiers
-for various purposes. For example, drawable resources are used to
-instantiate Drawable objects, so their data is a primitive resource containing
-either a color constant or string path to a bitmap or XML asset. Other
-common resource kinds are string (localized string primitives), color
-(color primitives), layout (a string path to an XML asset describing a view
-layout), and style (a bag resource describing user interface attributes).
-There is also a standard "attr" resource kind, which defines the resource
-identifiers to be used for naming bag items and XML attributes</p>
-
-<p><strong>Style</strong>: The name of the resource kind containing bags that are used
-to supply a set of user interface attributes. For example, a TextView class may
-be given a style resource that defines its text size, color, and alignment.
-In a layout XML file, you associate a style with a bag using the "style"
-attribute, whose value is the name of the style resource.</p>
-
-<p><strong>Style Class</strong>: Specifies a related set of attribute resources.
-This data is not placed in the resource table itself, but used to generate
-constants in the source code that make it easier for you to retrieve values out of
-a style resource and/or XML tag's attributes. For example, the
-Android platform defines a "View" style class that
-contains all of the standard view attributes: padding, visibility,
-background, etc.; when View is inflated it uses this style class to
-retrieve those values from the XML file (at which point style and theme
-information is applied as appropriate) and load them into its instance.</p>
-
-<p><strong>Configuration</strong>: For any particular resource identifier, there may be
-multiple different available values depending on the current configuration.
-The configuration includes the locale (language and country), screen
-orientation, etc. The current configuration is used to
-select which resource values are in effect when the resource table is
-loaded.</p>
-
-<p><strong>Theme</strong>: A standard style resource that supplies global
-attribute values for a particular context. For example, when writing an
-Activity the application developer can select a standard theme to use, such
-as the Theme.White or Theme.Black styles; this style supplies information
-such as the screen background image/color, default text color, button style,
-text editor style, text size, etc. When inflating a layout resource, most
-values for widgets (the text color, selector, background) if not explicitly
-set will come from the current theme; style and attribute
-values supplied in the layout can also assign their value from explicitly
-named values in the theme attributes if desired.</p>
-
-<p><strong>Overlay</strong>: A resource table that does not define a new set of resources,
-but instead replaces the values of resources that are in another resource table.
-Like a configuration, this is applied at load time
-to the resource data; it can add new configuration values (for example
-strings in a new locale), replace existing values (for example change
-the standard white background image to a "Hello Kitty" background image),
-and modify resource bags (for example change the font size of the Theme.White
-style to have an 18 pt font size). This is the facility that allows the
-user to select between different global appearances of their device, or
-download files with new appearances.</p>
-
-<h2>Resource Reference</h2>
-<p>The <a href="available-resources.html">Available Resources</a>
-document provides a detailed list of the various types of resource and how to use them
-from within the Java source code, or from other references.</p>
-
-<a name="i18n" id="i18n"></a>
-<h2>Internationalization and Localization</h2>
-<p class="note"><strong>Coming Soon:</strong> Internationalization and Localization are
-critical, but are also not quite ready yet in the current SDK. As the
-SDK matures, this section will contain information on the Internationalization
-and Localization features of the Android platform. In the meantime, it is a good
-idea to start by externalizing all strings, and practicing good structure in
-creating and using resources.</p>
+<p><strong>This document has moved. Please see <a href="index.html">Application Resources</a>.</strong></p>
\ No newline at end of file
diff --git a/docs/html/guide/topics/resources/runtime-changes.jd b/docs/html/guide/topics/resources/runtime-changes.jd
new file mode 100644
index 0000000..dff664c
--- /dev/null
+++ b/docs/html/guide/topics/resources/runtime-changes.jd
@@ -0,0 +1,245 @@
+page.title=Handling Runtime Changes
+parent.title=Application Resources
+parent.link=index.html
+@jd:body
+
+<div id="qv-wrapper">
+<div id="qv">
+
+ <h2>In this document</h2>
+ <ol>
+ <li><a href="#CarryingAnObject">Carrying an Object During a Configuration Change</a></li>
+ <li><a href="#HandlingTheChange">Handling the Configuration Change Yourself</a>
+ </ol>
+
+ <h2>See also</h2>
+ <ol>
+ <li><a href="providing-resources.html">Providing Resources</a></li>
+ <li><a href="accessing-resources.html">Accessing Resources</a></li>
+ <li><a href="{@docRoot}resources/articles/faster-screen-orientation-change.html">Faster Screen
+Orientation Change</a></li>
+ </ol>
+</div>
+</div>
+
+<p>Some device configurations can change during runtime
+(such as screen orientation, keyboard availability, and language). When such a change occurs,
+Android's default behavior is to restart the running
+Activity ({@link android.app.Activity#onDestroy()} is called, followed by {@link
+android.app.Activity#onCreate(Bundle) onCreate()}). In doing so, the system re-queries your
+application resources for alternatives that might apply to the new configuration.</p>
+
+<p>It is important that your Activity safely handles restarts and restores its previous
+state through the normal <a href="{@docRoot}guide/topics/fundamentals.html#lcycles">Activity
+lifecycle</a>. In fact, it's a useful field test to invoke configuration changes (such as changing
+the screen orientation) during various states of your application to be sure that it properly
+restarts itself with the application state intact. So it's in the best interest of your application
+to allow the system to restart your application during any configuration change—this behavior
+is in place to help you by automatically handling configuration changes and adapting your
+application as necessary.</p>
+
+<p>However, you might encounter a situation in which restarting your application and
+restoring significant amounts of data can be costly, create a slow user experience, and
+using {@link android.app.Activity#onSaveInstanceState(Bundle) onSaveInstanceState()} does not
+suffice. In such a situation, you have two options:</p>
+
+<ol type="a">
+ <li><a href="#CarryingAnObject">Carrying an Object During a Configuration Change</a>
+ <p>Allow your
+application to restart so that the appropriate configuration changes can take effect, but also
+implement {@link android.app.Activity#onRetainNonConfigurationInstance()} paired with {@link
+android.app.Activity#getLastNonConfigurationInstance()} to carry an {@link java.lang.Object} over
+to the new instance of your Activity.</p>
+ <p>This is the recommended technique if you're facing performance issues during the
+configuration restart. It allows your Activity to properly restart and reload resources for
+the new configuration and also allows you to carry your arbitrary data that may be expensive to
+collect again.</p>
+ </li>
+ <li><a href="#HandlingTheChange">Handling the Configuration Change Yourself</a>
+ <p>Declare that your
+application will handle certain configuration changes and prevent the system from restarting your
+application when such a change occurs. For example, you can declare in your manifest that your
+Activity will handle configuration changes to the screen orientation. When the orientation
+changes, your Activity will not be restarted and your Activity will receive a call to {@link
+android.app.Activity#onConfigurationChanged(Configuration) onConfigurationChanged()} so that you can
+perform necessary changes based on the new configuration.</p>
+ <p>This technique should be considered a last resort and temporary solution, because not all
+runtime configuration changes can be handled this way—your application will eventually
+encounter a runtime configuration in which you cannot prevent the Activity from being restarted,
+whereas the first option will handle all configuration changes.</p>
+ </li>
+</ol>
+
+<p class="note"><strong>Note:</strong> Your application should always be able to successfully
+restart at any time without any loss of user data or state in order to handle other events such as
+when the user receives an incoming phone call and then returns to your application (read about the
+<a href="{@docRoot}guide/topics/fundamentals.html#lcycles">Activity lifecycle</a>). The following
+techniques for handling runtime configuration changes should only be necessary to optimize
+performance during specific configuration changes.</p>
+
+
+<h2 id="CarryingAnObject">Carrying an Object During a Configuration Change</h2>
+
+<p>If your application has acquired significant amounts of data during its life, which would be
+costly to recover due to a restart of the Activity, you can use {@link
+android.app.Activity#onRetainNonConfigurationInstance()} paired with {@link
+android.app.Activity#getLastNonConfigurationInstance()} to pass an {@link java.lang.Object}
+to the new Activity instance. The {@link android.app.Activity#onRetainNonConfigurationInstance()}
+method is called between {@link android.app.Activity#onStop()} and {@link
+android.app.Activity#onDestroy()} when your Activity is being shut down due to a configuration
+change. In your implementation of this method, you can return any {@link java.lang.Object} that you
+need to efficiently restore your state after the configuration change. When your Activity is
+created again, you can call {@link
+android.app.Activity#getLastNonConfigurationInstance()} to retrieve the {@link
+java.lang.Object}.</p>
+
+<p>A scenario in which this can be valuable is if your application loads a lot of data from the
+web. If the user changes the orientation of the device and the Activity restarts, your application
+will need to re-fetch the data, which could be slow. What you can do is implement
+{@link android.app.Activity#onRetainNonConfigurationInstance()} to return an object carrying your
+data and then retrieve the data when your Activity restarts with {@link
+android.app.Activity#getLastNonConfigurationInstance()}. For example:</p>
+
+<pre>
+@Override
+public Object onRetainNonConfigurationInstance() {
+ final MyDataObject data = collectMyLoadedData();
+ return data;
+}
+</pre>
+
+<p class="caution"><strong>Caution:</strong> While you can return any object, you
+should never pass an object that is tied to the {@link android.app.Activity}, such as a {@link
+android.graphics.drawable.Drawable}, an {@link android.widget.Adapter}, a {@link android.view.View}
+or any other object that's associated with a {@link android.content.Context}. If you do, it will
+leak all the Views and resources of the original Activity instance. (To leak the resources
+means that your application maintains a hold on them and they cannot be garbage-collected, so
+lots of memory can be lost.)</p>
+
+<p>Then get the {@code data} after the restart:</p>
+
+<pre>
+@Override
+public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+
+ final MyDataObject data = (MyDataObject) getLastNonConfigurationInstance();
+ if (data == null) {
+ data = loadMyData();
+ }
+ ...
+}
+</pre>
+
+<p>In this case, {@link android.app.Activity#getLastNonConfigurationInstance()} is called to get
+the data saved during the configuration change, and if it is null (which will happen if the
+Activity is started in any case other than a configuration change) then the data is loaded
+from the original source.</p>
+
+
+
+
+
+<h2 id="HandlingTheChange">Handling the Configuration Change Yourself</h2>
+
+<p>If your application doesn't need to update resources during a specific configuration
+change <em>and</em> you have a performance limitation that requires you to
+avoid the Activity restart, then you can declare that your Activity handles the configuration change
+itself, which will prevent the system from restarting your Activity.</p>
+
+<p class="note"><strong>Note:</strong> Handling the configuration change yourself can make it much
+more difficult to use alternative resources, because the system will not automatically apply them
+for you.</p>
+
+<p>To declare that your Activity handles a configuration change, edit the appropriate <a
+href="{@docRoot}guide/topics/manifest/activity-element.html">{@code <activity>}</a> element
+in your manifest file to include the <a
+href="{@docRoot}guide/topics/manifest/activity-element.html#config">{@code
+android:configChanges}</a> attribute with a string value that represents the configuration that you
+want to handle. Possible values are listed in the documentation for
+the <a href="{@docRoot}guide/topics/manifest/activity-element.html#config">{@code
+android:configChanges}</a> attribute (the most commonly used values are {@code orientation} to
+handle when the screen orientation changes and {@code keyboardHidden} to handle when the
+keyboard availability changes). You can declare multiple configuration values in the attribute
+by separating them with a pipe character ("|").</p>
+
+<p>For example, the following manifest snippet declares an Activity that handles both the
+screen orientation change and keyboard availability change:</p>
+
+<pre>
+<activity android:name=".MyActivity"
+ android:configChanges="orientation|keyboardHidden"
+ android:label="@string/app_name">
+</pre>
+
+<p>Now when one of these configurations change, {@code MyActivity} is not restarted.
+Instead, the Activity receives a call to {@link
+android.app.Activity#onConfigurationChanged(Configuration) onConfigurationChanged()}. This method
+is passed a {@link android.content.res.Configuration} object that specifies
+the new device configuration. By reading fields in the {@link android.content.res.Configuration},
+you can determine the new configuration and make appropriate changes by updating
+the resources used in your interface. At the
+time this method is called, your Activity's {@link android.content.res.Resources} object is updated
+to return resources based on the new configuration, so you can easily
+reset elements of your UI without the system restarting your Activity.</p>
+
+<p>For example, the following {@link
+android.app.Activity#onConfigurationChanged(Configuration) onConfigurationChanged()} implementation
+checks the availability of a hardware keyboard and the current device orientation:</p>
+
+<pre>
+@Override
+public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+
+ // Checks the orientation of the screen
+ if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
+ Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
+ } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
+ Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
+ }
+ // Checks whether a hardware keyboard is available
+ if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
+ Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
+ } else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
+ Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
+ }
+}
+</pre>
+
+<p>The {@link android.content.res.Configuration} object represents all of the current
+configurations, not just the ones that have changed. Most of the time, you won't care exactly how
+the configuration has changed and can simply re-assign all your resources that provide alternatives
+to the configuration that you're handling. For example, because the {@link
+android.content.res.Resources} object is now updated, you can reset
+any {@link android.widget.ImageView}s with {@link android.widget.ImageView#setImageResource(int)}
+and the appropriate resource for the new configuration is used (as described in <a
+href="providing-resources.html#AlternateResources">Providing Resources</a>).</p>
+
+<p>Notice that the values from the {@link
+android.content.res.Configuration} fields are integers that are matched to specific constants
+from the {@link android.content.res.Configuration} class. For documentation about which constants
+to use with each field, refer to the appropriate field in the {@link
+android.content.res.Configuration} reference.</p>
+
+<p class="note"><strong>Remember:</strong> When you declare your Activity to handle a configuration
+change, you are responsible for resetting any elements for which you provide alternatives. If you
+declare your Activity to handle the orientation change and have images that should change
+between landscape and portrait, you must re-assign each resource to each element during {@link
+android.app.Activity#onConfigurationChanged(Configuration) onConfigurationChanged()}.</p>
+
+<p>If you don't need to update your application based on these configuration
+changes, you can instead <em>not</em> implement {@link
+android.app.Activity#onConfigurationChanged(Configuration) onConfigurationChanged()}. In
+which case, all of the resources used before the configuration change are still used
+and you've only avoided the restart of your Activity. However, your application should always be
+able to shutdown and restart with its previous state intact. Not only because
+there are other configuration changes that you cannot prevent from restarting your application but
+also in order to handle events such as when the user receives an incoming phone call and then
+returns to your application.</p>
+
+<p>For more about which configuration changes you can handle in your Activity, see the <a
+href="{@docRoot}guide/topics/manifest/activity-element.html#config">{@code
+android:configChanges}</a> documentation and the {@link android.content.res.Configuration}
+class.</p>
diff --git a/docs/html/guide/topics/resources/string-resource.jd b/docs/html/guide/topics/resources/string-resource.jd
new file mode 100644
index 0000000..81c5d55
--- /dev/null
+++ b/docs/html/guide/topics/resources/string-resource.jd
@@ -0,0 +1,444 @@
+page.title=String Resources
+parent.title=Resource Types
+parent.link=available-resources.html
+@jd:body
+
+<p>A string resource provides text strings for your application
+with optional text styling and formatting. There are three types of resources that can provide
+your application with strings:</p>
+
+<dl>
+ <dt><a href="#String">String</a></dt>
+ <dd>XML resource that provides a single string.</dd>
+ <dt><a href="#StringArray">String Array</a></dt>
+ <dd>XML resource that provides an array of strings.</dd>
+ <dt><a href="#Plurals">Plurals</a></dt>
+ <dd>XML resource that carries different strings for different pluralizations
+ of the same word or phrase.</dd>
+</dl>
+
+<p>All strings are capable of applying some styling markup and formatting arguments. For
+information about styling and formatting strings, see the section about <a
+href="#FormattingAndStyling">Formatting and Styling</a>.</p>
+
+
+
+
+<h2 id="String">String</h2>
+
+<p>A single string that can be referenced from the application or from other resource files (such
+as an XML layout).</p>
+
+<p class="note"><strong>Note:</strong> A string is a simple resource that is referenced
+using the value provided in the {@code name} attribute (not the name of the XML file). So, you can
+combine string resources with other simple resources in the one XML file,
+under one {@code <resources>} element.</p>
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/values/<em>filename</em>.xml</code><br/>
+The filename is arbitrary. The {@code <string>} element's {@code name} will be used as the
+resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to a {@link java.lang.String}.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.string.<em>string_name</em></code><br/>
+In XML:<code>@string/<em>string_name</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#string-resources-element">resources</a>>
+ <<a href="#string-element">string</a>
+ name="<em>string_name</em>"
+ ><em>text_string</em></string>
+</resources>
+</pre>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+<dl class="tag-list">
+
+ <dt id="string-resources-element"><code><resources></code></dt>
+ <dd><strong>Required.</strong> This must be the root node.
+ <p>No attributes.</p>
+ </dd>
+ <dt id="string-element"><code><string></code></dt>
+ <dd>A string, which can include styling tags. Beware that you must escape apostrophes and
+quotation marks. For more information about how to properly style and format your strings see <a
+href="#FormattingAndStyling">Formatting and Styling</a>, below.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>name</code></dt>
+ <dd><em>String</em>. A name for the string. This name will be used as the resource
+ID.</dd>
+ </dl>
+ </dd>
+
+</dl>
+</dd> <!-- end elements and attributes -->
+
+<dt>example:</dt>
+<dd>XML file saved at <code>res/values/strings.xml</code>:
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="hello">Hello!</string>
+</resources>
+</pre>
+
+ <p>This layout XML applies a string to a View:</p>
+<pre>
+<TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ <strong>android:text="@string/hello"</strong> />
+</pre>
+
+ <p>This application code retrieves a string:</p>
+<pre>
+String string = {@link android.content.Context#getString(int) getString}(R.string.hello);
+</pre>
+<p>You can use either {@link android.content.Context#getString(int)} or
+{@link android.content.Context#getText(int)} to retieve a string. {@link
+android.content.Context#getText(int)} will retain any rich text styling applied to the string.</p>
+
+</dd> <!-- end example -->
+
+</dl>
+
+
+
+
+
+
+
+
+
+<h2 id="StringArray">String Array</h2>
+
+<p>An array of strings that can be referenced from the application.</p>
+
+<p class="note"><strong>Note:</strong> A string array is a simple resource that is referenced
+using the value provided in the {@code name} attribute (not the name of the XML file). As
+such, you can combine string array resources with other simple resources in the one XML file,
+under one {@code <resources>} element.</p>
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/values/<em>filename</em>.xml</code><br/>
+The filename is arbitrary. The {@code <string-array>} element's {@code name} will be used as the
+resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to an array of {@link java.lang.String}s.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.array.<em>string_array_name</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#string-array-resources-element">resources</a>>
+ <<a href="#string-array-element">string-array</a>
+ name="<em>string_array_name</em>">
+ <<a href="#string-array-item-element">item</a>
+ ><em>text_string</em></item>
+ </string-array>
+</resources>
+</pre>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+<dl class="tag-list">
+ <dt id="string-array-resources-element"><code><resources></code></dt>
+ <dd><strong>Required.</strong> This must be the root node.
+ <p>No attributes.</p>
+ </dd>
+ <dt id="string-array-element"><code><string-array></code></dt>
+ <dd>Defines an array of strings. Contains one or more {@code <item>} elements.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>name</code></dt>
+ <dd><em>String</em>. A name for the array. This name will be used as the resource
+ID to reference the array.</dd>
+ </dl>
+
+ </dd>
+ <dt id="string-array-item-element"><code><item></code></dt>
+ <dd>A string, which can include styling tags. The value can be a referenced to another
+string resource. Must be a child of a {@code <string-array>} element. Beware that you
+must escape apostrophes and
+quotation marks. See <a href="#FormattingAndStyling">Formatting and Styling</a>, below, for
+information about to properly style and format your strings.
+ <p>No attributes.</p>
+ </dd>
+</dl>
+</dd> <!-- end elements -->
+
+<dt>example:</dt>
+<dd>XML file saved at <code>res/values/strings.xml</code>:
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string-array name="planets_array">
+ <item>Mercury</item>
+ <item>Venus</item>
+ <item>Earth</item>
+ <item>Mars</item>
+ </string-array>
+</resources>
+</pre>
+
+ <p>This application code retrieves a string array:</p>
+<pre>
+Resources res = {@link android.content.Context#getResources()};
+String[] planets = res.{@link android.content.res.Resources#getStringArray(int)
+getStringArray}(R.array.planets_array);
+</pre>
+</dd> <!-- end example -->
+
+</dl>
+
+
+
+
+
+
+
+<h2 id="Plurals">Plurals</h2>
+
+<p>A pair of strings that each provide a different plural form of the same word or phrase,
+which you can collectively reference from the application. When you request the plurals
+resource using a method such as {@link android.content.res.Resources#getQuantityString(int,int)
+getQuantityString()}, you must pass a "count", which will determine the plural form you
+require and return that string to you.</p>
+
+<p class="note"><strong>Note:</strong> A plurals collection is a simple resource that is
+referenced using the value provided in the {@code name} attribute (not the name of the XML
+file). As such, you can combine plurals resources with other simple resources in the one
+XML file, under one {@code <resources>} element.</p>
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/values/<em>filename</em>.xml</code><br/>
+The filename is arbitrary. The {@code <plurals>} element's {@code name} will be used as the
+resource ID.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.plurals.<em>plural_name</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#plurals-resources-element">resources</a>>
+ <<a href="#plurals-element">plurals</a>
+ name="<em>plural_name</em>">
+ <<a href="#plurals-item-element">item</a>
+ quantity=["one" | "other"]
+ ><em>text_string</em></item>
+ </plurals>
+</resources>
+</pre>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+<dl class="tag-list">
+
+ <dt id="plurals-resources-element"><code><resources></code></dt>
+ <dd><strong>Required.</strong> This must be the root node.
+ <p>No attributes.</p>
+ </dd>
+ <dt id="plurals-element"><code><plurals></code></dt>
+ <dd>A collection of strings, of which, one string is provided depending on the amount of
+something. Contains one or more {@code <item>} elements.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>name</code></dt>
+ <dd><em>String</em>. A name for the pair of strings. This name will be used as the
+resource ID.</dd>
+ </dl>
+
+ </dd>
+ <dt id="plurals-item-element"><code><item></code></dt>
+ <dd>A plural or singular string. The value can be a referenced to another
+string resource. Must be a child of a {@code <plurals>} element. Beware that you must
+escape apostrophes and quotation marks. See <a href="#FormattingAndStyling">Formatting and
+Styling</a>, below, for information about to properly style and format your strings.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>quantity</code></dt>
+ <dd><em>Keyword</em>. A value indicating the case in which this string should be used. Valid
+values:
+ <table>
+ <tr><th>Value</th><th>Description</th></tr>
+ <tr>
+ <td>{@code one}</td><td>When there is one (a singular string).</td>
+ </tr>
+ <tr>
+ <td>{@code other}</td><td>When the quantity is anything other than one (a plural
+string, but also used when the count is zero).</td>
+ </tr>
+ </table>
+ </dd>
+ </dl>
+ </dd>
+
+</dl>
+</dd> <!-- end elements -->
+
+<dt>example:</dt>
+<dd>XML file saved at {@code res/values/strings.xml}:</p>
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <plurals name="numberOfSongsAvailable">
+ <item quantity="one">One song found.</item>
+ <item quantity="other">%d songs found.</item>
+ </plurals>
+</resources>
+</pre>
+ <p>Java code:</p>
+<pre>
+int count = getNumberOfsongsAvailable();
+Resources res = {@link android.content.Context#getResources()};
+String songsFound = res.{@link android.content.res.Resources#getQuantityString(int,int)
+getQuantityString}(R.plurals.numberOfSongsAvailable, count);
+</pre>
+</dd> <!-- end example -->
+
+</dl>
+
+
+
+
+
+
+
+
+<h2 id="FormattingAndStyling">Formatting and Styling</h2>
+
+<p>Here are a few important things you should know about how to properly
+format and style your string resources.</p>
+
+
+<h3>Escaping apostrophes and quotes</h3>
+
+<p>If you have an apostrophe or a quote in your string, you must either escape it or enclose the
+whole string in the other type of enclosing quotes. For example, here are some stings that
+do and don't work:</p>
+
+<pre>
+<string name="good_example">"This'll work"</string>
+<string name="good_example_2">This\'ll also work</string>
+<string name="bad_example">This doesn't work</string>
+<string name="bad_example_2">XML encodings don&apos;t work</string>
+</pre>
+
+
+<h3>Formatting strings</h3>
+
+<p>If you need to format your strings using <a
+href="{@docRoot}reference/java/lang/String.html#format(java.lang.String,
+java.lang.Object...)">{@code String.format(String, Object...)}</a>,
+then you can do so by putting
+your format arguments in the string resource. For example, with the following resource:</p>
+
+<pre>
+<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>
+</pre>
+
+<p>In this example, the format string has two arguments: {@code %1$s} is a string and {@code %2$d}
+is a decimal number. You can format the string with arguements from your application like this:</p>
+
+<pre>
+Resources res = {@link android.content.Context#getResources()};
+String text = String.<a href="{@docRoot}reference/java/lang/String.html#format(java.lang.String,
+java.lang.Object...)">format</a>(res.getString(R.string.welcome_messages), username, mailCount);
+</pre>
+
+
+
+<h3>Styling with HTML markup</h3>
+
+<p>You can add styling to your strings with HTML markup. For example:</p>
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="welcome">Welcome to <b>Android</b>!</string>
+</resources>
+</pre>
+<p>Supported HTML elements include:</p>
+<ul>
+ <li>{@code <b>} for <b>bold</b> text.</li>
+ <li>{@code <i>} for <i>italic</i> text.</li>
+ <li>{@code <u>} for <u>underline</u> text.</li>
+</ul>
+
+<p>Sometimes you may want to create a styled text resource that is also used as a format
+string. Normally, this won't work because the <a
+href="{@docRoot}reference/java/lang/String.html#format(java.lang.String,
+java.lang.Object...)">{@code String.format(String, Object...)}</a>
+method will strip all the style
+information from the string. The work-around to this is to write the HTML tags with escaped
+entities, which are then recovered with {@link android.text.Html#fromHtml(String)},
+after the formatting takes place. For example:</p>
+
+<ol>
+ <li>Store your styled text resource as an HTML-escaped string:
+<pre>
+<resources>
+ <string name="welcome_messages">Hello, %1$s! You have &lt;b>%2$d new messages&lt;/b>.</string>
+</resources>
+</pre>
+<p>In this formatted string, a {@code <b>} element is added. Notice that the opening bracket is
+HTML-escaped, using the {@code &lt;} notation.</p>
+ </li>
+ <li>Then format the string as usual, but also call {@link android.text.Html#fromHtml} to
+convert the HTML text into styled text:
+<pre>
+Resources res = {@link android.content.Context#getResources()};
+String text = String.<a
+href="{@docRoot}reference/java/lang/String.html#format(java.lang.String,
+java.lang.Object...)">format</a>(res.getString(R.string.welcome_messages), username, mailCount);
+CharSequence styledText = Html.fromHtml(text);
+</pre>
+ </li>
+</ol>
+
+<p>Because the {@link android.text.Html#fromHtml} method will format all HTML entities, be sure to
+escape any possible HTML characters in the strings you use with the formatted text, using
+{@link android.text.TextUtils#htmlEncode}. For instance, if you'll be passing a string argument to
+<a href="{@docRoot}reference/java/lang/String.html#format(java.lang.String,
+java.lang.Object...)">{@code String.format()}</a> that may contain characters such as
+"<" or "&", then they must be escaped before formatting, so that when the formatted string
+is passed through {@link android.text.Html#fromHtml}, the characters come out the way they were
+originally written. For example:</p>
+<pre>
+String escapedUsername = TextUtil.{@link android.text.TextUtils#htmlEncode htmlEncode}(username);
+
+Resources res = {@link android.content.Context#getResources()};
+String text = String.<a href="{@docRoot}reference/java/lang/String.html#format(java.lang.String,
+java.lang.Object...)">format</a>(res.getString(R.string.welcome_messages), escapedUsername, mailCount);
+CharSequence styledText = Html.fromHtml(text);
+</pre>
+
+
+
diff --git a/docs/html/guide/topics/resources/style-resource.jd b/docs/html/guide/topics/resources/style-resource.jd
new file mode 100644
index 0000000..def727c
--- /dev/null
+++ b/docs/html/guide/topics/resources/style-resource.jd
@@ -0,0 +1,128 @@
+page.title=Style Resource
+parent.title=Resource Types
+parent.link=available-resources.html
+@jd:body
+
+<div id="qv-wrapper">
+ <div id="qv">
+ <h2>See also</h2>
+ <ol>
+ <li><a href="{@docRoot}guide/topics/ui/themes.html">Applying Styles and Themes</a></li>
+ </ol>
+ </div>
+</div>
+
+
+<p>A style resource defines the format and look for a UI.
+A style can be applied to an individual {@link android.view.View} (from within a layout file) or to
+an entire {@link android.app.Activity} or application (from within the manifest file).</p>
+
+<p>For more information about creating and applying styles, please read
+<a href="{@docRoot}guide/topics/ui/themes.html">Applying Styles and Themes</a>.</p>
+
+<p class="note"><strong>Note:</strong> A style is a simple resource that is referenced
+using the value provided in the {@code name} attribute (not the name of the XML file). As
+such, you can combine style resources with other simple resources in the one XML file,
+under one {@code <resources>} element.</p>
+
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/values/<em>filename</em>.xml</code><br/>
+The filename is arbitrary. The element's {@code name} will be used as the resource ID.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In XML: <code>@[package:]style/<em>style_name</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+<?xml version="1.0" encoding="utf-8"?>
+<<a href="#resources-element">resources</a>>
+ <<a href="#style-element">style</a>
+ name="<em>style_name</em>"
+ parent="@[package:]style/<em>style_to_inherit</em>">
+ <<a href="#item-element">item</a>
+ name="<em>[package:]style_property_name</em>"
+ ><em>style_value</em></item>
+ </style>
+</resources>
+</pre>
+</dd>
+
+<dt>elements:</dt>
+<dd>
+<dl class="tag-list">
+
+ <dt id="resources-element"><code><resources></code></dt>
+ <dd><strong>Required.</strong> This must be the root node.
+ <p>No attributes.</p>
+ </dd>
+ <dt id="style-element"><code><style></code></dt>
+ <dd>Defines a single style. Contains {@code <item>} elements.
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>name</code></dt>
+ <dd><em>String</em>. <strong>Required</strong>. A name for the style, which is used as the
+resource ID to apply the style to a View, Activity, or application.
+ </dd>
+ <dt><code>parent</code></dt>
+ <dd><em>Style resource</em>. Reference to a style from which this
+style should inherit style properties.
+ </dd>
+ </dl>
+
+ </dd>
+ <dt id="item-element"><code><item></code></dt>
+ <dd>Defines a single property for the style. Must be a child of a
+ <code><style></code> element.</p>
+ <p class="caps">attributes:</p>
+ <dl class="atn-list">
+ <dt><code>name</code></dt>
+ <dd><em>Attribute resource</em>. <strong>Required</strong>. The name of the style property
+to be defined, with a package prefix if necessary (for example {@code android:textColor}).
+ </dd>
+ </dl>
+ </dd>
+
+</dl>
+</dd> <!-- end elements and attributes -->
+
+<dt>example:</dt>
+<dd>
+ <dl>
+
+ <dt>XML file for the style (saved in <code>res/values/</code>):</dt>
+ <dd>
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <style name="CustomText" parent="@style/Text">
+ <item name="android:textSize">20sp</item>
+ <item name="android:textColor">#008</item>
+ </style>
+</resources>
+</pre>
+ </dd>
+
+ <dt>XML file that applies the style to a {@link android.widget.TextView}
+ (saved in <code>res/layout/</code>):</dt>
+ <dd>
+<pre>
+<?xml version="1.0" encoding="utf-8"?>
+<EditText
+ style="@style/CustomText"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="Hello, World!" />
+</pre>
+ </dd>
+
+ </dl>
+</dd> <!-- end example -->
+
+</dl>
+
+
diff --git a/docs/html/images/resources/resource_devices_diagram1.png b/docs/html/images/resources/resource_devices_diagram1.png
new file mode 100644
index 0000000..adbdab6
--- /dev/null
+++ b/docs/html/images/resources/resource_devices_diagram1.png
Binary files differ
diff --git a/docs/html/images/resources/resource_devices_diagram2.png b/docs/html/images/resources/resource_devices_diagram2.png
new file mode 100644
index 0000000..403dd4f
--- /dev/null
+++ b/docs/html/images/resources/resource_devices_diagram2.png
Binary files differ
diff --git a/docs/html/sdk/installing.jd b/docs/html/sdk/installing.jd
index abf36c7..1099c3c 100644
--- a/docs/html/sdk/installing.jd
+++ b/docs/html/sdk/installing.jd
@@ -529,7 +529,7 @@
<code>apt-get:</code>:
<pre>apt-get install ia32-libs</pre>
</li>
- <li>Next, install Java: <pre>apt-get install sun-java6-bin</pre></li>
+ <li>Next, install Java: <pre>apt-get install sun-java6-jdk</pre></li>
<li>The Ubuntu package manager does not currently offer an Eclipse 3.3
version for download, so we recommend that you download Eclipse from
eclipse.org (<a
diff --git a/include/camera/CameraParameters.h b/include/camera/CameraParameters.h
index a7568d7..3b0e9e5 100644
--- a/include/camera/CameraParameters.h
+++ b/include/camera/CameraParameters.h
@@ -289,6 +289,9 @@
static const char SCENE_MODE_SPORTS[];
static const char SCENE_MODE_PARTY[];
static const char SCENE_MODE_CANDLELIGHT[];
+ // Applications are looking for a barcode. Camera driver will be optimized
+ // for barcode reading.
+ static const char SCENE_MODE_BARCODE[];
// Formats for setPreviewFormat and setPictureFormat.
static const char PIXEL_FORMAT_YUV422SP[];
@@ -309,6 +312,10 @@
// focus, which is usually at hyperfocal distance. Applications should
// not call CameraHardwareInterface.autoFocus in this mode.
static const char FOCUS_MODE_FIXED[];
+ // Extended depth of field (EDOF). Focusing is done digitally and
+ // continuously. Applications should not call
+ // CameraHardwareInterface.autoFocus in this mode.
+ static const char FOCUS_MODE_EDOF[];
private:
DefaultKeyedVector<String8,String8> mMap;
diff --git a/include/media/stagefright/HTTPDataSource.h b/include/media/stagefright/HTTPDataSource.h
index 83be475..ea31942 100644
--- a/include/media/stagefright/HTTPDataSource.h
+++ b/include/media/stagefright/HTTPDataSource.h
@@ -77,9 +77,6 @@
int mStartingPort;
HTTPStream *mHttp;
- char *mHost;
- int mPort;
- char *mPath;
void *mBuffer;
size_t mBufferLength;
@@ -95,6 +92,8 @@
ssize_t sendRangeRequest(size_t offset);
void initHeaders(const KeyedVector<String8, String8> *overrides);
+ status_t connectWithRedirectsAndRange(off_t rangeStart);
+
HTTPDataSource(const HTTPDataSource &);
HTTPDataSource &operator=(const HTTPDataSource &);
};
diff --git a/include/media/stagefright/MediaDefs.h b/include/media/stagefright/MediaDefs.h
index 1efeb92..3f8bc51 100644
--- a/include/media/stagefright/MediaDefs.h
+++ b/include/media/stagefright/MediaDefs.h
@@ -31,6 +31,7 @@
extern const char *MEDIA_MIMETYPE_AUDIO_AMR_WB;
extern const char *MEDIA_MIMETYPE_AUDIO_MPEG;
extern const char *MEDIA_MIMETYPE_AUDIO_AAC;
+extern const char *MEDIA_MIMETYPE_AUDIO_QCELP;
extern const char *MEDIA_MIMETYPE_AUDIO_RAW;
extern const char *MEDIA_MIMETYPE_CONTAINER_MPEG4;
diff --git a/libs/audioflinger/AudioFlinger.cpp b/libs/audioflinger/AudioFlinger.cpp
index 7166c89..2414e8d 100644
--- a/libs/audioflinger/AudioFlinger.cpp
+++ b/libs/audioflinger/AudioFlinger.cpp
@@ -1867,7 +1867,7 @@
// The first time a track is added we wait
// for all its buffers to be filled before processing it
if (cblk->framesReady() && (track->isReady() || track->isStopped()) &&
- !track->isPaused())
+ !track->isPaused() && !track->isTerminated())
{
//LOGV("track %d u=%08x, s=%08x [OK]", track->name(), cblk->user, cblk->server);
diff --git a/libs/camera/CameraParameters.cpp b/libs/camera/CameraParameters.cpp
index 76a9715..b50d4d2 100644
--- a/libs/camera/CameraParameters.cpp
+++ b/libs/camera/CameraParameters.cpp
@@ -122,6 +122,7 @@
const char CameraParameters::SCENE_MODE_SPORTS[] = "sports";
const char CameraParameters::SCENE_MODE_PARTY[] = "party";
const char CameraParameters::SCENE_MODE_CANDLELIGHT[] = "candlelight";
+const char CameraParameters::SCENE_MODE_BARCODE[] = "barcode";
// Formats for setPreviewFormat and setPictureFormat.
const char CameraParameters::PIXEL_FORMAT_YUV422SP[] = "yuv422sp";
@@ -135,6 +136,7 @@
const char CameraParameters::FOCUS_MODE_INFINITY[] = "infinity";
const char CameraParameters::FOCUS_MODE_MACRO[] = "macro";
const char CameraParameters::FOCUS_MODE_FIXED[] = "fixed";
+const char CameraParameters::FOCUS_MODE_EDOF[] = "edof";
CameraParameters::CameraParameters()
: mMap()
diff --git a/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp b/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp
index 5969617..ea68352 100644
--- a/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp
+++ b/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp
@@ -90,6 +90,8 @@
int DisplayHardware::getWidth() const { return mWidth; }
int DisplayHardware::getHeight() const { return mHeight; }
PixelFormat DisplayHardware::getFormat() const { return mFormat; }
+uint32_t DisplayHardware::getMaxTextureSize() const { return mMaxTextureSize; }
+uint32_t DisplayHardware::getMaxViewportDims() const { return mMaxViewportDims; }
void DisplayHardware::init(uint32_t dpy)
{
@@ -246,6 +248,11 @@
LOGI("version : %s", glGetString(GL_VERSION));
LOGI("extensions: %s", gl_extensions);
+ glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
+ glGetIntegerv(GL_MAX_VIEWPORT_DIMS, &mMaxViewportDims);
+ LOGI("GL_MAX_TEXTURE_SIZE = %d", mMaxTextureSize);
+ LOGI("GL_MAX_VIEWPORT_DIMS = %d", mMaxViewportDims);
+
#if 0
// for drivers that don't have proper support for flushing cached buffers
// on gralloc unlock, uncomment this block and test for the specific
@@ -273,6 +280,7 @@
#warning "EGL_ANDROID_image_native_buffer not supported"
#endif
+
// Unbind the context from this thread
eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
diff --git a/libs/surfaceflinger/DisplayHardware/DisplayHardware.h b/libs/surfaceflinger/DisplayHardware/DisplayHardware.h
index 6914d0c..df046af 100644
--- a/libs/surfaceflinger/DisplayHardware/DisplayHardware.h
+++ b/libs/surfaceflinger/DisplayHardware/DisplayHardware.h
@@ -76,6 +76,8 @@
PixelFormat getFormat() const;
uint32_t getFlags() const;
void makeCurrent() const;
+ uint32_t getMaxTextureSize() const;
+ uint32_t getMaxViewportDims() const;
uint32_t getPageFlipCount() const;
EGLDisplay getEGLDisplay() const { return mDisplay; }
@@ -104,6 +106,8 @@
PixelFormat mFormat;
uint32_t mFlags;
mutable uint32_t mPageFlipCount;
+ GLint mMaxViewportDims;
+ GLint mMaxTextureSize;
sp<FramebufferNativeWindow> mNativeWindow;
overlay_control_device_t* mOverlayEngine;
diff --git a/libs/surfaceflinger/Layer.cpp b/libs/surfaceflinger/Layer.cpp
index 4dc4a15..0a3254d 100644
--- a/libs/surfaceflinger/Layer.cpp
+++ b/libs/surfaceflinger/Layer.cpp
@@ -41,6 +41,10 @@
namespace android {
+template <typename T> inline T min(T a, T b) {
+ return a<b ? a : b;
+}
+
// ---------------------------------------------------------------------------
const uint32_t Layer::typeInfo = LayerBaseClient::typeInfo | 4;
@@ -109,17 +113,26 @@
// the display's pixel format
const DisplayHardware& hw(graphicPlane(0).displayHardware());
+ uint32_t const maxSurfaceDims = min(
+ hw.getMaxTextureSize(), hw.getMaxViewportDims());
+
+ // never allow a surface larger than what our underlying GL implementation
+ // can handle.
+ if ((uint32_t(w)>maxSurfaceDims) || (uint32_t(h)>maxSurfaceDims)) {
+ return BAD_VALUE;
+ }
+
PixelFormatInfo displayInfo;
getPixelFormatInfo(hw.getFormat(), &displayInfo);
const uint32_t hwFlags = hw.getFlags();
mFormat = format;
- mWidth = w;
+ mWidth = w;
mHeight = h;
mSecure = (flags & ISurfaceComposer::eSecure) ? true : false;
mNeedsBlending = (info.h_alpha - info.l_alpha) > 0;
mNoEGLImageForSwBuffers = !(hwFlags & DisplayHardware::CACHED_BUFFERS);
-
+
// we use the red index
int displayRedSize = displayInfo.getSize(PixelFormatInfo::INDEX_RED);
int layerRedsize = info.getSize(PixelFormatInfo::INDEX_RED);
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index 2b7683a..a38be48 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -102,6 +102,9 @@
private static final int MSG_MEDIA_SERVER_DIED = 5;
private static final int MSG_MEDIA_SERVER_STARTED = 6;
private static final int MSG_PLAY_SOUND_EFFECT = 7;
+ private static final int MSG_BTA2DP_DOCK_TIMEOUT = 8;
+
+ private static final int BTA2DP_DOCK_TIMEOUT_MILLIS = 8000;
/** @see AudioSystemThread */
private AudioSystemThread mAudioSystemThread;
@@ -489,27 +492,19 @@
// If stream is muted, set last audible index only
if (streamState.muteCount() != 0) {
- streamState.setLastAudibleIndex(index);
- // Post a persist volume msg
- sendMsg(mAudioHandler, MSG_PERSIST_VOLUME, streamType,
- SENDMSG_REPLACE, 0, 1, streamState, PERSIST_DELAY);
+ // Do not allow last audible index to be 0
+ if (index != 0) {
+ streamState.setLastAudibleIndex(index);
+ // Post a persist volume msg
+ sendMsg(mAudioHandler, MSG_PERSIST_VOLUME, streamType,
+ SENDMSG_REPLACE, 0, 1, streamState, PERSIST_DELAY);
+ }
} else {
if (streamState.setIndex(index, lastAudible) || force) {
// Post message to set system volume (it in turn will post a message
// to persist).
- // If we are in silent mode and stream is affected by ringer mode
- // and the new volume is not 0, just persist the new volume but do not change
- // current value
- if (mRingerMode == AudioManager.RINGER_MODE_NORMAL ||
- !isStreamAffectedByRingerMode(streamType) ||
- index == 0) {
- sendMsg(mAudioHandler, MSG_SET_SYSTEM_VOLUME, streamType, SENDMSG_NOOP, 0, 0,
- streamState, 0);
- } else {
- // Post a persist volume msg
- sendMsg(mAudioHandler, MSG_PERSIST_VOLUME, streamType,
- SENDMSG_REPLACE, 0, 1, streamState, PERSIST_DELAY);
- }
+ sendMsg(mAudioHandler, MSG_SET_SYSTEM_VOLUME, streamType, SENDMSG_NOOP, 0, 0,
+ streamState, 0);
}
}
}
@@ -601,10 +596,8 @@
return mRingerMode == AudioManager.RINGER_MODE_VIBRATE;
case AudioManager.VIBRATE_SETTING_OFF:
- // Phone ringer should always vibrate in vibrate mode
- if (vibrateType == AudioManager.VIBRATE_TYPE_RINGER) {
- return mRingerMode == AudioManager.RINGER_MODE_VIBRATE;
- }
+ // return false, even for incoming calls
+ return false;
default:
return false;
@@ -1127,6 +1120,9 @@
if (direction == AudioManager.ADJUST_RAISE) {
// exiting silent mode
newRingerMode = AudioManager.RINGER_MODE_NORMAL;
+ } else {
+ // prevent last audible index to reach 0
+ adjustVolumeIndex = false;
}
}
@@ -1653,6 +1649,11 @@
case MSG_PLAY_SOUND_EFFECT:
playSoundEffect(msg.arg1, msg.arg2);
break;
+
+ case MSG_BTA2DP_DOCK_TIMEOUT:
+ // msg.obj == address of BTA2DP device
+ makeA2dpDeviceUnavailableNow( (String) msg.obj );
+ break;
}
}
}
@@ -1707,6 +1708,38 @@
}
}
+ private void makeA2dpDeviceAvailable(String address) {
+ AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
+ AudioSystem.DEVICE_STATE_AVAILABLE,
+ address);
+ // Reset A2DP suspend state each time a new sink is connected
+ AudioSystem.setParameters("A2dpSuspended=false");
+ mConnectedDevices.put( new Integer(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP),
+ address);
+ }
+
+ private void makeA2dpDeviceUnavailableNow(String address) {
+ Intent noisyIntent = new Intent(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
+ mContext.sendBroadcast(noisyIntent);
+ AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
+ AudioSystem.DEVICE_STATE_UNAVAILABLE,
+ address);
+ mConnectedDevices.remove(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP);
+ }
+
+ private void makeA2dpDeviceUnavailableLater(String address) {
+ // the device will be made unavailable later, so consider it disconnected right away
+ mConnectedDevices.remove(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP);
+ // send the delayed message to make the device unavailable later
+ Message msg = mAudioHandler.obtainMessage(MSG_BTA2DP_DOCK_TIMEOUT, address);
+ mAudioHandler.sendMessageDelayed(msg, BTA2DP_DOCK_TIMEOUT_MILLIS);
+
+ }
+
+ private void cancelA2dpDeviceTimeout(String address) {
+ mAudioHandler.removeMessages(MSG_BTA2DP_DOCK_TIMEOUT);
+ }
+
/**
* Receiver for misc intent broadcasts the Phone app cares about.
*/
@@ -1741,20 +1774,25 @@
if (isConnected &&
state != BluetoothA2dp.STATE_CONNECTED && state != BluetoothA2dp.STATE_PLAYING) {
- AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
- AudioSystem.DEVICE_STATE_UNAVAILABLE,
- address);
- mConnectedDevices.remove(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP);
+ if (btDevice.isBluetoothDock()) {
+ if (state == BluetoothA2dp.STATE_DISCONNECTED) {
+ // introduction of a delay for transient disconnections of docks when
+ // power is rapidly turned off/on, this message will be canceled if
+ // we reconnect the dock under a preset delay
+ makeA2dpDeviceUnavailableLater(address);
+ // the next time isConnected is evaluated, it will be false for the dock
+ }
+ } else {
+ makeA2dpDeviceUnavailableNow(address);
+ }
} else if (!isConnected &&
(state == BluetoothA2dp.STATE_CONNECTED ||
state == BluetoothA2dp.STATE_PLAYING)) {
- AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
- AudioSystem.DEVICE_STATE_AVAILABLE,
- address);
- // Reset A2DP suspend state each time a new sink is connected
- AudioSystem.setParameters("A2dpSuspended=false");
- mConnectedDevices.put( new Integer(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP),
- address);
+ if (btDevice.isBluetoothDock()) {
+ // this could be a reconnection after a transient disconnection
+ cancelA2dpDeviceTimeout(address);
+ }
+ makeA2dpDeviceAvailable(address);
}
} else if (action.equals(BluetoothHeadset.ACTION_STATE_CHANGED)) {
int state = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE,
@@ -2090,14 +2128,18 @@
Log.i(TAG, " AudioFocus abandonAudioFocus() from " + clientId);
// this will take care of notifying the new focus owner if needed
- removeFocusStackEntry(clientId, true);
+ synchronized(mFocusStack) {
+ removeFocusStackEntry(clientId, true);
+ }
return AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
}
public void unregisterAudioFocusClient(String clientId) {
- removeFocusStackEntry(clientId, false);
+ synchronized(mFocusStack) {
+ removeFocusStackEntry(clientId, false);
+ }
}
diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp
index 594e010..a6d8d2c 100644
--- a/media/libmediaplayerservice/MediaPlayerService.cpp
+++ b/media/libmediaplayerservice/MediaPlayerService.cpp
@@ -747,6 +747,11 @@
}
}
+ // Use PV_PLAYER for rtsp for now
+ if (!strncasecmp(url, "rtsp://", 7)) {
+ return PV_PLAYER;
+ }
+
return getDefaultPlayerType();
}
diff --git a/media/libstagefright/AudioPlayer.cpp b/media/libstagefright/AudioPlayer.cpp
index 005c64a..bcf2463 100644
--- a/media/libstagefright/AudioPlayer.cpp
+++ b/media/libstagefright/AudioPlayer.cpp
@@ -102,7 +102,7 @@
(numChannels == 2)
? AudioSystem::CHANNEL_OUT_STEREO
: AudioSystem::CHANNEL_OUT_MONO,
- 8192, 0, &AudioCallback, this, 0);
+ 0, 0, &AudioCallback, this, 0);
if ((err = mAudioTrack->initCheck()) != OK) {
delete mAudioTrack;
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 63dfa67..b14a03c 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -444,6 +444,8 @@
notifyListener_l(MEDIA_BUFFERING_UPDATE, percentage * 100.0);
postBufferingEvent_l();
+ } else {
+ LOGE("Not sending buffering status because duration is unknown.");
}
}
@@ -552,8 +554,6 @@
seekAudioIfNecessary_l();
}
- postBufferingEvent_l();
-
if (mFlags & AT_EOS) {
// Legacy behaviour, if a stream finishes playing and then
// is started again, we play from the start...
@@ -763,9 +763,14 @@
mDurationUs = durationUs;
}
}
- }
- mAudioSource->start();
+ mAudioSource->start();
+ } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_QCELP)) {
+ // For legacy reasons we're simply going to ignore the absence
+ // of an audio decoder for QCELP instead of aborting playback
+ // altogether.
+ return OK;
+ }
return mAudioSource != NULL ? OK : UNKNOWN_ERROR;
}
@@ -1225,6 +1230,8 @@
mFlags |= PREPARED;
mAsyncPrepareEvent = NULL;
mPreparedCondition.broadcast();
+
+ postBufferingEvent_l();
}
status_t AwesomePlayer::suspend() {
@@ -1232,7 +1239,19 @@
Mutex::Autolock autoLock(mLock);
if (mSuspensionState != NULL) {
- return INVALID_OPERATION;
+ if (mLastVideoBuffer == NULL) {
+ //go into here if video is suspended again
+ //after resuming without being played between
+ //them
+ SuspensionState *state = mSuspensionState;
+ mSuspensionState = NULL;
+ reset_l();
+ mSuspensionState = state;
+ return OK;
+ }
+
+ delete mSuspensionState;
+ mSuspensionState = NULL;
}
if (mFlags & PREPARING) {
@@ -1337,7 +1356,7 @@
play_l();
}
- delete state;
+ mSuspensionState = state;
state = NULL;
return OK;
diff --git a/media/libstagefright/ESDS.cpp b/media/libstagefright/ESDS.cpp
index 28d338c..b7c8e0c 100644
--- a/media/libstagefright/ESDS.cpp
+++ b/media/libstagefright/ESDS.cpp
@@ -25,7 +25,8 @@
mSize(size),
mInitCheck(NO_INIT),
mDecoderSpecificOffset(0),
- mDecoderSpecificLength(0) {
+ mDecoderSpecificLength(0),
+ mObjectTypeIndication(0) {
memcpy(mData, data, size);
mInitCheck = parse();
@@ -40,6 +41,16 @@
return mInitCheck;
}
+status_t ESDS::getObjectTypeIndication(uint8_t *objectTypeIndication) const {
+ if (mInitCheck != OK) {
+ return mInitCheck;
+ }
+
+ *objectTypeIndication = mObjectTypeIndication;
+
+ return OK;
+}
+
status_t ESDS::getCodecSpecificInfo(const void **data, size_t *size) const {
if (mInitCheck != OK) {
return mInitCheck;
@@ -164,6 +175,8 @@
return ERROR_MALFORMED;
}
+ mObjectTypeIndication = mData[offset];
+
offset += 13;
size -= 13;
diff --git a/media/libstagefright/HTTPDataSource.cpp b/media/libstagefright/HTTPDataSource.cpp
index 48f8e7a..a0b1993 100644
--- a/media/libstagefright/HTTPDataSource.cpp
+++ b/media/libstagefright/HTTPDataSource.cpp
@@ -29,74 +29,101 @@
namespace android {
-// Given a connected HTTPStream, determine if the given path redirects
-// somewhere else, if so, disconnect the stream, update host path and port
-// accordingly and return true, otherwise return false and leave the stream
-// connected.
-static bool PerformRedirectIfNecessary(
- HTTPStream *http, const String8 &headers,
- string *host, string *path, int *port,
- status_t *result) {
- String8 request;
- request.append("GET ");
- request.append(path->c_str());
- request.append(" HTTP/1.1\r\n");
- request.append(headers);
- request.append("Host: ");
- request.append(host->c_str());
- request.append("\r\n\r\n");
+status_t HTTPDataSource::connectWithRedirectsAndRange(off_t rangeStart) {
+ string host = mStartingHost.string();
+ string path = mStartingPath.string();
+ int port = mStartingPort;
- status_t err = http->send(request.string());
+ LOGV("Connecting to host '%s', port %d, path '%s'",
+ host.c_str(), port, path.c_str());
- int http_status;
- if (err == OK) {
- err = http->receive_header(&http_status);
+ int numRedirectsRemaining = 5;
+ while (numRedirectsRemaining-- > 0) {
+ status_t err = mHttp->connect(host.c_str(), port);
+
+ if (err != OK) {
+ return err;
+ }
+
+ String8 request;
+ request.append("GET ");
+ request.append(path.c_str());
+ request.append(" HTTP/1.1\r\n");
+ request.append(mHeaders);
+ request.append("Host: ");
+ request.append(host.c_str());
+ request.append("\r\n");
+
+ if (rangeStart > 0) {
+ char range[128];
+ sprintf(range, "Range: bytes=%ld-\r\n", rangeStart);
+
+ request.append(range);
+ }
+
+ request.append("\r\n");
+
+ err = mHttp->send(request.string());
+
+ if (err != OK) {
+ return err;
+ }
+
+ int httpStatus;
+ err = mHttp->receive_header(&httpStatus);
+
+ if (err != OK) {
+ return err;
+ }
+
+ if (httpStatus >= 200 && httpStatus < 300) {
+ return OK;
+ }
+
+ if (httpStatus != 301 && httpStatus != 302) {
+ LOGE("HTTP request failed w/ http status %d", httpStatus);
+ return ERROR_IO;
+ }
+
+ string location;
+ CHECK(mHttp->find_header_value("Location", &location));
+
+ CHECK(string(location, 0, 7) == "http://");
+ location.erase(0, 7);
+ string::size_type slashPos = location.find('/');
+ if (slashPos == string::npos) {
+ slashPos = location.size();
+ location += '/';
+ }
+
+ mHttp->disconnect();
+
+ LOGV("Redirecting to %s\n", location.c_str());
+
+ host = string(location, 0, slashPos);
+
+ string::size_type colonPos = host.find(':');
+ if (colonPos != string::npos) {
+ const char *start = host.c_str() + colonPos + 1;
+ char *end;
+ long tmp = strtol(start, &end, 10);
+ CHECK(end > start && (*end == '\0'));
+
+ port = (tmp >= 0 && tmp < 65536) ? (int)tmp : 80;
+
+ host.erase(colonPos, host.size() - colonPos);
+ } else {
+ port = 80;
+ }
+
+ path = string(location, slashPos);
+
+ mStartingHost = host.c_str();
+ mStartingPath = path.c_str();
+ mStartingPort = port;
}
- *result = err;
-
- if (err != OK) {
- return false;
- }
-
- if (http_status != 301 && http_status != 302) {
- return false;
- }
-
- string location;
- CHECK(http->find_header_value("Location", &location));
-
- CHECK(string(location, 0, 7) == "http://");
- location.erase(0, 7);
- string::size_type slashPos = location.find('/');
- if (slashPos == string::npos) {
- slashPos = location.size();
- location += '/';
- }
-
- http->disconnect();
-
- LOGI("Redirecting to %s\n", location.c_str());
-
- *host = string(location, 0, slashPos);
-
- string::size_type colonPos = host->find(':');
- if (colonPos != string::npos) {
- const char *start = host->c_str() + colonPos + 1;
- char *end;
- long tmp = strtol(start, &end, 10);
- CHECK(end > start && (*end == '\0'));
-
- *port = (tmp >= 0 && tmp < 65536) ? (int)tmp : 80;
-
- host->erase(colonPos, host->size() - colonPos);
- } else {
- *port = 80;
- }
-
- *path = string(location, slashPos);
-
- return true;
+ return ERROR_IO;
}
HTTPDataSource::HTTPDataSource(
@@ -150,10 +177,6 @@
mState = DISCONNECTED;
mHttp = new HTTPStream;
- mHost = NULL;
- mPort = 0;
- mPath = NULL;
-
initHeaders(headers);
mBuffer = malloc(kBufferSize);
@@ -176,39 +199,17 @@
mBufferOffset = 0;
mContentLengthValid = false;
- string host = mStartingHost.string();
- string path = mStartingPath.string();
- int port = mStartingPort;
+ status_t err = connectWithRedirectsAndRange(0);
- LOGI("Connecting to host '%s', port %d, path '%s'",
- host.c_str(), port, path.c_str());
-
- int numRedirectsRemaining = 5;
- status_t result;
- do {
- status_t err = mHttp->connect(host.c_str(), port);
-
- if (err != OK) {
- Mutex::Autolock autoLock(mStateLock);
-
- if (mState != CONNECTING) {
- LOGV("connect() cancelled");
- }
- mState = DISCONNECTED;
-
- return err;
- }
- } while (PerformRedirectIfNecessary(
- mHttp, mHeaders, &host, &path, &port, &result)
- && numRedirectsRemaining-- > 0);
-
- if (result != OK) {
- // An error occurred while attempting to follow redirections/connect.
+ if (err != OK) {
Mutex::Autolock autoLock(mStateLock);
+ if (mState != CONNECTING) {
+ LOGV("connect() cancelled");
+ }
mState = DISCONNECTED;
- return result;
+ return err;
}
string value;
@@ -218,10 +219,6 @@
mContentLengthValid = true;
}
- mHost = strdup(host.c_str());
- mPort = port;
- mPath = strdup(path.c_str());
-
Mutex::Autolock autoLock(mStateLock);
if (mState != CONNECTING) {
@@ -233,6 +230,7 @@
}
mState = CONNECTED;
+
return OK;
}
@@ -278,57 +276,13 @@
free(mBuffer);
mBuffer = NULL;
-
- if (mPath) {
- free(mPath);
- mPath = NULL;
- }
-
- if (mHost) {
- free(mHost);
- mHost = NULL;
- }
}
ssize_t HTTPDataSource::sendRangeRequest(size_t offset) {
- char host[128];
- sprintf(host, "Host: %s\r\n", mHost);
+ status_t err = connectWithRedirectsAndRange(offset);
- char range[128];
- if (offset > 0) {
- sprintf(range, "Range: bytes=%d-\r\n", offset);
- } else {
- range[0] = '\0';
- }
-
- int http_status;
-
- status_t err;
- int attempt = 1;
- for (;;) {
- if ((err = mHttp->send("GET ")) != OK
- || (err = mHttp->send(mPath)) != OK
- || (err = mHttp->send(" HTTP/1.1\r\n")) != OK
- || (err = mHttp->send(mHeaders.string())) != OK
- || (err = mHttp->send(host)) != OK
- || (err = mHttp->send(range)) != OK
- || (err = mHttp->send("\r\n")) != OK
- || (err = mHttp->receive_header(&http_status)) != OK) {
-
- if (attempt == 3) {
- return err;
- }
-
- mHttp->connect(mHost, mPort);
- ++attempt;
- } else {
- break;
- }
- }
-
- if ((http_status / 100) != 2) {
- LOGE("HTTP request failed, http status = %d", http_status);
- return UNKNOWN_ERROR;
+ if (err != OK) {
+ return err;
}
string value;
@@ -407,8 +361,10 @@
if (num_bytes_received < 0
|| (mContentLengthValid && num_bytes_received < contentLength)) {
if (mNumRetriesLeft-- > 0) {
- disconnect();
- if (connect() == OK) {
+ mHttp->disconnect();
+ mBufferLength = 0;
+ num_bytes_received = connectWithRedirectsAndRange(mBufferOffset);
+ if (num_bytes_received == OK) {
LOGI("retrying connection succeeded.");
goto rinse_repeat;
}
diff --git a/media/libstagefright/MPEG4Extractor.cpp b/media/libstagefright/MPEG4Extractor.cpp
index bd3925a..323f145 100644
--- a/media/libstagefright/MPEG4Extractor.cpp
+++ b/media/libstagefright/MPEG4Extractor.cpp
@@ -741,19 +741,25 @@
uint16_t data_ref_index = U16_AT(&buffer[6]);
uint16_t num_channels = U16_AT(&buffer[16]);
- if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_NB,
- FourCC2MIME(chunk_type))
- || !strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_WB,
- FourCC2MIME(chunk_type))) {
- // AMR audio is always mono.
- num_channels = 1;
- }
-
uint16_t sample_size = U16_AT(&buffer[18]);
uint32_t sample_rate = U32_AT(&buffer[24]) >> 16;
- // printf("*** coding='%s' %d channels, size %d, rate %d\n",
- // chunk, num_channels, sample_size, sample_rate);
+ if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_NB,
+ FourCC2MIME(chunk_type))) {
+ // AMR NB audio is always mono, 8kHz
+ num_channels = 1;
+ sample_rate = 8000;
+ } else if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_WB,
+ FourCC2MIME(chunk_type))) {
+ // AMR WB audio is always mono, 16kHz
+ num_channels = 1;
+ sample_rate = 16000;
+ }
+
+#if 0
+ printf("*** coding='%s' %d channels, size %d, rate %d\n",
+ chunk, num_channels, sample_size, sample_rate);
+#endif
mLastTrack->meta->setCString(kKeyMIMEType, FourCC2MIME(chunk_type));
mLastTrack->meta->setInt32(kKeyChannelCount, num_channels);
@@ -1235,6 +1241,18 @@
status_t MPEG4Extractor::updateAudioTrackInfoFromESDS_MPEG4Audio(
const void *esds_data, size_t esds_size) {
ESDS esds(esds_data, esds_size);
+
+ uint8_t objectTypeIndication;
+ if (esds.getObjectTypeIndication(&objectTypeIndication) != OK) {
+ return ERROR_MALFORMED;
+ }
+
+ if (objectTypeIndication == 0xe1) {
+ // This isn't MPEG4 audio at all, it's QCELP 14k...
+ mLastTrack->meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_QCELP);
+ return OK;
+ }
+
const uint8_t *csd;
size_t csd_size;
if (esds.getCodecSpecificInfo(
@@ -1624,6 +1642,8 @@
}
if (!memcmp(header, "ftyp3gp", 7) || !memcmp(header, "ftypmp42", 8)
+ || !memcmp(header, "ftyp3gr6", 8) || !memcmp(header, "ftyp3gs6", 8)
+ || !memcmp(header, "ftyp3ge6", 8) || !memcmp(header, "ftyp3gg6", 8)
|| !memcmp(header, "ftypisom", 8) || !memcmp(header, "ftypM4V ", 8)
|| !memcmp(header, "ftypM4A ", 8) || !memcmp(header, "ftypf4v ", 8)
|| !memcmp(header, "ftypkddi", 8) || !memcmp(header, "ftypM4VP", 8)) {
diff --git a/media/libstagefright/MediaDefs.cpp b/media/libstagefright/MediaDefs.cpp
index 04b1454..3a89170 100644
--- a/media/libstagefright/MediaDefs.cpp
+++ b/media/libstagefright/MediaDefs.cpp
@@ -29,6 +29,7 @@
const char *MEDIA_MIMETYPE_AUDIO_AMR_WB = "audio/amr-wb";
const char *MEDIA_MIMETYPE_AUDIO_MPEG = "audio/mpeg";
const char *MEDIA_MIMETYPE_AUDIO_AAC = "audio/mp4a-latm";
+const char *MEDIA_MIMETYPE_AUDIO_QCELP = "audio/qcelp";
const char *MEDIA_MIMETYPE_AUDIO_RAW = "audio/raw";
const char *MEDIA_MIMETYPE_CONTAINER_MPEG4 = "video/mpeg4";
diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index 6037088..873c2aa 100644
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -2068,7 +2068,13 @@
CODEC_LOGV("Calling fill_buffer on buffer %p", info->mBuffer);
status_t err = mOMX->fillBuffer(mNode, info->mBuffer);
- CHECK_EQ(err, OK);
+
+ if (err != OK) {
+ CODEC_LOGE("fillBuffer failed w/ error 0x%08x", err);
+
+ setState(ERROR);
+ return;
+ }
info->mOwnedByComponent = true;
}
@@ -3034,7 +3040,7 @@
continue;
}
- OMXCodec::setComponentRole(omx, node, queryDecoders, mime);
+ OMXCodec::setComponentRole(omx, node, !queryDecoders, mime);
results->push();
CodecCapabilities *caps = &results->editItemAt(results->size() - 1);
diff --git a/media/libstagefright/TimedEventQueue.cpp b/media/libstagefright/TimedEventQueue.cpp
index e62d501..3de8c1d 100644
--- a/media/libstagefright/TimedEventQueue.cpp
+++ b/media/libstagefright/TimedEventQueue.cpp
@@ -19,6 +19,7 @@
#define __STDC_LIMIT_MACROS
#include <stdint.h>
+//#define LOG_NDEBUG 0
#define LOG_TAG "TimedEventQueue"
#include <utils/Log.h>
@@ -169,6 +170,8 @@
mQueueHeadChangedCondition.signal();
}
+ LOGV("cancelling event %d", (*it).event->eventID());
+
(*it).event->setEventID(0);
it = mQueue.erase(it);
@@ -229,14 +232,16 @@
mQueueNotEmptyCondition.wait(mLock);
}
- List<QueueItem>::iterator it;
+ event_id eventID = 0;
for (;;) {
if (mQueue.empty()) {
// The only event in the queue could have been cancelled
// while we were waiting for its scheduled time.
break;
}
- it = mQueue.begin();
+
+ List<QueueItem>::iterator it = mQueue.begin();
+ eventID = (*it).event->eventID();
now_us = getRealTimeUs();
int64_t when_us = (*it).realtime_us;
@@ -276,19 +281,39 @@
}
}
- if (mQueue.empty()) {
- continue;
- }
-
- event = (*it).event;
- event->setEventID(0);
- mQueue.erase(it);
+ // The event w/ this id may have been cancelled while we're
+ // waiting for its trigger-time, in that case
+ // removeEventFromQueue_l will return NULL.
+ // Otherwise, the QueueItem will be removed
+ // from the queue and the referenced event returned.
+ event = removeEventFromQueue_l(eventID);
}
- // Fire event with the lock NOT held.
- event->fire(this, now_us);
+ if (event != NULL) {
+ // Fire event with the lock NOT held.
+ event->fire(this, now_us);
+ }
}
}
+sp<TimedEventQueue::Event> TimedEventQueue::removeEventFromQueue_l(
+ event_id id) {
+ for (List<QueueItem>::iterator it = mQueue.begin();
+ it != mQueue.end(); ++it) {
+ if ((*it).event->eventID() == id) {
+ sp<Event> event = (*it).event;
+ event->setEventID(0);
+
+ mQueue.erase(it);
+
+ return event;
+ }
+ }
+
+ LOGW("Event %d was not found in the queue, already cancelled?", id);
+
+ return NULL;
+}
+
} // namespace android
diff --git a/media/libstagefright/codecs/aacdec/AACDecoder.cpp b/media/libstagefright/codecs/aacdec/AACDecoder.cpp
index 2ed8ef1..ae23691 100644
--- a/media/libstagefright/codecs/aacdec/AACDecoder.cpp
+++ b/media/libstagefright/codecs/aacdec/AACDecoder.cpp
@@ -203,25 +203,32 @@
Int decoderErr = PVMP4AudioDecodeFrame(mConfig, mDecoderBuf);
+ size_t numOutBytes =
+ mConfig->frameLength * sizeof(int16_t) * mConfig->desiredChannels;
+
if (decoderErr != MP4AUDEC_SUCCESS) {
- LOGE("AAC decoder returned error %d", decoderErr);
+ LOGW("AAC decoder returned error %d, substituting silence", decoderErr);
- buffer->release();
- buffer = NULL;
+ memset(buffer->data(), 0, numOutBytes);
- return ERROR_MALFORMED;
- }
-
- buffer->set_range(
- 0, mConfig->frameLength * sizeof(int16_t) * mConfig->desiredChannels);
-
- mInputBuffer->set_range(
- mInputBuffer->range_offset() + mConfig->inputBufferUsedLength,
- mInputBuffer->range_length() - mConfig->inputBufferUsedLength);
-
- if (mInputBuffer->range_length() == 0) {
+ // Discard input buffer.
mInputBuffer->release();
mInputBuffer = NULL;
+
+ // fall through
+ }
+
+ buffer->set_range(0, numOutBytes);
+
+ if (mInputBuffer != NULL) {
+ mInputBuffer->set_range(
+ mInputBuffer->range_offset() + mConfig->inputBufferUsedLength,
+ mInputBuffer->range_length() - mConfig->inputBufferUsedLength);
+
+ if (mInputBuffer->range_length() == 0) {
+ mInputBuffer->release();
+ mInputBuffer = NULL;
+ }
}
buffer->meta_data()->setInt64(
diff --git a/media/libstagefright/id3/ID3.cpp b/media/libstagefright/id3/ID3.cpp
index d688e2c..ca0c68c 100644
--- a/media/libstagefright/id3/ID3.cpp
+++ b/media/libstagefright/id3/ID3.cpp
@@ -58,13 +58,27 @@
return mVersion;
}
+// static
+bool ID3::ParseSyncsafeInteger(const uint8_t encoded[4], size_t *x) {
+ *x = 0;
+ for (int32_t i = 0; i < 4; ++i) {
+ if (encoded[i] & 0x80) {
+ return false;
+ }
+
+ *x = ((*x) << 7) | encoded[i];
+ }
+
+ return true;
+}
+
bool ID3::parseV2(const sp<DataSource> &source) {
- struct id3_header {
- char id[3];
- uint8_t version_major;
- uint8_t version_minor;
- uint8_t flags;
- uint8_t enc_size[4];
+struct id3_header {
+ char id[3];
+ uint8_t version_major;
+ uint8_t version_minor;
+ uint8_t flags;
+ uint8_t enc_size[4];
};
id3_header header;
@@ -100,17 +114,18 @@
// set, we cannot guarantee to understand the tag format.
return false;
}
+ } else if (header.version_major == 4) {
+ if (header.flags & 0x0f) {
+ // The lower 4 bits are undefined in this spec.
+ return false;
+ }
} else {
return false;
}
- size_t size = 0;
- for (int32_t i = 0; i < 4; ++i) {
- if (header.enc_size[i] & 0x80) {
- return false;
- }
-
- size = (size << 7) | header.enc_size[i];
+ size_t size;
+ if (!ParseSyncsafeInteger(header.enc_size, &size)) {
+ return false;
}
if (size > kMaxMetadataSize) {
@@ -178,13 +193,42 @@
LOGV("have crc");
}
}
+ } else if (header.version_major == 4 && (header.flags & 0x40)) {
+ // Version 2.4 has an optional extended header, that's different
+ // from Version 2.3's...
+
+ if (mSize < 4) {
+ free(mData);
+ mData = NULL;
+
+ return false;
+ }
+
+ size_t ext_size;
+ if (!ParseSyncsafeInteger(mData, &ext_size)) {
+ free(mData);
+ mData = NULL;
+
+ return false;
+ }
+
+ if (ext_size < 6 || ext_size > mSize) {
+ free(mData);
+ mData = NULL;
+
+ return false;
+ }
+
+ mFirstFrameOffset = ext_size;
}
if (header.version_major == 2) {
mVersion = ID3_V2_2;
- } else {
- CHECK_EQ(header.version_major, 3);
+ } else if (header.version_major == 3) {
mVersion = ID3_V2_3;
+ } else {
+ CHECK_EQ(header.version_major, 4);
+ mVersion = ID3_V2_4;
}
return true;
@@ -242,7 +286,7 @@
if (mParent.mVersion == ID3_V2_2) {
id->setTo((const char *)&mParent.mData[mOffset], 3);
- } else if (mParent.mVersion == ID3_V2_3) {
+ } else if (mParent.mVersion == ID3_V2_3 || mParent.mVersion == ID3_V2_4) {
id->setTo((const char *)&mParent.mData[mOffset], 4);
} else {
CHECK(mParent.mVersion == ID3_V1 || mParent.mVersion == ID3_V1_1);
@@ -346,6 +390,26 @@
if (*mFrameData == 0x00) {
// ISO 8859-1
convertISO8859ToString8(mFrameData + 1, n, id);
+ } else if (*mFrameData == 0x03) {
+ // UTF-8
+ id->setTo((const char *)(mFrameData + 1), n);
+ } else if (*mFrameData == 0x02) {
+ // UTF-16 BE, no byte order mark.
+ // API wants number of characters, not number of bytes...
+ int len = n / 2;
+ const char16_t *framedata = (const char16_t *) (mFrameData + 1);
+ char16_t *framedatacopy = NULL;
+#if BYTE_ORDER == LITTLE_ENDIAN
+ framedatacopy = new char16_t[len];
+ for (int i = 0; i < len; i++) {
+ framedatacopy[i] = bswap_16(framedata[i]);
+ }
+ framedata = framedatacopy;
+#endif
+ id->setTo(framedata, len);
+ if (framedatacopy != NULL) {
+ delete[] framedatacopy;
+ }
} else {
// UCS-2
// API wants number of characters, not number of bytes...
@@ -387,7 +451,7 @@
size_t ID3::Iterator::getHeaderLength() const {
if (mParent.mVersion == ID3_V2_2) {
return 6;
- } else if (mParent.mVersion == ID3_V2_3) {
+ } else if (mParent.mVersion == ID3_V2_3 || mParent.mVersion == ID3_V2_4) {
return 10;
} else {
CHECK(mParent.mVersion == ID3_V1 || mParent.mVersion == ID3_V1_1);
@@ -435,7 +499,8 @@
if (!strcmp(id, mID)) {
break;
}
- } else if (mParent.mVersion == ID3_V2_3) {
+ } else if (mParent.mVersion == ID3_V2_3
+ || mParent.mVersion == ID3_V2_4) {
if (mOffset + 10 > mParent.mSize) {
return;
}
@@ -444,7 +509,17 @@
return;
}
- mFrameSize = 10 + U32_AT(&mParent.mData[mOffset + 4]);
+ size_t baseSize;
+ if (mParent.mVersion == ID3_V2_4) {
+ if (!ParseSyncsafeInteger(
+ &mParent.mData[mOffset + 4], &baseSize)) {
+ return;
+ }
+ } else {
+ baseSize = U32_AT(&mParent.mData[mOffset + 4]);
+ }
+
+ mFrameSize = 10 + baseSize;
if (mOffset + mFrameSize > mParent.mSize) {
LOGV("partial frame at offset %d (size = %d, bytes-remaining = %d)",
@@ -452,6 +527,20 @@
return;
}
+ uint16_t flags = U16_AT(&mParent.mData[mOffset + 8]);
+
+ if ((mParent.mVersion == ID3_V2_4 && (flags & 0x000e))
+ || (mParent.mVersion == ID3_V2_3 && (flags & 0x00c0))) {
+ // Compression, Encryption or per-Frame unsynchronization
+ // are not supported at this time.
+
+ LOGV("Skipping unsupported frame (compression, encryption "
+ "or per-frame unsynchronization flagged");
+
+ mOffset += mFrameSize;
+ continue;
+ }
+
mFrameData = &mParent.mData[mOffset + 10];
if (!mID) {
@@ -518,8 +607,8 @@
}
static size_t StringSize(const uint8_t *start, uint8_t encoding) {
- if (encoding== 0x00) {
- // ISO 8859-1
+ if (encoding == 0x00 || encoding == 0x03) {
+ // ISO 8859-1 or UTF-8
return strlen((const char *)start) + 1;
}
@@ -537,13 +626,15 @@
*length = 0;
mime->setTo("");
- Iterator it(*this, mVersion == ID3_V2_3 ? "APIC" : "PIC");
+ Iterator it(
+ *this,
+ (mVersion == ID3_V2_3 || mVersion == ID3_V2_4) ? "APIC" : "PIC");
while (!it.done()) {
size_t size;
const uint8_t *data = it.getData(&size);
- if (mVersion == ID3_V2_3) {
+ if (mVersion == ID3_V2_3 || mVersion == ID3_V2_4) {
uint8_t encoding = data[0];
mime->setTo((const char *)&data[1]);
size_t mimeLen = strlen((const char *)&data[1]) + 1;
diff --git a/media/libstagefright/include/ESDS.h b/media/libstagefright/include/ESDS.h
index 01bcd18..3a79951 100644
--- a/media/libstagefright/include/ESDS.h
+++ b/media/libstagefright/include/ESDS.h
@@ -31,6 +31,7 @@
status_t InitCheck() const;
+ status_t getObjectTypeIndication(uint8_t *objectTypeIndication) const;
status_t getCodecSpecificInfo(const void **data, size_t *size) const;
private:
@@ -47,6 +48,7 @@
size_t mDecoderSpecificOffset;
size_t mDecoderSpecificLength;
+ uint8_t mObjectTypeIndication;
status_t skipDescriptorHeader(
size_t offset, size_t size,
diff --git a/media/libstagefright/include/ID3.h b/media/libstagefright/include/ID3.h
index da042a3..c6b1a8b 100644
--- a/media/libstagefright/include/ID3.h
+++ b/media/libstagefright/include/ID3.h
@@ -31,7 +31,8 @@
ID3_V1,
ID3_V1_1,
ID3_V2_2,
- ID3_V2_3
+ ID3_V2_3,
+ ID3_V2_4,
};
ID3(const sp<DataSource> &source);
@@ -80,6 +81,8 @@
bool parseV2(const sp<DataSource> &source);
void removeUnsynchronization();
+ static bool ParseSyncsafeInteger(const uint8_t encoded[4], size_t *x);
+
ID3(const ID3 &);
ID3 &operator=(const ID3 &);
};
diff --git a/media/libstagefright/include/TimedEventQueue.h b/media/libstagefright/include/TimedEventQueue.h
index 21eade37..11f844c 100644
--- a/media/libstagefright/include/TimedEventQueue.h
+++ b/media/libstagefright/include/TimedEventQueue.h
@@ -121,6 +121,8 @@
static void *ThreadWrapper(void *me);
void threadEntry();
+ sp<Event> removeEventFromQueue_l(event_id id);
+
TimedEventQueue(const TimedEventQueue &);
TimedEventQueue &operator=(const TimedEventQueue &);
};
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java
index ee6067ab..23bbb87 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java
@@ -439,7 +439,7 @@
@MediumTest
public void testPrepareAsyncReset() throws Exception {
- assertTrue(MediaFrameworkTest.checkStreamingServer());
+ //assertTrue(MediaFrameworkTest.checkStreamingServer());
boolean isReset = CodecTest.prepareAsyncReset(MediaNames.STREAM_MP3);
assertTrue("PrepareAsync Reset", isReset);
}
@@ -472,7 +472,7 @@
@LargeTest
public void testStreamPrepareAsyncCallback() throws Exception {
- assertTrue(MediaFrameworkTest.checkStreamingServer());
+ //assertTrue(MediaFrameworkTest.checkStreamingServer());
boolean onPrepareSuccess =
CodecTest.prepareAsyncCallback(MediaNames.STREAM_H264_480_360_1411k, false);
assertTrue("StreamH264PrepareAsyncCallback", onPrepareSuccess);
@@ -480,7 +480,7 @@
@LargeTest
public void testStreamPrepareAsyncCallbackReset() throws Exception {
- assertTrue(MediaFrameworkTest.checkStreamingServer());
+ //assertTrue(MediaFrameworkTest.checkStreamingServer());
boolean onPrepareSuccess =
CodecTest.prepareAsyncCallback(MediaNames.STREAM_H264_480_360_1411k, true);
assertTrue("StreamH264PrepareAsyncCallback", onPrepareSuccess);
diff --git a/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java b/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java
index 57f9ce7..79c8f9a 100644
--- a/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java
+++ b/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java
@@ -346,16 +346,13 @@
PackageHelper.APP_INSTALL_AUTO);
if (installPreference == PackageHelper.APP_INSTALL_INTERNAL) {
checkInt = true;
- checkBoth = true;
break check_inner;
} else if (installPreference == PackageHelper.APP_INSTALL_EXTERNAL) {
checkExt = true;
- checkBoth = true;
break check_inner;
}
// Fall back to default policy if nothing else is specified.
checkInt = true;
- checkBoth = true;
}
// Package size = code size + cache size + data size
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
index 0c0bf93..2b4714d 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
@@ -789,7 +789,8 @@
+ " VALUES(?,?);");
// Set the timeout to 30 minutes in milliseconds
- loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT, 30 * 60 * 1000);
+ loadSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
+ Integer.toString(30 * 60 * 1000));
} finally {
if (stmt != null) stmt.close();
}
diff --git a/preloaded-classes b/preloaded-classes
index 54c7303..8114562 100644
--- a/preloaded-classes
+++ b/preloaded-classes
@@ -313,7 +313,7 @@
android.net.http.EventHandler
android.net.http.Headers
android.net.http.HttpsConnection
-android.net.http.HttpDateTime
+com.android.internal.http.HttpDateTime
android.net.http.Request
android.net.http.RequestQueue
android.net.http.SslCertificate
diff --git a/services/java/com/android/server/PackageManagerBackupAgent.java b/services/java/com/android/server/PackageManagerBackupAgent.java
index 26b57bf..77bddb0 100644
--- a/services/java/com/android/server/PackageManagerBackupAgent.java
+++ b/services/java/com/android/server/PackageManagerBackupAgent.java
@@ -122,8 +122,8 @@
ParcelFileDescriptor newState) {
if (DEBUG) Slog.v(TAG, "onBackup()");
- ByteArrayOutputStream bufStream = new ByteArrayOutputStream(); // we'll reuse these
- DataOutputStream outWriter = new DataOutputStream(bufStream);
+ ByteArrayOutputStream outputBuffer = new ByteArrayOutputStream(); // we'll reuse these
+ DataOutputStream outputBufferStream = new DataOutputStream(outputBuffer);
parseStateFile(oldState);
// If the stored version string differs, we need to re-backup all
@@ -148,11 +148,9 @@
*/
if (!mExisting.contains(GLOBAL_METADATA_KEY)) {
if (DEBUG) Slog.v(TAG, "Storing global metadata key");
- outWriter.writeInt(Build.VERSION.SDK_INT);
- outWriter.writeUTF(Build.VERSION.INCREMENTAL);
- byte[] metadata = bufStream.toByteArray();
- data.writeEntityHeader(GLOBAL_METADATA_KEY, metadata.length);
- data.writeEntityData(metadata, metadata.length);
+ outputBufferStream.writeInt(Build.VERSION.SDK_INT);
+ outputBufferStream.writeUTF(Build.VERSION.INCREMENTAL);
+ writeEntity(data, GLOBAL_METADATA_KEY, outputBuffer.toByteArray());
} else {
if (DEBUG) Slog.v(TAG, "Global metadata key already stored");
// don't consider it to have been skipped/deleted
@@ -178,49 +176,46 @@
continue;
}
- boolean doBackup = false;
- if (!mExisting.contains(packName)) {
- // We haven't backed up this app before
- doBackup = true;
- } else {
- // We *have* backed this one up before. Check whether the version
+ if (mExisting.contains(packName)) {
+ // We have backed up this app before. Check whether the version
// of the backup matches the version of the current app; if they
// don't match, the app has been updated and we need to store its
// metadata again. In either case, take it out of mExisting so that
// we don't consider it deleted later.
- if (info.versionCode != mStateVersions.get(packName).versionCode) {
- doBackup = true;
- }
mExisting.remove(packName);
- }
-
- if (doBackup) {
- // We need to store this app's metadata
- /*
- * Metadata for each package:
- *
- * int version -- [4] the package's versionCode
- * byte[] signatures -- [len] flattened Signature[] of the package
- */
-
- // marshal the version code in a canonical form
- bufStream.reset();
- outWriter.writeInt(info.versionCode);
- byte[] versionBuf = bufStream.toByteArray();
-
- byte[] sigs = flattenSignatureArray(info.signatures);
-
- if (DEBUG) {
- Slog.v(TAG, "+ metadata for " + packName
- + " version=" + info.versionCode
- + " versionLen=" + versionBuf.length
- + " sigsLen=" + sigs.length);
+ if (info.versionCode == mStateVersions.get(packName).versionCode) {
+ continue;
}
- // Now we can write the backup entity for this package
- data.writeEntityHeader(packName, versionBuf.length + sigs.length);
- data.writeEntityData(versionBuf, versionBuf.length);
- data.writeEntityData(sigs, sigs.length);
}
+
+ if (info.signatures == null || info.signatures.length == 0)
+ {
+ Slog.w(TAG, "Not backing up package " + packName
+ + " since it appears to have no signatures.");
+ continue;
+ }
+
+ // We need to store this app's metadata
+ /*
+ * Metadata for each package:
+ *
+ * int version -- [4] the package's versionCode
+ * byte[] signatures -- [len] flattened Signature[] of the package
+ */
+
+ // marshal the version code in a canonical form
+ outputBuffer.reset();
+ outputBufferStream.writeInt(info.versionCode);
+ writeSignatureArray(outputBufferStream, info.signatures);
+
+ if (DEBUG) {
+ Slog.v(TAG, "+ writing metadata for " + packName
+ + " version=" + info.versionCode
+ + " entityLen=" + outputBuffer.size());
+ }
+
+ // Now we can write the backup entity for this package
+ writeEntity(data, packName, outputBuffer.toByteArray());
}
}
@@ -245,6 +240,12 @@
// Finally, write the new state blob -- just the list of all apps we handled
writeStateFile(mAllPackages, newState);
}
+
+ private static void writeEntity(BackupDataOutput data, String key, byte[] bytes)
+ throws IOException {
+ data.writeEntityHeader(key, bytes.length);
+ data.writeEntityData(bytes, bytes.length);
+ }
// "Restore" here is a misnomer. What we're really doing is reading back the
// set of app signatures associated with each backed-up app in this restore
@@ -263,13 +264,13 @@
if (DEBUG) Slog.v(TAG, " got key=" + key + " dataSize=" + dataSize);
// generic setup to parse any entity data
- byte[] dataBuf = new byte[dataSize];
- data.readEntityData(dataBuf, 0, dataSize);
- ByteArrayInputStream baStream = new ByteArrayInputStream(dataBuf);
- DataInputStream in = new DataInputStream(baStream);
+ byte[] inputBytes = new byte[dataSize];
+ data.readEntityData(inputBytes, 0, dataSize);
+ ByteArrayInputStream inputBuffer = new ByteArrayInputStream(inputBytes);
+ DataInputStream inputBufferStream = new DataInputStream(inputBuffer);
if (key.equals(GLOBAL_METADATA_KEY)) {
- int storedSdkVersion = in.readInt();
+ int storedSdkVersion = inputBufferStream.readInt();
if (DEBUG) Slog.v(TAG, " storedSystemVersion = " + storedSystemVersion);
if (storedSystemVersion > Build.VERSION.SDK_INT) {
// returning before setting the sig map means we rejected the restore set
@@ -277,7 +278,7 @@
return;
}
mStoredSdkVersion = storedSdkVersion;
- mStoredIncrementalVersion = in.readUTF();
+ mStoredIncrementalVersion = inputBufferStream.readUTF();
mHasMetadata = true;
if (DEBUG) {
Slog.i(TAG, "Restore set version " + storedSystemVersion
@@ -287,13 +288,19 @@
}
} else {
// it's a file metadata record
- int versionCode = in.readInt();
- Signature[] sigs = unflattenSignatureArray(in);
+ int versionCode = inputBufferStream.readInt();
+ Signature[] sigs = readSignatureArray(inputBufferStream);
if (DEBUG) {
- Slog.i(TAG, " restored metadata for " + key
+ Slog.i(TAG, " read metadata for " + key
+ " dataSize=" + dataSize
+ " versionCode=" + versionCode + " sigs=" + sigs);
}
+
+ if (sigs == null || sigs.length == 0) {
+ Slog.w(TAG, "Not restoring package " + key
+ + " since it appears to have no signatures.");
+ continue;
+ }
ApplicationInfo app = new ApplicationInfo();
app.packageName = key;
@@ -306,63 +313,50 @@
mRestoredSignatures = sigMap;
}
+ private static void writeSignatureArray(DataOutputStream out, Signature[] sigs)
+ throws IOException {
+ // write the number of signatures in the array
+ out.writeInt(sigs.length);
- // Util: convert an array of Signatures into a flattened byte buffer. The
- // flattened format contains enough info to reconstruct the signature array.
- private byte[] flattenSignatureArray(Signature[] allSigs) {
- ByteArrayOutputStream outBuf = new ByteArrayOutputStream();
- DataOutputStream out = new DataOutputStream(outBuf);
-
- // build the set of subsidiary buffers
- try {
- // first the # of signatures in the array
- out.writeInt(allSigs.length);
-
- // then the signatures themselves, length + flattened buffer
- for (Signature sig : allSigs) {
- byte[] flat = sig.toByteArray();
- out.writeInt(flat.length);
- out.write(flat);
- }
- } catch (IOException e) {
- // very strange; we're writing to memory here. abort.
- return null;
+ // write the signatures themselves, length + flattened buffer
+ for (Signature sig : sigs) {
+ byte[] flat = sig.toByteArray();
+ out.writeInt(flat.length);
+ out.write(flat);
}
-
- return outBuf.toByteArray();
}
- private Signature[] unflattenSignatureArray(/*byte[] buffer*/ DataInputStream in) {
- Signature[] sigs = null;
-
+ private static Signature[] readSignatureArray(DataInputStream in) {
try {
- int num = in.readInt();
+ int num;
+ try {
+ num = in.readInt();
+ } catch (EOFException e) {
+ // clean termination
+ Slog.w(TAG, "Read empty signature block");
+ return null;
+ }
+
if (DEBUG) Slog.v(TAG, " ... unflatten read " + num);
-
+
// Sensical?
if (num > 20) {
Slog.e(TAG, "Suspiciously large sig count in restore data; aborting");
throw new IllegalStateException("Bad restore state");
}
-
- sigs = new Signature[num];
+
+ Signature[] sigs = new Signature[num];
for (int i = 0; i < num; i++) {
int len = in.readInt();
byte[] flatSig = new byte[len];
in.read(flatSig);
sigs[i] = new Signature(flatSig);
}
- } catch (EOFException e) {
- // clean termination
- if (sigs == null) {
- Slog.w(TAG, "Empty signature block found");
- }
+ return sigs;
} catch (IOException e) {
- Slog.e(TAG, "Unable to unflatten sigs");
+ Slog.e(TAG, "Unable to read signatures");
return null;
}
-
- return sigs;
}
// Util: parse out an existing state file into a usable structure
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index e6663d4..b7ab9fe 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -179,6 +179,8 @@
static final int SCAN_NEW_INSTALL = 1<<4;
static final int SCAN_NO_PATHS = 1<<5;
+ static final int REMOVE_CHATTY = 1<<16;
+
static final ComponentName DEFAULT_CONTAINER_COMPONENT = new ComponentName(
"com.android.defcontainer",
"com.android.defcontainer.DefaultContainerService");
@@ -568,14 +570,15 @@
if (DEBUG_INSTALL) Log.v(TAG, "Handling post-install for " + msg.arg1);
PostInstallData data = mRunningInstalls.get(msg.arg1);
mRunningInstalls.delete(msg.arg1);
- boolean deleteOld = false;
if (data != null) {
InstallArgs args = data.args;
PackageInstalledInfo res = data.res;
if (res.returnCode == PackageManager.INSTALL_SUCCEEDED) {
- res.removedInfo.sendBroadcast(false, true);
+ res.removedInfo.sendBroadcast(false, true,
+ new PackageRemovedIntentReceiver(res.removedInfo.args,
+ res.removedInfo.args != null));
Bundle extras = new Bundle(1);
extras.putInt(Intent.EXTRA_UID, res.uid);
final boolean update = res.removedInfo.removedPackage != null;
@@ -590,18 +593,6 @@
res.pkg.applicationInfo.packageName,
extras, null);
}
- if (res.removedInfo.args != null) {
- // Remove the replaced package's older resources safely now
- deleteOld = true;
- }
- }
- // Force a gc to clear up things
- Runtime.getRuntime().gc();
- // We delete after a gc for applications on sdcard.
- if (deleteOld) {
- synchronized (mInstallLock) {
- res.removedInfo.args.doPostDeleteLI(true);
- }
}
if (args.observer != null) {
try {
@@ -615,10 +606,27 @@
}
} break;
case UPDATED_MEDIA_STATUS: {
- try {
- PackageHelper.getMountService().finishMediaUpdate();
- } catch (RemoteException e) {
- Log.e(TAG, "MountService not running?");
+ if (DEBUG_SD_INSTALL) Log.i(TAG, "Got message UPDATED_MEDIA_STATUS");
+ boolean reportStatus = msg.arg1 == 1;
+ boolean doGc = msg.arg2 == 1;
+ if (DEBUG_SD_INSTALL) Log.i(TAG, "reportStatus=" + reportStatus + ", doGc = " + doGc);
+ if (doGc) {
+ // Force a gc to clear up stale containers.
+ Runtime.getRuntime().gc();
+ }
+ if (msg.obj != null) {
+ Set<SdInstallArgs> args = (Set<SdInstallArgs>) msg.obj;
+ if (DEBUG_SD_INSTALL) Log.i(TAG, "Unloading all containers");
+ // Unload containers
+ unloadAllContainers(args);
+ }
+ if (reportStatus) {
+ try {
+ if (DEBUG_SD_INSTALL) Log.i(TAG, "Invoking MountService call back");
+ PackageHelper.getMountService().finishMediaUpdate();
+ } catch (RemoteException e) {
+ Log.e(TAG, "MountService not running?");
+ }
}
} break;
case WRITE_SETTINGS: {
@@ -2496,16 +2504,25 @@
private boolean collectCertificatesLI(PackageParser pp, PackageSetting ps,
PackageParser.Package pkg, File srcFile, int parseFlags) {
if (GET_CERTIFICATES) {
- if (ps == null || !ps.codePath.equals(srcFile)
- || ps.getTimeStamp() != srcFile.lastModified()) {
- Log.i(TAG, srcFile.toString() + " changed; collecting certs");
- if (!pp.collectCertificates(pkg, parseFlags)) {
- mLastScanError = pp.getParseError();
- return false;
+ if (ps != null
+ && ps.codePath.equals(srcFile)
+ && ps.getTimeStamp() == srcFile.lastModified()) {
+ if (ps.signatures.mSignatures != null
+ && ps.signatures.mSignatures.length != 0) {
+ // Optimization: reuse the existing cached certificates
+ // if the package appears to be unchanged.
+ pkg.mSignatures = ps.signatures.mSignatures;
+ return true;
}
+
+ Slog.w(TAG, "PackageSetting for " + ps.name + " is missing signatures. Collecting certs again to recover them.");
} else {
- // Lets implicitly assign existing certificates.
- pkg.mSignatures = ps.signatures.mSignatures;
+ Log.i(TAG, srcFile.toString() + " changed; collecting certs");
+ }
+
+ if (!pp.collectCertificates(pkg, parseFlags)) {
+ mLastScanError = pp.getParseError();
+ return false;
}
}
return true;
@@ -6042,12 +6059,14 @@
}
synchronized (mInstallLock) {
- res = deletePackageLI(packageName, deleteCodeAndResources, flags, info);
+ res = deletePackageLI(packageName, deleteCodeAndResources,
+ flags | REMOVE_CHATTY, info);
}
if(res && sendBroadCast) {
boolean systemUpdate = info.isRemovedPackageSystemUpdate;
- info.sendBroadcast(deleteCodeAndResources, systemUpdate);
+ info.sendBroadcast(deleteCodeAndResources, systemUpdate,
+ new PackageRemovedIntentReceiver(info.args, deleteCodeAndResources));
// If the removed package was a system update, the old system packaged
// was re-enabled; we need to broadcast this information
@@ -6060,18 +6079,28 @@
sendPackageBroadcast(Intent.ACTION_PACKAGE_REPLACED, packageName, extras, null);
}
}
- // Force a gc here.
- Runtime.getRuntime().gc();
- // Delete the resources here after sending the broadcast to let
- // other processes clean up before deleting resources.
- if (info.args != null) {
- synchronized (mInstallLock) {
- info.args.doPostDeleteLI(deleteCodeAndResources);
- }
- }
return res;
}
+ class PackageRemovedIntentReceiver extends IIntentReceiver.Stub {
+ boolean deleteOld;
+ InstallArgs args;
+ PackageRemovedIntentReceiver(InstallArgs args, boolean deleteOld) {
+ this.args = args;
+ this.deleteOld = deleteOld;
+ }
+ public void performReceive(Intent intent, int resultCode, String data, Bundle extras,
+ boolean ordered, boolean sticky) throws RemoteException {
+ // Force a gc to clear up things
+ Runtime.getRuntime().gc();
+ // We delete after a gc for applications on sdcard.
+ if (deleteOld && args != null) {
+ synchronized (mInstallLock) {
+ args.doPostDeleteLI(true);
+ }
+ }
+ }
+ }
static class PackageRemovedInfo {
String removedPackage;
int uid = -1;
@@ -6080,7 +6109,8 @@
// Clean up resources deleted packages.
InstallArgs args = null;
- void sendBroadcast(boolean fullRemove, boolean replacing) {
+ void sendBroadcast(boolean fullRemove, boolean replacing,
+ IIntentReceiver finishedReceiver) {
Bundle extras = new Bundle(1);
extras.putInt(Intent.EXTRA_UID, removedUid >= 0 ? removedUid : uid);
extras.putBoolean(Intent.EXTRA_DATA_REMOVED, fullRemove);
@@ -6088,7 +6118,7 @@
extras.putBoolean(Intent.EXTRA_REPLACING, true);
}
if (removedPackage != null) {
- sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, removedPackage, extras, null);
+ sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, removedPackage, extras, finishedReceiver);
}
if (removedUid >= 0) {
sendPackageBroadcast(Intent.ACTION_UID_REMOVED, null, extras, null);
@@ -6108,7 +6138,7 @@
if (outInfo != null) {
outInfo.removedPackage = packageName;
}
- removePackageLI(p, true);
+ removePackageLI(p, (flags&REMOVE_CHATTY) != 0);
// Retrieve object to delete permissions for shared user later on
PackageSetting deletedPs;
synchronized (mPackages) {
@@ -9420,9 +9450,9 @@
if (DEBUG_SD_INSTALL) Log.i(TAG, "updateExternalMediaStatus:: mediaStatus=" +
mediaStatus+", mMediaMounted=" + mMediaMounted);
if (mediaStatus == mMediaMounted) {
- if (reportStatus) {
- mHandler.sendEmptyMessage(UPDATED_MEDIA_STATUS);
- }
+ Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS,
+ reportStatus ? 1 : 0, -1);
+ mHandler.sendMessage(msg);
return;
}
mMediaMounted = mediaStatus;
@@ -9431,38 +9461,42 @@
mHandler.post(new Runnable() {
public void run() {
mHandler.removeCallbacks(this);
- try {
- updateExternalMediaStatusInner(mediaStatus);
- } finally {
- if (reportStatus) {
- mHandler.sendEmptyMessage(UPDATED_MEDIA_STATUS);
- }
- }
+ updateExternalMediaStatusInner(mediaStatus, reportStatus);
}
});
}
- private void updateExternalMediaStatusInner(boolean mediaStatus) {
- // If we are up here that means there are packages to be
- // enabled or disabled.
+ /*
+ * Collect information of applications on external media, map them
+ * against existing containers and update information based on current
+ * mount status. Please note that we always have to report status
+ * if reportStatus has been set to true especially when unloading packages.
+ */
+ private void updateExternalMediaStatusInner(boolean mediaStatus,
+ boolean reportStatus) {
+ // Collection of uids
+ int uidArr[] = null;
+ // Collection of stale containers
+ HashSet<String> removeCids = new HashSet<String>();
+ // Collection of packages on external media with valid containers.
+ HashMap<SdInstallArgs, String> processCids = new HashMap<SdInstallArgs, String>();
+ // Get list of secure containers.
final String list[] = PackageHelper.getSecureContainerList();
if (list == null || list.length == 0) {
Log.i(TAG, "No secure containers on sdcard");
- return;
- }
-
- int uidList[] = new int[list.length];
- int num = 0;
- HashSet<String> removeCids = new HashSet<String>();
- HashMap<SdInstallArgs, String> processCids = new HashMap<SdInstallArgs, String>();
- synchronized (mPackages) {
- for (String cid : list) {
- SdInstallArgs args = new SdInstallArgs(cid);
- if (DEBUG_SD_INSTALL) Log.i(TAG, "Processing container " + cid);
- boolean failed = true;
- try {
+ } else {
+ // Process list of secure containers and categorize them
+ // as active or stale based on their package internal state.
+ int uidList[] = new int[list.length];
+ int num = 0;
+ synchronized (mPackages) {
+ for (String cid : list) {
+ SdInstallArgs args = new SdInstallArgs(cid);
+ if (DEBUG_SD_INSTALL) Log.i(TAG, "Processing container " + cid);
String pkgName = args.getPackageName();
if (pkgName == null) {
+ if (DEBUG_SD_INSTALL) Log.i(TAG, "Container : " + cid + " stale");
+ removeCids.add(cid);
continue;
}
if (DEBUG_SD_INSTALL) Log.i(TAG, "Looking for pkg : " + pkgName);
@@ -9474,33 +9508,29 @@
" at code path: " + ps.codePathString);
// We do have a valid package installed on sdcard
processCids.put(args, ps.codePathString);
- failed = false;
int uid = ps.userId;
if (uid != -1) {
uidList[num++] = uid;
}
- }
- } finally {
- if (failed) {
+ } else {
// Stale container on sdcard. Just delete
if (DEBUG_SD_INSTALL) Log.i(TAG, "Container : " + cid + " stale");
removeCids.add(cid);
}
}
}
- }
- // Organize uids
- int uidArr[] = null;
- if (num > 0) {
- // Sort uid list
- Arrays.sort(uidList, 0, num);
- // Throw away duplicates
- uidArr = new int[num];
- uidArr[0] = uidList[0];
- int di = 0;
- for (int i = 1; i < num; i++) {
- if (uidList[i-1] != uidList[i]) {
- uidArr[di++] = uidList[i];
+
+ if (num > 0) {
+ // Sort uid list
+ Arrays.sort(uidList, 0, num);
+ // Throw away duplicates
+ uidArr = new int[num];
+ uidArr[0] = uidList[0];
+ int di = 0;
+ for (int i = 1; i < num; i++) {
+ if (uidList[i-1] != uidList[i]) {
+ uidArr[di++] = uidList[i];
+ }
}
}
}
@@ -9511,7 +9541,7 @@
startCleaningPackages();
} else {
if (DEBUG_SD_INSTALL) Log.i(TAG, "Unloading packages");
- unloadMediaPackages(processCids, uidArr);
+ unloadMediaPackages(processCids, uidArr, reportStatus);
}
}
@@ -9536,10 +9566,7 @@
* Look at potentially valid container ids from processCids
* If package information doesn't match the one on record
* or package scanning fails, the cid is added to list of
- * removeCids and cleaned up. Since cleaning up containers
- * involves destroying them, we do not want any parse
- * references to such stale containers. So force gc's
- * to avoid unnecessary crashes.
+ * removeCids. We currently don't delete stale containers.
*/
private void loadMediaPackages(HashMap<SdInstallArgs, String> processCids,
int uidArr[], HashSet<String> removeCids) {
@@ -9566,8 +9593,7 @@
continue;
}
// Parse package
- int parseFlags = PackageParser.PARSE_CHATTY |
- PackageParser.PARSE_ON_SDCARD | mDefParseFlags;
+ int parseFlags = PackageParser.PARSE_ON_SDCARD | mDefParseFlags;
doGc = true;
synchronized (mInstallLock) {
final PackageParser.Package pkg = scanPackageLI(new File(codePath),
@@ -9617,6 +9643,7 @@
if (pkgList.size() > 0) {
sendResourcesChangedBroadcast(true, pkgList, uidArr, null);
}
+ // Force gc to avoid any stale parser references that we might have.
if (doGc) {
Runtime.getRuntime().gc();
}
@@ -9628,12 +9655,33 @@
}
}
+ /*
+ * Utility method to unload a list of specified containers
+ */
+ private void unloadAllContainers(Set<SdInstallArgs> cidArgs) {
+ // Just unmount all valid containers.
+ for (SdInstallArgs arg : cidArgs) {
+ synchronized (mInstallLock) {
+ arg.doPostDeleteLI(false);
+ }
+ }
+ }
+
+ /*
+ * Unload packages mounted on external media. This involves deleting
+ * package data from internal structures, sending broadcasts about
+ * diabled packages, gc'ing to free up references, unmounting all
+ * secure containers corresponding to packages on external media, and
+ * posting a UPDATED_MEDIA_STATUS message if status has been requested.
+ * Please note that we always have to post this message if status has
+ * been requested no matter what.
+ */
private void unloadMediaPackages(HashMap<SdInstallArgs, String> processCids,
- int uidArr[]) {
+ int uidArr[], final boolean reportStatus) {
if (DEBUG_SD_INSTALL) Log.i(TAG, "unloading media packages");
ArrayList<String> pkgList = new ArrayList<String>();
ArrayList<SdInstallArgs> failedList = new ArrayList<SdInstallArgs>();
- Set<SdInstallArgs> keys = processCids.keySet();
+ final Set<SdInstallArgs> keys = processCids.keySet();
for (SdInstallArgs args : keys) {
String cid = args.cid;
String pkgName = args.getPackageName();
@@ -9651,22 +9699,23 @@
}
}
}
- // Send broadcasts
+ // We have to absolutely send UPDATED_MEDIA_STATUS only
+ // after confirming that all the receivers processed the ordered
+ // broadcast when packages get disabled, force a gc to clean things up.
+ // and unload all the containers.
if (pkgList.size() > 0) {
sendResourcesChangedBroadcast(false, pkgList, uidArr, new IIntentReceiver.Stub() {
public void performReceive(Intent intent, int resultCode, String data, Bundle extras,
boolean ordered, boolean sticky) throws RemoteException {
- // Force gc now that everyone is done cleaning up, to release
- // references on assets.
- Runtime.getRuntime().gc();
+ Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS,
+ reportStatus ? 1 : 0, 1, keys);
+ mHandler.sendMessage(msg);
}
});
- }
- // Just unmount all valid containers.
- for (SdInstallArgs args : keys) {
- synchronized (mInstallLock) {
- args.doPostDeleteLI(false);
- }
+ } else {
+ Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS,
+ reportStatus ? 1 : 0, -1, keys);
+ mHandler.sendMessage(msg);
}
}
@@ -9751,6 +9800,7 @@
}
if (returnCode == PackageManager.MOVE_SUCCEEDED) {
// Send resources unavailable broadcast
+ // TODO Add an ordered broadcast receiver here.
sendResourcesChangedBroadcast(false, pkgList, uidArr, null);
// Update package code and resource paths
synchronized (mInstallLock) {
@@ -9801,9 +9851,9 @@
}
}
}
- // Send resources available broadcast
- sendResourcesChangedBroadcast(true, pkgList, uidArr, null);
}
+ // Send resources available broadcast
+ sendResourcesChangedBroadcast(true, pkgList, uidArr, null);
}
}
if (returnCode != PackageManager.MOVE_SUCCEEDED){
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 25a60a6..9d5d035 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -99,6 +99,7 @@
DockObserver dock = null;
UiModeManagerService uiMode = null;
RecognitionManagerService recognition = null;
+ ThrottleService throttle = null;
// Critical services...
try {
@@ -269,6 +270,15 @@
}
try {
+ Slog.i(TAG, "Throttle Service");
+ throttle = new ThrottleService(context);
+ ServiceManager.addService(
+ Context.THROTTLE_SERVICE, throttle);
+ } catch (Throwable e) {
+ Slog.e(TAG, "Failure starting ThrottleService", e);
+ }
+
+ try {
Slog.i(TAG, "Accessibility Manager");
ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
new AccessibilityManagerService(context));
@@ -457,6 +467,7 @@
final BatteryService batteryF = battery;
final ConnectivityService connectivityF = connectivity;
final DockObserver dockF = dock;
+ final ThrottleService throttleF = throttle;
final UiModeManagerService uiModeF = uiMode;
final AppWidgetService appWidgetF = appWidget;
final WallpaperManagerService wallpaperF = wallpaper;
@@ -488,6 +499,7 @@
if (wallpaperF != null) wallpaperF.systemReady();
if (immF != null) immF.systemReady();
if (locationF != null) locationF.systemReady();
+ if (throttleF != null) throttleF.systemReady();
}
});
diff --git a/services/java/com/android/server/ThrottleService.java b/services/java/com/android/server/ThrottleService.java
new file mode 100644
index 0000000..9333dd8
--- /dev/null
+++ b/services/java/com/android/server/ThrottleService.java
@@ -0,0 +1,853 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server;
+
+import android.app.AlarmManager;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.database.ContentObserver;
+import android.net.IThrottleManager;
+import android.net.ThrottleManager;
+import android.os.Binder;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.IBinder;
+import android.os.INetworkManagementService;
+import android.os.Looper;
+import android.os.Message;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+import android.provider.Settings;
+import android.util.Slog;
+
+import com.android.internal.telephony.TelephonyProperties;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.Random;
+
+// TODO - add comments - reference the ThrottleManager for public API
+public class ThrottleService extends IThrottleManager.Stub {
+
+ private static final String TESTING_ENABLED_PROPERTY = "persist.throttle.testing";
+
+ private static final String TAG = "ThrottleService";
+ private static boolean DBG = true;
+ private Handler mHandler;
+ private HandlerThread mThread;
+
+ private Context mContext;
+
+ private static final int TESTING_POLLING_PERIOD_SEC = 60 * 1;
+ private static final int TESTING_RESET_PERIOD_SEC = 60 * 3;
+ private static final long TESTING_THRESHOLD = 1 * 1024 * 1024;
+
+ private static final int PERIOD_COUNT = 6;
+
+ private int mPolicyPollPeriodSec;
+ private long mPolicyThreshold;
+ private int mPolicyThrottleValue;
+ private int mPolicyResetDay; // 1-28
+ private int mPolicyNotificationsAllowedMask;
+
+ private long mLastRead; // read byte count from last poll
+ private long mLastWrite; // write byte count from last poll
+
+ private static final String ACTION_POLL = "com.android.server.ThrottleManager.action.POLL";
+ private static int POLL_REQUEST = 0;
+ private PendingIntent mPendingPollIntent;
+ private static final String ACTION_RESET = "com.android.server.ThorottleManager.action.RESET";
+ private static int RESET_REQUEST = 1;
+ private PendingIntent mPendingResetIntent;
+
+ private INetworkManagementService mNMService;
+ private AlarmManager mAlarmManager;
+ private NotificationManager mNotificationManager;
+
+ private DataRecorder mRecorder;
+
+ private String mIface;
+
+ private static final int NOTIFICATION_WARNING = 2;
+ private static final int NOTIFICATION_ALL = 0xFFFFFFFF;
+
+ private Notification mThrottlingNotification;
+ private boolean mWarningNotificationSent = false;
+
+ private SettingsObserver mSettingsObserver;
+
+ private int mThrottleIndex; // 0 for none, 1 for first throttle val, 2 for next, etc
+ private static final int THROTTLE_INDEX_UNINITIALIZED = -1;
+ private static final int THROTTLE_INDEX_UNTHROTTLED = 0;
+
+ public ThrottleService(Context context) {
+ if (DBG) Slog.d(TAG, "Starting ThrottleService");
+ mContext = context;
+
+ mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
+ Intent pollIntent = new Intent(ACTION_POLL, null);
+ mPendingPollIntent = PendingIntent.getBroadcast(mContext, POLL_REQUEST, pollIntent, 0);
+ Intent resetIntent = new Intent(ACTION_RESET, null);
+ mPendingResetIntent = PendingIntent.getBroadcast(mContext, RESET_REQUEST, resetIntent, 0);
+
+ IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
+ mNMService = INetworkManagementService.Stub.asInterface(b);
+
+ mNotificationManager = (NotificationManager)mContext.getSystemService(
+ Context.NOTIFICATION_SERVICE);
+ }
+
+ private static class SettingsObserver extends ContentObserver {
+ private int mMsg;
+ private Handler mHandler;
+ SettingsObserver(Handler handler, int msg) {
+ super(handler);
+ mHandler = handler;
+ mMsg = msg;
+ }
+
+ void observe(Context context) {
+ ContentResolver resolver = context.getContentResolver();
+ resolver.registerContentObserver(Settings.Secure.getUriFor(
+ Settings.Secure.THROTTLE_POLLING_SEC), false, this);
+ resolver.registerContentObserver(Settings.Secure.getUriFor(
+ Settings.Secure.THROTTLE_THRESHOLD_BYTES), false, this);
+ resolver.registerContentObserver(Settings.Secure.getUriFor(
+ Settings.Secure.THROTTLE_VALUE_KBITSPS), false, this);
+ resolver.registerContentObserver(Settings.Secure.getUriFor(
+ Settings.Secure.THROTTLE_RESET_DAY), false, this);
+ resolver.registerContentObserver(Settings.Secure.getUriFor(
+ Settings.Secure.THROTTLE_NOTIFICATION_TYPE), false, this);
+ resolver.registerContentObserver(Settings.Secure.getUriFor(
+ Settings.Secure.THROTTLE_HELP_URI), false, this);
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ mHandler.obtainMessage(mMsg).sendToTarget();
+ }
+ }
+
+ private void enforceAccessPermission() {
+ mContext.enforceCallingOrSelfPermission(
+ android.Manifest.permission.ACCESS_NETWORK_STATE,
+ "ThrottleService");
+ }
+
+ public synchronized long getResetTime(String iface) {
+ enforceAccessPermission();
+ if ((iface != null) &&
+ iface.equals(mIface) &&
+ (mRecorder != null)) {
+ mRecorder.getPeriodEnd();
+ }
+ return 0;
+ }
+ public synchronized long getPeriodStartTime(String iface) {
+ enforceAccessPermission();
+ if ((iface != null) &&
+ iface.equals(mIface) &&
+ (mRecorder != null)) {
+ mRecorder.getPeriodStart();
+ }
+ return 0;
+ }
+ //TODO - a better name? getCliffByteCountThreshold?
+ public synchronized long getCliffThreshold(String iface, int cliff) {
+ enforceAccessPermission();
+ if ((iface != null) && (cliff == 1) && iface.equals(mIface)) {
+ return mPolicyThreshold;
+ }
+ return 0;
+ }
+ // TODO - a better name? getThrottleRate?
+ public synchronized int getCliffLevel(String iface, int cliff) {
+ enforceAccessPermission();
+ if ((iface != null) && (cliff == 1) && iface.equals(mIface)) {
+ return mPolicyThrottleValue;
+ }
+ return 0;
+ }
+
+ public String getHelpUri() {
+ enforceAccessPermission();
+ return Settings.Secure.getString(mContext.getContentResolver(),
+ Settings.Secure.THROTTLE_HELP_URI);
+ }
+
+ public synchronized long getByteCount(String iface, int dir, int period, int ago) {
+ enforceAccessPermission();
+ if ((iface != null) &&
+ iface.equals(mIface) &&
+ (period == ThrottleManager.PERIOD_CYCLE) &&
+ (mRecorder != null)) {
+ if (dir == ThrottleManager.DIRECTION_TX) return mRecorder.getPeriodTx(ago);
+ if (dir == ThrottleManager.DIRECTION_RX) return mRecorder.getPeriodRx(ago);
+ }
+ return 0;
+ }
+
+ // TODO - a better name - getCurrentThrottleRate?
+ public synchronized int getThrottle(String iface) {
+ enforceAccessPermission();
+ if ((iface != null) && iface.equals(mIface) && (mThrottleIndex == 1)) {
+ return mPolicyThrottleValue;
+ }
+ return 0;
+ }
+
+ void systemReady() {
+ if (DBG) Slog.d(TAG, "systemReady");
+ mContext.registerReceiver(
+ new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ mHandler.obtainMessage(EVENT_POLL_ALARM).sendToTarget();
+ }
+ }, new IntentFilter(ACTION_POLL));
+
+ mContext.registerReceiver(
+ new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ mHandler.obtainMessage(EVENT_RESET_ALARM).sendToTarget();
+ }
+ }, new IntentFilter(ACTION_RESET));
+
+ // use a new thread as we don't want to stall the system for file writes
+ mThread = new HandlerThread(TAG);
+ mThread.start();
+ mHandler = new MyHandler(mThread.getLooper());
+ mHandler.obtainMessage(EVENT_REBOOT_RECOVERY).sendToTarget();
+
+ mSettingsObserver = new SettingsObserver(mHandler, EVENT_POLICY_CHANGED);
+ mSettingsObserver.observe(mContext);
+ }
+
+
+ private static final int EVENT_REBOOT_RECOVERY = 0;
+ private static final int EVENT_POLICY_CHANGED = 1;
+ private static final int EVENT_POLL_ALARM = 2;
+ private static final int EVENT_RESET_ALARM = 3;
+ private class MyHandler extends Handler {
+ public MyHandler(Looper l) {
+ super(l);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case EVENT_REBOOT_RECOVERY:
+ onRebootRecovery();
+ break;
+ case EVENT_POLICY_CHANGED:
+ onPolicyChanged();
+ break;
+ case EVENT_POLL_ALARM:
+ onPollAlarm();
+ break;
+ case EVENT_RESET_ALARM:
+ onResetAlarm();
+ }
+ }
+
+ private void onRebootRecovery() {
+ if (DBG) Slog.d(TAG, "onRebootRecovery");
+ // check for sim change TODO
+ // reregister for notification of policy change
+
+ mThrottleIndex = THROTTLE_INDEX_UNINITIALIZED;
+
+ mRecorder = new DataRecorder(mContext, ThrottleService.this);
+
+ // get policy
+ mHandler.obtainMessage(EVENT_POLICY_CHANGED).sendToTarget();
+
+ // evaluate current conditions
+ mHandler.obtainMessage(EVENT_POLL_ALARM).sendToTarget();
+ }
+
+ private void onSimChange() {
+ // TODO
+ }
+
+ // check for new policy info (threshold limit/value/etc)
+ private void onPolicyChanged() {
+ boolean testing = SystemProperties.get(TESTING_ENABLED_PROPERTY).equals("true");
+
+ int pollingPeriod = mContext.getResources().getInteger(
+ com.android.internal.R.integer.config_datause_polling_period_sec);
+ mPolicyPollPeriodSec = Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.THROTTLE_POLLING_SEC, pollingPeriod);
+
+ // TODO - remove testing stuff?
+ long defaultThreshold = mContext.getResources().getInteger(
+ com.android.internal.R.integer.config_datause_threshold_bytes);
+ int defaultValue = mContext.getResources().getInteger(
+ com.android.internal.R.integer.config_datause_throttle_kbitsps);
+ synchronized (ThrottleService.this) {
+ mPolicyThreshold = Settings.Secure.getLong(mContext.getContentResolver(),
+ Settings.Secure.THROTTLE_THRESHOLD_BYTES, defaultThreshold);
+ mPolicyThrottleValue = Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.THROTTLE_VALUE_KBITSPS, defaultValue);
+ if (testing) {
+ mPolicyPollPeriodSec = TESTING_POLLING_PERIOD_SEC;
+ mPolicyThreshold = TESTING_THRESHOLD;
+ }
+ }
+
+ mPolicyResetDay = Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.THROTTLE_RESET_DAY, -1);
+ if (mPolicyResetDay == -1 ||
+ ((mPolicyResetDay < 1) || (mPolicyResetDay > 28))) {
+ Random g = new Random();
+ mPolicyResetDay = 1 + g.nextInt(28); // 1-28
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.THROTTLE_RESET_DAY, mPolicyResetDay);
+ }
+ mIface = mContext.getResources().getString(
+ com.android.internal.R.string.config_datause_iface);
+ synchronized (ThrottleService.this) {
+ if (mIface == null) {
+ mPolicyThreshold = 0;
+ }
+ }
+
+ int defaultNotificationType = mContext.getResources().getInteger(
+ com.android.internal.R.integer.config_datause_notification_type);
+ mPolicyNotificationsAllowedMask = Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.THROTTLE_NOTIFICATION_TYPE, defaultNotificationType);
+
+ Slog.d(TAG, "onPolicyChanged testing=" + testing +", period=" + mPolicyPollPeriodSec +
+ ", threshold=" + mPolicyThreshold + ", value=" + mPolicyThrottleValue +
+ ", resetDay=" + mPolicyResetDay + ", noteType=" +
+ mPolicyNotificationsAllowedMask);
+
+ onResetAlarm();
+
+ onPollAlarm();
+
+ Intent broadcast = new Intent(ThrottleManager.POLICY_CHANGED_ACTION);
+ mContext.sendBroadcast(broadcast);
+ }
+
+ private void onPollAlarm() {
+ long now = SystemClock.elapsedRealtime();
+ long next = now + mPolicyPollPeriodSec*1000;
+ long incRead = 0;
+ long incWrite = 0;
+ try {
+ incRead = mNMService.getInterfaceRxCounter(mIface) - mLastRead;
+ incWrite = mNMService.getInterfaceTxCounter(mIface) - mLastWrite;
+ } catch (RemoteException e) {
+ Slog.e(TAG, "got remoteException in onPollAlarm:" + e);
+ }
+ // don't count this data if we're roaming.
+ boolean roaming = "true".equals(
+ SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISROAMING));
+ if (!roaming) {
+ mRecorder.addData(incRead, incWrite);
+ }
+
+ long periodRx = mRecorder.getPeriodRx(0);
+ long periodTx = mRecorder.getPeriodTx(0);
+ long total = periodRx + periodTx;
+ if (DBG) {
+ Slog.d(TAG, "onPollAlarm - now =" + now + ", roaming =" + roaming +
+ ", read =" + incRead + ", written =" + incWrite + ", new total =" + total);
+ }
+ mLastRead += incRead;
+ mLastWrite += incWrite;
+
+ checkThrottleAndPostNotification(total);
+
+ Intent broadcast = new Intent(ThrottleManager.THROTTLE_POLL_ACTION);
+ broadcast.putExtra(ThrottleManager.EXTRA_CYCLE_READ, periodRx);
+ broadcast.putExtra(ThrottleManager.EXTRA_CYCLE_WRITE, periodTx);
+ broadcast.putExtra(ThrottleManager.EXTRA_CYCLE_START, mRecorder.getPeriodStart());
+ broadcast.putExtra(ThrottleManager.EXTRA_CYCLE_END, mRecorder.getPeriodEnd());
+ mContext.sendStickyBroadcast(broadcast);
+
+ mAlarmManager.cancel(mPendingPollIntent);
+ mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, next, mPendingPollIntent);
+ }
+
+ private void checkThrottleAndPostNotification(long currentTotal) {
+ // is throttling enabled?
+ if (mPolicyThreshold == 0)
+ return;
+
+ // check if we need to throttle
+ if (currentTotal > mPolicyThreshold) {
+ if (mThrottleIndex != 1) {
+ synchronized (ThrottleService.this) {
+ mThrottleIndex = 1;
+ }
+ if (DBG) Slog.d(TAG, "Threshold " + mPolicyThreshold + " exceeded!");
+ try {
+ mNMService.setInterfaceThrottle(mIface,
+ mPolicyThrottleValue, mPolicyThrottleValue);
+ } catch (Exception e) {
+ Slog.e(TAG, "error setting Throttle: " + e);
+ }
+
+ mNotificationManager.cancel(com.android.internal.R.drawable.
+ stat_sys_throttled);
+
+ postNotification(com.android.internal.R.string.throttled_notification_title,
+ com.android.internal.R.string.throttled_notification_message,
+ com.android.internal.R.drawable.stat_sys_throttled,
+ Notification.FLAG_ONGOING_EVENT);
+
+ Intent broadcast = new Intent(ThrottleManager.THROTTLE_ACTION);
+ broadcast.putExtra(ThrottleManager.EXTRA_THROTTLE_LEVEL, mPolicyThrottleValue);
+ mContext.sendStickyBroadcast(broadcast);
+
+ } // else already up!
+ } else {
+ if ((mPolicyNotificationsAllowedMask & NOTIFICATION_WARNING) != 0) {
+ // check if we should warn about throttle
+ // pretend we only have 1/2 the time remaining that we actually do
+ // if our burn rate in the period so far would have us exceed the limit
+ // in that 1/2 window, warn the user.
+ // this gets more generous in the early to middle period and converges back
+ // to the limit as we move toward the period end.
+
+ // adding another factor - it must be greater than the total cap/4
+ // else we may get false alarms very early in the period.. in the first
+ // tenth of a percent of the period if we used more than a tenth of a percent
+ // of the cap we'd get a warning and that's not desired.
+ long start = mRecorder.getPeriodStart();
+ long end = mRecorder.getPeriodEnd();
+ long periodLength = end - start;
+ long now = System.currentTimeMillis();
+ long timeUsed = now - start;
+ long warningThreshold = 2*mPolicyThreshold*timeUsed/(timeUsed+periodLength);
+ if ((currentTotal > warningThreshold) && (currentTotal > mPolicyThreshold/4)) {
+ if (mWarningNotificationSent == false) {
+ mWarningNotificationSent = true;
+ mNotificationManager.cancel(com.android.internal.R.drawable.
+ stat_sys_throttled);
+ postNotification(com.android.internal.R.string.
+ throttle_warning_notification_title,
+ com.android.internal.R.string.
+ throttle_warning_notification_message,
+ com.android.internal.R.drawable.stat_sys_throttled,
+ 0);
+ }
+ } else {
+ if (mWarningNotificationSent == true) {
+ mNotificationManager.cancel(com.android.internal.R.drawable.
+ stat_sys_throttled);
+ mWarningNotificationSent =false;
+ }
+ }
+ }
+ }
+ }
+
+ private void postNotification(int titleInt, int messageInt, int icon, int flags) {
+ Intent intent = new Intent();
+ // TODO - fix up intent
+ intent.setClassName("com.android.phone", "com.android.phone.DataUsage");
+ intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
+
+ PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0);
+
+ Resources r = Resources.getSystem();
+ CharSequence title = r.getText(titleInt);
+ CharSequence message = r.getText(messageInt);
+ if (mThrottlingNotification == null) {
+ mThrottlingNotification = new Notification();
+ mThrottlingNotification.when = 0;
+ // TODO - fixup icon
+ mThrottlingNotification.icon = icon;
+ mThrottlingNotification.defaults &= ~Notification.DEFAULT_SOUND;
+ }
+ mThrottlingNotification.flags = flags;
+ mThrottlingNotification.tickerText = title;
+ mThrottlingNotification.setLatestEventInfo(mContext, title, message, pi);
+
+ mNotificationManager.notify(mThrottlingNotification.icon, mThrottlingNotification);
+ }
+
+
+ private synchronized void clearThrottleAndNotification() {
+ if (mThrottleIndex != THROTTLE_INDEX_UNTHROTTLED) {
+ synchronized (ThrottleService.this) {
+ mThrottleIndex = THROTTLE_INDEX_UNTHROTTLED;
+ }
+ try {
+ mNMService.setInterfaceThrottle(mIface, -1, -1);
+ } catch (Exception e) {
+ Slog.e(TAG, "error clearing Throttle: " + e);
+ }
+ Intent broadcast = new Intent(ThrottleManager.THROTTLE_ACTION);
+ broadcast.putExtra(ThrottleManager.EXTRA_THROTTLE_LEVEL, -1);
+ mContext.sendStickyBroadcast(broadcast);
+ }
+ mNotificationManager.cancel(com.android.internal.R.drawable.stat_sys_throttled);
+ mWarningNotificationSent = false;
+ }
+
+ private Calendar calculatePeriodEnd() {
+ Calendar end = GregorianCalendar.getInstance();
+ int day = end.get(Calendar.DAY_OF_MONTH);
+ end.set(Calendar.DAY_OF_MONTH, mPolicyResetDay);
+ end.set(Calendar.HOUR_OF_DAY, 0);
+ end.set(Calendar.MINUTE, 0);
+ if (day >= mPolicyResetDay) {
+ int month = end.get(Calendar.MONTH);
+ if (month == Calendar.DECEMBER) {
+ end.set(Calendar.YEAR, end.get(Calendar.YEAR) + 1);
+ month = Calendar.JANUARY - 1;
+ }
+ end.set(Calendar.MONTH, month + 1);
+ }
+
+ // TODO - remove!
+ if (SystemProperties.get(TESTING_ENABLED_PROPERTY).equals("true")) {
+ end = GregorianCalendar.getInstance();
+ end.add(Calendar.SECOND, TESTING_RESET_PERIOD_SEC);
+ }
+ return end;
+ }
+ private Calendar calculatePeriodStart(Calendar end) {
+ Calendar start = (Calendar)end.clone();
+ int month = end.get(Calendar.MONTH);
+ if (end.get(Calendar.MONTH) == Calendar.JANUARY) {
+ month = Calendar.DECEMBER + 1;
+ start.set(Calendar.YEAR, start.get(Calendar.YEAR) - 1);
+ }
+ start.set(Calendar.MONTH, month - 1);
+
+ // TODO - remove!!
+ if (SystemProperties.get(TESTING_ENABLED_PROPERTY).equals("true")) {
+ start = (Calendar)end.clone();
+ start.add(Calendar.SECOND, -TESTING_RESET_PERIOD_SEC);
+ }
+ return start;
+ }
+
+ private void onResetAlarm() {
+ if (DBG) {
+ Slog.d(TAG, "onResetAlarm - last period had " + mRecorder.getPeriodRx(0) +
+ " bytes read and " + mRecorder.getPeriodTx(0) + " written");
+ }
+
+ Calendar end = calculatePeriodEnd();
+ Calendar start = calculatePeriodStart(end);
+
+ clearThrottleAndNotification();
+
+ mRecorder.setNextPeriod(start,end);
+
+ mAlarmManager.cancel(mPendingResetIntent);
+ mAlarmManager.set(AlarmManager.RTC_WAKEUP, end.getTimeInMillis(),
+ mPendingResetIntent);
+ }
+ }
+
+ // records bytecount data for a given time and accumulates it into larger time windows
+ // for logging and other purposes
+ //
+ // since time can be changed (user or network action) we will have to track the time of the
+ // last recording and deal with it.
+ private static class DataRecorder {
+ long[] mPeriodRxData;
+ long[] mPeriodTxData;
+ int mCurrentPeriod;
+ int mPeriodCount;
+
+ Calendar mPeriodStart;
+ Calendar mPeriodEnd;
+
+ ThrottleService mParent;
+ Context mContext;
+
+ DataRecorder(Context context, ThrottleService parent) {
+ mContext = context;
+ mParent = parent;
+
+ synchronized (mParent) {
+ mPeriodCount = 6;
+ mPeriodRxData = new long[mPeriodCount];
+ mPeriodTxData = new long[mPeriodCount];
+
+ mPeriodStart = Calendar.getInstance();
+ mPeriodEnd = Calendar.getInstance();
+
+ zeroData(0);
+ retrieve();
+ }
+ }
+
+ void setNextPeriod(Calendar start, Calendar end) {
+ if (DBG) {
+ Slog.d(TAG, "setting next period to " + start.getTimeInMillis() +
+ " --until-- " + end.getTimeInMillis());
+ }
+ // if we roll back in time to a previous period, toss out the current data
+ // if we roll forward to the next period, advance to the next
+
+ if (end.before(mPeriodStart)) {
+ if (DBG) {
+ Slog.d(TAG, " old start was " + mPeriodStart.getTimeInMillis() + ", wiping");
+ }
+ synchronized (mParent) {
+ mPeriodRxData[mCurrentPeriod] = 0;
+ mPeriodTxData[mCurrentPeriod] = 0;
+ }
+ } else if(start.after(mPeriodEnd)) {
+ if (DBG) {
+ Slog.d(TAG, " old end was " + mPeriodEnd.getTimeInMillis() + ", following");
+ }
+ synchronized (mParent) {
+ ++mCurrentPeriod;
+ if (mCurrentPeriod >= mPeriodCount) mCurrentPeriod = 0;
+ mPeriodRxData[mCurrentPeriod] = 0;
+ mPeriodTxData[mCurrentPeriod] = 0;
+ }
+ } else {
+ if (DBG) Slog.d(TAG, " we fit - ammending to last period");
+ }
+ setPeriodStart(start);
+ setPeriodEnd(end);
+ record();
+ }
+
+ public long getPeriodEnd() {
+ synchronized (mParent) {
+ return mPeriodEnd.getTimeInMillis();
+ }
+ }
+
+ private void setPeriodEnd(Calendar end) {
+ synchronized (mParent) {
+ mPeriodEnd = end;
+ }
+ }
+
+ public long getPeriodStart() {
+ synchronized (mParent) {
+ return mPeriodStart.getTimeInMillis();
+ }
+ }
+
+ private void setPeriodStart(Calendar start) {
+ synchronized (mParent) {
+ mPeriodStart = start;
+ }
+ }
+
+ public int getPeriodCount() {
+ synchronized (mParent) {
+ return mPeriodCount;
+ }
+ }
+
+ private void zeroData(int field) {
+ synchronized (mParent) {
+ for(int period = 0; period<mPeriodCount; period++) {
+ mPeriodRxData[period] = 0;
+ mPeriodTxData[period] = 0;
+ }
+ mCurrentPeriod = 0;
+ }
+
+ }
+
+ // if time moves backward accumulate all read/write that's lost into the now
+ // otherwise time moved forward.
+ void addData(long bytesRead, long bytesWritten) {
+ synchronized (mParent) {
+ mPeriodRxData[mCurrentPeriod] += bytesRead;
+ mPeriodTxData[mCurrentPeriod] += bytesWritten;
+ }
+ record();
+ }
+
+ private File getDataFile() {
+ File dataDir = Environment.getDataDirectory();
+ File throttleDir = new File(dataDir, "system/throttle");
+ throttleDir.mkdirs();
+ File dataFile = new File(throttleDir, "data");
+ return dataFile;
+ }
+
+ private static final int DATA_FILE_VERSION = 1;
+
+ private void record() {
+ // 1 int version
+ // 1 int mPeriodCount
+ // 13*6 long[PERIOD_COUNT] mPeriodRxData
+ // 13*6 long[PERIOD_COUNT] mPeriodTxData
+ // 1 int mCurrentPeriod
+ // 13 long periodStartMS
+ // 13 long periodEndMS
+ // 200 chars max
+ StringBuilder builder = new StringBuilder();
+ builder.append(DATA_FILE_VERSION);
+ builder.append(":");
+ builder.append(mPeriodCount);
+ builder.append(":");
+ for(int i = 0; i < mPeriodCount; i++) {
+ builder.append(mPeriodRxData[i]);
+ builder.append(":");
+ }
+ for(int i = 0; i < mPeriodCount; i++) {
+ builder.append(mPeriodTxData[i]);
+ builder.append(":");
+ }
+ builder.append(mCurrentPeriod);
+ builder.append(":");
+ builder.append(mPeriodStart.getTimeInMillis());
+ builder.append(":");
+ builder.append(mPeriodEnd.getTimeInMillis());
+ builder.append(":");
+
+ BufferedWriter out = null;
+ try {
+ out = new BufferedWriter(new FileWriter(getDataFile()),256);
+ out.write(builder.toString());
+ } catch (IOException e) {
+ Slog.e(TAG, "Error writing data file");
+ return;
+ } finally {
+ if (out != null) {
+ try {
+ out.close();
+ } catch (Exception e) {}
+ }
+ }
+ }
+
+ private void retrieve() {
+ File f = getDataFile();
+ byte[] buffer;
+ FileInputStream s = null;
+ try {
+ buffer = new byte[(int)f.length()];
+ s = new FileInputStream(f);
+ s.read(buffer);
+ } catch (IOException e) {
+ Slog.e(TAG, "Error reading data file");
+ return;
+ } finally {
+ if (s != null) {
+ try {
+ s.close();
+ } catch (Exception e) {}
+ }
+ }
+ String data = new String(buffer);
+ if (data == null || data.length() == 0) return;
+ synchronized (mParent) {
+ String[] parsed = data.split(":");
+ int parsedUsed = 0;
+ if (parsed.length < 6) {
+ Slog.e(TAG, "reading data file with insufficient length - ignoring");
+ return;
+ }
+
+ if (Integer.parseInt(parsed[parsedUsed++]) != DATA_FILE_VERSION) {
+ Slog.e(TAG, "reading data file with bad version - ignoring");
+ return;
+ }
+
+ mPeriodCount = Integer.parseInt(parsed[parsedUsed++]);
+ if (parsed.length != 4 + (2 * mPeriodCount)) return;
+
+ mPeriodRxData = new long[mPeriodCount];
+ for(int i = 0; i < mPeriodCount; i++) {
+ mPeriodRxData[i] = Long.parseLong(parsed[parsedUsed++]);
+ }
+ mPeriodTxData = new long[mPeriodCount];
+ for(int i = 0; i < mPeriodCount; i++) {
+ mPeriodTxData[i] = Long.parseLong(parsed[parsedUsed++]);
+ }
+ mCurrentPeriod = Integer.parseInt(parsed[parsedUsed++]);
+ mPeriodStart = new GregorianCalendar();
+ mPeriodStart.setTimeInMillis(Long.parseLong(parsed[parsedUsed++]));
+ mPeriodEnd = new GregorianCalendar();
+ mPeriodEnd.setTimeInMillis(Long.parseLong(parsed[parsedUsed++]));
+ }
+ }
+
+ long getPeriodRx(int which) {
+ synchronized (mParent) {
+ if (which > mPeriodCount) return 0;
+ which = mCurrentPeriod - which;
+ if (which < 0) which += mPeriodCount;
+ return mPeriodRxData[which];
+ }
+ }
+ long getPeriodTx(int which) {
+ synchronized (mParent) {
+ if (which > mPeriodCount) return 0;
+ which = mCurrentPeriod - which;
+ if (which < 0) which += mPeriodCount;
+ return mPeriodTxData[which];
+ }
+ }
+ }
+
+ @Override
+ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+ if (mContext.checkCallingOrSelfPermission(
+ android.Manifest.permission.DUMP)
+ != PackageManager.PERMISSION_GRANTED) {
+ pw.println("Permission Denial: can't dump ThrottleService " +
+ "from from pid=" + Binder.getCallingPid() + ", uid=" +
+ Binder.getCallingUid());
+ return;
+ }
+ pw.println();
+
+ pw.println("The threshold is " + mPolicyThreshold +
+ ", after which you experince throttling to " +
+ mPolicyThrottleValue + "kbps");
+ pw.println("Current period is " +
+ (mRecorder.getPeriodEnd() - mRecorder.getPeriodStart())/1000 + " seconds long " +
+ "and ends in " + (mRecorder.getPeriodEnd() - System.currentTimeMillis()) / 1000 +
+ " seconds.");
+ pw.println("Polling every " + mPolicyPollPeriodSec + " seconds");
+ for (int i = 0; i < mRecorder.getPeriodCount(); i++) {
+ pw.println(" Period[" + i + "] - read:" + mRecorder.getPeriodRx(i) + ", written:" +
+ mRecorder.getPeriodTx(i));
+ }
+ }
+}
diff --git a/services/java/com/android/server/UiModeManagerService.java b/services/java/com/android/server/UiModeManagerService.java
index d6a42f6..3606629 100644
--- a/services/java/com/android/server/UiModeManagerService.java
+++ b/services/java/com/android/server/UiModeManagerService.java
@@ -25,6 +25,7 @@
import android.app.PendingIntent;
import android.app.StatusBarManager;
import android.app.UiModeManager;
+import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -103,6 +104,14 @@
private StatusBarManager mStatusBarManager;
private final PowerManager.WakeLock mWakeLock;
+ static Intent buildHomeIntent(String category) {
+ Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.addCategory(category);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+ | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
+ return intent;
+ }
+
// The broadcast receiver which receives the result of the ordered broadcast sent when
// the dock state changes. The original ordered broadcast is sent with an initial result
// code of RESULT_OK. If any of the registered broadcast receivers changes this value, e.g.,
@@ -114,24 +123,36 @@
return;
}
+ final int enableFlags = intent.getIntExtra("enableFlags", 0);
+ final int disableFlags = intent.getIntExtra("disableFlags", 0);
+
synchronized (mLock) {
// Launch a dock activity
- String category;
+ String category = null;
if (UiModeManager.ACTION_ENTER_CAR_MODE.equals(intent.getAction())) {
- // Only launch car home when car mode is enabled.
- category = Intent.CATEGORY_CAR_DOCK;
+ // Only launch car home when car mode is enabled and the caller
+ // has asked us to switch to it.
+ if ((enableFlags&UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
+ category = Intent.CATEGORY_CAR_DOCK;
+ }
} else if (UiModeManager.ACTION_ENTER_DESK_MODE.equals(intent.getAction())) {
- category = Intent.CATEGORY_DESK_DOCK;
+ // Only launch car home when desk mode is enabled and the caller
+ // has asked us to switch to it. Currently re-using the car
+ // mode flag since we don't have a formal API for "desk mode".
+ if ((enableFlags&UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
+ category = Intent.CATEGORY_DESK_DOCK;
+ }
} else {
- category = null;
+ // Launch the standard home app if requested.
+ if ((disableFlags&UiModeManager.DISABLE_CAR_MODE_GO_HOME) != 0) {
+ category = Intent.CATEGORY_HOME;
+ }
}
+
if (category != null) {
// This is the new activity that will serve as home while
// we are in care mode.
- intent = new Intent(Intent.ACTION_MAIN);
- intent.addCategory(category);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
- | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
+ Intent homeIntent = buildHomeIntent(category);
// Now we are going to be careful about switching the
// configuration and starting the activity -- we need to
@@ -148,7 +169,7 @@
}
try {
ActivityManagerNative.getDefault().startActivityWithConfig(
- null, intent, null, null, 0, null, null, 0, false, false,
+ null, homeIntent, null, null, 0, null, null, 0, false, false,
newConfig);
mHoldingConfiguration = false;
} catch (RemoteException e) {
@@ -188,7 +209,7 @@
mCharging = (intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0);
synchronized (mLock) {
if (mSystemReady) {
- updateLocked(0);
+ updateLocked(0, 0);
}
}
}
@@ -302,16 +323,16 @@
synchronized (mLock) {
setCarModeLocked(false);
if (mSystemReady) {
- updateLocked(flags);
+ updateLocked(0, flags);
}
}
}
- public void enableCarMode() {
+ public void enableCarMode(int flags) {
synchronized (mLock) {
setCarModeLocked(true);
if (mSystemReady) {
- updateLocked(0);
+ updateLocked(flags, 0);
}
}
}
@@ -342,7 +363,7 @@
Settings.Secure.UI_NIGHT_MODE, mode);
Binder.restoreCallingIdentity(ident);
mNightMode = mode;
- updateLocked(0);
+ updateLocked(0, 0);
}
}
}
@@ -355,7 +376,7 @@
synchronized (mLock) {
mSystemReady = true;
mCarModeEnabled = mDockState == Intent.EXTRA_DOCK_STATE_CAR;
- updateLocked(0);
+ updateLocked(0, 0);
mHandler.sendEmptyMessage(MSG_ENABLE_LOCATION_UPDATES);
}
}
@@ -376,7 +397,7 @@
mDockState = newState;
setCarModeLocked(mDockState == Intent.EXTRA_DOCK_STATE_CAR);
if (mSystemReady) {
- updateLocked(0);
+ updateLocked(UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME, 0);
}
}
}
@@ -426,7 +447,7 @@
}
}
- final void updateLocked(int flags) {
+ final void updateLocked(int enableFlags, int disableFlags) {
long ident = Binder.clearCallingIdentity();
try {
@@ -469,34 +490,39 @@
// not launch the corresponding dock application. This gives apps a chance
// to override the behavior and stay in their app even when the device is
// placed into a dock.
- mContext.sendOrderedBroadcast(new Intent(action), null,
+ Intent intent = new Intent(action);
+ intent.putExtra("enableFlags", enableFlags);
+ intent.putExtra("disableFlags", disableFlags);
+ mContext.sendOrderedBroadcast(intent, null,
mResultReceiver, null, Activity.RESULT_OK, null, null);
// Attempting to make this transition a little more clean, we are going
// to hold off on doing a configuration change until we have finished
- // the broacast and started the home activity.
+ // the broadcast and started the home activity.
mHoldingConfiguration = true;
+ } else {
+ Intent homeIntent = null;
+ if (mCarModeEnabled) {
+ if ((enableFlags&UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
+ homeIntent = buildHomeIntent(Intent.CATEGORY_CAR_DOCK);
+ }
+ } else if (mDockState == Intent.EXTRA_DOCK_STATE_DESK) {
+ if ((enableFlags&UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
+ homeIntent = buildHomeIntent(Intent.CATEGORY_DESK_DOCK);
+ }
+ } else {
+ if ((disableFlags&UiModeManager.DISABLE_CAR_MODE_GO_HOME) != 0) {
+ homeIntent = buildHomeIntent(Intent.CATEGORY_HOME);
+ }
+ }
+ if (homeIntent != null) {
+ try {
+ mContext.startActivity(homeIntent);
+ } catch (ActivityNotFoundException e) {
+ }
+ }
}
- if (oldAction != null && (flags&UiModeManager.DISABLE_CAR_MODE_GO_HOME) != 0) {
- // We are exiting the special mode, and have been asked to return
- // to the main home screen while doing so. To keep this clean, we
- // have the activity manager switch the configuration for us at the
- // same time as the switch.
- try {
- Intent intent = new Intent(Intent.ACTION_MAIN);
- intent.addCategory(Intent.CATEGORY_HOME);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- mHoldingConfiguration = false;
- updateConfigurationLocked(false);
- ActivityManagerNative.getDefault().startActivityWithConfig(
- null, intent, null, null, 0, null, null, 0, false, false,
- mConfiguration);
- } catch (RemoteException e) {
- Slog.w(TAG, e.getCause());
- }
- } else {
- updateConfigurationLocked(true);
- }
+ updateConfigurationLocked(true);
// keep screen on when charging and in car mode
boolean keepScreenOn = mCharging &&
@@ -569,7 +595,7 @@
if (isDoingNightMode() && mLocation != null
&& mNightMode == UiModeManager.MODE_NIGHT_AUTO) {
updateTwilightLocked();
- updateLocked(0);
+ updateLocked(0, 0);
}
}
break;
@@ -597,7 +623,7 @@
if (isDoingNightMode() && mLocation != null
&& mNightMode == UiModeManager.MODE_NIGHT_AUTO) {
updateTwilightLocked();
- updateLocked(0);
+ updateLocked(0, 0);
}
}
}
diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java
index cd6a131..657b6af 100644
--- a/services/java/com/android/server/WindowManagerService.java
+++ b/services/java/com/android/server/WindowManagerService.java
@@ -148,6 +148,7 @@
static final boolean DEBUG_STARTING_WINDOW = false;
static final boolean DEBUG_REORDER = false;
static final boolean DEBUG_WALLPAPER = false;
+ static final boolean DEBUG_FREEZE = false;
static final boolean SHOW_TRANSACTIONS = false;
static final boolean HIDE_STACK_CRAWLS = true;
static final boolean MEASURE_LATENCY = false;
@@ -4418,7 +4419,8 @@
final int N = mWindows.size();
for (int i=0; i<N; i++) {
WindowState w = (WindowState)mWindows.get(i);
- if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
+ if (w.isVisibleLw() && !w.mObscured
+ && (w.mOrientationChanging || !w.isDrawnLw())) {
return;
}
}
@@ -7925,7 +7927,7 @@
final AppWindowToken atoken = mAppToken;
return mSurface != null && !mAttachedHidden
&& (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
- && !mDrawPending && !mCommitDrawPending
+ && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending))
&& !mExiting && !mDestroying;
}
@@ -8029,12 +8031,14 @@
/**
* Returns true if the window has a surface that it has drawn a
- * complete UI in to.
+ * complete UI in to. Note that this returns true if the orientation
+ * is changing even if the window hasn't redrawn because we don't want
+ * to stop things from executing during that time.
*/
public boolean isDrawnLw() {
final AppWindowToken atoken = mAppToken;
return mSurface != null && !mDestroying
- && !mDrawPending && !mCommitDrawPending;
+ && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending));
}
public boolean fillsScreenLw(int screenWidth, int screenHeight,
@@ -10291,6 +10295,12 @@
if (w.mAttachedHidden || !w.isReadyForDisplay()) {
if (!w.mLastHidden) {
//dump();
+ if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow="
+ + w.mRootToken.waitingToShow + " polvis="
+ + w.mPolicyVisibility + " atthid="
+ + w.mAttachedHidden + " tokhid="
+ + w.mRootToken.hidden + " vis="
+ + w.mViewVisibility);
w.mLastHidden = true;
if (SHOW_TRANSACTIONS) logSurface(w,
"HIDE (performLayout)", null);
@@ -10686,23 +10696,28 @@
} else if (animating) {
requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
}
- mQueue.setHoldScreenLocked(holdScreen != null);
- if (screenBrightness < 0 || screenBrightness > 1.0f) {
- mPowerManager.setScreenBrightnessOverride(-1);
- } else {
- mPowerManager.setScreenBrightnessOverride((int)
- (screenBrightness * Power.BRIGHTNESS_ON));
- }
- if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
- mPowerManager.setButtonBrightnessOverride(-1);
- } else {
- mPowerManager.setButtonBrightnessOverride((int)
- (buttonBrightness * Power.BRIGHTNESS_ON));
- }
- if (holdScreen != mHoldingScreenOn) {
- mHoldingScreenOn = holdScreen;
- Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
- mH.sendMessage(m);
+
+ if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen
+ + " holdScreen=" + holdScreen);
+ if (!mDisplayFrozen) {
+ mQueue.setHoldScreenLocked(holdScreen != null);
+ if (screenBrightness < 0 || screenBrightness > 1.0f) {
+ mPowerManager.setScreenBrightnessOverride(-1);
+ } else {
+ mPowerManager.setScreenBrightnessOverride((int)
+ (screenBrightness * Power.BRIGHTNESS_ON));
+ }
+ if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
+ mPowerManager.setButtonBrightnessOverride(-1);
+ } else {
+ mPowerManager.setButtonBrightnessOverride((int)
+ (buttonBrightness * Power.BRIGHTNESS_ON));
+ }
+ if (holdScreen != mHoldingScreenOn) {
+ mHoldingScreenOn = holdScreen;
+ Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
+ mH.sendMessage(m);
+ }
}
if (mTurnOnScreen) {
@@ -10979,6 +10994,8 @@
mFreezeGcPending = now;
}
+ if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException());
+
mDisplayFrozen = true;
if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
@@ -11002,6 +11019,8 @@
return;
}
+ if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException());
+
mDisplayFrozen = false;
mH.removeMessages(H.APP_FREEZE_TIMEOUT);
if (PROFILE_ORIENTATION) {
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index bc26fa0..1486a1d 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -6867,6 +6867,8 @@
enforceCallingPermission(android.Manifest.permission.GET_TASKS,
"getRecentTasks()");
+ IPackageManager pm = ActivityThread.getPackageManager();
+
final int N = mRecentTasks.size();
ArrayList<ActivityManager.RecentTaskInfo> res
= new ArrayList<ActivityManager.RecentTaskInfo>(
@@ -6883,6 +6885,25 @@
rti.baseIntent = new Intent(
tr.intent != null ? tr.intent : tr.affinityIntent);
rti.origActivity = tr.origActivity;
+
+ if ((flags&ActivityManager.RECENT_IGNORE_UNAVAILABLE) != 0) {
+ // Check whether this activity is currently available.
+ try {
+ if (rti.origActivity != null) {
+ if (pm.getActivityInfo(rti.origActivity, 0) == null) {
+ continue;
+ }
+ } else if (rti.baseIntent != null) {
+ if (pm.queryIntentActivities(rti.baseIntent,
+ null, 0) == null) {
+ continue;
+ }
+ }
+ } catch (RemoteException e) {
+ // Will never happen.
+ }
+ }
+
res.add(rti);
maxNum--;
}
@@ -9884,7 +9905,7 @@
}
if (mOrderedBroadcasts.size() > 0) {
pw.println(" ");
- pw.println(" Active serialized broadcasts:");
+ pw.println(" Active ordered broadcasts:");
}
for (int i=mOrderedBroadcasts.size()-1; i>=0; i--) {
pw.println(" Serialized Broadcast #" + i + ":");
@@ -12898,7 +12919,7 @@
try {
if (DEBUG_BROADCAST_LIGHT) {
int seq = r.intent.getIntExtra("seq", -1);
- Slog.i(TAG, "Delivering to " + filter.receiverList.app
+ Slog.i(TAG, "Delivering to " + filter
+ " (seq=" + seq + "): " + r);
}
performReceive(filter.receiverList.app, filter.receiverList.receiver,
@@ -12938,7 +12959,7 @@
if (DEBUG_BROADCAST) Slog.v(TAG, "processNextBroadcast: "
+ mParallelBroadcasts.size() + " broadcasts, "
- + mOrderedBroadcasts.size() + " serialized broadcasts");
+ + mOrderedBroadcasts.size() + " ordered broadcasts");
updateCpuStats();
@@ -12956,7 +12977,7 @@
for (int i=0; i<N; i++) {
Object target = r.receivers.get(i);
if (DEBUG_BROADCAST) Slog.v(TAG,
- "Delivering non-serialized to registered "
+ "Delivering non-ordered to registered "
+ target + ": " + r);
deliverToRegisteredReceiver(r, (BroadcastFilter)target, false);
}
@@ -13094,12 +13115,14 @@
// a direct call.
BroadcastFilter filter = (BroadcastFilter)nextReceiver;
if (DEBUG_BROADCAST) Slog.v(TAG,
- "Delivering serialized to registered "
+ "Delivering ordered to registered "
+ filter + ": " + r);
deliverToRegisteredReceiver(r, filter, r.ordered);
if (r.receiver == null || !r.ordered) {
// The receiver has already finished, so schedule to
// process the next one.
+ if (DEBUG_BROADCAST) Slog.v(TAG, "Quick finishing: ordered="
+ + r.ordered + " receiver=" + r.receiver);
r.state = BroadcastRecord.IDLE;
scheduleBroadcastsLocked();
}
diff --git a/services/java/com/android/server/am/BroadcastRecord.java b/services/java/com/android/server/am/BroadcastRecord.java
index 75c9600..c3f0b3e 100644
--- a/services/java/com/android/server/am/BroadcastRecord.java
+++ b/services/java/com/android/server/am/BroadcastRecord.java
@@ -126,7 +126,9 @@
pw.println(prefix + "curApp=" + curApp);
pw.println(prefix + "curComponent="
+ (curComponent != null ? curComponent.toShortString() : "--"));
- pw.println(prefix + "curSourceDir=" + curReceiver.applicationInfo.sourceDir);
+ if (curReceiver != null && curReceiver.applicationInfo != null) {
+ pw.println(prefix + "curSourceDir=" + curReceiver.applicationInfo.sourceDir);
+ }
}
String stateStr = " (?)";
switch (state) {
diff --git a/telephony/java/com/android/internal/telephony/DataConnection.java b/telephony/java/com/android/internal/telephony/DataConnection.java
index 70fdadf..1f8bbcf 100644
--- a/telephony/java/com/android/internal/telephony/DataConnection.java
+++ b/telephony/java/com/android/internal/telephony/DataConnection.java
@@ -310,7 +310,8 @@
phone.mCM.deactivateDataCall(cid, obtainMessage(EVENT_DEACTIVATE_DONE, o));
} else {
if (DBG) log("tearDownData radio is off sendMessage EVENT_DEACTIVATE_DONE immediately");
- sendMessage(obtainMessage(EVENT_DEACTIVATE_DONE, o));
+ AsyncResult ar = new AsyncResult(o, null, null);
+ sendMessage(obtainMessage(EVENT_DEACTIVATE_DONE, ar));
}
}
diff --git a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
index e8e18a1..3b9e6cc 100644
--- a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
@@ -19,7 +19,6 @@
import android.app.PendingIntent;
import android.os.AsyncResult;
import android.os.Handler;
-import android.os.INetStatService;
import android.os.Message;
import android.os.RemoteException;
import android.provider.Settings;
@@ -172,7 +171,6 @@
protected Handler mDataConnectionTracker = null;
- protected INetStatService netstat;
protected long txPkts, rxPkts, sentSinceLastRecv;
protected int netStatPollPeriod;
protected int mNoRecvPollCount = 0;
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java
index 2f801cc..217e1e8 100644
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java
@@ -26,9 +26,9 @@
import android.net.ConnectivityManager;
import android.net.IConnectivityManager;
import android.net.NetworkInfo;
+import android.net.TrafficStats;
import android.net.wifi.WifiManager;
import android.os.AsyncResult;
-import android.os.INetStatService;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -176,8 +176,6 @@
p.mSST.registerForRoamingOff(this, EVENT_ROAMING_OFF, null);
p.mCM.registerForCdmaOtaProvision(this, EVENT_CDMA_OTA_PROVISION, null);
- this.netstat = INetStatService.Stub.asInterface(ServiceManager.getService("netstat"));
-
IntentFilter filter = new IntentFilter();
filter.addAction(INTENT_RECONNECT_ALARM);
filter.addAction(Intent.ACTION_SCREEN_ON);
@@ -495,79 +493,71 @@
preTxPkts = txPkts;
preRxPkts = rxPkts;
- // check if netstat is still valid to avoid NullPointerException after NTC
- if (netstat != null) {
- try {
- txPkts = netstat.getMobileTxPackets();
- rxPkts = netstat.getMobileRxPackets();
- } catch (RemoteException e) {
- txPkts = 0;
- rxPkts = 0;
- }
+ txPkts = TrafficStats.getMobileTxPackets();
+ rxPkts = TrafficStats.getMobileRxPackets();
- //Log.d(LOG_TAG, "rx " + String.valueOf(rxPkts) + " tx " + String.valueOf(txPkts));
+ //Log.d(LOG_TAG, "rx " + String.valueOf(rxPkts) + " tx " + String.valueOf(txPkts));
- if (netStatPollEnabled && (preTxPkts > 0 || preRxPkts > 0)) {
- sent = txPkts - preTxPkts;
- received = rxPkts - preRxPkts;
+ if (netStatPollEnabled && (preTxPkts > 0 || preRxPkts > 0)) {
+ sent = txPkts - preTxPkts;
+ received = rxPkts - preRxPkts;
- if ( sent > 0 && received > 0 ) {
- sentSinceLastRecv = 0;
- newActivity = Activity.DATAINANDOUT;
- } else if (sent > 0 && received == 0) {
- if (phone.getState() == Phone.State.IDLE) {
- sentSinceLastRecv += sent;
- } else {
- sentSinceLastRecv = 0;
- }
- newActivity = Activity.DATAOUT;
- } else if (sent == 0 && received > 0) {
- sentSinceLastRecv = 0;
- newActivity = Activity.DATAIN;
- } else if (sent == 0 && received == 0) {
- newActivity = (activity == Activity.DORMANT) ? activity : Activity.NONE;
+ if ( sent > 0 && received > 0 ) {
+ sentSinceLastRecv = 0;
+ newActivity = Activity.DATAINANDOUT;
+ } else if (sent > 0 && received == 0) {
+ if (phone.getState() == Phone.State.IDLE) {
+ sentSinceLastRecv += sent;
} else {
sentSinceLastRecv = 0;
- newActivity = (activity == Activity.DORMANT) ? activity : Activity.NONE;
}
-
- if (activity != newActivity) {
- activity = newActivity;
- phone.notifyDataActivity();
- }
- }
-
- if (sentSinceLastRecv >= NUMBER_SENT_PACKETS_OF_HANG) {
- // Packets sent without ack exceeded threshold.
-
- if (mNoRecvPollCount == 0) {
- EventLog.writeEvent(
- EventLogTags.PDP_RADIO_RESET_COUNTDOWN_TRIGGERED,
- sentSinceLastRecv);
- }
-
- if (mNoRecvPollCount < NO_RECV_POLL_LIMIT) {
- mNoRecvPollCount++;
- // Slow down the poll interval to let things happen
- netStatPollPeriod = POLL_NETSTAT_SLOW_MILLIS;
- } else {
- if (DBG) log("Sent " + String.valueOf(sentSinceLastRecv) +
- " pkts since last received");
- // We've exceeded the threshold. Restart the radio.
- netStatPollEnabled = false;
- stopNetStatPoll();
- restartRadio();
- EventLog.writeEvent(EventLogTags.PDP_RADIO_RESET, NO_RECV_POLL_LIMIT);
- }
+ newActivity = Activity.DATAOUT;
+ } else if (sent == 0 && received > 0) {
+ sentSinceLastRecv = 0;
+ newActivity = Activity.DATAIN;
+ } else if (sent == 0 && received == 0) {
+ newActivity = (activity == Activity.DORMANT) ? activity : Activity.NONE;
} else {
- mNoRecvPollCount = 0;
- netStatPollPeriod = POLL_NETSTAT_MILLIS;
+ sentSinceLastRecv = 0;
+ newActivity = (activity == Activity.DORMANT) ? activity : Activity.NONE;
}
- if (netStatPollEnabled) {
- mDataConnectionTracker.postDelayed(this, netStatPollPeriod);
+ if (activity != newActivity) {
+ activity = newActivity;
+ phone.notifyDataActivity();
}
}
+
+ if (sentSinceLastRecv >= NUMBER_SENT_PACKETS_OF_HANG) {
+ // Packets sent without ack exceeded threshold.
+
+ if (mNoRecvPollCount == 0) {
+ EventLog.writeEvent(
+ EventLogTags.PDP_RADIO_RESET_COUNTDOWN_TRIGGERED,
+ sentSinceLastRecv);
+ }
+
+ if (mNoRecvPollCount < NO_RECV_POLL_LIMIT) {
+ mNoRecvPollCount++;
+ // Slow down the poll interval to let things happen
+ netStatPollPeriod = POLL_NETSTAT_SLOW_MILLIS;
+ } else {
+ if (DBG) log("Sent " + String.valueOf(sentSinceLastRecv) +
+ " pkts since last received");
+ // We've exceeded the threshold. Restart the radio.
+ netStatPollEnabled = false;
+ stopNetStatPoll();
+ restartRadio();
+ EventLog.writeEvent(EventLogTags.PDP_RADIO_RESET, NO_RECV_POLL_LIMIT);
+ }
+ } else {
+ mNoRecvPollCount = 0;
+ netStatPollPeriod = POLL_NETSTAT_MILLIS;
+ }
+
+ if (netStatPollEnabled) {
+ mDataConnectionTracker.postDelayed(this, netStatPollPeriod);
+ }
}
};
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
index f968652..cbfb550 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
@@ -30,10 +30,10 @@
import android.net.ConnectivityManager;
import android.net.IConnectivityManager;
import android.net.NetworkInfo;
+import android.net.TrafficStats;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.AsyncResult;
-import android.os.INetStatService;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -83,7 +83,6 @@
//***** Instance Variables
- INetStatService netstat;
// Indicates baseband will not auto-attach
private boolean noAutoAttach = false;
@@ -219,8 +218,6 @@
p.mSST.registerForPsRestrictedEnabled(this, EVENT_PS_RESTRICT_ENABLED, null);
p.mSST.registerForPsRestrictedDisabled(this, EVENT_PS_RESTRICT_DISABLED, null);
- this.netstat = INetStatService.Stub.asInterface(ServiceManager.getService("netstat"));
-
IntentFilter filter = new IntentFilter();
filter.addAction(INTENT_RECONNECT_ALARM);
filter.addAction(Intent.ACTION_SCREEN_ON);
@@ -841,13 +838,8 @@
preTxPkts = txPkts;
preRxPkts = rxPkts;
- try {
- txPkts = netstat.getMobileTxPackets();
- rxPkts = netstat.getMobileRxPackets();
- } catch (RemoteException e) {
- txPkts = 0;
- rxPkts = 0;
- }
+ txPkts = TrafficStats.getMobileTxPackets();
+ rxPkts = TrafficStats.getMobileRxPackets();
//Log.d(LOG_TAG, "rx " + String.valueOf(rxPkts) + " tx " + String.valueOf(txPkts));
diff --git a/tests/ImfTest/src/com/android/imftest/samples/OneEditTextActivitySelected.java b/tests/ImfTest/src/com/android/imftest/samples/OneEditTextActivitySelected.java
index f313a90..64882aa 100644
--- a/tests/ImfTest/src/com/android/imftest/samples/OneEditTextActivitySelected.java
+++ b/tests/ImfTest/src/com/android/imftest/samples/OneEditTextActivitySelected.java
@@ -55,7 +55,11 @@
((ScrollView) mRootView).addView(layout);
setContentView(mRootView);
- }
+
+ // set to resize so IME is always shown (and also so
+ // ImfBaseTestCase#destructiveCheckImeInitialState thinks it should always be shown
+ this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
+ }
public View getRootView() {
return mRootView;
diff --git a/tests/ImfTest/tests/src/com/android/imftest/samples/ImfBaseTestCase.java b/tests/ImfTest/tests/src/com/android/imftest/samples/ImfBaseTestCase.java
index 1957640..50e2009 100755
--- a/tests/ImfTest/tests/src/com/android/imftest/samples/ImfBaseTestCase.java
+++ b/tests/ImfTest/tests/src/com/android/imftest/samples/ImfBaseTestCase.java
@@ -19,6 +19,7 @@
import android.app.Activity;
import android.app.KeyguardManager;
import android.content.Context;
+import android.content.res.Configuration;
import android.os.SystemClock;
import android.test.InstrumentationTestCase;
import android.view.KeyEvent;
@@ -43,7 +44,6 @@
public final int IME_MIN_HEIGHT = 150;
public final int IME_MAX_HEIGHT = 300;
- public final String TARGET_PACKAGE_NAME = "com.android.imftest";
protected InputMethodManager mImm;
protected T mTargetActivity;
protected boolean mExpectAutoPop;
@@ -56,9 +56,12 @@
@Override
public void setUp() throws Exception {
super.setUp();
+ final String packageName = getInstrumentation().getTargetContext().getPackageName();
+ mTargetActivity = launchActivity(packageName, mTargetActivityClass, null);
+ // expect ime to auto pop up if device has no hard keyboard
+ mExpectAutoPop = mTargetActivity.getResources().getConfiguration().hardKeyboardHidden ==
+ Configuration.HARDKEYBOARDHIDDEN_YES;
- mTargetActivity = launchActivity(TARGET_PACKAGE_NAME, mTargetActivityClass, null);
- mExpectAutoPop = mTargetActivity.getResources().getBoolean(R.bool.def_expect_ime_autopop);
mImm = InputMethodManager.getInstance(mTargetActivity);
KeyguardManager keyguardManager =
@@ -104,9 +107,9 @@
}
public void destructiveCheckImeInitialState(View rootView, View servedView) {
- if (mExpectAutoPop && (mTargetActivity.getWindow().getAttributes().
- softInputMode&WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST)
- == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) {
+ int windowSoftInputMode = mTargetActivity.getWindow().getAttributes().softInputMode;
+ int adjustMode = windowSoftInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
+ if (mExpectAutoPop && adjustMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) {
assertTrue(destructiveCheckImeUp(rootView, servedView));
} else {
assertFalse(destructiveCheckImeUp(rootView, servedView));
diff --git a/tools/layoutlib/bridge/src/android/graphics/Paint.java b/tools/layoutlib/bridge/src/android/graphics/Paint.java
index e4f9794..619ab30 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Paint.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Paint.java
@@ -208,6 +208,12 @@
this(0);
}
+ /*
+ * Do not remove or com.android.layoutlib.bridge.TestClassReplacement fails.
+ */
+ @Override
+ public void finalize() { }
+
public Paint(int flags) {
setFlags(flags | DEFAULT_PAINT_FLAGS);
initFont();