summaryrefslogtreecommitdiff
path: root/gen_strings.py
diff options
context:
space:
mode:
author Jeff Sharkey <jsharkey@android.com> 2019-12-11 17:45:38 -0700
committer Jeff Sharkey <jsharkey@android.com> 2019-12-17 12:12:57 -0700
commiteea49d3c8f120205aa58a86ca0f19683ee88ed5c (patch)
tree7c811b21c37b49dfce8d90d3f553c4380a06540e /gen_strings.py
parent16bba13d25da1077ed565bfd4e11acdaf6f5a543 (diff)
Methods to streamline bulk media operations.
The new storage model being built in Android Q and R means that most apps will now be limited to read access to most media items on the device. This change adds a way for developers to request a user to grant narrow access to specific media items. This supports operations like requesting write access, trash/untrash, favorite/unfavorite, and outright delete. Once the user confirms the action in the dialog, the action is carried out with no further action needed by the caller. We transport the set of Uris through a ClipData to pave the way for shifting to ParceledListSlice in a future release. Since there's many permutations of strings needed, generate them with a simple Python script to ensure they stay consistent. Bug: 141911164 Test: atest --test-mapping packages/apps/MediaProvider Test: atest CtsAppSecurityHostTestCases:android.appsecurity.cts.ExternalStorageHostTest#testMediaEscalation Change-Id: I70cda4759b9f0bfdfe397f3ee4dabf42d5bff7d0
Diffstat (limited to 'gen_strings.py')
-rw-r--r--gen_strings.py88
1 files changed, 88 insertions, 0 deletions
diff --git a/gen_strings.py b/gen_strings.py
new file mode 100644
index 000000000..ee0684161
--- /dev/null
+++ b/gen_strings.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2019 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.
+
+"""
+Helper script to generate tedious strings.xml permutations
+"""
+
+from string import Template
+
+verbs = ["write","trash","untrash","delete"]
+datas = [("audio","audio file"),("video","video"),("image","photo"),("generic","item")]
+
+print '''
+<!-- ========================= BEGIN AUTO-GENERATED BY gen_strings.py ========================= -->'''
+
+for verb in verbs:
+ verblabel = verb
+ if verb == "write":
+ verblabel = "change"
+
+ verblabelcaps = verblabel[0].upper() + verblabel[1:]
+ if verb == "trash":
+ verblabelcaps = "Move to trash"
+ if verb == "untrash":
+ verblabelcaps = "Move out of trash"
+
+ print '''
+<!-- ========================= %s STRINGS ========================= -->
+''' % (verb.upper())
+ for data, datalabel in datas:
+ if verb == "trash":
+ print Template('''
+<!-- Dialog title asking if user will allow $verb permission to the $data item displayed below this string. [CHAR LIMIT=128] -->
+<plurals name="permission_${verb}_${data}">
+ <item quantity="one">Let <xliff:g id="app_name" example="Gmail">^1</xliff:g> move this $datalabel to trash?</item>
+ <item quantity="other">Let <xliff:g id="app_name" example="Gmail">^1</xliff:g> move <xliff:g id="count" example="42">^2</xliff:g> ${datalabel}s to trash?</item>
+</plurals>
+''').substitute(vars()).strip("\n")
+ print Template('''
+<!-- Dialog body text explaining that this $data item will be permanently deleted after the shown duration. [CHAR LIMIT=128] -->
+<plurals name="permission_${verb}_${data}_info">
+ <item quantity="one">This $datalabel will be permanently deleted after <xliff:g id="duration" example="42">^3</xliff:g> days</item>
+ <item quantity="other">These ${datalabel}s will be permanently deleted after <xliff:g id="duration" example="42">^3</xliff:g> days</item>
+</plurals>
+''').substitute(vars()).strip("\n")
+
+ elif verb == "untrash":
+ print Template('''
+<!-- Dialog title asking if user will allow $verb permission to the $data item displayed below this string. [CHAR LIMIT=128] -->
+<plurals name="permission_${verb}_${data}">
+ <item quantity="one">Let <xliff:g id="app_name" example="Gmail">^1</xliff:g> move this $datalabel out of trash?</item>
+ <item quantity="other">Let <xliff:g id="app_name" example="Gmail">^1</xliff:g> move <xliff:g id="count" example="42">^2</xliff:g> ${datalabel}s out of trash?</item>
+</plurals>
+''').substitute(vars()).strip("\n")
+
+ else:
+ print Template('''
+<!-- Dialog title asking if user will allow $verb permission to the $data item displayed below this string. [CHAR LIMIT=128] -->
+<plurals name="permission_${verb}_${data}">
+ <item quantity="one">Let <xliff:g id="app_name" example="Gmail">^1</xliff:g> $verblabel this $datalabel?</item>
+ <item quantity="other">Let <xliff:g id="app_name" example="Gmail">^1</xliff:g> $verblabel <xliff:g id="count" example="42">^2</xliff:g> ${datalabel}s?</item>
+</plurals>
+''').substitute(vars()).strip("\n")
+
+
+ print Template('''
+<!-- Positive dialog button confirming that $verb permission should be granted. [CHAR LIMIT=32] -->
+<string name="permission_${verb}_grant">${verblabelcaps}</string>
+<!-- Negative dialog button confirming that $verb permission should not be granted. [CHAR LIMIT=32] -->
+<string name="permission_${verb}_deny">Cancel</string>
+''').substitute(vars()).strip("\n")
+
+print '''
+<!-- ========================= END AUTO-GENERATED BY gen_strings.py ========================= -->
+'''