diff options
author | Dianne Hackborn <hackbod@google.com> | 2015-06-12 18:11:41 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2015-06-15 11:53:59 -0700 |
commit | 1958e5e7870579337f1d1d3e6c6fae096ba3abb9 (patch) | |
tree | fad208704fc337915aff86df8021895eb1910701 /tests | |
parent | f63655e49fcccd922e8d5f61c67f58bd4a361211 (diff) | |
download | frameworks_base-1958e5e7870579337f1d1d3e6c6fae096ba3abb9.zip frameworks_base-1958e5e7870579337f1d1d3e6c6fae096ba3abb9.tar.gz frameworks_base-1958e5e7870579337f1d1d3e6c6fae096ba3abb9.tar.bz2 |
Fix issue #21813831: Need API for asking to be added to power whitelist
Add the API. Clean up a few related things.
Change-Id: I190adad1812f36f6095b98a1001fedb94874e8b5
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java | 22 |
1 files changed, 19 insertions, 3 deletions
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 94cbabf..2f0bf39 100644 --- a/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java +++ b/tests/ActivityTests/src/com/google/android/test/activity/ActivityTestMain.java @@ -32,15 +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; @@ -60,6 +63,7 @@ public class ActivityTestMain extends Activity { static final String KEY_CONFIGURATION = "configuration"; ActivityManager mAm; + PowerManager mPower; AlarmManager mAlarm; Configuration mOverrideConfig; int mSecondUser; @@ -158,8 +162,9 @@ public class ActivityTestMain extends Activity { Log.i(TAG, "Referrer: " + getReferrer()); - mAm = (ActivityManager)getSystemService(ACTIVITY_SERVICE); - mAlarm = (AlarmManager)getSystemService(ALARM_SERVICE); + mAm = getSystemService(ActivityManager.class); + mPower = getSystemService(PowerManager.class); + mAlarm = getSystemService(AlarmManager.class); if (savedInstanceState != null) { mOverrideConfig = savedInstanceState.getParcelable(KEY_CONFIGURATION); if (mOverrideConfig != null) { @@ -445,7 +450,7 @@ 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; } @@ -457,6 +462,17 @@ public class ActivityTestMain extends Activity { 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; + } + }); return true; } |