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

Commit b9781fe0 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "App ops: you can now turn off operations."

parents 1c2df382 5e45ee67
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5122,6 +5122,7 @@ package android.content {
    method public int bulkInsert(android.net.Uri, android.content.ContentValues[]);
    method public android.os.Bundle call(java.lang.String, java.lang.String, android.os.Bundle);
    method public abstract int delete(android.net.Uri, java.lang.String, java.lang.String[]);
    method public void dump(java.io.FileDescriptor, java.io.PrintWriter, java.lang.String[]);
    method public final android.content.Context getContext();
    method public final android.content.pm.PathPermission[] getPathPermissions();
    method public final java.lang.String getReadPermission();
+61 −13
Original line number Diff line number Diff line
@@ -44,19 +44,44 @@ public class AppOpsManager {
    public static final int OP_WRITE_CONTACTS = 5;
    public static final int OP_READ_CALL_LOG = 6;
    public static final int OP_WRITE_CALL_LOG = 7;
    public static final int OP_READ_CALENDAR = 8;
    public static final int OP_WRITE_CALENDAR = 9;
    public static final int OP_WIFI_SCAN = 10;

    private static String[] sOpNames = new String[] {
        "COARSE_LOCATION",
        "FINE_LOCATION",
        "GPS",
        "VIBRATE",
        "READ_CONTACTS",
        "WRITE_CONTACTS",
        "READ_CALL_LOG",
        "WRITE_CALL_LOG",
        "READ_CALENDAR",
        "WRITE_CALENDAR",
        "WIFI_SCAN",
    };

    private static String[] sOpPerms = new String[] {
        android.Manifest.permission.ACCESS_COARSE_LOCATION,
        android.Manifest.permission.ACCESS_FINE_LOCATION,
        android.Manifest.permission.ACCESS_FINE_LOCATION,
        android.Manifest.permission.VIBRATE,
        android.Manifest.permission.READ_CONTACTS,
        android.Manifest.permission.WRITE_CONTACTS,
        android.Manifest.permission.READ_CALL_LOG,
        android.Manifest.permission.WRITE_CALL_LOG,
        android.Manifest.permission.READ_CALENDAR,
        android.Manifest.permission.WRITE_CALENDAR,
        android.Manifest.permission.ACCESS_WIFI_STATE,
    };

    public static String opToString(int op) {
        switch (op) {
            case OP_COARSE_LOCATION: return "COARSE_LOCATION";
            case OP_FINE_LOCATION: return "FINE_LOCATION";
            case OP_GPS: return "GPS";
            case OP_VIBRATE: return "VIBRATE";
            case OP_READ_CONTACTS: return "READ_CONTACTS";
            case OP_WRITE_CONTACTS: return "WRITE_CONTACTS";
            case OP_READ_CALL_LOG: return "READ_CALL_LOG";
            case OP_WRITE_CALL_LOG: return "WRITE_CALL_LOG";
            default: return "Unknown(" + op + ")";
    public static String opToName(int op) {
        return op < sOpNames.length ? sOpNames[op] : ("Unknown(" + op + ")");
    }

    public static String opToPermission(int op) {
        return sOpPerms[op];
    }

    public static class PackageOps implements Parcelable {
@@ -120,12 +145,16 @@ public class AppOpsManager {

    public static class OpEntry implements Parcelable {
        private final int mOp;
        private final int mMode;
        private final long mTime;
        private final long mRejectTime;
        private final int mDuration;

        public OpEntry(int op, long time, int duration) {
        public OpEntry(int op, int mode, long time, long rejectTime, int duration) {
            mOp = op;
            mMode = mode;
            mTime = time;
            mRejectTime = rejectTime;
            mDuration = duration;
        }

@@ -133,10 +162,18 @@ public class AppOpsManager {
            return mOp;
        }

        public int getMode() {
            return mMode;
        }

        public long getTime() {
            return mTime;
        }

        public long getRejectTime() {
            return mRejectTime;
        }

        public boolean isRunning() {
            return mDuration == -1;
        }
@@ -153,13 +190,17 @@ public class AppOpsManager {
        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(mOp);
            dest.writeInt(mMode);
            dest.writeLong(mTime);
            dest.writeLong(mRejectTime);
            dest.writeInt(mDuration);
        }

        OpEntry(Parcel source) {
            mOp = source.readInt();
            mMode = source.readInt();
            mTime = source.readLong();
            mRejectTime = source.readLong();
            mDuration = source.readInt();
        }

@@ -195,6 +236,13 @@ public class AppOpsManager {
        return null;
    }

    public void setMode(int code, int uid, String packageName, int mode) {
        try {
            mService.setMode(code, uid, packageName, mode);
        } catch (RemoteException e) {
        }
    }

    public int checkOp(int op, int uid, String packageName) {
        try {
            int mode = mService.checkOperation(op, uid, packageName);
+15 −6
Original line number Diff line number Diff line
@@ -190,8 +190,13 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
        public Cursor query(String callingPkg, Uri uri, String[] projection,
                String selection, String[] selectionArgs, String sortOrder,
                ICancellationSignal cancellationSignal) {
            // XXX need content provider to help return correct result.
            enforceReadPermission(callingPkg, uri);
            if (enforceReadPermission(callingPkg, uri) != AppOpsManager.MODE_ALLOWED) {
                // The read is not allowed...  to fake it out, we replace the given
                // selection statement with a dummy one that will always be false.
                // This way we will get a cursor back that has the correct structure
                // but contains no rows.
                selection = "'A' = 'B'";
            }
            return ContentProvider.this.query(uri, projection, selection, selectionArgs, sortOrder,
                    CancellationSignal.fromTransport(cancellationSignal));
        }
@@ -203,8 +208,14 @@ public abstract class ContentProvider implements ComponentCallbacks2 {

        @Override
        public Uri insert(String callingPkg, Uri uri, ContentValues initialValues) {
            // XXX need content provider to help return correct result.
            enforceWritePermission(callingPkg, uri);
            if (enforceWritePermission(callingPkg, uri) != AppOpsManager.MODE_ALLOWED) {
                // If not allowed, we need to return some reasonable URI.  Maybe the
                // content provider should be responsible for this, but for now we
                // will just return the base URI with a dummy '0' tagged on to it.
                // You shouldn't be able to read if you can't write, anyway, so it
                // shouldn't matter much what is returned.
                return uri.buildUpon().appendPath("0").build();
            }
            return ContentProvider.this.insert(uri, initialValues);
        }

@@ -1189,12 +1200,10 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
     * Print the Provider's state into the given stream.  This gets invoked if
     * you run "adb shell dumpsys activity provider &lt;provider_component_name&gt;".
     *
     * @param prefix Desired prefix to prepend at each line of output.
     * @param fd The raw file descriptor that the dump is being sent to.
     * @param writer The PrintWriter to which you should dump your state.  This will be
     * closed for you after you return.
     * @param args additional arguments to the dump request.
     * @hide
     */
    public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
        writer.println("nothing to dump");
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ import java.util.Arrays;
 */
public class WorkSource implements Parcelable {
    static final String TAG = "WorkSource";
    static final boolean DEBUG = true;
    static final boolean DEBUG = false;

    int mNum;
    int[] mUids;
+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.app.AppOpsManager;
interface IAppOpsService {
    List<AppOpsManager.PackageOps> getPackagesForOps(in int[] ops);
    List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName, in int[] ops);
    void setMode(int code, int uid, String packageName, int mode);
    int checkOperation(int code, int uid, String packageName);
    int noteOperation(int code, int uid, String packageName);
    int startOperation(int code, int uid, String packageName);
Loading