Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cf426036 authored by Sunny Goyal's avatar Sunny Goyal Committed by Gerrit Code Review
Browse files

Merge "Showing a permission prompt for direct call shortcuts"

parents 6961b365 23b6a38a
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -69,7 +69,7 @@
        android:backupAgent="com.android.launcher3.LauncherBackupAgentHelper"
        android:backupAgent="com.android.launcher3.LauncherBackupAgentHelper"
        android:hardwareAccelerated="true"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/ic_launcher_home"
        android:icon="@mipmap/ic_launcher_home"
        android:label="@string/application_name"
        android:label="@string/app_name"
        android:largeHeap="@bool/config_largeHeap"
        android:largeHeap="@bool/config_largeHeap"
        android:restoreAnyVersion="true"
        android:restoreAnyVersion="true"
        android:supportsRtl="true" >
        android:supportsRtl="true" >
+4 −1
Original line number Original line Diff line number Diff line
@@ -31,7 +31,7 @@
    <string name="receive_first_load_broadcast_permission" translatable="false">com.android.launcher3.permission.RECEIVE_FIRST_LOAD_BROADCAST</string>
    <string name="receive_first_load_broadcast_permission" translatable="false">com.android.launcher3.permission.RECEIVE_FIRST_LOAD_BROADCAST</string>


    <!-- Application name -->
    <!-- Application name -->
    <string name="application_name">Launcher3</string>
    <string name="app_name">Launcher3</string>
    <!-- Default folder name -->
    <!-- Default folder name -->
    <string name="folder_name"></string>
    <string name="folder_name"></string>
    <!-- Work folder name -->
    <!-- Work folder name -->
@@ -100,6 +100,9 @@
    <string name="permdesc_write_settings">Allows the app to change the settings and
    <string name="permdesc_write_settings">Allows the app to change the settings and
        shortcuts in Home.</string>
        shortcuts in Home.</string>


    <!-- Toast shown on clicking a direct call shortcut. [CHAR_LIMIT=80] -->
    <string name="msg_no_phone_permission"><xliff:g id="app_name" example="Launcher3">%1$s</xliff:g> is not allowed to make phone calls</string>

    <!-- Widgets: -->
    <!-- Widgets: -->
    <skip />    
    <skip />    


+37 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.launcher3;
package com.android.launcher3;


import android.Manifest;
import android.animation.Animator;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.AnimatorSet;
@@ -153,6 +154,8 @@ public class Launcher extends Activity
    private static final int REQUEST_BIND_APPWIDGET = 11;
    private static final int REQUEST_BIND_APPWIDGET = 11;
    private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
    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_GRADIENT = 0;
    private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1;
    private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1;
    private static final int WORKSPACE_BACKGROUND_BLACK = 2;
    private static final int WORKSPACE_BACKGROUND_BLACK = 2;
@@ -875,6 +878,24 @@ public class Launcher extends Activity
    /** @Override for MNC */
    /** @Override for MNC */
    public void onRequestPermissionsResult(int requestCode, String[] permissions,
    public void onRequestPermissionsResult(int requestCode, String[] permissions,
            int[] grantResults) {
            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) {
        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
            mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
                    grantResults);
                    grantResults);
@@ -2932,6 +2953,22 @@ public class Launcher extends Activity
            }
            }
            return true;
            return true;
        } catch (SecurityException e) {
        } 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();
            Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
            Log.e(TAG, "Launcher does not have the permission to launch " + intent +
            Log.e(TAG, "Launcher does not have the permission to launch " + intent +
                    ". Make sure to create a MAIN intent-filter for the corresponding activity " +
                    ". Make sure to create a MAIN intent-filter for the corresponding activity " +
+2 −0
Original line number Original line Diff line number Diff line
@@ -87,6 +87,8 @@ public final class Utilities {
    private static final int[] sLoc0 = new int[2];
    private static final int[] sLoc0 = new int[2];
    private static final int[] sLoc1 = new int[2];
    private static final int[] sLoc1 = new int[2];


    public static final boolean ATLEAST_MARSHMALLOW = Build.VERSION.SDK_INT >= 23;

    // To turn on these properties, type
    // To turn on these properties, type
    // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
    // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
    private static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
    private static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";