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

Commit a604f39c authored by Steve Kondik's avatar Steve Kondik Committed by Michael Bestas
Browse files

appops: Privacy Guard for O

Squashed commit of all PG-related features including superuser

   Authors:
   - Sam Mortimer
   - Danesh Mondegarian
   - Jorge Ruesga
   - Diogo Ferreira
   - Roman Birg
   - Adnan Begovic
   - Chirayu Desai
   - Lars Greiss
   - Steve Kondik
   - CodeAurora

Pulled together from:

Author: Danesh M <daneshm90@gmail.com>
Date:   Thu Sep 5 19:23:15 2013 -0700

    Privacy Guard : Reimplement backed by AppOps

    Re-implements privacy guard to use appops.

    Change-Id: I2b52e8cf0d6e126fb156f83df885b5551503cd9d

Author: Shashank Mittal <mittals@codeaurora.org>
Date:   Fri Aug 16 01:09:28 2013 -0700

    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

Author: Shashank Mittal <mittals@codeaurora.org>
Date:   Tue Sep 3 19:23:10 2013 -0700

    wifi: Confirm user permission before toggling wifi.

    Check user permissions before enabling/disabling wifi.

    Change-Id: I1ddae6e47f42b6d3fc831c2c135ece75cf9e935d

Author: Shashank Mittal <mittals@codeaurora.org>
Date:   Thu Sep 5 17:24:44 2013 -0700

    AppOps: Add Bluetooth enable control into AppOps

    Check user permission before enabling bluetooth.

    Change-Id: Iefa4ea3319b33b2639beaf38d261d83649bbcf85

Author: Sam Mortimer <sam@mortimer.me.uk>
Date:   Wed Oct 2 22:06:42 2013 -0700

    [2/2] AppOps: Add per Op allowed and ignored counters

    Change-Id: Ifb3d25e17dbab082b816a0a655b4796a83af336b

Author: Sam Mortimer <sam@mortimer.me.uk>
Date:   Sun Oct 20 23:48:00 2013 -0700

    AppOps: track op persistence by name instead of id

    On XML write, include the op name.  On XML read, map
    the name back to op id (if it exists).

    Persistent AppOp state now follows the op name instead
    numeric id.  This allows upgrades between versions of
    android that have different code<>name mappings.

    Change-Id: Iffc02095b6838a34ff999f8db51c2c6739dd0db8

Author: Jorge Ruesga <jorge@ruesga.com>
Date:   Sat Jan 4 01:34:39 2014 +0100

    privacyguard: Share privacy package name between activity stacks

    AOSP 4.4 now has a stack supervisor with differents activity stacks for home and focus activities.
    Every ActivityStack instance has a ref to this supervisor. Just share the privacy guard package name
    throught the supervisor.

    JIRA: CYAN-2874
    Issue: https://jira.cyanogenmod.org/browse/CYAN-2874

Author: Steve Kondik <shade@chemlab.org>
Date:   Sun Feb 23 19:23:31 2014 +0100

    Use MODE_ASK as the default ops mode in Privacy Guard

    * Prompting the user is far more useful as a default behavior. The
      choice will be remembered after the first request.

Author: Steve Kondik <shade@chemlab.org>
Date:   Tue Feb 25 13:11:12 2014 +0100

    Relocate and cleanup new app ops features and PGify it

Author: Shashank Mittal <mittals@codeaurora.org>
Date:   Wed Dec 4 12:32:12 2013 -0800

    [2/2] Framework AppOps: Add BOOT_COMPLETED operation.

    Add BOOT_COMPLETED operation in AppOps.

    This operation is used to allow user to control auto start of
    applications and services at bootup.

    Change-Id: Ie8488ec1b4683c8617ca569cfc858709f0d35ba2

Author: Sam Mortimer <sam@mortimer.me.uk>
Date:   Mon Dec 8 13:51:02 2014 -0800

    Frameworks: Redirect appops strings to string references

    adapted to reflect new permission indices and codes

    Change-Id: Iba9a45838ee8eb7f5cb6ec6d29776574c86e84b6

Author: Kun Liang <kunliang@codeaurora.org>
Date:   Thu May 15 14:52:15 2014 +0800

    AppOps: Add nfc enable control into AppOps

    Check user permission before enabling nfc.

    Change-Id: Ia84e33c299e4fdecfd66ee933d9e7d37ed29c340

Author: Shashank Mittal <mittals@codeaurora.org>
Date:   Wed Jul 16 17:31:22 2014 -0700

    AppOps: Add support for AppOps policy file

    Add support to read AppOps policy file.
    AppOps policy file can be used to configure Ops default policy.

    Change-Id: Idb4e3501ff9f58e491b06e74152342aa9574afbf

Author: Kun Liang <kunliang@codeaurora.org>
Date:   Thu Dec 11 12:57:33 2014 +0800

    AppOps: fix deadlock issue when showing dialog

    WindowManagerService need call PowerManagerService to release
    wakelock. The Notifier in PowerManagerService need call AppOpsService
    to notify holding wakelock ops is finished.  Meanwhile, AppOpsService
    may need call WindowManagerService to show dialog. This scenario
    will lead to deadlock issue.
    To move showing dialog action out of lock section to fix this issue.
    Since only UI work is moved out of lock area, it is supposed to be
    safe.

    Change-Id: I3f2bf4b9c9d81914cfd3c0fc3fc76d0b4a06a1f6
    CRs-fixed: 786466

Author: Diogo Ferreira <defer@cyngn.com>
Date:   Mon Dec 15 12:07:42 2014 +0000

    appops: Add support for SU

    This patch adds support for superuser app-ops control. The end-goal
    is to better prepare superuser for the multi-user experience while
    also replacing the superuser app with existing components.

    Change-Id: I52acf98a39f18f12a23f4f902a39ae3f7c5b4895

Author: Diogo Ferreira <defer@cyngn.com>
Date:   Wed Dec 17 17:16:16 2014 +0000

    su: Add an indicator when a 'su' session is active

    This adds an indicator to the statusbar that is visible whenever a root
    session is active, akin to the fine location icon.

    Change-Id: I669fcc87e2b7a3201308170d7727ec5fb0e00e2b

Author: Diogo Ferreira <defer@cyngn.com>
Date:   Wed Jan 14 08:44:03 2015 +0000

    appops: Disassociate appops requests from notification broadcasts

    The AppOpsService is essentially a manager for a set of counters
    and permissions. Each operation request has the potential to change
    the state and, as such, access to such state is synchronized.

    We are whitnessing deadlocks caused by the broadcast and, in fact,
    while we want to notify superuser changes eventually, it does not
    have to be synchronous with the app ops request. This patch uses the
    request to schedule the notification on a handler, leaving the locking
    semantics of appops intact.

    Change-Id: I94f6dd2c66b9492f95d3c9ffb438b3e6417007d7

Author: Lars Greiss <kufikugel@googlemail.com>
Date:   Sat Apr 25 03:01:35 2015 +0300

    Launch app privacy settings when tapping on PG notification (1/2)

    Based on https://github.com/SlimRoms/frameworks_base/commit/97ccae06cd0ad1aa366c3a70e8e744277c409b06



    JIRA: CYAN-6077
    Change-Id: I8632e8c944c1d5d7ad2fb2a2276bae5fe2d4a0a0

Author: Roman Birg <roman@cyngn.com>
Date:   Tue Oct 27 11:52:53 2015 -0700

    AppOps: fix wifi scan op

    There's no direct permission tied to it and fix the op-to-switch entry.

    Change-Id: I661ef6707ba50adb371e3223a91880c4838df669
    Signed-off-by: default avatarRoman Birg <roman@cyngn.com>

Author: Roman Birg <roman@cyngn.com>
Date:   Tue Oct 27 13:44:57 2015 -0700

    AppOps: add a default constructor

    Change-Id: I4229a65c362fe4915e62684e5ebc209525c9f9d3
    Signed-off-by: default avatarRoman Birg <roman@cyngn.com>

Author: Roman Birg <roman@cyngn.com>
Date:   Thu Oct 29 12:59:14 2015 -0700

    add missing app ops to string array

    Also added op codes to prevent further mismatches.

    Change-Id: I6e20cc5bcabe6a3216cec47d984768bf12cf4311
    Signed-off-by: default avatarRoman Birg <roman@cyngn.com>

Author: Roman Birg <roman@cyngn.com>
Date:   Mon Nov 2 09:50:47 2015 -0800

    AppOps: relax some system appops for systemui

    Grant wifi, bt, boot_complete, nfc, and data changes for systemui.

    Also remove the bluetooth permission tied to the bluetooth_change op -
    it is not always directly tied to BLUETOOTH or BLUETOOTH_ADMIN, so we
    can't force one there.

    Change-Id: Ib042dc34b0763b2d84a57baa71dc9fa995724d64
    Signed-off-by: default avatarRoman Birg <roman@cyngn.com>

Author: Chirayu Desai <cdesai@cyanogenmod.org>
Date:   Mon Dec 7 14:10:44 2015 -0800

    Allow disabling the privacy guard notification - port from cm-12.1 (2/3)

    Change-Id: Iab0288f50685220c8be0c11ea5075f91ec1bbe32

Author: Michael Bestas <mikeioannina@gmail.com>
Date:   Sun Jan 3 04:36:26 2016 +0200

    Revert "AppOps: add a default constructor"

    * Not needed after http://review.cyanogenmod.org/126381

    This reverts commit 19e0ce07.

    Change-Id: I12bfe4f7d119627a3fe08d01e8ae5b065b0f709a

Author: Gabriele M <moto.falcon.git@gmail.com>
Date:   Wed Jan 6 18:27:32 2016 +0100

    Align checkbox and description in permission confirmation dialog

    Change-Id: I9a9ab3a3f59e3d56fc774174ba37d9e191698fe5

Author: Adnan Begovic <adnan@cyngn.com>
Date:   Mon May 23 16:06:10 2016 -0700

    appops: Implement concept of delayedcount.

     High frequency request ops will be delayed until their ignore count
     ceiling is met. This is to mitigate the overloading the main activity
     manager service handler and having watchdog kill our service.

     Google play services likes to share its uid with numerous packages to avoid
     having to grant permissions from the users perspective and thus is the worst
     example of overloading this queue -- so, to not encourage bad behavior,
     we move them to the back of the line. NOTE: these values are magic, and may need
     tuning. Ideally we'd want a ringbuffer or token bucket here to do proper rate
     limiting.

    Change-Id: I5c3e88807abc80f9700dd68dcecd87dac4626de7
    TICKET: CYNGNOS-2869

Author: Adnan Begovic <adnan@cyngn.com>
Date:   Tue May 24 18:17:03 2016 -0700

    appops: Respect screen interactivity before creating dialogs.

      If the device's screen is currently off, do not queue ask
      runnables who cannot be interacted with. Since these events
      are gating mechanisms for closing an IPC loop, they need to
      happen when the user is interacting with the device.

      Likewise, on screen off, clear the queue of every op as they
      become unnecessary.

    Change-Id: Ie930d200839c9408e882510c6bc3ede37ea889ef
    TICKET: CYNGNOS-2869

Author: Gabriele M <moto.falcon.git@gmail.com>
Date:   Sun Aug 6 13:08:33 2017 +0200

    Change visibility of the Privacy Guard ops set

    Change-Id: Iafcf058f5e2074982bf45f8c82ef8d027b9358f0

Author: Unpublished <unpublished@gmx.net>
Date:   Tue Oct 24 21:09:31 2017 +0200

    We don't want to feel deprecated...

    use official api instead of deprecated internal method that prints an
    error everytime we call it

    Change-Id: Ie00efe5f514ff8db2b82eeade3a588a17af8cfb4

Author: Jane Manchun Wong <jane@wongmjane.com>
Date:   Wed Mar 1 23:37:58 2017 -0500

    Remove Cid from PrivacyGuard's notification icon

    Change-Id: I5dfe6c2d10e9dd1a022e50e02f72151b1b8a520e

Author: Zhao Wei Liew <zhaoweiliew@gmail.com>
Date:   Tue Sep 6 21:33:57 2016 +0800

    core: Import some PG string improvements from CM 13.0

    This commit partially squashes the following commits:

    c682ba59
    core: String improvements from cm-12.1

    7450f849
    String update, change wording from "Mobile" to "Cellular"

    Change-Id: I0616eb06f48813814b4005e9b60358669f69b0c8

Change-Id: I5414dd0be6a81e143f5035e58709ac4258c93616
parent 31fbc981
Loading
Loading
Loading
Loading
+386 −7
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 The Android Open Source Project
 * Copyright (c) 2013-2016, The CyanogenMod Project
 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -30,6 +32,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;

@@ -70,6 +73,10 @@ public class AppOpsManager {
     * will do this for you).
     */

    /** {@hide} */
    public static final String ACTION_SU_SESSION_CHANGED =
            "android.intent.action.SU_SESSION_CHANGED";

    final Context mContext;
    final IAppOpsService mService;
    final ArrayMap<OnOpChangedListener, IAppOpsCallback> mModeWatchers
@@ -104,9 +111,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, sOpToPerms, sOpDefault
    //  - add rows to sOpToSwitch, sOpToString, sOpNames, sOpToPerms, sOpDefault,
    //    sOpDefaultStrictMode, sOpToOpString, sOpStrictMode.
    //  - add descriptive strings to Settings/res/values/arrays.xml
    //  - add the op to the appropriate template in AppOpsState.OpsTemplate (settings app)

@@ -252,8 +267,21 @@ public class AppOpsManager {
    public static final int OP_INSTANT_APP_START_FOREGROUND = 68;
    /** @hide Answer incoming phone calls */
    public static final int OP_ANSWER_PHONE_CALLS = 69;

    /** @hide Wifi state change */
    public static final int OP_CHANGE_WIFI_STATE = 70;
    /** @hide Bluetooth state change */
    public static final int OP_BLUETOOTH_CHANGE = 71;
    /** @hide Boot completed */
    public static final int OP_BOOT_COMPLETED = 72;
    /** @hide NFC state change */
    public static final int OP_NFC_CHANGE = 73;
    /** @hide Data connect state change */
    public static final int OP_DATA_CONNECT_CHANGE = 74;
    /** @hide SU access */
    public static final int OP_SU = 75;
    /** @hide */
    public static final int _NUM_OP = 70;
    public static final int _NUM_OP = 76;

    /** Access to coarse location information. */
    public static final String OPSTR_COARSE_LOCATION = "android:coarse_location";
@@ -366,6 +394,20 @@ public class AppOpsManager {
    public static final String OPSTR_ANSWER_PHONE_CALLS
            = "android:answer_phone_calls";

    /** @hide */
    private static final String OPSTR_WIFI_CHANGE
            = "android:wifi_change";
    private static final String OPSTR_BLUETOOTH_CHANGE
            = "android:bluetooth_change";
    private static final String OPSTR_BOOT_COMPLETED
            = "android:boot_completed";
    private static final String OPSTR_NFC_CHANGE
            = "android:nfc_change";
    private static final String OPSTR_DATA_CONNECT_CHANGE
            = "android:data_connect_change";
    private static final String OPSTR_SU
            = "android:su";

    // Warning: If an permission is added here it also has to be added to
    // com.android.packageinstaller.permission.utils.EventLogger
    private static final int[] RUNTIME_AND_APPOP_PERMISSIONS_OPS = {
@@ -433,7 +475,7 @@ public class AppOpsManager {
            OP_WRITE_CALL_LOG,
            OP_READ_CALENDAR,
            OP_WRITE_CALENDAR,
            OP_COARSE_LOCATION,
            OP_WIFI_SCAN,
            OP_POST_NOTIFICATION,
            OP_COARSE_LOCATION,
            OP_CALL_PHONE,
@@ -492,7 +534,13 @@ public class AppOpsManager {
            OP_REQUEST_INSTALL_PACKAGES,
            OP_PICTURE_IN_PICTURE,
            OP_INSTANT_APP_START_FOREGROUND,
            OP_ANSWER_PHONE_CALLS
            OP_ANSWER_PHONE_CALLS,
            OP_CHANGE_WIFI_STATE,
            OP_BLUETOOTH_CHANGE,
            OP_BOOT_COMPLETED,
            OP_NFC_CHANGE,
            OP_DATA_CONNECT_CHANGE,
            OP_SU
    };

    /**
@@ -570,6 +618,12 @@ public class AppOpsManager {
            OPSTR_PICTURE_IN_PICTURE,
            OPSTR_INSTANT_APP_START_FOREGROUND,
            OPSTR_ANSWER_PHONE_CALLS,
            OPSTR_WIFI_CHANGE,
            OPSTR_BLUETOOTH_CHANGE,
            OPSTR_BOOT_COMPLETED,
            OPSTR_NFC_CHANGE,
            OPSTR_DATA_CONNECT_CHANGE,
            OPSTR_SU,
    };

    /**
@@ -647,6 +701,12 @@ public class AppOpsManager {
            "PICTURE_IN_PICTURE",
            "INSTANT_APP_START_FOREGROUND",
            "ANSWER_PHONE_CALLS",
            "WIFI_CHANGE",
            "BLUETOOTH_CHANGE",
            "BOOT_COMPLETED",
            "NFC_CHANGE",
            "DATA_CONNECT_CHANGE",
            "SU",
    };

    /**
@@ -664,7 +724,7 @@ public class AppOpsManager {
            android.Manifest.permission.WRITE_CALL_LOG,
            android.Manifest.permission.READ_CALENDAR,
            android.Manifest.permission.WRITE_CALENDAR,
            android.Manifest.permission.ACCESS_WIFI_STATE,
            null, // no permission for wifi scan available
            null, // no permission required for notifications
            null, // neighboring cells shares the coarse location perm
            android.Manifest.permission.CALL_PHONE,
@@ -724,6 +784,12 @@ public class AppOpsManager {
            null, // no permission for entering picture-in-picture on hide
            Manifest.permission.INSTANT_APP_FOREGROUND_SERVICE,
            Manifest.permission.ANSWER_PHONE_CALLS,
            Manifest.permission.CHANGE_WIFI_STATE,
            null,
            Manifest.permission.RECEIVE_BOOT_COMPLETED,
            Manifest.permission.NFC,
            Manifest.permission.MODIFY_PHONE_STATE,
            null,
    };

    /**
@@ -802,6 +868,12 @@ public class AppOpsManager {
            null, // ENTER_PICTURE_IN_PICTURE_ON_HIDE
            null, // INSTANT_APP_START_FOREGROUND
            null, // ANSWER_PHONE_CALLS
            null, //WIFI_CHANGE
            null, //BLUETOOTH_CHANGE
            null, //BOOT_COMPLETED
            null, //NFC_CHANGE
            null, //DATA_CONNECT_CHANGE
            UserManager.DISALLOW_SU, //SU TODO: this should really be investigated.
    };

    /**
@@ -879,6 +951,12 @@ public class AppOpsManager {
            false, // ENTER_PICTURE_IN_PICTURE_ON_HIDE
            false, // INSTANT_APP_START_FOREGROUND
            false, // ANSWER_PHONE_CALLS
            true, // WIFI_CHANGE
            true, // BLUETOOTH_CHANGE
            true, // BOOT_COMPLETED
            true, // NFC_CHANGE
            true, //DATA_CONNECT_CHANGE
            false, //SU
    };

    /**
@@ -955,6 +1033,177 @@ public class AppOpsManager {
            AppOpsManager.MODE_ALLOWED,  // OP_PICTURE_IN_PICTURE
            AppOpsManager.MODE_DEFAULT,  // OP_INSTANT_APP_START_FOREGROUND
            AppOpsManager.MODE_ALLOWED, // ANSWER_PHONE_CALLS
            AppOpsManager.MODE_ALLOWED, // OP_CHANGE_WIFI_STATE
            AppOpsManager.MODE_ALLOWED, // OP_BLUETOOTH_CHANGE
            AppOpsManager.MODE_ALLOWED, // OP_BOOT_COMPLETED
            AppOpsManager.MODE_ALLOWED, // OP_NFC_CHANGE
            AppOpsManager.MODE_ALLOWED,
            AppOpsManager.MODE_ASK, // OP_SU
    };

    /**
     * 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
            AppOpsManager.MODE_ALLOWED, // MODE_RUN_IN_BACKGROUND
            AppOpsManager.MODE_ALLOWED, // OP_AUDIO_ACCESSIBILITY_VOLUME
            AppOpsManager.MODE_ALLOWED,
            AppOpsManager.MODE_DEFAULT, // OP_REQUEST_INSTALL_PACKAGES
            AppOpsManager.MODE_ALLOWED, // OP_PICTURE_IN_PICTURE
            AppOpsManager.MODE_DEFAULT, // OP_INSTANT_APP_START_FOREGROUND
            AppOpsManager.MODE_ALLOWED, // ANSWER_PHONE_CALLS
            AppOpsManager.MODE_ASK,     // OP_CHANGE_WIFI_STATE
            AppOpsManager.MODE_ASK,     // OP_BLUETOOTH_CHANGE
            AppOpsManager.MODE_ALLOWED, // OP_BOOT_COMPLETED
            AppOpsManager.MODE_ASK,     // OP_NFC_CHANGE
            AppOpsManager.MODE_ASK,     // OP_DATA_CONNECT_CHANGE
            AppOpsManager.MODE_ASK,     // OP_SU
    };

    /**
     * This specifies if operation is in strict mode.
     */
    private final static boolean[] sOpStrictMode = new boolean[] {
        true,     // OP_COARSE_LOCATION
        true,     // OP_FINE_LOCATION
        true,     // OP_GPS
        false,    // OP_VIBRATE
        true,     // OP_READ_CONTACTS
        true,     // OP_WRITE_CONTACTS
        true,     // OP_READ_CALL_LOG
        true,     // OP_WRITE_CALL_LOG
        false,    // OP_READ_CALENDAR
        false,    // OP_WRITE_CALENDAR
        true,     // OP_WIFI_SCAN
        false,    // OP_POST_NOTIFICATION
        false,    // OP_NEIGHBORING_CELLS
        true,     // OP_CALL_PHONE
        true,     // OP_READ_SMS
        true,     // OP_WRITE_SMS
        false,    // OP_RECEIVE_SMS
        false,    // OP_RECEIVE_EMERGECY_SMS
        true,     // OP_RECEIVE_MMS
        false,    // OP_RECEIVE_WAP_PUSH
        true,     // OP_SEND_SMS
        false,    // OP_READ_ICC_SMS
        false,    // OP_WRITE_ICC_SMS
        false,    // OP_WRITE_SETTINGS
        false,    // OP_SYSTEM_ALERT_WINDOW
        false,    // OP_ACCESS_NOTIFICATIONS
        true,     // OP_CAMERA
        true,     // OP_RECORD_AUDIO
        false,    // OP_PLAY_AUDIO
        false,    // OP_READ_CLIPBOARD
        false,    // OP_WRITE_CLIPBOARD
        false,    // OP_TAKE_MEDIA_BUTTONS
        false,    // OP_TAKE_AUDIO_FOCUS
        false,    // OP_AUDIO_MASTER_VOLUME
        false,    // OP_AUDIO_VOICE_VOLUME
        false,    // OP_AUDIO_RING_VOLUME
        false,    // OP_AUDIO_MEDIA_VOLUME
        false,    // OP_AUDIO_ALARM_VOLUME
        false,    // OP_AUDIO_NOTIFICATION_VOLUME
        false,    // OP_AUDIO_BLUETOOTH_VOLUME
        false,    // OP_WAKE_LOCK
        false,    // OP_MONITOR_LOCATION
        true,     // OP_MONITOR_HIGH_POWER_LOCATION
        false,    // OP_GET_USAGE_STATS
        false,    // OP_MUTE_MICROPHONE
        false,    // OP_TOAST_WINDOW
        false,    // OP_PROJECT_MEDIA
        false,    // OP_ACTIVATE_VPN
        true,     // OP WALLPAPER
        false,    // ASSIST_STRUCTURE
        false,    // ASSIST_SCREENSHOT
        false,    // READ_PHONE_STATE
        false,    // ADD_VOICEMAIL
        false,    // USE_SIP
        false,    // PROCESS_OUTGOING_CALLS
        false,    // USE_FINGERPRINT
        false,    // BODY_SENSORS
        false,    // READ_CELL_BROADCASTS
        false,    // MOCK_LOCATION
        true,     // READ_EXTERNAL_STORAGE
        true,     // WRITE_EXTERNAL_STORAGE
        false,    // TURN_ON_SCREEN
        false,    // GET_ACCOUNTS
        false,    // RUN_IN_BACKGROUND
        false,    // AUDIO_ACCESSIBILITY_VOLUME
        false,    // READ_PHONE_NUMBERS
        false,    // REQUEST_INSTALL_PACKAGES
        false,    // ENTER_PICTURE_IN_PICTURE_ON_HIDE
        false,    // INSTANT_APP_START_FOREGROUND
        false,    // ANSWER_PHONE_CALLS
        true,     // OP_CHANGE_WIFI_STATE
        true,     // OP_BLUETOOTH_CHANGE
        false,    // OP_BOOT_COMPLETED
        true,     // OP_NFC_CHANGE
        true,     // OP_DATA_CONNECT_CHANGE
        true,     // OP_SU
    };

    /**
@@ -1035,6 +1284,12 @@ public class AppOpsManager {
            false, // OP_PICTURE_IN_PICTURE
            false,
            false, // ANSWER_PHONE_CALLS
            false, // OP_CHANGE_WIFI_STATE
            false, // OP_BLUETOOTH_CHANGE
            false, // OP_BOOT_COMPLETED
            false, // OP_NFC_CHANGE
            false, // OP_DATA_CONNECT_CHANGE
            false, // OP_SU
    };

    /**
@@ -1047,6 +1302,20 @@ public class AppOpsManager {
     */
    private static HashMap<String, Integer> sPermToOp = new HashMap<>();

    private static HashMap<String, Integer> sNameToOp = new HashMap<String, Integer>();

    /**
     * App op guard states.
     * @hide
     */
    public static final int[] PRIVACY_GUARD_OP_STATES = new int[] {
            OP_COARSE_LOCATION,
            OP_READ_CALL_LOG,
            OP_READ_CONTACTS,
            OP_READ_CALENDAR,
            OP_READ_SMS,
    };

    static {
        if (sOpToSwitch.length != _NUM_OP) {
            throw new IllegalStateException("sOpToSwitch length " + sOpToSwitch.length
@@ -1068,6 +1337,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);
@@ -1080,6 +1353,10 @@ public class AppOpsManager {
            throw new IllegalStateException("sOpAllowSYstemRestrictionsBypass length "
                    + sOpRestrictions.length + " should be " + _NUM_OP);
        }
        if (sOpStrictMode.length != _NUM_OP) {
            throw new IllegalStateException("sOpStrictMode length "
                    + sOpStrictMode.length + " should be " + _NUM_OP);
        }
        for (int i=0; i<_NUM_OP; i++) {
            if (sOpToString[i] != null) {
                sOpStrToOp.put(sOpToString[i], i);
@@ -1090,6 +1367,9 @@ public class AppOpsManager {
                sPermToOp.put(sOpPerms[op], op);
            }
        }
        for (int i=0; i<_NUM_OP; i++) {
            sNameToOp.put(sOpNames[i], i);
        }
    }

    /**
@@ -1121,6 +1401,15 @@ public class AppOpsManager {
        throw new IllegalArgumentException("Unknown operation string: " + op);
    }

    /**
     * Map a non-localized name for the operation back to the Op number
     * @hide
     */
    public static int nameToOp(String name) {
        Integer val = sNameToOp.get(name);
        return val != null ? val : OP_NONE;
    }

    /**
     * Retrieve the permission associated with an operation, or null if there is not one.
     * @hide
@@ -1161,7 +1450,10 @@ 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];
    }

@@ -1248,9 +1540,11 @@ public class AppOpsManager {
        private final int mDuration;
        private final int mProxyUid;
        private final String mProxyPackageName;
        private final int mAllowedCount;
        private final int mIgnoredCount;

        public OpEntry(int op, int mode, long time, long rejectTime, int duration,
                int proxyUid, String proxyPackage) {
                int proxyUid, String proxyPackage, int allowedCount, int ignoredCount) {
            mOp = op;
            mMode = mode;
            mTime = time;
@@ -1258,6 +1552,8 @@ public class AppOpsManager {
            mDuration = duration;
            mProxyUid = proxyUid;
            mProxyPackageName = proxyPackage;
            mAllowedCount = allowedCount;
            mIgnoredCount = ignoredCount;
        }

        public int getOp() {
@@ -1292,6 +1588,14 @@ public class AppOpsManager {
            return mProxyPackageName;
        }

        public int getAllowedCount() {
            return mAllowedCount;
        }

        public int getIgnoredCount() {
            return mIgnoredCount;
        }

        @Override
        public int describeContents() {
            return 0;
@@ -1306,6 +1610,8 @@ public class AppOpsManager {
            dest.writeInt(mDuration);
            dest.writeInt(mProxyUid);
            dest.writeString(mProxyPackageName);
            dest.writeInt(mAllowedCount);
            dest.writeInt(mIgnoredCount);
        }

        OpEntry(Parcel source) {
@@ -1316,6 +1622,8 @@ public class AppOpsManager {
            mDuration = source.readInt();
            mProxyUid = source.readInt();
            mProxyPackageName = source.readString();
            mAllowedCount = source.readInt();
            mIgnoredCount = source.readInt();
        }

        public static final Creator<OpEntry> CREATOR = new Creator<OpEntry>() {
@@ -1956,4 +2264,75 @@ public class AppOpsManager {
            throw e.rethrowFromSystemServer();
        }
    }

    /** @hide */
    public static boolean isStrictEnable() {
        return SystemProperties.getBoolean("persist.sys.strict_op_enable", false);
    }

    /**
     * Check if op in strict mode
     * @hide
     */
    public static boolean isStrictOp(int code) {
        return sOpStrictMode[code];
    }


    /** @hide */
    public static int stringToMode(String permission) {
        if ("allowed".equalsIgnoreCase(permission)) {
            return AppOpsManager.MODE_ALLOWED;
        } else if ("ignored".equalsIgnoreCase(permission)) {
            return AppOpsManager.MODE_IGNORED;
        } else if ("ask".equalsIgnoreCase(permission)) {
            return AppOpsManager.MODE_ASK;
        }
        return AppOpsManager.MODE_ERRORED;
    }

    /** @hide */
    public static int stringOpToOp (String op) {
        Integer val = sOpStrToOp.get(op);
        if (val == null) {
            val = OP_NONE;
        }
        return val;
    }

    /** @hide */
    public boolean isControlAllowed(int op, String packageName) {
        boolean isShow = true;
        try {
            isShow = mService.isControlAllowed(op, packageName);
        } catch (RemoteException e) {
        }
        return isShow;
    }

    /** @hide */
    public boolean getPrivacyGuardSettingForPackage(int uid, String packageName) {
        try {
            return mService.getPrivacyGuardSettingForPackage(uid, packageName);
        } catch (RemoteException e) {
        }
        return false;
    }

    /** @hide */
    public void setPrivacyGuardSettingForPackage(int uid, String packageName,
            boolean state) {
        try {
            mService.setPrivacyGuardSettingForPackage(uid, packageName, state);
        } catch (RemoteException e) {
        }
    }

    /** @hide */
    public void resetCounters() {
        try {
            mService.resetCounters();
        } catch (RemoteException e) {
        }
    }
}
+13 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 The Android Open Source Project
 * Copyright (C) 2016 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.
@@ -801,6 +802,18 @@ public class UserManager {
    public static final String EXTRA_USER_ACCOUNT_OPTIONS
            = "android.os.extra.USER_ACCOUNT_OPTIONS";

    /**
     * Specifies if the user is not allowed to use SU commands.
     * The default value is <code>false</code>.
     *
     * <p/>Key for user restrictions.
     * <p/>Type: Boolean
     * @see #setUserRestrictions(Bundle)
     * @see #getUserRestrictions()
     * @hide
     */
    public static final String DISALLOW_SU = "no_su";

    /** @hide */
    public static final int PIN_VERIFICATION_FAILED_INCORRECT = -3;
    /** @hide */
+13 −0
Original line number Diff line number Diff line
@@ -812,6 +812,19 @@ public final class Settings {
    public static final String ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS =
            "android.settings.IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS";

    /**
     * @hide
     * Activity Action: Show the "app ops" details screen.
     * <p>
     * Input: The Intent's data URI specifies the application package name
     * to be shown, with the "package" scheme.  That is "package:com.my.app".
     * <p>
     * Output: Nothing.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_APP_OPS_DETAILS_SETTINGS =
            "android.settings.APP_OPS_DETAILS_SETTINGS";

    /**
     * @hide
     * Activity Action: Show the "app ops" settings screen.
+9 −0
Original line number Diff line number Diff line
@@ -50,4 +50,13 @@ interface IAppOpsService {
    void removeUser(int userHandle);

    boolean isOperationActive(int code, int uid, String packageName);

    boolean isControlAllowed(int code, String packageName);

    // Privacy guard methods
    boolean getPrivacyGuardSettingForPackage(int uid, String packageName);
    void setPrivacyGuardSettingForPackage(int uid, String packageName, boolean state);

    // AppOps accounting
    void resetCounters();
}
+2 −0
Original line number Diff line number Diff line
@@ -32,4 +32,6 @@
    <protected-broadcast
        android:name="com.android.server.policy.PhoneWindowManager.ACTION_TORCH_OFF" />

    <!-- Used to notify when SU is used. -->
    <protected-broadcast android:name="android.intent.action.SU_SESSION_CHANGED" />
</manifest>
Loading