diff options
author | Dianne Hackborn <hackbod@google.com> | 2015-06-12 19:38:38 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-06-12 19:38:39 +0000 |
commit | e554cc96597d4b738f14a1514772e4d49e78c542 (patch) | |
tree | cdee6876faa1c56d2e0ec3dc0cfb51f2913372db /tests | |
parent | 17de4b2a73996366ff3d7759793a6809654caebe (diff) | |
parent | 3d1933c45fe9ba2389ebd166d96abeceab1971d1 (diff) | |
download | frameworks_base-e554cc96597d4b738f14a1514772e4d49e78c542.zip frameworks_base-e554cc96597d4b738f14a1514772e4d49e78c542.tar.gz frameworks_base-e554cc96597d4b738f14a1514772e4d49e78c542.tar.bz2 |
Merge "Implement some control over ALLOW_WHILE_IDLE alarms." into mnc-dev
Diffstat (limited to 'tests')
3 files changed, 60 insertions, 0 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..94cbabf 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; @@ -36,6 +37,7 @@ import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.RemoteException; +import android.os.SystemClock; import android.os.UserHandle; import android.os.UserManager; import android.graphics.Bitmap; @@ -58,6 +60,7 @@ public class ActivityTestMain extends Activity { static final String KEY_CONFIGURATION = "configuration"; ActivityManager mAm; + AlarmManager mAlarm; Configuration mOverrideConfig; int mSecondUser; @@ -66,6 +69,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 +86,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); } @@ -146,6 +159,7 @@ public class ActivityTestMain extends Activity { Log.i(TAG, "Referrer: " + getReferrer()); mAm = (ActivityManager)getSystemService(ACTIVITY_SERVICE); + mAlarm = (AlarmManager)getSystemService(ALARM_SERVICE); if (savedInstanceState != null) { mOverrideConfig = savedInstanceState.getParcelable(KEY_CONFIGURATION); if (mOverrideConfig != null) { @@ -436,6 +450,13 @@ public class ActivityTestMain extends Activity { return true; } }); + menu.add("Spam idle alarm").setOnMenuItemClickListener( + new MenuItem.OnMenuItemClickListener() { + @Override public boolean onMenuItemClick(MenuItem item) { + scheduleSpamAlarm(0); + return true; + } + }); return true; } @@ -467,6 +488,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 +558,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); + } +} |