Merge "Delay tryToRebind if application exit reason is LMK"
This commit is contained in:
@@ -36,6 +36,7 @@ import android.annotation.NonNull;
|
|||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.AppGlobals;
|
import android.app.AppGlobals;
|
||||||
import android.app.AppOpsManager;
|
import android.app.AppOpsManager;
|
||||||
|
import android.app.ApplicationExitInfo;
|
||||||
import android.app.ILocalWallpaperColorConsumer;
|
import android.app.ILocalWallpaperColorConsumer;
|
||||||
import android.app.IWallpaperManager;
|
import android.app.IWallpaperManager;
|
||||||
import android.app.IWallpaperManagerCallback;
|
import android.app.IWallpaperManagerCallback;
|
||||||
@@ -189,6 +190,10 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
|
|||||||
|
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
|
|
||||||
|
private static final double LMK_LOW_THRESHOLD_MEMORY_PERCENTAGE = 10;
|
||||||
|
private static final int LMK_RECONNECT_REBIND_RETRIES = 3;
|
||||||
|
private static final long LMK_RECONNECT_DELAY_MS = 5000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minimum time between crashes of a wallpaper service for us to consider
|
* Minimum time between crashes of a wallpaper service for us to consider
|
||||||
* restarting it vs. just reverting to the static wallpaper.
|
* restarting it vs. just reverting to the static wallpaper.
|
||||||
@@ -1208,6 +1213,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
|
|||||||
/** Time in milliseconds until we expect the wallpaper to reconnect (unless we're in the
|
/** Time in milliseconds until we expect the wallpaper to reconnect (unless we're in the
|
||||||
* middle of an update). If exceeded, the wallpaper gets reset to the system default. */
|
* middle of an update). If exceeded, the wallpaper gets reset to the system default. */
|
||||||
private static final long WALLPAPER_RECONNECT_TIMEOUT_MS = 10000;
|
private static final long WALLPAPER_RECONNECT_TIMEOUT_MS = 10000;
|
||||||
|
private int mLmkLimitRebindRetries = LMK_RECONNECT_REBIND_RETRIES;
|
||||||
|
|
||||||
final WallpaperInfo mInfo;
|
final WallpaperInfo mInfo;
|
||||||
IWallpaperService mService;
|
IWallpaperService mService;
|
||||||
@@ -1448,20 +1454,51 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
|
|||||||
&& mWallpaper.userId == mCurrentUserId
|
&& mWallpaper.userId == mCurrentUserId
|
||||||
&& !Objects.equals(mDefaultWallpaperComponent, wpService)
|
&& !Objects.equals(mDefaultWallpaperComponent, wpService)
|
||||||
&& !Objects.equals(mImageWallpaper, wpService)) {
|
&& !Objects.equals(mImageWallpaper, wpService)) {
|
||||||
// There is a race condition which causes
|
List<ApplicationExitInfo> reasonList =
|
||||||
// {@link #mWallpaper.wallpaperUpdating} to be false even if it is
|
mActivityManager.getHistoricalProcessExitReasons(
|
||||||
// currently updating since the broadcast notifying us is async.
|
wpService.getPackageName(), 0, 1);
|
||||||
// This race is overcome by the general rule that we only reset the
|
int exitReason = ApplicationExitInfo.REASON_UNKNOWN;
|
||||||
// wallpaper if its service was shut down twice
|
if (reasonList != null && !reasonList.isEmpty()) {
|
||||||
// during {@link #MIN_WALLPAPER_CRASH_TIME} millis.
|
ApplicationExitInfo info = reasonList.get(0);
|
||||||
if (mWallpaper.lastDiedTime != 0
|
exitReason = info.getReason();
|
||||||
&& mWallpaper.lastDiedTime + MIN_WALLPAPER_CRASH_TIME
|
}
|
||||||
> SystemClock.uptimeMillis()) {
|
Slog.d(TAG, "exitReason: " + exitReason);
|
||||||
Slog.w(TAG, "Reverting to built-in wallpaper!");
|
// If exit reason is LOW_MEMORY_KILLER
|
||||||
clearWallpaperLocked(true, FLAG_SYSTEM, mWallpaper.userId, null);
|
// delay the mTryToRebindRunnable for 10s
|
||||||
|
if (exitReason == ApplicationExitInfo.REASON_LOW_MEMORY) {
|
||||||
|
if (isRunningOnLowMemory()) {
|
||||||
|
Slog.i(TAG, "Rebind is delayed due to lmk");
|
||||||
|
mContext.getMainThreadHandler().postDelayed(mTryToRebindRunnable,
|
||||||
|
LMK_RECONNECT_DELAY_MS);
|
||||||
|
mLmkLimitRebindRetries = LMK_RECONNECT_REBIND_RETRIES;
|
||||||
|
} else {
|
||||||
|
if (mLmkLimitRebindRetries <= 0) {
|
||||||
|
Slog.w(TAG, "Reverting to built-in wallpaper due to lmk!");
|
||||||
|
clearWallpaperLocked(true, FLAG_SYSTEM, mWallpaper.userId,
|
||||||
|
null);
|
||||||
|
mLmkLimitRebindRetries = LMK_RECONNECT_REBIND_RETRIES;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mLmkLimitRebindRetries--;
|
||||||
|
mContext.getMainThreadHandler().postDelayed(mTryToRebindRunnable,
|
||||||
|
LMK_RECONNECT_DELAY_MS);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mWallpaper.lastDiedTime = SystemClock.uptimeMillis();
|
// There is a race condition which causes
|
||||||
tryToRebind();
|
// {@link #mWallpaper.wallpaperUpdating} to be false even if it is
|
||||||
|
// currently updating since the broadcast notifying us is async.
|
||||||
|
// This race is overcome by the general rule that we only reset the
|
||||||
|
// wallpaper if its service was shut down twice
|
||||||
|
// during {@link #MIN_WALLPAPER_CRASH_TIME} millis.
|
||||||
|
if (mWallpaper.lastDiedTime != 0
|
||||||
|
&& mWallpaper.lastDiedTime + MIN_WALLPAPER_CRASH_TIME
|
||||||
|
> SystemClock.uptimeMillis()) {
|
||||||
|
Slog.w(TAG, "Reverting to built-in wallpaper!");
|
||||||
|
clearWallpaperLocked(true, FLAG_SYSTEM, mWallpaper.userId, null);
|
||||||
|
} else {
|
||||||
|
mWallpaper.lastDiedTime = SystemClock.uptimeMillis();
|
||||||
|
tryToRebind();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1472,6 +1509,14 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private boolean isRunningOnLowMemory() {
|
||||||
|
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
|
||||||
|
mActivityManager.getMemoryInfo(memoryInfo);
|
||||||
|
double availableMBsInPercentage = memoryInfo.availMem / (double)memoryInfo.totalMem *
|
||||||
|
100.0;
|
||||||
|
return availableMBsInPercentage < LMK_LOW_THRESHOLD_MEMORY_PERCENTAGE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by a live wallpaper if its colors have changed.
|
* Called by a live wallpaper if its colors have changed.
|
||||||
* @param primaryColors representation of wallpaper primary colors
|
* @param primaryColors representation of wallpaper primary colors
|
||||||
|
|||||||
Reference in New Issue
Block a user