OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.memconsumer; | 5 package org.chromium.memconsumer; |
6 | 6 |
7 import android.app.Notification; | 7 import android.app.Notification; |
8 import android.app.PendingIntent; | 8 import android.app.PendingIntent; |
9 import android.app.Service; | 9 import android.app.Service; |
10 import android.content.Intent; | 10 import android.content.Intent; |
(...skipping 22 matching lines...) Expand all Loading... |
33 return mBinder; | 33 return mBinder; |
34 } | 34 } |
35 | 35 |
36 public void useMemory(long memory) { | 36 public void useMemory(long memory) { |
37 if (memory > 0) { | 37 if (memory > 0) { |
38 Intent notificationIntent = new Intent(this, MemConsumer.class); | 38 Intent notificationIntent = new Intent(this, MemConsumer.class); |
39 notificationIntent.setAction(MemConsumer.NOTIFICATION_ACTION); | 39 notificationIntent.setAction(MemConsumer.NOTIFICATION_ACTION); |
40 PendingIntent pendingIntent = | 40 PendingIntent pendingIntent = |
41 PendingIntent.getActivity(this, 0, notificationIntent, 0); | 41 PendingIntent.getActivity(this, 0, notificationIntent, 0); |
42 Notification notification = | 42 Notification notification = |
43 new Notification.Builder(getApplicationContext()). | 43 new Notification.Builder(getApplicationContext()) |
44 setContentTitle("MC running (" + memory + "Mb)"). | 44 .setContentTitle("MC running (" + memory + "Mb)") |
45 setSmallIcon(R.drawable.notification_icon). | 45 .setSmallIcon(R.drawable.notification_icon) |
46 setDeleteIntent(pendingIntent). | 46 .setDeleteIntent(pendingIntent) |
47 setContentIntent(pendingIntent). | 47 .setContentIntent(pendingIntent) |
48 build(); | 48 .build(); |
49 startForeground(RESIDENT_NOTIFICATION_ID, notification); | 49 startForeground(RESIDENT_NOTIFICATION_ID, notification); |
50 mIsInForeground = true; | 50 mIsInForeground = true; |
51 } | 51 } |
52 if (mIsInForeground && memory == 0) { | 52 if (mIsInForeground && memory == 0) { |
53 stopForeground(true); | 53 stopForeground(true); |
54 mIsInForeground = false; | 54 mIsInForeground = false; |
55 } | 55 } |
56 nativeUseMemory(memory * 1024 * 1024); | 56 nativeUseMemory(memory * 1024 * 1024); |
57 } | 57 } |
58 | 58 |
59 // Allocate the amount of memory in native code. Otherwise the memory | 59 // Allocate the amount of memory in native code. Otherwise the memory |
60 // allocation is limited by the framework. | 60 // allocation is limited by the framework. |
61 private native void nativeUseMemory(long memory); | 61 private native void nativeUseMemory(long memory); |
62 } | 62 } |
OLD | NEW |