Hold wakelock for SMS/MMS restore service.
Since we start to put the message into the providers after
onRestoreFinished in the separate service we have to hold a wakelock for
it.
Bug: 27225193
Change-Id: I2b1fa219b13ebd45816d44b9dacb3b7177c5fe84
diff --git a/src/com/android/providers/telephony/TelephonyBackupAgent.java b/src/com/android/providers/telephony/TelephonyBackupAgent.java
index 8e9aeab..748a703 100644
--- a/src/com/android/providers/telephony/TelephonyBackupAgent.java
+++ b/src/com/android/providers/telephony/TelephonyBackupAgent.java
@@ -39,6 +39,7 @@
import android.net.Uri;
import android.os.Build;
import android.os.ParcelFileDescriptor;
+import android.os.PowerManager;
import android.provider.BaseColumns;
import android.provider.Telephony;
import android.telephony.PhoneNumberUtils;
@@ -465,32 +466,38 @@
}
private TelephonyBackupAgent mTelephonyBackupAgent;
+ private PowerManager.WakeLock mWakeLock;
@Override
protected void onHandleIntent(Intent intent) {
- File[] files = getFilesDir().listFiles(new FileFilter() {
- @Override
- public boolean accept(File file) {
- return file.getName().endsWith(SMS_BACKUP_FILE_SUFFIX) ||
- file.getName().endsWith(MMS_BACKUP_FILE_SUFFIX);
+ try {
+ mWakeLock.acquire();
+ File[] files = getFilesDir().listFiles(new FileFilter() {
+ @Override
+ public boolean accept(File file) {
+ return file.getName().endsWith(SMS_BACKUP_FILE_SUFFIX) ||
+ file.getName().endsWith(MMS_BACKUP_FILE_SUFFIX);
+ }
+ });
+
+ if (files == null) {
+ return;
}
- });
+ Arrays.sort(files, mFileComparator);
- if (files == null) {
- return;
- }
- Arrays.sort(files, mFileComparator);
-
- for (File file : files) {
- final String fileName = file.getName();
- try (FileInputStream fileInputStream = new FileInputStream(file)) {
- mTelephonyBackupAgent.doRestoreFile(fileName, fileInputStream.getFD());
- file.delete();
- } catch (IOException e) {
- if (DEBUG) {
- Log.e(TAG, e.toString());
+ for (File file : files) {
+ final String fileName = file.getName();
+ try (FileInputStream fileInputStream = new FileInputStream(file)) {
+ mTelephonyBackupAgent.doRestoreFile(fileName, fileInputStream.getFD());
+ file.delete();
+ } catch (IOException e) {
+ if (DEBUG) {
+ Log.e(TAG, e.toString());
+ }
}
}
+ } finally {
+ mWakeLock.release();
}
}
@@ -500,6 +507,9 @@
mTelephonyBackupAgent = new TelephonyBackupAgent();
mTelephonyBackupAgent.attach(this);
mTelephonyBackupAgent.onCreate();
+
+ PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
+ mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
}
@Override