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

Commit 8b8457f6 authored by Shashank Mittal's avatar Shashank Mittal Committed by Ricardo Cerqueira
Browse files

AppOpsService: Add MODE_ASK support to AppOps.

Add support for new mode(MODE_ASK) in AppOpsService to show a permission
dialog box to user to confirm user permission before allowing or ignoring
that operation.
All strict operations (defined in AppOpsManager) are going to be in
MODE_ASK by default.
Operations will be moved to MODE_ALLOWED or MODE_IGNORED according to
user's choice.

Change-Id: I1314125a2b8be558e422e4a9eea0ff066c21bf94
parent e0c02b16
Loading
Loading
Loading
Loading
+80 −2
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
 * Not a Contribution.
 *
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,6 +29,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.Process;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserManager;
import android.util.ArrayMap;

@@ -101,9 +105,17 @@ public class AppOpsManager {
     */
    public static final int MODE_DEFAULT = 3;

    /**
     * @hide Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}:
     * AppOps Service should show a dialog box on screen to get user
     * permission.
     */
    public static final int MODE_ASK = 4;

    // when adding one of these:
    //  - increment _NUM_OP
    //  - add rows to sOpToSwitch, sOpToString, sOpNames, sOpPerms, sOpDefaultMode
    //  - add rows to sOpToSwitch, sOpToString, sOpNames, sOpPerms, sOpDefaultMode, sOpDefaultStrictMode
    //  - add descriptive strings to frameworks/base/core/res/res/values/config.xml
    //  - add descriptive strings to Settings/res/values/arrays.xml
    //  - add the op to the appropriate template in AppOpsState.OpsTemplate (settings app)

@@ -616,6 +628,61 @@ public class AppOpsManager {
            AppOpsManager.MODE_IGNORED, // OP_ACTIVATE_VPN
    };

    /**
     * This specifies the default mode for each strict operation.
     */

    private static int[] sOpDefaultStrictMode = new int[] {
            AppOpsManager.MODE_ASK,     // OP_COARSE_LOCATION
            AppOpsManager.MODE_ASK,     // OP_FINE_LOCATION
            AppOpsManager.MODE_ASK,     // OP_GPS
            AppOpsManager.MODE_ALLOWED, // OP_VIBRATE
            AppOpsManager.MODE_ASK,     // OP_READ_CONTACTS
            AppOpsManager.MODE_ASK,     // OP_WRITE_CONTACTS
            AppOpsManager.MODE_ASK,     // OP_READ_CALL_LOG
            AppOpsManager.MODE_ASK,     // OP_WRITE_CALL_LOG
            AppOpsManager.MODE_ALLOWED, // OP_READ_CALENDAR
            AppOpsManager.MODE_ALLOWED, // OP_WRITE_CALENDAR
            AppOpsManager.MODE_ASK,     // OP_WIFI_SCAN
            AppOpsManager.MODE_ALLOWED, // OP_POST_NOTIFICATION
            AppOpsManager.MODE_ALLOWED, // OP_NEIGHBORING_CELLS
            AppOpsManager.MODE_ASK,     // OP_CALL_PHONE
            AppOpsManager.MODE_ASK,     // OP_READ_SMS
            AppOpsManager.MODE_ASK,     // OP_WRITE_SMS
            AppOpsManager.MODE_ASK,     // OP_RECEIVE_SMS
            AppOpsManager.MODE_ALLOWED, // OP_RECEIVE_EMERGECY_SMS
            AppOpsManager.MODE_ASK,     // OP_RECEIVE_MMS
            AppOpsManager.MODE_ALLOWED, // OP_RECEIVE_WAP_PUSH
            AppOpsManager.MODE_ASK,     // OP_SEND_SMS
            AppOpsManager.MODE_ALLOWED, // OP_READ_ICC_SMS
            AppOpsManager.MODE_ALLOWED, // OP_WRITE_ICC_SMS
            AppOpsManager.MODE_ALLOWED, // OP_WRITE_SETTINGS
            AppOpsManager.MODE_ALLOWED, // OP_SYSTEM_ALERT_WINDOW
            AppOpsManager.MODE_ALLOWED, // OP_ACCESS_NOTIFICATIONS
            AppOpsManager.MODE_ASK,     // OP_CAMERA
            AppOpsManager.MODE_ASK,     // OP_RECORD_AUDIO
            AppOpsManager.MODE_ALLOWED, // OP_PLAY_AUDIO
            AppOpsManager.MODE_ALLOWED, // OP_READ_CLIPBOARD
            AppOpsManager.MODE_ALLOWED, // OP_WRITE_CLIPBOARD
            AppOpsManager.MODE_ALLOWED, // OP_TAKE_MEDIA_BUTTONS
            AppOpsManager.MODE_ALLOWED, // OP_TAKE_AUDIO_FOCUS
            AppOpsManager.MODE_ALLOWED, // OP_AUDIO_MASTER_VOLUME
            AppOpsManager.MODE_ALLOWED, // OP_AUDIO_VOICE_VOLUME
            AppOpsManager.MODE_ALLOWED, // OP_AUDIO_RING_VOLUME
            AppOpsManager.MODE_ALLOWED, // OP_AUDIO_MEDIA_VOLUME
            AppOpsManager.MODE_ALLOWED, // OP_AUDIO_ALARM_VOLUME
            AppOpsManager.MODE_ALLOWED, // OP_AUDIO_NOTIFICATION_VOLUME
            AppOpsManager.MODE_ALLOWED, // OP_AUDIO_BLUETOOTH_VOLUME
            AppOpsManager.MODE_ALLOWED, // OP_WAKE_LOCK
            AppOpsManager.MODE_ALLOWED, // OP_MONITOR_LOCATION
            AppOpsManager.MODE_ASK,     // OP_MONITOR_HIGH_POWER_LOCATION
            AppOpsManager.MODE_DEFAULT, // OP_GET_USAGE_STATS
            AppOpsManager.MODE_ALLOWED, // OP_MUTE_MICROPHONE
            AppOpsManager.MODE_ALLOWED, // OP_TOAST_WINDOW
            AppOpsManager.MODE_IGNORED, // OP_PROJECT_MEDIA
            AppOpsManager.MODE_IGNORED, // OP_ACTIVATE_VPN
    };

    /**
     * This specifies whether each option is allowed to be reset
     * when resetting all app preferences.  Disable reset for
@@ -697,6 +764,10 @@ public class AppOpsManager {
            throw new IllegalStateException("sOpDefaultMode length " + sOpDefaultMode.length
                    + " should be " + _NUM_OP);
        }
        if (sOpDefaultStrictMode.length != _NUM_OP) {
            throw new IllegalStateException("sOpDefaultStrictMode length " + sOpDefaultStrictMode.length
                    + " should be " + _NUM_OP);
        }
        if (sOpDisableReset.length != _NUM_OP) {
            throw new IllegalStateException("sOpDisableReset length " + sOpDisableReset.length
                    + " should be " + _NUM_OP);
@@ -762,7 +833,9 @@ public class AppOpsManager {
     * Retrieve the default mode for the operation.
     * @hide
     */
    public static int opToDefaultMode(int op) {
    public static int opToDefaultMode(int op, boolean isStrict) {
        if (isStrict)
            return sOpDefaultStrictMode[op];
        return sOpDefaultMode[op];
    }

@@ -1378,4 +1451,9 @@ public class AppOpsManager {
    public void finishOp(int op) {
        finishOp(op, Process.myUid(), mContext.getOpPackageName());
    }

    /** @hide */
    public static boolean isStrictEnable() {
        return SystemProperties.getBoolean("persist.sys.strict_op_enable", false);
    }
}
+69 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
** Copyright (c) 2013, The Linux Foundation. All rights reserved.
** Not a Contribution.
**
** Copyright 2012 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.
*/
-->

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/parentPanel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="8dip"
    android:layout_marginRight="8dip"
    android:orientation="vertical">

    <TextView android:id="@+id/permission_text"
        style="?android:attr/textAppearanceMedium"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="20dip"
        android:paddingRight="20dip"
        android:paddingTop="16dip"
        android:paddingBottom="16dip" />

    <TableLayout android:id="@+id/permission_remember_layout"
        android:shrinkColumns="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="16dip"
        android:paddingRight="16dip">

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
            <RelativeLayout android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingTop="12dip"
                android:paddingLeft="8dip" >
            <CheckBox android:id="@+id/permission_remember_choice_checkbox"
                android:paddingTop="11dip"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            </RelativeLayout>
            <TextView android:id="@+id/permission_remember_choice_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingTop="18dip"
                android:text="@string/permission_remember_choice" />
        </TableRow>

    </TableLayout>

</LinearLayout>
+54 −1
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
** Not a Contribution.
**
** Copyright 2009, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -1899,4 +1901,55 @@
    <!-- bool value to for enabling motion accelerometer -->
    <bool name="use_motion_accel">false</bool>

    <!-- User display names for app ops codes -->
    <string-array name="app_ops_labels">
        <item>Trying to access location</item>
        <item>Trying to access location</item>
        <item>Trying to access location</item>
        <item>Trying to use vibrate</item>
        <item>Trying to read contacts</item>
        <item>Trying to modify contacts</item>
        <item>Trying to read call log</item>
        <item>Trying to modify call log</item>
        <item>Trying to read calendar</item>
        <item>Trying to modify calendar</item>
        <item>Trying to access location</item>
        <item>Trying to post notification</item>
        <item>Trying to access location</item>
        <item>Trying to make phone call</item>
        <item>Trying to read SMS/MMS</item>
        <item>Trying to write/modify SMS/MMS</item>
        <item>Trying to receive SMS/MMS</item>
        <item>Trying to receive SMS/MMS</item>
        <item>Trying to receive SMS/MMS</item>
        <item>Trying to receive SMS/MMS</item>
        <item>Trying to send SMS/MMS</item>
        <item>Trying to read SMS/MMS</item>
        <item>Trying to write/modify SMS/MMS</item>
        <item>Trying to modify settings</item>
        <item>Trying to draw on top</item>
        <item>Trying to access notifications</item>
        <item>Trying to access Camera</item>
        <item>Trying to record audio</item>
        <item>Trying to play audio</item>
        <item>Trying to read clipboard</item>
        <item>Trying to modify clipboard</item>
        <item>Trying to use media buttons</item>
        <item>Trying to use audio focus</item>
        <item>Trying to use master volume</item>
        <item>Trying to use voice volume</item>
        <item>Trying to use ring volume</item>
        <item>Trying to use media volume</item>
        <item>Trying to use alarm volume</item>
        <item>Trying to use notification volume</item>
        <item>Trying to use bluetooth volume</item>
        <item>Trying to Keep device awake</item>
        <item>Trying to access location</item>
        <item>Trying to access location</item>
        <item>Trying to get usage stats</item>
        <item>Trying to mute microphone</item>
        <item>Trying to toast window</item>
        <item>Trying to project media</item>
        <item>Trying to activate vpn</item>
    </string-array>
</resources>
+3 −0
Original line number Diff line number Diff line
@@ -4919,4 +4919,7 @@
    <string name="stk_cc_ss_to_ussd">SS request is modified to USSD request.</string>
    <string name="stk_cc_ss_to_ss">SS request is modified to new SS request.</string>

    <!-- Text of the checkbox for the permission confirmation dialog to remember the user's choice. [CHAR LIMIT=40] -->
    <string name="permission_remember_choice">Remember</string>
    <string name="permission">Permission</string>
</resources>
+13 −1
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/* Copyright 2012, The Android Open Source Project
/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
** Not a Contribution.
**
** Copyright 2012, 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.
@@ -220,6 +223,10 @@
  <java-symbol type="id" name="profile_badge_line2" />
  <java-symbol type="id" name="profile_badge_line3" />
  <java-symbol type="id" name="transitionPosition" />
  <java-symbol type="id" name="permission_text" />
  <java-symbol type="id" name="permission_remember_layout" />
  <java-symbol type="id" name="permission_remember_choice_checkbox" />
  <java-symbol type="id" name="permission_remember_choice_text" />

  <java-symbol type="attr" name="actionModeShareDrawable" />
  <java-symbol type="attr" name="alertDialogCenterButtons" />
@@ -461,6 +468,7 @@
  <java-symbol type="string" name="activitychooserview_choose_application" />
  <java-symbol type="string" name="activitychooserview_choose_application_error" />
  <java-symbol type="string" name="alternate_eri_file" />
  <java-symbol type="string" name="allow" />
  <java-symbol type="string" name="alwaysUse" />
  <java-symbol type="string" name="autofill_address_line_1_label_re" />
  <java-symbol type="string" name="autofill_address_line_1_re" />
@@ -565,6 +573,7 @@
  <java-symbol type="string" name="db_default_sync_mode" />
  <java-symbol type="string" name="db_wal_sync_mode" />
  <java-symbol type="string" name="decline" />
  <java-symbol type="string" name="deny" />
  <java-symbol type="string" name="description_target_unlock_tablet" />
  <java-symbol type="string" name="display_manager_built_in_display_name" />
  <java-symbol type="string" name="display_manager_hdmi_display_name" />
@@ -725,6 +734,7 @@
  <java-symbol type="string" name="orgTypeWork" />
  <java-symbol type="string" name="passwordIncorrect" />
  <java-symbol type="string" name="perms_description_app" />
  <java-symbol type="string" name="permission" />
  <java-symbol type="string" name="perms_new_perm_prefix" />
  <java-symbol type="string" name="petabyteShort" />
  <java-symbol type="string" name="phoneTypeAssistant" />
@@ -1295,6 +1305,7 @@
  <java-symbol type="layout" name="locale_picker_item" />
  <java-symbol type="layout" name="media_controller" />
  <java-symbol type="layout" name="overlay_display_window" />
  <java-symbol type="layout" name="permission_confirmation_dialog" />
  <java-symbol type="layout" name="preference" />
  <java-symbol type="layout" name="preference_header_item" />
  <java-symbol type="layout" name="preference_list_content" />
@@ -1562,6 +1573,7 @@
  <java-symbol type="anim" name="rotation_animation_jump_exit" />
  <java-symbol type="anim" name="rotation_animation_xfade_exit" />
  <java-symbol type="anim" name="rotation_animation_enter" />
  <java-symbol type="array" name="app_ops_labels" />
  <java-symbol type="array" name="config_autoBrightnessButtonBacklightValues" />
  <java-symbol type="array" name="config_autoBrightnessKeyboardBacklightValues" />
  <java-symbol type="array" name="config_autoBrightnessLcdBacklightValues" />
Loading