summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ActivityTests/AndroidManifest.xml1
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java48
-rw-r--r--tests/ActivityTests/src/com/google/android/test/activity/AlarmSpamReceiver.java31
-rw-r--r--tests/FixVibrateSetting/src/com/android/fixvibratesetting/FixVibrateSetting.java16
-rw-r--r--tests/FrameworkPerf/src/com/android/frameworkperf/SchedulerService.java21
-rw-r--r--tests/StatusBar/res/drawable-hdpi/stat_sys_warning.pngbin0 -> 769 bytes
-rw-r--r--tests/StatusBar/res/drawable-mdpi/stat_sys_warning.pngbin0 -> 654 bytes
-rw-r--r--tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java550
-rw-r--r--tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java23
-rw-r--r--tests/UsageStatsTest/src/com/android/tests/usagestats/UsageLogActivity.java6
10 files changed, 394 insertions, 302 deletions
diff --git a/tests/ActivityTests/AndroidManifest.xml b/tests/ActivityTests/AndroidManifest.xml
index c105491..dae7cc5 100644
--- a/tests/ActivityTests/AndroidManifest.xml
+++ b/tests/ActivityTests/AndroidManifest.xml
@@ -76,5 +76,6 @@
android:authorities="com.google.android.test.activity.single_user"
android:singleUser="true" android:exported="true" />
<receiver android:name="TrackTimeReceiver" />
+ <receiver android:name="AlarmSpamReceiver" />
</application>
</manifest>
diff --git a/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java b/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java
index ddcfd9e..2f0bf39 100644
--- a/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java
+++ b/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java
@@ -22,6 +22,7 @@ import java.util.List;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityOptions;
+import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
@@ -31,14 +32,18 @@ import android.content.ContentProviderClient;
import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.BitmapFactory;
+import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
+import android.os.PowerManager;
import android.os.RemoteException;
+import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
import android.graphics.Bitmap;
+import android.provider.Settings;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -58,6 +63,8 @@ public class ActivityTestMain extends Activity {
static final String KEY_CONFIGURATION = "configuration";
ActivityManager mAm;
+ PowerManager mPower;
+ AlarmManager mAlarm;
Configuration mOverrideConfig;
int mSecondUser;
@@ -66,6 +73,7 @@ public class ActivityTestMain extends Activity {
ServiceConnection mIsolatedConnection;
static final int MSG_SPAM = 1;
+ static final int MSG_SPAM_ALARM = 2;
final Handler mHandler = new Handler() {
@Override
@@ -82,6 +90,15 @@ public class ActivityTestMain extends Activity {
startActivity(intent, options);
scheduleSpam(!fg);
} break;
+ case MSG_SPAM_ALARM: {
+ long when = SystemClock.elapsedRealtime();
+ Intent intent = new Intent(ActivityTestMain.this, AlarmSpamReceiver.class);
+ intent.setAction("com.example.SPAM_ALARM=" + when);
+ PendingIntent pi = PendingIntent.getBroadcast(ActivityTestMain.this,
+ 0, intent, 0);
+ mAlarm.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME, when+(30*1000), pi);
+ scheduleSpamAlarm(30*1000);
+ } break;
}
super.handleMessage(msg);
}
@@ -145,7 +162,9 @@ public class ActivityTestMain extends Activity {
Log.i(TAG, "Referrer: " + getReferrer());
- mAm = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
+ mAm = getSystemService(ActivityManager.class);
+ mPower = getSystemService(PowerManager.class);
+ mAlarm = getSystemService(AlarmManager.class);
if (savedInstanceState != null) {
mOverrideConfig = savedInstanceState.getParcelable(KEY_CONFIGURATION);
if (mOverrideConfig != null) {
@@ -431,7 +450,25 @@ public class ActivityTestMain extends Activity {
new MenuItem.OnMenuItemClickListener() {
@Override public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(Intent.ACTION_MAIN);
- intent.putExtra("gulp", new int[1024*1024]);
+ intent.putExtra("gulp", new int[1024 * 1024]);
+ startActivity(intent);
+ return true;
+ }
+ });
+ menu.add("Spam idle alarm").setOnMenuItemClickListener(
+ new MenuItem.OnMenuItemClickListener() {
+ @Override public boolean onMenuItemClick(MenuItem item) {
+ scheduleSpamAlarm(0);
+ return true;
+ }
+ });
+ menu.add("Ignore battery optimizations").setOnMenuItemClickListener(
+ new MenuItem.OnMenuItemClickListener() {
+ @Override public boolean onMenuItemClick(MenuItem item) {
+ Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
+ if (!mPower.isIgnoringBatteryOptimizations(getPackageName())) {
+ intent.setData(Uri.fromParts("package", getPackageName(), null));
+ }
startActivity(intent);
return true;
}
@@ -467,6 +504,7 @@ public class ActivityTestMain extends Activity {
@Override
protected void onStop() {
super.onStop();
+ mHandler.removeMessages(MSG_SPAM_ALARM);
for (ServiceConnection conn : mConnections) {
unbindService(conn);
}
@@ -536,6 +574,12 @@ public class ActivityTestMain extends Activity {
mHandler.sendMessageDelayed(msg, 500);
}
+ void scheduleSpamAlarm(long delay) {
+ mHandler.removeMessages(MSG_SPAM_ALARM);
+ Message msg = mHandler.obtainMessage(MSG_SPAM_ALARM);
+ mHandler.sendMessageDelayed(msg, delay);
+ }
+
private View scrollWrap(View view) {
ScrollView scroller = new ScrollView(this);
scroller.addView(view, new ScrollView.LayoutParams(ScrollView.LayoutParams.MATCH_PARENT,
diff --git a/tests/ActivityTests/src/com/google/android/test/activity/AlarmSpamReceiver.java b/tests/ActivityTests/src/com/google/android/test/activity/AlarmSpamReceiver.java
new file mode 100644
index 0000000..0cb1ffb
--- /dev/null
+++ b/tests/ActivityTests/src/com/google/android/test/activity/AlarmSpamReceiver.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.android.test.activity;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.UserHandle;
+import android.util.Log;
+
+public class AlarmSpamReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Log.i("AlarmSpamReceiver", "Received spam = " + intent);
+ }
+}
diff --git a/tests/FixVibrateSetting/src/com/android/fixvibratesetting/FixVibrateSetting.java b/tests/FixVibrateSetting/src/com/android/fixvibratesetting/FixVibrateSetting.java
index 947ea78..2e51570 100644
--- a/tests/FixVibrateSetting/src/com/android/fixvibratesetting/FixVibrateSetting.java
+++ b/tests/FixVibrateSetting/src/com/android/fixvibratesetting/FixVibrateSetting.java
@@ -109,14 +109,20 @@ public class FixVibrateSetting extends Activity implements View.OnClickListener
}
private void test() {
- Notification n = new Notification(R.drawable.stat_sys_warning, "Test notification",
- System.currentTimeMillis());
Intent intent = new Intent(this, FixVibrateSetting.class);
PendingIntent pending = PendingIntent.getActivity(this, 0, intent, 0);
- n.setLatestEventInfo(this, "Test notification", "Test notification", pending);
- n.vibrate = new long[] { 0, 700, 500, 1000 };
- n.flags |= Notification.FLAG_AUTO_CANCEL;
+ Notification n = new Notification.Builder(this)
+ .setSmallIcon(R.drawable.stat_sys_warning)
+ .setTicker("Test notification")
+ .setWhen(System.currentTimeMillis())
+ .setContentTitle("Test notification")
+ .setContentText("Test notification")
+ .setContentIntent(pending)
+ .setVibrate(new long[] { 0, 700, 500, 1000 })
+ .setAutoCancel(true)
+ .build();
+
mNotificationManager.notify(1, n);
}
}
diff --git a/tests/FrameworkPerf/src/com/android/frameworkperf/SchedulerService.java b/tests/FrameworkPerf/src/com/android/frameworkperf/SchedulerService.java
index 7691e64..fc3f390 100644
--- a/tests/FrameworkPerf/src/com/android/frameworkperf/SchedulerService.java
+++ b/tests/FrameworkPerf/src/com/android/frameworkperf/SchedulerService.java
@@ -26,15 +26,18 @@ public class SchedulerService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- Notification status = new Notification(R.drawable.stat_happy, null,
- System.currentTimeMillis());
- status.flags |= Notification.FLAG_ONGOING_EVENT;
- status.setLatestEventInfo(this, "Scheduler Test running",
- "Scheduler Test running", PendingIntent.getActivity(this, 0,
- new Intent(this, FrameworkPerfActivity.class)
- .setAction(Intent.ACTION_MAIN)
- .addCategory(Intent.CATEGORY_LAUNCHER)
- .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0));
+ Notification status = new Notification.Builder(this)
+ .setSmallIcon(R.drawable.stat_happy)
+ .setWhen(System.currentTimeMillis())
+ .setContentTitle("Scheduler Test running")
+ .setContentText("Scheduler Test running")
+ .setContentIntent(PendingIntent.getActivity(this, 0,
+ new Intent(this, FrameworkPerfActivity.class)
+ .setAction(Intent.ACTION_MAIN)
+ .addCategory(Intent.CATEGORY_LAUNCHER)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0))
+ .setOngoing(true)
+ .build();
startForeground(1, status);
return START_STICKY;
}
diff --git a/tests/StatusBar/res/drawable-hdpi/stat_sys_warning.png b/tests/StatusBar/res/drawable-hdpi/stat_sys_warning.png
new file mode 100644
index 0000000..dbaf944
--- /dev/null
+++ b/tests/StatusBar/res/drawable-hdpi/stat_sys_warning.png
Binary files differ
diff --git a/tests/StatusBar/res/drawable-mdpi/stat_sys_warning.png b/tests/StatusBar/res/drawable-mdpi/stat_sys_warning.png
new file mode 100644
index 0000000..168f8f6
--- /dev/null
+++ b/tests/StatusBar/res/drawable-mdpi/stat_sys_warning.png
Binary files differ
diff --git a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java
index ba160b1..67b9d77 100644
--- a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java
+++ b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java
@@ -25,7 +25,6 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
-import android.os.Environment;
import android.os.Vibrator;
import android.os.Handler;
import android.os.UserHandle;
@@ -85,7 +84,7 @@ public class NotificationTestList extends TestActivity
}
private Test[] mTests = new Test[] {
- new Test("Off and sound") {
+ new Test("Off") {
public void run() {
PowerManager pm = (PowerManager)NotificationTestList.this.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl =
@@ -94,9 +93,12 @@ public class NotificationTestList extends TestActivity
pm.goToSleep(SystemClock.uptimeMillis());
- Notification n = new Notification();
- n.sound = Uri.parse("file://" + Environment.getExternalStorageDirectory() +
- "/virtual-void.mp3");
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.stat_sys_phone)
+ .setContentTitle(name)
+ .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
+ getPackageName() + "/raw/ringer"))
+ .build();
Log.d(TAG, "n.sound=" + n.sound);
mNM.notify(1, n);
@@ -114,122 +116,120 @@ public class NotificationTestList extends TestActivity
}
},
- new Test("Button") {
+ new Test("Custom Button") {
public void run() {
- Notification n = new Notification(R.drawable.icon1, null,
- mActivityCreateTime);
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon1)
+ .setWhen(mActivityCreateTime)
+ .setContentTitle(name)
+ .setOngoing(true)
+ .build();
n.contentView = new RemoteViews(getPackageName(), R.layout.button_notification);
- n.flags |= Notification.FLAG_ONGOING_EVENT;
- n.contentIntent = makeIntent();
n.contentView.setOnClickPendingIntent(R.id.button, makeIntent2());
mNM.notify(1, n);
}
},
- new Test("custom intent on text view") {
+ new Test("Action Button") {
public void run() {
- Notification n = new Notification(R.drawable.icon1, null,
- mActivityCreateTime);
- n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
- "This is a notification!!!", null);
- n.contentView.setOnClickPendingIntent(com.android.internal.R.id.text,
- makeIntent2());
- mNM.notify(1, n);
- }
- },
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon1)
+ .setWhen(mActivityCreateTime)
+ .setContentTitle(name)
+ .setOngoing(true)
+ .addAction(R.drawable.ic_statusbar_chat, "Button", makeIntent2())
+ .build();
- new Test("Ticker 1 line") {
- public void run() {
- Notification n = new Notification(R.drawable.icon1, "tick tick tick",
- mActivityCreateTime);
- n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
- "This is a notification!!!", makeIntent());
mNM.notify(1, n);
}
},
- new Test("No view") {
+ new Test("with intent") {
public void run() {
- Notification n = new Notification(R.drawable.icon1, "No view",
- System.currentTimeMillis());
- mNM.notify(1, n);
- }
- },
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon1)
+ .setWhen(mActivityCreateTime)
+ .setContentTitle("Persistent #1")
+ .setContentText("This is a notification!!!")
+ .setContentIntent(makeIntent2())
+ .setOngoing(true)
+ .build();
- new Test("No intent") {
- public void run() {
- Notification n = new Notification(R.drawable.icon1, "No intent",
- System.currentTimeMillis());
- n.setLatestEventInfo(NotificationTestList.this, "No intent",
- "No intent", null);
mNM.notify(1, n);
}
},
- new Test("Layout") {
+ new Test("Whens") {
public void run()
{
- Notification n;
+ Notification.Builder n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon1)
+ .setContentTitle(name)
+ .setOngoing(true);
- n = new Notification(NotificationTestList.this,
- R.drawable.ic_statusbar_missedcall,
- null, System.currentTimeMillis()-(1000*60*60*24),
- "(453) 123-2328",
- "", null);
- n.flags |= Notification.FLAG_ONGOING_EVENT;
+ mNM.notify(1, n.setContentTitle("(453) 123-2328")
+ .setWhen(System.currentTimeMillis()-(1000*60*60*24))
+ .build());
- mNM.notify(1, n);
-
- mNM.notify(2, new Notification(NotificationTestList.this,
- R.drawable.ic_statusbar_email,
- null, System.currentTimeMillis(),
- "Mark Willem, Me (2)",
- "Re: Didn't you get the memo?", null));
+ mNM.notify(1, n.setContentTitle("Mark Willem, Me (2)")
+ .setWhen(System.currentTimeMillis())
+ .build());
- mNM.notify(3, new Notification(NotificationTestList.this,
- R.drawable.ic_statusbar_chat,
- null, System.currentTimeMillis()+(1000*60*60*24),
- "Sophia Winterlanden",
- "Lorem ipsum dolor sit amet.", null));
+ mNM.notify(1, n.setContentTitle("Sophia Winterlanden")
+ .setWhen(System.currentTimeMillis() + (1000 * 60 * 60 * 24))
+ .build());
}
},
new Test("Bad Icon #1 (when=create)") {
public void run() {
- Notification n = new Notification(R.layout.chrono_notification /* not an icon */,
- null, mActivityCreateTime);
- n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
- "This is the same notification!!!", makeIntent());
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.layout.chrono_notification /* not an icon */)
+ .setWhen(mActivityCreateTime)
+ .setContentTitle("Persistent #1")
+ .setContentText("This is the same notification!!")
+ .setContentIntent(makeIntent())
+ .build();
mNM.notify(1, n);
}
},
new Test("Bad Icon #1 (when=now)") {
public void run() {
- Notification n = new Notification(R.layout.chrono_notification /* not an icon */,
- null, System.currentTimeMillis());
- n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
- "This is the same notification!!!", makeIntent());
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.layout.chrono_notification /* not an icon */)
+ .setWhen(System.currentTimeMillis())
+ .setContentTitle("Persistent #1")
+ .setContentText("This is the same notification!!")
+ .setContentIntent(makeIntent())
+ .build();
mNM.notify(1, n);
}
},
new Test("Null Icon #1 (when=now)") {
public void run() {
- Notification n = new Notification(0, null, System.currentTimeMillis());
- n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
- "This is the same notification!!!", makeIntent());
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(0)
+ .setWhen(System.currentTimeMillis())
+ .setContentTitle("Persistent #1")
+ .setContentText("This is the same notification!!")
+ .setContentIntent(makeIntent())
+ .build();
mNM.notify(1, n);
}
},
new Test("Bad resource #1 (when=create)") {
public void run() {
- Notification n = new Notification(R.drawable.icon2,
- null, mActivityCreateTime);
- n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
- "This is the same notification!!!", makeIntent());
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon2)
+ .setWhen(mActivityCreateTime)
+ .setContentTitle("Persistent #1")
+ .setContentText("This is the same notification!!")
+ .setContentIntent(makeIntent())
+ .build();
n.contentView.setInt(1 /*bogus*/, "bogus method", 666);
mNM.notify(1, n);
}
@@ -237,29 +237,18 @@ public class NotificationTestList extends TestActivity
new Test("Bad resource #1 (when=now)") {
public void run() {
- Notification n = new Notification(R.drawable.icon2,
- null, System.currentTimeMillis());
- n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
- "This is the same notification!!!", makeIntent());
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon2)
+ .setWhen(System.currentTimeMillis())
+ .setContentTitle("Persistent #1")
+ .setContentText("This is the same notification!!")
+ .setContentIntent(makeIntent())
+ .build();
n.contentView.setInt(1 /*bogus*/, "bogus method", 666);
mNM.notify(1, n);
}
},
-
- new Test("Bad resource #3") {
- public void run()
- {
- Notification n = new Notification(NotificationTestList.this,
- R.drawable.ic_statusbar_missedcall,
- null, System.currentTimeMillis()-(1000*60*60*24),
- "(453) 123-2328",
- "", null);
- n.contentView.setInt(1 /*bogus*/, "bogus method", 666);
- mNM.notify(3, n);
- }
- },
-
new Test("Times") {
public void run()
{
@@ -278,22 +267,25 @@ public class NotificationTestList extends TestActivity
new Runnable() {
public void run() {
Log.d(TAG, "Stress - Ongoing/Latest 0");
- Notification n = new Notification(NotificationTestList.this,
- R.drawable.icon3,
- null, System.currentTimeMillis(), "Stress - Ongoing",
- "Notify me!!!", null);
- n.flags |= Notification.FLAG_ONGOING_EVENT;
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon3)
+ .setWhen(System.currentTimeMillis())
+ .setContentTitle("Stress - Ongoing")
+ .setContentText("Notify me!!!")
+ .setOngoing(true)
+ .build();
mNM.notify(1, n);
}
},
new Runnable() {
public void run() {
Log.d(TAG, "Stress - Ongoing/Latest 1");
- Notification n = new Notification(NotificationTestList.this,
- R.drawable.icon4,
- null, System.currentTimeMillis(), "Stress - Latest",
- "Notify me!!!", null);
- //n.flags |= Notification.FLAG_ONGOING_EVENT;
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon4)
+ .setWhen(System.currentTimeMillis())
+ .setContentTitle("Stress - Latest")
+ .setContentText("Notify me!!!")
+ .build();
mNM.notify(1, n);
}
}
@@ -302,12 +294,15 @@ public class NotificationTestList extends TestActivity
new Test("Long") {
public void run()
{
- Notification n = new Notification();
- n.defaults |= Notification.DEFAULT_SOUND ;
- n.vibrate = new long[] {
- 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400,
- 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400,
- 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400 };
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon1)
+ .setContentTitle(name)
+ .setDefaults(Notification.DEFAULT_SOUND)
+ .setVibrate(new long[] {
+ 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400,
+ 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400,
+ 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400 })
+ .build();
mNM.notify(1, n);
}
},
@@ -320,21 +315,19 @@ public class NotificationTestList extends TestActivity
Thread t = new Thread() {
public void run() {
int x = 0;
+ final Notification.Builder n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon1)
+ .setContentTitle(name)
+ .setOngoing(true);
+
while (!mProgressDone) {
- Notification n = new Notification(R.drawable.icon1, null,
- PROGRESS_UPDATES_WHEN
+ n.setWhen(PROGRESS_UPDATES_WHEN
? System.currentTimeMillis()
: mActivityCreateTime);
- RemoteViews v = new RemoteViews(getPackageName(),
- R.layout.progress_notification);
-
- v.setProgressBar(R.id.progress_bar, 100, x, false);
- v.setTextViewText(R.id.status_text, "Progress: " + x + "%");
-
- n.contentView = v;
- n.flags |= Notification.FLAG_ONGOING_EVENT;
-
- mNM.notify(500, n);
+ n.setProgress(100, x, false);
+ n.setContentText("Progress: " + x + "%");
+
+ mNM.notify(500, n.build());
x = (x + 7) % 100;
try {
@@ -359,11 +352,12 @@ public class NotificationTestList extends TestActivity
new Test("Blue Lights") {
public void run()
{
- Notification n = new Notification();
- n.flags |= Notification.FLAG_SHOW_LIGHTS;
- n.ledARGB = 0xff0000ff;
- n.ledOnMS = 1;
- n.ledOffMS = 0;
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon2)
+ .setContentTitle(name)
+ .setLights(0xff0000ff, 1, 0)
+ .setDefaults(Notification.DEFAULT_LIGHTS)
+ .build();
mNM.notify(1, n);
}
},
@@ -371,11 +365,12 @@ public class NotificationTestList extends TestActivity
new Test("Red Lights") {
public void run()
{
- Notification n = new Notification();
- n.flags |= Notification.FLAG_SHOW_LIGHTS;
- n.ledARGB = 0xffff0000;
- n.ledOnMS = 1;
- n.ledOffMS = 0;
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon2)
+ .setContentTitle(name)
+ .setLights(0xffff0000, 1, 0)
+ .setDefaults(Notification.DEFAULT_LIGHTS)
+ .build();
mNM.notify(1, n);
}
},
@@ -383,11 +378,12 @@ public class NotificationTestList extends TestActivity
new Test("Yellow Lights") {
public void run()
{
- Notification n = new Notification();
- n.flags |= Notification.FLAG_SHOW_LIGHTS;
- n.ledARGB = 0xffffff00;
- n.ledOnMS = 1;
- n.ledOffMS = 0;
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon2)
+ .setContentTitle(name)
+ .setLights(0xffffff00, 1, 0)
+ .setDefaults(Notification.DEFAULT_LIGHTS)
+ .build();
mNM.notify(1, n);
}
},
@@ -395,11 +391,12 @@ public class NotificationTestList extends TestActivity
new Test("Lights off") {
public void run()
{
- Notification n = new Notification();
- n.flags |= Notification.FLAG_SHOW_LIGHTS;
- n.ledARGB = 0x00000000;
- n.ledOnMS = 0;
- n.ledOffMS = 0;
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon2)
+ .setContentTitle(name)
+ .setLights(0x00000000, 0, 0)
+ .setDefaults(Notification.DEFAULT_LIGHTS)
+ .build();
mNM.notify(1, n);
}
},
@@ -407,11 +404,12 @@ public class NotificationTestList extends TestActivity
new Test("Blue Blinking Slow") {
public void run()
{
- Notification n = new Notification();
- n.flags |= Notification.FLAG_SHOW_LIGHTS;
- n.ledARGB = 0xff0000ff;
- n.ledOnMS = 1300;
- n.ledOffMS = 1300;
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon2)
+ .setContentTitle(name)
+ .setLights(0xff0000ff, 1300, 1300)
+ .setDefaults(Notification.DEFAULT_LIGHTS)
+ .build();
mNM.notify(1, n);
}
},
@@ -419,11 +417,12 @@ public class NotificationTestList extends TestActivity
new Test("Blue Blinking Fast") {
public void run()
{
- Notification n = new Notification();
- n.flags |= Notification.FLAG_SHOW_LIGHTS;
- n.ledARGB = 0xff0000ff;
- n.ledOnMS = 300;
- n.ledOffMS = 300;
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon2)
+ .setContentTitle(name)
+ .setLights(0xff0000ff, 300, 300)
+ .setDefaults(Notification.DEFAULT_LIGHTS)
+ .build();
mNM.notify(1, n);
}
},
@@ -431,8 +430,11 @@ public class NotificationTestList extends TestActivity
new Test("Default All") {
public void run()
{
- Notification n = new Notification();
- n.defaults |= Notification.DEFAULT_ALL;
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon2)
+ .setContentTitle(name)
+ .setDefaults(Notification.DEFAULT_ALL)
+ .build();
mNM.notify(1, n);
}
},
@@ -440,20 +442,12 @@ public class NotificationTestList extends TestActivity
new Test("Default All, once") {
public void run()
{
- Notification n = new Notification();
- n.defaults |= Notification.DEFAULT_ALL;
- n.flags |= Notification.FLAG_ONLY_ALERT_ONCE ;
- mNM.notify(1, n);
- }
- },
-
- new Test("Content Sound") {
- public void run()
- {
- Notification n = new Notification();
- n.sound = Uri.parse(
- "content://media/internal/audio/media/7");
-
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon2)
+ .setContentTitle(name)
+ .setOnlyAlertOnce(true)
+ .setDefaults(Notification.DEFAULT_ALL)
+ .build();
mNM.notify(1, n);
}
},
@@ -461,10 +455,12 @@ public class NotificationTestList extends TestActivity
new Test("Resource Sound") {
public void run()
{
- Notification n = new Notification();
- n.sound = Uri.parse(
- ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
- getPackageName() + "/raw/ringer");
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.stat_sys_phone)
+ .setContentTitle(name)
+ .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
+ getPackageName() + "/raw/ringer"))
+ .build();
Log.d(TAG, "n.sound=" + n.sound);
mNM.notify(1, n);
@@ -474,9 +470,13 @@ public class NotificationTestList extends TestActivity
new Test("Sound and Cancel") {
public void run()
{
- Notification n = new Notification();
- n.sound = Uri.parse(
- "content://media/internal/audio/media/7");
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.stat_sys_phone)
+ .setContentTitle(name)
+ .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
+ getPackageName() + "/raw/ringer"))
+ .build();
+ Log.d(TAG, "n.sound=" + n.sound);
mNM.notify(1, n);
SystemClock.sleep(200);
@@ -487,8 +487,11 @@ public class NotificationTestList extends TestActivity
new Test("Vibrate") {
public void run()
{
- Notification n = new Notification();
- n.vibrate = new long[] { 0, 700, 500, 1000 };
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.stat_sys_phone)
+ .setContentTitle(name)
+ .setVibrate(new long[]{0, 700, 500, 1000})
+ .build();
mNM.notify(1, n);
}
@@ -497,8 +500,11 @@ public class NotificationTestList extends TestActivity
new Test("Vibrate and cancel") {
public void run()
{
- Notification n = new Notification();
- n.vibrate = new long[] { 0, 700, 500, 1000 };
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.stat_sys_phone)
+ .setContentTitle(name)
+ .setVibrate(new long[]{0, 700, 500, 1000})
+ .build();
mNM.notify(1, n);
SystemClock.sleep(500);
@@ -566,10 +572,13 @@ public class NotificationTestList extends TestActivity
new Test("Persistent #1") {
public void run() {
- Notification n = new Notification(R.drawable.icon1, "tick tick tick",
- mActivityCreateTime);
- n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
- "This is a notification!!!", makeIntent());
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon1)
+ .setWhen(mActivityCreateTime)
+ .setContentTitle(name)
+ .setContentText("This is a notification!!!")
+ .setContentIntent(makeIntent())
+ .build();
mNM.notify(1, n);
}
},
@@ -578,18 +587,19 @@ public class NotificationTestList extends TestActivity
public void run() {
mHandler.postDelayed(new Runnable() {
public void run() {
- Notification n = new Notification(R.drawable.icon1,
- " "
+ String message = " "
+ "tick tock tick tock\n\nSometimes notifications can "
+ "be really long and wrap to more than one line.\n"
+ "Sometimes."
+ "Ohandwhathappensifwehaveonereallylongstringarewesure"
- + "thatwesegmentitcorrectly?\n",
- System.currentTimeMillis());
- n.setLatestEventInfo(NotificationTestList.this,
- "Still Persistent #1",
- "This is still a notification!!!",
- makeIntent());
+ + "thatwesegmentitcorrectly?\n";
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon1)
+ .setContentTitle(name)
+ .setContentText("This is still a notification!!!")
+ .setContentIntent(makeIntent())
+ .setStyle(new Notification.BigTextStyle().bigText(message))
+ .build();
mNM.notify(1, n);
}
}, 3000);
@@ -598,54 +608,67 @@ public class NotificationTestList extends TestActivity
new Test("Persistent #2") {
public void run() {
- Notification n = new Notification(R.drawable.icon2, "tock tock tock",
- System.currentTimeMillis());
- n.setLatestEventInfo(NotificationTestList.this, "Persistent #2",
- "Notify me!!!", makeIntent());
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon1)
+ .setWhen(mActivityCreateTime)
+ .setContentTitle(name)
+ .setContentText("This is a notification!!!")
+ .setContentIntent(makeIntent())
+ .build();
mNM.notify(2, n);
}
},
new Test("Persistent #3") {
public void run() {
- Notification n = new Notification(R.drawable.icon2, "tock tock tock\nmooooo",
- System.currentTimeMillis());
- n.setLatestEventInfo(NotificationTestList.this, "Persistent #3",
- "Notify me!!!", makeIntent());
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon1)
+ .setWhen(mActivityCreateTime)
+ .setContentTitle(name)
+ .setContentText("This is a notification!!!")
+ .setContentIntent(makeIntent())
+ .build();
mNM.notify(3, n);
}
},
new Test("Persistent #2 Vibrate") {
public void run() {
- Notification n = new Notification(R.drawable.icon2, "tock tock tock",
- System.currentTimeMillis());
- n.setLatestEventInfo(NotificationTestList.this, "Persistent #2",
- "Notify me!!!", makeIntent());
- n.defaults = Notification.DEFAULT_VIBRATE;
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon1)
+ .setWhen(mActivityCreateTime)
+ .setContentTitle(name)
+ .setContentText("This is a notification!!!")
+ .setContentIntent(makeIntent())
+ .setDefaults(Notification.DEFAULT_VIBRATE)
+ .build();
mNM.notify(2, n);
}
},
new Test("Persistent #1 - different icon") {
public void run() {
- Notification n = new Notification(R.drawable.icon2, null,
- mActivityCreateTime);
- n.setLatestEventInfo(NotificationTestList.this, "Persistent #1",
- "This is the same notification!!!", makeIntent());
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon2)
+ .setWhen(mActivityCreateTime)
+ .setContentTitle(name)
+ .setContentText("This is a notification!!!")
+ .setContentIntent(makeIntent())
+ .build();
mNM.notify(1, n);
}
},
new Test("Chronometer Start") {
public void run() {
- Notification n = new Notification(R.drawable.icon2, "me me me me",
- System.currentTimeMillis());
- n.contentView = new RemoteViews(getPackageName(), R.layout.chrono_notification);
- mChronometerBase = SystemClock.elapsedRealtime();
- n.contentView.setChronometer(R.id.time, mChronometerBase, "Yay! (%s)", true);
- n.flags |= Notification.FLAG_ONGOING_EVENT;
- n.contentIntent = makeIntent();
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon1)
+ .setWhen(System.currentTimeMillis())
+ .setContentTitle(name)
+ .setContentIntent(makeIntent())
+ .setOngoing(true)
+ .setUsesChronometer(true)
+ .build();
mNM.notify(2, n);
}
},
@@ -655,12 +678,12 @@ public class NotificationTestList extends TestActivity
mHandler.postDelayed(new Runnable() {
public void run() {
Log.d(TAG, "Chronometer Stop");
- Notification n = new Notification();
- n.icon = R.drawable.icon1;
- n.contentView = new RemoteViews(getPackageName(),
- R.layout.chrono_notification);
- n.contentView.setChronometer(R.id.time, mChronometerBase, null, false);
- n.contentIntent = makeIntent();
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.icon1)
+ .setWhen(System.currentTimeMillis())
+ .setContentTitle(name)
+ .setContentIntent(makeIntent())
+ .build();
mNM.notify(2, n);
}
}, 3000);
@@ -669,29 +692,29 @@ public class NotificationTestList extends TestActivity
new Test("Sequential Persistent") {
public void run() {
- mNM.notify(1, notificationWithNumbers(1));
- mNM.notify(2, notificationWithNumbers(2));
+ mNM.notify(1, notificationWithNumbers(name, 1));
+ mNM.notify(2, notificationWithNumbers(name, 2));
}
},
new Test("Replace Persistent") {
public void run() {
- mNM.notify(1, notificationWithNumbers(1));
- mNM.notify(1, notificationWithNumbers(1));
+ mNM.notify(1, notificationWithNumbers(name, 1));
+ mNM.notify(1, notificationWithNumbers(name, 1));
}
},
new Test("Run and Cancel (n=1)") {
public void run() {
- mNM.notify(1, notificationWithNumbers(1));
+ mNM.notify(1, notificationWithNumbers(name, 1));
mNM.cancel(1);
}
},
new Test("Run an Cancel (n=2)") {
public void run() {
- mNM.notify(1, notificationWithNumbers(1));
- mNM.notify(2, notificationWithNumbers(2));
+ mNM.notify(1, notificationWithNumbers(name, 1));
+ mNM.notify(2, notificationWithNumbers(name, 2));
mNM.cancel(2);
}
},
@@ -701,8 +724,8 @@ public class NotificationTestList extends TestActivity
public void run() {
for (int i = 0; i < 10; i++) {
Log.d(TAG, "Add two notifications");
- mNM.notify(1, notificationWithNumbers(1));
- mNM.notify(2, notificationWithNumbers(2));
+ mNM.notify(1, notificationWithNumbers(name, 1));
+ mNM.notify(2, notificationWithNumbers(name, 2));
Log.d(TAG, "Cancel two notifications");
mNM.cancel(1);
mNM.cancel(2);
@@ -712,29 +735,14 @@ public class NotificationTestList extends TestActivity
new Test("Ten Notifications") {
public void run() {
- for (int i = 0; i < 2; i++) {
- Notification n = new Notification(
- kNumberedIconResIDs[i],
- null, System.currentTimeMillis());
- n.number = i;
- n.setLatestEventInfo(
- NotificationTestList.this,
- "Persistent #" + i,
- "Notify me!!!" + i,
- null);
- n.flags |= Notification.FLAG_ONGOING_EVENT;
- mNM.notify((i+1)*10, n);
- }
- for (int i = 2; i < 10; i++) {
- Notification n = new Notification(
- kNumberedIconResIDs[i],
- null, System.currentTimeMillis());
- n.number = i;
- n.setLatestEventInfo(
- NotificationTestList.this,
- "Persistent #" + i,
- "Notify me!!!" + i,
- null);
+ for (int i = 0; i < 10; i++) {
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(kNumberedIconResIDs[i])
+ .setContentTitle("Persistent #" + i)
+ .setContentText("Notify me!!!" + i)
+ .setOngoing(i < 2)
+ .setNumber(i)
+ .build();
mNM.notify((i+1)*10, n);
}
}
@@ -757,25 +765,25 @@ public class NotificationTestList extends TestActivity
new Test("Persistent with numbers 1") {
public void run() {
- mNM.notify(1, notificationWithNumbers(1));
+ mNM.notify(1, notificationWithNumbers(name, 1));
}
},
new Test("Persistent with numbers 22") {
public void run() {
- mNM.notify(1, notificationWithNumbers(22));
+ mNM.notify(1, notificationWithNumbers(name, 22));
}
},
new Test("Persistent with numbers 333") {
public void run() {
- mNM.notify(1, notificationWithNumbers(333));
+ mNM.notify(1, notificationWithNumbers(name, 333));
}
},
new Test("Persistent with numbers 4444") {
public void run() {
- mNM.notify(1, notificationWithNumbers(4444));
+ mNM.notify(1, notificationWithNumbers(name, 4444));
}
},
@@ -786,7 +794,7 @@ public class NotificationTestList extends TestActivity
.setContentTitle("High priority")
.setContentText("This should appear before all others")
.setPriority(Notification.PRIORITY_HIGH)
- .getNotification();
+ .build();
int[] idOut = new int[1];
try {
@@ -812,7 +820,7 @@ public class NotificationTestList extends TestActivity
.setContentTitle("MAX priority")
.setContentText("This might appear as an intruder alert")
.setPriority(Notification.PRIORITY_MAX)
- .getNotification();
+ .build();
int[] idOut = new int[1];
try {
@@ -838,7 +846,7 @@ public class NotificationTestList extends TestActivity
.setContentTitle("MIN priority")
.setContentText("You should not see this")
.setPriority(Notification.PRIORITY_MIN)
- .getNotification();
+ .build();
int[] idOut = new int[1];
try {
@@ -875,16 +883,15 @@ public class NotificationTestList extends TestActivity
};
- private Notification notificationWithNumbers(int num) {
- Notification n = new Notification(this,
- (num >= 0 && num < kNumberedIconResIDs.length)
- ? kNumberedIconResIDs[num]
- : kUnnumberedIconResID,
- null,
- System.currentTimeMillis(),
- "Notification", "Number=" + num,
- null);
- n.number = num;
+ private Notification notificationWithNumbers(String name, int num) {
+ Notification n = new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon((num >= 0 && num < kNumberedIconResIDs.length)
+ ? kNumberedIconResIDs[num]
+ : kUnnumberedIconResID)
+ .setContentTitle(name)
+ .setContentText("Number=" + num)
+ .setNumber(num)
+ .build();
return n;
}
@@ -932,9 +939,12 @@ public class NotificationTestList extends TestActivity
}
void timeNotification(int n, String label, long time) {
- mNM.notify(n, new Notification(NotificationTestList.this,
- R.drawable.ic_statusbar_missedcall, null,
- time, label, "" + new java.util.Date(time), null));
+ mNM.notify(n, new Notification.Builder(NotificationTestList.this)
+ .setSmallIcon(R.drawable.ic_statusbar_missedcall)
+ .setWhen(time)
+ .setContentTitle(label)
+ .setContentText(new java.util.Date(time).toString())
+ .build());
}
diff --git a/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java b/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java
index 50f98b8..cd04c2e 100644
--- a/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java
+++ b/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java
@@ -153,25 +153,24 @@ public class StatusBarTest extends TestActivity
},
new Test("Priority notification") {
public void run() {
- Notification not = new Notification();
- not.icon = R.drawable.stat_sys_phone;
- not.when = System.currentTimeMillis()-(1000*60*60*24);
- not.setLatestEventInfo(StatusBarTest.this,
- "Incoming call",
- "from: Imperious Leader",
- null
- );
- not.flags |= Notification.FLAG_HIGH_PRIORITY;
Intent fullScreenIntent = new Intent(StatusBarTest.this, TestAlertActivity.class);
int id = (int)System.currentTimeMillis(); // XXX HAX
fullScreenIntent.putExtra("id", id);
- not.fullScreenIntent = PendingIntent.getActivity(
+ PendingIntent pi = PendingIntent.getActivity(
StatusBarTest.this,
0,
fullScreenIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
- // if you tap on it you should get the original alert box
- not.contentIntent = not.fullScreenIntent;
+ Notification not = new Notification.Builder(StatusBarTest.this)
+ .setSmallIcon(R.drawable.stat_sys_phone)
+ .setWhen(System.currentTimeMillis() - (1000 * 60 * 60 * 24))
+ .setContentTitle("Incoming call")
+ .setContentText("from: Imperious Leader")
+ .setContentIntent(pi)
+ .setFullScreenIntent(pi, true)
+ .setPriority(Notification.PRIORITY_HIGH)
+ .build();
+
mNotificationManager.notify(id, not);
}
},
diff --git a/tests/UsageStatsTest/src/com/android/tests/usagestats/UsageLogActivity.java b/tests/UsageStatsTest/src/com/android/tests/usagestats/UsageLogActivity.java
index 8e6daea..05cac10 100644
--- a/tests/UsageStatsTest/src/com/android/tests/usagestats/UsageLogActivity.java
+++ b/tests/UsageStatsTest/src/com/android/tests/usagestats/UsageLogActivity.java
@@ -28,8 +28,6 @@ import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
-import java.util.ArrayList;
-
public class UsageLogActivity extends ListActivity implements Runnable {
private static final long USAGE_STATS_PERIOD = 1000 * 60 * 60 * 24 * 14;
@@ -166,8 +164,8 @@ public class UsageLogActivity extends ListActivity implements Runnable {
case UsageEvents.Event.CONFIGURATION_CHANGE:
return "Config change";
- case UsageEvents.Event.INTERACTION:
- return "Interaction";
+ case UsageEvents.Event.USER_INTERACTION:
+ return "User Interaction";
default:
return "Unknown: " + eventType;