From 15db7cdf8d3afc30d754e924c21eece66bf0f0fd Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Mon, 7 May 2018 09:42:38 -0400 Subject: [PATCH] Don't be clever with strings The app ops strings were not translating well, leading to crashes in some languages Test: atest SystemUITests Change-Id: Iee18504217c5c13543ad130f502695e3919d7ddf Fixes: 77640411 --- packages/SystemUI/res/values/strings.xml | 29 +++++----- .../systemui/statusbar/AppOpsInfo.java | 53 ++++++++----------- 2 files changed, 35 insertions(+), 47 deletions(-) diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index f1f80c70af39e..ea253559d988d 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -1567,21 +1567,20 @@ These notifications can\'t be turned off - camera - - microphone - - displaying over other apps on your screen - - - This app is %1$s. - This app is %1$s and %2$s. - - - - using the %1$s - using the %1$s and %2$s - + + This app is using the camera. + + This app is using the microphone. + + This app is displaying over other apps on your screen. + + This app is using the microphone and camera. + + This app is displaying over other apps on your screen and using the camera. + + This app is displaying over other apps on your screen and using the microphone. + + This app is displaying over other apps on your screen and using the microphone and camera. Settings OK diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/AppOpsInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/AppOpsInfo.java index 322a529d5e1ac..cfc4da4e4898c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/AppOpsInfo.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/AppOpsInfo.java @@ -109,7 +109,7 @@ public class AppOpsInfo extends LinearLayout implements NotificationGuts.GutsCon private void bindPrompt() { final TextView prompt = findViewById(R.id.prompt); - prompt.setText(getPromptString()); + prompt.setText(getPrompt()); } private void bindButtons() { @@ -121,41 +121,30 @@ public class AppOpsInfo extends LinearLayout implements NotificationGuts.GutsCon ok.setOnClickListener(mOnOk); } - private String getPromptString() { - String cameraString = - mContext.getResources().getString(R.string.notification_appops_camera_active); - String micString = - mContext.getResources().getString(R.string.notification_appops_microphone_active); - String overlayString = - mContext.getResources().getString(R.string.notification_appops_overlay_active); - String using = null; - String promptString; - if (mAppOps.contains(AppOpsManager.OP_CAMERA) - && mAppOps.contains(AppOpsManager.OP_RECORD_AUDIO)) { - using = mContext.getResources().getQuantityString( - R.plurals.notification_using, 2, micString, cameraString); - } else if (mAppOps.contains(AppOpsManager.OP_CAMERA)) { - using = mContext.getResources().getQuantityString( - R.plurals.notification_using, 1, cameraString); - } else if (mAppOps.contains(AppOpsManager.OP_RECORD_AUDIO)){ - using = mContext.getResources().getQuantityString( - R.plurals.notification_using, 1, micString); - } - - if (mAppOps.contains(AppOpsManager.OP_SYSTEM_ALERT_WINDOW)) { - if (using != null) { - promptString = mContext.getResources().getQuantityString( - R.plurals.notification_appops, 2, overlayString, using); + private String getPrompt() { + if (mAppOps == null || mAppOps.size() == 0) { + return ""; + } else if (mAppOps.size() == 1) { + if (mAppOps.contains(AppOpsManager.OP_CAMERA)) { + return mContext.getString(R.string.appops_camera); + } else if (mAppOps.contains(AppOpsManager.OP_RECORD_AUDIO)) { + return mContext.getString(R.string.appops_microphone); } else { - promptString = mContext.getResources().getQuantityString( - R.plurals.notification_appops, 1, overlayString); + return mContext.getString(R.string.appops_overlay); + } + } else if (mAppOps.size() == 2) { + if (mAppOps.contains(AppOpsManager.OP_CAMERA)) { + if (mAppOps.contains(AppOpsManager.OP_RECORD_AUDIO)) { + return mContext.getString(R.string.appops_camera_mic); + } else { + return mContext.getString(R.string.appops_camera_overlay); + } + } else { + return mContext.getString(R.string.appops_mic_overlay); } } else { - promptString = mContext.getResources().getQuantityString( - R.plurals.notification_appops, 1, using); + return mContext.getString(R.string.appops_camera_mic_overlay); } - - return promptString; } @Override