Skip to content

Commit a39871e

Browse files
committed
Use VMRuntime.isBootClassPathOnDisk
Bug: 17679443 Change-Id: If53c236058a7237d735c2344a715cf0a36301f9b
1 parent 0a62ab7 commit a39871e

4 files changed

Lines changed: 53 additions & 11 deletions

File tree

core/res/res/values/symbols.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,6 +1696,7 @@
16961696
<java-symbol type="string" name="launch_warning_replace" />
16971697
<java-symbol type="string" name="launch_warning_title" />
16981698
<java-symbol type="string" name="low_internal_storage_view_text" />
1699+
<java-symbol type="string" name="low_internal_storage_view_text_no_boot" />
16991700
<java-symbol type="string" name="low_internal_storage_view_title" />
17001701
<java-symbol type="string" name="notification_listener_binding_label" />
17011702
<java-symbol type="string" name="condition_provider_service_binding_label" />

services/core/java/com/android/server/pm/PackageManagerService.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4729,6 +4729,18 @@ private static String[] getDexCodeInstructionSets(String[] instructionSets) {
47294729
return dexCodeInstructionSets.toArray(new String[dexCodeInstructionSets.size()]);
47304730
}
47314731

4732+
/**
4733+
* Returns deduplicated list of supported instructions for dex code.
4734+
*/
4735+
public static String[] getAllDexCodeInstructionSets() {
4736+
String[] supportedInstructionSets = new String[Build.SUPPORTED_ABIS.length];
4737+
for (int i = 0; i < supportedInstructionSets.length; i++) {
4738+
String abi = Build.SUPPORTED_ABIS[i];
4739+
supportedInstructionSets[i] = VMRuntime.getInstructionSet(abi);
4740+
}
4741+
return getDexCodeInstructionSets(supportedInstructionSets);
4742+
}
4743+
47324744
@Override
47334745
public void forceDexOpt(String packageName) {
47344746
enforceSystemOrRoot("forceDexOpt");

services/core/java/com/android/server/storage/DeviceStorageMonitorService.java

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.android.server.EventLogTags;
2020
import com.android.server.SystemService;
21+
import com.android.server.pm.PackageManagerService;
2122

2223
import android.app.Notification;
2324
import android.app.NotificationManager;
@@ -51,6 +52,8 @@
5152
import java.io.FileDescriptor;
5253
import java.io.PrintWriter;
5354

55+
import dalvik.system.VMRuntime;
56+
5457
/**
5558
* This class implements a service to monitor the amount of disk
5659
* storage space on the device. If the free storage on device is less
@@ -89,6 +92,7 @@ public class DeviceStorageMonitorService extends SystemService {
8992
private long mLastReportedFreeMemTime;
9093
boolean mLowMemFlag=false;
9194
private boolean mMemFullFlag=false;
95+
private final boolean mIsBootImageOnDisk;
9296
private final ContentResolver mResolver;
9397
private final long mTotalMemory; // on /data
9498
private final StatFs mDataFileStats;
@@ -285,6 +289,10 @@ void checkMemory(boolean checkCache) {
285289
mLowMemFlag = false;
286290
}
287291
}
292+
if (!mLowMemFlag && !mIsBootImageOnDisk) {
293+
Slog.i(TAG, "No boot image on disk due to lack of space. Sending notification");
294+
sendNotification();
295+
}
288296
if (mFreeMem < mMemFullThreshold) {
289297
if (!mMemFullFlag) {
290298
sendFullNotification();
@@ -314,6 +322,7 @@ public DeviceStorageMonitorService(Context context) {
314322
super(context);
315323
mLastReportedFreeMemTime = 0;
316324
mResolver = context.getContentResolver();
325+
mIsBootImageOnDisk = isBootImageOnDisk();
317326
//create StatFs object
318327
mDataFileStats = new StatFs(DATA_PATH.getAbsolutePath());
319328
mSystemFileStats = new StatFs(SYSTEM_PATH.getAbsolutePath());
@@ -331,6 +340,15 @@ public DeviceStorageMonitorService(Context context) {
331340
mStorageNotFullIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
332341
}
333342

343+
private static boolean isBootImageOnDisk() {
344+
for (String instructionSet : PackageManagerService.getAllDexCodeInstructionSets()) {
345+
if (!VMRuntime.isBootClassPathOnDisk(instructionSet)) {
346+
return false;
347+
}
348+
}
349+
return true;
350+
}
351+
334352
/**
335353
* Initializes the disk space threshold value and posts an empty message to
336354
* kickstart the process.
@@ -364,7 +382,7 @@ public void checkMemory() {
364382

365383
@Override
366384
public boolean isMemoryLow() {
367-
return mLowMemFlag;
385+
return mLowMemFlag || !mIsBootImageOnDisk;
368386
}
369387

370388
@Override
@@ -409,6 +427,7 @@ void dumpImpl(PrintWriter pw) {
409427

410428
pw.print(" mLowMemFlag="); pw.print(mLowMemFlag);
411429
pw.print(" mMemFullFlag="); pw.println(mMemFullFlag);
430+
pw.print(" mIsBootImageOnDisk="); pw.print(mIsBootImageOnDisk);
412431

413432
pw.print(" mClearSucceeded="); pw.print(mClearSucceeded);
414433
pw.print(" mClearingCache="); pw.println(mClearingCache);
@@ -445,19 +464,25 @@ private void sendNotification() {
445464
Context.NOTIFICATION_SERVICE);
446465
CharSequence title = context.getText(
447466
com.android.internal.R.string.low_internal_storage_view_title);
448-
CharSequence details = context.getText(
449-
com.android.internal.R.string.low_internal_storage_view_text);
467+
CharSequence details = context.getText(mIsBootImageOnDisk
468+
? com.android.internal.R.string.low_internal_storage_view_text
469+
: com.android.internal.R.string.low_internal_storage_view_text_no_boot);
450470
PendingIntent intent = PendingIntent.getActivityAsUser(context, 0, lowMemIntent, 0,
451471
null, UserHandle.CURRENT);
452-
Notification notification = new Notification();
453-
notification.icon = com.android.internal.R.drawable.stat_notify_disk_full;
454-
notification.tickerText = title;
472+
Notification notification = new Notification.Builder(context)
473+
.setSmallIcon(com.android.internal.R.drawable.stat_notify_disk_full)
474+
.setTicker(title)
475+
.setColor(context.getResources().getColor(
476+
com.android.internal.R.color.system_notification_accent_color))
477+
.setContentTitle(title)
478+
.setContentText(details)
479+
.setContentIntent(intent)
480+
.setStyle(new Notification.BigTextStyle()
481+
.bigText(details))
482+
.setVisibility(Notification.VISIBILITY_PUBLIC)
483+
.setCategory(Notification.CATEGORY_SYSTEM)
484+
.build();
455485
notification.flags |= Notification.FLAG_NO_CLEAR;
456-
notification.color = context.getResources().getColor(
457-
com.android.internal.R.color.system_notification_accent_color);
458-
notification.setLatestEventInfo(context, title, details, intent);
459-
notification.visibility = Notification.VISIBILITY_PUBLIC;
460-
notification.category = Notification.CATEGORY_SYSTEM;
461486
mNotificationMgr.notifyAsUser(null, LOW_MEMORY_NOTIFICATION_ID, notification,
462487
UserHandle.ALL);
463488
context.sendStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL);

services/usage/java/com/android/server/usage/UsageStatsDatabase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@ private static void pruneFilesOlderThan(File dir, long expiryTime) {
382382
File[] files = dir.listFiles();
383383
if (files != null) {
384384
for (File f : files) {
385+
String path = f.getPath();
386+
if (path.endsWith(".bak")) {
387+
f = new File(path.substring(0, path.length() - 4));
388+
}
385389
long beginTime = Long.parseLong(f.getName());
386390
if (beginTime < expiryTime) {
387391
new AtomicFile(f).delete();

0 commit comments

Comments
 (0)