From 926c56f060e6ffd7a4a638f677c2c71ff53e78c5 Mon Sep 17 00:00:00 2001 From: Daichi Hirono Date: Fri, 13 Apr 2018 15:40:37 +0900 Subject: [PATCH] Add nullchecks to ScreenPinningRequest. To make ScreenPinningRequest workable with devices that does not have the recent view and navigation bar. Also mark ScreenPinningNotify methods as public so that it can be invoked from vendor customized code. Bug: 78248081 Test: Manually invoke Activity#startLockTask() Change-Id: I7b3578bfe32dffb32ca1c21f5e30f98aa452efb0 --- .../systemui/recents/ScreenPinningRequest.java | 16 ++++++++++------ .../statusbar/phone/ScreenPinningNotify.java | 6 +++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/recents/ScreenPinningRequest.java b/packages/SystemUI/src/com/android/systemui/recents/ScreenPinningRequest.java index bfbba7c1128a2..dd0967a5eb578 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/ScreenPinningRequest.java +++ b/packages/SystemUI/src/com/android/systemui/recents/ScreenPinningRequest.java @@ -217,7 +217,8 @@ public class ScreenPinningRequest implements View.OnClickListener { mLayout.findViewById(R.id.screen_pinning_text_area) .setLayoutDirection(View.LAYOUT_DIRECTION_LOCALE); View buttons = mLayout.findViewById(R.id.screen_pinning_buttons); - if (Recents.getSystemServices().hasSoftNavigationBar()) { + if (Recents.getSystemServices() != null && + Recents.getSystemServices().hasSoftNavigationBar()) { buttons.setLayoutDirection(View.LAYOUT_DIRECTION_LOCALE); swapChildrenIfRtlAndVertical(buttons); } else { @@ -235,7 +236,8 @@ public class ScreenPinningRequest implements View.OnClickListener { } StatusBar statusBar = SysUiServiceProvider.getComponent(mContext, StatusBar.class); - NavigationBarView navigationBarView = statusBar.getNavigationBarView(); + NavigationBarView navigationBarView = + statusBar != null ? statusBar.getNavigationBarView() : null; final boolean recentsVisible = navigationBarView != null && navigationBarView.isRecentsButtonVisible(); boolean touchExplorationEnabled = mAccessibilityService.isTouchExplorationEnabled(); @@ -256,10 +258,12 @@ public class ScreenPinningRequest implements View.OnClickListener { : R.string.screen_pinning_description_recents_invisible; } - ((ImageView) mLayout.findViewById(R.id.screen_pinning_back_icon)) - .setImageDrawable(navigationBarView.getBackDrawable(mContext)); - ((ImageView) mLayout.findViewById(R.id.screen_pinning_home_icon)) - .setImageDrawable(navigationBarView.getHomeDrawable(mContext)); + if (navigationBarView != null) { + ((ImageView) mLayout.findViewById(R.id.screen_pinning_back_icon)) + .setImageDrawable(navigationBarView.getBackDrawable(mContext)); + ((ImageView) mLayout.findViewById(R.id.screen_pinning_home_icon)) + .setImageDrawable(navigationBarView.getHomeDrawable(mContext)); + } ((TextView) mLayout.findViewById(R.id.screen_pinning_description)) .setText(descriptionStringResId); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScreenPinningNotify.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScreenPinningNotify.java index 0d07ad9cdf2e6..2a5028bbe181f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScreenPinningNotify.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScreenPinningNotify.java @@ -42,17 +42,17 @@ public class ScreenPinningNotify { } /** Show "Screen pinned" toast. */ - void showPinningStartToast() { + public void showPinningStartToast() { makeAllUserToastAndShow(R.string.screen_pinning_start); } /** Show "Screen unpinned" toast. */ - void showPinningExitToast() { + public void showPinningExitToast() { makeAllUserToastAndShow(R.string.screen_pinning_exit); } /** Show a toast that describes the gesture the user should use to escape pinned mode. */ - void showEscapeToast(boolean isRecentsButtonVisible) { + public void showEscapeToast(boolean isRecentsButtonVisible) { long showToastTime = SystemClock.elapsedRealtime(); if ((showToastTime - mLastShowToastTime) < SHOW_TOAST_MINIMUM_INTERVAL) { Slog.i(TAG, "Ignore toast since it is requested in very short interval.");