From 28c6b963d4ccac73ab857c839420513dd560945c Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Mon, 12 Oct 2015 11:42:05 -0700 Subject: Showing a permission prompt for direct call shortcuts Bug: 24580949 Change-Id: Idc92f9f5979a730f43b4905af2bc47b6834dc7a7 --- AndroidManifest.xml | 2 +- res/values/strings.xml | 5 ++++- src/com/android/launcher3/Launcher.java | 37 +++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 99a6ad9aa..48dcf4ee7 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -68,7 +68,7 @@ android:backupAgent="com.android.launcher3.LauncherBackupAgentHelper" android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher_home" - android:label="@string/application_name" + android:label="@string/app_name" android:largeHeap="@bool/config_largeHeap" android:restoreAnyVersion="true" android:supportsRtl="true" > diff --git a/res/values/strings.xml b/res/values/strings.xml index fefadef28..b54478860 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -31,7 +31,7 @@ com.android.launcher3.permission.RECEIVE_FIRST_LOAD_BROADCAST - Launcher3 + Launcher3 @@ -103,6 +103,9 @@ Allows the app to change the settings and shortcuts in Home. + + %1$s is not allowed to make phone calls + diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 7f8dc3c2e..3b1ee2abb 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -16,6 +16,7 @@ package com.android.launcher3; +import android.Manifest; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorSet; @@ -150,6 +151,8 @@ public class Launcher extends Activity private static final int REQUEST_BIND_APPWIDGET = 11; private static final int REQUEST_RECONFIGURE_APPWIDGET = 12; + private static final int REQUEST_PERMISSION_CALL_PHONE = 13; + private static final int WORKSPACE_BACKGROUND_GRADIENT = 0; private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1; private static final int WORKSPACE_BACKGROUND_BLACK = 2; @@ -872,6 +875,24 @@ public class Launcher extends Activity /** @Override for MNC */ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + if (requestCode == REQUEST_PERMISSION_CALL_PHONE && sPendingAddItem != null + && sPendingAddItem.requestCode == REQUEST_PERMISSION_CALL_PHONE) { + View v = null; + CellLayout layout = getCellLayout(sPendingAddItem.container, sPendingAddItem.screenId); + if (layout != null) { + v = layout.getChildAt(sPendingAddItem.cellX, sPendingAddItem.cellY); + } + Intent intent = sPendingAddItem.intent; + sPendingAddItem = null; + if (grantResults.length > 0 + && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + startActivity(v, intent, null); + } else { + // TODO: Show a snack bar with link to settings + Toast.makeText(this, getString(R.string.msg_no_phone_permission, + getString(R.string.app_name)), Toast.LENGTH_SHORT).show(); + } + } if (mLauncherCallbacks != null) { mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions, grantResults); @@ -2945,6 +2966,22 @@ public class Launcher extends Activity } return true; } catch (SecurityException e) { + if (Utilities.ATLEAST_MARSHMALLOW && tag instanceof ItemInfo) { + // Due to legacy reasons, direct call shortcuts require Launchers to have the + // corresponding permission. Show the appropriate permission prompt if that + // is the case. + if (intent.getComponent() == null + && Intent.ACTION_CALL.equals(intent.getAction()) + && checkSelfPermission(Manifest.permission.CALL_PHONE) != + PackageManager.PERMISSION_GRANTED) { + // TODO: Rename sPendingAddItem to a generic name. + sPendingAddItem = preparePendingAddArgs(REQUEST_PERMISSION_CALL_PHONE, intent, + 0, (ItemInfo) tag); + requestPermissions(new String[]{Manifest.permission.CALL_PHONE}, + REQUEST_PERMISSION_CALL_PHONE); + return false; + } + } Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); Log.e(TAG, "Launcher does not have the permission to launch " + intent + ". Make sure to create a MAIN intent-filter for the corresponding activity " + -- cgit v1.2.3