aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/permissions/PermissionsUtil.java
diff options
context:
space:
mode:
authorMohammadinamul Sheik <inamul@google.com>2015-07-15 13:32:50 -0700
committerMohammadinamul Sheik <inamul@google.com>2015-07-15 22:51:53 +0000
commit604158669b407a40cd0f23538fad4dce5d738f24 (patch)
tree85aab20d4da9aa12bdd409ce04541db25de1e2f4 /java/src/com/android/inputmethod/latin/permissions/PermissionsUtil.java
parent7d5fb3a9430550a3ccf1ed5afd70dbf8cc81574a (diff)
downloadlatinime-604158669b407a40cd0f23538fad4dce5d738f24.tar.gz
latinime-604158669b407a40cd0f23538fad4dce5d738f24.tar.xz
latinime-604158669b407a40cd0f23538fad4dce5d738f24.zip
[LatinIME] Support MNC permissions.
This build has been compiled against API 23 This build is approved to go out with the M OTA, but may NOT be released to the public until the Play Store has enabled API level 23 apps Version: 4.1.2300x.build_id 1. Replaces the personalization is on information with the suggest contacts. 2. Enables "Use Contacts" only if the app has permission to read contacts. 3. Disables the contacts dictionary in the Facilitator. 4. Do not register/read the contacts in the contact observer. Bug: 22236416 Change-Id: I9674e13d0d0f4a2014c5024fde0178de684c07e7
Diffstat (limited to 'java/src/com/android/inputmethod/latin/permissions/PermissionsUtil.java')
-rw-r--r--java/src/com/android/inputmethod/latin/permissions/PermissionsUtil.java93
1 files changed, 93 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/permissions/PermissionsUtil.java b/java/src/com/android/inputmethod/latin/permissions/PermissionsUtil.java
new file mode 100644
index 000000000..747f64f24
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/permissions/PermissionsUtil.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2015 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.inputmethod.latin.permissions;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.Build;
+import android.support.annotation.NonNull;
+import android.support.v4.app.ActivityCompat;
+import android.support.v4.content.ContextCompat;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Utility class for permissions.
+ */
+public class PermissionsUtil {
+
+ /**
+ * Returns the list of permissions not granted from the given list of permissions.
+ * @param context Context
+ * @param permissions list of permissions to check.
+ * @return the list of permissions that do not have permission to use.
+ */
+ public static List<String> getDeniedPermissions(Context context,
+ String... permissions) {
+ final List<String> deniedPermissions = new ArrayList<>();
+ for (String permission : permissions) {
+ if (ContextCompat.checkSelfPermission(context, permission)
+ != PackageManager.PERMISSION_GRANTED) {
+ deniedPermissions.add(permission);
+ }
+ }
+ return deniedPermissions;
+ }
+
+ /**
+ * Uses the given activity and requests the user for permissions.
+ * @param activity activity to use.
+ * @param requestCode request code/id to use.
+ * @param permissions String array of permissions that needs to be requested.
+ */
+ public static void requestPermissions(Activity activity, int requestCode,
+ String[] permissions) {
+ ActivityCompat.requestPermissions(activity, permissions, requestCode);
+ }
+
+ /**
+ * Checks if all the permissions are granted.
+ */
+ public static boolean allGranted(@NonNull int[] grantResults) {
+ for (int result : grantResults) {
+ if (result != PackageManager.PERMISSION_GRANTED) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Queries if al the permissions are granted for the given permission strings.
+ */
+ public static boolean checkAllPermissionsGranted(Context context, String... permissions) {
+ if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
+ // For all pre-M devices, we should have all the premissions granted on install.
+ return true;
+ }
+
+ for (String permission : permissions) {
+ if (ContextCompat.checkSelfPermission(context, permission)
+ != PackageManager.PERMISSION_GRANTED) {
+ return false;
+ }
+ }
+ return true;
+ }
+}