Loading packages/SystemUI/AndroidManifest.xml +9 −0 Original line number Diff line number Diff line Loading @@ -187,6 +187,15 @@ android:process=":screenshot" android:exported="false" /> <!-- Called from PhoneWindowManager --> <receiver android:name=".screenshot.ScreenshotServiceErrorReceiver" android:process=":screenshot" android:exported="false"> <intent-filter> <action android:name="com.android.systemui.screenshot.SHOW_ERROR" /> </intent-filter> </receiver> <service android:name=".LoadAverageService" android:exported="true" /> Loading packages/SystemUI/res/values/strings.xml +3 −1 Original line number Diff line number Diff line Loading @@ -185,7 +185,9 @@ <string name="screenshot_saved_text">Touch to view your screenshot.</string> <!-- Notification title displayed when we fail to take a screenshot. [CHAR LIMIT=50] --> <string name="screenshot_failed_title">Couldn\'t capture screenshot.</string> <!-- Notification text displayed when we fail to take a screenshot. [CHAR LIMIT=100] --> <!-- Notification text displayed when we fail to save a screenshot for unknown reasons. [CHAR LIMIT=100] --> <string name="screenshot_failed_to_save_unknown_text">Problem encountered while saving screenshot.</string> <!-- Notification text displayed when we fail to save a screenshot. [CHAR LIMIT=100] --> <string name="screenshot_failed_to_save_text">Can\'t save screenshot due to limited storage space.</string> <!-- Notification text displayed when we fail to take a screenshot. [CHAR LIMIT=100] --> <string name="screenshot_failed_to_capture_text">Taking screenshots is not allowed by the app or your organization.</string> Loading packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotServiceErrorReceiver.java 0 → 100644 +40 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.screenshot; import android.app.NotificationManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import com.android.systemui.R; /** * Performs a number of miscellaneous, non-system-critical actions * after the system has finished booting. */ public class ScreenshotServiceErrorReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, Intent intent) { // Show a message that we've failed to save the image to disk NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); GlobalScreenshot.notifyScreenshotError(context, nm, R.string.screenshot_failed_to_save_unknown_text); } } services/core/java/com/android/server/policy/PhoneWindowManager.java +32 −7 Original line number Diff line number Diff line Loading @@ -251,6 +251,12 @@ public class PhoneWindowManager implements WindowManagerPolicy { // app shows again. If that doesn't happen for 30s we drop the gesture. private static final long PANIC_GESTURE_EXPIRATION = 30000; private static final String SYSUI_PACKAGE = "com.android.systemui"; private static final String SYSUI_SCREENSHOT_SERVICE = "com.android.systemui.screenshot.TakeScreenshotService"; private static final String SYSUI_SCREENSHOT_ERROR_RECEIVER = "com.android.systemui.screenshot.ScreenshotServiceErrorReceiver"; /** * Keyguard stuff */ Loading Loading @@ -5186,6 +5192,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { if (mScreenshotConnection != null) { mContext.unbindService(mScreenshotConnection); mScreenshotConnection = null; notifyScreenshotError(); } } } Loading @@ -5197,10 +5204,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { if (mScreenshotConnection != null) { return; } ComponentName cn = new ComponentName("com.android.systemui", "com.android.systemui.screenshot.TakeScreenshotService"); Intent intent = new Intent(); intent.setComponent(cn); final ComponentName serviceComponent = new ComponentName(SYSUI_PACKAGE, SYSUI_SCREENSHOT_SERVICE); final Intent serviceIntent = new Intent(); serviceIntent.setComponent(serviceComponent); ServiceConnection conn = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { Loading Loading @@ -5235,17 +5242,35 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } } @Override public void onServiceDisconnected(ComponentName name) {} public void onServiceDisconnected(ComponentName name) { notifyScreenshotError(); } }; if (mContext.bindServiceAsUser( intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { if (mContext.bindServiceAsUser(serviceIntent, conn, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE, UserHandle.CURRENT)) { mScreenshotConnection = conn; mHandler.postDelayed(mScreenshotTimeout, 10000); } } } /** * Notifies the screenshot service to show an error. */ private void notifyScreenshotError() { // If the service process is killed, then ask it to clean up after itself final ComponentName errorComponent = new ComponentName(SYSUI_PACKAGE, SYSUI_SCREENSHOT_ERROR_RECEIVER); Intent errorIntent = new Intent(); errorIntent.setComponent(errorComponent); errorIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_FOREGROUND); mContext.sendBroadcastAsUser(errorIntent, UserHandle.ALL); } /** {@inheritDoc} */ @Override public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { Loading Loading
packages/SystemUI/AndroidManifest.xml +9 −0 Original line number Diff line number Diff line Loading @@ -187,6 +187,15 @@ android:process=":screenshot" android:exported="false" /> <!-- Called from PhoneWindowManager --> <receiver android:name=".screenshot.ScreenshotServiceErrorReceiver" android:process=":screenshot" android:exported="false"> <intent-filter> <action android:name="com.android.systemui.screenshot.SHOW_ERROR" /> </intent-filter> </receiver> <service android:name=".LoadAverageService" android:exported="true" /> Loading
packages/SystemUI/res/values/strings.xml +3 −1 Original line number Diff line number Diff line Loading @@ -185,7 +185,9 @@ <string name="screenshot_saved_text">Touch to view your screenshot.</string> <!-- Notification title displayed when we fail to take a screenshot. [CHAR LIMIT=50] --> <string name="screenshot_failed_title">Couldn\'t capture screenshot.</string> <!-- Notification text displayed when we fail to take a screenshot. [CHAR LIMIT=100] --> <!-- Notification text displayed when we fail to save a screenshot for unknown reasons. [CHAR LIMIT=100] --> <string name="screenshot_failed_to_save_unknown_text">Problem encountered while saving screenshot.</string> <!-- Notification text displayed when we fail to save a screenshot. [CHAR LIMIT=100] --> <string name="screenshot_failed_to_save_text">Can\'t save screenshot due to limited storage space.</string> <!-- Notification text displayed when we fail to take a screenshot. [CHAR LIMIT=100] --> <string name="screenshot_failed_to_capture_text">Taking screenshots is not allowed by the app or your organization.</string> Loading
packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotServiceErrorReceiver.java 0 → 100644 +40 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.screenshot; import android.app.NotificationManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import com.android.systemui.R; /** * Performs a number of miscellaneous, non-system-critical actions * after the system has finished booting. */ public class ScreenshotServiceErrorReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, Intent intent) { // Show a message that we've failed to save the image to disk NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); GlobalScreenshot.notifyScreenshotError(context, nm, R.string.screenshot_failed_to_save_unknown_text); } }
services/core/java/com/android/server/policy/PhoneWindowManager.java +32 −7 Original line number Diff line number Diff line Loading @@ -251,6 +251,12 @@ public class PhoneWindowManager implements WindowManagerPolicy { // app shows again. If that doesn't happen for 30s we drop the gesture. private static final long PANIC_GESTURE_EXPIRATION = 30000; private static final String SYSUI_PACKAGE = "com.android.systemui"; private static final String SYSUI_SCREENSHOT_SERVICE = "com.android.systemui.screenshot.TakeScreenshotService"; private static final String SYSUI_SCREENSHOT_ERROR_RECEIVER = "com.android.systemui.screenshot.ScreenshotServiceErrorReceiver"; /** * Keyguard stuff */ Loading Loading @@ -5186,6 +5192,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { if (mScreenshotConnection != null) { mContext.unbindService(mScreenshotConnection); mScreenshotConnection = null; notifyScreenshotError(); } } } Loading @@ -5197,10 +5204,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { if (mScreenshotConnection != null) { return; } ComponentName cn = new ComponentName("com.android.systemui", "com.android.systemui.screenshot.TakeScreenshotService"); Intent intent = new Intent(); intent.setComponent(cn); final ComponentName serviceComponent = new ComponentName(SYSUI_PACKAGE, SYSUI_SCREENSHOT_SERVICE); final Intent serviceIntent = new Intent(); serviceIntent.setComponent(serviceComponent); ServiceConnection conn = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { Loading Loading @@ -5235,17 +5242,35 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } } @Override public void onServiceDisconnected(ComponentName name) {} public void onServiceDisconnected(ComponentName name) { notifyScreenshotError(); } }; if (mContext.bindServiceAsUser( intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { if (mContext.bindServiceAsUser(serviceIntent, conn, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE, UserHandle.CURRENT)) { mScreenshotConnection = conn; mHandler.postDelayed(mScreenshotTimeout, 10000); } } } /** * Notifies the screenshot service to show an error. */ private void notifyScreenshotError() { // If the service process is killed, then ask it to clean up after itself final ComponentName errorComponent = new ComponentName(SYSUI_PACKAGE, SYSUI_SCREENSHOT_ERROR_RECEIVER); Intent errorIntent = new Intent(); errorIntent.setComponent(errorComponent); errorIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_FOREGROUND); mContext.sendBroadcastAsUser(errorIntent, UserHandle.ALL); } /** {@inheritDoc} */ @Override public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { Loading