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

Commit 0ef3e79d authored by Steve Kondik's avatar Steve Kondik Committed by Bruno Martins
Browse files

appops: Privacy Guard for P (1/2)

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: 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: 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:   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: 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:   Tue Jul 25 18:47:06 2017 +0200

    AppOps: Prevent deadlock when making note of applications

    If noteOperation() is called with ActivityManagerService locked,
    AppOpsService won't be able to show the PermissionDialog, causing
    noteOperation() to wait indefinitely. Keep a reference to the
    current ActivityManagerService instance so that we can check
    whether showing the PermissionDialog is safe or not.

    Even though there's currently no code path that causes startOperation()
    to be called with ActivityManagerService locked, add the same check
    there to prevent the same from happening in future.

    BUGBASH-17

    Change-Id: I118aac6ddf91774a038d73047162cfdb8395e58d

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

Author: MSe1969 <mse1969@posteo.de>
Date:   Fri, 16 Nov 2018 20:14:56 +0100

    ClipboardService: Restore different method calls to
    AppOps to fix PG

    Commit 34ffba62 'Limit instant app access
    to clipboard' (AOSP Bug-ID: 34231507) has introduced the new method
    'clipboardAccessAllowed', which replaces all AppOps calls. However, whilst
    the previous coding made use of the methods checkOp, noteOp and
    checkOpNoThrow, the new method only uses method 'checkOp'. Different from
    'noteOp', the 'checkOp' call only performs a check without setting the
    counter or initializing the Op.

    As a consequence, ClipBoard access did not show up any longer in Lineage's
    Privacy Guard, hence users couldn't control anymore the apps accordingly.

    This change aims at restoring the former call behavior by extending the
    'clipboardAccessAllowed' method with a parameter to specify the AppOp
    calling method according to the former code, which fixes the Privacy Guard
    issue.

    Change-Id: I4db7b4f043eb39068cd7a6346a0eb645648cfada

Author: Danny Baumann <dannybaumann@web.de>
Date:   Tue Dec 18 13:30:00 2018 +0100

    AppOpsService: Fix deadlock

    * When an app had access to external storage and was then set
      to "always ask" or "denied", the app could cause a deadlock
      on ActivityManager, resulting in a soft reboot

    Change-Id: I4341a321562c6ced00215218968f019bfb5f4443

Author: Michael W <baddaemon87@gmail.com>
Date:   Tue Dec 25 11:15:49 2018 +0100

    AppOpsService: Fix another possible deadlock

    * A possible race condition with the isInteractive() calls
      can result in a deadlock resulting in a soft reboot
    * Use a broadcast receiver instead and listen for screen
      state changes
    * Use AppOpsService.this for the synchronized part,
      otherwise the lock is essentially useless.
    * Move the whole content of the receiver under the lock so the
      relevant assignment of mIsInteractive is also synchronized
    * Idea by Danny Baumann <dannybaumann@web.de>

    Change-Id: I3c5a70cf67c3d0b3b9855a598d3d29e17c1aaedc

Change-Id: I5414dd0be6a81e143f5035e58709ac4258c93616
parent 218b4e07
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -4421,9 +4421,9 @@ Landroid/app/AppOpsManager$OnOpChangedInternalListener;
Landroid/app/AppOpsManager$OnOpChangedInternalListener;-><init>()V
Landroid/app/AppOpsManager$OnOpChangedInternalListener;->onOpChanged(ILjava/lang/String;)V
Landroid/app/AppOpsManager$OpEntry;
Landroid/app/AppOpsManager$OpEntry;-><init>(IIJJIILjava/lang/String;)V
Landroid/app/AppOpsManager$OpEntry;-><init>(II[J[JIILjava/lang/String;)V
Landroid/app/AppOpsManager$OpEntry;-><init>(II[J[JIZILjava/lang/String;)V
Landroid/app/AppOpsManager$OpEntry;-><init>(IIJJIILjava/lang/String;II)V
Landroid/app/AppOpsManager$OpEntry;-><init>(II[J[JIILjava/lang/String;II)V
Landroid/app/AppOpsManager$OpEntry;-><init>(II[J[JIZILjava/lang/String;II)V
Landroid/app/AppOpsManager$OpEntry;-><init>(Landroid/os/Parcel;)V
Landroid/app/AppOpsManager$OpEntry;->CREATOR:Landroid/os/Parcelable$Creator;
Landroid/app/AppOpsManager$OpEntry;->getDuration()I
+355 −11
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 The Android Open Source 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.
@@ -118,6 +119,12 @@ public class AppOpsManager {
     */
    public static final int MODE_FOREGROUND = 4;

    /**
     * @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 = 5;

    /**
     * Flag for {@link #startWatchingMode(String, String, int, OnOpChangedListener)}:
     * Also get reports if the foreground state of an op's uid changes.  This only works
@@ -135,6 +142,7 @@ public class AppOpsManager {
            "deny",         // MODE_ERRORED
            "default",      // MODE_DEFAULT
            "foreground",   // MODE_FOREGROUND
            "ask",          // MODE_ASK
    };

    /**
@@ -188,7 +196,8 @@ public class AppOpsManager {
    // when adding one of these:
    //  - increment _NUM_OP
    //  - define an OPSTR_* constant (marked as @SystemApi)
    //  - 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)

@@ -352,8 +361,18 @@ public class AppOpsManager {
    public static final int OP_START_FOREGROUND = 76;
    /** @hide */
    public static final int OP_BLUETOOTH_SCAN = 77;
    /** @hide */
    public static final int _NUM_OP = 78;
    /** @hide Bluetooth state change */
    public static final int OP_BLUETOOTH_CHANGE = 78;
    /** @hide Boot completed */
    public static final int OP_BOOT_COMPLETED = 79;
    /** @hide NFC state change */
    public static final int OP_NFC_CHANGE = 80;
    /** @hide Data connect state change */
    public static final int OP_DATA_CONNECT_CHANGE = 81;
    /** @hide SU access */
    public static final int OP_SU = 82;
    /** @hide */
    public static final int _NUM_OP = 83;

    /** Access to coarse location information. */
    public static final String OPSTR_COARSE_LOCATION = "android:coarse_location";
@@ -597,6 +616,17 @@ public class AppOpsManager {
    public static final String OPSTR_START_FOREGROUND = "android:start_foreground";
    /** @hide */
    public static final String OPSTR_BLUETOOTH_SCAN = "android:bluetooth_scan";
    /** @hide */
    public static final String OPSTR_BLUETOOTH_CHANGE = "android:bluetooth_change";
    /** @hide */
    public static final String OPSTR_BOOT_COMPLETED = "android:boot_completed";
    /** @hide */
    public static final String OPSTR_NFC_CHANGE = "android:nfc_change";
    /** @hide */
    public static final String OPSTR_DATA_CONNECT_CHANGE = "android:data_connect_change";

    /** @hide */
    public 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
@@ -646,6 +676,7 @@ public class AppOpsManager {
            OP_WRITE_SETTINGS,
            OP_REQUEST_INSTALL_PACKAGES,
            OP_START_FOREGROUND,
            OP_SU
    };

    /**
@@ -667,7 +698,7 @@ public class AppOpsManager {
            OP_WRITE_CALL_LOG,                  // WRITE_CALL_LOG
            OP_READ_CALENDAR,                   // READ_CALENDAR
            OP_WRITE_CALENDAR,                  // WRITE_CALENDAR
            OP_COARSE_LOCATION,                 // WIFI_SCAN
            OP_WIFI_SCAN,                       // WIFI_SCAN
            OP_POST_NOTIFICATION,               // POST_NOTIFICATION
            OP_COARSE_LOCATION,                 // NEIGHBORING_CELLS
            OP_CALL_PHONE,                      // CALL_PHONE
@@ -734,7 +765,12 @@ public class AppOpsManager {
            OP_ACCEPT_HANDOVER,                 // ACCEPT_HANDOVER
            OP_MANAGE_IPSEC_TUNNELS,            // MANAGE_IPSEC_HANDOVERS
            OP_START_FOREGROUND,                // START_FOREGROUND
            OP_COARSE_LOCATION,                 // BLUETOOTH_SCAN
            OP_BLUETOOTH_SCAN,                  // BLUETOOTH_SCAN
            OP_BLUETOOTH_CHANGE,                // BLUETOOTH_CHANGE
            OP_BOOT_COMPLETED,                  // BOOT_COMPLETED
            OP_NFC_CHANGE,                      // NFC_CHANGE
            OP_DATA_CONNECT_CHANGE,             // DATA_CONNECT_CHANGE
            OP_SU,                              // SU
    };

    /**
@@ -819,6 +855,11 @@ public class AppOpsManager {
            OPSTR_MANAGE_IPSEC_TUNNELS,
            OPSTR_START_FOREGROUND,
            OPSTR_BLUETOOTH_SCAN,
            OPSTR_BLUETOOTH_CHANGE,
            OPSTR_BOOT_COMPLETED,
            OPSTR_NFC_CHANGE,
            OPSTR_DATA_CONNECT_CHANGE,
            OPSTR_SU,
    };

    /**
@@ -904,6 +945,11 @@ public class AppOpsManager {
            "MANAGE_IPSEC_TUNNELS",
            "START_FOREGROUND",
            "BLUETOOTH_SCAN",
            "BLUETOOTH_CHANGE",
            "BOOT_COMPLETED",
            "NFC_CHANGE",
            "DATA_CONNECT_CHANGE",
            "SU",
    };

    /**
@@ -921,7 +967,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,
@@ -989,6 +1035,11 @@ public class AppOpsManager {
            null, // no permission for OP_MANAGE_IPSEC_TUNNELS
            Manifest.permission.FOREGROUND_SERVICE,
            null, // no permission for OP_BLUETOOTH_SCAN
            null,
            Manifest.permission.RECEIVE_BOOT_COMPLETED,
            Manifest.permission.NFC,
            null,
            null, // no permission for OP_SU
    };

    /**
@@ -1075,6 +1126,11 @@ public class AppOpsManager {
            null, // MANAGE_IPSEC_TUNNELS
            null, // START_FOREGROUND
            null, // maybe should be UserManager.DISALLOW_SHARE_LOCATION, //BLUETOOTH_SCAN
            null, // BLUETOOTH_CHANGE
            null, // BOOT_COMPLETED
            null, // NFC_CHANGE
            null, // DATA_CONNECT_CHANGE
            UserManager.DISALLOW_SU, // SU TODO: this should really be investigated.
    };

    /**
@@ -1160,6 +1216,11 @@ public class AppOpsManager {
            false, // MANAGE_IPSEC_HANDOVERS
            false, // START_FOREGROUND
            true, // BLUETOOTH_SCAN
            true, // BLUETOOTH_CHANGE
            true, // BOOT_COMPLETED
            true, // NFC_CHANGE
            true, // DATA_CONNECT_CHANGE
            false, // SU
    };

    /**
@@ -1244,6 +1305,190 @@ public class AppOpsManager {
            AppOpsManager.MODE_ERRORED,  // MANAGE_IPSEC_TUNNELS
            AppOpsManager.MODE_ALLOWED,  // OP_START_FOREGROUND
            AppOpsManager.MODE_ALLOWED,  // OP_BLUETOOTH_SCAN
            AppOpsManager.MODE_ALLOWED,  // OP_BLUETOOTH_CHANGE
            AppOpsManager.MODE_ALLOWED,  // OP_BOOT_COMPLETED
            AppOpsManager.MODE_ALLOWED,  // OP_NFC_CHANGE
            AppOpsManager.MODE_ALLOWED,  // OP_DATA_CONNECT_CHANGE
            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_ASK,     // MODE_RUN_IN_BACKGROUND
            AppOpsManager.MODE_ALLOWED, // OP_AUDIO_ACCESSIBILITY_VOLUME
            AppOpsManager.MODE_ALLOWED, // READ_PHONE_NUMBERS
            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_RUN_ANY_IN_BACKGROUND
            AppOpsManager.MODE_ALLOWED, // OP_CHANGE_WIFI_STATE
            AppOpsManager.MODE_ALLOWED, // REQUEST_DELETE_PACKAGES
            AppOpsManager.MODE_ALLOWED, // OP_BIND_ACCESSIBILITY_SERVICE
            AppOpsManager.MODE_ALLOWED, // ACCEPT_HANDOVER
            AppOpsManager.MODE_ERRORED, // MANAGE_IPSEC_TUNNELS
            AppOpsManager.MODE_ALLOWED, // OP_START_FOREGROUND
            AppOpsManager.MODE_ALLOWED, // OP_BLUETOOTH_SCAN
            AppOpsManager.MODE_ASK,     // OP_BLUETOOTH_CHANGE
            AppOpsManager.MODE_ASK,     // 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,  // COARSE_LOCATION
            true,  // FINE_LOCATION
            true,  // GPS
            false, // VIBRATE
            true,  // READ_CONTACTS
            true,  // WRITE_CONTACTS
            true,  // READ_CALL_LOG
            true,  // WRITE_CALL_LOG
            false, // READ_CALENDAR
            false, // WRITE_CALENDAR
            true,  // WIFI_SCAN
            false, // POST_NOTIFICATION
            false, // NEIGHBORING_CELLS
            true,  // CALL_PHONE
            true,  // READ_SMS
            true,  // WRITE_SMS
            true,  // RECEIVE_SMS
            false, // RECEIVE_EMERGECY_SMS
            true,  // RECEIVE_MMS
            false, // RECEIVE_WAP_PUSH
            true,  // SEND_SMS
            true,  // READ_ICC_SMS
            true,  // WRITE_ICC_SMS
            true,  // WRITE_SETTINGS
            false, // SYSTEM_ALERT_WINDOW
            false, // ACCESS_NOTIFICATIONS
            true,  // CAMERA
            true,  // RECORD_AUDIO
            true,  // PLAY_AUDIO
            false, // READ_CLIPBOARD
            false, // WRITE_CLIPBOARD
            true,  // TAKE_MEDIA_BUTTONS
            true,  // TAKE_AUDIO_FOCUS
            false, // AUDIO_MASTER_VOLUME
            false, // AUDIO_VOICE_VOLUME
            false, // AUDIO_RING_VOLUME
            false, // AUDIO_MEDIA_VOLUME
            false, // AUDIO_ALARM_VOLUME
            false, // AUDIO_NOTIFICATION_VOLUME
            false, // AUDIO_BLUETOOTH_VOLUME
            false, // WAKE_LOCK
            true,  // MONITOR_LOCATION
            true,  // MONITOR_HIGH_POWER_LOCATION
            true,  // GET_USAGE_STATS
            false, // MUTE_MICROPHONE
            false, // TOAST_WINDOW
            true,  // PROJECT_MEDIA
            false, // ACTIVATE_VPN
            false, // WALLPAPER
            false, // ASSIST_STRUCTURE
            false, // ASSIST_SCREENSHOT
            true,  // READ_PHONE_STATE
            true,  // ADD_VOICEMAIL
            true,  // USE_SIP
            true,  // PROCESS_OUTGOING_CALLS
            true,  // USE_FINGERPRINT
            true,  // BODY_SENSORS
            false, // READ_CELL_BROADCASTS
            true,  // MOCK_LOCATION
            true,  // READ_EXTERNAL_STORAGE
            true,  // WRITE_EXTERNAL_STORAGE
            false, // TURN_ON_SCREEN
            false, // GET_ACCOUNTS
            true,  // RUN_IN_BACKGROUND
            false, // AUDIO_ACCESSIBILITY_VOLUME
            true,  // READ_PHONE_NUMBERS
            true,  // REQUEST_INSTALL_PACKAGES
            true,  // ENTER_PICTURE_IN_PICTURE_ON_HIDE
            true,  // INSTANT_APP_START_FOREGROUND
            false, // ANSWER_PHONE_CALLS
            true,  // OP_RUN_ANY_IN_BACKGROUND
            false, // OP_CHANGE_WIFI_STATE
            false, // OP_REQUEST_DELETE_PACKAGES
            false, // OP_BIND_ACCESSIBILITY_SERVICE
            false, // ACCEPT_HANDOVER
            false, // MANAGE_IPSEC_HANDOVERS
            false, // START_FOREGROUND
            true,  // BLUETOOTH_SCAN
            true,  // BLUETOOTH_CHANGE
            true,  // BOOT_COMPLETED
            true,  // NFC_CHANGE
            true,  // DATA_CONNECT_CHANGE
            true,  // SU
    };

    /**
@@ -1332,6 +1577,11 @@ public class AppOpsManager {
            false, // MANAGE_IPSEC_TUNNELS
            false, // START_FOREGROUND
            false, // BLUETOOTH_SCAN
            false, // OP_BLUETOOTH_CHANGE
            false, // OP_BOOT_COMPLETED
            false, // OP_NFC_CHANGE
            false, // OP_DATA_CONNECT_CHANGE
            false, // OP_SU
    };

    /**
@@ -1344,6 +1594,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
@@ -1365,6 +1629,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);
@@ -1377,6 +1645,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);
@@ -1387,6 +1659,9 @@ public class AppOpsManager {
                sPermToOp.put(sOpPerms[op], op);
            }
        }
        for (int i=0; i<_NUM_OP; i++) {
            sNameToOp.put(sOpNames[i], i);
        }
    }

    /**
@@ -1418,6 +1693,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
@@ -1458,10 +1742,17 @@ 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];
    }

    public static int opToDefaultMode(int op) {
        return opToDefaultMode(op, false);
    }

    /**
     * Retrieve the human readable mode.
     * @hide
@@ -1557,9 +1848,11 @@ public class AppOpsManager {
        private final int mProxyUid;
        private final boolean mRunning;
        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;
            mTimes = new long[_NUM_UID_STATE];
@@ -1570,10 +1863,13 @@ public class AppOpsManager {
            mRunning = duration == -1;
            mProxyUid = proxyUid;
            mProxyPackageName = proxyPackage;
            mAllowedCount = allowedCount;
            mIgnoredCount = ignoredCount;
        }

        public OpEntry(int op, int mode, long[] times, long[] rejectTimes, int duration,
                boolean running, int proxyUid, String proxyPackage) {
                boolean running, int proxyUid, String proxyPackage,
                int allowedCount, int ignoredCount) {
            mOp = op;
            mMode = mode;
            mTimes = new long[_NUM_UID_STATE];
@@ -1584,11 +1880,14 @@ public class AppOpsManager {
            mRunning = running;
            mProxyUid = proxyUid;
            mProxyPackageName = proxyPackage;
            mAllowedCount = allowedCount;
            mIgnoredCount = ignoredCount;
        }

        public OpEntry(int op, int mode, long[] times, long[] rejectTimes, int duration,
                int proxyUid, String proxyPackage) {
            this(op, mode, times, rejectTimes, duration, duration == -1, proxyUid, proxyPackage);
                int proxyUid, String proxyPackage, int allowedCount, int ignoredCount) {
            this(op, mode, times, rejectTimes, duration, duration == -1, proxyUid, proxyPackage,
                    allowedCount, ignoredCount);
        }

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

        public int getAllowedCount() {
            return mAllowedCount;
        }

        public int getIgnoredCount() {
            return mIgnoredCount;
        }

        @Override
        public int describeContents() {
            return 0;
@@ -1670,6 +1977,8 @@ public class AppOpsManager {
            dest.writeBoolean(mRunning);
            dest.writeInt(mProxyUid);
            dest.writeString(mProxyPackageName);
            dest.writeInt(mAllowedCount);
            dest.writeInt(mIgnoredCount);
        }

        OpEntry(Parcel source) {
@@ -1681,6 +1990,8 @@ public class AppOpsManager {
            mRunning = source.readBoolean();
            mProxyUid = source.readInt();
            mProxyPackageName = source.readString();
            mAllowedCount = source.readInt();
            mIgnoredCount = source.readInt();
        }

        public static final Creator<OpEntry> CREATOR = new Creator<OpEntry>() {
@@ -2589,4 +2900,37 @@ public class AppOpsManager {
        }
        return time;
    }

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

    /** @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
@@ -961,6 +961,19 @@ public class UserManager {
     */
    public static final String DISALLOW_PRINTING = "no_printing";

    /**
     * Specifies whether the user is 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";

    /**
     * Application restriction key that is used to indicate the pending arrival
     * of real restrictions for the app.
+13 −0
Original line number Diff line number Diff line
@@ -897,6 +897,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.
+7 −0
Original line number Diff line number Diff line
@@ -56,4 +56,11 @@ interface IAppOpsService {
    boolean isOperationActive(int code, int uid, String packageName);

    void startWatchingModeWithFlags(int op, String packageName, int flags, IAppOpsCallback callback);

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

    // AppOps accounting
    void resetCounters();
}
Loading