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

Commit 646827a4 authored by Shashank Mittal's avatar Shashank Mittal Committed by Roman Birg
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 20982c69
Loading
Loading
Loading
Loading
+95 −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");
@@ -28,6 +31,7 @@ import android.os.Parcelable;
import android.os.Process;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.SystemProperties;
import android.os.UserManager;
import android.util.ArrayMap;

@@ -103,9 +107,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)

@@ -831,6 +843,76 @@ public class AppOpsManager {
            AppOpsManager.MODE_ALLOWED,
    };

    /**
     * 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
            AppOpsManager.MODE_ALLOWED, // OP WALLPAPER
            AppOpsManager.MODE_ALLOWED, // OP_ASSIST_STRUCTURE
            AppOpsManager.MODE_ALLOWED, // OP_ASSIST_SCREENSHOT
            AppOpsManager.MODE_ALLOWED, // OP_READ_PHONE_STATE
            AppOpsManager.MODE_ALLOWED, // OP_ADD_VOICEMAIL
            AppOpsManager.MODE_ALLOWED, // OP_USE_SIP
            AppOpsManager.MODE_ALLOWED, // OP_PROCESS_OUTGOING_CALLS
            AppOpsManager.MODE_ALLOWED, // OP_USE_FINGERPRINT
            AppOpsManager.MODE_ALLOWED, // OP_BODY_SENSORS
            AppOpsManager.MODE_ALLOWED, // OP_READ_CELL_BROADCASTS
            AppOpsManager.MODE_ERRORED, // OP_MOCK_LOCATION
            AppOpsManager.MODE_ALLOWED, // OP_READ_EXTERNAL_STORAGE
            AppOpsManager.MODE_ALLOWED, // OP_WRITE_EXTERNAL_STORAGE
            AppOpsManager.MODE_ALLOWED, // OP_TURN_ON_SCREEN
            AppOpsManager.MODE_ALLOWED, // OP_GET_ACCOUNTS
    };

    /**
     * This specifies whether each option is allowed to be reset
     * when resetting all app preferences.  Disable reset for
@@ -937,6 +1019,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);
@@ -1040,7 +1126,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];
    }

@@ -1767,4 +1855,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>
+88 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
**
** Copyright 2015, The CyanogenMod 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.
*/
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <!-- 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>
    <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>
        <item>Trying to write wallpaper</item>
        <item>Trying to assist structure</item>
        <item>Trying to use assist screenshot</item>
        <item>Trying to read phone state</item>
        <item>Trying to add voicemail</item>
        <item>Trying to use SIP</item>
        <item>Trying to intercept outgoing call</item>
        <item>Trying to use Fingerprint API</item>
        <item>Trying to access body sensors</item>
        <item>Trying to read cell broadcasts</item>
        <item>Trying to mock your location</item>
        <item>Trying to read external storage</item>
        <item>Trying to write external storage</item>
        <item>Trying to turn screen on</item>
        <item>Trying to get device accounts</item>
    </string-array>
</resources>
+42 −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 2015, The CyanogenMod 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.
*/
-->
<resources>
  <!-- We don't want to publish private symbols in android.R as part of the
       SDK.  Instead, put them here. -->
  <private-symbols package="com.android.internal" />

  <!-- Private symbols that we need to reference from framework code.  See
       frameworks/base/core/res/MakeJavaSymbols.sed for how to easily generate
       this.
  -->

  <!-- app opps always-ask -->
  <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="string" name="allow" />
  <java-symbol type="string" name="deny" />
  <java-symbol type="string" name="permission" />
  <java-symbol type="layout" name="permission_confirmation_dialog" />
  <java-symbol type="array" name="app_ops_labels" />

</resources>
+263 −37

File changed.

Preview size limit exceeded, changes collapsed.

Loading