diff options
Diffstat (limited to 'services/java')
-rw-r--r-- | services/java/com/android/server/AppsFailureReceiver.java (renamed from services/java/com/android/server/AppsLaunchFailureReceiver.java) | 38 | ||||
-rw-r--r-- | services/java/com/android/server/SystemServer.java | 6 |
2 files changed, 37 insertions, 7 deletions
diff --git a/services/java/com/android/server/AppsLaunchFailureReceiver.java b/services/java/com/android/server/AppsFailureReceiver.java index 81b23ec..bebef9b 100644 --- a/services/java/com/android/server/AppsLaunchFailureReceiver.java +++ b/services/java/com/android/server/AppsFailureReceiver.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2010, T-Mobile USA, Inc. + * Copyright (C) 2015 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,9 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.android.server; +import android.app.Notification; +import android.app.NotificationManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -28,11 +30,15 @@ import android.provider.ThemesContract; import java.util.ArrayList; import java.util.List; -public class AppsLaunchFailureReceiver extends BroadcastReceiver { +import com.android.internal.R; + +public class AppsFailureReceiver extends BroadcastReceiver { private static final int FAILURES_THRESHOLD = 3; private static final int EXPIRATION_TIME_IN_MILLISECONDS = 30000; // 30 seconds + private static final int THEME_RESET_NOTIFICATION_ID = 0x4641494C; + private int mFailuresCount = 0; private long mStartTime = 0; @@ -44,8 +50,9 @@ public class AppsLaunchFailureReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); - if (action.equals(Intent.ACTION_APP_LAUNCH_FAILURE)) { + if (action.equals(Intent.ACTION_APP_FAILURE)) { long currentTime = SystemClock.uptimeMillis(); + String pkgName = intent.getStringExtra("package"); if (currentTime - mStartTime > EXPIRATION_TIME_IN_MILLISECONDS) { // reset both the count and the timer mStartTime = currentTime; @@ -70,9 +77,10 @@ public class AppsLaunchFailureReceiver extends BroadcastReceiver { components.add(ThemesContract.ThemesColumns.MODIFIES_STATUS_BAR); components.add(ThemesContract.ThemesColumns.MODIFIES_NAVIGATION_BAR); tm.requestThemeChange(ThemeConfig.SYSTEM_DEFAULT, components); + postThemeResetNotification(context); } } - } else if (action.equals(Intent.ACTION_APP_LAUNCH_FAILURE_RESET) + } else if (action.equals(Intent.ACTION_APP_FAILURE_RESET) || action.equals(ThemeUtils.ACTION_THEME_CHANGED)) { mFailuresCount = 0; mStartTime = SystemClock.uptimeMillis(); @@ -83,4 +91,26 @@ public class AppsLaunchFailureReceiver extends BroadcastReceiver { } } + /** + * Posts a notification to let the user know their theme was reset + * @param context + */ + private void postThemeResetNotification(Context context) { + NotificationManager nm = + (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + String title = context.getString(R.string.theme_reset_notification_title); + String body = context.getString(R.string.theme_reset_notification_body); + Notification notice = new Notification.Builder(context) + .setAutoCancel(true) + .setOngoing(false) + .setContentTitle(title) + .setContentText(body) + .setStyle(new Notification.BigTextStyle().bigText(body)) + .setSmallIcon(android.R.drawable.stat_notify_error) + .setWhen(System.currentTimeMillis()) + .setCategory(Notification.CATEGORY_SYSTEM) + .setPriority(Notification.PRIORITY_MAX) + .build(); + nm.notify(THEME_RESET_NOTIFICATION_ID, notice); + } } diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index b4427ec..48deb68 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -1152,14 +1152,14 @@ public final class SystemServer { } IntentFilter filter = new IntentFilter(); - filter.addAction(Intent.ACTION_APP_LAUNCH_FAILURE); - filter.addAction(Intent.ACTION_APP_LAUNCH_FAILURE_RESET); + filter.addAction(Intent.ACTION_APP_FAILURE); + filter.addAction(Intent.ACTION_APP_FAILURE_RESET); filter.addAction(Intent.ACTION_PACKAGE_ADDED); filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addAction(ThemeUtils.ACTION_THEME_CHANGED); filter.addCategory(Intent.CATEGORY_THEME_PACKAGE_INSTALLED_STATE_CHANGE); filter.addDataScheme("package"); - context.registerReceiver(new AppsLaunchFailureReceiver(), filter); + context.registerReceiver(new AppsFailureReceiver(), filter); // These are needed to propagate to the runnable below. final NetworkManagementService networkManagementF = networkManagement; |